1 /*
   2  * Copyright (c) 2014, 2015, 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 BooleanTest
  26  * @bug 8028756
  27  * @library /testlibrary /../../test/lib
  28  * @modules java.base/sun.misc
  29  *          java.compiler
  30  *          java.management/sun.management
  31  *          jdk.jvmstat/sun.jvmstat.monitor
  32  * @build BooleanTest ClassFileInstaller sun.hotspot.WhiteBox jdk.test.lib.*
  33  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  34  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
  35  * @run main/othervm/timeout=600 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI BooleanTest
  36  * @summary testing of WB::set/getBooleanVMFlag()
  37  * @author igor.ignatyev@oracle.com
  38  */
  39 
  40 import sun.hotspot.WhiteBox;
  41 import jdk.test.lib.*;
  42 import sun.management.*;
  43 import com.sun.management.*;
  44 
  45 public class BooleanTest {
  46     private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
  47     private static final Boolean[] TESTS = {true, false, true, true, false};
  48     private static final String TEST_NAME = "BooleanTest";
  49     private static final String FLAG_NAME = "PrintCompilation";
  50     private static final String FLAG_DEBUG_NAME = "SafepointALot";
  51     private static final String METHOD = TEST_NAME + "::method";
  52     private static final String METHOD1 = METHOD + "1";
  53     private static final String METHOD2 = METHOD + "2";
  54 
  55     public static void main(String[] args) throws Exception {
  56         if (args.length == 0) {
  57             VmFlagTest.runTest(FLAG_NAME, TESTS,
  58                 VmFlagTest.WHITE_BOX::setBooleanVMFlag,
  59                 VmFlagTest.WHITE_BOX::getBooleanVMFlag);
  60             testFunctional(false);
  61             testFunctional(true);
  62             VmFlagTest.runTest(FLAG_DEBUG_NAME, VmFlagTest.WHITE_BOX::getBooleanVMFlag);
  63         } else {
  64             boolean value = Boolean.valueOf(args[0]);
  65             method1();
  66             VmFlagTest.WHITE_BOX.setBooleanVMFlag(FLAG_NAME, value);
  67             method2();
  68         }
  69     }
  70 
  71     private static void testFunctional(boolean value) throws Exception {
  72         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  73             "-Xbootclasspath/a:.",
  74             "-XX:+UnlockDiagnosticVMOptions",
  75             "-XX:+WhiteBoxAPI",
  76             "-Xcomp",
  77             "-XX:CompileCommand=compileonly," + METHOD + "*",
  78             "-XX:" + (value ? "-" : "+") + FLAG_NAME,
  79             TEST_NAME,
  80             "" + value);
  81         OutputAnalyzer out = new OutputAnalyzer(pb.start());
  82         if (value) {
  83             out.shouldNotContain(METHOD1);
  84             out.shouldContain(METHOD2);
  85         } else {
  86             out.shouldContain(METHOD1);
  87             out.shouldNotContain(METHOD2);
  88         }
  89     }
  90 
  91     private static void method1() { }
  92     private static void method2() { }
  93 }
  94