< 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 CallStaticJavaNode;
  55 class CloneMap;
  56 class ConnectionGraph;
  57 class IdealGraphPrinter;
  58 class InlineTree;
  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 NodeHash;
  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 StartNode;
  81 class SafePointNode;
  82 class JVMState;
  83 class Type;
  84 class TypeInt;
  85 class TypeInteger;
  86 class TypeKlassPtr;
  87 class TypePtr;
  88 class TypeOopPtr;
  89 class TypeFunc;
  90 class TypeVect;
  91 class Type_Array;
  92 class Unique_Node_List;
  93 class UnstableIfTrap;

  94 class nmethod;
  95 class Node_Stack;
  96 struct Final_Reshape_Counts;
  97 class VerifyMeetResult;
  98 
  99 enum LoopOptsMode {
 100   LoopOptsDefault,
 101   LoopOptsNone,
 102   LoopOptsMaxUnroll,
 103   LoopOptsShenandoahExpand,
 104   LoopOptsShenandoahPostExpand,
 105   LoopOptsSkipSplitIf,
 106   LoopOptsVerify
 107 };
 108 
 109 // The type of all node counts and indexes.
 110 // It must hold at least 16 bits, but must also be fast to load and store.
 111 // This type, if less than 32 bits, could limit the number of possible nodes.
 112 // (To make this type platform-specific, move to globalDefinitions_xxx.hpp.)
 113 typedef unsigned int node_idx_t;

 303 
 304   // Control of this compilation.
 305   int                   _max_inline_size;       // Max inline size for this compilation
 306   int                   _freq_inline_size;      // Max hot method inline size for this compilation
 307   int                   _fixed_slots;           // count of frame slots not allocated by the register
 308                                                 // allocator i.e. locks, original deopt pc, etc.
 309   uintx                 _max_node_limit;        // Max unique node count during a single compilation.
 310 
 311   bool                  _post_loop_opts_phase;  // Loop opts are finished.
 312 
 313   int                   _major_progress;        // Count of something big happening
 314   bool                  _inlining_progress;     // progress doing incremental inlining?
 315   bool                  _inlining_incrementally;// Are we doing incremental inlining (post parse)
 316   bool                  _do_cleanup;            // Cleanup is needed before proceeding with incremental inlining
 317   bool                  _has_loops;             // True if the method _may_ have some loops
 318   bool                  _has_split_ifs;         // True if the method _may_ have some split-if
 319   bool                  _has_unsafe_access;     // True if the method _may_ produce faults in unsafe loads or stores.
 320   bool                  _has_stringbuilder;     // True StringBuffers or StringBuilders are allocated
 321   bool                  _has_boxed_value;       // True if a boxed object is allocated
 322   bool                  _has_reserved_stack_access; // True if the method or an inlined method is annotated with ReservedStackAccess

 323   uint                  _max_vector_size;       // Maximum size of generated vectors
 324   bool                  _clear_upper_avx;       // Clear upper bits of ymm registers using vzeroupper
 325   uint                  _trap_hist[trapHistLength];  // Cumulative traps
 326   bool                  _trap_can_recompile;    // Have we emitted a recompiling trap?
 327   uint                  _decompile_count;       // Cumulative decompilation counts.
 328   bool                  _do_inlining;           // True if we intend to do inlining
 329   bool                  _do_scheduling;         // True if we intend to do scheduling
 330   bool                  _do_freq_based_layout;  // True if we intend to do frequency based block layout
 331   bool                  _do_vector_loop;        // True if allowed to execute loop in parallel iterations
 332   bool                  _use_cmove;             // True if CMove should be used without profitability analysis
 333   bool                  _do_aliasing;           // True if we intend to do aliasing
 334   bool                  _print_assembly;        // True if we should dump assembly code for this compilation
 335   bool                  _print_inlining;        // True if we should print inlining for this compilation
 336   bool                  _print_intrinsics;      // True if we should print intrinsics for this compilation
 337 #ifndef PRODUCT
 338   uint                  _igv_idx;               // Counter for IGV node identifiers
 339   bool                  _trace_opto_output;
 340   bool                  _parsed_irreducible_loop; // True if ciTypeFlow detected irreducible loops during parsing
 341 #endif
 342   bool                  _has_irreducible_loop;  // Found irreducible loops
 343   // JSR 292
 344   bool                  _has_method_handle_invokes; // True if this method has MethodHandle invokes.
 345   bool                  _has_monitors;          // Metadata transfered to nmethod to enable Continuations lock-detection fastpath
 346   bool                  _clinit_barrier_on_entry; // True if clinit barrier is needed on nmethod entry
 347   RTMState              _rtm_state;             // State of Restricted Transactional Memory usage
 348   int                   _loop_opts_cnt;         // loop opts round



 349   uint                  _stress_seed;           // Seed for stress testing
 350 
 351   // Compilation environment.
 352   Arena                 _comp_arena;            // Arena with lifetime equivalent to Compile
 353   void*                 _barrier_set_state;     // Potential GC barrier state for Compile
 354   ciEnv*                _env;                   // CI interface
 355   DirectiveSet*         _directive;             // Compiler directive
 356   CompileLog*           _log;                   // from CompilerThread
 357   const char*           _failure_reason;        // for record_failure/failing pattern
 358   GrowableArray<CallGenerator*> _intrinsics;    // List of intrinsics.
 359   GrowableArray<Node*>  _macro_nodes;           // List of nodes which need to be expanded before matching.
 360   GrowableArray<Node*>  _parse_predicate_opaqs; // List of Opaque1 nodes for the Parse Predicates.
 361   GrowableArray<Node*>  _template_assertion_predicate_opaqs; // List of Opaque4 nodes for Template Assertion Predicates.
 362   GrowableArray<Node*>  _expensive_nodes;       // List of nodes that are expensive to compute and that we'd better not let the GVN freely common
 363   GrowableArray<Node*>  _for_post_loop_igvn;    // List of nodes for IGVN after loop opts are over

 364   GrowableArray<UnstableIfTrap*> _unstable_if_traps;        // List of ifnodes after IGVN
 365   GrowableArray<Node_List*> _coarsened_locks;   // List of coarsened Lock and Unlock nodes
 366   ConnectionGraph*      _congraph;
 367 #ifndef PRODUCT
 368   IdealGraphPrinter*    _igv_printer;
 369   static IdealGraphPrinter* _debug_file_printer;
 370   static IdealGraphPrinter* _debug_network_printer;
 371 #endif
 372 
 373 
 374   // Node management
 375   uint                  _unique;                // Counter for unique Node indices
 376   uint                  _dead_node_count;       // Number of dead nodes; VectorSet::Size() is O(N).
 377                                                 // So use this to keep count and make the call O(1).
 378   VectorSet             _dead_node_list;        // Set of dead nodes
 379   DEBUG_ONLY(Unique_Node_List* _modified_nodes;)   // List of nodes which inputs were modified
 380   DEBUG_ONLY(bool       _phase_optimize_finished;) // Used for live node verification while creating new nodes
 381 
 382   // Arenas for new-space and old-space nodes.
 383   // Swapped between using _node_arena.

 603   int               do_cleanup() const          { return _do_cleanup; }
 604   void          set_major_progress()            { _major_progress++; }
 605   void          restore_major_progress(int progress) { _major_progress += progress; }
 606   void        clear_major_progress()            { _major_progress = 0; }
 607   int               max_inline_size() const     { return _max_inline_size; }
 608   void          set_freq_inline_size(int n)     { _freq_inline_size = n; }
 609   int               freq_inline_size() const    { return _freq_inline_size; }
 610   void          set_max_inline_size(int n)      { _max_inline_size = n; }
 611   bool              has_loops() const           { return _has_loops; }
 612   void          set_has_loops(bool z)           { _has_loops = z; }
 613   bool              has_split_ifs() const       { return _has_split_ifs; }
 614   void          set_has_split_ifs(bool z)       { _has_split_ifs = z; }
 615   bool              has_unsafe_access() const   { return _has_unsafe_access; }
 616   void          set_has_unsafe_access(bool z)   { _has_unsafe_access = z; }
 617   bool              has_stringbuilder() const   { return _has_stringbuilder; }
 618   void          set_has_stringbuilder(bool z)   { _has_stringbuilder = z; }
 619   bool              has_boxed_value() const     { return _has_boxed_value; }
 620   void          set_has_boxed_value(bool z)     { _has_boxed_value = z; }
 621   bool              has_reserved_stack_access() const { return _has_reserved_stack_access; }
 622   void          set_has_reserved_stack_access(bool z) { _has_reserved_stack_access = z; }


 623   uint              max_vector_size() const     { return _max_vector_size; }
 624   void          set_max_vector_size(uint s)     { _max_vector_size = s; }
 625   bool              clear_upper_avx() const     { return _clear_upper_avx; }
 626   void          set_clear_upper_avx(bool s)     { _clear_upper_avx = s; }
 627   void          set_trap_count(uint r, uint c)  { assert(r < trapHistLength, "oob");        _trap_hist[r] = c; }
 628   uint              trap_count(uint r) const    { assert(r < trapHistLength, "oob"); return _trap_hist[r]; }
 629   bool              trap_can_recompile() const  { return _trap_can_recompile; }
 630   void          set_trap_can_recompile(bool z)  { _trap_can_recompile = z; }
 631   uint              decompile_count() const     { return _decompile_count; }
 632   void          set_decompile_count(uint c)     { _decompile_count = c; }
 633   bool              allow_range_check_smearing() const;
 634   bool              do_inlining() const         { return _do_inlining; }
 635   void          set_do_inlining(bool z)         { _do_inlining = z; }
 636   bool              do_scheduling() const       { return _do_scheduling; }
 637   void          set_do_scheduling(bool z)       { _do_scheduling = z; }
 638   bool              do_freq_based_layout() const{ return _do_freq_based_layout; }
 639   void          set_do_freq_based_layout(bool z){ _do_freq_based_layout = z; }
 640   bool              do_vector_loop() const      { return _do_vector_loop; }
 641   void          set_do_vector_loop(bool z)      { _do_vector_loop = z; }
 642   bool              use_cmove() const           { return _use_cmove; }
 643   void          set_use_cmove(bool z)           { _use_cmove = z; }
 644   bool              do_aliasing() const          { return _do_aliasing; }
 645   bool              print_assembly() const       { return _print_assembly; }
 646   void          set_print_assembly(bool z)       { _print_assembly = z; }
 647   bool              print_inlining() const       { return _print_inlining; }
 648   void          set_print_inlining(bool z)       { _print_inlining = z; }
 649   bool              print_intrinsics() const     { return _print_intrinsics; }
 650   void          set_print_intrinsics(bool z)     { _print_intrinsics = z; }
 651   RTMState          rtm_state()  const           { return _rtm_state; }
 652   void          set_rtm_state(RTMState s)        { _rtm_state = s; }
 653   bool              use_rtm() const              { return (_rtm_state & NoRTM) == 0; }
 654   bool          profile_rtm() const              { return _rtm_state == ProfileRTM; }
 655   uint              max_node_limit() const       { return (uint)_max_node_limit; }
 656   void          set_max_node_limit(uint n)       { _max_node_limit = n; }
 657   bool              clinit_barrier_on_entry()       { return _clinit_barrier_on_entry; }
 658   void          set_clinit_barrier_on_entry(bool z) { _clinit_barrier_on_entry = z; }










 659   bool              has_monitors() const         { return _has_monitors; }
 660   void          set_has_monitors(bool v)         { _has_monitors = v; }
 661 
 662   // check the CompilerOracle for special behaviours for this compile
 663   bool          method_has_option(enum CompileCommand option) {
 664     return method() != nullptr && method()->has_option(option);
 665   }
 666 
 667 #ifndef PRODUCT
 668   uint          next_igv_idx()                  { return _igv_idx++; }
 669   bool          trace_opto_output() const       { return _trace_opto_output; }
 670   void          print_ideal_ir(const char* phase_name);
 671   bool          should_print_ideal() const      { return _directive->PrintIdealOption; }
 672   bool              parsed_irreducible_loop() const { return _parsed_irreducible_loop; }
 673   void          set_parsed_irreducible_loop(bool z) { _parsed_irreducible_loop = z; }
 674   int _in_dump_cnt;  // Required for dumping ir nodes.
 675 #endif
 676   bool              has_irreducible_loop() const { return _has_irreducible_loop; }
 677   void          set_has_irreducible_loop(bool z) { _has_irreducible_loop = z; }
 678 

 751            "duplicate entry in template assertion predicate opaque4 list");
 752     _template_assertion_predicate_opaqs.append(n);
 753   }
 754   void remove_template_assertion_predicate_opaq(Node* n) {
 755     if (template_assertion_predicate_count() > 0) {
 756       _template_assertion_predicate_opaqs.remove_if_existing(n);
 757     }
 758   }
 759   void add_coarsened_locks(GrowableArray<AbstractLockNode*>& locks);
 760   void remove_coarsened_lock(Node* n);
 761   bool coarsened_locks_consistent();
 762 
 763   bool       post_loop_opts_phase() { return _post_loop_opts_phase;  }
 764   void   set_post_loop_opts_phase() { _post_loop_opts_phase = true;  }
 765   void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }
 766 
 767   void record_for_post_loop_opts_igvn(Node* n);
 768   void remove_from_post_loop_opts_igvn(Node* n);
 769   void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
 770 







 771   void record_unstable_if_trap(UnstableIfTrap* trap);
 772   bool remove_unstable_if_trap(CallStaticJavaNode* unc, bool yield);
 773   void remove_useless_unstable_if_traps(Unique_Node_List &useful);
 774   void process_for_unstable_if_traps(PhaseIterGVN& igvn);
 775 
 776   void sort_macro_nodes();
 777 
 778   // Remove the opaque nodes that protect the Parse Predicates so that the unused checks and
 779   // uncommon traps will be eliminated from the graph.
 780   void cleanup_parse_predicates(PhaseIterGVN &igvn) const;
 781   bool is_predicate_opaq(Node* n) const {
 782     return _parse_predicate_opaqs.contains(n);
 783   }
 784 
 785   // Are there candidate expensive nodes for optimization?
 786   bool should_optimize_expensive_nodes(PhaseIterGVN &igvn);
 787   // Check whether n1 and n2 are similar
 788   static int cmp_expensive_nodes(Node* n1, Node* n2);
 789   // Sort expensive nodes to locate similar expensive nodes
 790   void sort_expensive_nodes();

 893   Arena*            type_arena()                { return _type_arena; }
 894   Dict*             type_dict()                 { return _type_dict; }
 895   size_t            type_last_size()            { return _type_last_size; }
 896   int               num_alias_types()           { return _num_alias_types; }
 897 
 898   void          init_type_arena()                       { _type_arena = &_Compile_types; }
 899   void          set_type_arena(Arena* a)                { _type_arena = a; }
 900   void          set_type_dict(Dict* d)                  { _type_dict = d; }
 901   void          set_type_last_size(size_t sz)           { _type_last_size = sz; }
 902 
 903   const TypeFunc* last_tf(ciMethod* m) {
 904     return (m == _last_tf_m) ? _last_tf : nullptr;
 905   }
 906   void set_last_tf(ciMethod* m, const TypeFunc* tf) {
 907     assert(m != nullptr || tf == nullptr, "");
 908     _last_tf_m = m;
 909     _last_tf = tf;
 910   }
 911 
 912   AliasType*        alias_type(int                idx)  { assert(idx < num_alias_types(), "oob"); return _alias_types[idx]; }
 913   AliasType*        alias_type(const TypePtr* adr_type, ciField* field = nullptr) { return find_alias_type(adr_type, false, field); }
 914   bool         have_alias_type(const TypePtr* adr_type);
 915   AliasType*        alias_type(ciField*         field);
 916 
 917   int               get_alias_index(const TypePtr* at)  { return alias_type(at)->index(); }
 918   const TypePtr*    get_adr_type(uint aidx)             { return alias_type(aidx)->adr_type(); }
 919   int               get_general_index(uint aidx)        { return alias_type(aidx)->general_index(); }
 920 
 921   // Building nodes
 922   void              rethrow_exceptions(JVMState* jvms);
 923   void              return_values(JVMState* jvms);
 924   JVMState*         build_start_state(StartNode* start, const TypeFunc* tf);
 925 
 926   // Decide how to build a call.
 927   // The profile factor is a discount to apply to this site's interp. profile.
 928   CallGenerator*    call_generator(ciMethod* call_method, int vtable_index, bool call_does_dispatch,
 929                                    JVMState* jvms, bool allow_inline, float profile_factor, ciKlass* speculative_receiver_type = nullptr,
 930                                    bool allow_intrinsics = true);
 931   bool should_delay_inlining(ciMethod* call_method, JVMState* jvms) {
 932     return should_delay_string_inlining(call_method, jvms) ||
 933            should_delay_boxing_inlining(call_method, jvms) ||
 934            should_delay_vector_inlining(call_method, jvms);
 935   }
 936   bool should_delay_string_inlining(ciMethod* call_method, JVMState* jvms);
 937   bool should_delay_boxing_inlining(ciMethod* call_method, JVMState* jvms);

1139   // Number of outgoing stack slots killed above the out_preserve_stack_slots
1140   // for calls to C.  Supports the var-args backing area for register parms.
1141   uint varargs_C_out_slots_killed() const;
1142 
1143   // Number of Stack Slots consumed by a synchronization entry
1144   int sync_stack_slots() const;
1145 
1146   // Compute the name of old_SP.  See <arch>.ad for frame layout.
1147   OptoReg::Name compute_old_SP();
1148 
1149  private:
1150   // Phase control:
1151   void Init(bool aliasing);                      // Prepare for a single compilation
1152   void Optimize();                               // Given a graph, optimize it
1153   void Code_Gen();                               // Generate code from a graph
1154 
1155   // Management of the AliasType table.
1156   void grow_alias_types();
1157   AliasCacheEntry* probe_alias_cache(const TypePtr* adr_type);
1158   const TypePtr *flatten_alias_type(const TypePtr* adr_type) const;
1159   AliasType* find_alias_type(const TypePtr* adr_type, bool no_create, ciField* field);
1160 
1161   void verify_top(Node*) const PRODUCT_RETURN;
1162 
1163   // Intrinsic setup.
1164   CallGenerator* make_vm_intrinsic(ciMethod* m, bool is_virtual);          // constructor
1165   int            intrinsic_insertion_index(ciMethod* m, bool is_virtual, bool& found);  // helper
1166   CallGenerator* find_intrinsic(ciMethod* m, bool is_virtual);             // query fn
1167   void           register_intrinsic(CallGenerator* cg);                    // update fn
1168 
1169 #ifndef PRODUCT
1170   static juint  _intrinsic_hist_count[];
1171   static jubyte _intrinsic_hist_flags[];
1172 #endif
1173   // Function calls made by the public function final_graph_reshaping.
1174   // No need to be made public as they are not called elsewhere.
1175   void final_graph_reshaping_impl(Node *n, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1176   void final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop, Unique_Node_List& dead_nodes);
1177   void final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1178   void eliminate_redundant_card_marks(Node* n);
1179 

1215   // End-of-run dumps.
1216   static void print_statistics() PRODUCT_RETURN;
1217 
1218   // Verify ADLC assumptions during startup
1219   static void adlc_verification() PRODUCT_RETURN;
1220 
1221   // Definitions of pd methods
1222   static void pd_compiler2_init();
1223 
1224   // Static parse-time type checking logic for gen_subtype_check:
1225   enum SubTypeCheckResult { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
1226   SubTypeCheckResult static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip = StressReflectiveCode);
1227 
1228   static Node* conv_I2X_index(PhaseGVN* phase, Node* offset, const TypeInt* sizetype,
1229                               // Optional control dependency (for example, on range check)
1230                               Node* ctrl = nullptr);
1231 
1232   // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
1233   static Node* constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl, bool carry_dependency = false);
1234 
1235   // Auxiliary methods for randomized fuzzing/stressing


1236   int random();
1237   bool randomized_select(int count);
1238 
1239   // supporting clone_map
1240   CloneMap&     clone_map();
1241   void          set_clone_map(Dict* d);
1242 
1243   bool needs_clinit_barrier(ciField* ik,         ciMethod* accessing_method);
1244   bool needs_clinit_barrier(ciMethod* ik,        ciMethod* accessing_method);
1245   bool needs_clinit_barrier(ciInstanceKlass* ik, ciMethod* accessing_method);
1246 
1247 #ifdef IA32
1248  private:
1249   bool _select_24_bit_instr;   // We selected an instruction with a 24-bit result
1250   bool _in_24_bit_fp_mode;     // We are emitting instructions with 24-bit results
1251 
1252   // Remember if this compilation changes hardware mode to 24-bit precision.
1253   void set_24_bit_selection_and_mode(bool selection, bool mode) {
1254     _select_24_bit_instr = selection;
1255     _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 CallStaticJavaNode;
  56 class CloneMap;
  57 class ConnectionGraph;
  58 class IdealGraphPrinter;
  59 class InlineTree;
  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 NodeHash;
  71 class NodeCloneInfo;
  72 class OptoReg;
  73 class PhaseCFG;
  74 class PhaseGVN;
  75 class PhaseIterGVN;
  76 class PhaseRegAlloc;
  77 class PhaseCCP;
  78 class PhaseOutput;
  79 class RootNode;
  80 class relocInfo;
  81 class StartNode;
  82 class SafePointNode;
  83 class JVMState;
  84 class Type;
  85 class TypeInt;
  86 class TypeInteger;
  87 class TypeKlassPtr;
  88 class TypePtr;
  89 class TypeOopPtr;
  90 class TypeFunc;
  91 class TypeVect;
  92 class Type_Array;
  93 class Unique_Node_List;
  94 class UnstableIfTrap;
  95 class InlineTypeNode;
  96 class nmethod;
  97 class Node_Stack;
  98 struct Final_Reshape_Counts;
  99 class VerifyMeetResult;
 100 
 101 enum LoopOptsMode {
 102   LoopOptsDefault,
 103   LoopOptsNone,
 104   LoopOptsMaxUnroll,
 105   LoopOptsShenandoahExpand,
 106   LoopOptsShenandoahPostExpand,
 107   LoopOptsSkipSplitIf,
 108   LoopOptsVerify
 109 };
 110 
 111 // The type of all node counts and indexes.
 112 // It must hold at least 16 bits, but must also be fast to load and store.
 113 // This type, if less than 32 bits, could limit the number of possible nodes.
 114 // (To make this type platform-specific, move to globalDefinitions_xxx.hpp.)
 115 typedef unsigned int node_idx_t;

 305 
 306   // Control of this compilation.
 307   int                   _max_inline_size;       // Max inline size for this compilation
 308   int                   _freq_inline_size;      // Max hot method inline size for this compilation
 309   int                   _fixed_slots;           // count of frame slots not allocated by the register
 310                                                 // allocator i.e. locks, original deopt pc, etc.
 311   uintx                 _max_node_limit;        // Max unique node count during a single compilation.
 312 
 313   bool                  _post_loop_opts_phase;  // Loop opts are finished.
 314 
 315   int                   _major_progress;        // Count of something big happening
 316   bool                  _inlining_progress;     // progress doing incremental inlining?
 317   bool                  _inlining_incrementally;// Are we doing incremental inlining (post parse)
 318   bool                  _do_cleanup;            // Cleanup is needed before proceeding with incremental inlining
 319   bool                  _has_loops;             // True if the method _may_ have some loops
 320   bool                  _has_split_ifs;         // True if the method _may_ have some split-if
 321   bool                  _has_unsafe_access;     // True if the method _may_ produce faults in unsafe loads or stores.
 322   bool                  _has_stringbuilder;     // True StringBuffers or StringBuilders are allocated
 323   bool                  _has_boxed_value;       // True if a boxed object is allocated
 324   bool                  _has_reserved_stack_access; // True if the method or an inlined method is annotated with ReservedStackAccess
 325   bool                  _has_circular_inline_type; // True if method loads an inline type with a circular, non-flat field
 326   uint                  _max_vector_size;       // Maximum size of generated vectors
 327   bool                  _clear_upper_avx;       // Clear upper bits of ymm registers using vzeroupper
 328   uint                  _trap_hist[trapHistLength];  // Cumulative traps
 329   bool                  _trap_can_recompile;    // Have we emitted a recompiling trap?
 330   uint                  _decompile_count;       // Cumulative decompilation counts.
 331   bool                  _do_inlining;           // True if we intend to do inlining
 332   bool                  _do_scheduling;         // True if we intend to do scheduling
 333   bool                  _do_freq_based_layout;  // True if we intend to do frequency based block layout
 334   bool                  _do_vector_loop;        // True if allowed to execute loop in parallel iterations
 335   bool                  _use_cmove;             // True if CMove should be used without profitability analysis
 336   bool                  _do_aliasing;           // True if we intend to do aliasing
 337   bool                  _print_assembly;        // True if we should dump assembly code for this compilation
 338   bool                  _print_inlining;        // True if we should print inlining for this compilation
 339   bool                  _print_intrinsics;      // True if we should print intrinsics for this compilation
 340 #ifndef PRODUCT
 341   uint                  _igv_idx;               // Counter for IGV node identifiers
 342   bool                  _trace_opto_output;
 343   bool                  _parsed_irreducible_loop; // True if ciTypeFlow detected irreducible loops during parsing
 344 #endif
 345   bool                  _has_irreducible_loop;  // Found irreducible loops
 346   // JSR 292
 347   bool                  _has_method_handle_invokes; // True if this method has MethodHandle invokes.
 348   bool                  _has_monitors;          // Metadata transfered to nmethod to enable Continuations lock-detection fastpath
 349   bool                  _clinit_barrier_on_entry; // True if clinit barrier is needed on nmethod entry
 350   RTMState              _rtm_state;             // State of Restricted Transactional Memory usage
 351   int                   _loop_opts_cnt;         // loop opts round
 352   bool                  _has_flat_accesses;     // Any known flat array accesses?
 353   bool                  _flat_accesses_share_alias; // Initially all flat array share a single slice
 354   bool                  _scalarize_in_safepoints; // Scalarize inline types in safepoint debug info
 355   uint                  _stress_seed;           // Seed for stress testing
 356 
 357   // Compilation environment.
 358   Arena                 _comp_arena;            // Arena with lifetime equivalent to Compile
 359   void*                 _barrier_set_state;     // Potential GC barrier state for Compile
 360   ciEnv*                _env;                   // CI interface
 361   DirectiveSet*         _directive;             // Compiler directive
 362   CompileLog*           _log;                   // from CompilerThread
 363   const char*           _failure_reason;        // for record_failure/failing pattern
 364   GrowableArray<CallGenerator*> _intrinsics;    // List of intrinsics.
 365   GrowableArray<Node*>  _macro_nodes;           // List of nodes which need to be expanded before matching.
 366   GrowableArray<Node*>  _parse_predicate_opaqs; // List of Opaque1 nodes for the Parse Predicates.
 367   GrowableArray<Node*>  _template_assertion_predicate_opaqs; // List of Opaque4 nodes for Template Assertion Predicates.
 368   GrowableArray<Node*>  _expensive_nodes;       // List of nodes that are expensive to compute and that we'd better not let the GVN freely common
 369   GrowableArray<Node*>  _for_post_loop_igvn;    // List of nodes for IGVN after loop opts are over
 370   GrowableArray<Node*>  _inline_type_nodes;     // List of InlineType nodes
 371   GrowableArray<UnstableIfTrap*> _unstable_if_traps;        // List of ifnodes after IGVN
 372   GrowableArray<Node_List*> _coarsened_locks;   // List of coarsened Lock and Unlock nodes
 373   ConnectionGraph*      _congraph;
 374 #ifndef PRODUCT
 375   IdealGraphPrinter*    _igv_printer;
 376   static IdealGraphPrinter* _debug_file_printer;
 377   static IdealGraphPrinter* _debug_network_printer;
 378 #endif
 379 
 380 
 381   // Node management
 382   uint                  _unique;                // Counter for unique Node indices
 383   uint                  _dead_node_count;       // Number of dead nodes; VectorSet::Size() is O(N).
 384                                                 // So use this to keep count and make the call O(1).
 385   VectorSet             _dead_node_list;        // Set of dead nodes
 386   DEBUG_ONLY(Unique_Node_List* _modified_nodes;)   // List of nodes which inputs were modified
 387   DEBUG_ONLY(bool       _phase_optimize_finished;) // Used for live node verification while creating new nodes
 388 
 389   // Arenas for new-space and old-space nodes.
 390   // Swapped between using _node_arena.

 610   int               do_cleanup() const          { return _do_cleanup; }
 611   void          set_major_progress()            { _major_progress++; }
 612   void          restore_major_progress(int progress) { _major_progress += progress; }
 613   void        clear_major_progress()            { _major_progress = 0; }
 614   int               max_inline_size() const     { return _max_inline_size; }
 615   void          set_freq_inline_size(int n)     { _freq_inline_size = n; }
 616   int               freq_inline_size() const    { return _freq_inline_size; }
 617   void          set_max_inline_size(int n)      { _max_inline_size = n; }
 618   bool              has_loops() const           { return _has_loops; }
 619   void          set_has_loops(bool z)           { _has_loops = z; }
 620   bool              has_split_ifs() const       { return _has_split_ifs; }
 621   void          set_has_split_ifs(bool z)       { _has_split_ifs = z; }
 622   bool              has_unsafe_access() const   { return _has_unsafe_access; }
 623   void          set_has_unsafe_access(bool z)   { _has_unsafe_access = z; }
 624   bool              has_stringbuilder() const   { return _has_stringbuilder; }
 625   void          set_has_stringbuilder(bool z)   { _has_stringbuilder = z; }
 626   bool              has_boxed_value() const     { return _has_boxed_value; }
 627   void          set_has_boxed_value(bool z)     { _has_boxed_value = z; }
 628   bool              has_reserved_stack_access() const { return _has_reserved_stack_access; }
 629   void          set_has_reserved_stack_access(bool z) { _has_reserved_stack_access = z; }
 630   bool              has_circular_inline_type() const { return _has_circular_inline_type; }
 631   void          set_has_circular_inline_type(bool z) { _has_circular_inline_type = z; }
 632   uint              max_vector_size() const     { return _max_vector_size; }
 633   void          set_max_vector_size(uint s)     { _max_vector_size = s; }
 634   bool              clear_upper_avx() const     { return _clear_upper_avx; }
 635   void          set_clear_upper_avx(bool s)     { _clear_upper_avx = s; }
 636   void          set_trap_count(uint r, uint c)  { assert(r < trapHistLength, "oob");        _trap_hist[r] = c; }
 637   uint              trap_count(uint r) const    { assert(r < trapHistLength, "oob"); return _trap_hist[r]; }
 638   bool              trap_can_recompile() const  { return _trap_can_recompile; }
 639   void          set_trap_can_recompile(bool z)  { _trap_can_recompile = z; }
 640   uint              decompile_count() const     { return _decompile_count; }
 641   void          set_decompile_count(uint c)     { _decompile_count = c; }
 642   bool              allow_range_check_smearing() const;
 643   bool              do_inlining() const         { return _do_inlining; }
 644   void          set_do_inlining(bool z)         { _do_inlining = z; }
 645   bool              do_scheduling() const       { return _do_scheduling; }
 646   void          set_do_scheduling(bool z)       { _do_scheduling = z; }
 647   bool              do_freq_based_layout() const{ return _do_freq_based_layout; }
 648   void          set_do_freq_based_layout(bool z){ _do_freq_based_layout = z; }
 649   bool              do_vector_loop() const      { return _do_vector_loop; }
 650   void          set_do_vector_loop(bool z)      { _do_vector_loop = z; }
 651   bool              use_cmove() const           { return _use_cmove; }
 652   void          set_use_cmove(bool z)           { _use_cmove = z; }
 653   bool              do_aliasing() const          { return _do_aliasing; }
 654   bool              print_assembly() const       { return _print_assembly; }
 655   void          set_print_assembly(bool z)       { _print_assembly = z; }
 656   bool              print_inlining() const       { return _print_inlining; }
 657   void          set_print_inlining(bool z)       { _print_inlining = z; }
 658   bool              print_intrinsics() const     { return _print_intrinsics; }
 659   void          set_print_intrinsics(bool z)     { _print_intrinsics = z; }
 660   RTMState          rtm_state()  const           { return _rtm_state; }
 661   void          set_rtm_state(RTMState s)        { _rtm_state = s; }
 662   bool              use_rtm() const              { return (_rtm_state & NoRTM) == 0; }
 663   bool          profile_rtm() const              { return _rtm_state == ProfileRTM; }
 664   uint              max_node_limit() const       { return (uint)_max_node_limit; }
 665   void          set_max_node_limit(uint n)       { _max_node_limit = n; }
 666   bool              clinit_barrier_on_entry()       { return _clinit_barrier_on_entry; }
 667   void          set_clinit_barrier_on_entry(bool z) { _clinit_barrier_on_entry = z; }
 668   void          set_flat_accesses()              { _has_flat_accesses = true; }
 669   bool          flat_accesses_share_alias() const { return _flat_accesses_share_alias; }
 670   void          set_flat_accesses_share_alias(bool z) { _flat_accesses_share_alias = z; }
 671   bool          scalarize_in_safepoints() const { return _scalarize_in_safepoints; }
 672   void          set_scalarize_in_safepoints(bool z) { _scalarize_in_safepoints = z; }
 673 
 674   // Support for scalarized inline type calling convention
 675   bool              has_scalarized_args() const  { return _method != nullptr && _method->has_scalarized_args(); }
 676   bool              needs_stack_repair()  const  { return _method != nullptr && _method->get_Method()->c2_needs_stack_repair(); }
 677 
 678   bool              has_monitors() const         { return _has_monitors; }
 679   void          set_has_monitors(bool v)         { _has_monitors = v; }
 680 
 681   // check the CompilerOracle for special behaviours for this compile
 682   bool          method_has_option(enum CompileCommand option) {
 683     return method() != nullptr && method()->has_option(option);
 684   }
 685 
 686 #ifndef PRODUCT
 687   uint          next_igv_idx()                  { return _igv_idx++; }
 688   bool          trace_opto_output() const       { return _trace_opto_output; }
 689   void          print_ideal_ir(const char* phase_name);
 690   bool          should_print_ideal() const      { return _directive->PrintIdealOption; }
 691   bool              parsed_irreducible_loop() const { return _parsed_irreducible_loop; }
 692   void          set_parsed_irreducible_loop(bool z) { _parsed_irreducible_loop = z; }
 693   int _in_dump_cnt;  // Required for dumping ir nodes.
 694 #endif
 695   bool              has_irreducible_loop() const { return _has_irreducible_loop; }
 696   void          set_has_irreducible_loop(bool z) { _has_irreducible_loop = z; }
 697 

 770            "duplicate entry in template assertion predicate opaque4 list");
 771     _template_assertion_predicate_opaqs.append(n);
 772   }
 773   void remove_template_assertion_predicate_opaq(Node* n) {
 774     if (template_assertion_predicate_count() > 0) {
 775       _template_assertion_predicate_opaqs.remove_if_existing(n);
 776     }
 777   }
 778   void add_coarsened_locks(GrowableArray<AbstractLockNode*>& locks);
 779   void remove_coarsened_lock(Node* n);
 780   bool coarsened_locks_consistent();
 781 
 782   bool       post_loop_opts_phase() { return _post_loop_opts_phase;  }
 783   void   set_post_loop_opts_phase() { _post_loop_opts_phase = true;  }
 784   void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }
 785 
 786   void record_for_post_loop_opts_igvn(Node* n);
 787   void remove_from_post_loop_opts_igvn(Node* n);
 788   void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
 789 
 790   // Keep track of inline type nodes for later processing
 791   void add_inline_type(Node* n);
 792   void remove_inline_type(Node* n);
 793   void process_inline_types(PhaseIterGVN &igvn, bool remove = false);
 794 
 795   void adjust_flat_array_access_aliases(PhaseIterGVN& igvn);
 796 
 797   void record_unstable_if_trap(UnstableIfTrap* trap);
 798   bool remove_unstable_if_trap(CallStaticJavaNode* unc, bool yield);
 799   void remove_useless_unstable_if_traps(Unique_Node_List &useful);
 800   void process_for_unstable_if_traps(PhaseIterGVN& igvn);
 801 
 802   void sort_macro_nodes();
 803 
 804   // Remove the opaque nodes that protect the Parse Predicates so that the unused checks and
 805   // uncommon traps will be eliminated from the graph.
 806   void cleanup_parse_predicates(PhaseIterGVN &igvn) const;
 807   bool is_predicate_opaq(Node* n) const {
 808     return _parse_predicate_opaqs.contains(n);
 809   }
 810 
 811   // Are there candidate expensive nodes for optimization?
 812   bool should_optimize_expensive_nodes(PhaseIterGVN &igvn);
 813   // Check whether n1 and n2 are similar
 814   static int cmp_expensive_nodes(Node* n1, Node* n2);
 815   // Sort expensive nodes to locate similar expensive nodes
 816   void sort_expensive_nodes();

 919   Arena*            type_arena()                { return _type_arena; }
 920   Dict*             type_dict()                 { return _type_dict; }
 921   size_t            type_last_size()            { return _type_last_size; }
 922   int               num_alias_types()           { return _num_alias_types; }
 923 
 924   void          init_type_arena()                       { _type_arena = &_Compile_types; }
 925   void          set_type_arena(Arena* a)                { _type_arena = a; }
 926   void          set_type_dict(Dict* d)                  { _type_dict = d; }
 927   void          set_type_last_size(size_t sz)           { _type_last_size = sz; }
 928 
 929   const TypeFunc* last_tf(ciMethod* m) {
 930     return (m == _last_tf_m) ? _last_tf : nullptr;
 931   }
 932   void set_last_tf(ciMethod* m, const TypeFunc* tf) {
 933     assert(m != nullptr || tf == nullptr, "");
 934     _last_tf_m = m;
 935     _last_tf = tf;
 936   }
 937 
 938   AliasType*        alias_type(int                idx)  { assert(idx < num_alias_types(), "oob"); return _alias_types[idx]; }
 939   AliasType*        alias_type(const TypePtr* adr_type, ciField* field = nullptr, bool uncached = false) { return find_alias_type(adr_type, false, field, uncached); }
 940   bool         have_alias_type(const TypePtr* adr_type);
 941   AliasType*        alias_type(ciField*         field);
 942 
 943   int               get_alias_index(const TypePtr* at, bool uncached = false) { return alias_type(at, nullptr, uncached)->index(); }
 944   const TypePtr*    get_adr_type(uint aidx)             { return alias_type(aidx)->adr_type(); }
 945   int               get_general_index(uint aidx)        { return alias_type(aidx)->general_index(); }
 946 
 947   // Building nodes
 948   void              rethrow_exceptions(JVMState* jvms);
 949   void              return_values(JVMState* jvms);
 950   JVMState*         build_start_state(StartNode* start, const TypeFunc* tf);
 951 
 952   // Decide how to build a call.
 953   // The profile factor is a discount to apply to this site's interp. profile.
 954   CallGenerator*    call_generator(ciMethod* call_method, int vtable_index, bool call_does_dispatch,
 955                                    JVMState* jvms, bool allow_inline, float profile_factor, ciKlass* speculative_receiver_type = nullptr,
 956                                    bool allow_intrinsics = true);
 957   bool should_delay_inlining(ciMethod* call_method, JVMState* jvms) {
 958     return should_delay_string_inlining(call_method, jvms) ||
 959            should_delay_boxing_inlining(call_method, jvms) ||
 960            should_delay_vector_inlining(call_method, jvms);
 961   }
 962   bool should_delay_string_inlining(ciMethod* call_method, JVMState* jvms);
 963   bool should_delay_boxing_inlining(ciMethod* call_method, JVMState* jvms);

1165   // Number of outgoing stack slots killed above the out_preserve_stack_slots
1166   // for calls to C.  Supports the var-args backing area for register parms.
1167   uint varargs_C_out_slots_killed() const;
1168 
1169   // Number of Stack Slots consumed by a synchronization entry
1170   int sync_stack_slots() const;
1171 
1172   // Compute the name of old_SP.  See <arch>.ad for frame layout.
1173   OptoReg::Name compute_old_SP();
1174 
1175  private:
1176   // Phase control:
1177   void Init(bool aliasing);                      // Prepare for a single compilation
1178   void Optimize();                               // Given a graph, optimize it
1179   void Code_Gen();                               // Generate code from a graph
1180 
1181   // Management of the AliasType table.
1182   void grow_alias_types();
1183   AliasCacheEntry* probe_alias_cache(const TypePtr* adr_type);
1184   const TypePtr *flatten_alias_type(const TypePtr* adr_type) const;
1185   AliasType* find_alias_type(const TypePtr* adr_type, bool no_create, ciField* field, bool uncached = false);
1186 
1187   void verify_top(Node*) const PRODUCT_RETURN;
1188 
1189   // Intrinsic setup.
1190   CallGenerator* make_vm_intrinsic(ciMethod* m, bool is_virtual);          // constructor
1191   int            intrinsic_insertion_index(ciMethod* m, bool is_virtual, bool& found);  // helper
1192   CallGenerator* find_intrinsic(ciMethod* m, bool is_virtual);             // query fn
1193   void           register_intrinsic(CallGenerator* cg);                    // update fn
1194 
1195 #ifndef PRODUCT
1196   static juint  _intrinsic_hist_count[];
1197   static jubyte _intrinsic_hist_flags[];
1198 #endif
1199   // Function calls made by the public function final_graph_reshaping.
1200   // No need to be made public as they are not called elsewhere.
1201   void final_graph_reshaping_impl(Node *n, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1202   void final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop, Unique_Node_List& dead_nodes);
1203   void final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1204   void eliminate_redundant_card_marks(Node* n);
1205 

1241   // End-of-run dumps.
1242   static void print_statistics() PRODUCT_RETURN;
1243 
1244   // Verify ADLC assumptions during startup
1245   static void adlc_verification() PRODUCT_RETURN;
1246 
1247   // Definitions of pd methods
1248   static void pd_compiler2_init();
1249 
1250   // Static parse-time type checking logic for gen_subtype_check:
1251   enum SubTypeCheckResult { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
1252   SubTypeCheckResult static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip = StressReflectiveCode);
1253 
1254   static Node* conv_I2X_index(PhaseGVN* phase, Node* offset, const TypeInt* sizetype,
1255                               // Optional control dependency (for example, on range check)
1256                               Node* ctrl = nullptr);
1257 
1258   // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
1259   static Node* constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl, bool carry_dependency = false);
1260 
1261   Node* optimize_acmp(PhaseGVN* phase, Node* a, Node* b);
1262 
1263   // Auxiliary method for randomized fuzzing/stressing
1264   int random();
1265   bool randomized_select(int count);
1266 
1267   // supporting clone_map
1268   CloneMap&     clone_map();
1269   void          set_clone_map(Dict* d);
1270 
1271   bool needs_clinit_barrier(ciField* ik,         ciMethod* accessing_method);
1272   bool needs_clinit_barrier(ciMethod* ik,        ciMethod* accessing_method);
1273   bool needs_clinit_barrier(ciInstanceKlass* ik, ciMethod* accessing_method);
1274 
1275 #ifdef IA32
1276  private:
1277   bool _select_24_bit_instr;   // We selected an instruction with a 24-bit result
1278   bool _in_24_bit_fp_mode;     // We are emitting instructions with 24-bit results
1279 
1280   // Remember if this compilation changes hardware mode to 24-bit precision.
1281   void set_24_bit_selection_and_mode(bool selection, bool mode) {
1282     _select_24_bit_instr = selection;
1283     _in_24_bit_fp_mode   = mode;
< prev index next >