the connection between JVM buffer and java heap?

Alan Bateman Alan.Bateman at Sun.COM
Sat Jan 12 03:44:13 PST 2008


zhang Jackie wrote:
> hi
>    are these two the same,or different? When sending data from Java , 
> the data is copied from java heap to JVM buffer and then give it to OS 
> . is this right?
>  
>    Thanks
When you say "JVM buffer" do you mean a byte array or 
java.nio.ByteBuffer used for I/O? If so, then it depends on the 
API/library. For the  stream-based APIs (java.io or java.net) the 
buffers are byte arrays in the java heap. I/O is done using a temporary 
stack-allocated or malloc'ed buffer so it is necessary to copy to or 
from the byte array in the java heap.  For NIO it depends on if the byte 
buffer is direct or non-direct. Direct buffers reside outside of the 
garbage collected heap and they can be used directly for I/O (no coping 
to/from temporary buffers). Non-direct buffers have a backing array in 
the heap and are copied to/from a temporary direct buffers when doing I/O.

-Alan.



More information about the hotspot-dev mailing list