Null-terminated Unicode strings in java.io on Windows

Mark Wielaard mark at klomp.org
Fri Jan 25 22:16:51 UTC 2008


Hi Robert,

Robert Lougher <rob.lougher at ...> writes:
> This is getting a bit hostile for no reason....  Thinking about
> alignment gives an interesting solution.
> 
> 1) Strings are not null-terminated
> 2) For most strings the alignment gives the VM room to terminate in
> place when GetStringChars is called
> 3) Copy strings that can't be terminated in place.

Note that Strings have a backing [j]char array which can be shared between
different Strings, and often are when read in in one go and then split in
different sub-String objects. All these Strings have a shared slice of this
backing jchar array, so there isn't any place to terminate it because that place
will overlap with another slice that can belong to another String.

You should know, because I learned all I know about this and pinning of the
backing storage of a String (not the String object itself) by reading your jamvm
code! :)

BTW. I would really recommend anybody wanting to know how the VM and JNI specs
truly work/can be implemented in practice take a look at jamvm, it is a truly
remarkable clear, concise and small implementation. Nothing bad about other
runtimes, but jamvm is small enough that you can read the code, sit down with
the spec and compare them almost directly to get a really nice insight in how
things are/can be done.

Cheers,

Mark




More information about the core-libs-dev mailing list