RFR: JDK-8205549 JDK-8205698 Support of flattened values in Unsafe
mandy chung
mandy.chung at oracle.com
Fri Jun 29 21:15:49 UTC 2018
On 6/29/18 1:36 PM, Frederic Parain wrote:
> I’d prefer asserts then just let the VM crash unpredictably.
> But we’re speaking about Unsafe, do whatever you want
> for getObject()/putObject().
>
> However, put*() methods should (must?) enforce value types immutability
> (this includes primitive fields too). I haven’t seen this in Mandy’s changeset
> (but I might I missed it).
This is not enforced (as John explains) in Unsafe::putXXX methods as
they are unsafe access. VarHandle and core reflection have an explicit
guard to disallow writing to fields of a value type [1][2]. Final is
final for value types. The caller to putValueXXX does require the
new value to be non-null (see X-VarHandle.java.template).
The check you put in in your patch is to throw NPE if it's writing
null to a flat field of value type. That is not done in the library
and I will create a JBS issue and fix that separately.
Mandy
[1]
http://hg.openjdk.java.net/valhalla/valhalla/file/tip/src/java.base/share/classes/java/lang/invoke/MethodHandles.java#l2419
[2]
http://hg.openjdk.java.net/valhalla/valhalla/file/tip/src/java.base/share/classes/java/lang/reflect/Field.java#l168
More information about the valhalla-dev
mailing list