hotspot/test/compiler/jvmci/events/JvmciNotifyInstallEventTest.java
changeset 35582 c32a0cc19877
parent 35148 5cfafc99d791
child 35823 59a847ec6ee3
equal deleted inserted replaced
35581:dd47cf4734f2 35582:c32a0cc19877
    56 import compiler.jvmci.common.CTVMUtilities;
    56 import compiler.jvmci.common.CTVMUtilities;
    57 import compiler.jvmci.common.testcases.SimpleClass;
    57 import compiler.jvmci.common.testcases.SimpleClass;
    58 import jdk.test.lib.Asserts;
    58 import jdk.test.lib.Asserts;
    59 import java.lang.reflect.Method;
    59 import java.lang.reflect.Method;
    60 import jdk.vm.ci.hotspot.HotSpotVMEventListener;
    60 import jdk.vm.ci.hotspot.HotSpotVMEventListener;
    61 import jdk.vm.ci.code.CompilationResult;
    61 import jdk.vm.ci.code.CompiledCode;
    62 import jdk.vm.ci.code.InstalledCode;
    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;
    63 import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider;
    67 import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider;
    64 import jdk.vm.ci.hotspot.HotSpotCompilationRequest;
    68 import jdk.vm.ci.hotspot.HotSpotCompiledCode;
       
    69 import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment;
    65 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
    70 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
    66 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
    71 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
    67 
    72 
    68 public class JvmciNotifyInstallEventTest implements HotSpotVMEventListener {
    73 public class JvmciNotifyInstallEventTest implements HotSpotVMEventListener {
    69     private static final String METHOD_NAME = "testMethod";
    74     private static final String METHOD_NAME = "testMethod";
   100         } catch (NoSuchMethodException e) {
   105         } catch (NoSuchMethodException e) {
   101             throw new Error("TEST BUG: Can't find " + METHOD_NAME, e);
   106             throw new Error("TEST BUG: Can't find " + METHOD_NAME, e);
   102         }
   107         }
   103         HotSpotResolvedJavaMethod method = CTVMUtilities
   108         HotSpotResolvedJavaMethod method = CTVMUtilities
   104                 .getResolvedMethod(SimpleClass.class, testMethod);
   109                 .getResolvedMethod(SimpleClass.class, testMethod);
   105         CompilationResult compResult = new CompilationResult(METHOD_NAME);
   110         HotSpotCompiledCode compiledCode = new HotSpotCompiledCode(METHOD_NAME, new byte[0], 0, new Site[0],
   106         HotSpotCompilationRequest compRequest = new HotSpotCompilationRequest(method, -1, 0L);
   111                 new Assumption[0], new ResolvedJavaMethod[]{method}, new Comment[0], new byte[0], 16,
   107         // to pass sanity check of default -1
   112                 new DataPatch[0], false, 0, 0);
   108         compResult.setTotalFrameSize(0);
   113         codeCache.installCode(method, compiledCode, /* installedCode = */ null, /* speculationLog = */ null,
   109         compResult.close();
       
   110         codeCache.installCode(compRequest, compResult, /* installedCode = */ null, /* speculationLog = */ null,
       
   111                 /* isDefault = */ false);
   114                 /* isDefault = */ false);
   112         Asserts.assertEQ(gotInstallNotification, 1,
   115         Asserts.assertEQ(gotInstallNotification, 1,
   113                 "Got unexpected event count after 1st install attempt");
   116                 "Got unexpected event count after 1st install attempt");
   114         // since "empty" compilation result is ok, a second attempt should be ok
   117         // since "empty" compilation result is ok, a second attempt should be ok
   115         codeCache.installCode(compRequest, compResult, /* installedCode = */ null, /* speculationLog = */ null,
   118         codeCache.installCode(method, compiledCode, /* installedCode = */ null, /* speculationLog = */ null,
   116                 /* isDefault = */ false);
   119                 /* isDefault = */ false);
   117         Asserts.assertEQ(gotInstallNotification, 2,
   120         Asserts.assertEQ(gotInstallNotification, 2,
   118                 "Got unexpected event count after 2nd install attempt");
   121                 "Got unexpected event count after 2nd install attempt");
   119     }
   122     }
   120 
   123 
   121     @Override
   124     @Override
   122     public void notifyInstall(HotSpotCodeCacheProvider hotSpotCodeCacheProvider,
   125     public void notifyInstall(HotSpotCodeCacheProvider hotSpotCodeCacheProvider,
   123             InstalledCode installedCode, CompilationResult compResult) {
   126             InstalledCode installedCode, CompiledCode compiledCode) {
   124         gotInstallNotification++;
   127         gotInstallNotification++;
   125     }
   128     }
   126 }
   129 }