author | pliden |
Mon, 14 May 2018 15:42:59 +0200 | |
changeset 50102 | 454fa295105c |
parent 47216 | 71c04702a3d5 |
child 51333 | f6641fcf7b7e |
permissions | -rw-r--r-- |
1 | 1 |
/* |
38031
e0b822facc03
8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents:
34160
diff
changeset
|
2 |
* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5046
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5046
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5046
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_C1_C1_IR_HPP |
26 |
#define SHARE_VM_C1_C1_IR_HPP |
|
27 |
||
28 |
#include "c1/c1_Instruction.hpp" |
|
29 |
#include "ci/ciExceptionHandler.hpp" |
|
30 |
#include "ci/ciMethod.hpp" |
|
31 |
#include "ci/ciStreams.hpp" |
|
32 |
#include "memory/allocation.hpp" |
|
33 |
||
1 | 34 |
// An XHandler is a C1 internal description for an exception handler |
35 |
||
36 |
class XHandler: public CompilationResourceObj { |
|
37 |
private: |
|
38 |
ciExceptionHandler* _desc; |
|
39 |
||
40 |
BlockBegin* _entry_block; // Entry block of xhandler |
|
41 |
LIR_List* _entry_code; // LIR-operations that must be executed before jumping to entry_block |
|
42 |
int _entry_pco; // pco where entry_code (or entry_block if no entry_code) starts |
|
43 |
int _phi_operand; // For resolving of phi functions at begin of entry_block |
|
44 |
int _scope_count; // for filling ExceptionRangeEntry::scope_count |
|
45 |
||
46 |
#ifdef ASSERT |
|
47 |
int _lir_op_id; // op_id of the LIR-operation throwing to this handler |
|
48 |
#endif |
|
49 |
||
50 |
public: |
|
51 |
// creation |
|
52 |
XHandler(ciExceptionHandler* desc) |
|
53 |
: _desc(desc) |
|
54 |
, _entry_block(NULL) |
|
55 |
, _entry_code(NULL) |
|
56 |
, _entry_pco(-1) |
|
57 |
, _phi_operand(-1) |
|
58 |
, _scope_count(-1) |
|
59 |
#ifdef ASSERT |
|
60 |
, _lir_op_id(-1) |
|
61 |
#endif |
|
62 |
{ } |
|
63 |
||
64 |
XHandler(XHandler* other) |
|
65 |
: _desc(other->_desc) |
|
66 |
, _entry_block(other->_entry_block) |
|
67 |
, _entry_code(other->_entry_code) |
|
68 |
, _entry_pco(other->_entry_pco) |
|
69 |
, _phi_operand(other->_phi_operand) |
|
70 |
, _scope_count(other->_scope_count) |
|
71 |
#ifdef ASSERT |
|
72 |
, _lir_op_id(other->_lir_op_id) |
|
73 |
#endif |
|
74 |
{ } |
|
75 |
||
76 |
// accessors for data of ciExceptionHandler |
|
77 |
int beg_bci() const { return _desc->start(); } |
|
78 |
int end_bci() const { return _desc->limit(); } |
|
79 |
int handler_bci() const { return _desc->handler_bci(); } |
|
80 |
bool is_catch_all() const { return _desc->is_catch_all(); } |
|
81 |
int catch_type() const { return _desc->catch_klass_index(); } |
|
82 |
ciInstanceKlass* catch_klass() const { return _desc->catch_klass(); } |
|
83 |
bool covers(int bci) const { return beg_bci() <= bci && bci < end_bci(); } |
|
84 |
||
85 |
// accessors for additional fields |
|
86 |
BlockBegin* entry_block() const { return _entry_block; } |
|
87 |
LIR_List* entry_code() const { return _entry_code; } |
|
88 |
int entry_pco() const { return _entry_pco; } |
|
89 |
int phi_operand() const { assert(_phi_operand != -1, "not set"); return _phi_operand; } |
|
90 |
int scope_count() const { assert(_scope_count != -1, "not set"); return _scope_count; } |
|
91 |
DEBUG_ONLY(int lir_op_id() const { return _lir_op_id; }); |
|
92 |
||
93 |
void set_entry_block(BlockBegin* entry_block) { |
|
94 |
assert(entry_block->is_set(BlockBegin::exception_entry_flag), "must be an exception handler entry"); |
|
95 |
assert(entry_block->bci() == handler_bci(), "bci's must correspond"); |
|
96 |
_entry_block = entry_block; |
|
97 |
} |
|
98 |
void set_entry_code(LIR_List* entry_code) { _entry_code = entry_code; } |
|
99 |
void set_entry_pco(int entry_pco) { _entry_pco = entry_pco; } |
|
100 |
void set_phi_operand(int phi_operand) { _phi_operand = phi_operand; } |
|
101 |
void set_scope_count(int scope_count) { _scope_count = scope_count; } |
|
102 |
DEBUG_ONLY(void set_lir_op_id(int lir_op_id) { _lir_op_id = lir_op_id; }); |
|
103 |
||
104 |
bool equals(XHandler* other) const; |
|
105 |
}; |
|
106 |
||
38031
e0b822facc03
8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents:
34160
diff
changeset
|
107 |
typedef GrowableArray<XHandler*> _XHandlerList; |
1 | 108 |
|
109 |
// XHandlers is the C1 internal list of exception handlers for a method |
|
110 |
class XHandlers: public CompilationResourceObj { |
|
111 |
private: |
|
112 |
_XHandlerList _list; |
|
113 |
||
114 |
public: |
|
115 |
// creation |
|
116 |
XHandlers() : _list() { } |
|
117 |
XHandlers(ciMethod* method); |
|
118 |
XHandlers(XHandlers* other); |
|
119 |
||
120 |
// accessors |
|
121 |
int length() const { return _list.length(); } |
|
122 |
XHandler* handler_at(int i) const { return _list.at(i); } |
|
123 |
bool has_handlers() const { return _list.length() > 0; } |
|
124 |
void append(XHandler* h) { _list.append(h); } |
|
125 |
XHandler* remove_last() { return _list.pop(); } |
|
126 |
||
127 |
bool could_catch(ciInstanceKlass* klass, bool type_is_exact) const; |
|
128 |
bool equals(XHandlers* others) const; |
|
129 |
}; |
|
130 |
||
131 |
||
132 |
class IRScope; |
|
38031
e0b822facc03
8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents:
34160
diff
changeset
|
133 |
typedef GrowableArray<IRScope*> IRScopeList; |
1 | 134 |
|
135 |
class Compilation; |
|
136 |
class IRScope: public CompilationResourceObj { |
|
137 |
private: |
|
138 |
// hierarchy |
|
139 |
Compilation* _compilation; // the current compilation |
|
140 |
IRScope* _caller; // the caller scope, or NULL |
|
141 |
int _level; // the inlining level |
|
142 |
ciMethod* _method; // the corresponding method |
|
143 |
IRScopeList _callees; // the inlined method scopes |
|
144 |
||
145 |
// graph |
|
146 |
XHandlers* _xhandlers; // the exception handlers |
|
147 |
int _number_of_locks; // the number of monitor lock slots needed |
|
148 |
bool _monitor_pairing_ok; // the monitor pairing info |
|
11886
feebf5c9f40c
7120481: storeStore barrier in constructor with final field
jiangli
parents:
7397
diff
changeset
|
149 |
bool _wrote_final; // has written final field |
23190
e8bbf9cd711e
8031818: Experimental VM flag for enforcing safe object construction
shade
parents:
22234
diff
changeset
|
150 |
bool _wrote_fields; // has written fields |
34160
3240e478a30e
8138894: C1: Support IRIW on weak memory platforms
mdoerr
parents:
33160
diff
changeset
|
151 |
bool _wrote_volatile; // has written volatile field |
1 | 152 |
BlockBegin* _start; // the start block, successsors are method entries |
153 |
||
38177 | 154 |
ResourceBitMap _requires_phi_function; // bit is set if phi functions at loop headers are necessary for a local variable |
1 | 155 |
|
156 |
// helper functions |
|
157 |
BlockBegin* build_graph(Compilation* compilation, int osr_bci); |
|
158 |
||
159 |
public: |
|
160 |
// creation |
|
161 |
IRScope(Compilation* compilation, IRScope* caller, int caller_bci, ciMethod* method, int osr_bci, bool create_graph = false); |
|
162 |
||
163 |
// accessors |
|
164 |
Compilation* compilation() const { return _compilation; } |
|
165 |
IRScope* caller() const { return _caller; } |
|
166 |
int level() const { return _level; } |
|
167 |
ciMethod* method() const { return _method; } |
|
168 |
int max_stack() const; // NOTE: expensive |
|
169 |
BitMap& requires_phi_function() { return _requires_phi_function; } |
|
170 |
||
171 |
// hierarchy |
|
172 |
bool is_top_scope() const { return _caller == NULL; } |
|
173 |
void add_callee(IRScope* callee) { _callees.append(callee); } |
|
174 |
int number_of_callees() const { return _callees.length(); } |
|
175 |
IRScope* callee_no(int i) const { return _callees.at(i); } |
|
176 |
||
177 |
// accessors, graph |
|
178 |
bool is_valid() const { return start() != NULL; } |
|
179 |
XHandlers* xhandlers() const { return _xhandlers; } |
|
180 |
int number_of_locks() const { return _number_of_locks; } |
|
181 |
void set_min_number_of_locks(int n) { if (n > _number_of_locks) _number_of_locks = n; } |
|
182 |
bool monitor_pairing_ok() const { return _monitor_pairing_ok; } |
|
183 |
BlockBegin* start() const { return _start; } |
|
11886
feebf5c9f40c
7120481: storeStore barrier in constructor with final field
jiangli
parents:
7397
diff
changeset
|
184 |
void set_wrote_final() { _wrote_final = true; } |
feebf5c9f40c
7120481: storeStore barrier in constructor with final field
jiangli
parents:
7397
diff
changeset
|
185 |
bool wrote_final () const { return _wrote_final; } |
23190
e8bbf9cd711e
8031818: Experimental VM flag for enforcing safe object construction
shade
parents:
22234
diff
changeset
|
186 |
void set_wrote_fields() { _wrote_fields = true; } |
e8bbf9cd711e
8031818: Experimental VM flag for enforcing safe object construction
shade
parents:
22234
diff
changeset
|
187 |
bool wrote_fields () const { return _wrote_fields; } |
34160
3240e478a30e
8138894: C1: Support IRIW on weak memory platforms
mdoerr
parents:
33160
diff
changeset
|
188 |
void set_wrote_volatile() { _wrote_volatile = true; } |
3240e478a30e
8138894: C1: Support IRIW on weak memory platforms
mdoerr
parents:
33160
diff
changeset
|
189 |
bool wrote_volatile () const { return _wrote_volatile; } |
1 | 190 |
}; |
191 |
||
192 |
||
193 |
// |
|
194 |
// IRScopeDebugInfo records the debug information for a particular IRScope |
|
195 |
// in a particular CodeEmitInfo. This allows the information to be computed |
|
196 |
// once early enough for the OopMap to be available to the LIR and also to be |
|
197 |
// reemited for different pcs using the same CodeEmitInfo without recomputing |
|
198 |
// everything. |
|
199 |
// |
|
200 |
||
201 |
class IRScopeDebugInfo: public CompilationResourceObj { |
|
202 |
private: |
|
203 |
IRScope* _scope; |
|
204 |
int _bci; |
|
205 |
GrowableArray<ScopeValue*>* _locals; |
|
206 |
GrowableArray<ScopeValue*>* _expressions; |
|
207 |
GrowableArray<MonitorValue*>* _monitors; |
|
208 |
IRScopeDebugInfo* _caller; |
|
209 |
||
210 |
public: |
|
211 |
IRScopeDebugInfo(IRScope* scope, |
|
212 |
int bci, |
|
213 |
GrowableArray<ScopeValue*>* locals, |
|
214 |
GrowableArray<ScopeValue*>* expressions, |
|
215 |
GrowableArray<MonitorValue*>* monitors, |
|
216 |
IRScopeDebugInfo* caller): |
|
217 |
_scope(scope) |
|
218 |
, _locals(locals) |
|
219 |
, _bci(bci) |
|
220 |
, _expressions(expressions) |
|
221 |
, _monitors(monitors) |
|
222 |
, _caller(caller) {} |
|
223 |
||
224 |
||
225 |
IRScope* scope() { return _scope; } |
|
226 |
int bci() { return _bci; } |
|
227 |
GrowableArray<ScopeValue*>* locals() { return _locals; } |
|
228 |
GrowableArray<ScopeValue*>* expressions() { return _expressions; } |
|
229 |
GrowableArray<MonitorValue*>* monitors() { return _monitors; } |
|
230 |
IRScopeDebugInfo* caller() { return _caller; } |
|
231 |
||
3600
27aa4477d039
6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents:
1
diff
changeset
|
232 |
//Whether we should reexecute this bytecode for deopt |
27aa4477d039
6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents:
1
diff
changeset
|
233 |
bool should_reexecute(); |
27aa4477d039
6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents:
1
diff
changeset
|
234 |
|
5046 | 235 |
void record_debug_info(DebugInformationRecorder* recorder, int pc_offset, bool topmost, bool is_method_handle_invoke = false) { |
1 | 236 |
if (caller() != NULL) { |
237 |
// Order is significant: Must record caller first. |
|
3600
27aa4477d039
6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents:
1
diff
changeset
|
238 |
caller()->record_debug_info(recorder, pc_offset, false/*topmost*/); |
1 | 239 |
} |
240 |
DebugToken* locvals = recorder->create_scope_values(locals()); |
|
241 |
DebugToken* expvals = recorder->create_scope_values(expressions()); |
|
242 |
DebugToken* monvals = recorder->create_monitor_values(monitors()); |
|
3600
27aa4477d039
6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents:
1
diff
changeset
|
243 |
// reexecute allowed only for the topmost frame |
4564
55dfb20908d0
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
3795
diff
changeset
|
244 |
bool reexecute = topmost ? should_reexecute() : false; |
4894
8a76fd3d098d
6910618: C2: Error: assert(d->is_oop(),"JVM_ArrayCopy: dst not an oop")
kvn
parents:
4564
diff
changeset
|
245 |
bool return_oop = false; // This flag will be ignored since it used only for C2 with escape analysis. |
33160
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
24318
diff
changeset
|
246 |
bool rethrow_exception = false; |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
24318
diff
changeset
|
247 |
recorder->describe_scope(pc_offset, methodHandle(), scope()->method(), bci(), reexecute, rethrow_exception, is_method_handle_invoke, return_oop, locvals, expvals, monvals); |
1 | 248 |
} |
249 |
}; |
|
250 |
||
251 |
||
252 |
class CodeEmitInfo: public CompilationResourceObj { |
|
253 |
friend class LinearScan; |
|
254 |
private: |
|
255 |
IRScopeDebugInfo* _scope_debug_info; |
|
256 |
IRScope* _scope; |
|
257 |
XHandlers* _exception_handlers; |
|
258 |
OopMap* _oop_map; |
|
259 |
ValueStack* _stack; // used by deoptimization (contains also monitors |
|
5687 | 260 |
bool _is_method_handle_invoke; // true if the associated call site is a MethodHandle call site. |
16611 | 261 |
bool _deoptimize_on_exception; |
1 | 262 |
|
263 |
FrameMap* frame_map() const { return scope()->compilation()->frame_map(); } |
|
264 |
Compilation* compilation() const { return scope()->compilation(); } |
|
265 |
||
266 |
public: |
|
267 |
||
268 |
// use scope from ValueStack |
|
16611 | 269 |
CodeEmitInfo(ValueStack* stack, XHandlers* exception_handlers, bool deoptimize_on_exception = false); |
1 | 270 |
|
271 |
// make a copy |
|
6745 | 272 |
CodeEmitInfo(CodeEmitInfo* info, ValueStack* stack = NULL); |
1 | 273 |
|
274 |
// accessors |
|
275 |
OopMap* oop_map() { return _oop_map; } |
|
276 |
ciMethod* method() const { return _scope->method(); } |
|
277 |
IRScope* scope() const { return _scope; } |
|
278 |
XHandlers* exception_handlers() const { return _exception_handlers; } |
|
279 |
ValueStack* stack() const { return _stack; } |
|
16611 | 280 |
bool deoptimize_on_exception() const { return _deoptimize_on_exception; } |
1 | 281 |
|
282 |
void add_register_oop(LIR_Opr opr); |
|
5687 | 283 |
void record_debug_info(DebugInformationRecorder* recorder, int pc_offset); |
1 | 284 |
|
5687 | 285 |
bool is_method_handle_invoke() const { return _is_method_handle_invoke; } |
286 |
void set_is_method_handle_invoke(bool x) { _is_method_handle_invoke = x; } |
|
24018
77b156916bab
8032410: compiler/uncommontrap/TestStackBangRbp.java times out on Solaris-Sparc V9
roland
parents:
23190
diff
changeset
|
287 |
|
77b156916bab
8032410: compiler/uncommontrap/TestStackBangRbp.java times out on Solaris-Sparc V9
roland
parents:
23190
diff
changeset
|
288 |
int interpreter_frame_size() const; |
1 | 289 |
}; |
290 |
||
291 |
||
292 |
class IR: public CompilationResourceObj { |
|
293 |
private: |
|
294 |
Compilation* _compilation; // the current compilation |
|
295 |
IRScope* _top_scope; // the root of the scope hierarchy |
|
296 |
int _num_loops; // Total number of loops |
|
297 |
BlockList* _code; // the blocks in code generation order w/ use counts |
|
298 |
||
299 |
public: |
|
300 |
// creation |
|
301 |
IR(Compilation* compilation, ciMethod* method, int osr_bci); |
|
302 |
||
303 |
// accessors |
|
304 |
bool is_valid() const { return top_scope()->is_valid(); } |
|
305 |
Compilation* compilation() const { return _compilation; } |
|
306 |
IRScope* top_scope() const { return _top_scope; } |
|
307 |
int number_of_locks() const { return top_scope()->number_of_locks(); } |
|
308 |
ciMethod* method() const { return top_scope()->method(); } |
|
309 |
BlockBegin* start() const { return top_scope()->start(); } |
|
310 |
BlockBegin* std_entry() const { return start()->end()->as_Base()->std_entry(); } |
|
311 |
BlockBegin* osr_entry() const { return start()->end()->as_Base()->osr_entry(); } |
|
312 |
BlockList* code() const { return _code; } |
|
313 |
int num_loops() const { return _num_loops; } |
|
314 |
int max_stack() const { return top_scope()->max_stack(); } // expensive |
|
315 |
||
316 |
// ir manipulation |
|
16611 | 317 |
void optimize_blocks(); |
318 |
void eliminate_null_checks(); |
|
1 | 319 |
void compute_predecessors(); |
320 |
void split_critical_edges(); |
|
321 |
void compute_code(); |
|
322 |
void compute_use_counts(); |
|
323 |
||
324 |
// The linear-scan order and the code emission order are equal, but |
|
325 |
// this may change in future |
|
326 |
BlockList* linear_scan_order() { assert(_code != NULL, "not computed"); return _code; } |
|
327 |
||
328 |
// iteration |
|
329 |
void iterate_preorder (BlockClosure* closure); |
|
330 |
void iterate_postorder (BlockClosure* closure); |
|
331 |
void iterate_linear_scan_order(BlockClosure* closure); |
|
332 |
||
333 |
// debugging |
|
334 |
static void print(BlockBegin* start, bool cfg_only, bool live_only = false) PRODUCT_RETURN; |
|
335 |
void print(bool cfg_only, bool live_only = false) PRODUCT_RETURN; |
|
336 |
void verify() PRODUCT_RETURN; |
|
337 |
}; |
|
338 |
||
339 |
||
340 |
// Globally do instruction substitution and remove substituted |
|
341 |
// instructions from the instruction list. |
|
342 |
// |
|
343 |
||
5707 | 344 |
class SubstitutionResolver: public BlockClosure, ValueVisitor { |
345 |
virtual void visit(Value* v); |
|
1 | 346 |
|
347 |
public: |
|
348 |
SubstitutionResolver(IR* hir) { |
|
349 |
hir->iterate_preorder(this); |
|
350 |
} |
|
351 |
||
352 |
SubstitutionResolver(BlockBegin* block) { |
|
353 |
block->iterate_preorder(this); |
|
354 |
} |
|
355 |
||
356 |
virtual void block_do(BlockBegin* block); |
|
357 |
}; |
|
7397 | 358 |
|
359 |
#endif // SHARE_VM_C1_C1_IR_HPP |