RFR: 8271820: Implementation of JEP 416: Reimplement Core Reflection with Method Handle [v9]
mchung at openjdk.java.net
Wed Sep 22 16:18:45 UTC 2021
> This reimplements core reflection with method handles.
> For `Constructor::newInstance` and `Method::invoke`, the new implementation uses `MethodHandle`. For `Field` accessor, the new implementation uses `VarHandle`. 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 target `MethodHandle` or `VarHandle` 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  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 .
> Ran tier1-tier8 tests.
>  https://bugs.openjdk.java.net/browse/JDK-8013527
>  https://bugs.openjdk.java.net/browse/JDK-8271820?focusedCommentId=14439430&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14439430
Mandy Chung has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 27 commits:
- Make MethodAccessor non-volatile. Remove MHInvoker/VHInvoker.
- minor cleanup and more test case.
- Rename InvokerBuilder to ReflectionInvokerBuilder
- Fix NativeAccessor.c build issue for the renamed classes
- Shorten the class name
- Rename the accessor classes to make it explicit for method handles
- Add a new test for testing methods whose parameter types and return type not visible to the caller
- Move the handling of native accessor to the factory method for method/constructor accessor
- DirectConstructorAccessorImpl should take the MHInvoker parameter
- ... and 17 more: https://git.openjdk.java.net/jdk/compare/161fdb4a...1e68d004
Stats: 6529 lines in 75 files changed: 5990 ins; 327 del; 212 mod
Fetch: git fetch https://git.openjdk.java.net/jdk pull/5027/head:pull/5027
More information about the core-libs-dev