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