src/share/vm/c1/c1_LIRGenerator.cpp

changeset 5987
5ccbab1c69f3
parent 5980
252d541466ea
child 5994
9acbfe04b5c3
     1.1 --- a/src/share/vm/c1/c1_LIRGenerator.cpp	Mon Oct 21 17:34:27 2013 -0700
     1.2 +++ b/src/share/vm/c1/c1_LIRGenerator.cpp	Tue Oct 22 09:51:47 2013 +0200
     1.3 @@ -2647,6 +2647,39 @@
     1.4    return result;
     1.5  }
     1.6  
     1.7 +// profile parameters on entry to the root of the compilation
     1.8 +void LIRGenerator::profile_parameters(Base* x) {
     1.9 +  if (compilation()->profile_parameters()) {
    1.10 +    CallingConvention* args = compilation()->frame_map()->incoming_arguments();
    1.11 +    ciMethodData* md = scope()->method()->method_data_or_null();
    1.12 +    assert(md != NULL, "Sanity");
    1.13 +
    1.14 +    if (md->parameters_type_data() != NULL) {
    1.15 +      ciParametersTypeData* parameters_type_data = md->parameters_type_data();
    1.16 +      ciTypeStackSlotEntries* parameters =  parameters_type_data->parameters();
    1.17 +      LIR_Opr mdp = LIR_OprFact::illegalOpr;
    1.18 +      for (int java_index = 0, i = 0, j = 0; j < parameters_type_data->number_of_parameters(); i++) {
    1.19 +        LIR_Opr src = args->at(i);
    1.20 +        assert(!src->is_illegal(), "check");
    1.21 +        BasicType t = src->type();
    1.22 +        if (t == T_OBJECT || t == T_ARRAY) {
    1.23 +          intptr_t profiled_k = parameters->type(j);
    1.24 +          Local* local = x->state()->local_at(java_index)->as_Local();
    1.25 +          ciKlass* exact = profile_arg_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)),
    1.26 +                                            in_bytes(ParametersTypeData::type_offset(j)) - in_bytes(ParametersTypeData::type_offset(0)),
    1.27 +                                            profiled_k, local, mdp, false, local->declared_type()->as_klass());
    1.28 +          // If the profile is known statically set it once for all and do not emit any code
    1.29 +          if (exact != NULL) {
    1.30 +            md->set_parameter_type(j, exact);
    1.31 +          }
    1.32 +          j++;
    1.33 +        }
    1.34 +        java_index += type2size[t];
    1.35 +      }
    1.36 +    }
    1.37 +  }
    1.38 +}
    1.39 +
    1.40  void LIRGenerator::do_Base(Base* x) {
    1.41    __ std_entry(LIR_OprFact::illegalOpr);
    1.42    // Emit moves from physical registers / stack slots to virtual registers
    1.43 @@ -2722,6 +2755,7 @@
    1.44  
    1.45    // increment invocation counters if needed
    1.46    if (!method()->is_accessor()) { // Accessors do not have MDOs, so no counting.
    1.47 +    profile_parameters(x);
    1.48      CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL, false);
    1.49      increment_invocation_counter(info);
    1.50    }
    1.51 @@ -3081,11 +3115,12 @@
    1.52  }
    1.53  
    1.54  void LIRGenerator::profile_arguments(ProfileCall* x) {
    1.55 -  if (MethodData::profile_arguments()) {
    1.56 +  if (compilation()->profile_arguments()) {
    1.57      int bci = x->bci_of_invoke();
    1.58      ciMethodData* md = x->method()->method_data_or_null();
    1.59      ciProfileData* data = md->bci_to_data(bci);
    1.60 -    if (data->is_CallTypeData() || data->is_VirtualCallTypeData()) {
    1.61 +    if ((data->is_CallTypeData() && data->as_CallTypeData()->has_arguments()) ||
    1.62 +        (data->is_VirtualCallTypeData() && data->as_VirtualCallTypeData()->has_arguments())) {
    1.63        ByteSize extra = data->is_CallTypeData() ? CallTypeData::args_data_offset() : VirtualCallTypeData::args_data_offset();
    1.64        int base_offset = md->byte_offset_of_slot(data, extra);
    1.65        LIR_Opr mdp = LIR_OprFact::illegalOpr;
    1.66 @@ -3111,6 +3146,71 @@
    1.67            md->set_argument_type(bci, i, exact);
    1.68          }
    1.69        }
    1.70 +    } else {
    1.71 +#ifdef ASSERT
    1.72 +      Bytecodes::Code code = x->method()->raw_code_at_bci(x->bci_of_invoke());
    1.73 +      int n = x->nb_profiled_args();
    1.74 +      assert(MethodData::profile_parameters() && x->inlined() &&
    1.75 +             ((code == Bytecodes::_invokedynamic && n <= 1) || (code == Bytecodes::_invokehandle && n <= 2)),
    1.76 +             "only at JSR292 bytecodes");
    1.77 +#endif
    1.78 +    }
    1.79 +  }
    1.80 +}
    1.81 +
    1.82 +// profile parameters on entry to an inlined method
    1.83 +void LIRGenerator::profile_parameters_at_call(ProfileCall* x) {
    1.84 +  if (compilation()->profile_parameters() && x->inlined()) {
    1.85 +    ciMethodData* md = x->callee()->method_data_or_null();
    1.86 +    if (md != NULL) {
    1.87 +      ciParametersTypeData* parameters_type_data = md->parameters_type_data();
    1.88 +      if (parameters_type_data != NULL) {
    1.89 +        ciTypeStackSlotEntries* parameters =  parameters_type_data->parameters();
    1.90 +        LIR_Opr mdp = LIR_OprFact::illegalOpr;
    1.91 +        bool has_receiver = !x->callee()->is_static();
    1.92 +        ciSignature* sig = x->callee()->signature();
    1.93 +        ciSignatureStream sig_stream(sig, has_receiver ? x->callee()->holder() : NULL);
    1.94 +        int i = 0; // to iterate on the Instructions
    1.95 +        Value arg = x->recv();
    1.96 +        bool not_null = false;
    1.97 +        int bci = x->bci_of_invoke();
    1.98 +        Bytecodes::Code bc = x->method()->java_code_at_bci(bci);
    1.99 +        // The first parameter is the receiver so that's what we start
   1.100 +        // with if it exists. On exception if method handle call to
   1.101 +        // virtual method has receiver in the args list
   1.102 +        if (arg == NULL || !Bytecodes::has_receiver(bc)) {
   1.103 +          i = 1;
   1.104 +          arg = x->profiled_arg_at(0);
   1.105 +          not_null = !x->arg_needs_null_check(0);
   1.106 +        }
   1.107 +        int k = 0; // to iterate on the profile data
   1.108 +        for (;;) {
   1.109 +          intptr_t profiled_k = parameters->type(k);
   1.110 +          ciKlass* exact = profile_arg_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)),
   1.111 +                                            in_bytes(ParametersTypeData::type_offset(k)) - in_bytes(ParametersTypeData::type_offset(0)),
   1.112 +                                            profiled_k, arg, mdp, not_null, sig_stream.next_klass());
   1.113 +          // If the profile is known statically set it once for all and do not emit any code
   1.114 +          if (exact != NULL) {
   1.115 +            md->set_parameter_type(k, exact);
   1.116 +          }
   1.117 +          k++;
   1.118 +          if (k >= parameters_type_data->number_of_parameters()) {
   1.119 +#ifdef ASSERT
   1.120 +            int extra = 0;
   1.121 +            if (MethodData::profile_arguments() && TypeProfileParmsLimit != -1 &&
   1.122 +                x->nb_profiled_args() >= TypeProfileParmsLimit &&
   1.123 +                x->recv() != NULL && Bytecodes::has_receiver(bc)) {
   1.124 +              extra += 1;
   1.125 +            }
   1.126 +            assert(i == x->nb_profiled_args() - extra || (TypeProfileParmsLimit != -1 && TypeProfileArgsLimit > TypeProfileParmsLimit), "unused parameters?");
   1.127 +#endif
   1.128 +            break;
   1.129 +          }
   1.130 +          arg = x->profiled_arg_at(i);
   1.131 +          not_null = !x->arg_needs_null_check(i);
   1.132 +          i++;
   1.133 +        }
   1.134 +      }
   1.135      }
   1.136    }
   1.137  }
   1.138 @@ -3126,6 +3226,11 @@
   1.139      profile_arguments(x);
   1.140    }
   1.141  
   1.142 +  // profile parameters on inlined method entry including receiver
   1.143 +  if (x->recv() != NULL || x->nb_profiled_args() > 0) {
   1.144 +    profile_parameters_at_call(x);
   1.145 +  }
   1.146 +
   1.147    if (x->recv() != NULL) {
   1.148      LIRItem value(x->recv(), this);
   1.149      value.load_item();

mercurial