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;
2701 Local* receiver = x->state()->local_at(0)->as_Local();
2702 assert(receiver != NULL, "must already exist");
2703 obj = receiver->operand();
2704 }
2705 assert(obj->is_valid(), "must be valid");
2706
2707 if (method()->is_synchronized() && GenerateSynchronizationCode) {
2708 LIR_Opr lock = new_register(T_INT);
2709 __ load_stack_address_monitor(0, lock);
2710
2711 CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL, x->check_flag(Instruction::DeoptimizeOnException));
2712 CodeStub* slow_path = new MonitorEnterStub(obj, lock, info);
2713
2714 // receiver is guaranteed non-NULL so don't need CodeEmitInfo
2715 __ lock_object(syncTempOpr(), obj, lock, new_register(T_OBJECT), slow_path, NULL);
2716 }
2717 }
2718
2719 // increment invocation counters if needed
2720 if (!method()->is_accessor()) { // Accessors do not have MDOs, so no counting.
2721 CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL, false);
2722 increment_invocation_counter(info);
2723 }
2724
2725 // all blocks with a successor must end with an unconditional jump
2726 // to the successor even if they are consecutive
2727 __ jump(x->default_sux());
2728 }
2729
2730
2731 void LIRGenerator::do_OsrEntry(OsrEntry* x) {
2732 // construct our frame and model the production of incoming pointer
2733 // to the OSR buffer.
2734 __ osr_entry(LIR_Assembler::osrBufferPointer());
2735 LIR_Opr result = rlock_result(x);
2736 __ move(LIR_Assembler::osrBufferPointer(), result);
2737 }
2738
2739
2740 void LIRGenerator::invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list) {
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 void LIRGenerator::profile_arguments(ProfileCall* x) {
3080 if (MethodData::profile_arguments()) {
3081 int bci = x->bci_of_invoke();
3082 ciMethodData* md = x->method()->method_data_or_null();
3083 ciProfileData* data = md->bci_to_data(bci);
3084 if (data->is_CallTypeData() || data->is_VirtualCallTypeData()) {
3085 ByteSize extra = data->is_CallTypeData() ? CallTypeData::args_data_offset() : VirtualCallTypeData::args_data_offset();
3086 int base_offset = md->byte_offset_of_slot(data, extra);
3087 LIR_Opr mdp = LIR_OprFact::illegalOpr;
3088 ciTypeStackSlotEntries* args = data->is_CallTypeData() ? ((ciCallTypeData*)data)->args() : ((ciVirtualCallTypeData*)data)->args();
3089
3090 Bytecodes::Code bc = x->method()->java_code_at_bci(bci);
3091 int start = 0;
3092 int stop = data->is_CallTypeData() ? ((ciCallTypeData*)data)->number_of_arguments() : ((ciVirtualCallTypeData*)data)->number_of_arguments();
3093 if (x->nb_profiled_args() < stop) {
3094 // if called through method handle invoke, some arguments may have been popped
3095 stop = x->nb_profiled_args();
3096 }
3097 ciSignature* sig = x->callee()->signature();
3098 // method handle call to virtual method
3099 bool has_receiver = x->inlined() && !x->callee()->is_static() && !Bytecodes::has_receiver(bc);
3100 ciSignatureStream sig_stream(sig, has_receiver ? x->callee()->holder() : NULL);
3101 for (int i = 0; i < stop; i++) {
3102 int off = in_bytes(TypeEntriesAtCall::argument_type_offset(i)) - in_bytes(TypeEntriesAtCall::args_data_offset());
3103 ciKlass* exact = profile_arg_type(md, base_offset, off,
3104 args->type(i), x->profiled_arg_at(i+start), mdp,
3105 !x->arg_needs_null_check(i+start), sig_stream.next_klass());
3106 if (exact != NULL) {
3107 md->set_argument_type(bci, i, exact);
3108 }
3109 }
3110 }
3111 }
3112 }
3113
3114 void LIRGenerator::do_ProfileCall(ProfileCall* x) {
3115 // Need recv in a temporary register so it interferes with the other temporaries
3116 LIR_Opr recv = LIR_OprFact::illegalOpr;
3117 LIR_Opr mdo = new_register(T_OBJECT);
3118 // tmp is used to hold the counters on SPARC
3119 LIR_Opr tmp = new_pointer_register();
3120
3121 if (x->nb_profiled_args() > 0) {
3122 profile_arguments(x);
3123 }
3124
3125 if (x->recv() != NULL) {
3126 LIRItem value(x->recv(), this);
3127 value.load_item();
3128 recv = new_register(T_OBJECT);
3129 __ move(value.result(), recv);
3130 }
3131 __ profile_call(x->method(), x->bci_of_invoke(), x->callee(), mdo, recv, tmp, x->known_holder());
3132 }
3133
3134 void LIRGenerator::do_ProfileReturnType(ProfileReturnType* x) {
3135 int bci = x->bci_of_invoke();
3136 ciMethodData* md = x->method()->method_data_or_null();
3137 ciProfileData* data = md->bci_to_data(bci);
3138 assert(data->is_CallTypeData() || data->is_VirtualCallTypeData(), "wrong profile data type");
3139 ciReturnTypeEntry* ret = data->is_CallTypeData() ? ((ciCallTypeData*)data)->ret() : ((ciVirtualCallTypeData*)data)->ret();
3140 LIR_Opr mdp = LIR_OprFact::illegalOpr;
3141 ciKlass* exact = profile_arg_type(md, 0, md->byte_offset_of_slot(data, ret->type_offset()),
3142 ret->type(), x->ret(), mdp,
|
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::profile_parameters(Base* x) {
2647 if (MethodData::profile_parameters()) {
2648 CallingConvention* args = compilation()->frame_map()->incoming_arguments();
2649 ciMethodData* md = scope()->method()->method_data_or_null();
2650 assert(md != NULL, "Sanity");
2651
2652 if (md->parameters_type_data() != NULL) {
2653 ciParametersTypeData* parameters_type_data = md->parameters_type_data();
2654 ciTypeStackSlotEntries* parameters = parameters_type_data->parameters();
2655 LIR_Opr mdp = LIR_OprFact::illegalOpr;
2656 for (int java_index = 0, i = 0, j = 0; j < parameters_type_data->number_of_parameters(); i++) {
2657 LIR_Opr src = args->at(i);
2658 assert(!src->is_illegal(), "check");
2659 BasicType t = src->type();
2660 if (t == T_OBJECT || t == T_ARRAY) {
2661 intptr_t profiled_k = parameters->type(j);
2662 Local* local = x->state()->local_at(java_index)->as_Local();
2663 ciKlass* exact = profile_arg_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)),
2664 in_bytes(ParametersTypeData::type_offset(j)) - in_bytes(ParametersTypeData::type_offset(0)),
2665 profiled_k, local, mdp, false, local->declared_type()->as_klass());
2666 if (exact != NULL) {
2667 md->set_parameter_type(j, exact);
2668 }
2669 j++;
2670 }
2671 java_index += type2size[t];
2672 }
2673 }
2674 }
2675 }
2676
2677 void LIRGenerator::do_Base(Base* x) {
2678 __ std_entry(LIR_OprFact::illegalOpr);
2679 // Emit moves from physical registers / stack slots to virtual registers
2680 CallingConvention* args = compilation()->frame_map()->incoming_arguments();
2681 IRScope* irScope = compilation()->hir()->top_scope();
2682 int java_index = 0;
2683 for (int i = 0; i < args->length(); i++) {
2684 LIR_Opr src = args->at(i);
2685 assert(!src->is_illegal(), "check");
2686 BasicType t = src->type();
2687
2688 // Types which are smaller than int are passed as int, so
2689 // correct the type which passed.
2690 switch (t) {
2691 case T_BYTE:
2692 case T_BOOLEAN:
2693 case T_SHORT:
2694 case T_CHAR:
2695 t = T_INT;
2696 break;
2732 Local* receiver = x->state()->local_at(0)->as_Local();
2733 assert(receiver != NULL, "must already exist");
2734 obj = receiver->operand();
2735 }
2736 assert(obj->is_valid(), "must be valid");
2737
2738 if (method()->is_synchronized() && GenerateSynchronizationCode) {
2739 LIR_Opr lock = new_register(T_INT);
2740 __ load_stack_address_monitor(0, lock);
2741
2742 CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL, x->check_flag(Instruction::DeoptimizeOnException));
2743 CodeStub* slow_path = new MonitorEnterStub(obj, lock, info);
2744
2745 // receiver is guaranteed non-NULL so don't need CodeEmitInfo
2746 __ lock_object(syncTempOpr(), obj, lock, new_register(T_OBJECT), slow_path, NULL);
2747 }
2748 }
2749
2750 // increment invocation counters if needed
2751 if (!method()->is_accessor()) { // Accessors do not have MDOs, so no counting.
2752 profile_parameters(x);
2753 CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL, false);
2754 increment_invocation_counter(info);
2755 }
2756
2757 // all blocks with a successor must end with an unconditional jump
2758 // to the successor even if they are consecutive
2759 __ jump(x->default_sux());
2760 }
2761
2762
2763 void LIRGenerator::do_OsrEntry(OsrEntry* x) {
2764 // construct our frame and model the production of incoming pointer
2765 // to the OSR buffer.
2766 __ osr_entry(LIR_Assembler::osrBufferPointer());
2767 LIR_Opr result = rlock_result(x);
2768 __ move(LIR_Assembler::osrBufferPointer(), result);
2769 }
2770
2771
2772 void LIRGenerator::invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list) {
3096
3097 case vmIntrinsics::_Reference_get:
3098 do_Reference_get(x);
3099 break;
3100
3101 case vmIntrinsics::_updateCRC32:
3102 case vmIntrinsics::_updateBytesCRC32:
3103 case vmIntrinsics::_updateByteBufferCRC32:
3104 do_update_CRC32(x);
3105 break;
3106
3107 default: ShouldNotReachHere(); break;
3108 }
3109 }
3110
3111 void LIRGenerator::profile_arguments(ProfileCall* x) {
3112 if (MethodData::profile_arguments()) {
3113 int bci = x->bci_of_invoke();
3114 ciMethodData* md = x->method()->method_data_or_null();
3115 ciProfileData* data = md->bci_to_data(bci);
3116 if ((data->is_CallTypeData() && data->as_CallTypeData()->has_arguments()) ||
3117 (data->is_VirtualCallTypeData() && data->as_VirtualCallTypeData()->has_arguments())) {
3118 ByteSize extra = data->is_CallTypeData() ? CallTypeData::args_data_offset() : VirtualCallTypeData::args_data_offset();
3119 int base_offset = md->byte_offset_of_slot(data, extra);
3120 LIR_Opr mdp = LIR_OprFact::illegalOpr;
3121 ciTypeStackSlotEntries* args = data->is_CallTypeData() ? ((ciCallTypeData*)data)->args() : ((ciVirtualCallTypeData*)data)->args();
3122
3123 Bytecodes::Code bc = x->method()->java_code_at_bci(bci);
3124 int start = 0;
3125 int stop = data->is_CallTypeData() ? ((ciCallTypeData*)data)->number_of_arguments() : ((ciVirtualCallTypeData*)data)->number_of_arguments();
3126 if (x->nb_profiled_args() < stop) {
3127 // if called through method handle invoke, some arguments may have been popped
3128 stop = x->nb_profiled_args();
3129 }
3130 ciSignature* sig = x->callee()->signature();
3131 // method handle call to virtual method
3132 bool has_receiver = x->inlined() && !x->callee()->is_static() && !Bytecodes::has_receiver(bc);
3133 ciSignatureStream sig_stream(sig, has_receiver ? x->callee()->holder() : NULL);
3134 for (int i = 0; i < stop; i++) {
3135 int off = in_bytes(TypeEntriesAtCall::argument_type_offset(i)) - in_bytes(TypeEntriesAtCall::args_data_offset());
3136 ciKlass* exact = profile_arg_type(md, base_offset, off,
3137 args->type(i), x->profiled_arg_at(i+start), mdp,
3138 !x->arg_needs_null_check(i+start), sig_stream.next_klass());
3139 if (exact != NULL) {
3140 md->set_argument_type(bci, i, exact);
3141 }
3142 }
3143 } else {
3144 #ifdef ASSERT
3145 Bytecodes::Code code = x->method()->raw_code_at_bci(x->bci_of_invoke());
3146 int n = x->nb_profiled_args();
3147 assert(MethodData::profile_parameters() && x->inlined() &&
3148 ((code == Bytecodes::_invokedynamic && n <= 1) || (code == Bytecodes::_invokehandle && n <= 2)),
3149 "only at JSR292 bytecodes");
3150 #endif
3151 }
3152 }
3153 }
3154
3155 void LIRGenerator::profile_parameters_at_call(ProfileCall* x) {
3156 if (MethodData::profile_parameters() && x->inlined()) {
3157 ciMethodData* md = x->callee()->method_data_or_null();
3158 if (md != NULL) {
3159 ciParametersTypeData* parameters_type_data = md->parameters_type_data();
3160 if (parameters_type_data != NULL) {
3161 ciTypeStackSlotEntries* parameters = parameters_type_data->parameters();
3162 LIR_Opr mdp = LIR_OprFact::illegalOpr;
3163 bool has_receiver = !x->callee()->is_static();
3164 ciSignature* sig = x->callee()->signature();
3165 ciSignatureStream sig_stream(sig, has_receiver ? x->callee()->holder() : NULL);
3166 int i = 0; // to iterate on the Instructions
3167 Value arg = x->recv();
3168 bool not_null = false;
3169 int bci = x->bci_of_invoke();
3170 Bytecodes::Code bc = x->method()->java_code_at_bci(bci);
3171 // method handle call to virtual method has receiver in the args list
3172 if (arg == NULL || !Bytecodes::has_receiver(bc)) {
3173 i = 1;
3174 arg = x->profiled_arg_at(0);
3175 not_null = !x->arg_needs_null_check(0);
3176 }
3177 int k = 0; // to iterate on the profile data
3178 for (;;) {
3179 intptr_t profiled_k = parameters->type(k);
3180 ciKlass* exact = profile_arg_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)),
3181 in_bytes(ParametersTypeData::type_offset(k)) - in_bytes(ParametersTypeData::type_offset(0)),
3182 profiled_k, arg, mdp, not_null, sig_stream.next_klass());
3183 if (exact != NULL) {
3184 md->set_parameter_type(k, exact);
3185 }
3186 k++;
3187 if (k >= parameters_type_data->number_of_parameters()) {
3188 #ifdef ASSERT
3189 int extra = 0;
3190 if (MethodData::profile_arguments() && x->nb_profiled_args() >= TypeProfileParmsLimit &&
3191 x->recv() != NULL && Bytecodes::has_receiver(bc)) {
3192 extra += 1;
3193 }
3194 assert(i == x->nb_profiled_args() - extra || (TypeProfileParmsLimit != -1 && TypeProfileArgsLimit > TypeProfileParmsLimit), "unused parameters?");
3195 #endif
3196 break;
3197 }
3198 arg = x->profiled_arg_at(i);
3199 not_null = !x->arg_needs_null_check(i);
3200 i++;
3201 }
3202 }
3203 }
3204 }
3205 }
3206
3207 void LIRGenerator::do_ProfileCall(ProfileCall* x) {
3208 // Need recv in a temporary register so it interferes with the other temporaries
3209 LIR_Opr recv = LIR_OprFact::illegalOpr;
3210 LIR_Opr mdo = new_register(T_OBJECT);
3211 // tmp is used to hold the counters on SPARC
3212 LIR_Opr tmp = new_pointer_register();
3213
3214 if (x->nb_profiled_args() > 0) {
3215 profile_arguments(x);
3216 }
3217 if (x->recv() != NULL || x->nb_profiled_args() > 0) {
3218 profile_parameters_at_call(x);
3219 }
3220
3221 if (x->recv() != NULL) {
3222 LIRItem value(x->recv(), this);
3223 value.load_item();
3224 recv = new_register(T_OBJECT);
3225 __ move(value.result(), recv);
3226 }
3227 __ profile_call(x->method(), x->bci_of_invoke(), x->callee(), mdo, recv, tmp, x->known_holder());
3228 }
3229
3230 void LIRGenerator::do_ProfileReturnType(ProfileReturnType* x) {
3231 int bci = x->bci_of_invoke();
3232 ciMethodData* md = x->method()->method_data_or_null();
3233 ciProfileData* data = md->bci_to_data(bci);
3234 assert(data->is_CallTypeData() || data->is_VirtualCallTypeData(), "wrong profile data type");
3235 ciReturnTypeEntry* ret = data->is_CallTypeData() ? ((ciCallTypeData*)data)->ret() : ((ciVirtualCallTypeData*)data)->ret();
3236 LIR_Opr mdp = LIR_OprFact::illegalOpr;
3237 ciKlass* exact = profile_arg_type(md, 0, md->byte_offset_of_slot(data, ret->type_offset()),
3238 ret->type(), x->ret(), mdp,
|