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 26 * @bug 8232069 27 * @summary Testing different combination of CompressedOops and CompressedClassPointers 28 * @requires vm.cds 29 * @requires vm.gc == "null" 30 * @requires vm.bits == 64 31 * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds 32 * @compile test-classes/Hello.java 33 * @modules java.base/jdk.internal.misc 34 * @run driver TestCombinedCompressedFlags 35 */ 36 37 import jdk.test.lib.process.OutputAnalyzer; 38 import java.util.List; 39 import java.util.ArrayList; 40 41 public class TestCombinedCompressedFlags { 42 public static String HELLO_STRING = "Hello World"; 43 public static String EXEC_ABNORMAL_MSG = "Unable to use shared archive."; 44 public static final int PASS = 0; 45 public static final int FAIL = 1; 46 47 static class ConfArg { 48 public boolean useCompressedOops; // UseCompressedOops 49 public String msg; 50 public int code; 51 public ConfArg(boolean useCompressedOops, String msg, int code) { 52 this.useCompressedOops = useCompressedOops; 53 this.msg = msg; 54 this.code = code; 55 } 56 } 57 58 static class RunArg { 59 public ConfArg dumpArg; 60 public List<ConfArg> execArgs; 61 public RunArg(ConfArg arg) { 62 dumpArg = arg; 63 initExecArgs(); 64 } 65 private void initExecArgs() { 66 /* The combinations have four cases. 67 * UseCompressedOops Result 68 * 1. 69 * dump: on 70 * test: on Pass 71 * off Fail 72 * 2. 73 * dump: off 74 * test: off Pass 75 * on Fail 76 **/ 77 execArgs = new ArrayList<ConfArg>(); 78 if (dumpArg.useCompressedOops) { 79 execArgs 80 .add(new ConfArg(true, HELLO_STRING, PASS)); 81 execArgs 82 .add(new ConfArg(false, EXEC_ABNORMAL_MSG, FAIL)); 83 84 } else if (!dumpArg.useCompressedOops) { 85 execArgs 86 .add(new ConfArg(false, HELLO_STRING, PASS)); 87 execArgs 88 .add(new ConfArg(true, EXEC_ABNORMAL_MSG, FAIL)); 89 } 90 } 91 } 92 93 public static String getCompressedOopsArg(boolean on) { 94 if (on) return "-XX:+UseCompressedOops"; 95 else return "-XX:-UseCompressedOops"; 96 } 97 98 public static List<RunArg> runList; 99 100 public static void configureRunArgs() { 101 runList = new ArrayList<RunArg>(); 102 runList 103 .add(new RunArg(new ConfArg(true, null, PASS))); 104 runList 105 .add(new RunArg(new ConfArg(false, null, PASS))); 106 } 107 108 public static void main(String[] args) throws Exception { 109 String helloJar = JarBuilder.build("hello", "Hello"); 110 configureRunArgs(); 111 OutputAnalyzer out; 112 for (RunArg t: runList) { 113 out = TestCommon 114 .dump(helloJar, 115 new String[] {"Hello"}, 116 getCompressedOopsArg(t.dumpArg.useCompressedOops), 117 "-Xlog:cds", 118 "-XX:NativeMemoryTracking=detail"); 119 out.shouldContain("Dumping shared data to file:"); 120 out.shouldHaveExitValue(0); 121 122 for (ConfArg c : t.execArgs) { 123 out = TestCommon.exec(helloJar, 124 "-cp", 125 helloJar, 126 "-Xlog:cds", 127 "-XX:NativeMemoryTracking=detail", 128 getCompressedOopsArg(c.useCompressedOops), 129 "Hello"); 130 out.shouldContain(c.msg); 131 out.shouldHaveExitValue(c.code); 132 } 133 } 134 } 135 }