jdk/src/share/classes/java/nio/Direct-X-Buffer.java.template
changeset 6902 3352f8839320
parent 5506 202f599c92aa
child 7025 6e002f9a2899
--- a/jdk/src/share/classes/java/nio/Direct-X-Buffer.java.template	Fri Oct 15 15:09:37 2010 +0100
+++ b/jdk/src/share/classes/java/nio/Direct-X-Buffer.java.template	Mon Oct 18 10:29:59 2010 +0100
@@ -29,6 +29,7 @@
 
 import sun.misc.Cleaner;
 import sun.misc.Unsafe;
+import sun.misc.VM;
 import sun.nio.ch.DirectBuffer;
 
 
@@ -114,8 +115,9 @@
     Direct$Type$Buffer$RW$(int cap) {                   // package-private
 #if[rw]
         super(-1, 0, cap, cap, false);
+        boolean pa = VM.isDirectMemoryPageAligned();
         int ps = Bits.pageSize();
-        int size = cap + ps;
+        long size = Math.max(1L, (long)cap + (pa ? ps : 0));
         Bits.reserveMemory(size, cap);
 
         long base = 0;
@@ -126,7 +128,7 @@
             throw x;
         }
         unsafe.setMemory(base, size, (byte) 0);
-        if (base % ps != 0) {
+        if (pa && (base % ps != 0)) {
             // Round up to page boundary
             address = base + ps - (base & (ps - 1));
         } else {