MemoryUsage MetaspacePool::get_memory_usage() { size_t committed = MetaspaceAux::committed_bytes(); return MemoryUsage(initial_size(), used_in_bytes(), committed, max_size()); }
void PSPermGen::compute_new_size(size_t used_before_collection) { // Update our padded average of objects allocated in perm // gen between collections. assert(used_before_collection >= _last_used, "negative allocation amount since last GC?"); const size_t alloc_since_last_gc = used_before_collection - _last_used; _avg_size->sample(alloc_since_last_gc); const size_t current_live = used_in_bytes(); // Stash away the current amount live for the next call to this method. _last_used = current_live; // We have different alignment constraints than the rest of the heap. const size_t alignment = MAX2(MinPermHeapExpansion, virtual_space()->alignment()); // Compute the desired size: // The free space is the newly computed padded average, // so the desired size is what's live + the free space. size_t desired_size = current_live + (size_t)_avg_size->padded_average(); desired_size = align_size_up(desired_size, alignment); // ...and no larger or smaller than our max and min allowed. desired_size = MAX2(MIN2(desired_size, _max_gen_size), _min_gen_size); assert(desired_size <= _max_gen_size, "just checking"); const size_t size_before = _virtual_space->committed_size(); if (desired_size == size_before) { // no change, we're done return; } { // We'll be growing or shrinking the heap: in either case, // we need to hold a lock. MutexLocker x(ExpandHeap_lock); if (desired_size > size_before) { const size_t change_bytes = desired_size - size_before; const size_t aligned_change_bytes = align_size_up(change_bytes, alignment); expand_by(aligned_change_bytes); } else { // Shrinking const size_t change_bytes = size_before - desired_size; const size_t aligned_change_bytes = align_size_down(change_bytes, alignment); shrink(aligned_change_bytes); } } // While this code isn't controlled by AdaptiveSizePolicy, it's // convenient to see all resizing decsions under the same flag. if (PrintAdaptiveSizePolicy) { ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); gclog_or_tty->print_cr("AdaptiveSizePolicy::perm generation size: " "collection: %d " "(" SIZE_FORMAT ") -> (" SIZE_FORMAT ") ", heap->total_collections(), size_before, _virtual_space->committed_size()); } }