Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/aarch64/codegen/J9AheadOfTimeCompile.cpp
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2019, 2022 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/CodeGenerator.hpp"
25
#include "il/Node_inlines.hpp"
26
#include "il/StaticSymbol.hpp"
27
#include "runtime/RelocationRuntime.hpp"
28
#include "runtime/RelocationRecord.hpp"
29
30
J9::ARM64::AheadOfTimeCompile::AheadOfTimeCompile(TR::CodeGenerator *cg) :
31
J9::AheadOfTimeCompile(NULL, cg->comp()),
32
_cg(cg)
33
{
34
}
35
36
void J9::ARM64::AheadOfTimeCompile::processRelocations()
37
{
38
TR::Compilation *comp = self()->comp();
39
TR_J9VMBase *fej9 = (TR_J9VMBase *)(_cg->fe());
40
TR::IteratedExternalRelocation *r;
41
42
for (auto aotIterator = _cg->getExternalRelocationList().begin(); aotIterator != _cg->getExternalRelocationList().end(); ++aotIterator)
43
{
44
(*aotIterator)->addExternalRelocation(_cg);
45
}
46
47
for (r = getAOTRelocationTargets().getFirst(); r != NULL; r = r->getNext())
48
{
49
addToSizeOfAOTRelocations(r->getSizeOfRelocationData());
50
}
51
52
// now allocate the memory size of all iterated relocations + the header (total length field)
53
54
// Note that when using the SymbolValidationManager, the well-known classes
55
// must be checked even if no explicit records were generated, since they
56
// might be responsible for the lack of records.
57
bool useSVM = comp->getOption(TR_UseSymbolValidationManager);
58
59
if (self()->getSizeOfAOTRelocations() != 0 || useSVM)
60
{
61
// It would be more straightforward to put the well-known classes offset
62
// in the AOT method header, but that would use space for AOT bodies that
63
// don't use the SVM.
64
int wellKnownClassesOffsetSize = useSVM ? SIZEPOINTER : 0;
65
uintptr_t reloBufferSize =
66
self()->getSizeOfAOTRelocations() + SIZEPOINTER + wellKnownClassesOffsetSize;
67
uint8_t *relocationDataCursor =
68
self()->setRelocationData(fej9->allocateRelocationData(comp, reloBufferSize));
69
70
// set up the size for the region
71
*(uintptr_t *)relocationDataCursor = reloBufferSize;
72
relocationDataCursor += SIZEPOINTER;
73
74
if (useSVM)
75
{
76
TR::SymbolValidationManager *svm = comp->getSymbolValidationManager();
77
void *offsets = const_cast<void *>(svm->wellKnownClassChainOffsets());
78
uintptr_t *wkcOffsetAddr = (uintptr_t *)relocationDataCursor;
79
*wkcOffsetAddr = self()->offsetInSharedCacheFromPointer(fej9->sharedCache(), offsets);
80
#if defined(J9VM_OPT_JITSERVER)
81
self()->addWellKnownClassesSerializationRecord(svm->aotCacheWellKnownClassesRecord(), wkcOffsetAddr);
82
#endif /* defined(J9VM_OPT_JITSERVER) */
83
relocationDataCursor += SIZEPOINTER;
84
}
85
86
// set up pointers for each iterated relocation and initialize header
87
TR::IteratedExternalRelocation *s;
88
for (s = getAOTRelocationTargets().getFirst(); s != NULL; s = s->getNext())
89
{
90
s->setRelocationData(relocationDataCursor);
91
s->initializeRelocation(_cg);
92
relocationDataCursor += s->getSizeOfRelocationData();
93
}
94
}
95
}
96
97
bool
98
J9::ARM64::AheadOfTimeCompile::initializePlatformSpecificAOTRelocationHeader(TR::IteratedExternalRelocation *relocation,
99
TR_RelocationTarget *reloTarget,
100
TR_RelocationRecord *reloRecord,
101
uint8_t targetKind)
102
{
103
bool platformSpecificReloInitialized = true;
104
105
switch (targetKind)
106
{
107
case TR_DiscontiguousSymbolFromManager:
108
{
109
TR_RelocationRecordDiscontiguousSymbolFromManager *dsfmRecord = reinterpret_cast<TR_RelocationRecordDiscontiguousSymbolFromManager *>(reloRecord);
110
111
uint8_t *symbol = (uint8_t *)relocation->getTargetAddress();
112
uint16_t symbolID = self()->comp()->getSymbolValidationManager()->getSymbolIDFromValue(static_cast<void *>(symbol));
113
114
uint16_t symbolType = (uint16_t)(uintptr_t)relocation->getTargetAddress2();
115
116
dsfmRecord->setSymbolID(reloTarget, symbolID);
117
dsfmRecord->setSymbolType(reloTarget, static_cast<TR::SymbolType>(symbolType));
118
}
119
break;
120
121
case TR_HCR:
122
{
123
TR_RelocationRecordHCR *hcrRecord = reinterpret_cast<TR_RelocationRecordHCR *>(reloRecord);
124
125
uintptr_t gv = reinterpret_cast<uintptr_t>(relocation->getTargetAddress());
126
uint8_t flags = static_cast<uint8_t>(reinterpret_cast<uintptr_t>(relocation->getTargetAddress2()));
127
128
TR_ASSERT((flags & RELOCATION_CROSS_PLATFORM_FLAGS_MASK) == 0, "reloFlags bits overlap cross-platform flags bits\n");
129
hcrRecord->setReloFlags(reloTarget, flags);
130
hcrRecord->setOffset(reloTarget, gv);
131
}
132
break;
133
134
default:
135
platformSpecificReloInitialized = false;
136
}
137
138
return platformSpecificReloInitialized;
139
}
140
141
142