author | psandoz |
Thu, 23 Jun 2016 13:46:48 +0200 | |
changeset 39472 | 6df82f4c63ac |
parent 38382 | 98d5a441bc2f |
child 40732 | 2fd9cf42bb3c |
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 |
||
37792 | 63 |
private static abstract class ByteArrayViewVarHandle extends VarHandle { |
36934 | 64 |
final boolean be; |
65 |
||
37792 | 66 |
ByteArrayViewVarHandle(VarForm form, boolean be) { |
67 |
super(form); |
|
36934 | 68 |
this.be = be; |
69 |
} |
|
70 |
} |
|
71 |
||
72 |
static final class ArrayHandle extends ByteArrayViewVarHandle { |
|
73 |
||
74 |
ArrayHandle(boolean be) { |
|
37792 | 75 |
super(ArrayHandle.FORM, be); |
76 |
} |
|
77 |
||
78 |
@Override |
|
79 |
final MethodType accessModeTypeUncached(AccessMode accessMode) { |
|
80 |
return accessMode.at.accessModeType(byte[].class, $type$.class, int.class); |
|
36934 | 81 |
} |
82 |
||
83 |
@ForceInline |
|
84 |
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
|
85 |
return Preconditions.checkIndex(index, ba.length - ALIGN, null); |
36934 | 86 |
} |
87 |
||
88 |
@ForceInline |
|
89 |
static long address(byte[] ba, int index) { |
|
90 |
long address = ((long) index) + Unsafe.ARRAY_BYTE_BASE_OFFSET; |
|
91 |
if ((address & ALIGN) != 0) |
|
92 |
throw newIllegalStateExceptionForMisalignedAccess(index); |
|
93 |
return address; |
|
94 |
} |
|
95 |
||
96 |
@ForceInline |
|
97 |
static $type$ get(ArrayHandle handle, Object oba, int index) { |
|
98 |
byte[] ba = (byte[]) oba; |
|
99 |
#if[floatingPoint] |
|
100 |
$rawType$ rawValue = UNSAFE.get$RawType$Unaligned( |
|
101 |
ba, |
|
102 |
((long) index(ba, index)) + Unsafe.ARRAY_BYTE_BASE_OFFSET, |
|
103 |
handle.be); |
|
104 |
return $Type$.$rawType$BitsTo$Type$(rawValue); |
|
105 |
#else[floatingPoint] |
|
106 |
return UNSAFE.get$Type$Unaligned( |
|
107 |
ba, |
|
108 |
((long) index(ba, index)) + Unsafe.ARRAY_BYTE_BASE_OFFSET, |
|
109 |
handle.be); |
|
110 |
#end[floatingPoint] |
|
111 |
} |
|
112 |
||
113 |
@ForceInline |
|
114 |
static void set(ArrayHandle handle, Object oba, int index, $type$ value) { |
|
115 |
byte[] ba = (byte[]) oba; |
|
116 |
#if[floatingPoint] |
|
117 |
UNSAFE.put$RawType$Unaligned( |
|
118 |
ba, |
|
119 |
((long) index(ba, index)) + Unsafe.ARRAY_BYTE_BASE_OFFSET, |
|
120 |
$Type$.$type$ToRaw$RawType$Bits(value), |
|
121 |
handle.be); |
|
122 |
#else[floatingPoint] |
|
123 |
UNSAFE.put$RawType$Unaligned( |
|
124 |
ba, |
|
125 |
((long) index(ba, index)) + Unsafe.ARRAY_BYTE_BASE_OFFSET, |
|
126 |
value, |
|
127 |
handle.be); |
|
128 |
#end[floatingPoint] |
|
129 |
} |
|
130 |
||
131 |
@ForceInline |
|
132 |
static $type$ getVolatile(ArrayHandle handle, Object oba, int index) { |
|
133 |
byte[] ba = (byte[]) oba; |
|
134 |
return convEndian(handle.be, |
|
135 |
UNSAFE.get$RawType$Volatile( |
|
136 |
ba, |
|
137 |
address(ba, index(ba, index)))); |
|
138 |
} |
|
139 |
||
140 |
@ForceInline |
|
141 |
static void setVolatile(ArrayHandle handle, Object oba, int index, $type$ value) { |
|
142 |
byte[] ba = (byte[]) oba; |
|
143 |
UNSAFE.put$RawType$Volatile( |
|
144 |
ba, |
|
145 |
address(ba, index(ba, index)), |
|
146 |
convEndian(handle.be, value)); |
|
147 |
} |
|
148 |
||
149 |
@ForceInline |
|
150 |
static $type$ getAcquire(ArrayHandle handle, Object oba, int index) { |
|
151 |
byte[] ba = (byte[]) oba; |
|
152 |
return convEndian(handle.be, |
|
153 |
UNSAFE.get$RawType$Acquire( |
|
154 |
ba, |
|
155 |
address(ba, index(ba, index)))); |
|
156 |
} |
|
157 |
||
158 |
@ForceInline |
|
159 |
static void setRelease(ArrayHandle handle, Object oba, int index, $type$ value) { |
|
160 |
byte[] ba = (byte[]) oba; |
|
161 |
UNSAFE.put$RawType$Release( |
|
162 |
ba, |
|
163 |
address(ba, index(ba, index)), |
|
164 |
convEndian(handle.be, value)); |
|
165 |
} |
|
166 |
||
167 |
@ForceInline |
|
168 |
static $type$ getOpaque(ArrayHandle handle, Object oba, int index) { |
|
169 |
byte[] ba = (byte[]) oba; |
|
170 |
return convEndian(handle.be, |
|
171 |
UNSAFE.get$RawType$Opaque( |
|
172 |
ba, |
|
173 |
address(ba, index(ba, index)))); |
|
174 |
} |
|
175 |
||
176 |
@ForceInline |
|
177 |
static void setOpaque(ArrayHandle handle, Object oba, int index, $type$ value) { |
|
178 |
byte[] ba = (byte[]) oba; |
|
179 |
UNSAFE.put$RawType$Opaque( |
|
180 |
ba, |
|
181 |
address(ba, index(ba, index)), |
|
182 |
convEndian(handle.be, value)); |
|
183 |
} |
|
184 |
#if[CAS] |
|
185 |
||
186 |
@ForceInline |
|
187 |
static boolean compareAndSet(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) { |
|
188 |
byte[] ba = (byte[]) oba; |
|
189 |
return UNSAFE.compareAndSwap$RawType$( |
|
190 |
ba, |
|
191 |
address(ba, index(ba, index)), |
|
192 |
convEndian(handle.be, expected), convEndian(handle.be, value)); |
|
193 |
} |
|
194 |
||
195 |
@ForceInline |
|
39472
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38382
diff
changeset
|
196 |
static $type$ compareAndExchange(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) { |
36934 | 197 |
byte[] ba = (byte[]) oba; |
198 |
return convEndian(handle.be, |
|
199 |
UNSAFE.compareAndExchange$RawType$Volatile( |
|
200 |
ba, |
|
201 |
address(ba, index(ba, index)), |
|
202 |
convEndian(handle.be, expected), convEndian(handle.be, value))); |
|
203 |
} |
|
204 |
||
205 |
@ForceInline |
|
206 |
static $type$ compareAndExchangeAcquire(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) { |
|
207 |
byte[] ba = (byte[]) oba; |
|
208 |
return convEndian(handle.be, |
|
209 |
UNSAFE.compareAndExchange$RawType$Acquire( |
|
210 |
ba, |
|
211 |
address(ba, index(ba, index)), |
|
212 |
convEndian(handle.be, expected), convEndian(handle.be, value))); |
|
213 |
} |
|
214 |
||
215 |
@ForceInline |
|
216 |
static $type$ compareAndExchangeRelease(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) { |
|
217 |
byte[] ba = (byte[]) oba; |
|
218 |
return convEndian(handle.be, |
|
219 |
UNSAFE.compareAndExchange$RawType$Release( |
|
220 |
ba, |
|
221 |
address(ba, index(ba, index)), |
|
222 |
convEndian(handle.be, expected), convEndian(handle.be, value))); |
|
223 |
} |
|
224 |
||
225 |
@ForceInline |
|
226 |
static boolean weakCompareAndSet(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) { |
|
227 |
byte[] ba = (byte[]) oba; |
|
228 |
return UNSAFE.weakCompareAndSwap$RawType$( |
|
229 |
ba, |
|
230 |
address(ba, index(ba, index)), |
|
231 |
convEndian(handle.be, expected), convEndian(handle.be, value)); |
|
232 |
} |
|
233 |
||
234 |
@ForceInline |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
235 |
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
|
236 |
byte[] ba = (byte[]) oba; |
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38367
diff
changeset
|
237 |
return UNSAFE.weakCompareAndSwap$RawType$Volatile( |
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
238 |
ba, |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
239 |
address(ba, index(ba, index)), |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
240 |
convEndian(handle.be, expected), convEndian(handle.be, value)); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
241 |
} |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
242 |
|
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
243 |
@ForceInline |
36934 | 244 |
static boolean weakCompareAndSetAcquire(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) { |
245 |
byte[] ba = (byte[]) oba; |
|
246 |
return UNSAFE.weakCompareAndSwap$RawType$Acquire( |
|
247 |
ba, |
|
248 |
address(ba, index(ba, index)), |
|
249 |
convEndian(handle.be, expected), convEndian(handle.be, value)); |
|
250 |
} |
|
251 |
||
252 |
@ForceInline |
|
253 |
static boolean weakCompareAndSetRelease(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) { |
|
254 |
byte[] ba = (byte[]) oba; |
|
255 |
return UNSAFE.weakCompareAndSwap$RawType$Release( |
|
256 |
ba, |
|
257 |
address(ba, index(ba, index)), |
|
258 |
convEndian(handle.be, expected), convEndian(handle.be, value)); |
|
259 |
} |
|
260 |
||
261 |
@ForceInline |
|
262 |
static $type$ getAndSet(ArrayHandle handle, Object oba, int index, $type$ value) { |
|
263 |
byte[] ba = (byte[]) oba; |
|
264 |
return convEndian(handle.be, |
|
265 |
UNSAFE.getAndSet$RawType$( |
|
266 |
ba, |
|
267 |
address(ba, index(ba, index)), |
|
268 |
convEndian(handle.be, value))); |
|
269 |
} |
|
270 |
#end[CAS] |
|
271 |
#if[AtomicAdd] |
|
272 |
||
273 |
@ForceInline |
|
38382
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
274 |
static $type$ getAndAdd(ArrayHandle handle, Object oba, int index, $type$ delta) { |
36934 | 275 |
byte[] ba = (byte[]) oba; |
38382
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
276 |
if (handle.be == BE) { |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
277 |
return UNSAFE.getAndAdd$RawType$( |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
278 |
ba, |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
279 |
address(ba, index(ba, index)), |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
280 |
delta); |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
281 |
} else { |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
282 |
return getAndAddConvEndianWithCAS(ba, index, delta); |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
283 |
} |
36934 | 284 |
} |
285 |
||
286 |
@ForceInline |
|
38382
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
287 |
static $type$ getAndAddConvEndianWithCAS(byte[] ba, int index, $type$ delta) { |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
288 |
$type$ nativeExpectedValue, expectedValue; |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
289 |
long offset = address(ba, index(ba, index)); |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
290 |
do { |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
291 |
nativeExpectedValue = UNSAFE.get$RawType$Volatile(ba, offset); |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
292 |
expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue); |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
293 |
} while (!UNSAFE.weakCompareAndSwap$RawType$Volatile(ba, offset, |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
294 |
nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue + delta))); |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
295 |
return expectedValue; |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
296 |
} |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
297 |
|
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
298 |
@ForceInline |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
299 |
static $type$ addAndGet(ArrayHandle handle, Object oba, int index, $type$ delta) { |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
300 |
return getAndAdd(handle, oba, index, delta) + delta; |
36934 | 301 |
} |
302 |
#end[AtomicAdd] |
|
37792 | 303 |
|
304 |
static final VarForm FORM = new VarForm(ArrayHandle.class, byte[].class, $type$.class, int.class); |
|
36934 | 305 |
} |
306 |
||
307 |
||
308 |
static final class ByteBufferHandle extends ByteArrayViewVarHandle { |
|
309 |
||
310 |
ByteBufferHandle(boolean be) { |
|
37792 | 311 |
super(ByteBufferHandle.FORM, be); |
312 |
} |
|
313 |
||
314 |
@Override |
|
315 |
final MethodType accessModeTypeUncached(AccessMode accessMode) { |
|
316 |
return accessMode.at.accessModeType(ByteBuffer.class, $type$.class, int.class); |
|
36934 | 317 |
} |
318 |
||
319 |
@ForceInline |
|
320 |
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
|
321 |
return Preconditions.checkIndex(index, UNSAFE.getInt(bb, BUFFER_LIMIT) - ALIGN, null); |
36934 | 322 |
} |
323 |
||
324 |
@ForceInline |
|
325 |
static int indexRO(ByteBuffer bb, int index) { |
|
326 |
if (UNSAFE.getBoolean(bb, BYTE_BUFFER_IS_READ_ONLY)) |
|
327 |
throw new ReadOnlyBufferException(); |
|
38356
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
328 |
return Preconditions.checkIndex(index, UNSAFE.getInt(bb, BUFFER_LIMIT) - ALIGN, null); |
36934 | 329 |
} |
330 |
||
331 |
@ForceInline |
|
332 |
static long address(ByteBuffer bb, int index) { |
|
333 |
long address = ((long) index) + UNSAFE.getLong(bb, BUFFER_ADDRESS); |
|
334 |
if ((address & ALIGN) != 0) |
|
335 |
throw newIllegalStateExceptionForMisalignedAccess(index); |
|
336 |
return address; |
|
337 |
} |
|
338 |
||
339 |
@ForceInline |
|
340 |
static $type$ get(ByteBufferHandle handle, Object obb, int index) { |
|
341 |
ByteBuffer bb = (ByteBuffer) obb; |
|
342 |
#if[floatingPoint] |
|
343 |
$rawType$ rawValue = UNSAFE.get$RawType$Unaligned( |
|
344 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
345 |
((long) index(bb, index)) + UNSAFE.getLong(bb, BUFFER_ADDRESS), |
|
346 |
handle.be); |
|
347 |
return $Type$.$rawType$BitsTo$Type$(rawValue); |
|
348 |
#else[floatingPoint] |
|
349 |
return UNSAFE.get$Type$Unaligned( |
|
350 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
351 |
((long) index(bb, index)) + UNSAFE.getLong(bb, BUFFER_ADDRESS), |
|
352 |
handle.be); |
|
353 |
#end[floatingPoint] |
|
354 |
} |
|
355 |
||
356 |
@ForceInline |
|
357 |
static void set(ByteBufferHandle handle, Object obb, int index, $type$ value) { |
|
358 |
ByteBuffer bb = (ByteBuffer) obb; |
|
359 |
#if[floatingPoint] |
|
360 |
UNSAFE.put$RawType$Unaligned( |
|
361 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
362 |
((long) indexRO(bb, index)) + UNSAFE.getLong(bb, BUFFER_ADDRESS), |
|
363 |
$Type$.$type$ToRaw$RawType$Bits(value), |
|
364 |
handle.be); |
|
365 |
#else[floatingPoint] |
|
366 |
UNSAFE.put$Type$Unaligned( |
|
367 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
368 |
((long) indexRO(bb, index)) + UNSAFE.getLong(bb, BUFFER_ADDRESS), |
|
369 |
value, |
|
370 |
handle.be); |
|
371 |
#end[floatingPoint] |
|
372 |
} |
|
373 |
||
374 |
@ForceInline |
|
375 |
static $type$ getVolatile(ByteBufferHandle handle, Object obb, int index) { |
|
376 |
ByteBuffer bb = (ByteBuffer) obb; |
|
377 |
return convEndian(handle.be, |
|
378 |
UNSAFE.get$RawType$Volatile( |
|
379 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
380 |
address(bb, index(bb, index)))); |
|
381 |
} |
|
382 |
||
383 |
@ForceInline |
|
384 |
static void setVolatile(ByteBufferHandle handle, Object obb, int index, $type$ value) { |
|
385 |
ByteBuffer bb = (ByteBuffer) obb; |
|
386 |
UNSAFE.put$RawType$Volatile( |
|
387 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
388 |
address(bb, indexRO(bb, index)), |
|
389 |
convEndian(handle.be, value)); |
|
390 |
} |
|
391 |
||
392 |
@ForceInline |
|
393 |
static $type$ getAcquire(ByteBufferHandle handle, Object obb, int index) { |
|
394 |
ByteBuffer bb = (ByteBuffer) obb; |
|
395 |
return convEndian(handle.be, |
|
396 |
UNSAFE.get$RawType$Acquire( |
|
397 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
398 |
address(bb, index(bb, index)))); |
|
399 |
} |
|
400 |
||
401 |
@ForceInline |
|
402 |
static void setRelease(ByteBufferHandle handle, Object obb, int index, $type$ value) { |
|
403 |
ByteBuffer bb = (ByteBuffer) obb; |
|
404 |
UNSAFE.put$RawType$Release( |
|
405 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
406 |
address(bb, indexRO(bb, index)), |
|
407 |
convEndian(handle.be, value)); |
|
408 |
} |
|
409 |
||
410 |
@ForceInline |
|
411 |
static $type$ getOpaque(ByteBufferHandle handle, Object obb, int index) { |
|
412 |
ByteBuffer bb = (ByteBuffer) obb; |
|
413 |
return convEndian(handle.be, |
|
414 |
UNSAFE.get$RawType$Opaque( |
|
415 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
416 |
address(bb, index(bb, index)))); |
|
417 |
} |
|
418 |
||
419 |
@ForceInline |
|
420 |
static void setOpaque(ByteBufferHandle handle, Object obb, int index, $type$ value) { |
|
421 |
ByteBuffer bb = (ByteBuffer) obb; |
|
422 |
UNSAFE.put$RawType$Opaque( |
|
423 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
424 |
address(bb, indexRO(bb, index)), |
|
425 |
convEndian(handle.be, value)); |
|
426 |
} |
|
427 |
#if[CAS] |
|
428 |
||
429 |
@ForceInline |
|
430 |
static boolean compareAndSet(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) { |
|
431 |
ByteBuffer bb = (ByteBuffer) obb; |
|
432 |
return UNSAFE.compareAndSwap$RawType$( |
|
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 |
|
39472
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38382
diff
changeset
|
439 |
static $type$ compareAndExchange(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) { |
36934 | 440 |
ByteBuffer bb = (ByteBuffer) obb; |
441 |
return convEndian(handle.be, |
|
442 |
UNSAFE.compareAndExchange$RawType$Volatile( |
|
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 $type$ compareAndExchangeAcquire(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) { |
|
450 |
ByteBuffer bb = (ByteBuffer) obb; |
|
451 |
return convEndian(handle.be, |
|
452 |
UNSAFE.compareAndExchange$RawType$Acquire( |
|
453 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
454 |
address(bb, indexRO(bb, index)), |
|
455 |
convEndian(handle.be, expected), convEndian(handle.be, value))); |
|
456 |
} |
|
457 |
||
458 |
@ForceInline |
|
459 |
static $type$ compareAndExchangeRelease(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) { |
|
460 |
ByteBuffer bb = (ByteBuffer) obb; |
|
461 |
return convEndian(handle.be, |
|
462 |
UNSAFE.compareAndExchange$RawType$Release( |
|
463 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
464 |
address(bb, indexRO(bb, index)), |
|
465 |
convEndian(handle.be, expected), convEndian(handle.be, value))); |
|
466 |
} |
|
467 |
||
468 |
@ForceInline |
|
469 |
static boolean weakCompareAndSet(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) { |
|
470 |
ByteBuffer bb = (ByteBuffer) obb; |
|
471 |
return UNSAFE.weakCompareAndSwap$RawType$( |
|
472 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
473 |
address(bb, indexRO(bb, index)), |
|
474 |
convEndian(handle.be, expected), convEndian(handle.be, value)); |
|
475 |
} |
|
476 |
||
477 |
@ForceInline |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
478 |
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
|
479 |
ByteBuffer bb = (ByteBuffer) obb; |
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38367
diff
changeset
|
480 |
return UNSAFE.weakCompareAndSwap$RawType$Volatile( |
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
481 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
482 |
address(bb, indexRO(bb, index)), |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
483 |
convEndian(handle.be, expected), convEndian(handle.be, value)); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
484 |
} |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
485 |
|
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
486 |
@ForceInline |
36934 | 487 |
static boolean weakCompareAndSetAcquire(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) { |
488 |
ByteBuffer bb = (ByteBuffer) obb; |
|
489 |
return UNSAFE.weakCompareAndSwap$RawType$Acquire( |
|
490 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
491 |
address(bb, indexRO(bb, index)), |
|
492 |
convEndian(handle.be, expected), convEndian(handle.be, value)); |
|
493 |
} |
|
494 |
||
495 |
@ForceInline |
|
496 |
static boolean weakCompareAndSetRelease(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) { |
|
497 |
ByteBuffer bb = (ByteBuffer) obb; |
|
498 |
return UNSAFE.weakCompareAndSwap$RawType$Release( |
|
499 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
500 |
address(bb, indexRO(bb, index)), |
|
501 |
convEndian(handle.be, expected), convEndian(handle.be, value)); |
|
502 |
} |
|
503 |
||
504 |
@ForceInline |
|
505 |
static $type$ getAndSet(ByteBufferHandle handle, Object obb, int index, $type$ value) { |
|
506 |
ByteBuffer bb = (ByteBuffer) obb; |
|
507 |
return convEndian(handle.be, |
|
508 |
UNSAFE.getAndSet$RawType$( |
|
509 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
|
510 |
address(bb, indexRO(bb, index)), |
|
511 |
convEndian(handle.be, value))); |
|
512 |
} |
|
513 |
#end[CAS] |
|
514 |
#if[AtomicAdd] |
|
515 |
||
516 |
@ForceInline |
|
38382
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
517 |
static $type$ getAndAdd(ByteBufferHandle handle, Object obb, int index, $type$ delta) { |
36934 | 518 |
ByteBuffer bb = (ByteBuffer) obb; |
38382
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
519 |
if (handle.be == BE) { |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
520 |
return UNSAFE.getAndAdd$RawType$( |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
521 |
UNSAFE.getObject(bb, BYTE_BUFFER_HB), |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
522 |
address(bb, indexRO(bb, index)), |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
523 |
delta); |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
524 |
} else { |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
525 |
return getAndAddConvEndianWithCAS(bb, index, delta); |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
526 |
} |
36934 | 527 |
} |
528 |
||
529 |
@ForceInline |
|
38382
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
530 |
static $type$ getAndAddConvEndianWithCAS(ByteBuffer bb, int index, $type$ delta) { |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
531 |
$type$ nativeExpectedValue, expectedValue; |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
532 |
Object base = UNSAFE.getObject(bb, BYTE_BUFFER_HB); |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
533 |
long offset = address(bb, indexRO(bb, index)); |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
534 |
do { |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
535 |
nativeExpectedValue = UNSAFE.get$RawType$Volatile(base, offset); |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
536 |
expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue); |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
537 |
} while (!UNSAFE.weakCompareAndSwap$RawType$Volatile(base, offset, |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
538 |
nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue + delta))); |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
539 |
return expectedValue; |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
540 |
} |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
541 |
|
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
542 |
@ForceInline |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
543 |
static $type$ addAndGet(ByteBufferHandle handle, Object obb, int index, $type$ delta) { |
98d5a441bc2f
8157152: Atomic add for VarHandle byte[]/ByteBuffer views is incorrect for endian conversion
psandoz
parents:
38372
diff
changeset
|
544 |
return getAndAdd(handle, obb, index, delta) + delta; |
36934 | 545 |
} |
546 |
#end[AtomicAdd] |
|
37792 | 547 |
|
548 |
static final VarForm FORM = new VarForm(ByteBufferHandle.class, ByteBuffer.class, $type$.class, int.class); |
|
36934 | 549 |
} |
550 |
} |