436 ChunkPoolCleaner* cleaner = new ChunkPoolCleaner(); |
436 ChunkPoolCleaner* cleaner = new ChunkPoolCleaner(); |
437 cleaner->enroll(); |
437 cleaner->enroll(); |
438 } |
438 } |
439 |
439 |
440 //------------------------------Arena------------------------------------------ |
440 //------------------------------Arena------------------------------------------ |
441 NOT_PRODUCT(volatile jint Arena::_instance_count = 0;) |
441 Arena::Arena(MEMFLAGS flag, size_t init_size) : _flags(flag), _size_in_bytes(0) { |
442 |
|
443 Arena::Arena(size_t init_size) { |
|
444 size_t round_size = (sizeof (char *)) - 1; |
442 size_t round_size = (sizeof (char *)) - 1; |
445 init_size = (init_size+round_size) & ~round_size; |
443 init_size = (init_size+round_size) & ~round_size; |
446 _first = _chunk = new (AllocFailStrategy::EXIT_OOM, init_size) Chunk(init_size); |
444 _first = _chunk = new (AllocFailStrategy::EXIT_OOM, init_size) Chunk(init_size); |
447 _hwm = _chunk->bottom(); // Save the cached hwm, max |
445 _hwm = _chunk->bottom(); // Save the cached hwm, max |
448 _max = _chunk->top(); |
446 _max = _chunk->top(); |
|
447 MemTracker::record_new_arena(flag); |
449 set_size_in_bytes(init_size); |
448 set_size_in_bytes(init_size); |
450 NOT_PRODUCT(Atomic::inc(&_instance_count);) |
449 } |
451 } |
450 |
452 |
451 Arena::Arena(MEMFLAGS flag) : _flags(flag), _size_in_bytes(0) { |
453 Arena::Arena() { |
|
454 _first = _chunk = new (AllocFailStrategy::EXIT_OOM, Chunk::init_size) Chunk(Chunk::init_size); |
452 _first = _chunk = new (AllocFailStrategy::EXIT_OOM, Chunk::init_size) Chunk(Chunk::init_size); |
455 _hwm = _chunk->bottom(); // Save the cached hwm, max |
453 _hwm = _chunk->bottom(); // Save the cached hwm, max |
456 _max = _chunk->top(); |
454 _max = _chunk->top(); |
|
455 MemTracker::record_new_arena(flag); |
457 set_size_in_bytes(Chunk::init_size); |
456 set_size_in_bytes(Chunk::init_size); |
458 NOT_PRODUCT(Atomic::inc(&_instance_count);) |
|
459 } |
457 } |
460 |
458 |
461 Arena *Arena::move_contents(Arena *copy) { |
459 Arena *Arena::move_contents(Arena *copy) { |
462 copy->destruct_contents(); |
460 copy->destruct_contents(); |
463 copy->_chunk = _chunk; |
461 copy->_chunk = _chunk; |
491 } |
489 } |
492 |
490 |
493 // dynamic memory type binding |
491 // dynamic memory type binding |
494 void* Arena::operator new(size_t size, MEMFLAGS flags) throw() { |
492 void* Arena::operator new(size_t size, MEMFLAGS flags) throw() { |
495 #ifdef ASSERT |
493 #ifdef ASSERT |
496 void* p = (void*)AllocateHeap(size, flags|otArena, CALLER_PC); |
494 void* p = (void*)AllocateHeap(size, flags, CALLER_PC); |
497 if (PrintMallocFree) trace_heap_malloc(size, "Arena-new", p); |
495 if (PrintMallocFree) trace_heap_malloc(size, "Arena-new", p); |
498 return p; |
496 return p; |
499 #else |
497 #else |
500 return (void *) AllocateHeap(size, flags|otArena, CALLER_PC); |
498 return (void *) AllocateHeap(size, flags, CALLER_PC); |
501 #endif |
499 #endif |
502 } |
500 } |
503 |
501 |
504 void* Arena::operator new(size_t size, const std::nothrow_t& nothrow_constant, MEMFLAGS flags) throw() { |
502 void* Arena::operator new(size_t size, const std::nothrow_t& nothrow_constant, MEMFLAGS flags) throw() { |
505 #ifdef ASSERT |
503 #ifdef ASSERT |
506 void* p = os::malloc(size, flags|otArena, CALLER_PC); |
504 void* p = os::malloc(size, flags, CALLER_PC); |
507 if (PrintMallocFree) trace_heap_malloc(size, "Arena-new", p); |
505 if (PrintMallocFree) trace_heap_malloc(size, "Arena-new", p); |
508 return p; |
506 return p; |
509 #else |
507 #else |
510 return os::malloc(size, flags|otArena, CALLER_PC); |
508 return os::malloc(size, flags, CALLER_PC); |
511 #endif |
509 #endif |
512 } |
510 } |
513 |
511 |
514 void Arena::operator delete(void* p) { |
512 void Arena::operator delete(void* p) { |
515 FreeHeap(p); |
513 FreeHeap(p); |
530 |
528 |
531 // This is high traffic method, but many calls actually don't |
529 // This is high traffic method, but many calls actually don't |
532 // change the size |
530 // change the size |
533 void Arena::set_size_in_bytes(size_t size) { |
531 void Arena::set_size_in_bytes(size_t size) { |
534 if (_size_in_bytes != size) { |
532 if (_size_in_bytes != size) { |
|
533 long delta = (long)(size - size_in_bytes()); |
535 _size_in_bytes = size; |
534 _size_in_bytes = size; |
536 MemTracker::record_arena_size((address)this, size); |
535 MemTracker::record_arena_size_change(delta, _flags); |
537 } |
536 } |
538 } |
537 } |
539 |
538 |
540 // Total of all Chunks in arena |
539 // Total of all Chunks in arena |
541 size_t Arena::used() const { |
540 size_t Arena::used() const { |