-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
8271820: Implementation of JEP 416: Reimplement Core Reflection with Method Handle #5027
Conversation
…ent-method-invoke
…ent-method-invoke
…ent-method-invoke
…ent-method-invoke
…ent-method-invoke
👋 Welcome back mchung! A progress list of the required criteria for merging this PR into |
@mlchung The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
/label remove kulla |
/label remove security |
@mlchung |
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.
Good work.
useDirectMethodHandle = METHOD_MH_ACCESSOR; | ||
} else if (val.equals("fields")) { | ||
useDirectMethodHandle = FIELD_MH_ACCESSOR; | ||
} |
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.
Happy to see that property can be used to control both.
Thanks all for the review. JEP 416 is now target to JDK 18. I'll integrate this PR today. |
/integrate |
Going to push as commit c6339cb.
Your commit was automatically rebased without conflicts. |
Hi, Apache Wicket tests started failing with JDK 18 b23 and I think it is caused by this PR. |
@martin-g mutating static final fields with reflection @mlchung should verify, but it looks like the |
Mailing list message from Alan Bateman on core-libs-dev: On 14/11/2021 00:59, Claes Redestad wrote:
If I read this correctly, a wicked Wicket test is making use of a Are there many Wicket tests trying to modify static field fields? Have -Alan |
Thank you for the comments!
No! We have just one failing test with JDK 18 b23. In someone else's case it might be needed to "hack" a third party library. As a good citizen I'm reporting it back to you! |
Because it is not possible to modify it in JDK 18 b23. The OpenJDK team is informed. They will probably fix the regression. Or document it that it is not possible anymore to do such hacks. openjdk/jdk#5027 (comment)
@martin-g I wasn't making any judgement. To qualify why this is not something I think anyone should do: poking into reflection internals to make a static final field mutable opens you up to situations where some readers still see the old value. An optimizing compiler (JIT or AOT) may treat the value as constant and propagates it. Future JVM features might decide to be even more aggressive, and trust these fields even more completely. While it's unspecified what should happen after overwriting a static final field with reflection, it does work if you're lucky. The one-off use in Wicket for a test seem benign enough. Alan: changing |
Mailing list message from Alan Bateman on core-libs-dev: On 14/11/2021 22:56, Claes Redestad wrote:
Sure, but I don't think that would be enough as Wicket would also need -Alan |
Since commit 191de98 (HEAD -> master, origin/master) Author: Martin Grigorov <mgrigorov@apache.org> Date: Sun Nov 14 21:56:30 2021 +0200 Remove 'final' modifier from a static field Because it is not possible to modify it in JDK 18 b23. The OpenJDK team is informed. They will probably fix the regression. Or document it that it is not possible anymore to do such hacks. openjdk/jdk#5027 (comment) org.apache.wicket.util.string.Strings#SESSION_ID_PARAM is no more 'final' so there is no need to change the modifiers
I have already fixed our build with apache/wicket@191de98 and apache/wicket@128125f |
Mailing list message from David Holmes on core-libs-dev: Hi Alan, On 15/11/2021 5:11 pm, Alan Bateman wrote:
I think there may be a misunderstanding here, AFAICS they are using Cheers,
|
Mailing list message from Alan Bateman on core-libs-dev: On 15/11/2021 09:48, David Holmes wrote:
That's the outcome. To get there, they call a private method -Alan. |
Mailing list message from David Holmes on core-libs-dev: On 15/11/2021 8:14 pm, Alan Bateman wrote:
Apologies - the misunderstanding was mine. David
|
@martin-g Thanks for reporting this. Appreciated. JEP 416 makes |
I further looked at the specification and implementation of If the underlying field is final, a
The hack dropping |
This reimplements core reflection with method handles.
For
Constructor::newInstance
andMethod::invoke
, the new implementation usesMethodHandle
. ForField
accessor, the new implementation usesVarHandle
. For the first few invocations of one of these reflective methods on a specific reflective object we invoke the corresponding method handle directly. After that we spin a dynamic bytecode stub defined in a hidden class which loads the targetMethodHandle
orVarHandle
from its class data as a dynamically computed constant. Loading the method handle from a constant allows JIT to inline the method-handle invocation in order to achieve good performance.The VM's native reflection methods are needed during early startup, before the method-handle mechanism is initialized. That happens soon after System::initPhase1 and before System::initPhase2, after which we switch to using method handles exclusively.
The core reflection and method handle implementation are updated to handle chained caller-sensitive method calls [1] properly. A caller-sensitive method can define with a caller-sensitive adapter method that will take an additional caller class parameter and the adapter method will be annotated with
@CallerSensitiveAdapter
for better auditing. See the detailed description from [2].Ran tier1-tier8 tests.
[1] https://bugs.openjdk.java.net/browse/JDK-8013527
[2] https://bugs.openjdk.java.net/browse/JDK-8271820?focusedCommentId=14439430&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14439430
Progress
Issues
Reviewers
Contributors
<plevart@openjdk.org>
<redestad@openjdk.org>
<mchung@openjdk.org>
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/5027/head:pull/5027
$ git checkout pull/5027
Update a local copy of the PR:
$ git checkout pull/5027
$ git pull https://git.openjdk.java.net/jdk pull/5027/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 5027
View PR using the GUI difftool:
$ git pr show -t 5027
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/5027.diff