35 #include "libadt/dict.hpp"
36 #include "libadt/vectset.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "oops/methodData.hpp"
39 #include "opto/idealGraphPrinter.hpp"
40 #include "opto/phasetype.hpp"
41 #include "opto/phase.hpp"
42 #include "opto/regmask.hpp"
43 #include "runtime/deoptimization.hpp"
44 #include "runtime/sharedRuntime.hpp"
45 #include "runtime/timerTrace.hpp"
46 #include "runtime/vmThread.hpp"
47 #include "utilities/ticks.hpp"
48 #include "utilities/vmEnums.hpp"
49
50 class AbstractLockNode;
51 class AddPNode;
52 class Block;
53 class Bundle;
54 class CallGenerator;
55 class CallStaticJavaNode;
56 class CloneMap;
57 class CompilationFailureInfo;
58 class ConnectionGraph;
59 class IdealGraphPrinter;
60 class InlineTree;
61 class Matcher;
62 class MachConstantNode;
63 class MachConstantBaseNode;
64 class MachNode;
65 class MachOper;
66 class MachSafePointNode;
67 class Node;
68 class Node_Array;
69 class Node_List;
70 class Node_Notes;
71 class NodeHash;
72 class NodeCloneInfo;
73 class OptoReg;
74 class ParsePredicateNode;
77 class PhaseIterGVN;
78 class PhaseRegAlloc;
79 class PhaseCCP;
80 class PhaseOutput;
81 class RootNode;
82 class relocInfo;
83 class StartNode;
84 class SafePointNode;
85 class JVMState;
86 class Type;
87 class TypeInt;
88 class TypeInteger;
89 class TypeKlassPtr;
90 class TypePtr;
91 class TypeOopPtr;
92 class TypeFunc;
93 class TypeVect;
94 class Type_Array;
95 class Unique_Node_List;
96 class UnstableIfTrap;
97 class nmethod;
98 class Node_Stack;
99 struct Final_Reshape_Counts;
100 class VerifyMeetResult;
101
102 enum LoopOptsMode {
103 LoopOptsDefault,
104 LoopOptsNone,
105 LoopOptsMaxUnroll,
106 LoopOptsShenandoahExpand,
107 LoopOptsShenandoahPostExpand,
108 LoopOptsSkipSplitIf,
109 LoopOptsVerify
110 };
111
112 // The type of all node counts and indexes.
113 // It must hold at least 16 bits, but must also be fast to load and store.
114 // This type, if less than 32 bits, could limit the number of possible nodes.
115 // (To make this type platform-specific, move to globalDefinitions_xxx.hpp.)
116 typedef unsigned int node_idx_t;
313 // Control of this compilation.
314 int _max_inline_size; // Max inline size for this compilation
315 int _freq_inline_size; // Max hot method inline size for this compilation
316 int _fixed_slots; // count of frame slots not allocated by the register
317 // allocator i.e. locks, original deopt pc, etc.
318 uintx _max_node_limit; // Max unique node count during a single compilation.
319
320 bool _post_loop_opts_phase; // Loop opts are finished.
321 bool _allow_macro_nodes; // True if we allow creation of macro nodes.
322
323 int _major_progress; // Count of something big happening
324 bool _inlining_progress; // progress doing incremental inlining?
325 bool _inlining_incrementally;// Are we doing incremental inlining (post parse)
326 bool _do_cleanup; // Cleanup is needed before proceeding with incremental inlining
327 bool _has_loops; // True if the method _may_ have some loops
328 bool _has_split_ifs; // True if the method _may_ have some split-if
329 bool _has_unsafe_access; // True if the method _may_ produce faults in unsafe loads or stores.
330 bool _has_stringbuilder; // True StringBuffers or StringBuilders are allocated
331 bool _has_boxed_value; // True if a boxed object is allocated
332 bool _has_reserved_stack_access; // True if the method or an inlined method is annotated with ReservedStackAccess
333 uint _max_vector_size; // Maximum size of generated vectors
334 bool _clear_upper_avx; // Clear upper bits of ymm registers using vzeroupper
335 uint _trap_hist[trapHistLength]; // Cumulative traps
336 bool _trap_can_recompile; // Have we emitted a recompiling trap?
337 uint _decompile_count; // Cumulative decompilation counts.
338 bool _do_inlining; // True if we intend to do inlining
339 bool _do_scheduling; // True if we intend to do scheduling
340 bool _do_freq_based_layout; // True if we intend to do frequency based block layout
341 bool _do_vector_loop; // True if allowed to execute loop in parallel iterations
342 bool _use_cmove; // True if CMove should be used without profitability analysis
343 bool _do_aliasing; // True if we intend to do aliasing
344 bool _print_assembly; // True if we should dump assembly code for this compilation
345 bool _print_inlining; // True if we should print inlining for this compilation
346 bool _print_intrinsics; // True if we should print intrinsics for this compilation
347 #ifndef PRODUCT
348 uint _igv_idx; // Counter for IGV node identifiers
349 uint _igv_phase_iter[PHASE_NUM_TYPES]; // Counters for IGV phase iterations
350 bool _trace_opto_output;
351 bool _parsed_irreducible_loop; // True if ciTypeFlow detected irreducible loops during parsing
352 #endif
353 bool _has_irreducible_loop; // Found irreducible loops
354 // JSR 292
355 bool _has_method_handle_invokes; // True if this method has MethodHandle invokes.
356 bool _has_monitors; // Metadata transfered to nmethod to enable Continuations lock-detection fastpath
357 bool _has_scoped_access; // For shared scope closure
358 bool _clinit_barrier_on_entry; // True if clinit barrier is needed on nmethod entry
359 int _loop_opts_cnt; // loop opts round
360 uint _stress_seed; // Seed for stress testing
361
362 // Compilation environment.
363 Arena _comp_arena; // Arena with lifetime equivalent to Compile
364 void* _barrier_set_state; // Potential GC barrier state for Compile
365 ciEnv* _env; // CI interface
366 DirectiveSet* _directive; // Compiler directive
367 CompileLog* _log; // from CompilerThread
368 CHeapStringHolder _failure_reason; // for record_failure/failing pattern
369 CompilationFailureInfo* _first_failure_details; // Details for the first failure happening during compilation
370 GrowableArray<CallGenerator*> _intrinsics; // List of intrinsics.
371 GrowableArray<Node*> _macro_nodes; // List of nodes which need to be expanded before matching.
372 GrowableArray<ParsePredicateNode*> _parse_predicates; // List of Parse Predicates.
373 GrowableArray<Node*> _template_assertion_predicate_opaqs; // List of Opaque4 nodes for Template Assertion Predicates.
374 GrowableArray<Node*> _expensive_nodes; // List of nodes that are expensive to compute and that we'd better not let the GVN freely common
375 GrowableArray<Node*> _for_post_loop_igvn; // List of nodes for IGVN after loop opts are over
376 GrowableArray<UnstableIfTrap*> _unstable_if_traps; // List of ifnodes after IGVN
377 GrowableArray<Node_List*> _coarsened_locks; // List of coarsened Lock and Unlock nodes
378 ConnectionGraph* _congraph;
379 #ifndef PRODUCT
380 IdealGraphPrinter* _igv_printer;
381 static IdealGraphPrinter* _debug_file_printer;
382 static IdealGraphPrinter* _debug_network_printer;
383 #endif
384
385
386 // Node management
387 uint _unique; // Counter for unique Node indices
388 uint _dead_node_count; // Number of dead nodes; VectorSet::Size() is O(N).
389 // So use this to keep count and make the call O(1).
390 VectorSet _dead_node_list; // Set of dead nodes
391 DEBUG_ONLY(Unique_Node_List* _modified_nodes;) // List of nodes which inputs were modified
392 DEBUG_ONLY(bool _phase_optimize_finished;) // Used for live node verification while creating new nodes
393
394 // Arenas for new-space and old-space nodes.
395 // Swapped between using _node_arena.
622 int do_cleanup() const { return _do_cleanup; }
623 void set_major_progress() { _major_progress++; }
624 void restore_major_progress(int progress) { _major_progress += progress; }
625 void clear_major_progress() { _major_progress = 0; }
626 int max_inline_size() const { return _max_inline_size; }
627 void set_freq_inline_size(int n) { _freq_inline_size = n; }
628 int freq_inline_size() const { return _freq_inline_size; }
629 void set_max_inline_size(int n) { _max_inline_size = n; }
630 bool has_loops() const { return _has_loops; }
631 void set_has_loops(bool z) { _has_loops = z; }
632 bool has_split_ifs() const { return _has_split_ifs; }
633 void set_has_split_ifs(bool z) { _has_split_ifs = z; }
634 bool has_unsafe_access() const { return _has_unsafe_access; }
635 void set_has_unsafe_access(bool z) { _has_unsafe_access = z; }
636 bool has_stringbuilder() const { return _has_stringbuilder; }
637 void set_has_stringbuilder(bool z) { _has_stringbuilder = z; }
638 bool has_boxed_value() const { return _has_boxed_value; }
639 void set_has_boxed_value(bool z) { _has_boxed_value = z; }
640 bool has_reserved_stack_access() const { return _has_reserved_stack_access; }
641 void set_has_reserved_stack_access(bool z) { _has_reserved_stack_access = z; }
642 uint max_vector_size() const { return _max_vector_size; }
643 void set_max_vector_size(uint s) { _max_vector_size = s; }
644 bool clear_upper_avx() const { return _clear_upper_avx; }
645 void set_clear_upper_avx(bool s) { _clear_upper_avx = s; }
646 void set_trap_count(uint r, uint c) { assert(r < trapHistLength, "oob"); _trap_hist[r] = c; }
647 uint trap_count(uint r) const { assert(r < trapHistLength, "oob"); return _trap_hist[r]; }
648 bool trap_can_recompile() const { return _trap_can_recompile; }
649 void set_trap_can_recompile(bool z) { _trap_can_recompile = z; }
650 uint decompile_count() const { return _decompile_count; }
651 void set_decompile_count(uint c) { _decompile_count = c; }
652 bool allow_range_check_smearing() const;
653 bool do_inlining() const { return _do_inlining; }
654 void set_do_inlining(bool z) { _do_inlining = z; }
655 bool do_scheduling() const { return _do_scheduling; }
656 void set_do_scheduling(bool z) { _do_scheduling = z; }
657 bool do_freq_based_layout() const{ return _do_freq_based_layout; }
658 void set_do_freq_based_layout(bool z){ _do_freq_based_layout = z; }
659 bool do_vector_loop() const { return _do_vector_loop; }
660 void set_do_vector_loop(bool z) { _do_vector_loop = z; }
661 bool use_cmove() const { return _use_cmove; }
662 void set_use_cmove(bool z) { _use_cmove = z; }
663 bool do_aliasing() const { return _do_aliasing; }
664 bool print_assembly() const { return _print_assembly; }
665 void set_print_assembly(bool z) { _print_assembly = z; }
666 bool print_inlining() const { return _print_inlining; }
667 void set_print_inlining(bool z) { _print_inlining = z; }
668 bool print_intrinsics() const { return _print_intrinsics; }
669 void set_print_intrinsics(bool z) { _print_intrinsics = z; }
670 uint max_node_limit() const { return (uint)_max_node_limit; }
671 void set_max_node_limit(uint n) { _max_node_limit = n; }
672 bool clinit_barrier_on_entry() { return _clinit_barrier_on_entry; }
673 void set_clinit_barrier_on_entry(bool z) { _clinit_barrier_on_entry = z; }
674 bool has_monitors() const { return _has_monitors; }
675 void set_has_monitors(bool v) { _has_monitors = v; }
676 bool has_scoped_access() const { return _has_scoped_access; }
677 void set_has_scoped_access(bool v) { _has_scoped_access = v; }
678
679 // check the CompilerOracle for special behaviours for this compile
680 bool method_has_option(CompileCommandEnum 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; }
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 void mark_unbalanced_boxes() const;
784
785 bool post_loop_opts_phase() { return _post_loop_opts_phase; }
786 void set_post_loop_opts_phase() { _post_loop_opts_phase = true; }
787 void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }
788
789 bool allow_macro_nodes() { return _allow_macro_nodes; }
790 void reset_allow_macro_nodes() { _allow_macro_nodes = false; }
791
792 void record_for_post_loop_opts_igvn(Node* n);
793 void remove_from_post_loop_opts_igvn(Node* n);
794 void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
795
796 void record_unstable_if_trap(UnstableIfTrap* trap);
797 bool remove_unstable_if_trap(CallStaticJavaNode* unc, bool yield);
798 void remove_useless_unstable_if_traps(Unique_Node_List &useful);
799 void process_for_unstable_if_traps(PhaseIterGVN& igvn);
800
801 void shuffle_macro_nodes();
802 void sort_macro_nodes();
803
804 void mark_parse_predicate_nodes_useless(PhaseIterGVN& igvn);
805
806 // Are there candidate expensive nodes for optimization?
807 bool should_optimize_expensive_nodes(PhaseIterGVN &igvn);
808 // Check whether n1 and n2 are similar
809 static int cmp_expensive_nodes(Node* n1, Node* n2);
810 // Sort expensive nodes to locate similar expensive nodes
811 void sort_expensive_nodes();
812
813 // Compilation environment.
814 Arena* comp_arena() { return &_comp_arena; }
815 ciEnv* env() const { return _env; }
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);
1179 // Number of outgoing stack slots killed above the out_preserve_stack_slots
1180 // for calls to C. Supports the var-args backing area for register parms.
1181 uint varargs_C_out_slots_killed() const;
1182
1183 // Number of Stack Slots consumed by a synchronization entry
1184 int sync_stack_slots() const;
1185
1186 // Compute the name of old_SP. See <arch>.ad for frame layout.
1187 OptoReg::Name compute_old_SP();
1188
1189 private:
1190 // Phase control:
1191 void Init(bool aliasing); // Prepare for a single compilation
1192 void Optimize(); // Given a graph, optimize it
1193 void Code_Gen(); // Generate code from a graph
1194
1195 // Management of the AliasType table.
1196 void grow_alias_types();
1197 AliasCacheEntry* probe_alias_cache(const TypePtr* adr_type);
1198 const TypePtr *flatten_alias_type(const TypePtr* adr_type) const;
1199 AliasType* find_alias_type(const TypePtr* adr_type, bool no_create, ciField* field);
1200
1201 void verify_top(Node*) const PRODUCT_RETURN;
1202
1203 // Intrinsic setup.
1204 CallGenerator* make_vm_intrinsic(ciMethod* m, bool is_virtual); // constructor
1205 int intrinsic_insertion_index(ciMethod* m, bool is_virtual, bool& found); // helper
1206 CallGenerator* find_intrinsic(ciMethod* m, bool is_virtual); // query fn
1207 void register_intrinsic(CallGenerator* cg); // update fn
1208
1209 #ifndef PRODUCT
1210 static juint _intrinsic_hist_count[];
1211 static jubyte _intrinsic_hist_flags[];
1212 #endif
1213 // Function calls made by the public function final_graph_reshaping.
1214 // No need to be made public as they are not called elsewhere.
1215 void final_graph_reshaping_impl(Node *n, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1216 void final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop, Unique_Node_List& dead_nodes);
1217 void final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1218 void eliminate_redundant_card_marks(Node* n);
1219 void handle_div_mod_op(Node* n, BasicType bt, bool is_unsigned);
1256 // End-of-run dumps.
1257 static void print_statistics() PRODUCT_RETURN;
1258
1259 // Verify ADLC assumptions during startup
1260 static void adlc_verification() PRODUCT_RETURN;
1261
1262 // Definitions of pd methods
1263 static void pd_compiler2_init();
1264
1265 // Static parse-time type checking logic for gen_subtype_check:
1266 enum SubTypeCheckResult { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
1267 SubTypeCheckResult static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip = StressReflectiveCode);
1268
1269 static Node* conv_I2X_index(PhaseGVN* phase, Node* offset, const TypeInt* sizetype,
1270 // Optional control dependency (for example, on range check)
1271 Node* ctrl = nullptr);
1272
1273 // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
1274 static Node* constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl, bool carry_dependency = false);
1275
1276 // Auxiliary methods for randomized fuzzing/stressing
1277 int random();
1278 bool randomized_select(int count);
1279
1280 // seed random number generation and log the seed for repeatability.
1281 void initialize_stress_seed(const DirectiveSet* directive);
1282
1283 // supporting clone_map
1284 CloneMap& clone_map();
1285 void set_clone_map(Dict* d);
1286
1287 bool needs_clinit_barrier(ciField* ik, ciMethod* accessing_method);
1288 bool needs_clinit_barrier(ciMethod* ik, ciMethod* accessing_method);
1289 bool needs_clinit_barrier(ciInstanceKlass* ik, ciMethod* accessing_method);
1290
1291 #ifdef IA32
1292 private:
1293 bool _select_24_bit_instr; // We selected an instruction with a 24-bit result
1294 bool _in_24_bit_fp_mode; // We are emitting instructions with 24-bit results
1295
1296 // Remember if this compilation changes hardware mode to 24-bit precision.
|
35 #include "libadt/dict.hpp"
36 #include "libadt/vectset.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "oops/methodData.hpp"
39 #include "opto/idealGraphPrinter.hpp"
40 #include "opto/phasetype.hpp"
41 #include "opto/phase.hpp"
42 #include "opto/regmask.hpp"
43 #include "runtime/deoptimization.hpp"
44 #include "runtime/sharedRuntime.hpp"
45 #include "runtime/timerTrace.hpp"
46 #include "runtime/vmThread.hpp"
47 #include "utilities/ticks.hpp"
48 #include "utilities/vmEnums.hpp"
49
50 class AbstractLockNode;
51 class AddPNode;
52 class Block;
53 class Bundle;
54 class CallGenerator;
55 class CallNode;
56 class CallStaticJavaNode;
57 class CloneMap;
58 class CompilationFailureInfo;
59 class ConnectionGraph;
60 class IdealGraphPrinter;
61 class InlineTree;
62 class Matcher;
63 class MachConstantNode;
64 class MachConstantBaseNode;
65 class MachNode;
66 class MachOper;
67 class MachSafePointNode;
68 class Node;
69 class Node_Array;
70 class Node_List;
71 class Node_Notes;
72 class NodeHash;
73 class NodeCloneInfo;
74 class OptoReg;
75 class ParsePredicateNode;
78 class PhaseIterGVN;
79 class PhaseRegAlloc;
80 class PhaseCCP;
81 class PhaseOutput;
82 class RootNode;
83 class relocInfo;
84 class StartNode;
85 class SafePointNode;
86 class JVMState;
87 class Type;
88 class TypeInt;
89 class TypeInteger;
90 class TypeKlassPtr;
91 class TypePtr;
92 class TypeOopPtr;
93 class TypeFunc;
94 class TypeVect;
95 class Type_Array;
96 class Unique_Node_List;
97 class UnstableIfTrap;
98 class InlineTypeNode;
99 class nmethod;
100 class Node_Stack;
101 struct Final_Reshape_Counts;
102 class VerifyMeetResult;
103
104 enum LoopOptsMode {
105 LoopOptsDefault,
106 LoopOptsNone,
107 LoopOptsMaxUnroll,
108 LoopOptsShenandoahExpand,
109 LoopOptsShenandoahPostExpand,
110 LoopOptsSkipSplitIf,
111 LoopOptsVerify
112 };
113
114 // The type of all node counts and indexes.
115 // It must hold at least 16 bits, but must also be fast to load and store.
116 // This type, if less than 32 bits, could limit the number of possible nodes.
117 // (To make this type platform-specific, move to globalDefinitions_xxx.hpp.)
118 typedef unsigned int node_idx_t;
315 // Control of this compilation.
316 int _max_inline_size; // Max inline size for this compilation
317 int _freq_inline_size; // Max hot method inline size for this compilation
318 int _fixed_slots; // count of frame slots not allocated by the register
319 // allocator i.e. locks, original deopt pc, etc.
320 uintx _max_node_limit; // Max unique node count during a single compilation.
321
322 bool _post_loop_opts_phase; // Loop opts are finished.
323 bool _allow_macro_nodes; // True if we allow creation of macro nodes.
324
325 int _major_progress; // Count of something big happening
326 bool _inlining_progress; // progress doing incremental inlining?
327 bool _inlining_incrementally;// Are we doing incremental inlining (post parse)
328 bool _do_cleanup; // Cleanup is needed before proceeding with incremental inlining
329 bool _has_loops; // True if the method _may_ have some loops
330 bool _has_split_ifs; // True if the method _may_ have some split-if
331 bool _has_unsafe_access; // True if the method _may_ produce faults in unsafe loads or stores.
332 bool _has_stringbuilder; // True StringBuffers or StringBuilders are allocated
333 bool _has_boxed_value; // True if a boxed object is allocated
334 bool _has_reserved_stack_access; // True if the method or an inlined method is annotated with ReservedStackAccess
335 bool _has_circular_inline_type; // True if method loads an inline type with a circular, non-flat field
336 uint _max_vector_size; // Maximum size of generated vectors
337 bool _clear_upper_avx; // Clear upper bits of ymm registers using vzeroupper
338 uint _trap_hist[trapHistLength]; // Cumulative traps
339 bool _trap_can_recompile; // Have we emitted a recompiling trap?
340 uint _decompile_count; // Cumulative decompilation counts.
341 bool _do_inlining; // True if we intend to do inlining
342 bool _do_scheduling; // True if we intend to do scheduling
343 bool _do_freq_based_layout; // True if we intend to do frequency based block layout
344 bool _do_vector_loop; // True if allowed to execute loop in parallel iterations
345 bool _use_cmove; // True if CMove should be used without profitability analysis
346 bool _do_aliasing; // True if we intend to do aliasing
347 bool _print_assembly; // True if we should dump assembly code for this compilation
348 bool _print_inlining; // True if we should print inlining for this compilation
349 bool _print_intrinsics; // True if we should print intrinsics for this compilation
350 #ifndef PRODUCT
351 uint _igv_idx; // Counter for IGV node identifiers
352 uint _igv_phase_iter[PHASE_NUM_TYPES]; // Counters for IGV phase iterations
353 bool _trace_opto_output;
354 bool _parsed_irreducible_loop; // True if ciTypeFlow detected irreducible loops during parsing
355 #endif
356 bool _has_irreducible_loop; // Found irreducible loops
357 // JSR 292
358 bool _has_method_handle_invokes; // True if this method has MethodHandle invokes.
359 bool _has_monitors; // Metadata transfered to nmethod to enable Continuations lock-detection fastpath
360 bool _has_scoped_access; // For shared scope closure
361 bool _clinit_barrier_on_entry; // True if clinit barrier is needed on nmethod entry
362 int _loop_opts_cnt; // loop opts round
363 bool _has_flat_accesses; // Any known flat array accesses?
364 bool _flat_accesses_share_alias; // Initially all flat array share a single slice
365 bool _scalarize_in_safepoints; // Scalarize inline types in safepoint debug info
366 uint _stress_seed; // Seed for stress testing
367
368 // Compilation environment.
369 Arena _comp_arena; // Arena with lifetime equivalent to Compile
370 void* _barrier_set_state; // Potential GC barrier state for Compile
371 ciEnv* _env; // CI interface
372 DirectiveSet* _directive; // Compiler directive
373 CompileLog* _log; // from CompilerThread
374 CHeapStringHolder _failure_reason; // for record_failure/failing pattern
375 CompilationFailureInfo* _first_failure_details; // Details for the first failure happening during compilation
376 GrowableArray<CallGenerator*> _intrinsics; // List of intrinsics.
377 GrowableArray<Node*> _macro_nodes; // List of nodes which need to be expanded before matching.
378 GrowableArray<ParsePredicateNode*> _parse_predicates; // List of Parse Predicates.
379 GrowableArray<Node*> _template_assertion_predicate_opaqs; // List of Opaque4 nodes for Template Assertion Predicates.
380 GrowableArray<Node*> _expensive_nodes; // List of nodes that are expensive to compute and that we'd better not let the GVN freely common
381 GrowableArray<Node*> _for_post_loop_igvn; // List of nodes for IGVN after loop opts are over
382 GrowableArray<Node*> _inline_type_nodes; // List of InlineType nodes
383 GrowableArray<UnstableIfTrap*> _unstable_if_traps; // List of ifnodes after IGVN
384 GrowableArray<Node_List*> _coarsened_locks; // List of coarsened Lock and Unlock nodes
385 ConnectionGraph* _congraph;
386 #ifndef PRODUCT
387 IdealGraphPrinter* _igv_printer;
388 static IdealGraphPrinter* _debug_file_printer;
389 static IdealGraphPrinter* _debug_network_printer;
390 #endif
391
392
393 // Node management
394 uint _unique; // Counter for unique Node indices
395 uint _dead_node_count; // Number of dead nodes; VectorSet::Size() is O(N).
396 // So use this to keep count and make the call O(1).
397 VectorSet _dead_node_list; // Set of dead nodes
398 DEBUG_ONLY(Unique_Node_List* _modified_nodes;) // List of nodes which inputs were modified
399 DEBUG_ONLY(bool _phase_optimize_finished;) // Used for live node verification while creating new nodes
400
401 // Arenas for new-space and old-space nodes.
402 // Swapped between using _node_arena.
629 int do_cleanup() const { return _do_cleanup; }
630 void set_major_progress() { _major_progress++; }
631 void restore_major_progress(int progress) { _major_progress += progress; }
632 void clear_major_progress() { _major_progress = 0; }
633 int max_inline_size() const { return _max_inline_size; }
634 void set_freq_inline_size(int n) { _freq_inline_size = n; }
635 int freq_inline_size() const { return _freq_inline_size; }
636 void set_max_inline_size(int n) { _max_inline_size = n; }
637 bool has_loops() const { return _has_loops; }
638 void set_has_loops(bool z) { _has_loops = z; }
639 bool has_split_ifs() const { return _has_split_ifs; }
640 void set_has_split_ifs(bool z) { _has_split_ifs = z; }
641 bool has_unsafe_access() const { return _has_unsafe_access; }
642 void set_has_unsafe_access(bool z) { _has_unsafe_access = z; }
643 bool has_stringbuilder() const { return _has_stringbuilder; }
644 void set_has_stringbuilder(bool z) { _has_stringbuilder = z; }
645 bool has_boxed_value() const { return _has_boxed_value; }
646 void set_has_boxed_value(bool z) { _has_boxed_value = z; }
647 bool has_reserved_stack_access() const { return _has_reserved_stack_access; }
648 void set_has_reserved_stack_access(bool z) { _has_reserved_stack_access = z; }
649 bool has_circular_inline_type() const { return _has_circular_inline_type; }
650 void set_has_circular_inline_type(bool z) { _has_circular_inline_type = z; }
651 uint max_vector_size() const { return _max_vector_size; }
652 void set_max_vector_size(uint s) { _max_vector_size = s; }
653 bool clear_upper_avx() const { return _clear_upper_avx; }
654 void set_clear_upper_avx(bool s) { _clear_upper_avx = s; }
655 void set_trap_count(uint r, uint c) { assert(r < trapHistLength, "oob"); _trap_hist[r] = c; }
656 uint trap_count(uint r) const { assert(r < trapHistLength, "oob"); return _trap_hist[r]; }
657 bool trap_can_recompile() const { return _trap_can_recompile; }
658 void set_trap_can_recompile(bool z) { _trap_can_recompile = z; }
659 uint decompile_count() const { return _decompile_count; }
660 void set_decompile_count(uint c) { _decompile_count = c; }
661 bool allow_range_check_smearing() const;
662 bool do_inlining() const { return _do_inlining; }
663 void set_do_inlining(bool z) { _do_inlining = z; }
664 bool do_scheduling() const { return _do_scheduling; }
665 void set_do_scheduling(bool z) { _do_scheduling = z; }
666 bool do_freq_based_layout() const{ return _do_freq_based_layout; }
667 void set_do_freq_based_layout(bool z){ _do_freq_based_layout = z; }
668 bool do_vector_loop() const { return _do_vector_loop; }
669 void set_do_vector_loop(bool z) { _do_vector_loop = z; }
670 bool use_cmove() const { return _use_cmove; }
671 void set_use_cmove(bool z) { _use_cmove = z; }
672 bool do_aliasing() const { return _do_aliasing; }
673 bool print_assembly() const { return _print_assembly; }
674 void set_print_assembly(bool z) { _print_assembly = z; }
675 bool print_inlining() const { return _print_inlining; }
676 void set_print_inlining(bool z) { _print_inlining = z; }
677 bool print_intrinsics() const { return _print_intrinsics; }
678 void set_print_intrinsics(bool z) { _print_intrinsics = z; }
679 uint max_node_limit() const { return (uint)_max_node_limit; }
680 void set_max_node_limit(uint n) { _max_node_limit = n; }
681 bool clinit_barrier_on_entry() { return _clinit_barrier_on_entry; }
682 void set_clinit_barrier_on_entry(bool z) { _clinit_barrier_on_entry = z; }
683 void set_flat_accesses() { _has_flat_accesses = true; }
684 bool flat_accesses_share_alias() const { return _flat_accesses_share_alias; }
685 void set_flat_accesses_share_alias(bool z) { _flat_accesses_share_alias = z; }
686 bool scalarize_in_safepoints() const { return _scalarize_in_safepoints; }
687 void set_scalarize_in_safepoints(bool z) { _scalarize_in_safepoints = z; }
688
689 // Support for scalarized inline type calling convention
690 bool has_scalarized_args() const { return _method != nullptr && _method->has_scalarized_args(); }
691 bool needs_stack_repair() const { return _method != nullptr && _method->get_Method()->c2_needs_stack_repair(); }
692
693 bool has_monitors() const { return _has_monitors; }
694 void set_has_monitors(bool v) { _has_monitors = v; }
695 bool has_scoped_access() const { return _has_scoped_access; }
696 void set_has_scoped_access(bool v) { _has_scoped_access = v; }
697
698 // check the CompilerOracle for special behaviours for this compile
699 bool method_has_option(CompileCommandEnum 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; }
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 void mark_unbalanced_boxes() const;
803
804 bool post_loop_opts_phase() { return _post_loop_opts_phase; }
805 void set_post_loop_opts_phase() { _post_loop_opts_phase = true; }
806 void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }
807
808 bool allow_macro_nodes() { return _allow_macro_nodes; }
809 void reset_allow_macro_nodes() { _allow_macro_nodes = false; }
810
811 void record_for_post_loop_opts_igvn(Node* n);
812 void remove_from_post_loop_opts_igvn(Node* n);
813 void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
814
815 // Keep track of inline type nodes for later processing
816 void add_inline_type(Node* n);
817 void remove_inline_type(Node* n);
818 void process_inline_types(PhaseIterGVN &igvn, bool remove = false);
819
820 void adjust_flat_array_access_aliases(PhaseIterGVN& igvn);
821
822 void record_unstable_if_trap(UnstableIfTrap* trap);
823 bool remove_unstable_if_trap(CallStaticJavaNode* unc, bool yield);
824 void remove_useless_unstable_if_traps(Unique_Node_List &useful);
825 void process_for_unstable_if_traps(PhaseIterGVN& igvn);
826
827 void shuffle_macro_nodes();
828 void sort_macro_nodes();
829
830 void mark_parse_predicate_nodes_useless(PhaseIterGVN& igvn);
831
832 // Are there candidate expensive nodes for optimization?
833 bool should_optimize_expensive_nodes(PhaseIterGVN &igvn);
834 // Check whether n1 and n2 are similar
835 static int cmp_expensive_nodes(Node* n1, Node* n2);
836 // Sort expensive nodes to locate similar expensive nodes
837 void sort_expensive_nodes();
838
839 // Compilation environment.
840 Arena* comp_arena() { return &_comp_arena; }
841 ciEnv* env() const { return _env; }
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);
1205 // Number of outgoing stack slots killed above the out_preserve_stack_slots
1206 // for calls to C. Supports the var-args backing area for register parms.
1207 uint varargs_C_out_slots_killed() const;
1208
1209 // Number of Stack Slots consumed by a synchronization entry
1210 int sync_stack_slots() const;
1211
1212 // Compute the name of old_SP. See <arch>.ad for frame layout.
1213 OptoReg::Name compute_old_SP();
1214
1215 private:
1216 // Phase control:
1217 void Init(bool aliasing); // Prepare for a single compilation
1218 void Optimize(); // Given a graph, optimize it
1219 void Code_Gen(); // Generate code from a graph
1220
1221 // Management of the AliasType table.
1222 void grow_alias_types();
1223 AliasCacheEntry* probe_alias_cache(const TypePtr* adr_type);
1224 const TypePtr *flatten_alias_type(const TypePtr* adr_type) const;
1225 AliasType* find_alias_type(const TypePtr* adr_type, bool no_create, ciField* field, bool uncached = false);
1226
1227 void verify_top(Node*) const PRODUCT_RETURN;
1228
1229 // Intrinsic setup.
1230 CallGenerator* make_vm_intrinsic(ciMethod* m, bool is_virtual); // constructor
1231 int intrinsic_insertion_index(ciMethod* m, bool is_virtual, bool& found); // helper
1232 CallGenerator* find_intrinsic(ciMethod* m, bool is_virtual); // query fn
1233 void register_intrinsic(CallGenerator* cg); // update fn
1234
1235 #ifndef PRODUCT
1236 static juint _intrinsic_hist_count[];
1237 static jubyte _intrinsic_hist_flags[];
1238 #endif
1239 // Function calls made by the public function final_graph_reshaping.
1240 // No need to be made public as they are not called elsewhere.
1241 void final_graph_reshaping_impl(Node *n, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1242 void final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop, Unique_Node_List& dead_nodes);
1243 void final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1244 void eliminate_redundant_card_marks(Node* n);
1245 void handle_div_mod_op(Node* n, BasicType bt, bool is_unsigned);
1282 // End-of-run dumps.
1283 static void print_statistics() PRODUCT_RETURN;
1284
1285 // Verify ADLC assumptions during startup
1286 static void adlc_verification() PRODUCT_RETURN;
1287
1288 // Definitions of pd methods
1289 static void pd_compiler2_init();
1290
1291 // Static parse-time type checking logic for gen_subtype_check:
1292 enum SubTypeCheckResult { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
1293 SubTypeCheckResult static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip = StressReflectiveCode);
1294
1295 static Node* conv_I2X_index(PhaseGVN* phase, Node* offset, const TypeInt* sizetype,
1296 // Optional control dependency (for example, on range check)
1297 Node* ctrl = nullptr);
1298
1299 // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
1300 static Node* constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl, bool carry_dependency = false);
1301
1302 Node* optimize_acmp(PhaseGVN* phase, Node* a, Node* b);
1303
1304 // Auxiliary method for randomized fuzzing/stressing
1305 int random();
1306 bool randomized_select(int count);
1307
1308 // seed random number generation and log the seed for repeatability.
1309 void initialize_stress_seed(const DirectiveSet* directive);
1310
1311 // supporting clone_map
1312 CloneMap& clone_map();
1313 void set_clone_map(Dict* d);
1314
1315 bool needs_clinit_barrier(ciField* ik, ciMethod* accessing_method);
1316 bool needs_clinit_barrier(ciMethod* ik, ciMethod* accessing_method);
1317 bool needs_clinit_barrier(ciInstanceKlass* ik, ciMethod* accessing_method);
1318
1319 #ifdef IA32
1320 private:
1321 bool _select_24_bit_instr; // We selected an instruction with a 24-bit result
1322 bool _in_24_bit_fp_mode; // We are emitting instructions with 24-bit results
1323
1324 // Remember if this compilation changes hardware mode to 24-bit precision.
|