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                                         "-XX:+UnlockExperimentalVMOptions",
 51                                         "-XX:-UseCompactObjectHeaders",
 52                                         "-Xlog:cds");
 53          out.shouldContain("Dumping shared data to file:");
 54          out.shouldHaveExitValue(0);
 55 
 56          System.out.println("1. Run with same args of dump");
 57          out = TestCommon
 58                    .exec(helloJar,
 59                          "-XX:+UseZGC",
 60                          "-XX:+UnlockExperimentalVMOptions",
 61                          "-XX:-UseCompactObjectHeaders",
 62                          "-Xlog:cds",
 63                          "Hello");
 64          out.shouldContain(HELLO);
 65          out.shouldHaveExitValue(0);
 66 
 67          System.out.println("2. Run with +UseCompressedOops +UseCompressedClassPointers");
 68          out = TestCommon
 69                    .exec(helloJar,
 70                          "-XX:-UseZGC",
 71                          "-XX:+UseCompressedOops",           // in case turned off by vmoptions
 72                          "-XX:+UseCompressedClassPointers",  // by jtreg
 73                          "-XX:+UnlockExperimentalVMOptions",
 74                          "-XX:-UseCompactObjectHeaders",
 75                          "-Xlog:cds",
 76                          "Hello");
 77          out.shouldContain(UNABLE_TO_USE_ARCHIVE);
 78          out.shouldContain(ERR_MSG);
 79          out.shouldHaveExitValue(1);
 80 
 81          System.out.println("3. Run with -UseCompressedOops -UseCompressedClassPointers");
 82          out = TestCommon
 83                    .exec(helloJar,
 84                          "-XX:+UseSerialGC",
 85                          "-XX:-UseCompressedOops",
 86                          "-XX:-UseCompressedClassPointers",
 87                          "-XX:+UnlockExperimentalVMOptions",
 88                          "-XX:-UseCompactObjectHeaders",
 89                          "-Xlog:cds",
 90                          "Hello");
 91          out.shouldContain(UNABLE_TO_USE_ARCHIVE);
 92          out.shouldContain(ERR_MSG);
 93          out.shouldHaveExitValue(1);
 94 
 95          System.out.println("4. Run with -UseCompressedOops +UseCompressedClassPointers");
 96          out = TestCommon
 97                    .exec(helloJar,
 98                          "-XX:+UseSerialGC",
 99                          "-XX:-UseCompressedOops",
100                          "-XX:+UseCompressedClassPointers",
101                          "-XX:+UnlockExperimentalVMOptions",
102                          "-XX:-UseCompactObjectHeaders",
103                          "-Xlog:cds",
104                          "Hello");
105          out.shouldContain(HELLO);
106          out.shouldHaveExitValue(0);
107 
108          System.out.println("5. Run with +UseCompressedOops -UseCompressedClassPointers");
109          out = TestCommon
110                    .exec(helloJar,
111                          "-XX:+UseSerialGC",
112                          "-XX:+UseCompressedOops",
113                          "-XX:-UseCompressedClassPointers",
114                          "-XX:+UnlockExperimentalVMOptions",
115                          "-XX:-UseCompactObjectHeaders",
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("6. Run with +UseCompressedOops +UseCompressedClassPointers");
123          out = TestCommon
124                    .exec(helloJar,
125                          "-XX:+UseSerialGC",
126                          "-XX:+UseCompressedOops",
127                          "-XX:+UseCompressedClassPointers",
128                          "-XX:+UnlockExperimentalVMOptions",
129                          "-XX:-UseCompactObjectHeaders",
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("7. Dump with -UseCompressedOops -UseCompressedClassPointers");
137          out = TestCommon
138                    .dump(helloJar,
139                          new String[] {"Hello"},
140                          "-XX:+UseSerialGC",
141                          "-XX:-UseCompressedOops",
142                          "-XX:+UseCompressedClassPointers",
143                          "-XX:+UnlockExperimentalVMOptions",
144                          "-XX:-UseCompactObjectHeaders",
145                          "-Xlog:cds");
146          out.shouldContain("Dumping shared data to file:");
147          out.shouldHaveExitValue(0);
148 
149          System.out.println("8. Run with ZGC");
150          out = TestCommon
151                    .exec(helloJar,
152                          "-XX:+UseZGC",
153                          "-XX:+UnlockExperimentalVMOptions",
154                          "-XX:-UseCompactObjectHeaders",
155                          "-Xlog:cds",
156                          "Hello");
157          out.shouldContain(HELLO);
158          out.shouldHaveExitValue(0);
159     }
160 }