Path: blob/master/test/hotspot/jtreg/compiler/compilercontrol/InlineMatcherTest.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 InlineMatcherTest25* @bug 807409526* @summary Testing of compiler/InlineMatcher27* @modules java.base/jdk.internal.misc28* @library /test/lib29*30* @build sun.hotspot.WhiteBox31* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox32* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI33* compiler.compilercontrol.InlineMatcherTest34*/3536package compiler.compilercontrol;3738import sun.hotspot.WhiteBox;3940import java.lang.reflect.Method;41import java.util.ArrayList;4243public class InlineMatcherTest {4445/** Instance of WhiteBox */46protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();4748Method helper;49Method getDate;50Method inner;51Method toString;5253final public static int FORCE_INLINE = 2;54final public static int DONT_INLINE = 1;55final public static int NO_MATCH = 0;56final public static int PARSING_FAILURE = -1;5758public InlineMatcherTest() {5960}6162public void test() throws Exception {63// instantiate before calling getMethod on innerHelper64TestCases testCases = new TestCases();6566helper = getMethod(InlineMatcherTest.class, "helper");6768testCases.add(helper, "*.*", PARSING_FAILURE);69testCases.add(helper, "+*.*", FORCE_INLINE);70testCases.add(helper, "++*.*", NO_MATCH); // + is a valid part of the71// class name72testCases.add(helper, "-*.*", DONT_INLINE);73testCases.add(helper, "--*.*", NO_MATCH); // - is a valid part of the74// class name7576String className = this.getClass().getName().replace('.', '/');77testCases.add(helper, "+" + className + ".*", FORCE_INLINE);78testCases.add(helper, "+" + className + ".helper", FORCE_INLINE);79testCases.add(helper, "+" + className + ".helper()", FORCE_INLINE);80testCases.add(helper, "+" + className + ".helper()V", FORCE_INLINE);81testCases.add(helper, "+" + className + ".helper(", FORCE_INLINE);8283testCases.add(helper, "-" + className + ".*", DONT_INLINE);84testCases.add(helper, "-" + className + ".helper", DONT_INLINE);85testCases.add(helper, "-" + className + ".helper()", DONT_INLINE);86testCases.add(helper, "-" + className + ".helper()V", DONT_INLINE);87testCases.add(helper, "-" + className + ".helper(", DONT_INLINE);8889testCases.add(helper, "+abc.*", NO_MATCH);90testCases.add(helper, "+*.abc", NO_MATCH);91testCases.add(helper, "-abc.*", NO_MATCH);92testCases.add(helper, "-*.abcls ", NO_MATCH);9394int failures = 0;9596for (TestCase t : testCases) {97System.out.println("Test case: " + t.pattern);98if (!t.test()) {99failures++;100System.out.println(" * FAILED");101}102}103if (failures != 0) {104throw new Exception("There where " + failures + " failures in this test");105}106}107108public static void main(String... args) throws Exception {109InlineMatcherTest test = new InlineMatcherTest();110test.test();111}112113public void helper() {114115}116117private static Method getMethod(Class klass, String name, Class<?>... parameterTypes) {118try {119return klass.getDeclaredMethod(name, parameterTypes);120} catch (NoSuchMethodException | SecurityException e) {121throw new RuntimeException("exception on getting method Helper." + name, e);122}123}124125class TestCase {126String pattern;127Method testTarget;128int expectedResult;129130public TestCase(Method testTarget, String pattern, int expectedResult) {131this.testTarget = testTarget;132this.pattern = pattern;133this.expectedResult = expectedResult;134}135136public String resultAsStr(int errorCode) {137switch (errorCode) {138case PARSING_FAILURE:139return "Parsing failed";140case NO_MATCH:141return "No match";142case DONT_INLINE:143return "Dont Inline";144case FORCE_INLINE:145return "Force Inline";146default:147return "Unknown error";148}149}150151boolean test() {152int result = WHITE_BOX.matchesInline(testTarget, pattern);153if (result != expectedResult) {154System.out155.println("FAIL Wrong result, Got: " + resultAsStr(result) + "\n TestCase: " + this.toString());156return false;157}158return true;159}160161@Override162public String toString() {163return "Method: '" + testTarget.toString() + "' Pattern: '" + pattern + "' Expected: "164+ resultAsStr(expectedResult);165}166167public void innerHelper() {168169}170}171172class TestCases extends ArrayList<TestCase> {173private static final long serialVersionUID = 1L;174175public boolean add(Method testTarget, String pattern, int expectedResult) {176return super.add(new TestCase(testTarget, pattern, expectedResult));177}178}179}180181182