コード例 #1
0
ファイル: PoolAllocator.cpp プロジェクト: Esaud17/AmayaOS
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;
}
コード例 #2
0
void GCMemoryManager::gc_begin(bool recordGCBeginTime, bool recordPreGCUsage,
                               bool recordAccumulatedGCTime) {
  assert(_last_gc_stat != NULL && _current_gc_stat != NULL, "Just checking");
  if (recordAccumulatedGCTime) {
    _accumulated_timer.start();
  }
  // _num_collections now increases in gc_end, to count completed collections
  if (recordGCBeginTime) {
    _current_gc_stat->set_index(_num_collections+1);
    _current_gc_stat->set_start_time(Management::timestamp());
  }

  if (recordPreGCUsage) {
    // Keep memory usage of all memory pools
    for (int i = 0; i < MemoryService::num_memory_pools(); i++) {
      MemoryPool* pool = MemoryService::get_memory_pool(i);
      MemoryUsage usage = pool->get_memory_usage();
      _current_gc_stat->set_before_gc_usage(i, usage);
      HS_DTRACE_PROBE8(hotspot, mem__pool__gc__begin,
        name(), strlen(name()),
        pool->name(), strlen(pool->name()),
        usage.init_size(), usage.used(),
        usage.committed(), usage.max_size());
    }
  }
}
コード例 #3
0
int Path::randomWalk(const Scene *scene, Sampler *sampler,
		int nSteps, int rrStart, ETransportMode mode,
		MemoryPool &pool) {
	/* Determine the relevant edge and vertex to start the random walk */
	PathVertex *curVertex  = m_vertices[m_vertices.size()-1],
	           *predVertex = m_vertices.size() < 2 ? NULL :
	                         m_vertices[m_vertices.size()-2];
	PathEdge *predEdge     = m_edges.empty() ? NULL :
	                         m_edges[m_edges.size()-1];
	Spectrum throughput(1.0f);

	for (int i=0; i<nSteps || nSteps == -1; ++i) {
		PathVertex *succVertex = pool.allocVertex();
		PathEdge *succEdge = pool.allocEdge();

		if (!curVertex->sampleNext(scene, sampler, predVertex, predEdge, succEdge,
				succVertex, mode, rrStart != -1 && i >= rrStart, &throughput)) {
			pool.release(succVertex);
			pool.release(succEdge);
			return i;
		}

		append(succEdge, succVertex);

		predVertex = curVertex;
		curVertex = succVertex;
		predEdge = succEdge;
	}

	return nSteps;
}
コード例 #4
0
ファイル: VirtualMachine.cpp プロジェクト: vbyeh/ECS150-Proj3
TVMStatus VMMemoryPoolAllocate(TVMMemoryPoolID memory, TVMMemorySize size, void **pointer){
	TMachineSignalState sigState;	
	MachineSuspendSignals(&sigState);
	ThreadStore* tStore = ThreadStore::getInstance();

	if((size == 0) || (pointer == NULL)){
		printf("VMMemoryPoolAllocate(): size was zero or pointer was null.\n");
		MachineResumeSignals(&sigState);
		return VM_STATUS_ERROR_INVALID_PARAMETER;
	}

//	printf("VMMemoryPoolAllocate(): looking for pool: %d\n", memory);
	MemoryPool *pool = tStore->findMemoryPoolByID(memory);

	if(pool == NULL){
		printf("VMMemoryPoolAllocate(): pool was null.\n");
		MachineResumeSignals(&sigState);
		return VM_STATUS_ERROR_INVALID_PARAMETER;
	}
	
	uint8_t* newMemory = pool->allocateMemory(size);
//	printf("VMMemoryPoolAllocate(): allocated chunk %d\n", newMemory);

	if(newMemory == NULL){
		printf("VMMemoryPoolAllocate(): new memory allocated was null.\n");
		return VM_STATUS_ERROR_INSUFFICIENT_RESOURCES;
	}

//	printf("VMMemoryPoolAllocate(): Memory allocated successfully!\n");
	*pointer = newMemory;										//if execution gets here, everything is valid and
	MachineResumeSignals(&sigState);				//the memory should be allocated
	return VM_STATUS_SUCCESS;
}
コード例 #5
0
ファイル: VirtualMachine.cpp プロジェクト: vbyeh/ECS150-Proj3
TVMStatus VMMemoryPoolDeallocate(TVMMemoryPoolID memory, void *pointer){
	TMachineSignalState sigState;	
	MachineSuspendSignals(&sigState);
	ThreadStore* tStore = ThreadStore::getInstance();

	if(pointer == NULL){
		printf("VMMemoryPoolDeallocate(): pointer was null.\n");
		return VM_STATUS_ERROR_INVALID_PARAMETER;
	}

	MemoryPool *pool = tStore->findMemoryPoolByID(memory);
	
	if(pool == NULL){
		printf("VMMemoryPoolDeallocate(): pool was null.\n");
		return VM_STATUS_ERROR_INVALID_PARAMETER;
	}

//	printf("VMMemoryPoolDeallocate(): attempting to deallocate chunk %d\n", pointer);

	if(pool->deallocate((uint8_t*)pointer) == false){	//attempts to deallocate the memory specified by pointer
		return VM_STATUS_ERROR_INVALID_PARAMETER;	//returns true on successful deallocation, and false if the
	}//memory pointed to by pointer was not previously allocated in the memory pool

	MachineResumeSignals(&sigState);
	return VM_STATUS_SUCCESS;
}
コード例 #6
0
void Path::release(size_t start, size_t end, MemoryPool &pool) {
	for (size_t i=start; i<end; ++i) {
		pool.release(m_vertices[i]);
		if (i+1 < end)
			pool.release(m_edges[i]);
	}
}
コード例 #7
0
void Path::release(MemoryPool &pool) {
	for (size_t i=0; i<m_vertices.size(); ++i)
		pool.release(m_vertices[i]);
	for (size_t i=0; i<m_edges.size(); ++i)
		pool.release(m_edges[i]);
	m_vertices.clear();
	m_edges.clear();
}
コード例 #8
0
MemoryPool* MemoryService::get_memory_pool(instanceHandle ph) {
  for (int i = 0; i < _pools_list->length(); i++) {
    MemoryPool* pool = _pools_list->at(i);
    if (pool->is_pool(ph)) {
      return pool;
    }
  }
  return NULL;
}
コード例 #9
0
void MemoryService::track_memory_usage() {
  // Track the peak memory usage
  for (int i = 0; i < _pools_list->length(); i++) {
    MemoryPool* pool = _pools_list->at(i);
    pool->record_peak_memory_usage();
  }

  // Detect low memory
  LowMemoryDetector::detect_low_memory();
}
コード例 #10
0
// recompute enabled flag
void LowMemoryDetector::recompute_enabled_for_collected_pools() {
  bool enabled = false;
  int num_memory_pools = MemoryService::num_memory_pools();
  for (int i=0; i<num_memory_pools; i++) {
    MemoryPool* pool = MemoryService::get_memory_pool(i);
    if (pool->is_collected_pool() && is_enabled(pool)) {
      enabled = true;
      break;
    }
  }
  _enabled_for_collected_pools = enabled;
}
コード例 #11
0
//-----------------------------------------------------------------------------
static void testAppendChar()
{
  MemoryPool pool = newMemoryPool();

  StringBuffer s = newStringBuffer(&pool, "A test string");
  s.appendChar(&s, '!');
  assertEquals(string, "A test string!", s.str);
  s.appendChar(&s, '-');
  assertEquals(string, "A test string!-", s.str);

  pool.drain(&pool);
}
コード例 #12
0
void MemoryService::oops_do(OopClosure* f) {
  int i;

  for (i = 0; i < _pools_list->length(); i++) {
    MemoryPool* pool = _pools_list->at(i);
    pool->oops_do(f);
  }
  for (i = 0; i < _managers_list->length(); i++) {
    MemoryManager* mgr = _managers_list->at(i);
    mgr->oops_do(f);
  }
}
コード例 #13
0
ファイル: PoolAllocator.cpp プロジェクト: Esaud17/AmayaOS
void PoolAllocator::release(Address addr)
{
    for (Size i = POOL_MIN_POWER - 1; i < POOL_MAX_POWER; i++) {
        for (MemoryPool *p = pools[i]; p; p = p->next) {
            if (addr < p->addr + (p->count * p->size) &&
                addr >= p->addr)
            {
                p->release(addr);
                return;
            }
        }
    }
}
コード例 #14
0
//-----------------------------------------------------------------------------
static void testAppendString()
{
  MemoryPool pool = newMemoryPool();

  StringBuffer s = newStringBuffer(&pool, "A test string");
  s.append(&s, " - appended value");
  assertEquals(string, "A test string - appended value", s.str);
  s.append(&s, " & another value");
  assertEquals(string, "A test string - appended value & another value", s.str);
  assertTrue(s.size > strlen("A test string - appended value & another value"));

  pool.drain(&pool);
}
コード例 #15
0
int Path::randomWalkFromPixel(const Scene *scene, Sampler *sampler,
		int nSteps, const Point2i &pixelPosition, int rrStart, MemoryPool &pool) {

	PathVertex *v1 = pool.allocVertex(), *v2 = pool.allocVertex();
	PathEdge *e0 = pool.allocEdge(), *e1 = pool.allocEdge();

	/* Use a special sampling routine for the first two sensor vertices so that
	   the resulting subpath passes through the specified pixel position */
	int t = vertex(0)->sampleSensor(scene,
		sampler, pixelPosition, e0, v1, e1, v2);

	if (t < 1) {
		pool.release(e0);
		pool.release(v1);
		return 0;
	}

	append(e0, v1);

	if (t < 2) {
		pool.release(e1);
		pool.release(v2);
		return 1;
	}

	append(e1, v2);

	PathVertex *predVertex = v1, *curVertex = v2;
	PathEdge *predEdge = e1;
	Spectrum throughput(1.0f);

	for (; t<nSteps || nSteps == -1; ++t) {
		PathVertex *succVertex = pool.allocVertex();
		PathEdge *succEdge = pool.allocEdge();

		if (!curVertex->sampleNext(scene, sampler, predVertex, predEdge, succEdge,
				succVertex, ERadiance, rrStart != -1 && t >= rrStart, &throughput)) {
			pool.release(succVertex);
			pool.release(succEdge);
			return t;
		}

		append(succEdge, succVertex);

		predVertex = curVertex;
		curVertex = succVertex;
		predEdge = succEdge;
	}

	return nSteps;
}
コード例 #16
0
//-----------------------------------------------------------------------------
static void testToString()
{
  MemoryPool pool = newMemoryPool();

  StringBuffer sb = newStringBuffer(&pool, "A test strin");
  sb.appendChar(&sb, 'g');
  assertEquals(string, "A test string", sb.str);

  string s = sb.toString(&sb, &pool);
  assertEquals(string, "A test string", s);
  assertEquals(unsigned_int, 13, strlen(s));

  pool.drain(&pool);
}
コード例 #17
0
ファイル: test.cpp プロジェクト: kophy/DSAF
int main() {
    MemoryPool<A, 32> m;
    cout << endl;

    for (int i = 0; i < 5; ++i) {
        cout << "***** " << i << " *****" << endl << endl;
        A *temp = m.allocate();
        cout << "return pointer = " << static_cast<const void *>(temp) << endl;
        m.deallocate(temp);
        cout << endl;
    }

    return 0;
}
コード例 #18
0
ファイル: MemoryManager.cpp プロジェクト: bijoux-plugin/xll
//
// Method that tells the pool owned by the calling thread that
// it is free to reuse all of its memory
//
void MemoryManager::CPP_FreeAllTempMemory()
{
	DWORD dwThreadID;
	MemoryPool* pmp;

	dwThreadID = GetCurrentThreadId(); //the id of the calling thread
	pmp = GetMemoryPool(dwThreadID);

	if (!pmp) //no more room for pools
	{
		return;
	}

	pmp->FreeAllTempMemory();
}
コード例 #19
0
ファイル: MemoryManager.cpp プロジェクト: bijoux-plugin/xll
//
// Destructor.  Because of the way memory pools get copied,
// this function needs to call an additional function to clear
// up the MemoryPool memory - the deconstructor on MemoryPool
// does not actually delete its memory
//
MemoryManager::~MemoryManager(void)
{
	MemoryPool* pmp = m_rgmp;
	int i;

	for (i = 0; i < m_impMax; i++)
	{
		if (pmp->m_rgchMemBlock)
		{
			pmp->ClearPool();
		}
		pmp++;
	}
	delete [] m_rgmp;
}
コード例 #20
0
ファイル: MemoryManager.cpp プロジェクト: bijoux-plugin/xll
//
// Method that will query the correct memory pool of the calling
// thread for a set number of bytes.  Returns 0 if there was a
// failure in getting the memory.
//
LPSTR MemoryManager::CPP_GetTempMemory(int cByte)
{
	DWORD dwThreadID;
	MemoryPool* pmp;

	dwThreadID = GetCurrentThreadId(); //the id of the calling thread
	pmp = GetMemoryPool(dwThreadID);

	if (!pmp) //no more room for pools
	{
		return 0;
	}

	return pmp->GetTempMemory(cByte);
}
コード例 #21
0
ファイル: main.cpp プロジェクト: 23chrischen/mbed
int main (void) {
    Thread thread(send_thread);
    bool result = true;
    int result_counter = 0;

    while (true) {
        osEvent evt = queue.get();
        if (evt.status == osEventMessage) {
            message_t *message = (message_t*)evt.value.p;
            const float expected_voltage = CREATE_VOLTAGE(message->counter);
            const float expected_current = CREATE_CURRENT(message->counter);
            // Check using macros if received values correspond to values sent via queue
            bool expected_values = (expected_voltage == message->voltage) &&
                                   (expected_current == message->current);
            result = result && expected_values;
            const char *result_msg = expected_values ? "OK" : "FAIL";
            printf("%3d %.2fV %.2fA ... [%s]\r\n", message->counter,
                                                   message->voltage,
                                                   message->current,
                                                   result_msg);
            mpool.free(message);
            if (result == false || ++result_counter == QUEUE_SIZE) {
                break;
            }
        }
    }
    notify_completion(result);
    return 0;
}
コード例 #22
0
void MemoryService::gc_begin(bool fullGC) {
  GCMemoryManager* mgr; 
  if (fullGC) {
    mgr = _major_gc_manager;
  } else {
    mgr = _minor_gc_manager;
  }
  assert(mgr->is_gc_memory_manager(), "Sanity check");
  mgr->gc_begin();

  // Track the peak memory usage when GC begins
  for (int i = 0; i < _pools_list->length(); i++) {
    MemoryPool* pool = _pools_list->at(i);
    pool->record_peak_memory_usage();
  }
}
コード例 #23
0
ファイル: VirtualMachine.cpp プロジェクト: vbyeh/ECS150-Proj3
TVMStatus VMMemoryPoolCreate(void *base, TVMMemorySize size, TVMMemoryPoolIDRef memory){
	TMachineSignalState sigState;	
	MachineSuspendSignals(&sigState);
	ThreadStore* tStore = ThreadStore::getInstance();

	if((base == NULL) || (memory == NULL)){
		MachineResumeSignals(&sigState);
		return VM_STATUS_ERROR_INVALID_PARAMETER;
	}

	MemoryPool *pool = new MemoryPool((uint8_t*)base, size);
	*memory = pool->getID();
	tStore->insert(pool);
	MachineResumeSignals(&sigState);
	return VM_STATUS_SUCCESS;
}
コード例 #24
0
ファイル: uintcore.cpp プロジェクト: 0wnrepo/sealcrypto
        ConstPointer duplicate_uint_if_needed(const std::uint64_t *uint, int uint64_count, int new_uint64_count, bool force, MemoryPool &pool)
        {
#ifdef _DEBUG
            if (uint == nullptr && uint64_count > 0)
            {
                throw invalid_argument("uint");
            }
            if (uint64_count < 0)
            {
                throw invalid_argument("uint64_count");
            }
            if (new_uint64_count < 0)
            {
                throw invalid_argument("new_uint64_count");
            }
#endif
            if (!force && uint64_count >= new_uint64_count)
            {
                return ConstPointer::Aliasing(uint);
            }
            Pointer allocation = pool.get_for_uint64_count(new_uint64_count);
            set_uint_uint(uint, uint64_count, new_uint64_count, allocation.get());
            ConstPointer const_allocation;
            const_allocation.acquire(allocation);
            return const_allocation;
        }
コード例 #25
0
ファイル: field.cpp プロジェクト: strategist922/ironbee
Field create_dynamic_field(
    MemoryPool    pool,
    const char*   name,
    size_t        name_length,
    Field::type_e type,
    void*         cbdata_get,
    void*         cbdata_set
)
{
    ib_field_t* f = NULL;

    ib_status_t rc = ib_field_create_dynamic(
        &f,
        pool.ib(),
        name, name_length,
        static_cast<ib_ftype_t>(type),
        Hooks::field_dynamic_get,
        cbdata_get,
        Hooks::field_dynamic_set,
        cbdata_set
    );
    throw_if_error(rc);

    return Field(f);
}
コード例 #26
0
ファイル: main.cpp プロジェクト: Farewellly/mbed
int main (void) {
    GREENTEA_SETUP(20, "default_auto");

    Thread thread(send_thread, NULL, osPriorityNormal, STACK_SIZE);
    bool result = true;
    int result_counter = 0;

    while (true) {
        osEvent evt = queue.get();
        if (evt.status == osEventMessage) {
            message_t *message = (message_t*)evt.value.p;
            const float expected_voltage = CREATE_VOLTAGE(message->counter);
            const float expected_current = CREATE_CURRENT(message->counter);
            // Check using macros if received values correspond to values sent via queue
            bool expected_values = (expected_voltage == message->voltage) &&
                                   (expected_current == message->current);
            result = result && expected_values;
            const char *result_msg = expected_values ? "OK" : "FAIL";
            printf("%3d %.2fV %.2fA ... [%s]\r\n", message->counter,
                                                   message->voltage,
                                                   message->current,
                                                   result_msg);
            mpool.free(message);
            if (result == false || ++result_counter == QUEUE_SIZE) {
                break;
            }
        }
    }
    GREENTEA_TESTSUITE_RESULT(result);
    return 0;
}
コード例 #27
0
ファイル: polycore.cpp プロジェクト: 0wnrepo/sealcrypto
        ConstPointer duplicate_poly_if_needed(const std::uint64_t *poly, int coeff_count, int coeff_uint64_count, int new_coeff_count, int new_coeff_uint64_count, bool force, MemoryPool &pool)
        {
#ifdef _DEBUG
            if (poly == nullptr && coeff_count > 0 && coeff_uint64_count > 0)
            {
                throw invalid_argument("poly");
            }
            if (coeff_count < 0)
            {
                throw invalid_argument("coeff_count");
            }
            if (coeff_uint64_count < 0)
            {
                throw invalid_argument("coeff_uint64_count");
            }
            if (new_coeff_count < 0)
            {
                throw invalid_argument("new_coeff_count");
            }
            if (new_coeff_uint64_count < 0)
            {
                throw invalid_argument("new_coeff_uint64_count");
            }
#endif
            if (!force && coeff_count >= new_coeff_count && coeff_uint64_count == new_coeff_uint64_count)
            {
                return ConstPointer::Aliasing(poly);
            }
            Pointer allocation = pool.get_for_uint64_count(new_coeff_count * new_coeff_uint64_count);
            set_poly_poly(poly, coeff_count, coeff_uint64_count, new_coeff_count, new_coeff_uint64_count, allocation.get());
            ConstPointer const_allocation;
            const_allocation.acquire(allocation);
            return const_allocation;
        }
コード例 #28
0
ファイル: MemoryPool.cpp プロジェクト: moving-on/Mycode
int main()
{
	MemoryPool *m = new MemoryPool(4);
	int *h;
	int *p=(int*)m->Alloc();
	*p = 1;
	h = p;
	for (int i = 2; i < 256; i++)
	{
		p = (int*)m->Alloc();
		*p = i;
	}
	for (; h != p; h++)
		cout << *h << " " << endl;
	delete m;
}
コード例 #29
0
void GCMemoryManager::gc_end() {
  _accumulated_timer.stop();
  _last_gc_stat->set_end_time(Management::timestamp());

  int i;
  // keep the last gc statistics for all memory pools
  for (i = 0; i < MemoryService::num_memory_pools(); i++) {
    MemoryPool* pool = MemoryService::get_memory_pool(i);
    MemoryUsage usage = pool->get_memory_usage();

    HS_DTRACE_PROBE8(hotspot, mem__pool__gc__end,
      name(), strlen(name()),
      pool->name(), strlen(pool->name()),
      usage.init_size(), usage.used(),
      usage.committed(), usage.max_size());

    _last_gc_stat->set_after_gc_usage(i, usage);
  }

  // Set last collection usage of the memory pools managed by this collector
  for (i = 0; i < num_memory_pools(); i++) {
    MemoryPool* pool = get_memory_pool(i);
    MemoryUsage usage = pool->get_memory_usage();

    // Compare with GC usage threshold
    pool->set_last_collection_usage(usage);
    LowMemoryDetector::detect_after_gc_memory(pool);
  }
}
コード例 #30
0
void LowMemoryDetector::process_sensor_changes(TRAPS) {
  ResourceMark rm(THREAD);
  HandleMark hm(THREAD);

  // No need to hold Service_lock to call out to Java
  int num_memory_pools = MemoryService::num_memory_pools();
  for (int i = 0; i < num_memory_pools; i++) {
    MemoryPool* pool = MemoryService::get_memory_pool(i);
    SensorInfo* sensor = pool->usage_sensor();
    SensorInfo* gc_sensor = pool->gc_usage_sensor();
    if (sensor != NULL && sensor->has_pending_requests()) {
      sensor->process_pending_requests(CHECK);
    }
    if (gc_sensor != NULL && gc_sensor->has_pending_requests()) {
      gc_sensor->process_pending_requests(CHECK);
    }
  }
}