Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/codegen/J9AheadOfTimeCompile.hpp
6000 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
#ifndef J9_AHEADOFTIMECOMPILE_HPP
24
#define J9_AHEADOFTIMECOMPILE_HPP
25
26
#ifndef J9_AHEADOFTIMECOMPILE_CONNECTOR
27
#define J9_AHEADOFTIMECOMPILE_CONNECTOR
28
namespace J9 { class AheadOfTimeCompile; }
29
namespace J9 { typedef J9::AheadOfTimeCompile AheadOfTimeCompileConnector; }
30
#endif // J9_AHEADOFTIMECOMPILE_CONNECTOR
31
32
#include "codegen/OMRAheadOfTimeCompile.hpp"
33
#include "runtime/RelocationRecord.hpp"
34
35
#include <stdint.h>
36
#include "env/jittypes.h"
37
38
namespace TR { class Compilation; }
39
class AOTCacheRecord;
40
class AOTCacheClassChainRecord;
41
class AOTCacheWellKnownClassesRecord;
42
43
44
namespace J9
45
{
46
47
class OMR_EXTENSIBLE AheadOfTimeCompile : public OMR::AheadOfTimeCompileConnector
48
{
49
public:
50
static const size_t SIZEPOINTER = sizeof(uintptr_t);
51
52
AheadOfTimeCompile(uint32_t *headerSizeMap, TR::Compilation *c) :
53
OMR::AheadOfTimeCompileConnector(headerSizeMap, c)
54
{
55
}
56
57
/**
58
* @brief Gets the class chain offset for a given RAMClass. Calls TR_SharedCache::rememberClass()
59
* and fails the compilation if the class chain cannot be created.
60
*
61
* @param[in] classToRemember the RAMClass to get the class chain offset for
62
* @param[out] classChainRecord pointer to the AOT cache class chain record corresponding to the class chain, if this
63
* is an out-of-process compilation that will be stored in JITServerAOT cache;
64
* ignored for local compilations and out-of-process compilations not stored in AOT cache
65
* @return class chain SCC offset
66
*/
67
uintptr_t getClassChainOffset(TR_OpaqueClassBlock *classToRemember, const AOTCacheClassChainRecord *&classChainRecord);
68
69
uintptr_t findCorrectInlinedSiteIndex(void *constantPool, uintptr_t currentInlinedSiteIndex);
70
71
#if defined(J9VM_OPT_JITSERVER)
72
/**
73
* @brief Adds an AOT cache class record corresponding to a ROMClass SCC offset
74
* if this out-of-process compilation will be stored in AOT cache.
75
*
76
* The resulting AOT cache class record is the root class record of the class chain record.
77
*
78
* @param classChainRecord pointer to the AOT cache class chain record for the class
79
* @param romClassOffsetAddr pointer to the binary relocation record field that stores the ROMClass SCC offset
80
*/
81
void addClassSerializationRecord(const AOTCacheClassChainRecord *classChainRecord, const uintptr_t *romClassOffsetAddr);
82
83
/**
84
* @brief Adds an AOT cache class record corresponding to a ROMClass SCC offset
85
* if this out-of-process compilation will be stored in AOT cache.
86
*
87
* The AOT cache class record is looked up in the client session or created
88
* on demand, possibly requesting missing information from the client.
89
*
90
* @param ramClass the RAMClass that the ROMClass SCC offset is for
91
* @param romClassOffsetAddr pointer to the binary relocation record field that stores the ROMClass SCC offset
92
*/
93
void addClassSerializationRecord(TR_OpaqueClassBlock *ramClass, const uintptr_t *romClassOffsetAddr);
94
95
/**
96
* @brief Adds an AOT cache method record corresponding to a ROMMethod SCC offset
97
* if this out-of-process compilation will be stored in AOT cache.
98
*
99
* The AOT cache method record is looked up in the client session or created
100
* on demand, possibly requesting missing information from the client.
101
*
102
* @param method the RAMMethod that the ROMMethod SCC offset is for
103
* @param definingClass RAMClass for the defining class of the method
104
* @param romMethodOffsetAddr pointer to the binary relocation record field that stores the ROMMethod SCC offset
105
*/
106
void addMethodSerializationRecord(J9Method *method, TR_OpaqueClassBlock *definingClass, const uintptr_t *romMethodOffsetAddr);
107
108
/**
109
* @brief Adds an AOT cache class chain record corresponding to a class chain SCC
110
* offset if this out-of-process compilation will be stored in AOT cache.
111
*
112
* @param classChainRecord pointer to the AOT cache class chain record
113
* @param classChainOffsetAddr pointer to the binary relocation record field that stores the class chain SCC offset
114
*/
115
void addClassChainSerializationRecord(const AOTCacheClassChainRecord *classChainRecord, const uintptr_t *classChainOffsetAddr);
116
117
/**
118
* @brief Adds an AOT cache class loader record corresponding to a class chain SCC offset identifying
119
* a class loader if this out-of-process compilation will be stored in AOT cache.
120
*
121
* The resulting AOT cache class loader record is the class loader record of the root class of the class chain.
122
* Note that while the AOT cache class chain record passed to this method is the one for the class being
123
* remembered, i.e. the same as the one passed to addClassChainSerializationRecord(), the AOT cache record
124
* associated with this SCC offset is the one identifying the class loader of the class being remembered.
125
* The JITServer AOT cache identifies class loaders by the name of the first loaded class (not by its class
126
* chain), hence the AOT cache class loader records are a distinct type from the class chain records.
127
*
128
* @param classChainRecord pointer to the AOT cache class chain record for the class
129
* whose loader is identified by the class chain SCC offset
130
* @param loaderChainOffsetAddr pointer to the binary relocation record field that stores
131
* the class chain SCC offset identifying the class loader
132
*/
133
void addClassLoaderSerializationRecord(const AOTCacheClassChainRecord *classChainRecord, const uintptr_t *loaderChainOffsetAddr);
134
135
/**
136
* @brief Adds an AOT cache well-known classes record corresponding to a well-known classes
137
* SCC offset if this out-of-process compilation will be stored in AOT cache.
138
*
139
* @param wkcRecord pointer to the AOT cache well-known classes record
140
* @param wkcOffsetAddr pointer to the binary relocation record field that stores the well-known classes SCC offset
141
*/
142
void addWellKnownClassesSerializationRecord(const AOTCacheWellKnownClassesRecord *wkcRecord, const uintptr_t *wkcOffsetAddr);
143
#endif /* defined(J9VM_OPT_JITSERVER) */
144
145
void dumpRelocationData();
146
uint8_t* dumpRelocationHeaderData(uint8_t *cursor, bool isVerbose);
147
148
/**
149
* @brief Initializes the relocation record header.
150
*
151
* @param relocation pointer to the iterated external relocation
152
* @return pointer into the buffer right after the fields of the header (ie the offsets section)
153
*/
154
virtual uint8_t *initializeAOTRelocationHeader(TR::IteratedExternalRelocation *relocation);
155
156
/**
157
* @brief Initialization of relocation record headers for whom data for the fields are acquired
158
* in a manner that is specific to a particular platform. This is the default implementation.
159
*
160
* @param relocation pointer to the iterated external relocation
161
* @param reloTarget pointer to the TR_RelocationTarget object
162
* @param reloRecord pointer to the TR_RelocationRecord object
163
* @param targetKind the TR_ExternalRelocationTargetKind enum value
164
*
165
* @return true if a platform specific relocation record header was initialized; false otherwise
166
*/
167
bool initializePlatformSpecificAOTRelocationHeader(TR::IteratedExternalRelocation *relocation, TR_RelocationTarget *reloTarget, TR_RelocationRecord *reloRecord, uint8_t targetKind)
168
{ return false; }
169
170
static void interceptAOTRelocation(TR::ExternalRelocation *relocation);
171
172
uint32_t getSizeOfAOTRelocationHeader(TR_ExternalRelocationTargetKind k) { return TR_RelocationRecord::getSizeOfAOTRelocationHeader(k); }
173
uint32_t *setAOTRelocationKindToHeaderSizeMap(uint32_t *p) { TR_ASSERT_FATAL(false, "Should not be called!\n"); return 0; }
174
175
/**
176
* Return true if an ExternalRelocation of kind TR_ClassAddress is expected
177
* to contain a pointer to TR_RelocationRecordInformation.
178
*/
179
static bool classAddressUsesReloRecordInfo() { return false; }
180
181
protected:
182
183
#if defined(J9VM_OPT_JITSERVER)
184
/**
185
* @brief Associates an AOT cache record with the corresponding SCC offset stored in AOT relocation data.
186
*
187
* If this is an out-of-process compilation that will be stored in JITServer AOT cache, computes the offset into
188
* AOT relocation data and calls Compilation::addSerializationRecord(record, offset), otherwise does nothing.
189
*
190
* @param record pointer to the AOT cache record to be added to this compilation
191
* @param sccOffsetAddr pointer to the binary relocation record field that stores the SCC offset
192
*/
193
void addSerializationRecord(const AOTCacheRecord *record, const uintptr_t *sccOffsetAddr);
194
#endif /* defined(J9VM_OPT_JITSERVER) */
195
196
/**
197
* @brief TR_J9SharedCache::offsetInSharedCacheFrom* asserts if the pointer
198
* passed in does not exist in the SCC. Under HCR, when an agent redefines
199
* a class, it causes the J9Class pointer to stay the same, but the
200
* J9ROMClass pointer changes. This means that if the compiler has a
201
* reference to a J9Class who J9ROMClass was in the SCC at one point in the
202
* compilation, it may no longer be so at another point in the compilation.
203
*
204
* This means that the compilation is no longer valid and should be aborted.
205
* Even if there isn't an abort during the compilation, at the end of the
206
* compilation, the compiler will fail the compile if such a redefinition
207
* occurred.
208
*
209
* Calling TR_J9SharedCache::offsetInSharedCacheFromPointer after such a
210
* redefinition could result in an assert. Therefore, this method exists as
211
* a wrapper around TR_J9SharedCache::isROMClassInSharedCache which doesn't
212
* assert and conveniently, updates the location referred to by the cacheOffset
213
* pointer passed in as a parameter.
214
*
215
* If the ptr isn't in the SCC, then the current method will abort the
216
* compilation. If the ptr is in the SCC, then the cacheOffset will be updated.
217
*
218
* @param sharedCache pointer to the TR_SharedCache object
219
* @param romClass J9ROMClass * whose offset in the SCC is required
220
* @return The offset into the SCC of romClass
221
*/
222
uintptr_t offsetInSharedCacheFromROMClass(TR_SharedCache *sharedCache, J9ROMClass *romClass);
223
224
/**
225
* @brief Same circumstance as offsetInSharedCacheFromROMClass above
226
*
227
* @param sharedCache pointer to the TR_SharedCache object
228
* @param romMethod J9ROMMethod * whose offset in the SCC is required
229
* @return The offset into the SCC of romMethod
230
*/
231
uintptr_t offsetInSharedCacheFromROMMethod(TR_SharedCache *sharedCache, J9ROMMethod *romMethod);
232
233
/**
234
* @brief Wrapper around TR_J9SharedCache::offsetInSharedCacheFromPointer for
235
* consistency with the above APIs
236
*
237
* @param sharedCache pointer to the TR_SharedCache object
238
* @param ptr pointer whose offset in the SCC is required
239
* @return The offset into the SCC of ptr
240
*/
241
uintptr_t offsetInSharedCacheFromPointer(TR_SharedCache *sharedCache, void *ptr);
242
243
/**
244
* @brief Initialization of relocation record headers for whom data for the fields are acquired
245
* in a manner that is common on all platforms
246
*
247
* @param relocation pointer to the iterated external relocation
248
* @param reloTarget pointer to the TR_RelocationTarget object
249
* @param reloRecord pointer to the associated TR_RelocationRecord API object
250
* @param kind the TR_ExternalRelocationTargetKind enum value
251
*/
252
void initializeCommonAOTRelocationHeader(TR::IteratedExternalRelocation *relocation, TR_RelocationTarget *reloTarget, TR_RelocationRecord *reloRecord, uint8_t kind);
253
};
254
255
}
256
257
#endif // TR_J9AHEADOFTIMECOMPILE_HPP
258
259