< prev index next >

src/hotspot/share/opto/compile.hpp

Print this page

  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 #include "utilities/vmEnums.hpp"
  49 
  50 class AbstractLockNode;
  51 class AddPNode;
  52 class Block;
  53 class Bundle;
  54 class CallGenerator;

  55 class CallStaticJavaNode;
  56 class CloneMap;
  57 class CompilationFailureInfo;
  58 class ConnectionGraph;
  59 class IdealGraphPrinter;
  60 class InlineTree;
  61 class Matcher;
  62 class MachConstantNode;
  63 class MachConstantBaseNode;
  64 class MachNode;
  65 class MachOper;
  66 class MachSafePointNode;
  67 class Node;
  68 class Node_Array;
  69 class Node_List;
  70 class Node_Notes;
  71 class NodeHash;
  72 class NodeCloneInfo;
  73 class OptoReg;
  74 class ParsePredicateNode;

  77 class PhaseIterGVN;
  78 class PhaseRegAlloc;
  79 class PhaseCCP;
  80 class PhaseOutput;
  81 class RootNode;
  82 class relocInfo;
  83 class StartNode;
  84 class SafePointNode;
  85 class JVMState;
  86 class Type;
  87 class TypeInt;
  88 class TypeInteger;
  89 class TypeKlassPtr;
  90 class TypePtr;
  91 class TypeOopPtr;
  92 class TypeFunc;
  93 class TypeVect;
  94 class Type_Array;
  95 class Unique_Node_List;
  96 class UnstableIfTrap;

  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;

 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   bool                  _allow_macro_nodes;     // True if we allow creation of macro nodes.
 322 
 323   int                   _major_progress;        // Count of something big happening
 324   bool                  _inlining_progress;     // progress doing incremental inlining?
 325   bool                  _inlining_incrementally;// Are we doing incremental inlining (post parse)
 326   bool                  _do_cleanup;            // Cleanup is needed before proceeding with incremental inlining
 327   bool                  _has_loops;             // True if the method _may_ have some loops
 328   bool                  _has_split_ifs;         // True if the method _may_ have some split-if
 329   bool                  _has_unsafe_access;     // True if the method _may_ produce faults in unsafe loads or stores.
 330   bool                  _has_stringbuilder;     // True StringBuffers or StringBuilders are allocated
 331   bool                  _has_boxed_value;       // True if a boxed object is allocated
 332   bool                  _has_reserved_stack_access; // True if the method or an inlined method is annotated with ReservedStackAccess

 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   uint                  _igv_phase_iter[PHASE_NUM_TYPES]; // Counters for IGV phase iterations
 350   bool                  _trace_opto_output;
 351   bool                  _parsed_irreducible_loop; // True if ciTypeFlow detected irreducible loops during parsing
 352 #endif
 353   bool                  _has_irreducible_loop;  // Found irreducible loops
 354   // JSR 292
 355   bool                  _has_method_handle_invokes; // True if this method has MethodHandle invokes.
 356   bool                  _has_monitors;          // Metadata transfered to nmethod to enable Continuations lock-detection fastpath
 357   bool                  _has_scoped_access;     // For shared scope closure
 358   bool                  _clinit_barrier_on_entry; // True if clinit barrier is needed on nmethod entry
 359   int                   _loop_opts_cnt;         // loop opts round



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

 376   GrowableArray<UnstableIfTrap*> _unstable_if_traps;        // List of ifnodes after IGVN
 377   GrowableArray<Node_List*> _coarsened_locks;   // List of coarsened Lock and Unlock nodes
 378   ConnectionGraph*      _congraph;
 379 #ifndef PRODUCT
 380   IdealGraphPrinter*    _igv_printer;
 381   static IdealGraphPrinter* _debug_file_printer;
 382   static IdealGraphPrinter* _debug_network_printer;
 383 #endif
 384 
 385 
 386   // Node management
 387   uint                  _unique;                // Counter for unique Node indices
 388   uint                  _dead_node_count;       // Number of dead nodes; VectorSet::Size() is O(N).
 389                                                 // So use this to keep count and make the call O(1).
 390   VectorSet             _dead_node_list;        // Set of dead nodes
 391   DEBUG_ONLY(Unique_Node_List* _modified_nodes;)   // List of nodes which inputs were modified
 392   DEBUG_ONLY(bool       _phase_optimize_finished;) // Used for live node verification while creating new nodes
 393 
 394   DEBUG_ONLY(bool       _phase_verify_ideal_loop;) // Are we in PhaseIdealLoop verification?
 395 

 624   int               do_cleanup() const          { return _do_cleanup; }
 625   void          set_major_progress()            { _major_progress++; }
 626   void          restore_major_progress(int progress) { _major_progress += progress; }
 627   void        clear_major_progress()            { _major_progress = 0; }
 628   int               max_inline_size() const     { return _max_inline_size; }
 629   void          set_freq_inline_size(int n)     { _freq_inline_size = n; }
 630   int               freq_inline_size() const    { return _freq_inline_size; }
 631   void          set_max_inline_size(int n)      { _max_inline_size = n; }
 632   bool              has_loops() const           { return _has_loops; }
 633   void          set_has_loops(bool z)           { _has_loops = z; }
 634   bool              has_split_ifs() const       { return _has_split_ifs; }
 635   void          set_has_split_ifs(bool z)       { _has_split_ifs = z; }
 636   bool              has_unsafe_access() const   { return _has_unsafe_access; }
 637   void          set_has_unsafe_access(bool z)   { _has_unsafe_access = z; }
 638   bool              has_stringbuilder() const   { return _has_stringbuilder; }
 639   void          set_has_stringbuilder(bool z)   { _has_stringbuilder = z; }
 640   bool              has_boxed_value() const     { return _has_boxed_value; }
 641   void          set_has_boxed_value(bool z)     { _has_boxed_value = z; }
 642   bool              has_reserved_stack_access() const { return _has_reserved_stack_access; }
 643   void          set_has_reserved_stack_access(bool z) { _has_reserved_stack_access = z; }


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










 676   bool              has_monitors() const         { return _has_monitors; }
 677   void          set_has_monitors(bool v)         { _has_monitors = v; }
 678   bool              has_scoped_access() const    { return _has_scoped_access; }
 679   void          set_has_scoped_access(bool v)    { _has_scoped_access = v; }
 680 
 681   // check the CompilerOracle for special behaviours for this compile
 682   bool          method_has_option(CompileCommandEnum 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; }

 784   bool coarsened_locks_consistent();
 785   void mark_unbalanced_boxes() const;
 786 
 787   bool       post_loop_opts_phase() { return _post_loop_opts_phase;  }
 788   void   set_post_loop_opts_phase() { _post_loop_opts_phase = true;  }
 789   void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }
 790 
 791 #ifdef ASSERT
 792   bool       phase_verify_ideal_loop() const { return _phase_verify_ideal_loop; }
 793   void   set_phase_verify_ideal_loop() { _phase_verify_ideal_loop = true; }
 794   void reset_phase_verify_ideal_loop() { _phase_verify_ideal_loop = false; }
 795 #endif
 796 
 797   bool       allow_macro_nodes() { return _allow_macro_nodes;  }
 798   void reset_allow_macro_nodes() { _allow_macro_nodes = false;  }
 799 
 800   void record_for_post_loop_opts_igvn(Node* n);
 801   void remove_from_post_loop_opts_igvn(Node* n);
 802   void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
 803 







 804   void record_unstable_if_trap(UnstableIfTrap* trap);
 805   bool remove_unstable_if_trap(CallStaticJavaNode* unc, bool yield);
 806   void remove_useless_unstable_if_traps(Unique_Node_List &useful);
 807   void process_for_unstable_if_traps(PhaseIterGVN& igvn);
 808 
 809   void shuffle_macro_nodes();
 810   void sort_macro_nodes();
 811 
 812   void mark_parse_predicate_nodes_useless(PhaseIterGVN& igvn);
 813 
 814   // Are there candidate expensive nodes for optimization?
 815   bool should_optimize_expensive_nodes(PhaseIterGVN &igvn);
 816   // Check whether n1 and n2 are similar
 817   static int cmp_expensive_nodes(Node* n1, Node* n2);
 818   // Sort expensive nodes to locate similar expensive nodes
 819   void sort_expensive_nodes();
 820 
 821   // Compilation environment.
 822   Arena*      comp_arena()           { return &_comp_arena; }
 823   ciEnv*      env() const            { return _env; }

 962   Arena*            type_arena()                { return _type_arena; }
 963   Dict*             type_dict()                 { return _type_dict; }
 964   size_t            type_last_size()            { return _type_last_size; }
 965   int               num_alias_types()           { return _num_alias_types; }
 966 
 967   void          init_type_arena()                       { _type_arena = &_Compile_types; }
 968   void          set_type_arena(Arena* a)                { _type_arena = a; }
 969   void          set_type_dict(Dict* d)                  { _type_dict = d; }
 970   void          set_type_last_size(size_t sz)           { _type_last_size = sz; }
 971 
 972   const TypeFunc* last_tf(ciMethod* m) {
 973     return (m == _last_tf_m) ? _last_tf : nullptr;
 974   }
 975   void set_last_tf(ciMethod* m, const TypeFunc* tf) {
 976     assert(m != nullptr || tf == nullptr, "");
 977     _last_tf_m = m;
 978     _last_tf = tf;
 979   }
 980 
 981   AliasType*        alias_type(int                idx)  { assert(idx < num_alias_types(), "oob"); return _alias_types[idx]; }
 982   AliasType*        alias_type(const TypePtr* adr_type, ciField* field = nullptr) { return find_alias_type(adr_type, false, field); }
 983   bool         have_alias_type(const TypePtr* adr_type);
 984   AliasType*        alias_type(ciField*         field);
 985 
 986   int               get_alias_index(const TypePtr* at)  { return alias_type(at)->index(); }
 987   const TypePtr*    get_adr_type(uint aidx)             { return alias_type(aidx)->adr_type(); }
 988   int               get_general_index(uint aidx)        { return alias_type(aidx)->general_index(); }
 989 
 990   // Building nodes
 991   void              rethrow_exceptions(JVMState* jvms);
 992   void              return_values(JVMState* jvms);
 993   JVMState*         build_start_state(StartNode* start, const TypeFunc* tf);
 994 
 995   // Decide how to build a call.
 996   // The profile factor is a discount to apply to this site's interp. profile.
 997   CallGenerator*    call_generator(ciMethod* call_method, int vtable_index, bool call_does_dispatch,
 998                                    JVMState* jvms, bool allow_inline, float profile_factor, ciKlass* speculative_receiver_type = nullptr,
 999                                    bool allow_intrinsics = true);
1000   bool should_delay_inlining(ciMethod* call_method, JVMState* jvms) {
1001     return should_delay_string_inlining(call_method, jvms) ||
1002            should_delay_boxing_inlining(call_method, jvms) ||
1003            should_delay_vector_inlining(call_method, jvms);
1004   }
1005   bool should_delay_string_inlining(ciMethod* call_method, JVMState* jvms);
1006   bool should_delay_boxing_inlining(ciMethod* call_method, JVMState* jvms);

1208   // Number of outgoing stack slots killed above the out_preserve_stack_slots
1209   // for calls to C.  Supports the var-args backing area for register parms.
1210   uint varargs_C_out_slots_killed() const;
1211 
1212   // Number of Stack Slots consumed by a synchronization entry
1213   int sync_stack_slots() const;
1214 
1215   // Compute the name of old_SP.  See <arch>.ad for frame layout.
1216   OptoReg::Name compute_old_SP();
1217 
1218  private:
1219   // Phase control:
1220   void Init(bool aliasing);                      // Prepare for a single compilation
1221   void Optimize();                               // Given a graph, optimize it
1222   void Code_Gen();                               // Generate code from a graph
1223 
1224   // Management of the AliasType table.
1225   void grow_alias_types();
1226   AliasCacheEntry* probe_alias_cache(const TypePtr* adr_type);
1227   const TypePtr *flatten_alias_type(const TypePtr* adr_type) const;
1228   AliasType* find_alias_type(const TypePtr* adr_type, bool no_create, ciField* field);
1229 
1230   void verify_top(Node*) const PRODUCT_RETURN;
1231 
1232   // Intrinsic setup.
1233   CallGenerator* make_vm_intrinsic(ciMethod* m, bool is_virtual);          // constructor
1234   int            intrinsic_insertion_index(ciMethod* m, bool is_virtual, bool& found);  // helper
1235   CallGenerator* find_intrinsic(ciMethod* m, bool is_virtual);             // query fn
1236   void           register_intrinsic(CallGenerator* cg);                    // update fn
1237 
1238 #ifndef PRODUCT
1239   static juint  _intrinsic_hist_count[];
1240   static jubyte _intrinsic_hist_flags[];
1241 #endif
1242   // Function calls made by the public function final_graph_reshaping.
1243   // No need to be made public as they are not called elsewhere.
1244   void final_graph_reshaping_impl(Node *n, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1245   void final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop, Unique_Node_List& dead_nodes);
1246   void final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1247   void handle_div_mod_op(Node* n, BasicType bt, bool is_unsigned);
1248 

1284   // End-of-run dumps.
1285   static void print_statistics() PRODUCT_RETURN;
1286 
1287   // Verify ADLC assumptions during startup
1288   static void adlc_verification() PRODUCT_RETURN;
1289 
1290   // Definitions of pd methods
1291   static void pd_compiler2_init();
1292 
1293   // Static parse-time type checking logic for gen_subtype_check:
1294   enum SubTypeCheckResult { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
1295   SubTypeCheckResult static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip = StressReflectiveCode);
1296 
1297   static Node* conv_I2X_index(PhaseGVN* phase, Node* offset, const TypeInt* sizetype,
1298                               // Optional control dependency (for example, on range check)
1299                               Node* ctrl = nullptr);
1300 
1301   // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
1302   static Node* constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl, bool carry_dependency = false);
1303 
1304   // Auxiliary methods for randomized fuzzing/stressing


1305   int random();
1306   bool randomized_select(int count);
1307 
1308   // seed random number generation and log the seed for repeatability.
1309   void initialize_stress_seed(const DirectiveSet* directive);
1310 
1311   // supporting clone_map
1312   CloneMap&     clone_map();
1313   void          set_clone_map(Dict* d);
1314 
1315   bool needs_clinit_barrier(ciField* ik,         ciMethod* accessing_method);
1316   bool needs_clinit_barrier(ciMethod* ik,        ciMethod* accessing_method);
1317   bool needs_clinit_barrier(ciInstanceKlass* ik, ciMethod* accessing_method);
1318 
1319 #ifdef IA32
1320  private:
1321   bool _select_24_bit_instr;   // We selected an instruction with a 24-bit result
1322   bool _in_24_bit_fp_mode;     // We are emitting instructions with 24-bit results
1323 
1324   // Remember if this compilation changes hardware mode to 24-bit precision.

  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 #include "utilities/vmEnums.hpp"
  49 
  50 class AbstractLockNode;
  51 class AddPNode;
  52 class Block;
  53 class Bundle;
  54 class CallGenerator;
  55 class CallNode;
  56 class CallStaticJavaNode;
  57 class CloneMap;
  58 class CompilationFailureInfo;
  59 class ConnectionGraph;
  60 class IdealGraphPrinter;
  61 class InlineTree;
  62 class Matcher;
  63 class MachConstantNode;
  64 class MachConstantBaseNode;
  65 class MachNode;
  66 class MachOper;
  67 class MachSafePointNode;
  68 class Node;
  69 class Node_Array;
  70 class Node_List;
  71 class Node_Notes;
  72 class NodeHash;
  73 class NodeCloneInfo;
  74 class OptoReg;
  75 class ParsePredicateNode;

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

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

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

 803   bool coarsened_locks_consistent();
 804   void mark_unbalanced_boxes() const;
 805 
 806   bool       post_loop_opts_phase() { return _post_loop_opts_phase;  }
 807   void   set_post_loop_opts_phase() { _post_loop_opts_phase = true;  }
 808   void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }
 809 
 810 #ifdef ASSERT
 811   bool       phase_verify_ideal_loop() const { return _phase_verify_ideal_loop; }
 812   void   set_phase_verify_ideal_loop() { _phase_verify_ideal_loop = true; }
 813   void reset_phase_verify_ideal_loop() { _phase_verify_ideal_loop = false; }
 814 #endif
 815 
 816   bool       allow_macro_nodes() { return _allow_macro_nodes;  }
 817   void reset_allow_macro_nodes() { _allow_macro_nodes = false;  }
 818 
 819   void record_for_post_loop_opts_igvn(Node* n);
 820   void remove_from_post_loop_opts_igvn(Node* n);
 821   void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
 822 
 823   // Keep track of inline type nodes for later processing
 824   void add_inline_type(Node* n);
 825   void remove_inline_type(Node* n);
 826   void process_inline_types(PhaseIterGVN &igvn, bool remove = false);
 827 
 828   void adjust_flat_array_access_aliases(PhaseIterGVN& igvn);
 829 
 830   void record_unstable_if_trap(UnstableIfTrap* trap);
 831   bool remove_unstable_if_trap(CallStaticJavaNode* unc, bool yield);
 832   void remove_useless_unstable_if_traps(Unique_Node_List &useful);
 833   void process_for_unstable_if_traps(PhaseIterGVN& igvn);
 834 
 835   void shuffle_macro_nodes();
 836   void sort_macro_nodes();
 837 
 838   void mark_parse_predicate_nodes_useless(PhaseIterGVN& igvn);
 839 
 840   // Are there candidate expensive nodes for optimization?
 841   bool should_optimize_expensive_nodes(PhaseIterGVN &igvn);
 842   // Check whether n1 and n2 are similar
 843   static int cmp_expensive_nodes(Node* n1, Node* n2);
 844   // Sort expensive nodes to locate similar expensive nodes
 845   void sort_expensive_nodes();
 846 
 847   // Compilation environment.
 848   Arena*      comp_arena()           { return &_comp_arena; }
 849   ciEnv*      env() const            { return _env; }

 988   Arena*            type_arena()                { return _type_arena; }
 989   Dict*             type_dict()                 { return _type_dict; }
 990   size_t            type_last_size()            { return _type_last_size; }
 991   int               num_alias_types()           { return _num_alias_types; }
 992 
 993   void          init_type_arena()                       { _type_arena = &_Compile_types; }
 994   void          set_type_arena(Arena* a)                { _type_arena = a; }
 995   void          set_type_dict(Dict* d)                  { _type_dict = d; }
 996   void          set_type_last_size(size_t sz)           { _type_last_size = sz; }
 997 
 998   const TypeFunc* last_tf(ciMethod* m) {
 999     return (m == _last_tf_m) ? _last_tf : nullptr;
1000   }
1001   void set_last_tf(ciMethod* m, const TypeFunc* tf) {
1002     assert(m != nullptr || tf == nullptr, "");
1003     _last_tf_m = m;
1004     _last_tf = tf;
1005   }
1006 
1007   AliasType*        alias_type(int                idx)  { assert(idx < num_alias_types(), "oob"); return _alias_types[idx]; }
1008   AliasType*        alias_type(const TypePtr* adr_type, ciField* field = nullptr, bool uncached = false) { return find_alias_type(adr_type, false, field, uncached); }
1009   bool         have_alias_type(const TypePtr* adr_type);
1010   AliasType*        alias_type(ciField*         field);
1011 
1012   int               get_alias_index(const TypePtr* at, bool uncached = false) { return alias_type(at, nullptr, uncached)->index(); }
1013   const TypePtr*    get_adr_type(uint aidx)             { return alias_type(aidx)->adr_type(); }
1014   int               get_general_index(uint aidx)        { return alias_type(aidx)->general_index(); }
1015 
1016   // Building nodes
1017   void              rethrow_exceptions(JVMState* jvms);
1018   void              return_values(JVMState* jvms);
1019   JVMState*         build_start_state(StartNode* start, const TypeFunc* tf);
1020 
1021   // Decide how to build a call.
1022   // The profile factor is a discount to apply to this site's interp. profile.
1023   CallGenerator*    call_generator(ciMethod* call_method, int vtable_index, bool call_does_dispatch,
1024                                    JVMState* jvms, bool allow_inline, float profile_factor, ciKlass* speculative_receiver_type = nullptr,
1025                                    bool allow_intrinsics = true);
1026   bool should_delay_inlining(ciMethod* call_method, JVMState* jvms) {
1027     return should_delay_string_inlining(call_method, jvms) ||
1028            should_delay_boxing_inlining(call_method, jvms) ||
1029            should_delay_vector_inlining(call_method, jvms);
1030   }
1031   bool should_delay_string_inlining(ciMethod* call_method, JVMState* jvms);
1032   bool should_delay_boxing_inlining(ciMethod* call_method, JVMState* jvms);

1234   // Number of outgoing stack slots killed above the out_preserve_stack_slots
1235   // for calls to C.  Supports the var-args backing area for register parms.
1236   uint varargs_C_out_slots_killed() const;
1237 
1238   // Number of Stack Slots consumed by a synchronization entry
1239   int sync_stack_slots() const;
1240 
1241   // Compute the name of old_SP.  See <arch>.ad for frame layout.
1242   OptoReg::Name compute_old_SP();
1243 
1244  private:
1245   // Phase control:
1246   void Init(bool aliasing);                      // Prepare for a single compilation
1247   void Optimize();                               // Given a graph, optimize it
1248   void Code_Gen();                               // Generate code from a graph
1249 
1250   // Management of the AliasType table.
1251   void grow_alias_types();
1252   AliasCacheEntry* probe_alias_cache(const TypePtr* adr_type);
1253   const TypePtr *flatten_alias_type(const TypePtr* adr_type) const;
1254   AliasType* find_alias_type(const TypePtr* adr_type, bool no_create, ciField* field, bool uncached = false);
1255 
1256   void verify_top(Node*) const PRODUCT_RETURN;
1257 
1258   // Intrinsic setup.
1259   CallGenerator* make_vm_intrinsic(ciMethod* m, bool is_virtual);          // constructor
1260   int            intrinsic_insertion_index(ciMethod* m, bool is_virtual, bool& found);  // helper
1261   CallGenerator* find_intrinsic(ciMethod* m, bool is_virtual);             // query fn
1262   void           register_intrinsic(CallGenerator* cg);                    // update fn
1263 
1264 #ifndef PRODUCT
1265   static juint  _intrinsic_hist_count[];
1266   static jubyte _intrinsic_hist_flags[];
1267 #endif
1268   // Function calls made by the public function final_graph_reshaping.
1269   // No need to be made public as they are not called elsewhere.
1270   void final_graph_reshaping_impl(Node *n, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1271   void final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop, Unique_Node_List& dead_nodes);
1272   void final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1273   void handle_div_mod_op(Node* n, BasicType bt, bool is_unsigned);
1274 

1310   // End-of-run dumps.
1311   static void print_statistics() PRODUCT_RETURN;
1312 
1313   // Verify ADLC assumptions during startup
1314   static void adlc_verification() PRODUCT_RETURN;
1315 
1316   // Definitions of pd methods
1317   static void pd_compiler2_init();
1318 
1319   // Static parse-time type checking logic for gen_subtype_check:
1320   enum SubTypeCheckResult { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
1321   SubTypeCheckResult static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip = StressReflectiveCode);
1322 
1323   static Node* conv_I2X_index(PhaseGVN* phase, Node* offset, const TypeInt* sizetype,
1324                               // Optional control dependency (for example, on range check)
1325                               Node* ctrl = nullptr);
1326 
1327   // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
1328   static Node* constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl, bool carry_dependency = false);
1329 
1330   Node* optimize_acmp(PhaseGVN* phase, Node* a, Node* b);
1331 
1332   // Auxiliary method for randomized fuzzing/stressing
1333   int random();
1334   bool randomized_select(int count);
1335 
1336   // seed random number generation and log the seed for repeatability.
1337   void initialize_stress_seed(const DirectiveSet* directive);
1338 
1339   // supporting clone_map
1340   CloneMap&     clone_map();
1341   void          set_clone_map(Dict* d);
1342 
1343   bool needs_clinit_barrier(ciField* ik,         ciMethod* accessing_method);
1344   bool needs_clinit_barrier(ciMethod* ik,        ciMethod* accessing_method);
1345   bool needs_clinit_barrier(ciInstanceKlass* ik, ciMethod* accessing_method);
1346 
1347 #ifdef IA32
1348  private:
1349   bool _select_24_bit_instr;   // We selected an instruction with a 24-bit result
1350   bool _in_24_bit_fp_mode;     // We are emitting instructions with 24-bit results
1351 
1352   // Remember if this compilation changes hardware mode to 24-bit precision.
< prev index next >