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         String[] traversal = {
  47                 "ShenandoahLoadRefBarrier",
  48                 "ShenandoahCASBarrier",
  49                 "ShenandoahCloneBarrier",
  50         };
  51 
  52         shouldFailAll("-XX:ShenandoahGCHeuristics=adaptive",   concurrent);
  53         shouldFailAll("-XX:ShenandoahGCHeuristics=static",     concurrent);
  54         shouldFailAll("-XX:ShenandoahGCHeuristics=compact",    concurrent);
  55         shouldFailAll("-XX:ShenandoahGCHeuristics=aggressive", concurrent);
  56         shouldFailAll("-XX:ShenandoahGCMode=traversal",        traversal);
  57         shouldPassAll("-XX:ShenandoahGCMode=passive",          concurrent);
  58         shouldPassAll("-XX:ShenandoahGCMode=passive",          traversal);
  59     }
  60 
  61     private static void shouldFailAll(String h, String[] barriers) throws Exception {
  62         for (String b : barriers) {
  63             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  64                     "-XX:+UnlockDiagnosticVMOptions",
  65                     "-XX:+UnlockExperimentalVMOptions",
  66                     "-XX:+UseShenandoahGC",
  67                     h,
  68                     "-XX:-" + b,
  69                     "-version"
  70             );
  71             OutputAnalyzer output = new OutputAnalyzer(pb.start());
  72             output.shouldHaveExitValue(1);
  73             output.shouldContain("Heuristics needs ");
  74             output.shouldContain("to work correctly");
  75         }
  76     }
  77 
  78     private static void shouldPassAll(String h, String[] barriers) throws Exception {
  79         for (String b : barriers) {
  80             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  81                     "-XX:+UnlockDiagnosticVMOptions",
  82                     "-XX:+UnlockExperimentalVMOptions",
  83                     "-XX:+UseShenandoahGC",
  84                     h,
  85                     "-XX:-" + b,
  86                     "-version"
  87             );
  88             OutputAnalyzer output = new OutputAnalyzer(pb.start());
  89             output.shouldHaveExitValue(0);
  90         }
  91     }
  92 
  93 }