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