author | prr |
Fri, 25 May 2018 12:12:24 -0700 | |
changeset 50347 | b2f046ae8eb6 |
parent 47216 | 71c04702a3d5 |
child 53855 | 7c362992527a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
36933
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
2 |
* Copyright (c) 2000, 2016, 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 |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* Type-specific source code for unit test |
|
25 |
* |
|
26 |
* Regenerate the BasicX classes via genBasic.sh whenever this file changes. |
|
27 |
* We check in the generated source files so that the test tree can be used |
|
28 |
* independently of the rest of the source tree. |
|
29 |
*/ |
|
30 |
||
31 |
// -- This file was mechanically generated: Do not edit! -- // |
|
32 |
||
33 |
import java.nio.*; |
|
34 |
||
35 |
||
36 |
public class BasicDouble |
|
37 |
extends Basic |
|
38 |
{ |
|
39 |
||
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
40 |
private static final double[] VALUES = { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
41 |
Double.MIN_VALUE, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
42 |
(double) -1, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
43 |
(double) 0, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
44 |
(double) 1, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
45 |
Double.MAX_VALUE, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
46 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
47 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
48 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
49 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
50 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
51 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
52 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
53 |
Double.NEGATIVE_INFINITY, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
54 |
Double.POSITIVE_INFINITY, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
55 |
Double.NaN, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
56 |
(double) -0.0, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
57 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
58 |
}; |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
59 |
|
2 | 60 |
private static void relGet(DoubleBuffer b) { |
61 |
int n = b.capacity(); |
|
62 |
for (int i = 0; i < n; i++) |
|
63 |
ck(b, (long)b.get(), (long)((double)ic(i))); |
|
64 |
b.rewind(); |
|
65 |
} |
|
66 |
||
67 |
private static void relGet(DoubleBuffer b, int start) { |
|
68 |
int n = b.remaining(); |
|
69 |
for (int i = start; i < n; i++) |
|
70 |
ck(b, (long)b.get(), (long)((double)ic(i))); |
|
71 |
b.rewind(); |
|
72 |
} |
|
73 |
||
74 |
private static void absGet(DoubleBuffer b) { |
|
75 |
int n = b.capacity(); |
|
76 |
for (int i = 0; i < n; i++) |
|
77 |
ck(b, (long)b.get(), (long)((double)ic(i))); |
|
78 |
b.rewind(); |
|
79 |
} |
|
80 |
||
81 |
private static void bulkGet(DoubleBuffer b) { |
|
82 |
int n = b.capacity(); |
|
83 |
double[] a = new double[n + 7]; |
|
84 |
b.get(a, 7, n); |
|
37913 | 85 |
for (int i = 0; i < n; i++) { |
2 | 86 |
ck(b, (long)a[i + 7], (long)((double)ic(i))); |
37913 | 87 |
} |
2 | 88 |
} |
89 |
||
90 |
private static void relPut(DoubleBuffer b) { |
|
91 |
int n = b.capacity(); |
|
92 |
b.clear(); |
|
93 |
for (int i = 0; i < n; i++) |
|
94 |
b.put((double)ic(i)); |
|
95 |
b.flip(); |
|
96 |
} |
|
97 |
||
98 |
private static void absPut(DoubleBuffer b) { |
|
99 |
int n = b.capacity(); |
|
100 |
b.clear(); |
|
101 |
for (int i = 0; i < n; i++) |
|
102 |
b.put(i, (double)ic(i)); |
|
103 |
b.limit(n); |
|
104 |
b.position(0); |
|
105 |
} |
|
106 |
||
107 |
private static void bulkPutArray(DoubleBuffer b) { |
|
108 |
int n = b.capacity(); |
|
109 |
b.clear(); |
|
110 |
double[] a = new double[n + 7]; |
|
111 |
for (int i = 0; i < n; i++) |
|
112 |
a[i + 7] = (double)ic(i); |
|
113 |
b.put(a, 7, n); |
|
114 |
b.flip(); |
|
115 |
} |
|
116 |
||
117 |
private static void bulkPutBuffer(DoubleBuffer b) { |
|
118 |
int n = b.capacity(); |
|
119 |
b.clear(); |
|
120 |
DoubleBuffer c = DoubleBuffer.allocate(n + 7); |
|
121 |
c.position(7); |
|
122 |
for (int i = 0; i < n; i++) |
|
123 |
c.put((double)ic(i)); |
|
124 |
c.flip(); |
|
125 |
c.position(7); |
|
126 |
b.put(c); |
|
127 |
b.flip(); |
|
31873
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
128 |
try { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
129 |
b.put(b); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
130 |
fail("IllegalArgumentException expected for put into same buffer"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
131 |
} catch (IllegalArgumentException e) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
132 |
if (e.getMessage() == null) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
133 |
fail("Non-null IllegalArgumentException message expected from" |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
134 |
+ " put into same buffer"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
135 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
136 |
} |
2 | 137 |
} |
138 |
||
139 |
//6231529 |
|
140 |
private static void callReset(DoubleBuffer b) { |
|
141 |
b.position(0); |
|
142 |
b.mark(); |
|
143 |
||
144 |
b.duplicate().reset(); |
|
145 |
b.asReadOnlyBuffer().reset(); |
|
146 |
} |
|
147 |
||
148 |
||
149 |
||
150 |
// 6221101-6234263 |
|
151 |
||
152 |
private static void putBuffer() { |
|
153 |
final int cap = 10; |
|
154 |
||
155 |
DoubleBuffer direct1 = ByteBuffer.allocateDirect(cap).asDoubleBuffer(); |
|
156 |
DoubleBuffer nondirect1 = ByteBuffer.allocate(cap).asDoubleBuffer(); |
|
157 |
direct1.put(nondirect1); |
|
158 |
||
159 |
DoubleBuffer direct2 = ByteBuffer.allocateDirect(cap).asDoubleBuffer(); |
|
160 |
DoubleBuffer nondirect2 = ByteBuffer.allocate(cap).asDoubleBuffer(); |
|
161 |
nondirect2.put(direct2); |
|
162 |
||
163 |
DoubleBuffer direct3 = ByteBuffer.allocateDirect(cap).asDoubleBuffer(); |
|
164 |
DoubleBuffer direct4 = ByteBuffer.allocateDirect(cap).asDoubleBuffer(); |
|
165 |
direct3.put(direct4); |
|
166 |
||
167 |
DoubleBuffer nondirect3 = ByteBuffer.allocate(cap).asDoubleBuffer(); |
|
168 |
DoubleBuffer nondirect4 = ByteBuffer.allocate(cap).asDoubleBuffer(); |
|
169 |
nondirect3.put(nondirect4); |
|
170 |
} |
|
171 |
||
172 |
||
173 |
||
174 |
||
175 |
||
176 |
||
177 |
||
178 |
||
179 |
||
180 |
||
181 |
||
182 |
||
183 |
||
184 |
||
185 |
||
186 |
||
187 |
||
188 |
private static void checkSlice(DoubleBuffer b, DoubleBuffer slice) { |
|
189 |
ck(slice, 0, slice.position()); |
|
190 |
ck(slice, b.remaining(), slice.limit()); |
|
191 |
ck(slice, b.remaining(), slice.capacity()); |
|
192 |
if (b.isDirect() != slice.isDirect()) |
|
193 |
fail("Lost direction", slice); |
|
194 |
if (b.isReadOnly() != slice.isReadOnly()) |
|
195 |
fail("Lost read-only", slice); |
|
196 |
} |
|
197 |
||
198 |
||
199 |
||
200 |
||
201 |
||
202 |
||
203 |
||
204 |
||
205 |
||
206 |
||
207 |
||
208 |
||
209 |
||
210 |
||
211 |
||
212 |
||
213 |
||
214 |
||
215 |
||
216 |
||
217 |
||
218 |
||
219 |
||
220 |
||
221 |
||
222 |
||
223 |
||
224 |
||
225 |
||
226 |
||
227 |
||
228 |
||
229 |
||
230 |
||
231 |
||
232 |
||
233 |
||
234 |
||
235 |
||
236 |
||
237 |
||
238 |
||
239 |
||
240 |
||
241 |
||
242 |
||
243 |
||
244 |
||
245 |
||
246 |
||
247 |
||
248 |
||
249 |
||
250 |
||
251 |
||
252 |
||
253 |
||
254 |
||
255 |
||
256 |
||
257 |
||
258 |
||
259 |
||
260 |
||
261 |
||
262 |
||
263 |
||
264 |
||
265 |
||
266 |
||
267 |
||
268 |
||
269 |
||
270 |
||
271 |
||
272 |
||
273 |
||
274 |
||
275 |
||
276 |
||
277 |
||
278 |
||
279 |
||
280 |
||
281 |
||
282 |
||
283 |
||
284 |
||
285 |
||
286 |
||
287 |
||
288 |
||
289 |
||
290 |
||
291 |
||
292 |
||
293 |
||
294 |
||
295 |
||
296 |
||
297 |
||
298 |
||
299 |
||
300 |
||
301 |
||
302 |
||
303 |
||
304 |
||
305 |
||
306 |
||
307 |
||
308 |
||
309 |
||
310 |
||
311 |
||
312 |
||
1634
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
313 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
314 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
315 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
316 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
317 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
318 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
319 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
320 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
321 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
322 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
323 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
324 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
325 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
326 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
327 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
328 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
329 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
330 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
331 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
332 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
333 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
334 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
335 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
336 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
337 |
|
36933
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
338 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
339 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
340 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
341 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
342 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
343 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
344 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
345 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
346 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
347 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
348 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
349 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
350 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
351 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
352 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
353 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
354 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
355 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
356 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
357 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
358 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
359 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
360 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
361 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
362 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
363 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
364 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
365 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
366 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
367 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
368 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
369 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
370 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
371 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
372 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
373 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
374 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
375 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
376 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
377 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
378 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
379 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
380 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
381 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
382 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
383 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
384 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
385 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
386 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
387 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
388 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
389 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
390 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
391 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
392 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
393 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
394 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
395 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
396 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
397 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
398 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
399 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
400 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
401 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
402 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
403 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
404 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
405 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
406 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
407 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
408 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
409 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
410 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
411 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
412 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
413 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
414 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
415 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
416 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
417 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
418 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
419 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
420 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
421 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
422 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
423 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
424 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
425 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
426 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
427 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
428 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
429 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
430 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
431 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
432 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
433 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
434 |
|
37913 | 435 |
|
436 |
||
437 |
||
438 |
||
439 |
||
440 |
||
441 |
||
442 |
||
443 |
||
444 |
||
445 |
||
446 |
||
447 |
||
448 |
||
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
449 |
private static void fail(String problem, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
450 |
DoubleBuffer xb, DoubleBuffer yb, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
451 |
double x, double y) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
452 |
fail(problem + String.format(": x=%s y=%s", x, y), xb, yb); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
453 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
454 |
|
37913 | 455 |
private static void catchIllegalArgument(Buffer b, Runnable thunk) { |
456 |
tryCatch(b, IllegalArgumentException.class, thunk); |
|
457 |
} |
|
458 |
||
459 |
private static void catchReadOnlyBuffer(Buffer b, Runnable thunk) { |
|
460 |
tryCatch(b, ReadOnlyBufferException.class, thunk); |
|
461 |
} |
|
462 |
||
463 |
private static void catchIndexOutOfBounds(Buffer b, Runnable thunk) { |
|
464 |
tryCatch(b, IndexOutOfBoundsException.class, thunk); |
|
465 |
} |
|
466 |
||
467 |
private static void catchIndexOutOfBounds(double[] t, Runnable thunk) { |
|
468 |
tryCatch(t, IndexOutOfBoundsException.class, thunk); |
|
469 |
} |
|
470 |
||
14001
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
471 |
private static void tryCatch(Buffer b, Class<?> ex, Runnable thunk) { |
2 | 472 |
boolean caught = false; |
473 |
try { |
|
474 |
thunk.run(); |
|
475 |
} catch (Throwable x) { |
|
1634
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
476 |
if (ex.isAssignableFrom(x.getClass())) { |
2 | 477 |
caught = true; |
1634
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
478 |
} else { |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
479 |
fail(x.getMessage() + " not expected"); |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
480 |
} |
2 | 481 |
} |
37913 | 482 |
if (!caught) { |
2 | 483 |
fail(ex.getName() + " not thrown", b); |
37913 | 484 |
} |
2 | 485 |
} |
486 |
||
37913 | 487 |
private static void tryCatch(double[] t, Class<?> ex, Runnable thunk) { |
2 | 488 |
tryCatch(DoubleBuffer.wrap(t), ex, thunk); |
489 |
} |
|
490 |
||
491 |
public static void test(int level, final DoubleBuffer b, boolean direct) { |
|
492 |
||
493 |
show(level, b); |
|
494 |
||
495 |
if (direct != b.isDirect()) |
|
496 |
fail("Wrong direction", b); |
|
497 |
||
498 |
// Gets and puts |
|
499 |
||
500 |
relPut(b); |
|
501 |
relGet(b); |
|
502 |
absGet(b); |
|
503 |
bulkGet(b); |
|
504 |
||
505 |
absPut(b); |
|
506 |
relGet(b); |
|
507 |
absGet(b); |
|
508 |
bulkGet(b); |
|
509 |
||
510 |
bulkPutArray(b); |
|
511 |
relGet(b); |
|
512 |
||
513 |
bulkPutBuffer(b); |
|
514 |
relGet(b); |
|
515 |
||
516 |
||
517 |
||
518 |
||
519 |
||
520 |
||
521 |
||
522 |
||
523 |
||
524 |
||
525 |
||
526 |
||
527 |
||
528 |
||
529 |
||
530 |
||
531 |
||
532 |
||
533 |
||
534 |
||
535 |
||
536 |
||
537 |
||
2593
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1639
diff
changeset
|
538 |
|
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1639
diff
changeset
|
539 |
|
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1639
diff
changeset
|
540 |
|
13563
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
541 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
542 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
543 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
544 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
545 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
546 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
547 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
548 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
549 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
550 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
551 |
|
2 | 552 |
// Compact |
553 |
||
554 |
relPut(b); |
|
555 |
b.position(13); |
|
556 |
b.compact(); |
|
557 |
b.flip(); |
|
558 |
relGet(b, 13); |
|
559 |
||
560 |
// Exceptions |
|
561 |
||
562 |
relPut(b); |
|
563 |
b.limit(b.capacity() / 2); |
|
564 |
b.position(b.limit()); |
|
565 |
||
37913 | 566 |
tryCatch(b, BufferUnderflowException.class, () -> b.get()); |
567 |
tryCatch(b, BufferOverflowException.class, () -> b.put((double)42)); |
|
568 |
// The index must be non-negative and less than the buffer's limit. |
|
569 |
catchIndexOutOfBounds(b, () -> b.get(b.limit())); |
|
570 |
catchIndexOutOfBounds(b, () -> b.get(-1)); |
|
571 |
catchIndexOutOfBounds(b, () -> b.put(b.limit(), (double)42)); |
|
572 |
tryCatch(b, InvalidMarkException.class, |
|
573 |
() -> b.position(0).mark().compact().reset()); |
|
1634
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
574 |
|
31873
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
575 |
try { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
576 |
b.position(b.limit() + 1); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
577 |
fail("IllegalArgumentException expected for position beyond limit"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
578 |
} catch (IllegalArgumentException e) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
579 |
if (e.getMessage() == null) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
580 |
fail("Non-null IllegalArgumentException message expected for" |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
581 |
+ " position beyond limit"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
582 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
583 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
584 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
585 |
try { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
586 |
b.position(-1); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
587 |
fail("IllegalArgumentException expected for negative position"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
588 |
} catch (IllegalArgumentException e) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
589 |
if (e.getMessage() == null) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
590 |
fail("Non-null IllegalArgumentException message expected for" |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
591 |
+ " negative position"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
592 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
593 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
594 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
595 |
try { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
596 |
b.limit(b.capacity() + 1); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
597 |
fail("IllegalArgumentException expected for limit beyond capacity"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
598 |
} catch (IllegalArgumentException e) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
599 |
if (e.getMessage() == null) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
600 |
fail("Non-null IllegalArgumentException message expected for" |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
601 |
+ " limit beyond capacity"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
602 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
603 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
604 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
605 |
try { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
606 |
b.limit(-1); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
607 |
fail("IllegalArgumentException expected for negative limit"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
608 |
} catch (IllegalArgumentException e) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
609 |
if (e.getMessage() == null) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
610 |
fail("Non-null IllegalArgumentException message expected for" |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
611 |
+ " negative limit"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
612 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
613 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
614 |
|
2 | 615 |
// Values |
616 |
||
617 |
b.clear(); |
|
618 |
b.put((double)0); |
|
619 |
b.put((double)-1); |
|
620 |
b.put((double)1); |
|
621 |
b.put(Double.MAX_VALUE); |
|
622 |
b.put(Double.MIN_VALUE); |
|
623 |
||
624 |
||
625 |
||
626 |
||
627 |
||
628 |
||
629 |
||
630 |
||
631 |
||
632 |
b.put(-Double.MAX_VALUE); |
|
633 |
b.put(-Double.MIN_VALUE); |
|
634 |
b.put(Double.NEGATIVE_INFINITY); |
|
635 |
b.put(Double.POSITIVE_INFINITY); |
|
636 |
b.put(Double.NaN); |
|
637 |
b.put(0.5121609353879392); // Changes value if incorrectly swapped |
|
638 |
||
639 |
||
640 |
b.flip(); |
|
641 |
ck(b, b.get(), 0); |
|
642 |
ck(b, b.get(), (double)-1); |
|
643 |
ck(b, b.get(), 1); |
|
644 |
ck(b, b.get(), Double.MAX_VALUE); |
|
645 |
ck(b, b.get(), Double.MIN_VALUE); |
|
646 |
||
647 |
||
648 |
||
649 |
||
650 |
||
651 |
||
652 |
||
653 |
||
654 |
||
655 |
||
656 |
||
31873
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
657 |
|
37913 | 658 |
|
659 |
||
660 |
double v; |
|
2 | 661 |
ck(b, b.get(), -Double.MAX_VALUE); |
662 |
ck(b, b.get(), -Double.MIN_VALUE); |
|
663 |
ck(b, b.get(), Double.NEGATIVE_INFINITY); |
|
664 |
ck(b, b.get(), Double.POSITIVE_INFINITY); |
|
665 |
if (Double.doubleToRawLongBits(v = b.get()) |
|
37913 | 666 |
!= Double.doubleToRawLongBits(Double.NaN)) { |
2 | 667 |
fail(b, (long)Double.NaN, (long)v); |
37913 | 668 |
} |
2 | 669 |
ck(b, b.get(), 0.5121609353879392); |
670 |
||
671 |
||
672 |
||
673 |
// Comparison |
|
674 |
b.rewind(); |
|
675 |
DoubleBuffer b2 = DoubleBuffer.allocate(b.capacity()); |
|
676 |
b2.put(b); |
|
677 |
b2.flip(); |
|
678 |
b.position(2); |
|
679 |
b2.position(2); |
|
680 |
if (!b.equals(b2)) { |
|
681 |
for (int i = 2; i < b.limit(); i++) { |
|
682 |
double x = b.get(i); |
|
683 |
double y = b2.get(i); |
|
684 |
if (x != y |
|
685 |
||
686 |
|| Double.compare(x, y) != 0 |
|
687 |
||
688 |
||
689 |
||
690 |
||
37913 | 691 |
) { |
2 | 692 |
out.println("[" + i + "] " + x + " != " + y); |
37913 | 693 |
} |
2 | 694 |
} |
695 |
fail("Identical buffers not equal", b, b2); |
|
696 |
} |
|
37913 | 697 |
if (b.compareTo(b2) != 0) { |
2 | 698 |
fail("Comparison to identical buffer != 0", b, b2); |
37913 | 699 |
} |
2 | 700 |
b.limit(b.limit() + 1); |
701 |
b.position(b.limit() - 1); |
|
702 |
b.put((double)99); |
|
703 |
b.rewind(); |
|
704 |
b2.rewind(); |
|
705 |
if (b.equals(b2)) |
|
706 |
fail("Non-identical buffers equal", b, b2); |
|
707 |
if (b.compareTo(b2) <= 0) |
|
708 |
fail("Comparison to shorter buffer <= 0", b, b2); |
|
709 |
b.limit(b.limit() - 1); |
|
710 |
||
711 |
b.put(2, (double)42); |
|
712 |
if (b.equals(b2)) |
|
713 |
fail("Non-identical buffers equal", b, b2); |
|
714 |
if (b.compareTo(b2) <= 0) |
|
715 |
fail("Comparison to lesser buffer <= 0", b, b2); |
|
716 |
||
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
717 |
// Check equals and compareTo with interesting values |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
718 |
for (double x : VALUES) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
719 |
DoubleBuffer xb = DoubleBuffer.wrap(new double[] { x }); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
720 |
if (xb.compareTo(xb) != 0) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
721 |
fail("compareTo not reflexive", xb, xb, x, x); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
722 |
} |
37913 | 723 |
if (!xb.equals(xb)) { |
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
724 |
fail("equals not reflexive", xb, xb, x, x); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
725 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
726 |
for (double y : VALUES) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
727 |
DoubleBuffer yb = DoubleBuffer.wrap(new double[] { y }); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
728 |
if (xb.compareTo(yb) != - yb.compareTo(xb)) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
729 |
fail("compareTo not anti-symmetric", |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
730 |
xb, yb, x, y); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
731 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
732 |
if ((xb.compareTo(yb) == 0) != xb.equals(yb)) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
733 |
fail("compareTo inconsistent with equals", |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
734 |
xb, yb, x, y); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
735 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
736 |
if (xb.compareTo(yb) != Double.compare(x, y)) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
737 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
738 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
739 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
740 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
741 |
if (x == 0.0 && y == 0.0) continue; |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
742 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
743 |
fail("Incorrect results for DoubleBuffer.compareTo", |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
744 |
xb, yb, x, y); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
745 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
746 |
if (xb.equals(yb) != ((x == y) || ((x != x) && (y != y)))) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
747 |
fail("Incorrect results for DoubleBuffer.equals", |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
748 |
xb, yb, x, y); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
749 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
750 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
751 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
752 |
|
2 | 753 |
// Sub, dup |
754 |
||
755 |
relPut(b); |
|
756 |
relGet(b.duplicate()); |
|
757 |
b.position(13); |
|
758 |
relGet(b.duplicate(), 13); |
|
759 |
relGet(b.duplicate().slice(), 13); |
|
760 |
relGet(b.slice(), 13); |
|
761 |
relGet(b.slice().duplicate(), 13); |
|
762 |
||
763 |
// Slice |
|
764 |
||
765 |
b.position(5); |
|
766 |
DoubleBuffer sb = b.slice(); |
|
767 |
checkSlice(b, sb); |
|
768 |
b.position(0); |
|
769 |
DoubleBuffer sb2 = sb.slice(); |
|
770 |
checkSlice(sb, sb2); |
|
771 |
||
772 |
if (!sb.equals(sb2)) |
|
773 |
fail("Sliced slices do not match", sb, sb2); |
|
37913 | 774 |
if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset())) { |
2 | 775 |
fail("Array offsets do not match: " |
776 |
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2); |
|
37913 | 777 |
} |
2 | 778 |
|
779 |
||
780 |
||
781 |
||
782 |
||
783 |
||
784 |
||
785 |
||
786 |
||
787 |
||
788 |
||
789 |
||
790 |
||
791 |
||
792 |
||
793 |
||
794 |
||
795 |
||
796 |
||
797 |
||
798 |
||
799 |
||
800 |
||
801 |
||
802 |
||
803 |
||
804 |
||
805 |
||
806 |
||
807 |
||
808 |
||
809 |
||
810 |
// Read-only views |
|
811 |
||
812 |
b.rewind(); |
|
813 |
final DoubleBuffer rb = b.asReadOnlyBuffer(); |
|
814 |
if (!b.equals(rb)) |
|
815 |
fail("Buffer not equal to read-only view", b, rb); |
|
816 |
show(level + 1, rb); |
|
817 |
||
37913 | 818 |
catchReadOnlyBuffer(b, () -> relPut(rb)); |
819 |
catchReadOnlyBuffer(b, () -> absPut(rb)); |
|
820 |
catchReadOnlyBuffer(b, () -> bulkPutArray(rb)); |
|
821 |
catchReadOnlyBuffer(b, () -> bulkPutBuffer(rb)); |
|
2 | 822 |
|
14001
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
823 |
// put(DoubleBuffer) should not change source position |
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
824 |
final DoubleBuffer src = DoubleBuffer.allocate(1); |
37913 | 825 |
catchReadOnlyBuffer(b, () -> rb.put(src)); |
14001
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
826 |
ck(src, src.position(), 0); |
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
827 |
|
37913 | 828 |
catchReadOnlyBuffer(b, () -> rb.compact()); |
2 | 829 |
|
830 |
||
831 |
||
832 |
||
833 |
||
834 |
||
835 |
||
836 |
||
837 |
||
838 |
||
14001
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
839 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
840 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
841 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
842 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
843 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
844 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
845 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
846 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
847 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
848 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
849 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
850 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
851 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
852 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
853 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
854 |
|
2 | 855 |
if (rb.getClass().getName().startsWith("java.nio.Heap")) { |
37913 | 856 |
catchReadOnlyBuffer(b, () -> rb.array()); |
857 |
catchReadOnlyBuffer(b, () -> rb.arrayOffset()); |
|
858 |
if (rb.hasArray()) { |
|
859 |
fail("Read-only heap buffer's backing array is accessible", rb); |
|
860 |
} |
|
2 | 861 |
} |
862 |
||
863 |
// Bulk puts from read-only buffers |
|
864 |
||
865 |
b.clear(); |
|
866 |
rb.rewind(); |
|
867 |
b.put(rb); |
|
868 |
||
869 |
||
870 |
||
871 |
||
872 |
||
873 |
||
874 |
||
875 |
||
876 |
||
877 |
||
878 |
||
879 |
relPut(b); // Required by testViews |
|
880 |
||
36933
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
881 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
882 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
883 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
884 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
885 |
|
2 | 886 |
} |
887 |
||
888 |
||
889 |
||
890 |
||
891 |
||
892 |
||
893 |
||
894 |
||
895 |
||
896 |
||
897 |
||
898 |
||
899 |
||
900 |
||
901 |
||
902 |
||
903 |
||
904 |
||
905 |
||
906 |
||
907 |
||
908 |
||
909 |
||
910 |
||
911 |
||
912 |
||
913 |
||
914 |
||
915 |
||
916 |
||
917 |
||
918 |
||
919 |
||
920 |
||
921 |
||
922 |
||
923 |
||
924 |
||
925 |
||
926 |
||
927 |
||
928 |
||
929 |
||
930 |
||
931 |
public static void test(final double [] ba) { |
|
932 |
int offset = 47; |
|
933 |
int length = 900; |
|
934 |
final DoubleBuffer b = DoubleBuffer.wrap(ba, offset, length); |
|
935 |
show(0, b); |
|
936 |
ck(b, b.capacity(), ba.length); |
|
937 |
ck(b, b.position(), offset); |
|
938 |
ck(b, b.limit(), offset + length); |
|
939 |
||
940 |
// The offset must be non-negative and no larger than <array.length>. |
|
37913 | 941 |
catchIndexOutOfBounds(ba, () -> DoubleBuffer.wrap(ba, -1, ba.length)); |
942 |
catchIndexOutOfBounds(ba, () -> DoubleBuffer.wrap(ba, ba.length + 1, ba.length)); |
|
943 |
catchIndexOutOfBounds(ba, () -> DoubleBuffer.wrap(ba, 0, -1)); |
|
944 |
catchIndexOutOfBounds(ba, () -> DoubleBuffer.wrap(ba, 0, ba.length + 1)); |
|
2 | 945 |
|
946 |
// A NullPointerException will be thrown if the array is null. |
|
37913 | 947 |
tryCatch(ba, NullPointerException.class, |
948 |
() -> DoubleBuffer.wrap((double []) null, 0, 5)); |
|
949 |
tryCatch(ba, NullPointerException.class, |
|
950 |
() -> DoubleBuffer.wrap((double []) null)); |
|
2 | 951 |
} |
952 |
||
953 |
private static void testAllocate() { |
|
954 |
// An IllegalArgumentException will be thrown for negative capacities. |
|
37913 | 955 |
catchIllegalArgument((Buffer) null, () -> DoubleBuffer.allocate(-1)); |
31873
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
956 |
try { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
957 |
DoubleBuffer.allocate(-1); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
958 |
} catch (IllegalArgumentException e) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
959 |
if (e.getMessage() == null) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
960 |
fail("Non-null IllegalArgumentException message expected for" |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
961 |
+ " attempt to allocate negative capacity buffer"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
962 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
963 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
964 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
965 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
966 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
967 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
968 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
969 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
970 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
971 |
|
2 | 972 |
|
973 |
||
974 |
||
975 |
} |
|
976 |
||
977 |
public static void test() { |
|
978 |
testAllocate(); |
|
979 |
test(0, DoubleBuffer.allocate(7 * 1024), false); |
|
980 |
test(0, DoubleBuffer.wrap(new double[7 * 1024], 0, 7 * 1024), false); |
|
981 |
test(new double[1024]); |
|
982 |
||
983 |
||
984 |
||
985 |
||
986 |
||
987 |
||
988 |
||
989 |
||
990 |
||
991 |
||
992 |
callReset(DoubleBuffer.allocate(10)); |
|
993 |
||
994 |
||
995 |
||
996 |
putBuffer(); |
|
997 |
||
998 |
} |
|
999 |
||
1000 |
} |