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(HELLO);
 84          out.shouldHaveExitValue(0);
 85 
 86          System.out.println("4. Run with +UseCompressedOops +UseCompressedClassPointers");












 87          out = TestCommon
 88                    .exec(helloJar,
 89                          "-XX:+UseSerialGC",
 90                          "-XX:+UseCompressedOops",
 91                          "-XX:+UseCompressedClassPointers",
 92                          "-Xlog:cds",
 93                          "Hello");
 94          out.shouldContain(UNABLE_TO_USE_ARCHIVE);
 95          out.shouldContain(ERR_MSG);
 96          out.shouldHaveExitValue(1);
 97 
 98          System.out.println("5. Run with ZGC");











 99          out = TestCommon
100                    .exec(helloJar,
101                          "-XX:+UseZGC",
102                          "-Xlog:cds",
103                          "Hello");
104          out.shouldContain(HELLO);
105          out.shouldHaveExitValue(0);
106     }
107 }
--- EOF ---