public static void main(String[] args) { InvalidateInstalledCodeTest test = new InvalidateInstalledCodeTest(); List<CompileCodeTestCase> testCases = CompileCodeTestCase.generate(/* bci = */ 0); testCases.addAll(CompileCodeTestCase.generate(/* bci = */ -1)); testCases.forEach(test::check); test.checkNull(); }
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"); } }
public static void main(String[] args) { ExecuteInstalledCodeTest test = new ExecuteInstalledCodeTest(); List<CompileCodeTestCase> testCases = new ArrayList<>(); testCases.addAll(CompileCodeTestCase.generate(/* bci = */ -1)); testCases .stream() // ignore <init> of abstract class -- 8138793 .filter( e -> !(e.executable instanceof Constructor && Modifier.isAbstract(e.executable.getDeclaringClass().getModifiers()))) .forEach(test::checkSanity); }
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); } } }