Example #1
0
Address PoolAllocator::allocate(Size *size)
{
    Size index, nPools = 1;
    MemoryPool *pool = ZERO;
    
    /* Find the correct pool size. */
    for (index = POOL_MIN_POWER; index < POOL_MAX_POWER; index++)
        if (*size <= (Size) 1 << (index + 1)) break;

    /* Do we need to allocate an initial pool? */
    if (!pools[index] && parent)
        pool = pools[index] = newPool(index, POOL_MIN_COUNT(*size));

    /* Search for pool with enough memory. */
    else {
        /* Loop current pools. */
        for (pool = pools[index]; pool; pool = pool->next, nPools++) {
            /* At least one block still free? */
            if (pool->free)
                break;

            /* If no pool has free space anymore, allocate another. */
            if (!pool->next) {
                pool = newPool(index, POOL_MIN_COUNT(*size) * nPools);
                break;
            }
        }
    }
    
    /* Attempt to allocate. */
    return pool ? pool->allocate() : ZERO;
}
Example #2
0
/* allocate an object in the requested generation > 0 */
void *ggggc_mallocGen1(struct GGGGC_Descriptor *descriptor, /* descriptor for object */
                       unsigned char gen, /* generation to allocate in */
                       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_pools[gen]) {
        pool = ggggc_pools[gen];
    } else {
        ggggc_gens[gen] = ggggc_pools[gen] = pool = newPool(gen, 1);
    }

    /* do we have enough space? */
    if (pool->end - pool->free >= descriptor->size) {
        ggc_size_t retCard, freeCard;

        /* good, allocate here */
        ret = (struct GGGGC_Header *) pool->free;
        pool->free += descriptor->size;
        retCard = GGGGC_CARD_OF(ret);
        freeCard = GGGGC_CARD_OF(pool->free);

        /* if we passed a card, mark the first object */
        if (retCard != freeCard && pool->free < pool->end)
            pool->firstObject[freeCard] =
                ((ggc_size_t) pool->free & GGGGC_CARD_INNER_MASK) / sizeof(ggc_size_t);

        /* and clear the next descriptor so that it's clear there's no object
         * there (yet) */
        if (pool->free < pool->end) *pool->free = 0;

    } else if (pool->next) {
        ggggc_pools[gen] = pool = pool->next;
        goto retry;

    } else if (force) {
        /* get a new pool */
        pool->next = newPool(gen, 1);
        ggggc_pools[gen] = pool = pool->next;
        goto retry;

    } else {
        /* failed to allocate */
        return NULL;

    }

    return ret;
}
Example #3
0
/* 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;
}
Example #4
0
static	pANTLR3_COMMON_TOKEN    
newPoolToken	    (pANTLR3_TOKEN_FACTORY factory)
{
    pANTLR3_COMMON_TOKEN    token;

    /* See if we need a new token pool before allocating a new
     * one
     */
    if	(factory->nextToken >= ANTLR3_FACTORY_POOL_SIZE)
    {
	/* We ran out of tokens in the current pool, so we need a new pool
	 */
	newPool(factory);
    }

    /* Assuming everything went well (we are trying for performance here so doing minimal
     * error checking. Then we can work out what the pointer is to the next token.
     */
    token   = factory->pools[factory->thisPool] + factory->nextToken;
    factory->nextToken++;

    /* We have our token pointer now, so we can initialize it to the predefined model.
     */
    ANTLR3_MEMMOVE((void *)token, (const void *)&factory->unTruc, (ANTLR3_UINT64)sizeof(ANTLR3_COMMON_TOKEN));

    /* And we are done
     */
    return  token;
}
Example #5
0
/* heuristically expand a generation if it has too many survivors */
void ggggc_expandGeneration(struct GGGGC_Pool *pool)
{
    ggc_size_t space, survivors, poolCt;

    if (!pool) return;

    /* first figure out how much space was used */
    space = 0;
    survivors = 0;
    poolCt = 0;
    while (1) {
        space += pool->end - pool->start;
        survivors += pool->survivors;
        pool->survivors = 0;
        poolCt++;
        if (!pool->next) break;
        pool = pool->next;
    }

    /* now decide if it's too much */
    if (survivors > space/2) {
        /* allocate more */
        ggc_size_t i;
        for (i = 0; i < poolCt; i++) {
            pool->next = newPool(0);
            pool = pool->next;
            if (!pool) break;
        }
    }
}
Example #6
0
ANTLR3_API pANTLR3_ARBORETUM
antlr3ArboretumNew(pANTLR3_STRING_FACTORY strFactory)
{
    pANTLR3_ARBORETUM   factory;

    // Allocate memory
    //
    factory	= (pANTLR3_ARBORETUM) ANTLR3_MALLOC((size_t)sizeof(ANTLR3_ARBORETUM));
    if	(factory == NULL)
    {
		return	NULL;
    }

	// Install a vector factory to create, track and free() any child
	// node lists.
	//
	factory->vFactory					= antlr3VectorFactoryNew(0);
	if	(factory->vFactory == NULL)
	{
		free(factory);
		return	NULL;
	}

    // We also keep a reclaim stack, so that any Nil nodes that are
    // orphaned are not just left in the pool but are reused, other wise
    // we create 6 times as many nilNodes as ordinary nodes and use loads of
    // memory. Perhaps at some point, the analysis phase will generate better
    // code and we won't need to do this here.
    //
    factory->nilStack       =  antlr3StackNew(0);

    // Install factory API
    //
    factory->newTree	    =  newPoolTree;
    factory->newFromTree    =  newFromTree;
    factory->newFromToken   =  newFromToken;
    factory->close			=  factoryClose;

    // Allocate the initial pool
    //
    factory->thisPool	= -1;
    factory->pools		= NULL;
    newPool(factory);

    // Factory space is good, we now want to initialize our cheating token
    // which one it is initialized is the model for all tokens we manufacture
    //
    antlr3SetCTAPI(&factory->unTruc);

    // Set some initial variables for future copying, including a string factory
    // that we can use later for converting trees to strings.
    //
	factory->unTruc.factory				= factory;
    factory->unTruc.baseTree.strFactory	= strFactory;

    return  factory;

}
static  void
factoryReset        (pANTLR3_TOKEN_FACTORY factory)
{
    // Just start again with pool #0 when we are
    // called.
    //
    factory->thisPool   = -1;
    newPool(factory);
}
Example #8
0
static	pANTLR3_BASE_TREE    
newPoolTree	    (pANTLR3_ARBORETUM factory)
{
	pANTLR3_COMMON_TREE    tree;

    // If we have anything on the re claim stack, reuse that sucker first
    //
    tree = (pANTLR3_COMMON_TREE) factory->nilStack->peek(factory->nilStack);

    if  (tree != NULL)
    {
        // Cool we got something we could reuse, it will have been cleaned up by
        // whatever put it back on the stack (for instance if it had a child vector,
        // that will have been cleared to hold zero entries and that vector will get reused too.
        // It is the basetree pointer that is placed on the stack of course
        //
        factory->nilStack->pop(factory->nilStack);
        return (pANTLR3_BASE_TREE)tree;

    }
	// See if we need a new tree pool before allocating a new tree
	//
	if	(factory->nextTree >= ANTLR3_FACTORY_POOL_SIZE)
	{
		// We ran out of tokens in the current pool, so we need a new pool
		//
		newPool(factory);
	}

	// Assuming everything went well - we are trying for performance here so doing minimal
	// error checking - then we can work out what the pointer is to the next commontree.
	//
	tree   = factory->pools[factory->thisPool] + factory->nextTree;
	factory->nextTree++;

	// We have our token pointer now, so we can initialize it to the predefined model.
	//
    antlr3SetCTAPI(tree);

    // Set some initial variables for future copying, including a string factory
    // that we can use later for converting trees to strings.
    //
	tree->factory				= factory;
    tree->baseTree.strFactory	= factory->unTruc.baseTree.strFactory;

	// The super points to the common tree so we must override the one used by
	// by the pre-built tree as otherwise we will always poitn to the same initial
	// common tree and we might spend 3 hours trying to debug why - this would never
	// happen to me of course! :-(
	//
	tree->baseTree.super	= tree;

	// And we are done
	//
	return  &(tree->baseTree);
}
auto_ptr<XMLGrammarPool>
SAMLCreateAndPopulateGrammarPool()
{
   auto_ptr<XMLGrammarPool> newPool(new XMLGrammarPoolImpl(XMLPlatformUtils::fgMemoryManager));

   /*
    * Create a parser instance to load all the schemas, so they can
    * be cached for later. In addition to making parsing faster, we
    * need to cache them so that Xerces does not try to download
    * schemas from the web when one is referenced or imported by another
    * schema.
    */
   XercesDOMParser parser(NULL, XMLPlatformUtils::fgMemoryManager,
                          newPool.get());

   gchar *dir = Pref_GetString(gPrefs, VGAUTH_PREF_SAML_SCHEMA_DIR,
                               VGAUTH_PREF_GROUP_NAME_SERVICE, NULL);
   if (NULL == dir) {
#ifdef _WIN32
      /*
       * To make life easier for the Windows installer, assume
       * the schema directory is next to the executable.  Also
       * check in ../ in case we're in a dev environment.
       */
      dir = g_build_filename(gInstallDir, "schemas", NULL);
      if (!(g_file_test(dir, G_FILE_TEST_EXISTS) &&
            g_file_test(dir, G_FILE_TEST_IS_DIR))) {

         gchar *newDir = g_build_filename(gInstallDir, "..", "schemas", NULL);

         Debug("%s: schemas not found in Windows install loc '%s',"
               " trying dev location of '%s'\n", __FUNCTION__, dir, newDir);

         g_free(dir);
         dir = newDir;
      }
#else
      /*
       * XXX -- clean this up to make a better default for Linux.
       */
      dir = g_build_filename(gInstallDir, "..", "schemas", NULL);
#endif
   }
   Log("%s: Using '%s' for SAML schemas\n", __FUNCTION__, dir);
   SAMLGlibString schemaDir(dir);

   for (unsigned int i = 0; i < G_N_ELEMENTS(schemas); i++) {
      if (!SAMLLoadSchema(parser, schemaDir, schemas[i])) {
         return auto_ptr<XMLGrammarPool>(NULL);
      }
   }

   return newPool;
}
Example #10
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*));
}
Example #11
0
ClientPool :: ClientPool (const char *uri, QObject * parent)
   : QObject (parent)
     
{
   std::shared_ptr<mongoc_uri_t> auto_uri (
      mongoc_uri_new(uri), 
      uriDeleter);
   
   auto *pool = mongoc_client_pool_new ( auto_uri.get() );
   std::shared_ptr <mongoc_client_pool_t> newPool (pool, clientPoolDeleter);
   clientPool.swap (newPool);
}
/* 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;
}
ANTLR3_API pANTLR3_TOKEN_FACTORY
antlr3TokenFactoryNew(pANTLR3_INPUT_STREAM input)
{
    pANTLR3_TOKEN_FACTORY   factory;

    /* allocate memory
     */
    factory     = (pANTLR3_TOKEN_FACTORY) ANTLR3_MALLOC((size_t)sizeof(ANTLR3_TOKEN_FACTORY));

    if  (factory == NULL)
    {
        return  NULL;
    }

    /* Install factory API
     */
    factory->newToken       = newPoolToken;
    factory->close          = factoryClose;
    factory->setInputStream = setInputStream;
    factory->reset          = factoryReset;

    /* Allocate the initial pool
     */
    factory->thisPool   = -1;
    factory->pools      = NULL;
    factory->maxPool    = -1;
    newPool(factory);

    /* Factory space is good, we now want to initialize our cheating token
     * which one it is initialized is the model for all tokens we manufacture
     */
    antlr3SetTokenAPI(&factory->unTruc);

    /* Set some initial variables for future copying
     */
    factory->unTruc.factoryMade = ANTLR3_TRUE;

    // Input stream
    //
    setInputStream(factory, input);

    return  factory;

}
//  I am nullyfying the freepoolshead pointer
void *ggggc_malloc(struct GGGGC_Descriptor *descriptor)
{
	//Change this for incrementing the pool list 
	struct FreeObjects *start=freelist , *prev=start,*temp;
	
	struct GGGGC_Pool  *pool;
    if(ggggc_poolList==NULL) // ALLOCATE 10 NEW POOLS IF NO POOL IS ALLOCATED YET
    {
    	pool=ggggc_poolList;
    	for(int i=0;i<10;i++)
    	{
    		pool=newPool(1);
    		pool->next=NULL;
    		pool->survivors = 0;
    		if(ggggc_poolList==NULL)
    		{
				ggggc_poolList=gggggc_curPool=pool;
			}
			pool=pool->next;
		}
	}
	
	struct GGGGC_Header *obj_header=NULL;
	//First check if free space is avaialble in the pool
method_1_ForAllocation:	
	//For the first method of allocation we will traverse all the pools to see if any space is available or not.
	pool=ggggc_curPool;
	while(pool!=NULL) 
	{
		if(pool->end - pool->free >= descriptor->size)
		{
			obj_header = (struct GGGGC_Header *) pool->free;
			pool->free = pool->free + descriptor->size;
			obj_header->descriptor__ptr=descriptor;
			//obj_header->descriptor__ptr->user__ptr=isNotFreeObject;
			return obj_header;
		}
		pool=pool->next;
	}
	else if(freeList)  //Implementing First Fit Criteria with splitting. Free objects also have an object header
static pANTLR3_COMMON_TOKEN
newPoolToken(pANTLR3_TOKEN_FACTORY factory)
{
    pANTLR3_COMMON_TOKEN token;

    /* See if we need a new token pool before allocating a new
     * one
     */
    if (factory->nextToken >= ANTLR3_FACTORY_POOL_SIZE)
    {
        /* We ran out of tokens in the current pool, so we need a new pool
         */
        newPool(factory);
    }

    /* Assuming everything went well (we are trying for performance here so doing minimal
     * error checking. Then we can work out what the pointer is to the next token.
     */
    token = factory->pools[factory->thisPool] + factory->nextToken;
    factory->nextToken++;

    /* We have our token pointer now, so we can initialize it to the predefined model.
     * We only need do this though if the token is not already initialized, we just check
     * an api function pointer for this as they are allocated via calloc.
     */
    if  (token->setStartIndex == NULL)
    {
        antlr3SetTokenAPI(token);

        // It is factory made, and we need to copy the string factory pointer
        //
        token->factoryMade  = ANTLR3_TRUE;
        token->strFactory   = factory->input == NULL ? NULL : factory->input->strFactory;
        token->input        = factory->input;
    }

    /* And we are done
     */
    return token;
}
Example #16
0
static void init() {
  if (triePool == NULL) {
    triePool = newPool(sizeof(TrieRec), 1024);
  }
}
Example #17
0
void *ggggc_mallocOld(struct GGGGC_Descriptor *descriptor){
    struct GGGGC_FreeObj *prevFreeObj = NULL, *curFreeObj = NULL, *splitFreeObj = NULL;
    ggc_size_t *ret = NULL, curFreeObjSize = 0, *curFreeObjEnd = NULL, allocationSizeRounded = 0;
    allocationSizeRounded = roundToTwo(descriptor->size); 
    
    /*
    if((totalOldSpace < 3*totalOldFilled) && totalFilled > totalSurvivors *2){
        ggggc_collect();
    }
    */
    
    //allocate a pool if no pool
    if(!ggggc_oldPoolList){
        ggggc_oldPoolList = newPool(1);
        ggggc_oldPoolList->generation = 2;
        totalOldSpace += ggggc_oldPoolList->end - ggggc_oldPoolList->start;
        ggggc_curOldPool = ggggc_oldPoolList;
    }

    while (ggggc_curOldPool){
        curFreeObj = ggggc_curOldPool -> freelist;
        prevFreeObj = NULL;
        while (curFreeObj){
            curFreeObjEnd = GetfreeObjEnd(curFreeObj);
            curFreeObjSize = curFreeObjEnd - (ggc_size_t*) curFreeObj;
            if(curFreeObjSize >= allocationSizeRounded){
                //free obj has enought space to allocate
                ret = (ggc_size_t*) curFreeObj;
                if(curFreeObjSize >= allocationSizeRounded + 2){
                    //Split
                    splitFreeObj = (struct GGGGC_FreeObj *)((ggc_size_t *) curFreeObj + allocationSizeRounded);
                    splitFreeObj->end_bitSneaky = curFreeObj->end_bitSneaky;
                    splitFreeObj->next = curFreeObj->next;
                    if(prevFreeObj)
                        prevFreeObj->next = splitFreeObj;
                    else if(curFreeObj == ggggc_curOldPool->freelist)
                        ggggc_curOldPool->freelist = splitFreeObj;
                }
                else{
                    if(prevFreeObj)
                        prevFreeObj->next = curFreeObj->next;
                    else if(curFreeObj == ggggc_curOldPool->freelist)
                        ggggc_curOldPool->freelist = curFreeObj->next;
                }
                setToZero(ret, allocationSizeRounded);
                ((struct GGGGC_Header*)ret)->descriptor__ptr = descriptor;
                //totalFilled += allocationSizeRounded;
                return ret;
            }
            prevFreeObj = curFreeObj;
            curFreeObj = curFreeObj -> next;
        }
        if (ggggc_curOldPool->end - ggggc_curOldPool->free >= allocationSizeRounded){
            //allocate using free space 
            ret = (ggc_size_t*)ggggc_curOldPool->free;
            ggggc_curOldPool->free += allocationSizeRounded;
            setToZero(ret, allocationSizeRounded);
            ((struct GGGGC_Header*)ret)->descriptor__ptr = descriptor;   
            //totalFilled += allocationSizeRounded;
            return ret;
        }
        ggggc_curOldPool = ggggc_curOldPool -> next;
    }
    return NULL;
}
Example #18
0
File: code.c Project: fmccabe/cafe
void initCode() {
  MethodClass.clss = specialClass;

  pkgPool = newPool(sizeof(PackageRec), 16);
  packages = NewHash(16, (hashFun) pkHash, (compFun) compPk, (destFun) delPkg);
}