< prev index next >

test/compiler/jvmci/events/JvmciNotifyInstallEventTest.java

Print this page




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


  32  *          java.base/jdk.internal.org.objectweb.asm.tree
  33  *          jdk.internal.vm.ci/jdk.vm.ci.hotspot
  34  *          jdk.internal.vm.ci/jdk.vm.ci.code
  35  *          jdk.internal.vm.ci/jdk.vm.ci.code.site
  36  *          jdk.internal.vm.ci/jdk.vm.ci.meta
  37  *          jdk.internal.vm.ci/jdk.vm.ci.runtime
  38  *          jdk.internal.vm.ci/jdk.vm.ci.services
  39  *
  40  * @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
  41  * @build compiler.jvmci.common.JVMCIHelpers
  42  * @run driver jdk.test.lib.FileInstaller ./JvmciNotifyInstallEventTest.config
  43  *     ./META-INF/services/jdk.vm.ci.services.JVMCIServiceLocator
  44  * @run driver ClassFileInstaller
  45  *      compiler.jvmci.common.JVMCIHelpers$EmptyHotspotCompiler
  46  *      compiler.jvmci.common.JVMCIHelpers$EmptyCompilerFactory
  47  *      compiler.jvmci.common.JVMCIHelpers$EmptyCompilationRequestResult
  48  *      compiler.jvmci.common.JVMCIHelpers$EmptyVMEventListener
  49  * @run main/othervm -XX:+UnlockExperimentalVMOptions
  50  *     -Xbootclasspath/a:. -Xmixed
  51  *     -XX:+UseJVMCICompiler -XX:-BootstrapJVMCI

  52  *     compiler.jvmci.events.JvmciNotifyInstallEventTest
  53  * @run main/othervm -XX:+UnlockExperimentalVMOptions
  54  *     -Djvmci.Compiler=EmptyCompiler -Xbootclasspath/a:. -Xmixed
  55  *     -XX:+UseJVMCICompiler -XX:-BootstrapJVMCI

  56  *     compiler.jvmci.events.JvmciNotifyInstallEventTest
  57  * @run main/othervm -XX:+UnlockExperimentalVMOptions
  58  *     -Djvmci.Compiler=EmptyCompiler -Xbootclasspath/a:. -Xmixed
  59  *     -XX:+UseJVMCICompiler -XX:-BootstrapJVMCI -XX:JVMCINMethodSizeLimit=0





  60  *     compiler.jvmci.events.JvmciNotifyInstallEventTest
  61  */
  62 
  63 package compiler.jvmci.events;
  64 
  65 import compiler.jvmci.common.CTVMUtilities;
  66 import compiler.jvmci.common.testcases.SimpleClass;
  67 import jdk.test.lib.Asserts;
  68 import jdk.test.lib.Utils;
  69 import jdk.vm.ci.services.JVMCIServiceLocator;
  70 import jdk.vm.ci.code.CompiledCode;
  71 import jdk.vm.ci.code.InstalledCode;
  72 import jdk.vm.ci.code.site.DataPatch;
  73 import jdk.vm.ci.code.site.Site;
  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 import jdk.vm.ci.hotspot.HotSpotVMEventListener;
  80 import jdk.vm.ci.meta.Assumptions.Assumption;
  81 import jdk.vm.ci.meta.ResolvedJavaMethod;
  82 
  83 import java.lang.reflect.Method;
  84 
  85 public class JvmciNotifyInstallEventTest extends JVMCIServiceLocator implements HotSpotVMEventListener {
  86     private static final String METHOD_NAME = "testMethod";


  87     private static volatile int gotInstallNotification = 0;
  88 
  89     public static void main(String args[]) {
  90         new JvmciNotifyInstallEventTest().runTest();
  91     }
  92 
  93     @Override
  94     public <S> S getProvider(Class<S> service) {
  95         if (service == HotSpotVMEventListener.class) {
  96             return service.cast(this);
  97         }
  98         return null;
  99     }
 100 
 101     private void runTest() {
 102         if (gotInstallNotification != 0) {
 103             throw new Error("Got install notification before test actions");
 104         }
 105         HotSpotCodeCacheProvider codeCache;
 106         try {
 107             codeCache = (HotSpotCodeCacheProvider) HotSpotJVMCIRuntime.runtime()
 108                     .getHostJVMCIBackend().getCodeCache();
 109         } catch (InternalError ie) {





 110             // passed
 111             return;
 112         }


 113         Method testMethod;
 114         try {
 115             testMethod = SimpleClass.class.getDeclaredMethod(METHOD_NAME);
 116         } catch (NoSuchMethodException e) {
 117             throw new Error("TEST BUG: Can't find " + METHOD_NAME, e);
 118         }
 119         HotSpotResolvedJavaMethod method = CTVMUtilities
 120                 .getResolvedMethod(SimpleClass.class, testMethod);
 121         HotSpotCompiledCode compiledCode = new HotSpotCompiledCode(METHOD_NAME,
 122                 new byte[0], 0, new Site[0], new Assumption[0],
 123                 new ResolvedJavaMethod[]{method}, new Comment[0], new byte[0],
 124                 16, new DataPatch[0], false, 0, null);
 125         codeCache.installCode(method, compiledCode, /* installedCode = */ null,
 126                 /* speculationLog = */ null, /* isDefault = */ false);
 127         Asserts.assertEQ(gotInstallNotification, 1,
 128                 "Got unexpected event count after 1st install attempt");
 129         // since "empty" compilation result is ok, a second attempt should be ok
 130         codeCache.installCode(method, compiledCode, /* installedCode = */ null,
 131                 /* speculationLog = */ null, /* isDefault = */ false);
 132         Asserts.assertEQ(gotInstallNotification, 2,
< prev index next >