|
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 /** |
|
26 * @test |
|
27 * @bug 8136421 |
|
28 * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9") & os.arch != "aarch64" |
|
29 * @library /testlibrary /../../test/lib / |
|
30 * @clean compiler.jvmci.compilerToVM.* |
|
31 * @compile -g DummyInterface.java |
|
32 * @compile -g DummyAbstractClass.java |
|
33 * @compile -g DummyClass.java |
|
34 * @compile ../common/CompilerToVMHelper.java |
|
35 * @run main ClassFileInstaller jdk.vm.ci.hotspot.CompilerToVMHelper |
|
36 * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI |
|
37 * -Xbootclasspath/a:. |
|
38 * compiler.jvmci.compilerToVM.GetLocalVariableTableTest |
|
39 * @clean compiler.jvmci.compilerToVM.* |
|
40 */ |
|
41 |
|
42 package compiler.jvmci.compilerToVM; |
|
43 |
|
44 import compiler.jvmci.common.CTVMUtilities; |
|
45 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl; |
|
46 import jdk.vm.ci.hotspot.CompilerToVMHelper; |
|
47 import jdk.test.lib.Asserts; |
|
48 |
|
49 import java.lang.reflect.Executable; |
|
50 import java.util.HashMap; |
|
51 import java.util.Map; |
|
52 |
|
53 public class GetLocalVariableTableTest { |
|
54 |
|
55 public static final int MAIN_LOCALS_COUNT = 0; |
|
56 public static final int INSTANCE_LOCALS_COUNT = 4; |
|
57 public static final int EMPTY_INSTANCE_COUNT = 1; |
|
58 public static final int EMPTY_STATIC_COUNT = 0; |
|
59 public static final int ABSTRACT_INHERIT_LOCALS_COUNT = 2; |
|
60 public static final int DEFAULTFUNC_LOCALS_COUNT = 4; |
|
61 |
|
62 public static void main(String[] args) { |
|
63 Map<Executable, Integer> testCases = createTestCases(); |
|
64 testCases.forEach(GetLocalVariableTableTest::runSanityTest); |
|
65 } |
|
66 |
|
67 private static Map<Executable, Integer> createTestCases() { |
|
68 HashMap<Executable, Integer> methods = new HashMap<>(); |
|
69 try { |
|
70 Class<?> aClass; |
|
71 |
|
72 aClass = GetLocalVariableTableTest.class; |
|
73 methods.put(aClass.getDeclaredMethod("main", String[].class), |
|
74 MAIN_LOCALS_COUNT); |
|
75 |
|
76 aClass = DummyClass.class; |
|
77 methods.put(aClass.getMethod("dummyInstanceFunction"), |
|
78 INSTANCE_LOCALS_COUNT); |
|
79 methods.put(aClass.getMethod("dummyEmptyInstanceFunction"), |
|
80 EMPTY_INSTANCE_COUNT); |
|
81 methods.put(aClass.getMethod("dummyEmptyStaticFunction"), |
|
82 EMPTY_STATIC_COUNT); |
|
83 methods.put(aClass.getMethod("dummyFunction"), |
|
84 EMPTY_INSTANCE_COUNT); |
|
85 methods.put(aClass.getMethod("dummyAbstractFunction"), |
|
86 ABSTRACT_INHERIT_LOCALS_COUNT); |
|
87 |
|
88 aClass = DummyInterface.class; |
|
89 methods.put(aClass.getMethod("dummyFunction"), EMPTY_STATIC_COUNT); |
|
90 methods.put(aClass.getMethod("dummyDefaultFunction", int.class, |
|
91 int.class), DEFAULTFUNC_LOCALS_COUNT); |
|
92 |
|
93 aClass = DummyAbstractClass.class; |
|
94 methods.put(aClass.getMethod("dummyAbstractFunction"), 0); |
|
95 } catch (NoSuchMethodException e) { |
|
96 throw new Error("TEST BUG", e); |
|
97 } |
|
98 return methods; |
|
99 } |
|
100 |
|
101 private static void runSanityTest(Executable aMethod, |
|
102 Integer expectedTableLength) { |
|
103 HotSpotResolvedJavaMethodImpl method = CTVMUtilities |
|
104 .getResolvedMethod(aMethod); |
|
105 |
|
106 int tblLength = CompilerToVMHelper.getLocalVariableTableLength(method); |
|
107 Asserts.assertEQ(tblLength, expectedTableLength, aMethod + " : incorrect " |
|
108 + "local variable table length."); |
|
109 |
|
110 long tblStart = CompilerToVMHelper.getLocalVariableTableStart(method); |
|
111 if (tblLength > 0) { |
|
112 Asserts.assertNE(tblStart, 0L, aMethod + " : local variable table starts" |
|
113 + " at 0 with length " + tblLength); |
|
114 } |
|
115 } |
|
116 } |