1.1 --- a/src/share/vm/interpreter/linkResolver.cpp Thu Jun 04 23:11:44 2015 -0700 1.2 +++ b/src/share/vm/interpreter/linkResolver.cpp Thu May 07 15:05:46 2015 +0200 1.3 @@ -1592,6 +1592,26 @@ 1.4 result.set_handle(resolved_method, resolved_appendix, resolved_method_type, CHECK); 1.5 } 1.6 1.7 +static void wrap_invokedynamic_exception(TRAPS) { 1.8 + if (HAS_PENDING_EXCEPTION) { 1.9 + if (TraceMethodHandles) { 1.10 + tty->print_cr("invokedynamic throws BSME for " INTPTR_FORMAT, p2i((void *)PENDING_EXCEPTION)); 1.11 + PENDING_EXCEPTION->print(); 1.12 + } 1.13 + if (PENDING_EXCEPTION->is_a(SystemDictionary::BootstrapMethodError_klass())) { 1.14 + // throw these guys, since they are already wrapped 1.15 + return; 1.16 + } 1.17 + if (!PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) { 1.18 + // intercept only LinkageErrors which might have failed to wrap 1.19 + return; 1.20 + } 1.21 + // See the "Linking Exceptions" section for the invokedynamic instruction in the JVMS. 1.22 + Handle nested_exception(THREAD, PENDING_EXCEPTION); 1.23 + CLEAR_PENDING_EXCEPTION; 1.24 + THROW_CAUSE(vmSymbols::java_lang_BootstrapMethodError(), nested_exception) 1.25 + } 1.26 +} 1.27 1.28 void LinkResolver::resolve_invokedynamic(CallInfo& result, constantPoolHandle pool, int index, TRAPS) { 1.29 assert(EnableInvokeDynamic, ""); 1.30 @@ -1607,7 +1627,8 @@ 1.31 ConstantPoolCacheEntry* cpce = pool->invokedynamic_cp_cache_entry_at(index); 1.32 if (cpce->is_f1_null()) { 1.33 int pool_index = cpce->constant_pool_index(); 1.34 - oop bsm_info = pool->resolve_bootstrap_specifier_at(pool_index, CHECK); 1.35 + oop bsm_info = pool->resolve_bootstrap_specifier_at(pool_index, THREAD); 1.36 + wrap_invokedynamic_exception(CHECK); 1.37 assert(bsm_info != NULL, ""); 1.38 // FIXME: Cache this once per BootstrapMethods entry, not once per CONSTANT_InvokeDynamic. 1.39 bootstrap_specifier = Handle(THREAD, bsm_info); 1.40 @@ -1616,7 +1637,8 @@ 1.41 methodHandle method( THREAD, cpce->f1_as_method()); 1.42 Handle appendix( THREAD, cpce->appendix_if_resolved(pool)); 1.43 Handle method_type(THREAD, cpce->method_type_if_resolved(pool)); 1.44 - result.set_handle(method, appendix, method_type, CHECK); 1.45 + result.set_handle(method, appendix, method_type, THREAD); 1.46 + wrap_invokedynamic_exception(CHECK); 1.47 return; 1.48 } 1.49 1.50 @@ -1647,25 +1669,9 @@ 1.51 &resolved_appendix, 1.52 &resolved_method_type, 1.53 THREAD); 1.54 - if (HAS_PENDING_EXCEPTION) { 1.55 - if (TraceMethodHandles) { 1.56 - tty->print_cr("invokedynamic throws BSME for " INTPTR_FORMAT, p2i((void *)PENDING_EXCEPTION)); 1.57 - PENDING_EXCEPTION->print(); 1.58 - } 1.59 - if (PENDING_EXCEPTION->is_a(SystemDictionary::BootstrapMethodError_klass())) { 1.60 - // throw these guys, since they are already wrapped 1.61 - return; 1.62 - } 1.63 - if (!PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) { 1.64 - // intercept only LinkageErrors which might have failed to wrap 1.65 - return; 1.66 - } 1.67 - // See the "Linking Exceptions" section for the invokedynamic instruction in the JVMS. 1.68 - Handle nested_exception(THREAD, PENDING_EXCEPTION); 1.69 - CLEAR_PENDING_EXCEPTION; 1.70 - THROW_CAUSE(vmSymbols::java_lang_BootstrapMethodError(), nested_exception) 1.71 - } 1.72 - result.set_handle(resolved_method, resolved_appendix, resolved_method_type, CHECK); 1.73 + wrap_invokedynamic_exception(CHECK); 1.74 + result.set_handle(resolved_method, resolved_appendix, resolved_method_type, THREAD); 1.75 + wrap_invokedynamic_exception(CHECK); 1.76 } 1.77 1.78 //------------------------------------------------------------------------------------------------------------------------