[jmm-dev] VarHandle.safepoint() methods
dl at cs.oswego.edu
Thu Jan 5 12:55:18 UTC 2017
On 01/05/2017 04:56 AM, Andrew Haley wrote:
>> The runtime is free to insert "checkpoint crossing boundaries"
>> anywhere in code (between any two bytecodes), except where
>> specifically prohibited by contract.
> I think I see. The underlying implementation mechanism would be
> essentially the same, and would still allow references to be hoisted
> out of loops, but we have an easier way to describe it in the
> specification language.
A complementary approach would be to allow programmers
to manually insert safepoint checks, such that the JVM would
not insert one if already there.
As in (for some field x, VH X, and local r:)
r = X.get(this);
if (VarHandles.checkPointed()) // returns true if safepoint
r = X.getAcquire(this);
(This is analogous to cases when you manually null-check
a reference -- the VM does not insert another one.)
There would need to be some rules and/or a checker tool,
which seem hard to come up with. But it would at least
avoid needing to specify a special variant of VH.get,
which seems even harder.
More information about the jmm-dev