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 } |