changeset 60484:770e74282b24

8067651: LevelTransitionTest.java, fix trivial methods levels logic Summary: Make test method really trivial, adjust trivial logic, make logic independent of background compilation. Reviewed-by: iignatyev, thartmann, kvn
author enikitin
date Mon, 27 Jul 2020 21:17:44 +0200
parents 29212f925331
children 6a6ae223d6e0
files test/hotspot/jtreg/compiler/tiered/ConstantGettersTransitionsTest.java test/hotspot/jtreg/compiler/tiered/LevelTransitionTest.java test/hotspot/jtreg/compiler/tiered/MethodHelper.java
diffstat 3 files changed, 80 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/test/hotspot/jtreg/compiler/tiered/ConstantGettersTransitionsTest.java	Fri Aug 07 12:58:40 2020 -0700
+++ b/test/hotspot/jtreg/compiler/tiered/ConstantGettersTransitionsTest.java	Mon Jul 27 21:17:44 2020 +0200
@@ -106,8 +106,8 @@
 
         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);
         }
 
         /**
--- a/test/hotspot/jtreg/compiler/tiered/LevelTransitionTest.java	Fri Aug 07 12:58:40 2020 -0700
+++ b/test/hotspot/jtreg/compiler/tiered/LevelTransitionTest.java	Mon Jul 27 21:17:44 2020 +0200
@@ -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 @@
 
 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 @@
             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 @@
                 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 @@
         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 @@
         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 @@
         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 @@
         }
 
         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 @@
             }
 
             /**
-             * 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;
             }
         }
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/compiler/tiered/MethodHelper.java	Mon Jul 27 21:17:44 2020 +0200
@@ -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);
+            }
+        };
+    }
+}