Exemplo n.º 1
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");
    }
  }