2664 // Accumulate any precedence edges
2665 if (mem->in(i) != NULL) {
2666 n->add_prec(mem->in(i));
2667 }
2668 }
2669 // Everything above this point has been processed.
2670 done = true;
2671 }
2672 // Eliminate the previous StoreCM
2673 prev->set_req(MemNode::Memory, mem->in(MemNode::Memory));
2674 assert(mem->outcnt() == 0, "should be dead");
2675 mem->disconnect_inputs(NULL, this);
2676 } else {
2677 prev = mem;
2678 }
2679 mem = prev->in(MemNode::Memory);
2680 }
2681 }
2682 }
2683
2684 //------------------------------final_graph_reshaping_impl----------------------
2685 // Implement items 1-5 from final_graph_reshaping below.
2686 void Compile::final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc) {
2687
2688 if ( n->outcnt() == 0 ) return; // dead node
2689 uint nop = n->Opcode();
2690
2691 // Check for 2-input instruction with "last use" on right input.
2692 // Swap to left input. Implements item (2).
2693 if( n->req() == 3 && // two-input instruction
2694 n->in(1)->outcnt() > 1 && // left use is NOT a last use
2695 (!n->in(1)->is_Phi() || n->in(1)->in(2) != n) && // it is not data loop
2696 n->in(2)->outcnt() == 1 &&// right use IS a last use
2697 !n->in(2)->is_Con() ) { // right use is not a constant
2698 // Check for commutative opcode
2699 switch( nop ) {
2700 case Op_AddI: case Op_AddF: case Op_AddD: case Op_AddL:
2701 case Op_MaxI: case Op_MinI:
2702 case Op_MulI: case Op_MulF: case Op_MulD: case Op_MulL:
2703 case Op_AndL: case Op_XorL: case Op_OrL:
2763 case Op_Opaque1: // Remove Opaque Nodes before matching
2764 case Op_Opaque2: // Remove Opaque Nodes before matching
2765 case Op_Opaque3:
2766 n->subsume_by(n->in(1), this);
2767 break;
2768 case Op_CallStaticJava:
2769 case Op_CallJava:
2770 case Op_CallDynamicJava:
2771 frc.inc_java_call_count(); // Count java call site;
2772 case Op_CallRuntime:
2773 case Op_CallLeaf:
2774 case Op_CallLeafNoFP: {
2775 assert( n->is_Call(), "" );
2776 CallNode *call = n->as_Call();
2777 // Count call sites where the FP mode bit would have to be flipped.
2778 // Do not count uncommon runtime calls:
2779 // uncommon_trap, _complete_monitor_locking, _complete_monitor_unlocking,
2780 // _new_Java, _new_typeArray, _new_objArray, _rethrow_Java, ...
2781 if( !call->is_CallStaticJava() || !call->as_CallStaticJava()->_name ) {
2782 frc.inc_call_count(); // Count the call site
2783 } else { // See if uncommon argument is shared
2784 Node *n = call->in(TypeFunc::Parms);
2785 int nop = n->Opcode();
2786 // Clone shared simple arguments to uncommon calls, item (1).
2787 if( n->outcnt() > 1 &&
2788 !n->is_Proj() &&
2789 nop != Op_CreateEx &&
2790 nop != Op_CheckCastPP &&
2791 nop != Op_DecodeN &&
2792 nop != Op_DecodeNKlass &&
2793 !n->is_Mem() ) {
2794 Node *x = n->clone();
2795 call->set_req( TypeFunc::Parms, x );
2796 }
2797 }
2798 break;
2799 }
2800
2801 case Op_StoreD:
2802 case Op_LoadD:
2803 case Op_LoadD_unaligned:
2804 frc.inc_double_count();
2805 goto handle_mem;
2806 case Op_StoreF:
2807 case Op_LoadF:
2808 frc.inc_float_count();
2809 goto handle_mem;
2810
2811 case Op_StoreCM:
2812 {
2813 // Convert OopStore dependence into precedence edge
2814 Node* prec = n->in(MemNode::OopStore);
2815 n->del_req(MemNode::OopStore);
2816 n->add_prec(prec);
2817 eliminate_redundant_card_marks(n);
4600 for(; di.test(); ++di) {
4601 int t = gen(di._key);
4602 if (g < t) {
4603 g = t;
4604 #ifndef PRODUCT
4605 if (is_debug()) {
4606 tty->print_cr("CloneMap::max_gen() update max=%d from %d", g, _2_node_idx_t(di._key));
4607 }
4608 #endif
4609 }
4610 }
4611 return g;
4612 }
4613
4614 void CloneMap::dump(node_idx_t key) const {
4615 uint64_t val = value(key);
4616 if (val != 0) {
4617 NodeCloneInfo ni(val);
4618 ni.dump();
4619 }
4620 }
|
2664 // Accumulate any precedence edges
2665 if (mem->in(i) != NULL) {
2666 n->add_prec(mem->in(i));
2667 }
2668 }
2669 // Everything above this point has been processed.
2670 done = true;
2671 }
2672 // Eliminate the previous StoreCM
2673 prev->set_req(MemNode::Memory, mem->in(MemNode::Memory));
2674 assert(mem->outcnt() == 0, "should be dead");
2675 mem->disconnect_inputs(NULL, this);
2676 } else {
2677 prev = mem;
2678 }
2679 mem = prev->in(MemNode::Memory);
2680 }
2681 }
2682 }
2683
2684 void Compile::value_type_return_from_mh_intrinsic(CallNode *call, Final_Reshape_Counts &frc) {
2685 if (ValueTypeReturnedAsFields &&
2686 call->is_CallStaticJava() &&
2687 call->as_CallStaticJava()->method() != NULL &&
2688 call->as_CallStaticJava()->method()->is_method_handle_intrinsic() &&
2689 call->proj_out(TypeFunc::Parms) != NULL &&
2690 call->proj_out(TypeFunc::Parms)->bottom_type()->isa_valuetypeptr()) {
2691 // A value type is returned from the call but we don't know its
2692 // type. One of the value being returned is the klass of the value
2693 // type. We need to allocate a value type instance of that type
2694 // and initialize it with other values being returned. This is
2695 // done with the stub call below that we add right after this
2696 // call.
2697 Node* ret = call->proj_out(TypeFunc::Parms);
2698 assert(ret->bottom_type()->is_valuetypeptr()->klass() == env()->___Value_klass(), "unexpected return type from MH intrinsic");
2699 const TypeFunc* _tf = call->_tf;
2700 const TypeTuple* domain = OptoRuntime::store_value_type_fields_Type()->domain_cc();
2701 const TypeFunc* new_tf = TypeFunc::make(_tf->domain_sig(), _tf->domain_cc(), _tf->range_sig(), domain);
2702 call->_tf = new_tf;
2703
2704 CallProjections projs;
2705 call->extract_projections(&projs, true, true);
2706 Node* ctl = projs.fallthrough_catchproj;
2707 Node* mem = projs.fallthrough_memproj;
2708 Node* io = projs.fallthrough_ioproj;
2709 Node* ex_ctl = projs.catchall_catchproj;
2710 Node* ex_mem = projs.catchall_memproj;
2711 Node* ex_io = projs.catchall_ioproj;
2712 CallStaticJavaNode* rt_call = new CallStaticJavaNode(OptoRuntime::store_value_type_fields_Type(),
2713 StubRoutines::store_value_type_fields_to_buf(),
2714 "store_value_type_fields",
2715 call->jvms()->bci(),
2716 TypePtr::BOTTOM);
2717 Node* out_ctl = new ProjNode(rt_call, TypeFunc::Control);
2718 Node* out_mem = new ProjNode(rt_call, TypeFunc::Memory);
2719 Node* out_io = new ProjNode(rt_call, TypeFunc::I_O);
2720 Node* res = new ProjNode(rt_call, TypeFunc::Parms);
2721
2722 Node* catc = new CatchNode(out_ctl, out_io, 2);
2723 Node* norm = new CatchProjNode(catc, CatchProjNode::fall_through_index, CatchProjNode::no_handler_bci);
2724 Node* excp = new CatchProjNode(catc, CatchProjNode::catch_all_index, CatchProjNode::no_handler_bci);
2725 Node* r = new RegionNode(3);
2726 Node* mem_phi = new PhiNode(r, Type::MEMORY, TypePtr::BOTTOM);
2727 Node* io_phi = new PhiNode(r, Type::ABIO);
2728 r->init_req(1, excp);
2729 mem_phi->init_req(1, out_mem);
2730 io_phi->init_req(1, out_io);
2731
2732 frc._visited.set(norm->_idx);
2733 frc._visited.set(excp->_idx);
2734
2735 ctl->replace_by(norm);
2736 mem->replace_by(out_mem);
2737 io->replace_by(out_io);
2738 ret->replace_by(res);
2739 ex_ctl->replace_by(r);
2740 ex_mem->replace_by(mem_phi);
2741 ex_io->replace_by(io_phi);
2742
2743 r->init_req(2, ex_ctl);
2744 mem_phi->init_req(2, ex_mem);
2745 io_phi->init_req(2, ex_io);
2746
2747 rt_call->init_req(TypeFunc::Control, ctl);
2748 rt_call->init_req(TypeFunc::Memory, mem);
2749 rt_call->init_req(TypeFunc::I_O, io);
2750 rt_call->init_req(TypeFunc::FramePtr, call->in(TypeFunc::FramePtr));
2751 rt_call->init_req(TypeFunc::ReturnAdr, call->in(TypeFunc::ReturnAdr));
2752
2753 rt_call->init_req(TypeFunc::Parms, ret);
2754 // We don't know how many values are returned. This assumes the
2755 // worst case, that all available registers are used.
2756 for (uint i = TypeFunc::Parms+1; i < domain->cnt(); i++) {
2757 if (domain->field_at(i) == Type::HALF) {
2758 rt_call->init_req(i, top());
2759 continue;
2760 }
2761 Node* proj = new ProjNode(call, i);
2762 rt_call->init_req(i, proj);
2763 }
2764
2765 // We can safepoint at that new call
2766 add_safepoint_edges(rt_call, call->jvms());
2767 }
2768 }
2769
2770 //------------------------------final_graph_reshaping_impl----------------------
2771 // Implement items 1-5 from final_graph_reshaping below.
2772 void Compile::final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc) {
2773
2774 if ( n->outcnt() == 0 ) return; // dead node
2775 uint nop = n->Opcode();
2776
2777 // Check for 2-input instruction with "last use" on right input.
2778 // Swap to left input. Implements item (2).
2779 if( n->req() == 3 && // two-input instruction
2780 n->in(1)->outcnt() > 1 && // left use is NOT a last use
2781 (!n->in(1)->is_Phi() || n->in(1)->in(2) != n) && // it is not data loop
2782 n->in(2)->outcnt() == 1 &&// right use IS a last use
2783 !n->in(2)->is_Con() ) { // right use is not a constant
2784 // Check for commutative opcode
2785 switch( nop ) {
2786 case Op_AddI: case Op_AddF: case Op_AddD: case Op_AddL:
2787 case Op_MaxI: case Op_MinI:
2788 case Op_MulI: case Op_MulF: case Op_MulD: case Op_MulL:
2789 case Op_AndL: case Op_XorL: case Op_OrL:
2849 case Op_Opaque1: // Remove Opaque Nodes before matching
2850 case Op_Opaque2: // Remove Opaque Nodes before matching
2851 case Op_Opaque3:
2852 n->subsume_by(n->in(1), this);
2853 break;
2854 case Op_CallStaticJava:
2855 case Op_CallJava:
2856 case Op_CallDynamicJava:
2857 frc.inc_java_call_count(); // Count java call site;
2858 case Op_CallRuntime:
2859 case Op_CallLeaf:
2860 case Op_CallLeafNoFP: {
2861 assert( n->is_Call(), "" );
2862 CallNode *call = n->as_Call();
2863 // Count call sites where the FP mode bit would have to be flipped.
2864 // Do not count uncommon runtime calls:
2865 // uncommon_trap, _complete_monitor_locking, _complete_monitor_unlocking,
2866 // _new_Java, _new_typeArray, _new_objArray, _rethrow_Java, ...
2867 if( !call->is_CallStaticJava() || !call->as_CallStaticJava()->_name ) {
2868 frc.inc_call_count(); // Count the call site
2869 } else if (call->req() > TypeFunc::Parms) { // See if uncommon argument is shared
2870 Node *n = call->in(TypeFunc::Parms);
2871 int nop = n->Opcode();
2872 // Clone shared simple arguments to uncommon calls, item (1).
2873 if( n->outcnt() > 1 &&
2874 !n->is_Proj() &&
2875 nop != Op_CreateEx &&
2876 nop != Op_CheckCastPP &&
2877 nop != Op_DecodeN &&
2878 nop != Op_DecodeNKlass &&
2879 !n->is_Mem() ) {
2880 Node *x = n->clone();
2881 call->set_req( TypeFunc::Parms, x );
2882 }
2883 }
2884 value_type_return_from_mh_intrinsic(call, frc);
2885 break;
2886 }
2887
2888 case Op_StoreD:
2889 case Op_LoadD:
2890 case Op_LoadD_unaligned:
2891 frc.inc_double_count();
2892 goto handle_mem;
2893 case Op_StoreF:
2894 case Op_LoadF:
2895 frc.inc_float_count();
2896 goto handle_mem;
2897
2898 case Op_StoreCM:
2899 {
2900 // Convert OopStore dependence into precedence edge
2901 Node* prec = n->in(MemNode::OopStore);
2902 n->del_req(MemNode::OopStore);
2903 n->add_prec(prec);
2904 eliminate_redundant_card_marks(n);
4687 for(; di.test(); ++di) {
4688 int t = gen(di._key);
4689 if (g < t) {
4690 g = t;
4691 #ifndef PRODUCT
4692 if (is_debug()) {
4693 tty->print_cr("CloneMap::max_gen() update max=%d from %d", g, _2_node_idx_t(di._key));
4694 }
4695 #endif
4696 }
4697 }
4698 return g;
4699 }
4700
4701 void CloneMap::dump(node_idx_t key) const {
4702 uint64_t val = value(key);
4703 if (val != 0) {
4704 NodeCloneInfo ni(val);
4705 ni.dump();
4706 }
4707 }
4708
4709 // Helper function for enforcing certain bytecodes to reexecute if
4710 // deoptimization happens
4711 static bool should_reexecute_implied_by_bytecode(JVMState *jvms, bool is_anewarray) {
4712 ciMethod* cur_method = jvms->method();
4713 int cur_bci = jvms->bci();
4714 if (cur_method != NULL && cur_bci != InvocationEntryBci) {
4715 Bytecodes::Code code = cur_method->java_code_at_bci(cur_bci);
4716 return Interpreter::bytecode_should_reexecute(code) ||
4717 is_anewarray && code == Bytecodes::_multianewarray;
4718 // Reexecute _multianewarray bytecode which was replaced with
4719 // sequence of [a]newarray. See Parse::do_multianewarray().
4720 //
4721 // Note: interpreter should not have it set since this optimization
4722 // is limited by dimensions and guarded by flag so in some cases
4723 // multianewarray() runtime calls will be generated and
4724 // the bytecode should not be reexecutes (stack will not be reset).
4725 } else
4726 return false;
4727 }
4728
4729 void Compile::add_safepoint_edges(SafePointNode* call, JVMState* youngest_jvms, bool can_prune_locals, uint stack_slots_not_pruned) {
4730 // do not scribble on the input jvms
4731 JVMState* out_jvms = youngest_jvms->clone_deep(C);
4732 call->set_jvms(out_jvms); // Start jvms list for call node
4733
4734 // For a known set of bytecodes, the interpreter should reexecute them if
4735 // deoptimization happens. We set the reexecute state for them here
4736 if (out_jvms->is_reexecute_undefined() && //don't change if already specified
4737 should_reexecute_implied_by_bytecode(out_jvms, call->is_AllocateArray())) {
4738 out_jvms->set_should_reexecute(true); //NOTE: youngest_jvms not changed
4739 }
4740
4741 // Presize the call:
4742 DEBUG_ONLY(uint non_debug_edges = call->req());
4743 call->add_req_batch(top(), youngest_jvms->debug_depth());
4744 assert(call->req() == non_debug_edges + youngest_jvms->debug_depth(), "");
4745
4746 // Set up edges so that the call looks like this:
4747 // Call [state:] ctl io mem fptr retadr
4748 // [parms:] parm0 ... parmN
4749 // [root:] loc0 ... locN stk0 ... stkSP mon0 obj0 ... monN objN
4750 // [...mid:] loc0 ... locN stk0 ... stkSP mon0 obj0 ... monN objN [...]
4751 // [young:] loc0 ... locN stk0 ... stkSP mon0 obj0 ... monN objN
4752 // Note that caller debug info precedes callee debug info.
4753
4754 // Fill pointer walks backwards from "young:" to "root:" in the diagram above:
4755 uint debug_ptr = call->req();
4756
4757 // Loop over the map input edges associated with jvms, add them
4758 // to the call node, & reset all offsets to match call node array.
4759 for (JVMState* in_jvms = youngest_jvms; in_jvms != NULL; ) {
4760 uint debug_end = debug_ptr;
4761 uint debug_start = debug_ptr - in_jvms->debug_size();
4762 debug_ptr = debug_start; // back up the ptr
4763
4764 uint p = debug_start; // walks forward in [debug_start, debug_end)
4765 uint j, k, l;
4766 SafePointNode* in_map = in_jvms->map();
4767 out_jvms->set_map(call);
4768
4769 if (can_prune_locals) {
4770 assert(in_jvms->method() == out_jvms->method(), "sanity");
4771 // If the current throw can reach an exception handler in this JVMS,
4772 // then we must keep everything live that can reach that handler.
4773 // As a quick and dirty approximation, we look for any handlers at all.
4774 if (in_jvms->method()->has_exception_handlers()) {
4775 can_prune_locals = false;
4776 }
4777 }
4778
4779 // Add the Locals
4780 k = in_jvms->locoff();
4781 l = in_jvms->loc_size();
4782 out_jvms->set_locoff(p);
4783 if (!can_prune_locals) {
4784 for (j = 0; j < l; j++)
4785 call->set_req(p++, in_map->in(k+j));
4786 } else {
4787 p += l; // already set to top above by add_req_batch
4788 }
4789
4790 // Add the Expression Stack
4791 k = in_jvms->stkoff();
4792 l = in_jvms->sp();
4793 out_jvms->set_stkoff(p);
4794 if (!can_prune_locals) {
4795 for (j = 0; j < l; j++)
4796 call->set_req(p++, in_map->in(k+j));
4797 } else if (can_prune_locals && stack_slots_not_pruned != 0) {
4798 // Divide stack into {S0,...,S1}, where S0 is set to top.
4799 uint s1 = stack_slots_not_pruned;
4800 stack_slots_not_pruned = 0; // for next iteration
4801 if (s1 > l) s1 = l;
4802 uint s0 = l - s1;
4803 p += s0; // skip the tops preinstalled by add_req_batch
4804 for (j = s0; j < l; j++)
4805 call->set_req(p++, in_map->in(k+j));
4806 } else {
4807 p += l; // already set to top above by add_req_batch
4808 }
4809
4810 // Add the Monitors
4811 k = in_jvms->monoff();
4812 l = in_jvms->mon_size();
4813 out_jvms->set_monoff(p);
4814 for (j = 0; j < l; j++)
4815 call->set_req(p++, in_map->in(k+j));
4816
4817 // Copy any scalar object fields.
4818 k = in_jvms->scloff();
4819 l = in_jvms->scl_size();
4820 out_jvms->set_scloff(p);
4821 for (j = 0; j < l; j++)
4822 call->set_req(p++, in_map->in(k+j));
4823
4824 // Finish the new jvms.
4825 out_jvms->set_endoff(p);
4826
4827 assert(out_jvms->endoff() == debug_end, "fill ptr must match");
4828 assert(out_jvms->depth() == in_jvms->depth(), "depth must match");
4829 assert(out_jvms->loc_size() == in_jvms->loc_size(), "size must match");
4830 assert(out_jvms->mon_size() == in_jvms->mon_size(), "size must match");
4831 assert(out_jvms->scl_size() == in_jvms->scl_size(), "size must match");
4832 assert(out_jvms->debug_size() == in_jvms->debug_size(), "size must match");
4833
4834 // Update the two tail pointers in parallel.
4835 out_jvms = out_jvms->caller();
4836 in_jvms = in_jvms->caller();
4837 }
4838
4839 assert(debug_ptr == non_debug_edges, "debug info must fit exactly");
4840
4841 // Test the correctness of JVMState::debug_xxx accessors:
4842 assert(call->jvms()->debug_start() == non_debug_edges, "");
4843 assert(call->jvms()->debug_end() == call->req(), "");
4844 assert(call->jvms()->debug_depth() == call->req() - non_debug_edges, "");
4845 }
|