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  * @requires vm.gc.Shenandoah
  28  * @library /test/lib
  29  * @run main/othervm TestWrongBarrierDisable
  30  */
  31 
  32 import java.util.*;
  33 
  34 import jdk.test.lib.process.ProcessTools;
  35 import jdk.test.lib.process.OutputAnalyzer;
  36 
  37 public class TestWrongBarrierDisable {
  38 
  39     public static void main(String[] args) throws Exception {
  40         String[] concurrent = {
  41                 "ShenandoahReadBarrier",
  42                 "ShenandoahWriteBarrier",
  43                 "ShenandoahCASBarrier",
  44                 "ShenandoahAcmpBarrier",
  45                 "ShenandoahCloneBarrier",
  46                 "ShenandoahSATBBarrier",
  47                 "ShenandoahKeepAliveBarrier",
  48                 "ShenandoahStoreValReadBarrier",
  49         };
  50 
  51         String[] traversal = {
  52                 "ShenandoahReadBarrier",
  53                 "ShenandoahWriteBarrier",
  54                 "ShenandoahCASBarrier",
  55                 "ShenandoahAcmpBarrier",
  56                 "ShenandoahCloneBarrier",
  57         };
  58 
  59         shouldFailAll("adaptive",   concurrent);
  60         shouldFailAll("static",     concurrent);
  61         shouldFailAll("compact",    concurrent);
  62         shouldFailAll("aggressive", concurrent);
  63         shouldFailAll("traversal",  traversal);
  64         shouldPassAll("passive",    concurrent);
  65         shouldPassAll("passive",    traversal);
  66     }
  67 
  68     private static void shouldFailAll(String h, String[] barriers) throws Exception {
  69         for (String b : barriers) {
  70             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  71                     "-XX:+UnlockDiagnosticVMOptions",
  72                     "-XX:+UnlockExperimentalVMOptions",
  73                     "-XX:+UseShenandoahGC",
  74                     "-XX:ShenandoahGCHeuristics=" + h,
  75                     "-XX:-" + b,
  76                     "-version"
  77             );
  78             OutputAnalyzer output = new OutputAnalyzer(pb.start());
  79             output.shouldNotHaveExitValue(0);
  80             output.shouldContain("Heuristics needs ");
  81             output.shouldContain("to work correctly");
  82         }
  83     }
  84 
  85     private static void shouldPassAll(String h, String[] barriers) throws Exception {
  86         for (String b : barriers) {
  87             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  88                     "-XX:+UnlockDiagnosticVMOptions",
  89                     "-XX:+UnlockExperimentalVMOptions",
  90                     "-XX:+UseShenandoahGC",
  91                     "-XX:ShenandoahGCHeuristics=" + h,
  92                     "-XX:-" + b,
  93                     "-version"
  94             );
  95             OutputAnalyzer output = new OutputAnalyzer(pb.start());
  96             output.shouldHaveExitValue(0);
  97         }
  98     }
  99 
 100 }