< prev index next >

src/hotspot/share/opto/compile.hpp

Print this page

  34 #include "compiler/compilerEvent.hpp"
  35 #include "libadt/dict.hpp"
  36 #include "libadt/vectset.hpp"
  37 #include "memory/resourceArea.hpp"
  38 #include "oops/methodData.hpp"
  39 #include "opto/idealGraphPrinter.hpp"
  40 #include "opto/phasetype.hpp"
  41 #include "opto/phase.hpp"
  42 #include "opto/regmask.hpp"
  43 #include "runtime/deoptimization.hpp"
  44 #include "runtime/sharedRuntime.hpp"
  45 #include "runtime/timerTrace.hpp"
  46 #include "runtime/vmThread.hpp"
  47 #include "utilities/ticks.hpp"
  48 
  49 class AbstractLockNode;
  50 class AddPNode;
  51 class Block;
  52 class Bundle;
  53 class CallGenerator;

  54 class CloneMap;
  55 class ConnectionGraph;
  56 class IdealGraphPrinter;
  57 class InlineTree;
  58 class Int_Array;
  59 class Matcher;
  60 class MachConstantNode;
  61 class MachConstantBaseNode;
  62 class MachNode;
  63 class MachOper;
  64 class MachSafePointNode;
  65 class Node;
  66 class Node_Array;
  67 class Node_List;
  68 class Node_Notes;
  69 class NodeCloneInfo;
  70 class OptoReg;
  71 class PhaseCFG;
  72 class PhaseGVN;
  73 class PhaseIterGVN;
  74 class PhaseRegAlloc;
  75 class PhaseCCP;
  76 class PhaseOutput;
  77 class RootNode;
  78 class relocInfo;
  79 class Scope;
  80 class StartNode;
  81 class SafePointNode;
  82 class JVMState;
  83 class Type;
  84 class TypeData;
  85 class TypeInt;
  86 class TypeInteger;
  87 class TypePtr;
  88 class TypeOopPtr;
  89 class TypeFunc;
  90 class TypeVect;
  91 class Unique_Node_List;

  92 class nmethod;
  93 class Node_Stack;
  94 struct Final_Reshape_Counts;
  95 
  96 enum LoopOptsMode {
  97   LoopOptsDefault,
  98   LoopOptsNone,
  99   LoopOptsMaxUnroll,
 100   LoopOptsShenandoahExpand,
 101   LoopOptsShenandoahPostExpand,
 102   LoopOptsSkipSplitIf,
 103   LoopOptsVerify
 104 };
 105 
 106 typedef unsigned int node_idx_t;
 107 class NodeCloneInfo {
 108  private:
 109   uint64_t _idx_clone_orig;
 110  public:
 111 

 288   bool                  _do_freq_based_layout;  // True if we intend to do frequency based block layout
 289   bool                  _do_vector_loop;        // True if allowed to execute loop in parallel iterations
 290   bool                  _use_cmove;             // True if CMove should be used without profitability analysis
 291   bool                  _age_code;              // True if we need to profile code age (decrement the aging counter)
 292   int                   _AliasLevel;            // Locally-adjusted version of AliasLevel flag.
 293   bool                  _print_assembly;        // True if we should dump assembly code for this compilation
 294   bool                  _print_inlining;        // True if we should print inlining for this compilation
 295   bool                  _print_intrinsics;      // True if we should print intrinsics for this compilation
 296 #ifndef PRODUCT
 297   uint                  _igv_idx;               // Counter for IGV node identifiers
 298   bool                  _trace_opto_output;
 299   bool                  _print_ideal;
 300   bool                  _parsed_irreducible_loop; // True if ciTypeFlow detected irreducible loops during parsing
 301 #endif
 302   bool                  _has_irreducible_loop;  // Found irreducible loops
 303   // JSR 292
 304   bool                  _has_method_handle_invokes; // True if this method has MethodHandle invokes.
 305   RTMState              _rtm_state;             // State of Restricted Transactional Memory usage
 306   int                   _loop_opts_cnt;         // loop opts round
 307   bool                  _clinit_barrier_on_entry; // True if clinit barrier is needed on nmethod entry



 308   uint                  _stress_seed;           // Seed for stress testing
 309 
 310   // Compilation environment.
 311   Arena                 _comp_arena;            // Arena with lifetime equivalent to Compile
 312   void*                 _barrier_set_state;     // Potential GC barrier state for Compile
 313   ciEnv*                _env;                   // CI interface
 314   DirectiveSet*         _directive;             // Compiler directive
 315   CompileLog*           _log;                   // from CompilerThread
 316   const char*           _failure_reason;        // for record_failure/failing pattern
 317   GrowableArray<CallGenerator*> _intrinsics;    // List of intrinsics.
 318   GrowableArray<Node*>  _macro_nodes;           // List of nodes which need to be expanded before matching.
 319   GrowableArray<Node*>  _predicate_opaqs;       // List of Opaque1 nodes for the loop predicates.
 320   GrowableArray<Node*>  _skeleton_predicate_opaqs; // List of Opaque4 nodes for the loop skeleton predicates.
 321   GrowableArray<Node*>  _expensive_nodes;       // List of nodes that are expensive to compute and that we'd better not let the GVN freely common
 322   GrowableArray<Node*>  _for_post_loop_igvn;    // List of nodes for IGVN after loop opts are over

 323   GrowableArray<Node_List*> _coarsened_locks;   // List of coarsened Lock and Unlock nodes
 324   ConnectionGraph*      _congraph;
 325 #ifndef PRODUCT
 326   IdealGraphPrinter*    _printer;
 327   static IdealGraphPrinter* _debug_file_printer;
 328   static IdealGraphPrinter* _debug_network_printer;
 329 #endif
 330 
 331 
 332   // Node management
 333   uint                  _unique;                // Counter for unique Node indices
 334   VectorSet             _dead_node_list;        // Set of dead nodes
 335   uint                  _dead_node_count;       // Number of dead nodes; VectorSet::Size() is O(N).
 336                                                 // So use this to keep count and make the call O(1).
 337   DEBUG_ONLY(Unique_Node_List* _modified_nodes;)   // List of nodes which inputs were modified
 338   DEBUG_ONLY(bool       _phase_optimize_finished;) // Used for live node verification while creating new nodes
 339 
 340   debug_only(static int _debug_idx;)            // Monotonic counter (not reset), use -XX:BreakAtNode=<idx>
 341   Arena                 _node_arena;            // Arena for new-space Nodes
 342   Arena                 _old_arena;             // Arena for old-space Nodes, lifetime during xform

 578   void          set_do_vector_loop(bool z)      { _do_vector_loop = z; }
 579   bool              use_cmove() const           { return _use_cmove; }
 580   void          set_use_cmove(bool z)           { _use_cmove = z; }
 581   bool              age_code() const             { return _age_code; }
 582   void          set_age_code(bool z)             { _age_code = z; }
 583   int               AliasLevel() const           { return _AliasLevel; }
 584   bool              print_assembly() const       { return _print_assembly; }
 585   void          set_print_assembly(bool z)       { _print_assembly = z; }
 586   bool              print_inlining() const       { return _print_inlining; }
 587   void          set_print_inlining(bool z)       { _print_inlining = z; }
 588   bool              print_intrinsics() const     { return _print_intrinsics; }
 589   void          set_print_intrinsics(bool z)     { _print_intrinsics = z; }
 590   RTMState          rtm_state()  const           { return _rtm_state; }
 591   void          set_rtm_state(RTMState s)        { _rtm_state = s; }
 592   bool              use_rtm() const              { return (_rtm_state & NoRTM) == 0; }
 593   bool          profile_rtm() const              { return _rtm_state == ProfileRTM; }
 594   uint              max_node_limit() const       { return (uint)_max_node_limit; }
 595   void          set_max_node_limit(uint n)       { _max_node_limit = n; }
 596   bool              clinit_barrier_on_entry()       { return _clinit_barrier_on_entry; }
 597   void          set_clinit_barrier_on_entry(bool z) { _clinit_barrier_on_entry = z; }









 598 
 599   // check the CompilerOracle for special behaviours for this compile
 600   bool          method_has_option(enum CompileCommand option) {
 601     return method() != NULL && method()->has_option(option);
 602   }
 603 
 604 #ifndef PRODUCT
 605   uint          next_igv_idx()                  { return _igv_idx++; }
 606   bool          trace_opto_output() const       { return _trace_opto_output; }
 607   bool          print_ideal() const             { return _print_ideal; }
 608   bool              parsed_irreducible_loop() const { return _parsed_irreducible_loop; }
 609   void          set_parsed_irreducible_loop(bool z) { _parsed_irreducible_loop = z; }
 610   int _in_dump_cnt;  // Required for dumping ir nodes.
 611 #endif
 612   bool              has_irreducible_loop() const { return _has_irreducible_loop; }
 613   void          set_has_irreducible_loop(bool z) { _has_irreducible_loop = z; }
 614 
 615   // JSR 292
 616   bool              has_method_handle_invokes() const { return _has_method_handle_invokes;     }
 617   void          set_has_method_handle_invokes(bool z) {        _has_method_handle_invokes = z; }

 702     assert(!_skeleton_predicate_opaqs.contains(n), "duplicate entry in skeleton predicate opaque4 list");
 703     _skeleton_predicate_opaqs.append(n);
 704   }
 705   void remove_skeleton_predicate_opaq(Node* n) {
 706     if (skeleton_predicate_count() > 0) {
 707       _skeleton_predicate_opaqs.remove_if_existing(n);
 708     }
 709   }
 710   void add_coarsened_locks(GrowableArray<AbstractLockNode*>& locks);
 711   void remove_coarsened_lock(Node* n);
 712   bool coarsened_locks_consistent();
 713 
 714   bool       post_loop_opts_phase() { return _post_loop_opts_phase;  }
 715   void   set_post_loop_opts_phase() { _post_loop_opts_phase = true;  }
 716   void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }
 717 
 718   void record_for_post_loop_opts_igvn(Node* n);
 719   void remove_from_post_loop_opts_igvn(Node* n);
 720   void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
 721 







 722   void sort_macro_nodes();
 723 
 724   // remove the opaque nodes that protect the predicates so that the unused checks and
 725   // uncommon traps will be eliminated from the graph.
 726   void cleanup_loop_predicates(PhaseIterGVN &igvn);
 727   bool is_predicate_opaq(Node* n) {
 728     return _predicate_opaqs.contains(n);
 729   }
 730 
 731   // Are there candidate expensive nodes for optimization?
 732   bool should_optimize_expensive_nodes(PhaseIterGVN &igvn);
 733   // Check whether n1 and n2 are similar
 734   static int cmp_expensive_nodes(Node* n1, Node* n2);
 735   // Sort expensive nodes to locate similar expensive nodes
 736   void sort_expensive_nodes();
 737 
 738   // Compilation environment.
 739   Arena*      comp_arena()           { return &_comp_arena; }
 740   ciEnv*      env() const            { return _env; }
 741   CompileLog* log() const            { return _log; }

 841   Arena*            type_arena()                { return _type_arena; }
 842   Dict*             type_dict()                 { return _type_dict; }
 843   size_t            type_last_size()            { return _type_last_size; }
 844   int               num_alias_types()           { return _num_alias_types; }
 845 
 846   void          init_type_arena()                       { _type_arena = &_Compile_types; }
 847   void          set_type_arena(Arena* a)                { _type_arena = a; }
 848   void          set_type_dict(Dict* d)                  { _type_dict = d; }
 849   void          set_type_last_size(size_t sz)           { _type_last_size = sz; }
 850 
 851   const TypeFunc* last_tf(ciMethod* m) {
 852     return (m == _last_tf_m) ? _last_tf : NULL;
 853   }
 854   void set_last_tf(ciMethod* m, const TypeFunc* tf) {
 855     assert(m != NULL || tf == NULL, "");
 856     _last_tf_m = m;
 857     _last_tf = tf;
 858   }
 859 
 860   AliasType*        alias_type(int                idx)  { assert(idx < num_alias_types(), "oob"); return _alias_types[idx]; }
 861   AliasType*        alias_type(const TypePtr* adr_type, ciField* field = NULL) { return find_alias_type(adr_type, false, field); }
 862   bool         have_alias_type(const TypePtr* adr_type);
 863   AliasType*        alias_type(ciField*         field);
 864 
 865   int               get_alias_index(const TypePtr* at)  { return alias_type(at)->index(); }
 866   const TypePtr*    get_adr_type(uint aidx)             { return alias_type(aidx)->adr_type(); }
 867   int               get_general_index(uint aidx)        { return alias_type(aidx)->general_index(); }
 868 
 869   // Building nodes
 870   void              rethrow_exceptions(JVMState* jvms);
 871   void              return_values(JVMState* jvms);
 872   JVMState*         build_start_state(StartNode* start, const TypeFunc* tf);
 873 
 874   // Decide how to build a call.
 875   // The profile factor is a discount to apply to this site's interp. profile.
 876   CallGenerator*    call_generator(ciMethod* call_method, int vtable_index, bool call_does_dispatch,
 877                                    JVMState* jvms, bool allow_inline, float profile_factor, ciKlass* speculative_receiver_type = NULL,
 878                                    bool allow_intrinsics = true);
 879   bool should_delay_inlining(ciMethod* call_method, JVMState* jvms) {
 880     return should_delay_string_inlining(call_method, jvms) ||
 881            should_delay_boxing_inlining(call_method, jvms) ||
 882            should_delay_vector_inlining(call_method, jvms);
 883   }
 884   bool should_delay_string_inlining(ciMethod* call_method, JVMState* jvms);
 885   bool should_delay_boxing_inlining(ciMethod* call_method, JVMState* jvms);

 915   // Return a bitset with the reasons where deoptimization is allowed,
 916   // i.e., where there were not too many uncommon traps.
 917   int _allowed_reasons;
 918   int      allowed_deopt_reasons() { return _allowed_reasons; }
 919   void set_allowed_deopt_reasons();
 920 
 921   // Parsing, optimization
 922   PhaseGVN*         initial_gvn()               { return _initial_gvn; }
 923   Unique_Node_List* for_igvn()                  { return _for_igvn; }
 924   inline void       record_for_igvn(Node* n);   // Body is after class Unique_Node_List.
 925   void          set_initial_gvn(PhaseGVN *gvn)           { _initial_gvn = gvn; }
 926   void          set_for_igvn(Unique_Node_List *for_igvn) { _for_igvn = for_igvn; }
 927 
 928   // Replace n by nn using initial_gvn, calling hash_delete and
 929   // record_for_igvn as needed.
 930   void gvn_replace_by(Node* n, Node* nn);
 931 
 932 
 933   void              identify_useful_nodes(Unique_Node_List &useful);
 934   void              update_dead_node_list(Unique_Node_List &useful);
 935   void              remove_useless_nodes (Unique_Node_List &useful);
 936 
 937   void              remove_useless_node(Node* dead);
 938 
 939   // Record this CallGenerator for inlining at the end of parsing.
 940   void              add_late_inline(CallGenerator* cg)        {
 941     _late_inlines.insert_before(_late_inlines_pos, cg);
 942     _late_inlines_pos++;
 943   }
 944 
 945   void              prepend_late_inline(CallGenerator* cg)    {
 946     _late_inlines.insert_before(0, cg);
 947   }
 948 
 949   void              add_string_late_inline(CallGenerator* cg) {
 950     _string_late_inlines.push(cg);
 951   }
 952 
 953   void              add_boxing_late_inline(CallGenerator* cg) {
 954     _boxing_late_inlines.push(cg);
 955   }

1080   uint varargs_C_out_slots_killed() const;
1081 
1082   // Number of Stack Slots consumed by a synchronization entry
1083   int sync_stack_slots() const;
1084 
1085   // Compute the name of old_SP.  See <arch>.ad for frame layout.
1086   OptoReg::Name compute_old_SP();
1087 
1088  private:
1089   // Phase control:
1090   void Init(int aliaslevel);                     // Prepare for a single compilation
1091   int  Inline_Warm();                            // Find more inlining work.
1092   void Finish_Warm();                            // Give up on further inlines.
1093   void Optimize();                               // Given a graph, optimize it
1094   void Code_Gen();                               // Generate code from a graph
1095 
1096   // Management of the AliasType table.
1097   void grow_alias_types();
1098   AliasCacheEntry* probe_alias_cache(const TypePtr* adr_type);
1099   const TypePtr *flatten_alias_type(const TypePtr* adr_type) const;
1100   AliasType* find_alias_type(const TypePtr* adr_type, bool no_create, ciField* field);
1101 
1102   void verify_top(Node*) const PRODUCT_RETURN;
1103 
1104   // Intrinsic setup.
1105   CallGenerator* make_vm_intrinsic(ciMethod* m, bool is_virtual);          // constructor
1106   int            intrinsic_insertion_index(ciMethod* m, bool is_virtual, bool& found);  // helper
1107   CallGenerator* find_intrinsic(ciMethod* m, bool is_virtual);             // query fn
1108   void           register_intrinsic(CallGenerator* cg);                    // update fn
1109 
1110 #ifndef PRODUCT
1111   static juint  _intrinsic_hist_count[];
1112   static jubyte _intrinsic_hist_flags[];
1113 #endif
1114   // Function calls made by the public function final_graph_reshaping.
1115   // No need to be made public as they are not called elsewhere.
1116   void final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc);
1117   void final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop);
1118   void final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &frc );
1119   void eliminate_redundant_card_marks(Node* n);
1120 

1153   // End-of-run dumps.
1154   static void print_statistics() PRODUCT_RETURN;
1155 
1156   // Verify ADLC assumptions during startup
1157   static void adlc_verification() PRODUCT_RETURN;
1158 
1159   // Definitions of pd methods
1160   static void pd_compiler2_init();
1161 
1162   // Static parse-time type checking logic for gen_subtype_check:
1163   enum { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
1164   int static_subtype_check(ciKlass* superk, ciKlass* subk);
1165 
1166   static Node* conv_I2X_index(PhaseGVN* phase, Node* offset, const TypeInt* sizetype,
1167                               // Optional control dependency (for example, on range check)
1168                               Node* ctrl = NULL);
1169 
1170   // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
1171   static Node* constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl, bool carry_dependency = false);
1172 
1173   // Auxiliary methods for randomized fuzzing/stressing


1174   int random();
1175   bool randomized_select(int count);
1176 
1177   // supporting clone_map
1178   CloneMap&     clone_map();
1179   void          set_clone_map(Dict* d);
1180 
1181   bool needs_clinit_barrier(ciField* ik,         ciMethod* accessing_method);
1182   bool needs_clinit_barrier(ciMethod* ik,        ciMethod* accessing_method);
1183   bool needs_clinit_barrier(ciInstanceKlass* ik, ciMethod* accessing_method);
1184 
1185 #ifdef IA32
1186  private:
1187   bool _select_24_bit_instr;   // We selected an instruction with a 24-bit result
1188   bool _in_24_bit_fp_mode;     // We are emitting instructions with 24-bit results
1189 
1190   // Remember if this compilation changes hardware mode to 24-bit precision.
1191   void set_24_bit_selection_and_mode(bool selection, bool mode) {
1192     _select_24_bit_instr = selection;
1193     _in_24_bit_fp_mode   = mode;

  34 #include "compiler/compilerEvent.hpp"
  35 #include "libadt/dict.hpp"
  36 #include "libadt/vectset.hpp"
  37 #include "memory/resourceArea.hpp"
  38 #include "oops/methodData.hpp"
  39 #include "opto/idealGraphPrinter.hpp"
  40 #include "opto/phasetype.hpp"
  41 #include "opto/phase.hpp"
  42 #include "opto/regmask.hpp"
  43 #include "runtime/deoptimization.hpp"
  44 #include "runtime/sharedRuntime.hpp"
  45 #include "runtime/timerTrace.hpp"
  46 #include "runtime/vmThread.hpp"
  47 #include "utilities/ticks.hpp"
  48 
  49 class AbstractLockNode;
  50 class AddPNode;
  51 class Block;
  52 class Bundle;
  53 class CallGenerator;
  54 class CallNode;
  55 class CloneMap;
  56 class ConnectionGraph;
  57 class IdealGraphPrinter;
  58 class InlineTree;
  59 class Int_Array;
  60 class Matcher;
  61 class MachConstantNode;
  62 class MachConstantBaseNode;
  63 class MachNode;
  64 class MachOper;
  65 class MachSafePointNode;
  66 class Node;
  67 class Node_Array;
  68 class Node_List;
  69 class Node_Notes;
  70 class NodeCloneInfo;
  71 class OptoReg;
  72 class PhaseCFG;
  73 class PhaseGVN;
  74 class PhaseIterGVN;
  75 class PhaseRegAlloc;
  76 class PhaseCCP;
  77 class PhaseOutput;
  78 class RootNode;
  79 class relocInfo;
  80 class Scope;
  81 class StartNode;
  82 class SafePointNode;
  83 class JVMState;
  84 class Type;
  85 class TypeData;
  86 class TypeInt;
  87 class TypeInteger;
  88 class TypePtr;
  89 class TypeOopPtr;
  90 class TypeFunc;
  91 class TypeVect;
  92 class Unique_Node_List;
  93 class InlineTypeBaseNode;
  94 class nmethod;
  95 class Node_Stack;
  96 struct Final_Reshape_Counts;
  97 
  98 enum LoopOptsMode {
  99   LoopOptsDefault,
 100   LoopOptsNone,
 101   LoopOptsMaxUnroll,
 102   LoopOptsShenandoahExpand,
 103   LoopOptsShenandoahPostExpand,
 104   LoopOptsSkipSplitIf,
 105   LoopOptsVerify
 106 };
 107 
 108 typedef unsigned int node_idx_t;
 109 class NodeCloneInfo {
 110  private:
 111   uint64_t _idx_clone_orig;
 112  public:
 113 

 290   bool                  _do_freq_based_layout;  // True if we intend to do frequency based block layout
 291   bool                  _do_vector_loop;        // True if allowed to execute loop in parallel iterations
 292   bool                  _use_cmove;             // True if CMove should be used without profitability analysis
 293   bool                  _age_code;              // True if we need to profile code age (decrement the aging counter)
 294   int                   _AliasLevel;            // Locally-adjusted version of AliasLevel flag.
 295   bool                  _print_assembly;        // True if we should dump assembly code for this compilation
 296   bool                  _print_inlining;        // True if we should print inlining for this compilation
 297   bool                  _print_intrinsics;      // True if we should print intrinsics for this compilation
 298 #ifndef PRODUCT
 299   uint                  _igv_idx;               // Counter for IGV node identifiers
 300   bool                  _trace_opto_output;
 301   bool                  _print_ideal;
 302   bool                  _parsed_irreducible_loop; // True if ciTypeFlow detected irreducible loops during parsing
 303 #endif
 304   bool                  _has_irreducible_loop;  // Found irreducible loops
 305   // JSR 292
 306   bool                  _has_method_handle_invokes; // True if this method has MethodHandle invokes.
 307   RTMState              _rtm_state;             // State of Restricted Transactional Memory usage
 308   int                   _loop_opts_cnt;         // loop opts round
 309   bool                  _clinit_barrier_on_entry; // True if clinit barrier is needed on nmethod entry
 310   bool                  _has_flattened_accesses; // Any known flattened array accesses?
 311   bool                  _flattened_accesses_share_alias; // Initially all flattened array share a single slice
 312   bool                  _scalarize_in_safepoints; // Scalarize inline types in safepoint debug info
 313   uint                  _stress_seed;           // Seed for stress testing
 314 
 315   // Compilation environment.
 316   Arena                 _comp_arena;            // Arena with lifetime equivalent to Compile
 317   void*                 _barrier_set_state;     // Potential GC barrier state for Compile
 318   ciEnv*                _env;                   // CI interface
 319   DirectiveSet*         _directive;             // Compiler directive
 320   CompileLog*           _log;                   // from CompilerThread
 321   const char*           _failure_reason;        // for record_failure/failing pattern
 322   GrowableArray<CallGenerator*> _intrinsics;    // List of intrinsics.
 323   GrowableArray<Node*>  _macro_nodes;           // List of nodes which need to be expanded before matching.
 324   GrowableArray<Node*>  _predicate_opaqs;       // List of Opaque1 nodes for the loop predicates.
 325   GrowableArray<Node*>  _skeleton_predicate_opaqs; // List of Opaque4 nodes for the loop skeleton predicates.
 326   GrowableArray<Node*>  _expensive_nodes;       // List of nodes that are expensive to compute and that we'd better not let the GVN freely common
 327   GrowableArray<Node*>  _for_post_loop_igvn;    // List of nodes for IGVN after loop opts are over
 328   GrowableArray<Node*>  _inline_type_nodes;     // List of InlineType nodes
 329   GrowableArray<Node_List*> _coarsened_locks;   // List of coarsened Lock and Unlock nodes
 330   ConnectionGraph*      _congraph;
 331 #ifndef PRODUCT
 332   IdealGraphPrinter*    _printer;
 333   static IdealGraphPrinter* _debug_file_printer;
 334   static IdealGraphPrinter* _debug_network_printer;
 335 #endif
 336 
 337 
 338   // Node management
 339   uint                  _unique;                // Counter for unique Node indices
 340   VectorSet             _dead_node_list;        // Set of dead nodes
 341   uint                  _dead_node_count;       // Number of dead nodes; VectorSet::Size() is O(N).
 342                                                 // So use this to keep count and make the call O(1).
 343   DEBUG_ONLY(Unique_Node_List* _modified_nodes;)   // List of nodes which inputs were modified
 344   DEBUG_ONLY(bool       _phase_optimize_finished;) // Used for live node verification while creating new nodes
 345 
 346   debug_only(static int _debug_idx;)            // Monotonic counter (not reset), use -XX:BreakAtNode=<idx>
 347   Arena                 _node_arena;            // Arena for new-space Nodes
 348   Arena                 _old_arena;             // Arena for old-space Nodes, lifetime during xform

 584   void          set_do_vector_loop(bool z)      { _do_vector_loop = z; }
 585   bool              use_cmove() const           { return _use_cmove; }
 586   void          set_use_cmove(bool z)           { _use_cmove = z; }
 587   bool              age_code() const             { return _age_code; }
 588   void          set_age_code(bool z)             { _age_code = z; }
 589   int               AliasLevel() const           { return _AliasLevel; }
 590   bool              print_assembly() const       { return _print_assembly; }
 591   void          set_print_assembly(bool z)       { _print_assembly = z; }
 592   bool              print_inlining() const       { return _print_inlining; }
 593   void          set_print_inlining(bool z)       { _print_inlining = z; }
 594   bool              print_intrinsics() const     { return _print_intrinsics; }
 595   void          set_print_intrinsics(bool z)     { _print_intrinsics = z; }
 596   RTMState          rtm_state()  const           { return _rtm_state; }
 597   void          set_rtm_state(RTMState s)        { _rtm_state = s; }
 598   bool              use_rtm() const              { return (_rtm_state & NoRTM) == 0; }
 599   bool          profile_rtm() const              { return _rtm_state == ProfileRTM; }
 600   uint              max_node_limit() const       { return (uint)_max_node_limit; }
 601   void          set_max_node_limit(uint n)       { _max_node_limit = n; }
 602   bool              clinit_barrier_on_entry()       { return _clinit_barrier_on_entry; }
 603   void          set_clinit_barrier_on_entry(bool z) { _clinit_barrier_on_entry = z; }
 604   void          set_flattened_accesses()         { _has_flattened_accesses = true; }
 605   bool          flattened_accesses_share_alias() const { return _flattened_accesses_share_alias; }
 606   void          set_flattened_accesses_share_alias(bool z) { _flattened_accesses_share_alias = z; }
 607   bool          scalarize_in_safepoints() const { return _scalarize_in_safepoints; }
 608   void          set_scalarize_in_safepoints(bool z) { _scalarize_in_safepoints = z; }
 609 
 610   // Support for scalarized inline type calling convention
 611   bool              has_scalarized_args() const  { return _method != NULL && _method->has_scalarized_args(); }
 612   bool              needs_stack_repair()  const  { return _method != NULL && _method->get_Method()->c2_needs_stack_repair(); }
 613 
 614   // check the CompilerOracle for special behaviours for this compile
 615   bool          method_has_option(enum CompileCommand option) {
 616     return method() != NULL && method()->has_option(option);
 617   }
 618 
 619 #ifndef PRODUCT
 620   uint          next_igv_idx()                  { return _igv_idx++; }
 621   bool          trace_opto_output() const       { return _trace_opto_output; }
 622   bool          print_ideal() const             { return _print_ideal; }
 623   bool              parsed_irreducible_loop() const { return _parsed_irreducible_loop; }
 624   void          set_parsed_irreducible_loop(bool z) { _parsed_irreducible_loop = z; }
 625   int _in_dump_cnt;  // Required for dumping ir nodes.
 626 #endif
 627   bool              has_irreducible_loop() const { return _has_irreducible_loop; }
 628   void          set_has_irreducible_loop(bool z) { _has_irreducible_loop = z; }
 629 
 630   // JSR 292
 631   bool              has_method_handle_invokes() const { return _has_method_handle_invokes;     }
 632   void          set_has_method_handle_invokes(bool z) {        _has_method_handle_invokes = z; }

 717     assert(!_skeleton_predicate_opaqs.contains(n), "duplicate entry in skeleton predicate opaque4 list");
 718     _skeleton_predicate_opaqs.append(n);
 719   }
 720   void remove_skeleton_predicate_opaq(Node* n) {
 721     if (skeleton_predicate_count() > 0) {
 722       _skeleton_predicate_opaqs.remove_if_existing(n);
 723     }
 724   }
 725   void add_coarsened_locks(GrowableArray<AbstractLockNode*>& locks);
 726   void remove_coarsened_lock(Node* n);
 727   bool coarsened_locks_consistent();
 728 
 729   bool       post_loop_opts_phase() { return _post_loop_opts_phase;  }
 730   void   set_post_loop_opts_phase() { _post_loop_opts_phase = true;  }
 731   void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }
 732 
 733   void record_for_post_loop_opts_igvn(Node* n);
 734   void remove_from_post_loop_opts_igvn(Node* n);
 735   void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
 736 
 737   // Keep track of inline type nodes for later processing
 738   void add_inline_type(Node* n);
 739   void remove_inline_type(Node* n);
 740   void process_inline_types(PhaseIterGVN &igvn, bool remove = false);
 741 
 742   void adjust_flattened_array_access_aliases(PhaseIterGVN& igvn);
 743 
 744   void sort_macro_nodes();
 745 
 746   // remove the opaque nodes that protect the predicates so that the unused checks and
 747   // uncommon traps will be eliminated from the graph.
 748   void cleanup_loop_predicates(PhaseIterGVN &igvn);
 749   bool is_predicate_opaq(Node* n) {
 750     return _predicate_opaqs.contains(n);
 751   }
 752 
 753   // Are there candidate expensive nodes for optimization?
 754   bool should_optimize_expensive_nodes(PhaseIterGVN &igvn);
 755   // Check whether n1 and n2 are similar
 756   static int cmp_expensive_nodes(Node* n1, Node* n2);
 757   // Sort expensive nodes to locate similar expensive nodes
 758   void sort_expensive_nodes();
 759 
 760   // Compilation environment.
 761   Arena*      comp_arena()           { return &_comp_arena; }
 762   ciEnv*      env() const            { return _env; }
 763   CompileLog* log() const            { return _log; }

 863   Arena*            type_arena()                { return _type_arena; }
 864   Dict*             type_dict()                 { return _type_dict; }
 865   size_t            type_last_size()            { return _type_last_size; }
 866   int               num_alias_types()           { return _num_alias_types; }
 867 
 868   void          init_type_arena()                       { _type_arena = &_Compile_types; }
 869   void          set_type_arena(Arena* a)                { _type_arena = a; }
 870   void          set_type_dict(Dict* d)                  { _type_dict = d; }
 871   void          set_type_last_size(size_t sz)           { _type_last_size = sz; }
 872 
 873   const TypeFunc* last_tf(ciMethod* m) {
 874     return (m == _last_tf_m) ? _last_tf : NULL;
 875   }
 876   void set_last_tf(ciMethod* m, const TypeFunc* tf) {
 877     assert(m != NULL || tf == NULL, "");
 878     _last_tf_m = m;
 879     _last_tf = tf;
 880   }
 881 
 882   AliasType*        alias_type(int                idx)  { assert(idx < num_alias_types(), "oob"); return _alias_types[idx]; }
 883   AliasType*        alias_type(const TypePtr* adr_type, ciField* field = NULL, bool uncached = false) { return find_alias_type(adr_type, false, field, uncached); }
 884   bool         have_alias_type(const TypePtr* adr_type);
 885   AliasType*        alias_type(ciField*         field);
 886 
 887   int               get_alias_index(const TypePtr* at, bool uncached = false) { return alias_type(at, NULL, uncached)->index(); }
 888   const TypePtr*    get_adr_type(uint aidx)             { return alias_type(aidx)->adr_type(); }
 889   int               get_general_index(uint aidx)        { return alias_type(aidx)->general_index(); }
 890 
 891   // Building nodes
 892   void              rethrow_exceptions(JVMState* jvms);
 893   void              return_values(JVMState* jvms);
 894   JVMState*         build_start_state(StartNode* start, const TypeFunc* tf);
 895 
 896   // Decide how to build a call.
 897   // The profile factor is a discount to apply to this site's interp. profile.
 898   CallGenerator*    call_generator(ciMethod* call_method, int vtable_index, bool call_does_dispatch,
 899                                    JVMState* jvms, bool allow_inline, float profile_factor, ciKlass* speculative_receiver_type = NULL,
 900                                    bool allow_intrinsics = true);
 901   bool should_delay_inlining(ciMethod* call_method, JVMState* jvms) {
 902     return should_delay_string_inlining(call_method, jvms) ||
 903            should_delay_boxing_inlining(call_method, jvms) ||
 904            should_delay_vector_inlining(call_method, jvms);
 905   }
 906   bool should_delay_string_inlining(ciMethod* call_method, JVMState* jvms);
 907   bool should_delay_boxing_inlining(ciMethod* call_method, JVMState* jvms);

 937   // Return a bitset with the reasons where deoptimization is allowed,
 938   // i.e., where there were not too many uncommon traps.
 939   int _allowed_reasons;
 940   int      allowed_deopt_reasons() { return _allowed_reasons; }
 941   void set_allowed_deopt_reasons();
 942 
 943   // Parsing, optimization
 944   PhaseGVN*         initial_gvn()               { return _initial_gvn; }
 945   Unique_Node_List* for_igvn()                  { return _for_igvn; }
 946   inline void       record_for_igvn(Node* n);   // Body is after class Unique_Node_List.
 947   void          set_initial_gvn(PhaseGVN *gvn)           { _initial_gvn = gvn; }
 948   void          set_for_igvn(Unique_Node_List *for_igvn) { _for_igvn = for_igvn; }
 949 
 950   // Replace n by nn using initial_gvn, calling hash_delete and
 951   // record_for_igvn as needed.
 952   void gvn_replace_by(Node* n, Node* nn);
 953 
 954 
 955   void              identify_useful_nodes(Unique_Node_List &useful);
 956   void              update_dead_node_list(Unique_Node_List &useful);
 957   void              disconnect_useless_nodes(Unique_Node_List &useful, Unique_Node_List* worklist);
 958 
 959   void              remove_useless_node(Node* dead);
 960 
 961   // Record this CallGenerator for inlining at the end of parsing.
 962   void              add_late_inline(CallGenerator* cg)        {
 963     _late_inlines.insert_before(_late_inlines_pos, cg);
 964     _late_inlines_pos++;
 965   }
 966 
 967   void              prepend_late_inline(CallGenerator* cg)    {
 968     _late_inlines.insert_before(0, cg);
 969   }
 970 
 971   void              add_string_late_inline(CallGenerator* cg) {
 972     _string_late_inlines.push(cg);
 973   }
 974 
 975   void              add_boxing_late_inline(CallGenerator* cg) {
 976     _boxing_late_inlines.push(cg);
 977   }

1102   uint varargs_C_out_slots_killed() const;
1103 
1104   // Number of Stack Slots consumed by a synchronization entry
1105   int sync_stack_slots() const;
1106 
1107   // Compute the name of old_SP.  See <arch>.ad for frame layout.
1108   OptoReg::Name compute_old_SP();
1109 
1110  private:
1111   // Phase control:
1112   void Init(int aliaslevel);                     // Prepare for a single compilation
1113   int  Inline_Warm();                            // Find more inlining work.
1114   void Finish_Warm();                            // Give up on further inlines.
1115   void Optimize();                               // Given a graph, optimize it
1116   void Code_Gen();                               // Generate code from a graph
1117 
1118   // Management of the AliasType table.
1119   void grow_alias_types();
1120   AliasCacheEntry* probe_alias_cache(const TypePtr* adr_type);
1121   const TypePtr *flatten_alias_type(const TypePtr* adr_type) const;
1122   AliasType* find_alias_type(const TypePtr* adr_type, bool no_create, ciField* field, bool uncached = false);
1123 
1124   void verify_top(Node*) const PRODUCT_RETURN;
1125 
1126   // Intrinsic setup.
1127   CallGenerator* make_vm_intrinsic(ciMethod* m, bool is_virtual);          // constructor
1128   int            intrinsic_insertion_index(ciMethod* m, bool is_virtual, bool& found);  // helper
1129   CallGenerator* find_intrinsic(ciMethod* m, bool is_virtual);             // query fn
1130   void           register_intrinsic(CallGenerator* cg);                    // update fn
1131 
1132 #ifndef PRODUCT
1133   static juint  _intrinsic_hist_count[];
1134   static jubyte _intrinsic_hist_flags[];
1135 #endif
1136   // Function calls made by the public function final_graph_reshaping.
1137   // No need to be made public as they are not called elsewhere.
1138   void final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc);
1139   void final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop);
1140   void final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &frc );
1141   void eliminate_redundant_card_marks(Node* n);
1142 

1175   // End-of-run dumps.
1176   static void print_statistics() PRODUCT_RETURN;
1177 
1178   // Verify ADLC assumptions during startup
1179   static void adlc_verification() PRODUCT_RETURN;
1180 
1181   // Definitions of pd methods
1182   static void pd_compiler2_init();
1183 
1184   // Static parse-time type checking logic for gen_subtype_check:
1185   enum { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
1186   int static_subtype_check(ciKlass* superk, ciKlass* subk);
1187 
1188   static Node* conv_I2X_index(PhaseGVN* phase, Node* offset, const TypeInt* sizetype,
1189                               // Optional control dependency (for example, on range check)
1190                               Node* ctrl = NULL);
1191 
1192   // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
1193   static Node* constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl, bool carry_dependency = false);
1194 
1195   Node* optimize_acmp(PhaseGVN* phase, Node* a, Node* b);
1196 
1197   // Auxiliary method for randomized fuzzing/stressing
1198   int random();
1199   bool randomized_select(int count);
1200 
1201   // supporting clone_map
1202   CloneMap&     clone_map();
1203   void          set_clone_map(Dict* d);
1204 
1205   bool needs_clinit_barrier(ciField* ik,         ciMethod* accessing_method);
1206   bool needs_clinit_barrier(ciMethod* ik,        ciMethod* accessing_method);
1207   bool needs_clinit_barrier(ciInstanceKlass* ik, ciMethod* accessing_method);
1208 
1209 #ifdef IA32
1210  private:
1211   bool _select_24_bit_instr;   // We selected an instruction with a 24-bit result
1212   bool _in_24_bit_fp_mode;     // We are emitting instructions with 24-bit results
1213 
1214   // Remember if this compilation changes hardware mode to 24-bit precision.
1215   void set_24_bit_selection_and_mode(bool selection, bool mode) {
1216     _select_24_bit_instr = selection;
1217     _in_24_bit_fp_mode   = mode;
< prev index next >