< prev index next >

src/hotspot/share/opto/parse.hpp

Print this page

334     BytecodeParseHistogram* parse_histogram()      { return _parse_histogram; }
335 #endif
336 
337  private:
338   friend class Block;
339 
340   // Variables which characterize this compilation as a whole:
341 
342   JVMState*     _caller;        // JVMS which carries incoming args & state.
343   float         _expected_uses; // expected number of calls to this code
344   float         _prof_factor;   // discount applied to my profile counts
345   int           _depth;         // Inline tree depth, for debug printouts
346   const TypeFunc*_tf;           // My kind of function type
347   int           _entry_bci;     // the osr bci or InvocationEntryBci
348 
349   ciTypeFlow*   _flow;          // Results of previous flow pass.
350   Block*        _blocks;        // Array of basic-block structs.
351   int           _block_count;   // Number of elements in _blocks.
352 
353   GraphKit      _exits;         // Record all normal returns and throws here.
354   bool          _wrote_final;   // Did we write a final field?
355   bool          _wrote_volatile;     // Did we write a volatile field?
356   bool          _wrote_stable;       // Did we write a @Stable field?
357   bool          _wrote_fields;       // Did we write any field?
358   Node*         _alloc_with_final_or_stable; // An allocation node with final or @Stable field
359   Node*         _stress_rf_hook; // StressReachabilityFences support
360 
361   // Variables which track Java semantics during bytecode parsing:
362 
363   Block*            _block;     // block currently getting parsed
364   ciBytecodeStream  _iter;      // stream of this method's bytecodes
365 
366   const FastLockNode* _synch_lock; // FastLockNode for synchronized method
367 
368 #ifndef PRODUCT
369   int _max_switch_depth;        // Debugging SwitchRanges.
370   int _est_switch_depth;        // Debugging SwitchRanges.
371 #endif
372 
373   bool         _first_return;                  // true if return is the first to be parsed
374   bool         _replaced_nodes_for_exceptions; // needs processing of replaced nodes in exception paths?

376 
377  public:
378   // Constructor
379   Parse(JVMState* caller, ciMethod* parse_method, float expected_uses);
380 
381   virtual Parse* is_Parse() const { return (Parse*)this; }
382 
383   // Accessors.
384   JVMState*     caller()        const { return _caller; }
385   float         expected_uses() const { return _expected_uses; }
386   float         prof_factor()   const { return _prof_factor; }
387   int           depth()         const { return _depth; }
388   const TypeFunc* tf()          const { return _tf; }
389   //            entry_bci()     -- see osr_bci, etc.
390 
391   ciTypeFlow*   flow()          const { return _flow; }
392   //            blocks()        -- see rpo_at, start_block, etc.
393   int           block_count()   const { return _block_count; }
394 
395   GraphKit&     exits()               { return _exits; }
396   bool          wrote_final() const   { return _wrote_final; }
397   void      set_wrote_final(bool z)   { _wrote_final = z; }
398   bool          wrote_volatile() const { return _wrote_volatile; }
399   void      set_wrote_volatile(bool z) { _wrote_volatile = z; }
400   bool          wrote_stable() const  { return _wrote_stable; }
401   void      set_wrote_stable(bool z)  { _wrote_stable = z; }
402   bool         wrote_fields() const   { return _wrote_fields; }
403   void     set_wrote_fields(bool z)   { _wrote_fields = z; }
404   Node*    alloc_with_final_or_stable() const   { return _alloc_with_final_or_stable; }
405   void set_alloc_with_final_or_stable(Node* n)  {
406     assert((_alloc_with_final_or_stable == nullptr) || (_alloc_with_final_or_stable == n), "different init objects?");
407     _alloc_with_final_or_stable = n;
408   }
409 
410   Block*             block()    const { return _block; }
411   ciBytecodeStream&  iter()           { return _iter; }
412   Bytecodes::Code    bc()       const { return _iter.cur_bc(); }
413 
414   void set_block(Block* b)            { _block = b; }
415 
416   // Derived accessors:
417   bool is_osr_parse() const {

426   // Must this parse be aborted?
427   bool failing() const { return C->failing_internal(); } // might have cascading effects, not stressing bailouts for now.
428 
429   Block* rpo_at(int rpo) {
430     assert(0 <= rpo && rpo < _block_count, "oob");
431     return &_blocks[rpo];
432   }
433   Block* start_block() {
434     return rpo_at(flow()->start_block()->rpo());
435   }
436   // Can return null if the flow pass did not complete a block.
437   Block* successor_for_bci(int bci) {
438     return block()->successor_for_bci(bci);
439   }
440 
441  private:
442   // Create a JVMS & map for the initial state of this method.
443   SafePointNode* create_entry_map();
444 
445   // OSR helpers
446   Node *fetch_interpreter_state(int index, BasicType bt, Node* local_addrs);
447   Node* check_interpreter_type(Node* l, const Type* type, SafePointNode* &bad_type_exit);
448   void  load_interpreter_state(Node* osr_buf);
449 
450   // Functions for managing basic blocks:
451   void init_blocks();
452   void load_state_from(Block* b);
453   void store_state_to(Block* b) { b->record_state(this); }
454 
455   // Parse all the basic blocks.
456   void do_all_blocks();
457 
458   // Parse the current basic block
459   void do_one_block();
460 
461   // Raise an error if we get a bad ciTypeFlow CFG.
462   void handle_missing_successor(int bci);
463 
464   // first actions (before BCI 0)
465   void do_method_entry();
466 
467   // implementation of monitorenter/monitorexit
468   void do_monitor_enter();
469   void do_monitor_exit();
470 
471   // Eagerly create phie throughout the state, to cope with back edges.
472   void ensure_phis_everywhere();
473 
474   // Merge the current mapping into the basic block starting at bci
475   void merge(          int target_bci);
476   // Same as plain merge, except that it allocates a new path number.
477   void merge_new_path( int target_bci);
478   // Push the exception oop and merge the current mapping into an exception handler.
479   void push_and_merge_exception(int target_bci, Node* ex_oop);
480   // Helper: Merge the current mapping into the given basic block
481   void merge_common(Block* target, int pnum);
482   // Helper functions for merging individual cells.
483   Node* maybe_narrow_phi_input(Node* ctrl, Node* n, const Type* phi_type);
484   PhiNode *ensure_phi(       int idx, bool nocreate = false);
485   PhiNode *ensure_memory_phi(int idx, bool nocreate = false);
486   // Helper to merge the current memory state into the given basic block
487   void merge_memory_edges(MergeMemNode* n, int pnum, bool nophi);
488 
489   // Parse this bytecode, and alter the Parsers JVM->Node mapping
490   void do_one_bytecode();
491 
492   // helper function to generate array store check
493   void array_store_check();
494   // Helper function to generate array load
495   void array_load(BasicType etype);

496   // Helper function to generate array store
497   void array_store(BasicType etype);

498   // Helper function to compute array addressing
499   Node* array_addressing(BasicType type, int vals, const Type*& elemtype);









500 
501   void clinit_deopt();
502 
503   // Pass current map to exits
504   void return_current(Node* value);
505 
506   // Register finalizers on return from Object.<init>
507   void call_register_finalizer();
508 
509   // Insert a compiler safepoint into the graph
510   void add_safepoint();
511 
512   // Insert a compiler safepoint into the graph, if there is a back-branch.
513   void maybe_add_safepoint(int target_bci) {
514     if (target_bci <= bci()) {
515       add_safepoint();
516     }
517   }
518 
519   // Note:  Intrinsic generation routines may be found in library_call.cpp.

525   bool can_not_compile_call_site(ciMethod *dest_method, ciInstanceKlass *klass);
526 
527   // Helper functions for type checking bytecodes:
528   void  do_checkcast();
529   void  do_instanceof();
530 
531   // Helper functions for shifting & arithmetic
532   Node* floating_point_mod(Node* a, Node* b, BasicType type);
533   void l2f();
534 
535   // implementation of _get* and _put* bytecodes
536   void do_getstatic() { do_field_access(true,  false); }
537   void do_getfield () { do_field_access(true,  true); }
538   void do_putstatic() { do_field_access(false, false); }
539   void do_putfield () { do_field_access(false, true); }
540 
541   // common code for making initial checks and forming addresses
542   void do_field_access(bool is_get, bool is_field);
543 
544   // common code for actually performing the load or store
545   void do_get_xxx(Node* obj, ciField* field, bool is_field);
546   void do_put_xxx(Node* obj, ciField* field, bool is_field);
547 


548   // implementation of object creation bytecodes
549   void do_new();
550   void do_newarray(BasicType elemtype);
551   void do_anewarray();
552   void do_multianewarray();
553   Node* expand_multianewarray(ciArrayKlass* array_klass, Node* *lengths, int ndimensions, int nargs);
554 
555   // implementation of jsr/ret
556   void do_jsr();
557   void do_ret();
558 
559   float   dynamic_branch_prediction(float &cnt, BoolTest::mask btest, Node* test);
560   float   branch_prediction(float &cnt, BoolTest::mask btest, int target_bci, Node* test);
561   bool    seems_never_taken(float prob) const;
562   bool    path_is_suitable_for_uncommon_trap(float prob) const;
563 
564   void    do_ifnull(BoolTest::mask btest, Node* c);
565   void    do_if(BoolTest::mask btest, Node* c);









566   int     repush_if_args();
567   void    adjust_map_after_if(BoolTest::mask btest, Node* c, float prob, Block* path);
568   void    sharpen_type_after_if(BoolTest::mask btest,
569                                 Node* con, const Type* tcon,
570                                 Node* val, const Type* tval);
571   void    maybe_add_predicate_after_if(Block* path);
572   IfNode* jump_if_fork_int(Node* a, Node* b, BoolTest::mask mask, float prob, float cnt);
573   void    jump_if_true_fork(IfNode *ifNode, int dest_bci_if_true, bool unc);
574   void    jump_if_false_fork(IfNode *ifNode, int dest_bci_if_false, bool unc);
575   void    jump_if_always_fork(int dest_bci_if_true, bool unc);
576 
577   friend class SwitchRange;
578   void    do_tableswitch();
579   void    do_lookupswitch();
580   void    jump_switch_ranges(Node* a, SwitchRange* lo, SwitchRange* hi, int depth = 0);
581   bool    create_jump_tables(Node* a, SwitchRange* lo, SwitchRange* hi);
582   void    linear_search_switch_ranges(Node* key_val, SwitchRange*& lo, SwitchRange*& hi);
583 
584   // helper function for call statistics
585   void count_compiled_calls(bool at_method_entry, bool is_inline) PRODUCT_RETURN;
586 
587   Node_Notes* make_node_notes(Node_Notes* caller_nn);

334     BytecodeParseHistogram* parse_histogram()      { return _parse_histogram; }
335 #endif
336 
337  private:
338   friend class Block;
339 
340   // Variables which characterize this compilation as a whole:
341 
342   JVMState*     _caller;        // JVMS which carries incoming args & state.
343   float         _expected_uses; // expected number of calls to this code
344   float         _prof_factor;   // discount applied to my profile counts
345   int           _depth;         // Inline tree depth, for debug printouts
346   const TypeFunc*_tf;           // My kind of function type
347   int           _entry_bci;     // the osr bci or InvocationEntryBci
348 
349   ciTypeFlow*   _flow;          // Results of previous flow pass.
350   Block*        _blocks;        // Array of basic-block structs.
351   int           _block_count;   // Number of elements in _blocks.
352 
353   GraphKit      _exits;         // Record all normal returns and throws here.
354   bool          _wrote_non_strict_final; // Did we write a non-strict final field?
355   bool          _wrote_volatile;     // Did we write a volatile field?
356   bool          _wrote_stable;       // Did we write a @Stable field?
357   bool          _wrote_fields;       // Did we write any field?
358   Node*         _alloc_with_final_or_stable; // An allocation node with final or @Stable field
359   Node*         _stress_rf_hook; // StressReachabilityFences support
360 
361   // Variables which track Java semantics during bytecode parsing:
362 
363   Block*            _block;     // block currently getting parsed
364   ciBytecodeStream  _iter;      // stream of this method's bytecodes
365 
366   const FastLockNode* _synch_lock; // FastLockNode for synchronized method
367 
368 #ifndef PRODUCT
369   int _max_switch_depth;        // Debugging SwitchRanges.
370   int _est_switch_depth;        // Debugging SwitchRanges.
371 #endif
372 
373   bool         _first_return;                  // true if return is the first to be parsed
374   bool         _replaced_nodes_for_exceptions; // needs processing of replaced nodes in exception paths?

376 
377  public:
378   // Constructor
379   Parse(JVMState* caller, ciMethod* parse_method, float expected_uses);
380 
381   virtual Parse* is_Parse() const { return (Parse*)this; }
382 
383   // Accessors.
384   JVMState*     caller()        const { return _caller; }
385   float         expected_uses() const { return _expected_uses; }
386   float         prof_factor()   const { return _prof_factor; }
387   int           depth()         const { return _depth; }
388   const TypeFunc* tf()          const { return _tf; }
389   //            entry_bci()     -- see osr_bci, etc.
390 
391   ciTypeFlow*   flow()          const { return _flow; }
392   //            blocks()        -- see rpo_at, start_block, etc.
393   int           block_count()   const { return _block_count; }
394 
395   GraphKit&     exits()               { return _exits; }
396   bool          wrote_non_strict_final() const { return _wrote_non_strict_final; }
397   void      set_wrote_non_strict_final(bool z) { _wrote_non_strict_final = z; }
398   bool          wrote_volatile() const { return _wrote_volatile; }
399   void      set_wrote_volatile(bool z) { _wrote_volatile = z; }
400   bool          wrote_stable() const  { return _wrote_stable; }
401   void      set_wrote_stable(bool z)  { _wrote_stable = z; }
402   bool         wrote_fields() const   { return _wrote_fields; }
403   void     set_wrote_fields(bool z)   { _wrote_fields = z; }
404   Node*    alloc_with_final_or_stable() const   { return _alloc_with_final_or_stable; }
405   void set_alloc_with_final_or_stable(Node* n)  {
406     assert((_alloc_with_final_or_stable == nullptr) || (_alloc_with_final_or_stable == n), "different init objects?");
407     _alloc_with_final_or_stable = n;
408   }
409 
410   Block*             block()    const { return _block; }
411   ciBytecodeStream&  iter()           { return _iter; }
412   Bytecodes::Code    bc()       const { return _iter.cur_bc(); }
413 
414   void set_block(Block* b)            { _block = b; }
415 
416   // Derived accessors:
417   bool is_osr_parse() const {

426   // Must this parse be aborted?
427   bool failing() const { return C->failing_internal(); } // might have cascading effects, not stressing bailouts for now.
428 
429   Block* rpo_at(int rpo) {
430     assert(0 <= rpo && rpo < _block_count, "oob");
431     return &_blocks[rpo];
432   }
433   Block* start_block() {
434     return rpo_at(flow()->start_block()->rpo());
435   }
436   // Can return null if the flow pass did not complete a block.
437   Block* successor_for_bci(int bci) {
438     return block()->successor_for_bci(bci);
439   }
440 
441  private:
442   // Create a JVMS & map for the initial state of this method.
443   SafePointNode* create_entry_map();
444 
445   // OSR helpers
446   Node* fetch_interpreter_state(int index, const Type* type, Node* local_addrs);
447   Node* check_interpreter_type(Node* l, ciType* ci_type, SafePointNode* &bad_type_exit);
448   void  load_interpreter_state(Node* osr_buf);
449 
450   // Functions for managing basic blocks:
451   void init_blocks();
452   void load_state_from(Block* b);
453   void store_state_to(Block* b) { b->record_state(this); }
454 
455   // Parse all the basic blocks.
456   void do_all_blocks();
457 
458   // Parse the current basic block
459   void do_one_block();
460 
461   // Raise an error if we get a bad ciTypeFlow CFG.
462   void handle_missing_successor(int bci);
463 
464   // first actions (before BCI 0)
465   void do_method_entry();
466 
467   // implementation of monitorenter/monitorexit
468   void do_monitor_enter();
469   void do_monitor_exit();
470 
471   // Eagerly create phie throughout the state, to cope with back edges.
472   void ensure_phis_everywhere();
473 
474   // Merge the current mapping into the basic block starting at bci
475   void merge(          int target_bci);
476   // Same as plain merge, except that it allocates a new path number.
477   void merge_new_path( int target_bci);
478   // Push the exception oop and merge the current mapping into an exception handler.
479   void push_and_merge_exception(int target_bci, Node* ex_oop);
480   // Helper: Merge the current mapping into the given basic block
481   void merge_common(Block* target, int pnum);
482   // Helper functions for merging individual cells.
483   Node*    maybe_narrow_phi_input(Node* ctrl, Node* n, const Type* phi_type);
484   Node*    ensure_phi(       int idx, bool nocreate = false);
485   PhiNode* ensure_memory_phi(int idx, bool nocreate = false);
486   // Helper to merge the current memory state into the given basic block
487   void merge_memory_edges(MergeMemNode* n, int pnum, bool nophi);
488 
489   // Parse this bytecode, and alter the Parsers JVM->Node mapping
490   void do_one_bytecode();
491 
492   // helper function to generate array store check
493   Node* array_store_check(Node*& adr, const Type*& elemtype);
494   // Helper function to generate array load
495   void array_load(BasicType etype);
496   Node* load_from_unknown_flat_array(Node* array, Node* array_index, const TypeOopPtr* element_ptr);
497   // Helper function to generate array store
498   void array_store(BasicType etype);
499   void store_to_unknown_flat_array(Node* array, Node* idx, Node* non_null_stored_value);
500   // Helper function to compute array addressing
501   Node* prepare_array_addressing(BasicType type, int vals, const Type*& elemtype);
502   Node* get_ptr_to_array_element(Node* array, Node* idx, BasicType elembt, const TypeInt* sizetype, Node* control);
503   bool needs_range_check(const TypeInt* size_type, const Node* index) const;
504   Node* create_speculative_inline_type_array_checks(Node* array, const TypeAryPtr* array_type, const Type*& element_type);
505   Node* cast_to_speculative_array_type(Node* array, const TypeAryPtr*& array_type, const Type*& element_type);
506   Node* cast_to_profiled_array_type(Node* const array);
507   Node* speculate_non_null_free_array(Node* array, const TypeAryPtr*& array_type);
508   Node* speculate_non_flat_array(Node* array, const TypeAryPtr* array_type);
509   void create_range_check(Node* idx, Node* ary, const TypeInt* sizetype);
510   Node* record_profile_for_speculation_at_array_load(Node* ld);
511 
512   void clinit_deopt();
513 
514   // Pass current map to exits
515   void return_current(Node* value);
516 
517   // Register finalizers on return from Object.<init>
518   void call_register_finalizer();
519 
520   // Insert a compiler safepoint into the graph
521   void add_safepoint();
522 
523   // Insert a compiler safepoint into the graph, if there is a back-branch.
524   void maybe_add_safepoint(int target_bci) {
525     if (target_bci <= bci()) {
526       add_safepoint();
527     }
528   }
529 
530   // Note:  Intrinsic generation routines may be found in library_call.cpp.

536   bool can_not_compile_call_site(ciMethod *dest_method, ciInstanceKlass *klass);
537 
538   // Helper functions for type checking bytecodes:
539   void  do_checkcast();
540   void  do_instanceof();
541 
542   // Helper functions for shifting & arithmetic
543   Node* floating_point_mod(Node* a, Node* b, BasicType type);
544   void l2f();
545 
546   // implementation of _get* and _put* bytecodes
547   void do_getstatic() { do_field_access(true,  false); }
548   void do_getfield () { do_field_access(true,  true); }
549   void do_putstatic() { do_field_access(false, false); }
550   void do_putfield () { do_field_access(false, true); }
551 
552   // common code for making initial checks and forming addresses
553   void do_field_access(bool is_get, bool is_field);
554 
555   // common code for actually performing the load or store
556   void do_get_xxx(Node* obj, ciField* field);
557   void do_put_xxx(Node* obj, ciField* field, bool is_field);
558 
559   ciType* improve_abstract_inline_type_klass(ciType* field_klass);
560 
561   // implementation of object creation bytecodes
562   void do_new();
563   void do_newarray(BasicType elemtype);
564   void do_newarray();
565   void do_multianewarray();
566   Node* expand_multianewarray(ciArrayKlass* array_klass, Node* *lengths, int ndimensions, int nargs);
567 
568   // implementation of jsr/ret
569   void do_jsr();
570   void do_ret();
571 
572   float   dynamic_branch_prediction(float &cnt, BoolTest::mask btest, Node* test);
573   float   branch_prediction(float &cnt, BoolTest::mask btest, int target_bci, Node* test);
574   bool    seems_never_taken(float prob) const;
575   bool    path_is_suitable_for_uncommon_trap(float prob) const;
576 
577   void    do_ifnull(BoolTest::mask btest, Node* c);
578   void    do_if(BoolTest::mask btest, Node* c, bool can_trap = true, bool new_path = false, Node** ctrl_taken = nullptr,
579                 Node** mem_taken = nullptr, Node** id_taken = nullptr);
580   void    do_acmp(BoolTest::mask btest, Node* left, Node* right);
581   void    acmp_always_null_input(Node* input, const TypeOopPtr* tinput, BoolTest::mask btest, Node* eq_region);
582   void    acmp_type_check_or_trap(Node** non_null_input, ciKlass* input_type, Deoptimization::DeoptReason);
583   void    acmp_type_check(Node* input, const TypeOopPtr* tinput, ProfilePtrKind input_ptr, ciKlass* input_type, BoolTest::mask btest, Node* eq_region);
584   Node*   acmp_null_check(Node* input, const TypeOopPtr* tinput, ProfilePtrKind input_ptr, Node*& null_ctl);
585 public:
586   static IfNode* acmp_fast_path_if_from_substitutable_call(PhaseGVN* phase, CallStaticJavaNode* call);
587 private:
588   int     repush_if_args();
589   void    adjust_map_after_if(BoolTest::mask btest, Node* c, float prob, Block* path, bool can_trap = true);
590   void    sharpen_type_after_if(BoolTest::mask btest,
591                                 Node* con, const Type* tcon,
592                                 Node* val, const Type* tval);
593   void    maybe_add_predicate_after_if(Block* path);
594   IfNode* jump_if_fork_int(Node* a, Node* b, BoolTest::mask mask, float prob, float cnt);
595   void    jump_if_true_fork(IfNode *ifNode, int dest_bci_if_true, bool unc);
596   void    jump_if_false_fork(IfNode *ifNode, int dest_bci_if_false, bool unc);
597   void    jump_if_always_fork(int dest_bci_if_true, bool unc);
598 
599   friend class SwitchRange;
600   void    do_tableswitch();
601   void    do_lookupswitch();
602   void    jump_switch_ranges(Node* a, SwitchRange* lo, SwitchRange* hi, int depth = 0);
603   bool    create_jump_tables(Node* a, SwitchRange* lo, SwitchRange* hi);
604   void    linear_search_switch_ranges(Node* key_val, SwitchRange*& lo, SwitchRange*& hi);
605 
606   // helper function for call statistics
607   void count_compiled_calls(bool at_method_entry, bool is_inline) PRODUCT_RETURN;
608 
609   Node_Notes* make_node_notes(Node_Notes* caller_nn);
< prev index next >