From 91de59b50f1d6b191ea848c6e9f5544f587a279e Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Fri, 4 Feb 2022 10:52:07 +0300 Subject: [PATCH 1/4] Fix --- src/hotspot/share/gc/serial/defNewGeneration.cpp | 8 ++++++-- src/hotspot/share/gc/serial/defNewGeneration.hpp | 1 + src/hotspot/share/gc/shared/cardGeneration.cpp | 6 +++--- src/hotspot/share/gc/shared/genCollectedHeap.cpp | 7 +++++++ src/hotspot/share/gc/shared/genCollectedHeap.hpp | 1 + src/hotspot/share/gc/shared/generation.cpp | 11 ++++------- src/hotspot/share/gc/shared/generation.hpp | 11 +++++++++-- 7 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/hotspot/share/gc/serial/defNewGeneration.cpp b/src/hotspot/share/gc/serial/defNewGeneration.cpp index dac84ffb78ad7..d8cabc4749807 100644 --- a/src/hotspot/share/gc/serial/defNewGeneration.cpp +++ b/src/hotspot/share/gc/serial/defNewGeneration.cpp @@ -360,7 +360,7 @@ void DefNewGeneration::compute_new_size() { size_t old_size = gch->old_gen()->capacity(); size_t new_size_before = _virtual_space.committed_size(); - size_t min_new_size = initial_size(); + size_t min_new_size = _initial_size; size_t max_new_size = reserved().byte_size(); assert(min_new_size <= new_size_before && new_size_before <= max_new_size, @@ -421,7 +421,6 @@ void DefNewGeneration::compute_new_size() { } } - size_t DefNewGeneration::capacity() const { return eden()->capacity() + from()->capacity(); // to() is only used during scavenge @@ -439,6 +438,11 @@ size_t DefNewGeneration::free() const { + from()->free(); // to() is only used during scavenge } +size_t DefNewGeneration::initial_capacity() const { + const size_t initial_bytes = _initial_size; + return initial_bytes - compute_survivor_size(initial_bytes, SpaceAlignment); +} + size_t DefNewGeneration::max_capacity() const { const size_t reserved_bytes = reserved().byte_size(); return reserved_bytes - compute_survivor_size(reserved_bytes, SpaceAlignment); diff --git a/src/hotspot/share/gc/serial/defNewGeneration.hpp b/src/hotspot/share/gc/serial/defNewGeneration.hpp index f060a5ea8ac99..568905f28a064 100644 --- a/src/hotspot/share/gc/serial/defNewGeneration.hpp +++ b/src/hotspot/share/gc/serial/defNewGeneration.hpp @@ -215,6 +215,7 @@ class DefNewGeneration: public Generation { size_t capacity() const; size_t used() const; size_t free() const; + size_t initial_capacity() const; size_t max_capacity() const; size_t capacity_before_gc() const; size_t unsafe_max_alloc_nogc() const; diff --git a/src/hotspot/share/gc/shared/cardGeneration.cpp b/src/hotspot/share/gc/shared/cardGeneration.cpp index 523f65c8cc3a5..0b4d831d38148 100644 --- a/src/hotspot/share/gc/shared/cardGeneration.cpp +++ b/src/hotspot/share/gc/shared/cardGeneration.cpp @@ -202,7 +202,7 @@ void CardGeneration::compute_new_size() { const double min_tmp = used_after_gc / maximum_used_percentage; size_t minimum_desired_capacity = (size_t)MIN2(min_tmp, double(max_uintx)); // Don't shrink less than the initial generation size - minimum_desired_capacity = MAX2(minimum_desired_capacity, initial_size()); + minimum_desired_capacity = MAX2(minimum_desired_capacity, _initial_size); assert(used_after_gc <= minimum_desired_capacity, "sanity check"); const size_t free_after_gc = free(); @@ -241,7 +241,7 @@ void CardGeneration::compute_new_size() { const double minimum_used_percentage = 1.0 - maximum_free_percentage; const double max_tmp = used_after_gc / minimum_used_percentage; size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(max_uintx)); - maximum_desired_capacity = MAX2(maximum_desired_capacity, initial_size()); + maximum_desired_capacity = MAX2(maximum_desired_capacity, _initial_size); log_trace(gc, heap)(" maximum_free_percentage: %6.2f minimum_used_percentage: %6.2f", maximum_free_percentage, minimum_used_percentage); log_trace(gc, heap)(" _capacity_at_prologue: %6.1fK minimum_desired_capacity: %6.1fK maximum_desired_capacity: %6.1fK", @@ -271,7 +271,7 @@ void CardGeneration::compute_new_size() { } assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size"); log_trace(gc, heap)(" shrinking: initSize: %.1fK maximum_desired_capacity: %.1fK", - initial_size() / (double) K, maximum_desired_capacity / (double) K); + _initial_size / (double) K, maximum_desired_capacity / (double) K); log_trace(gc, heap)(" shrink_bytes: %.1fK current_shrink_factor: " SIZE_FORMAT " new shrink factor: " SIZE_FORMAT " _min_heap_delta_bytes: %.1fK", shrink_bytes / (double) K, current_shrink_factor, diff --git a/src/hotspot/share/gc/shared/genCollectedHeap.cpp b/src/hotspot/share/gc/shared/genCollectedHeap.cpp index c840e5a666790..b2dfae0c74428 100644 --- a/src/hotspot/share/gc/shared/genCollectedHeap.cpp +++ b/src/hotspot/share/gc/shared/genCollectedHeap.cpp @@ -249,6 +249,13 @@ size_t GenCollectedHeap::max_capacity() const { return _young_gen->max_capacity() + _old_gen->max_capacity(); } +MemoryUsage GenCollectedHeap::memory_usage() { + return MemoryUsage(_young_gen->initial_capacity() + _old_gen->initial_capacity(), + used(), + capacity(), + max_capacity()); +} + // Update the _full_collections_completed counter // at the end of a stop-world full GC. unsigned int GenCollectedHeap::update_full_collections_completed() { diff --git a/src/hotspot/share/gc/shared/genCollectedHeap.hpp b/src/hotspot/share/gc/shared/genCollectedHeap.hpp index 1cce08f4b0c99..69f865783dea6 100644 --- a/src/hotspot/share/gc/shared/genCollectedHeap.hpp +++ b/src/hotspot/share/gc/shared/genCollectedHeap.hpp @@ -173,6 +173,7 @@ class GenCollectedHeap : public CollectedHeap { size_t capacity() const; size_t used() const; + MemoryUsage memory_usage(); // Save the "used_region" for both generations. void save_used_regions(); diff --git a/src/hotspot/share/gc/shared/generation.cpp b/src/hotspot/share/gc/shared/generation.cpp index a0a57dea115e0..3947eb310ace1 100644 --- a/src/hotspot/share/gc/shared/generation.cpp +++ b/src/hotspot/share/gc/shared/generation.cpp @@ -45,7 +45,8 @@ Generation::Generation(ReservedSpace rs, size_t initial_size) : _gc_manager(NULL), - _ref_processor(NULL) { + _ref_processor(NULL), + _initial_size(initial_size) { if (!_virtual_space.initialize(rs, initial_size)) { vm_exit_during_initialization("Could not reserve enough space for " "object heap"); @@ -60,12 +61,8 @@ Generation::Generation(ReservedSpace rs, size_t initial_size) : (HeapWord*)_virtual_space.high_boundary()); } -size_t Generation::initial_size() { - GenCollectedHeap* gch = GenCollectedHeap::heap(); - if (gch->is_young_gen(this)) { - return gch->young_gen_spec()->init_size(); - } - return gch->old_gen_spec()->init_size(); +size_t Generation::initial_capacity() const { + return _initial_size; } size_t Generation::max_capacity() const { diff --git a/src/hotspot/share/gc/shared/generation.hpp b/src/hotspot/share/gc/shared/generation.hpp index b9183ec28987b..80bb47175c353 100644 --- a/src/hotspot/share/gc/shared/generation.hpp +++ b/src/hotspot/share/gc/shared/generation.hpp @@ -97,6 +97,9 @@ class Generation: public CHeapObj { // Statistics for garbage collection GCStats* _gc_stats; + // Initial generation size + size_t _initial_size; + // Initialize the generation. Generation(ReservedSpace rs, size_t initial_byte_size); @@ -127,14 +130,18 @@ class Generation: public CHeapObj { virtual Generation::Name kind() { return Generation::Other; } // Space inquiries (results in bytes) - size_t initial_size(); virtual size_t capacity() const = 0; // The maximum number of object bytes the // generation can currently hold. virtual size_t used() const = 0; // The number of used bytes in the gen. virtual size_t free() const = 0; // The number of free bytes in the gen. // Support for java.lang.Runtime.maxMemory(); see CollectedHeap. - // Returns the total number of bytes available in a generation + + // Returns the initial number of bytes available in a generation + // for the allocation of objects. + virtual size_t initial_capacity() const; + + // Returns the total number of bytes available in a generation // for the allocation of objects. virtual size_t max_capacity() const; From 04b6e3d2aa3ff3c915a4044973c461c42e2268f4 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Fri, 4 Feb 2022 11:07:33 +0300 Subject: [PATCH 2/4] Better fix --- src/hotspot/share/gc/serial/defNewGeneration.cpp | 5 +++-- src/hotspot/share/gc/shared/cardGeneration.cpp | 6 +++--- src/hotspot/share/gc/shared/generation.cpp | 4 ++-- src/hotspot/share/gc/shared/generation.hpp | 7 ++++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/hotspot/share/gc/serial/defNewGeneration.cpp b/src/hotspot/share/gc/serial/defNewGeneration.cpp index d8cabc4749807..64c2e0982a76c 100644 --- a/src/hotspot/share/gc/serial/defNewGeneration.cpp +++ b/src/hotspot/share/gc/serial/defNewGeneration.cpp @@ -360,7 +360,7 @@ void DefNewGeneration::compute_new_size() { size_t old_size = gch->old_gen()->capacity(); size_t new_size_before = _virtual_space.committed_size(); - size_t min_new_size = _initial_size; + size_t min_new_size = initial_size(); size_t max_new_size = reserved().byte_size(); assert(min_new_size <= new_size_before && new_size_before <= max_new_size, @@ -421,6 +421,7 @@ void DefNewGeneration::compute_new_size() { } } + size_t DefNewGeneration::capacity() const { return eden()->capacity() + from()->capacity(); // to() is only used during scavenge @@ -439,7 +440,7 @@ size_t DefNewGeneration::free() const { } size_t DefNewGeneration::initial_capacity() const { - const size_t initial_bytes = _initial_size; + const size_t initial_bytes = initial_size(); return initial_bytes - compute_survivor_size(initial_bytes, SpaceAlignment); } diff --git a/src/hotspot/share/gc/shared/cardGeneration.cpp b/src/hotspot/share/gc/shared/cardGeneration.cpp index 0b4d831d38148..523f65c8cc3a5 100644 --- a/src/hotspot/share/gc/shared/cardGeneration.cpp +++ b/src/hotspot/share/gc/shared/cardGeneration.cpp @@ -202,7 +202,7 @@ void CardGeneration::compute_new_size() { const double min_tmp = used_after_gc / maximum_used_percentage; size_t minimum_desired_capacity = (size_t)MIN2(min_tmp, double(max_uintx)); // Don't shrink less than the initial generation size - minimum_desired_capacity = MAX2(minimum_desired_capacity, _initial_size); + minimum_desired_capacity = MAX2(minimum_desired_capacity, initial_size()); assert(used_after_gc <= minimum_desired_capacity, "sanity check"); const size_t free_after_gc = free(); @@ -241,7 +241,7 @@ void CardGeneration::compute_new_size() { const double minimum_used_percentage = 1.0 - maximum_free_percentage; const double max_tmp = used_after_gc / minimum_used_percentage; size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(max_uintx)); - maximum_desired_capacity = MAX2(maximum_desired_capacity, _initial_size); + maximum_desired_capacity = MAX2(maximum_desired_capacity, initial_size()); log_trace(gc, heap)(" maximum_free_percentage: %6.2f minimum_used_percentage: %6.2f", maximum_free_percentage, minimum_used_percentage); log_trace(gc, heap)(" _capacity_at_prologue: %6.1fK minimum_desired_capacity: %6.1fK maximum_desired_capacity: %6.1fK", @@ -271,7 +271,7 @@ void CardGeneration::compute_new_size() { } assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size"); log_trace(gc, heap)(" shrinking: initSize: %.1fK maximum_desired_capacity: %.1fK", - _initial_size / (double) K, maximum_desired_capacity / (double) K); + initial_size() / (double) K, maximum_desired_capacity / (double) K); log_trace(gc, heap)(" shrink_bytes: %.1fK current_shrink_factor: " SIZE_FORMAT " new shrink factor: " SIZE_FORMAT " _min_heap_delta_bytes: %.1fK", shrink_bytes / (double) K, current_shrink_factor, diff --git a/src/hotspot/share/gc/shared/generation.cpp b/src/hotspot/share/gc/shared/generation.cpp index 3947eb310ace1..c16df86218192 100644 --- a/src/hotspot/share/gc/shared/generation.cpp +++ b/src/hotspot/share/gc/shared/generation.cpp @@ -45,8 +45,8 @@ Generation::Generation(ReservedSpace rs, size_t initial_size) : _gc_manager(NULL), - _ref_processor(NULL), - _initial_size(initial_size) { + _initial_size(initial_size), + _ref_processor(NULL) { if (!_virtual_space.initialize(rs, initial_size)) { vm_exit_during_initialization("Could not reserve enough space for " "object heap"); diff --git a/src/hotspot/share/gc/shared/generation.hpp b/src/hotspot/share/gc/shared/generation.hpp index 80bb47175c353..f7e0083285131 100644 --- a/src/hotspot/share/gc/shared/generation.hpp +++ b/src/hotspot/share/gc/shared/generation.hpp @@ -77,6 +77,9 @@ class Generation: public CHeapObj { GCMemoryManager* _gc_manager; + // Initial generation size + size_t _initial_size; + protected: // Minimum and maximum addresses for memory reserved (not necessarily // committed) for generation. @@ -97,9 +100,6 @@ class Generation: public CHeapObj { // Statistics for garbage collection GCStats* _gc_stats; - // Initial generation size - size_t _initial_size; - // Initialize the generation. Generation(ReservedSpace rs, size_t initial_byte_size); @@ -130,6 +130,7 @@ class Generation: public CHeapObj { virtual Generation::Name kind() { return Generation::Other; } // Space inquiries (results in bytes) + size_t initial_size() const { return _initial_size; } virtual size_t capacity() const = 0; // The maximum number of object bytes the // generation can currently hold. virtual size_t used() const = 0; // The number of used bytes in the gen. From 6b526c7dacf543ff26e6fd2b60c85e3052a5fb8d Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Fri, 4 Feb 2022 11:36:37 +0300 Subject: [PATCH 3/4] Fix Parallel too --- .../gc/parallel/parallelScavengeHeap.cpp | 7 ++ .../gc/parallel/parallelScavengeHeap.hpp | 1 + .../jtreg/gc/TestInitMaxMemoryMXBeans.java | 91 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 test/hotspot/jtreg/gc/TestInitMaxMemoryMXBeans.java diff --git a/src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp b/src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp index 3a4774d15ca5f..43c9424111ee1 100644 --- a/src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp +++ b/src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp @@ -223,6 +223,13 @@ size_t ParallelScavengeHeap::max_capacity() const { return MAX2(estimated, capacity()); } +MemoryUsage ParallelScavengeHeap::memory_usage() { + return MemoryUsage(MIN2(InitialHeapSize, capacity()), + used(), + capacity(), + max_capacity()); +} + bool ParallelScavengeHeap::is_in(const void* p) const { return young_gen()->is_in(p) || old_gen()->is_in(p); } diff --git a/src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp b/src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp index 0a81c0b1315f9..62057aeff7de5 100644 --- a/src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp +++ b/src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp @@ -164,6 +164,7 @@ class ParallelScavengeHeap : public CollectedHeap { size_t capacity() const; size_t used() const; + MemoryUsage memory_usage(); // Return "true" if all generations have reached the // maximal committed limit that they can reach, without a garbage diff --git a/test/hotspot/jtreg/gc/TestInitMaxMemoryMXBeans.java b/test/hotspot/jtreg/gc/TestInitMaxMemoryMXBeans.java new file mode 100644 index 0000000000000..c824937f5cc53 --- /dev/null +++ b/test/hotspot/jtreg/gc/TestInitMaxMemoryMXBeans.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2022, Red Hat, Inc. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/** + * @test id=Serial + * @bug 8281254 + * @summary Test memory beans report Init == Max, when Xmx == Xms + * @requires vm.gc.Serial + * @modules java.management + * @run main/othervm -XX:+UseSerialGC -Xms76m -Xmx76m TestInitMaxMemoryMXBeans + */ + +/** + * @test id=Parallel + * @bug 8281254 + * @summary Test memory beans report Init == Max, when Xmx == Xms + * @requires vm.gc.Parallel + * @modules java.management + * @run main/othervm -XX:+UseParallelGC -Xms76m -Xmx76m TestInitMaxMemoryMXBeans + */ + +/** + * @test id=G1 + * @bug 8281254 + * @summary Test memory beans report Init == Max, when Xmx == Xms + * @requires vm.gc.G1 + * @modules java.management + * @run main/othervm -XX:+UseG1GC -Xms76m -Xmx76m TestInitMaxMemoryMXBeans + */ + +/** + * @test id=Shenandoah + * @bug 8281254 + * @summary Test memory beans report Init == Max, when Xmx == Xms + * @requires vm.gc.Shenandoah + * @modules java.management + * @run main/othervm -XX:+UseShenandoahGC -Xms76m -Xmx76m TestInitMaxMemoryMXBeans + */ + +/** + * @test id=Z + * @bug 8281254 + * @summary Test memory beans report Init == Max, when Xmx == Xms + * @requires vm.gc.Z + * @modules java.management + * @run main/othervm -XX:+UseZGC -Xms76m -Xmx76m TestInitMaxMemoryMXBeans + */ + +/** + * @test id=Epsilon + * @bug 8281254 + * @summary Test memory beans report Init == Max, when Xmx == Xms + * @requires vm.gc.Epsilon + * @modules java.management + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xms76m -Xmx76m TestInitMaxMemoryMXBeans + */ + +import java.lang.management.*; + +public class TestInitMaxMemoryMXBeans { + public static void main(String[] args) throws Exception { + MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); + long heapInit = memoryMXBean.getHeapMemoryUsage().getInit(); + long heapMax = memoryMXBean.getHeapMemoryUsage().getMax(); + + if (heapInit != heapMax) { + throw new IllegalStateException("Discrepancy: init = " + heapInit + ", max = " + heapMax); + } + } +} From 3f12ba7e0f0e37825cc6eed9c3b248049aa9676d Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Fri, 4 Feb 2022 11:41:18 +0300 Subject: [PATCH 4/4] Revert extensive changes --- .../share/gc/parallel/parallelScavengeHeap.cpp | 7 ------- .../share/gc/parallel/parallelScavengeHeap.hpp | 1 - src/hotspot/share/gc/serial/defNewGeneration.cpp | 5 ----- src/hotspot/share/gc/serial/defNewGeneration.hpp | 1 - src/hotspot/share/gc/shared/collectedHeap.cpp | 5 ++++- src/hotspot/share/gc/shared/genCollectedHeap.cpp | 7 ------- src/hotspot/share/gc/shared/genCollectedHeap.hpp | 1 - src/hotspot/share/gc/shared/generation.cpp | 9 ++++++--- src/hotspot/share/gc/shared/generation.hpp | 12 ++---------- 9 files changed, 12 insertions(+), 36 deletions(-) diff --git a/src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp b/src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp index 43c9424111ee1..3a4774d15ca5f 100644 --- a/src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp +++ b/src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp @@ -223,13 +223,6 @@ size_t ParallelScavengeHeap::max_capacity() const { return MAX2(estimated, capacity()); } -MemoryUsage ParallelScavengeHeap::memory_usage() { - return MemoryUsage(MIN2(InitialHeapSize, capacity()), - used(), - capacity(), - max_capacity()); -} - bool ParallelScavengeHeap::is_in(const void* p) const { return young_gen()->is_in(p) || old_gen()->is_in(p); } diff --git a/src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp b/src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp index 62057aeff7de5..0a81c0b1315f9 100644 --- a/src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp +++ b/src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp @@ -164,7 +164,6 @@ class ParallelScavengeHeap : public CollectedHeap { size_t capacity() const; size_t used() const; - MemoryUsage memory_usage(); // Return "true" if all generations have reached the // maximal committed limit that they can reach, without a garbage diff --git a/src/hotspot/share/gc/serial/defNewGeneration.cpp b/src/hotspot/share/gc/serial/defNewGeneration.cpp index 64c2e0982a76c..dac84ffb78ad7 100644 --- a/src/hotspot/share/gc/serial/defNewGeneration.cpp +++ b/src/hotspot/share/gc/serial/defNewGeneration.cpp @@ -439,11 +439,6 @@ size_t DefNewGeneration::free() const { + from()->free(); // to() is only used during scavenge } -size_t DefNewGeneration::initial_capacity() const { - const size_t initial_bytes = initial_size(); - return initial_bytes - compute_survivor_size(initial_bytes, SpaceAlignment); -} - size_t DefNewGeneration::max_capacity() const { const size_t reserved_bytes = reserved().byte_size(); return reserved_bytes - compute_survivor_size(reserved_bytes, SpaceAlignment); diff --git a/src/hotspot/share/gc/serial/defNewGeneration.hpp b/src/hotspot/share/gc/serial/defNewGeneration.hpp index 568905f28a064..f060a5ea8ac99 100644 --- a/src/hotspot/share/gc/serial/defNewGeneration.hpp +++ b/src/hotspot/share/gc/serial/defNewGeneration.hpp @@ -215,7 +215,6 @@ class DefNewGeneration: public Generation { size_t capacity() const; size_t used() const; size_t free() const; - size_t initial_capacity() const; size_t max_capacity() const; size_t capacity_before_gc() const; size_t unsafe_max_alloc_nogc() const; diff --git a/src/hotspot/share/gc/shared/collectedHeap.cpp b/src/hotspot/share/gc/shared/collectedHeap.cpp index f9ad0759b4281..6e448184a1e4a 100644 --- a/src/hotspot/share/gc/shared/collectedHeap.cpp +++ b/src/hotspot/share/gc/shared/collectedHeap.cpp @@ -371,7 +371,10 @@ MetaWord* CollectedHeap::satisfy_failed_metadata_allocation(ClassLoaderData* loa } MemoryUsage CollectedHeap::memory_usage() { - return MemoryUsage(InitialHeapSize, used(), capacity(), max_capacity()); + return MemoryUsage(MIN2(InitialHeapSize, capacity()), + used(), + capacity(), + max_capacity()); } void CollectedHeap::set_gc_cause(GCCause::Cause v) { diff --git a/src/hotspot/share/gc/shared/genCollectedHeap.cpp b/src/hotspot/share/gc/shared/genCollectedHeap.cpp index b2dfae0c74428..c840e5a666790 100644 --- a/src/hotspot/share/gc/shared/genCollectedHeap.cpp +++ b/src/hotspot/share/gc/shared/genCollectedHeap.cpp @@ -249,13 +249,6 @@ size_t GenCollectedHeap::max_capacity() const { return _young_gen->max_capacity() + _old_gen->max_capacity(); } -MemoryUsage GenCollectedHeap::memory_usage() { - return MemoryUsage(_young_gen->initial_capacity() + _old_gen->initial_capacity(), - used(), - capacity(), - max_capacity()); -} - // Update the _full_collections_completed counter // at the end of a stop-world full GC. unsigned int GenCollectedHeap::update_full_collections_completed() { diff --git a/src/hotspot/share/gc/shared/genCollectedHeap.hpp b/src/hotspot/share/gc/shared/genCollectedHeap.hpp index 69f865783dea6..1cce08f4b0c99 100644 --- a/src/hotspot/share/gc/shared/genCollectedHeap.hpp +++ b/src/hotspot/share/gc/shared/genCollectedHeap.hpp @@ -173,7 +173,6 @@ class GenCollectedHeap : public CollectedHeap { size_t capacity() const; size_t used() const; - MemoryUsage memory_usage(); // Save the "used_region" for both generations. void save_used_regions(); diff --git a/src/hotspot/share/gc/shared/generation.cpp b/src/hotspot/share/gc/shared/generation.cpp index c16df86218192..a0a57dea115e0 100644 --- a/src/hotspot/share/gc/shared/generation.cpp +++ b/src/hotspot/share/gc/shared/generation.cpp @@ -45,7 +45,6 @@ Generation::Generation(ReservedSpace rs, size_t initial_size) : _gc_manager(NULL), - _initial_size(initial_size), _ref_processor(NULL) { if (!_virtual_space.initialize(rs, initial_size)) { vm_exit_during_initialization("Could not reserve enough space for " @@ -61,8 +60,12 @@ Generation::Generation(ReservedSpace rs, size_t initial_size) : (HeapWord*)_virtual_space.high_boundary()); } -size_t Generation::initial_capacity() const { - return _initial_size; +size_t Generation::initial_size() { + GenCollectedHeap* gch = GenCollectedHeap::heap(); + if (gch->is_young_gen(this)) { + return gch->young_gen_spec()->init_size(); + } + return gch->old_gen_spec()->init_size(); } size_t Generation::max_capacity() const { diff --git a/src/hotspot/share/gc/shared/generation.hpp b/src/hotspot/share/gc/shared/generation.hpp index f7e0083285131..b9183ec28987b 100644 --- a/src/hotspot/share/gc/shared/generation.hpp +++ b/src/hotspot/share/gc/shared/generation.hpp @@ -77,9 +77,6 @@ class Generation: public CHeapObj { GCMemoryManager* _gc_manager; - // Initial generation size - size_t _initial_size; - protected: // Minimum and maximum addresses for memory reserved (not necessarily // committed) for generation. @@ -130,19 +127,14 @@ class Generation: public CHeapObj { virtual Generation::Name kind() { return Generation::Other; } // Space inquiries (results in bytes) - size_t initial_size() const { return _initial_size; } + size_t initial_size(); virtual size_t capacity() const = 0; // The maximum number of object bytes the // generation can currently hold. virtual size_t used() const = 0; // The number of used bytes in the gen. virtual size_t free() const = 0; // The number of free bytes in the gen. // Support for java.lang.Runtime.maxMemory(); see CollectedHeap. - - // Returns the initial number of bytes available in a generation - // for the allocation of objects. - virtual size_t initial_capacity() const; - - // Returns the total number of bytes available in a generation + // Returns the total number of bytes available in a generation // for the allocation of objects. virtual size_t max_capacity() const;