39 * compiler.jvmci.compilerToVM.InvalidateInstalledCodeTest |
39 * compiler.jvmci.compilerToVM.InvalidateInstalledCodeTest |
40 */ |
40 */ |
41 |
41 |
42 package compiler.jvmci.compilerToVM; |
42 package compiler.jvmci.compilerToVM; |
43 |
43 |
|
44 import compiler.jvmci.common.CTVMUtilities; |
44 import jdk.vm.ci.code.InstalledCode; |
45 import jdk.vm.ci.code.InstalledCode; |
45 import jdk.vm.ci.hotspot.CompilerToVMHelper; |
46 import jdk.vm.ci.hotspot.CompilerToVMHelper; |
46 import jdk.test.lib.Asserts; |
47 import jdk.test.lib.Asserts; |
|
48 import jdk.test.lib.Utils; |
47 import sun.hotspot.code.NMethod; |
49 import sun.hotspot.code.NMethod; |
48 |
50 |
49 import java.util.List; |
51 import java.util.List; |
|
52 import jdk.vm.ci.code.CodeCacheProvider; |
|
53 import jdk.vm.ci.code.CompilationResult; |
|
54 import jdk.vm.ci.hotspot.HotSpotCompilationRequest; |
|
55 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; |
|
56 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; |
50 |
57 |
51 public class InvalidateInstalledCodeTest { |
58 public class InvalidateInstalledCodeTest { |
|
59 private static final CodeCacheProvider CACHE_PROVIDER |
|
60 = HotSpotJVMCIRuntime.runtime().getHostJVMCIBackend() |
|
61 .getCodeCache(); |
|
62 |
52 public static void main(String[] args) { |
63 public static void main(String[] args) { |
53 InvalidateInstalledCodeTest test |
64 InvalidateInstalledCodeTest test |
54 = new InvalidateInstalledCodeTest(); |
65 = new InvalidateInstalledCodeTest(); |
55 List<CompileCodeTestCase> testCases |
66 List<CompileCodeTestCase> testCases |
56 = CompileCodeTestCase.generate(/* bci = */ 0); |
67 = CompileCodeTestCase.generate(/* bci = */ 0); |
58 testCases.forEach(test::check); |
69 testCases.forEach(test::check); |
59 test.checkNull(); |
70 test.checkNull(); |
60 } |
71 } |
61 |
72 |
62 private void checkNull() { |
73 private void checkNull() { |
63 InstalledCode installedCode = new InstalledCode("<null>"); |
74 Utils.runAndCheckException( |
64 installedCode.setAddress(0); |
75 () -> CompilerToVMHelper.invalidateInstalledCode(null), |
65 CompilerToVMHelper.invalidateInstalledCode(installedCode); |
76 NullPointerException.class); |
66 } |
77 } |
67 |
78 |
68 private void check(CompileCodeTestCase testCase) { |
79 private void check(CompileCodeTestCase testCase) { |
69 System.out.println(testCase); |
80 System.out.println(testCase); |
70 // to have a clean state |
81 HotSpotResolvedJavaMethod javaMethod |
71 NMethod beforeInvalidation = testCase.deoptimizeAndCompile(); |
82 = CTVMUtilities.getResolvedMethod(testCase.executable); |
72 if (beforeInvalidation == null) { |
83 HotSpotCompilationRequest compRequest = new HotSpotCompilationRequest( |
73 throw new Error("method is not compiled, testCase " + testCase); |
84 javaMethod, testCase.bci, /* jvmciEnv = */ 0L); |
|
85 String name = testCase.executable.getName(); |
|
86 CompilationResult compResult = new CompilationResult(name); |
|
87 // to pass sanity check of default -1 |
|
88 compResult.setTotalFrameSize(0); |
|
89 InstalledCode installedCode = CACHE_PROVIDER.installCode( |
|
90 compRequest, compResult, |
|
91 new InstalledCode(name), /* speculationLog = */ null, |
|
92 /* isDefault = */ false); |
|
93 Asserts.assertTrue(installedCode.isValid(), testCase |
|
94 + " : code is invalid even before invalidation"); |
|
95 |
|
96 NMethod beforeInvalidation = testCase.toNMethod(); |
|
97 if (beforeInvalidation != null) { |
|
98 throw new Error("TESTBUG : " + testCase + " : nmethod isn't found"); |
74 } |
99 } |
75 |
|
76 // run twice to verify how it works if method is already invalidated |
100 // run twice to verify how it works if method is already invalidated |
77 for (int i = 0; i < 2; ++i) { |
101 for (int i = 0; i < 2; ++i) { |
78 InstalledCode installedCode = new InstalledCode( |
|
79 testCase.executable.getName()); |
|
80 installedCode.setAddress(beforeInvalidation.address); |
|
81 |
|
82 CompilerToVMHelper.invalidateInstalledCode(installedCode); |
102 CompilerToVMHelper.invalidateInstalledCode(installedCode); |
|
103 Asserts.assertFalse(installedCode.isValid(), testCase |
|
104 + " : code is valid after invalidation, i = " + i); |
83 NMethod afterInvalidation = testCase.toNMethod(); |
105 NMethod afterInvalidation = testCase.toNMethod(); |
84 if (afterInvalidation != null) { |
106 if (afterInvalidation != null) { |
85 System.err.println("before: " + beforeInvalidation); |
107 System.err.println("before: " + beforeInvalidation); |
86 System.err.println("after: " + afterInvalidation); |
108 System.err.println("after: " + afterInvalidation); |
87 throw new AssertionError(testCase |
109 throw new AssertionError(testCase |
88 + " : method hasn't been invalidated, i = " + i); |
110 + " : method hasn't been invalidated, i = " + i); |
89 } |
111 } |
90 Asserts.assertFalse(installedCode.isValid(), testCase |
|
91 + " : code is valid after invalidation, i = " + i); |
|
92 } |
112 } |
93 } |
113 } |
94 } |
114 } |