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_C1_C1_GRAPHBUILDER_HPP
26 #define SHARE_C1_C1_GRAPHBUILDER_HPP
27
28 #include "c1/c1_IR.hpp"
29 #include "c1/c1_Instruction.hpp"
30 #include "c1/c1_ValueMap.hpp"
31 #include "c1/c1_ValueStack.hpp"
32 #include "ci/ciMethodData.hpp"
33 #include "ci/ciStreams.hpp"
34 #include "compiler/compileLog.hpp"
35
36 class MemoryBuffer;
37
38 class GraphBuilder {
39 friend class JfrResolution;
40 private:
41 // Per-scope data. These are pushed and popped as we descend into
42 // inlined methods. Currently in order to generate good code in the
43 // inliner we have to attempt to inline methods directly into the
44 // basic block we are parsing; this adds complexity.
45 class ScopeData: public CompilationResourceObj {
46 private:
47 ScopeData* _parent;
48 // bci-to-block mapping
49 BlockList* _bci2block;
50 // Scope
51 IRScope* _scope;
52 // Whether this scope or any parent scope has exception handlers
53 bool _has_handler;
54 // The bytecodes
55 ciBytecodeStream* _stream;
56
57 // Work list
175 // for all GraphBuilders
176 static bool _can_trap[Bytecodes::number_of_java_codes];
177
178 // for each instance of GraphBuilder
179 ScopeData* _scope_data; // Per-scope data; used for inlining
180 Compilation* _compilation; // the current compilation
181 ValueMap* _vmap; // the map of values encountered (for CSE)
182 MemoryBuffer* _memory;
183 const char* _inline_bailout_msg; // non-null if most recent inline attempt failed
184 int _instruction_count; // for bailing out in pathological jsr/ret cases
185 BlockBegin* _start; // the start block
186 BlockBegin* _osr_entry; // the osr entry block block
187 ValueStack* _initial_state; // The state for the start block
188
189 // for each call to connect_to_end; can also be set by inliner
190 BlockBegin* _block; // the current block
191 ValueStack* _state; // the current execution state
192 Instruction* _last; // the last instruction added
193 bool _skip_block; // skip processing of the rest of this block
194
195 // accessors
196 ScopeData* scope_data() const { return _scope_data; }
197 Compilation* compilation() const { return _compilation; }
198 BlockList* bci2block() const { return scope_data()->bci2block(); }
199 ValueMap* vmap() const { assert(UseLocalValueNumbering, "should not access otherwise"); return _vmap; }
200 bool has_handler() const { return scope_data()->has_handler(); }
201
202 BlockBegin* block() const { return _block; }
203 ValueStack* state() const { return _state; }
204 void set_state(ValueStack* state) { _state = state; }
205 IRScope* scope() const { return scope_data()->scope(); }
206 ciMethod* method() const { return scope()->method(); }
207 ciBytecodeStream* stream() const { return scope_data()->stream(); }
208 Instruction* last() const { return _last; }
209 Bytecodes::Code code() const { return stream()->cur_bc(); }
210 int bci() const { return stream()->cur_bci(); }
211 int next_bci() const { return stream()->next_bci(); }
212
213 // unified bailout support
214 void bailout(const char* msg) const { compilation()->bailout(msg); }
215 bool bailed_out() const { return compilation()->bailed_out(); }
216
217 // stack manipulation helpers
218 void ipush(Value t) const { state()->ipush(t); }
219 void lpush(Value t) const { state()->lpush(t); }
220 void fpush(Value t) const { state()->fpush(t); }
221 void dpush(Value t) const { state()->dpush(t); }
222 void apush(Value t) const { state()->apush(t); }
223 void push(ValueType* type, Value t) const { state()-> push(type, t); }
224
225 Value ipop() { return state()->ipop(); }
226 Value lpop() { return state()->lpop(); }
227 Value fpop() { return state()->fpop(); }
228 Value dpop() { return state()->dpop(); }
229 Value apop() { return state()->apop(); }
230 Value pop(ValueType* type) { return state()-> pop(type); }
231
251 void if_same(ValueType* type, If::Condition cond);
252 void jsr(int dest);
253 void ret(int local_index);
254 void table_switch();
255 void lookup_switch();
256 void method_return(Value x, bool ignore_return = false);
257 void call_register_finalizer();
258 void access_field(Bytecodes::Code code);
259 void invoke(Bytecodes::Code code);
260 void new_instance(int klass_index);
261 void new_type_array();
262 void new_object_array();
263 void check_cast(int klass_index);
264 void instance_of(int klass_index);
265 void monitorenter(Value x, int bci);
266 void monitorexit(Value x, int bci);
267 void new_multi_array(int dimensions);
268 void throw_op(int bci);
269 Value round_fp(Value fp_value);
270
271 // stack/code manipulation helpers
272 Instruction* append_with_bci(Instruction* instr, int bci);
273 Instruction* append(Instruction* instr);
274 Instruction* append_split(StateSplit* instr);
275
276 // other helpers
277 BlockBegin* block_at(int bci) { return scope_data()->block_at(bci); }
278 XHandlers* handle_exception(Instruction* instruction);
279 void connect_to_end(BlockBegin* beg);
280 void null_check(Value value);
281 void eliminate_redundant_phis(BlockBegin* start);
282 BlockEnd* iterate_bytecodes_for_block(int bci);
283 void iterate_all_blocks(bool start_in_current_block_for_inlining = false);
284 Dependencies* dependency_recorder() const; // = compilation()->dependencies()
285 bool direct_compare(ciKlass* k);
286 Value make_constant(ciConstant value, ciField* field);
287
288 void kill_all();
289
290 // use of state copy routines (try to minimize unnecessary state
379 void append_unsafe_CAS(ciMethod* callee);
380 void append_unsafe_get_and_set(ciMethod* callee, bool is_add);
381 void append_char_access(ciMethod* callee, bool is_store);
382 void append_alloc_array_copy(ciMethod* callee);
383
384 void print_inlining(ciMethod* callee, const char* msg, bool success = true);
385
386 void profile_call(ciMethod* callee, Value recv, ciKlass* predicted_holder, Values* obj_args, bool inlined);
387 void profile_return_type(Value ret, ciMethod* callee, ciMethod* m = nullptr, int bci = -1);
388 void profile_invocation(ciMethod* inlinee, ValueStack* state);
389
390 // Shortcuts to profiling control.
391 bool is_profiling() { return _compilation->is_profiling(); }
392 bool profile_branches() { return _compilation->profile_branches(); }
393 bool profile_calls() { return _compilation->profile_calls(); }
394 bool profile_inlined_calls() { return _compilation->profile_inlined_calls(); }
395 bool profile_checkcasts() { return _compilation->profile_checkcasts(); }
396 bool profile_parameters() { return _compilation->profile_parameters(); }
397 bool profile_arguments() { return _compilation->profile_arguments(); }
398 bool profile_return() { return _compilation->profile_return(); }
399
400 Values* args_list_for_profiling(ciMethod* target, int& start, bool may_have_receiver);
401 Values* collect_args_for_profiling(Values* args, ciMethod* target, bool may_have_receiver);
402 void check_args_for_profiling(Values* obj_args, int expected);
403
404 public:
405 NOT_PRODUCT(void print_stats();)
406
407 // initialization
408 static void initialize();
409
410 // public
411 static bool can_trap(ciMethod* method, Bytecodes::Code code) {
412 assert(0 <= code && code < Bytecodes::number_of_java_codes, "illegal bytecode");
413 if (_can_trap[code]) return true;
414 // special handling for finalizer registration
415 return code == Bytecodes::_return && method->intrinsic_id() == vmIntrinsics::_Object_init;
416 }
417
418 // creation
|
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_C1_C1_GRAPHBUILDER_HPP
26 #define SHARE_C1_C1_GRAPHBUILDER_HPP
27
28 #include "c1/c1_IR.hpp"
29 #include "c1/c1_Instruction.hpp"
30 #include "c1/c1_ValueMap.hpp"
31 #include "c1/c1_ValueStack.hpp"
32 #include "ci/ciMethodData.hpp"
33 #include "ci/ciStreams.hpp"
34 #include "compiler/compileLog.hpp"
35
36 class MemoryBuffer;
37
38 class DelayedFieldAccess : public CompilationResourceObj {
39 private:
40 Value _obj;
41 ciInstanceKlass* _holder;
42 int _offset;
43 ValueStack* _state_before;
44
45 public:
46 DelayedFieldAccess(Value obj, ciInstanceKlass* holder, int offset, ValueStack* state_before)
47 : _obj(obj), _holder(holder) , _offset(offset), _state_before(state_before) { }
48
49 Value obj() const { return _obj; }
50 ciInstanceKlass* holder() const { return _holder; }
51 int offset() const { return _offset; }
52 void inc_offset(int offset) { _offset += offset; }
53 ValueStack* state_before() const { return _state_before; }
54 };
55
56 class GraphBuilder {
57 friend class JfrResolution;
58 private:
59 // Per-scope data. These are pushed and popped as we descend into
60 // inlined methods. Currently in order to generate good code in the
61 // inliner we have to attempt to inline methods directly into the
62 // basic block we are parsing; this adds complexity.
63 class ScopeData: public CompilationResourceObj {
64 private:
65 ScopeData* _parent;
66 // bci-to-block mapping
67 BlockList* _bci2block;
68 // Scope
69 IRScope* _scope;
70 // Whether this scope or any parent scope has exception handlers
71 bool _has_handler;
72 // The bytecodes
73 ciBytecodeStream* _stream;
74
75 // Work list
193 // for all GraphBuilders
194 static bool _can_trap[Bytecodes::number_of_java_codes];
195
196 // for each instance of GraphBuilder
197 ScopeData* _scope_data; // Per-scope data; used for inlining
198 Compilation* _compilation; // the current compilation
199 ValueMap* _vmap; // the map of values encountered (for CSE)
200 MemoryBuffer* _memory;
201 const char* _inline_bailout_msg; // non-null if most recent inline attempt failed
202 int _instruction_count; // for bailing out in pathological jsr/ret cases
203 BlockBegin* _start; // the start block
204 BlockBegin* _osr_entry; // the osr entry block block
205 ValueStack* _initial_state; // The state for the start block
206
207 // for each call to connect_to_end; can also be set by inliner
208 BlockBegin* _block; // the current block
209 ValueStack* _state; // the current execution state
210 Instruction* _last; // the last instruction added
211 bool _skip_block; // skip processing of the rest of this block
212
213 // support for optimization of accesses to flat fields and flat arrays
214 DelayedFieldAccess* _pending_field_access;
215 DelayedLoadIndexed* _pending_load_indexed;
216
217 // accessors
218 ScopeData* scope_data() const { return _scope_data; }
219 Compilation* compilation() const { return _compilation; }
220 BlockList* bci2block() const { return scope_data()->bci2block(); }
221 ValueMap* vmap() const { assert(UseLocalValueNumbering, "should not access otherwise"); return _vmap; }
222 bool has_handler() const { return scope_data()->has_handler(); }
223
224 BlockBegin* block() const { return _block; }
225 ValueStack* state() const { return _state; }
226 void set_state(ValueStack* state) { _state = state; }
227 IRScope* scope() const { return scope_data()->scope(); }
228 ciMethod* method() const { return scope()->method(); }
229 ciBytecodeStream* stream() const { return scope_data()->stream(); }
230 Instruction* last() const { return _last; }
231 Bytecodes::Code code() const { return stream()->cur_bc(); }
232 int bci() const { return stream()->cur_bci(); }
233 int next_bci() const { return stream()->next_bci(); }
234 bool has_pending_field_access() { return _pending_field_access != nullptr; }
235 DelayedFieldAccess* pending_field_access() { return _pending_field_access; }
236 void set_pending_field_access(DelayedFieldAccess* delayed) { _pending_field_access = delayed; }
237 bool has_pending_load_indexed() { return _pending_load_indexed != nullptr; }
238 DelayedLoadIndexed* pending_load_indexed() { return _pending_load_indexed; }
239 void set_pending_load_indexed(DelayedLoadIndexed* delayed) { _pending_load_indexed = delayed; }
240
241 // unified bailout support
242 void bailout(const char* msg) const { compilation()->bailout(msg); }
243 bool bailed_out() const { return compilation()->bailed_out(); }
244
245 // stack manipulation helpers
246 void ipush(Value t) const { state()->ipush(t); }
247 void lpush(Value t) const { state()->lpush(t); }
248 void fpush(Value t) const { state()->fpush(t); }
249 void dpush(Value t) const { state()->dpush(t); }
250 void apush(Value t) const { state()->apush(t); }
251 void push(ValueType* type, Value t) const { state()-> push(type, t); }
252
253 Value ipop() { return state()->ipop(); }
254 Value lpop() { return state()->lpop(); }
255 Value fpop() { return state()->fpop(); }
256 Value dpop() { return state()->dpop(); }
257 Value apop() { return state()->apop(); }
258 Value pop(ValueType* type) { return state()-> pop(type); }
259
279 void if_same(ValueType* type, If::Condition cond);
280 void jsr(int dest);
281 void ret(int local_index);
282 void table_switch();
283 void lookup_switch();
284 void method_return(Value x, bool ignore_return = false);
285 void call_register_finalizer();
286 void access_field(Bytecodes::Code code);
287 void invoke(Bytecodes::Code code);
288 void new_instance(int klass_index);
289 void new_type_array();
290 void new_object_array();
291 void check_cast(int klass_index);
292 void instance_of(int klass_index);
293 void monitorenter(Value x, int bci);
294 void monitorexit(Value x, int bci);
295 void new_multi_array(int dimensions);
296 void throw_op(int bci);
297 Value round_fp(Value fp_value);
298
299 // inline types
300 void copy_inline_content(ciInlineKlass* vk, Value src, int src_off, Value dest, int dest_off, ValueStack* state_before, ciField* encloding_field = nullptr);
301
302 // stack/code manipulation helpers
303 Instruction* append_with_bci(Instruction* instr, int bci);
304 Instruction* append(Instruction* instr);
305 Instruction* append_split(StateSplit* instr);
306
307 // other helpers
308 BlockBegin* block_at(int bci) { return scope_data()->block_at(bci); }
309 XHandlers* handle_exception(Instruction* instruction);
310 void connect_to_end(BlockBegin* beg);
311 void null_check(Value value);
312 void eliminate_redundant_phis(BlockBegin* start);
313 BlockEnd* iterate_bytecodes_for_block(int bci);
314 void iterate_all_blocks(bool start_in_current_block_for_inlining = false);
315 Dependencies* dependency_recorder() const; // = compilation()->dependencies()
316 bool direct_compare(ciKlass* k);
317 Value make_constant(ciConstant value, ciField* field);
318
319 void kill_all();
320
321 // use of state copy routines (try to minimize unnecessary state
410 void append_unsafe_CAS(ciMethod* callee);
411 void append_unsafe_get_and_set(ciMethod* callee, bool is_add);
412 void append_char_access(ciMethod* callee, bool is_store);
413 void append_alloc_array_copy(ciMethod* callee);
414
415 void print_inlining(ciMethod* callee, const char* msg, bool success = true);
416
417 void profile_call(ciMethod* callee, Value recv, ciKlass* predicted_holder, Values* obj_args, bool inlined);
418 void profile_return_type(Value ret, ciMethod* callee, ciMethod* m = nullptr, int bci = -1);
419 void profile_invocation(ciMethod* inlinee, ValueStack* state);
420
421 // Shortcuts to profiling control.
422 bool is_profiling() { return _compilation->is_profiling(); }
423 bool profile_branches() { return _compilation->profile_branches(); }
424 bool profile_calls() { return _compilation->profile_calls(); }
425 bool profile_inlined_calls() { return _compilation->profile_inlined_calls(); }
426 bool profile_checkcasts() { return _compilation->profile_checkcasts(); }
427 bool profile_parameters() { return _compilation->profile_parameters(); }
428 bool profile_arguments() { return _compilation->profile_arguments(); }
429 bool profile_return() { return _compilation->profile_return(); }
430 bool profile_array_accesses(){ return _compilation->profile_array_accesses();}
431
432 Values* args_list_for_profiling(ciMethod* target, int& start, bool may_have_receiver);
433 Values* collect_args_for_profiling(Values* args, ciMethod* target, bool may_have_receiver);
434 void check_args_for_profiling(Values* obj_args, int expected);
435
436 public:
437 NOT_PRODUCT(void print_stats();)
438
439 // initialization
440 static void initialize();
441
442 // public
443 static bool can_trap(ciMethod* method, Bytecodes::Code code) {
444 assert(0 <= code && code < Bytecodes::number_of_java_codes, "illegal bytecode");
445 if (_can_trap[code]) return true;
446 // special handling for finalizer registration
447 return code == Bytecodes::_return && method->intrinsic_id() == vmIntrinsics::_Object_init;
448 }
449
450 // creation
|