comparison src/share/vm/c1/c1_LIRGenerator.cpp @ 13086:096c224171c4

Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author Doug Simon <doug.simon@oracle.com>
date Wed, 20 Nov 2013 00:10:38 +0100
parents 3cce976666d9 e6ba215af802
children d8041d695d19
comparison
equal deleted inserted replaced
12782:92b7ec34ddfa 13086:096c224171c4
1173 1173
1174 void LIRGenerator::do_Return(Return* x) { 1174 void LIRGenerator::do_Return(Return* x) {
1175 if (compilation()->env()->dtrace_method_probes()) { 1175 if (compilation()->env()->dtrace_method_probes()) {
1176 BasicTypeList signature; 1176 BasicTypeList signature;
1177 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread 1177 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread
1178 signature.append(T_OBJECT); // Method* 1178 signature.append(T_METADATA); // Method*
1179 LIR_OprList* args = new LIR_OprList(); 1179 LIR_OprList* args = new LIR_OprList();
1180 args->append(getThreadPointer()); 1180 args->append(getThreadPointer());
1181 LIR_Opr meth = new_register(T_METADATA); 1181 LIR_Opr meth = new_register(T_METADATA);
1182 __ metadata2reg(method()->constant_encoding(), meth); 1182 __ metadata2reg(method()->constant_encoding(), meth);
1183 args->append(meth); 1183 args->append(meth);
1263 void LIRGenerator::do_getClass(Intrinsic* x) { 1263 void LIRGenerator::do_getClass(Intrinsic* x) {
1264 assert(x->number_of_arguments() == 1, "wrong type"); 1264 assert(x->number_of_arguments() == 1, "wrong type");
1265 1265
1266 LIRItem rcvr(x->argument_at(0), this); 1266 LIRItem rcvr(x->argument_at(0), this);
1267 rcvr.load_item(); 1267 rcvr.load_item();
1268 LIR_Opr temp = new_register(T_METADATA);
1268 LIR_Opr result = rlock_result(x); 1269 LIR_Opr result = rlock_result(x);
1269 1270
1270 // need to perform the null check on the rcvr 1271 // need to perform the null check on the rcvr
1271 CodeEmitInfo* info = NULL; 1272 CodeEmitInfo* info = NULL;
1272 if (x->needs_null_check()) { 1273 if (x->needs_null_check()) {
1273 info = state_for(x); 1274 info = state_for(x);
1274 } 1275 }
1275 __ move(new LIR_Address(rcvr.result(), oopDesc::klass_offset_in_bytes(), T_ADDRESS), result, info); 1276
1276 __ move_wide(new LIR_Address(result, in_bytes(Klass::java_mirror_offset()), T_OBJECT), result); 1277 // FIXME T_ADDRESS should actually be T_METADATA but it can't because the
1278 // meaning of these two is mixed up (see JDK-8026837).
1279 __ move(new LIR_Address(rcvr.result(), oopDesc::klass_offset_in_bytes(), T_ADDRESS), temp, info);
1280 __ move_wide(new LIR_Address(temp, in_bytes(Klass::java_mirror_offset()), T_OBJECT), result);
1277 } 1281 }
1278 1282
1279 1283
1280 // Example: Thread.currentThread() 1284 // Example: Thread.currentThread()
1281 void LIRGenerator::do_currentThread(Intrinsic* x) { 1285 void LIRGenerator::do_currentThread(Intrinsic* x) {
2568 move_to_phi(x->state()); 2572 move_to_phi(x->state());
2569 2573
2570 __ jump(x->default_sux()); 2574 __ jump(x->default_sux());
2571 } 2575 }
2572 2576
2577 /**
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) {
2596 ciKlass* result = NULL;
2597 bool do_null = !not_null && !TypeEntries::was_null_seen(profiled_k);
2598 bool do_update = !TypeEntries::is_type_unknown(profiled_k);
2599 // known not to be null or null bit already set and already set to
2600 // unknown: nothing we can do to improve profiling
2601 if (!do_null && !do_update) {
2602 return result;
2603 }
2604
2605 ciKlass* exact_klass = NULL;
2606 Compilation* comp = Compilation::current();
2607 if (do_update) {
2608 // try to find exact type, using CHA if possible, so that loading
2609 // the klass from the object can be avoided
2610 ciType* type = obj->exact_type();
2611 if (type == NULL) {
2612 type = obj->declared_type();
2613 type = comp->cha_exact_type(type);
2614 }
2615 assert(type == NULL || type->is_klass(), "type should be class");
2616 exact_klass = (type != NULL && type->is_loaded()) ? (ciKlass*)type : NULL;
2617
2618 do_update = exact_klass == NULL || ciTypeEntries::valid_ciklass(profiled_k) != exact_klass;
2619 }
2620
2621 if (!do_null && !do_update) {
2622 return result;
2623 }
2624
2625 ciKlass* exact_signature_k = NULL;
2626 if (do_update) {
2627 // Is the type from the signature exact (the only one possible)?
2628 exact_signature_k = signature_at_call_k->exact_klass();
2629 if (exact_signature_k == NULL) {
2630 exact_signature_k = comp->cha_exact_type(signature_at_call_k);
2631 } else {
2632 result = exact_signature_k;
2633 // Known statically. No need to emit any code: prevent
2634 // LIR_Assembler::emit_profile_type() from emitting useless code
2635 profiled_k = ciTypeEntries::with_status(result, profiled_k);
2636 }
2637 if (exact_signature_k != NULL && exact_klass != exact_signature_k) {
2638 assert(exact_klass == NULL, "obj and signature disagree?");
2639 // sometimes the type of the signature is better than the best type
2640 // the compiler has
2641 exact_klass = exact_signature_k;
2642 }
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;
2655 }
2656
2657 if (!do_null && !do_update) {
2658 return result;
2659 }
2660
2661 if (mdp == LIR_OprFact::illegalOpr) {
2662 mdp = new_register(T_METADATA);
2663 __ metadata2reg(md->constant_encoding(), mdp);
2664 if (md_base_offset != 0) {
2665 LIR_Address* base_type_address = new LIR_Address(mdp, md_base_offset, T_ADDRESS);
2666 mdp = new_pointer_register();
2667 __ leal(LIR_OprFact::address(base_type_address), mdp);
2668 }
2669 }
2670 LIRItem value(obj, this);
2671 value.load_item();
2672 __ profile_type(new LIR_Address(mdp, md_offset, T_METADATA),
2673 value.result(), exact_klass, profiled_k, new_pointer_register(), not_null, exact_signature_k != NULL);
2674 return result;
2675 }
2676
2677 // profile parameters on entry to the root of the compilation
2678 void LIRGenerator::profile_parameters(Base* x) {
2679 if (compilation()->profile_parameters()) {
2680 CallingConvention* args = compilation()->frame_map()->incoming_arguments();
2681 ciMethodData* md = scope()->method()->method_data_or_null();
2682 assert(md != NULL, "Sanity");
2683
2684 if (md->parameters_type_data() != NULL) {
2685 ciParametersTypeData* parameters_type_data = md->parameters_type_data();
2686 ciTypeStackSlotEntries* parameters = parameters_type_data->parameters();
2687 LIR_Opr mdp = LIR_OprFact::illegalOpr;
2688 for (int java_index = 0, i = 0, j = 0; j < parameters_type_data->number_of_parameters(); i++) {
2689 LIR_Opr src = args->at(i);
2690 assert(!src->is_illegal(), "check");
2691 BasicType t = src->type();
2692 if (t == T_OBJECT || t == T_ARRAY) {
2693 intptr_t profiled_k = parameters->type(j);
2694 Local* local = x->state()->local_at(java_index)->as_Local();
2695 ciKlass* exact = profile_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)),
2696 in_bytes(ParametersTypeData::type_offset(j)) - in_bytes(ParametersTypeData::type_offset(0)),
2697 profiled_k, local, mdp, false, local->declared_type()->as_klass(), NULL);
2698 // If the profile is known statically set it once for all and do not emit any code
2699 if (exact != NULL) {
2700 md->set_parameter_type(j, exact);
2701 }
2702 j++;
2703 }
2704 java_index += type2size[t];
2705 }
2706 }
2707 }
2708 }
2573 2709
2574 void LIRGenerator::do_Base(Base* x) { 2710 void LIRGenerator::do_Base(Base* x) {
2575 __ std_entry(LIR_OprFact::illegalOpr); 2711 __ std_entry(LIR_OprFact::illegalOpr);
2576 // Emit moves from physical registers / stack slots to virtual registers 2712 // Emit moves from physical registers / stack slots to virtual registers
2577 CallingConvention* args = compilation()->frame_map()->incoming_arguments(); 2713 CallingConvention* args = compilation()->frame_map()->incoming_arguments();
2609 } 2745 }
2610 2746
2611 if (compilation()->env()->dtrace_method_probes()) { 2747 if (compilation()->env()->dtrace_method_probes()) {
2612 BasicTypeList signature; 2748 BasicTypeList signature;
2613 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread 2749 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread
2614 signature.append(T_OBJECT); // Method* 2750 signature.append(T_METADATA); // Method*
2615 LIR_OprList* args = new LIR_OprList(); 2751 LIR_OprList* args = new LIR_OprList();
2616 args->append(getThreadPointer()); 2752 args->append(getThreadPointer());
2617 LIR_Opr meth = new_register(T_METADATA); 2753 LIR_Opr meth = new_register(T_METADATA);
2618 __ metadata2reg(method()->constant_encoding(), meth); 2754 __ metadata2reg(method()->constant_encoding(), meth);
2619 args->append(meth); 2755 args->append(meth);
2644 } 2780 }
2645 } 2781 }
2646 2782
2647 // increment invocation counters if needed 2783 // increment invocation counters if needed
2648 if (!method()->is_accessor()) { // Accessors do not have MDOs, so no counting. 2784 if (!method()->is_accessor()) { // Accessors do not have MDOs, so no counting.
2785 profile_parameters(x);
2649 CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL, false); 2786 CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL, false);
2650 increment_invocation_counter(info); 2787 increment_invocation_counter(info);
2651 } 2788 }
2652 2789
2653 // all blocks with a successor must end with an unconditional jump 2790 // all blocks with a successor must end with an unconditional jump
3002 3139
3003 default: ShouldNotReachHere(); break; 3140 default: ShouldNotReachHere(); break;
3004 } 3141 }
3005 } 3142 }
3006 3143
3144 void LIRGenerator::profile_arguments(ProfileCall* x) {
3145 if (compilation()->profile_arguments()) {
3146 int bci = x->bci_of_invoke();
3147 ciMethodData* md = x->method()->method_data_or_null();
3148 ciProfileData* data = md->bci_to_data(bci);
3149 if ((data->is_CallTypeData() && data->as_CallTypeData()->has_arguments()) ||
3150 (data->is_VirtualCallTypeData() && data->as_VirtualCallTypeData()->has_arguments())) {
3151 ByteSize extra = data->is_CallTypeData() ? CallTypeData::args_data_offset() : VirtualCallTypeData::args_data_offset();
3152 int base_offset = md->byte_offset_of_slot(data, extra);
3153 LIR_Opr mdp = LIR_OprFact::illegalOpr;
3154 ciTypeStackSlotEntries* args = data->is_CallTypeData() ? ((ciCallTypeData*)data)->args() : ((ciVirtualCallTypeData*)data)->args();
3155
3156 Bytecodes::Code bc = x->method()->java_code_at_bci(bci);
3157 int start = 0;
3158 int stop = data->is_CallTypeData() ? ((ciCallTypeData*)data)->number_of_arguments() : ((ciVirtualCallTypeData*)data)->number_of_arguments();
3159 if (x->inlined() && x->callee()->is_static() && Bytecodes::has_receiver(bc)) {
3160 // first argument is not profiled at call (method handle invoke)
3161 assert(x->method()->raw_code_at_bci(bci) == Bytecodes::_invokehandle, "invokehandle expected");
3162 start = 1;
3163 }
3164 ciSignature* callee_signature = x->callee()->signature();
3165 // method handle call to virtual method
3166 bool has_receiver = x->inlined() && !x->callee()->is_static() && !Bytecodes::has_receiver(bc);
3167 ciSignatureStream callee_signature_stream(callee_signature, has_receiver ? x->callee()->holder() : NULL);
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++) {
3176 int off = in_bytes(TypeEntriesAtCall::argument_type_offset(i)) - in_bytes(TypeEntriesAtCall::args_data_offset());
3177 ciKlass* exact = profile_type(md, base_offset, off,
3178 args->type(i), x->profiled_arg_at(i+start), mdp,
3179 !x->arg_needs_null_check(i+start),
3180 signature_at_call_stream.next_klass(), callee_signature_stream.next_klass());
3181 if (exact != NULL) {
3182 md->set_argument_type(bci, i, exact);
3183 }
3184 }
3185 } else {
3186 #ifdef ASSERT
3187 Bytecodes::Code code = x->method()->raw_code_at_bci(x->bci_of_invoke());
3188 int n = x->nb_profiled_args();
3189 assert(MethodData::profile_parameters() && x->inlined() &&
3190 ((code == Bytecodes::_invokedynamic && n <= 1) || (code == Bytecodes::_invokehandle && n <= 2)),
3191 "only at JSR292 bytecodes");
3192 #endif
3193 }
3194 }
3195 }
3196
3197 // profile parameters on entry to an inlined method
3198 void LIRGenerator::profile_parameters_at_call(ProfileCall* x) {
3199 if (compilation()->profile_parameters() && x->inlined()) {
3200 ciMethodData* md = x->callee()->method_data_or_null();
3201 if (md != NULL) {
3202 ciParametersTypeData* parameters_type_data = md->parameters_type_data();
3203 if (parameters_type_data != NULL) {
3204 ciTypeStackSlotEntries* parameters = parameters_type_data->parameters();
3205 LIR_Opr mdp = LIR_OprFact::illegalOpr;
3206 bool has_receiver = !x->callee()->is_static();
3207 ciSignature* sig = x->callee()->signature();
3208 ciSignatureStream sig_stream(sig, has_receiver ? x->callee()->holder() : NULL);
3209 int i = 0; // to iterate on the Instructions
3210 Value arg = x->recv();
3211 bool not_null = false;
3212 int bci = x->bci_of_invoke();
3213 Bytecodes::Code bc = x->method()->java_code_at_bci(bci);
3214 // The first parameter is the receiver so that's what we start
3215 // with if it exists. One exception is method handle call to
3216 // virtual method: the receiver is in the args list
3217 if (arg == NULL || !Bytecodes::has_receiver(bc)) {
3218 i = 1;
3219 arg = x->profiled_arg_at(0);
3220 not_null = !x->arg_needs_null_check(0);
3221 }
3222 int k = 0; // to iterate on the profile data
3223 for (;;) {
3224 intptr_t profiled_k = parameters->type(k);
3225 ciKlass* exact = profile_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)),
3226 in_bytes(ParametersTypeData::type_offset(k)) - in_bytes(ParametersTypeData::type_offset(0)),
3227 profiled_k, arg, mdp, not_null, sig_stream.next_klass(), NULL);
3228 // If the profile is known statically set it once for all and do not emit any code
3229 if (exact != NULL) {
3230 md->set_parameter_type(k, exact);
3231 }
3232 k++;
3233 if (k >= parameters_type_data->number_of_parameters()) {
3234 #ifdef ASSERT
3235 int extra = 0;
3236 if (MethodData::profile_arguments() && TypeProfileParmsLimit != -1 &&
3237 x->nb_profiled_args() >= TypeProfileParmsLimit &&
3238 x->recv() != NULL && Bytecodes::has_receiver(bc)) {
3239 extra += 1;
3240 }
3241 assert(i == x->nb_profiled_args() - extra || (TypeProfileParmsLimit != -1 && TypeProfileArgsLimit > TypeProfileParmsLimit), "unused parameters?");
3242 #endif
3243 break;
3244 }
3245 arg = x->profiled_arg_at(i);
3246 not_null = !x->arg_needs_null_check(i);
3247 i++;
3248 }
3249 }
3250 }
3251 }
3252 }
3253
3007 void LIRGenerator::do_ProfileCall(ProfileCall* x) { 3254 void LIRGenerator::do_ProfileCall(ProfileCall* x) {
3008 // Need recv in a temporary register so it interferes with the other temporaries 3255 // Need recv in a temporary register so it interferes with the other temporaries
3009 LIR_Opr recv = LIR_OprFact::illegalOpr; 3256 LIR_Opr recv = LIR_OprFact::illegalOpr;
3010 LIR_Opr mdo = new_register(T_OBJECT); 3257 LIR_Opr mdo = new_register(T_OBJECT);
3011 // tmp is used to hold the counters on SPARC 3258 // tmp is used to hold the counters on SPARC
3012 LIR_Opr tmp = new_pointer_register(); 3259 LIR_Opr tmp = new_pointer_register();
3260
3261 if (x->nb_profiled_args() > 0) {
3262 profile_arguments(x);
3263 }
3264
3265 // profile parameters on inlined method entry including receiver
3266 if (x->recv() != NULL || x->nb_profiled_args() > 0) {
3267 profile_parameters_at_call(x);
3268 }
3269
3013 if (x->recv() != NULL) { 3270 if (x->recv() != NULL) {
3014 LIRItem value(x->recv(), this); 3271 LIRItem value(x->recv(), this);
3015 value.load_item(); 3272 value.load_item();
3016 recv = new_register(T_OBJECT); 3273 recv = new_register(T_OBJECT);
3017 __ move(value.result(), recv); 3274 __ move(value.result(), recv);
3018 } 3275 }
3019 __ profile_call(x->method(), x->bci_of_invoke(), x->callee(), mdo, recv, tmp, x->known_holder()); 3276 __ profile_call(x->method(), x->bci_of_invoke(), x->callee(), mdo, recv, tmp, x->known_holder());
3277 }
3278
3279 void LIRGenerator::do_ProfileReturnType(ProfileReturnType* x) {
3280 int bci = x->bci_of_invoke();
3281 ciMethodData* md = x->method()->method_data_or_null();
3282 ciProfileData* data = md->bci_to_data(bci);
3283 assert(data->is_CallTypeData() || data->is_VirtualCallTypeData(), "wrong profile data type");
3284 ciReturnTypeEntry* ret = data->is_CallTypeData() ? ((ciCallTypeData*)data)->ret() : ((ciVirtualCallTypeData*)data)->ret();
3285 LIR_Opr mdp = LIR_OprFact::illegalOpr;
3286
3287 bool ignored_will_link;
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());
3296 if (exact != NULL) {
3297 md->set_return_type(bci, exact);
3298 }
3020 } 3299 }
3021 3300
3022 void LIRGenerator::do_ProfileInvoke(ProfileInvoke* x) { 3301 void LIRGenerator::do_ProfileInvoke(ProfileInvoke* x) {
3023 // We can safely ignore accessors here, since c2 will inline them anyway, 3302 // We can safely ignore accessors here, since c2 will inline them anyway,
3024 // accessors are also always mature. 3303 // accessors are also always mature.
3051 assert(level > CompLevel_simple, "Shouldn't be here"); 3330 assert(level > CompLevel_simple, "Shouldn't be here");
3052 3331
3053 int offset = -1; 3332 int offset = -1;
3054 LIR_Opr counter_holder; 3333 LIR_Opr counter_holder;
3055 if (level == CompLevel_limited_profile) { 3334 if (level == CompLevel_limited_profile) {
3056 address counters_adr = method->ensure_method_counters(); 3335 MethodCounters* counters_adr = method->ensure_method_counters();
3336 if (counters_adr == NULL) {
3337 bailout("method counters allocation failed");
3338 return;
3339 }
3057 counter_holder = new_pointer_register(); 3340 counter_holder = new_pointer_register();
3058 __ move(LIR_OprFact::intptrConst(counters_adr), counter_holder); 3341 __ move(LIR_OprFact::intptrConst(counters_adr), counter_holder);
3059 offset = in_bytes(backedge ? MethodCounters::backedge_counter_offset() : 3342 offset = in_bytes(backedge ? MethodCounters::backedge_counter_offset() :
3060 MethodCounters::invocation_counter_offset()); 3343 MethodCounters::invocation_counter_offset());
3061 } else if (level == CompLevel_full_profile) { 3344 } else if (level == CompLevel_full_profile) {
3089 void LIRGenerator::do_RuntimeCall(RuntimeCall* x) { 3372 void LIRGenerator::do_RuntimeCall(RuntimeCall* x) {
3090 LIR_OprList* args = new LIR_OprList(x->number_of_arguments()); 3373 LIR_OprList* args = new LIR_OprList(x->number_of_arguments());
3091 BasicTypeList* signature = new BasicTypeList(x->number_of_arguments()); 3374 BasicTypeList* signature = new BasicTypeList(x->number_of_arguments());
3092 3375
3093 if (x->pass_thread()) { 3376 if (x->pass_thread()) {
3094 signature->append(T_ADDRESS); 3377 signature->append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread
3095 args->append(getThreadPointer()); 3378 args->append(getThreadPointer());
3096 } 3379 }
3097 3380
3098 for (int i = 0; i < x->number_of_arguments(); i++) { 3381 for (int i = 0; i < x->number_of_arguments(); i++) {
3099 Value a = x->argument_at(i); 3382 Value a = x->argument_at(i);