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 #include "opto/printinlining.hpp"
50
51 class AbstractLockNode;
52 class AddPNode;
53 class Block;
54 class Bundle;
55 class CallGenerator;
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 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 // 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
582 int do_cleanup() const { return _do_cleanup; }
583 void set_major_progress() { _major_progress++; }
584 void restore_major_progress(int progress) { _major_progress += progress; }
585 void clear_major_progress() { _major_progress = 0; }
586 int max_inline_size() const { return _max_inline_size; }
587 void set_freq_inline_size(int n) { _freq_inline_size = n; }
588 int freq_inline_size() const { return _freq_inline_size; }
589 void set_max_inline_size(int n) { _max_inline_size = n; }
590 bool has_loops() const { return _has_loops; }
591 void set_has_loops(bool z) { _has_loops = z; }
592 bool has_split_ifs() const { return _has_split_ifs; }
593 void set_has_split_ifs(bool z) { _has_split_ifs = z; }
594 bool has_unsafe_access() const { return _has_unsafe_access; }
595 void set_has_unsafe_access(bool z) { _has_unsafe_access = z; }
596 bool has_stringbuilder() const { return _has_stringbuilder; }
597 void set_has_stringbuilder(bool z) { _has_stringbuilder = z; }
598 bool has_boxed_value() const { return _has_boxed_value; }
599 void set_has_boxed_value(bool z) { _has_boxed_value = z; }
600 bool has_reserved_stack_access() const { return _has_reserved_stack_access; }
601 void set_has_reserved_stack_access(bool z) { _has_reserved_stack_access = z; }
602 uint max_vector_size() const { return _max_vector_size; }
603 void set_max_vector_size(uint s) { _max_vector_size = s; }
604 bool clear_upper_avx() const { return _clear_upper_avx; }
605 void set_clear_upper_avx(bool s) { _clear_upper_avx = s; }
606 void set_trap_count(uint r, uint c) { assert(r < trapHistLength, "oob"); _trap_hist[r] = c; }
607 uint trap_count(uint r) const { assert(r < trapHistLength, "oob"); return _trap_hist[r]; }
608 bool trap_can_recompile() const { return _trap_can_recompile; }
609 void set_trap_can_recompile(bool z) { _trap_can_recompile = z; }
610 uint decompile_count() const { return _decompile_count; }
611 void set_decompile_count(uint c) { _decompile_count = c; }
612 bool allow_range_check_smearing() const;
613 bool do_inlining() const { return _do_inlining; }
614 void set_do_inlining(bool z) { _do_inlining = z; }
615 bool do_scheduling() const { return _do_scheduling; }
616 void set_do_scheduling(bool z) { _do_scheduling = z; }
617 bool do_freq_based_layout() const{ return _do_freq_based_layout; }
618 void set_do_freq_based_layout(bool z){ _do_freq_based_layout = z; }
619 bool do_vector_loop() const { return _do_vector_loop; }
620 void set_do_vector_loop(bool z) { _do_vector_loop = z; }
621 bool use_cmove() const { return _use_cmove; }
622 void set_use_cmove(bool z) { _use_cmove = z; }
623 bool do_aliasing() const { return _do_aliasing; }
624 bool print_assembly() const { return _print_assembly; }
625 void set_print_assembly(bool z) { _print_assembly = z; }
626 bool print_inlining() const { return _print_inlining; }
627 void set_print_inlining(bool z) { _print_inlining = z; }
628 bool print_intrinsics() const { return _print_intrinsics; }
629 void set_print_intrinsics(bool z) { _print_intrinsics = z; }
630 uint max_node_limit() const { return (uint)_max_node_limit; }
631 void set_max_node_limit(uint n) { _max_node_limit = n; }
632 bool clinit_barrier_on_entry() { return _clinit_barrier_on_entry; }
633 void set_clinit_barrier_on_entry(bool z) { _clinit_barrier_on_entry = z; }
634 bool has_monitors() const { return _has_monitors; }
635 void set_has_monitors(bool v) { _has_monitors = v; }
636 bool has_scoped_access() const { return _has_scoped_access; }
637 void set_has_scoped_access(bool v) { _has_scoped_access = v; }
638
639 // check the CompilerOracle for special behaviours for this compile
640 bool method_has_option(CompileCommandEnum option) {
641 return method() != nullptr && method()->has_option(option);
642 }
643
644 #ifndef PRODUCT
645 uint next_igv_idx() { return _igv_idx++; }
646 bool trace_opto_output() const { return _trace_opto_output; }
647 void print_ideal_ir(const char* phase_name);
648 bool should_print_ideal() const { return _directive->PrintIdealOption; }
649 bool parsed_irreducible_loop() const { return _parsed_irreducible_loop; }
650 void set_parsed_irreducible_loop(bool z) { _parsed_irreducible_loop = z; }
651 int _in_dump_cnt; // Required for dumping ir nodes.
652 #endif
653 bool has_irreducible_loop() const { return _has_irreducible_loop; }
744 bool coarsened_locks_consistent();
745 void mark_unbalanced_boxes() const;
746
747 bool post_loop_opts_phase() { return _post_loop_opts_phase; }
748 void set_post_loop_opts_phase() { _post_loop_opts_phase = true; }
749 void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }
750
751 #ifdef ASSERT
752 bool phase_verify_ideal_loop() const { return _phase_verify_ideal_loop; }
753 void set_phase_verify_ideal_loop() { _phase_verify_ideal_loop = true; }
754 void reset_phase_verify_ideal_loop() { _phase_verify_ideal_loop = false; }
755 #endif
756
757 bool allow_macro_nodes() { return _allow_macro_nodes; }
758 void reset_allow_macro_nodes() { _allow_macro_nodes = false; }
759
760 void record_for_post_loop_opts_igvn(Node* n);
761 void remove_from_post_loop_opts_igvn(Node* n);
762 void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
763
764 void record_unstable_if_trap(UnstableIfTrap* trap);
765 bool remove_unstable_if_trap(CallStaticJavaNode* unc, bool yield);
766 void remove_useless_unstable_if_traps(Unique_Node_List &useful);
767 void process_for_unstable_if_traps(PhaseIterGVN& igvn);
768
769 void shuffle_macro_nodes();
770 void sort_macro_nodes();
771
772 void mark_parse_predicate_nodes_useless(PhaseIterGVN& igvn);
773
774 // Are there candidate expensive nodes for optimization?
775 bool should_optimize_expensive_nodes(PhaseIterGVN &igvn);
776 // Check whether n1 and n2 are similar
777 static int cmp_expensive_nodes(Node* n1, Node* n2);
778 // Sort expensive nodes to locate similar expensive nodes
779 void sort_expensive_nodes();
780
781 // Compilation environment.
782 Arena* comp_arena() { return &_comp_arena; }
783 ciEnv* env() const { return _env; }
920 Arena* type_arena() { return _type_arena; }
921 Dict* type_dict() { return _type_dict; }
922 size_t type_last_size() { return _type_last_size; }
923 int num_alias_types() { return _num_alias_types; }
924
925 void init_type_arena() { _type_arena = &_Compile_types; }
926 void set_type_arena(Arena* a) { _type_arena = a; }
927 void set_type_dict(Dict* d) { _type_dict = d; }
928 void set_type_last_size(size_t sz) { _type_last_size = sz; }
929
930 const TypeFunc* last_tf(ciMethod* m) {
931 return (m == _last_tf_m) ? _last_tf : nullptr;
932 }
933 void set_last_tf(ciMethod* m, const TypeFunc* tf) {
934 assert(m != nullptr || tf == nullptr, "");
935 _last_tf_m = m;
936 _last_tf = tf;
937 }
938
939 AliasType* alias_type(int idx) { assert(idx < num_alias_types(), "oob"); return _alias_types[idx]; }
940 AliasType* alias_type(const TypePtr* adr_type, ciField* field = nullptr) { return find_alias_type(adr_type, false, field); }
941 bool have_alias_type(const TypePtr* adr_type);
942 AliasType* alias_type(ciField* field);
943
944 int get_alias_index(const TypePtr* at) { return alias_type(at)->index(); }
945 const TypePtr* get_adr_type(uint aidx) { return alias_type(aidx)->adr_type(); }
946 int get_general_index(uint aidx) { return alias_type(aidx)->general_index(); }
947
948 // Building nodes
949 void rethrow_exceptions(JVMState* jvms);
950 void return_values(JVMState* jvms);
951 JVMState* build_start_state(StartNode* start, const TypeFunc* tf);
952
953 // Decide how to build a call.
954 // The profile factor is a discount to apply to this site's interp. profile.
955 CallGenerator* call_generator(ciMethod* call_method, int vtable_index, bool call_does_dispatch,
956 JVMState* jvms, bool allow_inline, float profile_factor, ciKlass* speculative_receiver_type = nullptr,
957 bool allow_intrinsics = true);
958 bool should_delay_inlining(ciMethod* call_method, JVMState* jvms) {
959 return should_delay_string_inlining(call_method, jvms) ||
960 should_delay_boxing_inlining(call_method, jvms) ||
961 should_delay_vector_inlining(call_method, jvms);
962 }
963 bool should_delay_string_inlining(ciMethod* call_method, JVMState* jvms);
964 bool should_delay_boxing_inlining(ciMethod* call_method, JVMState* jvms);
1165 // Number of outgoing stack slots killed above the out_preserve_stack_slots
1166 // for calls to C. Supports the var-args backing area for register parms.
1167 uint varargs_C_out_slots_killed() const;
1168
1169 // Number of Stack Slots consumed by a synchronization entry
1170 int sync_stack_slots() const;
1171
1172 // Compute the name of old_SP. See <arch>.ad for frame layout.
1173 OptoReg::Name compute_old_SP();
1174
1175 private:
1176 // Phase control:
1177 void Init(bool aliasing); // Prepare for a single compilation
1178 void Optimize(); // Given a graph, optimize it
1179 void Code_Gen(); // Generate code from a graph
1180
1181 // Management of the AliasType table.
1182 void grow_alias_types();
1183 AliasCacheEntry* probe_alias_cache(const TypePtr* adr_type);
1184 const TypePtr *flatten_alias_type(const TypePtr* adr_type) const;
1185 AliasType* find_alias_type(const TypePtr* adr_type, bool no_create, ciField* field);
1186
1187 void verify_top(Node*) const PRODUCT_RETURN;
1188
1189 // Intrinsic setup.
1190 CallGenerator* make_vm_intrinsic(ciMethod* m, bool is_virtual); // constructor
1191 int intrinsic_insertion_index(ciMethod* m, bool is_virtual, bool& found); // helper
1192 CallGenerator* find_intrinsic(ciMethod* m, bool is_virtual); // query fn
1193 void register_intrinsic(CallGenerator* cg); // update fn
1194
1195 #ifndef PRODUCT
1196 static juint _intrinsic_hist_count[];
1197 static jubyte _intrinsic_hist_flags[];
1198 #endif
1199 // Function calls made by the public function final_graph_reshaping.
1200 // No need to be made public as they are not called elsewhere.
1201 void final_graph_reshaping_impl(Node *n, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1202 void final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop, Unique_Node_List& dead_nodes);
1203 void final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1204 void handle_div_mod_op(Node* n, BasicType bt, bool is_unsigned);
1205
1241 // End-of-run dumps.
1242 static void print_statistics() PRODUCT_RETURN;
1243
1244 // Verify ADLC assumptions during startup
1245 static void adlc_verification() PRODUCT_RETURN;
1246
1247 // Definitions of pd methods
1248 static void pd_compiler2_init();
1249
1250 // Static parse-time type checking logic for gen_subtype_check:
1251 enum SubTypeCheckResult { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
1252 SubTypeCheckResult static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip = StressReflectiveCode);
1253
1254 static Node* conv_I2X_index(PhaseGVN* phase, Node* offset, const TypeInt* sizetype,
1255 // Optional control dependency (for example, on range check)
1256 Node* ctrl = nullptr);
1257
1258 // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
1259 static Node* constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl, bool carry_dependency = false);
1260
1261 // Auxiliary methods for randomized fuzzing/stressing
1262 int random();
1263 bool randomized_select(int count);
1264
1265 // seed random number generation and log the seed for repeatability.
1266 void initialize_stress_seed(const DirectiveSet* directive);
1267
1268 // supporting clone_map
1269 CloneMap& clone_map();
1270 void set_clone_map(Dict* d);
1271
1272 bool needs_clinit_barrier(ciField* ik, ciMethod* accessing_method);
1273 bool needs_clinit_barrier(ciMethod* ik, ciMethod* accessing_method);
1274 bool needs_clinit_barrier(ciInstanceKlass* ik, ciMethod* accessing_method);
1275
1276 #ifdef IA32
1277 private:
1278 bool _select_24_bit_instr; // We selected an instruction with a 24-bit result
1279 bool _in_24_bit_fp_mode; // We are emitting instructions with 24-bit results
1280
1281 // Remember if this compilation changes hardware mode to 24-bit precision.
|
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 #include "opto/printinlining.hpp"
50
51 class AbstractLockNode;
52 class AddPNode;
53 class Block;
54 class Bundle;
55 class CallGenerator;
56 class CallNode;
57 class CallStaticJavaNode;
58 class CloneMap;
59 class CompilationFailureInfo;
60 class ConnectionGraph;
61 class IdealGraphPrinter;
62 class InlineTree;
63 class Matcher;
64 class MachConstantNode;
65 class MachConstantBaseNode;
66 class MachNode;
67 class MachOper;
68 class MachSafePointNode;
69 class Node;
70 class Node_Array;
71 class Node_List;
72 class Node_Notes;
73 class NodeHash;
74 class NodeCloneInfo;
75 class OptoReg;
76 class ParsePredicateNode;
79 class PhaseIterGVN;
80 class PhaseRegAlloc;
81 class PhaseCCP;
82 class PhaseOutput;
83 class RootNode;
84 class relocInfo;
85 class StartNode;
86 class SafePointNode;
87 class JVMState;
88 class Type;
89 class TypeInt;
90 class TypeInteger;
91 class TypeKlassPtr;
92 class TypePtr;
93 class TypeOopPtr;
94 class TypeFunc;
95 class TypeVect;
96 class Type_Array;
97 class Unique_Node_List;
98 class UnstableIfTrap;
99 class InlineTypeNode;
100 class nmethod;
101 class Node_Stack;
102 struct Final_Reshape_Counts;
103 class VerifyMeetResult;
104
105 enum LoopOptsMode {
106 LoopOptsDefault,
107 LoopOptsNone,
108 LoopOptsMaxUnroll,
109 LoopOptsShenandoahExpand,
110 LoopOptsShenandoahPostExpand,
111 LoopOptsSkipSplitIf,
112 LoopOptsVerify
113 };
114
115 // The type of all node counts and indexes.
116 // It must hold at least 16 bits, but must also be fast to load and store.
117 // This type, if less than 32 bits, could limit the number of possible nodes.
118 // (To make this type platform-specific, move to globalDefinitions_xxx.hpp.)
119 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
589 int do_cleanup() const { return _do_cleanup; }
590 void set_major_progress() { _major_progress++; }
591 void restore_major_progress(int progress) { _major_progress += progress; }
592 void clear_major_progress() { _major_progress = 0; }
593 int max_inline_size() const { return _max_inline_size; }
594 void set_freq_inline_size(int n) { _freq_inline_size = n; }
595 int freq_inline_size() const { return _freq_inline_size; }
596 void set_max_inline_size(int n) { _max_inline_size = n; }
597 bool has_loops() const { return _has_loops; }
598 void set_has_loops(bool z) { _has_loops = z; }
599 bool has_split_ifs() const { return _has_split_ifs; }
600 void set_has_split_ifs(bool z) { _has_split_ifs = z; }
601 bool has_unsafe_access() const { return _has_unsafe_access; }
602 void set_has_unsafe_access(bool z) { _has_unsafe_access = z; }
603 bool has_stringbuilder() const { return _has_stringbuilder; }
604 void set_has_stringbuilder(bool z) { _has_stringbuilder = z; }
605 bool has_boxed_value() const { return _has_boxed_value; }
606 void set_has_boxed_value(bool z) { _has_boxed_value = z; }
607 bool has_reserved_stack_access() const { return _has_reserved_stack_access; }
608 void set_has_reserved_stack_access(bool z) { _has_reserved_stack_access = z; }
609 bool has_circular_inline_type() const { return _has_circular_inline_type; }
610 void set_has_circular_inline_type(bool z) { _has_circular_inline_type = z; }
611 uint max_vector_size() const { return _max_vector_size; }
612 void set_max_vector_size(uint s) { _max_vector_size = s; }
613 bool clear_upper_avx() const { return _clear_upper_avx; }
614 void set_clear_upper_avx(bool s) { _clear_upper_avx = s; }
615 void set_trap_count(uint r, uint c) { assert(r < trapHistLength, "oob"); _trap_hist[r] = c; }
616 uint trap_count(uint r) const { assert(r < trapHistLength, "oob"); return _trap_hist[r]; }
617 bool trap_can_recompile() const { return _trap_can_recompile; }
618 void set_trap_can_recompile(bool z) { _trap_can_recompile = z; }
619 uint decompile_count() const { return _decompile_count; }
620 void set_decompile_count(uint c) { _decompile_count = c; }
621 bool allow_range_check_smearing() const;
622 bool do_inlining() const { return _do_inlining; }
623 void set_do_inlining(bool z) { _do_inlining = z; }
624 bool do_scheduling() const { return _do_scheduling; }
625 void set_do_scheduling(bool z) { _do_scheduling = z; }
626 bool do_freq_based_layout() const{ return _do_freq_based_layout; }
627 void set_do_freq_based_layout(bool z){ _do_freq_based_layout = z; }
628 bool do_vector_loop() const { return _do_vector_loop; }
629 void set_do_vector_loop(bool z) { _do_vector_loop = z; }
630 bool use_cmove() const { return _use_cmove; }
631 void set_use_cmove(bool z) { _use_cmove = z; }
632 bool do_aliasing() const { return _do_aliasing; }
633 bool print_assembly() const { return _print_assembly; }
634 void set_print_assembly(bool z) { _print_assembly = z; }
635 bool print_inlining() const { return _print_inlining; }
636 void set_print_inlining(bool z) { _print_inlining = z; }
637 bool print_intrinsics() const { return _print_intrinsics; }
638 void set_print_intrinsics(bool z) { _print_intrinsics = z; }
639 uint max_node_limit() const { return (uint)_max_node_limit; }
640 void set_max_node_limit(uint n) { _max_node_limit = n; }
641 bool clinit_barrier_on_entry() { return _clinit_barrier_on_entry; }
642 void set_clinit_barrier_on_entry(bool z) { _clinit_barrier_on_entry = z; }
643 void set_flat_accesses() { _has_flat_accesses = true; }
644 bool flat_accesses_share_alias() const { return _flat_accesses_share_alias; }
645 void set_flat_accesses_share_alias(bool z) { _flat_accesses_share_alias = z; }
646 bool scalarize_in_safepoints() const { return _scalarize_in_safepoints; }
647 void set_scalarize_in_safepoints(bool z) { _scalarize_in_safepoints = z; }
648
649 // Support for scalarized inline type calling convention
650 bool has_scalarized_args() const { return _method != nullptr && _method->has_scalarized_args(); }
651 bool needs_stack_repair() const { return _method != nullptr && _method->get_Method()->c2_needs_stack_repair(); }
652
653 bool has_monitors() const { return _has_monitors; }
654 void set_has_monitors(bool v) { _has_monitors = v; }
655 bool has_scoped_access() const { return _has_scoped_access; }
656 void set_has_scoped_access(bool v) { _has_scoped_access = v; }
657
658 // check the CompilerOracle for special behaviours for this compile
659 bool method_has_option(CompileCommandEnum option) {
660 return method() != nullptr && method()->has_option(option);
661 }
662
663 #ifndef PRODUCT
664 uint next_igv_idx() { return _igv_idx++; }
665 bool trace_opto_output() const { return _trace_opto_output; }
666 void print_ideal_ir(const char* phase_name);
667 bool should_print_ideal() const { return _directive->PrintIdealOption; }
668 bool parsed_irreducible_loop() const { return _parsed_irreducible_loop; }
669 void set_parsed_irreducible_loop(bool z) { _parsed_irreducible_loop = z; }
670 int _in_dump_cnt; // Required for dumping ir nodes.
671 #endif
672 bool has_irreducible_loop() const { return _has_irreducible_loop; }
763 bool coarsened_locks_consistent();
764 void mark_unbalanced_boxes() const;
765
766 bool post_loop_opts_phase() { return _post_loop_opts_phase; }
767 void set_post_loop_opts_phase() { _post_loop_opts_phase = true; }
768 void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }
769
770 #ifdef ASSERT
771 bool phase_verify_ideal_loop() const { return _phase_verify_ideal_loop; }
772 void set_phase_verify_ideal_loop() { _phase_verify_ideal_loop = true; }
773 void reset_phase_verify_ideal_loop() { _phase_verify_ideal_loop = false; }
774 #endif
775
776 bool allow_macro_nodes() { return _allow_macro_nodes; }
777 void reset_allow_macro_nodes() { _allow_macro_nodes = false; }
778
779 void record_for_post_loop_opts_igvn(Node* n);
780 void remove_from_post_loop_opts_igvn(Node* n);
781 void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
782
783 // Keep track of inline type nodes for later processing
784 void add_inline_type(Node* n);
785 void remove_inline_type(Node* n);
786 void process_inline_types(PhaseIterGVN &igvn, bool remove = false);
787
788 void adjust_flat_array_access_aliases(PhaseIterGVN& igvn);
789
790 void record_unstable_if_trap(UnstableIfTrap* trap);
791 bool remove_unstable_if_trap(CallStaticJavaNode* unc, bool yield);
792 void remove_useless_unstable_if_traps(Unique_Node_List &useful);
793 void process_for_unstable_if_traps(PhaseIterGVN& igvn);
794
795 void shuffle_macro_nodes();
796 void sort_macro_nodes();
797
798 void mark_parse_predicate_nodes_useless(PhaseIterGVN& igvn);
799
800 // Are there candidate expensive nodes for optimization?
801 bool should_optimize_expensive_nodes(PhaseIterGVN &igvn);
802 // Check whether n1 and n2 are similar
803 static int cmp_expensive_nodes(Node* n1, Node* n2);
804 // Sort expensive nodes to locate similar expensive nodes
805 void sort_expensive_nodes();
806
807 // Compilation environment.
808 Arena* comp_arena() { return &_comp_arena; }
809 ciEnv* env() const { return _env; }
946 Arena* type_arena() { return _type_arena; }
947 Dict* type_dict() { return _type_dict; }
948 size_t type_last_size() { return _type_last_size; }
949 int num_alias_types() { return _num_alias_types; }
950
951 void init_type_arena() { _type_arena = &_Compile_types; }
952 void set_type_arena(Arena* a) { _type_arena = a; }
953 void set_type_dict(Dict* d) { _type_dict = d; }
954 void set_type_last_size(size_t sz) { _type_last_size = sz; }
955
956 const TypeFunc* last_tf(ciMethod* m) {
957 return (m == _last_tf_m) ? _last_tf : nullptr;
958 }
959 void set_last_tf(ciMethod* m, const TypeFunc* tf) {
960 assert(m != nullptr || tf == nullptr, "");
961 _last_tf_m = m;
962 _last_tf = tf;
963 }
964
965 AliasType* alias_type(int idx) { assert(idx < num_alias_types(), "oob"); return _alias_types[idx]; }
966 AliasType* alias_type(const TypePtr* adr_type, ciField* field = nullptr, bool uncached = false) { return find_alias_type(adr_type, false, field, uncached); }
967 bool have_alias_type(const TypePtr* adr_type);
968 AliasType* alias_type(ciField* field);
969
970 int get_alias_index(const TypePtr* at, bool uncached = false) { return alias_type(at, nullptr, uncached)->index(); }
971 const TypePtr* get_adr_type(uint aidx) { return alias_type(aidx)->adr_type(); }
972 int get_general_index(uint aidx) { return alias_type(aidx)->general_index(); }
973
974 // Building nodes
975 void rethrow_exceptions(JVMState* jvms);
976 void return_values(JVMState* jvms);
977 JVMState* build_start_state(StartNode* start, const TypeFunc* tf);
978
979 // Decide how to build a call.
980 // The profile factor is a discount to apply to this site's interp. profile.
981 CallGenerator* call_generator(ciMethod* call_method, int vtable_index, bool call_does_dispatch,
982 JVMState* jvms, bool allow_inline, float profile_factor, ciKlass* speculative_receiver_type = nullptr,
983 bool allow_intrinsics = true);
984 bool should_delay_inlining(ciMethod* call_method, JVMState* jvms) {
985 return should_delay_string_inlining(call_method, jvms) ||
986 should_delay_boxing_inlining(call_method, jvms) ||
987 should_delay_vector_inlining(call_method, jvms);
988 }
989 bool should_delay_string_inlining(ciMethod* call_method, JVMState* jvms);
990 bool should_delay_boxing_inlining(ciMethod* call_method, JVMState* jvms);
1191 // Number of outgoing stack slots killed above the out_preserve_stack_slots
1192 // for calls to C. Supports the var-args backing area for register parms.
1193 uint varargs_C_out_slots_killed() const;
1194
1195 // Number of Stack Slots consumed by a synchronization entry
1196 int sync_stack_slots() const;
1197
1198 // Compute the name of old_SP. See <arch>.ad for frame layout.
1199 OptoReg::Name compute_old_SP();
1200
1201 private:
1202 // Phase control:
1203 void Init(bool aliasing); // Prepare for a single compilation
1204 void Optimize(); // Given a graph, optimize it
1205 void Code_Gen(); // Generate code from a graph
1206
1207 // Management of the AliasType table.
1208 void grow_alias_types();
1209 AliasCacheEntry* probe_alias_cache(const TypePtr* adr_type);
1210 const TypePtr *flatten_alias_type(const TypePtr* adr_type) const;
1211 AliasType* find_alias_type(const TypePtr* adr_type, bool no_create, ciField* field, bool uncached = false);
1212
1213 void verify_top(Node*) const PRODUCT_RETURN;
1214
1215 // Intrinsic setup.
1216 CallGenerator* make_vm_intrinsic(ciMethod* m, bool is_virtual); // constructor
1217 int intrinsic_insertion_index(ciMethod* m, bool is_virtual, bool& found); // helper
1218 CallGenerator* find_intrinsic(ciMethod* m, bool is_virtual); // query fn
1219 void register_intrinsic(CallGenerator* cg); // update fn
1220
1221 #ifndef PRODUCT
1222 static juint _intrinsic_hist_count[];
1223 static jubyte _intrinsic_hist_flags[];
1224 #endif
1225 // Function calls made by the public function final_graph_reshaping.
1226 // No need to be made public as they are not called elsewhere.
1227 void final_graph_reshaping_impl(Node *n, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1228 void final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop, Unique_Node_List& dead_nodes);
1229 void final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1230 void handle_div_mod_op(Node* n, BasicType bt, bool is_unsigned);
1231
1267 // End-of-run dumps.
1268 static void print_statistics() PRODUCT_RETURN;
1269
1270 // Verify ADLC assumptions during startup
1271 static void adlc_verification() PRODUCT_RETURN;
1272
1273 // Definitions of pd methods
1274 static void pd_compiler2_init();
1275
1276 // Static parse-time type checking logic for gen_subtype_check:
1277 enum SubTypeCheckResult { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
1278 SubTypeCheckResult static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip = StressReflectiveCode);
1279
1280 static Node* conv_I2X_index(PhaseGVN* phase, Node* offset, const TypeInt* sizetype,
1281 // Optional control dependency (for example, on range check)
1282 Node* ctrl = nullptr);
1283
1284 // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
1285 static Node* constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl, bool carry_dependency = false);
1286
1287 Node* optimize_acmp(PhaseGVN* phase, Node* a, Node* b);
1288
1289 // Auxiliary method for randomized fuzzing/stressing
1290 int random();
1291 bool randomized_select(int count);
1292
1293 // seed random number generation and log the seed for repeatability.
1294 void initialize_stress_seed(const DirectiveSet* directive);
1295
1296 // supporting clone_map
1297 CloneMap& clone_map();
1298 void set_clone_map(Dict* d);
1299
1300 bool needs_clinit_barrier(ciField* ik, ciMethod* accessing_method);
1301 bool needs_clinit_barrier(ciMethod* ik, ciMethod* accessing_method);
1302 bool needs_clinit_barrier(ciInstanceKlass* ik, ciMethod* accessing_method);
1303
1304 #ifdef IA32
1305 private:
1306 bool _select_24_bit_instr; // We selected an instruction with a 24-bit result
1307 bool _in_24_bit_fp_mode; // We are emitting instructions with 24-bit results
1308
1309 // Remember if this compilation changes hardware mode to 24-bit precision.
|