hotspot/src/share/vm/prims/methodHandles.cpp
changeset 9967 9ddc1c490930
parent 9963 4a783069663c
child 9976 6fef34e63df1
equal deleted inserted replaced
9966:b30a5eb9bcff 9967:9ddc1c490930
  2968   // TO DO: expand at least some of the MemberNames, to avoid massive callbacks
  2968   // TO DO: expand at least some of the MemberNames, to avoid massive callbacks
  2969   return res;
  2969   return res;
  2970 }
  2970 }
  2971 JVM_END
  2971 JVM_END
  2972 
  2972 
       
  2973 methodOop MethodHandles::resolve_raise_exception_method(TRAPS) {
       
  2974   if (_raise_exception_method != NULL) {
       
  2975     // no need to do it twice
       
  2976     return raise_exception_method();
       
  2977   }
       
  2978   // LinkResolver::resolve_invokedynamic can reach this point
       
  2979   // because an invokedynamic has failed very early (7049415)
       
  2980   KlassHandle MHN_klass = SystemDictionaryHandles::MethodHandleNatives_klass();
       
  2981   if (MHN_klass.not_null()) {
       
  2982     TempNewSymbol raiseException_name = SymbolTable::new_symbol("raiseException", CHECK_NULL);
       
  2983     TempNewSymbol raiseException_sig = SymbolTable::new_symbol("(ILjava/lang/Object;Ljava/lang/Object;)V", CHECK_NULL);
       
  2984     methodOop raiseException_method  = instanceKlass::cast(MHN_klass->as_klassOop())
       
  2985                   ->find_method(raiseException_name, raiseException_sig);
       
  2986     if (raiseException_method != NULL && raiseException_method->is_static()) {
       
  2987       return raiseException_method;
       
  2988     }
       
  2989   }
       
  2990   // not found; let the caller deal with it
       
  2991   return NULL;
       
  2992 }
       
  2993 void MethodHandles::raise_exception(int code, oop actual, oop required, TRAPS) {
       
  2994   methodOop raiseException_method = resolve_raise_exception_method(CHECK);
       
  2995   if (raiseException_method != NULL &&
       
  2996       instanceKlass::cast(raiseException_method->method_holder())->is_not_initialized()) {
       
  2997     instanceKlass::cast(raiseException_method->method_holder())->initialize(CHECK);
       
  2998     // it had better be resolved by now, or maybe JSR 292 failed to load
       
  2999     raiseException_method = raise_exception_method();
       
  3000   }
       
  3001   if (raiseException_method == NULL) {
       
  3002     THROW_MSG(vmSymbols::java_lang_InternalError(), "no raiseException method");
       
  3003   }
       
  3004   JavaCallArguments args;
       
  3005   args.push_int(code);
       
  3006   args.push_oop(actual);
       
  3007   args.push_oop(required);
       
  3008   JavaValue result(T_VOID);
       
  3009   JavaCalls::call(&result, raiseException_method, &args, CHECK);
       
  3010 }
       
  3011 
  2973 JVM_ENTRY(jobject, MH_invoke_UOE(JNIEnv *env, jobject igmh, jobjectArray igargs)) {
  3012 JVM_ENTRY(jobject, MH_invoke_UOE(JNIEnv *env, jobject igmh, jobjectArray igargs)) {
  2974     TempNewSymbol UOE_name = SymbolTable::new_symbol("java/lang/UnsupportedOperationException", CHECK_NULL);
  3013     TempNewSymbol UOE_name = SymbolTable::new_symbol("java/lang/UnsupportedOperationException", CHECK_NULL);
  2975     THROW_MSG_NULL(UOE_name, "MethodHandle.invoke cannot be invoked reflectively");
  3014     THROW_MSG_NULL(UOE_name, "MethodHandle.invoke cannot be invoked reflectively");
  2976     return NULL;
  3015     return NULL;
  2977 }
  3016 }
  3057       env->ExceptionClear();
  3096       env->ExceptionClear();
  3058     }
  3097     }
  3059   }
  3098   }
  3060 
  3099 
  3061   if (enable_MH) {
  3100   if (enable_MH) {
  3062     KlassHandle MHN_klass = SystemDictionaryHandles::MethodHandleNatives_klass();
  3101     methodOop raiseException_method = MethodHandles::resolve_raise_exception_method(CHECK);
  3063     if (MHN_klass.not_null()) {
  3102     if (raiseException_method != NULL) {
  3064       TempNewSymbol raiseException_name = SymbolTable::new_symbol("raiseException", CHECK);
  3103       MethodHandles::set_raise_exception_method(raiseException_method);
  3065       TempNewSymbol raiseException_sig = SymbolTable::new_symbol("(ILjava/lang/Object;Ljava/lang/Object;)V", CHECK);
       
  3066       methodOop raiseException_method  = instanceKlass::cast(MHN_klass->as_klassOop())
       
  3067                     ->find_method(raiseException_name, raiseException_sig);
       
  3068       if (raiseException_method != NULL && raiseException_method->is_static()) {
       
  3069         MethodHandles::set_raise_exception_method(raiseException_method);
       
  3070       } else {
       
  3071         warning("JSR 292 method handle code is mismatched to this JVM.  Disabling support.");
       
  3072         enable_MH = false;
       
  3073       }
       
  3074     } else {
  3104     } else {
       
  3105       warning("JSR 292 method handle code is mismatched to this JVM.  Disabling support.");
  3075       enable_MH = false;
  3106       enable_MH = false;
  3076     }
  3107     }
  3077   }
  3108   }
  3078 
  3109 
  3079   if (enable_MH) {
  3110   if (enable_MH) {