2572 move_to_phi(x->state()); |
2572 move_to_phi(x->state()); |
2573 |
2573 |
2574 __ jump(x->default_sux()); |
2574 __ jump(x->default_sux()); |
2575 } |
2575 } |
2576 |
2576 |
2577 |
2577 /** |
2578 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) { |
2578 * Emit profiling code if needed for arguments, parameters, return value types |
|
2579 * |
|
2580 * @param md MDO the code will update at runtime |
|
2581 * @param md_base_offset common offset in the MDO for this profile and subsequent ones |
|
2582 * @param md_offset offset in the MDO (on top of md_base_offset) for this profile |
|
2583 * @param profiled_k current profile |
|
2584 * @param obj IR node for the object to be profiled |
|
2585 * @param mdp register to hold the pointer inside the MDO (md + md_base_offset). |
|
2586 * Set once we find an update to make and use for next ones. |
|
2587 * @param not_null true if we know obj cannot be null |
|
2588 * @param signature_at_call_k signature at call for obj |
|
2589 * @param callee_signature_k signature of callee for obj |
|
2590 * at call and callee signatures differ at method handle call |
|
2591 * @return the only klass we know will ever be seen at this profile point |
|
2592 */ |
|
2593 ciKlass* LIRGenerator::profile_type(ciMethodData* md, int md_base_offset, int md_offset, intptr_t profiled_k, |
|
2594 Value obj, LIR_Opr& mdp, bool not_null, ciKlass* signature_at_call_k, |
|
2595 ciKlass* callee_signature_k) { |
2579 ciKlass* result = NULL; |
2596 ciKlass* result = NULL; |
2580 bool do_null = !not_null && !TypeEntries::was_null_seen(profiled_k); |
2597 bool do_null = !not_null && !TypeEntries::was_null_seen(profiled_k); |
2581 bool do_update = !TypeEntries::is_type_unknown(profiled_k); |
2598 bool do_update = !TypeEntries::is_type_unknown(profiled_k); |
2582 // known not to be null or null bit already set and already set to |
2599 // known not to be null or null bit already set and already set to |
2583 // unknown: nothing we can do to improve profiling |
2600 // unknown: nothing we can do to improve profiling |
2588 ciKlass* exact_klass = NULL; |
2605 ciKlass* exact_klass = NULL; |
2589 Compilation* comp = Compilation::current(); |
2606 Compilation* comp = Compilation::current(); |
2590 if (do_update) { |
2607 if (do_update) { |
2591 // try to find exact type, using CHA if possible, so that loading |
2608 // try to find exact type, using CHA if possible, so that loading |
2592 // the klass from the object can be avoided |
2609 // the klass from the object can be avoided |
2593 ciType* type = arg->exact_type(); |
2610 ciType* type = obj->exact_type(); |
2594 if (type == NULL) { |
2611 if (type == NULL) { |
2595 type = arg->declared_type(); |
2612 type = obj->declared_type(); |
2596 type = comp->cha_exact_type(type); |
2613 type = comp->cha_exact_type(type); |
2597 } |
2614 } |
2598 assert(type == NULL || type->is_klass(), "type should be class"); |
2615 assert(type == NULL || type->is_klass(), "type should be class"); |
2599 exact_klass = (type != NULL && type->is_loaded()) ? (ciKlass*)type : NULL; |
2616 exact_klass = (type != NULL && type->is_loaded()) ? (ciKlass*)type : NULL; |
2600 |
2617 |
2606 } |
2623 } |
2607 |
2624 |
2608 ciKlass* exact_signature_k = NULL; |
2625 ciKlass* exact_signature_k = NULL; |
2609 if (do_update) { |
2626 if (do_update) { |
2610 // Is the type from the signature exact (the only one possible)? |
2627 // Is the type from the signature exact (the only one possible)? |
2611 exact_signature_k = signature_k->exact_klass(); |
2628 exact_signature_k = signature_at_call_k->exact_klass(); |
2612 if (exact_signature_k == NULL) { |
2629 if (exact_signature_k == NULL) { |
2613 exact_signature_k = comp->cha_exact_type(signature_k); |
2630 exact_signature_k = comp->cha_exact_type(signature_at_call_k); |
2614 } else { |
2631 } else { |
2615 result = exact_signature_k; |
2632 result = exact_signature_k; |
2616 do_update = false; |
|
2617 // Known statically. No need to emit any code: prevent |
2633 // Known statically. No need to emit any code: prevent |
2618 // LIR_Assembler::emit_profile_type() from emitting useless code |
2634 // LIR_Assembler::emit_profile_type() from emitting useless code |
2619 profiled_k = ciTypeEntries::with_status(result, profiled_k); |
2635 profiled_k = ciTypeEntries::with_status(result, profiled_k); |
2620 } |
2636 } |
2621 if (exact_signature_k != NULL && exact_klass != exact_signature_k) { |
2637 if (exact_signature_k != NULL && exact_klass != exact_signature_k) { |
2622 assert(exact_klass == NULL, "arg and signature disagree?"); |
2638 assert(exact_klass == NULL, "obj and signature disagree?"); |
2623 // sometimes the type of the signature is better than the best type |
2639 // sometimes the type of the signature is better than the best type |
2624 // the compiler has |
2640 // the compiler has |
2625 exact_klass = exact_signature_k; |
2641 exact_klass = exact_signature_k; |
2626 do_update = exact_klass == NULL || ciTypeEntries::valid_ciklass(profiled_k) != exact_klass; |
2642 } |
2627 } |
2643 if (callee_signature_k != NULL && |
|
2644 callee_signature_k != signature_at_call_k) { |
|
2645 ciKlass* improved_klass = callee_signature_k->exact_klass(); |
|
2646 if (improved_klass == NULL) { |
|
2647 improved_klass = comp->cha_exact_type(callee_signature_k); |
|
2648 } |
|
2649 if (improved_klass != NULL && exact_klass != improved_klass) { |
|
2650 assert(exact_klass == NULL, "obj and signature disagree?"); |
|
2651 exact_klass = exact_signature_k; |
|
2652 } |
|
2653 } |
|
2654 do_update = exact_klass == NULL || ciTypeEntries::valid_ciklass(profiled_k) != exact_klass; |
2628 } |
2655 } |
2629 |
2656 |
2630 if (!do_null && !do_update) { |
2657 if (!do_null && !do_update) { |
2631 return result; |
2658 return result; |
2632 } |
2659 } |
2638 LIR_Address* base_type_address = new LIR_Address(mdp, md_base_offset, T_ADDRESS); |
2665 LIR_Address* base_type_address = new LIR_Address(mdp, md_base_offset, T_ADDRESS); |
2639 mdp = new_pointer_register(); |
2666 mdp = new_pointer_register(); |
2640 __ leal(LIR_OprFact::address(base_type_address), mdp); |
2667 __ leal(LIR_OprFact::address(base_type_address), mdp); |
2641 } |
2668 } |
2642 } |
2669 } |
2643 LIRItem value(arg, this); |
2670 LIRItem value(obj, this); |
2644 value.load_item(); |
2671 value.load_item(); |
2645 __ profile_type(new LIR_Address(mdp, md_offset, T_METADATA), |
2672 __ profile_type(new LIR_Address(mdp, md_offset, T_METADATA), |
2646 value.result(), exact_klass, profiled_k, new_pointer_register(), not_null, exact_signature_k != NULL); |
2673 value.result(), exact_klass, profiled_k, new_pointer_register(), not_null, exact_signature_k != NULL); |
2647 return result; |
2674 return result; |
2648 } |
2675 } |
2663 assert(!src->is_illegal(), "check"); |
2690 assert(!src->is_illegal(), "check"); |
2664 BasicType t = src->type(); |
2691 BasicType t = src->type(); |
2665 if (t == T_OBJECT || t == T_ARRAY) { |
2692 if (t == T_OBJECT || t == T_ARRAY) { |
2666 intptr_t profiled_k = parameters->type(j); |
2693 intptr_t profiled_k = parameters->type(j); |
2667 Local* local = x->state()->local_at(java_index)->as_Local(); |
2694 Local* local = x->state()->local_at(java_index)->as_Local(); |
2668 ciKlass* exact = profile_arg_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)), |
2695 ciKlass* exact = profile_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)), |
2669 in_bytes(ParametersTypeData::type_offset(j)) - in_bytes(ParametersTypeData::type_offset(0)), |
2696 in_bytes(ParametersTypeData::type_offset(j)) - in_bytes(ParametersTypeData::type_offset(0)), |
2670 profiled_k, local, mdp, false, local->declared_type()->as_klass()); |
2697 profiled_k, local, mdp, false, local->declared_type()->as_klass(), NULL); |
2671 // If the profile is known statically set it once for all and do not emit any code |
2698 // If the profile is known statically set it once for all and do not emit any code |
2672 if (exact != NULL) { |
2699 if (exact != NULL) { |
2673 md->set_parameter_type(j, exact); |
2700 md->set_parameter_type(j, exact); |
2674 } |
2701 } |
2675 j++; |
2702 j++; |
3127 ciTypeStackSlotEntries* args = data->is_CallTypeData() ? ((ciCallTypeData*)data)->args() : ((ciVirtualCallTypeData*)data)->args(); |
3154 ciTypeStackSlotEntries* args = data->is_CallTypeData() ? ((ciCallTypeData*)data)->args() : ((ciVirtualCallTypeData*)data)->args(); |
3128 |
3155 |
3129 Bytecodes::Code bc = x->method()->java_code_at_bci(bci); |
3156 Bytecodes::Code bc = x->method()->java_code_at_bci(bci); |
3130 int start = 0; |
3157 int start = 0; |
3131 int stop = data->is_CallTypeData() ? ((ciCallTypeData*)data)->number_of_arguments() : ((ciVirtualCallTypeData*)data)->number_of_arguments(); |
3158 int stop = data->is_CallTypeData() ? ((ciCallTypeData*)data)->number_of_arguments() : ((ciVirtualCallTypeData*)data)->number_of_arguments(); |
3132 if (x->nb_profiled_args() < stop) { |
3159 if (x->inlined() && x->callee()->is_static() && Bytecodes::has_receiver(bc)) { |
3133 // if called through method handle invoke, some arguments may have been popped |
3160 // first argument is not profiled at call (method handle invoke) |
3134 stop = x->nb_profiled_args(); |
3161 assert(x->method()->raw_code_at_bci(bci) == Bytecodes::_invokehandle, "invokehandle expected"); |
3135 } |
3162 start = 1; |
3136 ciSignature* sig = x->callee()->signature(); |
3163 } |
|
3164 ciSignature* callee_signature = x->callee()->signature(); |
3137 // method handle call to virtual method |
3165 // method handle call to virtual method |
3138 bool has_receiver = x->inlined() && !x->callee()->is_static() && !Bytecodes::has_receiver(bc); |
3166 bool has_receiver = x->inlined() && !x->callee()->is_static() && !Bytecodes::has_receiver(bc); |
3139 ciSignatureStream sig_stream(sig, has_receiver ? x->callee()->holder() : NULL); |
3167 ciSignatureStream callee_signature_stream(callee_signature, has_receiver ? x->callee()->holder() : NULL); |
3140 for (int i = 0; i < stop; i++) { |
3168 |
|
3169 bool ignored_will_link; |
|
3170 ciSignature* signature_at_call = NULL; |
|
3171 x->method()->get_method_at_bci(bci, ignored_will_link, &signature_at_call); |
|
3172 ciSignatureStream signature_at_call_stream(signature_at_call); |
|
3173 |
|
3174 // if called through method handle invoke, some arguments may have been popped |
|
3175 for (int i = 0; i < stop && i+start < x->nb_profiled_args(); i++) { |
3141 int off = in_bytes(TypeEntriesAtCall::argument_type_offset(i)) - in_bytes(TypeEntriesAtCall::args_data_offset()); |
3176 int off = in_bytes(TypeEntriesAtCall::argument_type_offset(i)) - in_bytes(TypeEntriesAtCall::args_data_offset()); |
3142 ciKlass* exact = profile_arg_type(md, base_offset, off, |
3177 ciKlass* exact = profile_type(md, base_offset, off, |
3143 args->type(i), x->profiled_arg_at(i+start), mdp, |
3178 args->type(i), x->profiled_arg_at(i+start), mdp, |
3144 !x->arg_needs_null_check(i+start), sig_stream.next_klass()); |
3179 !x->arg_needs_null_check(i+start), |
|
3180 signature_at_call_stream.next_klass(), callee_signature_stream.next_klass()); |
3145 if (exact != NULL) { |
3181 if (exact != NULL) { |
3146 md->set_argument_type(bci, i, exact); |
3182 md->set_argument_type(bci, i, exact); |
3147 } |
3183 } |
3148 } |
3184 } |
3149 } else { |
3185 } else { |
3174 Value arg = x->recv(); |
3210 Value arg = x->recv(); |
3175 bool not_null = false; |
3211 bool not_null = false; |
3176 int bci = x->bci_of_invoke(); |
3212 int bci = x->bci_of_invoke(); |
3177 Bytecodes::Code bc = x->method()->java_code_at_bci(bci); |
3213 Bytecodes::Code bc = x->method()->java_code_at_bci(bci); |
3178 // The first parameter is the receiver so that's what we start |
3214 // The first parameter is the receiver so that's what we start |
3179 // with if it exists. On exception if method handle call to |
3215 // with if it exists. One exception is method handle call to |
3180 // virtual method has receiver in the args list |
3216 // virtual method: the receiver is in the args list |
3181 if (arg == NULL || !Bytecodes::has_receiver(bc)) { |
3217 if (arg == NULL || !Bytecodes::has_receiver(bc)) { |
3182 i = 1; |
3218 i = 1; |
3183 arg = x->profiled_arg_at(0); |
3219 arg = x->profiled_arg_at(0); |
3184 not_null = !x->arg_needs_null_check(0); |
3220 not_null = !x->arg_needs_null_check(0); |
3185 } |
3221 } |
3186 int k = 0; // to iterate on the profile data |
3222 int k = 0; // to iterate on the profile data |
3187 for (;;) { |
3223 for (;;) { |
3188 intptr_t profiled_k = parameters->type(k); |
3224 intptr_t profiled_k = parameters->type(k); |
3189 ciKlass* exact = profile_arg_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)), |
3225 ciKlass* exact = profile_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)), |
3190 in_bytes(ParametersTypeData::type_offset(k)) - in_bytes(ParametersTypeData::type_offset(0)), |
3226 in_bytes(ParametersTypeData::type_offset(k)) - in_bytes(ParametersTypeData::type_offset(0)), |
3191 profiled_k, arg, mdp, not_null, sig_stream.next_klass()); |
3227 profiled_k, arg, mdp, not_null, sig_stream.next_klass(), NULL); |
3192 // If the profile is known statically set it once for all and do not emit any code |
3228 // If the profile is known statically set it once for all and do not emit any code |
3193 if (exact != NULL) { |
3229 if (exact != NULL) { |
3194 md->set_parameter_type(k, exact); |
3230 md->set_parameter_type(k, exact); |
3195 } |
3231 } |
3196 k++; |
3232 k++; |
3245 ciMethodData* md = x->method()->method_data_or_null(); |
3281 ciMethodData* md = x->method()->method_data_or_null(); |
3246 ciProfileData* data = md->bci_to_data(bci); |
3282 ciProfileData* data = md->bci_to_data(bci); |
3247 assert(data->is_CallTypeData() || data->is_VirtualCallTypeData(), "wrong profile data type"); |
3283 assert(data->is_CallTypeData() || data->is_VirtualCallTypeData(), "wrong profile data type"); |
3248 ciReturnTypeEntry* ret = data->is_CallTypeData() ? ((ciCallTypeData*)data)->ret() : ((ciVirtualCallTypeData*)data)->ret(); |
3284 ciReturnTypeEntry* ret = data->is_CallTypeData() ? ((ciCallTypeData*)data)->ret() : ((ciVirtualCallTypeData*)data)->ret(); |
3249 LIR_Opr mdp = LIR_OprFact::illegalOpr; |
3285 LIR_Opr mdp = LIR_OprFact::illegalOpr; |
3250 ciKlass* exact = profile_arg_type(md, 0, md->byte_offset_of_slot(data, ret->type_offset()), |
3286 |
3251 ret->type(), x->ret(), mdp, |
3287 bool ignored_will_link; |
3252 !x->needs_null_check(), x->callee()->signature()->return_type()->as_klass()); |
3288 ciSignature* signature_at_call = NULL; |
|
3289 x->method()->get_method_at_bci(bci, ignored_will_link, &signature_at_call); |
|
3290 |
|
3291 ciKlass* exact = profile_type(md, 0, md->byte_offset_of_slot(data, ret->type_offset()), |
|
3292 ret->type(), x->ret(), mdp, |
|
3293 !x->needs_null_check(), |
|
3294 signature_at_call->return_type()->as_klass(), |
|
3295 x->callee()->signature()->return_type()->as_klass()); |
3253 if (exact != NULL) { |
3296 if (exact != NULL) { |
3254 md->set_return_type(bci, exact); |
3297 md->set_return_type(bci, exact); |
3255 } |
3298 } |
3256 } |
3299 } |
3257 |
3300 |