test/hotspot/jtreg/runtime/Metaspace/MaxMetaspaceSizeTest.java runs with MaxMetaspaceSize=4K and expects to get an OOM
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-Xmx1g",
"-XX:MaxMetaspaceSize=4K",
"-XX:+UseCompressedClassPointers",
"-XX:CompressedClassSpaceSize=1g",
"--version");
However, if CDS is enabled, it's possible to run the VM with a very small MaxMetaspaceSize without getting an OOM.
We should run with -Xshare:off to guarantee that lots of class metadata objects are allocated as classes are being parsed.
Also, this comment is wrong and should be deleted:
https://github.com/openjdk/jdk/blob/4a11db8b606f2b10f48f0b45335b661fe3095fc4/test/hotspot/jtreg/runtime/Metaspace/MaxMetaspaceSizeTest.java#L45
// We do not explicitly limit MaxMetaspaceSize to a lower minimum. User can get as low as he wants.
We actually override the user setting here:
https://github.com/openjdk/jdk/blob/4a11db8b606f2b10f48f0b45335b661fe3095fc4/src/hotspot/share/memory/metaspace.cpp#L647
MaxMetaspaceSize = MAX2(MaxMetaspaceSize, commit_alignment());
On my Linux/x64, MaxMetaspaceSize is set to at least 64K.
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-Xmx1g",
"-XX:MaxMetaspaceSize=4K",
"-XX:+UseCompressedClassPointers",
"-XX:CompressedClassSpaceSize=1g",
"--version");
However, if CDS is enabled, it's possible to run the VM with a very small MaxMetaspaceSize without getting an OOM.
We should run with -Xshare:off to guarantee that lots of class metadata objects are allocated as classes are being parsed.
Also, this comment is wrong and should be deleted:
https://github.com/openjdk/jdk/blob/4a11db8b606f2b10f48f0b45335b661fe3095fc4/test/hotspot/jtreg/runtime/Metaspace/MaxMetaspaceSizeTest.java#L45
// We do not explicitly limit MaxMetaspaceSize to a lower minimum. User can get as low as he wants.
We actually override the user setting here:
https://github.com/openjdk/jdk/blob/4a11db8b606f2b10f48f0b45335b661fe3095fc4/src/hotspot/share/memory/metaspace.cpp#L647
MaxMetaspaceSize = MAX2(MaxMetaspaceSize, commit_alignment());
On my Linux/x64, MaxMetaspaceSize is set to at least 64K.