Skip to content

OpenJDK: Implement JVM_CopySwapMemory - #23

Merged
guillerodriguez merged 1 commit into
masterfrom
feat/openjdk-copyswapmemory
Aug 26, 2026
Merged

OpenJDK: Implement JVM_CopySwapMemory#23
guillerodriguez merged 1 commit into
masterfrom
feat/openjdk-copyswapmemory

Conversation

@guillerodriguez

Copy link
Copy Markdown
Contributor

OpenJDK 8u201 added JVM_CopySwapMemory (as part of the OpenJDK 8 backport of JDK-8141491), which copies memory between two regions while swapping the byte order of each element. Without it, the process crashes on the first bulk NIO transfer involving a byte-swapped buffer.

The implementation is a simple byte-reversal loop: alignment-safe (element accesses go through memcpy) and overlap-safe (copying backwards when the destination might lie within the source).

@guillerodriguez
guillerodriguez requested a review from phvega August 23, 2026 18:05
@guillerodriguez
guillerodriguez force-pushed the feat/openjdk-copyswapmemory branch 2 times, most recently from dbd8f3a to 650da17 Compare August 23, 2026 23:07
OpenJDK 8u201 added JVM_CopySwapMemory (as part of the OpenJDK 8
backport of JDK-8141491), which copies memory between two regions
while swapping the byte order of each element. Without it, the
process crashes on the first bulk NIO transfer involving a
byte-swapped buffer.

The implementation uses a simple byte-reversal loop with byte-wise
reads and writes, allowing unaligned source and destination addresses.
The copy is overlap-safe: When the ranges overlap, copying proceeds in
a direction that prevents unread source bytes from being overwritten.

Signed-off-by: Guillermo Rodríguez <grodriguez@ingelabs.com>
@guillerodriguez
guillerodriguez force-pushed the feat/openjdk-copyswapmemory branch from 650da17 to 09880a9 Compare August 23, 2026 23:20
@guillerodriguez
guillerodriguez merged commit 04d134a into master Aug 26, 2026
5 checks passed
@guillerodriguez
guillerodriguez deleted the feat/openjdk-copyswapmemory branch August 26, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants