Skip to content

Commit d920f85

Browse files
committed
8264540: WhiteBox.metaspaceReserveAlignment should return shared region alignment
Reviewed-by: ccheung, iklam
1 parent 104e925 commit d920f85

File tree

5 files changed

+27
-18
lines changed

5 files changed

+27
-18
lines changed

src/hotspot/share/prims/whitebox.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,8 +1778,14 @@ WB_ENTRY(jlong, WB_MetaspaceCapacityUntilGC(JNIEnv* env, jobject wb))
17781778
return (jlong) MetaspaceGC::capacity_until_GC();
17791779
WB_END
17801780

1781-
WB_ENTRY(jlong, WB_MetaspaceReserveAlignment(JNIEnv* env, jobject wb))
1782-
return (jlong)Metaspace::reserve_alignment();
1781+
// The function is only valid when CDS is available.
1782+
WB_ENTRY(jlong, WB_MetaspaceSharedRegionAlignment(JNIEnv* env, jobject wb))
1783+
#if INCLUDE_CDS
1784+
return (jlong)MetaspaceShared::core_region_alignment();
1785+
#else
1786+
ShouldNotReachHere();
1787+
return 0L;
1788+
#endif
17831789
WB_END
17841790

17851791
WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj))
@@ -2503,7 +2509,7 @@ static JNINativeMethod methods[] = {
25032509
CC"(Ljava/lang/ClassLoader;J)J", (void*)&WB_AllocateMetaspace },
25042510
{CC"incMetaspaceCapacityUntilGC", CC"(J)J", (void*)&WB_IncMetaspaceCapacityUntilGC },
25052511
{CC"metaspaceCapacityUntilGC", CC"()J", (void*)&WB_MetaspaceCapacityUntilGC },
2506-
{CC"metaspaceReserveAlignment", CC"()J", (void*)&WB_MetaspaceReserveAlignment },
2512+
{CC"metaspaceSharedRegionAlignment", CC"()J", (void*)&WB_MetaspaceSharedRegionAlignment },
25072513
{CC"getCPUFeatures", CC"()Ljava/lang/String;", (void*)&WB_GetCPUFeatures },
25082514
{CC"getNMethod0", CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;",
25092515
(void*)&WB_GetNMethod },

test/hotspot/jtreg/runtime/cds/SpaceUtilizationCheck.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
public class SpaceUtilizationCheck {
4646
// For the RW/RO regions:
4747
// [1] Each region must have strictly less than
48-
// WhiteBox.metaspaceReserveAlignment() bytes of unused space.
48+
// WhiteBox.metaspaceSharedRegionAlignment() bytes of unused space.
4949
// [2] There must be no gap between two consecutive regions.
5050

5151
public static void main(String[] args) throws Exception {
@@ -58,8 +58,8 @@ static void test(String... extra_options) throws Exception {
5858
OutputAnalyzer output = CDSTestUtils.createArchiveAndCheck(opts);
5959
Pattern pattern = Pattern.compile("(..) space: *([0-9]+).* out of *([0-9]+) bytes .* at 0x([0-9a0-f]+)");
6060
WhiteBox wb = WhiteBox.getWhiteBox();
61-
long reserve_alignment = wb.metaspaceReserveAlignment();
62-
System.out.println("Metaspace::reserve_alignment() = " + reserve_alignment);
61+
long reserve_alignment = wb.metaspaceSharedRegionAlignment();
62+
System.out.println("MetaspaceShared::core_region_alignment() = " + reserve_alignment);
6363

6464
// Look for output like this. The pattern will only match the first 2 regions, which is what we need to check
6565
//
@@ -88,7 +88,7 @@ static void test(String... extra_options) throws Exception {
8888
}
8989
if (unused > reserve_alignment) {
9090
// [1] Check for unused space
91-
throw new RuntimeException("Unused space (" + unused + ") must be smaller than Metaspace::reserve_alignment() (" +
91+
throw new RuntimeException("Unused space (" + unused + ") must be smaller than MetaspaceShared::core_region_alignment() (" +
9292
reserve_alignment + ")");
9393
}
9494
if (last_region >= 0 && address != last_region) {

test/hotspot/jtreg/runtime/cds/appcds/SharedArchiveConsistency.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public class SharedArchiveConsistency {
6767
public static int sp_used_offset; // offset of CDSFileMapRegion::_used
6868
public static int size_t_size; // size of size_t
6969
public static int int_size; // size of int
70+
public static long alignment; // MetaspaceShared::core_region_alignment
7071

7172
// The following should be consistent with the enum in the C++ MetaspaceShared class
7273
public static String[] shared_region_name = {
@@ -104,6 +105,7 @@ public static void getFileOffsetInfo() throws Exception {
104105
sp_used_offset = wb.getOffsetForName("CDSFileMapRegion::_used") - sp_offset_crc;
105106
size_t_size = wb.getOffsetForName("size_t_size");
106107
CDSFileMapRegion_size = wb.getOffsetForName("CDSFileMapRegion_size");
108+
alignment = wb.metaspaceSharedRegionAlignment();
107109
}
108110

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

196198
static long get_region_used_size_aligned(FileChannel fc, int region) throws Exception {
197199
long n = sp_offset + CDSFileMapRegion_size * region + sp_used_offset;
198-
long alignment = WhiteBox.getWhiteBox().metaspaceReserveAlignment();
199200
long used = readInt(fc, n, size_t_size);
200201
used = (used + alignment - 1) & ~(alignment - 1);
201202
return used;

test/hotspot/jtreg/runtime/cds/appcds/SharedRegionAlignmentTest.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@
3131
* disable it if ZGC is used.
3232
* @bug 8236847
3333
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds/test-classes
34+
* @build sun.hotspot.WhiteBox
3435
* @build Hello
36+
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
3537
* @run driver jdk.test.lib.helpers.ClassFileInstaller -jar hello.jar Hello
36-
* @run driver SharedRegionAlignmentTest
38+
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. SharedRegionAlignmentTest
3739
*/
3840

41+
3942
import jdk.test.lib.process.OutputAnalyzer;
4043
import jdk.test.lib.helpers.ClassFileInstaller;
44+
import sun.hotspot.WhiteBox;
4145

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

5359
String [][] largePageArgs = {
5460
{}, // default
5561
{UseLargePages}
5662
};
5763

58-
final String logFor64K = "core_region_alignment = 65535";
59-
6064
int dumpCase = 0;
6165
for (String[] dumpLP: largePageArgs) {
6266
dumpCase ++;
@@ -67,8 +71,8 @@ static void testCombo() throws Exception {
6771
OutputAnalyzer out = TestCommon.dump(appJar,
6872
TestCommon.list(mainClass),
6973
TestCommon.concat(dumpLP, logArg));
70-
out.shouldContain("Dumping shared data to file");
71-
boolean is_aligned_64k = out.getStdout().contains(logFor64K);
74+
out.shouldContain("Dumping shared data to file")
75+
.shouldContain(checkString);
7276

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

8084
TestCommon.run(TestCommon.concat(runLP, "-cp", appJar, logArg, mainClass))
8185
.assertNormalExit(output -> {
82-
if (is_aligned_64k) {
83-
output.shouldContain(logFor64K);
84-
}
85-
output.shouldContain("Hello World");
86+
output.shouldContain(checkString)
87+
.shouldContain("Hello World");
8688
});
8789
}
8890
}

test/lib/sun/hotspot/WhiteBox.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ public void clearInlineCaches(boolean preserve_static_stubs) {
397397
public native long allocateMetaspace(ClassLoader classLoader, long size);
398398
public native long incMetaspaceCapacityUntilGC(long increment);
399399
public native long metaspaceCapacityUntilGC();
400-
public native long metaspaceReserveAlignment();
400+
public native long metaspaceSharedRegionAlignment();
401401

402402
// Metaspace Arena Tests
403403
public native long createMetaspaceTestContext(long commit_limit, long reserve_limit);

0 commit comments

Comments
 (0)