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 "-Xlog:cds", 106 "Hello"); 107 out.shouldContain(UNABLE_TO_USE_ARCHIVE); 108 out.shouldContain(ERR_MSG); 109 out.shouldHaveExitValue(1); 110 111 System.out.println("4. Run with -UseCompressedOops +UseCompressedClassPointers"); 112 out = TestCommon 113 .exec(helloJar, 114 "-XX:+UseSerialGC", 115 "-XX:-UseCompressedOops", 116 "-XX:+UseCompressedClassPointers", 117 "-XX:+UnlockExperimentalVMOptions", 118 compactHeaders, 119 "-Xlog:cds", 120 "Hello"); 121 out.shouldContain(HELLO); 122 out.shouldHaveExitValue(0); 123 124 System.out.println("5. Run with +UseCompressedOops -UseCompressedClassPointers"); 125 out = TestCommon 126 .exec(helloJar, 127 "-XX:+UseSerialGC", 128 "-XX:+UseCompressedOops", 129 "-XX:-UseCompressedClassPointers", 130 "-Xlog:cds", 131 "Hello"); 132 out.shouldContain(UNABLE_TO_USE_ARCHIVE); 133 out.shouldContain(ERR_MSG); 134 out.shouldHaveExitValue(1); 135 136 System.out.println("6. Run with +UseCompressedOops +UseCompressedClassPointers"); 137 out = TestCommon 138 .exec(helloJar, 139 "-XX:+UseSerialGC", 140 "-XX:+UseCompressedOops", 141 "-XX:+UseCompressedClassPointers", 142 "-XX:+UnlockExperimentalVMOptions", 143 compactHeaders, 144 "-Xlog:cds", 145 "Hello"); 146 out.shouldContain(UNABLE_TO_USE_ARCHIVE); 147 out.shouldContain(ERR_MSG); 148 out.shouldHaveExitValue(1); 149 150 System.out.println("7. Dump with -UseCompressedOops -UseCompressedClassPointers"); 151 out = TestCommon 152 .dump(helloJar, 153 new String[] {"Hello"}, 154 "-XX:+UseSerialGC", 155 "-XX:-UseCompressedOops", 156 "-XX:+UseCompressedClassPointers", 157 "-XX:+UnlockExperimentalVMOptions", 158 compactHeaders, 159 "-Xlog:cds"); 160 out.shouldContain("Dumping shared data to file:"); 161 out.shouldHaveExitValue(0); 162 163 System.out.println("8. Run with ZGC"); 164 out = TestCommon 165 .exec(helloJar, 166 "-XX:+UseZGC", 167 zGenerational, 168 "-XX:+UnlockExperimentalVMOptions", 169 compactHeaders, 170 "-Xlog:cds", 171 "Hello"); 172 out.shouldContain(HELLO); 173 out.shouldHaveExitValue(0); 174 } 175 }