Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/x/codegen/X86Recompilation.hpp
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 2019 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 X86RECOMPILATION_INCL
24
#define X86RECOMPILATION_INCL
25
26
#include "control/Recompilation.hpp"
27
#include "control/RecompilationInfo.hpp"
28
namespace TR { class CodeGenerator; }
29
class TR_ResolvedMethod;
30
31
// ***************************************************************************
32
//
33
// Recompilation Support Runtime methods
34
//
35
// Methods headers look different based on the type of compilation: there are
36
// inherent differences between sampling and counting compilations and yet
37
// again between counting with profiling and counting without preexistence headers.
38
//
39
// The linkage info field contains information about what kind of compilation
40
// produced this method.
41
//
42
// WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
43
// WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
44
//
45
// When changing the prologue or preprologue shape/size, all recompilation-related
46
// code must be revisited to make sure it is kept consistent.
47
//
48
// WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
49
// WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
50
51
//
52
// Sampling Compilation
53
// ====================
54
//
55
// If preexistence was not performed on this method, the following is what the
56
// prologue looks like:
57
//
58
// -16 db[3] padding 3 bytes
59
// -13 call _samplingRecompileMethod <-- immediate field aligned on 4-byte bndry
60
// -8 dd address of persistent jitted body info
61
// -4 dd method linkage info and flags
62
// 0 ?? first instruction of the method (must be atleast 2 bytes)
63
//
64
// With preexistence the prologue looks like the following
65
//
66
// -24 db padding 1 byte
67
// -23 mov edi, j9method
68
// -18 call interpretedCallGlue
69
// -13 call _samplingRecompileMethod <-- immediate field aligned on 4 byte bndry
70
// -8 dd address of persistent jitted body info
71
// -4 dd method linkage info and flags
72
// 0 ?? first instruction of the method (must be atleast 2 bytes)
73
//
74
// The first instruction of the method can be either of the following types
75
// push ebx (deprecated) used when using ebx as dedicated bp
76
// (this instruction is forced to be 2 bytes)
77
// (there is a debug flag in ia32Code that enabled this)
78
// sub esp, byte default when the stack frame is small
79
// sub esp, dword default when the stack frame is large
80
//
81
// To recompile, the first instruction of the method is overwritten to be a
82
// jump to the call instruction at (startPC-13).
83
//
84
// It is not possible to have a sampling body without recompilation.
85
//
86
// Counting Recompilation
87
// ======================
88
// The method header looks like the following:
89
// Without Preexistence
90
// -8 dd address of persistent jitted body info
91
// -4 dd method linkage info flags
92
// startPC + 0 ?? first instruction of the method
93
//
94
// With Preexistence
95
// -20 dw padding 2 bytes
96
// -18 mov edi, j9method
97
// -13 call interpreterCallGlue
98
// -8 dd address of persistent jitted body info
99
// -4 dd method linkage info flags
100
// startPC + 0 ?? first instruction of the method
101
//
102
// The prologue of the method looks like the following:
103
// When Profiling
104
// cmp [recompilationCounter], 0
105
// jl LrecompSnippet
106
// Otherwise
107
// sub [recompilationCounter], 1
108
// jl LrecompSnippet
109
//
110
// recompilationCounter is the first field of persistent jitted body info, so the
111
// address contained in this instruction and at startPC - 8 is the same.
112
// (Duplication to minimize the thread safety issues that come up when
113
// patching the first instruction)
114
//
115
// ***************************************************************************
116
117
// We define offsets relative to startPC (ie. the interpreter entry point)
118
// because that way they are constant.
119
//
120
#if defined(TR_TARGET_64BIT)
121
122
# define START_PC_TO_ITR_GLUE_SAMPLING (-21)
123
# define START_PC_TO_ORIGINAL_ENTRY_BYTES (-19)
124
# define START_PC_TO_RECOMPILE_SAMPLING (-17)
125
# define START_PC_TO_ITR_GLUE_COUNTING (-16)
126
# define START_PC_TO_METHOD_INFO_ADDRESS (-12)
127
128
# define COUNTING_PROLOGUE_SIZE (19)
129
130
# define COUNTING_RECOMPILE_METHOD TR_AMD64countingRecompileMethod
131
# define SAMPLING_RECOMPILE_METHOD TR_AMD64samplingRecompileMethod
132
# define COUNTING_PATCH_CALL_SITE TR_AMD64countingPatchCallSite
133
# define SAMPLING_PATCH_CALL_SITE TR_AMD64samplingPatchCallSite
134
135
#else
136
137
# define START_PC_TO_ITR_GLUE_SAMPLING (-23)
138
# define START_PC_TO_ITR_GLUE_COUNTING (-18)
139
# define START_PC_TO_RECOMPILE_SAMPLING (-13)
140
# define START_PC_TO_METHOD_INFO_ADDRESS (-8)
141
# define START_PC_TO_ORIGINAL_ENTRY_BYTES (-2)
142
143
# define COUNTING_PROLOGUE_SIZE (13)
144
145
# define COUNTING_RECOMPILE_METHOD TR_IA32countingRecompileMethod
146
# define SAMPLING_RECOMPILE_METHOD TR_IA32samplingRecompileMethod
147
# define COUNTING_PATCH_CALL_SITE TR_IA32countingPatchCallSite
148
# define SAMPLING_PATCH_CALL_SITE TR_IA32samplingPatchCallSite
149
150
#endif
151
152
#define CALL_INSTRUCTION 0xE8
153
#define TWO_BYTE_JUMP_INSTRUCTION 0xEB
154
#define SPIN_LOOP_INSTRUCTION 0xFEEB
155
156
157
class TR_X86Recompilation : public TR::Recompilation
158
{
159
public:
160
161
TR_X86Recompilation(TR::Compilation *);
162
163
static TR::Recompilation * allocate(TR::Compilation *);
164
165
virtual TR_PersistentMethodInfo *getExistingMethodInfo(TR_ResolvedMethod *method);
166
virtual TR::Instruction *generatePrePrologue();
167
virtual TR::Instruction *generatePrologue(TR::Instruction *);
168
virtual void postCompilation();
169
170
TR::CodeGenerator *cg() { return _compilation->cg(); }
171
172
private:
173
void setMethodReturnInfoBits();
174
};
175
176
#endif
177
178