JDK-8025089 : MetaspaceMemoryPoolMXBean.getUsage() throws "Memory Pool not found" error
  • Type: Bug
  • Component: core-svc
  • Sub-Component: javax.management
  • Affected Version: 8,9
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • Submitted: 2013-09-19
  • Updated: 2023-12-14
  • Resolved: 2015-11-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Blocks :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
I played with various setting of MetaspaceSize/MaxMetaspaceSize and found that some combinations causes " java.lang.InternalError: Memory Pool not found" when I call pool.getUsage()

To reproduce this bug compile the following program:

----- MetaspaceSizeTest.java  --- 
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.MemoryUsage;
import java.util.List;

public class MetaspaceSizeTest {

    public static void main(String args[]) {
        MemoryPoolMXBean pool = getMemoryPool("Metaspace");
        MemoryUsage mu = pool.getUsage();
        System.out.println(mu);
    }

    private static MemoryPoolMXBean getMemoryPool(String name) {
        List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
        for (MemoryPoolMXBean pool : pools) {
            if (pool.getName().equals(name)) {
                return pool;
            }
        }
        throw new RuntimeException("Expected to find a memory pool with name " + name);
    }
}
----------------

and run it as shown bellow:

# for x in 2m 3m ; do for y in 2m 3m 4m ; do echo "size: $x max: $y" ;java -XX:MetaspaceSize=$x -XX:MaxMetaspaceSize=$y MetaspaceSizeTest ; done ; done;

You will see:

size: 2m max: 2m
Exception in thread "main" java.lang.InternalError: Memory Pool not found
        at sun.management.MemoryPoolImpl.getUsage0(Native Method)
        at sun.management.MemoryPoolImpl.getUsage(MemoryPoolImpl.java:96)
        at MetaspaceSizeTest.main(MetaspaceSizeTest.java:11)

size: 2m max: 3m
Exception in thread "main" java.lang.InternalError: Memory Pool not found
        at sun.management.MemoryPoolImpl.getUsage0(Native Method)
        at sun.management.MemoryPoolImpl.getUsage(MemoryPoolImpl.java:96)
        at MetaspaceSizeTest.main(MetaspaceSizeTest.java:11)
size: 2m max: 4m
init = 2252800(2200K) used = 2069648(2021K) committed = 2265088(2212K) max = 4194304(4096K)

size: 3m max: 2m
Exception in thread "main" java.lang.InternalError: Memory Pool not found
        at sun.management.MemoryPoolImpl.getUsage0(Native Method)
        at sun.management.MemoryPoolImpl.getUsage(MemoryPoolImpl.java:96)
        at MetaspaceSizeTest.main(MetaspaceSizeTest.java:11)

size: 3m max: 3m
Exception in thread "main" java.lang.InternalError: Memory Pool not found
        at sun.management.MemoryPoolImpl.getUsage0(Native Method)
        at sun.management.MemoryPoolImpl.getUsage(MemoryPoolImpl.java:96)
        at MetaspaceSizeTest.main(MetaspaceSizeTest.java:11)

size: 3m max: 4m
init = 2252800(2200K) used = 2069648(2021K) committed = 2265088(2212K) max = 4194304(4096K)


===
# java -version
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b107)
Java HotSpot(TM) Client VM (build 25.0-b49, mixed mode)


Comments
This is not reproducible anymore. The nightly failure of lowmem013 mentioned has also not been seen for a few months now. Closing this.
18-11-2015

Aha. The reason was that the main shadow bug, JDK-8024799, was closed as a duplicate of this bug. I saw that you updated the other bug to instead be a duplicate of JDK-8024547. Feel free to restore the priority of this bug
11-12-2013

Could the incorrect error message be fixed by core-libs? The HotSpot bug: java.lang.IllegalArgumentException: committed = 20983808 should be < max = 20971520 was fixed with: JDK-8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces and the test bug will be fixed with: JDK-7196801 NPG: Fix java/lang/management/MemoryMXBean/LowMemoryTest2
11-10-2013

I still think we should have core-libs fix this code because this error is wrong.
30-09-2013

The error message is misleading. Coleen found the cause of these error messages: "I figured out why I was getting InternalError on the jdk/test/java/lang/management/MemoryMXBean/LowMemoryTest2. The jdk code for getUsage for MetaspacePool was converting null return to an internal error exception. The null return was really because the MemoryUsage constructor was getting an exception: Exception in thread "Thread-0" java.lang.IllegalArgumentException: committed = 20983808 should be < max = 20971520 at java.lang.management.MemoryUsage.<init>(MemoryUsage.java:160) at sun.management.MemoryPoolImpl.getUsage0(Native Method) at sun.management.MemoryPoolImpl.isUsageThresholdExceeded(MemoryPoolImpl.java:182) " She used this patch to get a more correct error message: --- old/src/share/native/sun/management/MemoryPoolImpl.c 2013-08-30 16:31:01.018916834 -0400 +++ new/src/share/native/sun/management/MemoryPoolImpl.c 2013-08-30 16:30:59.921660365 -0400 @@ -31,39 +31,21 @@ Java_sun_management_MemoryPoolImpl_getMemoryManagers0 (JNIEnv *env, jobject pool) { - jobject mgrs = jmm_interface->GetMemoryManagers(env, pool); - if (mgrs == NULL) { - // Throw internal error since this implementation expects the - // pool will never become invalid. - JNU_ThrowInternalError(env, "Memory Pool not found"); - } - return mgrs; + return jmm_interface->GetMemoryManagers(env, pool); } JNIEXPORT jobject JNICALL Java_sun_management_MemoryPoolImpl_getUsage0 (JNIEnv *env, jobject pool) { - jobject usage = jmm_interface->GetMemoryPoolUsage(env, pool); - if (usage == NULL) { - // Throw internal error since this implementation expects the - // pool will never become invalid. - JNU_ThrowInternalError(env, "Memory Pool not found"); - } - return usage; + return jmm_interface->GetMemoryPoolUsage(env, pool); } JNIEXPORT jobject JNICALL Java_sun_management_MemoryPoolImpl_getPeakUsage0 (JNIEnv *env, jobject pool) { - jobject usage = jmm_interface->GetPeakMemoryPoolUsage(env, pool); - if (usage == NULL) { - // Throw internal error since this implementation expects the - // pool will never become invalid. - JNU_ThrowInternalError(env, "Memory Pool not found"); - } - return usage; + return jmm_interface->GetPeakMemoryPoolUsage(env, pool); } JNIEXPORT void JNICALL The real cause of this bug is: JDK-8024547 - MaxMetaspaceSize should limit the committed memory used by the metaspaces
23-09-2013