Replacing Unsafe.allocateInstance
Paul Sandoz
paul.sandoz at oracle.com
Tue Aug 4 15:39:13 UTC 2015
On 2 Aug 2015, at 09:52, Christoph Engelbert <chris at hazelcast.com> wrote:
> Hey Paul,
>
> The assumption of non creating JDK classes without calling constructors is not completely right.
> Seen serialization frameworks that create String instances and “injecting” a char[] afterwards however I prefer calling the package private constructor to just prevent copying of the char[] (in cases where it won’t break the immutability contract like deserialisation)
This is of course playing with fire on many levels and totally unsupported :-)
The package private constructor could go away, the internals of String could change (e.g. optimise for UTF-8 ) in a manner that is also not global (imagine species of String, each with different layouts, char[], byte[] UTF-8, String object header fused with an array).
We need frozen arrays:
http://cr.openjdk.java.net/~jrose/arrays/frozen-array-value-rules.html
Paul.
More information about the jdk9-dev
mailing list