1 /* 2 * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @summary Test the various CPU-specific reservation schemes 27 * @requires vm.bits == 64 & !vm.graal.enabled & vm.debug == true 28 * @requires vm.flagless 29 * @requires vm.cds 30 * @requires (os.family != "windows") & (os.family != "aix") 31 * @library /test/lib 32 * @modules java.base/jdk.internal.misc 33 * java.management 34 * @run driver CompressedCPUSpecificClassSpaceReservation 35 */ 36 37 import jdk.test.lib.Platform; 38 import jdk.test.lib.process.OutputAnalyzer; 39 import jdk.test.lib.process.ProcessTools; 40 import jtreg.SkippedException; 41 42 import java.io.IOException; 43 44 public class CompressedCPUSpecificClassSpaceReservation { 45 // Note: windows: On windows, we currently have the issue that os::reserve_memory_aligned relies on 46 // os::attempt_reserve_memory_at because VirtualAlloc cannot be unmapped in parts; this precludes use of 47 // +SimulateFullAddressSpace (VM won't be able to reserve heap). Therefore we exclude the test for windows 48 // for now. 49 50 private static void do_test(boolean CDS) throws IOException { 51 // We start the VM with -XX:+SimulateFullAdressSpace, which means the JVM will go through all motions 52 // of reserving the cds+class space, but never succeed. That means we see every single allocation attempt. 53 // We start with -Xlog options enabled. The expected output goes like this: 54 // [0.017s][debug][os,map] reserve_between (range [0x0000000000000000-0x0000000100000000), size 0x41000000, alignment 0x1000000, randomize: 1) 55 ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder( 56 "-Xshare:" + (CDS ? "on" : "off"), 57 "-Xmx128m", 58 "-XX:CompressedClassSpaceSize=128m", 59 "-XX:+UnlockExperimentalVMOptions", "-XX:-UseCompactObjectHeaders", 60 "-Xlog:metaspace*", "-Xlog:metaspace+map=trace", "-Xlog:os+map=trace", 61 "-XX:+SimulateFullAddressSpace", // So that no resevation attempt will succeed 62 "-version"); 63 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 64 65 final String tryReserveForUnscaled = "reserve_between (range [0x0000000000000000-0x0000000100000000)"; 66 final String tryReserveForZeroBased = "reserve_between (range [0x0000000100000000-0x0000000800000000)"; 67 final String tryReserveFor16bitMoveIntoQ3 = "reserve_between (range [0x0000000100000000-0x0001000000000000)"; 68 if (Platform.isAArch64()) { 69 if (CDS) { 70 output.shouldNotContain(tryReserveForUnscaled); 71 } else { 72 output.shouldContain(tryReserveForUnscaled); 73 } 74 output.shouldContain("Trying to reserve at an EOR-compatible address"); 75 output.shouldNotContain(tryReserveForZeroBased); 76 output.shouldContain(tryReserveFor16bitMoveIntoQ3); 77 } else if (Platform.isPPC()) { 78 if (CDS) { 79 output.shouldNotContain(tryReserveForUnscaled); 80 output.shouldNotContain(tryReserveForZeroBased); 81 } else { 82 output.shouldContain(tryReserveForUnscaled); 83 output.shouldContain(tryReserveForZeroBased); 84 } 85 output.shouldContain(tryReserveFor16bitMoveIntoQ3); 86 } else if (Platform.isRISCV64()) { 87 output.shouldContain(tryReserveForUnscaled); // unconditionally 88 if (CDS) { 89 output.shouldNotContain(tryReserveForZeroBased); 90 // bits 32..44 91 output.shouldContain("reserve_between (range [0x0000000100000000-0x0000100000000000)"); 92 } else { 93 output.shouldContain(tryReserveForZeroBased); 94 // bits 32..44, but not lower than zero-based limit 95 output.shouldContain("reserve_between (range [0x0000000800000000-0x0000100000000000)"); 96 } 97 // bits 44..64 98 output.shouldContain("reserve_between (range [0x0000100000000000-0xffffffffffffffff)"); 99 } else if (Platform.isS390x()) { 100 output.shouldContain(tryReserveForUnscaled); // unconditionally 101 if (CDS) { 102 output.shouldNotContain(tryReserveForZeroBased); 103 } else { 104 output.shouldContain(tryReserveForZeroBased); 105 } 106 output.shouldContain(tryReserveFor16bitMoveIntoQ3); 107 } else if (Platform.isX64()) { 108 if (CDS) { 109 output.shouldNotContain(tryReserveForUnscaled); 110 output.shouldNotContain(tryReserveForZeroBased); 111 } else { 112 output.shouldContain(tryReserveForUnscaled); 113 output.shouldContain(tryReserveForZeroBased); 114 } 115 } else { 116 throw new RuntimeException("Unexpected platform"); 117 } 118 119 // In all cases we should have managed to map successfully eventually 120 if (CDS) { 121 output.shouldContain("CDS archive(s) mapped at:"); 122 } else { 123 output.shouldContain("CDS archive(s) not mapped"); 124 } 125 output.shouldContain("Compressed class space mapped at:"); 126 } 127 128 public static void main(String[] args) throws Exception { 129 System.out.println("Test with CDS"); 130 do_test(true); 131 System.out.println("Test without CDS"); 132 do_test(false); 133 } 134 }