34 #include "compiler/compilerEvent.hpp"
35 #include "libadt/dict.hpp"
36 #include "libadt/vectset.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "oops/methodData.hpp"
39 #include "opto/idealGraphPrinter.hpp"
40 #include "opto/phasetype.hpp"
41 #include "opto/phase.hpp"
42 #include "opto/regmask.hpp"
43 #include "runtime/deoptimization.hpp"
44 #include "runtime/sharedRuntime.hpp"
45 #include "runtime/timerTrace.hpp"
46 #include "runtime/vmThread.hpp"
47 #include "utilities/ticks.hpp"
48
49 class AbstractLockNode;
50 class AddPNode;
51 class Block;
52 class Bundle;
53 class CallGenerator;
54 class CallStaticJavaNode;
55 class CloneMap;
56 class CompilationFailureInfo;
57 class ConnectionGraph;
58 class IdealGraphPrinter;
59 class InlineTree;
60 class Matcher;
61 class MachConstantNode;
62 class MachConstantBaseNode;
63 class MachNode;
64 class MachOper;
65 class MachSafePointNode;
66 class Node;
67 class Node_Array;
68 class Node_List;
69 class Node_Notes;
70 class NodeHash;
71 class NodeCloneInfo;
72 class OptoReg;
73 class ParsePredicateNode;
76 class PhaseIterGVN;
77 class PhaseRegAlloc;
78 class PhaseCCP;
79 class PhaseOutput;
80 class RootNode;
81 class relocInfo;
82 class StartNode;
83 class SafePointNode;
84 class JVMState;
85 class Type;
86 class TypeInt;
87 class TypeInteger;
88 class TypeKlassPtr;
89 class TypePtr;
90 class TypeOopPtr;
91 class TypeFunc;
92 class TypeVect;
93 class Type_Array;
94 class Unique_Node_List;
95 class UnstableIfTrap;
96 class nmethod;
97 class Node_Stack;
98 struct Final_Reshape_Counts;
99 class VerifyMeetResult;
100
101 enum LoopOptsMode {
102 LoopOptsDefault,
103 LoopOptsNone,
104 LoopOptsMaxUnroll,
105 LoopOptsShenandoahExpand,
106 LoopOptsShenandoahPostExpand,
107 LoopOptsSkipSplitIf,
108 LoopOptsVerify
109 };
110
111 // The type of all node counts and indexes.
112 // It must hold at least 16 bits, but must also be fast to load and store.
113 // This type, if less than 32 bits, could limit the number of possible nodes.
114 // (To make this type platform-specific, move to globalDefinitions_xxx.hpp.)
115 typedef unsigned int node_idx_t;
311
312 // Control of this compilation.
313 int _max_inline_size; // Max inline size for this compilation
314 int _freq_inline_size; // Max hot method inline size for this compilation
315 int _fixed_slots; // count of frame slots not allocated by the register
316 // allocator i.e. locks, original deopt pc, etc.
317 uintx _max_node_limit; // Max unique node count during a single compilation.
318
319 bool _post_loop_opts_phase; // Loop opts are finished.
320
321 int _major_progress; // Count of something big happening
322 bool _inlining_progress; // progress doing incremental inlining?
323 bool _inlining_incrementally;// Are we doing incremental inlining (post parse)
324 bool _do_cleanup; // Cleanup is needed before proceeding with incremental inlining
325 bool _has_loops; // True if the method _may_ have some loops
326 bool _has_split_ifs; // True if the method _may_ have some split-if
327 bool _has_unsafe_access; // True if the method _may_ produce faults in unsafe loads or stores.
328 bool _has_stringbuilder; // True StringBuffers or StringBuilders are allocated
329 bool _has_boxed_value; // True if a boxed object is allocated
330 bool _has_reserved_stack_access; // True if the method or an inlined method is annotated with ReservedStackAccess
331 uint _max_vector_size; // Maximum size of generated vectors
332 bool _clear_upper_avx; // Clear upper bits of ymm registers using vzeroupper
333 uint _trap_hist[trapHistLength]; // Cumulative traps
334 bool _trap_can_recompile; // Have we emitted a recompiling trap?
335 uint _decompile_count; // Cumulative decompilation counts.
336 bool _do_inlining; // True if we intend to do inlining
337 bool _do_scheduling; // True if we intend to do scheduling
338 bool _do_freq_based_layout; // True if we intend to do frequency based block layout
339 bool _do_vector_loop; // True if allowed to execute loop in parallel iterations
340 bool _use_cmove; // True if CMove should be used without profitability analysis
341 bool _do_aliasing; // True if we intend to do aliasing
342 bool _print_assembly; // True if we should dump assembly code for this compilation
343 bool _print_inlining; // True if we should print inlining for this compilation
344 bool _print_intrinsics; // True if we should print intrinsics for this compilation
345 #ifndef PRODUCT
346 uint _igv_idx; // Counter for IGV node identifiers
347 uint _igv_phase_iter[PHASE_NUM_TYPES]; // Counters for IGV phase iterations
348 bool _trace_opto_output;
349 bool _parsed_irreducible_loop; // True if ciTypeFlow detected irreducible loops during parsing
350 #endif
351 bool _has_irreducible_loop; // Found irreducible loops
352 // JSR 292
353 bool _has_method_handle_invokes; // True if this method has MethodHandle invokes.
354 bool _has_monitors; // Metadata transfered to nmethod to enable Continuations lock-detection fastpath
355 bool _clinit_barrier_on_entry; // True if clinit barrier is needed on nmethod entry
356 RTMState _rtm_state; // State of Restricted Transactional Memory usage
357 int _loop_opts_cnt; // loop opts round
358 uint _stress_seed; // Seed for stress testing
359
360 // Compilation environment.
361 Arena _comp_arena; // Arena with lifetime equivalent to Compile
362 void* _barrier_set_state; // Potential GC barrier state for Compile
363 ciEnv* _env; // CI interface
364 DirectiveSet* _directive; // Compiler directive
365 CompileLog* _log; // from CompilerThread
366 const char* _failure_reason; // for record_failure/failing pattern
367 CompilationFailureInfo* _first_failure_details; // Details for the first failure happening during compilation
368 GrowableArray<CallGenerator*> _intrinsics; // List of intrinsics.
369 GrowableArray<Node*> _macro_nodes; // List of nodes which need to be expanded before matching.
370 GrowableArray<ParsePredicateNode*> _parse_predicates; // List of Parse Predicates.
371 GrowableArray<Node*> _template_assertion_predicate_opaqs; // List of Opaque4 nodes for Template Assertion Predicates.
372 GrowableArray<Node*> _expensive_nodes; // List of nodes that are expensive to compute and that we'd better not let the GVN freely common
373 GrowableArray<Node*> _for_post_loop_igvn; // List of nodes for IGVN after loop opts are over
374 GrowableArray<UnstableIfTrap*> _unstable_if_traps; // List of ifnodes after IGVN
375 GrowableArray<Node_List*> _coarsened_locks; // List of coarsened Lock and Unlock nodes
376 ConnectionGraph* _congraph;
377 #ifndef PRODUCT
378 IdealGraphPrinter* _igv_printer;
379 static IdealGraphPrinter* _debug_file_printer;
380 static IdealGraphPrinter* _debug_network_printer;
381 #endif
382
383
384 // Node management
385 uint _unique; // Counter for unique Node indices
386 uint _dead_node_count; // Number of dead nodes; VectorSet::Size() is O(N).
387 // So use this to keep count and make the call O(1).
388 VectorSet _dead_node_list; // Set of dead nodes
389 DEBUG_ONLY(Unique_Node_List* _modified_nodes;) // List of nodes which inputs were modified
390 DEBUG_ONLY(bool _phase_optimize_finished;) // Used for live node verification while creating new nodes
391
392 // Arenas for new-space and old-space nodes.
393 // Swapped between using _node_arena.
620 int do_cleanup() const { return _do_cleanup; }
621 void set_major_progress() { _major_progress++; }
622 void restore_major_progress(int progress) { _major_progress += progress; }
623 void clear_major_progress() { _major_progress = 0; }
624 int max_inline_size() const { return _max_inline_size; }
625 void set_freq_inline_size(int n) { _freq_inline_size = n; }
626 int freq_inline_size() const { return _freq_inline_size; }
627 void set_max_inline_size(int n) { _max_inline_size = n; }
628 bool has_loops() const { return _has_loops; }
629 void set_has_loops(bool z) { _has_loops = z; }
630 bool has_split_ifs() const { return _has_split_ifs; }
631 void set_has_split_ifs(bool z) { _has_split_ifs = z; }
632 bool has_unsafe_access() const { return _has_unsafe_access; }
633 void set_has_unsafe_access(bool z) { _has_unsafe_access = z; }
634 bool has_stringbuilder() const { return _has_stringbuilder; }
635 void set_has_stringbuilder(bool z) { _has_stringbuilder = z; }
636 bool has_boxed_value() const { return _has_boxed_value; }
637 void set_has_boxed_value(bool z) { _has_boxed_value = z; }
638 bool has_reserved_stack_access() const { return _has_reserved_stack_access; }
639 void set_has_reserved_stack_access(bool z) { _has_reserved_stack_access = z; }
640 uint max_vector_size() const { return _max_vector_size; }
641 void set_max_vector_size(uint s) { _max_vector_size = s; }
642 bool clear_upper_avx() const { return _clear_upper_avx; }
643 void set_clear_upper_avx(bool s) { _clear_upper_avx = s; }
644 void set_trap_count(uint r, uint c) { assert(r < trapHistLength, "oob"); _trap_hist[r] = c; }
645 uint trap_count(uint r) const { assert(r < trapHistLength, "oob"); return _trap_hist[r]; }
646 bool trap_can_recompile() const { return _trap_can_recompile; }
647 void set_trap_can_recompile(bool z) { _trap_can_recompile = z; }
648 uint decompile_count() const { return _decompile_count; }
649 void set_decompile_count(uint c) { _decompile_count = c; }
650 bool allow_range_check_smearing() const;
651 bool do_inlining() const { return _do_inlining; }
652 void set_do_inlining(bool z) { _do_inlining = z; }
653 bool do_scheduling() const { return _do_scheduling; }
654 void set_do_scheduling(bool z) { _do_scheduling = z; }
655 bool do_freq_based_layout() const{ return _do_freq_based_layout; }
656 void set_do_freq_based_layout(bool z){ _do_freq_based_layout = z; }
657 bool do_vector_loop() const { return _do_vector_loop; }
658 void set_do_vector_loop(bool z) { _do_vector_loop = z; }
659 bool use_cmove() const { return _use_cmove; }
660 void set_use_cmove(bool z) { _use_cmove = z; }
661 bool do_aliasing() const { return _do_aliasing; }
662 bool print_assembly() const { return _print_assembly; }
663 void set_print_assembly(bool z) { _print_assembly = z; }
664 bool print_inlining() const { return _print_inlining; }
665 void set_print_inlining(bool z) { _print_inlining = z; }
666 bool print_intrinsics() const { return _print_intrinsics; }
667 void set_print_intrinsics(bool z) { _print_intrinsics = z; }
668 RTMState rtm_state() const { return _rtm_state; }
669 void set_rtm_state(RTMState s) { _rtm_state = s; }
670 bool use_rtm() const { return (_rtm_state & NoRTM) == 0; }
671 bool profile_rtm() const { return _rtm_state == ProfileRTM; }
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
679 // check the CompilerOracle for special behaviours for this compile
680 bool method_has_option(enum CompileCommand option) {
681 return method() != nullptr && method()->has_option(option);
682 }
683
684 #ifndef PRODUCT
685 uint next_igv_idx() { return _igv_idx++; }
686 bool trace_opto_output() const { return _trace_opto_output; }
687 void print_ideal_ir(const char* phase_name);
688 bool should_print_ideal() const { return _directive->PrintIdealOption; }
689 bool parsed_irreducible_loop() const { return _parsed_irreducible_loop; }
690 void set_parsed_irreducible_loop(bool z) { _parsed_irreducible_loop = z; }
691 int _in_dump_cnt; // Required for dumping ir nodes.
692 #endif
693 bool has_irreducible_loop() const { return _has_irreducible_loop; }
694 void set_has_irreducible_loop(bool z) { _has_irreducible_loop = z; }
695
772 _template_assertion_predicate_opaqs.append(n);
773 }
774
775 void remove_template_assertion_predicate_opaq(Node* n) {
776 if (template_assertion_predicate_count() > 0) {
777 _template_assertion_predicate_opaqs.remove_if_existing(n);
778 }
779 }
780 void add_coarsened_locks(GrowableArray<AbstractLockNode*>& locks);
781 void remove_coarsened_lock(Node* n);
782 bool coarsened_locks_consistent();
783
784 bool post_loop_opts_phase() { return _post_loop_opts_phase; }
785 void set_post_loop_opts_phase() { _post_loop_opts_phase = true; }
786 void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }
787
788 void record_for_post_loop_opts_igvn(Node* n);
789 void remove_from_post_loop_opts_igvn(Node* n);
790 void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
791
792 void record_unstable_if_trap(UnstableIfTrap* trap);
793 bool remove_unstable_if_trap(CallStaticJavaNode* unc, bool yield);
794 void remove_useless_unstable_if_traps(Unique_Node_List &useful);
795 void process_for_unstable_if_traps(PhaseIterGVN& igvn);
796
797 void shuffle_macro_nodes();
798 void sort_macro_nodes();
799
800 void mark_parse_predicate_nodes_useless(PhaseIterGVN& igvn);
801
802 // Are there candidate expensive nodes for optimization?
803 bool should_optimize_expensive_nodes(PhaseIterGVN &igvn);
804 // Check whether n1 and n2 are similar
805 static int cmp_expensive_nodes(Node* n1, Node* n2);
806 // Sort expensive nodes to locate similar expensive nodes
807 void sort_expensive_nodes();
808
809 // Compilation environment.
810 Arena* comp_arena() { return &_comp_arena; }
811 ciEnv* env() const { return _env; }
917 Arena* type_arena() { return _type_arena; }
918 Dict* type_dict() { return _type_dict; }
919 size_t type_last_size() { return _type_last_size; }
920 int num_alias_types() { return _num_alias_types; }
921
922 void init_type_arena() { _type_arena = &_Compile_types; }
923 void set_type_arena(Arena* a) { _type_arena = a; }
924 void set_type_dict(Dict* d) { _type_dict = d; }
925 void set_type_last_size(size_t sz) { _type_last_size = sz; }
926
927 const TypeFunc* last_tf(ciMethod* m) {
928 return (m == _last_tf_m) ? _last_tf : nullptr;
929 }
930 void set_last_tf(ciMethod* m, const TypeFunc* tf) {
931 assert(m != nullptr || tf == nullptr, "");
932 _last_tf_m = m;
933 _last_tf = tf;
934 }
935
936 AliasType* alias_type(int idx) { assert(idx < num_alias_types(), "oob"); return _alias_types[idx]; }
937 AliasType* alias_type(const TypePtr* adr_type, ciField* field = nullptr) { return find_alias_type(adr_type, false, field); }
938 bool have_alias_type(const TypePtr* adr_type);
939 AliasType* alias_type(ciField* field);
940
941 int get_alias_index(const TypePtr* at) { return alias_type(at)->index(); }
942 const TypePtr* get_adr_type(uint aidx) { return alias_type(aidx)->adr_type(); }
943 int get_general_index(uint aidx) { return alias_type(aidx)->general_index(); }
944
945 // Building nodes
946 void rethrow_exceptions(JVMState* jvms);
947 void return_values(JVMState* jvms);
948 JVMState* build_start_state(StartNode* start, const TypeFunc* tf);
949
950 // Decide how to build a call.
951 // The profile factor is a discount to apply to this site's interp. profile.
952 CallGenerator* call_generator(ciMethod* call_method, int vtable_index, bool call_does_dispatch,
953 JVMState* jvms, bool allow_inline, float profile_factor, ciKlass* speculative_receiver_type = nullptr,
954 bool allow_intrinsics = true);
955 bool should_delay_inlining(ciMethod* call_method, JVMState* jvms) {
956 return should_delay_string_inlining(call_method, jvms) ||
957 should_delay_boxing_inlining(call_method, jvms) ||
958 should_delay_vector_inlining(call_method, jvms);
959 }
960 bool should_delay_string_inlining(ciMethod* call_method, JVMState* jvms);
961 bool should_delay_boxing_inlining(ciMethod* call_method, JVMState* jvms);
1163 // Number of outgoing stack slots killed above the out_preserve_stack_slots
1164 // for calls to C. Supports the var-args backing area for register parms.
1165 uint varargs_C_out_slots_killed() const;
1166
1167 // Number of Stack Slots consumed by a synchronization entry
1168 int sync_stack_slots() const;
1169
1170 // Compute the name of old_SP. See <arch>.ad for frame layout.
1171 OptoReg::Name compute_old_SP();
1172
1173 private:
1174 // Phase control:
1175 void Init(bool aliasing); // Prepare for a single compilation
1176 void Optimize(); // Given a graph, optimize it
1177 void Code_Gen(); // Generate code from a graph
1178
1179 // Management of the AliasType table.
1180 void grow_alias_types();
1181 AliasCacheEntry* probe_alias_cache(const TypePtr* adr_type);
1182 const TypePtr *flatten_alias_type(const TypePtr* adr_type) const;
1183 AliasType* find_alias_type(const TypePtr* adr_type, bool no_create, ciField* field);
1184
1185 void verify_top(Node*) const PRODUCT_RETURN;
1186
1187 // Intrinsic setup.
1188 CallGenerator* make_vm_intrinsic(ciMethod* m, bool is_virtual); // constructor
1189 int intrinsic_insertion_index(ciMethod* m, bool is_virtual, bool& found); // helper
1190 CallGenerator* find_intrinsic(ciMethod* m, bool is_virtual); // query fn
1191 void register_intrinsic(CallGenerator* cg); // update fn
1192
1193 #ifndef PRODUCT
1194 static juint _intrinsic_hist_count[];
1195 static jubyte _intrinsic_hist_flags[];
1196 #endif
1197 // Function calls made by the public function final_graph_reshaping.
1198 // No need to be made public as they are not called elsewhere.
1199 void final_graph_reshaping_impl(Node *n, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1200 void final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop, Unique_Node_List& dead_nodes);
1201 void final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1202 void eliminate_redundant_card_marks(Node* n);
1203
1239 // End-of-run dumps.
1240 static void print_statistics() PRODUCT_RETURN;
1241
1242 // Verify ADLC assumptions during startup
1243 static void adlc_verification() PRODUCT_RETURN;
1244
1245 // Definitions of pd methods
1246 static void pd_compiler2_init();
1247
1248 // Static parse-time type checking logic for gen_subtype_check:
1249 enum SubTypeCheckResult { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
1250 SubTypeCheckResult static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip = StressReflectiveCode);
1251
1252 static Node* conv_I2X_index(PhaseGVN* phase, Node* offset, const TypeInt* sizetype,
1253 // Optional control dependency (for example, on range check)
1254 Node* ctrl = nullptr);
1255
1256 // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
1257 static Node* constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl, bool carry_dependency = false);
1258
1259 // Auxiliary methods for randomized fuzzing/stressing
1260 int random();
1261 bool randomized_select(int count);
1262
1263 // supporting clone_map
1264 CloneMap& clone_map();
1265 void set_clone_map(Dict* d);
1266
1267 bool needs_clinit_barrier(ciField* ik, ciMethod* accessing_method);
1268 bool needs_clinit_barrier(ciMethod* ik, ciMethod* accessing_method);
1269 bool needs_clinit_barrier(ciInstanceKlass* ik, ciMethod* accessing_method);
1270
1271 #ifdef IA32
1272 private:
1273 bool _select_24_bit_instr; // We selected an instruction with a 24-bit result
1274 bool _in_24_bit_fp_mode; // We are emitting instructions with 24-bit results
1275
1276 // Remember if this compilation changes hardware mode to 24-bit precision.
1277 void set_24_bit_selection_and_mode(bool selection, bool mode) {
1278 _select_24_bit_instr = selection;
1279 _in_24_bit_fp_mode = mode;
|
34 #include "compiler/compilerEvent.hpp"
35 #include "libadt/dict.hpp"
36 #include "libadt/vectset.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "oops/methodData.hpp"
39 #include "opto/idealGraphPrinter.hpp"
40 #include "opto/phasetype.hpp"
41 #include "opto/phase.hpp"
42 #include "opto/regmask.hpp"
43 #include "runtime/deoptimization.hpp"
44 #include "runtime/sharedRuntime.hpp"
45 #include "runtime/timerTrace.hpp"
46 #include "runtime/vmThread.hpp"
47 #include "utilities/ticks.hpp"
48
49 class AbstractLockNode;
50 class AddPNode;
51 class Block;
52 class Bundle;
53 class CallGenerator;
54 class CallNode;
55 class CallStaticJavaNode;
56 class CloneMap;
57 class 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 InlineTypeNode;
98 class nmethod;
99 class Node_Stack;
100 struct Final_Reshape_Counts;
101 class VerifyMeetResult;
102
103 enum LoopOptsMode {
104 LoopOptsDefault,
105 LoopOptsNone,
106 LoopOptsMaxUnroll,
107 LoopOptsShenandoahExpand,
108 LoopOptsShenandoahPostExpand,
109 LoopOptsSkipSplitIf,
110 LoopOptsVerify
111 };
112
113 // The type of all node counts and indexes.
114 // It must hold at least 16 bits, but must also be fast to load and store.
115 // This type, if less than 32 bits, could limit the number of possible nodes.
116 // (To make this type platform-specific, move to globalDefinitions_xxx.hpp.)
117 typedef unsigned int node_idx_t;
313
314 // Control of this compilation.
315 int _max_inline_size; // Max inline size for this compilation
316 int _freq_inline_size; // Max hot method inline size for this compilation
317 int _fixed_slots; // count of frame slots not allocated by the register
318 // allocator i.e. locks, original deopt pc, etc.
319 uintx _max_node_limit; // Max unique node count during a single compilation.
320
321 bool _post_loop_opts_phase; // Loop opts are finished.
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 bool _has_circular_inline_type; // True if method loads an inline type with a circular, non-flat field
334 uint _max_vector_size; // Maximum size of generated vectors
335 bool _clear_upper_avx; // Clear upper bits of ymm registers using vzeroupper
336 uint _trap_hist[trapHistLength]; // Cumulative traps
337 bool _trap_can_recompile; // Have we emitted a recompiling trap?
338 uint _decompile_count; // Cumulative decompilation counts.
339 bool _do_inlining; // True if we intend to do inlining
340 bool _do_scheduling; // True if we intend to do scheduling
341 bool _do_freq_based_layout; // True if we intend to do frequency based block layout
342 bool _do_vector_loop; // True if allowed to execute loop in parallel iterations
343 bool _use_cmove; // True if CMove should be used without profitability analysis
344 bool _do_aliasing; // True if we intend to do aliasing
345 bool _print_assembly; // True if we should dump assembly code for this compilation
346 bool _print_inlining; // True if we should print inlining for this compilation
347 bool _print_intrinsics; // True if we should print intrinsics for this compilation
348 #ifndef PRODUCT
349 uint _igv_idx; // Counter for IGV node identifiers
350 uint _igv_phase_iter[PHASE_NUM_TYPES]; // Counters for IGV phase iterations
351 bool _trace_opto_output;
352 bool _parsed_irreducible_loop; // True if ciTypeFlow detected irreducible loops during parsing
353 #endif
354 bool _has_irreducible_loop; // Found irreducible loops
355 // JSR 292
356 bool _has_method_handle_invokes; // True if this method has MethodHandle invokes.
357 bool _has_monitors; // Metadata transfered to nmethod to enable Continuations lock-detection fastpath
358 bool _clinit_barrier_on_entry; // True if clinit barrier is needed on nmethod entry
359 RTMState _rtm_state; // State of Restricted Transactional Memory usage
360 int _loop_opts_cnt; // loop opts round
361 bool _has_flat_accesses; // Any known flat array accesses?
362 bool _flat_accesses_share_alias; // Initially all flat array share a single slice
363 bool _scalarize_in_safepoints; // Scalarize inline types in safepoint debug info
364 uint _stress_seed; // Seed for stress testing
365
366 // Compilation environment.
367 Arena _comp_arena; // Arena with lifetime equivalent to Compile
368 void* _barrier_set_state; // Potential GC barrier state for Compile
369 ciEnv* _env; // CI interface
370 DirectiveSet* _directive; // Compiler directive
371 CompileLog* _log; // from CompilerThread
372 const char* _failure_reason; // for record_failure/failing pattern
373 CompilationFailureInfo* _first_failure_details; // Details for the first failure happening during compilation
374 GrowableArray<CallGenerator*> _intrinsics; // List of intrinsics.
375 GrowableArray<Node*> _macro_nodes; // List of nodes which need to be expanded before matching.
376 GrowableArray<ParsePredicateNode*> _parse_predicates; // List of Parse Predicates.
377 GrowableArray<Node*> _template_assertion_predicate_opaqs; // List of Opaque4 nodes for Template Assertion Predicates.
378 GrowableArray<Node*> _expensive_nodes; // List of nodes that are expensive to compute and that we'd better not let the GVN freely common
379 GrowableArray<Node*> _for_post_loop_igvn; // List of nodes for IGVN after loop opts are over
380 GrowableArray<Node*> _inline_type_nodes; // List of InlineType nodes
381 GrowableArray<UnstableIfTrap*> _unstable_if_traps; // List of ifnodes after IGVN
382 GrowableArray<Node_List*> _coarsened_locks; // List of coarsened Lock and Unlock nodes
383 ConnectionGraph* _congraph;
384 #ifndef PRODUCT
385 IdealGraphPrinter* _igv_printer;
386 static IdealGraphPrinter* _debug_file_printer;
387 static IdealGraphPrinter* _debug_network_printer;
388 #endif
389
390
391 // Node management
392 uint _unique; // Counter for unique Node indices
393 uint _dead_node_count; // Number of dead nodes; VectorSet::Size() is O(N).
394 // So use this to keep count and make the call O(1).
395 VectorSet _dead_node_list; // Set of dead nodes
396 DEBUG_ONLY(Unique_Node_List* _modified_nodes;) // List of nodes which inputs were modified
397 DEBUG_ONLY(bool _phase_optimize_finished;) // Used for live node verification while creating new nodes
398
399 // Arenas for new-space and old-space nodes.
400 // Swapped between using _node_arena.
627 int do_cleanup() const { return _do_cleanup; }
628 void set_major_progress() { _major_progress++; }
629 void restore_major_progress(int progress) { _major_progress += progress; }
630 void clear_major_progress() { _major_progress = 0; }
631 int max_inline_size() const { return _max_inline_size; }
632 void set_freq_inline_size(int n) { _freq_inline_size = n; }
633 int freq_inline_size() const { return _freq_inline_size; }
634 void set_max_inline_size(int n) { _max_inline_size = n; }
635 bool has_loops() const { return _has_loops; }
636 void set_has_loops(bool z) { _has_loops = z; }
637 bool has_split_ifs() const { return _has_split_ifs; }
638 void set_has_split_ifs(bool z) { _has_split_ifs = z; }
639 bool has_unsafe_access() const { return _has_unsafe_access; }
640 void set_has_unsafe_access(bool z) { _has_unsafe_access = z; }
641 bool has_stringbuilder() const { return _has_stringbuilder; }
642 void set_has_stringbuilder(bool z) { _has_stringbuilder = z; }
643 bool has_boxed_value() const { return _has_boxed_value; }
644 void set_has_boxed_value(bool z) { _has_boxed_value = z; }
645 bool has_reserved_stack_access() const { return _has_reserved_stack_access; }
646 void set_has_reserved_stack_access(bool z) { _has_reserved_stack_access = z; }
647 bool has_circular_inline_type() const { return _has_circular_inline_type; }
648 void set_has_circular_inline_type(bool z) { _has_circular_inline_type = z; }
649 uint max_vector_size() const { return _max_vector_size; }
650 void set_max_vector_size(uint s) { _max_vector_size = s; }
651 bool clear_upper_avx() const { return _clear_upper_avx; }
652 void set_clear_upper_avx(bool s) { _clear_upper_avx = s; }
653 void set_trap_count(uint r, uint c) { assert(r < trapHistLength, "oob"); _trap_hist[r] = c; }
654 uint trap_count(uint r) const { assert(r < trapHistLength, "oob"); return _trap_hist[r]; }
655 bool trap_can_recompile() const { return _trap_can_recompile; }
656 void set_trap_can_recompile(bool z) { _trap_can_recompile = z; }
657 uint decompile_count() const { return _decompile_count; }
658 void set_decompile_count(uint c) { _decompile_count = c; }
659 bool allow_range_check_smearing() const;
660 bool do_inlining() const { return _do_inlining; }
661 void set_do_inlining(bool z) { _do_inlining = z; }
662 bool do_scheduling() const { return _do_scheduling; }
663 void set_do_scheduling(bool z) { _do_scheduling = z; }
664 bool do_freq_based_layout() const{ return _do_freq_based_layout; }
665 void set_do_freq_based_layout(bool z){ _do_freq_based_layout = z; }
666 bool do_vector_loop() const { return _do_vector_loop; }
667 void set_do_vector_loop(bool z) { _do_vector_loop = z; }
668 bool use_cmove() const { return _use_cmove; }
669 void set_use_cmove(bool z) { _use_cmove = z; }
670 bool do_aliasing() const { return _do_aliasing; }
671 bool print_assembly() const { return _print_assembly; }
672 void set_print_assembly(bool z) { _print_assembly = z; }
673 bool print_inlining() const { return _print_inlining; }
674 void set_print_inlining(bool z) { _print_inlining = z; }
675 bool print_intrinsics() const { return _print_intrinsics; }
676 void set_print_intrinsics(bool z) { _print_intrinsics = z; }
677 RTMState rtm_state() const { return _rtm_state; }
678 void set_rtm_state(RTMState s) { _rtm_state = s; }
679 bool use_rtm() const { return (_rtm_state & NoRTM) == 0; }
680 bool profile_rtm() const { return _rtm_state == ProfileRTM; }
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
698 // check the CompilerOracle for special behaviours for this compile
699 bool method_has_option(enum CompileCommand option) {
700 return method() != nullptr && method()->has_option(option);
701 }
702
703 #ifndef PRODUCT
704 uint next_igv_idx() { return _igv_idx++; }
705 bool trace_opto_output() const { return _trace_opto_output; }
706 void print_ideal_ir(const char* phase_name);
707 bool should_print_ideal() const { return _directive->PrintIdealOption; }
708 bool parsed_irreducible_loop() const { return _parsed_irreducible_loop; }
709 void set_parsed_irreducible_loop(bool z) { _parsed_irreducible_loop = z; }
710 int _in_dump_cnt; // Required for dumping ir nodes.
711 #endif
712 bool has_irreducible_loop() const { return _has_irreducible_loop; }
713 void set_has_irreducible_loop(bool z) { _has_irreducible_loop = z; }
714
791 _template_assertion_predicate_opaqs.append(n);
792 }
793
794 void remove_template_assertion_predicate_opaq(Node* n) {
795 if (template_assertion_predicate_count() > 0) {
796 _template_assertion_predicate_opaqs.remove_if_existing(n);
797 }
798 }
799 void add_coarsened_locks(GrowableArray<AbstractLockNode*>& locks);
800 void remove_coarsened_lock(Node* n);
801 bool coarsened_locks_consistent();
802
803 bool post_loop_opts_phase() { return _post_loop_opts_phase; }
804 void set_post_loop_opts_phase() { _post_loop_opts_phase = true; }
805 void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }
806
807 void record_for_post_loop_opts_igvn(Node* n);
808 void remove_from_post_loop_opts_igvn(Node* n);
809 void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
810
811 // Keep track of inline type nodes for later processing
812 void add_inline_type(Node* n);
813 void remove_inline_type(Node* n);
814 void process_inline_types(PhaseIterGVN &igvn, bool remove = false);
815
816 void adjust_flat_array_access_aliases(PhaseIterGVN& igvn);
817
818 void record_unstable_if_trap(UnstableIfTrap* trap);
819 bool remove_unstable_if_trap(CallStaticJavaNode* unc, bool yield);
820 void remove_useless_unstable_if_traps(Unique_Node_List &useful);
821 void process_for_unstable_if_traps(PhaseIterGVN& igvn);
822
823 void shuffle_macro_nodes();
824 void sort_macro_nodes();
825
826 void mark_parse_predicate_nodes_useless(PhaseIterGVN& igvn);
827
828 // Are there candidate expensive nodes for optimization?
829 bool should_optimize_expensive_nodes(PhaseIterGVN &igvn);
830 // Check whether n1 and n2 are similar
831 static int cmp_expensive_nodes(Node* n1, Node* n2);
832 // Sort expensive nodes to locate similar expensive nodes
833 void sort_expensive_nodes();
834
835 // Compilation environment.
836 Arena* comp_arena() { return &_comp_arena; }
837 ciEnv* env() const { return _env; }
943 Arena* type_arena() { return _type_arena; }
944 Dict* type_dict() { return _type_dict; }
945 size_t type_last_size() { return _type_last_size; }
946 int num_alias_types() { return _num_alias_types; }
947
948 void init_type_arena() { _type_arena = &_Compile_types; }
949 void set_type_arena(Arena* a) { _type_arena = a; }
950 void set_type_dict(Dict* d) { _type_dict = d; }
951 void set_type_last_size(size_t sz) { _type_last_size = sz; }
952
953 const TypeFunc* last_tf(ciMethod* m) {
954 return (m == _last_tf_m) ? _last_tf : nullptr;
955 }
956 void set_last_tf(ciMethod* m, const TypeFunc* tf) {
957 assert(m != nullptr || tf == nullptr, "");
958 _last_tf_m = m;
959 _last_tf = tf;
960 }
961
962 AliasType* alias_type(int idx) { assert(idx < num_alias_types(), "oob"); return _alias_types[idx]; }
963 AliasType* alias_type(const TypePtr* adr_type, ciField* field = nullptr, bool uncached = false) { return find_alias_type(adr_type, false, field, uncached); }
964 bool have_alias_type(const TypePtr* adr_type);
965 AliasType* alias_type(ciField* field);
966
967 int get_alias_index(const TypePtr* at, bool uncached = false) { return alias_type(at, nullptr, uncached)->index(); }
968 const TypePtr* get_adr_type(uint aidx) { return alias_type(aidx)->adr_type(); }
969 int get_general_index(uint aidx) { return alias_type(aidx)->general_index(); }
970
971 // Building nodes
972 void rethrow_exceptions(JVMState* jvms);
973 void return_values(JVMState* jvms);
974 JVMState* build_start_state(StartNode* start, const TypeFunc* tf);
975
976 // Decide how to build a call.
977 // The profile factor is a discount to apply to this site's interp. profile.
978 CallGenerator* call_generator(ciMethod* call_method, int vtable_index, bool call_does_dispatch,
979 JVMState* jvms, bool allow_inline, float profile_factor, ciKlass* speculative_receiver_type = nullptr,
980 bool allow_intrinsics = true);
981 bool should_delay_inlining(ciMethod* call_method, JVMState* jvms) {
982 return should_delay_string_inlining(call_method, jvms) ||
983 should_delay_boxing_inlining(call_method, jvms) ||
984 should_delay_vector_inlining(call_method, jvms);
985 }
986 bool should_delay_string_inlining(ciMethod* call_method, JVMState* jvms);
987 bool should_delay_boxing_inlining(ciMethod* call_method, JVMState* jvms);
1189 // Number of outgoing stack slots killed above the out_preserve_stack_slots
1190 // for calls to C. Supports the var-args backing area for register parms.
1191 uint varargs_C_out_slots_killed() const;
1192
1193 // Number of Stack Slots consumed by a synchronization entry
1194 int sync_stack_slots() const;
1195
1196 // Compute the name of old_SP. See <arch>.ad for frame layout.
1197 OptoReg::Name compute_old_SP();
1198
1199 private:
1200 // Phase control:
1201 void Init(bool aliasing); // Prepare for a single compilation
1202 void Optimize(); // Given a graph, optimize it
1203 void Code_Gen(); // Generate code from a graph
1204
1205 // Management of the AliasType table.
1206 void grow_alias_types();
1207 AliasCacheEntry* probe_alias_cache(const TypePtr* adr_type);
1208 const TypePtr *flatten_alias_type(const TypePtr* adr_type) const;
1209 AliasType* find_alias_type(const TypePtr* adr_type, bool no_create, ciField* field, bool uncached = false);
1210
1211 void verify_top(Node*) const PRODUCT_RETURN;
1212
1213 // Intrinsic setup.
1214 CallGenerator* make_vm_intrinsic(ciMethod* m, bool is_virtual); // constructor
1215 int intrinsic_insertion_index(ciMethod* m, bool is_virtual, bool& found); // helper
1216 CallGenerator* find_intrinsic(ciMethod* m, bool is_virtual); // query fn
1217 void register_intrinsic(CallGenerator* cg); // update fn
1218
1219 #ifndef PRODUCT
1220 static juint _intrinsic_hist_count[];
1221 static jubyte _intrinsic_hist_flags[];
1222 #endif
1223 // Function calls made by the public function final_graph_reshaping.
1224 // No need to be made public as they are not called elsewhere.
1225 void final_graph_reshaping_impl(Node *n, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1226 void final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop, Unique_Node_List& dead_nodes);
1227 void final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1228 void eliminate_redundant_card_marks(Node* n);
1229
1265 // End-of-run dumps.
1266 static void print_statistics() PRODUCT_RETURN;
1267
1268 // Verify ADLC assumptions during startup
1269 static void adlc_verification() PRODUCT_RETURN;
1270
1271 // Definitions of pd methods
1272 static void pd_compiler2_init();
1273
1274 // Static parse-time type checking logic for gen_subtype_check:
1275 enum SubTypeCheckResult { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
1276 SubTypeCheckResult static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip = StressReflectiveCode);
1277
1278 static Node* conv_I2X_index(PhaseGVN* phase, Node* offset, const TypeInt* sizetype,
1279 // Optional control dependency (for example, on range check)
1280 Node* ctrl = nullptr);
1281
1282 // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
1283 static Node* constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl, bool carry_dependency = false);
1284
1285 Node* optimize_acmp(PhaseGVN* phase, Node* a, Node* b);
1286
1287 // Auxiliary method for randomized fuzzing/stressing
1288 int random();
1289 bool randomized_select(int count);
1290
1291 // supporting clone_map
1292 CloneMap& clone_map();
1293 void set_clone_map(Dict* d);
1294
1295 bool needs_clinit_barrier(ciField* ik, ciMethod* accessing_method);
1296 bool needs_clinit_barrier(ciMethod* ik, ciMethod* accessing_method);
1297 bool needs_clinit_barrier(ciInstanceKlass* ik, ciMethod* accessing_method);
1298
1299 #ifdef IA32
1300 private:
1301 bool _select_24_bit_instr; // We selected an instruction with a 24-bit result
1302 bool _in_24_bit_fp_mode; // We are emitting instructions with 24-bit results
1303
1304 // Remember if this compilation changes hardware mode to 24-bit precision.
1305 void set_24_bit_selection_and_mode(bool selection, bool mode) {
1306 _select_24_bit_instr = selection;
1307 _in_24_bit_fp_mode = mode;
|