-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8333793: Improve BootstrapMethodInvoker for ConstantBootstraps and ProxyGenerator #19598
Conversation
👋 Welcome back redestad! A progress list of the required criteria for merging this PR into |
@cl4es This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 690 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
.invokeExact(caller, name, (Class<?>)type, (MethodType)argv[0], | ||
(MethodHandle)argv[1], (MethodType)argv[2]); | ||
} else if (isStringConcatFactoryBSM(bsmType) && argv.length >= 1) { | ||
} else if (argv.length >= 1 && bsmType == SCF_MT) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that these argv.length
comparisons were here for cases where the wrong number of arguments are passed to a bootstrap method?
I don't see why check argv.length > 1
is still required here... Some of the other cases are also happy to just access argv
, (which we also do here on the next line).
If you don't think this extract check is needed, please remove this source of confusion.
As an aside: I suppose we pre-generate all the linkers that get spun up for these |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend considering the MethodHandle, Object[]
signature used by ConstantBootstrap.invoke
: There had been previous proposals to use any method as a bootstrap method, and that API in particular can bridge that gap.
private static boolean isLambdaMetafactoryIndyBSM(MethodType bsmType) { | ||
return bsmType == LMF_INDY_MT; | ||
} | ||
private static final MethodType CONDY_GET_STATIC_FINAL_MT = MethodType.methodType(Object.class, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type should just be called CONDY_NO_ARG
as it's the most common form of condy that doesn't take any arg (nullConstant
primitiveClass
etc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that ConstantBootstraps::primitiveClass(Lookup, String, Class)
has a static return type of Class<?>
, so the following is also needed:
/**
* Exact type used of the {@link ConstantBootstraps#primitiveClass(Lookup, String, Class)}
* bootstrap method.
*/
private static final MethodType CONDY_CLASS_NO_ARG_MT
= CONDY_GET_STATIC_FINAL_MT.changeReturnType(Class.class);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not the intent of this PR to exhaustively enumerate all methods in ConstantBootstraps
, primarily those shown to be bootstrap sensitive in some app. I've so far never seen a use of primitiveClass
(and I admit being ignorant as to why this even exists as a BSM) so I don't have any reason to believe special-casing it will carry its own weight.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For its existence, I think it was the same as null, that they weren't representable by cp entries for bootstrap method args. They are now backed by PrimitiveClassDescImpl, a type of condy, and ClassFile API currently writes loadConstant(primitiveCd) as a condy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sure there's a perfectly good explanation why we've done it like that rather than translating things like javac would (AFAICT a load from Integer/Short/Byte/...TYPE
).
private static boolean isLambdaMetafactoryAltMetafactoryBSM(MethodType bsmType) { | ||
return bsmType == LMF_ALT_MT; | ||
} | ||
private static final MethodType CONDY_GET_STATIC_FINAL_CLASS_MT = MethodType.methodType(Object.class, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend calling this CONDY_EXTRA_CLASS
, as this is the type of arrayVarHandle
.
…gnized type signatures
I'm not sure I see what linkers you're alluding to here in profiles (and I don't think we have code pre-generating all of them), and I don't see how to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Jorn is recommending to use invokeBasic with erased types as how LambdaForm does it. We can try that approach, but we need new tests to verify that bootstrap method type mismatches throw the same exceptions, so that should be another RFE.
Sure. If you can show how you'd do that I'd be happy to test it. Maybe there are excess native linkers I'm not seeing from using Thanks for reviewing! /integrate |
@cl4es This pull request has not yet been marked as ready for integration. |
@cl4es I'm talking about the linker being spun in The idea would be to call |
But any way, if you don't see those linkers being spun in profiles, maybe it's not important, and the extra safety is more worthwhile. |
Thanks, I'll see if I can get that working and if it has any effect as a follow-up. Testing caught a bug introduced by a copy-paste error in 532966a, re-running a few more tests now. |
@cl4es This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
Since JDK-8332457 was more or less backed out there's no obvious gain from parts of this patch. I'd like to rework it and add startup tests that verify the ConstantBootstraps. Closing for now. |
This PR refactors type matching in BootstrapMethodInvoker and adds a few types, seeking to improve bootstrap overheads of some ConstantBootstraps and in particular the ProxyGenerator condys generated for e.g. annotation proxies since JDK-8332457
I've adjusted the micro-benchmark added by JDK-8332457 to not only generate a proxy but also call into one of the proxied methodt (
Object::hashCode
).Running org.openjdk.bench.java.lang.reflect.ProxyGenBench as a one-off startup benchmark sees significant improvement (-9% instructions, -6% cycles):
Number of classes loaded drops from 1096 to 1092
Running the micro regularly shows no significant difference:
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/19598/head:pull/19598
$ git checkout pull/19598
Update a local copy of the PR:
$ git checkout pull/19598
$ git pull https://git.openjdk.org/jdk.git pull/19598/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 19598
View PR using the GUI difftool:
$ git pr show -t 19598
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/19598.diff
Webrev
Link to Webrev Comment