hotspot/test/compiler/tiered/LevelTransitionTest.java
author ctornqvi
Fri, 19 Aug 2016 10:06:30 -0400
changeset 40631 ed82623d7831
parent 40059 c2304140ed64
child 42640 09dba077f1e7
permissions -rw-r--r--
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder Reviewed-by: coleenp, gtriantafill, mseledtsov, iignatyev, dholmes, dsamersoff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28194
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
     1
/*
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
28194
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
     4
 *
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
     8
 *
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    13
 * accompanied this code).
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    14
 *
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    18
 *
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    21
 * questions.
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    22
 */
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    23
39438
206a712f8f16 8132920: use package in compiler testlibraries
iignatyev
parents: 38033
diff changeset
    24
/**
206a712f8f16 8132920: use package in compiler testlibraries
iignatyev
parents: 38033
diff changeset
    25
 * @test LevelTransitionTest
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    26
 * @summary Test the correctness of compilation level transitions for different methods
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
    27
 * @library /test/lib /
39438
206a712f8f16 8132920: use package in compiler testlibraries
iignatyev
parents: 38033
diff changeset
    28
 * @modules java.base/jdk.internal.misc
206a712f8f16 8132920: use package in compiler testlibraries
iignatyev
parents: 38033
diff changeset
    29
 *          java.management
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    30
 *
39438
206a712f8f16 8132920: use package in compiler testlibraries
iignatyev
parents: 38033
diff changeset
    31
 * @ignore 8067651
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
    32
 * @build sun.hotspot.WhiteBox
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    33
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    34
 *                                sun.hotspot.WhiteBox$WhiteBoxPermission
39438
206a712f8f16 8132920: use package in compiler testlibraries
iignatyev
parents: 38033
diff changeset
    35
 * @run main/othervm/timeout=240 -Xmixed -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    36
 *                   -XX:+WhiteBoxAPI -XX:+TieredCompilation -XX:-UseCounterDecay
39438
206a712f8f16 8132920: use package in compiler testlibraries
iignatyev
parents: 38033
diff changeset
    37
 *                   -XX:CompileCommand=compileonly,compiler.whitebox.SimpleTestCaseHelper::*
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    38
 *                   -XX:CompileCommand=compileonly,compiler.tiered.LevelTransitionTest$ExtendedTestCase$CompileMethodHolder::*
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    39
 *                   compiler.tiered.TransitionsTestExecutor
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    40
 *                   compiler.tiered.LevelTransitionTest
39438
206a712f8f16 8132920: use package in compiler testlibraries
iignatyev
parents: 38033
diff changeset
    41
 */
206a712f8f16 8132920: use package in compiler testlibraries
iignatyev
parents: 38033
diff changeset
    42
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    43
package compiler.tiered;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    44
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    45
import compiler.whitebox.CompilerWhiteBoxTest;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    46
import compiler.whitebox.SimpleTestCase;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    47
28194
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    48
import java.lang.reflect.Executable;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    49
import java.lang.reflect.Method;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    50
import java.util.Objects;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    51
import java.util.concurrent.Callable;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    52
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    53
public class LevelTransitionTest extends TieredLevelsTest {
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    54
    /**
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    55
     * Shows if method was profiled by being executed on levels 2 or 3
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    56
     */
28194
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    57
    protected boolean isMethodProfiled;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    58
    private int transitionCount;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    59
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    60
    public static void main(String[] args) throws Throwable {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    61
        assert (!CompilerWhiteBoxTest.skipOnTieredCompilation(false));
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    62
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    63
        CompilerWhiteBoxTest.main(LevelTransitionTest::new, args);
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    64
        // run extended test cases
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    65
        for (TestCase testCase : ExtendedTestCase.values()) {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    66
            new LevelTransitionTest(testCase).runTest();
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    67
        }
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    68
    }
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    69
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    70
    protected LevelTransitionTest(TestCase testCase) {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    71
        super(testCase);
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    72
        isMethodProfiled = testCase.isOsr(); // OSR methods were already profiled by warmup
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    73
        transitionCount = 0;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    74
    }
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    75
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    76
    @Override
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    77
    protected void test() throws Exception {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    78
        checkTransitions();
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    79
        deoptimize();
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    80
        printInfo();
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    81
        if (testCase.isOsr()) {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    82
            // deoptimization makes the following transitions be unstable
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    83
            // methods go to level 3 before 4 because of uncommon_trap and reprofile
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    84
            return;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    85
        }
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    86
        checkTransitions();
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    87
    }
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    88
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    89
    /**
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    90
     * Makes and verifies transitions between compilation levels
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    91
     */
38032
bedc2fbb9454 8153885: [TESTBUG] few regression tests failed after 8151880 changes
neliasso
parents: 34185
diff changeset
    92
    protected void checkTransitions() throws Exception {
28194
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    93
        checkNotCompiled();
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    94
        boolean finish = false;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    95
        while (!finish) {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    96
            System.out.printf("Level transition #%d%n", ++transitionCount);
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    97
            int newLevel;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    98
            int current = getCompLevel();
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
    99
            int expected = getNextLevel(current);
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   100
            if (current == expected) {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   101
                // if we are on expected level, just execute it more
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   102
                // to ensure that the level won't change
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   103
                System.out.printf("Method %s is already on expected level %d%n", method, expected);
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   104
                compile();
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   105
                newLevel = getCompLevel();
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   106
                finish = true;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   107
            } else {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   108
                newLevel = changeCompLevel();
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   109
                finish = false;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   110
            }
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   111
            System.out.printf("Method %s is compiled on level %d. Expected level is %d%n", method, newLevel, expected);
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   112
            checkLevel(expected, newLevel);
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   113
            printInfo();
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   114
        }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   115
        ;
28194
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   116
    }
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   117
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   118
    /**
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   119
     * Gets next expected level for the test case on each transition.
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   120
     *
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   121
     * @param currentLevel a level the test case is compiled on
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   122
     * @return expected compilation level
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   123
     */
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   124
    protected int getNextLevel(int currentLevel) {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   125
        int nextLevel = currentLevel;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   126
        switch (currentLevel) {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   127
            case CompilerWhiteBoxTest.COMP_LEVEL_NONE:
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   128
                nextLevel = isMethodProfiled ? CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   129
                        : CompilerWhiteBoxTest.COMP_LEVEL_FULL_PROFILE;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   130
                break;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   131
            case CompilerWhiteBoxTest.COMP_LEVEL_LIMITED_PROFILE:
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   132
            case CompilerWhiteBoxTest.COMP_LEVEL_FULL_PROFILE:
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   133
                nextLevel = CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   134
                isMethodProfiled = true;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   135
                break;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   136
        }
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   137
        nextLevel = isTrivial() ? CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE : nextLevel;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   138
        return Math.min(nextLevel, CompilerWhiteBoxTest.TIERED_STOP_AT_LEVEL);
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   139
    }
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   140
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   141
    /**
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   142
     * Determines if tested method should be handled as trivial
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   143
     *
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   144
     * @return {@code true} for trivial methods, {@code false} otherwise
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   145
     */
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   146
    protected boolean isTrivial() {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   147
        return testCase == ExtendedTestCase.ACCESSOR_TEST
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   148
                || testCase == SimpleTestCase.METHOD_TEST
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   149
                || testCase == SimpleTestCase.STATIC_TEST
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   150
                || (testCase == ExtendedTestCase.TRIVIAL_CODE_TEST && isMethodProfiled);
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   151
    }
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   152
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   153
    /**
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   154
     * Invokes {@linkplain #method} until its compilation level is changed.
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   155
     * Note that if the level won't change, it will be an endless loop
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   156
     *
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   157
     * @return compilation level the {@linkplain #method} was compiled on
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   158
     */
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   159
    protected int changeCompLevel() {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   160
        int currentLevel = getCompLevel();
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   161
        int newLevel = currentLevel;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   162
        int result = 0;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   163
        while (currentLevel == newLevel) {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   164
            result = compile(1);
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   165
            if (WHITE_BOX.isMethodCompiled(method, testCase.isOsr())) {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   166
                newLevel = getCompLevel();
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   167
            }
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   168
        }
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   169
        return newLevel;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   170
    }
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   171
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   172
    protected static class Helper {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   173
        /**
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   174
         * Gets method from a specified class using its name
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   175
         *
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   176
         * @param aClass type method belongs to
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   177
         * @param name   the name of the method
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   178
         * @return {@link Method} that represents corresponding class method
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   179
         */
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   180
        public static Method getMethod(Class<?> aClass, String name) {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   181
            Method method;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   182
            try {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   183
                method = aClass.getDeclaredMethod(name);
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   184
            } catch (NoSuchMethodException e) {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   185
                throw new Error("TESTBUG: Unable to get method " + name, e);
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   186
            }
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   187
            return method;
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   188
        }
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   189
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   190
        /**
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   191
         * Gets {@link Callable} that invokes given method from the given object
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   192
         *
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   193
         * @param object the object the specified method is invoked from
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   194
         * @param name   the name of the method
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   195
         */
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   196
        public static Callable<Integer> getCallable(Object object, String name) {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   197
            Method method = getMethod(object.getClass(), name);
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   198
            return () -> {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   199
                try {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   200
                    return Objects.hashCode(method.invoke(object));
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   201
                } catch (ReflectiveOperationException e) {
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   202
                    throw new Error("TESTBUG: Invocation failure", e);
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   203
                }
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   204
            };
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   205
        }
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   206
    }
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   207
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   208
    private static enum ExtendedTestCase implements CompilerWhiteBoxTest.TestCase {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   209
        ACCESSOR_TEST("accessor"),
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   210
        NONTRIVIAL_METHOD_TEST("nonTrivialMethod"),
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   211
        TRIVIAL_CODE_TEST("trivialCode");
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   212
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   213
        private final Executable executable;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   214
        private final Callable<Integer> callable;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   215
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   216
        @Override
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   217
        public Executable getExecutable() {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   218
            return executable;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   219
        }
28194
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   220
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   221
        @Override
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   222
        public Callable<Integer> getCallable() {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   223
            return callable;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   224
        }
28194
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   225
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   226
        @Override
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   227
        public boolean isOsr() {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   228
            return false;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   229
        }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   230
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   231
        private ExtendedTestCase(String methodName) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   232
            this.executable = LevelTransitionTest.Helper.getMethod(CompileMethodHolder.class, methodName);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   233
            this.callable = LevelTransitionTest.Helper.getCallable(new CompileMethodHolder(), methodName);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   234
        }
28194
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   235
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   236
        private static class CompileMethodHolder {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   237
            private final int iter = 10;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   238
            private int field = 42;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   239
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   240
            /**
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   241
             * Non-trivial method for threshold policy: contains loops
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   242
             */
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   243
            public int nonTrivialMethod() {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   244
                int acc = 0;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   245
                for (int i = 0; i < iter; i++) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   246
                    acc += i;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   247
                }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   248
                return acc;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   249
            }
28194
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   250
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   251
            /**
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   252
             * Field accessor method
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   253
             */
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   254
            public int accessor() {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   255
                return field;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   256
            }
28194
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   257
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   258
            /**
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   259
             * Method considered as trivial by amount of code
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   260
             */
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   261
            public int trivialCode() {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   262
                int var = 0xBAAD_C0DE;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   263
                var *= field;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   264
                return var;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   265
            }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   266
        }
28194
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   267
    }
8c6c124a108b 8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
ppunegov
parents:
diff changeset
   268
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
   269
}