Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/compiler/compileTask.hpp
40930 views
1
/*
2
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#ifndef SHARE_COMPILER_COMPILETASK_HPP
26
#define SHARE_COMPILER_COMPILETASK_HPP
27
28
#include "ci/ciMethod.hpp"
29
#include "code/nmethod.hpp"
30
#include "compiler/compileLog.hpp"
31
#include "memory/allocation.hpp"
32
#include "utilities/xmlstream.hpp"
33
34
JVMCI_ONLY(class JVMCICompileState;)
35
36
// CompileTask
37
//
38
// An entry in the compile queue. It represents a pending or current
39
// compilation.
40
41
class CompileTask : public CHeapObj<mtCompiler> {
42
friend class VMStructs;
43
friend class JVMCIVMStructs;
44
45
public:
46
// Different reasons for a compilation
47
// The order is important - mapped to reason_names[]
48
enum CompileReason {
49
Reason_None,
50
Reason_InvocationCount, // Simple/StackWalk-policy
51
Reason_BackedgeCount, // Simple/StackWalk-policy
52
Reason_Tiered, // Tiered-policy
53
Reason_Replay, // ciReplay
54
Reason_Whitebox, // Whitebox API
55
Reason_MustBeCompiled, // Used for -Xcomp or AlwaysCompileLoopMethods (see CompilationPolicy::must_be_compiled())
56
Reason_Bootstrap, // JVMCI bootstrap
57
Reason_Count
58
};
59
60
static const char* reason_name(CompileTask::CompileReason compile_reason) {
61
static const char* reason_names[] = {
62
"no_reason",
63
"count",
64
"backedge_count",
65
"tiered",
66
"replay",
67
"whitebox",
68
"must_be_compiled",
69
"bootstrap"
70
};
71
return reason_names[compile_reason];
72
}
73
74
private:
75
static CompileTask* _task_free_list;
76
Monitor* _lock;
77
uint _compile_id;
78
Method* _method;
79
jobject _method_holder;
80
int _osr_bci;
81
bool _is_complete;
82
bool _is_success;
83
bool _is_blocking;
84
#if INCLUDE_JVMCI
85
bool _has_waiter;
86
// Compilation state for a blocking JVMCI compilation
87
JVMCICompileState* _blocking_jvmci_compile_state;
88
#endif
89
int _comp_level;
90
int _num_inlined_bytecodes;
91
nmethodLocker* _code_handle; // holder of eventual result
92
CompileTask* _next, *_prev;
93
bool _is_free;
94
// Fields used for logging why the compilation was initiated:
95
jlong _time_queued; // time when task was enqueued
96
jlong _time_started; // time when compilation started
97
Method* _hot_method; // which method actually triggered this task
98
jobject _hot_method_holder;
99
int _hot_count; // information about its invocation counter
100
CompileReason _compile_reason; // more info about the task
101
const char* _failure_reason;
102
// Specifies if _failure_reason is on the C heap.
103
bool _failure_reason_on_C_heap;
104
105
public:
106
CompileTask() : _failure_reason(NULL), _failure_reason_on_C_heap(false) {
107
_lock = new Monitor(Mutex::nonleaf+2, "CompileTaskLock");
108
}
109
110
void initialize(int compile_id, const methodHandle& method, int osr_bci, int comp_level,
111
const methodHandle& hot_method, int hot_count,
112
CompileTask::CompileReason compile_reason, bool is_blocking);
113
114
static CompileTask* allocate();
115
static void free(CompileTask* task);
116
117
int compile_id() const { return _compile_id; }
118
Method* method() const { return _method; }
119
Method* hot_method() const { return _hot_method; }
120
int osr_bci() const { return _osr_bci; }
121
bool is_complete() const { return _is_complete; }
122
bool is_blocking() const { return _is_blocking; }
123
bool is_success() const { return _is_success; }
124
bool can_become_stale() const {
125
switch (_compile_reason) {
126
case Reason_BackedgeCount:
127
case Reason_InvocationCount:
128
case Reason_Tiered:
129
return !_is_blocking;
130
default:
131
return false;
132
}
133
}
134
#if INCLUDE_JVMCI
135
bool should_wait_for_compilation() const {
136
// Wait for blocking compilation to finish.
137
switch (_compile_reason) {
138
case Reason_Replay:
139
case Reason_Whitebox:
140
case Reason_Bootstrap:
141
return _is_blocking;
142
default:
143
return false;
144
}
145
}
146
147
bool has_waiter() const { return _has_waiter; }
148
void clear_waiter() { _has_waiter = false; }
149
JVMCICompileState* blocking_jvmci_compile_state() const { return _blocking_jvmci_compile_state; }
150
void set_blocking_jvmci_compile_state(JVMCICompileState* state) {
151
_blocking_jvmci_compile_state = state;
152
}
153
#endif
154
155
nmethodLocker* code_handle() const { return _code_handle; }
156
void set_code_handle(nmethodLocker* l) { _code_handle = l; }
157
nmethod* code() const; // _code_handle->code()
158
void set_code(nmethod* nm); // _code_handle->set_code(nm)
159
160
Monitor* lock() const { return _lock; }
161
162
void mark_complete() { _is_complete = true; }
163
void mark_success() { _is_success = true; }
164
void mark_started(jlong time) { _time_started = time; }
165
166
int comp_level() { return _comp_level;}
167
void set_comp_level(int comp_level) { _comp_level = comp_level;}
168
169
AbstractCompiler* compiler();
170
CompileTask* select_for_compilation();
171
172
int num_inlined_bytecodes() const { return _num_inlined_bytecodes; }
173
void set_num_inlined_bytecodes(int n) { _num_inlined_bytecodes = n; }
174
175
CompileTask* next() const { return _next; }
176
void set_next(CompileTask* next) { _next = next; }
177
CompileTask* prev() const { return _prev; }
178
void set_prev(CompileTask* prev) { _prev = prev; }
179
bool is_free() const { return _is_free; }
180
void set_is_free(bool val) { _is_free = val; }
181
bool is_unloaded() const;
182
183
// RedefineClasses support
184
void metadata_do(MetadataClosure* f);
185
void mark_on_stack();
186
187
private:
188
static void print_impl(outputStream* st, Method* method, int compile_id, int comp_level,
189
bool is_osr_method = false, int osr_bci = -1, bool is_blocking = false,
190
const char* msg = NULL, bool short_form = false, bool cr = true,
191
jlong time_queued = 0, jlong time_started = 0);
192
193
public:
194
void print(outputStream* st = tty, const char* msg = NULL, bool short_form = false, bool cr = true);
195
void print_ul(const char* msg = NULL);
196
static void print(outputStream* st, const nmethod* nm, const char* msg = NULL, bool short_form = false, bool cr = true) {
197
print_impl(st, nm->method(), nm->compile_id(), nm->comp_level(),
198
nm->is_osr_method(), nm->is_osr_method() ? nm->osr_entry_bci() : -1, /*is_blocking*/ false,
199
msg, short_form, cr);
200
}
201
static void print_ul(const nmethod* nm, const char* msg = NULL);
202
203
static void print_inline_indent(int inline_level, outputStream* st = tty);
204
205
void print_tty();
206
void print_line_on_error(outputStream* st, char* buf, int buflen);
207
208
void log_task(xmlStream* log);
209
void log_task_queued();
210
void log_task_start(CompileLog* log);
211
void log_task_done(CompileLog* log);
212
213
void set_failure_reason(const char* reason, bool on_C_heap = false) {
214
_failure_reason = reason;
215
_failure_reason_on_C_heap = on_C_heap;
216
}
217
218
bool check_break_at_flags();
219
220
static void print_inlining_inner(outputStream* st, ciMethod* method, int inline_level, int bci, const char* msg = NULL);
221
static void print_inlining_tty(ciMethod* method, int inline_level, int bci, const char* msg = NULL) {
222
print_inlining_inner(tty, method, inline_level, bci, msg);
223
}
224
static void print_inlining_ul(ciMethod* method, int inline_level, int bci, const char* msg = NULL);
225
};
226
227
#endif // SHARE_COMPILER_COMPILETASK_HPP
228
229