42650
|
1 |
/*
|
|
2 |
* Copyright (c) 2016, 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 |
package jdk.tools.jaotc;
|
|
25 |
|
|
26 |
import jdk.tools.jaotc.binformat.BinaryContainer;
|
|
27 |
import jdk.tools.jaotc.binformat.Symbol;
|
|
28 |
import jdk.tools.jaotc.CompiledMethodInfo.StubInformation;
|
|
29 |
|
|
30 |
import jdk.vm.ci.code.site.Call;
|
|
31 |
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* Symbol for a regular Java call. This method also creates additional relocations for {@code .plt}
|
|
35 |
* to {@code .got} and {@code .got} to {@code .plt}.
|
|
36 |
*/
|
|
37 |
final class JavaCallSiteRelocationSymbol extends CallSiteRelocationSymbol {
|
|
38 |
|
|
39 |
private static final byte[] zeroSlot = new byte[8];
|
|
40 |
private static final byte[] minusOneSlot = {-1, -1, -1, -1, -1, -1, -1, -1};
|
|
41 |
|
|
42 |
public JavaCallSiteRelocationSymbol(CompiledMethodInfo mi, Call call, CallSiteRelocationInfo callSiteRelocation, BinaryContainer binaryContainer) {
|
|
43 |
super(createPltEntrySymbol(binaryContainer, mi, call, callSiteRelocation));
|
|
44 |
StubInformation stub = getStub(mi, call);
|
|
45 |
addRelocations(mi, stub, binaryContainer, call, callSiteRelocation);
|
|
46 |
}
|
|
47 |
|
|
48 |
/**
|
|
49 |
* Returns a unique symbol name with the {@code suffix} appended.
|
|
50 |
*/
|
|
51 |
private static String relocationSymbolName(String suffix, CompiledMethodInfo mi, Call call, CallSiteRelocationInfo callSiteRelocation) {
|
|
52 |
return "M" + mi.getCodeId() + "_" + call.pcOffset + "_" + callSiteRelocation.targetSymbol + "_" + suffix;
|
|
53 |
}
|
|
54 |
|
|
55 |
private static Symbol createPltEntrySymbol(BinaryContainer binaryContainer, CompiledMethodInfo mi, Call call, CallSiteRelocationInfo callSiteRelocation) {
|
|
56 |
String symbolName = relocationSymbolName("plt.entry", mi, call, callSiteRelocation);
|
|
57 |
StubInformation stub = getStub(mi, call);
|
|
58 |
return createCodeContainerSymbol(binaryContainer, symbolName, stub.getOffset());
|
|
59 |
}
|
|
60 |
|
|
61 |
private static StubInformation getStub(CompiledMethodInfo mi, Call call) {
|
|
62 |
HotSpotResolvedJavaMethod callTarget = (HotSpotResolvedJavaMethod) call.target;
|
|
63 |
String callTargetSymbol = MiscUtils.uniqueMethodName(callTarget) + ".at." + call.pcOffset;
|
|
64 |
return mi.getStubFor(callTargetSymbol);
|
|
65 |
}
|
|
66 |
|
|
67 |
/**
|
|
68 |
* Add all the required relocations.
|
|
69 |
*/
|
|
70 |
private static void addRelocations(CompiledMethodInfo mi, StubInformation stub, BinaryContainer binaryContainer, Call call, CallSiteRelocationInfo callSiteRelocation) {
|
|
71 |
final boolean isVirtualCall = MiscUtils.isVirtualCall(mi, call);
|
|
72 |
|
|
73 |
final int gotStartOffset = binaryContainer.appendExtLinkageGotBytes(zeroSlot, 0, zeroSlot.length);
|
|
74 |
if (isVirtualCall) {
|
|
75 |
// Nothing.
|
|
76 |
} else {
|
|
77 |
// For c2i stub we need slot with -1 value.
|
|
78 |
binaryContainer.appendExtLinkageGotBytes(minusOneSlot, 0, minusOneSlot.length);
|
|
79 |
}
|
|
80 |
|
|
81 |
// Add relocation to GOT cell for call resolution jump.
|
|
82 |
String gotSymbolName = "got." + getResolveSymbolName(binaryContainer, mi, call);
|
|
83 |
Symbol gotSymbol = binaryContainer.getGotSymbol(gotSymbolName);
|
|
84 |
addExternalPltToGotRelocation(binaryContainer, gotSymbol, stub.getResolveJumpOffset());
|
|
85 |
|
|
86 |
// Add relocation to resolve call jump instruction address for GOT cell.
|
|
87 |
String pltJmpSymbolName = relocationSymbolName("plt.jmp", mi, call, callSiteRelocation);
|
|
88 |
addCodeContainerRelocation(binaryContainer, pltJmpSymbolName, stub.getResolveJumpStart(), gotStartOffset);
|
|
89 |
|
|
90 |
// Add relocation to GOT cell for dispatch jump.
|
|
91 |
String gotEntrySymbolName = relocationSymbolName("got.entry", mi, call, callSiteRelocation);
|
|
92 |
addExtLinkageGotContainerRelocation(binaryContainer, gotEntrySymbolName, gotStartOffset, stub.getDispatchJumpOffset());
|
|
93 |
|
43461
|
94 |
// Virtual call needs initial -1 value.
|
42650
|
95 |
byte[] slot = isVirtualCall ? minusOneSlot : zeroSlot;
|
43461
|
96 |
final int gotMetaOffset = binaryContainer.appendMetaspaceGotBytes(slot, 0, slot.length);
|
42650
|
97 |
|
|
98 |
// Add relocation to GOT cell for move instruction (Klass* for virtual, Method* otherwise).
|
|
99 |
String gotMoveSymbolName = relocationSymbolName("got.move", mi, call, callSiteRelocation);
|
43461
|
100 |
addMetaspaceGotRelocation(binaryContainer, gotMoveSymbolName, gotMetaOffset, stub.getMovOffset());
|
42650
|
101 |
|
|
102 |
if (isVirtualCall) {
|
|
103 |
// Nothing.
|
|
104 |
} else {
|
|
105 |
// Add relocation to GOT cell for c2i adapter jump.
|
|
106 |
String gotC2ISymbolName = relocationSymbolName("got.c2i", mi, call, callSiteRelocation);
|
|
107 |
addExtLinkageGotContainerRelocation(binaryContainer, gotC2ISymbolName, gotStartOffset + 8, stub.getC2IJumpOffset());
|
|
108 |
}
|
|
109 |
}
|
|
110 |
|
|
111 |
/**
|
|
112 |
* Returns the name of the resolve method for this particular call.
|
|
113 |
*/
|
|
114 |
private static String getResolveSymbolName(BinaryContainer binaryContainer, CompiledMethodInfo mi, Call call) {
|
|
115 |
String resolveSymbolName;
|
|
116 |
if (MiscUtils.isStaticCall(call)) {
|
|
117 |
resolveSymbolName = binaryContainer.getResolveStaticEntrySymbolName();
|
|
118 |
} else if (MiscUtils.isSpecialCall(call)) {
|
|
119 |
resolveSymbolName = binaryContainer.getResolveOptVirtualEntrySymbolName();
|
|
120 |
} else if (MiscUtils.isOptVirtualCall(mi, call)) {
|
|
121 |
resolveSymbolName = binaryContainer.getResolveOptVirtualEntrySymbolName();
|
|
122 |
} else if (MiscUtils.isVirtualCall(mi, call)) {
|
|
123 |
resolveSymbolName = binaryContainer.getResolveVirtualEntrySymbolName();
|
|
124 |
} else {
|
|
125 |
throw new InternalError("Unknown call type in " + mi.asTag() + " @ " + call.pcOffset + " for call" + call.target);
|
|
126 |
}
|
|
127 |
return resolveSymbolName;
|
|
128 |
}
|
|
129 |
|
|
130 |
}
|