Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/hotspot/share/gc/shared/collectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
91 changes: 91 additions & 0 deletions test/hotspot/jtreg/gc/TestInitMaxMemoryMXBeans.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}