author | psandoz |
Fri, 29 Apr 2016 13:46:19 -0700 | |
changeset 37719 | add11bc0e6e2 |
parent 36934 | 590fc47a0aeb |
child 38358 | cb99c6d2af1b |
child 37792 | dd626e6f5967 |
permissions | -rw-r--r-- |
36934 | 1 |
/* |
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
|
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. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
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 |
* |
|
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. |
|
24 |
*/ |
|
25 |
package java.lang.invoke; |
|
26 |
||
27 |
import jdk.internal.misc.Unsafe; |
|
28 |
import jdk.internal.vm.annotation.ForceInline; |
|
29 |
||
30 |
import java.nio.ByteBuffer; |
|
31 |
import java.nio.ReadOnlyBufferException; |
|
32 |
import java.util.Objects; |
|
33 |
||
34 |
import static java.lang.invoke.MethodHandleStatics.UNSAFE; |
|
35 |
||
36 |
#warn |
|
37 |
||
38 |
final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase { |
|
39 |
||
40 |
static final int ALIGN = $BoxType$.BYTES - 1; |
|
41 |
||
42 |
#if[floatingPoint] |
|
43 |
@ForceInline |
|
44 |
static $rawType$ convEndian(boolean big, $type$ v) { |
|
45 |
$rawType$ rv = $Type$.$type$ToRaw$RawType$Bits(v); |
|
46 |
return big == BE ? rv : $RawBoxType$.reverseBytes(rv); |
|
47 |
} |
|
48 |
||
49 |
@ForceInline |
|
50 |
static $type$ convEndian(boolean big, $rawType$ rv) { |
|
51 |
rv = big == BE ? rv : $RawBoxType$.reverseBytes(rv); |
|
52 |
return $Type$.$rawType$BitsTo$Type$(rv); |
|
53 |
} |
|
54 |
#else[floatingPoint] |
|
55 |
@ForceInline |
|
56 |
static $type$ convEndian(boolean big, $type$ n) { |
|
57 |
return big == BE ? n : $BoxType$.reverseBytes(n); |
|
58 |
} |
|
59 |
#end[floatingPoint] |
|
60 |
||
61 |
||
62 |
private static class ByteArrayViewVarHandle extends VarHandle { |
|
63 |
final boolean be; |
|
64 |
||
65 |
ByteArrayViewVarHandle(Class<? extends ByteArrayViewVarHandle> implSubType, |
|
66 |
Class<?> arrayType, Class<?> component, boolean be) { |
|
67 |
super(VarForm.createFromStatic(implSubType), |
|
68 |
arrayType, component, int.class); |
|
69 |
this.be = be; |
|
70 |
} |
|
71 |
} |
|
72 |
||
73 |
static final class ArrayHandle extends ByteArrayViewVarHandle { |
|
74 |
||
75 |
ArrayHandle(boolean be) { |
|
76 |
super(ArrayHandle.class, byte[].class, $type$.class, be); |
|
77 |
} |
|
78 |
||
79 |
@ForceInline |
|
80 |
static int index(byte[] ba, int index) { |
|
81 |
return Objects.checkIndex(index, ba.length - ALIGN, null); |
|
82 |
} |
|
83 |
||
84 |
@ForceInline |
|
85 |
static long address(byte[] ba, int index) { |
|
86 |
long address = ((long) index) + Unsafe.ARRAY_BYTE_BASE_OFFSET; |
|
87 |
if ((address & ALIGN) != 0) |
|
88 |
throw newIllegalStateExceptionForMisalignedAccess(index); |
|
89 |
return address; |
|
90 |
} |
|
91 |
||
92 |
@ForceInline |
|
93 |
static $type$ get(ArrayHandle handle, Object oba, int index) { |
|
94 |
byte[] ba = (byte[]) oba; |
|
95 |
#if[floatingPoint] |
|
96 |
$rawType$ rawValue = UNSAFE.get$RawType$Unaligned( |
|
97 |
ba, |
|
98 |
((long) index(ba, index)) + Unsafe.ARRAY_BYTE_BASE_OFFSET, |
|
99 |
handle.be); |
|
100 |
return $Type$.$rawType$BitsTo$Type$(rawValue); |
|
101 |
#else[floatingPoint] |
|
102 |
return UNSAFE.get$Type$Unaligned( |
|
103 |
ba, |
|
104 |
((long) index(ba, index)) + Unsafe.ARRAY_BYTE_BASE_OFFSET, |
|
105 |
handle.be); |
|
106 |
#end[floatingPoint] |
|
107 |
} |
|
108 |
||
109 |
@ForceInline |
|
110 |
static void set(ArrayHandle handle, Object oba, int index, $type$ value) { |
|
111 |
byte[] ba = (byte[]) oba; |
|
112 |
#if[floatingPoint] |
|
113 |
UNSAFE.put$RawType$Unaligned( |
|
114 |
ba, |
|
115 |
((long) index(ba, index)) + Unsafe.ARRAY_BYTE_BASE_OFFSET, |
|
116 |
$Type$.$type$ToRaw$RawType$Bits(value), |
|
117 |
handle.be); |
|
118 |
#else[floatingPoint] |
|
119 |
UNSAFE.put$RawType$Unaligned( |
|
120 |
ba, |
|
121 |
((long) index(ba, index)) + Unsafe.ARRAY_BYTE_BASE_OFFSET, |
|
122 |
value, |
|
123 |
handle.be); |
|
124 |
#end[floatingPoint] |
|
125 |
} |
|
126 |
||
127 |
@ForceInline |
|
128 |
static $type$ getVolatile(ArrayHandle handle, Object oba, int index) { |
|
129 |
byte[] ba = (byte[]) oba; |
|
130 |
return convEndian(handle.be, |
|
131 |
UNSAFE.get$RawType$Volatile( |
|
132 |
ba, |
|
133 |
address(ba, index(ba, index)))); |
|
134 |
} |
|
135 |
||
136 |
@ForceInline |
|
137 |
static void setVolatile(ArrayHandle handle, Object oba, int index, $type$ value) { |
|
138 |
byte[] ba = (byte[]) oba; |
|
139 |
UNSAFE.put$RawType$Volatile( |
|
140 |
ba, |
|
141 |
address(ba, index(ba, index)), |
|
142 |
convEndian(handle.be, value)); |
|
143 |
} |
|
144 |
||
145 |
@ForceInline |
|
146 |
static $type$ getAcquire(ArrayHandle handle, Object oba, int index) { |
|
147 |
byte[] ba = (byte[]) oba; |
|
148 |
return convEndian(handle.be, |
|
149 |
UNSAFE.get$RawType$Acquire( |
|
150 |
ba, |
|
151 |
address(ba, index(ba, index)))); |
|
152 |
} |
|
153 |
||
154 |
@ForceInline |
|
155 |
static void setRelease(ArrayHandle handle, Object oba, int index, $type$ value) { |
|
156 |
byte[] ba = (byte[]) oba; |
|
157 |
UNSAFE.put$RawType$Release( |
|
158 |
ba, |
|
159 |
address(ba, index(ba, index)), |
|
160 |
convEndian(handle.be, value)); |
|
161 |
} |
|
162 |
||
163 |
@ForceInline |
|
164 |
static $type$ getOpaque(ArrayHandle handle, Object oba, int index) { |
|
165 |
byte[] ba = (byte[]) oba; |
|
166 |
return convEndian(handle.be, |
|
167 |
UNSAFE.get$RawType$Opaque( |
|
168 |
ba, |
|
169 |
address(ba, index(ba, index)))); |
|
170 |
} |
|
171 |
||
172 |
@ForceInline |
|
173 |
static void setOpaque(ArrayHandle handle, Object oba, int index, $type$ value) { |
|
174 |
byte[] ba = (byte[]) oba; |
|
175 |
UNSAFE.put$RawType$Opaque( |
|
176 |
ba, |
|
177 |
address(ba, index(ba, index)), |
|
178 |
convEndian(handle.be, value)); |
|
179 |
} |
|
180 |
#if[CAS] |
|
181 |
||
182 |
@ForceInline |
|
183 |
static boolean compareAndSet(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) { |
|
184 |
byte[] ba = (byte[]) oba; |
|
185 |
return UNSAFE.compareAndSwap$RawType$( |
|
186 |
ba, |
|
187 |
address(ba, index(ba, index)), |
|
188 |
convEndian(handle.be, expected), convEndian(handle.be, value)); |
|
189 |
} |
|
190 |
||
191 |
@ForceInline |
|
192 |
static $type$ compareAndExchangeVolatile(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) { |
|
193 |
byte[] ba = (byte[]) oba; |
|
194 |
return convEndian(handle.be, |
|
195 |
UNSAFE.compareAndExchange$RawType$Volatile( |
|
196 |
ba, |
|
197 |
address(ba, index(ba, index)), |
|
198 |
convEndian(handle.be, expected), convEndian(handle.be, value))); |
|
199 |
} |
|
200 |
||
201 |
@ForceInline |
|
202 |
static $type$ compareAndExchangeAcquire(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) { |
|
203 |
byte[] ba = (byte[]) oba; |
|
204 |
return convEndian(handle.be, |
|
205 |
UNSAFE.compareAndExchange$RawType$Acquire( |
|
206 |
ba, |
|
207 |
address(ba, index(ba, index)), |
|
208 |
convEndian(handle.be, expected), convEndian(handle.be, value))); |
|
209 |
} |
|
210 |
||
211 |
@ForceInline |
|
212 |
static $type$ compareAndExchangeRelease(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) { |
|
213 |
byte[] ba = (byte[]) oba; |
|
214 |
return convEndian(handle.be, |
|
215 |
UNSAFE.compareAndExchange$RawType$Release( |
|
216 |
ba, |
|
217 |
address(ba, index(ba, index)), |
|
218 |
convEndian(handle.be, expected), convEndian(handle.be, value))); |
|
219 |
} |
|
220 |
||
221 |
@ForceInline |
|
222 |
static boolean weakCompareAndSet(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) { |
|
223 |
byte[] ba = (byte[]) oba; |
|
224 |
return UNSAFE.weakCompareAndSwap$RawType$( |
|
225 |
ba, |
|
226 |
address(ba, index(ba, index)), |
|
227 |
convEndian(handle.be, expected), convEndian(handle.be, value)); |
|
228 |
} |
|
229 |
||
230 |
@ForceInline |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
231 |
static boolean weakCompareAndSetVolatile(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) { |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
232 |
byte[] ba = (byte[]) oba; |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
233 |
// TODO defer to strong form until new Unsafe method is added |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
234 |
return UNSAFE.compareAndSwap$RawType$( |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
235 |
ba, |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
236 |
address(ba, index(ba, index)), |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
237 |
convEndian(handle.be, expected), convEndian(handle.be, value)); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
238 |
} |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
239 |
|
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
240 |
@ForceInline |
36934 | 241 |
static boolean weakCompareAndSetAcquire(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) { |
242 |
byte[] ba = (byte[]) oba; |
|
243 |
return UNSAFE.weakCompareAndSwap$RawType$Acquire( |
|
244 |
ba, |
|
245 |
address(ba, index(ba, index)), |
|
246 |
convEndian(handle.be, expected), convEndian(handle.be, value)); |
|
247 |
} |
|
248 |
||
249 |
@ForceInline |
|
250 |
static boolean weakCompareAndSetRelease(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) { |
|
251 |
byte[] ba = (byte[]) oba; |
|
252 |
return UNSAFE.weakCompareAndSwap$RawType$Release( |
|
253 |
ba, |
|
254 |
address(ba, index(ba, index)), |
|
255 |
convEndian(handle.be, expected), convEndian(handle.be, value)); |
|
256 |
} |
|
257 |
||
258 |
@ForceInline |
|
259 |
static $type$ getAndSet(ArrayHandle handle, Object oba, int index, $type$ value) { |
|
260 |
byte[] ba = (byte[]) oba; |
|
261 |
return convEndian(handle.be, |
|
262 |
UNSAFE.getAndSet$RawType$( |
|
263 |
ba, |
|
264 |
address(ba, index(ba, index)), |
|
265 |
convEndian(handle.be, value))); |
|
266 |
} |
|
267 |
#end[CAS] |
|
268 |
#if[AtomicAdd] |
|
269 |
||
270 |
@ForceInline |
|
271 |
static $type$ getAndAdd(ArrayHandle handle, Object oba, int index, $type$ value) { |
|
272 |
byte[] ba = (byte[]) oba; |
|
273 |
return convEndian(handle.be, |
|
274 |
UNSAFE.getAndAdd$RawType$( |
|
275 |
ba, |
|
276 |
address(ba, index(ba, index)), |
|
277 |
convEndian(handle.be, value))); |
|
278 |
} |
|
279 |
||
280 |
@ForceInline |
|
281 |
static $type$ addAndGet(ArrayHandle handle, Object oba, int index, $type$ value) { |
|
282 |
byte[] ba = (byte[]) oba; |
|
283 |
return convEndian(handle.be, UNSAFE.getAndAdd$RawType$( |
|
284 |
ba, |
|
285 |
address(ba, index(ba, index)), |
|
286 |
convEndian(handle.be, value))) + value; |
|
287 |
} |
|
288 |
#end[AtomicAdd] |
|
289 |
} |
|
290 |
||
291 |
||
292 |
static final class ByteBufferHandle extends ByteArrayViewVarHandle { |
|
293 |
||
294 |
ByteBufferHandle(boolean be) { |
|
295 |
super(ByteBufferHandle.class, ByteBuffer.class, $type$.class, be); |
|
296 |
} |
|
297 |
||
298 |
@ForceInline |
|
299 |
static int index(ByteBuffer bb, int index) { |
|
300 |
return Objects.checkIndex(index, UNSAFE.getInt(bb, BUFFER_LIMIT) - ALIGN, null); |
|
301 |
} |
|
302 |
||
303 |
@ForceInline |
|
304 |
static int indexRO(ByteBuffer bb, int index) { |
|
305 |
if (UNSAFE.getBoolean(bb, BYTE_BUFFER_IS_READ_ONLY)) |
|
306 |
throw new ReadOnlyBufferException(); |
|
307 |
return Objects.checkIndex(index, UNSAFE.getInt(bb, BUFFER_LIMIT) - ALIGN, null); |
|
308 |
} |
|
309 |
||
310 |
@ForceInline |
|
311 |
static long address(ByteBuffer bb, int index) { |
|
312 |
long address = ((long) index) + UNSAFE.getLong(bb, BUFFER_ADDRESS); |
|
313 |
if ((address & ALIGN) != 0) |
|
314 |
throw newIllegalStateExceptionForMisalignedAccess(index); |
|
315 |
return address; |
|
316 |
} |
|
317 |
||
318 |
@ForceInline |
|
319 |
static $type$ get(ByteBufferHandle handle, Object obb, int index) { |
|
320 |
ByteBuffer bb = (ByteBuffer) obb; |
|
321 |
#if[floatingPoint] |
|
322 |
$rawType$ rawValue = UNSAFE.get$RawType$Unaligned( |
|
323 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
324 |
((long) index(bb, index)) + UNSAFE.getLong(bb, BUFFER_ADDRESS), |
|
325 |
handle.be); |
|
326 |
return $Type$.$rawType$BitsTo$Type$(rawValue); |
|
327 |
#else[floatingPoint] |
|
328 |
return UNSAFE.get$Type$Unaligned( |
|
329 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
330 |
((long) index(bb, index)) + UNSAFE.getLong(bb, BUFFER_ADDRESS), |
|
331 |
handle.be); |
|
332 |
#end[floatingPoint] |
|
333 |
} |
|
334 |
||
335 |
@ForceInline |
|
336 |
static void set(ByteBufferHandle handle, Object obb, int index, $type$ value) { |
|
337 |
ByteBuffer bb = (ByteBuffer) obb; |
|
338 |
#if[floatingPoint] |
|
339 |
UNSAFE.put$RawType$Unaligned( |
|
340 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
341 |
((long) indexRO(bb, index)) + UNSAFE.getLong(bb, BUFFER_ADDRESS), |
|
342 |
$Type$.$type$ToRaw$RawType$Bits(value), |
|
343 |
handle.be); |
|
344 |
#else[floatingPoint] |
|
345 |
UNSAFE.put$Type$Unaligned( |
|
346 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
347 |
((long) indexRO(bb, index)) + UNSAFE.getLong(bb, BUFFER_ADDRESS), |
|
348 |
value, |
|
349 |
handle.be); |
|
350 |
#end[floatingPoint] |
|
351 |
} |
|
352 |
||
353 |
@ForceInline |
|
354 |
static $type$ getVolatile(ByteBufferHandle handle, Object obb, int index) { |
|
355 |
ByteBuffer bb = (ByteBuffer) obb; |
|
356 |
return convEndian(handle.be, |
|
357 |
UNSAFE.get$RawType$Volatile( |
|
358 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
359 |
address(bb, index(bb, index)))); |
|
360 |
} |
|
361 |
||
362 |
@ForceInline |
|
363 |
static void setVolatile(ByteBufferHandle handle, Object obb, int index, $type$ value) { |
|
364 |
ByteBuffer bb = (ByteBuffer) obb; |
|
365 |
UNSAFE.put$RawType$Volatile( |
|
366 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
367 |
address(bb, indexRO(bb, index)), |
|
368 |
convEndian(handle.be, value)); |
|
369 |
} |
|
370 |
||
371 |
@ForceInline |
|
372 |
static $type$ getAcquire(ByteBufferHandle handle, Object obb, int index) { |
|
373 |
ByteBuffer bb = (ByteBuffer) obb; |
|
374 |
return convEndian(handle.be, |
|
375 |
UNSAFE.get$RawType$Acquire( |
|
376 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
377 |
address(bb, index(bb, index)))); |
|
378 |
} |
|
379 |
||
380 |
@ForceInline |
|
381 |
static void setRelease(ByteBufferHandle handle, Object obb, int index, $type$ value) { |
|
382 |
ByteBuffer bb = (ByteBuffer) obb; |
|
383 |
UNSAFE.put$RawType$Release( |
|
384 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
385 |
address(bb, indexRO(bb, index)), |
|
386 |
convEndian(handle.be, value)); |
|
387 |
} |
|
388 |
||
389 |
@ForceInline |
|
390 |
static $type$ getOpaque(ByteBufferHandle handle, Object obb, int index) { |
|
391 |
ByteBuffer bb = (ByteBuffer) obb; |
|
392 |
return convEndian(handle.be, |
|
393 |
UNSAFE.get$RawType$Opaque( |
|
394 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
395 |
address(bb, index(bb, index)))); |
|
396 |
} |
|
397 |
||
398 |
@ForceInline |
|
399 |
static void setOpaque(ByteBufferHandle handle, Object obb, int index, $type$ value) { |
|
400 |
ByteBuffer bb = (ByteBuffer) obb; |
|
401 |
UNSAFE.put$RawType$Opaque( |
|
402 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
403 |
address(bb, indexRO(bb, index)), |
|
404 |
convEndian(handle.be, value)); |
|
405 |
} |
|
406 |
#if[CAS] |
|
407 |
||
408 |
@ForceInline |
|
409 |
static boolean compareAndSet(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) { |
|
410 |
ByteBuffer bb = (ByteBuffer) obb; |
|
411 |
return UNSAFE.compareAndSwap$RawType$( |
|
412 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
413 |
address(bb, indexRO(bb, index)), |
|
414 |
convEndian(handle.be, expected), convEndian(handle.be, value)); |
|
415 |
} |
|
416 |
||
417 |
@ForceInline |
|
418 |
static $type$ compareAndExchangeVolatile(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) { |
|
419 |
ByteBuffer bb = (ByteBuffer) obb; |
|
420 |
return convEndian(handle.be, |
|
421 |
UNSAFE.compareAndExchange$RawType$Volatile( |
|
422 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
423 |
address(bb, indexRO(bb, index)), |
|
424 |
convEndian(handle.be, expected), convEndian(handle.be, value))); |
|
425 |
} |
|
426 |
||
427 |
@ForceInline |
|
428 |
static $type$ compareAndExchangeAcquire(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) { |
|
429 |
ByteBuffer bb = (ByteBuffer) obb; |
|
430 |
return convEndian(handle.be, |
|
431 |
UNSAFE.compareAndExchange$RawType$Acquire( |
|
432 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
433 |
address(bb, indexRO(bb, index)), |
|
434 |
convEndian(handle.be, expected), convEndian(handle.be, value))); |
|
435 |
} |
|
436 |
||
437 |
@ForceInline |
|
438 |
static $type$ compareAndExchangeRelease(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) { |
|
439 |
ByteBuffer bb = (ByteBuffer) obb; |
|
440 |
return convEndian(handle.be, |
|
441 |
UNSAFE.compareAndExchange$RawType$Release( |
|
442 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
443 |
address(bb, indexRO(bb, index)), |
|
444 |
convEndian(handle.be, expected), convEndian(handle.be, value))); |
|
445 |
} |
|
446 |
||
447 |
@ForceInline |
|
448 |
static boolean weakCompareAndSet(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) { |
|
449 |
ByteBuffer bb = (ByteBuffer) obb; |
|
450 |
return UNSAFE.weakCompareAndSwap$RawType$( |
|
451 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
452 |
address(bb, indexRO(bb, index)), |
|
453 |
convEndian(handle.be, expected), convEndian(handle.be, value)); |
|
454 |
} |
|
455 |
||
456 |
@ForceInline |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
457 |
static boolean weakCompareAndSetVolatile(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) { |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
458 |
ByteBuffer bb = (ByteBuffer) obb; |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
459 |
// TODO defer to strong form until new Unsafe method is added |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
460 |
return UNSAFE.compareAndSwap$RawType$( |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
461 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
462 |
address(bb, indexRO(bb, index)), |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
463 |
convEndian(handle.be, expected), convEndian(handle.be, value)); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
464 |
} |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
465 |
|
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
466 |
@ForceInline |
36934 | 467 |
static boolean weakCompareAndSetAcquire(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) { |
468 |
ByteBuffer bb = (ByteBuffer) obb; |
|
469 |
return UNSAFE.weakCompareAndSwap$RawType$Acquire( |
|
470 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
471 |
address(bb, indexRO(bb, index)), |
|
472 |
convEndian(handle.be, expected), convEndian(handle.be, value)); |
|
473 |
} |
|
474 |
||
475 |
@ForceInline |
|
476 |
static boolean weakCompareAndSetRelease(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) { |
|
477 |
ByteBuffer bb = (ByteBuffer) obb; |
|
478 |
return UNSAFE.weakCompareAndSwap$RawType$Release( |
|
479 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
480 |
address(bb, indexRO(bb, index)), |
|
481 |
convEndian(handle.be, expected), convEndian(handle.be, value)); |
|
482 |
} |
|
483 |
||
484 |
@ForceInline |
|
485 |
static $type$ getAndSet(ByteBufferHandle handle, Object obb, int index, $type$ value) { |
|
486 |
ByteBuffer bb = (ByteBuffer) obb; |
|
487 |
return convEndian(handle.be, |
|
488 |
UNSAFE.getAndSet$RawType$( |
|
489 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
490 |
address(bb, indexRO(bb, index)), |
|
491 |
convEndian(handle.be, value))); |
|
492 |
} |
|
493 |
#end[CAS] |
|
494 |
#if[AtomicAdd] |
|
495 |
||
496 |
@ForceInline |
|
497 |
static $type$ getAndAdd(ByteBufferHandle handle, Object obb, int index, $type$ value) { |
|
498 |
ByteBuffer bb = (ByteBuffer) obb; |
|
499 |
return convEndian(handle.be, |
|
500 |
UNSAFE.getAndAdd$RawType$( |
|
501 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
502 |
address(bb, indexRO(bb, index)), |
|
503 |
convEndian(handle.be, value))); |
|
504 |
} |
|
505 |
||
506 |
@ForceInline |
|
507 |
static $type$ addAndGet(ByteBufferHandle handle, Object obb, int index, $type$ value) { |
|
508 |
ByteBuffer bb = (ByteBuffer) obb; |
|
509 |
return convEndian(handle.be, |
|
510 |
UNSAFE.getAndAdd$RawType$( |
|
511 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
512 |
address(bb, indexRO(bb, index)), |
|
513 |
convEndian(handle.be, value))) + value; |
|
514 |
} |
|
515 |
#end[AtomicAdd] |
|
516 |
} |
|
517 |
} |