jdk/src/share/classes/java/nio/Direct-X-Buffer.java.template
changeset 6902 3352f8839320
parent 5506 202f599c92aa
child 7025 6e002f9a2899
equal deleted inserted replaced
6897:561a431cf238 6902:3352f8839320
    27 
    27 
    28 package java.nio;
    28 package java.nio;
    29 
    29 
    30 import sun.misc.Cleaner;
    30 import sun.misc.Cleaner;
    31 import sun.misc.Unsafe;
    31 import sun.misc.Unsafe;
       
    32 import sun.misc.VM;
    32 import sun.nio.ch.DirectBuffer;
    33 import sun.nio.ch.DirectBuffer;
    33 
    34 
    34 
    35 
    35 class Direct$Type$Buffer$RW$$BO$
    36 class Direct$Type$Buffer$RW$$BO$
    36 #if[rw]
    37 #if[rw]
   112     // Primary constructor
   113     // Primary constructor
   113     //
   114     //
   114     Direct$Type$Buffer$RW$(int cap) {                   // package-private
   115     Direct$Type$Buffer$RW$(int cap) {                   // package-private
   115 #if[rw]
   116 #if[rw]
   116         super(-1, 0, cap, cap, false);
   117         super(-1, 0, cap, cap, false);
       
   118         boolean pa = VM.isDirectMemoryPageAligned();
   117         int ps = Bits.pageSize();
   119         int ps = Bits.pageSize();
   118         int size = cap + ps;
   120         long size = Math.max(1L, (long)cap + (pa ? ps : 0));
   119         Bits.reserveMemory(size, cap);
   121         Bits.reserveMemory(size, cap);
   120 
   122 
   121         long base = 0;
   123         long base = 0;
   122         try {
   124         try {
   123             base = unsafe.allocateMemory(size);
   125             base = unsafe.allocateMemory(size);
   124         } catch (OutOfMemoryError x) {
   126         } catch (OutOfMemoryError x) {
   125             Bits.unreserveMemory(size, cap);
   127             Bits.unreserveMemory(size, cap);
   126             throw x;
   128             throw x;
   127         }
   129         }
   128         unsafe.setMemory(base, size, (byte) 0);
   130         unsafe.setMemory(base, size, (byte) 0);
   129         if (base % ps != 0) {
   131         if (pa && (base % ps != 0)) {
   130             // Round up to page boundary
   132             // Round up to page boundary
   131             address = base + ps - (base & (ps - 1));
   133             address = base + ps - (base & (ps - 1));
   132         } else {
   134         } else {
   133             address = base;
   135             address = base;
   134         }
   136         }