author | bpb |
Wed, 20 Feb 2019 10:57:22 -0800 | |
changeset 53855 | 7c362992527a |
parent 48356 | 29e165bdf669 |
child 53901 | 0448cb38c418 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
53855 | 2 |
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
#warn This file is preprocessed before being compiled |
|
27 |
||
28 |
package java.nio; |
|
29 |
||
30 |
/** |
|
31 |
#if[rw] |
|
32 |
* A read/write Heap$Type$Buffer. |
|
33 |
#else[rw] |
|
34 |
* A read-only Heap$Type$Buffer. This class extends the corresponding |
|
35 |
* read/write class, overriding the mutation methods to throw a {@link |
|
36 |
* ReadOnlyBufferException} and overriding the view-buffer methods to return an |
|
37 |
* instance of this class rather than of the superclass. |
|
38 |
#end[rw] |
|
39 |
*/ |
|
40 |
||
53855 | 41 |
import java.util.Objects; |
42 |
||
2 | 43 |
class Heap$Type$Buffer$RW$ |
44 |
extends {#if[ro]?Heap}$Type$Buffer |
|
45 |
{ |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
46 |
// Cached array base offset |
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
47 |
private static final long ARRAY_BASE_OFFSET = UNSAFE.arrayBaseOffset($type$[].class); |
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
48 |
|
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
49 |
// Cached array base offset |
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
50 |
private static final long ARRAY_INDEX_SCALE = UNSAFE.arrayIndexScale($type$[].class); |
2 | 51 |
|
52 |
// For speed these fields are actually declared in X-Buffer; |
|
53 |
// these declarations are here as documentation |
|
54 |
/* |
|
55 |
#if[rw] |
|
56 |
protected final $type$[] hb; |
|
57 |
protected final int offset; |
|
58 |
#end[rw] |
|
59 |
*/ |
|
60 |
||
61 |
Heap$Type$Buffer$RW$(int cap, int lim) { // package-private |
|
62 |
#if[rw] |
|
63 |
super(-1, 0, lim, cap, new $type$[cap], 0); |
|
64 |
/* |
|
65 |
hb = new $type$[cap]; |
|
66 |
offset = 0; |
|
67 |
*/ |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
68 |
this.address = ARRAY_BASE_OFFSET; |
2 | 69 |
#else[rw] |
70 |
super(cap, lim); |
|
71 |
this.isReadOnly = true; |
|
72 |
#end[rw] |
|
73 |
} |
|
74 |
||
75 |
Heap$Type$Buffer$RW$($type$[] buf, int off, int len) { // package-private |
|
76 |
#if[rw] |
|
77 |
super(-1, off, off + len, buf.length, buf, 0); |
|
78 |
/* |
|
79 |
hb = buf; |
|
80 |
offset = 0; |
|
81 |
*/ |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
82 |
this.address = ARRAY_BASE_OFFSET; |
2 | 83 |
#else[rw] |
84 |
super(buf, off, len); |
|
85 |
this.isReadOnly = true; |
|
86 |
#end[rw] |
|
87 |
} |
|
88 |
||
89 |
protected Heap$Type$Buffer$RW$($type$[] buf, |
|
90 |
int mark, int pos, int lim, int cap, |
|
91 |
int off) |
|
92 |
{ |
|
93 |
#if[rw] |
|
94 |
super(mark, pos, lim, cap, buf, off); |
|
95 |
/* |
|
96 |
hb = buf; |
|
97 |
offset = off; |
|
98 |
*/ |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
99 |
this.address = ARRAY_BASE_OFFSET + off * ARRAY_INDEX_SCALE; |
2 | 100 |
#else[rw] |
101 |
super(buf, mark, pos, lim, cap, off); |
|
102 |
this.isReadOnly = true; |
|
103 |
#end[rw] |
|
104 |
} |
|
105 |
||
106 |
public $Type$Buffer slice() { |
|
107 |
return new Heap$Type$Buffer$RW$(hb, |
|
108 |
-1, |
|
109 |
0, |
|
110 |
this.remaining(), |
|
111 |
this.remaining(), |
|
112 |
this.position() + offset); |
|
113 |
} |
|
114 |
||
36933
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
115 |
#if[byte] |
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
116 |
$Type$Buffer slice(int pos, int lim) { |
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
117 |
assert (pos >= 0); |
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
118 |
assert (pos <= lim); |
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
119 |
int rem = lim - pos; |
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
120 |
return new Heap$Type$Buffer$RW$(hb, |
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
121 |
-1, |
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
122 |
0, |
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
123 |
rem, |
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
124 |
rem, |
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
125 |
pos + offset); |
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
126 |
} |
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
127 |
#end[byte] |
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
128 |
|
2 | 129 |
public $Type$Buffer duplicate() { |
130 |
return new Heap$Type$Buffer$RW$(hb, |
|
131 |
this.markValue(), |
|
132 |
this.position(), |
|
133 |
this.limit(), |
|
134 |
this.capacity(), |
|
135 |
offset); |
|
136 |
} |
|
137 |
||
138 |
public $Type$Buffer asReadOnlyBuffer() { |
|
139 |
#if[rw] |
|
140 |
return new Heap$Type$BufferR(hb, |
|
141 |
this.markValue(), |
|
142 |
this.position(), |
|
143 |
this.limit(), |
|
144 |
this.capacity(), |
|
145 |
offset); |
|
146 |
#else[rw] |
|
147 |
return duplicate(); |
|
148 |
#end[rw] |
|
149 |
} |
|
150 |
||
151 |
#if[rw] |
|
152 |
||
153 |
protected int ix(int i) { |
|
154 |
return i + offset; |
|
155 |
} |
|
156 |
||
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
157 |
#if[byte] |
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
158 |
private long byteOffset(long i) { |
36933
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
159 |
return address + i; |
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
160 |
} |
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
161 |
#end[byte] |
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
162 |
|
2 | 163 |
public $type$ get() { |
164 |
return hb[ix(nextGetIndex())]; |
|
165 |
} |
|
166 |
||
167 |
public $type$ get(int i) { |
|
168 |
return hb[ix(checkIndex(i))]; |
|
169 |
} |
|
170 |
||
17922
d56eec572de5
8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents:
5506
diff
changeset
|
171 |
#if[streamableType] |
d56eec572de5
8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents:
5506
diff
changeset
|
172 |
$type$ getUnchecked(int i) { |
d56eec572de5
8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents:
5506
diff
changeset
|
173 |
return hb[ix(i)]; |
d56eec572de5
8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents:
5506
diff
changeset
|
174 |
} |
d56eec572de5
8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents:
5506
diff
changeset
|
175 |
#end[streamableType] |
d56eec572de5
8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents:
5506
diff
changeset
|
176 |
|
2 | 177 |
public $Type$Buffer get($type$[] dst, int offset, int length) { |
178 |
checkBounds(offset, length, dst.length); |
|
179 |
if (length > remaining()) |
|
180 |
throw new BufferUnderflowException(); |
|
181 |
System.arraycopy(hb, ix(position()), dst, offset, length); |
|
182 |
position(position() + length); |
|
183 |
return this; |
|
184 |
} |
|
185 |
||
53855 | 186 |
public $Type$Buffer get(int index, $type$[] dst, int offset, int length) { |
187 |
Objects.checkFromIndexSize(index, length, limit()); |
|
188 |
Objects.checkFromIndexSize(offset, length, dst.length); |
|
189 |
System.arraycopy(hb, ix(index), dst, offset, length); |
|
190 |
return this; |
|
191 |
} |
|
192 |
||
2 | 193 |
public boolean isDirect() { |
194 |
return false; |
|
195 |
} |
|
196 |
||
197 |
#end[rw] |
|
198 |
||
199 |
public boolean isReadOnly() { |
|
200 |
return {#if[rw]?false:true}; |
|
201 |
} |
|
202 |
||
203 |
public $Type$Buffer put($type$ x) { |
|
204 |
#if[rw] |
|
205 |
hb[ix(nextPutIndex())] = x; |
|
206 |
return this; |
|
207 |
#else[rw] |
|
208 |
throw new ReadOnlyBufferException(); |
|
209 |
#end[rw] |
|
210 |
} |
|
211 |
||
212 |
public $Type$Buffer put(int i, $type$ x) { |
|
213 |
#if[rw] |
|
214 |
hb[ix(checkIndex(i))] = x; |
|
215 |
return this; |
|
216 |
#else[rw] |
|
217 |
throw new ReadOnlyBufferException(); |
|
218 |
#end[rw] |
|
219 |
} |
|
220 |
||
221 |
public $Type$Buffer put($type$[] src, int offset, int length) { |
|
222 |
#if[rw] |
|
223 |
checkBounds(offset, length, src.length); |
|
224 |
if (length > remaining()) |
|
225 |
throw new BufferOverflowException(); |
|
226 |
System.arraycopy(src, offset, hb, ix(position()), length); |
|
227 |
position(position() + length); |
|
228 |
return this; |
|
229 |
#else[rw] |
|
230 |
throw new ReadOnlyBufferException(); |
|
231 |
#end[rw] |
|
232 |
} |
|
233 |
||
234 |
public $Type$Buffer put($Type$Buffer src) { |
|
235 |
#if[rw] |
|
236 |
if (src instanceof Heap$Type$Buffer) { |
|
237 |
if (src == this) |
|
31873
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
30338
diff
changeset
|
238 |
throw createSameBufferException(); |
2 | 239 |
Heap$Type$Buffer sb = (Heap$Type$Buffer)src; |
240 |
int n = sb.remaining(); |
|
241 |
if (n > remaining()) |
|
242 |
throw new BufferOverflowException(); |
|
243 |
System.arraycopy(sb.hb, sb.ix(sb.position()), |
|
244 |
hb, ix(position()), n); |
|
245 |
sb.position(sb.position() + n); |
|
246 |
position(position() + n); |
|
247 |
} else if (src.isDirect()) { |
|
248 |
int n = src.remaining(); |
|
249 |
if (n > remaining()) |
|
250 |
throw new BufferOverflowException(); |
|
251 |
src.get(hb, ix(position()), n); |
|
252 |
position(position() + n); |
|
253 |
} else { |
|
254 |
super.put(src); |
|
255 |
} |
|
256 |
return this; |
|
257 |
#else[rw] |
|
258 |
throw new ReadOnlyBufferException(); |
|
259 |
#end[rw] |
|
260 |
} |
|
261 |
||
53855 | 262 |
public $Type$Buffer put(int index, $type$[] src, int offset, int length) { |
263 |
#if[rw] |
|
264 |
Objects.checkFromIndexSize(index, length, limit()); |
|
265 |
Objects.checkFromIndexSize(offset, length, src.length); |
|
266 |
System.arraycopy(src, offset, hb, ix(index), length); |
|
267 |
return this; |
|
268 |
#else[rw] |
|
269 |
throw new ReadOnlyBufferException(); |
|
270 |
#end[rw] |
|
271 |
} |
|
272 |
||
2 | 273 |
public $Type$Buffer compact() { |
274 |
#if[rw] |
|
275 |
System.arraycopy(hb, ix(position()), hb, ix(0), remaining()); |
|
276 |
position(remaining()); |
|
277 |
limit(capacity()); |
|
1634
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
1247
diff
changeset
|
278 |
discardMark(); |
2 | 279 |
return this; |
280 |
#else[rw] |
|
281 |
throw new ReadOnlyBufferException(); |
|
282 |
#end[rw] |
|
283 |
} |
|
284 |
||
285 |
||
286 |
||
287 |
#if[byte] |
|
288 |
||
289 |
byte _get(int i) { // package-private |
|
290 |
return hb[i]; |
|
291 |
} |
|
292 |
||
293 |
void _put(int i, byte b) { // package-private |
|
294 |
#if[rw] |
|
295 |
hb[i] = b; |
|
296 |
#else[rw] |
|
297 |
throw new ReadOnlyBufferException(); |
|
298 |
#end[rw] |
|
299 |
} |
|
300 |
||
301 |
// char |
|
302 |
||
303 |
#if[rw] |
|
304 |
||
305 |
public char getChar() { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
306 |
return UNSAFE.getCharUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian); |
2 | 307 |
} |
308 |
||
309 |
public char getChar(int i) { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
310 |
return UNSAFE.getCharUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian); |
2 | 311 |
} |
312 |
||
313 |
#end[rw] |
|
314 |
||
315 |
public $Type$Buffer putChar(char x) { |
|
316 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
317 |
UNSAFE.putCharUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian); |
2 | 318 |
return this; |
319 |
#else[rw] |
|
320 |
throw new ReadOnlyBufferException(); |
|
321 |
#end[rw] |
|
322 |
} |
|
323 |
||
324 |
public $Type$Buffer putChar(int i, char x) { |
|
325 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
326 |
UNSAFE.putCharUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian); |
2 | 327 |
return this; |
328 |
#else[rw] |
|
329 |
throw new ReadOnlyBufferException(); |
|
330 |
#end[rw] |
|
331 |
} |
|
332 |
||
333 |
public CharBuffer asCharBuffer() { |
|
334 |
int size = this.remaining() >> 1; |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
335 |
long addr = address + position(); |
2 | 336 |
return (bigEndian |
337 |
? (CharBuffer)(new ByteBufferAsCharBuffer$RW$B(this, |
|
338 |
-1, |
|
339 |
0, |
|
340 |
size, |
|
341 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
342 |
addr)) |
2 | 343 |
: (CharBuffer)(new ByteBufferAsCharBuffer$RW$L(this, |
344 |
-1, |
|
345 |
0, |
|
346 |
size, |
|
347 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
348 |
addr))); |
2 | 349 |
} |
350 |
||
351 |
||
352 |
// short |
|
353 |
||
354 |
#if[rw] |
|
355 |
||
356 |
public short getShort() { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
357 |
return UNSAFE.getShortUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian); |
2 | 358 |
} |
359 |
||
360 |
public short getShort(int i) { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
361 |
return UNSAFE.getShortUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian); |
2 | 362 |
} |
363 |
||
364 |
#end[rw] |
|
365 |
||
366 |
public $Type$Buffer putShort(short x) { |
|
367 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
368 |
UNSAFE.putShortUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian); |
2 | 369 |
return this; |
370 |
#else[rw] |
|
371 |
throw new ReadOnlyBufferException(); |
|
372 |
#end[rw] |
|
373 |
} |
|
374 |
||
375 |
public $Type$Buffer putShort(int i, short x) { |
|
376 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
377 |
UNSAFE.putShortUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian); |
2 | 378 |
return this; |
379 |
#else[rw] |
|
380 |
throw new ReadOnlyBufferException(); |
|
381 |
#end[rw] |
|
382 |
} |
|
383 |
||
384 |
public ShortBuffer asShortBuffer() { |
|
385 |
int size = this.remaining() >> 1; |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
386 |
long addr = address + position(); |
2 | 387 |
return (bigEndian |
388 |
? (ShortBuffer)(new ByteBufferAsShortBuffer$RW$B(this, |
|
389 |
-1, |
|
390 |
0, |
|
391 |
size, |
|
392 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
393 |
addr)) |
2 | 394 |
: (ShortBuffer)(new ByteBufferAsShortBuffer$RW$L(this, |
395 |
-1, |
|
396 |
0, |
|
397 |
size, |
|
398 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
399 |
addr))); |
2 | 400 |
} |
401 |
||
402 |
||
403 |
// int |
|
404 |
||
405 |
#if[rw] |
|
406 |
||
407 |
public int getInt() { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
408 |
return UNSAFE.getIntUnaligned(hb, byteOffset(nextGetIndex(4)), bigEndian); |
2 | 409 |
} |
410 |
||
411 |
public int getInt(int i) { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
412 |
return UNSAFE.getIntUnaligned(hb, byteOffset(checkIndex(i, 4)), bigEndian); |
2 | 413 |
} |
414 |
||
415 |
#end[rw] |
|
416 |
||
417 |
public $Type$Buffer putInt(int x) { |
|
418 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
419 |
UNSAFE.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), x, bigEndian); |
2 | 420 |
return this; |
421 |
#else[rw] |
|
422 |
throw new ReadOnlyBufferException(); |
|
423 |
#end[rw] |
|
424 |
} |
|
425 |
||
426 |
public $Type$Buffer putInt(int i, int x) { |
|
427 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
428 |
UNSAFE.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), x, bigEndian); |
2 | 429 |
return this; |
430 |
#else[rw] |
|
431 |
throw new ReadOnlyBufferException(); |
|
432 |
#end[rw] |
|
433 |
} |
|
434 |
||
435 |
public IntBuffer asIntBuffer() { |
|
436 |
int size = this.remaining() >> 2; |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
437 |
long addr = address + position(); |
2 | 438 |
return (bigEndian |
439 |
? (IntBuffer)(new ByteBufferAsIntBuffer$RW$B(this, |
|
440 |
-1, |
|
441 |
0, |
|
442 |
size, |
|
443 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
444 |
addr)) |
2 | 445 |
: (IntBuffer)(new ByteBufferAsIntBuffer$RW$L(this, |
446 |
-1, |
|
447 |
0, |
|
448 |
size, |
|
449 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
450 |
addr))); |
2 | 451 |
} |
452 |
||
453 |
||
454 |
// long |
|
455 |
||
456 |
#if[rw] |
|
457 |
||
458 |
public long getLong() { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
459 |
return UNSAFE.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian); |
2 | 460 |
} |
461 |
||
462 |
public long getLong(int i) { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
463 |
return UNSAFE.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian); |
2 | 464 |
} |
465 |
||
466 |
#end[rw] |
|
467 |
||
468 |
public $Type$Buffer putLong(long x) { |
|
469 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
470 |
UNSAFE.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), x, bigEndian); |
2 | 471 |
return this; |
472 |
#else[rw] |
|
473 |
throw new ReadOnlyBufferException(); |
|
474 |
#end[rw] |
|
475 |
} |
|
476 |
||
477 |
public $Type$Buffer putLong(int i, long x) { |
|
478 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
479 |
UNSAFE.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), x, bigEndian); |
2 | 480 |
return this; |
481 |
#else[rw] |
|
482 |
throw new ReadOnlyBufferException(); |
|
483 |
#end[rw] |
|
484 |
} |
|
485 |
||
486 |
public LongBuffer asLongBuffer() { |
|
487 |
int size = this.remaining() >> 3; |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
488 |
long addr = address + position(); |
2 | 489 |
return (bigEndian |
490 |
? (LongBuffer)(new ByteBufferAsLongBuffer$RW$B(this, |
|
491 |
-1, |
|
492 |
0, |
|
493 |
size, |
|
494 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
495 |
addr)) |
2 | 496 |
: (LongBuffer)(new ByteBufferAsLongBuffer$RW$L(this, |
497 |
-1, |
|
498 |
0, |
|
499 |
size, |
|
500 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
501 |
addr))); |
2 | 502 |
} |
503 |
||
504 |
||
505 |
// float |
|
506 |
||
507 |
#if[rw] |
|
508 |
||
509 |
public float getFloat() { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
510 |
int x = UNSAFE.getIntUnaligned(hb, byteOffset(nextGetIndex(4)), bigEndian); |
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
511 |
return Float.intBitsToFloat(x); |
2 | 512 |
} |
513 |
||
514 |
public float getFloat(int i) { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
515 |
int x = UNSAFE.getIntUnaligned(hb, byteOffset(checkIndex(i, 4)), bigEndian); |
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
516 |
return Float.intBitsToFloat(x); |
2 | 517 |
} |
518 |
||
519 |
#end[rw] |
|
520 |
||
521 |
public $Type$Buffer putFloat(float x) { |
|
522 |
#if[rw] |
|
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
523 |
int y = Float.floatToRawIntBits(x); |
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
524 |
UNSAFE.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), y, bigEndian); |
2 | 525 |
return this; |
526 |
#else[rw] |
|
527 |
throw new ReadOnlyBufferException(); |
|
528 |
#end[rw] |
|
529 |
} |
|
530 |
||
531 |
public $Type$Buffer putFloat(int i, float x) { |
|
532 |
#if[rw] |
|
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
533 |
int y = Float.floatToRawIntBits(x); |
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
534 |
UNSAFE.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), y, bigEndian); |
2 | 535 |
return this; |
536 |
#else[rw] |
|
537 |
throw new ReadOnlyBufferException(); |
|
538 |
#end[rw] |
|
539 |
} |
|
540 |
||
541 |
public FloatBuffer asFloatBuffer() { |
|
542 |
int size = this.remaining() >> 2; |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
543 |
long addr = address + position(); |
2 | 544 |
return (bigEndian |
545 |
? (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$B(this, |
|
546 |
-1, |
|
547 |
0, |
|
548 |
size, |
|
549 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
550 |
addr)) |
2 | 551 |
: (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$L(this, |
552 |
-1, |
|
553 |
0, |
|
554 |
size, |
|
555 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
556 |
addr))); |
2 | 557 |
} |
558 |
||
559 |
||
560 |
// double |
|
561 |
||
562 |
#if[rw] |
|
563 |
||
564 |
public double getDouble() { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
565 |
long x = UNSAFE.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian); |
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
566 |
return Double.longBitsToDouble(x); |
2 | 567 |
} |
568 |
||
569 |
public double getDouble(int i) { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
570 |
long x = UNSAFE.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian); |
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
571 |
return Double.longBitsToDouble(x); |
2 | 572 |
} |
573 |
||
574 |
#end[rw] |
|
575 |
||
576 |
public $Type$Buffer putDouble(double x) { |
|
577 |
#if[rw] |
|
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
578 |
long y = Double.doubleToRawLongBits(x); |
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
579 |
UNSAFE.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), y, bigEndian); |
2 | 580 |
return this; |
581 |
#else[rw] |
|
582 |
throw new ReadOnlyBufferException(); |
|
583 |
#end[rw] |
|
584 |
} |
|
585 |
||
586 |
public $Type$Buffer putDouble(int i, double x) { |
|
587 |
#if[rw] |
|
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
588 |
long y = Double.doubleToRawLongBits(x); |
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
589 |
UNSAFE.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), y, bigEndian); |
2 | 590 |
return this; |
591 |
#else[rw] |
|
592 |
throw new ReadOnlyBufferException(); |
|
593 |
#end[rw] |
|
594 |
} |
|
595 |
||
596 |
public DoubleBuffer asDoubleBuffer() { |
|
597 |
int size = this.remaining() >> 3; |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
598 |
long addr = address + position(); |
2 | 599 |
return (bigEndian |
600 |
? (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$B(this, |
|
601 |
-1, |
|
602 |
0, |
|
603 |
size, |
|
604 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
605 |
addr)) |
2 | 606 |
: (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$L(this, |
607 |
-1, |
|
608 |
0, |
|
609 |
size, |
|
610 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
611 |
addr))); |
2 | 612 |
} |
613 |
||
614 |
||
615 |
#end[byte] |
|
616 |
||
617 |
||
618 |
#if[char] |
|
619 |
||
620 |
String toString(int start, int end) { // package-private |
|
621 |
try { |
|
622 |
return new String(hb, start + offset, end - start); |
|
623 |
} catch (StringIndexOutOfBoundsException x) { |
|
624 |
throw new IndexOutOfBoundsException(); |
|
625 |
} |
|
626 |
} |
|
627 |
||
628 |
||
629 |
// --- Methods to support CharSequence --- |
|
630 |
||
1224
8c1bc7c5dd00
6733145: (bf) CharBuffer.subSequence can be updated to take advantage of covariant returns
martin
parents:
2
diff
changeset
|
631 |
public CharBuffer subSequence(int start, int end) { |
2 | 632 |
if ((start < 0) |
633 |
|| (end > length()) |
|
634 |
|| (start > end)) |
|
635 |
throw new IndexOutOfBoundsException(); |
|
2593
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1634
diff
changeset
|
636 |
int pos = position(); |
2 | 637 |
return new HeapCharBuffer$RW$(hb, |
2593
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1634
diff
changeset
|
638 |
-1, |
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1634
diff
changeset
|
639 |
pos + start, |
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1634
diff
changeset
|
640 |
pos + end, |
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1634
diff
changeset
|
641 |
capacity(), |
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1634
diff
changeset
|
642 |
offset); |
2 | 643 |
} |
644 |
||
645 |
#end[char] |
|
646 |
||
647 |
||
648 |
#if[!byte] |
|
649 |
||
650 |
public ByteOrder order() { |
|
651 |
return ByteOrder.nativeOrder(); |
|
652 |
} |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
653 |
#end[!byte] |
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
654 |
#if[char] |
2 | 655 |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
656 |
ByteOrder charRegionOrder() { |
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
657 |
return order(); |
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
658 |
} |
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
659 |
#end[char] |
2 | 660 |
} |