|
1 | 1 | /* |
2 | | - * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
27 | 27 | * @requires vm.jvmci |
28 | 28 | * @library /test/lib / |
29 | 29 | * @library ../common/patches |
30 | | - * @ignore 8249621 |
31 | | - * @ignore 8163894 |
32 | 30 | * @modules java.base/jdk.internal.misc |
33 | 31 | * @modules java.base/jdk.internal.org.objectweb.asm |
34 | 32 | * java.base/jdk.internal.org.objectweb.asm.tree |
35 | 33 | * jdk.internal.vm.ci/jdk.vm.ci.hotspot |
36 | 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 | 37 | * jdk.internal.vm.ci/jdk.vm.ci.runtime |
38 | 38 | * |
39 | 39 | * @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper |
40 | | - * @build compiler.jvmci.compilerToVM.InvalidateInstalledCodeTest |
41 | | - * @build jdk.test.whitebox.WhiteBox |
| 40 | + * jdk.test.whitebox.WhiteBox jdk.test.whitebox.parser.DiagnosticCommand |
42 | 41 | * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox |
43 | | - * @run main/othervm -Xbootclasspath/a:. |
| 42 | + * jdk.test.whitebox.parser.DiagnosticCommand |
| 43 | + * @run junit/othervm -Xbootclasspath/a:. |
44 | 44 | * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI |
45 | 45 | * -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI |
46 | 46 | * compiler.jvmci.compilerToVM.InvalidateInstalledCodeTest |
47 | 47 | */ |
48 | 48 |
|
49 | 49 | package compiler.jvmci.compilerToVM; |
50 | 50 |
|
| 51 | +import compiler.jvmci.common.CodeInstallerTest; |
51 | 52 | import compiler.jvmci.common.CTVMUtilities; |
52 | 53 | import jdk.test.lib.Asserts; |
53 | 54 | import jdk.test.lib.Utils; |
54 | | -import jdk.vm.ci.code.CodeCacheProvider; |
55 | | -import jdk.vm.ci.code.CompilationResult; |
56 | 55 | import jdk.vm.ci.code.InstalledCode; |
| 56 | +import jdk.vm.ci.code.site.Site; |
| 57 | +import jdk.vm.ci.code.site.DataPatch; |
57 | 58 | import jdk.vm.ci.hotspot.CompilerToVMHelper; |
58 | | -import jdk.vm.ci.hotspot.HotSpotCompilationRequest; |
59 | 59 | import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; |
60 | 60 | import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; |
61 | | -import jdk.test.whitebox.code.NMethod; |
| 61 | +import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment; |
| 62 | +import jdk.vm.ci.hotspot.HotSpotNmethod; |
| 63 | +import jdk.vm.ci.meta.Assumptions.Assumption; |
62 | 64 |
|
63 | 65 | import java.util.List; |
| 66 | +import org.junit.Test; |
64 | 67 |
|
65 | | -public class InvalidateInstalledCodeTest { |
66 | | - private static final CodeCacheProvider CACHE_PROVIDER |
67 | | - = HotSpotJVMCIRuntime.runtime().getHostJVMCIBackend() |
68 | | - .getCodeCache(); |
| 68 | +public class InvalidateInstalledCodeTest extends CodeInstallerTest { |
69 | 69 |
|
70 | | - public static void main(String[] args) { |
71 | | - InvalidateInstalledCodeTest test |
72 | | - = new InvalidateInstalledCodeTest(); |
| 70 | + @Test |
| 71 | + public void testInvalidation() { |
73 | 72 | List<CompileCodeTestCase> testCases |
74 | 73 | = CompileCodeTestCase.generate(/* bci = */ 0); |
75 | 74 | testCases.addAll(CompileCodeTestCase.generate(/* bci = */ -1)); |
76 | | - testCases.forEach(test::check); |
77 | | - test.checkNull(); |
| 75 | + testCases.forEach(t -> check(t)); |
| 76 | + checkNull(); |
78 | 77 | } |
79 | 78 |
|
80 | 79 | private void checkNull() { |
81 | 80 | Utils.runAndCheckException( |
82 | | - () -> CompilerToVMHelper.invalidateInstalledCode(null), |
| 81 | + () -> CompilerToVMHelper.invalidateHotSpotNmethod(null, true), |
83 | 82 | NullPointerException.class); |
84 | 83 | } |
85 | 84 |
|
86 | 85 | private void check(CompileCodeTestCase testCase) { |
87 | | - System.out.println(testCase); |
88 | | - HotSpotResolvedJavaMethod javaMethod |
89 | | - = CTVMUtilities.getResolvedMethod(testCase.executable); |
90 | | - HotSpotCompilationRequest compRequest = new HotSpotCompilationRequest( |
91 | | - javaMethod, testCase.bci, /* jvmciEnv = */ 0L); |
92 | | - String name = testCase.executable.getName(); |
93 | | - CompilationResult compResult = new CompilationResult(name); |
94 | | - // to pass sanity check of default -1 |
95 | | - compResult.setTotalFrameSize(0); |
96 | | - compResult.close(); |
97 | | - InstalledCode installedCode = CACHE_PROVIDER.installCode( |
98 | | - compRequest, compResult, |
99 | | - new InstalledCode(name), /* speculationLog = */ null, |
100 | | - /* isDefault = */ false); |
101 | | - Asserts.assertTrue(installedCode.isValid(), testCase |
102 | | - + " : code is invalid even before invalidation"); |
| 86 | + HotSpotResolvedJavaMethod javaMethod = CTVMUtilities.getResolvedMethod(testCase.executable); |
| 87 | + HotSpotNmethod nmethod = (HotSpotNmethod) installEmptyCode(new Site[0], new Assumption[0], |
| 88 | + new Comment[0], 8, new DataPatch[0], null); |
103 | 89 |
|
104 | | - NMethod beforeInvalidation = testCase.toNMethod(); |
105 | | - if (beforeInvalidation != null) { |
106 | | - throw new Error("TESTBUG : " + testCase + " : nmethod isn't found"); |
107 | | - } |
108 | | - // run twice to verify how it works if method is already invalidated |
109 | | - for (int i = 0; i < 2; ++i) { |
110 | | - CompilerToVMHelper.invalidateInstalledCode(installedCode); |
111 | | - Asserts.assertFalse(installedCode.isValid(), testCase |
112 | | - + " : code is valid after invalidation, i = " + i); |
113 | | - NMethod afterInvalidation = testCase.toNMethod(); |
114 | | - if (afterInvalidation != null) { |
115 | | - System.err.println("before: " + beforeInvalidation); |
116 | | - System.err.println("after: " + afterInvalidation); |
117 | | - throw new AssertionError(testCase |
118 | | - + " : method hasn't been invalidated, i = " + i); |
119 | | - } |
120 | | - } |
| 90 | + Asserts.assertTrue(nmethod.isValid(), testCase + " : code is invalid even before invalidation"); |
| 91 | + |
| 92 | + Asserts.assertTrue(nmethod.isValid(), testCase + " : code is not valid, i = " + nmethod); |
| 93 | + Asserts.assertTrue(nmethod.isAlive(), testCase + " : code is not alive, i = " + nmethod); |
| 94 | + |
| 95 | + // Make nmethod non-entrant but still alive |
| 96 | + CompilerToVMHelper.invalidateHotSpotNmethod(nmethod, false); |
| 97 | + Asserts.assertFalse(nmethod.isValid(), testCase + " : code is valid, i = " + nmethod); |
| 98 | + Asserts.assertTrue(nmethod.isAlive(), testCase + " : code is not alive, i = " + nmethod); |
| 99 | + |
| 100 | + // Deoptimize the nmethod and cut the link to it from the HotSpotNmethod |
| 101 | + CompilerToVMHelper.invalidateHotSpotNmethod(nmethod, true); |
| 102 | + Asserts.assertFalse(nmethod.isValid(), testCase + " : code is valid, i = " + nmethod); |
| 103 | + Asserts.assertFalse(nmethod.isAlive(), testCase + " : code is alive, i = " + nmethod); |
121 | 104 | } |
122 | 105 | } |
0 commit comments