Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/control/CompilationController.hpp
6000 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 2018 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 COMPILATIONCONTROLLER_INCL
24
#define COMPILATIONCONTROLLER_INCL
25
26
#include "compile/CompilationTypes.hpp"
27
#include "control/OptimizationPlan.hpp"
28
#include "runtime/CodeCacheManager.hpp"
29
#include "env/VMJ9.h"
30
31
class TR_OptimizationPlan;
32
struct TR_MethodToBeCompiled;
33
34
int32_t printTruncatedSignature(char *sigBuf, int32_t bufLen, J9Method *j9method);
35
36
extern "C" {
37
int32_t returnIprofilerState();
38
}
39
40
//--------------------------- TR_MethodEvent ----------------------------
41
class TR_MethodEvent
42
{
43
public:
44
enum { InvalidEvent=0,
45
InterpreterCounterTripped,
46
InterpretedMethodSample,
47
JittedMethodSample,
48
MethodBodyInvalidated,
49
NewInstanceImpl,
50
ShareableMethodHandleThunk,
51
CustomMethodHandleThunk,
52
OtherRecompilationTrigger,
53
JitCompilationInducedByDLT,
54
HWPRecompilationTrigger,
55
NumEvents // must be the last one
56
};
57
int32_t _eventType;
58
J9Method * _j9method;
59
void * _oldStartPC;
60
void * _samplePC;
61
J9VMThread * _vmThread;
62
J9Class * _classNeedingThunk; // for newInstanceImpl
63
TR_Hotness _nextOptLevel; // Used for HWP-based recompilation
64
};
65
66
67
//-------------------------TR::DefaultCompilationStrategy ----------------------
68
namespace TR
69
{
70
class DefaultCompilationStrategy : public TR::CompilationStrategy
71
{
72
public:
73
TR_PERSISTENT_ALLOC(TR_Memory::PersistentInfo);
74
DefaultCompilationStrategy();
75
TR_OptimizationPlan *processEvent(TR_MethodEvent *event, bool *newPlanCreated);
76
TR_OptimizationPlan *processInterpreterSample(TR_MethodEvent *event);
77
TR_OptimizationPlan *processJittedSample(TR_MethodEvent *event);
78
TR_OptimizationPlan *processHWPSample(TR_MethodEvent *event);
79
TR_Hotness getInitialOptLevel(J9Method *j9method);
80
bool adjustOptimizationPlan(TR_MethodToBeCompiled *entry, int32_t optLevelAdjustment);
81
void beforeCodeGen(TR_OptimizationPlan *plan, TR::Recompilation *recomp);
82
void postCompilation(TR_OptimizationPlan *plan, TR::Recompilation *recomp);
83
void shutdown();
84
virtual bool enableSwitchToProfiling() { return !TR::CodeCacheManager::instance()->almostOutOfCodeCache(); }
85
private:
86
// statistics regarding the events it receives
87
unsigned _statEventType[TR_MethodEvent::NumEvents];
88
};
89
} // namespace TR
90
91
//----------------------- TR::ThresholdCompilationStrategy ---------------------
92
namespace TR
93
{
94
95
class ThresholdCompilationStrategy : public TR::CompilationStrategy
96
{
97
public:
98
TR_PERSISTENT_ALLOC(TR_Memory::PersistentInfo); // Do I need this ?
99
ThresholdCompilationStrategy();
100
TR_OptimizationPlan *processEvent(TR_MethodEvent *event, bool *newPlanCreated);
101
TR_OptimizationPlan *processJittedSample(TR_MethodEvent *event);
102
TR_Hotness getInitialOptLevel();
103
int32_t getSamplesNeeded(TR_Hotness optLevel) { TR_ASSERT(_samplesNeededToMoveTo[optLevel] >= 0, "must be valid entry"); return _samplesNeededToMoveTo[optLevel]; }
104
bool getPerformInstrumentation(TR_Hotness optLevel) { return _performInstrumentation[optLevel]; }
105
TR_Hotness getNextOptLevel(TR_Hotness curOptLevel) { TR_ASSERT(_nextLevel[curOptLevel] != unknownHotness, "must be valid opt level"); return _nextLevel[curOptLevel]; }
106
107
private:
108
TR_Hotness _nextLevel[numHotnessLevels+1];
109
int32_t _samplesNeededToMoveTo[numHotnessLevels+1];
110
bool _performInstrumentation[numHotnessLevels+1];
111
};
112
} // namespace TR
113
#endif // ifndef COMPILATIONCONTROLLER_INCL
114
115