hotspot/test/compiler/whitebox/SimpleTestCase.java
author dpochepk
Fri, 06 Nov 2015 14:54:02 +0300
changeset 34155 8d9e0cbf93a2
child 38025 5ed9ce1e4a2f
permissions -rw-r--r--
8138689: use package for /compiler/whitebox common classes Summary: Moved CompilerWhiteBoxTest to package, updating tests accordingly Reviewed-by: iignatyev
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34155
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
     1
/*
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
     4
 *
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
     8
 *
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    13
 * accompanied this code).
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    14
 *
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    18
 *
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    21
 * questions.
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    22
 */
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    23
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    24
package compiler.whitebox;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    25
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    26
import java.lang.reflect.Constructor;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    27
import java.lang.reflect.Executable;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    28
import java.lang.reflect.Method;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    29
import java.util.concurrent.Callable;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    30
import sun.hotspot.WhiteBox;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    31
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    32
public enum SimpleTestCase implements CompilerWhiteBoxTest.TestCase {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    33
    /** constructor test case */
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    34
    CONSTRUCTOR_TEST(Helper.CONSTRUCTOR, Helper.CONSTRUCTOR_CALLABLE, false),
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    35
    /** method test case */
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    36
    METHOD_TEST(Helper.METHOD, Helper.METHOD_CALLABLE, false),
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    37
    /** static method test case */
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    38
    STATIC_TEST(Helper.STATIC, Helper.STATIC_CALLABLE, false),
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    39
    /** OSR constructor test case */
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    40
    OSR_CONSTRUCTOR_TEST(Helper.OSR_CONSTRUCTOR,
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    41
            Helper.OSR_CONSTRUCTOR_CALLABLE, true),
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    42
    /** OSR method test case */
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    43
    OSR_METHOD_TEST(Helper.OSR_METHOD, Helper.OSR_METHOD_CALLABLE, true),
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    44
    /** OSR static method test case */
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    45
    OSR_STATIC_TEST(Helper.OSR_STATIC, Helper.OSR_STATIC_CALLABLE, true);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    46
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    47
    private final Executable executable;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    48
    private final Callable<Integer> callable;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    49
    private final boolean isOsr;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    50
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    51
    private SimpleTestCase(Executable executable, Callable<Integer> callable,
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    52
            boolean isOsr) {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    53
        this.executable = executable;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    54
        this.callable = callable;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    55
        this.isOsr = isOsr;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    56
    }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    57
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    58
    @Override
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    59
    public Executable getExecutable() {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    60
        return executable;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    61
    }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    62
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    63
    @Override
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    64
    public Callable<Integer> getCallable() {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    65
        return callable;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    66
    }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    67
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    68
    @Override
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    69
    public boolean isOsr() {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    70
        return isOsr;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    71
    }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    72
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    73
    private static class Helper {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    74
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    75
        private static final Callable<Integer> CONSTRUCTOR_CALLABLE
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    76
                = new Callable<Integer>() {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    77
            @Override
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    78
            public Integer call() throws Exception {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    79
                return new Helper(1337).hashCode();
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    80
            }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    81
        };
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    82
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    83
        private static final Callable<Integer> METHOD_CALLABLE
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    84
                = new Callable<Integer>() {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    85
            private final Helper helper = new Helper();
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    86
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    87
            @Override
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    88
            public Integer call() throws Exception {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    89
                return helper.method();
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    90
            }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    91
        };
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    92
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    93
        private static final Callable<Integer> STATIC_CALLABLE
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    94
                = new Callable<Integer>() {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    95
            @Override
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    96
            public Integer call() throws Exception {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    97
                return staticMethod();
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    98
            }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
    99
        };
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   100
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   101
        private static final Callable<Integer> OSR_CONSTRUCTOR_CALLABLE
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   102
                = new Callable<Integer>() {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   103
            @Override
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   104
            public Integer call() throws Exception {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   105
                return new Helper(null, CompilerWhiteBoxTest.BACKEDGE_THRESHOLD).hashCode();
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   106
            }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   107
        };
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   108
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   109
        private static final Callable<Integer> OSR_METHOD_CALLABLE
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   110
                = new Callable<Integer>() {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   111
            private final Helper helper = new Helper();
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   112
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   113
            @Override
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   114
            public Integer call() throws Exception {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   115
                return helper.osrMethod(CompilerWhiteBoxTest.BACKEDGE_THRESHOLD);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   116
            }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   117
        };
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   118
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   119
        private static final Callable<Integer> OSR_STATIC_CALLABLE
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   120
                = new Callable<Integer>() {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   121
            @Override
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   122
            public Integer call() throws Exception {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   123
                return osrStaticMethod(CompilerWhiteBoxTest.BACKEDGE_THRESHOLD);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   124
            }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   125
        };
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   126
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   127
        private static final Constructor CONSTRUCTOR;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   128
        private static final Constructor OSR_CONSTRUCTOR;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   129
        private static final Method METHOD;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   130
        private static final Method STATIC;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   131
        private static final Method OSR_METHOD;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   132
        private static final Method OSR_STATIC;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   133
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   134
        static {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   135
            try {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   136
                CONSTRUCTOR = Helper.class.getDeclaredConstructor(int.class);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   137
            } catch (NoSuchMethodException | SecurityException e) {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   138
                throw new RuntimeException(
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   139
                        "exception on getting method Helper.<init>(int)", e);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   140
            }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   141
            try {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   142
                OSR_CONSTRUCTOR = Helper.class.getDeclaredConstructor(
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   143
                        Object.class, long.class);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   144
            } catch (NoSuchMethodException | SecurityException e) {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   145
                throw new RuntimeException(
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   146
                        "exception on getting method Helper.<init>(Object, long)", e);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   147
            }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   148
            METHOD = getMethod("method");
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   149
            STATIC = getMethod("staticMethod");
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   150
            OSR_METHOD = getMethod("osrMethod", long.class);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   151
            OSR_STATIC = getMethod("osrStaticMethod", long.class);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   152
        }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   153
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   154
        private static Method getMethod(String name, Class<?>... parameterTypes) {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   155
            try {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   156
                return Helper.class.getDeclaredMethod(name, parameterTypes);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   157
            } catch (NoSuchMethodException | SecurityException e) {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   158
                throw new RuntimeException(
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   159
                        "exception on getting method Helper." + name, e);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   160
            }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   161
        }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   162
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   163
        private static int staticMethod() {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   164
            return 1138;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   165
        }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   166
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   167
        private int method() {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   168
            return 42;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   169
        }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   170
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   171
        /**
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   172
         * Deoptimizes all non-osr versions of the given executable after
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   173
         * compilation finished.
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   174
         *
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   175
         * @param e Executable
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   176
         * @throws Exception
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   177
         */
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   178
        private static void waitAndDeoptimize(Executable e) {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   179
            CompilerWhiteBoxTest.waitBackgroundCompilation(e);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   180
            if (WhiteBox.getWhiteBox().isMethodQueuedForCompilation(e)) {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   181
                throw new RuntimeException(e + " must not be in queue");
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   182
            }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   183
            // Deoptimize non-osr versions of executable
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   184
            WhiteBox.getWhiteBox().deoptimizeMethod(e, false);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   185
        }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   186
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   187
        /**
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   188
         * Executes the method multiple times to make sure we have
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   189
         * enough profiling information before triggering an OSR
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   190
         * compilation. Otherwise the C2 compiler may add uncommon traps.
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   191
         *
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   192
         * @param m Method to be executed
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   193
         * @return Number of times the method was executed
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   194
         * @throws Exception
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   195
         */
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   196
        private static int warmup(Method m) throws Exception {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   197
            waitAndDeoptimize(m);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   198
            Helper helper = new Helper();
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   199
            int result = 0;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   200
            for (long i = 0; i < CompilerWhiteBoxTest.THRESHOLD; ++i) {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   201
                result += (int)m.invoke(helper, 1);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   202
            }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   203
            // Wait to make sure OSR compilation is not blocked by
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   204
            // non-OSR compilation in the compile queue
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   205
            CompilerWhiteBoxTest.waitBackgroundCompilation(m);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   206
            return result;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   207
        }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   208
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   209
        /**
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   210
         * Executes the constructor multiple times to make sure we
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   211
         * have enough profiling information before triggering an OSR
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   212
         * compilation. Otherwise the C2 compiler may add uncommon traps.
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   213
         *
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   214
         * @param c Constructor to be executed
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   215
         * @return Number of times the constructor was executed
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   216
         * @throws Exception
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   217
         */
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   218
        private static int warmup(Constructor c) throws Exception {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   219
            waitAndDeoptimize(c);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   220
            int result = 0;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   221
            for (long i = 0; i < CompilerWhiteBoxTest.THRESHOLD; ++i) {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   222
                result += c.newInstance(null, 1).hashCode();
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   223
            }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   224
            // Wait to make sure OSR compilation is not blocked by
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   225
            // non-OSR compilation in the compile queue
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   226
            CompilerWhiteBoxTest.waitBackgroundCompilation(c);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   227
            return result;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   228
        }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   229
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   230
        private static int osrStaticMethod(long limit) throws Exception {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   231
            int result = 0;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   232
            if (limit != 1) {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   233
                result = warmup(OSR_STATIC);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   234
            }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   235
            // Trigger osr compilation
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   236
            for (long i = 0; i < limit; ++i) {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   237
                result += staticMethod();
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   238
            }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   239
            return result;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   240
        }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   241
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   242
        private int osrMethod(long limit) throws Exception {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   243
            int result = 0;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   244
            if (limit != 1) {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   245
                result = warmup(OSR_METHOD);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   246
            }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   247
            // Trigger osr compilation
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   248
            for (long i = 0; i < limit; ++i) {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   249
                result += method();
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   250
            }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   251
            return result;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   252
        }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   253
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   254
        private final int x;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   255
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   256
        // for method and OSR method test case
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   257
        public Helper() {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   258
            x = 0;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   259
        }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   260
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   261
        // for OSR constructor test case
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   262
        private Helper(Object o, long limit) throws Exception {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   263
            int result = 0;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   264
            if (limit != 1) {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   265
                result = warmup(OSR_CONSTRUCTOR);
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   266
            }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   267
            // Trigger osr compilation
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   268
            for (long i = 0; i < limit; ++i) {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   269
                result += method();
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   270
            }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   271
            x = result;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   272
        }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   273
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   274
        // for constructor test case
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   275
        private Helper(int x) {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   276
            this.x = x;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   277
        }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   278
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   279
        @Override
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   280
        public int hashCode() {
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   281
            return x;
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   282
        }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   283
    }
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents:
diff changeset
   284
}