1 /* 2 * Copyright (c) 2018 Red Hat, Inc. and/or its affiliates. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. 7 * 8 * This code is distributed in the hope that it will be useful, but WITHOUT 9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 * version 2 for more details (a copy is included in the LICENSE file that 12 * accompanied this code). 13 * 14 * You should have received a copy of the GNU General Public License version 15 * 2 along with this work; if not, write to the Free Software Foundation, 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17 * 18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 * 22 */ 23 24 /* 25 * @test TestClassUnloadingArguments 26 * @summary Test that loop mining arguments are sane 27 * @key gc 28 * @library /testlibrary 29 * @run driver TestClassUnloadingArguments 30 */ 31 32 import java.util.*; 33 34 import com.oracle.java.testlibrary.*; 35 36 public class TestClassUnloadingArguments { 37 38 public static void testWith(String msg, boolean cu, boolean cuConc, String... args) throws Exception { 39 String[] cmds = Arrays.copyOf(args, args.length + 2); 40 cmds[args.length] = "-XX:+PrintFlagsFinal"; 41 cmds[args.length + 1] = "-version"; 42 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmds); 43 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 44 output.shouldHaveExitValue(0); 45 output.shouldContain("ClassUnloading"); 46 output.shouldContain("ClassUnloadingWithConcurrentMark"); 47 48 Asserts.assertEQ(output.firstMatch("(.+?) ClassUnloading.+?= (.+?) (.+?)", 2), 49 Boolean.toString(cu), 50 msg + ", but got wrong ClassUnloading"); 51 Asserts.assertEQ(output.firstMatch("(.+?) ClassUnloadingWithConcurrentMark.+?= (.+?) (.+?)", 2), 52 Boolean.toString(cuConc), 53 msg + ", but got wrong ClassUnloadingWithConcurrentMark"); 54 } 55 56 public static void main(String[] args) throws Exception { 57 testDefaultGC(); 58 testShenandoah(); 59 } 60 61 public static void testDefaultGC() throws Exception { 62 testWith("Default GC should have class unloading enabled", 63 true, true); 64 65 // Not in JDK 8 and Parallel GC 66 // testWith("Default GC should disable everything", 67 // false, false, 68 // "-XX:-ClassUnloading"); 69 70 testWith("Default GC should disable conc unload", 71 true, false, 72 "-XX:-ClassUnloadingWithConcurrentMark"); 73 74 // Not in JDK 8 and Parallel GC 75 // testWith("Default GC should not let conc unload to be enabled separately", 76 // false, false, 77 // "-XX:-ClassUnloading", 78 // "-XX:+ClassUnloadingWithConcurrentMark"); 79 } 80 81 public static void testShenandoah() throws Exception { 82 testWith("Shenandoah GC should have class unloading enabled", 83 true, false, 84 "-XX:+UseShenandoahGC"); 85 86 testWith("Shenandoah GC should disable everything", 87 false, false, 88 "-XX:+UseShenandoahGC", 89 "-XX:-ClassUnloading"); 90 91 testWith("Shenandoah GC should enable conc unload", 92 true, true, 93 "-XX:+UseShenandoahGC", 94 "-XX:+ClassUnloadingWithConcurrentMark"); 95 96 testWith("Shenandoah GC should not let conc unload to be enabled separately", 97 false, false, 98 "-XX:+UseShenandoahGC", 99 "-XX:-ClassUnloading", 100 "-XX:+ClassUnloadingWithConcurrentMark"); 101 } 102 103 }