Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/control/J9Recompilation.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_RECOMPILATION_INCL
24
#define J9_RECOMPILATION_INCL
25
26
/*
27
* The following #define and typedef must appear before any #includes in this file
28
*/
29
#ifndef J9_RECOMPILATION_CONNECTOR
30
#define J9_RECOMPILATION_CONNECTOR
31
namespace J9 { class Recompilation; }
32
namespace J9 { typedef J9::Recompilation RecompilationConnector; }
33
#endif
34
35
#include "control/OMRRecompilation.hpp"
36
#include "control/RecompilationInfo.hpp"
37
#include <stdint.h>
38
39
namespace TR { class DefaultCompilationStrategy; }
40
class TR_ValueProfiler;
41
class TR_RecompilationProfiler;
42
43
namespace J9
44
{
45
46
class Recompilation : public OMR::RecompilationConnector
47
{
48
friend class TR::DefaultCompilationStrategy;
49
50
public:
51
52
Recompilation(TR::Compilation *comp);
53
54
void setupMethodInfo();
55
56
void createProfilers();
57
58
TR_PersistentJittedBodyInfo *getJittedBodyInfo() { return _bodyInfo; }
59
TR_PersistentMethodInfo *getMethodInfo() { return _methodInfo; }
60
void setMethodInfo(TR_PersistentMethodInfo *methodInfo) { _methodInfo = methodInfo; }
61
void setJittedBodyInfo(TR_PersistentJittedBodyInfo *bodyInfo) { _bodyInfo = bodyInfo; }
62
63
TR_ValueProfiler * getValueProfiler();
64
TR_BlockFrequencyProfiler * getBlockFrequencyProfiler();
65
TR_RecompilationProfiler * getFirstProfiler() { return _profilers.getFirst(); }
66
void removeProfiler(TR_RecompilationProfiler *rp);
67
68
bool isProfilingCompilation() { return _bodyInfo->getIsProfilingBody(); }
69
70
// for replay
71
void setIsProfilingCompilation(bool v) { _bodyInfo->setIsProfilingBody(v); }
72
73
TR_PersistentProfileInfo *findOrCreateProfileInfo();
74
TR_PersistentProfileInfo *getProfileInfo();
75
76
bool useSampling() {return _useSampling;}
77
78
bool switchToProfiling(uint32_t freq, uint32_t count);
79
bool switchToProfiling();
80
void switchAwayFromProfiling();
81
82
int32_t getProfilingFrequency();
83
int32_t getProfilingCount();
84
85
TR::SymbolReference *getCounterSymRef();
86
void *getCounterAddress() { return _bodyInfo->getCounterAddress(); }
87
88
bool isRecompilation() { return !_firstCompile; }
89
90
void startOfCompilation();
91
void beforeOptimization();
92
void beforeCodeGen();
93
void endOfCompilation();
94
95
bool couldBeCompiledAgain();
96
bool shouldBeCompiledAgain();
97
98
void preventRecompilation();
99
100
static void shutdown();
101
102
static TR_PersistentJittedBodyInfo *getJittedBodyInfoFromPC(void *startPC);
103
104
static TR_PersistentMethodInfo *getMethodInfoFromPC(void *startPC)
105
{
106
TR_PersistentJittedBodyInfo *jbi = getJittedBodyInfoFromPC(startPC);
107
return jbi? jbi->getMethodInfo() : NULL;
108
}
109
110
static bool countingSupported() { return _countingSupported; }
111
static TR_Hotness getNextCompileLevel(void *oldStartPC);
112
static void methodHasBeenRecompiled(void *oldStartPC, void *newStartPC, TR_FrontEnd *fe);
113
static void fixUpMethodCode(void *startPC);
114
115
// Recompile the method when convenient
116
//
117
static bool induceRecompilation(TR_FrontEnd *fe, void *startPC, bool *queued, TR_OptimizationPlan *optimizationPlan = NULL);
118
119
static bool isAlreadyBeingCompiled(TR_OpaqueMethodBlock *methodInfo, void *startPC, TR_FrontEnd *fe);
120
static void methodCannotBeRecompiled(void *oldStartPC, TR_FrontEnd *fe);
121
static void invalidateMethodBody(void *startPC, TR_FrontEnd *fe);
122
123
// Called at runtime to sample a method
124
//
125
static void sampleMethod(void *vmThread, TR_FrontEnd *fe, void *startPC, int32_t codeSize, void *samplePC, void *methodInfo, int32_t tickCount);
126
127
static bool isAlreadyPreparedForRecompile(void *startPC);
128
129
virtual TR_PersistentMethodInfo *getExistingMethodInfo(TR_ResolvedMethod *method);
130
131
static int32_t globalSampleCount;
132
static int32_t hwpGlobalSampleCount;
133
static int32_t jitGlobalSampleCount;
134
static int32_t jitRecompilationsInduced;
135
136
#if defined(J9VM_OPT_JITSERVER)
137
static TR_PersistentJittedBodyInfo * persistentJittedBodyInfoFromString(const std::string &bodyInfoStr, const std::string &methodInfoStr, TR_Memory * trMemory);
138
static void resetPersistentProfileInfo(TR_PersistentMethodInfo *methodInfo);
139
#endif /* defined(J9VM_OPT_JITSERVER) */
140
141
protected:
142
static int32_t limitMethodsCompiled;
143
static int32_t hotThresholdMethodsCompiled;
144
static int32_t scorchingThresholdMethodsCompiled;
145
static bool _countingSupported;
146
147
bool _firstCompile;
148
bool _useSampling;
149
bool _doNotCompileAgain;
150
TR_Hotness _nextLevel;
151
int32_t _nextCounter;
152
TR_SingleTimer _timer;
153
154
TR_PersistentMethodInfo *_methodInfo;
155
TR_PersistentJittedBodyInfo *_bodyInfo;
156
157
TR_LinkHead<TR_RecompilationProfiler> _profilers;
158
};
159
}
160
161
162
// A way to call induceRecompilation from ASM via jitCallCFunction.
163
// argsPtr[0] == startPC, argsPtr[1] == vmThread.
164
// resultPtr is ignored.
165
//
166
extern "C" void induceRecompilation_unwrapper(void **argsPtr, void **resultPtr);
167
168
169
#endif
170
171