author | stsmirno |
Mon, 17 Oct 2016 18:54:12 -0400 | |
changeset 41705 | 332239c052cc |
parent 41063 | 3226f7a0929c |
child 42607 | acd91f1875d4 |
permissions | -rw-r--r-- |
33160 | 1 |
package compiler.jvmci.compilerToVM; |
2 |
||
40059 | 3 |
import jdk.test.lib.Asserts; |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40059
diff
changeset
|
4 |
import jdk.test.lib.util.Pair; |
40059 | 5 |
import jdk.test.lib.Utils; |
33160 | 6 |
import jdk.vm.ci.code.InstalledCode; |
7 |
import jdk.vm.ci.code.InvalidInstalledCodeException; |
|
8 |
import jdk.vm.ci.hotspot.CompilerToVMHelper; |
|
9 |
import sun.hotspot.code.NMethod; |
|
10 |
||
11 |
import java.lang.reflect.Constructor; |
|
12 |
import java.lang.reflect.Modifier; |
|
13 |
import java.util.ArrayList; |
|
14 |
import java.util.List; |
|
15 |
||
16 |
/* |
|
17 |
* @test |
|
18 |
* @bug 8136421 |
|
39291
a4efe145313d
8157831: JVMCI tests should not be executed on linux-arm32
lmesnik
parents:
38152
diff
changeset
|
19 |
* @requires (vm.simpleArch == "x64" | vm.simpleArch == "sparcv9" | vm.simpleArch == "aarch64") |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40059
diff
changeset
|
20 |
* @library /test/lib / |
36508 | 21 |
* @library ../common/patches |
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36508
diff
changeset
|
22 |
* @modules java.base/jdk.internal.misc |
36508 | 23 |
* @modules java.base/jdk.internal.org.objectweb.asm |
24 |
* java.base/jdk.internal.org.objectweb.asm.tree |
|
25 |
* jdk.vm.ci/jdk.vm.ci.hotspot |
|
26 |
* jdk.vm.ci/jdk.vm.ci.code |
|
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40059
diff
changeset
|
27 |
* @build jdk.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox |
40053
b3617982544e
8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents:
39291
diff
changeset
|
28 |
* @run driver ClassFileInstaller sun.hotspot.WhiteBox |
b3617982544e
8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents:
39291
diff
changeset
|
29 |
* sun.hotspot.WhiteBox$WhiteBoxPermission |
36508 | 30 |
* @run main/othervm -Xbootclasspath/a:. |
31 |
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI |
|
32 |
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI |
|
33 |
* compiler.jvmci.compilerToVM.ExecuteInstalledCodeTest |
|
33160 | 34 |
*/ |
35 |
||
36 |
public class ExecuteInstalledCodeTest { |
|
37 |
||
38 |
public static void main(String[] args) { |
|
39 |
ExecuteInstalledCodeTest test = new ExecuteInstalledCodeTest(); |
|
40 |
List<CompileCodeTestCase> testCases = new ArrayList<>(); |
|
41 |
testCases.addAll(CompileCodeTestCase.generate(/* bci = */ -1)); |
|
42 |
testCases .stream() |
|
43 |
// ignore <init> of abstract class -- 8138793 |
|
44 |
.filter(e -> !(e.executable instanceof Constructor |
|
45 |
&& Modifier.isAbstract( |
|
46 |
e.executable.getDeclaringClass() |
|
47 |
.getModifiers()))) |
|
48 |
.forEach(test::checkSanity); |
|
49 |
} |
|
50 |
||
51 |
private void checkSanity(CompileCodeTestCase testCase) { |
|
52 |
System.out.println(testCase); |
|
53 |
// to have a clean state |
|
54 |
testCase.deoptimize(); |
|
55 |
Pair<Object, ? extends Throwable> reflectionResult; |
|
33632 | 56 |
Object[] args = Utils.getNullValues( |
57 |
testCase.executable.getParameterTypes()); |
|
58 |
reflectionResult = testCase.invoke(args); |
|
33160 | 59 |
NMethod nMethod = testCase.compile(); |
60 |
if (nMethod == null) { |
|
61 |
throw new Error(testCase + " : nmethod is null"); |
|
62 |
} |
|
33632 | 63 |
InstalledCode installedCode = testCase.toInstalledCode(); |
33160 | 64 |
Object result = null; |
65 |
Throwable expectedException = reflectionResult.second; |
|
66 |
boolean gotException = true; |
|
67 |
try { |
|
68 |
args = addReceiver(testCase, args); |
|
69 |
result = CompilerToVMHelper.executeInstalledCode( |
|
70 |
args, installedCode); |
|
71 |
if (testCase.executable instanceof Constructor) { |
|
72 |
// <init> doesn't have return value, it changes receiver |
|
73 |
result = args[0]; |
|
74 |
} |
|
75 |
gotException = false; |
|
76 |
} catch (InvalidInstalledCodeException e) { |
|
77 |
throw new AssertionError( |
|
78 |
testCase + " : unexpected InvalidInstalledCodeException", e); |
|
79 |
} catch (Throwable t) { |
|
80 |
if (expectedException == null) { |
|
81 |
throw new AssertionError(testCase |
|
82 |
+ " : got unexpected execption : " + t.getMessage(), t); |
|
83 |
} |
|
84 |
||
85 |
if (expectedException.getClass() != t.getClass()) { |
|
86 |
System.err.println("exception from CompilerToVM:"); |
|
87 |
t.printStackTrace(); |
|
88 |
System.err.println("exception from reflection:"); |
|
89 |
expectedException.printStackTrace(); |
|
90 |
throw new AssertionError(String.format( |
|
91 |
"%s : got unexpected different exceptions : %s != %s", |
|
92 |
testCase, expectedException.getClass(), t.getClass())); |
|
93 |
} |
|
94 |
} |
|
95 |
||
96 |
Asserts.assertEQ(reflectionResult.first, result, testCase |
|
97 |
+ " : different return value"); |
|
98 |
if (!gotException) { |
|
99 |
Asserts.assertNull(expectedException, testCase |
|
100 |
+ " : expected exception hasn't been thrown"); |
|
101 |
} |
|
102 |
} |
|
103 |
||
104 |
private Object[] addReceiver(CompileCodeTestCase testCase, Object[] args) { |
|
105 |
if (!Modifier.isStatic(testCase.executable.getModifiers())) { |
|
106 |
// add instance as 0th arg |
|
107 |
Object[] newArgs = new Object[args.length + 1]; |
|
33632 | 108 |
newArgs[0] = testCase.receiver; |
33160 | 109 |
System.arraycopy(args, 0, newArgs, 1, args.length); |
110 |
args = newArgs; |
|
111 |
} |
|
112 |
return args; |
|
113 |
} |
|
114 |
} |