src/share/vm/c1/c1_LIRGenerator.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/c1

src/share/vm/c1/c1_LIRGenerator.cpp

Print this page
rev 5468 : 8026251: New type profiling points: parameters to methods
Summary: x86 interpreter and c1 type profiling for parameters on method entries
Reviewed-by:


2630   if (!do_null && !do_update) {
2631     return result;
2632   }
2633 
2634   if (mdp == LIR_OprFact::illegalOpr) {
2635     mdp = new_register(T_METADATA);
2636     __ metadata2reg(md->constant_encoding(), mdp);
2637     if (md_base_offset != 0) {
2638       LIR_Address* base_type_address = new LIR_Address(mdp, md_base_offset, T_ADDRESS);
2639       mdp = new_pointer_register();
2640       __ leal(LIR_OprFact::address(base_type_address), mdp);
2641     }
2642   }
2643   LIRItem value(arg, this);
2644   value.load_item();
2645   __ 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);
2647   return result;
2648 }
2649 

































2650 void LIRGenerator::do_Base(Base* x) {
2651   __ std_entry(LIR_OprFact::illegalOpr);
2652   // Emit moves from physical registers / stack slots to virtual registers
2653   CallingConvention* args = compilation()->frame_map()->incoming_arguments();
2654   IRScope* irScope = compilation()->hir()->top_scope();
2655   int java_index = 0;
2656   for (int i = 0; i < args->length(); i++) {
2657     LIR_Opr src = args->at(i);
2658     assert(!src->is_illegal(), "check");
2659     BasicType t = src->type();
2660 
2661     // Types which are smaller than int are passed as int, so
2662     // correct the type which passed.
2663     switch (t) {
2664     case T_BYTE:
2665     case T_BOOLEAN:
2666     case T_SHORT:
2667     case T_CHAR:
2668       t = T_INT;
2669       break;


2705       Local* receiver = x->state()->local_at(0)->as_Local();
2706       assert(receiver != NULL, "must already exist");
2707       obj = receiver->operand();
2708     }
2709     assert(obj->is_valid(), "must be valid");
2710 
2711     if (method()->is_synchronized() && GenerateSynchronizationCode) {
2712       LIR_Opr lock = new_register(T_INT);
2713       __ load_stack_address_monitor(0, lock);
2714 
2715       CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL, x->check_flag(Instruction::DeoptimizeOnException));
2716       CodeStub* slow_path = new MonitorEnterStub(obj, lock, info);
2717 
2718       // receiver is guaranteed non-NULL so don't need CodeEmitInfo
2719       __ lock_object(syncTempOpr(), obj, lock, new_register(T_OBJECT), slow_path, NULL);
2720     }
2721   }
2722 
2723   // increment invocation counters if needed
2724   if (!method()->is_accessor()) { // Accessors do not have MDOs, so no counting.

2725     CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL, false);
2726     increment_invocation_counter(info);
2727   }
2728 
2729   // all blocks with a successor must end with an unconditional jump
2730   // to the successor even if they are consecutive
2731   __ jump(x->default_sux());
2732 }
2733 
2734 
2735 void LIRGenerator::do_OsrEntry(OsrEntry* x) {
2736   // construct our frame and model the production of incoming pointer
2737   // to the OSR buffer.
2738   __ osr_entry(LIR_Assembler::osrBufferPointer());
2739   LIR_Opr result = rlock_result(x);
2740   __ move(LIR_Assembler::osrBufferPointer(), result);
2741 }
2742 
2743 
2744 void LIRGenerator::invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list) {


3064     break;
3065   case vmIntrinsics::_fullFence :
3066     if (os::is_MP()) __ membar();
3067     break;
3068 
3069   case vmIntrinsics::_Reference_get:
3070     do_Reference_get(x);
3071     break;
3072 
3073   case vmIntrinsics::_updateCRC32:
3074   case vmIntrinsics::_updateBytesCRC32:
3075   case vmIntrinsics::_updateByteBufferCRC32:
3076     do_update_CRC32(x);
3077     break;
3078 
3079   default: ShouldNotReachHere(); break;
3080   }
3081 }
3082 
3083 void LIRGenerator::profile_arguments(ProfileCall* x) {
3084   if (MethodData::profile_arguments()) {
3085     int bci = x->bci_of_invoke();
3086     ciMethodData* md = x->method()->method_data_or_null();
3087     ciProfileData* data = md->bci_to_data(bci);
3088     if (data->is_CallTypeData() || data->is_VirtualCallTypeData()) {

3089       ByteSize extra = data->is_CallTypeData() ? CallTypeData::args_data_offset() : VirtualCallTypeData::args_data_offset();
3090       int base_offset = md->byte_offset_of_slot(data, extra);
3091       LIR_Opr mdp = LIR_OprFact::illegalOpr;
3092       ciTypeStackSlotEntries* args = data->is_CallTypeData() ? ((ciCallTypeData*)data)->args() : ((ciVirtualCallTypeData*)data)->args();
3093 
3094       Bytecodes::Code bc = x->method()->java_code_at_bci(bci);
3095       int start = 0;
3096       int stop = data->is_CallTypeData() ? ((ciCallTypeData*)data)->number_of_arguments() : ((ciVirtualCallTypeData*)data)->number_of_arguments();
3097       if (x->nb_profiled_args() < stop) {
3098         // if called through method handle invoke, some arguments may have been popped
3099         stop = x->nb_profiled_args();
3100       }
3101       ciSignature* sig = x->callee()->signature();
3102       // method handle call to virtual method
3103       bool has_receiver = x->inlined() && !x->callee()->is_static() && !Bytecodes::has_receiver(bc);
3104       ciSignatureStream sig_stream(sig, has_receiver ? x->callee()->holder() : NULL);
3105       for (int i = 0; i < stop; i++) {
3106         int off = in_bytes(TypeEntriesAtCall::argument_type_offset(i)) - in_bytes(TypeEntriesAtCall::args_data_offset());
3107         ciKlass* exact = profile_arg_type(md, base_offset, off,
3108                                           args->type(i), x->profiled_arg_at(i+start), mdp,
3109                                           !x->arg_needs_null_check(i+start), sig_stream.next_klass());
3110         if (exact != NULL) {
3111           md->set_argument_type(bci, i, exact);
3112         }
3113       }

































































3114     }
3115   }
3116 }
3117 
3118 void LIRGenerator::do_ProfileCall(ProfileCall* x) {
3119   // Need recv in a temporary register so it interferes with the other temporaries
3120   LIR_Opr recv = LIR_OprFact::illegalOpr;
3121   LIR_Opr mdo = new_register(T_OBJECT);
3122   // tmp is used to hold the counters on SPARC
3123   LIR_Opr tmp = new_pointer_register();
3124 
3125   if (x->nb_profiled_args() > 0) {
3126     profile_arguments(x);





3127   }
3128 
3129   if (x->recv() != NULL) {
3130     LIRItem value(x->recv(), this);
3131     value.load_item();
3132     recv = new_register(T_OBJECT);
3133     __ move(value.result(), recv);
3134   }
3135   __ profile_call(x->method(), x->bci_of_invoke(), x->callee(), mdo, recv, tmp, x->known_holder());
3136 }
3137 
3138 void LIRGenerator::do_ProfileReturnType(ProfileReturnType* x) {
3139   int bci = x->bci_of_invoke();
3140   ciMethodData* md = x->method()->method_data_or_null();
3141   ciProfileData* data = md->bci_to_data(bci);
3142   assert(data->is_CallTypeData() || data->is_VirtualCallTypeData(), "wrong profile data type");
3143   ciReturnTypeEntry* ret = data->is_CallTypeData() ? ((ciCallTypeData*)data)->ret() : ((ciVirtualCallTypeData*)data)->ret();
3144   LIR_Opr mdp = LIR_OprFact::illegalOpr;
3145   ciKlass* exact = profile_arg_type(md, 0, md->byte_offset_of_slot(data, ret->type_offset()),
3146                                     ret->type(), x->ret(), mdp,




2630   if (!do_null && !do_update) {
2631     return result;
2632   }
2633 
2634   if (mdp == LIR_OprFact::illegalOpr) {
2635     mdp = new_register(T_METADATA);
2636     __ metadata2reg(md->constant_encoding(), mdp);
2637     if (md_base_offset != 0) {
2638       LIR_Address* base_type_address = new LIR_Address(mdp, md_base_offset, T_ADDRESS);
2639       mdp = new_pointer_register();
2640       __ leal(LIR_OprFact::address(base_type_address), mdp);
2641     }
2642   }
2643   LIRItem value(arg, this);
2644   value.load_item();
2645   __ 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);
2647   return result;
2648 }
2649 
2650 // profile parameters on entry to the root of the compilation
2651 void LIRGenerator::profile_parameters(Base* x) {
2652   if (compilation()->profile_parameters()) {
2653     CallingConvention* args = compilation()->frame_map()->incoming_arguments();
2654     ciMethodData* md = scope()->method()->method_data_or_null();
2655     assert(md != NULL, "Sanity");
2656 
2657     if (md->parameters_type_data() != NULL) {
2658       ciParametersTypeData* parameters_type_data = md->parameters_type_data();
2659       ciTypeStackSlotEntries* parameters =  parameters_type_data->parameters();
2660       LIR_Opr mdp = LIR_OprFact::illegalOpr;
2661       for (int java_index = 0, i = 0, j = 0; j < parameters_type_data->number_of_parameters(); i++) {
2662         LIR_Opr src = args->at(i);
2663         assert(!src->is_illegal(), "check");
2664         BasicType t = src->type();
2665         if (t == T_OBJECT || t == T_ARRAY) {
2666           intptr_t profiled_k = parameters->type(j);
2667           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)),
2669                                             in_bytes(ParametersTypeData::type_offset(j)) - in_bytes(ParametersTypeData::type_offset(0)),
2670                                             profiled_k, local, mdp, false, local->declared_type()->as_klass());
2671           // If the profile is known statically set it once for all and do not emit any code
2672           if (exact != NULL) {
2673             md->set_parameter_type(j, exact);
2674           }
2675           j++;
2676         }
2677         java_index += type2size[t];
2678       }
2679     }
2680   }
2681 }
2682 
2683 void LIRGenerator::do_Base(Base* x) {
2684   __ std_entry(LIR_OprFact::illegalOpr);
2685   // Emit moves from physical registers / stack slots to virtual registers
2686   CallingConvention* args = compilation()->frame_map()->incoming_arguments();
2687   IRScope* irScope = compilation()->hir()->top_scope();
2688   int java_index = 0;
2689   for (int i = 0; i < args->length(); i++) {
2690     LIR_Opr src = args->at(i);
2691     assert(!src->is_illegal(), "check");
2692     BasicType t = src->type();
2693 
2694     // Types which are smaller than int are passed as int, so
2695     // correct the type which passed.
2696     switch (t) {
2697     case T_BYTE:
2698     case T_BOOLEAN:
2699     case T_SHORT:
2700     case T_CHAR:
2701       t = T_INT;
2702       break;


2738       Local* receiver = x->state()->local_at(0)->as_Local();
2739       assert(receiver != NULL, "must already exist");
2740       obj = receiver->operand();
2741     }
2742     assert(obj->is_valid(), "must be valid");
2743 
2744     if (method()->is_synchronized() && GenerateSynchronizationCode) {
2745       LIR_Opr lock = new_register(T_INT);
2746       __ load_stack_address_monitor(0, lock);
2747 
2748       CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL, x->check_flag(Instruction::DeoptimizeOnException));
2749       CodeStub* slow_path = new MonitorEnterStub(obj, lock, info);
2750 
2751       // receiver is guaranteed non-NULL so don't need CodeEmitInfo
2752       __ lock_object(syncTempOpr(), obj, lock, new_register(T_OBJECT), slow_path, NULL);
2753     }
2754   }
2755 
2756   // increment invocation counters if needed
2757   if (!method()->is_accessor()) { // Accessors do not have MDOs, so no counting.
2758     profile_parameters(x);
2759     CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL, false);
2760     increment_invocation_counter(info);
2761   }
2762 
2763   // all blocks with a successor must end with an unconditional jump
2764   // to the successor even if they are consecutive
2765   __ jump(x->default_sux());
2766 }
2767 
2768 
2769 void LIRGenerator::do_OsrEntry(OsrEntry* x) {
2770   // construct our frame and model the production of incoming pointer
2771   // to the OSR buffer.
2772   __ osr_entry(LIR_Assembler::osrBufferPointer());
2773   LIR_Opr result = rlock_result(x);
2774   __ move(LIR_Assembler::osrBufferPointer(), result);
2775 }
2776 
2777 
2778 void LIRGenerator::invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list) {


3098     break;
3099   case vmIntrinsics::_fullFence :
3100     if (os::is_MP()) __ membar();
3101     break;
3102 
3103   case vmIntrinsics::_Reference_get:
3104     do_Reference_get(x);
3105     break;
3106 
3107   case vmIntrinsics::_updateCRC32:
3108   case vmIntrinsics::_updateBytesCRC32:
3109   case vmIntrinsics::_updateByteBufferCRC32:
3110     do_update_CRC32(x);
3111     break;
3112 
3113   default: ShouldNotReachHere(); break;
3114   }
3115 }
3116 
3117 void LIRGenerator::profile_arguments(ProfileCall* x) {
3118   if (compilation()->profile_arguments()) {
3119     int bci = x->bci_of_invoke();
3120     ciMethodData* md = x->method()->method_data_or_null();
3121     ciProfileData* data = md->bci_to_data(bci);
3122     if ((data->is_CallTypeData() && data->as_CallTypeData()->has_arguments()) ||
3123         (data->is_VirtualCallTypeData() && data->as_VirtualCallTypeData()->has_arguments())) {
3124       ByteSize extra = data->is_CallTypeData() ? CallTypeData::args_data_offset() : VirtualCallTypeData::args_data_offset();
3125       int base_offset = md->byte_offset_of_slot(data, extra);
3126       LIR_Opr mdp = LIR_OprFact::illegalOpr;
3127       ciTypeStackSlotEntries* args = data->is_CallTypeData() ? ((ciCallTypeData*)data)->args() : ((ciVirtualCallTypeData*)data)->args();
3128 
3129       Bytecodes::Code bc = x->method()->java_code_at_bci(bci);
3130       int start = 0;
3131       int stop = data->is_CallTypeData() ? ((ciCallTypeData*)data)->number_of_arguments() : ((ciVirtualCallTypeData*)data)->number_of_arguments();
3132       if (x->nb_profiled_args() < stop) {
3133         // if called through method handle invoke, some arguments may have been popped
3134         stop = x->nb_profiled_args();
3135       }
3136       ciSignature* sig = x->callee()->signature();
3137       // method handle call to virtual method
3138       bool has_receiver = x->inlined() && !x->callee()->is_static() && !Bytecodes::has_receiver(bc);
3139       ciSignatureStream sig_stream(sig, has_receiver ? x->callee()->holder() : NULL);
3140       for (int i = 0; i < stop; i++) {
3141         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,
3143                                           args->type(i), x->profiled_arg_at(i+start), mdp,
3144                                           !x->arg_needs_null_check(i+start), sig_stream.next_klass());
3145         if (exact != NULL) {
3146           md->set_argument_type(bci, i, exact);
3147         }
3148       }
3149     } else {
3150 #ifdef ASSERT
3151       Bytecodes::Code code = x->method()->raw_code_at_bci(x->bci_of_invoke());
3152       int n = x->nb_profiled_args();
3153       assert(MethodData::profile_parameters() && x->inlined() &&
3154              ((code == Bytecodes::_invokedynamic && n <= 1) || (code == Bytecodes::_invokehandle && n <= 2)),
3155              "only at JSR292 bytecodes");
3156 #endif
3157     }
3158   }
3159 }
3160 
3161 // profile parameters on entry to an inlined method
3162 void LIRGenerator::profile_parameters_at_call(ProfileCall* x) {
3163   if (compilation()->profile_parameters() && x->inlined()) {
3164     ciMethodData* md = x->callee()->method_data_or_null();
3165     if (md != NULL) {
3166       ciParametersTypeData* parameters_type_data = md->parameters_type_data();
3167       if (parameters_type_data != NULL) {
3168         ciTypeStackSlotEntries* parameters =  parameters_type_data->parameters();
3169         LIR_Opr mdp = LIR_OprFact::illegalOpr;
3170         bool has_receiver = !x->callee()->is_static();
3171         ciSignature* sig = x->callee()->signature();
3172         ciSignatureStream sig_stream(sig, has_receiver ? x->callee()->holder() : NULL);
3173         int i = 0; // to iterate on the Instructions
3174         Value arg = x->recv();
3175         bool not_null = false;
3176         int bci = x->bci_of_invoke();
3177         Bytecodes::Code bc = x->method()->java_code_at_bci(bci);
3178         // The first parameter is the receiver so that's what we start
3179         // with if it exists. On exception if method handle call to
3180         // virtual method has receiver in the args list
3181         if (arg == NULL || !Bytecodes::has_receiver(bc)) {
3182           i = 1;
3183           arg = x->profiled_arg_at(0);
3184           not_null = !x->arg_needs_null_check(0);
3185         }
3186         int k = 0; // to iterate on the profile data
3187         for (;;) {
3188           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)),
3190                                             in_bytes(ParametersTypeData::type_offset(k)) - in_bytes(ParametersTypeData::type_offset(0)),
3191                                             profiled_k, arg, mdp, not_null, sig_stream.next_klass());
3192           // If the profile is known statically set it once for all and do not emit any code
3193           if (exact != NULL) {
3194             md->set_parameter_type(k, exact);
3195           }
3196           k++;
3197           if (k >= parameters_type_data->number_of_parameters()) {
3198 #ifdef ASSERT
3199             int extra = 0;
3200             if (MethodData::profile_arguments() && TypeProfileParmsLimit != -1 &&
3201                 x->nb_profiled_args() >= TypeProfileParmsLimit &&
3202                 x->recv() != NULL && Bytecodes::has_receiver(bc)) {
3203               extra += 1;
3204             }
3205             assert(i == x->nb_profiled_args() - extra || (TypeProfileParmsLimit != -1 && TypeProfileArgsLimit > TypeProfileParmsLimit), "unused parameters?");
3206 #endif
3207             break;
3208           }
3209           arg = x->profiled_arg_at(i);
3210           not_null = !x->arg_needs_null_check(i);
3211           i++;
3212         }
3213       }
3214     }
3215   }
3216 }
3217 
3218 void LIRGenerator::do_ProfileCall(ProfileCall* x) {
3219   // Need recv in a temporary register so it interferes with the other temporaries
3220   LIR_Opr recv = LIR_OprFact::illegalOpr;
3221   LIR_Opr mdo = new_register(T_OBJECT);
3222   // tmp is used to hold the counters on SPARC
3223   LIR_Opr tmp = new_pointer_register();
3224 
3225   if (x->nb_profiled_args() > 0) {
3226     profile_arguments(x);
3227   }
3228   
3229   // profile parameters on inlined method entry including receiver
3230   if (x->recv() != NULL || x->nb_profiled_args() > 0) {
3231     profile_parameters_at_call(x);
3232   }
3233 
3234   if (x->recv() != NULL) {
3235     LIRItem value(x->recv(), this);
3236     value.load_item();
3237     recv = new_register(T_OBJECT);
3238     __ move(value.result(), recv);
3239   }
3240   __ profile_call(x->method(), x->bci_of_invoke(), x->callee(), mdo, recv, tmp, x->known_holder());
3241 }
3242 
3243 void LIRGenerator::do_ProfileReturnType(ProfileReturnType* x) {
3244   int bci = x->bci_of_invoke();
3245   ciMethodData* md = x->method()->method_data_or_null();
3246   ciProfileData* data = md->bci_to_data(bci);
3247   assert(data->is_CallTypeData() || data->is_VirtualCallTypeData(), "wrong profile data type");
3248   ciReturnTypeEntry* ret = data->is_CallTypeData() ? ((ciCallTypeData*)data)->ret() : ((ciVirtualCallTypeData*)data)->ret();
3249   LIR_Opr mdp = LIR_OprFact::illegalOpr;
3250   ciKlass* exact = profile_arg_type(md, 0, md->byte_offset_of_slot(data, ret->type_offset()),
3251                                     ret->type(), x->ret(), mdp,


src/share/vm/c1/c1_LIRGenerator.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File