RFR: 8291065: Creating a VarHandle for a static field triggers class initialization
Chen Liang
liach at openjdk.org
Fri May 5 04:56:33 UTC 2023
Also fixed the bug with NPE in `IndirectVarHandle::isAccessModeSupported`.
A few implementation-detail methods in VarHandle are now documented with the implied constraints to avoid subtle problems in the future. Changed `IndirectVarHandle` to call `asDirect` lazily to accomodate the lazy VarHandle changes. Also changed VarHandleBaseTest to report the whole incorrect type of exception caught than swallow it and leaving only a message.
Current problems:
- [ ] The lazy var handle is quite slow on the first invocation.
- As seen in the benchmark, users can first call `Lookup::ensureInitialized` to create an eager handle.
- After that, the lazy handle has a performance on par with the regular var handle.
- [ ] The class-loading-based test is not in a unit test
- The test frameworks don't seem to offer fine-grained control for class-loading detection or reliable unloading
Benchmark Mode Cnt Score Error Units
VarHandleLazyStaticInvocation.initializedInvocation avgt 30 0.769 ± 0.003 ns/op
VarHandleLazyStaticInvocation.lazyInvocation avgt 30 0.767 ± 0.002 ns/op
VarHandleLazyStaticCreation.eagerInitialize ss 10 348580.000 ± 115234.161 ns/op
VarHandleLazyStaticCreation.lazyInitialize ss 10 961670.000 ± 154813.238 ns/op
-------------
Commit messages:
- copyright year
- Benchmarks. lazy initialize is SLOW
- nuke meaningless overrides
- make static field var handles lazy and fix NPE in isAccessModeSupported
Changes: https://git.openjdk.org/jdk/pull/13821/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=13821&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8291065
Stats: 509 lines in 9 files changed: 418 ins; 17 del; 74 mod
Patch: https://git.openjdk.org/jdk/pull/13821.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/13821/head:pull/13821
PR: https://git.openjdk.org/jdk/pull/13821
More information about the core-libs-dev
mailing list