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