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 5462 : 8026251: New type profiling points: parameters to methods
Summary: x86 interpreter and c1 type profiling for parameters on method entries
Reviewed-by:


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) {


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 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 // profile parameters on entry to the root of the compilation
2647 void LIRGenerator::profile_parameters(Base* x) {
2648   if (compilation()->profile_parameters()) {
2649     CallingConvention* args = compilation()->frame_map()->incoming_arguments();
2650     ciMethodData* md = scope()->method()->method_data_or_null();
2651     assert(md != NULL, "Sanity");
2652 
2653     if (md->parameters_type_data() != NULL) {
2654       ciParametersTypeData* parameters_type_data = md->parameters_type_data();
2655       ciTypeStackSlotEntries* parameters =  parameters_type_data->parameters();
2656       LIR_Opr mdp = LIR_OprFact::illegalOpr;
2657       for (int java_index = 0, i = 0, j = 0; j < parameters_type_data->number_of_parameters(); i++) {
2658         LIR_Opr src = args->at(i);
2659         assert(!src->is_illegal(), "check");
2660         BasicType t = src->type();
2661         if (t == T_OBJECT || t == T_ARRAY) {
2662           intptr_t profiled_k = parameters->type(j);
2663           Local* local = x->state()->local_at(java_index)->as_Local();
2664           ciKlass* exact = profile_arg_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)),
2665                                             in_bytes(ParametersTypeData::type_offset(j)) - in_bytes(ParametersTypeData::type_offset(0)),
2666                                             profiled_k, local, mdp, false, local->declared_type()->as_klass());
2667           // If the profile is known statically set it once for all and do not emit any code
2668           if (exact != NULL) {
2669             md->set_parameter_type(j, exact);
2670           }
2671           j++;
2672         }
2673         java_index += type2size[t];
2674       }
2675     }
2676   }
2677 }
2678 
2679 void LIRGenerator::do_Base(Base* x) {
2680   __ std_entry(LIR_OprFact::illegalOpr);
2681   // Emit moves from physical registers / stack slots to virtual registers
2682   CallingConvention* args = compilation()->frame_map()->incoming_arguments();
2683   IRScope* irScope = compilation()->hir()->top_scope();
2684   int java_index = 0;
2685   for (int i = 0; i < args->length(); i++) {
2686     LIR_Opr src = args->at(i);
2687     assert(!src->is_illegal(), "check");
2688     BasicType t = src->type();
2689 
2690     // Types which are smaller than int are passed as int, so
2691     // correct the type which passed.
2692     switch (t) {
2693     case T_BYTE:
2694     case T_BOOLEAN:
2695     case T_SHORT:
2696     case T_CHAR:
2697       t = T_INT;
2698       break;


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


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