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