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 OpaqueTemplateAssertionPredicateNode;
75 class OptoReg;
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 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 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 bool _merge_stores_phase; // Phase for merging stores, after post loop opts phase.
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 uint _max_vector_size; // Maximum size of generated vectors
336 bool _clear_upper_avx; // Clear upper bits of ymm registers using vzeroupper
337 uint _trap_hist[trapHistLength]; // Cumulative traps
338 bool _trap_can_recompile; // Have we emitted a recompiling trap?
339 uint _decompile_count; // Cumulative decompilation counts.
340 bool _do_inlining; // True if we intend to do inlining
341 bool _do_scheduling; // True if we intend to do scheduling
342 bool _do_freq_based_layout; // True if we intend to do frequency based block layout
343 bool _do_vector_loop; // True if allowed to execute loop in parallel iterations
344 bool _use_cmove; // True if CMove should be used without profitability analysis
345 bool _do_aliasing; // True if we intend to do aliasing
346 bool _print_assembly; // True if we should dump assembly code for this compilation
347 bool _print_inlining; // True if we should print inlining for this compilation
348 bool _print_intrinsics; // True if we should print intrinsics for this compilation
349 #ifndef PRODUCT
350 uint _igv_idx; // Counter for IGV node identifiers
351 uint _igv_phase_iter[PHASE_NUM_TYPES]; // Counters for IGV phase iterations
352 bool _trace_opto_output;
353 bool _parsed_irreducible_loop; // True if ciTypeFlow detected irreducible loops during parsing
354 #endif
355 bool _has_irreducible_loop; // Found irreducible loops
356 // JSR 292
357 bool _has_method_handle_invokes; // True if this method has MethodHandle invokes.
358 bool _has_monitors; // Metadata transfered to nmethod to enable Continuations lock-detection fastpath
359 bool _has_scoped_access; // For shared scope closure
360 bool _clinit_barrier_on_entry; // True if clinit barrier is needed on nmethod entry
361 int _loop_opts_cnt; // loop opts round
362 uint _stress_seed; // Seed for stress testing
363
364 // Compilation environment.
365 Arena _comp_arena; // Arena with lifetime equivalent to Compile
366 void* _barrier_set_state; // Potential GC barrier state for Compile
367 ciEnv* _env; // CI interface
368 DirectiveSet* _directive; // Compiler directive
369 CompileLog* _log; // from CompilerThread
370 CHeapStringHolder _failure_reason; // for record_failure/failing pattern
371 CompilationFailureInfo* _first_failure_details; // Details for the first failure happening during compilation
372 GrowableArray<CallGenerator*> _intrinsics; // List of intrinsics.
373 GrowableArray<Node*> _macro_nodes; // List of nodes which need to be expanded before matching.
374 GrowableArray<ParsePredicateNode*> _parse_predicates; // List of Parse Predicates.
375 // List of OpaqueTemplateAssertionPredicateNode nodes for Template Assertion Predicates which can be seen as list
376 // of Template Assertion Predicates themselves.
377 GrowableArray<OpaqueTemplateAssertionPredicateNode*> _template_assertion_predicate_opaques;
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*> _for_merge_stores_igvn; // List of nodes for IGVN merge stores
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 DEBUG_ONLY(bool _phase_verify_ideal_loop;) // Are we in PhaseIdealLoop verification?
586 int do_cleanup() const { return _do_cleanup; }
587 void set_major_progress() { _major_progress++; }
588 void restore_major_progress(int progress) { _major_progress += progress; }
589 void clear_major_progress() { _major_progress = 0; }
590 int max_inline_size() const { return _max_inline_size; }
591 void set_freq_inline_size(int n) { _freq_inline_size = n; }
592 int freq_inline_size() const { return _freq_inline_size; }
593 void set_max_inline_size(int n) { _max_inline_size = n; }
594 bool has_loops() const { return _has_loops; }
595 void set_has_loops(bool z) { _has_loops = z; }
596 bool has_split_ifs() const { return _has_split_ifs; }
597 void set_has_split_ifs(bool z) { _has_split_ifs = z; }
598 bool has_unsafe_access() const { return _has_unsafe_access; }
599 void set_has_unsafe_access(bool z) { _has_unsafe_access = z; }
600 bool has_stringbuilder() const { return _has_stringbuilder; }
601 void set_has_stringbuilder(bool z) { _has_stringbuilder = z; }
602 bool has_boxed_value() const { return _has_boxed_value; }
603 void set_has_boxed_value(bool z) { _has_boxed_value = z; }
604 bool has_reserved_stack_access() const { return _has_reserved_stack_access; }
605 void set_has_reserved_stack_access(bool z) { _has_reserved_stack_access = z; }
606 uint max_vector_size() const { return _max_vector_size; }
607 void set_max_vector_size(uint s) { _max_vector_size = s; }
608 bool clear_upper_avx() const { return _clear_upper_avx; }
609 void set_clear_upper_avx(bool s) { _clear_upper_avx = s; }
610 void set_trap_count(uint r, uint c) { assert(r < trapHistLength, "oob"); _trap_hist[r] = c; }
611 uint trap_count(uint r) const { assert(r < trapHistLength, "oob"); return _trap_hist[r]; }
612 bool trap_can_recompile() const { return _trap_can_recompile; }
613 void set_trap_can_recompile(bool z) { _trap_can_recompile = z; }
614 uint decompile_count() const { return _decompile_count; }
615 void set_decompile_count(uint c) { _decompile_count = c; }
616 bool allow_range_check_smearing() const;
617 bool do_inlining() const { return _do_inlining; }
618 void set_do_inlining(bool z) { _do_inlining = z; }
619 bool do_scheduling() const { return _do_scheduling; }
620 void set_do_scheduling(bool z) { _do_scheduling = z; }
621 bool do_freq_based_layout() const{ return _do_freq_based_layout; }
622 void set_do_freq_based_layout(bool z){ _do_freq_based_layout = z; }
623 bool do_vector_loop() const { return _do_vector_loop; }
624 void set_do_vector_loop(bool z) { _do_vector_loop = z; }
625 bool use_cmove() const { return _use_cmove; }
626 void set_use_cmove(bool z) { _use_cmove = z; }
627 bool do_aliasing() const { return _do_aliasing; }
628 bool print_assembly() const { return _print_assembly; }
629 void set_print_assembly(bool z) { _print_assembly = z; }
630 bool print_inlining() const { return _print_inlining; }
631 void set_print_inlining(bool z) { _print_inlining = z; }
632 bool print_intrinsics() const { return _print_intrinsics; }
633 void set_print_intrinsics(bool z) { _print_intrinsics = z; }
634 uint max_node_limit() const { return (uint)_max_node_limit; }
635 void set_max_node_limit(uint n) { _max_node_limit = n; }
636 bool clinit_barrier_on_entry() { return _clinit_barrier_on_entry; }
637 void set_clinit_barrier_on_entry(bool z) { _clinit_barrier_on_entry = z; }
638 bool has_monitors() const { return _has_monitors; }
639 void set_has_monitors(bool v) { _has_monitors = v; }
640 bool has_scoped_access() const { return _has_scoped_access; }
641 void set_has_scoped_access(bool v) { _has_scoped_access = v; }
642
643 // check the CompilerOracle for special behaviours for this compile
644 bool method_has_option(CompileCommandEnum option) {
645 return method() != nullptr && method()->has_option(option);
646 }
647
648 #ifndef PRODUCT
649 uint next_igv_idx() { return _igv_idx++; }
650 bool trace_opto_output() const { return _trace_opto_output; }
651 void print_ideal_ir(const char* phase_name);
652 bool should_print_ideal() const { return _directive->PrintIdealOption; }
653 bool parsed_irreducible_loop() const { return _parsed_irreducible_loop; }
654 void set_parsed_irreducible_loop(bool z) { _parsed_irreducible_loop = z; }
655 int _in_dump_cnt; // Required for dumping ir nodes.
656 #endif
657 bool has_irreducible_loop() const { return _has_irreducible_loop; }
751 bool coarsened_locks_consistent();
752 void mark_unbalanced_boxes() const;
753
754 bool post_loop_opts_phase() { return _post_loop_opts_phase; }
755 void set_post_loop_opts_phase() { _post_loop_opts_phase = true; }
756 void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }
757
758 #ifdef ASSERT
759 bool phase_verify_ideal_loop() const { return _phase_verify_ideal_loop; }
760 void set_phase_verify_ideal_loop() { _phase_verify_ideal_loop = true; }
761 void reset_phase_verify_ideal_loop() { _phase_verify_ideal_loop = false; }
762 #endif
763
764 bool allow_macro_nodes() { return _allow_macro_nodes; }
765 void reset_allow_macro_nodes() { _allow_macro_nodes = false; }
766
767 void record_for_post_loop_opts_igvn(Node* n);
768 void remove_from_post_loop_opts_igvn(Node* n);
769 void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
770
771 void record_unstable_if_trap(UnstableIfTrap* trap);
772 bool remove_unstable_if_trap(CallStaticJavaNode* unc, bool yield);
773 void remove_useless_unstable_if_traps(Unique_Node_List &useful);
774 void process_for_unstable_if_traps(PhaseIterGVN& igvn);
775
776 bool merge_stores_phase() { return _merge_stores_phase; }
777 void set_merge_stores_phase() { _merge_stores_phase = true; }
778 void record_for_merge_stores_igvn(Node* n);
779 void remove_from_merge_stores_igvn(Node* n);
780 void process_for_merge_stores_igvn(PhaseIterGVN& igvn);
781
782 void shuffle_macro_nodes();
783 void sort_macro_nodes();
784
785 void mark_parse_predicate_nodes_useless(PhaseIterGVN& igvn);
786
787 // Are there candidate expensive nodes for optimization?
788 bool should_optimize_expensive_nodes(PhaseIterGVN &igvn);
789 // Check whether n1 and n2 are similar
790 static int cmp_expensive_nodes(Node* n1, Node* n2);
933 Arena* type_arena() { return _type_arena; }
934 Dict* type_dict() { return _type_dict; }
935 size_t type_last_size() { return _type_last_size; }
936 int num_alias_types() { return _num_alias_types; }
937
938 void init_type_arena() { _type_arena = &_Compile_types; }
939 void set_type_arena(Arena* a) { _type_arena = a; }
940 void set_type_dict(Dict* d) { _type_dict = d; }
941 void set_type_last_size(size_t sz) { _type_last_size = sz; }
942
943 const TypeFunc* last_tf(ciMethod* m) {
944 return (m == _last_tf_m) ? _last_tf : nullptr;
945 }
946 void set_last_tf(ciMethod* m, const TypeFunc* tf) {
947 assert(m != nullptr || tf == nullptr, "");
948 _last_tf_m = m;
949 _last_tf = tf;
950 }
951
952 AliasType* alias_type(int idx) { assert(idx < num_alias_types(), "oob"); return _alias_types[idx]; }
953 AliasType* alias_type(const TypePtr* adr_type, ciField* field = nullptr) { return find_alias_type(adr_type, false, field); }
954 bool have_alias_type(const TypePtr* adr_type);
955 AliasType* alias_type(ciField* field);
956
957 int get_alias_index(const TypePtr* at) { return alias_type(at)->index(); }
958 const TypePtr* get_adr_type(uint aidx) { return alias_type(aidx)->adr_type(); }
959 int get_general_index(uint aidx) { return alias_type(aidx)->general_index(); }
960
961 // Building nodes
962 void rethrow_exceptions(JVMState* jvms);
963 void return_values(JVMState* jvms);
964 JVMState* build_start_state(StartNode* start, const TypeFunc* tf);
965
966 // Decide how to build a call.
967 // The profile factor is a discount to apply to this site's interp. profile.
968 CallGenerator* call_generator(ciMethod* call_method, int vtable_index, bool call_does_dispatch,
969 JVMState* jvms, bool allow_inline, float profile_factor, ciKlass* speculative_receiver_type = nullptr,
970 bool allow_intrinsics = true);
971 bool should_delay_inlining(ciMethod* call_method, JVMState* jvms) {
972 return should_delay_string_inlining(call_method, jvms) ||
973 should_delay_boxing_inlining(call_method, jvms) ||
974 should_delay_vector_inlining(call_method, jvms);
975 }
976 bool should_delay_string_inlining(ciMethod* call_method, JVMState* jvms);
977 bool should_delay_boxing_inlining(ciMethod* call_method, JVMState* jvms);
1178 // Number of outgoing stack slots killed above the out_preserve_stack_slots
1179 // for calls to C. Supports the var-args backing area for register parms.
1180 uint varargs_C_out_slots_killed() const;
1181
1182 // Number of Stack Slots consumed by a synchronization entry
1183 int sync_stack_slots() const;
1184
1185 // Compute the name of old_SP. See <arch>.ad for frame layout.
1186 OptoReg::Name compute_old_SP();
1187
1188 private:
1189 // Phase control:
1190 void Init(bool aliasing); // Prepare for a single compilation
1191 void Optimize(); // Given a graph, optimize it
1192 void Code_Gen(); // Generate code from a graph
1193
1194 // Management of the AliasType table.
1195 void grow_alias_types();
1196 AliasCacheEntry* probe_alias_cache(const TypePtr* adr_type);
1197 const TypePtr *flatten_alias_type(const TypePtr* adr_type) const;
1198 AliasType* find_alias_type(const TypePtr* adr_type, bool no_create, ciField* field);
1199
1200 void verify_top(Node*) const PRODUCT_RETURN;
1201
1202 // Intrinsic setup.
1203 CallGenerator* make_vm_intrinsic(ciMethod* m, bool is_virtual); // constructor
1204 int intrinsic_insertion_index(ciMethod* m, bool is_virtual, bool& found); // helper
1205 CallGenerator* find_intrinsic(ciMethod* m, bool is_virtual); // query fn
1206 void register_intrinsic(CallGenerator* cg); // update fn
1207
1208 #ifndef PRODUCT
1209 static juint _intrinsic_hist_count[];
1210 static jubyte _intrinsic_hist_flags[];
1211 #endif
1212 // Function calls made by the public function final_graph_reshaping.
1213 // No need to be made public as they are not called elsewhere.
1214 void final_graph_reshaping_impl(Node *n, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1215 void final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop, Unique_Node_List& dead_nodes);
1216 void final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1217 void handle_div_mod_op(Node* n, BasicType bt, bool is_unsigned);
1218
1268 // End-of-run dumps.
1269 static void print_statistics() PRODUCT_RETURN;
1270
1271 // Verify ADLC assumptions during startup
1272 static void adlc_verification() PRODUCT_RETURN;
1273
1274 // Definitions of pd methods
1275 static void pd_compiler2_init();
1276
1277 // Static parse-time type checking logic for gen_subtype_check:
1278 enum SubTypeCheckResult { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
1279 SubTypeCheckResult static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip = StressReflectiveCode);
1280
1281 static Node* conv_I2X_index(PhaseGVN* phase, Node* offset, const TypeInt* sizetype,
1282 // Optional control dependency (for example, on range check)
1283 Node* ctrl = nullptr);
1284
1285 // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
1286 static Node* constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl, bool carry_dependency = false);
1287
1288 // Auxiliary methods for randomized fuzzing/stressing
1289 int random();
1290 bool randomized_select(int count);
1291
1292 // seed random number generation and log the seed for repeatability.
1293 void initialize_stress_seed(const DirectiveSet* directive);
1294
1295 // supporting clone_map
1296 CloneMap& clone_map();
1297 void set_clone_map(Dict* d);
1298
1299 bool needs_clinit_barrier(ciField* ik, ciMethod* accessing_method);
1300 bool needs_clinit_barrier(ciMethod* ik, ciMethod* accessing_method);
1301 bool needs_clinit_barrier(ciInstanceKlass* ik, ciMethod* accessing_method);
1302
1303 #ifdef IA32
1304 private:
1305 bool _select_24_bit_instr; // We selected an instruction with a 24-bit result
1306 bool _in_24_bit_fp_mode; // We are emitting instructions with 24-bit results
1307
1308 // 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 OpaqueTemplateAssertionPredicateNode;
76 class OptoReg;
80 class PhaseIterGVN;
81 class PhaseRegAlloc;
82 class PhaseCCP;
83 class PhaseOutput;
84 class RootNode;
85 class relocInfo;
86 class StartNode;
87 class SafePointNode;
88 class JVMState;
89 class Type;
90 class TypeInt;
91 class TypeInteger;
92 class TypeKlassPtr;
93 class TypePtr;
94 class TypeOopPtr;
95 class TypeFunc;
96 class TypeVect;
97 class Type_Array;
98 class Unique_Node_List;
99 class UnstableIfTrap;
100 class InlineTypeNode;
101 class nmethod;
102 class Node_Stack;
103 struct Final_Reshape_Counts;
104 class VerifyMeetResult;
105
106 enum LoopOptsMode {
107 LoopOptsDefault,
108 LoopOptsNone,
109 LoopOptsMaxUnroll,
110 LoopOptsShenandoahExpand,
111 LoopOptsShenandoahPostExpand,
112 LoopOptsSkipSplitIf,
113 LoopOptsVerify
114 };
115
116 // The type of all node counts and indexes.
117 // It must hold at least 16 bits, but must also be fast to load and store.
118 // This type, if less than 32 bits, could limit the number of possible nodes.
119 // (To make this type platform-specific, move to globalDefinitions_xxx.hpp.)
120 typedef unsigned int node_idx_t;
317 int _max_inline_size; // Max inline size for this compilation
318 int _freq_inline_size; // Max hot method inline size for this compilation
319 int _fixed_slots; // count of frame slots not allocated by the register
320 // allocator i.e. locks, original deopt pc, etc.
321 uintx _max_node_limit; // Max unique node count during a single compilation.
322
323 bool _post_loop_opts_phase; // Loop opts are finished.
324 bool _merge_stores_phase; // Phase for merging stores, after post loop opts phase.
325 bool _allow_macro_nodes; // True if we allow creation of macro nodes.
326
327 int _major_progress; // Count of something big happening
328 bool _inlining_progress; // progress doing incremental inlining?
329 bool _inlining_incrementally;// Are we doing incremental inlining (post parse)
330 bool _do_cleanup; // Cleanup is needed before proceeding with incremental inlining
331 bool _has_loops; // True if the method _may_ have some loops
332 bool _has_split_ifs; // True if the method _may_ have some split-if
333 bool _has_unsafe_access; // True if the method _may_ produce faults in unsafe loads or stores.
334 bool _has_stringbuilder; // True StringBuffers or StringBuilders are allocated
335 bool _has_boxed_value; // True if a boxed object is allocated
336 bool _has_reserved_stack_access; // True if the method or an inlined method is annotated with ReservedStackAccess
337 bool _has_circular_inline_type; // True if method loads an inline type with a circular, non-flat field
338 uint _max_vector_size; // Maximum size of generated vectors
339 bool _clear_upper_avx; // Clear upper bits of ymm registers using vzeroupper
340 uint _trap_hist[trapHistLength]; // Cumulative traps
341 bool _trap_can_recompile; // Have we emitted a recompiling trap?
342 uint _decompile_count; // Cumulative decompilation counts.
343 bool _do_inlining; // True if we intend to do inlining
344 bool _do_scheduling; // True if we intend to do scheduling
345 bool _do_freq_based_layout; // True if we intend to do frequency based block layout
346 bool _do_vector_loop; // True if allowed to execute loop in parallel iterations
347 bool _use_cmove; // True if CMove should be used without profitability analysis
348 bool _do_aliasing; // True if we intend to do aliasing
349 bool _print_assembly; // True if we should dump assembly code for this compilation
350 bool _print_inlining; // True if we should print inlining for this compilation
351 bool _print_intrinsics; // True if we should print intrinsics for this compilation
352 #ifndef PRODUCT
353 uint _igv_idx; // Counter for IGV node identifiers
354 uint _igv_phase_iter[PHASE_NUM_TYPES]; // Counters for IGV phase iterations
355 bool _trace_opto_output;
356 bool _parsed_irreducible_loop; // True if ciTypeFlow detected irreducible loops during parsing
357 #endif
358 bool _has_irreducible_loop; // Found irreducible loops
359 // JSR 292
360 bool _has_method_handle_invokes; // True if this method has MethodHandle invokes.
361 bool _has_monitors; // Metadata transfered to nmethod to enable Continuations lock-detection fastpath
362 bool _has_scoped_access; // For shared scope closure
363 bool _clinit_barrier_on_entry; // True if clinit barrier is needed on nmethod entry
364 int _loop_opts_cnt; // loop opts round
365 bool _has_flat_accesses; // Any known flat array accesses?
366 bool _flat_accesses_share_alias; // Initially all flat array share a single slice
367 bool _scalarize_in_safepoints; // Scalarize inline types in safepoint debug info
368 uint _stress_seed; // Seed for stress testing
369
370 // Compilation environment.
371 Arena _comp_arena; // Arena with lifetime equivalent to Compile
372 void* _barrier_set_state; // Potential GC barrier state for Compile
373 ciEnv* _env; // CI interface
374 DirectiveSet* _directive; // Compiler directive
375 CompileLog* _log; // from CompilerThread
376 CHeapStringHolder _failure_reason; // for record_failure/failing pattern
377 CompilationFailureInfo* _first_failure_details; // Details for the first failure happening during compilation
378 GrowableArray<CallGenerator*> _intrinsics; // List of intrinsics.
379 GrowableArray<Node*> _macro_nodes; // List of nodes which need to be expanded before matching.
380 GrowableArray<ParsePredicateNode*> _parse_predicates; // List of Parse Predicates.
381 // List of OpaqueTemplateAssertionPredicateNode nodes for Template Assertion Predicates which can be seen as list
382 // of Template Assertion Predicates themselves.
383 GrowableArray<OpaqueTemplateAssertionPredicateNode*> _template_assertion_predicate_opaques;
384 GrowableArray<Node*> _expensive_nodes; // List of nodes that are expensive to compute and that we'd better not let the GVN freely common
385 GrowableArray<Node*> _for_post_loop_igvn; // List of nodes for IGVN after loop opts are over
386 GrowableArray<Node*> _inline_type_nodes; // List of InlineType nodes
387 GrowableArray<Node*> _for_merge_stores_igvn; // List of nodes for IGVN merge stores
388 GrowableArray<UnstableIfTrap*> _unstable_if_traps; // List of ifnodes after IGVN
389 GrowableArray<Node_List*> _coarsened_locks; // List of coarsened Lock and Unlock nodes
390 ConnectionGraph* _congraph;
391 #ifndef PRODUCT
392 IdealGraphPrinter* _igv_printer;
393 static IdealGraphPrinter* _debug_file_printer;
394 static IdealGraphPrinter* _debug_network_printer;
395 #endif
396
397
398 // Node management
399 uint _unique; // Counter for unique Node indices
400 uint _dead_node_count; // Number of dead nodes; VectorSet::Size() is O(N).
401 // So use this to keep count and make the call O(1).
402 VectorSet _dead_node_list; // Set of dead nodes
403 DEBUG_ONLY(Unique_Node_List* _modified_nodes;) // List of nodes which inputs were modified
404 DEBUG_ONLY(bool _phase_optimize_finished;) // Used for live node verification while creating new nodes
405
406 DEBUG_ONLY(bool _phase_verify_ideal_loop;) // Are we in PhaseIdealLoop verification?
593 int do_cleanup() const { return _do_cleanup; }
594 void set_major_progress() { _major_progress++; }
595 void restore_major_progress(int progress) { _major_progress += progress; }
596 void clear_major_progress() { _major_progress = 0; }
597 int max_inline_size() const { return _max_inline_size; }
598 void set_freq_inline_size(int n) { _freq_inline_size = n; }
599 int freq_inline_size() const { return _freq_inline_size; }
600 void set_max_inline_size(int n) { _max_inline_size = n; }
601 bool has_loops() const { return _has_loops; }
602 void set_has_loops(bool z) { _has_loops = z; }
603 bool has_split_ifs() const { return _has_split_ifs; }
604 void set_has_split_ifs(bool z) { _has_split_ifs = z; }
605 bool has_unsafe_access() const { return _has_unsafe_access; }
606 void set_has_unsafe_access(bool z) { _has_unsafe_access = z; }
607 bool has_stringbuilder() const { return _has_stringbuilder; }
608 void set_has_stringbuilder(bool z) { _has_stringbuilder = z; }
609 bool has_boxed_value() const { return _has_boxed_value; }
610 void set_has_boxed_value(bool z) { _has_boxed_value = z; }
611 bool has_reserved_stack_access() const { return _has_reserved_stack_access; }
612 void set_has_reserved_stack_access(bool z) { _has_reserved_stack_access = z; }
613 bool has_circular_inline_type() const { return _has_circular_inline_type; }
614 void set_has_circular_inline_type(bool z) { _has_circular_inline_type = z; }
615 uint max_vector_size() const { return _max_vector_size; }
616 void set_max_vector_size(uint s) { _max_vector_size = s; }
617 bool clear_upper_avx() const { return _clear_upper_avx; }
618 void set_clear_upper_avx(bool s) { _clear_upper_avx = s; }
619 void set_trap_count(uint r, uint c) { assert(r < trapHistLength, "oob"); _trap_hist[r] = c; }
620 uint trap_count(uint r) const { assert(r < trapHistLength, "oob"); return _trap_hist[r]; }
621 bool trap_can_recompile() const { return _trap_can_recompile; }
622 void set_trap_can_recompile(bool z) { _trap_can_recompile = z; }
623 uint decompile_count() const { return _decompile_count; }
624 void set_decompile_count(uint c) { _decompile_count = c; }
625 bool allow_range_check_smearing() const;
626 bool do_inlining() const { return _do_inlining; }
627 void set_do_inlining(bool z) { _do_inlining = z; }
628 bool do_scheduling() const { return _do_scheduling; }
629 void set_do_scheduling(bool z) { _do_scheduling = z; }
630 bool do_freq_based_layout() const{ return _do_freq_based_layout; }
631 void set_do_freq_based_layout(bool z){ _do_freq_based_layout = z; }
632 bool do_vector_loop() const { return _do_vector_loop; }
633 void set_do_vector_loop(bool z) { _do_vector_loop = z; }
634 bool use_cmove() const { return _use_cmove; }
635 void set_use_cmove(bool z) { _use_cmove = z; }
636 bool do_aliasing() const { return _do_aliasing; }
637 bool print_assembly() const { return _print_assembly; }
638 void set_print_assembly(bool z) { _print_assembly = z; }
639 bool print_inlining() const { return _print_inlining; }
640 void set_print_inlining(bool z) { _print_inlining = z; }
641 bool print_intrinsics() const { return _print_intrinsics; }
642 void set_print_intrinsics(bool z) { _print_intrinsics = z; }
643 uint max_node_limit() const { return (uint)_max_node_limit; }
644 void set_max_node_limit(uint n) { _max_node_limit = n; }
645 bool clinit_barrier_on_entry() { return _clinit_barrier_on_entry; }
646 void set_clinit_barrier_on_entry(bool z) { _clinit_barrier_on_entry = z; }
647 void set_flat_accesses() { _has_flat_accesses = true; }
648 bool flat_accesses_share_alias() const { return _flat_accesses_share_alias; }
649 void set_flat_accesses_share_alias(bool z) { _flat_accesses_share_alias = z; }
650 bool scalarize_in_safepoints() const { return _scalarize_in_safepoints; }
651 void set_scalarize_in_safepoints(bool z) { _scalarize_in_safepoints = z; }
652
653 // Support for scalarized inline type calling convention
654 bool has_scalarized_args() const { return _method != nullptr && _method->has_scalarized_args(); }
655 bool needs_stack_repair() const { return _method != nullptr && _method->get_Method()->c2_needs_stack_repair(); }
656
657 bool has_monitors() const { return _has_monitors; }
658 void set_has_monitors(bool v) { _has_monitors = v; }
659 bool has_scoped_access() const { return _has_scoped_access; }
660 void set_has_scoped_access(bool v) { _has_scoped_access = v; }
661
662 // check the CompilerOracle for special behaviours for this compile
663 bool method_has_option(CompileCommandEnum option) {
664 return method() != nullptr && method()->has_option(option);
665 }
666
667 #ifndef PRODUCT
668 uint next_igv_idx() { return _igv_idx++; }
669 bool trace_opto_output() const { return _trace_opto_output; }
670 void print_ideal_ir(const char* phase_name);
671 bool should_print_ideal() const { return _directive->PrintIdealOption; }
672 bool parsed_irreducible_loop() const { return _parsed_irreducible_loop; }
673 void set_parsed_irreducible_loop(bool z) { _parsed_irreducible_loop = z; }
674 int _in_dump_cnt; // Required for dumping ir nodes.
675 #endif
676 bool has_irreducible_loop() const { return _has_irreducible_loop; }
770 bool coarsened_locks_consistent();
771 void mark_unbalanced_boxes() const;
772
773 bool post_loop_opts_phase() { return _post_loop_opts_phase; }
774 void set_post_loop_opts_phase() { _post_loop_opts_phase = true; }
775 void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }
776
777 #ifdef ASSERT
778 bool phase_verify_ideal_loop() const { return _phase_verify_ideal_loop; }
779 void set_phase_verify_ideal_loop() { _phase_verify_ideal_loop = true; }
780 void reset_phase_verify_ideal_loop() { _phase_verify_ideal_loop = false; }
781 #endif
782
783 bool allow_macro_nodes() { return _allow_macro_nodes; }
784 void reset_allow_macro_nodes() { _allow_macro_nodes = false; }
785
786 void record_for_post_loop_opts_igvn(Node* n);
787 void remove_from_post_loop_opts_igvn(Node* n);
788 void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
789
790 // Keep track of inline type nodes for later processing
791 void add_inline_type(Node* n);
792 void remove_inline_type(Node* n);
793 void process_inline_types(PhaseIterGVN &igvn, bool remove = false);
794
795 void adjust_flat_array_access_aliases(PhaseIterGVN& igvn);
796
797 void record_unstable_if_trap(UnstableIfTrap* trap);
798 bool remove_unstable_if_trap(CallStaticJavaNode* unc, bool yield);
799 void remove_useless_unstable_if_traps(Unique_Node_List &useful);
800 void process_for_unstable_if_traps(PhaseIterGVN& igvn);
801
802 bool merge_stores_phase() { return _merge_stores_phase; }
803 void set_merge_stores_phase() { _merge_stores_phase = true; }
804 void record_for_merge_stores_igvn(Node* n);
805 void remove_from_merge_stores_igvn(Node* n);
806 void process_for_merge_stores_igvn(PhaseIterGVN& igvn);
807
808 void shuffle_macro_nodes();
809 void sort_macro_nodes();
810
811 void mark_parse_predicate_nodes_useless(PhaseIterGVN& igvn);
812
813 // Are there candidate expensive nodes for optimization?
814 bool should_optimize_expensive_nodes(PhaseIterGVN &igvn);
815 // Check whether n1 and n2 are similar
816 static int cmp_expensive_nodes(Node* n1, Node* n2);
959 Arena* type_arena() { return _type_arena; }
960 Dict* type_dict() { return _type_dict; }
961 size_t type_last_size() { return _type_last_size; }
962 int num_alias_types() { return _num_alias_types; }
963
964 void init_type_arena() { _type_arena = &_Compile_types; }
965 void set_type_arena(Arena* a) { _type_arena = a; }
966 void set_type_dict(Dict* d) { _type_dict = d; }
967 void set_type_last_size(size_t sz) { _type_last_size = sz; }
968
969 const TypeFunc* last_tf(ciMethod* m) {
970 return (m == _last_tf_m) ? _last_tf : nullptr;
971 }
972 void set_last_tf(ciMethod* m, const TypeFunc* tf) {
973 assert(m != nullptr || tf == nullptr, "");
974 _last_tf_m = m;
975 _last_tf = tf;
976 }
977
978 AliasType* alias_type(int idx) { assert(idx < num_alias_types(), "oob"); return _alias_types[idx]; }
979 AliasType* alias_type(const TypePtr* adr_type, ciField* field = nullptr, bool uncached = false) { return find_alias_type(adr_type, false, field, uncached); }
980 bool have_alias_type(const TypePtr* adr_type);
981 AliasType* alias_type(ciField* field);
982
983 int get_alias_index(const TypePtr* at, bool uncached = false) { return alias_type(at, nullptr, uncached)->index(); }
984 const TypePtr* get_adr_type(uint aidx) { return alias_type(aidx)->adr_type(); }
985 int get_general_index(uint aidx) { return alias_type(aidx)->general_index(); }
986
987 // Building nodes
988 void rethrow_exceptions(JVMState* jvms);
989 void return_values(JVMState* jvms);
990 JVMState* build_start_state(StartNode* start, const TypeFunc* tf);
991
992 // Decide how to build a call.
993 // The profile factor is a discount to apply to this site's interp. profile.
994 CallGenerator* call_generator(ciMethod* call_method, int vtable_index, bool call_does_dispatch,
995 JVMState* jvms, bool allow_inline, float profile_factor, ciKlass* speculative_receiver_type = nullptr,
996 bool allow_intrinsics = true);
997 bool should_delay_inlining(ciMethod* call_method, JVMState* jvms) {
998 return should_delay_string_inlining(call_method, jvms) ||
999 should_delay_boxing_inlining(call_method, jvms) ||
1000 should_delay_vector_inlining(call_method, jvms);
1001 }
1002 bool should_delay_string_inlining(ciMethod* call_method, JVMState* jvms);
1003 bool should_delay_boxing_inlining(ciMethod* call_method, JVMState* jvms);
1204 // Number of outgoing stack slots killed above the out_preserve_stack_slots
1205 // for calls to C. Supports the var-args backing area for register parms.
1206 uint varargs_C_out_slots_killed() const;
1207
1208 // Number of Stack Slots consumed by a synchronization entry
1209 int sync_stack_slots() const;
1210
1211 // Compute the name of old_SP. See <arch>.ad for frame layout.
1212 OptoReg::Name compute_old_SP();
1213
1214 private:
1215 // Phase control:
1216 void Init(bool aliasing); // Prepare for a single compilation
1217 void Optimize(); // Given a graph, optimize it
1218 void Code_Gen(); // Generate code from a graph
1219
1220 // Management of the AliasType table.
1221 void grow_alias_types();
1222 AliasCacheEntry* probe_alias_cache(const TypePtr* adr_type);
1223 const TypePtr *flatten_alias_type(const TypePtr* adr_type) const;
1224 AliasType* find_alias_type(const TypePtr* adr_type, bool no_create, ciField* field, bool uncached = false);
1225
1226 void verify_top(Node*) const PRODUCT_RETURN;
1227
1228 // Intrinsic setup.
1229 CallGenerator* make_vm_intrinsic(ciMethod* m, bool is_virtual); // constructor
1230 int intrinsic_insertion_index(ciMethod* m, bool is_virtual, bool& found); // helper
1231 CallGenerator* find_intrinsic(ciMethod* m, bool is_virtual); // query fn
1232 void register_intrinsic(CallGenerator* cg); // update fn
1233
1234 #ifndef PRODUCT
1235 static juint _intrinsic_hist_count[];
1236 static jubyte _intrinsic_hist_flags[];
1237 #endif
1238 // Function calls made by the public function final_graph_reshaping.
1239 // No need to be made public as they are not called elsewhere.
1240 void final_graph_reshaping_impl(Node *n, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1241 void final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop, Unique_Node_List& dead_nodes);
1242 void final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1243 void handle_div_mod_op(Node* n, BasicType bt, bool is_unsigned);
1244
1294 // End-of-run dumps.
1295 static void print_statistics() PRODUCT_RETURN;
1296
1297 // Verify ADLC assumptions during startup
1298 static void adlc_verification() PRODUCT_RETURN;
1299
1300 // Definitions of pd methods
1301 static void pd_compiler2_init();
1302
1303 // Static parse-time type checking logic for gen_subtype_check:
1304 enum SubTypeCheckResult { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
1305 SubTypeCheckResult static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip = StressReflectiveCode);
1306
1307 static Node* conv_I2X_index(PhaseGVN* phase, Node* offset, const TypeInt* sizetype,
1308 // Optional control dependency (for example, on range check)
1309 Node* ctrl = nullptr);
1310
1311 // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
1312 static Node* constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl, bool carry_dependency = false);
1313
1314 Node* optimize_acmp(PhaseGVN* phase, Node* a, Node* b);
1315
1316 // Auxiliary method for randomized fuzzing/stressing
1317 int random();
1318 bool randomized_select(int count);
1319
1320 // seed random number generation and log the seed for repeatability.
1321 void initialize_stress_seed(const DirectiveSet* directive);
1322
1323 // supporting clone_map
1324 CloneMap& clone_map();
1325 void set_clone_map(Dict* d);
1326
1327 bool needs_clinit_barrier(ciField* ik, ciMethod* accessing_method);
1328 bool needs_clinit_barrier(ciMethod* ik, ciMethod* accessing_method);
1329 bool needs_clinit_barrier(ciInstanceKlass* ik, ciMethod* accessing_method);
1330
1331 #ifdef IA32
1332 private:
1333 bool _select_24_bit_instr; // We selected an instruction with a 24-bit result
1334 bool _in_24_bit_fp_mode; // We are emitting instructions with 24-bit results
1335
1336 // Remember if this compilation changes hardware mode to 24-bit precision.
|