int PoolExercise(int verbose, struct cfg *cfg, char *args[]) { void *data; int rate, i; struct linkedlist *l; struct pool *p; cfg = NULL; args[0] = NULL; if ((p = pool_new(EXERCISE_SM_COUNT, (new_fn)allocator_alloc, allocator_free, NULL, NULL, BUFFER_SIZE_SM, 0, NULL)) == NULL || (l = linkedlist_new(0, NULL)) == NULL) { PMNO(errno); return 1; } rate = EXERCISE_R0; for (i = 0; i < EXERCISE_SM_COUNT; i++) { if (i == EXERCISE_SM_P1) { rate = EXERCISE_R1; } else if (i == EXERCISE_SM_P2) { rate = EXERCISE_R2; } else if (i == EXERCISE_SM_P3) { rate = EXERCISE_R3; } if (rand() % 10 < rate) { if (pool_size(p) == EXERCISE_SM_COUNT && pool_unused(p) == 0) { continue; } else if ((data = pool_get(p)) == NULL) { AMSG(""); return -1; } else if (linkedlist_add(l, data) == -1) { AMSG("%04d %p s=%d,u=%d\n", i, data, pool_size(p), pool_unused(p)); return -1; } tcase_printf(verbose, "%04d get %p s=%d,u=%d\n", i, data, pool_size(p), pool_unused(p)); } else if ((data = linkedlist_remove(l, 0))) { if (data == NULL || pool_release(p, data) == -1) { AMSG("%04d %p s=%d,u=%d\n", i, data, pool_size(p), pool_unused(p)); return -1; } tcase_printf(verbose, "%04d rel %p s=%d,u=%d\n", i, data, pool_size(p), pool_unused(p)); } else { tcase_printf(verbose, "%04d nothing to release\n", i); } } linkedlist_del(l, NULL, NULL); pool_del(p); return 0; }
static void add_block(int index) { header *h = find_block(pool_block(index), pool_size(index)); insert(block_pool[index], h); pool_total += pool_block(index); free_ptr[index] = h->h_memory; free_count[index] = pool_count(index); }
void* pool_alloc(size_t index) { void* p = pool_get(index); #ifdef USE_VALGRIND VALGRIND_MALLOCLIKE_BLOCK(p, pool_size(index), 0, 0); #endif return p; }
OpenMPexec( const int poolRank , const int scratch_exec_size , const int scratch_reduce_size , const int scratch_thread_size ) : m_pool_rank( poolRank ) , m_pool_rank_rev( pool_size() - ( poolRank + 1 ) ) , m_scratch_exec_end( scratch_exec_size ) , m_scratch_reduce_end( m_scratch_exec_end + scratch_reduce_size ) , m_scratch_thread_end( m_scratch_reduce_end + scratch_thread_size ) , m_barrier_state(0) {}
/* redirect -- translate pointer into new space */ static void redirect(uchar **p) { uchar *q, *r, *s; header *h; int index; q = *p; /* q is the old pointer value */ if (q == NULL) return; h = get_header(q); if (h == NULL) return; /* Not in the managed heap */ ASSERT(h->h_objsize > 0); if (h->h_objsize <= MAX_SMALL_BYTES) { /* A small object */ index = pool_map(h->h_objsize); ASSERT(pool_size(index) == h->h_objsize); r = h->h_memory + round_down(q - h->h_memory, h->h_objsize); /* r is the start of the object containing q */ if (get_word(r, 0) == BROKEN_HEART) s = (uchar *) get_word(r, 1); else { /* Evacuate object at r */ if (free_count[index] == 0) add_block(index); s = free_ptr[index]; memcpy(s, r, pool_size(index)); free_ptr[index] += pool_size(index); free_count[index]--; get_word(r, 0) = BROKEN_HEART; get_word(r, 1) = (word) s; } /* s is the new location for the object r */ *p = s + (q - r); } else if (h->h_epoch < gencount) { /* A big block, not already moved to the new semispace */ unlink(h); insert(block_pool[n_sizes], h); h->h_epoch = gencount; } }
void *gc_alloc(value *desc, unsigned size, value *sp) { unsigned alloc_size; word *p = NULL; header *h; if (debug['z']) gc_collect(sp); size = round_up(size+4, BYTES_PER_WORD); if (size <= MAX_SMALL_BYTES) { /* Try to allocate from the appropriate pool */ unsigned index = pool_map(size); alloc_size = pool_size(index); ASSERT(alloc_size >= size); if (free_count[index] == 0) { while (pool_total + pool_block(index) > heap_size && free_count[index] == 0) scavenge(sp, pool_block(index)); if (free_count[index] == 0) add_block(index); } p = (word *) free_ptr[index]; free_ptr[index] += alloc_size; free_count[index]--; } else { /* Allocate whole pages */ alloc_size = round_up(size, GC_PAGESIZE); while (pool_total + alloc_size > heap_size) scavenge(sp, alloc_size); h = find_block(alloc_size, alloc_size); insert(block_pool[n_sizes], h); pool_total += alloc_size; p = (word *) h->h_memory; } alloc_since_gc += alloc_size; DEBUG_PRINT('c', ("[Alloc %d %p]", size, p)); *p = (word) desc; return p+1; }
char* allocate(std::size_t length) { std::size_t full_length(length + 1); if (full_length > std::size_t(end_m - next_m)) { std::size_t pool_size((std::max)(pool_size_m, full_length)); pool_m.push_back(static_cast<char*>(::operator new(pool_size))); next_m = pool_m.back(); end_m = next_m + pool_size; } char* result(next_m); next_m += length; *next_m++ = '\0'; return result; }
void* pool_alloc(size_t index) { #ifdef USE_VALGRIND VALGRIND_DISABLE_ERROR_REPORTING; #endif pool_local_t* pool = pool_local; void* p = pool_get(pool, index); TRACK_ALLOC(p, POOL_MIN << index); #ifdef USE_VALGRIND VALGRIND_ENABLE_ERROR_REPORTING; VALGRIND_MALLOCLIKE_BLOCK(p, pool_size(index), 0, 0); #endif return p; }