< prev index next > test/hotspot/jtreg/runtime/CompressedOops/CompressedClassPointersEncodingScheme.java
Print this page
/*
! * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
/*
! * Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
import java.io.IOException;
public class CompressedClassPointersEncodingScheme {
! private static void test(long forceAddress, long classSpaceSize, long expectedEncodingBase, int expectedEncodingShift) throws IOException {
String forceAddressString = String.format("0x%016X", forceAddress).toLowerCase();
String expectedEncodingBaseString = String.format("0x%016X", expectedEncodingBase).toLowerCase();
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-Xshare:off", // to make CompressedClassSpaceBaseAddress work
"-XX:+UnlockDiagnosticVMOptions",
"-XX:-UseCompressedOops", // keep VM from optimizing heap location
"-XX:CompressedClassSpaceBaseAddress=" + forceAddress,
"-XX:CompressedClassSpaceSize=" + classSpaceSize,
"-Xmx128m",
"-Xlog:metaspace*",
"-version");
import java.io.IOException;
public class CompressedClassPointersEncodingScheme {
! private static void test(long forceAddress, boolean COH, long classSpaceSize, long expectedEncodingBase, int expectedEncodingShift) throws IOException {
String forceAddressString = String.format("0x%016X", forceAddress).toLowerCase();
String expectedEncodingBaseString = String.format("0x%016X", expectedEncodingBase).toLowerCase();
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-Xshare:off", // to make CompressedClassSpaceBaseAddress work
"-XX:+UnlockDiagnosticVMOptions",
"-XX:-UseCompressedOops", // keep VM from optimizing heap location
+ "-XX:+UnlockExperimentalVMOptions",
+ "-XX:" + (COH ? "+" : "-") + "UseCompactObjectHeaders",
+ "-XX:" + (COH ? "+" : "-") + "UseObjectMonitorTable",
"-XX:CompressedClassSpaceBaseAddress=" + forceAddress,
"-XX:CompressedClassSpaceSize=" + classSpaceSize,
"-Xmx128m",
"-Xlog:metaspace*",
"-version");
output.reportDiagnosticSummary();
// We ignore cases where we were not able to map at the force address
if (output.contains("reserving class space failed")) {
! throw new SkippedException("Skipping because we cannot force ccs to " + forceAddressString);
}
output.shouldHaveExitValue(0);
output.shouldContain("Narrow klass base: " + expectedEncodingBaseString + ", Narrow klass shift: " + expectedEncodingShift);
}
output.reportDiagnosticSummary();
// We ignore cases where we were not able to map at the force address
if (output.contains("reserving class space failed")) {
! System.out.println("Skipping because we cannot force ccs to " + forceAddressString);
+ return;
}
output.shouldHaveExitValue(0);
output.shouldContain("Narrow klass base: " + expectedEncodingBaseString + ", Narrow klass shift: " + expectedEncodingShift);
}
final static long M = K * 1024;
final static long G = M * 1024;
public static void main(String[] args) throws Exception {
// Test ccs nestling right at the end of the 4G range
// Expecting base=0, shift=0
! test(4 * G - 128 * M, 128 * M, 0, 0);
// add more...
}
}
final static long M = K * 1024;
final static long G = M * 1024;
public static void main(String[] args) throws Exception {
// Test ccs nestling right at the end of the 4G range
// Expecting base=0, shift=0
! test(4 * G - 128 * M, false, 128 * M, 0, 0);
+ // Test ccs nestling right at the end of the 32G range
+ // Expecting:
+ // - non-aarch64: base=0, shift=3
+ // - aarch64: base to start of class range, shift 0
+ if (Platform.isAArch64()) {
+ // The best we can do on aarch64 is to be *near* the end of the 32g range, since a valid encoding base
+ // on aarch64 must be 4G aligned, and the max. class space size is 3G.
+ long forceAddress = 0x7_0000_0000L; // 28g, and also a valid EOR immediate
+ test(forceAddress, false, 3 * G, forceAddress, 0);
+ } else {
+ test(32 * G - 128 * M, false, 128 * M, 0, 3);
+ }
+
+ // Test ccs starting *below* 4G, but extending upwards beyond 4G. All platforms except aarch64 should pick
+ // zero based encoding.
+ if (Platform.isAArch64()) {
+ long forceAddress = 0xC000_0000L; // make sure we have a valid EOR immediate
+ test(forceAddress, false, G + (128 * M), forceAddress, 0);
+ } else {
+ test(4 * G - 128 * M, false, 2 * 128 * M, 0, 3);
+ }
// add more...
+ // Compact Object Header Mode with tiny classpointers
+ // On all platforms we expect the VM to chose the smallest possible shift value needed to cover the encoding range
+ long forceAddress = 30 * G;
+
+ long ccsSize = 128 * M;
+ int expectedShift = 6;
+ test(forceAddress, true, ccsSize, forceAddress, expectedShift);
+
+ ccsSize = 512 * M;
+ expectedShift = 8;
+ test(forceAddress, true, ccsSize, forceAddress, expectedShift);
+
+ ccsSize = G;
+ expectedShift = 9;
+ test(forceAddress, true, ccsSize, forceAddress, expectedShift);
+
+ ccsSize = 3 * G;
+ expectedShift = 10;
+ test(forceAddress, true, ccsSize, forceAddress, expectedShift);
}
}
< prev index next >