< 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 ParsePredicateNode;
  73 class PhaseCFG;

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

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

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



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

 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.

 616   int               do_cleanup() const          { return _do_cleanup; }
 617   void          set_major_progress()            { _major_progress++; }
 618   void          restore_major_progress(int progress) { _major_progress += progress; }
 619   void        clear_major_progress()            { _major_progress = 0; }
 620   int               max_inline_size() const     { return _max_inline_size; }
 621   void          set_freq_inline_size(int n)     { _freq_inline_size = n; }
 622   int               freq_inline_size() const    { return _freq_inline_size; }
 623   void          set_max_inline_size(int n)      { _max_inline_size = n; }
 624   bool              has_loops() const           { return _has_loops; }
 625   void          set_has_loops(bool z)           { _has_loops = z; }
 626   bool              has_split_ifs() const       { return _has_split_ifs; }
 627   void          set_has_split_ifs(bool z)       { _has_split_ifs = z; }
 628   bool              has_unsafe_access() const   { return _has_unsafe_access; }
 629   void          set_has_unsafe_access(bool z)   { _has_unsafe_access = z; }
 630   bool              has_stringbuilder() const   { return _has_stringbuilder; }
 631   void          set_has_stringbuilder(bool z)   { _has_stringbuilder = z; }
 632   bool              has_boxed_value() const     { return _has_boxed_value; }
 633   void          set_has_boxed_value(bool z)     { _has_boxed_value = z; }
 634   bool              has_reserved_stack_access() const { return _has_reserved_stack_access; }
 635   void          set_has_reserved_stack_access(bool z) { _has_reserved_stack_access = z; }


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










 672   bool              has_monitors() const         { return _has_monitors; }
 673   void          set_has_monitors(bool v)         { _has_monitors = v; }
 674 
 675   // check the CompilerOracle for special behaviours for this compile
 676   bool          method_has_option(enum CompileCommand option) {
 677     return method() != nullptr && method()->has_option(option);
 678   }
 679 
 680 #ifndef PRODUCT
 681   uint          next_igv_idx()                  { return _igv_idx++; }
 682   bool          trace_opto_output() const       { return _trace_opto_output; }
 683   void          print_ideal_ir(const char* phase_name);
 684   bool          should_print_ideal() const      { return _directive->PrintIdealOption; }
 685   bool              parsed_irreducible_loop() const { return _parsed_irreducible_loop; }
 686   void          set_parsed_irreducible_loop(bool z) { _parsed_irreducible_loop = z; }
 687   int _in_dump_cnt;  // Required for dumping ir nodes.
 688 #endif
 689   bool              has_irreducible_loop() const { return _has_irreducible_loop; }
 690   void          set_has_irreducible_loop(bool z) { _has_irreducible_loop = z; }
 691 

 768     _template_assertion_predicate_opaqs.append(n);
 769   }
 770 
 771   void remove_template_assertion_predicate_opaq(Node* n) {
 772     if (template_assertion_predicate_count() > 0) {
 773       _template_assertion_predicate_opaqs.remove_if_existing(n);
 774     }
 775   }
 776   void add_coarsened_locks(GrowableArray<AbstractLockNode*>& locks);
 777   void remove_coarsened_lock(Node* n);
 778   bool coarsened_locks_consistent();
 779 
 780   bool       post_loop_opts_phase() { return _post_loop_opts_phase;  }
 781   void   set_post_loop_opts_phase() { _post_loop_opts_phase = true;  }
 782   void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }
 783 
 784   void record_for_post_loop_opts_igvn(Node* n);
 785   void remove_from_post_loop_opts_igvn(Node* n);
 786   void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
 787 







 788   void record_unstable_if_trap(UnstableIfTrap* trap);
 789   bool remove_unstable_if_trap(CallStaticJavaNode* unc, bool yield);
 790   void remove_useless_unstable_if_traps(Unique_Node_List &useful);
 791   void process_for_unstable_if_traps(PhaseIterGVN& igvn);
 792 
 793   void sort_macro_nodes();
 794 
 795   void mark_parse_predicate_nodes_useless(PhaseIterGVN& igvn);
 796 
 797   // Are there candidate expensive nodes for optimization?
 798   bool should_optimize_expensive_nodes(PhaseIterGVN &igvn);
 799   // Check whether n1 and n2 are similar
 800   static int cmp_expensive_nodes(Node* n1, Node* n2);
 801   // Sort expensive nodes to locate similar expensive nodes
 802   void sort_expensive_nodes();
 803 
 804   // Compilation environment.
 805   Arena*      comp_arena()           { return &_comp_arena; }
 806   ciEnv*      env() const            { return _env; }
 807   CompileLog* log() const            { return _log; }

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

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

1235   // End-of-run dumps.
1236   static void print_statistics() PRODUCT_RETURN;
1237 
1238   // Verify ADLC assumptions during startup
1239   static void adlc_verification() PRODUCT_RETURN;
1240 
1241   // Definitions of pd methods
1242   static void pd_compiler2_init();
1243 
1244   // Static parse-time type checking logic for gen_subtype_check:
1245   enum SubTypeCheckResult { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
1246   SubTypeCheckResult static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip = StressReflectiveCode);
1247 
1248   static Node* conv_I2X_index(PhaseGVN* phase, Node* offset, const TypeInt* sizetype,
1249                               // Optional control dependency (for example, on range check)
1250                               Node* ctrl = nullptr);
1251 
1252   // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
1253   static Node* constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl, bool carry_dependency = false);
1254 
1255   // Auxiliary methods for randomized fuzzing/stressing


1256   int random();
1257   bool randomized_select(int count);
1258 
1259   // supporting clone_map
1260   CloneMap&     clone_map();
1261   void          set_clone_map(Dict* d);
1262 
1263   bool needs_clinit_barrier(ciField* ik,         ciMethod* accessing_method);
1264   bool needs_clinit_barrier(ciMethod* ik,        ciMethod* accessing_method);
1265   bool needs_clinit_barrier(ciInstanceKlass* ik, ciMethod* accessing_method);
1266 
1267 #ifdef IA32
1268  private:
1269   bool _select_24_bit_instr;   // We selected an instruction with a 24-bit result
1270   bool _in_24_bit_fp_mode;     // We are emitting instructions with 24-bit results
1271 
1272   // Remember if this compilation changes hardware mode to 24-bit precision.
1273   void set_24_bit_selection_and_mode(bool selection, bool mode) {
1274     _select_24_bit_instr = selection;
1275     _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 ParsePredicateNode;
  74 class PhaseCFG;

  76 class PhaseIterGVN;
  77 class PhaseRegAlloc;
  78 class PhaseCCP;
  79 class PhaseOutput;
  80 class RootNode;
  81 class relocInfo;
  82 class StartNode;
  83 class SafePointNode;
  84 class JVMState;
  85 class Type;
  86 class TypeInt;
  87 class TypeInteger;
  88 class TypeKlassPtr;
  89 class TypePtr;
  90 class TypeOopPtr;
  91 class TypeFunc;
  92 class TypeVect;
  93 class Type_Array;
  94 class Unique_Node_List;
  95 class UnstableIfTrap;
  96 class InlineTypeNode;
  97 class nmethod;
  98 class Node_Stack;
  99 struct Final_Reshape_Counts;
 100 class VerifyMeetResult;
 101 
 102 enum LoopOptsMode {
 103   LoopOptsDefault,
 104   LoopOptsNone,
 105   LoopOptsMaxUnroll,
 106   LoopOptsShenandoahExpand,
 107   LoopOptsShenandoahPostExpand,
 108   LoopOptsSkipSplitIf,
 109   LoopOptsVerify
 110 };
 111 
 112 // The type of all node counts and indexes.
 113 // It must hold at least 16 bits, but must also be fast to load and store.
 114 // This type, if less than 32 bits, could limit the number of possible nodes.
 115 // (To make this type platform-specific, move to globalDefinitions_xxx.hpp.)
 116 typedef unsigned int node_idx_t;

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

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

 787     _template_assertion_predicate_opaqs.append(n);
 788   }
 789 
 790   void remove_template_assertion_predicate_opaq(Node* n) {
 791     if (template_assertion_predicate_count() > 0) {
 792       _template_assertion_predicate_opaqs.remove_if_existing(n);
 793     }
 794   }
 795   void add_coarsened_locks(GrowableArray<AbstractLockNode*>& locks);
 796   void remove_coarsened_lock(Node* n);
 797   bool coarsened_locks_consistent();
 798 
 799   bool       post_loop_opts_phase() { return _post_loop_opts_phase;  }
 800   void   set_post_loop_opts_phase() { _post_loop_opts_phase = true;  }
 801   void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }
 802 
 803   void record_for_post_loop_opts_igvn(Node* n);
 804   void remove_from_post_loop_opts_igvn(Node* n);
 805   void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
 806 
 807   // Keep track of inline type nodes for later processing
 808   void add_inline_type(Node* n);
 809   void remove_inline_type(Node* n);
 810   void process_inline_types(PhaseIterGVN &igvn, bool remove = false);
 811 
 812   void adjust_flat_array_access_aliases(PhaseIterGVN& igvn);
 813 
 814   void record_unstable_if_trap(UnstableIfTrap* trap);
 815   bool remove_unstable_if_trap(CallStaticJavaNode* unc, bool yield);
 816   void remove_useless_unstable_if_traps(Unique_Node_List &useful);
 817   void process_for_unstable_if_traps(PhaseIterGVN& igvn);
 818 
 819   void sort_macro_nodes();
 820 
 821   void mark_parse_predicate_nodes_useless(PhaseIterGVN& igvn);
 822 
 823   // Are there candidate expensive nodes for optimization?
 824   bool should_optimize_expensive_nodes(PhaseIterGVN &igvn);
 825   // Check whether n1 and n2 are similar
 826   static int cmp_expensive_nodes(Node* n1, Node* n2);
 827   // Sort expensive nodes to locate similar expensive nodes
 828   void sort_expensive_nodes();
 829 
 830   // Compilation environment.
 831   Arena*      comp_arena()           { return &_comp_arena; }
 832   ciEnv*      env() const            { return _env; }
 833   CompileLog* log() const            { return _log; }

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

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

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