Skip to content

Carriers update for matchers-experiment - #30

Merged
biboudis merged 7 commits into
biboudis:matchers-experimentfrom
lahodaj:matchers-experiment-new-carriers
Jul 1, 2025
Merged

Carriers update for matchers-experiment#30
biboudis merged 7 commits into
biboudis:matchers-experimentfrom
lahodaj:matchers-experiment-new-carriers

Conversation

@lahodaj

@lahodaj lahodaj commented May 27, 2025

Copy link
Copy Markdown

This change proposes to:

  • minimize the Carriers API surface
  • simplify Carriers to avoid potentially unnecessary internal complexity.
  • add mandatory metadata to bootstrap methods
  • the component bootstrap is now expected to be used via indy.
  • TransPatterns updated to avoid the use through ConstantBootstraps.invoke, and to use indy instead of condy to get the component values.

MethodHandle initializingConstructor = SharedSecrets.getJavaLangRuntimeAccess().initializingConstructor(bindingMT);

return (Object[])Carriers.boxedComponentValueArray(bindingMT).invoke(method.invoke(matchCandidate, matchCandidate, initializingConstructor));
return (Object[])SharedSecrets.getJavaLangRuntimeAccess().boxedComponentValueArray(bindingMT).invoke(method.invoke(matchCandidate, matchCandidate, initializingConstructor));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would invokeExact work here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I realized I changed this mechanically, but reflection does not need to go through the Carriers at all. Fixed in 47dd83d

|| (!invocationType.returnType().equals(componentType))
|| !invocationType.parameterType(0).equals(Object.class))
throw new IllegalArgumentException("Illegal invocation type " + invocationType);
return new ConstantCallSite(MethodHandles.insertArguments(COMPONENT_GETTER, 0, i).asType(MethodType.methodType(componentType, Object.class)));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since you're inserting the first argument I'd go for COMPONENT_GETTER.bindTo(i)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I don't think that's possible - the parameter is an int, and bindTo requires the first parameter to be a reference.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ah, that's a good observation 👍

boxingType,
new int[methodType.parameterCount()]
).asType(boxingType.changeReturnType(Object[].class));
private static Object componentGetter(int component, Carrier carrier) throws Throwable {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤔 Why does this need throws Throwable?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, removed.

@lahodaj lahodaj changed the title Matchers experiment new carriers Carriers update for matchers-experiment Jun 4, 2025
.toArray(Class[]::new)
);
MethodHandle initializingConstructor = SharedSecrets.getJavaLangRuntimeAccess().initializingConstructor(bindingMT);
MethodHandle pack = MethodHandles.identity(Object[].class).asCollector(Object[].class, this.getPatternBindings().length).asType(bindingMT);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It's actually possible to avoid having to create a new MH each invocation, and instead have a hoisted, re-usable, handle.

private static Object[] collect(Object... params) {
    return params;
}

static final MethodHandle COLLECT_TO_ARRAY = MhUtil.findStatic(This.class, "collect", MethodType.methodType(Object[].class, Object[].class));

@lahodaj
lahodaj marked this pull request as ready for review June 13, 2025 06:08
@biboudis
biboudis merged commit 619b4aa into biboudis:matchers-experiment Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants