author | kshefov |
Sat, 20 Feb 2016 11:49:45 +0300 | |
changeset 36306 | 9b8ba80e9327 |
child 36508 | 5f9eee6b383b |
permissions | -rw-r--r-- |
36306
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
1 |
/* |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
4 |
* |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
8 |
* |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
13 |
* accompanied this code). |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
14 |
* |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
18 |
* |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
21 |
* questions. |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
22 |
* |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
23 |
*/ |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
24 |
|
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
25 |
/* |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
26 |
* @test |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
27 |
* @bug 8138708 |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
28 |
* @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64") |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
29 |
* @library /testlibrary /test/lib / |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
30 |
* @compile ../common/CompilerToVMHelper.java |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
31 |
* @build sun.hotspot.WhiteBox |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
32 |
* compiler.jvmci.compilerToVM.ResolvePossiblyCachedConstantInPoolTest |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
33 |
* @run main ClassFileInstaller sun.hotspot.WhiteBox |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
34 |
* sun.hotspot.WhiteBox$WhiteBoxPermission |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
35 |
* jdk.vm.ci.hotspot.CompilerToVMHelper |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
36 |
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
37 |
* -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
38 |
* compiler.jvmci.compilerToVM.ResolvePossiblyCachedConstantInPoolTest |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
39 |
*/ |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
40 |
|
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
41 |
package compiler.jvmci.compilerToVM; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
42 |
|
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
43 |
import compiler.jvmci.compilerToVM.ConstantPoolTestsHelper.DummyClasses; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
44 |
import compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
45 |
import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.*; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
46 |
import compiler.jvmci.compilerToVM.ConstantPoolTestCase.TestedCPEntry; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
47 |
import compiler.jvmci.compilerToVM.ConstantPoolTestCase.Validator; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
48 |
import java.util.HashMap; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
49 |
import java.util.Map; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
50 |
import jdk.test.lib.Asserts; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
51 |
import jdk.vm.ci.hotspot.CompilerToVMHelper; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
52 |
import jdk.vm.ci.meta.ConstantPool; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
53 |
|
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
54 |
/** |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
55 |
* Test for {@code jdk.vm.ci.hotspot.CompilerToVM.resolvePossiblyCachedConstantInPool} method |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
56 |
*/ |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
57 |
public class ResolvePossiblyCachedConstantInPoolTest { |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
58 |
|
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
59 |
public static void main(String[] args) throws Exception { |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
60 |
Map<ConstantTypes, Validator> typeTests = new HashMap<>(); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
61 |
typeTests.put(CONSTANT_STRING, ResolvePossiblyCachedConstantInPoolTest::validateString); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
62 |
ConstantPoolTestCase testCase = new ConstantPoolTestCase(typeTests); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
63 |
// The next "Class.forName" is here for the following reason. |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
64 |
// When class is initialized, constant pool cache is available. |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
65 |
// This method works only with cached constant pool. |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
66 |
for (DummyClasses dummy : DummyClasses.values()) { |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
67 |
Class.forName(dummy.klass.getName()); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
68 |
} |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
69 |
testCase.test(); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
70 |
} |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
71 |
|
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
72 |
private static void validateString(ConstantPool constantPoolCTVM, |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
73 |
ConstantTypes cpType, |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
74 |
DummyClasses dummyClass, |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
75 |
int cpi) { |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
76 |
TestedCPEntry entry = cpType.getTestedCPEntry(dummyClass, cpi); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
77 |
if (entry == null) { |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
78 |
return; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
79 |
} |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
80 |
int index = cpi; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
81 |
String cached = ""; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
82 |
int cpci = dummyClass.getCPCacheIndex(cpi); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
83 |
if (cpci != ConstantPoolTestsHelper.NO_CP_CACHE_PRESENT) { |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
84 |
index = cpci; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
85 |
cached = "cached "; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
86 |
} |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
87 |
Object constantInPool = CompilerToVMHelper.resolvePossiblyCachedConstantInPool(constantPoolCTVM, index); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
88 |
String stringToVerify = (String) constantInPool; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
89 |
String stringToRefer = entry.name; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
90 |
if (stringToRefer.equals("") && cpci != ConstantPoolTestsHelper.NO_CP_CACHE_PRESENT) { |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
91 |
stringToRefer = null; // tested method returns null for cached empty strings |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
92 |
} |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
93 |
String msg = String.format("Wrong string accessed by %sconstant pool index %d", cached, index); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
94 |
Asserts.assertEQ(stringToRefer, stringToVerify, msg); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
95 |
} |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
96 |
} |