44 * -Djvmci.compiler=EmptyCompiler -Xbootclasspath/a:. -Xmixed 45 * -XX:+UseJVMCICompiler -XX:-BootstrapJVMCI 46 * -Dcompiler.jvmci.events.JvmciNotifyInstallEventTest.noevent=false 47 * compiler.jvmci.events.JvmciNotifyInstallEventTest 48 * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:-EnableJVMCI 49 * -Djvmci.compiler=EmptyCompiler -Xbootclasspath/a:. -Xmixed 50 * -Dcompiler.jvmci.events.JvmciNotifyInstallEventTest.noevent=true 51 * compiler.jvmci.events.JvmciNotifyInstallEventTest 52 */ 53 54 package compiler.jvmci.events; 55 56 import compiler.jvmci.common.CTVMUtilities; 57 import compiler.jvmci.common.testcases.SimpleClass; 58 import jdk.test.lib.Asserts; 59 import java.lang.reflect.Method; 60 import jdk.vm.ci.hotspot.HotSpotVMEventListener; 61 import jdk.vm.ci.code.CompilationResult; 62 import jdk.vm.ci.code.InstalledCode; 63 import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider; 64 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; 65 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl; 66 67 public class JvmciNotifyInstallEventTest implements HotSpotVMEventListener { 68 private static final String METHOD_NAME = "testMethod"; 69 private static final boolean IS_POSITIVE = !Boolean.getBoolean( 70 "compiler.jvmci.events.JvmciNotifyInstallEventTest.noevent"); 71 private static volatile int gotInstallNotification = 0; 72 73 public static void main(String args[]) { 74 new JvmciNotifyInstallEventTest().runTest(); 75 } 76 77 private void runTest() { 78 if (gotInstallNotification != 0) { 79 throw new Error("Got install notification before test actions"); 80 } 81 HotSpotCodeCacheProvider codeCache = null; 82 try { 83 codeCache = (HotSpotCodeCacheProvider) HotSpotJVMCIRuntime.runtime() 84 .getHostJVMCIBackend().getCodeCache(); 85 } catch (InternalError ie) { 86 if (IS_POSITIVE) { 87 throw new AssertionError( 88 "Got unexpected InternalError trying to get code cache", 89 ie); 90 } 91 // passed 92 return; 93 } 94 Asserts.assertTrue(IS_POSITIVE, 95 "Haven't caught InternalError in negative case"); 96 Method testMethod; 97 try { 98 testMethod = SimpleClass.class.getDeclaredMethod(METHOD_NAME); 99 } catch (NoSuchMethodException e) { 100 throw new Error("TEST BUG: Can't find " + METHOD_NAME, e); 101 } 102 HotSpotResolvedJavaMethodImpl method = CTVMUtilities 103 .getResolvedMethod(SimpleClass.class, testMethod); 104 CompilationResult compResult = new CompilationResult(METHOD_NAME); 105 // to pass sanity check of default -1 106 compResult.setTotalFrameSize(0); 107 codeCache.installMethod(method, compResult, /* jvmciEnv = */ 0L, 108 /* isDefault = */ false); 109 Asserts.assertEQ(gotInstallNotification, 1, 110 "Got unexpected event count after 1st install attempt"); 111 // since "empty" compilation result is ok, a second attempt should be ok 112 codeCache.installMethod(method, compResult, /* jvmciEnv = */ 0L, 113 /* isDefault = */ false); 114 Asserts.assertEQ(gotInstallNotification, 2, 115 "Got unexpected event count after 2nd install attempt"); 116 } 117 118 @Override 119 public void notifyInstall(HotSpotCodeCacheProvider hotSpotCodeCacheProvider, 120 InstalledCode installedCode, CompilationResult compResult) { 121 gotInstallNotification++; 122 } 123 } | 44 * -Djvmci.compiler=EmptyCompiler -Xbootclasspath/a:. -Xmixed 45 * -XX:+UseJVMCICompiler -XX:-BootstrapJVMCI 46 * -Dcompiler.jvmci.events.JvmciNotifyInstallEventTest.noevent=false 47 * compiler.jvmci.events.JvmciNotifyInstallEventTest 48 * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:-EnableJVMCI 49 * -Djvmci.compiler=EmptyCompiler -Xbootclasspath/a:. -Xmixed 50 * -Dcompiler.jvmci.events.JvmciNotifyInstallEventTest.noevent=true 51 * compiler.jvmci.events.JvmciNotifyInstallEventTest 52 */ 53 54 package compiler.jvmci.events; 55 56 import compiler.jvmci.common.CTVMUtilities; 57 import compiler.jvmci.common.testcases.SimpleClass; 58 import jdk.test.lib.Asserts; 59 import java.lang.reflect.Method; 60 import jdk.vm.ci.hotspot.HotSpotVMEventListener; 61 import jdk.vm.ci.code.CompilationResult; 62 import jdk.vm.ci.code.InstalledCode; 63 import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider; 64 import jdk.vm.ci.hotspot.HotSpotCompilationRequest; 65 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; 66 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; 67 68 public class JvmciNotifyInstallEventTest implements HotSpotVMEventListener { 69 private static final String METHOD_NAME = "testMethod"; 70 private static final boolean IS_POSITIVE = !Boolean.getBoolean( 71 "compiler.jvmci.events.JvmciNotifyInstallEventTest.noevent"); 72 private static volatile int gotInstallNotification = 0; 73 74 public static void main(String args[]) { 75 new JvmciNotifyInstallEventTest().runTest(); 76 } 77 78 private void runTest() { 79 if (gotInstallNotification != 0) { 80 throw new Error("Got install notification before test actions"); 81 } 82 HotSpotCodeCacheProvider codeCache = null; 83 try { 84 codeCache = (HotSpotCodeCacheProvider) HotSpotJVMCIRuntime.runtime() 85 .getHostJVMCIBackend().getCodeCache(); 86 } catch (InternalError ie) { 87 if (IS_POSITIVE) { 88 throw new AssertionError( 89 "Got unexpected InternalError trying to get code cache", 90 ie); 91 } 92 // passed 93 return; 94 } 95 Asserts.assertTrue(IS_POSITIVE, 96 "Haven't caught InternalError in negative case"); 97 Method testMethod; 98 try { 99 testMethod = SimpleClass.class.getDeclaredMethod(METHOD_NAME); 100 } catch (NoSuchMethodException e) { 101 throw new Error("TEST BUG: Can't find " + METHOD_NAME, e); 102 } 103 HotSpotResolvedJavaMethod method = CTVMUtilities 104 .getResolvedMethod(SimpleClass.class, testMethod); 105 CompilationResult compResult = new CompilationResult(METHOD_NAME); 106 HotSpotCompilationRequest compRequest = new HotSpotCompilationRequest(method, -1, 0L); 107 // to pass sanity check of default -1 108 compResult.setTotalFrameSize(0); 109 codeCache.installCode(compRequest, compResult, /* installedCode = */ null, /* speculationLog = */ null, 110 /* isDefault = */ false); 111 Asserts.assertEQ(gotInstallNotification, 1, 112 "Got unexpected event count after 1st install attempt"); 113 // since "empty" compilation result is ok, a second attempt should be ok 114 codeCache.installCode(compRequest, compResult, /* installedCode = */ null, /* speculationLog = */ null, 115 /* isDefault = */ false); 116 Asserts.assertEQ(gotInstallNotification, 2, 117 "Got unexpected event count after 2nd install attempt"); 118 } 119 120 @Override 121 public void notifyInstall(HotSpotCodeCacheProvider hotSpotCodeCacheProvider, 122 InstalledCode installedCode, CompilationResult compResult) { 123 gotInstallNotification++; 124 } 125 } |