hotspot/test/compiler/whitebox/CompilerWhiteBoxTest.java
author thartmann
Mon, 13 Oct 2014 12:30:37 +0200
changeset 27146 06664440c7a3
parent 25736 6f35dbe32581
child 27411 f0e4c5b36ecd
permissions -rw-r--r--
8046268: compiler/whitebox/ tests fail : must be osr_compiled Summary: Added code to 'warm up' the methods before triggering OSR compilation by executing them a limited number of times. Like this, the profile information marks the loop exit as taken and we don't add an uncommon trap. Reviewed-by: kvn, dlong, iignatyev
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
     1
/*
23207
fc39038d37dc 8027124: [TESTBUG] NonTieredLevelsTest: java.lang.RuntimeException: private TestCase$Helper(java.lang.Object) must be osr_compiled
iignatyev
parents: 23188
diff changeset
     2
 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
     4
 *
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
     8
 *
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    14
 *
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    18
 *
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    21
 * questions.
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    22
 */
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    23
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    24
import sun.hotspot.WhiteBox;
23499
9d5b7480c9f4 8038240: new WB API to get nmethod
iignatyev
parents: 23207
diff changeset
    25
import sun.hotspot.code.NMethod;
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    26
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    27
import java.lang.reflect.Constructor;
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    28
import java.lang.reflect.Executable;
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    29
import java.lang.reflect.Method;
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    30
import java.util.Objects;
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    31
import java.util.concurrent.Callable;
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
    32
import java.util.function.Function;
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    33
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    34
/**
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    35
 * Abstract class for WhiteBox testing of JIT.
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    36
 *
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    37
 * @author igor.ignatyev@oracle.com
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    38
 */
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    39
public abstract class CompilerWhiteBoxTest {
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    40
    /** {@code CompLevel::CompLevel_none} -- Interpreter */
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    41
    protected static int COMP_LEVEL_NONE = 0;
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    42
    /** {@code CompLevel::CompLevel_any}, {@code CompLevel::CompLevel_all} */
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    43
    protected static int COMP_LEVEL_ANY = -1;
17126
42a942feeea2 8012322: Tiered: CompilationPolicy::can_be_compiled(CompLevel_all) mistakenly return false
iignatyev
parents: 17015
diff changeset
    44
    /** {@code CompLevel::CompLevel_simple} -- C1 */
42a942feeea2 8012322: Tiered: CompilationPolicy::can_be_compiled(CompLevel_all) mistakenly return false
iignatyev
parents: 17015
diff changeset
    45
    protected static int COMP_LEVEL_SIMPLE = 1;
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
    46
    /** {@code CompLevel::CompLevel_limited_profile} -- C1, invocation & backedge counters */
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
    47
    protected static int COMP_LEVEL_LIMITED_PROFILE = 2;
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
    48
    /** {@code CompLevel::CompLevel_full_profile} -- C1, invocation & backedge counters + mdo */
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
    49
    protected static int COMP_LEVEL_FULL_PROFILE = 3;
17126
42a942feeea2 8012322: Tiered: CompilationPolicy::can_be_compiled(CompLevel_all) mistakenly return false
iignatyev
parents: 17015
diff changeset
    50
    /** {@code CompLevel::CompLevel_full_optimization} -- C2 or Shark */
42a942feeea2 8012322: Tiered: CompilationPolicy::can_be_compiled(CompLevel_all) mistakenly return false
iignatyev
parents: 17015
diff changeset
    51
    protected static int COMP_LEVEL_FULL_OPTIMIZATION = 4;
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
    52
    /** Maximal value for CompLevel */
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
    53
    protected static int COMP_LEVEL_MAX = COMP_LEVEL_FULL_OPTIMIZATION;
17126
42a942feeea2 8012322: Tiered: CompilationPolicy::can_be_compiled(CompLevel_all) mistakenly return false
iignatyev
parents: 17015
diff changeset
    54
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    55
    /** Instance of WhiteBox */
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    56
    protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    57
    /** Value of {@code -XX:CompileThreshold} */
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    58
    protected static final int COMPILE_THRESHOLD
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    59
            = Integer.parseInt(getVMOption("CompileThreshold", "10000"));
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    60
    /** Value of {@code -XX:BackgroundCompilation} */
16367
9cd60b8380a1 8008211: Some of WB tests on compiler fail
iignatyev
parents: 15621
diff changeset
    61
    protected static final boolean BACKGROUND_COMPILATION
9cd60b8380a1 8008211: Some of WB tests on compiler fail
iignatyev
parents: 15621
diff changeset
    62
            = Boolean.valueOf(getVMOption("BackgroundCompilation", "true"));
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    63
    /** Value of {@code -XX:TieredCompilation} */
16689
efce070b8d42 8007288: Additional WB API for compiler's testing
iignatyev
parents: 16367
diff changeset
    64
    protected static final boolean TIERED_COMPILATION
efce070b8d42 8007288: Additional WB API for compiler's testing
iignatyev
parents: 16367
diff changeset
    65
            = Boolean.valueOf(getVMOption("TieredCompilation", "false"));
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    66
    /** Value of {@code -XX:TieredStopAtLevel} */
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    67
    protected static final int TIERED_STOP_AT_LEVEL
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    68
            = Integer.parseInt(getVMOption("TieredStopAtLevel", "0"));
19282
9764b5a041b6 8019915: whitebox testClearMethodStateTest fails with tiered on sparc
iignatyev
parents: 17126
diff changeset
    69
    /** Flag for verbose output, true if {@code -Dverbose} specified */
9764b5a041b6 8019915: whitebox testClearMethodStateTest fails with tiered on sparc
iignatyev
parents: 17126
diff changeset
    70
    protected static final boolean IS_VERBOSE
9764b5a041b6 8019915: whitebox testClearMethodStateTest fails with tiered on sparc
iignatyev
parents: 17126
diff changeset
    71
            = System.getProperty("verbose") != null;
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
    72
    /** invocation count to trigger compilation */
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
    73
    protected static final int THRESHOLD;
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
    74
    /** invocation count to trigger OSR compilation */
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
    75
    protected static final long BACKEDGE_THRESHOLD;
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
    76
    /** invocation count to warm up method before triggering OSR compilation */
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
    77
    protected static final long OSR_WARMUP = 2000;
20294
af95d17f2e04 8023452: TestCase$Helper(java.lang.Object) must be osr_compiled
iignatyev
parents: 19332
diff changeset
    78
    /** Value of {@code java.vm.info} (interpreted|mixed|comp mode) */
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
    79
    protected static final String MODE = System.getProperty("java.vm.info");
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
    80
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
    81
    static {
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
    82
        if (TIERED_COMPILATION) {
21091
588413a8426e 8023318: compiler/whitebox tests timeout with enabled TieredCompilation
iignatyev
parents: 20294
diff changeset
    83
            BACKEDGE_THRESHOLD = THRESHOLD = 150000;
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
    84
        } else {
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
    85
            THRESHOLD = COMPILE_THRESHOLD;
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
    86
            BACKEDGE_THRESHOLD = COMPILE_THRESHOLD * Long.parseLong(getVMOption(
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
    87
                    "OnStackReplacePercentage"));
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
    88
        }
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
    89
    }
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
    90
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    91
    /**
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    92
     * Returns value of VM option.
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    93
     *
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    94
     * @param name option's name
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    95
     * @return value of option or {@code null}, if option doesn't exist
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    96
     * @throws NullPointerException if name is null
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    97
     */
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    98
    protected static String getVMOption(String name) {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
    99
        Objects.requireNonNull(name);
25736
6f35dbe32581 8032449: Get rid of JMX in test/compiler
iignatyev
parents: 23499
diff changeset
   100
        return Objects.toString(WHITE_BOX.getVMFlag(name), null);
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   101
    }
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   102
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   103
    /**
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   104
     * Returns value of VM option or default value.
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   105
     *
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   106
     * @param name         option's name
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   107
     * @param defaultValue default value
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   108
     * @return value of option or {@code defaultValue}, if option doesn't exist
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   109
     * @throws NullPointerException if name is null
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   110
     * @see #getVMOption(String)
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   111
     */
16367
9cd60b8380a1 8008211: Some of WB tests on compiler fail
iignatyev
parents: 15621
diff changeset
   112
    protected static String getVMOption(String name, String defaultValue) {
9cd60b8380a1 8008211: Some of WB tests on compiler fail
iignatyev
parents: 15621
diff changeset
   113
        String result = getVMOption(name);
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   114
        return result == null ? defaultValue : result;
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   115
    }
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   116
17126
42a942feeea2 8012322: Tiered: CompilationPolicy::can_be_compiled(CompLevel_all) mistakenly return false
iignatyev
parents: 17015
diff changeset
   117
    /** copy of is_c1_compile(int) from utilities/globalDefinitions.hpp */
42a942feeea2 8012322: Tiered: CompilationPolicy::can_be_compiled(CompLevel_all) mistakenly return false
iignatyev
parents: 17015
diff changeset
   118
    protected static boolean isC1Compile(int compLevel) {
42a942feeea2 8012322: Tiered: CompilationPolicy::can_be_compiled(CompLevel_all) mistakenly return false
iignatyev
parents: 17015
diff changeset
   119
        return (compLevel > COMP_LEVEL_NONE)
42a942feeea2 8012322: Tiered: CompilationPolicy::can_be_compiled(CompLevel_all) mistakenly return false
iignatyev
parents: 17015
diff changeset
   120
                && (compLevel < COMP_LEVEL_FULL_OPTIMIZATION);
42a942feeea2 8012322: Tiered: CompilationPolicy::can_be_compiled(CompLevel_all) mistakenly return false
iignatyev
parents: 17015
diff changeset
   121
    }
42a942feeea2 8012322: Tiered: CompilationPolicy::can_be_compiled(CompLevel_all) mistakenly return false
iignatyev
parents: 17015
diff changeset
   122
42a942feeea2 8012322: Tiered: CompilationPolicy::can_be_compiled(CompLevel_all) mistakenly return false
iignatyev
parents: 17015
diff changeset
   123
    /** copy of is_c2_compile(int) from utilities/globalDefinitions.hpp */
42a942feeea2 8012322: Tiered: CompilationPolicy::can_be_compiled(CompLevel_all) mistakenly return false
iignatyev
parents: 17015
diff changeset
   124
    protected static boolean isC2Compile(int compLevel) {
42a942feeea2 8012322: Tiered: CompilationPolicy::can_be_compiled(CompLevel_all) mistakenly return false
iignatyev
parents: 17015
diff changeset
   125
        return compLevel == COMP_LEVEL_FULL_OPTIMIZATION;
42a942feeea2 8012322: Tiered: CompilationPolicy::can_be_compiled(CompLevel_all) mistakenly return false
iignatyev
parents: 17015
diff changeset
   126
    }
42a942feeea2 8012322: Tiered: CompilationPolicy::can_be_compiled(CompLevel_all) mistakenly return false
iignatyev
parents: 17015
diff changeset
   127
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   128
    protected static void main(
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   129
            Function<TestCase, CompilerWhiteBoxTest> constructor,
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   130
            String[] args) {
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   131
        if (args.length == 0) {
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   132
            for (TestCase test : SimpleTestCase.values()) {
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   133
                constructor.apply(test).runTest();
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   134
            }
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   135
        } else {
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   136
            for (String name : args) {
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   137
                constructor.apply(SimpleTestCase.valueOf(name)).runTest();
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   138
            }
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   139
        }
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   140
    }
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   141
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   142
    /** tested method */
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   143
    protected final Executable method;
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   144
    protected final TestCase testCase;
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   145
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   146
    /**
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   147
     * Constructor.
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   148
     *
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   149
     * @param testCase object, that contains tested method and way to invoke it.
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   150
     */
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   151
    protected CompilerWhiteBoxTest(TestCase testCase) {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   152
        Objects.requireNonNull(testCase);
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   153
        System.out.println("TEST CASE:" + testCase.name());
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   154
        method = testCase.getExecutable();
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   155
        this.testCase = testCase;
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   156
    }
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   157
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   158
    /**
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   159
     * Template method for testing. Prints tested method's info before
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   160
     * {@linkplain #test()} and after {@linkplain #test()} or on thrown
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   161
     * exception.
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   162
     *
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   163
     * @throws RuntimeException if method {@linkplain #test()} throws any
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   164
     *                          exception
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   165
     * @see #test()
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   166
     */
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   167
    protected final void runTest() {
25736
6f35dbe32581 8032449: Get rid of JMX in test/compiler
iignatyev
parents: 23499
diff changeset
   168
        if (CompilerWhiteBoxTest.MODE.startsWith("interpreted ")) {
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   169
            System.err.println(
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   170
                    "Warning: test is not applicable in interpreted mode");
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   171
            return;
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   172
        }
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   173
        System.out.println("at test's start:");
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   174
        printInfo();
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   175
        try {
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   176
            test();
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   177
        } catch (Exception e) {
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   178
            System.out.printf("on exception '%s':", e.getMessage());
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   179
            printInfo();
16367
9cd60b8380a1 8008211: Some of WB tests on compiler fail
iignatyev
parents: 15621
diff changeset
   180
            e.printStackTrace();
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   181
            if (e instanceof RuntimeException) {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   182
                throw (RuntimeException) e;
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   183
            }
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   184
            throw new RuntimeException(e);
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   185
        }
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   186
        System.out.println("at test's end:");
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   187
        printInfo();
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   188
    }
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   189
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   190
    /**
23188
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   191
     * Checks, that {@linkplain #method} is not compiled at the given compilation
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   192
     * level or above.
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   193
     *
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   194
     * @param compLevel
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   195
     *
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   196
     * @throws RuntimeException if {@linkplain #method} is in compiler queue or
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   197
     *                          is compiled, or if {@linkplain #method} has zero
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   198
     *                          compilation level.
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   199
     */
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   200
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   201
    protected final void checkNotCompiled(int compLevel) {
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   202
        if (WHITE_BOX.isMethodQueuedForCompilation(method)) {
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   203
            throw new RuntimeException(method + " must not be in queue");
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   204
        }
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   205
        if (WHITE_BOX.getMethodCompilationLevel(method, false) >= compLevel) {
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   206
            throw new RuntimeException(method + " comp_level must be >= maxCompLevel");
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   207
        }
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   208
        if (WHITE_BOX.getMethodCompilationLevel(method, true) >= compLevel) {
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   209
            throw new RuntimeException(method + " osr_comp_level must be >= maxCompLevel");
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   210
        }
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   211
    }
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   212
21757c31b2c9 8007270: Make IsMethodCompilable test work with tiered
neliasso
parents: 22214
diff changeset
   213
    /**
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   214
     * Checks, that {@linkplain #method} is not compiled.
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   215
     *
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   216
     * @throws RuntimeException if {@linkplain #method} is in compiler queue or
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   217
     *                          is compiled, or if {@linkplain #method} has zero
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   218
     *                          compilation level.
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   219
     */
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   220
    protected final void checkNotCompiled() {
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   221
        if (WHITE_BOX.isMethodCompiled(method, false)) {
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   222
            throw new RuntimeException(method + " must be not compiled");
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   223
        }
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   224
        if (WHITE_BOX.getMethodCompilationLevel(method, false) != 0) {
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   225
            throw new RuntimeException(method + " comp_level must be == 0");
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   226
        }
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   227
        checkNotOsrCompiled();
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   228
    }
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   229
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   230
    protected final void checkNotOsrCompiled() {
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   231
        if (WHITE_BOX.isMethodQueuedForCompilation(method)) {
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   232
            throw new RuntimeException(method + " must not be in queue");
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   233
        }
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   234
        if (WHITE_BOX.isMethodCompiled(method, true)) {
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   235
            throw new RuntimeException(method + " must be not osr_compiled");
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   236
        }
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   237
        if (WHITE_BOX.getMethodCompilationLevel(method, true) != 0) {
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   238
            throw new RuntimeException(method + " osr_comp_level must be == 0");
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   239
        }
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   240
    }
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   241
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   242
    /**
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   243
     * Checks, that {@linkplain #method} is compiled.
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   244
     *
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   245
     * @throws RuntimeException if {@linkplain #method} isn't in compiler queue
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   246
     *                          and isn't compiled, or if {@linkplain #method}
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   247
     *                          has nonzero compilation level
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   248
     */
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   249
    protected final void checkCompiled() {
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   250
        final long start = System.currentTimeMillis();
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   251
        waitBackgroundCompilation();
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   252
        if (WHITE_BOX.isMethodQueuedForCompilation(method)) {
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   253
            System.err.printf("Warning: %s is still in queue after %dms%n",
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   254
                    method, System.currentTimeMillis() - start);
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   255
            return;
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   256
        }
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   257
        if (!WHITE_BOX.isMethodCompiled(method, testCase.isOsr())) {
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   258
            throw new RuntimeException(method + " must be "
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   259
                    + (testCase.isOsr() ? "osr_" : "") + "compiled");
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   260
        }
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   261
        if (WHITE_BOX.getMethodCompilationLevel(method, testCase.isOsr())
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   262
                == 0) {
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   263
            throw new RuntimeException(method
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   264
                    + (testCase.isOsr() ? " osr_" : " ")
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   265
                    + "comp_level must be != 0");
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   266
        }
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   267
    }
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   268
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   269
    protected final void deoptimize() {
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   270
        WHITE_BOX.deoptimizeMethod(method, testCase.isOsr());
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   271
        if (testCase.isOsr()) {
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   272
            WHITE_BOX.deoptimizeMethod(method, false);
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   273
        }
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   274
    }
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   275
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   276
    protected final int getCompLevel() {
23499
9d5b7480c9f4 8038240: new WB API to get nmethod
iignatyev
parents: 23207
diff changeset
   277
        NMethod nm = NMethod.get(method, testCase.isOsr());
9d5b7480c9f4 8038240: new WB API to get nmethod
iignatyev
parents: 23207
diff changeset
   278
        return nm == null ? COMP_LEVEL_NONE : nm.comp_level;
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   279
    }
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   280
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   281
    protected final boolean isCompilable() {
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   282
        return WHITE_BOX.isMethodCompilable(method, COMP_LEVEL_ANY,
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   283
                testCase.isOsr());
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   284
    }
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   285
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   286
    protected final boolean isCompilable(int compLevel) {
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   287
        return WHITE_BOX
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   288
                .isMethodCompilable(method, compLevel, testCase.isOsr());
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   289
    }
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   290
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   291
    protected final void makeNotCompilable() {
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   292
        WHITE_BOX.makeMethodNotCompilable(method, COMP_LEVEL_ANY,
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   293
                testCase.isOsr());
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   294
    }
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   295
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   296
    protected final void makeNotCompilable(int compLevel) {
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   297
        WHITE_BOX.makeMethodNotCompilable(method, compLevel, testCase.isOsr());
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   298
    }
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   299
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   300
    /**
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   301
     * Waits for completion of background compilation of {@linkplain #method}.
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   302
     */
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   303
    protected final void waitBackgroundCompilation() {
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   304
        waitBackgroundCompilation(method);
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   305
    }
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   306
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   307
    /**
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   308
     * Waits for completion of background compilation of the given executable.
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   309
     *
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   310
     * @param executable Executable
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   311
     */
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   312
    protected static final void waitBackgroundCompilation(Executable executable) {
16367
9cd60b8380a1 8008211: Some of WB tests on compiler fail
iignatyev
parents: 15621
diff changeset
   313
        if (!BACKGROUND_COMPILATION) {
9cd60b8380a1 8008211: Some of WB tests on compiler fail
iignatyev
parents: 15621
diff changeset
   314
            return;
9cd60b8380a1 8008211: Some of WB tests on compiler fail
iignatyev
parents: 15621
diff changeset
   315
        }
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   316
        final Object obj = new Object();
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   317
        for (int i = 0; i < 10
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   318
                && WHITE_BOX.isMethodQueuedForCompilation(executable); ++i) {
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   319
            synchronized (obj) {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   320
                try {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   321
                    obj.wait(1000);
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   322
                } catch (InterruptedException e) {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   323
                    Thread.currentThread().interrupt();
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   324
                }
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   325
            }
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   326
        }
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   327
    }
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   328
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   329
    /**
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   330
     * Prints information about {@linkplain #method}.
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   331
     */
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   332
    protected final void printInfo() {
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   333
        System.out.printf("%n%s:%n", method);
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   334
        System.out.printf("\tcompilable:\t%b%n",
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   335
                WHITE_BOX.isMethodCompilable(method, COMP_LEVEL_ANY, false));
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   336
        System.out.printf("\tcompiled:\t%b%n",
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   337
                WHITE_BOX.isMethodCompiled(method, false));
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   338
        System.out.printf("\tcomp_level:\t%d%n",
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   339
                WHITE_BOX.getMethodCompilationLevel(method, false));
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   340
        System.out.printf("\tosr_compilable:\t%b%n",
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   341
                WHITE_BOX.isMethodCompilable(method, COMP_LEVEL_ANY, true));
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   342
        System.out.printf("\tosr_compiled:\t%b%n",
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   343
                WHITE_BOX.isMethodCompiled(method, true));
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   344
        System.out.printf("\tosr_comp_level:\t%d%n",
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   345
                WHITE_BOX.getMethodCompilationLevel(method, true));
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   346
        System.out.printf("\tin_queue:\t%b%n",
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   347
                WHITE_BOX.isMethodQueuedForCompilation(method));
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   348
        System.out.printf("compile_queues_size:\t%d%n%n",
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   349
                WHITE_BOX.getCompileQueuesSize());
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   350
    }
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   351
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   352
    /**
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   353
     * Executes testing.
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   354
     */
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   355
    protected abstract void test() throws Exception;
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   356
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   357
    /**
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   358
     * Tries to trigger compilation of {@linkplain #method} by call
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   359
     * {@linkplain TestCase#getCallable()} enough times.
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   360
     *
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   361
     * @return accumulated result
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   362
     * @see #compile(int)
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   363
     */
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   364
    protected final int compile() {
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   365
        if (testCase.isOsr()) {
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   366
            return compile(1);
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   367
        } else {
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   368
            return compile(THRESHOLD);
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   369
        }
16689
efce070b8d42 8007288: Additional WB API for compiler's testing
iignatyev
parents: 16367
diff changeset
   370
    }
efce070b8d42 8007288: Additional WB API for compiler's testing
iignatyev
parents: 16367
diff changeset
   371
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   372
    /**
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   373
     * Tries to trigger compilation of {@linkplain #method} by call
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   374
     * {@linkplain TestCase#getCallable()} specified times.
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   375
     *
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   376
     * @param count invocation count
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   377
     * @return accumulated result
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   378
     */
16689
efce070b8d42 8007288: Additional WB API for compiler's testing
iignatyev
parents: 16367
diff changeset
   379
    protected final int compile(int count) {
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   380
        int result = 0;
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   381
        Integer tmp;
16367
9cd60b8380a1 8008211: Some of WB tests on compiler fail
iignatyev
parents: 15621
diff changeset
   382
        for (int i = 0; i < count; ++i) {
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   383
            try {
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   384
                tmp = testCase.getCallable().call();
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   385
            } catch (Exception e) {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   386
                tmp = null;
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   387
            }
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   388
            result += tmp == null ? 0 : tmp;
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   389
        }
19282
9764b5a041b6 8019915: whitebox testClearMethodStateTest fails with tiered on sparc
iignatyev
parents: 17126
diff changeset
   390
        if (IS_VERBOSE) {
9764b5a041b6 8019915: whitebox testClearMethodStateTest fails with tiered on sparc
iignatyev
parents: 17126
diff changeset
   391
            System.out.println("method was invoked " + count + " times");
9764b5a041b6 8019915: whitebox testClearMethodStateTest fails with tiered on sparc
iignatyev
parents: 17126
diff changeset
   392
        }
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   393
        return result;
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   394
    }
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   395
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   396
    /**
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   397
     * Utility interface provides tested method and object to invoke it.
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   398
     */
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   399
    public interface TestCase {
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   400
        /** the name of test case */
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   401
        String name();
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   402
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   403
        /** tested method */
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   404
        Executable getExecutable();
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   405
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   406
        /** object to invoke {@linkplain #getExecutable()} */
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   407
        Callable<Integer> getCallable();
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   408
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   409
        /** flag for OSR test case */
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   410
        boolean isOsr();
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   411
    }
23207
fc39038d37dc 8027124: [TESTBUG] NonTieredLevelsTest: java.lang.RuntimeException: private TestCase$Helper(java.lang.Object) must be osr_compiled
iignatyev
parents: 23188
diff changeset
   412
fc39038d37dc 8027124: [TESTBUG] NonTieredLevelsTest: java.lang.RuntimeException: private TestCase$Helper(java.lang.Object) must be osr_compiled
iignatyev
parents: 23188
diff changeset
   413
    /**
fc39038d37dc 8027124: [TESTBUG] NonTieredLevelsTest: java.lang.RuntimeException: private TestCase$Helper(java.lang.Object) must be osr_compiled
iignatyev
parents: 23188
diff changeset
   414
     * @return {@code true} if the current test case is OSR and the mode is
fc39038d37dc 8027124: [TESTBUG] NonTieredLevelsTest: java.lang.RuntimeException: private TestCase$Helper(java.lang.Object) must be osr_compiled
iignatyev
parents: 23188
diff changeset
   415
     *          Xcomp, otherwise {@code false}
fc39038d37dc 8027124: [TESTBUG] NonTieredLevelsTest: java.lang.RuntimeException: private TestCase$Helper(java.lang.Object) must be osr_compiled
iignatyev
parents: 23188
diff changeset
   416
     */
fc39038d37dc 8027124: [TESTBUG] NonTieredLevelsTest: java.lang.RuntimeException: private TestCase$Helper(java.lang.Object) must be osr_compiled
iignatyev
parents: 23188
diff changeset
   417
    protected boolean skipXcompOSR() {
fc39038d37dc 8027124: [TESTBUG] NonTieredLevelsTest: java.lang.RuntimeException: private TestCase$Helper(java.lang.Object) must be osr_compiled
iignatyev
parents: 23188
diff changeset
   418
        boolean result =  testCase.isOsr()
fc39038d37dc 8027124: [TESTBUG] NonTieredLevelsTest: java.lang.RuntimeException: private TestCase$Helper(java.lang.Object) must be osr_compiled
iignatyev
parents: 23188
diff changeset
   419
                && CompilerWhiteBoxTest.MODE.startsWith("compiled ");
fc39038d37dc 8027124: [TESTBUG] NonTieredLevelsTest: java.lang.RuntimeException: private TestCase$Helper(java.lang.Object) must be osr_compiled
iignatyev
parents: 23188
diff changeset
   420
        if (result && IS_VERBOSE) {
fc39038d37dc 8027124: [TESTBUG] NonTieredLevelsTest: java.lang.RuntimeException: private TestCase$Helper(java.lang.Object) must be osr_compiled
iignatyev
parents: 23188
diff changeset
   421
            System.err.printf("Warning: %s is not applicable in %s%n",
fc39038d37dc 8027124: [TESTBUG] NonTieredLevelsTest: java.lang.RuntimeException: private TestCase$Helper(java.lang.Object) must be osr_compiled
iignatyev
parents: 23188
diff changeset
   422
                    testCase.name(), CompilerWhiteBoxTest.MODE);
fc39038d37dc 8027124: [TESTBUG] NonTieredLevelsTest: java.lang.RuntimeException: private TestCase$Helper(java.lang.Object) must be osr_compiled
iignatyev
parents: 23188
diff changeset
   423
        }
fc39038d37dc 8027124: [TESTBUG] NonTieredLevelsTest: java.lang.RuntimeException: private TestCase$Helper(java.lang.Object) must be osr_compiled
iignatyev
parents: 23188
diff changeset
   424
        return result;
fc39038d37dc 8027124: [TESTBUG] NonTieredLevelsTest: java.lang.RuntimeException: private TestCase$Helper(java.lang.Object) must be osr_compiled
iignatyev
parents: 23188
diff changeset
   425
    }
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   426
}
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   427
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   428
enum SimpleTestCase implements CompilerWhiteBoxTest.TestCase {
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   429
    /** constructor test case */
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   430
    CONSTRUCTOR_TEST(Helper.CONSTRUCTOR, Helper.CONSTRUCTOR_CALLABLE, false),
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   431
    /** method test case */
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   432
    METHOD_TEST(Helper.METHOD, Helper.METHOD_CALLABLE, false),
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   433
    /** static method test case */
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   434
    STATIC_TEST(Helper.STATIC, Helper.STATIC_CALLABLE, false),
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   435
    /** OSR constructor test case */
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   436
    OSR_CONSTRUCTOR_TEST(Helper.OSR_CONSTRUCTOR,
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   437
            Helper.OSR_CONSTRUCTOR_CALLABLE, true),
21091
588413a8426e 8023318: compiler/whitebox tests timeout with enabled TieredCompilation
iignatyev
parents: 20294
diff changeset
   438
    /** OSR method test case */
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   439
    OSR_METHOD_TEST(Helper.OSR_METHOD, Helper.OSR_METHOD_CALLABLE, true),
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   440
    /** OSR static method test case */
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   441
    OSR_STATIC_TEST(Helper.OSR_STATIC, Helper.OSR_STATIC_CALLABLE, true);
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   442
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   443
    private final Executable executable;
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   444
    private final Callable<Integer> callable;
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   445
    private final boolean isOsr;
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   446
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   447
    private SimpleTestCase(Executable executable, Callable<Integer> callable,
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   448
            boolean isOsr) {
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   449
        this.executable = executable;
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   450
        this.callable = callable;
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   451
        this.isOsr = isOsr;
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   452
    }
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   453
22214
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   454
    @Override
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   455
    public Executable getExecutable() {
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   456
        return executable;
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   457
    }
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   458
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   459
    @Override
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   460
    public Callable<Integer> getCallable() {
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   461
        return callable;
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   462
    }
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   463
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   464
    @Override
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   465
    public boolean isOsr() {
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   466
        return isOsr;
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   467
    }
c551021e75b2 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
iignatyev
parents: 21091
diff changeset
   468
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   469
    private static class Helper {
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   470
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   471
        private static final Callable<Integer> CONSTRUCTOR_CALLABLE
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   472
                = new Callable<Integer>() {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   473
            @Override
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   474
            public Integer call() throws Exception {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   475
                return new Helper(1337).hashCode();
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   476
            }
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   477
        };
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   478
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   479
        private static final Callable<Integer> METHOD_CALLABLE
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   480
                = new Callable<Integer>() {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   481
            private final Helper helper = new Helper();
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   482
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   483
            @Override
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   484
            public Integer call() throws Exception {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   485
                return helper.method();
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   486
            }
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   487
        };
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   488
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   489
        private static final Callable<Integer> STATIC_CALLABLE
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   490
                = new Callable<Integer>() {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   491
            @Override
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   492
            public Integer call() throws Exception {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   493
                return staticMethod();
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   494
            }
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   495
        };
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   496
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   497
        private static final Callable<Integer> OSR_CONSTRUCTOR_CALLABLE
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   498
                = new Callable<Integer>() {
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   499
            @Override
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   500
            public Integer call() throws Exception {
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   501
                int result = warmup(OSR_CONSTRUCTOR);
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   502
                return result + new Helper(null, CompilerWhiteBoxTest.BACKEDGE_THRESHOLD).hashCode();
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   503
            }
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   504
        };
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   505
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   506
        private static final Callable<Integer> OSR_METHOD_CALLABLE
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   507
                = new Callable<Integer>() {
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   508
            private final Helper helper = new Helper();
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   509
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   510
            @Override
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   511
            public Integer call() throws Exception {
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   512
                int result = warmup(OSR_METHOD);
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   513
                return result + helper.osrMethod(CompilerWhiteBoxTest.BACKEDGE_THRESHOLD);
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   514
            }
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   515
        };
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   516
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   517
        private static final Callable<Integer> OSR_STATIC_CALLABLE
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   518
                = new Callable<Integer>() {
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   519
            @Override
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   520
            public Integer call() throws Exception {
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   521
                int result = warmup(OSR_STATIC);
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   522
                return result + osrStaticMethod(CompilerWhiteBoxTest.BACKEDGE_THRESHOLD);
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   523
            }
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   524
        };
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   525
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   526
        /**
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   527
         * Deoptimizes all non-osr versions of the given executable after
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   528
         * compilation finished.
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   529
         *
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   530
         * @param e Executable
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   531
         * @throws Exception
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   532
         */
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   533
        private static void waitAndDeoptimize(Executable e) throws Exception {
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   534
            CompilerWhiteBoxTest.waitBackgroundCompilation(e);
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   535
            if (WhiteBox.getWhiteBox().isMethodQueuedForCompilation(e)) {
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   536
                throw new RuntimeException(e + " must not be in queue");
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   537
            }
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   538
            // Deoptimize non-osr versions of executable
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   539
            WhiteBox.getWhiteBox().deoptimizeMethod(e, false);
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   540
        }
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   541
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   542
        /**
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   543
         * Executes the method multiple times to make sure we have
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   544
         * enough profiling information before triggering an OSR
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   545
         * compilation. Otherwise the C2 compiler may add uncommon traps.
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   546
         *
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   547
         * @param m Method to be executed
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   548
         * @return Number of times the method was executed
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   549
         * @throws Exception
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   550
         */
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   551
        private static int warmup(Method m) throws Exception {
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   552
            Helper helper = new Helper();
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   553
            int result = 0;
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   554
            for (long i = 0; i < CompilerWhiteBoxTest.OSR_WARMUP; ++i) {
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   555
                result += (int)m.invoke(helper, 1);
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   556
            }
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   557
            // Deoptimize non-osr versions
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   558
            waitAndDeoptimize(m);
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   559
            return result;
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   560
        }
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   561
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   562
        /**
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   563
         * Executes the constructor multiple times to make sure we
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   564
         * have enough profiling information before triggering an OSR
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   565
         * compilation. Otherwise the C2 compiler may add uncommon traps.
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   566
         *
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   567
         * @param c Constructor to be executed
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   568
         * @return Number of times the constructor was executed
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   569
         * @throws Exception
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   570
         */
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   571
        private static int warmup(Constructor c) throws Exception {
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   572
            int result = 0;
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   573
            for (long i = 0; i < CompilerWhiteBoxTest.OSR_WARMUP; ++i) {
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   574
                result += c.newInstance(null, 1).hashCode();
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   575
            }
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   576
            // Deoptimize non-osr versions
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   577
            waitAndDeoptimize(c);
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   578
            return result;
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   579
        }
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   580
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   581
        private static final Constructor CONSTRUCTOR;
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   582
        private static final Constructor OSR_CONSTRUCTOR;
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   583
        private static final Method METHOD;
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   584
        private static final Method STATIC;
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   585
        private static final Method OSR_METHOD;
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   586
        private static final Method OSR_STATIC;
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   587
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   588
        static {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   589
            try {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   590
                CONSTRUCTOR = Helper.class.getDeclaredConstructor(int.class);
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   591
            } catch (NoSuchMethodException | SecurityException e) {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   592
                throw new RuntimeException(
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   593
                        "exception on getting method Helper.<init>(int)", e);
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   594
            }
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   595
            try {
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   596
                OSR_CONSTRUCTOR = Helper.class.getDeclaredConstructor(
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   597
                        Object.class, long.class);
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   598
            } catch (NoSuchMethodException | SecurityException e) {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   599
                throw new RuntimeException(
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   600
                        "exception on getting method Helper.<init>(Object, long)", e);
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   601
            }
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   602
            METHOD = getMethod("method");
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   603
            STATIC = getMethod("staticMethod");
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   604
            OSR_METHOD = getMethod("osrMethod", long.class);
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   605
            OSR_STATIC = getMethod("osrStaticMethod", long.class);
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   606
        }
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   607
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   608
        private static Method getMethod(String name, Class<?>... parameterTypes) {
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   609
            try {
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   610
                return Helper.class.getDeclaredMethod(name, parameterTypes);
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   611
            } catch (NoSuchMethodException | SecurityException e) {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   612
                throw new RuntimeException(
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   613
                        "exception on getting method Helper." + name, e);
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   614
            }
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   615
        }
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   616
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   617
        private static int staticMethod() {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   618
            return 1138;
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   619
        }
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   620
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   621
        private int method() {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   622
            return 42;
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   623
        }
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   624
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   625
        private static int osrStaticMethod(long limit) {
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   626
            int result = 0;
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   627
            for (long i = 0; i < limit; ++i) {
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   628
                result += staticMethod();
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   629
            }
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   630
            return result;
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   631
        }
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   632
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   633
        private int osrMethod(long limit) {
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   634
            int result = 0;
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   635
            for (long i = 0; i < limit; ++i) {
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   636
                result += method();
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   637
            }
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   638
            return result;
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   639
        }
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   640
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   641
        private final int x;
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   642
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   643
        // for method and OSR method test case
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   644
        public Helper() {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   645
            x = 0;
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   646
        }
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   647
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   648
        // for OSR constructor test case
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   649
        private Helper(Object o, long limit) {
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   650
            int result = 0;
27146
06664440c7a3 8046268: compiler/whitebox/ tests fail : must be osr_compiled
thartmann
parents: 25736
diff changeset
   651
            for (long i = 0; i < limit; ++i) {
19332
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   652
                result += method();
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   653
            }
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   654
            x = result;
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   655
        }
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   656
ee4c8c2af356 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 19282
diff changeset
   657
        // for constructor test case
17015
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   658
        private Helper(int x) {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   659
            this.x = x;
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   660
        }
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   661
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   662
        @Override
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   663
        public int hashCode() {
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   664
            return x;
92390f57e8b1 8011971: WB API doesn't accept j.l.reflect.Constructor
iignatyev
parents: 16689
diff changeset
   665
        }
15621
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   666
    }
b094c56bba84 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
   667
}