Ejemplo n.º 1
0
/* descriptor allocator when more than one word is required to describe the
 * pointers */
struct GGGGC_Descriptor *ggggc_allocateDescriptorL(ggc_size_t size, const ggc_size_t *pointers)
{
    struct GGGGC_Descriptor *dd, *ret;
    ggc_size_t dPWords, dSize;

    /* the size of the descriptor */
    if (pointers)
        dPWords = GGGGC_DESCRIPTOR_WORDS_REQ(size);
    else
        dPWords = 1;
    dSize = GGGGC_WORD_SIZEOF(struct GGGGC_Descriptor) + dPWords;

    /* get a descriptor-descriptor for the descriptor we're about to allocate */
    dd = ggggc_allocateDescriptorDescriptor(dSize);

    /* use that to allocate the descriptor */
    ret = (struct GGGGC_Descriptor *) ggggc_malloc(dd);
    ret->size = size;

    /* and set it up */
    if (pointers) {
        memcpy(ret->pointers, pointers, sizeof(ggc_size_t) * dPWords);
        ret->pointers[0] |= 1; /* first word is always the descriptor pointer */
    } else {
        ret->pointers[0] = 0;
    }

    return ret;
}
Ejemplo n.º 2
0
/* allocate a pointer array (size is in words) */
void *ggggc_mallocPointerArray(ggc_size_t sz)
{
    struct GGGGC_Descriptor *descriptor = ggggc_allocateDescriptorPA(sz + 1 + sizeof(struct GGGGC_Header)/sizeof(ggc_size_t));
    struct GGGGC_Array *ret = (struct GGGGC_Array *) ggggc_malloc(descriptor);
    ret->length = sz;
    return ret;
}
Ejemplo n.º 3
0
/* allocate a data array */
void *ggggc_mallocDataArray(ggc_size_t nmemb, ggc_size_t size)
{
    ggc_size_t sz = ((nmemb*size)+sizeof(ggc_size_t)-1)/sizeof(ggc_size_t);
    struct GGGGC_Descriptor *descriptor = ggggc_allocateDescriptorDA(sz + 1 + sizeof(struct GGGGC_Header)/sizeof(ggc_size_t));
    struct GGGGC_Array *ret = (struct GGGGC_Array *) ggggc_malloc(descriptor);
    ret->length = nmemb;
    return ret;
}
Ejemplo n.º 4
0
void * LSRValue::createInMemory(void *classD) {
    LSRClassTable * classDefs = (LSRClassTable *) classD;
    if (!classDefs->contains(className)) {
        return NULL;
    }
    void * desc = classDefs->getDescriptorPointer(className);
    objPtr = NULL;
    GGC_PUSH_1(objPtr);    
    objPtr = ggggc_malloc((struct GGGGC_Descriptor *) desc);
    return objPtr;
}
Ejemplo n.º 5
0
/* allocate an object */
void *ggggc_malloc(struct GGGGC_Descriptor *descriptor)
{
    /* FILLME */
    ggc_size_t *ret = NULL;

    //allocate a pool if no pool
    if(!ggggc_fromPoolList){
        ggggc_fromPoolList = newPool(1);
        ggggc_fromPoolList->generation = 1;
        totalYoungSpace += ggggc_fromPoolList->end - ggggc_fromPoolList->start;
        ggggc_toPoolList =  newPool(1);
        ggggc_toPoolList->generation = 3;
        totalYoungSpace += ggggc_toPoolList->end - ggggc_toPoolList->start;
        ggggc_fromPoolTail = ggggc_fromPoolList;
        ggggc_toPoolTail = ggggc_toPoolList;
    }

    if(!ggggc_curToPool)
        ggggc_curToPool = ggggc_toPoolList;

    while (ggggc_curToPool){
        if (ggggc_curToPool->end - ggggc_curToPool->free >= descriptor->size){
            //allocate using free space 
            ret = (ggc_size_t*)ggggc_curToPool->free;
            ggggc_curToPool->free += descriptor->size;
            setToZero(ret, descriptor->size);
            ((struct GGGGC_Header*)ret)->descriptor__ptr = descriptor;   
            //totalFilled += allocationSizeRounded;
            return ret;
        }
        ggggc_curToPool = ggggc_curToPool -> next;
    }

    ggggc_collect();

    //the descriptor used for allocate sis moved after collect
    if(isForwarded((ggc_size_t *)descriptor))
        descriptor = (struct GGGGC_Descriptor *)(getForwardingAddress((ggc_size_t *)descriptor));
    return ggggc_malloc(descriptor);
    //return GC_MALLOC(descriptor->size * sizeof(void*));
}
Ejemplo n.º 6
0
/* allocate a descriptor-descriptor for a descriptor of the given size */
struct GGGGC_Descriptor *ggggc_allocateDescriptorDescriptor(ggc_size_t size)
{
    struct GGGGC_Descriptor tmpDescriptor, *ret;
    ggc_size_t ddSize;

    /* need one description bit for every word in the object */
    ddSize = GGGGC_WORD_SIZEOF(struct GGGGC_Descriptor) + GGGGC_DESCRIPTOR_WORDS_REQ(size);

    /* check if we already have a descriptor */
    if (ggggc_descriptorDescriptors[size])
        return ggggc_descriptorDescriptors[size];

    /* otherwise, need to allocate one. First lock the space */
    if (ggggc_descriptorDescriptors[size]) {
        return ggggc_descriptorDescriptors[size];
    }

    /* now make a temporary descriptor to describe the descriptor descriptor */
    tmpDescriptor.header.descriptor__ptr = NULL;
    tmpDescriptor.header.extra_bits = 0;
    tmpDescriptor.size = ddSize;
    tmpDescriptor.pointers[0] = GGGGC_DESCRIPTOR_DESCRIPTION;

    /* allocate the descriptor descriptor */
    ret = (struct GGGGC_Descriptor *) ggggc_malloc(&tmpDescriptor);

    /* make it correct */
    ret->size = size;
    ret->pointers[0] = GGGGC_DESCRIPTOR_DESCRIPTION;

    /* put it in the list */
    ggggc_descriptorDescriptors[size] = ret;
    GGC_PUSH_1(ggggc_descriptorDescriptors[size]);
    GGC_GLOBALIZE();

    /* and give it a proper descriptor */
    ret->header.descriptor__ptr = ggggc_allocateDescriptorDescriptor(ddSize);

    return ret;
}
Ejemplo n.º 7
0
/* allocate an object */
void *ggggc_malloc(struct GGGGC_Descriptor *descriptor)
{
    GGC_YIELD();
    void * userPtr = NULL;
    struct GGGGC_Header header;
    header.descriptor__ptr = descriptor;
    if (!ggggc_curPool) {
        ggggc_curPool = ggggc_fromList = newPool(1);
        ggggc_toList = newPool(1);
        ggggc_forceCollect = 0;
    }


    ggc_size_t size = descriptor->size;
    if (ggggc_curPool->free + size >= ggggc_curPool->end) {
        if (ggggc_curPool->next) {
            ggggc_curPool = ggggc_curPool->next;
            return ggggc_malloc(descriptor);
        }
        struct GGGGC_Pool *temp = newPool(1);
        ggggc_curPool->next = temp;
        ggggc_curPool = temp;
        temp = newPool(1);
        struct GGGGC_Pool *poolIter = ggggc_toList;
        while(poolIter) {
            if (!(poolIter->next)) {
                poolIter->next = temp;
                break;
            }
            poolIter = poolIter->next;
        }
        ggggc_forceCollect = 1;
    }
    userPtr = (ggggc_curPool->free);
    ggggc_curPool->free += size;
    ((struct GGGGC_Header *) userPtr)[0] = header;
    ggggc_zero_object((struct GGGGC_Header*)userPtr);
    return userPtr;
}
Ejemplo n.º 8
0
/* and a combined malloc/allocslot */
void *ggggc_mallocSlot(struct GGGGC_DescriptorSlot *slot)
{
    return ggggc_malloc(ggggc_allocateDescriptorSlot(slot));
}