author | bpb |
Thu, 28 Feb 2019 12:05:59 -0800 | |
changeset 53959 | 1542e63eb537 |
parent 53901 | 0448cb38c418 |
child 54107 | 1d7aec80147a |
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 |
||
53959
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53901
diff
changeset
|
30 |
import java.util.Objects; |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53901
diff
changeset
|
31 |
|
2 | 32 |
/** |
33 |
#if[rw] |
|
34 |
* A read/write Heap$Type$Buffer. |
|
35 |
#else[rw] |
|
36 |
* A read-only Heap$Type$Buffer. This class extends the corresponding |
|
37 |
* read/write class, overriding the mutation methods to throw a {@link |
|
38 |
* ReadOnlyBufferException} and overriding the view-buffer methods to return an |
|
39 |
* instance of this class rather than of the superclass. |
|
40 |
#end[rw] |
|
41 |
*/ |
|
42 |
||
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 |
||
53959
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53901
diff
changeset
|
115 |
@Override |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53901
diff
changeset
|
116 |
public $Type$Buffer slice(int index, int length) { |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53901
diff
changeset
|
117 |
Objects.checkIndex(index, limit() + 1); |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53901
diff
changeset
|
118 |
Objects.checkIndex(length, limit() - index + 1); |
36933
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
119 |
return new Heap$Type$Buffer$RW$(hb, |
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
120 |
-1, |
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
121 |
0, |
53959
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53901
diff
changeset
|
122 |
length, |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53901
diff
changeset
|
123 |
length, |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53901
diff
changeset
|
124 |
index + offset); |
36933
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
125 |
} |
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
126 |
|
2 | 127 |
public $Type$Buffer duplicate() { |
128 |
return new Heap$Type$Buffer$RW$(hb, |
|
129 |
this.markValue(), |
|
130 |
this.position(), |
|
131 |
this.limit(), |
|
132 |
this.capacity(), |
|
133 |
offset); |
|
134 |
} |
|
135 |
||
136 |
public $Type$Buffer asReadOnlyBuffer() { |
|
137 |
#if[rw] |
|
138 |
return new Heap$Type$BufferR(hb, |
|
139 |
this.markValue(), |
|
140 |
this.position(), |
|
141 |
this.limit(), |
|
142 |
this.capacity(), |
|
143 |
offset); |
|
144 |
#else[rw] |
|
145 |
return duplicate(); |
|
146 |
#end[rw] |
|
147 |
} |
|
148 |
||
149 |
#if[rw] |
|
150 |
||
151 |
protected int ix(int i) { |
|
152 |
return i + offset; |
|
153 |
} |
|
154 |
||
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
155 |
#if[byte] |
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
156 |
private long byteOffset(long i) { |
36933
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
33665
diff
changeset
|
157 |
return address + i; |
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
158 |
} |
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
159 |
#end[byte] |
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
160 |
|
2 | 161 |
public $type$ get() { |
162 |
return hb[ix(nextGetIndex())]; |
|
163 |
} |
|
164 |
||
165 |
public $type$ get(int i) { |
|
166 |
return hb[ix(checkIndex(i))]; |
|
167 |
} |
|
168 |
||
17922
d56eec572de5
8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents:
5506
diff
changeset
|
169 |
#if[streamableType] |
d56eec572de5
8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents:
5506
diff
changeset
|
170 |
$type$ getUnchecked(int i) { |
d56eec572de5
8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents:
5506
diff
changeset
|
171 |
return hb[ix(i)]; |
d56eec572de5
8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents:
5506
diff
changeset
|
172 |
} |
d56eec572de5
8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents:
5506
diff
changeset
|
173 |
#end[streamableType] |
d56eec572de5
8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents:
5506
diff
changeset
|
174 |
|
2 | 175 |
public $Type$Buffer get($type$[] dst, int offset, int length) { |
176 |
checkBounds(offset, length, dst.length); |
|
177 |
if (length > remaining()) |
|
178 |
throw new BufferUnderflowException(); |
|
179 |
System.arraycopy(hb, ix(position()), dst, offset, length); |
|
180 |
position(position() + length); |
|
181 |
return this; |
|
182 |
} |
|
183 |
||
53855 | 184 |
public $Type$Buffer get(int index, $type$[] dst, int offset, int length) { |
185 |
Objects.checkFromIndexSize(index, length, limit()); |
|
186 |
Objects.checkFromIndexSize(offset, length, dst.length); |
|
187 |
System.arraycopy(hb, ix(index), dst, offset, length); |
|
188 |
return this; |
|
189 |
} |
|
190 |
||
2 | 191 |
public boolean isDirect() { |
192 |
return false; |
|
193 |
} |
|
194 |
||
195 |
#end[rw] |
|
196 |
||
197 |
public boolean isReadOnly() { |
|
198 |
return {#if[rw]?false:true}; |
|
199 |
} |
|
200 |
||
201 |
public $Type$Buffer put($type$ x) { |
|
202 |
#if[rw] |
|
203 |
hb[ix(nextPutIndex())] = x; |
|
204 |
return this; |
|
205 |
#else[rw] |
|
206 |
throw new ReadOnlyBufferException(); |
|
207 |
#end[rw] |
|
208 |
} |
|
209 |
||
210 |
public $Type$Buffer put(int i, $type$ x) { |
|
211 |
#if[rw] |
|
212 |
hb[ix(checkIndex(i))] = x; |
|
213 |
return this; |
|
214 |
#else[rw] |
|
215 |
throw new ReadOnlyBufferException(); |
|
216 |
#end[rw] |
|
217 |
} |
|
218 |
||
219 |
public $Type$Buffer put($type$[] src, int offset, int length) { |
|
220 |
#if[rw] |
|
221 |
checkBounds(offset, length, src.length); |
|
222 |
if (length > remaining()) |
|
223 |
throw new BufferOverflowException(); |
|
224 |
System.arraycopy(src, offset, hb, ix(position()), length); |
|
225 |
position(position() + length); |
|
226 |
return this; |
|
227 |
#else[rw] |
|
228 |
throw new ReadOnlyBufferException(); |
|
229 |
#end[rw] |
|
230 |
} |
|
231 |
||
232 |
public $Type$Buffer put($Type$Buffer src) { |
|
233 |
#if[rw] |
|
234 |
if (src instanceof Heap$Type$Buffer) { |
|
235 |
if (src == this) |
|
31873
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
30338
diff
changeset
|
236 |
throw createSameBufferException(); |
2 | 237 |
Heap$Type$Buffer sb = (Heap$Type$Buffer)src; |
238 |
int n = sb.remaining(); |
|
239 |
if (n > remaining()) |
|
240 |
throw new BufferOverflowException(); |
|
241 |
System.arraycopy(sb.hb, sb.ix(sb.position()), |
|
242 |
hb, ix(position()), n); |
|
243 |
sb.position(sb.position() + n); |
|
244 |
position(position() + n); |
|
245 |
} else if (src.isDirect()) { |
|
246 |
int n = src.remaining(); |
|
247 |
if (n > remaining()) |
|
248 |
throw new BufferOverflowException(); |
|
249 |
src.get(hb, ix(position()), n); |
|
250 |
position(position() + n); |
|
251 |
} else { |
|
252 |
super.put(src); |
|
253 |
} |
|
254 |
return this; |
|
255 |
#else[rw] |
|
256 |
throw new ReadOnlyBufferException(); |
|
257 |
#end[rw] |
|
258 |
} |
|
259 |
||
53855 | 260 |
public $Type$Buffer put(int index, $type$[] src, int offset, int length) { |
261 |
#if[rw] |
|
262 |
Objects.checkFromIndexSize(index, length, limit()); |
|
263 |
Objects.checkFromIndexSize(offset, length, src.length); |
|
264 |
System.arraycopy(src, offset, hb, ix(index), length); |
|
265 |
return this; |
|
266 |
#else[rw] |
|
267 |
throw new ReadOnlyBufferException(); |
|
268 |
#end[rw] |
|
269 |
} |
|
270 |
||
53901
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
271 |
#if[char] |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
272 |
|
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
273 |
public $Type$Buffer put(String src, int start, int end) { |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
274 |
int length = end - start; |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
275 |
checkBounds(start, length, src.length()); |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
276 |
if (isReadOnly()) |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
277 |
throw new ReadOnlyBufferException(); |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
278 |
int pos = position(); |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
279 |
int lim = limit(); |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
280 |
int rem = (pos <= lim) ? lim - pos : 0; |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
281 |
if (length > rem) |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
282 |
throw new BufferOverflowException(); |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
283 |
src.getChars(start, end, hb, ix(pos)); |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
284 |
position(pos + length); |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
285 |
return this; |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
286 |
} |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
287 |
|
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
288 |
#end[char] |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
289 |
|
2 | 290 |
public $Type$Buffer compact() { |
291 |
#if[rw] |
|
292 |
System.arraycopy(hb, ix(position()), hb, ix(0), remaining()); |
|
293 |
position(remaining()); |
|
294 |
limit(capacity()); |
|
1634
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
1247
diff
changeset
|
295 |
discardMark(); |
2 | 296 |
return this; |
297 |
#else[rw] |
|
298 |
throw new ReadOnlyBufferException(); |
|
299 |
#end[rw] |
|
300 |
} |
|
301 |
||
302 |
||
303 |
||
304 |
#if[byte] |
|
305 |
||
306 |
byte _get(int i) { // package-private |
|
307 |
return hb[i]; |
|
308 |
} |
|
309 |
||
310 |
void _put(int i, byte b) { // package-private |
|
311 |
#if[rw] |
|
312 |
hb[i] = b; |
|
313 |
#else[rw] |
|
314 |
throw new ReadOnlyBufferException(); |
|
315 |
#end[rw] |
|
316 |
} |
|
317 |
||
318 |
// char |
|
319 |
||
320 |
#if[rw] |
|
321 |
||
322 |
public char getChar() { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
323 |
return UNSAFE.getCharUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian); |
2 | 324 |
} |
325 |
||
326 |
public char getChar(int i) { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
327 |
return UNSAFE.getCharUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian); |
2 | 328 |
} |
329 |
||
330 |
#end[rw] |
|
331 |
||
332 |
public $Type$Buffer putChar(char x) { |
|
333 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
334 |
UNSAFE.putCharUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian); |
2 | 335 |
return this; |
336 |
#else[rw] |
|
337 |
throw new ReadOnlyBufferException(); |
|
338 |
#end[rw] |
|
339 |
} |
|
340 |
||
341 |
public $Type$Buffer putChar(int i, char x) { |
|
342 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
343 |
UNSAFE.putCharUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian); |
2 | 344 |
return this; |
345 |
#else[rw] |
|
346 |
throw new ReadOnlyBufferException(); |
|
347 |
#end[rw] |
|
348 |
} |
|
349 |
||
350 |
public CharBuffer asCharBuffer() { |
|
351 |
int size = this.remaining() >> 1; |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
352 |
long addr = address + position(); |
2 | 353 |
return (bigEndian |
354 |
? (CharBuffer)(new ByteBufferAsCharBuffer$RW$B(this, |
|
355 |
-1, |
|
356 |
0, |
|
357 |
size, |
|
358 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
359 |
addr)) |
2 | 360 |
: (CharBuffer)(new ByteBufferAsCharBuffer$RW$L(this, |
361 |
-1, |
|
362 |
0, |
|
363 |
size, |
|
364 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
365 |
addr))); |
2 | 366 |
} |
367 |
||
368 |
||
369 |
// short |
|
370 |
||
371 |
#if[rw] |
|
372 |
||
373 |
public short getShort() { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
374 |
return UNSAFE.getShortUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian); |
2 | 375 |
} |
376 |
||
377 |
public short getShort(int i) { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
378 |
return UNSAFE.getShortUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian); |
2 | 379 |
} |
380 |
||
381 |
#end[rw] |
|
382 |
||
383 |
public $Type$Buffer putShort(short x) { |
|
384 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
385 |
UNSAFE.putShortUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian); |
2 | 386 |
return this; |
387 |
#else[rw] |
|
388 |
throw new ReadOnlyBufferException(); |
|
389 |
#end[rw] |
|
390 |
} |
|
391 |
||
392 |
public $Type$Buffer putShort(int i, short x) { |
|
393 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
394 |
UNSAFE.putShortUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian); |
2 | 395 |
return this; |
396 |
#else[rw] |
|
397 |
throw new ReadOnlyBufferException(); |
|
398 |
#end[rw] |
|
399 |
} |
|
400 |
||
401 |
public ShortBuffer asShortBuffer() { |
|
402 |
int size = this.remaining() >> 1; |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
403 |
long addr = address + position(); |
2 | 404 |
return (bigEndian |
405 |
? (ShortBuffer)(new ByteBufferAsShortBuffer$RW$B(this, |
|
406 |
-1, |
|
407 |
0, |
|
408 |
size, |
|
409 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
410 |
addr)) |
2 | 411 |
: (ShortBuffer)(new ByteBufferAsShortBuffer$RW$L(this, |
412 |
-1, |
|
413 |
0, |
|
414 |
size, |
|
415 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
416 |
addr))); |
2 | 417 |
} |
418 |
||
419 |
||
420 |
// int |
|
421 |
||
422 |
#if[rw] |
|
423 |
||
424 |
public int getInt() { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
425 |
return UNSAFE.getIntUnaligned(hb, byteOffset(nextGetIndex(4)), bigEndian); |
2 | 426 |
} |
427 |
||
428 |
public int getInt(int i) { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
429 |
return UNSAFE.getIntUnaligned(hb, byteOffset(checkIndex(i, 4)), bigEndian); |
2 | 430 |
} |
431 |
||
432 |
#end[rw] |
|
433 |
||
434 |
public $Type$Buffer putInt(int x) { |
|
435 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
436 |
UNSAFE.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), x, bigEndian); |
2 | 437 |
return this; |
438 |
#else[rw] |
|
439 |
throw new ReadOnlyBufferException(); |
|
440 |
#end[rw] |
|
441 |
} |
|
442 |
||
443 |
public $Type$Buffer putInt(int i, int x) { |
|
444 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
445 |
UNSAFE.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), x, bigEndian); |
2 | 446 |
return this; |
447 |
#else[rw] |
|
448 |
throw new ReadOnlyBufferException(); |
|
449 |
#end[rw] |
|
450 |
} |
|
451 |
||
452 |
public IntBuffer asIntBuffer() { |
|
453 |
int size = this.remaining() >> 2; |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
454 |
long addr = address + position(); |
2 | 455 |
return (bigEndian |
456 |
? (IntBuffer)(new ByteBufferAsIntBuffer$RW$B(this, |
|
457 |
-1, |
|
458 |
0, |
|
459 |
size, |
|
460 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
461 |
addr)) |
2 | 462 |
: (IntBuffer)(new ByteBufferAsIntBuffer$RW$L(this, |
463 |
-1, |
|
464 |
0, |
|
465 |
size, |
|
466 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
467 |
addr))); |
2 | 468 |
} |
469 |
||
470 |
||
471 |
// long |
|
472 |
||
473 |
#if[rw] |
|
474 |
||
475 |
public long getLong() { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
476 |
return UNSAFE.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian); |
2 | 477 |
} |
478 |
||
479 |
public long getLong(int i) { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
480 |
return UNSAFE.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian); |
2 | 481 |
} |
482 |
||
483 |
#end[rw] |
|
484 |
||
485 |
public $Type$Buffer putLong(long x) { |
|
486 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
487 |
UNSAFE.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), x, bigEndian); |
2 | 488 |
return this; |
489 |
#else[rw] |
|
490 |
throw new ReadOnlyBufferException(); |
|
491 |
#end[rw] |
|
492 |
} |
|
493 |
||
494 |
public $Type$Buffer putLong(int i, long x) { |
|
495 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
496 |
UNSAFE.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), x, bigEndian); |
2 | 497 |
return this; |
498 |
#else[rw] |
|
499 |
throw new ReadOnlyBufferException(); |
|
500 |
#end[rw] |
|
501 |
} |
|
502 |
||
503 |
public LongBuffer asLongBuffer() { |
|
504 |
int size = this.remaining() >> 3; |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
505 |
long addr = address + position(); |
2 | 506 |
return (bigEndian |
507 |
? (LongBuffer)(new ByteBufferAsLongBuffer$RW$B(this, |
|
508 |
-1, |
|
509 |
0, |
|
510 |
size, |
|
511 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
512 |
addr)) |
2 | 513 |
: (LongBuffer)(new ByteBufferAsLongBuffer$RW$L(this, |
514 |
-1, |
|
515 |
0, |
|
516 |
size, |
|
517 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
518 |
addr))); |
2 | 519 |
} |
520 |
||
521 |
||
522 |
// float |
|
523 |
||
524 |
#if[rw] |
|
525 |
||
526 |
public float getFloat() { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
527 |
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
|
528 |
return Float.intBitsToFloat(x); |
2 | 529 |
} |
530 |
||
531 |
public float getFloat(int i) { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
532 |
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
|
533 |
return Float.intBitsToFloat(x); |
2 | 534 |
} |
535 |
||
536 |
#end[rw] |
|
537 |
||
538 |
public $Type$Buffer putFloat(float x) { |
|
539 |
#if[rw] |
|
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
540 |
int y = Float.floatToRawIntBits(x); |
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
541 |
UNSAFE.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), y, bigEndian); |
2 | 542 |
return this; |
543 |
#else[rw] |
|
544 |
throw new ReadOnlyBufferException(); |
|
545 |
#end[rw] |
|
546 |
} |
|
547 |
||
548 |
public $Type$Buffer putFloat(int i, float x) { |
|
549 |
#if[rw] |
|
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
550 |
int y = Float.floatToRawIntBits(x); |
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
551 |
UNSAFE.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), y, bigEndian); |
2 | 552 |
return this; |
553 |
#else[rw] |
|
554 |
throw new ReadOnlyBufferException(); |
|
555 |
#end[rw] |
|
556 |
} |
|
557 |
||
558 |
public FloatBuffer asFloatBuffer() { |
|
559 |
int size = this.remaining() >> 2; |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
560 |
long addr = address + position(); |
2 | 561 |
return (bigEndian |
562 |
? (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$B(this, |
|
563 |
-1, |
|
564 |
0, |
|
565 |
size, |
|
566 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
567 |
addr)) |
2 | 568 |
: (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$L(this, |
569 |
-1, |
|
570 |
0, |
|
571 |
size, |
|
572 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
573 |
addr))); |
2 | 574 |
} |
575 |
||
576 |
||
577 |
// double |
|
578 |
||
579 |
#if[rw] |
|
580 |
||
581 |
public double getDouble() { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
582 |
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
|
583 |
return Double.longBitsToDouble(x); |
2 | 584 |
} |
585 |
||
586 |
public double getDouble(int i) { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
587 |
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
|
588 |
return Double.longBitsToDouble(x); |
2 | 589 |
} |
590 |
||
591 |
#end[rw] |
|
592 |
||
593 |
public $Type$Buffer putDouble(double x) { |
|
594 |
#if[rw] |
|
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
595 |
long y = Double.doubleToRawLongBits(x); |
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
596 |
UNSAFE.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), y, bigEndian); |
2 | 597 |
return this; |
598 |
#else[rw] |
|
599 |
throw new ReadOnlyBufferException(); |
|
600 |
#end[rw] |
|
601 |
} |
|
602 |
||
603 |
public $Type$Buffer putDouble(int i, double x) { |
|
604 |
#if[rw] |
|
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
605 |
long y = Double.doubleToRawLongBits(x); |
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
606 |
UNSAFE.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), y, bigEndian); |
2 | 607 |
return this; |
608 |
#else[rw] |
|
609 |
throw new ReadOnlyBufferException(); |
|
610 |
#end[rw] |
|
611 |
} |
|
612 |
||
613 |
public DoubleBuffer asDoubleBuffer() { |
|
614 |
int size = this.remaining() >> 3; |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
615 |
long addr = address + position(); |
2 | 616 |
return (bigEndian |
617 |
? (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$B(this, |
|
618 |
-1, |
|
619 |
0, |
|
620 |
size, |
|
621 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
622 |
addr)) |
2 | 623 |
: (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$L(this, |
624 |
-1, |
|
625 |
0, |
|
626 |
size, |
|
627 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
628 |
addr))); |
2 | 629 |
} |
630 |
||
631 |
||
632 |
#end[byte] |
|
633 |
||
634 |
||
635 |
#if[char] |
|
636 |
||
637 |
String toString(int start, int end) { // package-private |
|
638 |
try { |
|
639 |
return new String(hb, start + offset, end - start); |
|
640 |
} catch (StringIndexOutOfBoundsException x) { |
|
641 |
throw new IndexOutOfBoundsException(); |
|
642 |
} |
|
643 |
} |
|
644 |
||
645 |
||
646 |
// --- Methods to support CharSequence --- |
|
647 |
||
1224
8c1bc7c5dd00
6733145: (bf) CharBuffer.subSequence can be updated to take advantage of covariant returns
martin
parents:
2
diff
changeset
|
648 |
public CharBuffer subSequence(int start, int end) { |
2 | 649 |
if ((start < 0) |
650 |
|| (end > length()) |
|
651 |
|| (start > end)) |
|
652 |
throw new IndexOutOfBoundsException(); |
|
2593
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1634
diff
changeset
|
653 |
int pos = position(); |
2 | 654 |
return new HeapCharBuffer$RW$(hb, |
2593
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1634
diff
changeset
|
655 |
-1, |
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1634
diff
changeset
|
656 |
pos + start, |
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1634
diff
changeset
|
657 |
pos + end, |
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1634
diff
changeset
|
658 |
capacity(), |
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1634
diff
changeset
|
659 |
offset); |
2 | 660 |
} |
661 |
||
662 |
#end[char] |
|
663 |
||
664 |
||
665 |
#if[!byte] |
|
666 |
||
667 |
public ByteOrder order() { |
|
668 |
return ByteOrder.nativeOrder(); |
|
669 |
} |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
670 |
#end[!byte] |
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
671 |
#if[char] |
2 | 672 |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
673 |
ByteOrder charRegionOrder() { |
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
674 |
return order(); |
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
675 |
} |
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
676 |
#end[char] |
2 | 677 |
} |