Skip to content
Permalink
Browse files
8264540: WhiteBox.metaspaceReserveAlignment should return shared regi…
…on alignment

Reviewed-by: ccheung, iklam
  • Loading branch information
yminqi committed Apr 5, 2021
1 parent 104e925 commit d920f8588cc99792145b379c6bc53cad5ad8e62a
@@ -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 @@
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 @@ static void test(String... extra_options) throws Exception {
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 @@ static void test(String... extra_options) throws Exception {
}
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 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 static void getFileOffsetInfo() throws Exception {
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 static void modifyJsaContentRandomly(File jsaFile) 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 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 @@ static void testCombo() throws Exception {
// 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 @@ static void testCombo() throws Exception {
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 @@ static void testCombo() throws Exception {

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 void clearInlineCaches(boolean preserve_static_stubs) {
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);

1 comment on commit d920f85

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on d920f85 Apr 5, 2021

Please sign in to comment.