2554 offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset());
2555 } else {
2556 assert(data->is_JumpData(), "need JumpData for branches");
2557 offset = md->byte_offset_of_slot(data, JumpData::taken_offset());
2558 }
2559 LIR_Opr md_reg = new_register(T_METADATA);
2560 __ metadata2reg(md->constant_encoding(), md_reg);
2561
2562 increment_counter(new LIR_Address(md_reg, offset,
2563 NOT_LP64(T_INT) LP64_ONLY(T_LONG)), DataLayout::counter_increment);
2564 }
2565
2566 // emit phi-instruction move after safepoint since this simplifies
2567 // describing the state as the safepoint.
2568 move_to_phi(x->state());
2569
2570 __ jump(x->default_sux());
2571 }
2572
2573
2574 void LIRGenerator::do_Base(Base* x) {
2575 __ std_entry(LIR_OprFact::illegalOpr);
2576 // Emit moves from physical registers / stack slots to virtual registers
2577 CallingConvention* args = compilation()->frame_map()->incoming_arguments();
2578 IRScope* irScope = compilation()->hir()->top_scope();
2579 int java_index = 0;
2580 for (int i = 0; i < args->length(); i++) {
2581 LIR_Opr src = args->at(i);
2582 assert(!src->is_illegal(), "check");
2583 BasicType t = src->type();
2584
2585 // Types which are smaller than int are passed as int, so
2586 // correct the type which passed.
2587 switch (t) {
2588 case T_BYTE:
2589 case T_BOOLEAN:
2590 case T_SHORT:
2591 case T_CHAR:
2592 t = T_INT;
2593 break;
2987 if (os::is_MP()) __ membar_release();
2988 break;
2989 case vmIntrinsics::_fullFence :
2990 if (os::is_MP()) __ membar();
2991 break;
2992
2993 case vmIntrinsics::_Reference_get:
2994 do_Reference_get(x);
2995 break;
2996
2997 case vmIntrinsics::_updateCRC32:
2998 case vmIntrinsics::_updateBytesCRC32:
2999 case vmIntrinsics::_updateByteBufferCRC32:
3000 do_update_CRC32(x);
3001 break;
3002
3003 default: ShouldNotReachHere(); break;
3004 }
3005 }
3006
3007 void LIRGenerator::do_ProfileCall(ProfileCall* x) {
3008 // Need recv in a temporary register so it interferes with the other temporaries
3009 LIR_Opr recv = LIR_OprFact::illegalOpr;
3010 LIR_Opr mdo = new_register(T_OBJECT);
3011 // tmp is used to hold the counters on SPARC
3012 LIR_Opr tmp = new_pointer_register();
3013 if (x->recv() != NULL) {
3014 LIRItem value(x->recv(), this);
3015 value.load_item();
3016 recv = new_register(T_OBJECT);
3017 __ move(value.result(), recv);
3018 }
3019 __ profile_call(x->method(), x->bci_of_invoke(), x->callee(), mdo, recv, tmp, x->known_holder());
3020 }
3021
3022 void LIRGenerator::do_ProfileInvoke(ProfileInvoke* x) {
3023 // We can safely ignore accessors here, since c2 will inline them anyway,
3024 // accessors are also always mature.
3025 if (!x->inlinee()->is_accessor()) {
3026 CodeEmitInfo* info = state_for(x, x->state(), true);
3027 // Notify the runtime very infrequently only to take care of counter overflows
3028 increment_event_counter_impl(info, x->inlinee(), (1 << Tier23InlineeNotifyFreqLog) - 1, InvocationEntryBci, false, true);
3029 }
3030 }
3031
3032 void LIRGenerator::increment_event_counter(CodeEmitInfo* info, int bci, bool backedge) {
|
2554 offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset());
2555 } else {
2556 assert(data->is_JumpData(), "need JumpData for branches");
2557 offset = md->byte_offset_of_slot(data, JumpData::taken_offset());
2558 }
2559 LIR_Opr md_reg = new_register(T_METADATA);
2560 __ metadata2reg(md->constant_encoding(), md_reg);
2561
2562 increment_counter(new LIR_Address(md_reg, offset,
2563 NOT_LP64(T_INT) LP64_ONLY(T_LONG)), DataLayout::counter_increment);
2564 }
2565
2566 // emit phi-instruction move after safepoint since this simplifies
2567 // describing the state as the safepoint.
2568 move_to_phi(x->state());
2569
2570 __ jump(x->default_sux());
2571 }
2572
2573
2574 ciKlass* LIRGenerator::profile_arg_type(ciMethodData* md, int md_base_offset, int md_offset, intptr_t profiled_k, Value arg, LIR_Opr& mdp, bool not_null, ciKlass* signature_k) {
2575 ciKlass* result = NULL;
2576 bool do_null = !not_null && !TypeEntries::was_null_seen(profiled_k);
2577 bool do_update = !TypeEntries::is_type_unknown(profiled_k);
2578 // known not to be null or null bit already set and already set to
2579 // unknown: nothing we can do to improve profiling
2580 if (!do_null && !do_update) {
2581 return result;
2582 }
2583
2584 ciKlass* exact_klass = NULL;
2585 Compilation* comp = Compilation::current();
2586 if (do_update) {
2587 // try to find exact type, using CHA if possible, so that loading
2588 // the klass from the object can be avoided
2589 ciType* type = arg->exact_type();
2590 if (type == NULL) {
2591 type = arg->declared_type();
2592 type = comp->cha_exact_type(type);
2593 }
2594 assert(type == NULL || type->is_klass(), "type should be class");
2595 exact_klass = (type != NULL && type->is_loaded()) ? (ciKlass*)type : NULL;
2596
2597 do_update = exact_klass == NULL || ciTypeEntries::valid_ciklass(profiled_k) != exact_klass;
2598 }
2599
2600 if (!do_null && !do_update) {
2601 return result;
2602 }
2603
2604 ciKlass* exact_signature_k = NULL;
2605 if (do_update) {
2606 // Is the type from the signature exact (the only one possible)?
2607 exact_signature_k = signature_k->exact_klass();
2608 if (exact_signature_k == NULL) {
2609 exact_signature_k = comp->cha_exact_type(signature_k);
2610 } else {
2611 result = exact_signature_k;
2612 do_update = false;
2613 // Known statically. No need to emit any code: prevent
2614 // LIR_Assembler::emit_profile_type() from emitting useless code
2615 profiled_k = TypeEntries::with_status((intptr_t)result, profiled_k);
2616 }
2617 if (exact_signature_k != NULL && exact_klass != exact_signature_k) {
2618 assert(exact_klass == NULL, "arg and signature disagree?");
2619 // sometimes the type of the signature is better than the best type
2620 // the compiler has
2621 exact_klass = exact_signature_k;
2622 do_update = exact_klass == NULL || ciTypeEntries::valid_ciklass(profiled_k) != exact_klass;
2623 }
2624 }
2625
2626 if (!do_null && !do_update) {
2627 return result;
2628 }
2629
2630 if (mdp == LIR_OprFact::illegalOpr) {
2631 mdp = new_register(T_METADATA);
2632 __ metadata2reg(md->constant_encoding(), mdp);
2633 if (md_base_offset != 0) {
2634 LIR_Address* base_type_address = new LIR_Address(mdp, md_base_offset, T_ADDRESS);
2635 mdp = new_pointer_register();
2636 __ leal(LIR_OprFact::address(base_type_address), mdp);
2637 }
2638 }
2639 LIRItem value(arg, this);
2640 value.load_item();
2641 __ profile_type(new LIR_Address(mdp, md_offset, T_METADATA),
2642 value.result(), exact_klass, profiled_k, new_pointer_register(), not_null, exact_signature_k != NULL);
2643 return result;
2644 }
2645
2646 void LIRGenerator::do_Base(Base* x) {
2647 __ std_entry(LIR_OprFact::illegalOpr);
2648 // Emit moves from physical registers / stack slots to virtual registers
2649 CallingConvention* args = compilation()->frame_map()->incoming_arguments();
2650 IRScope* irScope = compilation()->hir()->top_scope();
2651 int java_index = 0;
2652 for (int i = 0; i < args->length(); i++) {
2653 LIR_Opr src = args->at(i);
2654 assert(!src->is_illegal(), "check");
2655 BasicType t = src->type();
2656
2657 // Types which are smaller than int are passed as int, so
2658 // correct the type which passed.
2659 switch (t) {
2660 case T_BYTE:
2661 case T_BOOLEAN:
2662 case T_SHORT:
2663 case T_CHAR:
2664 t = T_INT;
2665 break;
3059 if (os::is_MP()) __ membar_release();
3060 break;
3061 case vmIntrinsics::_fullFence :
3062 if (os::is_MP()) __ membar();
3063 break;
3064
3065 case vmIntrinsics::_Reference_get:
3066 do_Reference_get(x);
3067 break;
3068
3069 case vmIntrinsics::_updateCRC32:
3070 case vmIntrinsics::_updateBytesCRC32:
3071 case vmIntrinsics::_updateByteBufferCRC32:
3072 do_update_CRC32(x);
3073 break;
3074
3075 default: ShouldNotReachHere(); break;
3076 }
3077 }
3078
3079 static ciKlass* sig_next_klass(ciSignature* sig, ciKlass*& first_sig_k, int& j) {
3080 ciKlass* sig_k;
3081 if (first_sig_k != NULL) {
3082 sig_k = first_sig_k;
3083 first_sig_k = NULL;
3084 } else {
3085 while (!sig->type_at(j)->is_klass()) j++;
3086 sig_k = sig->type_at(j)->as_klass();
3087 j++;
3088 }
3089 return sig_k;
3090 }
3091
3092 void LIRGenerator::profile_arguments(ProfileCall* x) {
3093 if (MethodData::profile_arguments()) {
3094 int bci = x->bci_of_invoke();
3095 ciMethodData* md = x->method()->method_data_or_null();
3096 ciProfileData* data = md->bci_to_data(bci);
3097 if (data->is_CallTypeData() || data->is_VirtualCallTypeData()) {
3098 ByteSize extra = data->is_CallTypeData() ? CallTypeData::args_data_offset() : VirtualCallTypeData::args_data_offset();
3099 int base_offset = md->byte_offset_of_slot(data, extra);
3100 LIR_Opr mdp = LIR_OprFact::illegalOpr;
3101 ciTypeStackSlotEntries* args = data->is_CallTypeData() ? ((ciCallTypeData*)data)->args() : ((ciVirtualCallTypeData*)data)->args();
3102
3103 Bytecodes::Code bc = x->method()->java_code_at_bci(bci);
3104 int start = 0;
3105 int stop = args->number_of_arguments();
3106 if (x->nb_profiled_args() < stop) {
3107 // if called through method handle invoke, some arguments may have been popped
3108 stop = x->nb_profiled_args();
3109 }
3110 ciSignature* sig = x->callee()->signature();
3111 // method handle call to virtual method
3112 bool has_receiver = x->inlined() && !x->callee()->is_static() && !Bytecodes::has_receiver(bc);
3113 ciKlass* first_sig_k = has_receiver ? x->callee()->holder() : NULL;
3114 for (int i = 0, j = 0; i < stop; i++) {
3115 int off = in_bytes(TypeStackSlotEntries::type_offset(i)) - in_bytes(TypeStackSlotEntries::args_data_offset());
3116 ciKlass* exact = profile_arg_type(md, base_offset, off,
3117 args->type(i), x->profiled_arg_at(i+start), mdp,
3118 !x->arg_needs_null_check(i+start), sig_next_klass(sig, first_sig_k, j));
3119 if (exact != NULL) {
3120 md->set_argument_type(bci, i, exact);
3121 }
3122 }
3123 }
3124 }
3125 }
3126
3127 void LIRGenerator::do_ProfileCall(ProfileCall* x) {
3128 // Need recv in a temporary register so it interferes with the other temporaries
3129 LIR_Opr recv = LIR_OprFact::illegalOpr;
3130 LIR_Opr mdo = new_register(T_OBJECT);
3131 // tmp is used to hold the counters on SPARC
3132 LIR_Opr tmp = new_pointer_register();
3133
3134 if (x->nb_profiled_args() > 0) {
3135 profile_arguments(x);
3136 }
3137
3138 if (x->recv() != NULL) {
3139 LIRItem value(x->recv(), this);
3140 value.load_item();
3141 recv = new_register(T_OBJECT);
3142 __ move(value.result(), recv);
3143 }
3144 __ profile_call(x->method(), x->bci_of_invoke(), x->callee(), mdo, recv, tmp, x->known_holder());
3145 }
3146
3147 void LIRGenerator::do_ProfileInvoke(ProfileInvoke* x) {
3148 // We can safely ignore accessors here, since c2 will inline them anyway,
3149 // accessors are also always mature.
3150 if (!x->inlinee()->is_accessor()) {
3151 CodeEmitInfo* info = state_for(x, x->state(), true);
3152 // Notify the runtime very infrequently only to take care of counter overflows
3153 increment_event_counter_impl(info, x->inlinee(), (1 << Tier23InlineeNotifyFreqLog) - 1, InvocationEntryBci, false, true);
3154 }
3155 }
3156
3157 void LIRGenerator::increment_event_counter(CodeEmitInfo* info, int bci, bool backedge) {
|