RFR: JDK-8205549 JDK-8205698 Support of flattened values in Unsafe

Paul Sandoz paul.sandoz at oracle.com
Fri Jun 29 20:51:52 UTC 2018



> On Jun 29, 2018, at 1:36 PM, Frederic Parain <frederic.parain at oracle.com> 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).

It’s a similar problem to the writing of final fields. Since it's possible peek and poke at any memory location with Unsafe with byte to longs and now to compound values in a single call i am unsure how we can, in general, enforce immutability or stop word tearing. Unsafe accesses can break the integrity of the VM in many ways.

Such enforcement is easier if performed by the caller. Perhaps there are ways to define a set of ranges over which an offset+length is valid for writes to a base Object but that requires bounds checking and this is the kind of checking that is currently performed by the caller (and it will not be enforced for off-heap access to the same memory addresses as the base Object).

Paul.


> I haven’t seen this in Mandy’s changeset
> (but I might I missed it).
> 
> Fred
> 
> 
>> On Jun 29, 2018, at 12:35, Paul Sandoz <paul.sandoz at oracle.com> wrote:
>> 
>> 
>> 
>>> On Jun 29, 2018, at 7:14 AM, Frederic Parain <frederic.parain at oracle.com> wrote:
>>> 
>>> The legacy getObject()/putObject() would be maintained with value
>>> types support just the time to allow a smooth transition.
>>> 
>> 
>> IMHO i think these should be left as is. Various external (and of course unsupported!) usages of Unsafe do all sorts of crazy things and there is a risk those usages could be perturbed, either due to performance or because the new code infers something incorrectly.
>> 
>> I would like to suggest an alternative if this is a major concern. Modify the sun.misc.Unsafe implementation in the unsupported module and add asserts to the Java implementations to fail if it is detected value types are used. Then document the restrictions.
>> 
>> Paul.
> 




More information about the valhalla-dev mailing list