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

 625   int               do_cleanup() const          { return _do_cleanup; }
 626   void          set_major_progress()            { _major_progress++; }
 627   void          restore_major_progress(int progress) { _major_progress += progress; }
 628   void        clear_major_progress()            { _major_progress = 0; }
 629   int               max_inline_size() const     { return _max_inline_size; }
 630   void          set_freq_inline_size(int n)     { _freq_inline_size = n; }
 631   int               freq_inline_size() const    { return _freq_inline_size; }
 632   void          set_max_inline_size(int n)      { _max_inline_size = n; }
 633   bool              has_loops() const           { return _has_loops; }
 634   void          set_has_loops(bool z)           { _has_loops = z; }
 635   bool              has_split_ifs() const       { return _has_split_ifs; }
 636   void          set_has_split_ifs(bool z)       { _has_split_ifs = z; }
 637   bool              has_unsafe_access() const   { return _has_unsafe_access; }
 638   void          set_has_unsafe_access(bool z)   { _has_unsafe_access = z; }
 639   bool              has_stringbuilder() const   { return _has_stringbuilder; }
 640   void          set_has_stringbuilder(bool z)   { _has_stringbuilder = z; }
 641   bool              has_boxed_value() const     { return _has_boxed_value; }
 642   void          set_has_boxed_value(bool z)     { _has_boxed_value = z; }
 643   bool              has_reserved_stack_access() const { return _has_reserved_stack_access; }
 644   void          set_has_reserved_stack_access(bool z) { _has_reserved_stack_access = 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   uint              max_node_limit() const       { return (uint)_max_node_limit; }
 674   void          set_max_node_limit(uint n)       { _max_node_limit = n; }
 675   bool              clinit_barrier_on_entry()       { return _clinit_barrier_on_entry; }
 676   void          set_clinit_barrier_on_entry(bool z) { _clinit_barrier_on_entry = z; }










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

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







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

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

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

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


1306   int random();
1307   bool randomized_select(int count);
1308 
1309   // seed random number generation and log the seed for repeatability.
1310   void initialize_stress_seed(const DirectiveSet* directive);
1311 
1312   // supporting clone_map
1313   CloneMap&     clone_map();
1314   void          set_clone_map(Dict* d);
1315 
1316   bool needs_clinit_barrier(ciField* ik,         ciMethod* accessing_method);
1317   bool needs_clinit_barrier(ciMethod* ik,        ciMethod* accessing_method);
1318   bool needs_clinit_barrier(ciInstanceKlass* ik, ciMethod* accessing_method);
1319 
1320 #ifdef IA32
1321  private:
1322   bool _select_24_bit_instr;   // We selected an instruction with a 24-bit result
1323   bool _in_24_bit_fp_mode;     // We are emitting instructions with 24-bit results
1324 
1325   // 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   // List of OpaqueTemplateAssertionPredicateNode nodes for Template Assertion Predicates.
 380   GrowableArray<Node*>  _template_assertion_predicate_opaqs;
 381   GrowableArray<Node*>  _expensive_nodes;       // List of nodes that are expensive to compute and that we'd better not let the GVN freely common
 382   GrowableArray<Node*>  _for_post_loop_igvn;    // List of nodes for IGVN after loop opts are over
 383   GrowableArray<Node*>  _inline_type_nodes;     // List of InlineType nodes
 384   GrowableArray<UnstableIfTrap*> _unstable_if_traps;        // List of ifnodes after IGVN
 385   GrowableArray<Node_List*> _coarsened_locks;   // List of coarsened Lock and Unlock nodes
 386   ConnectionGraph*      _congraph;
 387 #ifndef PRODUCT
 388   IdealGraphPrinter*    _igv_printer;
 389   static IdealGraphPrinter* _debug_file_printer;
 390   static IdealGraphPrinter* _debug_network_printer;
 391 #endif
 392 
 393 
 394   // Node management
 395   uint                  _unique;                // Counter for unique Node indices
 396   uint                  _dead_node_count;       // Number of dead nodes; VectorSet::Size() is O(N).
 397                                                 // So use this to keep count and make the call O(1).
 398   VectorSet             _dead_node_list;        // Set of dead nodes
 399   DEBUG_ONLY(Unique_Node_List* _modified_nodes;)   // List of nodes which inputs were modified
 400   DEBUG_ONLY(bool       _phase_optimize_finished;) // Used for live node verification while creating new nodes
 401 
 402   DEBUG_ONLY(bool       _phase_verify_ideal_loop;) // Are we in PhaseIdealLoop verification?
 403 

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

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

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

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

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