author | bpb |
Fri, 22 Feb 2019 10:13:33 -0800 | |
changeset 53901 | 0448cb38c418 |
parent 53855 | 7c362992527a |
child 53959 | 1542e63eb537 |
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 |
||
53901
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
273 |
#if[char] |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
274 |
|
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
275 |
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
|
276 |
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
|
277 |
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
|
278 |
if (isReadOnly()) |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
279 |
throw new ReadOnlyBufferException(); |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
280 |
int pos = position(); |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
281 |
int lim = limit(); |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
282 |
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
|
283 |
if (length > rem) |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
284 |
throw new BufferOverflowException(); |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
285 |
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
|
286 |
position(pos + length); |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
287 |
return this; |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
288 |
} |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
289 |
|
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
290 |
#end[char] |
0448cb38c418
8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents:
53855
diff
changeset
|
291 |
|
2 | 292 |
public $Type$Buffer compact() { |
293 |
#if[rw] |
|
294 |
System.arraycopy(hb, ix(position()), hb, ix(0), remaining()); |
|
295 |
position(remaining()); |
|
296 |
limit(capacity()); |
|
1634
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
1247
diff
changeset
|
297 |
discardMark(); |
2 | 298 |
return this; |
299 |
#else[rw] |
|
300 |
throw new ReadOnlyBufferException(); |
|
301 |
#end[rw] |
|
302 |
} |
|
303 |
||
304 |
||
305 |
||
306 |
#if[byte] |
|
307 |
||
308 |
byte _get(int i) { // package-private |
|
309 |
return hb[i]; |
|
310 |
} |
|
311 |
||
312 |
void _put(int i, byte b) { // package-private |
|
313 |
#if[rw] |
|
314 |
hb[i] = b; |
|
315 |
#else[rw] |
|
316 |
throw new ReadOnlyBufferException(); |
|
317 |
#end[rw] |
|
318 |
} |
|
319 |
||
320 |
// char |
|
321 |
||
322 |
#if[rw] |
|
323 |
||
324 |
public char getChar() { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
325 |
return UNSAFE.getCharUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian); |
2 | 326 |
} |
327 |
||
328 |
public char getChar(int i) { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
329 |
return UNSAFE.getCharUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian); |
2 | 330 |
} |
331 |
||
332 |
#end[rw] |
|
333 |
||
334 |
public $Type$Buffer putChar(char x) { |
|
335 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
336 |
UNSAFE.putCharUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian); |
2 | 337 |
return this; |
338 |
#else[rw] |
|
339 |
throw new ReadOnlyBufferException(); |
|
340 |
#end[rw] |
|
341 |
} |
|
342 |
||
343 |
public $Type$Buffer putChar(int i, char x) { |
|
344 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
345 |
UNSAFE.putCharUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian); |
2 | 346 |
return this; |
347 |
#else[rw] |
|
348 |
throw new ReadOnlyBufferException(); |
|
349 |
#end[rw] |
|
350 |
} |
|
351 |
||
352 |
public CharBuffer asCharBuffer() { |
|
353 |
int size = this.remaining() >> 1; |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
354 |
long addr = address + position(); |
2 | 355 |
return (bigEndian |
356 |
? (CharBuffer)(new ByteBufferAsCharBuffer$RW$B(this, |
|
357 |
-1, |
|
358 |
0, |
|
359 |
size, |
|
360 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
361 |
addr)) |
2 | 362 |
: (CharBuffer)(new ByteBufferAsCharBuffer$RW$L(this, |
363 |
-1, |
|
364 |
0, |
|
365 |
size, |
|
366 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
367 |
addr))); |
2 | 368 |
} |
369 |
||
370 |
||
371 |
// short |
|
372 |
||
373 |
#if[rw] |
|
374 |
||
375 |
public short getShort() { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
376 |
return UNSAFE.getShortUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian); |
2 | 377 |
} |
378 |
||
379 |
public short getShort(int i) { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
380 |
return UNSAFE.getShortUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian); |
2 | 381 |
} |
382 |
||
383 |
#end[rw] |
|
384 |
||
385 |
public $Type$Buffer putShort(short x) { |
|
386 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
387 |
UNSAFE.putShortUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian); |
2 | 388 |
return this; |
389 |
#else[rw] |
|
390 |
throw new ReadOnlyBufferException(); |
|
391 |
#end[rw] |
|
392 |
} |
|
393 |
||
394 |
public $Type$Buffer putShort(int i, short x) { |
|
395 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
396 |
UNSAFE.putShortUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian); |
2 | 397 |
return this; |
398 |
#else[rw] |
|
399 |
throw new ReadOnlyBufferException(); |
|
400 |
#end[rw] |
|
401 |
} |
|
402 |
||
403 |
public ShortBuffer asShortBuffer() { |
|
404 |
int size = this.remaining() >> 1; |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
405 |
long addr = address + position(); |
2 | 406 |
return (bigEndian |
407 |
? (ShortBuffer)(new ByteBufferAsShortBuffer$RW$B(this, |
|
408 |
-1, |
|
409 |
0, |
|
410 |
size, |
|
411 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
412 |
addr)) |
2 | 413 |
: (ShortBuffer)(new ByteBufferAsShortBuffer$RW$L(this, |
414 |
-1, |
|
415 |
0, |
|
416 |
size, |
|
417 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
418 |
addr))); |
2 | 419 |
} |
420 |
||
421 |
||
422 |
// int |
|
423 |
||
424 |
#if[rw] |
|
425 |
||
426 |
public int getInt() { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
427 |
return UNSAFE.getIntUnaligned(hb, byteOffset(nextGetIndex(4)), bigEndian); |
2 | 428 |
} |
429 |
||
430 |
public int getInt(int i) { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
431 |
return UNSAFE.getIntUnaligned(hb, byteOffset(checkIndex(i, 4)), bigEndian); |
2 | 432 |
} |
433 |
||
434 |
#end[rw] |
|
435 |
||
436 |
public $Type$Buffer putInt(int x) { |
|
437 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
438 |
UNSAFE.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), x, bigEndian); |
2 | 439 |
return this; |
440 |
#else[rw] |
|
441 |
throw new ReadOnlyBufferException(); |
|
442 |
#end[rw] |
|
443 |
} |
|
444 |
||
445 |
public $Type$Buffer putInt(int i, int x) { |
|
446 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
447 |
UNSAFE.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), x, bigEndian); |
2 | 448 |
return this; |
449 |
#else[rw] |
|
450 |
throw new ReadOnlyBufferException(); |
|
451 |
#end[rw] |
|
452 |
} |
|
453 |
||
454 |
public IntBuffer asIntBuffer() { |
|
455 |
int size = this.remaining() >> 2; |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
456 |
long addr = address + position(); |
2 | 457 |
return (bigEndian |
458 |
? (IntBuffer)(new ByteBufferAsIntBuffer$RW$B(this, |
|
459 |
-1, |
|
460 |
0, |
|
461 |
size, |
|
462 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
463 |
addr)) |
2 | 464 |
: (IntBuffer)(new ByteBufferAsIntBuffer$RW$L(this, |
465 |
-1, |
|
466 |
0, |
|
467 |
size, |
|
468 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
469 |
addr))); |
2 | 470 |
} |
471 |
||
472 |
||
473 |
// long |
|
474 |
||
475 |
#if[rw] |
|
476 |
||
477 |
public long getLong() { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
478 |
return UNSAFE.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian); |
2 | 479 |
} |
480 |
||
481 |
public long getLong(int i) { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
482 |
return UNSAFE.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian); |
2 | 483 |
} |
484 |
||
485 |
#end[rw] |
|
486 |
||
487 |
public $Type$Buffer putLong(long x) { |
|
488 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
489 |
UNSAFE.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), x, bigEndian); |
2 | 490 |
return this; |
491 |
#else[rw] |
|
492 |
throw new ReadOnlyBufferException(); |
|
493 |
#end[rw] |
|
494 |
} |
|
495 |
||
496 |
public $Type$Buffer putLong(int i, long x) { |
|
497 |
#if[rw] |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
498 |
UNSAFE.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), x, bigEndian); |
2 | 499 |
return this; |
500 |
#else[rw] |
|
501 |
throw new ReadOnlyBufferException(); |
|
502 |
#end[rw] |
|
503 |
} |
|
504 |
||
505 |
public LongBuffer asLongBuffer() { |
|
506 |
int size = this.remaining() >> 3; |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
507 |
long addr = address + position(); |
2 | 508 |
return (bigEndian |
509 |
? (LongBuffer)(new ByteBufferAsLongBuffer$RW$B(this, |
|
510 |
-1, |
|
511 |
0, |
|
512 |
size, |
|
513 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
514 |
addr)) |
2 | 515 |
: (LongBuffer)(new ByteBufferAsLongBuffer$RW$L(this, |
516 |
-1, |
|
517 |
0, |
|
518 |
size, |
|
519 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
520 |
addr))); |
2 | 521 |
} |
522 |
||
523 |
||
524 |
// float |
|
525 |
||
526 |
#if[rw] |
|
527 |
||
528 |
public float getFloat() { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
529 |
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
|
530 |
return Float.intBitsToFloat(x); |
2 | 531 |
} |
532 |
||
533 |
public float getFloat(int i) { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
534 |
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
|
535 |
return Float.intBitsToFloat(x); |
2 | 536 |
} |
537 |
||
538 |
#end[rw] |
|
539 |
||
540 |
public $Type$Buffer putFloat(float x) { |
|
541 |
#if[rw] |
|
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
542 |
int y = Float.floatToRawIntBits(x); |
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
543 |
UNSAFE.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), y, bigEndian); |
2 | 544 |
return this; |
545 |
#else[rw] |
|
546 |
throw new ReadOnlyBufferException(); |
|
547 |
#end[rw] |
|
548 |
} |
|
549 |
||
550 |
public $Type$Buffer putFloat(int i, float x) { |
|
551 |
#if[rw] |
|
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
552 |
int y = Float.floatToRawIntBits(x); |
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
553 |
UNSAFE.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), y, bigEndian); |
2 | 554 |
return this; |
555 |
#else[rw] |
|
556 |
throw new ReadOnlyBufferException(); |
|
557 |
#end[rw] |
|
558 |
} |
|
559 |
||
560 |
public FloatBuffer asFloatBuffer() { |
|
561 |
int size = this.remaining() >> 2; |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
562 |
long addr = address + position(); |
2 | 563 |
return (bigEndian |
564 |
? (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$B(this, |
|
565 |
-1, |
|
566 |
0, |
|
567 |
size, |
|
568 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
569 |
addr)) |
2 | 570 |
: (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$L(this, |
571 |
-1, |
|
572 |
0, |
|
573 |
size, |
|
574 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
575 |
addr))); |
2 | 576 |
} |
577 |
||
578 |
||
579 |
// double |
|
580 |
||
581 |
#if[rw] |
|
582 |
||
583 |
public double getDouble() { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
584 |
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
|
585 |
return Double.longBitsToDouble(x); |
2 | 586 |
} |
587 |
||
588 |
public double getDouble(int i) { |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
589 |
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
|
590 |
return Double.longBitsToDouble(x); |
2 | 591 |
} |
592 |
||
593 |
#end[rw] |
|
594 |
||
595 |
public $Type$Buffer putDouble(double x) { |
|
596 |
#if[rw] |
|
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
597 |
long y = Double.doubleToRawLongBits(x); |
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
598 |
UNSAFE.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), y, bigEndian); |
2 | 599 |
return this; |
600 |
#else[rw] |
|
601 |
throw new ReadOnlyBufferException(); |
|
602 |
#end[rw] |
|
603 |
} |
|
604 |
||
605 |
public $Type$Buffer putDouble(int i, double x) { |
|
606 |
#if[rw] |
|
30338
957ee8b5a33a
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
25859
diff
changeset
|
607 |
long y = Double.doubleToRawLongBits(x); |
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
608 |
UNSAFE.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), y, bigEndian); |
2 | 609 |
return this; |
610 |
#else[rw] |
|
611 |
throw new ReadOnlyBufferException(); |
|
612 |
#end[rw] |
|
613 |
} |
|
614 |
||
615 |
public DoubleBuffer asDoubleBuffer() { |
|
616 |
int size = this.remaining() >> 3; |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
617 |
long addr = address + position(); |
2 | 618 |
return (bigEndian |
619 |
? (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$B(this, |
|
620 |
-1, |
|
621 |
0, |
|
622 |
size, |
|
623 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
624 |
addr)) |
2 | 625 |
: (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$L(this, |
626 |
-1, |
|
627 |
0, |
|
628 |
size, |
|
629 |
size, |
|
40195
a13e4945de1d
8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
36933
diff
changeset
|
630 |
addr))); |
2 | 631 |
} |
632 |
||
633 |
||
634 |
#end[byte] |
|
635 |
||
636 |
||
637 |
#if[char] |
|
638 |
||
639 |
String toString(int start, int end) { // package-private |
|
640 |
try { |
|
641 |
return new String(hb, start + offset, end - start); |
|
642 |
} catch (StringIndexOutOfBoundsException x) { |
|
643 |
throw new IndexOutOfBoundsException(); |
|
644 |
} |
|
645 |
} |
|
646 |
||
647 |
||
648 |
// --- Methods to support CharSequence --- |
|
649 |
||
1224
8c1bc7c5dd00
6733145: (bf) CharBuffer.subSequence can be updated to take advantage of covariant returns
martin
parents:
2
diff
changeset
|
650 |
public CharBuffer subSequence(int start, int end) { |
2 | 651 |
if ((start < 0) |
652 |
|| (end > length()) |
|
653 |
|| (start > end)) |
|
654 |
throw new IndexOutOfBoundsException(); |
|
2593
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1634
diff
changeset
|
655 |
int pos = position(); |
2 | 656 |
return new HeapCharBuffer$RW$(hb, |
2593
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1634
diff
changeset
|
657 |
-1, |
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1634
diff
changeset
|
658 |
pos + start, |
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1634
diff
changeset
|
659 |
pos + end, |
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1634
diff
changeset
|
660 |
capacity(), |
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1634
diff
changeset
|
661 |
offset); |
2 | 662 |
} |
663 |
||
664 |
#end[char] |
|
665 |
||
666 |
||
667 |
#if[!byte] |
|
668 |
||
669 |
public ByteOrder order() { |
|
670 |
return ByteOrder.nativeOrder(); |
|
671 |
} |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
672 |
#end[!byte] |
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
673 |
#if[char] |
2 | 674 |
|
48356
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
675 |
ByteOrder charRegionOrder() { |
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
676 |
return order(); |
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
677 |
} |
29e165bdf669
8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents:
47216
diff
changeset
|
678 |
#end[char] |
2 | 679 |
} |