author | rschatz |
Wed, 20 Jan 2016 14:22:46 +0100 | |
changeset 35582 | c32a0cc19877 |
parent 35148 | 5cfafc99d791 |
child 35823 | 59a847ec6ee3 |
permissions | -rw-r--r-- |
33160 | 1 |
/* |
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 8136421 |
|
35148 | 27 |
* @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64") |
33160 | 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; |
|
35582
c32a0cc19877
8147599: [JVMCI] simplify code installation interface
rschatz
parents:
35148
diff
changeset
|
61 |
import jdk.vm.ci.code.CompiledCode; |
33160 | 62 |
import jdk.vm.ci.code.InstalledCode; |
35582
c32a0cc19877
8147599: [JVMCI] simplify code installation interface
rschatz
parents:
35148
diff
changeset
|
63 |
import jdk.vm.ci.code.site.DataPatch; |
c32a0cc19877
8147599: [JVMCI] simplify code installation interface
rschatz
parents:
35148
diff
changeset
|
64 |
import jdk.vm.ci.code.site.Site; |
c32a0cc19877
8147599: [JVMCI] simplify code installation interface
rschatz
parents:
35148
diff
changeset
|
65 |
import jdk.vm.ci.meta.Assumptions.Assumption; |
c32a0cc19877
8147599: [JVMCI] simplify code installation interface
rschatz
parents:
35148
diff
changeset
|
66 |
import jdk.vm.ci.meta.ResolvedJavaMethod; |
33160 | 67 |
import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider; |
35582
c32a0cc19877
8147599: [JVMCI] simplify code installation interface
rschatz
parents:
35148
diff
changeset
|
68 |
import jdk.vm.ci.hotspot.HotSpotCompiledCode; |
c32a0cc19877
8147599: [JVMCI] simplify code installation interface
rschatz
parents:
35148
diff
changeset
|
69 |
import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment; |
33160 | 70 |
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; |
33632 | 71 |
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; |
33160 | 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 |
} |
|
33632 | 108 |
HotSpotResolvedJavaMethod method = CTVMUtilities |
33160 | 109 |
.getResolvedMethod(SimpleClass.class, testMethod); |
35582
c32a0cc19877
8147599: [JVMCI] simplify code installation interface
rschatz
parents:
35148
diff
changeset
|
110 |
HotSpotCompiledCode compiledCode = new HotSpotCompiledCode(METHOD_NAME, new byte[0], 0, new Site[0], |
c32a0cc19877
8147599: [JVMCI] simplify code installation interface
rschatz
parents:
35148
diff
changeset
|
111 |
new Assumption[0], new ResolvedJavaMethod[]{method}, new Comment[0], new byte[0], 16, |
c32a0cc19877
8147599: [JVMCI] simplify code installation interface
rschatz
parents:
35148
diff
changeset
|
112 |
new DataPatch[0], false, 0, 0); |
c32a0cc19877
8147599: [JVMCI] simplify code installation interface
rschatz
parents:
35148
diff
changeset
|
113 |
codeCache.installCode(method, compiledCode, /* installedCode = */ null, /* speculationLog = */ null, |
33160 | 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 |
|
35582
c32a0cc19877
8147599: [JVMCI] simplify code installation interface
rschatz
parents:
35148
diff
changeset
|
118 |
codeCache.installCode(method, compiledCode, /* installedCode = */ null, /* speculationLog = */ null, |
33160 | 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, |
|
35582
c32a0cc19877
8147599: [JVMCI] simplify code installation interface
rschatz
parents:
35148
diff
changeset
|
126 |
InstalledCode installedCode, CompiledCode compiledCode) { |
33160 | 127 |
gotInstallNotification++; |
128 |
} |
|
129 |
} |