8264540: WhiteBox.metaspaceReserveAlignment should return shared region alignment

Reviewed-by: ccheung, iklam
This commit is contained in:
Yumin Qi 2021-04-05 18:31:12 +00:00
parent 104e925dfd
commit d920f8588c
5 changed files with 27 additions and 18 deletions

@ -1778,8 +1778,14 @@ WB_ENTRY(jlong, WB_MetaspaceCapacityUntilGC(JNIEnv* env, jobject wb))
return (jlong) MetaspaceGC::capacity_until_GC();
WB_END
WB_ENTRY(jlong, WB_MetaspaceReserveAlignment(JNIEnv* env, jobject wb))
return (jlong)Metaspace::reserve_alignment();
// The function is only valid when CDS is available.
WB_ENTRY(jlong, WB_MetaspaceSharedRegionAlignment(JNIEnv* env, jobject wb))
#if INCLUDE_CDS
return (jlong)MetaspaceShared::core_region_alignment();
#else
ShouldNotReachHere();
return 0L;
#endif
WB_END
WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj))
@ -2503,7 +2509,7 @@ static JNINativeMethod methods[] = {
CC"(Ljava/lang/ClassLoader;J)J", (void*)&WB_AllocateMetaspace },
{CC"incMetaspaceCapacityUntilGC", CC"(J)J", (void*)&WB_IncMetaspaceCapacityUntilGC },
{CC"metaspaceCapacityUntilGC", CC"()J", (void*)&WB_MetaspaceCapacityUntilGC },
{CC"metaspaceReserveAlignment", CC"()J", (void*)&WB_MetaspaceReserveAlignment },
{CC"metaspaceSharedRegionAlignment", CC"()J", (void*)&WB_MetaspaceSharedRegionAlignment },
{CC"getCPUFeatures", CC"()Ljava/lang/String;", (void*)&WB_GetCPUFeatures },
{CC"getNMethod0", CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;",
(void*)&WB_GetNMethod },

@ -45,7 +45,7 @@ import java.lang.Integer;
public class SpaceUtilizationCheck {
// For the RW/RO regions:
// [1] Each region must have strictly less than
// WhiteBox.metaspaceReserveAlignment() bytes of unused space.
// WhiteBox.metaspaceSharedRegionAlignment() bytes of unused space.
// [2] There must be no gap between two consecutive regions.
public static void main(String[] args) throws Exception {
@ -58,8 +58,8 @@ public class SpaceUtilizationCheck {
OutputAnalyzer output = CDSTestUtils.createArchiveAndCheck(opts);
Pattern pattern = Pattern.compile("(..) space: *([0-9]+).* out of *([0-9]+) bytes .* at 0x([0-9a0-f]+)");
WhiteBox wb = WhiteBox.getWhiteBox();
long reserve_alignment = wb.metaspaceReserveAlignment();
System.out.println("Metaspace::reserve_alignment() = " + reserve_alignment);
long reserve_alignment = wb.metaspaceSharedRegionAlignment();
System.out.println("MetaspaceShared::core_region_alignment() = " + reserve_alignment);
// Look for output like this. The pattern will only match the first 2 regions, which is what we need to check
//
@ -88,7 +88,7 @@ public class SpaceUtilizationCheck {
}
if (unused > reserve_alignment) {
// [1] Check for unused space
throw new RuntimeException("Unused space (" + unused + ") must be smaller than Metaspace::reserve_alignment() (" +
throw new RuntimeException("Unused space (" + unused + ") must be smaller than MetaspaceShared::core_region_alignment() (" +
reserve_alignment + ")");
}
if (last_region >= 0 && address != last_region) {

@ -67,6 +67,7 @@ public class SharedArchiveConsistency {
public static int sp_used_offset; // offset of CDSFileMapRegion::_used
public static int size_t_size; // size of size_t
public static int int_size; // size of int
public static long alignment; // MetaspaceShared::core_region_alignment
// The following should be consistent with the enum in the C++ MetaspaceShared class
public static String[] shared_region_name = {
@ -104,6 +105,7 @@ public class SharedArchiveConsistency {
sp_used_offset = wb.getOffsetForName("CDSFileMapRegion::_used") - sp_offset_crc;
size_t_size = wb.getOffsetForName("size_t_size");
CDSFileMapRegion_size = wb.getOffsetForName("CDSFileMapRegion_size");
alignment = wb.metaspaceSharedRegionAlignment();
}
public static int getFileHeaderSize(FileChannel fc) throws Exception {
@ -195,7 +197,6 @@ public class SharedArchiveConsistency {
static long get_region_used_size_aligned(FileChannel fc, int region) throws Exception {
long n = sp_offset + CDSFileMapRegion_size * region + sp_used_offset;
long alignment = WhiteBox.getWhiteBox().metaspaceReserveAlignment();
long used = readInt(fc, n, size_t_size);
used = (used + alignment - 1) & ~(alignment - 1);
return used;

@ -31,13 +31,17 @@
* disable it if ZGC is used.
* @bug 8236847
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds/test-classes
* @build sun.hotspot.WhiteBox
* @build Hello
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller -jar hello.jar Hello
* @run driver SharedRegionAlignmentTest
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. SharedRegionAlignmentTest
*/
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.helpers.ClassFileInstaller;
import sun.hotspot.WhiteBox;
public class SharedRegionAlignmentTest {
static String appJar = ClassFileInstaller.getJarPath("hello.jar");
@ -49,14 +53,14 @@ public class SharedRegionAlignmentTest {
// Dump (3 combinations): largePageArgs
// Run (3 combinations): largePageArgs
String UseLargePages = "-XX:+UseLargePages";
String checkString = "Core region alignment: " +
WhiteBox.getWhiteBox().metaspaceSharedRegionAlignment();
String [][] largePageArgs = {
{}, // default
{UseLargePages}
};
final String logFor64K = "core_region_alignment = 65535";
int dumpCase = 0;
for (String[] dumpLP: largePageArgs) {
dumpCase ++;
@ -67,8 +71,8 @@ public class SharedRegionAlignmentTest {
OutputAnalyzer out = TestCommon.dump(appJar,
TestCommon.list(mainClass),
TestCommon.concat(dumpLP, logArg));
out.shouldContain("Dumping shared data to file");
boolean is_aligned_64k = out.getStdout().contains(logFor64K);
out.shouldContain("Dumping shared data to file")
.shouldContain(checkString);
int runCase = 0;
for (String[] runLP: largePageArgs) {
@ -79,10 +83,8 @@ public class SharedRegionAlignmentTest {
TestCommon.run(TestCommon.concat(runLP, "-cp", appJar, logArg, mainClass))
.assertNormalExit(output -> {
if (is_aligned_64k) {
output.shouldContain(logFor64K);
}
output.shouldContain("Hello World");
output.shouldContain(checkString)
.shouldContain("Hello World");
});
}
}

@ -397,7 +397,7 @@ public class WhiteBox {
public native long allocateMetaspace(ClassLoader classLoader, long size);
public native long incMetaspaceCapacityUntilGC(long increment);
public native long metaspaceCapacityUntilGC();
public native long metaspaceReserveAlignment();
public native long metaspaceSharedRegionAlignment();
// Metaspace Arena Tests
public native long createMetaspaceTestContext(long commit_limit, long reserve_limit);