author | kvn |
Tue, 29 Oct 2019 15:35:06 -0700 | |
changeset 58851 | f1e6442241ca |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
35137
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
1 |
/* |
58851 | 2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
35137
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
4 |
* |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
8 |
* |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
13 |
* accompanied this code). |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
14 |
* |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
18 |
* |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
21 |
* questions. |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
22 |
*/ |
38027
8a5693d27400
8153439: do not install an empty SpeculationLog in an nmethod
dnsimon
parents:
35137
diff
changeset
|
23 |
package jdk.vm.ci.code.test; |
35137
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
24 |
|
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
25 |
import jdk.vm.ci.code.BytecodeFrame; |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
26 |
import jdk.vm.ci.code.DebugInfo; |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
27 |
import jdk.vm.ci.code.Location; |
43478
72039e58b2a8
8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java
never
parents:
40059
diff
changeset
|
28 |
import jdk.vm.ci.code.RegisterValue; |
72039e58b2a8
8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java
never
parents:
40059
diff
changeset
|
29 |
import jdk.vm.ci.code.StackSlot; |
35137
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
30 |
import jdk.vm.ci.code.VirtualObject; |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
31 |
import jdk.vm.ci.hotspot.HotSpotReferenceMap; |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
32 |
import jdk.vm.ci.meta.JavaKind; |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
33 |
import jdk.vm.ci.meta.JavaValue; |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
34 |
import jdk.vm.ci.meta.ResolvedJavaMethod; |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
35 |
|
40059 | 36 |
import java.lang.reflect.Method; |
43478
72039e58b2a8
8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java
never
parents:
40059
diff
changeset
|
37 |
import java.util.ArrayList; |
72039e58b2a8
8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java
never
parents:
40059
diff
changeset
|
38 |
import java.util.Arrays; |
72039e58b2a8
8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java
never
parents:
40059
diff
changeset
|
39 |
import java.util.List; |
40059 | 40 |
|
35137
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
41 |
/** |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
42 |
* Test code installation with debug information. |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
43 |
*/ |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
44 |
public class DebugInfoTest extends CodeInstallationTest { |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
45 |
|
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
46 |
protected interface DebugInfoCompiler { |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
47 |
|
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
48 |
VirtualObject[] compile(TestAssembler asm, JavaValue[] frameValues); |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
49 |
} |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
50 |
|
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
51 |
protected void test(DebugInfoCompiler compiler, Method method, int bci, JavaKind... slotKinds) { |
39441
7464b1552bf7
8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents:
38027
diff
changeset
|
52 |
test(compiler, method, bci, new Location[0], new Location[0], new int[0], slotKinds); |
7464b1552bf7
8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents:
38027
diff
changeset
|
53 |
} |
7464b1552bf7
8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents:
38027
diff
changeset
|
54 |
|
7464b1552bf7
8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents:
38027
diff
changeset
|
55 |
protected void test(DebugInfoCompiler compiler, Method method, int bci, Location[] objects, Location[] derivedBase, int[] sizeInBytes, JavaKind... slotKinds) { |
35137
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
56 |
ResolvedJavaMethod resolvedMethod = metaAccess.lookupJavaMethod(method); |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
57 |
|
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
58 |
int numLocals = resolvedMethod.getMaxLocals(); |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
59 |
int numStack = slotKinds.length - numLocals; |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
60 |
JavaValue[] values = new JavaValue[slotKinds.length]; |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
61 |
test(asm -> { |
43478
72039e58b2a8
8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java
never
parents:
40059
diff
changeset
|
62 |
/* |
72039e58b2a8
8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java
never
parents:
40059
diff
changeset
|
63 |
* Ensure that any objects mentioned in the VirtualObjects are also in the OopMap. |
72039e58b2a8
8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java
never
parents:
40059
diff
changeset
|
64 |
*/ |
58851 | 65 |
List<Location> newLocations = new ArrayList<>(Arrays.asList(objects)); |
66 |
List<Location> newDerived = new ArrayList<>(Arrays.asList(derivedBase)); |
|
43478
72039e58b2a8
8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java
never
parents:
40059
diff
changeset
|
67 |
int[] newSizeInBytes = sizeInBytes; |
35137
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
68 |
VirtualObject[] vobjs = compiler.compile(asm, values); |
43478
72039e58b2a8
8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java
never
parents:
40059
diff
changeset
|
69 |
if (vobjs != null) { |
72039e58b2a8
8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java
never
parents:
40059
diff
changeset
|
70 |
for (VirtualObject obj : vobjs) { |
72039e58b2a8
8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java
never
parents:
40059
diff
changeset
|
71 |
JavaValue[] objValues = obj.getValues(); |
72039e58b2a8
8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java
never
parents:
40059
diff
changeset
|
72 |
for (int i = 0; i < objValues.length; i++) { |
58851 | 73 |
if (obj.getSlotKind(i) == JavaKind.Object) { |
74 |
Location oopLocation = null; |
|
75 |
int bytes = -1; |
|
76 |
if (objValues[i] instanceof RegisterValue) { |
|
77 |
RegisterValue reg = (RegisterValue) objValues[i]; |
|
78 |
oopLocation = Location.register(reg.getRegister()); |
|
79 |
bytes = reg.getValueKind().getPlatformKind().getSizeInBytes(); |
|
80 |
} else if (objValues[i] instanceof StackSlot) { |
|
81 |
StackSlot slot = (StackSlot) objValues[i]; |
|
82 |
oopLocation = Location.stack(asm.getOffset(slot)); |
|
83 |
bytes = slot.getValueKind().getPlatformKind().getSizeInBytes(); |
|
84 |
} |
|
85 |
if (oopLocation != null && !newLocations.contains(oopLocation)) { |
|
86 |
newLocations.add(oopLocation); |
|
87 |
newDerived.add(null); |
|
88 |
newSizeInBytes = Arrays.copyOf(newSizeInBytes, newSizeInBytes.length + 1); |
|
89 |
newSizeInBytes[newSizeInBytes.length - 1] = bytes; |
|
90 |
} |
|
43478
72039e58b2a8
8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java
never
parents:
40059
diff
changeset
|
91 |
} |
72039e58b2a8
8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java
never
parents:
40059
diff
changeset
|
92 |
} |
72039e58b2a8
8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java
never
parents:
40059
diff
changeset
|
93 |
} |
72039e58b2a8
8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java
never
parents:
40059
diff
changeset
|
94 |
} |
35137
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
95 |
|
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
96 |
BytecodeFrame frame = new BytecodeFrame(null, resolvedMethod, bci, false, false, values, slotKinds, numLocals, numStack, 0); |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
97 |
DebugInfo info = new DebugInfo(frame, vobjs); |
43478
72039e58b2a8
8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java
never
parents:
40059
diff
changeset
|
98 |
info.setReferenceMap(new HotSpotReferenceMap(newLocations.toArray(new Location[0]), newDerived.toArray(new Location[0]), newSizeInBytes, 8)); |
35137
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
99 |
|
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
100 |
asm.emitTrap(info); |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
101 |
}, method); |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
102 |
} |
c8f8f6de68a7
8144704: [JVMCI] add tests for simple code installation
rschatz
parents:
diff
changeset
|
103 |
} |