Skip to content

Commit

Permalink
An experiment based on a comment by vklang: the carrier object is in …
Browse files Browse the repository at this point in the history
…fact an invoker MethodHandle with output bindings inserted as parameteres
  • Loading branch information
lahodaj committed Jan 10, 2025
1 parent a78ebd9 commit f27b320
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 879 deletions.
13 changes: 7 additions & 6 deletions src/java.base/share/classes/java/lang/reflect/MemberPattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import sun.reflect.generics.scope.MemberPatternScope;

import java.lang.annotation.Annotation;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.runtime.Carriers;
import java.util.ArrayList;
Expand Down Expand Up @@ -403,21 +404,21 @@ public Object[] invoke(Object matchCandidate)
try {
Method method = getDeclaringClass().getDeclaredMethod(underlyingName, matchCandidate.getClass());
method.setAccessible(override);
return (Object[])Carriers.boxedComponentValueArray(
MethodType.methodType(
return (Object[]) Carriers.componentInvoker(MethodType.methodType(
Object.class,
Arrays.stream(this.getPatternBindings())
.map(PatternBinding::getType)
.toArray(Class[]::new)
)
).invoke(
method.invoke(matchCandidate, matchCandidate)
);
)).invoke(method.invoke(matchCandidate, matchCandidate), MethodHandles.lookup().findStatic(MemberPattern.class, "wrap", MethodType.methodType(Object[].class, Object[].class)));
} catch (Throwable e) {
throw new MatchException(e.getMessage(), e);
}
}

private static Object[] wrap(Object... args) {
return args;
}

byte[] getRawAnnotations() {
return annotations;
}
Expand Down
Loading

0 comments on commit f27b320

Please sign in to comment.