Mercurial > hg > truffle
comparison src/share/vm/opto/compile.cpp @ 14909:4ca6dc0799b6
Backout jdk9 merge
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Tue, 01 Apr 2014 13:57:07 +0200 |
parents | fdad2932c73f |
children | 52b4284cb496 |
comparison
equal
deleted
inserted
replaced
14908:8db6e76cb658 | 14909:4ca6dc0799b6 |
---|---|
23 */ | 23 */ |
24 | 24 |
25 #include "precompiled.hpp" | 25 #include "precompiled.hpp" |
26 #include "asm/macroAssembler.hpp" | 26 #include "asm/macroAssembler.hpp" |
27 #include "asm/macroAssembler.inline.hpp" | 27 #include "asm/macroAssembler.inline.hpp" |
28 #include "ci/ciReplay.hpp" | |
29 #include "classfile/systemDictionary.hpp" | 28 #include "classfile/systemDictionary.hpp" |
30 #include "code/exceptionHandlerTable.hpp" | 29 #include "code/exceptionHandlerTable.hpp" |
31 #include "code/nmethod.hpp" | 30 #include "code/nmethod.hpp" |
32 #include "compiler/compileLog.hpp" | 31 #include "compiler/compileLog.hpp" |
33 #include "compiler/disassembler.hpp" | 32 #include "compiler/disassembler.hpp" |
80 # include "adfiles/ad_zero.hpp" | 79 # include "adfiles/ad_zero.hpp" |
81 #endif | 80 #endif |
82 #ifdef TARGET_ARCH_MODEL_arm | 81 #ifdef TARGET_ARCH_MODEL_arm |
83 # include "adfiles/ad_arm.hpp" | 82 # include "adfiles/ad_arm.hpp" |
84 #endif | 83 #endif |
85 #ifdef TARGET_ARCH_MODEL_ppc_32 | 84 #ifdef TARGET_ARCH_MODEL_ppc |
86 # include "adfiles/ad_ppc_32.hpp" | 85 # include "adfiles/ad_ppc.hpp" |
87 #endif | |
88 #ifdef TARGET_ARCH_MODEL_ppc_64 | |
89 # include "adfiles/ad_ppc_64.hpp" | |
90 #endif | 86 #endif |
91 | 87 |
92 | 88 |
93 // -------------------- Compile::mach_constant_base_node ----------------------- | 89 // -------------------- Compile::mach_constant_base_node ----------------------- |
94 // Constant table base node singleton. | 90 // Constant table base node singleton. |
646 _in_scratch_emit_size(false), | 642 _in_scratch_emit_size(false), |
647 _dead_node_list(comp_arena()), | 643 _dead_node_list(comp_arena()), |
648 _dead_node_count(0), | 644 _dead_node_count(0), |
649 #ifndef PRODUCT | 645 #ifndef PRODUCT |
650 _trace_opto_output(TraceOptoOutput || method()->has_option("TraceOptoOutput")), | 646 _trace_opto_output(TraceOptoOutput || method()->has_option("TraceOptoOutput")), |
651 _in_dump_cnt(0), | |
652 _printer(IdealGraphPrinter::printer()), | 647 _printer(IdealGraphPrinter::printer()), |
653 #endif | 648 #endif |
654 _congraph(NULL), | 649 _congraph(NULL), |
655 _replay_inline_data(NULL), | |
656 _late_inlines(comp_arena(), 2, 0, NULL), | 650 _late_inlines(comp_arena(), 2, 0, NULL), |
657 _string_late_inlines(comp_arena(), 2, 0, NULL), | 651 _string_late_inlines(comp_arena(), 2, 0, NULL), |
658 _boxing_late_inlines(comp_arena(), 2, 0, NULL), | 652 _boxing_late_inlines(comp_arena(), 2, 0, NULL), |
659 _late_inlines_pos(0), | 653 _late_inlines_pos(0), |
660 _number_of_mh_late_inlines(0), | 654 _number_of_mh_late_inlines(0), |
684 print_opto_assembly = true; | 678 print_opto_assembly = true; |
685 } | 679 } |
686 } | 680 } |
687 set_print_assembly(print_opto_assembly); | 681 set_print_assembly(print_opto_assembly); |
688 set_parsed_irreducible_loop(false); | 682 set_parsed_irreducible_loop(false); |
689 | |
690 if (method()->has_option("ReplayInline")) { | |
691 _replay_inline_data = ciReplay::load_inline_data(method(), entry_bci(), ci_env->comp_level()); | |
692 } | |
693 #endif | 683 #endif |
694 set_print_inlining(PrintInlining || method()->has_option("PrintInlining") NOT_PRODUCT( || PrintOptoInlining)); | 684 set_print_inlining(PrintInlining || method()->has_option("PrintInlining") NOT_PRODUCT( || PrintOptoInlining)); |
695 set_print_intrinsics(PrintIntrinsics || method()->has_option("PrintIntrinsics")); | 685 set_print_intrinsics(PrintIntrinsics || method()->has_option("PrintIntrinsics")); |
696 | 686 |
697 if (ProfileTraps) { | 687 if (ProfileTraps) { |
703 Init(::AliasLevel); | 693 Init(::AliasLevel); |
704 | 694 |
705 | 695 |
706 print_compile_messages(); | 696 print_compile_messages(); |
707 | 697 |
708 _ilt = InlineTree::build_inline_tree_root(); | 698 if (UseOldInlining || PrintCompilation NOT_PRODUCT( || PrintOpto) ) |
699 _ilt = InlineTree::build_inline_tree_root(); | |
700 else | |
701 _ilt = NULL; | |
709 | 702 |
710 // Even if NO memory addresses are used, MergeMem nodes must have at least 1 slice | 703 // Even if NO memory addresses are used, MergeMem nodes must have at least 1 slice |
711 assert(num_alias_types() >= AliasIdxRaw, ""); | 704 assert(num_alias_types() >= AliasIdxRaw, ""); |
712 | 705 |
713 #define MINIMUM_NODE_HASH 1023 | 706 #define MINIMUM_NODE_HASH 1023 |
854 } | 847 } |
855 } | 848 } |
856 #endif | 849 #endif |
857 | 850 |
858 NOT_PRODUCT( verify_barriers(); ) | 851 NOT_PRODUCT( verify_barriers(); ) |
859 | |
860 // Dump compilation data to replay it. | |
861 if (method()->has_option("DumpReplay")) { | |
862 env()->dump_replay_data(_compile_id); | |
863 } | |
864 if (method()->has_option("DumpInline") && (ilt() != NULL)) { | |
865 env()->dump_inline_data(_compile_id); | |
866 } | |
867 | |
868 // Now that we know the size of all the monitors we can add a fixed slot | 852 // Now that we know the size of all the monitors we can add a fixed slot |
869 // for the original deopt pc. | 853 // for the original deopt pc. |
870 | 854 |
871 _orig_pc_slot = fixed_slots(); | 855 _orig_pc_slot = fixed_slots(); |
872 int next_slot = _orig_pc_slot + (sizeof(address) / VMRegImpl::stack_slot_size); | 856 int next_slot = _orig_pc_slot + (sizeof(address) / VMRegImpl::stack_slot_size); |
873 set_fixed_slots(next_slot); | 857 set_fixed_slots(next_slot); |
874 | |
875 // Compute when to use implicit null checks. Used by matching trap based | |
876 // nodes and NullCheck optimization. | |
877 set_allowed_deopt_reasons(); | |
878 | 858 |
879 // Now generate code | 859 // Now generate code |
880 Code_Gen(); | 860 Code_Gen(); |
881 if (failing()) return; | 861 if (failing()) return; |
882 | 862 |
951 _node_bundling_base(NULL), | 931 _node_bundling_base(NULL), |
952 _java_calls(0), | 932 _java_calls(0), |
953 _inner_loops(0), | 933 _inner_loops(0), |
954 #ifndef PRODUCT | 934 #ifndef PRODUCT |
955 _trace_opto_output(TraceOptoOutput), | 935 _trace_opto_output(TraceOptoOutput), |
956 _in_dump_cnt(0), | |
957 _printer(NULL), | 936 _printer(NULL), |
958 #endif | 937 #endif |
959 _dead_node_list(comp_arena()), | 938 _dead_node_list(comp_arena()), |
960 _dead_node_count(0), | 939 _dead_node_count(0), |
961 _congraph(NULL), | 940 _congraph(NULL), |
962 _replay_inline_data(NULL), | |
963 _number_of_mh_late_inlines(0), | 941 _number_of_mh_late_inlines(0), |
964 _inlining_progress(false), | 942 _inlining_progress(false), |
965 _inlining_incrementally(false), | 943 _inlining_incrementally(false), |
966 _print_inlining_list(NULL), | 944 _print_inlining_list(NULL), |
967 _print_inlining_idx(0), | 945 _print_inlining_idx(0), |
968 _preserve_jvm_state(0), | 946 _preserve_jvm_state(0) { |
969 _allowed_reasons(0) { | |
970 C = this; | 947 C = this; |
971 | 948 |
972 #ifndef PRODUCT | 949 #ifndef PRODUCT |
973 TraceTime t1(NULL, &_t_totalCompilation, TimeCompiler, false); | 950 TraceTime t1(NULL, &_t_totalCompilation, TimeCompiler, false); |
974 TraceTime t2(NULL, &_t_stubCompilation, TimeCompiler, false); | 951 TraceTime t2(NULL, &_t_stubCompilation, TimeCompiler, false); |
2267 // Apply peephole optimizations | 2244 // Apply peephole optimizations |
2268 if( OptoPeephole ) { | 2245 if( OptoPeephole ) { |
2269 NOT_PRODUCT( TracePhase t2("peephole", &_t_peephole, TimeCompiler); ) | 2246 NOT_PRODUCT( TracePhase t2("peephole", &_t_peephole, TimeCompiler); ) |
2270 PhasePeephole peep( _regalloc, cfg); | 2247 PhasePeephole peep( _regalloc, cfg); |
2271 peep.do_transform(); | 2248 peep.do_transform(); |
2272 } | |
2273 | |
2274 // Do late expand if CPU requires this. | |
2275 if (Matcher::require_postalloc_expand) { | |
2276 NOT_PRODUCT(TracePhase t2c("postalloc_expand", &_t_postalloc_expand, true)); | |
2277 cfg.postalloc_expand(_regalloc); | |
2278 } | 2249 } |
2279 | 2250 |
2280 // Convert Nodes to instruction bits in a buffer | 2251 // Convert Nodes to instruction bits in a buffer |
2281 { | 2252 { |
2282 // %%%% workspace merge brought two timers together for one job | 2253 // %%%% workspace merge brought two timers together for one job |
3026 // confuses register allocation. | 2997 // confuses register allocation. |
3027 if (n->req() > MemBarNode::Precedent) { | 2998 if (n->req() > MemBarNode::Precedent) { |
3028 n->set_req(MemBarNode::Precedent, top()); | 2999 n->set_req(MemBarNode::Precedent, top()); |
3029 } | 3000 } |
3030 break; | 3001 break; |
3002 // Must set a control edge on all nodes that produce a FlagsProj | |
3003 // so they can't escape the block that consumes the flags. | |
3004 // Must also set the non throwing branch as the control | |
3005 // for all nodes that depends on the result. Unless the node | |
3006 // already have a control that isn't the control of the | |
3007 // flag producer | |
3008 case Op_FlagsProj: | |
3009 { | |
3010 MathExactNode* math = (MathExactNode*) n->in(0); | |
3011 Node* ctrl = math->control_node(); | |
3012 Node* non_throwing = math->non_throwing_branch(); | |
3013 math->set_req(0, ctrl); | |
3014 | |
3015 Node* result = math->result_node(); | |
3016 if (result != NULL) { | |
3017 for (DUIterator_Fast jmax, j = result->fast_outs(jmax); j < jmax; j++) { | |
3018 Node* out = result->fast_out(j); | |
3019 // Phi nodes shouldn't be moved. They would only match below if they | |
3020 // had the same control as the MathExactNode. The only time that | |
3021 // would happen is if the Phi is also an input to the MathExact | |
3022 // | |
3023 // Cmp nodes shouldn't have control set at all. | |
3024 if (out->is_Phi() || | |
3025 out->is_Cmp()) { | |
3026 continue; | |
3027 } | |
3028 | |
3029 if (out->in(0) == NULL) { | |
3030 out->set_req(0, non_throwing); | |
3031 } else if (out->in(0) == ctrl) { | |
3032 out->set_req(0, non_throwing); | |
3033 } | |
3034 } | |
3035 } | |
3036 } | |
3037 break; | |
3031 default: | 3038 default: |
3032 assert( !n->is_Call(), "" ); | 3039 assert( !n->is_Call(), "" ); |
3033 assert( !n->is_Mem(), "" ); | 3040 assert( !n->is_Mem(), "" ); |
3034 break; | 3041 break; |
3035 } | 3042 } |
3247 if (md->is_empty()) { | 3254 if (md->is_empty()) { |
3248 // Assume the trap has not occurred, or that it occurred only | 3255 // Assume the trap has not occurred, or that it occurred only |
3249 // because of a transient condition during start-up in the interpreter. | 3256 // because of a transient condition during start-up in the interpreter. |
3250 return false; | 3257 return false; |
3251 } | 3258 } |
3252 ciMethod* m = Deoptimization::reason_is_speculate(reason) ? this->method() : NULL; | 3259 if (md->has_trap_at(bci, reason) != 0) { |
3253 if (md->has_trap_at(bci, m, reason) != 0) { | |
3254 // Assume PerBytecodeTrapLimit==0, for a more conservative heuristic. | 3260 // Assume PerBytecodeTrapLimit==0, for a more conservative heuristic. |
3255 // Also, if there are multiple reasons, or if there is no per-BCI record, | 3261 // Also, if there are multiple reasons, or if there is no per-BCI record, |
3256 // assume the worst. | 3262 // assume the worst. |
3257 if (log()) | 3263 if (log()) |
3258 log()->elem("observe trap='%s' count='%d'", | 3264 log()->elem("observe trap='%s' count='%d'", |
3266 } | 3272 } |
3267 | 3273 |
3268 // Less-accurate variant which does not require a method and bci. | 3274 // Less-accurate variant which does not require a method and bci. |
3269 bool Compile::too_many_traps(Deoptimization::DeoptReason reason, | 3275 bool Compile::too_many_traps(Deoptimization::DeoptReason reason, |
3270 ciMethodData* logmd) { | 3276 ciMethodData* logmd) { |
3271 if (trap_count(reason) >= Deoptimization::per_method_trap_limit(reason)) { | 3277 if (trap_count(reason) >= (uint)PerMethodTrapLimit) { |
3272 // Too many traps globally. | 3278 // Too many traps globally. |
3273 // Note that we use cumulative trap_count, not just md->trap_count. | 3279 // Note that we use cumulative trap_count, not just md->trap_count. |
3274 if (log()) { | 3280 if (log()) { |
3275 int mcount = (logmd == NULL)? -1: (int)logmd->trap_count(reason); | 3281 int mcount = (logmd == NULL)? -1: (int)logmd->trap_count(reason); |
3276 log()->elem("observe trap='%s' count='0' mcount='%d' ccount='%d'", | 3282 log()->elem("observe trap='%s' count='0' mcount='%d' ccount='%d'", |
3301 // Pick a cutoff point well within PerBytecodeRecompilationCutoff. | 3307 // Pick a cutoff point well within PerBytecodeRecompilationCutoff. |
3302 uint bc_cutoff = (uint) PerBytecodeRecompilationCutoff / 8; | 3308 uint bc_cutoff = (uint) PerBytecodeRecompilationCutoff / 8; |
3303 uint m_cutoff = (uint) PerMethodRecompilationCutoff / 2 + 1; // not zero | 3309 uint m_cutoff = (uint) PerMethodRecompilationCutoff / 2 + 1; // not zero |
3304 Deoptimization::DeoptReason per_bc_reason | 3310 Deoptimization::DeoptReason per_bc_reason |
3305 = Deoptimization::reason_recorded_per_bytecode_if_any(reason); | 3311 = Deoptimization::reason_recorded_per_bytecode_if_any(reason); |
3306 ciMethod* m = Deoptimization::reason_is_speculate(reason) ? this->method() : NULL; | |
3307 if ((per_bc_reason == Deoptimization::Reason_none | 3312 if ((per_bc_reason == Deoptimization::Reason_none |
3308 || md->has_trap_at(bci, m, reason) != 0) | 3313 || md->has_trap_at(bci, reason) != 0) |
3309 // The trap frequency measure we care about is the recompile count: | 3314 // The trap frequency measure we care about is the recompile count: |
3310 && md->trap_recompiled_at(bci, m) | 3315 && md->trap_recompiled_at(bci) |
3311 && md->overflow_recompile_count() >= bc_cutoff) { | 3316 && md->overflow_recompile_count() >= bc_cutoff) { |
3312 // Do not emit a trap here if it has already caused recompilations. | 3317 // Do not emit a trap here if it has already caused recompilations. |
3313 // Also, if there are multiple reasons, or if there is no per-BCI record, | 3318 // Also, if there are multiple reasons, or if there is no per-BCI record, |
3314 // assume the worst. | 3319 // assume the worst. |
3315 if (log()) | 3320 if (log()) |
3332 // The coast is clear. | 3337 // The coast is clear. |
3333 return false; | 3338 return false; |
3334 } | 3339 } |
3335 } | 3340 } |
3336 | 3341 |
3337 // Compute when not to trap. Used by matching trap based nodes and | |
3338 // NullCheck optimization. | |
3339 void Compile::set_allowed_deopt_reasons() { | |
3340 _allowed_reasons = 0; | |
3341 if (is_method_compilation()) { | |
3342 for (int rs = (int)Deoptimization::Reason_none+1; rs < Compile::trapHistLength; rs++) { | |
3343 assert(rs < BitsPerInt, "recode bit map"); | |
3344 if (!too_many_traps((Deoptimization::DeoptReason) rs)) { | |
3345 _allowed_reasons |= nth_bit(rs); | |
3346 } | |
3347 } | |
3348 } | |
3349 } | |
3350 | 3342 |
3351 #ifndef PRODUCT | 3343 #ifndef PRODUCT |
3352 //------------------------------verify_graph_edges--------------------------- | 3344 //------------------------------verify_graph_edges--------------------------- |
3353 // Walk the Graph and verify that there is a one-to-one correspondence | 3345 // Walk the Graph and verify that there is a one-to-one correspondence |
3354 // between Use-Def edges and Def-Use edges in the graph. | 3346 // between Use-Def edges and Def-Use edges in the graph. |
3763 tty->print(_print_inlining_list->adr_at(i)->ss()->as_string()); | 3755 tty->print(_print_inlining_list->adr_at(i)->ss()->as_string()); |
3764 } | 3756 } |
3765 } | 3757 } |
3766 } | 3758 } |
3767 | 3759 |
3768 // Dump inlining replay data to the stream. | |
3769 // Don't change thread state and acquire any locks. | |
3770 void Compile::dump_inline_data(outputStream* out) { | |
3771 InlineTree* inl_tree = ilt(); | |
3772 if (inl_tree != NULL) { | |
3773 out->print(" inline %d", inl_tree->count()); | |
3774 inl_tree->dump_replay_data(out); | |
3775 } | |
3776 } | |
3777 | |
3778 int Compile::cmp_expensive_nodes(Node* n1, Node* n2) { | 3760 int Compile::cmp_expensive_nodes(Node* n1, Node* n2) { |
3779 if (n1->Opcode() < n2->Opcode()) return -1; | 3761 if (n1->Opcode() < n2->Opcode()) return -1; |
3780 else if (n1->Opcode() > n2->Opcode()) return 1; | 3762 else if (n1->Opcode() > n2->Opcode()) return 1; |
3781 | 3763 |
3782 assert(n1->req() == n2->req(), err_msg_res("can't compare %s nodes: n1->req() = %d, n2->req() = %d", NodeClassNames[n1->Opcode()], n1->req(), n2->req())); | 3764 assert(n1->req() == n2->req(), err_msg_res("can't compare %s nodes: n1->req() = %d, n2->req() = %d", NodeClassNames[n1->Opcode()], n1->req(), n2->req())); |
3909 // Go over all type nodes that carry a speculative type, drop the | 3891 // Go over all type nodes that carry a speculative type, drop the |
3910 // speculative part of the type and enqueue the node for an igvn | 3892 // speculative part of the type and enqueue the node for an igvn |
3911 // which may optimize it out. | 3893 // which may optimize it out. |
3912 for (uint next = 0; next < worklist.size(); ++next) { | 3894 for (uint next = 0; next < worklist.size(); ++next) { |
3913 Node *n = worklist.at(next); | 3895 Node *n = worklist.at(next); |
3914 if (n->is_Type()) { | 3896 if (n->is_Type() && n->as_Type()->type()->isa_oopptr() != NULL && |
3897 n->as_Type()->type()->is_oopptr()->speculative() != NULL) { | |
3915 TypeNode* tn = n->as_Type(); | 3898 TypeNode* tn = n->as_Type(); |
3916 const Type* t = tn->type(); | 3899 const TypeOopPtr* t = tn->type()->is_oopptr(); |
3917 const Type* t_no_spec = t->remove_speculative(); | 3900 bool in_hash = igvn.hash_delete(n); |
3918 if (t_no_spec != t) { | 3901 assert(in_hash, "node should be in igvn hash table"); |
3919 bool in_hash = igvn.hash_delete(n); | 3902 tn->set_type(t->remove_speculative()); |
3920 assert(in_hash, "node should be in igvn hash table"); | 3903 igvn.hash_insert(n); |
3921 tn->set_type(t_no_spec); | 3904 igvn._worklist.push(n); // give it a chance to go away |
3922 igvn.hash_insert(n); | 3905 modified++; |
3923 igvn._worklist.push(n); // give it a chance to go away | |
3924 modified++; | |
3925 } | |
3926 } | 3906 } |
3927 uint max = n->len(); | 3907 uint max = n->len(); |
3928 for( uint i = 0; i < max; ++i ) { | 3908 for( uint i = 0; i < max; ++i ) { |
3929 Node *m = n->in(i); | 3909 Node *m = n->in(i); |
3930 if (not_a_node(m)) continue; | 3910 if (not_a_node(m)) continue; |
3934 // Drop the speculative part of all types in the igvn's type table | 3914 // Drop the speculative part of all types in the igvn's type table |
3935 igvn.remove_speculative_types(); | 3915 igvn.remove_speculative_types(); |
3936 if (modified > 0) { | 3916 if (modified > 0) { |
3937 igvn.optimize(); | 3917 igvn.optimize(); |
3938 } | 3918 } |
3939 #ifdef ASSERT | |
3940 // Verify that after the IGVN is over no speculative type has resurfaced | |
3941 worklist.clear(); | |
3942 worklist.push(root()); | |
3943 for (uint next = 0; next < worklist.size(); ++next) { | |
3944 Node *n = worklist.at(next); | |
3945 const Type* t = igvn.type(n); | |
3946 assert(t == t->remove_speculative(), "no more speculative types"); | |
3947 if (n->is_Type()) { | |
3948 t = n->as_Type()->type(); | |
3949 assert(t == t->remove_speculative(), "no more speculative types"); | |
3950 } | |
3951 uint max = n->len(); | |
3952 for( uint i = 0; i < max; ++i ) { | |
3953 Node *m = n->in(i); | |
3954 if (not_a_node(m)) continue; | |
3955 worklist.push(m); | |
3956 } | |
3957 } | |
3958 igvn.check_no_speculative_types(); | |
3959 #endif | |
3960 } | 3919 } |
3961 } | 3920 } |
3962 | 3921 |
3963 // Auxiliary method to support randomized stressing/fuzzing. | 3922 // Auxiliary method to support randomized stressing/fuzzing. |
3964 // | 3923 // |