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