Skip to content

Commit

Permalink
8297728: Cache invocation type rather than invoker in NamedFunction
Browse files Browse the repository at this point in the history
Reviewed-by: jvernee
  • Loading branch information
cl4es committed Nov 30, 2022
1 parent e9d501e commit 4485d4e
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/java.base/share/classes/java/lang/invoke/LambdaForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ boolean contains(Name name) {
static class NamedFunction {
final MemberName member;
private @Stable MethodHandle resolvedHandle;
@Stable MethodHandle invoker;
private @Stable MethodType type;

NamedFunction(MethodHandle resolvedHandle) {
this(resolvedHandle.internalMemberName(), resolvedHandle);
Expand Down Expand Up @@ -1185,10 +1185,6 @@ Object invokeWithArgumentsTracing(Object[] arguments) throws Throwable {
Object rval;
try {
traceInterpreter("[ call", this, arguments);
if (invoker == null) {
traceInterpreter("| getInvoker", this);
invoker();
}
// resolvedHandle might be uninitialized, ok for tracing
if (resolvedHandle == null) {
traceInterpreter("| resolve", this);
Expand All @@ -1204,17 +1200,24 @@ Object invokeWithArgumentsTracing(Object[] arguments) throws Throwable {
}

private MethodHandle invoker() {
if (invoker != null) return invoker;
// Get an invoker and cache it.
return invoker = computeInvoker(methodType().form());
return computeInvoker(methodType().form());
}

MethodType methodType() {
if (resolvedHandle != null)
MethodType type = this.type;
if (type == null) {
this.type = type = calculateMethodType(member, resolvedHandle);
}
return type;
}

private static MethodType calculateMethodType(MemberName member, MethodHandle resolvedHandle) {
if (resolvedHandle != null) {
return resolvedHandle.type();
else
} else {
// only for certain internal LFs during bootstrapping
return member.getInvocationType();
}
}

MemberName member() {
Expand Down

1 comment on commit 4485d4e

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.