Skip to content

Commit

Permalink
8281866: Enhance MethodHandle invocations
Browse files Browse the repository at this point in the history
Reviewed-by: mbaesken
Backport-of: d974d9da365f787f67971d88c79371c8b0769f75
  • Loading branch information
martinuy authored and RealCLanger committed Jul 1, 2022
1 parent 9dcec4d commit 860464e
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/hotspot/share/interpreter/linkResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1709,8 +1709,31 @@ void LinkResolver::resolve_handle_call(CallInfo& result,
resolved_klass == vmClasses::VarHandle_klass(), "");
assert(MethodHandles::is_signature_polymorphic_name(link_info.name()), "");
Handle resolved_appendix;
Method* resolved_method = lookup_polymorphic_method(link_info, &resolved_appendix, CHECK);
result.set_handle(resolved_klass, methodHandle(THREAD, resolved_method), resolved_appendix, CHECK);
Method* m = lookup_polymorphic_method(link_info, &resolved_appendix, CHECK);
methodHandle resolved_method(THREAD, m);

if (link_info.check_access()) {
Symbol* name = link_info.name();
vmIntrinsics::ID iid = MethodHandles::signature_polymorphic_name_id(name);
if (MethodHandles::is_signature_polymorphic_intrinsic(iid)) {
// Check if method can be accessed by the referring class.
// MH.linkTo* invocations are not rewritten to invokehandle.
assert(iid == vmIntrinsicID::_invokeBasic, "%s", vmIntrinsics::name_at(iid));

Klass* current_klass = link_info.current_klass();
assert(current_klass != NULL , "current_klass should not be null");
check_method_accessability(current_klass,
resolved_klass,
resolved_method->method_holder(),
resolved_method,
CHECK);
} else {
// Java code is free to arbitrarily link signature-polymorphic invokers.
assert(iid == vmIntrinsics::_invokeGeneric, "not an invoker: %s", vmIntrinsics::name_at(iid));
assert(MethodHandles::is_signature_polymorphic_public_name(resolved_klass, name), "not public");
}
}
result.set_handle(resolved_klass, resolved_method, resolved_appendix, CHECK);
}

void LinkResolver::resolve_invokedynamic(CallInfo& result, const constantPoolHandle& pool, int indy_index, TRAPS) {
Expand Down

0 comments on commit 860464e

Please sign in to comment.