This patch contains the implementation of the foreign linker & memory API JEP 
for Java 22. The initial patch is composed of commits brought over directly 
from the [panama-foreign repo](https://github.com/openjdk/panama-foreign). The 
main changes found in this patch come from the following PRs:

1. https://github.com/openjdk/panama-foreign/pull/836 Where previous iterations 
supported converting Java strings to and from native strings in the UTF-8 
encoding, we've extended the supported encoding to all the encodings found in 
the `java.nio.charset.StandardCharsets` class.
2. https://github.com/openjdk/panama-foreign/pull/838 We dropped the 
`MemoryLayout::sequenceLayout` factory method which inferred the size of the 
sequence to be `Long.MAX_VALUE`, as this led to confusion among clients. A 
client is now required to explicitly specify the sequence size.
3. https://github.com/openjdk/panama-foreign/pull/839 A new API was added: 
`Linker::canonicalLayouts`, which exposes a map containing the 
platform-specific mappings of common C type names to memory layouts.
4. https://github.com/openjdk/panama-foreign/pull/840 Memory access varhandles, 
as well as byte offset and slice handles derived from memory layouts, now 
feature an additional 'base offset' coordinate that is added to the offset 
computed by the handle. This allows composing these handles with other offset 
computation strategies that may not be based on the same memory layout. This 
addresses use-cases where clients are working with 'dynamic' layouts, whose 
size might not be known statically, such as variable length arrays, or variable 
size matrices.
5. https://github.com/openjdk/panama-foreign/pull/841 Remove this now redundant 
API. Clients can simply use the difference between the base address of two 
memory segments.
6. https://github.com/openjdk/panama-foreign/pull/845 Disambiguate uses of 
`SegmentAllocator::allocateArray`, by renaming methods that both allocate + 
initialize memory segments to `allocateFrom`. (see the original PR for the 
problematic case)
7. https://github.com/openjdk/panama-foreign/pull/846 Improve the documentation 
for variadic functions.
8. https://github.com/openjdk/panama-foreign/pull/849 Several test fixes to 
make sure the `jdk_foreign` tests can pass on 32-bit machines, taking linux-x86 
as a test bed.
9. https://github.com/openjdk/panama-foreign/pull/850 Make the linker API 
required. The `Linker::nativeLinker` method is not longer allowed to throw an 
`UnsupportedOperationException` on unsupported platforms. All tests are turned 
on by default, instead of being skipped when the linker is not present.
10. https://github.com/openjdk/panama-foreign/pull/851 Minor code tweaks to 
ensure the JIT can constant fold through native access checks if the accessing 
class is statically known (see commit/original PR for changes).
11. https://github.com/openjdk/panama-foreign/pull/853 Remove all the 
`@PreviewFeature` annotations from the API. Update all `@since` tags in the 
Javadoc to `@since 22` (per [JEP 
12](https://bugs.openjdk.org/browse/JDK-8195734)). Update tests and benchmarks 
to no longer build and run using `--enable-preview` (or the `@enablePreview` 
jtreg tag).

I want to call out in particular that this patch finalizes the FFM API (by 
moving it out of preview), and requires all JDK implementations to implement 
it. Most ports already have full FFM API support. The ones that are missing 
are: s390 ([currently under 
review](https://github.com/openjdk/jdk/pull/14801)), windows-x86 (deprecated 
for removal), and linux-86 & arm32 (which can both be implemented using the 
fallback linker [1](https://github.com/openjdk/panama-foreign/pull/770) 
[2](https://mail.openjdk.org/pipermail/porters-dev/2023-March/000753.html)).

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

Commit messages:
 - use immutable map for fallback linker canonical layouts
 - 8313265: Move the FFM API out of preview
 - 8313005: Ensure native access check can fold away
 - 8312981: Make the linker API required
 - 8312615: Ensure jdk_foreign tests pass on linux-x86
 - 8312186: TestStringEncodingFails for UTF-32
 - 8312059: Clarify the documention for variadic functions
 - 8311533: SegmentAllocator::allocateArray call can be ambiguous
 - 8310893: VarHandleTestExact fails
 - 8310820: Remove MemorySegment::segmentOffset
 - ... and 4 more: https://git.openjdk.org/jdk/compare/6fca2898...b0a1abaf

Changes: https://git.openjdk.org/jdk/pull/15103/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=15103&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8312522
  Stats: 2444 lines in 224 files changed: 1084 ins; 721 del; 639 mod
  Patch: https://git.openjdk.org/jdk/pull/15103.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/15103/head:pull/15103

PR: https://git.openjdk.org/jdk/pull/15103

Reply via email to