src/share/vm/memory/allocation.cpp

Print this page




 543 size_t Arena::used() const {
 544   size_t sum = _chunk->length() - (_max-_hwm); // Size leftover in this Chunk
 545   register Chunk *k = _first;
 546   while( k != _chunk) {         // Whilst have Chunks in a row
 547     sum += k->length();         // Total size of this Chunk
 548     k = k->next();              // Bump along to next Chunk
 549   }
 550   return sum;                   // Return total consumed space.
 551 }
 552 
 553 void Arena::signal_out_of_memory(size_t sz, const char* whence) const {
 554   vm_exit_out_of_memory(sz, OOM_MALLOC_ERROR, whence);
 555 }
 556 
 557 // Grow a new Chunk
 558 void* Arena::grow(size_t x, AllocFailType alloc_failmode) {
 559   // Get minimal required size.  Either real big, or even bigger for giant objs
 560   size_t len = MAX2(x, (size_t) Chunk::size);
 561 
 562   Chunk *k = _chunk;            // Get filled-up chunk address
 563   _chunk = new (alloc_failmode, len) Chunk(len);
 564 
 565   if (_chunk == NULL) {


 566     return NULL;
 567   }


 568   if (k) k->set_next(_chunk);   // Append new chunk to end of linked list
 569   else _first = _chunk;
 570   _hwm  = _chunk->bottom();     // Save the cached hwm, max
 571   _max =  _chunk->top();
 572   set_size_in_bytes(size_in_bytes() + len);
 573   void* result = _hwm;
 574   _hwm += x;
 575   return result;
 576 }
 577 
 578 
 579 
 580 // Reallocate storage in Arena.
 581 void *Arena::Arealloc(void* old_ptr, size_t old_size, size_t new_size, AllocFailType alloc_failmode) {
 582   assert(new_size >= 0, "bad size");
 583   if (new_size == 0) return NULL;
 584 #ifdef ASSERT
 585   if (UseMallocOnly) {
 586     // always allocate a new object  (otherwise we'll free this one twice)
 587     char* copy = (char*)Amalloc(new_size, alloc_failmode);




 543 size_t Arena::used() const {
 544   size_t sum = _chunk->length() - (_max-_hwm); // Size leftover in this Chunk
 545   register Chunk *k = _first;
 546   while( k != _chunk) {         // Whilst have Chunks in a row
 547     sum += k->length();         // Total size of this Chunk
 548     k = k->next();              // Bump along to next Chunk
 549   }
 550   return sum;                   // Return total consumed space.
 551 }
 552 
 553 void Arena::signal_out_of_memory(size_t sz, const char* whence) const {
 554   vm_exit_out_of_memory(sz, OOM_MALLOC_ERROR, whence);
 555 }
 556 
 557 // Grow a new Chunk
 558 void* Arena::grow(size_t x, AllocFailType alloc_failmode) {
 559   // Get minimal required size.  Either real big, or even bigger for giant objs
 560   size_t len = MAX2(x, (size_t) Chunk::size);
 561 
 562   Chunk *k = _chunk;            // Get filled-up chunk address

 563 
 564   Chunk* tmp_chunk;
 565   tmp_chunk = new (alloc_failmode, len) Chunk(len);
 566   if (tmp_chunk == NULL) {
 567     return NULL;
 568   }
 569   _chunk = tmp_chunk;
 570 
 571   if (k) k->set_next(_chunk);   // Append new chunk to end of linked list
 572   else _first = _chunk;
 573   _hwm  = _chunk->bottom();     // Save the cached hwm, max
 574   _max =  _chunk->top();
 575   set_size_in_bytes(size_in_bytes() + len);
 576   void* result = _hwm;
 577   _hwm += x;
 578   return result;
 579 }
 580 
 581 
 582 
 583 // Reallocate storage in Arena.
 584 void *Arena::Arealloc(void* old_ptr, size_t old_size, size_t new_size, AllocFailType alloc_failmode) {
 585   assert(new_size >= 0, "bad size");
 586   if (new_size == 0) return NULL;
 587 #ifdef ASSERT
 588   if (UseMallocOnly) {
 589     // always allocate a new object  (otherwise we'll free this one twice)
 590     char* copy = (char*)Amalloc(new_size, alloc_failmode);