[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


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

-------------

Commit messages:
 - reduce imports
 - stable Class::module + avoid type check for SharedSecrets
 - Unsafe get BM

Changes: https://git.openjdk.org/panama-foreign/pull/851/files
 Webrev: https://webrevs.openjdk.org/?repo=panama-foreign&pr=851&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8313005
  Stats: 176 lines in 4 files changed: 175 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/panama-foreign/pull/851.diff
  Fetch: git fetch https://git.openjdk.org/panama-foreign.git pull/851/head:pull/851

PR: https://git.openjdk.org/panama-foreign/pull/851


More information about the panama-dev mailing list