From 2d702e4a42efeea4d8cca316e232875111d9b4ec Mon Sep 17 00:00:00 2001 From: alanb Date: Wed, 16 May 2012 12:43:27 +0100 Subject: [PATCH] 7168505: (bf) MappedByteBuffer.load does not load buffer's content into memory Reviewed-by: mduigou, forax --- src/share/classes/java/nio/MappedByteBuffer.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/share/classes/java/nio/MappedByteBuffer.java b/src/share/classes/java/nio/MappedByteBuffer.java index e07ed1e2e..b022e1ca0 100644 --- a/src/share/classes/java/nio/MappedByteBuffer.java +++ b/src/share/classes/java/nio/MappedByteBuffer.java @@ -139,6 +139,9 @@ public abstract class MappedByteBuffer return isLoaded0(mappingAddress(offset), length, Bits.pageCount(length)); } + // not used, but a potential target for a store, see load() for details. + private static byte unused; + /** * Loads this buffer's content into physical memory. * @@ -157,15 +160,20 @@ public abstract class MappedByteBuffer long length = mappingLength(offset); load0(mappingAddress(offset), length); - // touch each page + // Read a byte from each page to bring it into memory. A checksum + // is computed as we go along to prevent the compiler from otherwise + // considering the loop as dead code. Unsafe unsafe = Unsafe.getUnsafe(); int ps = Bits.pageSize(); int count = Bits.pageCount(length); long a = mappingAddress(offset); + byte x = 0; for (int i=0; i