Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/arm/codegen/J9AheadOfTimeCompile.cpp
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 2021 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/AheadOfTimeCompile.hpp"
24
#include "codegen/ARMAOTRelocation.hpp"
25
#include "compile/SymbolReferenceTable.hpp"
26
#include "codegen/CodeGenerator.hpp"
27
#include "env/FrontEnd.hpp"
28
#include "codegen/Instruction.hpp"
29
#include "compile/AOTClassInfo.hpp"
30
#include "compile/Compilation.hpp"
31
#include "compile/ResolvedMethod.hpp"
32
#include "compile/VirtualGuard.hpp"
33
#include "env/CHTable.hpp"
34
#include "env/ClassLoaderTable.hpp"
35
#include "env/SharedCache.hpp"
36
#include "env/jittypes.h"
37
#include "env/VMJ9.h"
38
#include "il/LabelSymbol.hpp"
39
#include "il/Node.hpp"
40
#include "il/Node_inlines.hpp"
41
#include "il/StaticSymbol.hpp"
42
#include "il/SymbolReference.hpp"
43
#include "runtime/RelocationRuntime.hpp"
44
#include "runtime/RelocationRecord.hpp"
45
46
#define NON_HELPER 0
47
48
J9::ARM::AheadOfTimeCompile::AheadOfTimeCompile(TR::CodeGenerator *cg)
49
: J9::AheadOfTimeCompile(NULL, cg->comp()),
50
_cg(cg),
51
_relocationList(self()->trMemory())
52
{
53
}
54
55
void J9::ARM::AheadOfTimeCompile::processRelocations()
56
{
57
TR_J9VMBase *fej9 = (TR_J9VMBase *)(self()->cg()->fe());
58
ListIterator<TR::ARMRelocation> iterator(&self()->getRelocationList());
59
TR::ARMRelocation *relocation;
60
TR::IteratedExternalRelocation *r;
61
62
for (relocation=iterator.getFirst();
63
relocation!=NULL;
64
relocation=iterator.getNext())
65
{
66
relocation->mapRelocation(self()->cg());
67
}
68
69
for (auto aotIterator = self()->cg()->getExternalRelocationList().begin(); aotIterator != self()->cg()->getExternalRelocationList().end(); ++aotIterator)
70
{
71
(*aotIterator)->addExternalRelocation(self()->cg());
72
}
73
74
for (r = self()->getAOTRelocationTargets().getFirst();
75
r != NULL;
76
r = r->getNext())
77
{
78
self()->addToSizeOfAOTRelocations(r->getSizeOfRelocationData());
79
}
80
81
// now allocate the memory size of all iterated relocations + the header (total length field)
82
83
if (self()->getSizeOfAOTRelocations() != 0)
84
{
85
uint8_t *relocationDataCursor = self()->setRelocationData(fej9->allocateRelocationData(self()->comp(), self()->getSizeOfAOTRelocations() + 4));
86
87
// set up the size for the region
88
*(uint32_t *)relocationDataCursor = self()->getSizeOfAOTRelocations() + 4;
89
relocationDataCursor += 4;
90
91
// set up pointers for each iterated relocation and initialize header
92
TR::IteratedExternalRelocation *s;
93
for (s = self()->getAOTRelocationTargets().getFirst();
94
s != NULL;
95
s = s->getNext())
96
{
97
s->setRelocationData(relocationDataCursor);
98
s->initializeRelocation(_cg);
99
relocationDataCursor += s->getSizeOfRelocationData();
100
}
101
}
102
}
103
104
bool
105
J9::ARM::AheadOfTimeCompile::initializePlatformSpecificAOTRelocationHeader(TR::IteratedExternalRelocation *relocation,
106
TR_RelocationTarget *reloTarget,
107
TR_RelocationRecord *reloRecord,
108
uint8_t targetKind)
109
{
110
bool platformSpecificReloInitialized = true;
111
TR::Compilation* comp = self()->comp();
112
TR_J9VMBase *fej9 = comp->fej9();
113
TR_SharedCache *sharedCache = fej9->sharedCache();
114
uint8_t * aotMethodCodeStart = (uint8_t *) comp->getRelocatableMethodCodeStart();
115
116
switch (targetKind)
117
{
118
case TR_MethodObject:
119
{
120
TR_RelocationRecordMethodObject *moRecord = reinterpret_cast<TR_RelocationRecordMethodObject *>(reloRecord);
121
TR_RelocationRecordInformation *recordInfo = (TR_RelocationRecordInformation*) relocation->getTargetAddress();
122
123
TR::SymbolReference *symRef = reinterpret_cast<TR::SymbolReference *>(recordInfo->data1);
124
uintptr_t inlinedSiteIndex = self()->findCorrectInlinedSiteIndex(symRef->getOwningMethod(comp)->constantPool(), recordInfo->data2);
125
uint8_t flags = static_cast<uint8_t>(reinterpret_cast<uintptr_t>(recordInfo->data3));
126
127
TR_ASSERT((flags & RELOCATION_CROSS_PLATFORM_FLAGS_MASK) == 0, "reloFlags bits overlap cross-platform flags bits\n");
128
129
moRecord->setInlinedSiteIndex(reloTarget, reinterpret_cast<uintptr_t>(inlinedSiteIndex));
130
moRecord->setConstantPool(reloTarget, reinterpret_cast<uintptr_t>(symRef->getOwningMethod(comp)->constantPool()));
131
moRecord->setReloFlags(reloTarget, flags);
132
}
133
break;
134
135
case TR_ClassAddress:
136
{
137
TR_RelocationRecordClassAddress *caRecord = reinterpret_cast<TR_RelocationRecordClassAddress *>(reloRecord);
138
TR_RelocationRecordInformation *recordInfo = (TR_RelocationRecordInformation*) relocation->getTargetAddress();
139
140
TR::SymbolReference *symRef = reinterpret_cast<TR::SymbolReference *>(recordInfo->data1);
141
uintptr_t inlinedSiteIndex = reinterpret_cast<uintptr_t>(recordInfo->data2);
142
uint8_t flags = static_cast<uint8_t>(recordInfo->data3);
143
144
void *constantPool = symRef->getOwningMethod(comp)->constantPool();
145
inlinedSiteIndex = self()->findCorrectInlinedSiteIndex(constantPool, inlinedSiteIndex);
146
147
TR_ASSERT((flags & RELOCATION_CROSS_PLATFORM_FLAGS_MASK) == 0, "reloFlags bits overlap cross-platform flags bits\n");
148
caRecord->setReloFlags(reloTarget, flags);
149
caRecord->setInlinedSiteIndex(reloTarget, inlinedSiteIndex);
150
caRecord->setConstantPool(reloTarget, reinterpret_cast<uintptr_t>(constantPool));
151
caRecord->setCpIndex(reloTarget, symRef->getCPIndex());
152
}
153
break;
154
155
case TR_DataAddress:
156
{
157
TR_RelocationRecordDataAddress *daRecord = reinterpret_cast<TR_RelocationRecordDataAddress *>(reloRecord);
158
TR_RelocationRecordInformation *recordInfo = (TR_RelocationRecordInformation*) relocation->getTargetAddress();
159
160
TR::SymbolReference *symRef = reinterpret_cast<TR::SymbolReference *>(recordInfo->data1);
161
uintptr_t inlinedSiteIndex = reinterpret_cast<uintptr_t>(recordInfo->data2);
162
uint8_t flags = static_cast<uint8_t>(reinterpret_cast<uintptr_t>(recordInfo->data3));
163
164
void *constantPool = symRef->getOwningMethod(comp)->constantPool();
165
inlinedSiteIndex = self()->findCorrectInlinedSiteIndex(constantPool, inlinedSiteIndex);
166
167
TR_ASSERT((flags & RELOCATION_CROSS_PLATFORM_FLAGS_MASK) == 0, "reloFlags bits overlap cross-platform flags bits\n");
168
daRecord->setReloFlags(reloTarget, flags);
169
daRecord->setInlinedSiteIndex(reloTarget, inlinedSiteIndex);
170
daRecord->setConstantPool(reloTarget, reinterpret_cast<uintptr_t>(constantPool));
171
daRecord->setCpIndex(reloTarget, symRef->getCPIndex());
172
daRecord->setOffset(reloTarget, symRef->getOffset());
173
}
174
break;
175
176
case TR_FixedSequenceAddress2:
177
{
178
TR_RelocationRecordWithOffset *rwoRecord = reinterpret_cast<TR_RelocationRecordWithOffset *>(reloRecord);
179
uint8_t flags = static_cast<uint8_t>(reinterpret_cast<uintptr_t>(relocation->getTargetAddress2()));
180
181
TR_ASSERT((flags & RELOCATION_CROSS_PLATFORM_FLAGS_MASK) == 0, "reloFlags bits overlap cross-platform flags bits\n");
182
rwoRecord->setReloFlags(reloTarget, flags);
183
184
uintptr_t offset = relocation->getTargetAddress()
185
? static_cast<uintptr_t>(relocation->getTargetAddress() - aotMethodCodeStart)
186
: 0x0;
187
188
rwoRecord->setOffset(reloTarget, offset);
189
}
190
break;
191
192
case TR_BodyInfoAddressLoad:
193
{
194
TR_RelocationRecord *rRecord = reinterpret_cast<TR_RelocationRecord *>(reloRecord);
195
196
uint8_t flags = flags = static_cast<uint8_t>(reinterpret_cast<uintptr_t>(relocation->getTargetAddress2()));
197
TR_ASSERT((flags & RELOCATION_CROSS_PLATFORM_FLAGS_MASK) == 0, "reloFlags bits overlap cross-platform flags bits\n");
198
rRecord->setReloFlags(reloTarget, flags);
199
}
200
break;
201
202
case TR_RamMethodSequence:
203
{
204
TR_RelocationRecordRamSequence *rsRecord = reinterpret_cast<TR_RelocationRecordRamSequence *>(reloRecord);
205
uint8_t flags = static_cast<uint8_t>(reinterpret_cast<uintptr_t>(relocation->getTargetAddress2()));
206
207
TR_ASSERT((flags & RELOCATION_CROSS_PLATFORM_FLAGS_MASK) == 0, "reloFlags bits overlap cross-platform flags bits\n");
208
rsRecord->setReloFlags(reloTarget, flags);
209
210
// Skip Offset
211
}
212
break;
213
214
case TR_GlobalValue:
215
case TR_HCR:
216
{
217
TR_RelocationRecordWithOffset *rwoRecord = reinterpret_cast<TR_RelocationRecordWithOffset *>(reloRecord);
218
219
uintptr_t gv = reinterpret_cast<uintptr_t>(relocation->getTargetAddress());
220
uint8_t flags = static_cast<uint8_t>(reinterpret_cast<uintptr_t>(relocation->getTargetAddress2()));
221
222
TR_ASSERT((flags & RELOCATION_CROSS_PLATFORM_FLAGS_MASK) == 0, "reloFlags bits overlap cross-platform flags bits\n");
223
rwoRecord->setReloFlags(reloTarget, flags);
224
rwoRecord->setOffset(reloTarget, gv);
225
}
226
break;
227
228
case TR_ArbitraryClassAddress:
229
{
230
TR_RelocationRecordArbitraryClassAddress *acaRecord = reinterpret_cast<TR_RelocationRecordArbitraryClassAddress *>(reloRecord);
231
232
// ExternalRelocation data is as expected for TR_ClassAddress
233
TR_RelocationRecordInformation *recordInfo = (TR_RelocationRecordInformation *)relocation->getTargetAddress();
234
235
auto symRef = (TR::SymbolReference *)recordInfo->data1;
236
auto sym = symRef->getSymbol()->castToStaticSymbol();
237
auto j9class = (TR_OpaqueClassBlock *)sym->getStaticAddress();
238
// flags stored in data3 are currently unused
239
uintptr_t inlinedSiteIndex = self()->findCorrectInlinedSiteIndex(symRef->getOwningMethod(comp)->constantPool(), recordInfo->data2);
240
241
uintptr_t classChainIdentifyingLoaderOffsetInSharedCache = sharedCache->getClassChainOffsetIdentifyingLoader(j9class);
242
const AOTCacheClassChainRecord *classChainRecord = NULL;
243
uintptr_t classChainOffsetInSharedCache = self()->getClassChainOffset(j9class, classChainRecord);
244
245
acaRecord->setInlinedSiteIndex(reloTarget, inlinedSiteIndex);
246
acaRecord->setClassChainIdentifyingLoaderOffsetInSharedCache(reloTarget, classChainIdentifyingLoaderOffsetInSharedCache,
247
self(), classChainRecord);
248
acaRecord->setClassChainForInlinedMethod(reloTarget, classChainOffsetInSharedCache, self(), classChainRecord);
249
}
250
break;
251
252
default:
253
platformSpecificReloInitialized = false;
254
}
255
256
return platformSpecificReloInitialized;
257
}
258
259