8199462: Use Reference.reachabilityFence in direct ByteBuffer methods

Reviewed-by: psandoz, vlivanov, plevart
This commit is contained in:
Ben Walsh 2018-03-12 16:09:18 -07:00 committed by Paul Sandoz
parent f439f2166b
commit de3604ea0c
6 changed files with 113 additions and 67 deletions

View file

@ -26,6 +26,7 @@
package java.nio;
import java.io.FileDescriptor;
import java.lang.ref.Reference;
import jdk.internal.misc.Unsafe;
@ -166,9 +167,15 @@ public abstract class MappedByteBuffer
int count = Bits.pageCount(length);
long a = mappingAddress(offset);
byte x = 0;
for (int i=0; i<count; i++) {
x ^= unsafe.getByte(a);
a += ps;
try {
for (int i=0; i<count; i++) {
// TODO consider changing to getByteOpaque thus avoiding
// dead code elimination and the need to calculate a checksum
x ^= unsafe.getByte(a);
a += ps;
}
} finally {
Reference.reachabilityFence(this);
}
if (unused != 0)
unused = x;