< prev index next >

test/compiler/jvmci/events/JvmciNotifyInstallEventTest.java

Print this page

        

*** 38,64 **** * compiler.jvmci.events.JvmciNotifyInstallEventTest * compiler.jvmci.common.CTVMUtilities * compiler.jvmci.common.testcases.SimpleClass * jdk.vm.ci.hotspot.CompilerToVMHelper * jdk.test.lib.Asserts * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI * -Djvmci.compiler=EmptyCompiler -Xbootclasspath/a:. -Xmixed * -XX:+UseJVMCICompiler -XX:-BootstrapJVMCI ! * -Dcompiler.jvmci.events.JvmciNotifyInstallEventTest.noevent=false * compiler.jvmci.events.JvmciNotifyInstallEventTest * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:-EnableJVMCI * -Djvmci.compiler=EmptyCompiler -Xbootclasspath/a:. -Xmixed ! * -Dcompiler.jvmci.events.JvmciNotifyInstallEventTest.noevent=true * compiler.jvmci.events.JvmciNotifyInstallEventTest */ package compiler.jvmci.events; import compiler.jvmci.common.CTVMUtilities; import compiler.jvmci.common.testcases.SimpleClass; import jdk.test.lib.Asserts; import java.lang.reflect.Method; import jdk.vm.ci.hotspot.HotSpotVMEventListener; import jdk.vm.ci.code.CompiledCode; import jdk.vm.ci.code.InstalledCode; import jdk.vm.ci.code.site.DataPatch; import jdk.vm.ci.code.site.Site; --- 38,71 ---- * compiler.jvmci.events.JvmciNotifyInstallEventTest * compiler.jvmci.common.CTVMUtilities * compiler.jvmci.common.testcases.SimpleClass * jdk.vm.ci.hotspot.CompilerToVMHelper * jdk.test.lib.Asserts + * jdk.test.lib.Utils * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI * -Djvmci.compiler=EmptyCompiler -Xbootclasspath/a:. -Xmixed * -XX:+UseJVMCICompiler -XX:-BootstrapJVMCI ! * -Dcompiler.jvmci.events.JvmciNotifyInstallEventTest.failoninit=false ! * compiler.jvmci.events.JvmciNotifyInstallEventTest ! * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI ! * -Djvmci.compiler=EmptyCompiler -Xbootclasspath/a:. -Xmixed ! * -XX:+UseJVMCICompiler -XX:-BootstrapJVMCI -XX:JVMCINMethodSizeLimit=0 ! * -Dcompiler.jvmci.events.JvmciNotifyInstallEventTest.failoninit=false * compiler.jvmci.events.JvmciNotifyInstallEventTest * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:-EnableJVMCI * -Djvmci.compiler=EmptyCompiler -Xbootclasspath/a:. -Xmixed ! * -Dcompiler.jvmci.events.JvmciNotifyInstallEventTest.failoninit=true * compiler.jvmci.events.JvmciNotifyInstallEventTest */ package compiler.jvmci.events; import compiler.jvmci.common.CTVMUtilities; import compiler.jvmci.common.testcases.SimpleClass; import jdk.test.lib.Asserts; import java.lang.reflect.Method; + import jdk.test.lib.Utils; import jdk.vm.ci.hotspot.HotSpotVMEventListener; import jdk.vm.ci.code.CompiledCode; import jdk.vm.ci.code.InstalledCode; import jdk.vm.ci.code.site.DataPatch; import jdk.vm.ci.code.site.Site;
*** 70,126 **** import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; public class JvmciNotifyInstallEventTest implements HotSpotVMEventListener { private static final String METHOD_NAME = "testMethod"; ! private static final boolean IS_POSITIVE = !Boolean.getBoolean( ! "compiler.jvmci.events.JvmciNotifyInstallEventTest.noevent"); private static volatile int gotInstallNotification = 0; public static void main(String args[]) { new JvmciNotifyInstallEventTest().runTest(); } private void runTest() { if (gotInstallNotification != 0) { throw new Error("Got install notification before test actions"); } ! HotSpotCodeCacheProvider codeCache = null; try { codeCache = (HotSpotCodeCacheProvider) HotSpotJVMCIRuntime.runtime() .getHostJVMCIBackend().getCodeCache(); } catch (InternalError ie) { ! if (IS_POSITIVE) { throw new AssertionError( "Got unexpected InternalError trying to get code cache", ie); } // passed return; } ! Asserts.assertTrue(IS_POSITIVE, "Haven't caught InternalError in negative case"); Method testMethod; try { testMethod = SimpleClass.class.getDeclaredMethod(METHOD_NAME); } catch (NoSuchMethodException e) { throw new Error("TEST BUG: Can't find " + METHOD_NAME, e); } HotSpotResolvedJavaMethod method = CTVMUtilities .getResolvedMethod(SimpleClass.class, testMethod); ! HotSpotCompiledCode compiledCode = new HotSpotCompiledCode(METHOD_NAME, new byte[0], 0, new Site[0], ! new Assumption[0], new ResolvedJavaMethod[]{method}, new Comment[0], new byte[0], 16, ! new DataPatch[0], false, 0, null); ! codeCache.installCode(method, compiledCode, /* installedCode = */ null, /* speculationLog = */ null, ! /* isDefault = */ false); Asserts.assertEQ(gotInstallNotification, 1, "Got unexpected event count after 1st install attempt"); // since "empty" compilation result is ok, a second attempt should be ok ! codeCache.installCode(method, compiledCode, /* installedCode = */ null, /* speculationLog = */ null, ! /* isDefault = */ false); Asserts.assertEQ(gotInstallNotification, 2, "Got unexpected event count after 2nd install attempt"); } @Override public void notifyInstall(HotSpotCodeCacheProvider hotSpotCodeCacheProvider, InstalledCode installedCode, CompiledCode compiledCode) { --- 77,145 ---- import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; public class JvmciNotifyInstallEventTest implements HotSpotVMEventListener { private static final String METHOD_NAME = "testMethod"; ! private static final boolean FAIL_ON_INIT = !Boolean.getBoolean( ! "compiler.jvmci.events.JvmciNotifyInstallEventTest.failoninit"); private static volatile int gotInstallNotification = 0; public static void main(String args[]) { new JvmciNotifyInstallEventTest().runTest(); } private void runTest() { if (gotInstallNotification != 0) { throw new Error("Got install notification before test actions"); } ! HotSpotCodeCacheProvider codeCache; try { codeCache = (HotSpotCodeCacheProvider) HotSpotJVMCIRuntime.runtime() .getHostJVMCIBackend().getCodeCache(); } catch (InternalError ie) { ! if (FAIL_ON_INIT) { throw new AssertionError( "Got unexpected InternalError trying to get code cache", ie); } // passed return; } ! Asserts.assertTrue(FAIL_ON_INIT, "Haven't caught InternalError in negative case"); Method testMethod; try { testMethod = SimpleClass.class.getDeclaredMethod(METHOD_NAME); } catch (NoSuchMethodException e) { throw new Error("TEST BUG: Can't find " + METHOD_NAME, e); } HotSpotResolvedJavaMethod method = CTVMUtilities .getResolvedMethod(SimpleClass.class, testMethod); ! HotSpotCompiledCode compiledCode = new HotSpotCompiledCode(METHOD_NAME, ! new byte[0], 0, new Site[0], new Assumption[0], ! new ResolvedJavaMethod[]{method}, new Comment[0], new byte[0], ! 16, new DataPatch[0], false, 0, null); ! codeCache.installCode(method, compiledCode, /* installedCode = */ null, ! /* speculationLog = */ null, /* isDefault = */ false); Asserts.assertEQ(gotInstallNotification, 1, "Got unexpected event count after 1st install attempt"); // since "empty" compilation result is ok, a second attempt should be ok ! codeCache.installCode(method, compiledCode, /* installedCode = */ null, ! /* speculationLog = */ null, /* isDefault = */ false); Asserts.assertEQ(gotInstallNotification, 2, "Got unexpected event count after 2nd install attempt"); + // and an incorrect cases + Utils.runAndCheckException(() -> { + codeCache.installCode(method, null, null, null, true); + }, NullPointerException.class); + Asserts.assertEQ(gotInstallNotification, 2, + "Got unexpected event count after 3rd install attempt"); + Utils.runAndCheckException(() -> { + codeCache.installCode(null, null, null, null, true); + }, NullPointerException.class); + Asserts.assertEQ(gotInstallNotification, 2, + "Got unexpected event count after 4th install attempt"); } @Override public void notifyInstall(HotSpotCodeCacheProvider hotSpotCodeCacheProvider, InstalledCode installedCode, CompiledCode compiledCode) {
< prev index next >