src/share/vm/opto/doCall.cpp

changeset 1573
dd57230ba8fe
parent 1572
97125851f396
child 1592
c3b315a0d58a
     1.1 --- a/src/share/vm/opto/doCall.cpp	Tue Jan 05 13:05:58 2010 +0100
     1.2 +++ b/src/share/vm/opto/doCall.cpp	Tue Jan 05 15:21:25 2010 +0100
     1.3 @@ -224,16 +224,61 @@
     1.4      }
     1.5    }
     1.6  
     1.7 +  // Do MethodHandle calls.
     1.8 +  if (call_method->is_method_handle_invoke()) {
     1.9 +    if (jvms->method()->java_code_at_bci(jvms->bci()) != Bytecodes::_invokedynamic) {
    1.10 +      GraphKit kit(jvms);
    1.11 +      Node* n = kit.argument(0);
    1.12 +
    1.13 +      if (n->Opcode() == Op_ConP) {
    1.14 +        const TypeOopPtr* oop_ptr = n->bottom_type()->is_oopptr();
    1.15 +        ciObject* const_oop = oop_ptr->const_oop();
    1.16 +        ciMethodHandle* method_handle = const_oop->as_method_handle();
    1.17 +
    1.18 +        // Set the actually called method to have access to the class
    1.19 +        // and signature in the MethodHandleCompiler.
    1.20 +        method_handle->set_callee(call_method);
    1.21 +
    1.22 +        // Get an adapter for the MethodHandle.
    1.23 +        ciMethod* target_method = method_handle->get_method_handle_adapter();
    1.24 +
    1.25 +        CallGenerator* hit_cg = this->call_generator(target_method, vtable_index, false, jvms, true, prof_factor);
    1.26 +        if (hit_cg != NULL && hit_cg->is_inline())
    1.27 +          return hit_cg;
    1.28 +      }
    1.29 +
    1.30 +      return CallGenerator::for_direct_call(call_method);
    1.31 +    }
    1.32 +    else {
    1.33 +      // Get the MethodHandle from the CallSite.
    1.34 +      ciMethod* caller_method = jvms->method();
    1.35 +      ciBytecodeStream str(caller_method);
    1.36 +      str.force_bci(jvms->bci());  // Set the stream to the invokedynamic bci.
    1.37 +      ciCallSite*     call_site     = str.get_call_site();
    1.38 +      ciMethodHandle* method_handle = call_site->get_target();
    1.39 +
    1.40 +      // Set the actually called method to have access to the class
    1.41 +      // and signature in the MethodHandleCompiler.
    1.42 +      method_handle->set_callee(call_method);
    1.43 +
    1.44 +      // Get an adapter for the MethodHandle.
    1.45 +      ciMethod* target_method = method_handle->get_invokedynamic_adapter();
    1.46 +
    1.47 +      CallGenerator* hit_cg = this->call_generator(target_method, vtable_index, false, jvms, true, prof_factor);
    1.48 +      if (hit_cg != NULL && hit_cg->is_inline()) {
    1.49 +        CallGenerator* miss_cg = CallGenerator::for_dynamic_call(call_method);
    1.50 +        return CallGenerator::for_predicted_dynamic_call(method_handle, miss_cg, hit_cg, prof_factor);
    1.51 +      }
    1.52 +
    1.53 +      // If something failed, generate a normal dynamic call.
    1.54 +      return CallGenerator::for_dynamic_call(call_method);
    1.55 +    }
    1.56 +  }
    1.57 +
    1.58    // There was no special inlining tactic, or it bailed out.
    1.59    // Use a more generic tactic, like a simple call.
    1.60    if (call_is_virtual) {
    1.61      return CallGenerator::for_virtual_call(call_method, vtable_index);
    1.62 -  } else if (call_method->is_method_handle_invoke()) {
    1.63 -    if (jvms->method()->java_code_at_bci(jvms->bci()) == Bytecodes::_invokedynamic)
    1.64 -      return CallGenerator::for_dynamic_call(call_method);
    1.65 -    else
    1.66 -      // %%% if the target MH is a compile-time constant, we should try to inline it
    1.67 -      return CallGenerator::for_direct_call(call_method);
    1.68    } else {
    1.69      // Class Hierarchy Analysis or Type Profile reveals a unique target,
    1.70      // or it is a static or special call.

mercurial