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