1 /*
   2  * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
   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 /* @test TestWrongBarrierDisable
  25  * @summary Test that disabling wrong barriers fails early
  26  * @key gc
  27  * @library /testlibrary
  28  * @run main/othervm TestWrongBarrierDisable
  29  */
  30 
  31 import java.util.*;
  32 
  33 import com.oracle.java.testlibrary.*;
  34 
  35 public class TestWrongBarrierDisable {
  36 
  37     public static void main(String[] args) throws Exception {
  38         String[] concurrent = {
  39                 "ShenandoahLoadRefBarrier",
  40                 "ShenandoahCASBarrier",
  41                 "ShenandoahCloneBarrier",
  42                 "ShenandoahSATBBarrier",
  43                 "ShenandoahKeepAliveBarrier",
  44         };
  45 
  46         shouldFailAll("-XX:ShenandoahGCHeuristics=adaptive",   concurrent);
  47         shouldFailAll("-XX:ShenandoahGCHeuristics=static",     concurrent);
  48         shouldFailAll("-XX:ShenandoahGCHeuristics=compact",    concurrent);
  49         shouldFailAll("-XX:ShenandoahGCHeuristics=aggressive", concurrent);
  50         shouldPassAll("-XX:ShenandoahGCMode=passive",          concurrent);
  51     }
  52 
  53     private static void shouldFailAll(String h, String[] barriers) throws Exception {
  54         for (String b : barriers) {
  55             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  56                     "-XX:+UnlockDiagnosticVMOptions",
  57                     "-XX:+UnlockExperimentalVMOptions",
  58                     "-XX:+UseShenandoahGC",
  59                     h,
  60                     "-XX:-" + b,
  61                     "-version"
  62             );
  63             OutputAnalyzer output = new OutputAnalyzer(pb.start());
  64             output.shouldHaveExitValue(1);
  65             output.shouldContain("Heuristics needs ");
  66             output.shouldContain("to work correctly");
  67         }
  68     }
  69 
  70     private static void shouldPassAll(String h, String[] barriers) throws Exception {
  71         for (String b : barriers) {
  72             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  73                     "-XX:+UnlockDiagnosticVMOptions",
  74                     "-XX:+UnlockExperimentalVMOptions",
  75                     "-XX:+UseShenandoahGC",
  76                     h,
  77                     "-XX:-" + b,
  78                     "-version"
  79             );
  80             OutputAnalyzer output = new OutputAnalyzer(pb.start());
  81             output.shouldHaveExitValue(0);
  82         }
  83     }
  84 
  85 }