long ItemCheck(treeNode tree) { GGC_PUSH_1(tree); if (GGC_RP(tree, left) == NULL) { return GGC_RD(tree, item); } else { return GGC_RD(tree, item) + ItemCheck(GGC_RP(tree, left)) - ItemCheck(GGC_RP(tree, right)); } } /* ItemCheck() */
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; }
/* allocate an object in generation 0 */ void *ggggc_mallocGen0(struct GGGGC_Descriptor *descriptor, /* the object to allocate */ int force /* allocate a new pool instead of collecting, if necessary */ ) { struct GGGGC_Pool *pool; struct GGGGC_Header *ret; retry: /* get our allocation pool */ if (ggggc_pool0) { pool = ggggc_pool0; } else { ggggc_gen0 = ggggc_pool0 = pool = newPool(0, 1); } /* do we have enough space? */ if (pool->end - pool->free >= descriptor->size) { /* good, allocate here */ ret = (struct GGGGC_Header *) pool->free; pool->free += descriptor->size; /* set its descriptor (no need for write barrier, as this is generation 0) */ ret->descriptor__ptr = descriptor; #ifdef GGGGC_DEBUG_MEMORY_CORRUPTION ret->ggggc_memoryCorruptionCheck = GGGGC_MEMORY_CORRUPTION_VAL; #endif /* and clear the rest (necessary since this goes to the untrusted mutator) */ memset(ret + 1, 0, descriptor->size * sizeof(ggc_size_t) - sizeof(struct GGGGC_Header)); } else if (pool->next) { ggggc_pool0 = pool = pool->next; goto retry; } else if (force) { /* get a new pool */ pool->next = newPool(0, 1); ggggc_pool0 = pool = pool->next; goto retry; } else { /* need to collect, which means we need to actually be a GC-safe function */ GGC_PUSH_1(descriptor); ggggc_collect0(0); GGC_POP(); pool = ggggc_pool0; goto retry; } return ret; }
int main(void) { LLL mylll = NULL; printf("calling main\n"); GGC_PUSH_1(mylll); mylll = buildLLL(MAX); #if 0 dumpLLL(mylll); #endif testLLL(mylll); return 0; }
/* allocate a descriptor from a descriptor slot */ struct GGGGC_Descriptor *ggggc_allocateDescriptorSlot(struct GGGGC_DescriptorSlot *slot) { if (slot->descriptor) return slot->descriptor; if (slot->descriptor) { return slot->descriptor; } slot->descriptor = ggggc_allocateDescriptor(slot->size, slot->pointers); /* make the slot descriptor a root */ GGC_PUSH_1(slot->descriptor); GGC_GLOBALIZE(); return slot->descriptor; }
void testLLL(LLL lll) { unsigned char *counted; GGC_PUSH_1(lll); counted = (unsigned char *) calloc(MAX, sizeof(unsigned char)); while (lll) { counted[GGC_RD(lll, val)]++; if (counted[GGC_RD(lll, val)] > 1) { fprintf(stderr, "ERROR! Encountered %d twice!\n", GGC_RD(lll, val)); exit(1); } lll = GGC_RP(lll, next); } return; }
/* allocate a descriptor from a descriptor slot */ struct GGGGC_Descriptor *ggggc_allocateDescriptorSlot(struct GGGGC_DescriptorSlot *slot) { if (slot->descriptor) return slot->descriptor; ggc_mutex_lock_raw(&slot->lock); if (slot->descriptor) { ggc_mutex_unlock(&slot->lock); return slot->descriptor; } slot->descriptor = ggggc_allocateDescriptor(slot->size, slot->pointers); /* make the slot descriptor a root */ GGC_PUSH_1(slot->descriptor); GGC_GLOBALIZE(); ggc_mutex_unlock(&slot->lock); return slot->descriptor; }
/* 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 */ ggc_mutex_lock_raw(&ggggc_descriptorDescriptorsLock); if (ggggc_descriptorDescriptors[size]) { ggc_mutex_unlock(&ggggc_descriptorDescriptorsLock); return ggggc_descriptorDescriptors[size]; } /* now make a temporary descriptor to describe the descriptor descriptor */ tmpDescriptor.header.descriptor__ptr = NULL; tmpDescriptor.size = ddSize; tmpDescriptor.pointers[0] = GGGGC_DESCRIPTOR_DESCRIPTION; /* allocate the descriptor descriptor */ ret = (struct GGGGC_Descriptor *) ggggc_mallocGen0(&tmpDescriptor, 1); /* make it correct */ ret->size = size; ret->pointers[0] = GGGGC_DESCRIPTOR_DESCRIPTION; /* put it in the list */ ggggc_descriptorDescriptors[size] = ret; ggc_mutex_unlock(&ggggc_descriptorDescriptorsLock); GGC_PUSH_1(ggggc_descriptorDescriptors[size]); GGC_GLOBALIZE(); /* and give it a proper descriptor */ ret->header.descriptor__ptr = ggggc_allocateDescriptorDescriptor(ddSize); return ret; }
void SymbolTable::setDescriptorPointer() { ggc_size_t size = 1; ggc_size_t pointers = 0; std::map<std::string, LSRValue>::iterator iter = symMap.begin(); while (iter != symMap.end()) { size++; if (!iter->second.isInt()) { // Anything but an int is a pointer in this language !!!!!!! pointers = pointers | 1<<size; } iter++; } if (pointers) { // If pointers is no longer 0 we set at least one pointer, // need to set the lowest order bit to 1 to denote that we have pointers. pointers = pointers | 1; } descriptorPointer = NULL; GGC_PUSH_1(descriptorPointer); GGC_GLOBALIZE(); descriptorPointer = (void *) ggggc_allocateDescriptor(size,pointers); }
/* general purpose thread wrapper */ static void *ggggcThreadWrapper(void *arg) { ThreadInfo ti = (ThreadInfo) arg; GGC_PUSH_1(ti); GGC_RD(ti, func)(GGC_RP(ti, arg)); /* now remove this thread from the thread barrier */ while (ggc_mutex_trylock(&ggggc_worldBarrierLock) != 0) GGC_YIELD(); ggggc_threadCount--; if (ggggc_threadCount > 0) { ggc_barrier_destroy(&ggggc_worldBarrier); ggc_barrier_init(&ggggc_worldBarrier, ggggc_threadCount); } ggc_mutex_unlock(&ggggc_worldBarrierLock); /* and give back its pools */ ggggc_freeGeneration(ggggc_gen0); return 0; }