> On 25 Nov 2015, at 18:29, Peter Levart <peter.lev...@gmail.com> wrote: > > > > On 11/25/2015 12:46 PM, Paul Sandoz wrote: >> We are in Unsafe territory :-) >> >> >> Since the Java mismatch method and the intrinsic only make temporary reads, >> IIUC such updates by GC to the array can only occur at a safe points, and i >> don’t think int loops produce a safe point check within the hot loop and nor >> does the intrinsic, is this really an issue? >> > > IIUC, in interpreter, safepoint can happen between any two bytecodes: > > "Safepoints are initiated using a cooperative, polling-based mechanism. In > simple terms, every so often a thread asks “should I block for a safepoint?”. > Asking this question efficiently is not so simple. One place where the > question is often asked is during a thread state transition. Not all state > transitions do this, for example a thread leaving the VM to go to native > code, but many do. The other places where a thread asks are in compiled code > when returning from a method or at certain stages during loop iteration. > Threads executing interpreted code don't usually ask the question, instead > when the safepoint is requested the interpreter switches to a different > dispatch table that includes the code to ask the question; when the safepoint > is over, the dispatch table is switched back again. Once a safepoint has been > requested, the VMThread must wait until all threads are known to be in a > safepoint-safe state before proceeding to execute the VM operation. During a > safepoint the Threads_lock is used to block any threads that were running, > with the VMThread finally releasing the Threads_lock after the VM operation > has been performed." >
Ah, i see, if in the interpreter the dispatch table is switched between getting av and bv then that would be a problem: long av = U.getLongUnaligned(a, aOffset + bi); long bv = U.getLongUnaligned(b, bOffset + bi); I will document that this method should not be used with reference component types :-) (i anyway neglected to mention about alignment in those cases). Thanks, Paul. > > You could treat a "false positive" mismatch like you do with NaN floats and > doubles (fall-back to normal code), but what about "false negatives"? > > Suppose that you take a snapshot of address of object A from the 1st array, > followed by safepoint which moves object A to somewhere else and moves object > B to the same address A has occupied before (compacting collector). After > safepoint returns, you take the snapshot of address of object B from the > corresponding slot of the 2nd array. Now you compare the addresses and they > are the same, but they represent(ed) pointers to distinct objects. > > Regards, Peter >