< prev index next >

src/share/vm/interpreter/linkResolver.cpp

Print this page
rev 12143 : 8166974: invokedynamic implementation should not wrap Errors
Reviewed-by: dholmes, jrose


1610   resolve_handle_call(result, link_info, CHECK);
1611 }
1612 
1613 void LinkResolver::resolve_handle_call(CallInfo& result,
1614                                        const LinkInfo& link_info,
1615                                        TRAPS) {
1616   // JSR 292:  this must be an implicitly generated method MethodHandle.invokeExact(*...) or similar
1617   KlassHandle resolved_klass = link_info.resolved_klass();
1618   assert(resolved_klass() == SystemDictionary::MethodHandle_klass() ||
1619          resolved_klass() == SystemDictionary::VarHandle_klass(), "");
1620   assert(MethodHandles::is_signature_polymorphic_name(link_info.name()), "");
1621   Handle       resolved_appendix;
1622   Handle       resolved_method_type;
1623   methodHandle resolved_method = lookup_polymorphic_method(link_info,
1624                                        &resolved_appendix, &resolved_method_type, CHECK);
1625   result.set_handle(resolved_klass, resolved_method, resolved_appendix, resolved_method_type, CHECK);
1626 }
1627 
1628 static void wrap_invokedynamic_exception(TRAPS) {
1629   if (HAS_PENDING_EXCEPTION) {





1630     if (TraceMethodHandles) {
1631       tty->print_cr("invokedynamic throws BSME for " INTPTR_FORMAT, p2i((void *)PENDING_EXCEPTION));
1632       PENDING_EXCEPTION->print();
1633     }
1634     if (PENDING_EXCEPTION->is_a(SystemDictionary::BootstrapMethodError_klass())) {
1635       // throw these guys, since they are already wrapped
1636       return;
1637     }
1638     if (!PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
1639       // intercept only LinkageErrors which might have failed to wrap
1640       return;


1641     }
1642     // See the "Linking Exceptions" section for the invokedynamic instruction in the JVMS.
1643     Handle nested_exception(THREAD, PENDING_EXCEPTION);
1644     CLEAR_PENDING_EXCEPTION;
1645     THROW_CAUSE(vmSymbols::java_lang_BootstrapMethodError(), nested_exception)
1646   }
1647 }
1648 
1649 void LinkResolver::resolve_invokedynamic(CallInfo& result, const constantPoolHandle& pool, int index, TRAPS) {
1650   Symbol* method_name       = pool->name_ref_at(index);
1651   Symbol* method_signature  = pool->signature_ref_at(index);
1652   KlassHandle current_klass = KlassHandle(THREAD, pool->pool_holder());
1653 
1654   // Resolve the bootstrap specifier (BSM + optional arguments).
1655   Handle bootstrap_specifier;
1656   // Check if CallSite has been bound already:
1657   ConstantPoolCacheEntry* cpce = pool->invokedynamic_cp_cache_entry_at(index);
1658   if (cpce->is_f1_null()) {
1659     int pool_index = cpce->constant_pool_index();
1660     oop bsm_info = pool->resolve_bootstrap_specifier_at(pool_index, THREAD);
1661     wrap_invokedynamic_exception(CHECK);
1662     assert(bsm_info != NULL, "");




1610   resolve_handle_call(result, link_info, CHECK);
1611 }
1612 
1613 void LinkResolver::resolve_handle_call(CallInfo& result,
1614                                        const LinkInfo& link_info,
1615                                        TRAPS) {
1616   // JSR 292:  this must be an implicitly generated method MethodHandle.invokeExact(*...) or similar
1617   KlassHandle resolved_klass = link_info.resolved_klass();
1618   assert(resolved_klass() == SystemDictionary::MethodHandle_klass() ||
1619          resolved_klass() == SystemDictionary::VarHandle_klass(), "");
1620   assert(MethodHandles::is_signature_polymorphic_name(link_info.name()), "");
1621   Handle       resolved_appendix;
1622   Handle       resolved_method_type;
1623   methodHandle resolved_method = lookup_polymorphic_method(link_info,
1624                                        &resolved_appendix, &resolved_method_type, CHECK);
1625   result.set_handle(resolved_klass, resolved_method, resolved_appendix, resolved_method_type, CHECK);
1626 }
1627 
1628 static void wrap_invokedynamic_exception(TRAPS) {
1629   if (HAS_PENDING_EXCEPTION) {
1630     // See the "Linking Exceptions" section for the invokedynamic instruction
1631     // in JVMS 6.5.
1632     if (PENDING_EXCEPTION->is_a(SystemDictionary::Error_klass())) {
1633       // Pass through an Error, including BootstrapMethodError, any other form
1634       // of linkage error, or say ThreadDeath/OutOfMemoryError
1635       if (TraceMethodHandles) {
1636         tty->print_cr("invokedynamic passes through an Error for " INTPTR_FORMAT, p2i((void *)PENDING_EXCEPTION));
1637         PENDING_EXCEPTION->print();
1638       }


1639       return;
1640     }
1641 
1642     // Otherwise wrap the exception in a BootstrapMethodError
1643     if (TraceMethodHandles) {
1644       tty->print_cr("invokedynamic throws BSME for " INTPTR_FORMAT, p2i((void *)PENDING_EXCEPTION));
1645       PENDING_EXCEPTION->print();
1646     }

1647     Handle nested_exception(THREAD, PENDING_EXCEPTION);
1648     CLEAR_PENDING_EXCEPTION;
1649     THROW_CAUSE(vmSymbols::java_lang_BootstrapMethodError(), nested_exception)
1650   }
1651 }
1652 
1653 void LinkResolver::resolve_invokedynamic(CallInfo& result, const constantPoolHandle& pool, int index, TRAPS) {
1654   Symbol* method_name       = pool->name_ref_at(index);
1655   Symbol* method_signature  = pool->signature_ref_at(index);
1656   KlassHandle current_klass = KlassHandle(THREAD, pool->pool_holder());
1657 
1658   // Resolve the bootstrap specifier (BSM + optional arguments).
1659   Handle bootstrap_specifier;
1660   // Check if CallSite has been bound already:
1661   ConstantPoolCacheEntry* cpce = pool->invokedynamic_cp_cache_entry_at(index);
1662   if (cpce->is_f1_null()) {
1663     int pool_index = cpce->constant_pool_index();
1664     oop bsm_info = pool->resolve_bootstrap_specifier_at(pool_index, THREAD);
1665     wrap_invokedynamic_exception(CHECK);
1666     assert(bsm_info != NULL, "");


< prev index next >