GeezerVison is showing github.com — Auto-port 5.0: fix FFM address semantics in directBufferAddress (#16… · netty/netty@e16d76f
File tree
Expand file treeCollapse file tree
Open diff view settings
common/src/main/java/io/netty/util/internal transport-native-unix-common/src/main/java/io/netty/channel/unix
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: common/src/main/java/io/netty/util/internal/PlatformDependent0.java +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -689,7 +689,9 @@ static long directBufferAddress(ByteBuffer buffer) { |
689 | 689 | } |
690 | 690 | if (hasMemorySegmentAddressOfBuffer()) { |
691 | 691 | try { |
692 | | - return (long) MEMORY_SEGMENT_ADDRESS_OF_BUFFER.invokeExact((Buffer) buffer); |
| 692 | + // MemorySegment.ofBuffer(buffer).address() includes the current position offset. |
| 693 | + // Netty/JNI GetDirectBufferAddress expects the base (index 0) address, so subtract position. |
| 694 | + return (long) MEMORY_SEGMENT_ADDRESS_OF_BUFFER.invokeExact((Buffer) buffer) - buffer.position(); |
693 | 695 | } catch (Throwable e) { |
694 | 696 | LinkageError error = new LinkageError("Failed to call MemorySegment.ofBuffer(arg1).address()"); |
695 | 697 | error.initCause(e); |
|
Collapse file
Copy file name to clipboardExpand all lines: transport-native-unix-common/src/main/java/io/netty/channel/unix/Buffer.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -62,7 +62,7 @@ public static CleanableDirectBuffer allocateDirectBufferWithNativeOrder(int capa |
62 | 62 | */ |
63 | 63 | public static long memoryAddress(ByteBuffer buffer) { |
64 | 64 | assert buffer.isDirect(); |
65 | | - if (PlatformDependent.hasUnsafe()) { |
| 65 | + if (PlatformDependent.hasDirectByteBufferAddress(buffer)) { |
66 | 66 | return PlatformDependent.directBufferAddress(buffer); |
67 | 67 | } |
68 | 68 | return memoryAddress0(buffer); |
|