< prev index next >

test/compiler/jvmci/events/JvmciNotifyInstallEventTest.java

Print this page




  23 
  24 /*
  25  * @test
  26  * @bug 8136421
  27  * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64")
  28  * @library / /testlibrary
  29  * @compile ../common/CompilerToVMHelper.java
  30  * @build compiler.jvmci.common.JVMCIHelpers
  31  *     compiler.jvmci.events.JvmciNotifyInstallEventTest
  32  * @run main jdk.test.lib.FileInstaller ../common/services/ ./META-INF/services/
  33  * @run main jdk.test.lib.FileInstaller ./JvmciNotifyInstallEventTest.config
  34  *     ./META-INF/services/jdk.vm.ci.hotspot.HotSpotVMEventListener
  35  * @run main ClassFileInstaller
  36  *     compiler.jvmci.common.JVMCIHelpers$EmptyHotspotCompiler
  37  *     compiler.jvmci.common.JVMCIHelpers$EmptyCompilerFactory
  38  *     compiler.jvmci.events.JvmciNotifyInstallEventTest
  39  *     compiler.jvmci.common.CTVMUtilities
  40  *     compiler.jvmci.common.testcases.SimpleClass
  41  *     jdk.vm.ci.hotspot.CompilerToVMHelper
  42  *     jdk.test.lib.Asserts

  43  * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
  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.CompiledCode;
  62 import jdk.vm.ci.code.InstalledCode;
  63 import jdk.vm.ci.code.site.DataPatch;
  64 import jdk.vm.ci.code.site.Site;
  65 import jdk.vm.ci.meta.Assumptions.Assumption;
  66 import jdk.vm.ci.meta.ResolvedJavaMethod;
  67 import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider;
  68 import jdk.vm.ci.hotspot.HotSpotCompiledCode;
  69 import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment;
  70 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
  71 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
  72 
  73 public class JvmciNotifyInstallEventTest implements HotSpotVMEventListener {
  74     private static final String METHOD_NAME = "testMethod";
  75     private static final boolean IS_POSITIVE = !Boolean.getBoolean(
  76             "compiler.jvmci.events.JvmciNotifyInstallEventTest.noevent");
  77     private static volatile int gotInstallNotification = 0;
  78 
  79     public static void main(String args[]) {
  80         new JvmciNotifyInstallEventTest().runTest();
  81     }
  82 
  83     private void runTest() {
  84         if (gotInstallNotification != 0) {
  85             throw new Error("Got install notification before test actions");
  86         }
  87         HotSpotCodeCacheProvider codeCache = null;
  88         try {
  89             codeCache = (HotSpotCodeCacheProvider) HotSpotJVMCIRuntime.runtime()
  90                     .getHostJVMCIBackend().getCodeCache();
  91         } catch (InternalError ie) {
  92             if (IS_POSITIVE) {
  93                 throw new AssertionError(
  94                         "Got unexpected InternalError trying to get code cache",
  95                         ie);
  96             }
  97             // passed
  98             return;
  99         }
 100         Asserts.assertTrue(IS_POSITIVE,
 101                     "Haven't caught InternalError in negative case");
 102         Method testMethod;
 103         try {
 104             testMethod = SimpleClass.class.getDeclaredMethod(METHOD_NAME);
 105         } catch (NoSuchMethodException e) {
 106             throw new Error("TEST BUG: Can't find " + METHOD_NAME, e);
 107         }
 108         HotSpotResolvedJavaMethod method = CTVMUtilities
 109                 .getResolvedMethod(SimpleClass.class, testMethod);
 110         HotSpotCompiledCode compiledCode = new HotSpotCompiledCode(METHOD_NAME, new byte[0], 0, new Site[0],
 111                 new Assumption[0], new ResolvedJavaMethod[]{method}, new Comment[0], new byte[0], 16,
 112                 new DataPatch[0], false, 0, null);
 113         codeCache.installCode(method, compiledCode, /* installedCode = */ null, /* speculationLog = */ null,
 114                 /* isDefault = */ false);

 115         Asserts.assertEQ(gotInstallNotification, 1,
 116                 "Got unexpected event count after 1st install attempt");
 117         // since "empty" compilation result is ok, a second attempt should be ok
 118         codeCache.installCode(method, compiledCode, /* installedCode = */ null, /* speculationLog = */ null,
 119                 /* isDefault = */ false);
 120         Asserts.assertEQ(gotInstallNotification, 2,
 121                 "Got unexpected event count after 2nd install attempt");











 122     }
 123 
 124     @Override
 125     public void notifyInstall(HotSpotCodeCacheProvider hotSpotCodeCacheProvider,
 126             InstalledCode installedCode, CompiledCode compiledCode) {
 127         gotInstallNotification++;
 128     }
 129 }


  23 
  24 /*
  25  * @test
  26  * @bug 8136421
  27  * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64")
  28  * @library / /testlibrary
  29  * @compile ../common/CompilerToVMHelper.java
  30  * @build compiler.jvmci.common.JVMCIHelpers
  31  *     compiler.jvmci.events.JvmciNotifyInstallEventTest
  32  * @run main jdk.test.lib.FileInstaller ../common/services/ ./META-INF/services/
  33  * @run main jdk.test.lib.FileInstaller ./JvmciNotifyInstallEventTest.config
  34  *     ./META-INF/services/jdk.vm.ci.hotspot.HotSpotVMEventListener
  35  * @run main ClassFileInstaller
  36  *     compiler.jvmci.common.JVMCIHelpers$EmptyHotspotCompiler
  37  *     compiler.jvmci.common.JVMCIHelpers$EmptyCompilerFactory
  38  *     compiler.jvmci.events.JvmciNotifyInstallEventTest
  39  *     compiler.jvmci.common.CTVMUtilities
  40  *     compiler.jvmci.common.testcases.SimpleClass
  41  *     jdk.vm.ci.hotspot.CompilerToVMHelper
  42  *     jdk.test.lib.Asserts
  43  *     jdk.test.lib.Utils
  44  * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
  45  *     -Djvmci.compiler=EmptyCompiler -Xbootclasspath/a:. -Xmixed
  46  *     -XX:+UseJVMCICompiler -XX:-BootstrapJVMCI
  47  *     -Dcompiler.jvmci.events.JvmciNotifyInstallEventTest.failoninit=false
  48  *     compiler.jvmci.events.JvmciNotifyInstallEventTest
  49  * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
  50  *     -Djvmci.compiler=EmptyCompiler -Xbootclasspath/a:. -Xmixed
  51  *     -XX:+UseJVMCICompiler -XX:-BootstrapJVMCI -XX:JVMCINMethodSizeLimit=0
  52  *     -Dcompiler.jvmci.events.JvmciNotifyInstallEventTest.failoninit=false
  53  *     compiler.jvmci.events.JvmciNotifyInstallEventTest
  54  * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:-EnableJVMCI
  55  *     -Djvmci.compiler=EmptyCompiler -Xbootclasspath/a:. -Xmixed
  56  *     -Dcompiler.jvmci.events.JvmciNotifyInstallEventTest.failoninit=true
  57  *     compiler.jvmci.events.JvmciNotifyInstallEventTest
  58  */
  59 
  60 package compiler.jvmci.events;
  61 
  62 import compiler.jvmci.common.CTVMUtilities;
  63 import compiler.jvmci.common.testcases.SimpleClass;
  64 import jdk.test.lib.Asserts;
  65 import java.lang.reflect.Method;
  66 import jdk.test.lib.Utils;
  67 import jdk.vm.ci.hotspot.HotSpotVMEventListener;
  68 import jdk.vm.ci.code.CompiledCode;
  69 import jdk.vm.ci.code.InstalledCode;
  70 import jdk.vm.ci.code.site.DataPatch;
  71 import jdk.vm.ci.code.site.Site;
  72 import jdk.vm.ci.meta.Assumptions.Assumption;
  73 import jdk.vm.ci.meta.ResolvedJavaMethod;
  74 import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider;
  75 import jdk.vm.ci.hotspot.HotSpotCompiledCode;
  76 import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment;
  77 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
  78 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
  79 
  80 public class JvmciNotifyInstallEventTest implements HotSpotVMEventListener {
  81     private static final String METHOD_NAME = "testMethod";
  82     private static final boolean FAIL_ON_INIT = !Boolean.getBoolean(
  83             "compiler.jvmci.events.JvmciNotifyInstallEventTest.failoninit");
  84     private static volatile int gotInstallNotification = 0;
  85 
  86     public static void main(String args[]) {
  87         new JvmciNotifyInstallEventTest().runTest();
  88     }
  89 
  90     private void runTest() {
  91         if (gotInstallNotification != 0) {
  92             throw new Error("Got install notification before test actions");
  93         }
  94         HotSpotCodeCacheProvider codeCache;
  95         try {
  96             codeCache = (HotSpotCodeCacheProvider) HotSpotJVMCIRuntime.runtime()
  97                     .getHostJVMCIBackend().getCodeCache();
  98         } catch (InternalError ie) {
  99             if (FAIL_ON_INIT) {
 100                 throw new AssertionError(
 101                         "Got unexpected InternalError trying to get code cache",
 102                         ie);
 103             }
 104             // passed
 105             return;
 106         }
 107         Asserts.assertTrue(FAIL_ON_INIT,
 108                     "Haven't caught InternalError in negative case");
 109         Method testMethod;
 110         try {
 111             testMethod = SimpleClass.class.getDeclaredMethod(METHOD_NAME);
 112         } catch (NoSuchMethodException e) {
 113             throw new Error("TEST BUG: Can't find " + METHOD_NAME, e);
 114         }
 115         HotSpotResolvedJavaMethod method = CTVMUtilities
 116                 .getResolvedMethod(SimpleClass.class, testMethod);
 117         HotSpotCompiledCode compiledCode = new HotSpotCompiledCode(METHOD_NAME,
 118                 new byte[0], 0, new Site[0], new Assumption[0],
 119                 new ResolvedJavaMethod[]{method}, new Comment[0], new byte[0],
 120                 16, new DataPatch[0], false, 0, null);
 121         codeCache.installCode(method, compiledCode, /* installedCode = */ null,
 122                 /* speculationLog = */ null, /* isDefault = */ false);
 123         Asserts.assertEQ(gotInstallNotification, 1,
 124                 "Got unexpected event count after 1st install attempt");
 125         // since "empty" compilation result is ok, a second attempt should be ok
 126         codeCache.installCode(method, compiledCode, /* installedCode = */ null,
 127                 /* speculationLog = */ null, /* isDefault = */ false);
 128         Asserts.assertEQ(gotInstallNotification, 2,
 129                 "Got unexpected event count after 2nd install attempt");
 130         // and an incorrect cases
 131         Utils.runAndCheckException(() -> {
 132             codeCache.installCode(method, null, null, null, true);
 133         }, NullPointerException.class);
 134         Asserts.assertEQ(gotInstallNotification, 2,
 135                 "Got unexpected event count after 3rd install attempt");
 136         Utils.runAndCheckException(() -> {
 137             codeCache.installCode(null, null, null, null, true);
 138         }, NullPointerException.class);
 139         Asserts.assertEQ(gotInstallNotification, 2,
 140                 "Got unexpected event count after 4th install attempt");
 141     }
 142 
 143     @Override
 144     public void notifyInstall(HotSpotCodeCacheProvider hotSpotCodeCacheProvider,
 145             InstalledCode installedCode, CompiledCode compiledCode) {
 146         gotInstallNotification++;
 147     }
 148 }
< prev index next >