memory mapped i/o?

Bryce McKinlay
Mon Dec 4 17:54:00 GMT 2000

David Brownell wrote:

> >      It would be convenient to create primitive arrays
> > directly mapped to a file, but gcj cannot easily do this because the
> > array requires an object header.
> And I'd guess that assumption is buried deep in the ABI, yes?  There'd
> need to be a new ABI data type for such a thing, I'd guess.

Currently, array objects like a "byte[]" are always allocated as a single
object. They consist of the standard object fields (vtable pointer,
synchronization monitor), followed by a length field, followed by (length *
type_size) space for the actual array entries (refer to gcj/array.h and
JvNewPrimArray() in

This contrasts to the way String objects are allocated, which, while also
capable of being alocated as a single variable length object, contain an
extra "data" pointer which may or may not point to a different object. The
data pointer is used to optimize things like subString(), so that different
String objects may actually be pointing to different parts of the same
physical char array (this is safe because Strings are immutable).

In principle, it shouldn't be too difficult to add a "data" pointer to array
objects as well. Normally, this pointer would just point to (*array->data +
1), but by pointing it at some mmap'ed region, you could efficiently do your
I/O or whatever. The disadvantage of course is that you're adding an extra
word to the size of every array object, and a possible performance penalty to
every array access by having to load and offset against the data pointer. The
compiler should be able to optimize that away where it counts, however.

> I just did a bit more poking around.  It appears that the RealTime Java
> API has some memory region APIs (chapter 5) that in principle ought to
> be able expose memory mapped I/O ... or controller registers, etc.

It looks to me like RawMemoryAccess class in this proposal isn't quite what
you want, because it still involves copying from regular arrays to and from
the "raw memory" area. I havn't studied the spec in detail however.


  [ bryce ]

More information about the Java mailing list