コード例 #1
0
  private void verifyRTMRetryCount(int retryCount) throws Throwable {
    CompilableTest busyLock = new BusyLock();
    long expectedAborts = retryCount + 1L;

    OutputAnalyzer outputAnalyzer =
        RTMTestBase.executeRTMTest(
            busyLock,
            "-XX:-UseRTMXendForLockBusy",
            "-XX:RTMTotalCountIncrRate=1",
            CommandLineOptionTest.prepareNumericFlag("RTMRetryCount", retryCount),
            "-XX:RTMTotalCountIncrRate=1",
            "-XX:+PrintPreciseRTMLockingStatistics",
            BusyLock.class.getName(),
            Boolean.toString(TestRTMRetryCount.INFLATE_MONITOR),
            Integer.toString(TestRTMRetryCount.LOCKING_TIME));

    outputAnalyzer.shouldHaveExitValue(0);

    List<RTMLockingStatistics> statistics =
        RTMLockingStatistics.fromString(
            busyLock.getMethodWithLockName(), outputAnalyzer.getStdout());

    Asserts.assertEQ(
        statistics.size(),
        1,
        "VM output should contain "
            + "exactly one rtm locking statistics entry for method "
            + busyLock.getMethodWithLockName());

    Asserts.assertEQ(
        statistics.get(0).getTotalAborts(),
        expectedAborts,
        String.format("It is expected to get %d aborts", expectedAborts));
  }
コード例 #2
0
  private static void runSanityTest(Executable aMethod, Integer expectedTableLength) {
    HotSpotResolvedJavaMethod method = CTVMUtilities.getResolvedMethod(aMethod);
    int tableLength = CompilerToVMHelper.getExceptionTableLength(method);
    Asserts.assertEQ(
        tableLength, expectedTableLength, aMethod + " incorrect exception table length.");

    long tableStart = CompilerToVMHelper.getExceptionTableStart(method);
    if (tableLength > 0) {
      Asserts.assertNE(tableStart, 0L, aMethod + " exception table starts " + "at 0.");
    }
  }
コード例 #3
0
 private void test() {
   System.out.println(getName());
   Asserts.assertFalse(WB.isMethodCompiled(METHOD), getName() + " : method unexpectedly compiled");
   /* need to call testFrame at least once to be able to compile it, so
   calling with materialize=false, because testFrame is not compiled */
   testFrame("someString", /* materialize= */ false);
   WB.enqueueMethodForCompilation(METHOD, 4);
   Asserts.assertTrue(WB.isMethodCompiled(METHOD), getName() + "Method unexpectedly not compiled");
   // calling with materialize=true to materialize compiled testFrame
   testFrame("someString", /* materialize= */ true);
 }
コード例 #4
0
 private void testFrame(String str, boolean materialize) {
   Helper helper = new Helper(str);
   check(materialize);
   Asserts.assertTrue(
       (helper.string != null) && (this != null) && (helper != null),
       getName() + " : some locals are null");
 }
コード例 #5
0
  private void checkSanity(CompileCodeTestCase testCase) {
    System.out.println(testCase);
    // to have a clean state
    testCase.deoptimize();
    Pair<Object, ? extends Throwable> reflectionResult;
    Object[] args = Utils.getNullValues(testCase.executable.getParameterTypes());
    reflectionResult = testCase.invoke(args);
    NMethod nMethod = testCase.compile();
    if (nMethod == null) {
      throw new Error(testCase + " : nmethod is null");
    }
    InstalledCode installedCode = testCase.toInstalledCode();
    Object result = null;
    Throwable expectedException = reflectionResult.second;
    boolean gotException = true;
    try {
      args = addReceiver(testCase, args);
      result = CompilerToVMHelper.executeInstalledCode(args, installedCode);
      if (testCase.executable instanceof Constructor) {
        // <init> doesn't have return value, it changes receiver
        result = args[0];
      }
      gotException = false;
    } catch (InvalidInstalledCodeException e) {
      throw new AssertionError(testCase + " : unexpected InvalidInstalledCodeException", e);
    } catch (Throwable t) {
      if (expectedException == null) {
        throw new AssertionError(testCase + " : got unexpected execption : " + t.getMessage(), t);
      }

      if (expectedException.getClass() != t.getClass()) {
        System.err.println("exception from CompilerToVM:");
        t.printStackTrace();
        System.err.println("exception from reflection:");
        expectedException.printStackTrace();
        throw new AssertionError(
            String.format(
                "%s : got unexpected different exceptions : %s != %s",
                testCase, expectedException.getClass(), t.getClass()));
      }
    }

    Asserts.assertEQ(reflectionResult.first, result, testCase + " : different return value");
    if (!gotException) {
      Asserts.assertNull(expectedException, testCase + " : expected exception hasn't been thrown");
    }
  }
コード例 #6
0
 private void check(boolean materialize) {
   // Materialize virtual objects on last invocation
   if (materialize) {
     HotSpotStackFrameReference hsFrame =
         CompilerToVMHelper.getNextStackFrame(
             /* topmost frame */ null,
             new ResolvedJavaMethod[] {RESOLVED_METHOD}, /* don't skip any */
             0);
     Asserts.assertNotNull(hsFrame, getName() + " : got null frame");
     Asserts.assertTrue(WB.isMethodCompiled(METHOD), getName() + "Test method should be compiled");
     Asserts.assertTrue(
         hsFrame.hasVirtualObjects(),
         getName() + ": has no virtual object before materialization");
     CompilerToVMHelper.materializeVirtualObjects(hsFrame, INVALIDATE);
     Asserts.assertFalse(
         hsFrame.hasVirtualObjects(), getName() + " : has virtual object after materialization");
     Asserts.assertEQ(
         WB.isMethodCompiled(METHOD), !INVALIDATE, getName() + " : unexpected compiled status");
   }
 }
コード例 #7
0
    private void selfTest() {
      boolean isHumongous = WHITE_BOX.getObjectSize(allocation) > HALF_G1_REGION_SIZE;
      boolean shouldBeHumongous = WHITE_BOX.g1IsHumongous(allocation);

      // Sanity check
      Asserts.assertEquals(
          isHumongous,
          shouldBeHumongous,
          String.format(
              "Test Bug: Object of size %d is expected to be %shumongous but it is not",
              WHITE_BOX.getObjectSize(allocation), (shouldBeHumongous ? "" : "non-")));
    }
コード例 #8
0
ファイル: TestObjectClone.java プロジェクト: gaoxiaojun/dync
  public static void main(String[] args) throws Exception {
    TestObjectClone[] params1 = {
      a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a,
      a, a, b, c, d
    };

    for (int i = 0; i < 15000; i++) {
      f(params1[i % params1.length]);
    }

    Asserts.assertTrue(f(a) != a);
    Asserts.assertTrue(f(b) == b);
    Asserts.assertTrue(f(c) == c);
    Asserts.assertTrue(f(d) == d);

    try {
      f(null);
      throw new AssertionError("");
    } catch (NullPointerException e) {
      /* expected */
    }

    System.out.println("TEST PASSED");
  }
コード例 #9
0
  private void check(CompileCodeTestCase testCase) {
    System.out.println(testCase);
    HotSpotResolvedJavaMethod javaMethod = CTVMUtilities.getResolvedMethod(testCase.executable);
    HotSpotCompilationRequest compRequest =
        new HotSpotCompilationRequest(javaMethod, testCase.bci, /* jvmciEnv = */ 0L);
    String name = testCase.executable.getName();
    CompilationResult compResult = new CompilationResult(name);
    // to pass sanity check of default -1
    compResult.setTotalFrameSize(0);
    InstalledCode installedCode =
        CACHE_PROVIDER.installCode(
            compRequest,
            compResult,
            new InstalledCode(name),
            /* speculationLog = */ null,
            /* isDefault = */ false);
    Asserts.assertTrue(
        installedCode.isValid(), testCase + " : code is invalid even before invalidation");

    NMethod beforeInvalidation = testCase.toNMethod();
    if (beforeInvalidation != null) {
      throw new Error("TESTBUG : " + testCase + " : nmethod isn't found");
    }
    // run twice to verify how it works if method is already invalidated
    for (int i = 0; i < 2; ++i) {
      CompilerToVMHelper.invalidateInstalledCode(installedCode);
      Asserts.assertFalse(
          installedCode.isValid(), testCase + " : code is valid after invalidation, i = " + i);
      NMethod afterInvalidation = testCase.toNMethod();
      if (afterInvalidation != null) {
        System.err.println("before: " + beforeInvalidation);
        System.err.println("after: " + afterInvalidation);
        throw new AssertionError(testCase + " : method hasn't been invalidated, i = " + i);
      }
    }
  }
コード例 #10
0
  private static ProcessBuilder prepareTestCase(int testCase) throws Exception {
    ProcessBuilder pb;

    Asserts.assertTrue(0 < testCase && testCase < 6, "testCase should be from 1 to 5");

    addVMParam("-showversion");
    addVMOptionsToCheck("MinHeapFreeRatio", "SurvivorRatio", "NewRatio");

    if (testCase < 5) {
      addVMParam("-XX:Flags=flags_file", "-XX:-PrintVMOptions");
      addProperty("shared.property", "command_line_before");
      addProperty("clb", "unique_command_line_before");
      addVMParam("-XX:MinHeapFreeRatio=7");
    }

    if (testCase < 4) {
      addVMOptionsFile(getAbsolutePathFromSource(VM_OPTION_FILE_1));
    }

    if (testCase < 3) {
      addVMParam("-XX:MinHeapFreeRatio=9", "-XX:-PrintVMOptions");
      addProperty("shared.property", "command_line_after");
      addProperty("cla", "unique_command_line_after");
    }

    /* Create ProcessBuilder after all setup is done to update environment variables */
    pb = createProcessBuilder();

    if (testCase < 2) {
      updateEnvironment(
          pb,
          JAVA_OPTIONS,
          "-Dshared.property=somevalue -Djo=unique_java_options "
              + "-XX:MinHeapFreeRatio=18 -Dshared.property=java_options -XX:MinHeapFreeRatio=11 -XX:+PrintVMOptions");
    }

    if (testCase < 6) {
      updateEnvironment(
          pb,
          JAVA_TOOL_OPTIONS,
          "-Dshared.property=qwerty -Djto=unique_java_tool_options "
              + "-XX:MinHeapFreeRatio=15 -Dshared.property=java_tool_options -XX:MinHeapFreeRatio=6 -XX:+PrintVMOptions");
    }

    return pb;
  }
コード例 #11
0
 private void runTest(TestCase tcase) {
   System.out.println(tcase);
   HotSpotResolvedObjectType resolvedIface =
       CompilerToVMHelper.lookupType(
           Utils.toJVMTypeSignature(tcase.anInterface), getClass(), /* resolve = */ true);
   HotSpotResolvedObjectType resolvedImplementer =
       CompilerToVMHelper.getImplementor(resolvedIface);
   HotSpotResolvedObjectType resolvedExpected = null;
   if (tcase.expectedImplementer != null) {
     resolvedExpected =
         CompilerToVMHelper.lookupType(
             Utils.toJVMTypeSignature(tcase.expectedImplementer),
             getClass(),
             /* resolve = */ true);
   }
   Asserts.assertEQ(
       resolvedImplementer,
       resolvedExpected,
       "Unexpected implementer for " + tcase.anInterface.getName());
 }
コード例 #12
0
  public static void main(String[] args) {

    if (args.length != 1) {
      throw new Error("Expected memory counter name wasn't provided as command line argument");
    }
    MemoryCounter memoryCounter = MemoryCounter.valueOf(args[0].toUpperCase());

    int byteArrayMemoryOverhead = Helpers.detectByteArrayAllocationOverhead();

    // Largest non-humongous byte[]
    int maxByteArrayNonHumongousSize = HALF_G1_REGION_SIZE - byteArrayMemoryOverhead;

    // Maximum byte[] that takes one region
    int maxByteArrayOneRegionSize = G1_REGION_SIZE - byteArrayMemoryOverhead;

    List<Integer> allocationSizes =
        Arrays.asList(
            (int) maxByteArrayNonHumongousSize + 1,
            (int) (0.8f * maxByteArrayOneRegionSize),
            (int) (maxByteArrayOneRegionSize),
            (int) (1.2f * maxByteArrayOneRegionSize),
            (int) (1.5f * maxByteArrayOneRegionSize),
            (int) (1.7f * maxByteArrayOneRegionSize),
            (int) (2.0f * maxByteArrayOneRegionSize),
            (int) (2.5f * maxByteArrayOneRegionSize));

    List<Allocation> allocations = new ArrayList<>();
    List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();

    long gcCountBefore =
        gcBeans.stream().mapToLong(GarbageCollectorMXBean::getCollectionCount).sum();

    System.out.println("Starting allocations - no GC should happen until we finish them");

    for (int allocationSize : allocationSizes) {

      long usedMemoryBefore = memoryCounter.getUsedMemory();
      long expectedAllocationSize =
          (long) Math.ceil((double) allocationSize / G1_REGION_SIZE) * G1_REGION_SIZE;
      allocations.add(new Allocation(allocationSize, expectedAllocationSize));
      long usedMemoryAfter = memoryCounter.getUsedMemory();

      System.out.format(
          "Expected allocation size: %d\nUsed memory before allocation: %d\n"
              + "Used memory after allocation: %d\n",
          expectedAllocationSize, usedMemoryBefore, usedMemoryAfter);

      long gcCountNow =
          gcBeans.stream().mapToLong(GarbageCollectorMXBean::getCollectionCount).sum();

      if (gcCountNow == gcCountBefore) {
        // We should allocate at least allocation.expectedSize
        Asserts.assertGreaterThanOrEqual(
            usedMemoryAfter - usedMemoryBefore,
            expectedAllocationSize,
            "Counter of type "
                + memoryCounter.getClass().getSimpleName()
                + " returned wrong allocation size");
      } else {
        System.out.println("GC happened during allocation so the check is skipped");
        gcCountBefore = gcCountNow;
      }
    }

    System.out.println("Finished allocations - no GC should have happened before this line");

    allocations
        .stream()
        .forEach(
            allocation -> {
              long usedMemoryBefore = memoryCounter.getUsedMemory();
              allocation.forgetAllocation();

              WHITE_BOX.fullGC();

              long usedMemoryAfter = memoryCounter.getUsedMemory();

              // We should free at least allocation.expectedSize * ALLOCATION_SIZE_TOLERANCE_FACTOR
              Asserts.assertGreaterThanOrEqual(
                  usedMemoryBefore - usedMemoryAfter,
                  (long) (allocation.expectedSize * ALLOCATION_SIZE_TOLERANCE_FACTOR),
                  "Counter of type "
                      + memoryCounter.getClass().getSimpleName()
                      + " returned wrong allocation size");
            });
  }