1 /* 2 * Copyright (c) 2020, 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 id=ZSinglegen 26 * @bug 8232069 27 * @requires vm.cds 28 * @requires vm.bits == 64 29 * @requires vm.gc.ZSinglegen 30 * @requires vm.gc.Serial 31 * @requires vm.gc == null 32 * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds 33 * @compile test-classes/Hello.java 34 * @run driver TestZGCWithCDS -XX:-ZGenerational 35 */ 36 37 /* 38 * @test id=ZGenerational 39 * @bug 8232069 40 * @requires vm.cds 41 * @requires vm.bits == 64 42 * @requires vm.gc.ZGenerational 43 * @requires vm.gc.Serial 44 * @requires vm.gc == null 45 * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds 46 * @compile test-classes/Hello.java 47 * @run driver TestZGCWithCDS -XX:+ZGenerational 48 */ 49 50 import jdk.test.lib.Platform; 51 import jdk.test.lib.process.OutputAnalyzer; 52 53 public class TestZGCWithCDS { 54 public final static String HELLO = "Hello World"; 55 public final static String UNABLE_TO_USE_ARCHIVE = "Unable to use shared archive."; 56 public final static String ERR_MSG = "The saved state of UseCompressedOops and UseCompressedClassPointers is different from runtime, CDS will be disabled."; 57 public static void main(String... args) throws Exception { 58 String zGenerational = args[0]; 59 String compactHeaders = "-XX:" + (zGenerational.equals("-XX:+ZGenerational") ? "+" : "-") + "UseCompactObjectHeaders"; 60 String helloJar = JarBuilder.build("hello", "Hello"); 61 System.out.println("0. Dump with ZGC"); 62 OutputAnalyzer out = TestCommon 63 .dump(helloJar, 64 new String[] {"Hello"}, 65 "-XX:+UseZGC", 66 zGenerational, 67 "-XX:+UnlockExperimentalVMOptions", 68 compactHeaders, 69 "-Xlog:cds"); 70 out.shouldContain("Dumping shared data to file:"); 71 out.shouldHaveExitValue(0); 72 73 System.out.println("1. Run with same args of dump"); 74 out = TestCommon 75 .exec(helloJar, 76 "-XX:+UseZGC", 77 zGenerational, 78 "-XX:+UnlockExperimentalVMOptions", 79 compactHeaders, 80 "-Xlog:cds", 81 "Hello"); 82 out.shouldContain(HELLO); 83 out.shouldHaveExitValue(0); 84 85 System.out.println("2. Run with +UseCompressedOops +UseCompressedClassPointers"); 86 out = TestCommon 87 .exec(helloJar, 88 "-XX:-UseZGC", 89 "-XX:+UseCompressedOops", // in case turned off by vmoptions 90 "-XX:+UseCompressedClassPointers", // by jtreg 91 "-XX:+UnlockExperimentalVMOptions", 92 compactHeaders, 93 "-Xlog:cds", 94 "Hello"); 95 out.shouldContain(UNABLE_TO_USE_ARCHIVE); 96 out.shouldContain(ERR_MSG); 97 out.shouldHaveExitValue(1); 98 99 System.out.println("3. Run with -UseCompressedOops -UseCompressedClassPointers"); 100 out = TestCommon 101 .exec(helloJar, 102 "-XX:+UseSerialGC", 103 "-XX:-UseCompressedOops", 104 "-XX:-UseCompressedClassPointers", 105 "-XX:+UnlockExperimentalVMOptions", 106 compactHeaders, 107 "-Xlog:cds", 108 "Hello"); 109 out.shouldContain(UNABLE_TO_USE_ARCHIVE); 110 out.shouldContain(ERR_MSG); 111 out.shouldHaveExitValue(1); 112 113 System.out.println("4. Run with -UseCompressedOops +UseCompressedClassPointers"); 114 out = TestCommon 115 .exec(helloJar, 116 "-XX:+UseSerialGC", 117 "-XX:-UseCompressedOops", 118 "-XX:+UseCompressedClassPointers", 119 "-XX:+UnlockExperimentalVMOptions", 120 compactHeaders, 121 "-Xlog:cds", 122 "Hello"); 123 out.shouldContain(HELLO); 124 out.shouldHaveExitValue(0); 125 126 System.out.println("5. Run with +UseCompressedOops -UseCompressedClassPointers"); 127 out = TestCommon 128 .exec(helloJar, 129 "-XX:+UseSerialGC", 130 "-XX:+UseCompressedOops", 131 "-XX:-UseCompressedClassPointers", 132 "-XX:+UnlockExperimentalVMOptions", 133 compactHeaders, 134 "-Xlog:cds", 135 "Hello"); 136 out.shouldContain(UNABLE_TO_USE_ARCHIVE); 137 out.shouldContain(ERR_MSG); 138 out.shouldHaveExitValue(1); 139 140 System.out.println("6. Run with +UseCompressedOops +UseCompressedClassPointers"); 141 out = TestCommon 142 .exec(helloJar, 143 "-XX:+UseSerialGC", 144 "-XX:+UseCompressedOops", 145 "-XX:+UseCompressedClassPointers", 146 "-XX:+UnlockExperimentalVMOptions", 147 compactHeaders, 148 "-Xlog:cds", 149 "Hello"); 150 out.shouldContain(UNABLE_TO_USE_ARCHIVE); 151 out.shouldContain(ERR_MSG); 152 out.shouldHaveExitValue(1); 153 154 System.out.println("7. Dump with -UseCompressedOops -UseCompressedClassPointers"); 155 out = TestCommon 156 .dump(helloJar, 157 new String[] {"Hello"}, 158 "-XX:+UseSerialGC", 159 "-XX:-UseCompressedOops", 160 "-XX:+UseCompressedClassPointers", 161 "-XX:+UnlockExperimentalVMOptions", 162 compactHeaders, 163 "-Xlog:cds"); 164 out.shouldContain("Dumping shared data to file:"); 165 out.shouldHaveExitValue(0); 166 167 System.out.println("8. Run with ZGC"); 168 out = TestCommon 169 .exec(helloJar, 170 "-XX:+UseZGC", 171 zGenerational, 172 "-XX:+UnlockExperimentalVMOptions", 173 compactHeaders, 174 "-Xlog:cds", 175 "Hello"); 176 out.shouldContain(HELLO); 177 out.shouldHaveExitValue(0); 178 } 179 }