Exemplo n.º 1
0
/*
** Test Arena allocation.
*/
static void ArenaAllocate( void )
{
    PLArenaPool ap;
    void    *ptr;
	PRInt32	i;

    PL_InitArenaPool( &ap, "AllocArena", 2048, sizeof(double));
    PR_LOG( tLM, PR_LOG_DEBUG, ("AA, InitPool -- Pool: %p. first: %p, current: %p, size: %d", 
        &ap, ap.first, ap.current, ap.arenasize  ));

	for( i = 0; i < 150; i++ )
	{
		PL_ARENA_ALLOCATE( ptr, &ap, 512 );
        PR_LOG( tLM, PR_LOG_DEBUG,("AA, after alloc -- Pool: %p. first: %p, current: %p, size: %d", 
               &ap, ap.first, ap.current, ap.arenasize  ));
		PR_LOG( tLM, PR_LOG_DEBUG,(
		    "AA -- Pool: %p. alloc: %p ", &ap, ptr ));
	}

    PL_FreeArenaPool( &ap );

	for( i = 0; i < 221; i++ )
	{
		PL_ARENA_ALLOCATE( ptr, &ap, 512 );
        PR_LOG( tLM, PR_LOG_DEBUG,("AA, after alloc -- Pool: %p. first: %p, current: %p, size: %d", 
               &ap, ap.first, ap.current, ap.arenasize  ));
		PR_LOG( tLM, PR_LOG_DEBUG,(
		    "AA -- Pool: %p. alloc: %p ", &ap, ptr ));
	}

    PL_FreeArenaPool( &ap );
    
    return;
} /* end ArenaGrow() */
Exemplo n.º 2
0
/*
 * If zero is true, zeroize the arena memory before freeing it.
 */
void
PORT_FreeArena(PLArenaPool *arena, PRBool zero)
{
    PORTArenaPool *pool = (PORTArenaPool *)arena;
    PRLock *lock = (PRLock *)0;
    size_t len = sizeof *arena;

    if (!pool)
        return;
    if (ARENAPOOL_MAGIC == pool->magic) {
        len = sizeof *pool;
        lock = pool->lock;
        PZ_Lock(lock);
    }
    if (zero) {
        PL_ClearArenaPool(arena, 0);
    }
    (void)PR_CallOnce(&setupUseFreeListOnce, &SetupUseFreeList);
    if (useFreeList) {
        PL_FreeArenaPool(arena);
    } else {
        PL_FinishArenaPool(arena);
    }
    PORT_ZFree(arena, len);
    if (lock) {
        PZ_Unlock(lock);
        PZ_DestroyLock(lock);
    }
}
Exemplo n.º 3
0
/*
 * If zero is true, zeroize the arena memory before freeing it.
 */
void
PORT_FreeArena(PLArenaPool *arena, PRBool zero)
{
    PORTArenaPool *pool = (PORTArenaPool *)arena;
    PRLock *       lock = (PRLock *)0;
    size_t         len  = sizeof *arena;
    static PRBool  checkedEnv = PR_FALSE;
    static PRBool  doFreeArenaPool = PR_FALSE;

    if (!pool)
    	return;
    if (ARENAPOOL_MAGIC == pool->magic ) {
	len  = sizeof *pool;
	lock = pool->lock;
	PZ_Lock(lock);
    }
    if (!checkedEnv) {
	/* no need for thread protection here */
	doFreeArenaPool = (PR_GetEnv("NSS_DISABLE_ARENA_FREE_LIST") == NULL);
	checkedEnv = PR_TRUE;
    }
    if (zero) {
	PL_ClearArenaPool(arena, 0);
    }
    if (doFreeArenaPool) {
	PL_FreeArenaPool(arena);
    } else {
	PL_FinishArenaPool(arena);
    }
    PORT_ZFree(arena, len);
    if (lock) {
	PZ_Unlock(lock);
	PZ_DestroyLock(lock);
    }
}
Exemplo n.º 4
0
int main()
{
    while (___sl_get_nondet_int()) {
        PLArenaPool pool;

        while (___sl_get_nondet_int()) {
            // initialize arena pool
            PL_InitArenaPool(&pool, "cool pool", 0x1000, 0x10);

            torture_arena(&pool);
            ___sl_plot("01-torture_arena");

            PL_FreeArenaPool(&pool);
            ___sl_plot("02-PL_FreeArenaPool");

            PL_FinishArenaPool(&pool);
            ___sl_plot("03-PL_FinishArenaPool");
        }

        ___sl_plot("04-done");

        PL_ArenaFinish();
        ___sl_plot("05-PL_ArenaFinish");
    }

    return 0;
}
int main()
{
    PLArenaPool pool;
    PL_InitArenaPool(&pool, "cool pool", 0x1000, 0x10);
    ___sl_plot("PL_InitArenaPool");

    // this should be OK
    PL_FreeArenaPool(&pool);
    ___sl_plot("PL_FreeArenaPool-01");
    PL_FreeArenaPool(&pool);
    ___sl_plot("PL_FreeArenaPool-02");
    PL_FinishArenaPool(&pool);
    ___sl_plot("PL_FinishArenaPool-00");

    PL_ArenaFinish();
    return 0;
}
void torture_arena(PLArenaPool *pool)
{
    while (___sl_get_nondet_int()) {
        PL_ArenaAllocate(pool, 0x100);

        while (___sl_get_nondet_int())
            PL_FreeArenaPool(pool);
    }
}
Exemplo n.º 7
0
void
PORT_DestroyCheapArena(PORTCheapArenaPool *pool)
{
    (void)PR_CallOnce(&setupUseFreeListOnce, &SetupUseFreeList);
    if (useFreeList) {
        PL_FreeArenaPool(&pool->arena);
    } else {
        PL_FinishArenaPool(&pool->arena);
    }
}
Exemplo n.º 8
0
nsDisplayListBuilder::~nsDisplayListBuilder() {
  NS_ASSERTION(mFramesMarkedForDisplay.Length() == 0,
               "All frames should have been unmarked");
  NS_ASSERTION(mPresShellStates.Length() == 0,
               "All presshells should have been exited");
  NS_ASSERTION(!mCurrentTableItem, "No table item should be active");

  PL_FreeArenaPool(&mPool);
  PL_FinishArenaPool(&mPool);
}
int main()
{
    // initialize arena pool
    PLArenaPool pool;
    PL_InitArenaPool(&pool, "cool pool", 0x1000, 0x10);

    // trigger allocation of one arena
    void *ptr1 = PL_ArenaAllocate(&pool, 0x100);

    // attempt to reuse the existing arena
    void *ptr2 = PL_ArenaAllocate(&pool, 0x100);

    // free the arena pool twice
    PL_FreeArenaPool(&pool);
    PL_FreeArenaPool(&pool);
    ___sl_plot("01-PL_FreeArenaPool");

    ptr1 = PL_ArenaAllocate(&pool, 0x100);
    ptr2 = PL_ArenaAllocate(&pool, 0x100);
    ___sl_plot("02-PL_ArenaAllocate");

    // free the arena pool
    PL_FreeArenaPool(&pool);
    ___sl_plot("04-PL_FreeArenaPool", &ptr1, &ptr2);

    PL_ArenaFinish();
    ___sl_plot("05-PL_ArenaFinish");

    // XXX: this is misuse of the NSPR API
    void *ptr0 = PL_ArenaAllocate(&pool, 0x100);
    ___sl_plot("06-PL_ArenaAllocate");

    // free the arena pool
    PL_FreeArenaPool(&pool);
    ___sl_plot("07-PL_FreeArenaPool");

    PL_ArenaFinish();
    ___sl_plot("08-PL_ArenaFinish");

    return 0;
}
Exemplo n.º 10
0
/*
 * If zero is true, zeroize the arena memory before freeing it.
 */
void
PORT_FreeArena(PLArenaPool *arena, PRBool zero)
{
    PORTArenaPool *pool = (PORTArenaPool *)arena;
    PRLock *       lock = (PRLock *)0;
    size_t         len  = sizeof *arena;
    extern const PRVersionDescription * libVersionPoint(void);
    static const PRVersionDescription * pvd;
    static PRBool  doFreeArenaPool = PR_FALSE;

    if (ARENAPOOL_MAGIC == pool->magic ) {
	len  = sizeof *pool;
	lock = pool->lock;
	PZ_Lock(lock);
    }
    if (!pvd) {
	/* Each of NSPR's DLLs has a function libVersionPoint().
	** We could do a lot of extra work to be sure we're calling the
	** one in the DLL that holds PR_FreeArenaPool, but instead we
	** rely on the fact that ALL NSPR DLLs in the same directory
	** must be from the same release, and we call which ever one we get. 
	*/
	/* no need for thread protection here */
	pvd = libVersionPoint();
	if ((pvd->vMajor > 4) || 
	    (pvd->vMajor == 4 && pvd->vMinor > 1) ||
	    (pvd->vMajor == 4 && pvd->vMinor == 1 && pvd->vPatch >= 1)) {
	    const char *ev = PR_GetEnv("NSS_DISABLE_ARENA_FREE_LIST");
	    if (!ev) doFreeArenaPool = PR_TRUE;
	}
    }
    if (zero) {
	PLArena *a;
	for (a = arena->first.next; a; a = a->next) {
	    PR_ASSERT(a->base <= a->avail && a->avail <= a->limit);
	    memset((void *)a->base, 0, a->avail - a->base);
	}
    }
    if (doFreeArenaPool) {
	PL_FreeArenaPool(arena);
    } else {
	PL_FinishArenaPool(arena);
    }
    PORT_ZFree(arena, len);
    if (lock) {
	PZ_Unlock(lock);
	PZ_DestroyLock(lock);
    }
}
Exemplo n.º 11
0
void torture_arena(PLArenaPool *pool)
{
    size_t size = ___sl_get_nondet_int();
    if (size < 0x80)
        abort();
    if (0x81 < size)
        abort();

    size *= 0x10;

    while (___sl_get_nondet_int()) {
        PL_ArenaAllocate(pool, size);

        while (___sl_get_nondet_int())
            PL_FreeArenaPool(pool);
    }
}
void
nsStringBundleService::flushBundleCache()
{
  // release all bundles in the cache
  mBundleMap.Reset();
  
  PRCList *current = PR_LIST_HEAD(&mBundleCache);
  while (current != &mBundleCache) {
    bundleCacheEntry_t *cacheEntry = (bundleCacheEntry_t*)current;

    recycleEntry(cacheEntry);
    PRCList *oldItem = current;
    current = PR_NEXT_LINK(current);
    
    // will be freed in PL_FreeArenaPool
    PR_REMOVE_LINK(oldItem);
  }
  PL_FreeArenaPool(&mCacheEntryPool);
}
Exemplo n.º 13
0
int main()
{
    // initialize arena pool
    PLArenaPool pool;
    PL_InitArenaPool(&pool, "cool pool", 0x1000, 0x10);

    // trigger allocation of one arena
    void *ptr = PL_ArenaAllocate(&pool, 0x100);
    __VERIFIER_plot("01-PL_ArenaAllocate", &ptr);

    // free the arena pool
    PL_FreeArenaPool(&pool);
    __VERIFIER_plot("02-PL_FreeArenaPool");

    PL_ArenaFinish();
    __VERIFIER_plot("03-PL_ArenaFinish");

    return 0;
}
Exemplo n.º 14
0
void torture_arena(PLArenaPool *pool)
{
    while (___sl_get_nondet_int()) {
        ssize_t size = ___sl_get_nondet_int();
        if (size < sizeof(double))
            abort();
        if (0x1000 < size)
            abort();

        size &= ~(sizeof(double) - 1);

        ___sl_plot("01-torture_arena", &pool, &size, &arena_freelist);

        PL_ArenaAllocate(pool, size);

        while (___sl_get_nondet_int())
            PL_FreeArenaPool(pool);
    }
}
Exemplo n.º 15
0
int main()
{
    while (___sl_get_nondet_int()) {
        PLArenaPool pool;

        while (___sl_get_nondet_int()) {
            // initialize arena pool
            PL_InitArenaPool(&pool, "cool pool", 0x1000, sizeof(double));

            torture_arena(&pool);

            PL_FreeArenaPool(&pool);
            PL_FinishArenaPool(&pool);
        }

        PL_ArenaFinish();
    }

    return 0;
}
Exemplo n.º 16
0
/*
** StressThread()
** A bunch of these beat on individual arenas
** This tests the free_list protection.
**
*/
static void PR_CALLBACK StressThread( void *arg )
{
    PLArenaPool ap;
    PRIntn i;
    PRIntn sz;
    void *ptr;
    PRThread *tp = PR_GetCurrentThread();

    PR_LOG( tLM, PR_LOG_DEBUG, ("Stress Thread %p started\n", PR_GetCurrentThread()));
    PL_InitArenaPool( &ap, "TheArena", RandSize( poolMin, poolMax), sizeof(double));

    for ( i = 0; i < stressIterations; i++ )
    {
        PRIntn allocated = 0;

        while ( allocated < maxAlloc )
        {
            sz = RandSize( arenaMin, arenaMax );
            PL_ARENA_ALLOCATE( ptr, &ap, sz );
            if ( ptr == NULL )
            {
                PR_LOG( tLM, PR_LOG_ERROR, ("ARENA_ALLOCATE() returned NULL\n\tAllocated: %d\n", allocated));
                break;
            }
            allocated += sz;
        }
        PR_LOG( tLM, PR_LOG_DEBUG, ("Stress thread %p finished one iteration\n", tp));
        PL_FreeArenaPool( &ap );
    }
    PR_LOG( tLM, PR_LOG_DEBUG, ("Stress thread %p finished all iteration\n", tp));
    PL_FinishArenaPool( &ap );
    PR_LOG( tLM, PR_LOG_DEBUG, ("Stress thread %p after FinishArenaPool()\n", tp));

    /* That's all folks! let's quit */
    PR_EnterMonitor(tMon);
    threadCount--;
    PR_Notify(tMon);
    PR_ExitMonitor(tMon);    
    return;
}    
Exemplo n.º 17
0
/*
** Test arena Mark and Release.
*/
static void MarkAndRelease( void )
{
    PLArenaPool ap;
    void    *ptr = NULL;
    void    *mark0, *mark1;
    PRIntn  i;

    PL_InitArenaPool( &ap, "TheArena", 4096, sizeof(double));
    mark0 = PL_ARENA_MARK( &ap );
    PR_LOG( tLM, PR_LOG_DEBUG,
        ("mark0. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p, m0: %p", 
            &ap, ap.first.next, ap.current, ap.arenasize, ptr, mark0 ));

	for( i = 0; i < 201; i++ )
	{
		PL_ARENA_ALLOCATE( ptr, &ap, 512 );
        PR_LOG( tLM, PR_LOG_DEBUG,
            ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
                &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
	}

    mark1 = PL_ARENA_MARK( &ap );
    PR_LOG( tLM, PR_LOG_DEBUG,
        ("mark1. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p, m1: %p", 
            &ap, ap.first.next, ap.current, ap.arenasize, ptr, mark1 ));


	for( i = 0; i < 225; i++ )
	{
		PL_ARENA_ALLOCATE( ptr, &ap, 512 );
        PR_LOG( tLM, PR_LOG_DEBUG,
            ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
                &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
	}

    PL_ARENA_RELEASE( &ap, mark1 );
    PR_LOG( tLM, PR_LOG_DEBUG,
        ("Release-1: %p -- Pool: %p. first: %p, current: %p, size: %d", 
               mark1, &ap, ap.first, ap.current, ap.arenasize  ));

	for( i = 0; i < 20; i++ )
	{
		PL_ARENA_ALLOCATE( ptr, &ap, 512 );
        PR_LOG( tLM, PR_LOG_DEBUG,
            ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
                &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
	}

    PL_ARENA_RELEASE( &ap, mark1 );
    PR_LOG( tLM, PR_LOG_DEBUG,
        ("Release-1. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
            &ap, ap.first.next, ap.current, ap.arenasize, ptr ));

    PL_ARENA_RELEASE( &ap, mark0 );
    PR_LOG( tLM, PR_LOG_DEBUG,
        ("Release-0. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
            &ap, ap.first.next, ap.current, ap.arenasize, ptr ));

    PL_FreeArenaPool( &ap );
    PR_LOG( tLM, PR_LOG_DEBUG,
        ("Free. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
            &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
    
    PL_FinishArenaPool( &ap );
    PR_LOG( tLM, PR_LOG_DEBUG,
        ("Finish. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
            &ap, ap.first.next, ap.current, ap.arenasize, ptr ));

    return;
} /* end MarkAndRelease() */