Skip to content

Commit

Permalink
8264540: WhiteBox.metaspaceReserveAlignment should return shared regi…
Browse files Browse the repository at this point in the history
…on alignment

Reviewed-by: ccheung, iklam
  • Loading branch information
yminqi committed Apr 5, 2021
1 parent 104e925 commit d920f85
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
12 changes: 9 additions & 3 deletions src/hotspot/share/prims/whitebox.cpp
Expand Up @@ -1778,8 +1778,14 @@ WB_ENTRY(jlong, WB_MetaspaceCapacityUntilGC(JNIEnv* env, jobject wb))
return (jlong) MetaspaceGC::capacity_until_GC(); return (jlong) MetaspaceGC::capacity_until_GC();
WB_END WB_END


WB_ENTRY(jlong, WB_MetaspaceReserveAlignment(JNIEnv* env, jobject wb)) // The function is only valid when CDS is available.
return (jlong)Metaspace::reserve_alignment(); 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_END


WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj)) WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj))
Expand Down Expand Up @@ -2503,7 +2509,7 @@ static JNINativeMethod methods[] = {
CC"(Ljava/lang/ClassLoader;J)J", (void*)&WB_AllocateMetaspace }, CC"(Ljava/lang/ClassLoader;J)J", (void*)&WB_AllocateMetaspace },
{CC"incMetaspaceCapacityUntilGC", CC"(J)J", (void*)&WB_IncMetaspaceCapacityUntilGC }, {CC"incMetaspaceCapacityUntilGC", CC"(J)J", (void*)&WB_IncMetaspaceCapacityUntilGC },
{CC"metaspaceCapacityUntilGC", CC"()J", (void*)&WB_MetaspaceCapacityUntilGC }, {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"getCPUFeatures", CC"()Ljava/lang/String;", (void*)&WB_GetCPUFeatures },
{CC"getNMethod0", CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;", {CC"getNMethod0", CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;",
(void*)&WB_GetNMethod }, (void*)&WB_GetNMethod },
Expand Down
8 changes: 4 additions & 4 deletions test/hotspot/jtreg/runtime/cds/SpaceUtilizationCheck.java
Expand Up @@ -45,7 +45,7 @@
public class SpaceUtilizationCheck { public class SpaceUtilizationCheck {
// For the RW/RO regions: // For the RW/RO regions:
// [1] Each region must have strictly less than // [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. // [2] There must be no gap between two consecutive regions.


public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Expand All @@ -58,8 +58,8 @@ static void test(String... extra_options) throws Exception {
OutputAnalyzer output = CDSTestUtils.createArchiveAndCheck(opts); OutputAnalyzer output = CDSTestUtils.createArchiveAndCheck(opts);
Pattern pattern = Pattern.compile("(..) space: *([0-9]+).* out of *([0-9]+) bytes .* at 0x([0-9a0-f]+)"); Pattern pattern = Pattern.compile("(..) space: *([0-9]+).* out of *([0-9]+) bytes .* at 0x([0-9a0-f]+)");
WhiteBox wb = WhiteBox.getWhiteBox(); WhiteBox wb = WhiteBox.getWhiteBox();
long reserve_alignment = wb.metaspaceReserveAlignment(); long reserve_alignment = wb.metaspaceSharedRegionAlignment();
System.out.println("Metaspace::reserve_alignment() = " + reserve_alignment); 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 // Look for output like this. The pattern will only match the first 2 regions, which is what we need to check
// //
Expand Down Expand Up @@ -88,7 +88,7 @@ static void test(String... extra_options) throws Exception {
} }
if (unused > reserve_alignment) { if (unused > reserve_alignment) {
// [1] Check for unused space // [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 + ")"); reserve_alignment + ")");
} }
if (last_region >= 0 && address != last_region) { if (last_region >= 0 && address != last_region) {
Expand Down
Expand Up @@ -67,6 +67,7 @@ public class SharedArchiveConsistency {
public static int sp_used_offset; // offset of CDSFileMapRegion::_used public static int sp_used_offset; // offset of CDSFileMapRegion::_used
public static int size_t_size; // size of size_t public static int size_t_size; // size of size_t
public static int int_size; // size of int 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 // The following should be consistent with the enum in the C++ MetaspaceShared class
public static String[] shared_region_name = { public static String[] shared_region_name = {
Expand Down Expand Up @@ -104,6 +105,7 @@ public static void getFileOffsetInfo() throws Exception {
sp_used_offset = wb.getOffsetForName("CDSFileMapRegion::_used") - sp_offset_crc; sp_used_offset = wb.getOffsetForName("CDSFileMapRegion::_used") - sp_offset_crc;
size_t_size = wb.getOffsetForName("size_t_size"); size_t_size = wb.getOffsetForName("size_t_size");
CDSFileMapRegion_size = wb.getOffsetForName("CDSFileMapRegion_size"); CDSFileMapRegion_size = wb.getOffsetForName("CDSFileMapRegion_size");
alignment = wb.metaspaceSharedRegionAlignment();
} }


public static int getFileHeaderSize(FileChannel fc) throws Exception { public static int getFileHeaderSize(FileChannel fc) throws Exception {
Expand Down Expand Up @@ -195,7 +197,6 @@ public static void modifyJsaContentRandomly(File jsaFile) throws Exception {


static long get_region_used_size_aligned(FileChannel fc, int region) throws Exception { static long get_region_used_size_aligned(FileChannel fc, int region) throws Exception {
long n = sp_offset + CDSFileMapRegion_size * region + sp_used_offset; long n = sp_offset + CDSFileMapRegion_size * region + sp_used_offset;
long alignment = WhiteBox.getWhiteBox().metaspaceReserveAlignment();
long used = readInt(fc, n, size_t_size); long used = readInt(fc, n, size_t_size);
used = (used + alignment - 1) & ~(alignment - 1); used = (used + alignment - 1) & ~(alignment - 1);
return used; return used;
Expand Down
Expand Up @@ -31,13 +31,17 @@
* disable it if ZGC is used. * disable it if ZGC is used.
* @bug 8236847 * @bug 8236847
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds/test-classes * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds/test-classes
* @build sun.hotspot.WhiteBox
* @build Hello * @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 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.process.OutputAnalyzer;
import jdk.test.lib.helpers.ClassFileInstaller; import jdk.test.lib.helpers.ClassFileInstaller;
import sun.hotspot.WhiteBox;


public class SharedRegionAlignmentTest { public class SharedRegionAlignmentTest {
static String appJar = ClassFileInstaller.getJarPath("hello.jar"); static String appJar = ClassFileInstaller.getJarPath("hello.jar");
Expand All @@ -49,14 +53,14 @@ static void testCombo() throws Exception {
// Dump (3 combinations): largePageArgs // Dump (3 combinations): largePageArgs
// Run (3 combinations): largePageArgs // Run (3 combinations): largePageArgs
String UseLargePages = "-XX:+UseLargePages"; String UseLargePages = "-XX:+UseLargePages";
String checkString = "Core region alignment: " +
WhiteBox.getWhiteBox().metaspaceSharedRegionAlignment();


String [][] largePageArgs = { String [][] largePageArgs = {
{}, // default {}, // default
{UseLargePages} {UseLargePages}
}; };


final String logFor64K = "core_region_alignment = 65535";

int dumpCase = 0; int dumpCase = 0;
for (String[] dumpLP: largePageArgs) { for (String[] dumpLP: largePageArgs) {
dumpCase ++; dumpCase ++;
Expand All @@ -67,8 +71,8 @@ static void testCombo() throws Exception {
OutputAnalyzer out = TestCommon.dump(appJar, OutputAnalyzer out = TestCommon.dump(appJar,
TestCommon.list(mainClass), TestCommon.list(mainClass),
TestCommon.concat(dumpLP, logArg)); TestCommon.concat(dumpLP, logArg));
out.shouldContain("Dumping shared data to file"); out.shouldContain("Dumping shared data to file")
boolean is_aligned_64k = out.getStdout().contains(logFor64K); .shouldContain(checkString);


int runCase = 0; int runCase = 0;
for (String[] runLP: largePageArgs) { for (String[] runLP: largePageArgs) {
Expand All @@ -79,10 +83,8 @@ static void testCombo() throws Exception {


TestCommon.run(TestCommon.concat(runLP, "-cp", appJar, logArg, mainClass)) TestCommon.run(TestCommon.concat(runLP, "-cp", appJar, logArg, mainClass))
.assertNormalExit(output -> { .assertNormalExit(output -> {
if (is_aligned_64k) { output.shouldContain(checkString)
output.shouldContain(logFor64K); .shouldContain("Hello World");
}
output.shouldContain("Hello World");
}); });
} }
} }
Expand Down
2 changes: 1 addition & 1 deletion test/lib/sun/hotspot/WhiteBox.java
Expand Up @@ -397,7 +397,7 @@ public void clearInlineCaches(boolean preserve_static_stubs) {
public native long allocateMetaspace(ClassLoader classLoader, long size); public native long allocateMetaspace(ClassLoader classLoader, long size);
public native long incMetaspaceCapacityUntilGC(long increment); public native long incMetaspaceCapacityUntilGC(long increment);
public native long metaspaceCapacityUntilGC(); public native long metaspaceCapacityUntilGC();
public native long metaspaceReserveAlignment(); public native long metaspaceSharedRegionAlignment();


// Metaspace Arena Tests // Metaspace Arena Tests
public native long createMetaspaceTestContext(long commit_limit, long reserve_limit); public native long createMetaspaceTestContext(long commit_limit, long reserve_limit);
Expand Down

1 comment on commit d920f85

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.