8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests

Mon, 03 Jun 2019 16:14:54 +0100

author
xliu
date
Mon, 03 Jun 2019 16:14:54 +0100
changeset 9689
89dcef434423
parent 9688
54e5e3c816d4
child 9690
61d955db2a5b

8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
Summary: Includes compile_id addition from JDK-8054492
Reviewed-by: andrew

src/share/vm/prims/whitebox.cpp file | annotate | diff | comparison | revisions
test/compiler/tiered/ConstantGettersTransitionsTest.java file | annotate | diff | comparison | revisions
test/compiler/tiered/LevelTransitionTest.java file | annotate | diff | comparison | revisions
test/compiler/tiered/NonTieredLevelsTest.java file | annotate | diff | comparison | revisions
test/compiler/tiered/TieredLevelsTest.java file | annotate | diff | comparison | revisions
test/compiler/tiered/TransitionsTestExecutor.java file | annotate | diff | comparison | revisions
test/compiler/whitebox/CompilerWhiteBoxTest.java file | annotate | diff | comparison | revisions
test/testlibrary/whitebox/sun/hotspot/code/NMethod.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/prims/whitebox.cpp	Sun Mar 31 16:57:21 2019 -0700
     1.2 +++ b/src/share/vm/prims/whitebox.cpp	Mon Jun 03 16:14:54 2019 +0100
     1.3 @@ -848,19 +848,23 @@
     1.4    ThreadToNativeFromVM ttn(thread);
     1.5    jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
     1.6    CHECK_JNI_EXCEPTION_(env, NULL);
     1.7 -  result = env->NewObjectArray(2, clazz, NULL);
     1.8 +  result = env->NewObjectArray(3, clazz, NULL);
     1.9    if (result == NULL) {
    1.10      return result;
    1.11    }
    1.12  
    1.13 -  jobject obj = integerBox(thread, env, code->comp_level());
    1.14 +  jobject level = integerBox(thread, env, code->comp_level());
    1.15    CHECK_JNI_EXCEPTION_(env, NULL);
    1.16 -  env->SetObjectArrayElement(result, 0, obj);
    1.17 +  env->SetObjectArrayElement(result, 0, level);
    1.18 +
    1.19 +  jobject id = integerBox(thread, env, code->compile_id());
    1.20 +  CHECK_JNI_EXCEPTION_(env, NULL);
    1.21 +  env->SetObjectArrayElement(result, 1, id);
    1.22  
    1.23    jbyteArray insts = env->NewByteArray(insts_size);
    1.24    CHECK_JNI_EXCEPTION_(env, NULL);
    1.25    env->SetByteArrayRegion(insts, 0, insts_size, (jbyte*) code->insts_begin());
    1.26 -  env->SetObjectArrayElement(result, 1, insts);
    1.27 +  env->SetObjectArrayElement(result, 2, insts);
    1.28  
    1.29    return result;
    1.30  WB_END
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/compiler/tiered/ConstantGettersTransitionsTest.java	Mon Jun 03 16:14:54 2019 +0100
     2.3 @@ -0,0 +1,193 @@
     2.4 +/*
     2.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + */
    2.26 +
    2.27 +import java.lang.reflect.Executable;
    2.28 +import java.util.concurrent.Callable;
    2.29 +
    2.30 +/**
    2.31 + * @test ConstantGettersTransitionsTest
    2.32 + * @library /testlibrary /testlibrary/whitebox /compiler/whitebox
    2.33 + * @build TransitionsTestExecutor ConstantGettersTransitionsTest
    2.34 + * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
    2.35 + * @run main/othervm/timeout=240 -Xmixed -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
    2.36 + *                   -XX:+WhiteBoxAPI -XX:+TieredCompilation
    2.37 + *                   -XX:CompileCommand=compileonly,ConstantGettersTestCase$TrivialMethods::*
    2.38 + *                   TransitionsTestExecutor ConstantGettersTransitionsTest
    2.39 + * @summary Test the correctness of compilation level transitions for constant getters methods
    2.40 + */
    2.41 +public class ConstantGettersTransitionsTest extends LevelTransitionTest {
    2.42 +    public static void main(String[] args) {
    2.43 +        assert (!CompilerWhiteBoxTest.skipOnTieredCompilation(false));
    2.44 +
    2.45 +        // run test cases
    2.46 +        for (TestCase testCase : ConstantGettersTestCase.values()) {
    2.47 +            new ConstantGettersTransitionsTest(testCase).runTest();
    2.48 +        }
    2.49 +    }
    2.50 +
    2.51 +    @Override
    2.52 +    protected boolean isTrivial() {
    2.53 +        return true;
    2.54 +    }
    2.55 +
    2.56 +    private ConstantGettersTransitionsTest(TestCase testCase) {
    2.57 +        super(testCase);
    2.58 +    }
    2.59 +}
    2.60 +
    2.61 +enum ConstantGettersTestCase implements CompilerWhiteBoxTest.TestCase {
    2.62 +    ICONST_M1,
    2.63 +    ICONST_0,
    2.64 +    ICONST_1,
    2.65 +    ICONST_2,
    2.66 +    ICONST_3,
    2.67 +    ICONST_4,
    2.68 +    ICONST_5,
    2.69 +    LCONST_0,
    2.70 +    LCONST_1,
    2.71 +    FCONST_0,
    2.72 +    FCONST_1,
    2.73 +    FCONST_2,
    2.74 +    DCONST_0,
    2.75 +    DCONST_1,
    2.76 +    DCONST_W,
    2.77 +    BYTE,
    2.78 +    SHORT,
    2.79 +    CHAR;
    2.80 +
    2.81 +    private final Executable executable;
    2.82 +    private final Callable<Integer> callable;
    2.83 +
    2.84 +    @Override
    2.85 +    public Executable getExecutable() {
    2.86 +        return executable;
    2.87 +    }
    2.88 +
    2.89 +    @Override
    2.90 +    public Callable<Integer> getCallable() {
    2.91 +        return callable;
    2.92 +    }
    2.93 +
    2.94 +    @Override
    2.95 +    public boolean isOsr() {
    2.96 +        return false;
    2.97 +    }
    2.98 +
    2.99 +    private ConstantGettersTestCase() {
   2.100 +        String name = "make" + this.name();
   2.101 +        this.executable = LevelTransitionTest.Helper.getMethod(TrivialMethods.class, name);
   2.102 +        this.callable = LevelTransitionTest.Helper.getCallable(new TrivialMethods(), name);
   2.103 +    }
   2.104 +
   2.105 +    /**
   2.106 +     * Contains methods that load constants with certain types of bytecodes
   2.107 +     * See JVMS 2.11.2. Load and Store Instructions
   2.108 +     * Note that it doesn't have a method for ldc_w instruction
   2.109 +     */
   2.110 +    private static class TrivialMethods {
   2.111 +        public static int makeICONST_M1() {
   2.112 +            return -1;
   2.113 +        }
   2.114 +
   2.115 +        public static int makeICONST_0() {
   2.116 +            return 0;
   2.117 +        }
   2.118 +
   2.119 +        public static int makeICONST_1() {
   2.120 +            return 1;
   2.121 +        }
   2.122 +
   2.123 +        public static int makeICONST_2() {
   2.124 +            return 2;
   2.125 +        }
   2.126 +
   2.127 +        public static int makeICONST_3() {
   2.128 +            return 3;
   2.129 +        }
   2.130 +
   2.131 +        public static int makeICONST_4() {
   2.132 +            return 4;
   2.133 +        }
   2.134 +
   2.135 +        public static int makeICONST_5() {
   2.136 +            return 5;
   2.137 +        }
   2.138 +
   2.139 +        public static long makeLCONST_0() {
   2.140 +            return 0L;
   2.141 +        }
   2.142 +
   2.143 +        public static long makeLCONST_1() {
   2.144 +            return 1L;
   2.145 +        }
   2.146 +
   2.147 +        public static float makeFCONST_0() {
   2.148 +            return 0F;
   2.149 +        }
   2.150 +
   2.151 +        public static float makeFCONST_1() {
   2.152 +            return 1F;
   2.153 +        }
   2.154 +
   2.155 +        public static float makeFCONST_2() {
   2.156 +            return 2F;
   2.157 +        }
   2.158 +
   2.159 +        public static double makeDCONST_0() {
   2.160 +            return 0D;
   2.161 +        }
   2.162 +
   2.163 +        public static double makeDCONST_1() {
   2.164 +            return 1D;
   2.165 +        }
   2.166 +
   2.167 +        public static double makeDCONST_W() {
   2.168 +            // ldc2_w
   2.169 +            return Double.MAX_VALUE;
   2.170 +        }
   2.171 +
   2.172 +        public static Object makeOBJECT() {
   2.173 +            // aconst_null
   2.174 +            return null;
   2.175 +        }
   2.176 +
   2.177 +        public static byte makeBYTE() {
   2.178 +            // bipush
   2.179 +            return (byte) 0x7F;
   2.180 +        }
   2.181 +
   2.182 +        public static short makeSHORT() {
   2.183 +            // sipush
   2.184 +            return (short) 0x7FFF;
   2.185 +        }
   2.186 +
   2.187 +        public static char makeCHAR() {
   2.188 +            // ldc
   2.189 +            return (char) 0xFFFF;
   2.190 +        }
   2.191 +
   2.192 +        public static boolean makeBOOLEAN() {
   2.193 +            return true;
   2.194 +        }
   2.195 +    }
   2.196 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/compiler/tiered/LevelTransitionTest.java	Mon Jun 03 16:14:54 2019 +0100
     3.3 @@ -0,0 +1,247 @@
     3.4 +/*
     3.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 + * or visit www.oracle.com if you need additional information or have any
    3.24 + * questions.
    3.25 + */
    3.26 +
    3.27 +import java.lang.reflect.Executable;
    3.28 +import java.lang.reflect.Method;
    3.29 +import java.util.Objects;
    3.30 +import java.util.concurrent.Callable;
    3.31 +
    3.32 +/**
    3.33 + * @test LevelTransitionTest
    3.34 + * @library /testlibrary /testlibrary/whitebox /compiler/whitebox
    3.35 + * @build TransitionsTestExecutor LevelTransitionTest
    3.36 + * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
    3.37 + * @run main/othervm/timeout=240 -Xmixed -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
    3.38 + *                   -XX:+WhiteBoxAPI -XX:+TieredCompilation
    3.39 + *                   -XX:CompileCommand=compileonly,SimpleTestCase$Helper::*
    3.40 + *                   -XX:CompileCommand=compileonly,ExtendedTestCase$CompileMethodHolder::*
    3.41 + *                   TransitionsTestExecutor LevelTransitionTest
    3.42 + * @summary Test the correctness of compilation level transitions for different methods
    3.43 + */
    3.44 +public class LevelTransitionTest extends TieredLevelsTest {
    3.45 +    /** Shows if method was profiled by being executed on levels 2 or 3 */
    3.46 +    protected boolean isMethodProfiled;
    3.47 +    private int transitionCount;
    3.48 +
    3.49 +    public static void main(String[] args) throws Throwable {
    3.50 +        assert (!CompilerWhiteBoxTest.skipOnTieredCompilation(false));
    3.51 +
    3.52 +        CompilerWhiteBoxTest.main(LevelTransitionTest::new, args);
    3.53 +        // run extended test cases
    3.54 +        for (TestCase testCase : ExtendedTestCase.values()) {
    3.55 +            new LevelTransitionTest(testCase).runTest();
    3.56 +        }
    3.57 +    }
    3.58 +
    3.59 +    protected LevelTransitionTest(TestCase testCase) {
    3.60 +        super(testCase);
    3.61 +        isMethodProfiled = testCase.isOsr(); // OSR methods were already profiled by warmup
    3.62 +        transitionCount = 0;
    3.63 +    }
    3.64 +
    3.65 +    @Override
    3.66 +    protected void test() throws Exception {
    3.67 +        checkTransitions();
    3.68 +        deoptimize();
    3.69 +        printInfo();
    3.70 +        if (testCase.isOsr()) {
    3.71 +            // deoptimization makes the following transitions be unstable
    3.72 +            // methods go to level 3 before 4 because of uncommon_trap and reprofile
    3.73 +            return;
    3.74 +        }
    3.75 +        checkTransitions();
    3.76 +    }
    3.77 +
    3.78 +    /**
    3.79 +     * Makes and verifies transitions between compilation levels
    3.80 +     */
    3.81 +    protected void checkTransitions() {
    3.82 +        checkNotCompiled();
    3.83 +        boolean finish = false;
    3.84 +        while (!finish) {
    3.85 +            System.out.printf("Level transition #%d%n", ++transitionCount);
    3.86 +            int newLevel;
    3.87 +            int current = getCompLevel();
    3.88 +            int expected = getNextLevel(current);
    3.89 +            if (current == expected) {
    3.90 +                // if we are on expected level, just execute it more
    3.91 +                // to ensure that the level won't change
    3.92 +                System.out.printf("Method %s is already on expected level %d%n", method, expected);
    3.93 +                compile();
    3.94 +                newLevel = getCompLevel();
    3.95 +                finish = true;
    3.96 +            } else {
    3.97 +                newLevel = changeCompLevel();
    3.98 +                finish = false;
    3.99 +            }
   3.100 +            System.out.printf("Method %s is compiled on level %d. Expected level is %d%n", method, newLevel, expected);
   3.101 +            checkLevel(expected, newLevel);
   3.102 +            printInfo();
   3.103 +        };
   3.104 +    }
   3.105 +
   3.106 +    /**
   3.107 +     * Gets next expected level for the test case on each transition.
   3.108 +     *
   3.109 +     * @param currentLevel a level the test case is compiled on
   3.110 +     * @return expected compilation level
   3.111 +     */
   3.112 +    protected int getNextLevel(int currentLevel) {
   3.113 +        int nextLevel = currentLevel;
   3.114 +        switch (currentLevel) {
   3.115 +            case CompilerWhiteBoxTest.COMP_LEVEL_NONE:
   3.116 +                nextLevel = isMethodProfiled ? CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION
   3.117 +                        : CompilerWhiteBoxTest.COMP_LEVEL_FULL_PROFILE;
   3.118 +                break;
   3.119 +            case CompilerWhiteBoxTest.COMP_LEVEL_LIMITED_PROFILE:
   3.120 +            case CompilerWhiteBoxTest.COMP_LEVEL_FULL_PROFILE:
   3.121 +                nextLevel = CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION;
   3.122 +                isMethodProfiled = true;
   3.123 +                break;
   3.124 +        }
   3.125 +        nextLevel = isTrivial() ? CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE : nextLevel;
   3.126 +        return Math.min(nextLevel, CompilerWhiteBoxTest.TIERED_STOP_AT_LEVEL);
   3.127 +    }
   3.128 +
   3.129 +    /**
   3.130 +     * Determines if tested method should be handled as trivial
   3.131 +     *
   3.132 +     * @return {@code true} for trivial methods, {@code false} otherwise
   3.133 +     */
   3.134 +    protected boolean isTrivial() {
   3.135 +        return testCase == ExtendedTestCase.ACCESSOR_TEST
   3.136 +                || testCase == SimpleTestCase.METHOD_TEST
   3.137 +                || testCase == SimpleTestCase.STATIC_TEST
   3.138 +                || (testCase == ExtendedTestCase.TRIVIAL_CODE_TEST && isMethodProfiled);
   3.139 +    }
   3.140 +
   3.141 +    /**
   3.142 +     * Invokes {@linkplain #method} until its compilation level is changed.
   3.143 +     * Note that if the level won't change, it will be an endless loop
   3.144 +     *
   3.145 +     * @return compilation level the {@linkplain #method} was compiled on
   3.146 +     */
   3.147 +    protected int changeCompLevel() {
   3.148 +        int currentLevel = getCompLevel();
   3.149 +        int newLevel = currentLevel;
   3.150 +        int result = 0;
   3.151 +        while (currentLevel == newLevel) {
   3.152 +            result = compile(1);
   3.153 +            if (WHITE_BOX.isMethodCompiled(method, testCase.isOsr())) {
   3.154 +                newLevel = getCompLevel();
   3.155 +            }
   3.156 +        }
   3.157 +        return newLevel;
   3.158 +    }
   3.159 +
   3.160 +    protected static class Helper {
   3.161 +        /**
   3.162 +         * Gets method from a specified class using its name
   3.163 +         *
   3.164 +         * @param aClass type method belongs to
   3.165 +         * @param name   the name of the method
   3.166 +         * @return {@link Method} that represents corresponding class method
   3.167 +         */
   3.168 +        public static Method getMethod(Class<?> aClass, String name) {
   3.169 +            Method method;
   3.170 +            try {
   3.171 +                method = aClass.getDeclaredMethod(name);
   3.172 +            } catch (NoSuchMethodException e) {
   3.173 +                throw new Error("TESTBUG: Unable to get method " + name, e);
   3.174 +            }
   3.175 +            return method;
   3.176 +        }
   3.177 +
   3.178 +        /**
   3.179 +         * Gets {@link Callable} that invokes given method from the given object
   3.180 +         *
   3.181 +         * @param object the object the specified method is invoked from
   3.182 +         * @param name   the name of the method
   3.183 +         */
   3.184 +        public static Callable<Integer> getCallable(Object object, String name) {
   3.185 +            Method method = getMethod(object.getClass(), name);
   3.186 +            return () -> {
   3.187 +                try {
   3.188 +                    return Objects.hashCode(method.invoke(object));
   3.189 +                } catch (ReflectiveOperationException e) {
   3.190 +                    throw new Error("TESTBUG: Invocation failure", e);
   3.191 +                }
   3.192 +            };
   3.193 +        }
   3.194 +    }
   3.195 +}
   3.196 +
   3.197 +enum ExtendedTestCase implements CompilerWhiteBoxTest.TestCase {
   3.198 +    ACCESSOR_TEST("accessor"),
   3.199 +    NONTRIVIAL_METHOD_TEST("nonTrivialMethod"),
   3.200 +    TRIVIAL_CODE_TEST("trivialCode");
   3.201 +
   3.202 +    private final Executable executable;
   3.203 +    private final Callable<Integer> callable;
   3.204 +
   3.205 +    @Override
   3.206 +    public Executable getExecutable() {
   3.207 +        return executable;
   3.208 +    }
   3.209 +
   3.210 +    @Override
   3.211 +    public Callable<Integer> getCallable() {
   3.212 +        return callable;
   3.213 +    }
   3.214 +
   3.215 +    @Override
   3.216 +    public boolean isOsr() {
   3.217 +        return false;
   3.218 +    }
   3.219 +
   3.220 +    private ExtendedTestCase(String methodName) {
   3.221 +        this.executable = LevelTransitionTest.Helper.getMethod(CompileMethodHolder.class, methodName);
   3.222 +        this.callable = LevelTransitionTest.Helper.getCallable(new CompileMethodHolder(), methodName);
   3.223 +    }
   3.224 +
   3.225 +    private static class CompileMethodHolder {
   3.226 +        private final int iter = 10;
   3.227 +        private int field = 42;
   3.228 +
   3.229 +        /** Non-trivial method for threshold policy: contains loops */
   3.230 +        public int nonTrivialMethod() {
   3.231 +            int acc = 0;
   3.232 +            for (int i = 0; i < iter; i++) {
   3.233 +                acc += i;
   3.234 +            }
   3.235 +            return acc;
   3.236 +        }
   3.237 +
   3.238 +        /** Field accessor method */
   3.239 +        public int accessor() {
   3.240 +            return field;
   3.241 +        }
   3.242 +
   3.243 +        /** Method considered as trivial by amount of code */
   3.244 +        public int trivialCode() {
   3.245 +            int var = 0xBAAD_C0DE;
   3.246 +            var *= field;
   3.247 +            return var;
   3.248 +        }
   3.249 +    }
   3.250 +}
     4.1 --- a/test/compiler/tiered/NonTieredLevelsTest.java	Sun Mar 31 16:57:21 2019 -0700
     4.2 +++ b/test/compiler/tiered/NonTieredLevelsTest.java	Mon Jun 03 16:14:54 2019 +0100
     4.3 @@ -54,9 +54,7 @@
     4.4  
     4.5      }
     4.6      public static void main(String[] args) throws Exception {
     4.7 -        if (TIERED_COMPILATION) {
     4.8 -            System.err.println("Test isn't applicable w/ enabled "
     4.9 -                    + "TieredCompilation. Skip test.");
    4.10 +        if (CompilerWhiteBoxTest.skipOnTieredCompilation(true)) {
    4.11              return;
    4.12          }
    4.13          CompilerWhiteBoxTest.main(NonTieredLevelsTest::new, args);
     5.1 --- a/test/compiler/tiered/TieredLevelsTest.java	Sun Mar 31 16:57:21 2019 -0700
     5.2 +++ b/test/compiler/tiered/TieredLevelsTest.java	Mon Jun 03 16:14:54 2019 +0100
     5.3 @@ -34,16 +34,14 @@
     5.4   * @author igor.ignatyev@oracle.com
     5.5   */
     5.6  public class TieredLevelsTest extends CompLevelsTest {
     5.7 -    public static void main(String[] args) throws Exception {
     5.8 -        if (!TIERED_COMPILATION) {
     5.9 -            System.err.println("Test isn't applicable w/ disabled "
    5.10 -                    + "TieredCompilation. Skip test.");
    5.11 +    public static void main(String[] args) throws Exception, Throwable {
    5.12 +        if (CompilerWhiteBoxTest.skipOnTieredCompilation(false)) {
    5.13              return;
    5.14          }
    5.15          CompilerWhiteBoxTest.main(TieredLevelsTest::new, args);
    5.16      }
    5.17  
    5.18 -    private TieredLevelsTest(TestCase testCase) {
    5.19 +    protected TieredLevelsTest(TestCase testCase) {
    5.20          super(testCase);
    5.21          // to prevent inlining of #method
    5.22          WHITE_BOX.testSetDontInlineMethod(method, true);
    5.23 @@ -76,14 +74,18 @@
    5.24          }
    5.25      }
    5.26  
    5.27 -
    5.28      @Override
    5.29      protected void checkLevel(int expected, int actual) {
    5.30          if (expected == COMP_LEVEL_FULL_PROFILE
    5.31                  && actual == COMP_LEVEL_LIMITED_PROFILE) {
    5.32              // for simple method full_profile may be replaced by limited_profile
    5.33 +            if (IS_VERBOSE) {
    5.34 +                System.out.printf("Level check: full profiling was replaced "
    5.35 +                        + "by limited profiling. Expected: %d, actual:%d",
    5.36 +                        expected, actual);
    5.37 +            }
    5.38              return;
    5.39          }
    5.40          super.checkLevel(expected, actual);
    5.41 -   }
    5.42 +    }
    5.43  }
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/compiler/tiered/TransitionsTestExecutor.java	Mon Jun 03 16:14:54 2019 +0100
     6.3 @@ -0,0 +1,66 @@
     6.4 +/*
     6.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 + *
     6.8 + * This code is free software; you can redistribute it and/or modify it
     6.9 + * under the terms of the GNU General Public License version 2 only, as
    6.10 + * published by the Free Software Foundation.
    6.11 + *
    6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.15 + * version 2 for more details (a copy is included in the LICENSE file that
    6.16 + * accompanied this code).
    6.17 + *
    6.18 + * You should have received a copy of the GNU General Public License version
    6.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.21 + *
    6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    6.23 + * or visit www.oracle.com if you need additional information or have any
    6.24 + * questions.
    6.25 + */
    6.26 +
    6.27 +import com.oracle.java.testlibrary.OutputAnalyzer;
    6.28 +import com.oracle.java.testlibrary.ProcessTools;
    6.29 +
    6.30 +import java.lang.management.ManagementFactory;
    6.31 +import java.lang.management.RuntimeMXBean;
    6.32 +import java.util.ArrayList;
    6.33 +import java.util.Collections;
    6.34 +import java.util.List;
    6.35 +
    6.36 +/**
    6.37 + * Executes given test in a separate VM with enabled Tiered Compilation for
    6.38 + * CompilationPolicyChoice 2 and 3
    6.39 + */
    6.40 +public class TransitionsTestExecutor {
    6.41 +    public static void main(String[] args) throws Throwable {
    6.42 +        if (CompilerWhiteBoxTest.skipOnTieredCompilation(false)) {
    6.43 +            return;
    6.44 +        }
    6.45 +        if (args.length != 1) {
    6.46 +            throw new Error("TESTBUG: Test name should be specified");
    6.47 +        }
    6.48 +        executeTestFor(2, args[0]);
    6.49 +        executeTestFor(3, args[0]);
    6.50 +    }
    6.51 +
    6.52 +    private static void executeTestFor(int compilationPolicy, String testName) throws Throwable {
    6.53 +        String policy = "-XX:CompilationPolicyChoice=" + compilationPolicy;
    6.54 +
    6.55 +        // Get runtime arguments including VM options given to this executor
    6.56 +        RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    6.57 +        List<String> vmArgs = runtime.getInputArguments();
    6.58 +
    6.59 +        // Construct execution command with compilation policy choice and test name
    6.60 +        List<String> args = new ArrayList<>(vmArgs);
    6.61 +        Collections.addAll(args, policy, testName);
    6.62 +
    6.63 +        OutputAnalyzer out = ProcessTools.executeTestJvm(args.toArray(new String[args.size()]));
    6.64 +        int exitCode = out.getExitValue();
    6.65 +        if (exitCode != 0) {
    6.66 +            throw new Error("Test execution failed with exit code " + exitCode);
    6.67 +        }
    6.68 +    }
    6.69 +}
     7.1 --- a/test/compiler/whitebox/CompilerWhiteBoxTest.java	Sun Mar 31 16:57:21 2019 -0700
     7.2 +++ b/test/compiler/whitebox/CompilerWhiteBoxTest.java	Mon Jun 03 16:14:54 2019 +0100
     7.3 @@ -41,19 +41,19 @@
     7.4   */
     7.5  public abstract class CompilerWhiteBoxTest {
     7.6      /** {@code CompLevel::CompLevel_none} -- Interpreter */
     7.7 -    protected static int COMP_LEVEL_NONE = 0;
     7.8 +    protected static final int COMP_LEVEL_NONE = 0;
     7.9      /** {@code CompLevel::CompLevel_any}, {@code CompLevel::CompLevel_all} */
    7.10 -    protected static int COMP_LEVEL_ANY = -1;
    7.11 +    protected static final int COMP_LEVEL_ANY = -1;
    7.12      /** {@code CompLevel::CompLevel_simple} -- C1 */
    7.13 -    protected static int COMP_LEVEL_SIMPLE = 1;
    7.14 +    protected static final int COMP_LEVEL_SIMPLE = 1;
    7.15      /** {@code CompLevel::CompLevel_limited_profile} -- C1, invocation &amp; backedge counters */
    7.16 -    protected static int COMP_LEVEL_LIMITED_PROFILE = 2;
    7.17 +    protected static final int COMP_LEVEL_LIMITED_PROFILE = 2;
    7.18      /** {@code CompLevel::CompLevel_full_profile} -- C1, invocation &amp; backedge counters + mdo */
    7.19 -    protected static int COMP_LEVEL_FULL_PROFILE = 3;
    7.20 +    protected static final int COMP_LEVEL_FULL_PROFILE = 3;
    7.21      /** {@code CompLevel::CompLevel_full_optimization} -- C2 or Shark */
    7.22 -    protected static int COMP_LEVEL_FULL_OPTIMIZATION = 4;
    7.23 +    protected static final int COMP_LEVEL_FULL_OPTIMIZATION = 4;
    7.24      /** Maximal value for CompLevel */
    7.25 -    protected static int COMP_LEVEL_MAX = COMP_LEVEL_FULL_OPTIMIZATION;
    7.26 +    protected static final int COMP_LEVEL_MAX = COMP_LEVEL_FULL_OPTIMIZATION;
    7.27  
    7.28      /** Instance of WhiteBox */
    7.29      protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
    7.30 @@ -347,14 +347,22 @@
    7.31          System.out.printf("%n%s:%n", method);
    7.32          System.out.printf("\tcompilable:\t%b%n",
    7.33                  WHITE_BOX.isMethodCompilable(method, COMP_LEVEL_ANY, false));
    7.34 -        System.out.printf("\tcompiled:\t%b%n",
    7.35 -                WHITE_BOX.isMethodCompiled(method, false));
    7.36 +        boolean isCompiled = WHITE_BOX.isMethodCompiled(method, false);
    7.37 +        System.out.printf("\tcompiled:\t%b%n", isCompiled);
    7.38 +        if (isCompiled) {
    7.39 +            System.out.printf("\tcompile_id:\t%d%n",
    7.40 +                    NMethod.get(method, false).compile_id);
    7.41 +        }
    7.42          System.out.printf("\tcomp_level:\t%d%n",
    7.43                  WHITE_BOX.getMethodCompilationLevel(method, false));
    7.44          System.out.printf("\tosr_compilable:\t%b%n",
    7.45                  WHITE_BOX.isMethodCompilable(method, COMP_LEVEL_ANY, true));
    7.46 -        System.out.printf("\tosr_compiled:\t%b%n",
    7.47 -                WHITE_BOX.isMethodCompiled(method, true));
    7.48 +        isCompiled = WHITE_BOX.isMethodCompiled(method, true);
    7.49 +        System.out.printf("\tosr_compiled:\t%b%n", isCompiled);
    7.50 +        if (isCompiled) {
    7.51 +            System.out.printf("\tosr_compile_id:\t%d%n",
    7.52 +                    NMethod.get(method, true).compile_id);
    7.53 +        }
    7.54          System.out.printf("\tosr_comp_level:\t%d%n",
    7.55                  WHITE_BOX.getMethodCompilationLevel(method, true));
    7.56          System.out.printf("\tin_queue:\t%b%n",
    7.57 @@ -437,6 +445,22 @@
    7.58          }
    7.59          return result;
    7.60      }
    7.61 +
    7.62 +    /**
    7.63 +     * Skip the test for the specified value of Tiered Compilation
    7.64 +     * @param value of TieredCompilation the test should not run with
    7.65 +     * @return {@code true} if the test should be skipped,
    7.66 +     *         {@code false} otherwise
    7.67 +     */
    7.68 +    protected static boolean skipOnTieredCompilation(boolean value) {
    7.69 +        if (value == CompilerWhiteBoxTest.TIERED_COMPILATION) {
    7.70 +            System.err.println("Test isn't applicable w/ "
    7.71 +                    + (value ? "enabled" : "disabled")
    7.72 +                    + "TieredCompilation. Skip test.");
    7.73 +            return true;
    7.74 +        }
    7.75 +        return false;
    7.76 +    }
    7.77  }
    7.78  
    7.79  enum SimpleTestCase implements CompilerWhiteBoxTest.TestCase {
     8.1 --- a/test/testlibrary/whitebox/sun/hotspot/code/NMethod.java	Sun Mar 31 16:57:21 2019 -0700
     8.2 +++ b/test/testlibrary/whitebox/sun/hotspot/code/NMethod.java	Mon Jun 03 16:14:54 2019 +0100
     8.3 @@ -34,18 +34,21 @@
     8.4      return obj == null ? null : new NMethod(obj);
     8.5    }
     8.6    private NMethod(Object[] obj) {
     8.7 -    assert obj.length == 2;
     8.8 +    assert obj.length == 3;
     8.9      comp_level = (Integer) obj[0];
    8.10 -    insts = (byte[]) obj[1];
    8.11 +    compile_id = (Integer) obj[1];
    8.12 +    insts = (byte[]) obj[2];
    8.13    }
    8.14 -  public byte[] insts;
    8.15 -  public int comp_level;
    8.16 +  public final byte[] insts;
    8.17 +  public final int comp_level;
    8.18 +  public final int compile_id;
    8.19  
    8.20    @Override
    8.21    public String toString() {
    8.22      return "NMethod{" +
    8.23          "insts=" + insts +
    8.24          ", comp_level=" + comp_level +
    8.25 +        ", compile_id=" + compile_id +
    8.26          '}';
    8.27    }
    8.28  }

mercurial