477 __ branch(lir_cond_aboveEqual, T_INT, stub); // forward branch |
477 __ branch(lir_cond_aboveEqual, T_INT, stub); // forward branch |
478 } |
478 } |
479 __ move(index, result); |
479 __ move(index, result); |
480 } |
480 } |
481 |
481 |
482 |
|
483 // increment a counter returning the incremented value |
|
484 LIR_Opr LIRGenerator::increment_and_return_counter(LIR_Opr base, int offset, int increment) { |
|
485 LIR_Address* counter = new LIR_Address(base, offset, T_INT); |
|
486 LIR_Opr result = new_register(T_INT); |
|
487 __ load(counter, result); |
|
488 __ add(result, LIR_OprFact::intConst(increment), result); |
|
489 __ store(result, counter); |
|
490 return result; |
|
491 } |
|
492 |
482 |
493 |
483 |
494 void LIRGenerator::arithmetic_op(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp_op, CodeEmitInfo* info) { |
484 void LIRGenerator::arithmetic_op(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp_op, CodeEmitInfo* info) { |
495 LIR_Opr result_op = result; |
485 LIR_Opr result_op = result; |
496 LIR_Opr left_op = left; |
486 LIR_Opr left_op = left; |
834 ciProfileData* data = md->bci_to_data(if_instr->profiled_bci()); |
823 ciProfileData* data = md->bci_to_data(if_instr->profiled_bci()); |
835 assert(data != NULL, "must have profiling data"); |
824 assert(data != NULL, "must have profiling data"); |
836 assert(data->is_BranchData(), "need BranchData for two-way branches"); |
825 assert(data->is_BranchData(), "need BranchData for two-way branches"); |
837 int taken_count_offset = md->byte_offset_of_slot(data, BranchData::taken_offset()); |
826 int taken_count_offset = md->byte_offset_of_slot(data, BranchData::taken_offset()); |
838 int not_taken_count_offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset()); |
827 int not_taken_count_offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset()); |
|
828 if (if_instr->is_swapped()) { |
|
829 int t = taken_count_offset; |
|
830 taken_count_offset = not_taken_count_offset; |
|
831 not_taken_count_offset = t; |
|
832 } |
|
833 |
839 LIR_Opr md_reg = new_register(T_OBJECT); |
834 LIR_Opr md_reg = new_register(T_OBJECT); |
840 __ move(LIR_OprFact::oopConst(md->constant_encoding()), md_reg); |
835 __ oop2reg(md->constant_encoding(), md_reg); |
841 LIR_Opr data_offset_reg = new_register(T_INT); |
836 |
|
837 LIR_Opr data_offset_reg = new_pointer_register(); |
842 __ cmove(lir_cond(cond), |
838 __ cmove(lir_cond(cond), |
843 LIR_OprFact::intConst(taken_count_offset), |
839 LIR_OprFact::intptrConst(taken_count_offset), |
844 LIR_OprFact::intConst(not_taken_count_offset), |
840 LIR_OprFact::intptrConst(not_taken_count_offset), |
845 data_offset_reg); |
841 data_offset_reg); |
846 LIR_Opr data_reg = new_register(T_INT); |
842 |
847 LIR_Address* data_addr = new LIR_Address(md_reg, data_offset_reg, T_INT); |
843 // MDO cells are intptr_t, so the data_reg width is arch-dependent. |
|
844 LIR_Opr data_reg = new_pointer_register(); |
|
845 LIR_Address* data_addr = new LIR_Address(md_reg, data_offset_reg, data_reg->type()); |
848 __ move(LIR_OprFact::address(data_addr), data_reg); |
846 __ move(LIR_OprFact::address(data_addr), data_reg); |
|
847 // Use leal instead of add to avoid destroying condition codes on x86 |
849 LIR_Address* fake_incr_value = new LIR_Address(data_reg, DataLayout::counter_increment, T_INT); |
848 LIR_Address* fake_incr_value = new LIR_Address(data_reg, DataLayout::counter_increment, T_INT); |
850 // Use leal instead of add to avoid destroying condition codes on x86 |
|
851 __ leal(LIR_OprFact::address(fake_incr_value), data_reg); |
849 __ leal(LIR_OprFact::address(fake_incr_value), data_reg); |
852 __ move(data_reg, LIR_OprFact::address(data_addr)); |
850 __ move(data_reg, LIR_OprFact::address(data_addr)); |
853 } |
851 } |
854 } |
852 } |
855 |
|
856 |
853 |
857 // Phi technique: |
854 // Phi technique: |
858 // This is about passing live values from one basic block to the other. |
855 // This is about passing live values from one basic block to the other. |
859 // In code generated with Java it is rather rare that more than one |
856 // In code generated with Java it is rather rare that more than one |
860 // value is on the stack from one basic block to the other. |
857 // value is on the stack from one basic block to the other. |
2189 |
2184 |
2190 if (x->is_safepoint()) { |
2185 if (x->is_safepoint()) { |
2191 ValueStack* state = x->state_before() ? x->state_before() : x->state(); |
2186 ValueStack* state = x->state_before() ? x->state_before() : x->state(); |
2192 |
2187 |
2193 // increment backedge counter if needed |
2188 // increment backedge counter if needed |
2194 increment_backedge_counter(state_for(x, state)); |
2189 CodeEmitInfo* info = state_for(x, state); |
2195 |
2190 increment_backedge_counter(info, info->bci()); |
2196 CodeEmitInfo* safepoint_info = state_for(x, state); |
2191 CodeEmitInfo* safepoint_info = state_for(x, state); |
2197 __ safepoint(safepoint_poll_register(), safepoint_info); |
2192 __ safepoint(safepoint_poll_register(), safepoint_info); |
|
2193 } |
|
2194 |
|
2195 // Gotos can be folded Ifs, handle this case. |
|
2196 if (x->should_profile()) { |
|
2197 ciMethod* method = x->profiled_method(); |
|
2198 assert(method != NULL, "method should be set if branch is profiled"); |
|
2199 ciMethodData* md = method->method_data(); |
|
2200 if (md == NULL) { |
|
2201 bailout("out of memory building methodDataOop"); |
|
2202 return; |
|
2203 } |
|
2204 ciProfileData* data = md->bci_to_data(x->profiled_bci()); |
|
2205 assert(data != NULL, "must have profiling data"); |
|
2206 int offset; |
|
2207 if (x->direction() == Goto::taken) { |
|
2208 assert(data->is_BranchData(), "need BranchData for two-way branches"); |
|
2209 offset = md->byte_offset_of_slot(data, BranchData::taken_offset()); |
|
2210 } else if (x->direction() == Goto::not_taken) { |
|
2211 assert(data->is_BranchData(), "need BranchData for two-way branches"); |
|
2212 offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset()); |
|
2213 } else { |
|
2214 assert(data->is_JumpData(), "need JumpData for branches"); |
|
2215 offset = md->byte_offset_of_slot(data, JumpData::taken_offset()); |
|
2216 } |
|
2217 LIR_Opr md_reg = new_register(T_OBJECT); |
|
2218 __ oop2reg(md->constant_encoding(), md_reg); |
|
2219 |
|
2220 increment_counter(new LIR_Address(md_reg, offset, |
|
2221 NOT_LP64(T_INT) LP64_ONLY(T_LONG)), DataLayout::counter_increment); |
2198 } |
2222 } |
2199 |
2223 |
2200 // emit phi-instruction move after safepoint since this simplifies |
2224 // emit phi-instruction move after safepoint since this simplifies |
2201 // describing the state as the safepoint. |
2225 // describing the state as the safepoint. |
2202 move_to_phi(x->state()); |
2226 move_to_phi(x->state()); |
2611 |
2638 |
2612 default: ShouldNotReachHere(); break; |
2639 default: ShouldNotReachHere(); break; |
2613 } |
2640 } |
2614 } |
2641 } |
2615 |
2642 |
2616 |
|
2617 void LIRGenerator::do_ProfileCall(ProfileCall* x) { |
2643 void LIRGenerator::do_ProfileCall(ProfileCall* x) { |
2618 // Need recv in a temporary register so it interferes with the other temporaries |
2644 // Need recv in a temporary register so it interferes with the other temporaries |
2619 LIR_Opr recv = LIR_OprFact::illegalOpr; |
2645 LIR_Opr recv = LIR_OprFact::illegalOpr; |
2620 LIR_Opr mdo = new_register(T_OBJECT); |
2646 LIR_Opr mdo = new_register(T_OBJECT); |
2621 LIR_Opr tmp = new_register(T_INT); |
2647 // tmp is used to hold the counters on SPARC |
|
2648 LIR_Opr tmp = new_pointer_register(); |
2622 if (x->recv() != NULL) { |
2649 if (x->recv() != NULL) { |
2623 LIRItem value(x->recv(), this); |
2650 LIRItem value(x->recv(), this); |
2624 value.load_item(); |
2651 value.load_item(); |
2625 recv = new_register(T_OBJECT); |
2652 recv = new_register(T_OBJECT); |
2626 __ move(value.result(), recv); |
2653 __ move(value.result(), recv); |
2627 } |
2654 } |
2628 __ profile_call(x->method(), x->bci_of_invoke(), mdo, recv, tmp, x->known_holder()); |
2655 __ profile_call(x->method(), x->bci_of_invoke(), mdo, recv, tmp, x->known_holder()); |
2629 } |
2656 } |
2630 |
2657 |
2631 |
2658 void LIRGenerator::do_ProfileInvoke(ProfileInvoke* x) { |
2632 void LIRGenerator::do_ProfileCounter(ProfileCounter* x) { |
2659 // We can safely ignore accessors here, since c2 will inline them anyway, |
2633 LIRItem mdo(x->mdo(), this); |
2660 // accessors are also always mature. |
2634 mdo.load_item(); |
2661 if (!x->inlinee()->is_accessor()) { |
2635 |
2662 CodeEmitInfo* info = state_for(x, x->state(), true); |
2636 increment_counter(new LIR_Address(mdo.result(), x->offset(), T_INT), x->increment()); |
2663 // Increment invocation counter, don't notify the runtime, because we don't inline loops, |
2637 } |
2664 increment_event_counter_impl(info, x->inlinee(), 0, InvocationEntryBci, false, false); |
2638 |
2665 } |
|
2666 } |
|
2667 |
|
2668 void LIRGenerator::increment_event_counter(CodeEmitInfo* info, int bci, bool backedge) { |
|
2669 int freq_log; |
|
2670 int level = compilation()->env()->comp_level(); |
|
2671 if (level == CompLevel_limited_profile) { |
|
2672 freq_log = (backedge ? Tier2BackedgeNotifyFreqLog : Tier2InvokeNotifyFreqLog); |
|
2673 } else if (level == CompLevel_full_profile) { |
|
2674 freq_log = (backedge ? Tier3BackedgeNotifyFreqLog : Tier3InvokeNotifyFreqLog); |
|
2675 } else { |
|
2676 ShouldNotReachHere(); |
|
2677 } |
|
2678 // Increment the appropriate invocation/backedge counter and notify the runtime. |
|
2679 increment_event_counter_impl(info, info->scope()->method(), (1 << freq_log) - 1, bci, backedge, true); |
|
2680 } |
|
2681 |
|
2682 void LIRGenerator::increment_event_counter_impl(CodeEmitInfo* info, |
|
2683 ciMethod *method, int frequency, |
|
2684 int bci, bool backedge, bool notify) { |
|
2685 assert(frequency == 0 || is_power_of_2(frequency + 1), "Frequency must be x^2 - 1 or 0"); |
|
2686 int level = _compilation->env()->comp_level(); |
|
2687 assert(level > CompLevel_simple, "Shouldn't be here"); |
|
2688 |
|
2689 int offset = -1; |
|
2690 LIR_Opr counter_holder = new_register(T_OBJECT); |
|
2691 LIR_Opr meth; |
|
2692 if (level == CompLevel_limited_profile) { |
|
2693 offset = in_bytes(backedge ? methodOopDesc::backedge_counter_offset() : |
|
2694 methodOopDesc::invocation_counter_offset()); |
|
2695 __ oop2reg(method->constant_encoding(), counter_holder); |
|
2696 meth = counter_holder; |
|
2697 } else if (level == CompLevel_full_profile) { |
|
2698 offset = in_bytes(backedge ? methodDataOopDesc::backedge_counter_offset() : |
|
2699 methodDataOopDesc::invocation_counter_offset()); |
|
2700 __ oop2reg(method->method_data()->constant_encoding(), counter_holder); |
|
2701 meth = new_register(T_OBJECT); |
|
2702 __ oop2reg(method->constant_encoding(), meth); |
|
2703 } else { |
|
2704 ShouldNotReachHere(); |
|
2705 } |
|
2706 LIR_Address* counter = new LIR_Address(counter_holder, offset, T_INT); |
|
2707 LIR_Opr result = new_register(T_INT); |
|
2708 __ load(counter, result); |
|
2709 __ add(result, LIR_OprFact::intConst(InvocationCounter::count_increment), result); |
|
2710 __ store(result, counter); |
|
2711 if (notify) { |
|
2712 LIR_Opr mask = load_immediate(frequency << InvocationCounter::count_shift, T_INT); |
|
2713 __ logical_and(result, mask, result); |
|
2714 __ cmp(lir_cond_equal, result, LIR_OprFact::intConst(0)); |
|
2715 // The bci for info can point to cmp for if's we want the if bci |
|
2716 CodeStub* overflow = new CounterOverflowStub(info, bci, meth); |
|
2717 __ branch(lir_cond_equal, T_INT, overflow); |
|
2718 __ branch_destination(overflow->continuation()); |
|
2719 } |
|
2720 } |
2639 |
2721 |
2640 LIR_Opr LIRGenerator::call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info) { |
2722 LIR_Opr LIRGenerator::call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info) { |
2641 LIRItemList args(1); |
2723 LIRItemList args(1); |
2642 LIRItem value(arg1, this); |
2724 LIRItem value(arg1, this); |
2643 args.append(&value); |
2725 args.append(&value); |
2746 __ move(phys_reg, result); |
2828 __ move(phys_reg, result); |
2747 } |
2829 } |
2748 return result; |
2830 return result; |
2749 } |
2831 } |
2750 |
2832 |
2751 |
|
2752 |
|
2753 void LIRGenerator::increment_invocation_counter(CodeEmitInfo* info, bool backedge) { |
|
2754 #ifdef TIERED |
|
2755 if (_compilation->env()->comp_level() == CompLevel_fast_compile && |
|
2756 (method()->code_size() >= Tier1BytecodeLimit || backedge)) { |
|
2757 int limit = InvocationCounter::Tier1InvocationLimit; |
|
2758 int offset = in_bytes(methodOopDesc::invocation_counter_offset() + |
|
2759 InvocationCounter::counter_offset()); |
|
2760 if (backedge) { |
|
2761 limit = InvocationCounter::Tier1BackEdgeLimit; |
|
2762 offset = in_bytes(methodOopDesc::backedge_counter_offset() + |
|
2763 InvocationCounter::counter_offset()); |
|
2764 } |
|
2765 |
|
2766 LIR_Opr meth = new_register(T_OBJECT); |
|
2767 __ oop2reg(method()->constant_encoding(), meth); |
|
2768 LIR_Opr result = increment_and_return_counter(meth, offset, InvocationCounter::count_increment); |
|
2769 __ cmp(lir_cond_aboveEqual, result, LIR_OprFact::intConst(limit)); |
|
2770 CodeStub* overflow = new CounterOverflowStub(info, info->bci()); |
|
2771 __ branch(lir_cond_aboveEqual, T_INT, overflow); |
|
2772 __ branch_destination(overflow->continuation()); |
|
2773 } |
|
2774 #endif |
|
2775 } |
|