Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/compile/J9Compilation.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 TR_J9_COMPILATIONBASE_INCL
24
#define TR_J9_COMPILATIONBASE_INCL
25
26
/*
27
* The following #define and typedef must appear before any #includes in this file
28
*/
29
#ifndef TR_J9_COMPILATIONBASE_CONNECTOR
30
#define TR_J9_COMPILATIONBASE_CONNECTOR
31
namespace J9 { class Compilation; }
32
namespace J9 { typedef J9::Compilation CompilationConnector; }
33
#endif
34
35
#include "compile/OMRCompilation.hpp"
36
37
#include "compile/CompilationTypes.hpp"
38
#include "control/Options.hpp"
39
#include "control/Options_inlines.hpp"
40
#include "infra/Statistics.hpp"
41
#include "env/CompilerEnv.hpp"
42
#include "env/OMRMemory.hpp"
43
#include "compile/AOTClassInfo.hpp"
44
#include "runtime/SymbolValidationManager.hpp"
45
#if defined(J9VM_OPT_JITSERVER)
46
#include "env/PersistentCollections.hpp"
47
#endif /* defined(J9VM_OPT_JITSERVER) */
48
49
50
class TR_AOTGuardSite;
51
class TR_FrontEnd;
52
class TR_ResolvedMethod;
53
class TR_OptimizationPlan;
54
class TR_J9VMBase;
55
class TR_ValueProfileInfoManager;
56
class TR_BranchProfileInfoManager;
57
class TR_MethodBranchProfileInfo;
58
class TR_ExternalValueProfileInfo;
59
class TR_J9VM;
60
class TR_AccessedProfileInfo;
61
class TR_RelocationRuntime;
62
namespace TR { class IlGenRequest; }
63
#ifdef J9VM_OPT_JITSERVER
64
struct SerializedRuntimeAssumption;
65
class ClientSessionData;
66
class AOTCacheRecord;
67
#endif /* defined(J9VM_OPT_JITSERVER) */
68
69
#define COMPILATION_AOT_HAS_INVOKEHANDLE -9
70
#define COMPILATION_RESERVE_RESOLVED_TRAMPOLINE_FATAL_ERROR -10
71
#define COMPILATION_RESERVE_RESOLVED_TRAMPOLINE_INSUFFICIENT_SPACE -11
72
#define COMPILATION_RESERVE_RESOLVED_TRAMPOLINE_ERROR_INBINARYENCODING -12
73
#define COMPILATION_RESERVE_RESOLVED_TRAMPOLINE_ERROR -13
74
#define COMPILATION_RESERVE_UNRESOLVED_TRAMPOLINE_FATAL_ERROR -14
75
#define COMPILATION_RESERVE_UNRESOLVED_TRAMPOLINE_INSUFFICIENT_SPACE -15
76
#define COMPILATION_RESERVE_UNRESOLVED_TRAMPOLINE_ERROR_INBINARYENCODING -16
77
#define COMPILATION_RESERVE_UNRESOLVED_TRAMPOLINE_ERROR -17
78
#define COMPILATION_RESERVE_NTRAMPOLINES_INSUFFICIENT_SPACE -18
79
#define COMPILATION_RESERVE_NTRAMPOLINES_ERROR_INBINARYENCODING -19
80
#define COMPILATION_AOT_RELOCATION_FAILED -20
81
82
83
namespace J9
84
{
85
86
class OMR_EXTENSIBLE Compilation : public OMR::CompilationConnector
87
{
88
public:
89
90
TR_ALLOC(TR_Memory::Compilation)
91
92
Compilation(
93
int32_t compThreadId,
94
J9VMThread *j9VMThread,
95
TR_FrontEnd *,
96
TR_ResolvedMethod *,
97
TR::IlGenRequest &,
98
TR::Options &,
99
TR::Region &heapMemoryRegion,
100
TR_Memory *,
101
TR_OptimizationPlan *optimizationPlan,
102
TR_RelocationRuntime *reloRuntime,
103
TR::Environment *target = NULL);
104
105
~Compilation();
106
107
TR_J9VMBase *fej9();
108
TR_J9VM *fej9vm();
109
110
static void allocateCompYieldStatsMatrix();
111
112
static TR_Stats **_compYieldStatsMatrix;
113
114
void updateCompYieldStatistics(TR_CallingContext callingContext);
115
116
bool getUpdateCompYieldStats() { return _updateCompYieldStats; }
117
118
void printCompYieldStats();
119
120
uint64_t getMaxYieldInterval() { return _maxYieldInterval; }
121
122
static const char * getContextName(TR_CallingContext context);
123
124
static void printCompYieldStatsMatrix();
125
126
static void printEntryName(int32_t, int32_t);
127
128
bool getNeedsClassLookahead() {return _needsClassLookahead;}
129
130
void setNeedsClassLookahead(bool b) {_needsClassLookahead = b;}
131
132
bool hasBlockFrequencyInfo();
133
134
bool isShortRunningMethod(int32_t callerIndex);
135
136
int32_t getDltBcIndex() { return (uint32_t)_dltBcIndex;}
137
void setDltBcIndex(int32_t ix) { _dltBcIndex=ix;}
138
139
int32_t *getDltSlotDescription() { return _dltSlotDescription;}
140
void setDltSlotDescription(int32_t *ds) { _dltSlotDescription = ds;}
141
142
void *getReservedDataCache() { return _reservedDataCache; }
143
void setReservedDataCache(void *dataCache) { _reservedDataCache = dataCache; }
144
145
uint32_t getTotalNeededDataCacheSpace() { return _totalNeededDataCacheSpace; }
146
void incrementTotalNeededDataCacheSpace(uint32_t size) { _totalNeededDataCacheSpace += size; }
147
148
void * getAotMethodDataStart() const { return _aotMethodDataStart; }
149
void setAotMethodDataStart(void *p) { _aotMethodDataStart = p; }
150
151
TR_AOTMethodHeader * getAotMethodHeaderEntry();
152
153
TR::Node *findNullChkInfo(TR::Node *node);
154
155
bool isAlignStackMaps() { return J9::Compilation::target().cpu.isARM(); }
156
157
void changeOptLevel(TR_Hotness);
158
159
// For replay
160
void *getCurMethodMetadata() {return _curMethodMetadata;}
161
void setCurMethodMetadata(void *m) {_curMethodMetadata = m;}
162
163
void setGetImplInlineable(bool b) { _getImplInlineable = b; }
164
bool getGetImplInlineable() { return _getImplInlineable; }
165
166
//for converters
167
bool canTransformConverterMethod(TR::RecognizedMethod method);
168
bool isConverterMethod(TR::RecognizedMethod method);
169
170
bool useCompressedPointers();
171
bool useAnchors();
172
173
bool isRecompilationEnabled();
174
175
bool isJProfilingCompilation();
176
177
bool pendingPushLivenessDuringIlgen();
178
179
TR::list<TR_ExternalValueProfileInfo*> &getExternalVPInfos() { return _externalVPInfoList; }
180
181
TR_ValueProfileInfoManager *getValueProfileInfoManager() { return _vpInfoManager;}
182
void setValueProfileInfoManager(TR_ValueProfileInfoManager * mgr) { _vpInfoManager = mgr; }
183
184
TR_BranchProfileInfoManager *getBranchProfileInfoManager() { return _bpInfoManager;}
185
void setBranchProfileInfoManager(TR_BranchProfileInfoManager * mgr) { _bpInfoManager = mgr; }
186
187
TR::list<TR_MethodBranchProfileInfo*> &getMethodBranchInfos() { return _methodBranchInfoList; }
188
189
// See if the allocation of an object of the class can be inlined.
190
bool canAllocateInlineClass(TR_OpaqueClassBlock *clazz);
191
192
// See if it is OK to remove an allocation node to e.g. merge it with others
193
// or allocate it locally on a stack frame.
194
// If so, return the allocation size. Otherwise return 0.
195
// The second argument is the returned class information.
196
//
197
int32_t canAllocateInlineOnStack(TR::Node* node, TR_OpaqueClassBlock* &classInfo);
198
int32_t canAllocateInline(TR::Node* node, TR_OpaqueClassBlock* &classInfo);
199
200
TR::KnownObjectTable *getOrCreateKnownObjectTable();
201
void freeKnownObjectTable();
202
203
bool compileRelocatableCode();
204
205
bool compilePortableCode();
206
207
int32_t maxInternalPointers();
208
209
bool compilationShouldBeInterrupted(TR_CallingContext);
210
211
/* Heuristic Region APIs
212
*
213
* Heuristic Regions denotes regions where decisions
214
* within the region do not need to be remembered. In relocatable compiles,
215
* when the compiler requests some information via front end query,
216
* it's possible that the front end might walk a data structure,
217
* looking at several different possible answers before finally deciding
218
* on one. For a relocatable compile, only the final answer is important.
219
* Thus, a heuristic region is used to ignore all of the intermediate
220
* steps in determining the final answer.
221
*/
222
void enterHeuristicRegion();
223
void exitHeuristicRegion();
224
225
/* Used to ensure that a implementer chosen for inlining is valid under
226
* AOT.
227
*/
228
bool validateTargetToBeInlined(TR_ResolvedMethod *implementer);
229
230
void reportILGeneratorPhase();
231
void reportAnalysisPhase(uint8_t id);
232
void reportOptimizationPhase(OMR::Optimizations);
233
void reportOptimizationPhaseForSnap(OMR::Optimizations);
234
235
CompilationPhase saveCompilationPhase();
236
void restoreCompilationPhase(CompilationPhase phase);
237
238
/**
239
* \brief
240
* Answers whether the fact that a method has not been executed yet implies
241
* that the method is cold.
242
*
243
* \return
244
* true if the fact that a method has not been executed implies it is cold;
245
* false otherwise
246
*/
247
bool notYetRunMeansCold();
248
249
// --------------------------------------------------------------------------
250
// Hardware profiling
251
//
252
bool HWProfileDone() { return _doneHWProfile;}
253
void setHWProfileDone(bool val) {_doneHWProfile = val;}
254
255
void addHWPInstruction(TR::Instruction *instruction,
256
TR_HWPInstructionInfo::type instructionType,
257
void *data = NULL);
258
void addHWPCallInstruction(TR::Instruction *instruction, bool indirectCall = false, TR::Instruction *prev = NULL);
259
void addHWPReturnInstruction(TR::Instruction *instruction);
260
void addHWPValueProfileInstruction(TR::Instruction *instruction);
261
void addHWPBCMap(TR_HWPBytecodePCToIAMap map) { _hwpBCMap.add(map); }
262
TR_Array<TR_HWPInstructionInfo> *getHWPInstructions() { return &_hwpInstructions; }
263
TR_Array<TR_HWPBytecodePCToIAMap> *getHWPBCMap() { return &_hwpBCMap; }
264
265
bool verifyCompressedRefsAnchors(bool anchorize);
266
void verifyCompressedRefsAnchors();
267
268
void verifyCompressedRefsAnchors(TR::Node *parent, TR::Node *node,
269
TR::TreeTop *tt, vcount_t visitCount);
270
void verifyCompressedRefsAnchors(TR::Node *parent, TR::Node *node,
271
TR::TreeTop *tt, vcount_t visitCount,
272
TR::list<TR_Pair<TR::Node, TR::TreeTop> *> &nodesList);
273
274
// CodeGenerator?
275
TR::list<TR_AOTGuardSite*> *getAOTGuardPatchSites() { return _aotGuardPatchSites; }
276
TR_AOTGuardSite *addAOTNOPSite();
277
278
TR::list<TR_VirtualGuardSite*> *getSideEffectGuardPatchSites() { return &_sideEffectGuardPatchSites; }
279
TR_VirtualGuardSite *addSideEffectNOPSite();
280
281
TR_CHTable *getCHTable() const { return _transientCHTable; }
282
283
// Inliner
284
using OMR::CompilationConnector::incInlineDepth;
285
bool incInlineDepth(TR::ResolvedMethodSymbol *, TR_ByteCodeInfo &, int32_t cpIndex, TR::SymbolReference *callSymRef, bool directCall, TR_PrexArgInfo *argInfo = 0);
286
287
bool isGeneratedReflectionMethod(TR_ResolvedMethod *method);
288
289
TR_ExternalRelocationTargetKind getReloTypeForMethodToBeInlined(TR_VirtualGuardSelection *guard, TR::Node *callNode, TR_OpaqueClassBlock *receiverClass);
290
291
// cache J9 VM pointers
292
TR_OpaqueClassBlock *getObjectClassPointer();
293
TR_OpaqueClassBlock *getRunnableClassPointer();
294
TR_OpaqueClassBlock *getStringClassPointer();
295
TR_OpaqueClassBlock *getSystemClassPointer();
296
TR_OpaqueClassBlock *getReferenceClassPointer();
297
TR_OpaqueClassBlock *getJITHelpersClassPointer();
298
TR_OpaqueClassBlock *getClassClassPointer(bool isVettedForAOT = false);
299
300
// Monitors
301
TR_Array<List<TR::RegisterMappedSymbol> * > & getMonitorAutos() { return _monitorAutos; }
302
void addMonitorAuto(TR::RegisterMappedSymbol *, int32_t callerIndex);
303
void addAsMonitorAuto(TR::SymbolReference* symRef, bool dontAddIfDLT);
304
TR::list<TR::SymbolReference*> * getMonitorAutoSymRefsInCompiledMethod() { return &_monitorAutoSymRefsInCompiledMethod; }
305
306
// OSR Guard Redefinition Classes
307
void addClassForOSRRedefinition(TR_OpaqueClassBlock *clazz);
308
TR_Array<TR_OpaqueClassBlock*> *getClassesForOSRRedefinition() { return &_classForOSRRedefinition; }
309
310
void addClassForStaticFinalFieldModification(TR_OpaqueClassBlock *clazz);
311
TR_Array<TR_OpaqueClassBlock*> *getClassesForStaticFinalFieldModification() { return &_classForStaticFinalFieldModification; }
312
313
TR::list<TR::AOTClassInfo*>* _aotClassInfo;
314
315
J9VMThread *j9VMThread() { return _j9VMThread; }
316
317
// cache profile information
318
TR_AccessedProfileInfo *getProfileInfo() { return _profileInfo; }
319
320
// Flag to test whether early stages of JProfiling ran
321
void setSkippedJProfilingBlock(bool b = true) { _skippedJProfilingBlock = b; }
322
bool getSkippedJProfilingBlock() { return _skippedJProfilingBlock; }
323
324
//
325
bool supportsQuadOptimization();
326
327
TR_RelocationRuntime *reloRuntime() { return _reloRuntime; }
328
329
bool incompleteOptimizerSupportForReadWriteBarriers();
330
331
#if defined(J9VM_OPT_JITSERVER)
332
static bool isOutOfProcessCompilation() { return _outOfProcessCompilation; } // server side
333
static void setOutOfProcessCompilation() { _outOfProcessCompilation = true; }
334
335
bool isRemoteCompilation() const { return _remoteCompilation; } // client side
336
void setRemoteCompilation() { _remoteCompilation = true; }
337
338
TR::list<SerializedRuntimeAssumption *> &getSerializedRuntimeAssumptions() { return _serializedRuntimeAssumptions; }
339
340
ClientSessionData *getClientData() const { return _clientData; }
341
void setClientData(ClientSessionData *clientData) { _clientData = clientData; }
342
343
JITServer::ServerStream *getStream() const { return _stream; }
344
void setStream(JITServer::ServerStream *stream) { _stream = stream; }
345
346
void switchToPerClientMemory() { _trMemory = _perClientMemory; }
347
void switchToGlobalMemory() { _trMemory = &_globalMemory; }
348
349
TR::list<TR_OpaqueMethodBlock *> &getMethodsRequiringTrampolines() { return _methodsRequiringTrampolines; }
350
351
bool isDeserializedAOTMethod() const { return _deserializedAOTMethod; }
352
void setDeserializedAOTMethod(bool deserialized) { _deserializedAOTMethod = deserialized; }
353
354
bool isDeserializedAOTMethodUsingSVM() const { return _deserializedAOTMethodUsingSVM; }
355
void setDeserializedAOTMethodUsingSVM(bool usingSVM) { _deserializedAOTMethodUsingSVM = usingSVM; }
356
357
bool isAOTCacheStore() const { return _aotCacheStore; }
358
void setAOTCacheStore(bool store) { _aotCacheStore = store; }
359
360
Vector<std::pair<const AOTCacheRecord *, uintptr_t>> &getSerializationRecords() { return _serializationRecords; }
361
// Adds an AOT cache record and the corresponding offset into AOT relocation data to the list that
362
// will be used when the result of this out-of-process compilation is serialized and stored in
363
// JITServer AOT cache. If record is NULL, fails serialization by setting _aotCacheStore to false.
364
void addSerializationRecord(const AOTCacheRecord *record, uintptr_t reloDataOffset);
365
#endif /* defined(J9VM_OPT_JITSERVER) */
366
367
TR::SymbolValidationManager *getSymbolValidationManager() { return _symbolValidationManager; }
368
369
// Flag to record if any optimization has prohibited OSR over a range of trees
370
void setOSRProhibitedOverRangeOfTrees() { _osrProhibitedOverRangeOfTrees = true; }
371
bool isOSRProhibitedOverRangeOfTrees() { return _osrProhibitedOverRangeOfTrees; }
372
373
private:
374
enum CachedClassPointerId
375
{
376
OBJECT_CLASS_POINTER,
377
RUNNABLE_CLASS_POINTER,
378
STRING_CLASS_POINTER,
379
SYSTEM_CLASS_POINTER,
380
REFERENCE_CLASS_POINTER,
381
JITHELPERS_CLASS_POINTER,
382
CACHED_CLASS_POINTER_COUNT,
383
};
384
385
TR_OpaqueClassBlock *getCachedClassPointer(CachedClassPointerId which);
386
387
J9VMThread *_j9VMThread;
388
389
bool _doneHWProfile;
390
TR_Array<TR_HWPInstructionInfo> _hwpInstructions;
391
TR_Array<TR_HWPBytecodePCToIAMap> _hwpBCMap;
392
393
bool _updateCompYieldStats;
394
395
uint64_t _hiresTimeForPreviousCallingContext;
396
397
TR_CallingContext _previousCallingContext;
398
399
uint64_t _maxYieldInterval;
400
401
TR_CallingContext _sourceContextForMaxYieldInterval;
402
403
TR_CallingContext _destinationContextForMaxYieldInterval;
404
405
static uint64_t _maxYieldIntervalS;
406
407
static TR_CallingContext _sourceContextForMaxYieldIntervalS;
408
409
static TR_CallingContext _destinationContextForMaxYieldIntervalS;
410
411
bool _needsClassLookahead;
412
413
uint16_t _dltBcIndex;
414
415
int32_t * _dltSlotDescription;
416
417
void * _reservedDataCache;
418
419
uint32_t _totalNeededDataCacheSpace;
420
421
void * _aotMethodDataStart; // used at relocation time
422
423
void * _curMethodMetadata;
424
425
bool _getImplInlineable;
426
427
TR_ValueProfileInfoManager *_vpInfoManager;
428
429
TR_BranchProfileInfoManager *_bpInfoManager;
430
431
TR::list<TR_MethodBranchProfileInfo*> _methodBranchInfoList;
432
TR::list<TR_ExternalValueProfileInfo*> _externalVPInfoList;
433
TR::list<TR_AOTGuardSite*>* _aotGuardPatchSites;
434
TR::list<TR_VirtualGuardSite*> _sideEffectGuardPatchSites;
435
436
// cache VM pointers
437
TR_OpaqueClassBlock *_cachedClassPointers[CACHED_CLASS_POINTER_COUNT];
438
439
TR_OpaqueClassBlock *_aotClassClassPointer;
440
bool _aotClassClassPointerInitialized;
441
442
TR_Array<List<TR::RegisterMappedSymbol> *> _monitorAutos;
443
TR::list<TR::SymbolReference*> _monitorAutoSymRefsInCompiledMethod;
444
445
TR_Array<TR_OpaqueClassBlock*> _classForOSRRedefinition;
446
// Classes that have their static final fields folded and need assumptions
447
TR_Array<TR_OpaqueClassBlock*> _classForStaticFinalFieldModification;
448
449
// cache profile information
450
TR_AccessedProfileInfo *_profileInfo;
451
452
bool _skippedJProfilingBlock;
453
454
TR_RelocationRuntime *_reloRuntime;
455
456
#if defined(J9VM_OPT_JITSERVER)
457
// This list contains assumptions created during the compilation at the JITServer
458
// It needs to be sent to the client at the end of compilation
459
TR::list<SerializedRuntimeAssumption *> _serializedRuntimeAssumptions;
460
// The following flag is set when this compilation is performed in a
461
// VM that does not have the runtime part (server side in JITServer)
462
static bool _outOfProcessCompilation;
463
// The following flag is set when a request to complete this compilation
464
// has been sent to a remote VM (client side in JITServer)
465
bool _remoteCompilation;
466
// Client session data for the client that requested this out-of-process
467
// compilation (at the JITServer); unused (always NULL) at the client side
468
ClientSessionData *_clientData;
469
// Server stream used by this out-of-process compilation; always NULL at the client
470
JITServer::ServerStream *_stream;
471
472
TR_Memory *_perClientMemory;
473
TR_Memory _globalMemory;
474
// This list contains RAM method pointers of resolved methods
475
// that require method trampolines.
476
// It needs to be sent to the client at the end of compilation
477
// so that trampolines can be reserved there.
478
TR::list<TR_OpaqueMethodBlock *> _methodsRequiringTrampolines;
479
480
// True if this remote compilation resulted in deserializing an AOT method
481
// received from the JITServer AOT cache; always false at the server
482
bool _deserializedAOTMethod;
483
// True if this deserialized AOT method received from the
484
// JITServer AOT cache uses SVM; always false at the server
485
bool _deserializedAOTMethodUsingSVM;
486
// True if the result of this out-of-process compilation will be
487
// stored in JITServer AOT cache; always false at the client
488
bool _aotCacheStore;
489
// List of AOT cache records and corresponding offsets into AOT relocation data that will
490
// be used to store the result of this compilation in AOT cache; always empty at the client
491
Vector<std::pair<const AOTCacheRecord *, uintptr_t>> _serializationRecords;
492
#endif /* defined(J9VM_OPT_JITSERVER) */
493
494
TR::SymbolValidationManager *_symbolValidationManager;
495
bool _osrProhibitedOverRangeOfTrees;
496
};
497
498
}
499
500
#endif
501
502