Path: blob/master/test/hotspot/jtreg/compiler/compilercontrol/TestCompilerDirectivesCompatibilityBase.java
41149 views
/*1* Copyright (c) 2015, 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 TestCompilerDirectivesCompatibilityBase25* @bug 813716726* @summary Test compiler control compatibility with compile command27* @library /test/lib /28* @modules java.base/jdk.internal.misc29* java.compiler30* java.management31*32* @build sun.hotspot.WhiteBox33* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox34* @run testng/othervm -Xbootclasspath/a:. -Xmixed -XX:+UnlockDiagnosticVMOptions35* -XX:+WhiteBoxAPI36* compiler.compilercontrol.TestCompilerDirectivesCompatibilityBase37*/3839package compiler.compilercontrol;4041import compiler.testlibrary.CompilerUtils;42import compiler.whitebox.CompilerWhiteBoxTest;43import jdk.test.lib.dcmd.CommandExecutor;44import jdk.test.lib.dcmd.JMXExecutor;45import org.testng.annotations.Test;46import sun.hotspot.WhiteBox;4748import java.io.File;49import java.lang.reflect.Method;5051public class TestCompilerDirectivesCompatibilityBase {5253public static final WhiteBox WB = WhiteBox.getWhiteBox();54public static String control_on, control_off;55Method method, nomatch;5657public void run(CommandExecutor executor) throws Exception {5859control_on = System.getProperty("test.src", ".") + File.separator + "control_on.txt";60control_off = System.getProperty("test.src", ".") + File.separator + "control_off.txt";61method = getMethod(TestCompilerDirectivesCompatibilityBase.class, "helper");62nomatch = getMethod(TestCompilerDirectivesCompatibilityBase.class, "another");6364int[] levels = CompilerUtils.getAvailableCompilationLevels();65for (int complevel : levels) {66// Only test the major compilers, ignore profiling levels67if (complevel == CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE || complevel == CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION){68testCompatibility(executor, complevel);69}70}71}7273public void testCompatibility(CommandExecutor executor, int comp_level) throws Exception {7475// Call all validation twice to catch error when overwriting a directive76// Flag is default off77expect(!WB.getBooleanVMFlag("PrintAssembly"));78expect(!WB.shouldPrintAssembly(method, comp_level));79expect(!WB.shouldPrintAssembly(nomatch, comp_level));80expect(!WB.shouldPrintAssembly(method, comp_level));81expect(!WB.shouldPrintAssembly(nomatch, comp_level));8283// load directives that turn it on84executor.execute("Compiler.directives_add " + control_on);85expect(WB.shouldPrintAssembly(method, comp_level));86expect(!WB.shouldPrintAssembly(nomatch, comp_level));87expect(WB.shouldPrintAssembly(method, comp_level));88expect(!WB.shouldPrintAssembly(nomatch, comp_level));8990// remove and see that it is true again91executor.execute("Compiler.directives_remove");92expect(!WB.shouldPrintAssembly(method, comp_level));93expect(!WB.shouldPrintAssembly(nomatch, comp_level));94expect(!WB.shouldPrintAssembly(method, comp_level));95expect(!WB.shouldPrintAssembly(nomatch, comp_level));96}9798public void expect(boolean test) throws Exception {99if (!test) {100throw new Exception("Test failed");101}102}103104public void expect(boolean test, String msg) throws Exception {105if (!test) {106throw new Exception(msg);107}108}109110@Test111public void jmx() throws Exception {112run(new JMXExecutor());113}114115public void helper() {116}117118public void another() {119}120121public static Method getMethod(Class klass, String name, Class<?>... parameterTypes) {122try {123return klass.getDeclaredMethod(name, parameterTypes);124} catch (NoSuchMethodException | SecurityException e) {125throw new RuntimeException("exception on getting method Helper." + name, e);126}127}128}129130131