comparison src/share/vm/interpreter/linkResolver.cpp @ 23061:81bed6c76a89

8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError Reviewed-by: coleenp, dsimms
author aeriksso
date Thu, 07 May 2015 15:05:46 +0200
parents 99edc344d77c
children dd9cc155639c 0b85ccd62409
comparison
equal deleted inserted replaced
23060:91a1be057e0a 23061:81bed6c76a89
1590 method_name, method_signature, 1590 method_name, method_signature,
1591 current_klass, &resolved_appendix, &resolved_method_type, CHECK); 1591 current_klass, &resolved_appendix, &resolved_method_type, CHECK);
1592 result.set_handle(resolved_method, resolved_appendix, resolved_method_type, CHECK); 1592 result.set_handle(resolved_method, resolved_appendix, resolved_method_type, CHECK);
1593 } 1593 }
1594 1594
1595 static void wrap_invokedynamic_exception(TRAPS) {
1596 if (HAS_PENDING_EXCEPTION) {
1597 if (TraceMethodHandles) {
1598 tty->print_cr("invokedynamic throws BSME for " INTPTR_FORMAT, p2i((void *)PENDING_EXCEPTION));
1599 PENDING_EXCEPTION->print();
1600 }
1601 if (PENDING_EXCEPTION->is_a(SystemDictionary::BootstrapMethodError_klass())) {
1602 // throw these guys, since they are already wrapped
1603 return;
1604 }
1605 if (!PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
1606 // intercept only LinkageErrors which might have failed to wrap
1607 return;
1608 }
1609 // See the "Linking Exceptions" section for the invokedynamic instruction in the JVMS.
1610 Handle nested_exception(THREAD, PENDING_EXCEPTION);
1611 CLEAR_PENDING_EXCEPTION;
1612 THROW_CAUSE(vmSymbols::java_lang_BootstrapMethodError(), nested_exception)
1613 }
1614 }
1595 1615
1596 void LinkResolver::resolve_invokedynamic(CallInfo& result, constantPoolHandle pool, int index, TRAPS) { 1616 void LinkResolver::resolve_invokedynamic(CallInfo& result, constantPoolHandle pool, int index, TRAPS) {
1597 assert(EnableInvokeDynamic, ""); 1617 assert(EnableInvokeDynamic, "");
1598 1618
1599 //resolve_pool(<resolved_klass>, method_name, method_signature, current_klass, pool, index, CHECK); 1619 //resolve_pool(<resolved_klass>, method_name, method_signature, current_klass, pool, index, CHECK);
1605 Handle bootstrap_specifier; 1625 Handle bootstrap_specifier;
1606 // Check if CallSite has been bound already: 1626 // Check if CallSite has been bound already:
1607 ConstantPoolCacheEntry* cpce = pool->invokedynamic_cp_cache_entry_at(index); 1627 ConstantPoolCacheEntry* cpce = pool->invokedynamic_cp_cache_entry_at(index);
1608 if (cpce->is_f1_null()) { 1628 if (cpce->is_f1_null()) {
1609 int pool_index = cpce->constant_pool_index(); 1629 int pool_index = cpce->constant_pool_index();
1610 oop bsm_info = pool->resolve_bootstrap_specifier_at(pool_index, CHECK); 1630 oop bsm_info = pool->resolve_bootstrap_specifier_at(pool_index, THREAD);
1631 wrap_invokedynamic_exception(CHECK);
1611 assert(bsm_info != NULL, ""); 1632 assert(bsm_info != NULL, "");
1612 // FIXME: Cache this once per BootstrapMethods entry, not once per CONSTANT_InvokeDynamic. 1633 // FIXME: Cache this once per BootstrapMethods entry, not once per CONSTANT_InvokeDynamic.
1613 bootstrap_specifier = Handle(THREAD, bsm_info); 1634 bootstrap_specifier = Handle(THREAD, bsm_info);
1614 } 1635 }
1615 if (!cpce->is_f1_null()) { 1636 if (!cpce->is_f1_null()) {
1616 methodHandle method( THREAD, cpce->f1_as_method()); 1637 methodHandle method( THREAD, cpce->f1_as_method());
1617 Handle appendix( THREAD, cpce->appendix_if_resolved(pool)); 1638 Handle appendix( THREAD, cpce->appendix_if_resolved(pool));
1618 Handle method_type(THREAD, cpce->method_type_if_resolved(pool)); 1639 Handle method_type(THREAD, cpce->method_type_if_resolved(pool));
1619 result.set_handle(method, appendix, method_type, CHECK); 1640 result.set_handle(method, appendix, method_type, THREAD);
1641 wrap_invokedynamic_exception(CHECK);
1620 return; 1642 return;
1621 } 1643 }
1622 1644
1623 if (TraceMethodHandles) { 1645 if (TraceMethodHandles) {
1624 ResourceMark rm(THREAD); 1646 ResourceMark rm(THREAD);
1645 bootstrap_specifier, 1667 bootstrap_specifier,
1646 method_name, method_signature, 1668 method_name, method_signature,
1647 &resolved_appendix, 1669 &resolved_appendix,
1648 &resolved_method_type, 1670 &resolved_method_type,
1649 THREAD); 1671 THREAD);
1650 if (HAS_PENDING_EXCEPTION) { 1672 wrap_invokedynamic_exception(CHECK);
1651 if (TraceMethodHandles) { 1673 result.set_handle(resolved_method, resolved_appendix, resolved_method_type, THREAD);
1652 tty->print_cr("invokedynamic throws BSME for " INTPTR_FORMAT, p2i((void *)PENDING_EXCEPTION)); 1674 wrap_invokedynamic_exception(CHECK);
1653 PENDING_EXCEPTION->print();
1654 }
1655 if (PENDING_EXCEPTION->is_a(SystemDictionary::BootstrapMethodError_klass())) {
1656 // throw these guys, since they are already wrapped
1657 return;
1658 }
1659 if (!PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
1660 // intercept only LinkageErrors which might have failed to wrap
1661 return;
1662 }
1663 // See the "Linking Exceptions" section for the invokedynamic instruction in the JVMS.
1664 Handle nested_exception(THREAD, PENDING_EXCEPTION);
1665 CLEAR_PENDING_EXCEPTION;
1666 THROW_CAUSE(vmSymbols::java_lang_BootstrapMethodError(), nested_exception)
1667 }
1668 result.set_handle(resolved_method, resolved_appendix, resolved_method_type, CHECK);
1669 } 1675 }
1670 1676
1671 //------------------------------------------------------------------------------------------------------------------------ 1677 //------------------------------------------------------------------------------------------------------------------------
1672 #ifndef PRODUCT 1678 #ifndef PRODUCT
1673 1679