8067651: LevelTransitionTest.java, fix trivial methods levels logic

Make test method really trivial, adjust trivial logic, make logic independent of background compilation.

Reviewed-by: iignatyev, thartmann, kvn
This commit is contained in:
Evgeny Nikitin 2020-07-27 21:17:44 +02:00
parent 4ac45a3b50
commit 3c276ce1fe
3 changed files with 80 additions and 49 deletions

@ -106,8 +106,8 @@ public class ConstantGettersTransitionsTest extends LevelTransitionTest {
private ConstantGettersTestCase() {
String name = "make" + this.name();
this.executable = LevelTransitionTest.Helper.getMethod(TrivialMethods.class, name);
this.callable = LevelTransitionTest.Helper.getCallable(new TrivialMethods(), name);
this.executable = MethodHelper.getMethod(TrivialMethods.class, name);
this.callable = MethodHelper.getCallable(new TrivialMethods(), name);
}
/**

@ -23,6 +23,7 @@
/**
* @test LevelTransitionTest
* @requires vm.compMode != "Xcomp"
* @summary Test the correctness of compilation level transitions for different methods
* @library /test/lib /
* @modules java.base/jdk.internal.misc
@ -33,6 +34,7 @@
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm/timeout=240 -Xmixed -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:+TieredCompilation -XX:-UseCounterDecay
* -XX:-BackgroundCompilation
* -XX:CompileCommand=compileonly,compiler.whitebox.SimpleTestCaseHelper::*
* -XX:CompileCommand=compileonly,compiler.tiered.LevelTransitionTest$ExtendedTestCase$CompileMethodHolder::*
* compiler.tiered.LevelTransitionTest
@ -42,11 +44,11 @@ package compiler.tiered;
import compiler.whitebox.CompilerWhiteBoxTest;
import compiler.whitebox.SimpleTestCase;
import jdk.test.lib.Platform;
import jtreg.SkippedException;
import java.lang.reflect.Executable;
import java.lang.reflect.Method;
import java.util.Objects;
import java.util.concurrent.Callable;
public class LevelTransitionTest extends TieredLevelsTest {
@ -98,6 +100,7 @@ public class LevelTransitionTest extends TieredLevelsTest {
int newLevel;
int current = getCompLevel();
int expected = getNextLevel(current);
System.out.println("Levels, current: " + current + ", expected: " + expected);
if (current == expected) {
// if we are on expected level, just execute it more
// to ensure that the level won't change
@ -107,9 +110,10 @@ public class LevelTransitionTest extends TieredLevelsTest {
finish = true;
} else {
newLevel = changeCompLevel();
System.out.printf("Method %s has been compiled to level %d. Expected level is %d%n",
method, newLevel, expected);
finish = false;
}
System.out.printf("Method %s is compiled on level %d. Expected level is %d%n", method, newLevel, expected);
checkLevel(expected, newLevel);
printInfo();
}
@ -126,8 +130,9 @@ public class LevelTransitionTest extends TieredLevelsTest {
int nextLevel = currentLevel;
switch (currentLevel) {
case CompilerWhiteBoxTest.COMP_LEVEL_NONE:
nextLevel = isMethodProfiled ? CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION
: CompilerWhiteBoxTest.COMP_LEVEL_FULL_PROFILE;
nextLevel = isTrivial() ? CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE :
isMethodProfiled ? CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION :
CompilerWhiteBoxTest.COMP_LEVEL_FULL_PROFILE;
break;
case CompilerWhiteBoxTest.COMP_LEVEL_LIMITED_PROFILE:
case CompilerWhiteBoxTest.COMP_LEVEL_FULL_PROFILE:
@ -148,7 +153,7 @@ public class LevelTransitionTest extends TieredLevelsTest {
return testCase == ExtendedTestCase.ACCESSOR_TEST
|| testCase == SimpleTestCase.METHOD_TEST
|| testCase == SimpleTestCase.STATIC_TEST
|| (testCase == ExtendedTestCase.TRIVIAL_CODE_TEST && isMethodProfiled);
|| testCase == ExtendedTestCase.TRIVIAL_CODE_TEST;
}
/**
@ -170,42 +175,6 @@ public class LevelTransitionTest extends TieredLevelsTest {
return newLevel;
}
protected static class Helper {
/**
* Gets method from a specified class using its name
*
* @param aClass type method belongs to
* @param name the name of the method
* @return {@link Method} that represents corresponding class method
*/
public static Method getMethod(Class<?> aClass, String name) {
Method method;
try {
method = aClass.getDeclaredMethod(name);
} catch (NoSuchMethodException e) {
throw new Error("TESTBUG: Unable to get method " + name, e);
}
return method;
}
/**
* Gets {@link Callable} that invokes given method from the given object
*
* @param object the object the specified method is invoked from
* @param name the name of the method
*/
public static Callable<Integer> getCallable(Object object, String name) {
Method method = getMethod(object.getClass(), name);
return () -> {
try {
return Objects.hashCode(method.invoke(object));
} catch (ReflectiveOperationException e) {
throw new Error("TESTBUG: Invocation failure", e);
}
};
}
}
private static enum ExtendedTestCase implements CompilerWhiteBoxTest.TestCase {
ACCESSOR_TEST("accessor"),
NONTRIVIAL_METHOD_TEST("nonTrivialMethod"),
@ -230,8 +199,8 @@ public class LevelTransitionTest extends TieredLevelsTest {
}
private ExtendedTestCase(String methodName) {
this.executable = LevelTransitionTest.Helper.getMethod(CompileMethodHolder.class, methodName);
this.callable = LevelTransitionTest.Helper.getCallable(new CompileMethodHolder(), methodName);
this.executable = MethodHelper.getMethod(CompileMethodHolder.class, methodName);
this.callable = MethodHelper.getCallable(new CompileMethodHolder(), methodName);
}
private static class CompileMethodHolder {
@ -257,12 +226,10 @@ public class LevelTransitionTest extends TieredLevelsTest {
}
/**
* Method considered as trivial by amount of code
* Method considered as trivial by type (constant getter)
*/
public int trivialCode() {
int var = 0xBAAD_C0DE;
var *= field;
return var;
return 0x42;
}
}
}

@ -0,0 +1,64 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package compiler.tiered;
import java.lang.reflect.Method;
import java.util.Objects;
import java.util.concurrent.Callable;
public class MethodHelper {
/**
* Gets method from a specified class using its name
*
* @param aClass type method belongs to
* @param name the name of the method
* @return {@link Method} that represents corresponding class method
*/
public static Method getMethod(Class<?> aClass, String name) {
Method method;
try {
method = aClass.getDeclaredMethod(name);
} catch (NoSuchMethodException e) {
throw new Error("TESTBUG: Unable to get method " + name, e);
}
return method;
}
/**
* Gets {@link Callable} that invokes given method from the given object
*
* @param object the object the specified method is invoked from
* @param name the name of the method
*/
public static Callable<Integer> getCallable(Object object, String name) {
Method method = getMethod(object.getClass(), name);
return () -> {
try {
return Objects.hashCode(method.invoke(object));
} catch (ReflectiveOperationException e) {
throw new Error("TESTBUG: Invocation failure", e);
}
};
}
}