Path: blob/master/test/lib-test/sun/hotspot/whitebox/vm_flags/BooleanTest.java
41154 views
/*1* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 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 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test BooleanTest25* @bug 802875626* @library /test/lib27* @modules java.base/jdk.internal.misc28* java.compiler29* java.management/sun.management30* jdk.internal.jvmstat/sun.jvmstat.monitor31* @build sun.hotspot.WhiteBox32* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox33* @run main/othervm/timeout=600 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI BooleanTest34* @summary testing of WB::set/getBooleanVMFlag()35* @author [email protected]36*/3738import sun.hotspot.WhiteBox;39import jdk.test.lib.process.OutputAnalyzer;40import jdk.test.lib.process.ProcessTools;41import sun.management.*;42import com.sun.management.*;4344public class BooleanTest {45private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();46private static final Boolean[] TESTS = {true, false, true, true, false};47private static final String TEST_NAME = "BooleanTest";48private static final String FLAG_NAME = "PrintCompilation";49private static final String FLAG_DEBUG_NAME = "SafepointALot";50private static final String METHOD = TEST_NAME + "::method";51private static final String METHOD1 = METHOD + "1";52private static final String METHOD2 = METHOD + "2";5354public static void main(String[] args) throws Exception {55if (args.length == 0) {56VmFlagTest.runTest(FLAG_NAME, TESTS,57VmFlagTest.WHITE_BOX::setBooleanVMFlag,58VmFlagTest.WHITE_BOX::getBooleanVMFlag);59testFunctional(false);60testFunctional(true);61VmFlagTest.runTest(FLAG_DEBUG_NAME, VmFlagTest.WHITE_BOX::getBooleanVMFlag);62} else {63boolean value = Boolean.valueOf(args[0]);64method1();65VmFlagTest.WHITE_BOX.setBooleanVMFlag(FLAG_NAME, value);66method2();67}68}6970private static void testFunctional(boolean value) throws Exception {71ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(72"-Xbootclasspath/a:.",73"-XX:+UnlockDiagnosticVMOptions",74"-XX:+WhiteBoxAPI",75"-Xcomp",76"-XX:CompileCommand=compileonly," + METHOD + "*",77"-XX:" + (value ? "-" : "+") + FLAG_NAME,78TEST_NAME,79"" + value);80OutputAnalyzer out = new OutputAnalyzer(pb.start());81if (value) {82out.shouldNotContain(METHOD1);83out.shouldContain(METHOD2);84} else {85out.shouldContain(METHOD1);86out.shouldNotContain(METHOD2);87}88}8990private static void method1() { }91private static void method2() { }92}93949596