[foreign-memaccess+abi] RFR: 8313005: Ensure native access check can fold away
Jorn Vernee
jvernee at openjdk.org
Tue Jul 25 18:55:20 UTC 2023
On Tue, 25 Jul 2023 18:13:12 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
> This patch helps to ensure that native access checks done by restricted methods can completely fold away (see JBS for details).
>
> This is accomplished by:
> 1. Marking the `module` field of `java.lang.Class` `@Stable`
> 2. Using a constant `JavaLangAccess` instance.
>
> I've also added 2 new benchmarks that show the improvement (in two separate classes so that the benchmark methods in each class are comparable to each other in terms of numbers).
>
> Numbers on my machine are as follows:
>
> Before:
>
> Benchmark Mode Cnt Score Error Units
> MemorySegmentGetUnsafe.panama avgt 30 0.817 ± 0.002 ns/op
> MemorySegmentGetUnsafe.unsafe avgt 30 0.400 ± 0.003 ns/op
>
> MemorySegmentCopyUnsafe.panama avgt 30 8.145 ± 0.016 ns/op
> MemorySegmentCopyUnsafe.unsafe avgt 30 7.744 ± 0.012 ns/op
>
>
> After:
>
> Benchmark Mode Cnt Score Error Units
> MemorySegmentGetUnsafe.panama avgt 30 0.411 ± 0.002 ns/op
> MemorySegmentGetUnsafe.unsafe avgt 30 0.404 ± 0.003 ns/op
>
> MemorySegmentCopyUnsafe.panama avgt 30 7.737 ± 0.013 ns/op
> MemorySegmentCopyUnsafe.unsafe avgt 30 7.728 ± 0.011 ns/op
src/java.base/share/classes/jdk/internal/reflect/Reflection.java line 122:
> 120: static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
> 121: }
> 122: Holder.JLA.ensureNativeAccess(module, owner, methodName);
Note that I have to put this here in a holder class instead of inside the enclosing class to avoid bootstrap cycles (resulting in `getJavaLangAccess` returning `null`)
-------------
PR Review Comment: https://git.openjdk.org/panama-foreign/pull/851#discussion_r1273917178
More information about the panama-dev
mailing list