Skip to content

OpenJDK: Implement JVM_CopySwapMemory - #23

Open
guillerodriguez wants to merge 1 commit into
masterfrom
feat/openjdk-copyswapmemory
Open

OpenJDK: Implement JVM_CopySwapMemory#23
guillerodriguez wants to merge 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
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.

1 participant