Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8264540: WhiteBox.metaspaceReserveAlignment should return shared region alignment #3309

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

@@ -1780,8 +1780,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))
@@ -2505,7 +2511,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);
ProTip! Use n and p to navigate between commits in a pull request.