test/compiler/whitebox/CompilerWhiteBoxTest.java

Wed, 22 Jan 2014 12:37:28 -0800

author
katleman
date
Wed, 22 Jan 2014 12:37:28 -0800
changeset 6575
2bac854670c0
parent 5983
600c83f8e6a5
child 6211
d1760952ebdd
permissions
-rw-r--r--

Added tag jdk8u5-b05 for changeset b90de55aca30

iignatyev@4592 1 /*
iignatyev@4592 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
iignatyev@4592 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
iignatyev@4592 4 *
iignatyev@4592 5 * This code is free software; you can redistribute it and/or modify it
iignatyev@4592 6 * under the terms of the GNU General Public License version 2 only, as
iignatyev@4592 7 * published by the Free Software Foundation.
iignatyev@4592 8 *
iignatyev@4592 9 * This code is distributed in the hope that it will be useful, but WITHOUT
iignatyev@4592 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
iignatyev@4592 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
iignatyev@4592 12 * version 2 for more details (a copy is included in the LICENSE file that
iignatyev@4592 13 * accompanied this code).
iignatyev@4592 14 *
iignatyev@4592 15 * You should have received a copy of the GNU General Public License version
iignatyev@4592 16 * 2 along with this work; if not, write to the Free Software Foundation,
iignatyev@4592 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
iignatyev@4592 18 *
iignatyev@4592 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
iignatyev@4592 20 * or visit www.oracle.com if you need additional information or have any
iignatyev@4592 21 * questions.
iignatyev@4592 22 */
iignatyev@4592 23
iignatyev@4951 24 import com.sun.management.HotSpotDiagnosticMXBean;
iignatyev@4951 25 import com.sun.management.VMOption;
iignatyev@4592 26 import sun.hotspot.WhiteBox;
iignatyev@4592 27 import sun.management.ManagementFactoryHelper;
iignatyev@4592 28
iignatyev@4951 29 import java.lang.reflect.Constructor;
iignatyev@4951 30 import java.lang.reflect.Executable;
iignatyev@4592 31 import java.lang.reflect.Method;
iignatyev@4951 32 import java.util.Objects;
iignatyev@4951 33 import java.util.concurrent.Callable;
iignatyev@4592 34
iignatyev@4951 35 /**
iignatyev@4951 36 * Abstract class for WhiteBox testing of JIT.
iignatyev@4951 37 *
iignatyev@4592 38 * @author igor.ignatyev@oracle.com
iignatyev@4592 39 */
iignatyev@4592 40 public abstract class CompilerWhiteBoxTest {
iignatyev@4951 41 /** {@code CompLevel::CompLevel_none} -- Interpreter */
iignatyev@4951 42 protected static int COMP_LEVEL_NONE = 0;
iignatyev@4951 43 /** {@code CompLevel::CompLevel_any}, {@code CompLevel::CompLevel_all} */
iignatyev@4951 44 protected static int COMP_LEVEL_ANY = -1;
iignatyev@5032 45 /** {@code CompLevel::CompLevel_simple} -- C1 */
iignatyev@5032 46 protected static int COMP_LEVEL_SIMPLE = 1;
iignatyev@5541 47 /** {@code CompLevel::CompLevel_limited_profile} -- C1, invocation & backedge counters */
iignatyev@5541 48 protected static int COMP_LEVEL_LIMITED_PROFILE = 2;
iignatyev@5541 49 /** {@code CompLevel::CompLevel_full_profile} -- C1, invocation & backedge counters + mdo */
iignatyev@5541 50 protected static int COMP_LEVEL_FULL_PROFILE = 3;
iignatyev@5032 51 /** {@code CompLevel::CompLevel_full_optimization} -- C2 or Shark */
iignatyev@5032 52 protected static int COMP_LEVEL_FULL_OPTIMIZATION = 4;
iignatyev@5541 53 /** Maximal value for CompLeveL */
iignatyev@5541 54 protected static int COMP_LEVEL_MAX = COMP_LEVEL_FULL_OPTIMIZATION;
iignatyev@5032 55
iignatyev@4951 56 /** Instance of WhiteBox */
iignatyev@4592 57 protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
iignatyev@4951 58 /** Value of {@code -XX:CompileThreshold} */
iignatyev@4592 59 protected static final int COMPILE_THRESHOLD
iignatyev@4592 60 = Integer.parseInt(getVMOption("CompileThreshold", "10000"));
iignatyev@4951 61 /** Value of {@code -XX:BackgroundCompilation} */
iignatyev@4766 62 protected static final boolean BACKGROUND_COMPILATION
iignatyev@4766 63 = Boolean.valueOf(getVMOption("BackgroundCompilation", "true"));
iignatyev@4951 64 /** Value of {@code -XX:TieredCompilation} */
iignatyev@4908 65 protected static final boolean TIERED_COMPILATION
iignatyev@4908 66 = Boolean.valueOf(getVMOption("TieredCompilation", "false"));
iignatyev@4951 67 /** Value of {@code -XX:TieredStopAtLevel} */
iignatyev@4951 68 protected static final int TIERED_STOP_AT_LEVEL
iignatyev@4951 69 = Integer.parseInt(getVMOption("TieredStopAtLevel", "0"));
iignatyev@5512 70 /** Flag for verbose output, true if {@code -Dverbose} specified */
iignatyev@5512 71 protected static final boolean IS_VERBOSE
iignatyev@5512 72 = System.getProperty("verbose") != null;
iignatyev@5541 73 /** count of invocation to triger compilation */
iignatyev@5541 74 protected static final int THRESHOLD;
iignatyev@5541 75 /** count of invocation to triger OSR compilation */
iignatyev@5541 76 protected static final long BACKEDGE_THRESHOLD;
iignatyev@5796 77 /** Value of {@code java.vm.info} (interpreted|mixed|comp mode) */
iignatyev@5796 78 protected static final String MODE
iignatyev@5796 79 = System.getProperty("java.vm.info");
iignatyev@5541 80
iignatyev@5541 81 static {
iignatyev@5541 82 if (TIERED_COMPILATION) {
iignatyev@5983 83 BACKEDGE_THRESHOLD = THRESHOLD = 150000;
iignatyev@5541 84 } else {
iignatyev@5541 85 THRESHOLD = COMPILE_THRESHOLD;
iignatyev@5541 86 BACKEDGE_THRESHOLD = COMPILE_THRESHOLD * Long.parseLong(getVMOption(
iignatyev@5541 87 "OnStackReplacePercentage"));
iignatyev@5541 88 }
iignatyev@5541 89 }
iignatyev@4592 90
iignatyev@4951 91 /**
iignatyev@4951 92 * Returns value of VM option.
iignatyev@4951 93 *
iignatyev@4951 94 * @param name option's name
iignatyev@4951 95 * @return value of option or {@code null}, if option doesn't exist
iignatyev@4951 96 * @throws NullPointerException if name is null
iignatyev@4951 97 */
iignatyev@4951 98 protected static String getVMOption(String name) {
iignatyev@4951 99 Objects.requireNonNull(name);
iignatyev@4951 100 HotSpotDiagnosticMXBean diagnostic
iignatyev@4951 101 = ManagementFactoryHelper.getDiagnosticMXBean();
iignatyev@4951 102 VMOption tmp;
iignatyev@4592 103 try {
iignatyev@4951 104 tmp = diagnostic.getVMOption(name);
iignatyev@4951 105 } catch (IllegalArgumentException e) {
iignatyev@4951 106 tmp = null;
iignatyev@4592 107 }
iignatyev@4951 108 return (tmp == null ? null : tmp.getValue());
iignatyev@4592 109 }
iignatyev@4592 110
iignatyev@4951 111 /**
iignatyev@4951 112 * Returns value of VM option or default value.
iignatyev@4951 113 *
iignatyev@4951 114 * @param name option's name
iignatyev@4951 115 * @param defaultValue default value
iignatyev@4951 116 * @return value of option or {@code defaultValue}, if option doesn't exist
iignatyev@4951 117 * @throws NullPointerException if name is null
iignatyev@4951 118 * @see #getVMOption(String)
iignatyev@4951 119 */
iignatyev@4766 120 protected static String getVMOption(String name, String defaultValue) {
iignatyev@4766 121 String result = getVMOption(name);
iignatyev@4592 122 return result == null ? defaultValue : result;
iignatyev@4592 123 }
iignatyev@4592 124
iignatyev@5032 125 /** copy of is_c1_compile(int) from utilities/globalDefinitions.hpp */
iignatyev@5032 126 protected static boolean isC1Compile(int compLevel) {
iignatyev@5032 127 return (compLevel > COMP_LEVEL_NONE)
iignatyev@5032 128 && (compLevel < COMP_LEVEL_FULL_OPTIMIZATION);
iignatyev@5032 129 }
iignatyev@5032 130
iignatyev@5032 131 /** copy of is_c2_compile(int) from utilities/globalDefinitions.hpp */
iignatyev@5032 132 protected static boolean isC2Compile(int compLevel) {
iignatyev@5032 133 return compLevel == COMP_LEVEL_FULL_OPTIMIZATION;
iignatyev@5032 134 }
iignatyev@5032 135
iignatyev@4951 136 /** tested method */
iignatyev@4951 137 protected final Executable method;
iignatyev@5541 138 protected final TestCase testCase;
iignatyev@4951 139
iignatyev@4951 140 /**
iignatyev@4951 141 * Constructor.
iignatyev@4951 142 *
iignatyev@4951 143 * @param testCase object, that contains tested method and way to invoke it.
iignatyev@4951 144 */
iignatyev@4951 145 protected CompilerWhiteBoxTest(TestCase testCase) {
iignatyev@4951 146 Objects.requireNonNull(testCase);
iignatyev@4951 147 System.out.println("TEST CASE:" + testCase.name());
iignatyev@4951 148 method = testCase.executable;
iignatyev@5541 149 this.testCase = testCase;
iignatyev@4951 150 }
iignatyev@4951 151
iignatyev@4951 152 /**
iignatyev@4951 153 * Template method for testing. Prints tested method's info before
iignatyev@4951 154 * {@linkplain #test()} and after {@linkplain #test()} or on thrown
iignatyev@4951 155 * exception.
iignatyev@4951 156 *
iignatyev@4951 157 * @throws RuntimeException if method {@linkplain #test()} throws any
iignatyev@4951 158 * exception
iignatyev@4951 159 * @see #test()
iignatyev@4951 160 */
iignatyev@4951 161 protected final void runTest() {
iignatyev@4592 162 if (ManagementFactoryHelper.getCompilationMXBean() == null) {
iignatyev@4592 163 System.err.println(
iignatyev@4592 164 "Warning: test is not applicable in interpreted mode");
iignatyev@4592 165 return;
iignatyev@4592 166 }
iignatyev@4592 167 System.out.println("at test's start:");
iignatyev@4951 168 printInfo();
iignatyev@4592 169 try {
iignatyev@4592 170 test();
iignatyev@4592 171 } catch (Exception e) {
iignatyev@4592 172 System.out.printf("on exception '%s':", e.getMessage());
iignatyev@4951 173 printInfo();
iignatyev@4766 174 e.printStackTrace();
iignatyev@4951 175 if (e instanceof RuntimeException) {
iignatyev@4951 176 throw (RuntimeException) e;
iignatyev@4951 177 }
iignatyev@4592 178 throw new RuntimeException(e);
iignatyev@4592 179 }
iignatyev@4592 180 System.out.println("at test's end:");
iignatyev@4951 181 printInfo();
iignatyev@4592 182 }
iignatyev@4592 183
iignatyev@4951 184 /**
iignatyev@4951 185 * Checks, that {@linkplain #method} is not compiled.
iignatyev@4951 186 *
iignatyev@4951 187 * @throws RuntimeException if {@linkplain #method} is in compiler queue or
iignatyev@4951 188 * is compiled, or if {@linkplain #method} has zero
iignatyev@4951 189 * compilation level.
iignatyev@4951 190 */
iignatyev@4951 191 protected final void checkNotCompiled() {
iignatyev@4908 192 if (WHITE_BOX.isMethodQueuedForCompilation(method)) {
iignatyev@4908 193 throw new RuntimeException(method + " must not be in queue");
iignatyev@4908 194 }
iignatyev@5541 195 if (WHITE_BOX.isMethodCompiled(method, false)) {
iignatyev@4592 196 throw new RuntimeException(method + " must be not compiled");
iignatyev@4592 197 }
iignatyev@5541 198 if (WHITE_BOX.getMethodCompilationLevel(method, false) != 0) {
iignatyev@4592 199 throw new RuntimeException(method + " comp_level must be == 0");
iignatyev@4592 200 }
iignatyev@5541 201 if (WHITE_BOX.isMethodCompiled(method, true)) {
iignatyev@5541 202 throw new RuntimeException(method + " must be not osr_compiled");
iignatyev@5541 203 }
iignatyev@5541 204 if (WHITE_BOX.getMethodCompilationLevel(method, true) != 0) {
iignatyev@5541 205 throw new RuntimeException(method + " osr_comp_level must be == 0");
iignatyev@5541 206 }
iignatyev@5796 207 }
iignatyev@4592 208
iignatyev@4951 209 /**
iignatyev@4951 210 * Checks, that {@linkplain #method} is compiled.
iignatyev@4951 211 *
iignatyev@4951 212 * @throws RuntimeException if {@linkplain #method} isn't in compiler queue
iignatyev@4951 213 * and isn't compiled, or if {@linkplain #method}
iignatyev@4951 214 * has nonzero compilation level
iignatyev@4951 215 */
iignatyev@4951 216 protected final void checkCompiled() {
iignatyev@4592 217 final long start = System.currentTimeMillis();
iignatyev@4951 218 waitBackgroundCompilation();
iignatyev@4592 219 if (WHITE_BOX.isMethodQueuedForCompilation(method)) {
iignatyev@4592 220 System.err.printf("Warning: %s is still in queue after %dms%n",
iignatyev@4592 221 method, System.currentTimeMillis() - start);
iignatyev@4592 222 return;
iignatyev@4592 223 }
iignatyev@5541 224 if (!WHITE_BOX.isMethodCompiled(method, testCase.isOsr)) {
iignatyev@5541 225 throw new RuntimeException(method + " must be "
iignatyev@5541 226 + (testCase.isOsr ? "osr_" : "") + "compiled");
iignatyev@4592 227 }
iignatyev@5541 228 if (WHITE_BOX.getMethodCompilationLevel(method, testCase.isOsr) == 0) {
iignatyev@5541 229 throw new RuntimeException(method
iignatyev@5541 230 + (testCase.isOsr ? " osr_" : " ")
iignatyev@5541 231 + "comp_level must be != 0");
iignatyev@4592 232 }
iignatyev@4592 233 }
iignatyev@4592 234
iignatyev@5541 235 protected final void deoptimize() {
iignatyev@5541 236 WHITE_BOX.deoptimizeMethod(method, testCase.isOsr);
iignatyev@5541 237 if (testCase.isOsr) {
iignatyev@5541 238 WHITE_BOX.deoptimizeMethod(method, false);
iignatyev@5541 239 }
iignatyev@5541 240 }
iignatyev@5541 241
iignatyev@5541 242 protected final int getCompLevel() {
iignatyev@5541 243 return WHITE_BOX.getMethodCompilationLevel(method, testCase.isOsr);
iignatyev@5541 244 }
iignatyev@5541 245
iignatyev@5541 246 protected final boolean isCompilable() {
iignatyev@5541 247 return WHITE_BOX.isMethodCompilable(method, COMP_LEVEL_ANY,
iignatyev@5541 248 testCase.isOsr);
iignatyev@5541 249 }
iignatyev@5541 250
iignatyev@5541 251 protected final boolean isCompilable(int compLevel) {
iignatyev@5541 252 return WHITE_BOX.isMethodCompilable(method, compLevel, testCase.isOsr);
iignatyev@5541 253 }
iignatyev@5541 254
iignatyev@5541 255 protected final void makeNotCompilable() {
iignatyev@5541 256 WHITE_BOX.makeMethodNotCompilable(method, COMP_LEVEL_ANY,
iignatyev@5541 257 testCase.isOsr);
iignatyev@5541 258 }
iignatyev@5541 259
iignatyev@5541 260 protected final void makeNotCompilable(int compLevel) {
iignatyev@5541 261 WHITE_BOX.makeMethodNotCompilable(method, compLevel, testCase.isOsr);
iignatyev@5541 262 }
iignatyev@5541 263
iignatyev@4951 264 /**
iignatyev@4951 265 * Waits for completion of background compilation of {@linkplain #method}.
iignatyev@4951 266 */
iignatyev@4951 267 protected final void waitBackgroundCompilation() {
iignatyev@4766 268 if (!BACKGROUND_COMPILATION) {
iignatyev@4766 269 return;
iignatyev@4766 270 }
iignatyev@4592 271 final Object obj = new Object();
iignatyev@4951 272 for (int i = 0; i < 10
iignatyev@4951 273 && WHITE_BOX.isMethodQueuedForCompilation(method); ++i) {
iignatyev@4951 274 synchronized (obj) {
iignatyev@4951 275 try {
iignatyev@4951 276 obj.wait(1000);
iignatyev@4951 277 } catch (InterruptedException e) {
iignatyev@4951 278 Thread.currentThread().interrupt();
iignatyev@4592 279 }
iignatyev@4592 280 }
iignatyev@4592 281 }
iignatyev@4592 282 }
iignatyev@4592 283
iignatyev@4951 284 /**
iignatyev@4951 285 * Prints information about {@linkplain #method}.
iignatyev@4951 286 */
iignatyev@4951 287 protected final void printInfo() {
iignatyev@4592 288 System.out.printf("%n%s:%n", method);
iignatyev@4592 289 System.out.printf("\tcompilable:\t%b%n",
iignatyev@5541 290 WHITE_BOX.isMethodCompilable(method, COMP_LEVEL_ANY, false));
iignatyev@4592 291 System.out.printf("\tcompiled:\t%b%n",
iignatyev@5541 292 WHITE_BOX.isMethodCompiled(method, false));
iignatyev@4592 293 System.out.printf("\tcomp_level:\t%d%n",
iignatyev@5541 294 WHITE_BOX.getMethodCompilationLevel(method, false));
iignatyev@5541 295 System.out.printf("\tosr_compilable:\t%b%n",
iignatyev@5541 296 WHITE_BOX.isMethodCompilable(method, COMP_LEVEL_ANY, true));
iignatyev@5541 297 System.out.printf("\tosr_compiled:\t%b%n",
iignatyev@5541 298 WHITE_BOX.isMethodCompiled(method, true));
iignatyev@5541 299 System.out.printf("\tosr_comp_level:\t%d%n",
iignatyev@5541 300 WHITE_BOX.getMethodCompilationLevel(method, true));
iignatyev@5541 301 System.out.printf("\tin_queue:\t%b%n",
iignatyev@4592 302 WHITE_BOX.isMethodQueuedForCompilation(method));
iignatyev@4592 303 System.out.printf("compile_queues_size:\t%d%n%n",
iignatyev@4592 304 WHITE_BOX.getCompileQueuesSize());
iignatyev@4592 305 }
iignatyev@4592 306
iignatyev@4951 307 /**
iignatyev@4951 308 * Executes testing.
iignatyev@4951 309 */
iignatyev@4592 310 protected abstract void test() throws Exception;
iignatyev@4592 311
iignatyev@4951 312 /**
iignatyev@4951 313 * Tries to trigger compilation of {@linkplain #method} by call
iignatyev@5541 314 * {@linkplain #testCase.callable} enough times.
iignatyev@4951 315 *
iignatyev@4951 316 * @return accumulated result
iignatyev@4951 317 * @see #compile(int)
iignatyev@4951 318 */
iignatyev@4592 319 protected final int compile() {
iignatyev@5541 320 if (testCase.isOsr) {
iignatyev@5541 321 return compile(1);
iignatyev@5541 322 } else {
iignatyev@5541 323 return compile(THRESHOLD);
iignatyev@5541 324 }
iignatyev@4908 325 }
iignatyev@4908 326
iignatyev@4951 327 /**
iignatyev@4951 328 * Tries to trigger compilation of {@linkplain #method} by call
iignatyev@5541 329 * {@linkplain #testCase.callable} specified times.
iignatyev@4951 330 *
iignatyev@4951 331 * @param count invocation count
iignatyev@4951 332 * @return accumulated result
iignatyev@4951 333 */
iignatyev@4908 334 protected final int compile(int count) {
iignatyev@4592 335 int result = 0;
iignatyev@4951 336 Integer tmp;
iignatyev@4766 337 for (int i = 0; i < count; ++i) {
iignatyev@4951 338 try {
iignatyev@5541 339 tmp = testCase.callable.call();
iignatyev@4951 340 } catch (Exception e) {
iignatyev@4951 341 tmp = null;
iignatyev@4951 342 }
iignatyev@4951 343 result += tmp == null ? 0 : tmp;
iignatyev@4592 344 }
iignatyev@5512 345 if (IS_VERBOSE) {
iignatyev@5512 346 System.out.println("method was invoked " + count + " times");
iignatyev@5512 347 }
iignatyev@4592 348 return result;
iignatyev@4592 349 }
iignatyev@4951 350 }
iignatyev@4592 351
iignatyev@4951 352 /**
iignatyev@4951 353 * Utility structure containing tested method and object to invoke it.
iignatyev@4951 354 */
iignatyev@4951 355 enum TestCase {
iignatyev@4951 356 /** constructor test case */
iignatyev@5541 357 CONSTRUCTOR_TEST(Helper.CONSTRUCTOR, Helper.CONSTRUCTOR_CALLABLE, false),
iignatyev@4951 358 /** method test case */
iignatyev@5541 359 METOD_TEST(Helper.METHOD, Helper.METHOD_CALLABLE, false),
iignatyev@4951 360 /** static method test case */
iignatyev@5541 361 STATIC_TEST(Helper.STATIC, Helper.STATIC_CALLABLE, false),
iignatyev@5541 362
iignatyev@5541 363 /** OSR constructor test case */
iignatyev@5541 364 OSR_CONSTRUCTOR_TEST(Helper.OSR_CONSTRUCTOR,
iignatyev@5541 365 Helper.OSR_CONSTRUCTOR_CALLABLE, true),
iignatyev@5983 366 /** OSR method test case */
iignatyev@5541 367 OSR_METOD_TEST(Helper.OSR_METHOD, Helper.OSR_METHOD_CALLABLE, true),
iignatyev@5541 368 /** OSR static method test case */
iignatyev@5541 369 OSR_STATIC_TEST(Helper.OSR_STATIC, Helper.OSR_STATIC_CALLABLE, true);
iignatyev@4951 370
iignatyev@4951 371 /** tested method */
iignatyev@4951 372 final Executable executable;
iignatyev@4951 373 /** object to invoke {@linkplain #executable} */
iignatyev@4951 374 final Callable<Integer> callable;
iignatyev@5983 375 /** flag for OSR test case */
iignatyev@5541 376 final boolean isOsr;
iignatyev@4951 377
iignatyev@5541 378 private TestCase(Executable executable, Callable<Integer> callable,
iignatyev@5541 379 boolean isOsr) {
iignatyev@4951 380 this.executable = executable;
iignatyev@4951 381 this.callable = callable;
iignatyev@5541 382 this.isOsr = isOsr;
iignatyev@4951 383 }
iignatyev@4951 384
iignatyev@4951 385 private static class Helper {
iignatyev@5541 386
iignatyev@4951 387 private static final Callable<Integer> CONSTRUCTOR_CALLABLE
iignatyev@4951 388 = new Callable<Integer>() {
iignatyev@4951 389 @Override
iignatyev@4951 390 public Integer call() throws Exception {
iignatyev@4951 391 return new Helper(1337).hashCode();
iignatyev@4951 392 }
iignatyev@4951 393 };
iignatyev@4951 394
iignatyev@4951 395 private static final Callable<Integer> METHOD_CALLABLE
iignatyev@4951 396 = new Callable<Integer>() {
iignatyev@4951 397 private final Helper helper = new Helper();
iignatyev@4951 398
iignatyev@4951 399 @Override
iignatyev@4951 400 public Integer call() throws Exception {
iignatyev@4951 401 return helper.method();
iignatyev@4951 402 }
iignatyev@4951 403 };
iignatyev@4951 404
iignatyev@4951 405 private static final Callable<Integer> STATIC_CALLABLE
iignatyev@4951 406 = new Callable<Integer>() {
iignatyev@4951 407 @Override
iignatyev@4951 408 public Integer call() throws Exception {
iignatyev@4951 409 return staticMethod();
iignatyev@4951 410 }
iignatyev@4951 411 };
iignatyev@4951 412
iignatyev@5541 413 private static final Callable<Integer> OSR_CONSTRUCTOR_CALLABLE
iignatyev@5541 414 = new Callable<Integer>() {
iignatyev@5541 415 @Override
iignatyev@5541 416 public Integer call() throws Exception {
iignatyev@5541 417 return new Helper(null).hashCode();
iignatyev@5541 418 }
iignatyev@5541 419 };
iignatyev@5541 420
iignatyev@5541 421 private static final Callable<Integer> OSR_METHOD_CALLABLE
iignatyev@5541 422 = new Callable<Integer>() {
iignatyev@5541 423 private final Helper helper = new Helper();
iignatyev@5541 424
iignatyev@5541 425 @Override
iignatyev@5541 426 public Integer call() throws Exception {
iignatyev@5541 427 return helper.osrMethod();
iignatyev@5541 428 }
iignatyev@5541 429 };
iignatyev@5541 430
iignatyev@5541 431 private static final Callable<Integer> OSR_STATIC_CALLABLE
iignatyev@5541 432 = new Callable<Integer>() {
iignatyev@5541 433 @Override
iignatyev@5541 434 public Integer call() throws Exception {
iignatyev@5541 435 return osrStaticMethod();
iignatyev@5541 436 }
iignatyev@5541 437 };
iignatyev@5541 438
iignatyev@5541 439
iignatyev@4951 440 private static final Constructor CONSTRUCTOR;
iignatyev@5541 441 private static final Constructor OSR_CONSTRUCTOR;
iignatyev@4951 442 private static final Method METHOD;
iignatyev@4951 443 private static final Method STATIC;
iignatyev@5541 444 private static final Method OSR_METHOD;
iignatyev@5541 445 private static final Method OSR_STATIC;
iignatyev@4951 446
iignatyev@4951 447 static {
iignatyev@4951 448 try {
iignatyev@4951 449 CONSTRUCTOR = Helper.class.getDeclaredConstructor(int.class);
iignatyev@4951 450 } catch (NoSuchMethodException | SecurityException e) {
iignatyev@4951 451 throw new RuntimeException(
iignatyev@4951 452 "exception on getting method Helper.<init>(int)", e);
iignatyev@4951 453 }
iignatyev@4951 454 try {
iignatyev@5541 455 OSR_CONSTRUCTOR = Helper.class.getDeclaredConstructor(
iignatyev@5541 456 Object.class);
iignatyev@4951 457 } catch (NoSuchMethodException | SecurityException e) {
iignatyev@4951 458 throw new RuntimeException(
iignatyev@5541 459 "exception on getting method Helper.<init>(Object)", e);
iignatyev@4951 460 }
iignatyev@5541 461 METHOD = getMethod("method");
iignatyev@5541 462 STATIC = getMethod("staticMethod");
iignatyev@5541 463 OSR_METHOD = getMethod("osrMethod");
iignatyev@5541 464 OSR_STATIC = getMethod("osrStaticMethod");
iignatyev@5541 465 }
iignatyev@5541 466
iignatyev@5541 467 private static Method getMethod(String name) {
iignatyev@4951 468 try {
iignatyev@5541 469 return Helper.class.getDeclaredMethod(name);
iignatyev@4951 470 } catch (NoSuchMethodException | SecurityException e) {
iignatyev@4951 471 throw new RuntimeException(
iignatyev@5541 472 "exception on getting method Helper." + name, e);
iignatyev@4951 473 }
iignatyev@5541 474
iignatyev@4951 475 }
iignatyev@4951 476
iignatyev@4951 477 private static int staticMethod() {
iignatyev@4951 478 return 1138;
iignatyev@4951 479 }
iignatyev@4951 480
iignatyev@4951 481 private int method() {
iignatyev@4951 482 return 42;
iignatyev@4951 483 }
iignatyev@4951 484
iignatyev@5541 485 private static int osrStaticMethod() {
iignatyev@5541 486 int result = 0;
iignatyev@5541 487 for (long i = 0; i < CompilerWhiteBoxTest.BACKEDGE_THRESHOLD; ++i) {
iignatyev@5541 488 result += staticMethod();
iignatyev@5541 489 }
iignatyev@5541 490 return result;
iignatyev@5541 491 }
iignatyev@5541 492
iignatyev@5541 493 private int osrMethod() {
iignatyev@5541 494 int result = 0;
iignatyev@5541 495 for (long i = 0; i < CompilerWhiteBoxTest.BACKEDGE_THRESHOLD; ++i) {
iignatyev@5541 496 result += method();
iignatyev@5541 497 }
iignatyev@5541 498 return result;
iignatyev@5541 499 }
iignatyev@5541 500
iignatyev@4951 501 private final int x;
iignatyev@4951 502
iignatyev@5541 503 // for method and OSR method test case
iignatyev@4951 504 public Helper() {
iignatyev@4951 505 x = 0;
iignatyev@4951 506 }
iignatyev@4951 507
iignatyev@5541 508 // for OSR constructor test case
iignatyev@5541 509 private Helper(Object o) {
iignatyev@5541 510 int result = 0;
iignatyev@5541 511 for (long i = 0; i < CompilerWhiteBoxTest.BACKEDGE_THRESHOLD; ++i) {
iignatyev@5541 512 result += method();
iignatyev@5541 513 }
iignatyev@5541 514 x = result;
iignatyev@5541 515 }
iignatyev@5541 516
iignatyev@5541 517 // for constructor test case
iignatyev@4951 518 private Helper(int x) {
iignatyev@4951 519 this.x = x;
iignatyev@4951 520 }
iignatyev@4951 521
iignatyev@4951 522 @Override
iignatyev@4951 523 public int hashCode() {
iignatyev@4951 524 return x;
iignatyev@4951 525 }
iignatyev@4592 526 }
iignatyev@4592 527 }

mercurial