Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/x/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 "env/FrontEnd.hpp"
25
#include "codegen/Instruction.hpp"
26
#include "compile/AOTClassInfo.hpp"
27
#include "compile/Compilation.hpp"
28
#include "compile/ResolvedMethod.hpp"
29
#include "compile/VirtualGuard.hpp"
30
#include "env/CHTable.hpp"
31
#include "env/ClassLoaderTable.hpp"
32
#include "env/CompilerEnv.hpp"
33
#include "env/SharedCache.hpp"
34
#include "env/jittypes.h"
35
#include "env/VMJ9.h"
36
#include "il/Node.hpp"
37
#include "il/Node_inlines.hpp"
38
#include "il/SymbolReference.hpp"
39
#include "ras/DebugCounter.hpp"
40
#include "runtime/CodeCacheConfig.hpp"
41
#include "runtime/CodeCacheManager.hpp"
42
#include "runtime/RelocationRuntime.hpp"
43
#include "runtime/RelocationRecord.hpp"
44
#include "runtime/SymbolValidationManager.hpp"
45
46
#define NON_HELPER 0x00
47
48
void J9::X86::AheadOfTimeCompile::processRelocations()
49
{
50
TR::Compilation *comp = _cg->comp();
51
52
// calculate the amount of memory needed to hold the relocation data
53
TR_J9VMBase *fej9 = (TR_J9VMBase *)(_cg->fe());
54
55
if (comp->target().is64Bit()
56
&& TR::CodeCacheManager::instance()->codeCacheConfig().needsMethodTrampolines()
57
&& _cg->getPicSlotCount())
58
{
59
_cg->addExternalRelocation(new (_cg->trHeapMemory()) TR::ExternalRelocation(NULL,
60
(uint8_t *)(uintptr_t)_cg->getPicSlotCount(),
61
TR_PicTrampolines, _cg),
62
__FILE__,
63
__LINE__,
64
NULL);
65
}
66
67
68
for (auto aotIterator = _cg->getExternalRelocationList().begin(); aotIterator != _cg->getExternalRelocationList().end(); ++aotIterator)
69
(*aotIterator)->addExternalRelocation(_cg);
70
71
TR::IteratedExternalRelocation *r;
72
for (r = self()->getAOTRelocationTargets().getFirst();
73
r != NULL;
74
r = r->getNext())
75
{
76
self()->addToSizeOfAOTRelocations(r->getSizeOfRelocationData());
77
}
78
79
// now allocate the memory size of all iterated relocations + the header (total length field)
80
81
// Note that when using the SymbolValidationManager, the well-known classes
82
// must be checked even if no explicit records were generated, since they
83
// might be responsible for the lack of records.
84
bool useSVM = comp->getOption(TR_UseSymbolValidationManager);
85
if (self()->getSizeOfAOTRelocations() != 0 || useSVM)
86
{
87
// It would be more straightforward to put the well-known classes offset
88
// in the AOT method header, but that would use space for AOT bodies that
89
// don't use the SVM. TODO: Move it once SVM takes over?
90
int wellKnownClassesOffsetSize = useSVM ? SIZEPOINTER : 0;
91
uintptr_t reloBufferSize =
92
self()->getSizeOfAOTRelocations() + SIZEPOINTER + wellKnownClassesOffsetSize;
93
uint8_t *relocationDataCursor = self()->setRelocationData(
94
fej9->allocateRelocationData(comp, reloBufferSize));
95
// set up the size for the region
96
*(uintptr_t *)relocationDataCursor = reloBufferSize;
97
relocationDataCursor += SIZEPOINTER;
98
99
if (useSVM)
100
{
101
TR::SymbolValidationManager *svm = comp->getSymbolValidationManager();
102
void *offsets = const_cast<void *>(svm->wellKnownClassChainOffsets());
103
uintptr_t *wkcOffsetAddr = (uintptr_t *)relocationDataCursor;
104
*wkcOffsetAddr = self()->offsetInSharedCacheFromPointer(fej9->sharedCache(), offsets);
105
#if defined(J9VM_OPT_JITSERVER)
106
self()->addWellKnownClassesSerializationRecord(svm->aotCacheWellKnownClassesRecord(), wkcOffsetAddr);
107
#endif /* defined(J9VM_OPT_JITSERVER) */
108
relocationDataCursor += SIZEPOINTER;
109
}
110
111
// set up pointers for each iterated relocation and initialize header
112
TR::IteratedExternalRelocation *s;
113
for (s = self()->getAOTRelocationTargets().getFirst();
114
s != 0;
115
s = s->getNext())
116
{
117
s->setRelocationData(relocationDataCursor);
118
s->initializeRelocation(_cg);
119
relocationDataCursor += s->getSizeOfRelocationData();
120
}
121
}
122
}
123
124
bool
125
J9::X86::AheadOfTimeCompile::initializePlatformSpecificAOTRelocationHeader(TR::IteratedExternalRelocation *relocation,
126
TR_RelocationTarget *reloTarget,
127
TR_RelocationRecord *reloRecord,
128
uint8_t targetKind)
129
{
130
bool platformSpecificReloInitialized = true;
131
132
switch (targetKind)
133
{
134
case TR_PicTrampolines:
135
{
136
TR_RelocationRecordPicTrampolines *ptRecord = reinterpret_cast<TR_RelocationRecordPicTrampolines *>(reloRecord);
137
138
TR_ASSERT(self()->comp()->target().is64Bit(), "TR_PicTrampolines not supported on 32-bit");
139
uint32_t numTrampolines = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(relocation->getTargetAddress()));
140
ptRecord->setNumTrampolines(reloTarget, numTrampolines);
141
}
142
break;
143
144
default:
145
platformSpecificReloInitialized = false;
146
}
147
148
return platformSpecificReloInitialized;
149
}
150
151
152