-
Notifications
You must be signed in to change notification settings - Fork 751
/
Copy pathJ9UnresolvedDataSnippet.cpp
204 lines (182 loc) · 7.33 KB
/
J9UnresolvedDataSnippet.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*******************************************************************************
* Copyright IBM Corp. and others 2019
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] https://openjdk.org/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/
#include "codegen/ARM64Instruction.hpp"
#include "codegen/CodeGenerator.hpp"
#include "codegen/MemoryReference.hpp"
#include "codegen/Relocation.hpp"
#include "codegen/UnresolvedDataSnippet.hpp"
#include "compile/Compilation.hpp"
#include "il/StaticSymbol.hpp"
#include "il/Symbol.hpp"
J9::ARM64::UnresolvedDataSnippet::UnresolvedDataSnippet(TR::CodeGenerator *cg, TR::Node *node, TR::SymbolReference *symRef, bool isStore, bool isGCSafePoint)
: J9::UnresolvedDataSnippet(cg, node, symRef, isStore, isGCSafePoint),
_memoryReference(NULL)
{
cg->machine()->setLinkRegisterKilled(true);
}
TR_RuntimeHelper
J9::ARM64::UnresolvedDataSnippet::getHelper()
{
if (getDataSymbol()->getShadowSymbol() != NULL) // instance data
{
if (isUnresolvedStore())
return TR_ARM64interpreterUnresolvedInstanceDataStoreGlue;
else
return TR_ARM64interpreterUnresolvedInstanceDataGlue;
}
else if (getDataSymbol()->isClassObject()) // class object
{
if (getDataSymbol()->addressIsCPIndexOfStatic())
return TR_ARM64interpreterUnresolvedClassGlue2;
else
return TR_ARM64interpreterUnresolvedClassGlue;
}
else if (getDataSymbol()->isConstString()) // const string
{
return TR_ARM64interpreterUnresolvedStringGlue;
}
else if (getDataSymbol()->isConstMethodType())
{
return TR_interpreterUnresolvedMethodTypeGlue;
}
else if (getDataSymbol()->isConstMethodHandle())
{
return TR_interpreterUnresolvedMethodHandleGlue;
}
else if (getDataSymbol()->isCallSiteTableEntry())
{
return TR_interpreterUnresolvedCallSiteTableEntryGlue;
}
else if (getDataSymbol()->isMethodTypeTableEntry())
{
return TR_interpreterUnresolvedMethodTypeTableEntryGlue;
}
else if (getDataSymbol()->isConstantDynamic())
{
return TR_ARM64interpreterUnresolvedConstantDynamicGlue;
}
else // must be static data
{
if (isUnresolvedStore())
return TR_ARM64interpreterUnresolvedStaticDataStoreGlue;
else
return TR_ARM64interpreterUnresolvedStaticDataGlue;
}
}
uint8_t *
J9::ARM64::UnresolvedDataSnippet::emitSnippetBody()
{
uint8_t *cursor = cg()->getBinaryBufferCursor();
TR_RuntimeHelper helper = getHelper();
TR::SymbolReference *glueRef = cg()->symRefTab()->findOrCreateRuntimeHelper(helper);
getSnippetLabel()->setCodeLocation(cursor);
*(int32_t *)cursor = cg()->encodeHelperBranchAndLink(glueRef, cursor, getNode()); // BL resolve
cursor += 4;
*(intptr_t *)cursor = (intptr_t)getAddressOfDataReference(); // Code Cache RA
cg()->addExternalRelocation(
TR::ExternalRelocation::create(
cursor,
NULL,
TR_AbsoluteMethodAddress,
cg()),
__FILE__,
__LINE__,
getNode());
cursor += 8;
if (getDataSymbol()->isCallSiteTableEntry())
{
*(intptr_t *)cursor = getDataSymbol()->castToCallSiteTableEntrySymbol()->getCallSiteIndex();
}
else if (getDataSymbol()->isMethodTypeTableEntry())
{
*(intptr_t *)cursor = getDataSymbol()->castToMethodTypeTableEntrySymbol()->getMethodTypeIndex();
}
else
{
*(intptr_t *)cursor = getDataSymbolReference()->getCPIndex(); // CP index
}
cursor += 8;
*(intptr_t *)cursor = (intptr_t)getDataSymbolReference()->getOwningMethod(cg()->comp())->constantPool(); // CP
cg()->addExternalRelocation(
TR::ExternalRelocation::create(
cursor,
*(uint8_t **)cursor,
getNode() ? (uint8_t *)(intptr_t)getNode()->getInlinedSiteIndex() : (uint8_t *)-1,
TR_ConstantPool,
cg()),
__FILE__,
__LINE__,
getNode());
cursor += 8;
*(int32_t *)cursor = getMemoryReference()->getOffset(); // offset
if (getDataSymbol()->isConstObjectRef())
{
// reset the offset to zero
// the resolve + picbuilder will fully provide the addr to use
*(int32_t *)cursor = 0;
}
cursor += 4;
*(int32_t *)cursor = TR::InstOpCode::getOpCodeBinaryEncoding(TR::InstOpCode::movzx); // instruction template -- "movz extraReg, #0"
TR_ASSERT(getMemoryReference()->getExtraRegister(), "_extraReg must have been allocated");
toRealRegister(getMemoryReference()->getExtraRegister())->setRegisterFieldRD((uint32_t *)cursor);
return cursor+4;
}
void
TR_Debug::print(TR::FILE *pOutFile, TR::UnresolvedDataSnippet * snippet)
{
uint8_t *cursor = snippet->getSnippetLabel()->getCodeLocation();
TR_RuntimeHelper helper = snippet->getHelper();
TR::SymbolReference *glueRef = _cg->getSymRef(helper);
printSnippetLabel(pOutFile, snippet->getSnippetLabel(), cursor, "Unresolved Data Snippet");
char *info = "";
int32_t distance;
if (isBranchToTrampoline(glueRef, cursor, distance))
{
info = " Through Trampoline";
}
printPrefix(pOutFile, NULL, cursor, 4);
distance = *((int32_t *) cursor) & 0x03ffffff; // imm26
distance = (distance << 6) >> 4; // sign extend and add two 0 bits
trfprintf(pOutFile, "bl \t" POINTER_PRINTF_FORMAT "\t\t;%s%s",
(intptr_t)cursor + distance, getRuntimeHelperName(helper), info);
cursor += 4;
printPrefix(pOutFile, NULL, cursor, sizeof(intptr_t));
trfprintf(pOutFile, ".dword \t" POINTER_PRINTF_FORMAT "\t\t; Code cache return address", *(intptr_t *)cursor);
cursor += sizeof(intptr_t);
printPrefix(pOutFile, NULL, cursor, sizeof(intptr_t));
trfprintf(pOutFile, ".dword \t0x%08x\t\t; cpIndex of the data reference", *(intptr_t *)cursor);
cursor += sizeof(intptr_t);
printPrefix(pOutFile, NULL, cursor, sizeof(intptr_t));
trfprintf(pOutFile, ".dword \t" POINTER_PRINTF_FORMAT "\t\t; Constant pool address", *(intptr_t *)cursor);
cursor += sizeof(intptr_t);
printPrefix(pOutFile, NULL, cursor, 4);
trfprintf(pOutFile, ".word \t0x%08x\t\t; Offset to be merged", *(int32_t *)cursor);
cursor += 4;
printPrefix(pOutFile, NULL, cursor, 4);
int32_t instr = *(int32_t *)cursor;
trfprintf(pOutFile, ".word \t0x%08x\t\t; Instruction template (extraReg=x%d)", instr, (instr & 0x1F));
}
uint32_t
J9::ARM64::UnresolvedDataSnippet::getLength(int32_t estimatedSnippetStart)
{
return 9 * 4;
}