author | kvn |
Wed, 01 May 2019 12:31:29 -0700 | |
changeset 54669 | ad45b3802d4e |
parent 50793 | ca4eea543d23 |
permissions | -rw-r--r-- |
42607
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
1 |
/* |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50793
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
42607
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
4 |
* |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
7 |
* published by the Free Software Foundation. |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
8 |
* |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
13 |
* accompanied this code). |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
14 |
* |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
18 |
* |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
21 |
* questions. |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
22 |
*/ |
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41063
diff
changeset
|
23 |
|
43972 | 24 |
/* |
25 |
* @test |
|
26 |
* @bug 8136421 |
|
27 |
* @requires vm.jvmci |
|
28 |
* @library /test/lib / |
|
29 |
* @library ../common/patches |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50793
diff
changeset
|
30 |
* @ignore Not supported JVMCI API |
43972 | 31 |
* @modules java.base/jdk.internal.misc |
32 |
* @modules java.base/jdk.internal.org.objectweb.asm |
|
33 |
* java.base/jdk.internal.org.objectweb.asm.tree |
|
34 |
* jdk.internal.vm.ci/jdk.vm.ci.hotspot |
|
35 |
* jdk.internal.vm.ci/jdk.vm.ci.code |
|
36 |
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox |
|
37 |
* @run driver ClassFileInstaller sun.hotspot.WhiteBox |
|
38 |
* sun.hotspot.WhiteBox$WhiteBoxPermission |
|
39 |
* @run main/othervm -Xbootclasspath/a:. |
|
40 |
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI |
|
41 |
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI |
|
50793
ca4eea543d23
8205400: [Graal] compiler/jvmci/compilerToVM/DisassembleCodeBlobTest.java fails with can't be enqueued for compilation on level 4
kvn
parents:
47216
diff
changeset
|
42 |
* -XX:-BackgroundCompilation |
43972 | 43 |
* compiler.jvmci.compilerToVM.ExecuteInstalledCodeTest |
44 |
*/ |
|
45 |
||
33160 | 46 |
package compiler.jvmci.compilerToVM; |
47 |
||
40059 | 48 |
import jdk.test.lib.Asserts; |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40059
diff
changeset
|
49 |
import jdk.test.lib.util.Pair; |
40059 | 50 |
import jdk.test.lib.Utils; |
33160 | 51 |
import jdk.vm.ci.code.InstalledCode; |
52 |
import jdk.vm.ci.code.InvalidInstalledCodeException; |
|
53 |
import jdk.vm.ci.hotspot.CompilerToVMHelper; |
|
54 |
import sun.hotspot.code.NMethod; |
|
55 |
||
56 |
import java.lang.reflect.Constructor; |
|
57 |
import java.lang.reflect.Modifier; |
|
58 |
import java.util.ArrayList; |
|
59 |
import java.util.List; |
|
60 |
||
61 |
public class ExecuteInstalledCodeTest { |
|
62 |
||
63 |
public static void main(String[] args) { |
|
64 |
ExecuteInstalledCodeTest test = new ExecuteInstalledCodeTest(); |
|
65 |
List<CompileCodeTestCase> testCases = new ArrayList<>(); |
|
66 |
testCases.addAll(CompileCodeTestCase.generate(/* bci = */ -1)); |
|
67 |
testCases .stream() |
|
68 |
// ignore <init> of abstract class -- 8138793 |
|
69 |
.filter(e -> !(e.executable instanceof Constructor |
|
70 |
&& Modifier.isAbstract( |
|
71 |
e.executable.getDeclaringClass() |
|
72 |
.getModifiers()))) |
|
73 |
.forEach(test::checkSanity); |
|
74 |
} |
|
75 |
||
76 |
private void checkSanity(CompileCodeTestCase testCase) { |
|
77 |
System.out.println(testCase); |
|
78 |
// to have a clean state |
|
79 |
testCase.deoptimize(); |
|
80 |
Pair<Object, ? extends Throwable> reflectionResult; |
|
33632 | 81 |
Object[] args = Utils.getNullValues( |
82 |
testCase.executable.getParameterTypes()); |
|
83 |
reflectionResult = testCase.invoke(args); |
|
33160 | 84 |
NMethod nMethod = testCase.compile(); |
85 |
if (nMethod == null) { |
|
86 |
throw new Error(testCase + " : nmethod is null"); |
|
87 |
} |
|
33632 | 88 |
InstalledCode installedCode = testCase.toInstalledCode(); |
33160 | 89 |
Object result = null; |
90 |
Throwable expectedException = reflectionResult.second; |
|
91 |
boolean gotException = true; |
|
92 |
try { |
|
93 |
args = addReceiver(testCase, args); |
|
94 |
result = CompilerToVMHelper.executeInstalledCode( |
|
95 |
args, installedCode); |
|
96 |
if (testCase.executable instanceof Constructor) { |
|
97 |
// <init> doesn't have return value, it changes receiver |
|
98 |
result = args[0]; |
|
99 |
} |
|
100 |
gotException = false; |
|
101 |
} catch (InvalidInstalledCodeException e) { |
|
102 |
throw new AssertionError( |
|
103 |
testCase + " : unexpected InvalidInstalledCodeException", e); |
|
104 |
} catch (Throwable t) { |
|
105 |
if (expectedException == null) { |
|
106 |
throw new AssertionError(testCase |
|
107 |
+ " : got unexpected execption : " + t.getMessage(), t); |
|
108 |
} |
|
109 |
||
110 |
if (expectedException.getClass() != t.getClass()) { |
|
111 |
System.err.println("exception from CompilerToVM:"); |
|
112 |
t.printStackTrace(); |
|
113 |
System.err.println("exception from reflection:"); |
|
114 |
expectedException.printStackTrace(); |
|
115 |
throw new AssertionError(String.format( |
|
116 |
"%s : got unexpected different exceptions : %s != %s", |
|
117 |
testCase, expectedException.getClass(), t.getClass())); |
|
118 |
} |
|
119 |
} |
|
120 |
||
121 |
Asserts.assertEQ(reflectionResult.first, result, testCase |
|
122 |
+ " : different return value"); |
|
123 |
if (!gotException) { |
|
124 |
Asserts.assertNull(expectedException, testCase |
|
125 |
+ " : expected exception hasn't been thrown"); |
|
126 |
} |
|
127 |
} |
|
128 |
||
129 |
private Object[] addReceiver(CompileCodeTestCase testCase, Object[] args) { |
|
130 |
if (!Modifier.isStatic(testCase.executable.getModifiers())) { |
|
131 |
// add instance as 0th arg |
|
132 |
Object[] newArgs = new Object[args.length + 1]; |
|
33632 | 133 |
newArgs[0] = testCase.receiver; |
33160 | 134 |
System.arraycopy(args, 0, newArgs, 1, args.length); |
135 |
args = newArgs; |
|
136 |
} |
|
137 |
return args; |
|
138 |
} |
|
139 |
} |