[ 
https://issues.apache.org/jira/browse/CASSANDRA-12381?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15407944#comment-15407944
 ] 

Robert Stupp edited comment on CASSANDRA-12381 at 8/4/16 3:31 PM:
------------------------------------------------------------------

[link to the netty issue|https://github.com/netty/netty/issues/5629]

A direct buffer with an array feels very weird. At least with the current state 
of OpenJDK/Oracle Java. I don't get how a direct buffer (off-heap) with an 
array (on-heap) would be consistent - that's why I mentioned it is not safe. 
On-heap objects can move (copied) - direct buffers must not move as these can 
be used by the OS for example for I/O. Maybe that is not true for the Dalvik VM 
/ Android.
However, adding a {{!isDirect()}} (i.e. {{hasArray()}} --> {{!isDirect && 
hasArray()}}) feels more safe - maybe just in trunk since if cannot be an issue 
now.


was (Author: snazy):
[link to the netty issue|https://github.com/netty/netty/issues/5629]

A direct buffer with an array feels very weird. At least with the current state 
of OpenJDK/Oracle Java. I don't get how a direct buffer (off-heap) with an 
array (on-heap) would be consistent - that's why I mentioned it is not safe. 
On-heap objects can move (copied) - direct buffers must not move as these can 
be used by the OS for example for I/O. Maybe that is not true for the Dalvik VM 
/ Android.
However, adding a {{!isDirect()}} feels more safe - maybe just in trunk since 
if cannot be an issue now.

> Verify use of ByteBuffer.hasArray() in whole code base
> ------------------------------------------------------
>
>                 Key: CASSANDRA-12381
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-12381
>             Project: Cassandra
>          Issue Type: Bug
>            Reporter: Robert Stupp
>            Assignee: Robert Stupp
>            Priority: Minor
>             Fix For: 3.0.x
>
>
> As [noted 
> here|https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html#allocateDirect-int-],
>  a direct {{ByteBuffer}} can have a backing array.
> If a direct {{ByteBuffer}} has a backing array, we should not make any 
> assumption on how it is actually used.
> This ticket is about to check whether uses of {{ByteBuffer.hasArray()}} need 
> to be replaced with {{ByteBuffer.isDirect()}}.
> (With CASSANDRA-11870 however, there is no way that such a direct 
> {{ByteBuffer}} has a backing array.)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to