src/share/vm/prims/methodHandles.cpp

changeset 2941
60b8287df30e
parent 2937
5ac411b3b8fc
child 2950
cba7b5c2d53f
     1.1 --- a/src/share/vm/prims/methodHandles.cpp	Tue May 31 10:05:36 2011 -0700
     1.2 +++ b/src/share/vm/prims/methodHandles.cpp	Wed Jun 01 23:25:20 2011 -0700
     1.3 @@ -2970,6 +2970,45 @@
     1.4  }
     1.5  JVM_END
     1.6  
     1.7 +methodOop MethodHandles::resolve_raise_exception_method(TRAPS) {
     1.8 +  if (_raise_exception_method != NULL) {
     1.9 +    // no need to do it twice
    1.10 +    return raise_exception_method();
    1.11 +  }
    1.12 +  // LinkResolver::resolve_invokedynamic can reach this point
    1.13 +  // because an invokedynamic has failed very early (7049415)
    1.14 +  KlassHandle MHN_klass = SystemDictionaryHandles::MethodHandleNatives_klass();
    1.15 +  if (MHN_klass.not_null()) {
    1.16 +    TempNewSymbol raiseException_name = SymbolTable::new_symbol("raiseException", CHECK_NULL);
    1.17 +    TempNewSymbol raiseException_sig = SymbolTable::new_symbol("(ILjava/lang/Object;Ljava/lang/Object;)V", CHECK_NULL);
    1.18 +    methodOop raiseException_method  = instanceKlass::cast(MHN_klass->as_klassOop())
    1.19 +                  ->find_method(raiseException_name, raiseException_sig);
    1.20 +    if (raiseException_method != NULL && raiseException_method->is_static()) {
    1.21 +      return raiseException_method;
    1.22 +    }
    1.23 +  }
    1.24 +  // not found; let the caller deal with it
    1.25 +  return NULL;
    1.26 +}
    1.27 +void MethodHandles::raise_exception(int code, oop actual, oop required, TRAPS) {
    1.28 +  methodOop raiseException_method = resolve_raise_exception_method(CHECK);
    1.29 +  if (raiseException_method != NULL &&
    1.30 +      instanceKlass::cast(raiseException_method->method_holder())->is_not_initialized()) {
    1.31 +    instanceKlass::cast(raiseException_method->method_holder())->initialize(CHECK);
    1.32 +    // it had better be resolved by now, or maybe JSR 292 failed to load
    1.33 +    raiseException_method = raise_exception_method();
    1.34 +  }
    1.35 +  if (raiseException_method == NULL) {
    1.36 +    THROW_MSG(vmSymbols::java_lang_InternalError(), "no raiseException method");
    1.37 +  }
    1.38 +  JavaCallArguments args;
    1.39 +  args.push_int(code);
    1.40 +  args.push_oop(actual);
    1.41 +  args.push_oop(required);
    1.42 +  JavaValue result(T_VOID);
    1.43 +  JavaCalls::call(&result, raiseException_method, &args, CHECK);
    1.44 +}
    1.45 +
    1.46  JVM_ENTRY(jobject, MH_invoke_UOE(JNIEnv *env, jobject igmh, jobjectArray igargs)) {
    1.47      TempNewSymbol UOE_name = SymbolTable::new_symbol("java/lang/UnsupportedOperationException", CHECK_NULL);
    1.48      THROW_MSG_NULL(UOE_name, "MethodHandle.invoke cannot be invoked reflectively");
    1.49 @@ -3059,19 +3098,11 @@
    1.50    }
    1.51  
    1.52    if (enable_MH) {
    1.53 -    KlassHandle MHN_klass = SystemDictionaryHandles::MethodHandleNatives_klass();
    1.54 -    if (MHN_klass.not_null()) {
    1.55 -      TempNewSymbol raiseException_name = SymbolTable::new_symbol("raiseException", CHECK);
    1.56 -      TempNewSymbol raiseException_sig = SymbolTable::new_symbol("(ILjava/lang/Object;Ljava/lang/Object;)V", CHECK);
    1.57 -      methodOop raiseException_method  = instanceKlass::cast(MHN_klass->as_klassOop())
    1.58 -                    ->find_method(raiseException_name, raiseException_sig);
    1.59 -      if (raiseException_method != NULL && raiseException_method->is_static()) {
    1.60 -        MethodHandles::set_raise_exception_method(raiseException_method);
    1.61 -      } else {
    1.62 -        warning("JSR 292 method handle code is mismatched to this JVM.  Disabling support.");
    1.63 -        enable_MH = false;
    1.64 -      }
    1.65 +    methodOop raiseException_method = MethodHandles::resolve_raise_exception_method(CHECK);
    1.66 +    if (raiseException_method != NULL) {
    1.67 +      MethodHandles::set_raise_exception_method(raiseException_method);
    1.68      } else {
    1.69 +      warning("JSR 292 method handle code is mismatched to this JVM.  Disabling support.");
    1.70        enable_MH = false;
    1.71      }
    1.72    }

mercurial