comparison src/share/vm/classfile/systemDictionary.cpp @ 1793:d257356e35f0

6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions Reviewed-by: never
author jrose
date Mon, 13 Sep 2010 23:24:30 -0700
parents 083fde3b838e
children 87d6a4d1ecbc
comparison
equal deleted inserted replaced
1792:d20603ee9e10 1793:d257356e35f0
2359 if (spe == NULL || spe->property_oop() == NULL) { 2359 if (spe == NULL || spe->property_oop() == NULL) {
2360 spe = NULL; 2360 spe = NULL;
2361 // Must create lots of stuff here, but outside of the SystemDictionary lock. 2361 // Must create lots of stuff here, but outside of the SystemDictionary lock.
2362 if (THREAD->is_Compiler_thread()) 2362 if (THREAD->is_Compiler_thread())
2363 return NULL; // do not attempt from within compiler 2363 return NULL; // do not attempt from within compiler
2364 bool for_invokeGeneric = (name_id == vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name));
2364 bool found_on_bcp = false; 2365 bool found_on_bcp = false;
2365 Handle mt = find_method_handle_type(signature(), accessing_klass, found_on_bcp, CHECK_NULL); 2366 Handle mt = find_method_handle_type(signature(), accessing_klass,
2367 for_invokeGeneric,
2368 found_on_bcp, CHECK_NULL);
2366 KlassHandle mh_klass = SystemDictionaryHandles::MethodHandle_klass(); 2369 KlassHandle mh_klass = SystemDictionaryHandles::MethodHandle_klass();
2367 methodHandle m = methodOopDesc::make_invoke_method(mh_klass, name, signature, 2370 methodHandle m = methodOopDesc::make_invoke_method(mh_klass, name, signature,
2368 mt, CHECK_NULL); 2371 mt, CHECK_NULL);
2369 // Now grab the lock. We might have to throw away the new method, 2372 // Now grab the lock. We might have to throw away the new method,
2370 // if a racing thread has managed to install one at the same time. 2373 // if a racing thread has managed to install one at the same time.
2391 // signature, as interpreted relative to the given class loader. 2394 // signature, as interpreted relative to the given class loader.
2392 // Because of class loader constraints, all method handle usage must be 2395 // Because of class loader constraints, all method handle usage must be
2393 // consistent with this loader. 2396 // consistent with this loader.
2394 Handle SystemDictionary::find_method_handle_type(symbolHandle signature, 2397 Handle SystemDictionary::find_method_handle_type(symbolHandle signature,
2395 KlassHandle accessing_klass, 2398 KlassHandle accessing_klass,
2399 bool for_invokeGeneric,
2396 bool& return_bcp_flag, 2400 bool& return_bcp_flag,
2397 TRAPS) { 2401 TRAPS) {
2398 Handle class_loader, protection_domain; 2402 Handle class_loader, protection_domain;
2399 bool is_on_bcp = true; // keep this true as long as we can materialize from the boot classloader 2403 bool is_on_bcp = true; // keep this true as long as we can materialize from the boot classloader
2400 Handle empty; 2404 Handle empty;
2446 JavaCalls::call_static(&result, 2450 JavaCalls::call_static(&result,
2447 SystemDictionary::MethodHandleNatives_klass(), 2451 SystemDictionary::MethodHandleNatives_klass(),
2448 vmSymbols::findMethodHandleType_name(), 2452 vmSymbols::findMethodHandleType_name(),
2449 vmSymbols::findMethodHandleType_signature(), 2453 vmSymbols::findMethodHandleType_signature(),
2450 &args, CHECK_(empty)); 2454 &args, CHECK_(empty));
2455 Handle method_type(THREAD, (oop) result.get_jobject());
2456
2457 if (for_invokeGeneric) {
2458 // call sun.dyn.MethodHandleNatives::notifyGenericMethodType(MethodType) -> void
2459 JavaCallArguments args(Handle(THREAD, method_type()));
2460 JavaValue no_result(T_VOID);
2461 JavaCalls::call_static(&no_result,
2462 SystemDictionary::MethodHandleNatives_klass(),
2463 vmSymbols::notifyGenericMethodType_name(),
2464 vmSymbols::notifyGenericMethodType_signature(),
2465 &args, THREAD);
2466 if (HAS_PENDING_EXCEPTION) {
2467 // If the notification fails, just kill it.
2468 CLEAR_PENDING_EXCEPTION;
2469 }
2470 }
2451 2471
2452 // report back to the caller with the MethodType and the "on_bcp" flag 2472 // report back to the caller with the MethodType and the "on_bcp" flag
2453 return_bcp_flag = is_on_bcp; 2473 return_bcp_flag = is_on_bcp;
2454 return Handle(THREAD, (oop) result.get_jobject()); 2474 return method_type;
2455 } 2475 }
2456 2476
2457 // Ask Java code to find or construct a method handle constant. 2477 // Ask Java code to find or construct a method handle constant.
2458 Handle SystemDictionary::link_method_handle_constant(KlassHandle caller, 2478 Handle SystemDictionary::link_method_handle_constant(KlassHandle caller,
2459 int ref_kind, //e.g., JVM_REF_invokeVirtual 2479 int ref_kind, //e.g., JVM_REF_invokeVirtual
2464 Handle empty; 2484 Handle empty;
2465 Handle name = java_lang_String::create_from_symbol(name_sym(), CHECK_(empty)); 2485 Handle name = java_lang_String::create_from_symbol(name_sym(), CHECK_(empty));
2466 Handle type; 2486 Handle type;
2467 if (signature->utf8_length() > 0 && signature->byte_at(0) == '(') { 2487 if (signature->utf8_length() > 0 && signature->byte_at(0) == '(') {
2468 bool ignore_is_on_bcp = false; 2488 bool ignore_is_on_bcp = false;
2469 type = find_method_handle_type(signature, caller, ignore_is_on_bcp, CHECK_(empty)); 2489 type = find_method_handle_type(signature, caller, false, ignore_is_on_bcp, CHECK_(empty));
2470 } else { 2490 } else {
2471 SignatureStream ss(signature(), false); 2491 SignatureStream ss(signature(), false);
2472 if (!ss.is_done()) { 2492 if (!ss.is_done()) {
2473 oop mirror = ss.as_java_mirror(caller->class_loader(), caller->protection_domain(), 2493 oop mirror = ss.as_java_mirror(caller->class_loader(), caller->protection_domain(),
2474 SignatureStream::NCDFError, CHECK_(empty)); 2494 SignatureStream::NCDFError, CHECK_(empty));