[jmm-dev] Optimizing external actions in the JMM
nitsanw at yahoo.com
Fri Jul 8 11:08:01 UTC 2016
where f is some external action that the compiler understands. If the
compiler knows `f` always returns 42 and has no other effect, can it
optimize ThreadA to
thereby introducing a OOTA-like value of 42 into the system?"
Why is this OOTA?
The thing is you define:
"external action that... always returns 42 and has no other effect"
Which according to:
"An external action is an action that may be observable outside of an execution,
and has a result based on an environment external to the execution."
is not an external action.
To make a function an "external action" we need to satisfy:
1. "may be observable outside of an execution" AND
2. "has a result based on an environment external to the execution"
The concerns you raise around off-heap memory handling boil down to:
- Unsafe.put(long address,*)/Unsafe.put(null, long address,*): don't fullfil 2
- Unsafe.get*(long address)/Unsafe.get*(null, long address): don't fullfil 1
The volatile accesses to offheap are not covered by JMM AFAIK, but are relied
upon by many to mean the same as their heap counter parts.
More information about the jmm-dev