I am trying to understand the JVM memory model. In particular, I would like to understand whether it would be feasible to have zero-copy (de)serialization libraries, such as Cap'n Proto or FlatBuffers. In particular, these two libraries do have partial support for Java, but it is not entirely clear to me whether the implementation is zero-copy.
Let me assume that I want to deserialize something, and that this region will be read only. I will start with an array of contiguous bytes, at least from the JVM point of view, although I understand they may fail to be contiguous due to the virtual memory manager (and possibily the JVM?). This array is somewhere on the JVM heap.
What I would like to do is to produce an instance of a given class, in such a way that accessing a field of this class just means to dereference a pointer into this array, without having to copy the single parts of this array somewhere else.
Is this feasible on the JVM? If not, what would be the optimum? Can I do this with a single copy regardless of the class layout?