author | kvn |
Tue, 04 Jun 2019 12:44:53 -0700 | |
changeset 55206 | 2fe2063fe567 |
parent 52427 | 3c6aa484536c |
permissions | -rw-r--r-- |
33160 | 1 |
/* |
55206 | 2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
33160 | 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 |
|
42607
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41705
diff
changeset
|
27 |
* @requires vm.jvmci |
33160 | 28 |
* @summary Testing compiler.jvmci.CompilerToVM.lookupKlassInPool method |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40059
diff
changeset
|
29 |
* @library /test/lib / |
36508 | 30 |
* @library ../common/patches |
52427
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
47216
diff
changeset
|
31 |
* @modules java.base/jdk.internal.access |
37301
a936b4e01afb
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
36508
diff
changeset
|
32 |
* java.base/jdk.internal.reflect |
36508 | 33 |
* java.base/jdk.internal.org.objectweb.asm |
34 |
* java.base/jdk.internal.org.objectweb.asm.tree |
|
43972 | 35 |
* jdk.internal.vm.ci/jdk.vm.ci.hotspot |
36 |
* jdk.internal.vm.ci/jdk.vm.ci.runtime |
|
37 |
* jdk.internal.vm.ci/jdk.vm.ci.meta |
|
40053
b3617982544e
8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents:
39450
diff
changeset
|
38 |
* |
43972 | 39 |
* @build jdk.internal.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:
39450
diff
changeset
|
40 |
* @run driver ClassFileInstaller sun.hotspot.WhiteBox |
b3617982544e
8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents:
39450
diff
changeset
|
41 |
* sun.hotspot.WhiteBox$WhiteBoxPermission |
36508 | 42 |
* @run main/othervm -Xbootclasspath/a:. |
43 |
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI |
|
44 |
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI |
|
55206 | 45 |
* -XX:-UseJVMCICompiler |
36508 | 46 |
* compiler.jvmci.compilerToVM.LookupKlassInPoolTest |
33160 | 47 |
*/ |
48 |
||
49 |
package compiler.jvmci.compilerToVM; |
|
50 |
||
36305
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
51 |
import compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes; |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
52 |
import compiler.jvmci.compilerToVM.ConstantPoolTestCase.TestedCPEntry; |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
53 |
import compiler.jvmci.compilerToVM.ConstantPoolTestCase.Validator; |
40059 | 54 |
import compiler.jvmci.compilerToVM.ConstantPoolTestsHelper.DummyClasses; |
33160 | 55 |
import jdk.vm.ci.hotspot.CompilerToVMHelper; |
33632 | 56 |
import jdk.vm.ci.hotspot.HotSpotResolvedObjectType; |
36305
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
57 |
import jdk.vm.ci.meta.ConstantPool; |
33160 | 58 |
|
40059 | 59 |
import java.util.HashMap; |
60 |
import java.util.Map; |
|
61 |
||
62 |
import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.CONSTANT_CLASS; |
|
63 |
||
33160 | 64 |
/** |
36305
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
65 |
* Test for {@code jdk.vm.ci.hotspot.CompilerToVM.lookupKlassInPool} method |
33160 | 66 |
*/ |
67 |
public class LookupKlassInPoolTest { |
|
68 |
||
36305
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
69 |
public static void main(String[] args) throws Exception { |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
70 |
Map<ConstantTypes, Validator> typeTests = new HashMap<>(); |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
71 |
typeTests.put(CONSTANT_CLASS, LookupKlassInPoolTest::validate); |
33160 | 72 |
ConstantPoolTestCase testCase = new ConstantPoolTestCase(typeTests); |
73 |
testCase.test(); |
|
36305
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
74 |
// The next "Class.forName" and repeating "testCase.test()" |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
75 |
// are here for the following reason. |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
76 |
// The first test run is without dummy class initialization, |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
77 |
// which means no constant pool cache exists. |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
78 |
// The second run is with initialized class (with constant pool cache available). |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
79 |
// Some CompilerToVM methods require different input |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
80 |
// depending on whether CP cache exists or not. |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
81 |
for (DummyClasses dummy : DummyClasses.values()) { |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
82 |
Class.forName(dummy.klass.getName()); |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
83 |
} |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
84 |
testCase.test(); |
33160 | 85 |
} |
86 |
||
36305
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
87 |
public static void validate(ConstantPool constantPoolCTVM, |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
88 |
ConstantTypes cpType, |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
89 |
DummyClasses dummyClass, |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
90 |
int i) { |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
91 |
TestedCPEntry entry = cpType.getTestedCPEntry(dummyClass, i); |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
92 |
if (entry == null) { |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
93 |
return; |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
94 |
} |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
95 |
Object classToVerify = CompilerToVMHelper.lookupKlassInPool(constantPoolCTVM, i); |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
96 |
if (!(classToVerify instanceof HotSpotResolvedObjectType) && !(classToVerify instanceof String)) { |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
97 |
String msg = String.format("Output of method CTVM.lookupKlassInPool is neither" |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
98 |
+ " a HotSpotResolvedObjectType, nor a String"); |
33160 | 99 |
throw new AssertionError(msg); |
100 |
} |
|
36305
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
101 |
String classNameToRefer = entry.klass; |
33160 | 102 |
String outputToVerify = classToVerify.toString(); |
103 |
if (!outputToVerify.contains(classNameToRefer)) { |
|
36305
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
104 |
String msg = String.format("Wrong class accessed by constant pool index %d: %s, but should be %s", |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
105 |
i, |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
106 |
outputToVerify, |
55c7fe59d6d7
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents:
35148
diff
changeset
|
107 |
classNameToRefer); |
33160 | 108 |
throw new AssertionError(msg); |
109 |
} |
|
110 |
} |
|
111 |
} |