Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/z/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
#pragma csect(CODE,"TRJ9ZAOTComp#C")
24
#pragma csect(STATIC,"TRJ9ZAOTComp#S")
25
#pragma csect(TEST,"TRJ9ZAOTComp#T")
26
27
#include "codegen/AheadOfTimeCompile.hpp"
28
#include "codegen/CodeGenerator.hpp"
29
#include "env/FrontEnd.hpp"
30
#include "compile/AOTClassInfo.hpp"
31
#include "compile/Compilation.hpp"
32
#include "compile/ResolvedMethod.hpp"
33
#include "compile/VirtualGuard.hpp"
34
#include "env/CHTable.hpp"
35
#include "env/CompilerEnv.hpp"
36
#include "env/ClassLoaderTable.hpp"
37
#include "env/SharedCache.hpp"
38
#include "env/jittypes.h"
39
#include "env/VMJ9.h"
40
#include "il/LabelSymbol.hpp"
41
#include "il/Node.hpp"
42
#include "il/Node_inlines.hpp"
43
#include "il/StaticSymbol.hpp"
44
#include "il/SymbolReference.hpp"
45
#include "runtime/RelocationRuntime.hpp"
46
#include "runtime/RelocationRecord.hpp"
47
48
#define WIDE_OFFSETS 0x80
49
#define EIP_RELATIVE 0x40
50
#define ORDERED_PAIR 0x20
51
#define NON_HELPER 0
52
53
J9::Z::AheadOfTimeCompile::AheadOfTimeCompile(TR::CodeGenerator *cg)
54
: J9::AheadOfTimeCompile(NULL, cg->comp()),
55
_relocationList(getTypedAllocator<TR::S390Relocation*>(cg->comp()->allocator())),
56
_cg(cg)
57
{
58
}
59
60
void J9::Z::AheadOfTimeCompile::processRelocations()
61
{
62
TR::Compilation *comp = self()->comp();
63
TR_J9VMBase *fej9 = (TR_J9VMBase *)(_cg->fe());
64
TR::IteratedExternalRelocation *r;
65
66
for (auto iterator = self()->getRelocationList().begin();
67
iterator != self()->getRelocationList().end();
68
++iterator)
69
{
70
(*iterator)->mapRelocation(_cg);
71
}
72
73
for (auto aotIterator = _cg->getExternalRelocationList().begin(); aotIterator != _cg->getExternalRelocationList().end(); ++aotIterator)
74
(*aotIterator)->addExternalRelocation(_cg);
75
76
for (r = self()->getAOTRelocationTargets().getFirst();
77
r != NULL;
78
r = r->getNext())
79
{
80
self()->addToSizeOfAOTRelocations(r->getSizeOfRelocationData());
81
}
82
83
// now allocate the memory size of all iterated relocations + the header (total length field)
84
85
// Note that when using the SymbolValidationManager, the well-known classes
86
// must be checked even if no explicit records were generated, since they
87
// might be responsible for the lack of records.
88
bool useSVM = comp->getOption(TR_UseSymbolValidationManager);
89
if (self()->getSizeOfAOTRelocations() != 0 || useSVM)
90
{
91
// It would be more straightforward to put the well-known classes offset
92
// in the AOT method header, but that would use space for AOT bodies that
93
// don't use the SVM. TODO: Move it once SVM takes over?
94
int wellKnownClassesOffsetSize = useSVM ? SIZEPOINTER : 0;
95
uintptr_t reloBufferSize =
96
self()->getSizeOfAOTRelocations() + SIZEPOINTER + wellKnownClassesOffsetSize;
97
uint8_t *relocationDataCursor = self()->setRelocationData(
98
fej9->allocateRelocationData(comp, reloBufferSize));
99
// set up the size for the region
100
*(uintptr_t *)relocationDataCursor = reloBufferSize;
101
relocationDataCursor += SIZEPOINTER;
102
103
if (useSVM)
104
{
105
TR::SymbolValidationManager *svm = comp->getSymbolValidationManager();
106
void *offsets = const_cast<void *>(svm->wellKnownClassChainOffsets());
107
uintptr_t *wkcOffsetAddr = (uintptr_t *)relocationDataCursor;
108
*wkcOffsetAddr = self()->offsetInSharedCacheFromPointer(fej9->sharedCache(), offsets);
109
#if defined(J9VM_OPT_JITSERVER)
110
self()->addWellKnownClassesSerializationRecord(svm->aotCacheWellKnownClassesRecord(), wkcOffsetAddr);
111
#endif /* defined(J9VM_OPT_JITSERVER) */
112
relocationDataCursor += SIZEPOINTER;
113
}
114
115
// set up pointers for each iterated relocation and initialize header
116
TR::IteratedExternalRelocation *s;
117
for (s = self()->getAOTRelocationTargets().getFirst();
118
s != NULL;
119
s = s->getNext())
120
{
121
s->setRelocationData(relocationDataCursor);
122
s->initializeRelocation(_cg);
123
relocationDataCursor += s->getSizeOfRelocationData();
124
}
125
}
126
}
127
128
bool
129
J9::Z::AheadOfTimeCompile::initializePlatformSpecificAOTRelocationHeader(TR::IteratedExternalRelocation *relocation,
130
TR_RelocationTarget *reloTarget,
131
TR_RelocationRecord *reloRecord,
132
uint8_t targetKind)
133
{
134
bool platformSpecificReloInitialized = true;
135
136
switch (targetKind)
137
{
138
case TR_EmitClass:
139
{
140
TR_RelocationRecordEmitClass *ecRecord = reinterpret_cast<TR_RelocationRecordEmitClass *>(reloRecord);
141
142
TR_ByteCodeInfo *bcInfo = reinterpret_cast<TR_ByteCodeInfo *>(relocation->getTargetAddress());
143
int32_t bcIndex = bcInfo->getByteCodeIndex();
144
uintptr_t inlinedSiteIndex = reinterpret_cast<uintptr_t>(relocation->getTargetAddress2());
145
146
ecRecord->setInlinedSiteIndex(reloTarget, inlinedSiteIndex);
147
ecRecord->setBCIndex(reloTarget, bcIndex);
148
}
149
break;
150
151
default:
152
platformSpecificReloInitialized = false;
153
}
154
155
return platformSpecificReloInitialized;
156
}
157
158
159