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 |
||
38356
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
27 |
import jdk.internal.util.Preconditions; |
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
28 |
import jdk.internal.vm.annotation.ForceInline; |
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
29 |
|
36934 | 30 |
import java.util.Objects; |
31 |
||
32 |
import static java.lang.invoke.MethodHandleStatics.UNSAFE; |
|
33 |
||
34 |
#warn |
|
35 |
||
36 |
final class VarHandle$Type$s { |
|
37 |
||
38 |
static class FieldInstanceReadOnly extends VarHandle { |
|
39 |
final long fieldOffset; |
|
40 |
final Class<?> receiverType; |
|
41 |
#if[Object] |
|
42 |
final Class<?> fieldType; |
|
43 |
#end[Object] |
|
44 |
||
45 |
FieldInstanceReadOnly(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType}) { |
|
46 |
this(receiverType, fieldOffset{#if[Object]?, fieldType}, FieldInstanceReadOnly.class); |
|
47 |
} |
|
48 |
||
49 |
protected FieldInstanceReadOnly(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType}, |
|
50 |
Class<? extends FieldInstanceReadOnly> handle) { |
|
51 |
super(VarForm.createFromStatic(handle), receiverType, {#if[Object]?fieldType:$type$.class}); |
|
52 |
this.fieldOffset = fieldOffset; |
|
53 |
this.receiverType = receiverType; |
|
54 |
#if[Object] |
|
55 |
this.fieldType = fieldType; |
|
56 |
#end[Object] |
|
57 |
} |
|
58 |
||
59 |
@ForceInline |
|
60 |
static $type$ get(FieldInstanceReadOnly handle, Object holder) { |
|
61 |
return UNSAFE.get$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)), |
|
62 |
handle.fieldOffset); |
|
63 |
} |
|
64 |
||
65 |
@ForceInline |
|
66 |
static $type$ getVolatile(FieldInstanceReadOnly handle, Object holder) { |
|
67 |
return UNSAFE.get$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)), |
|
68 |
handle.fieldOffset); |
|
69 |
} |
|
70 |
||
71 |
@ForceInline |
|
72 |
static $type$ getOpaque(FieldInstanceReadOnly handle, Object holder) { |
|
73 |
return UNSAFE.get$Type$Opaque(Objects.requireNonNull(handle.receiverType.cast(holder)), |
|
74 |
handle.fieldOffset); |
|
75 |
} |
|
76 |
||
77 |
@ForceInline |
|
78 |
static $type$ getAcquire(FieldInstanceReadOnly handle, Object holder) { |
|
79 |
return UNSAFE.get$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)), |
|
80 |
handle.fieldOffset); |
|
81 |
} |
|
82 |
} |
|
83 |
||
84 |
static class FieldInstanceReadWrite extends FieldInstanceReadOnly { |
|
85 |
||
86 |
FieldInstanceReadWrite(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType}) { |
|
87 |
super(receiverType, fieldOffset{#if[Object]?, fieldType}, FieldInstanceReadWrite.class); |
|
88 |
} |
|
89 |
||
90 |
@ForceInline |
|
91 |
static void set(FieldInstanceReadWrite handle, Object holder, $type$ value) { |
|
92 |
UNSAFE.put$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)), |
|
93 |
handle.fieldOffset, |
|
94 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
95 |
} |
|
96 |
||
97 |
@ForceInline |
|
98 |
static void setVolatile(FieldInstanceReadWrite handle, Object holder, $type$ value) { |
|
99 |
UNSAFE.put$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)), |
|
100 |
handle.fieldOffset, |
|
101 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
102 |
} |
|
103 |
||
104 |
@ForceInline |
|
105 |
static void setOpaque(FieldInstanceReadWrite handle, Object holder, $type$ value) { |
|
106 |
UNSAFE.put$Type$Opaque(Objects.requireNonNull(handle.receiverType.cast(holder)), |
|
107 |
handle.fieldOffset, |
|
108 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
109 |
} |
|
110 |
||
111 |
@ForceInline |
|
112 |
static void setRelease(FieldInstanceReadWrite handle, Object holder, $type$ value) { |
|
113 |
UNSAFE.put$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)), |
|
114 |
handle.fieldOffset, |
|
115 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
116 |
} |
|
117 |
#if[CAS] |
|
118 |
||
119 |
@ForceInline |
|
120 |
static boolean compareAndSet(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) { |
|
121 |
return UNSAFE.compareAndSwap$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)), |
|
122 |
handle.fieldOffset, |
|
123 |
{#if[Object]?handle.fieldType.cast(expected):expected}, |
|
124 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
125 |
} |
|
126 |
||
127 |
@ForceInline |
|
128 |
static $type$ compareAndExchangeVolatile(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) { |
|
129 |
return UNSAFE.compareAndExchange$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)), |
|
130 |
handle.fieldOffset, |
|
131 |
{#if[Object]?handle.fieldType.cast(expected):expected}, |
|
132 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
133 |
} |
|
134 |
||
135 |
@ForceInline |
|
136 |
static $type$ compareAndExchangeAcquire(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) { |
|
137 |
return UNSAFE.compareAndExchange$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)), |
|
138 |
handle.fieldOffset, |
|
139 |
{#if[Object]?handle.fieldType.cast(expected):expected}, |
|
140 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
141 |
} |
|
142 |
||
143 |
@ForceInline |
|
144 |
static $type$ compareAndExchangeRelease(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) { |
|
145 |
return UNSAFE.compareAndExchange$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)), |
|
146 |
handle.fieldOffset, |
|
147 |
{#if[Object]?handle.fieldType.cast(expected):expected}, |
|
148 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
149 |
} |
|
150 |
||
151 |
@ForceInline |
|
152 |
static boolean weakCompareAndSet(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) { |
|
153 |
return UNSAFE.weakCompareAndSwap$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)), |
|
154 |
handle.fieldOffset, |
|
155 |
{#if[Object]?handle.fieldType.cast(expected):expected}, |
|
156 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
157 |
} |
|
158 |
||
159 |
@ForceInline |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
160 |
static boolean weakCompareAndSetVolatile(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) { |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
161 |
// 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
|
162 |
return UNSAFE.compareAndSwap$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)), |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
163 |
handle.fieldOffset, |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
164 |
{#if[Object]?handle.fieldType.cast(expected):expected}, |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
165 |
{#if[Object]?handle.fieldType.cast(value):value}); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
166 |
} |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
167 |
|
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
168 |
@ForceInline |
36934 | 169 |
static boolean weakCompareAndSetAcquire(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) { |
170 |
return UNSAFE.weakCompareAndSwap$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)), |
|
171 |
handle.fieldOffset, |
|
172 |
{#if[Object]?handle.fieldType.cast(expected):expected}, |
|
173 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
174 |
} |
|
175 |
||
176 |
@ForceInline |
|
177 |
static boolean weakCompareAndSetRelease(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) { |
|
178 |
return UNSAFE.weakCompareAndSwap$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)), |
|
179 |
handle.fieldOffset, |
|
180 |
{#if[Object]?handle.fieldType.cast(expected):expected}, |
|
181 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
182 |
} |
|
183 |
||
184 |
@ForceInline |
|
185 |
static $type$ getAndSet(FieldInstanceReadWrite handle, Object holder, $type$ value) { |
|
186 |
return UNSAFE.getAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)), |
|
187 |
handle.fieldOffset, |
|
188 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
189 |
} |
|
190 |
#end[CAS] |
|
191 |
#if[AtomicAdd] |
|
192 |
||
193 |
@ForceInline |
|
194 |
static $type$ getAndAdd(FieldInstanceReadWrite handle, Object holder, $type$ value) { |
|
195 |
return UNSAFE.getAndAdd$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)), |
|
196 |
handle.fieldOffset, |
|
197 |
value); |
|
198 |
} |
|
199 |
||
200 |
@ForceInline |
|
201 |
static $type$ addAndGet(FieldInstanceReadWrite handle, Object holder, $type$ value) { |
|
202 |
return UNSAFE.getAndAdd$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)), |
|
203 |
handle.fieldOffset, |
|
204 |
value) + value; |
|
205 |
} |
|
206 |
#end[AtomicAdd] |
|
207 |
} |
|
208 |
||
209 |
||
210 |
static class FieldStaticReadOnly extends VarHandle { |
|
211 |
final Object base; |
|
212 |
final long fieldOffset; |
|
213 |
#if[Object] |
|
214 |
final Class<?> fieldType; |
|
215 |
#end[Object] |
|
216 |
||
217 |
FieldStaticReadOnly(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType}) { |
|
218 |
this(base, fieldOffset{#if[Object]?, fieldType}, FieldStaticReadOnly.class); |
|
219 |
} |
|
220 |
||
221 |
protected FieldStaticReadOnly(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType}, |
|
222 |
Class<? extends FieldStaticReadOnly> handle) { |
|
223 |
super(VarForm.createFromStatic(handle), null, {#if[Object]?fieldType:$type$.class}); |
|
224 |
this.base = base; |
|
225 |
this.fieldOffset = fieldOffset; |
|
226 |
#if[Object] |
|
227 |
this.fieldType = fieldType; |
|
228 |
#end[Object] |
|
229 |
} |
|
230 |
||
231 |
@ForceInline |
|
232 |
static $type$ get(FieldStaticReadOnly handle) { |
|
233 |
return UNSAFE.get$Type$(handle.base, |
|
234 |
handle.fieldOffset); |
|
235 |
} |
|
236 |
||
237 |
@ForceInline |
|
238 |
static $type$ getVolatile(FieldStaticReadOnly handle) { |
|
239 |
return UNSAFE.get$Type$Volatile(handle.base, |
|
240 |
handle.fieldOffset); |
|
241 |
} |
|
242 |
||
243 |
@ForceInline |
|
244 |
static $type$ getOpaque(FieldStaticReadOnly handle) { |
|
245 |
return UNSAFE.get$Type$Opaque(handle.base, |
|
246 |
handle.fieldOffset); |
|
247 |
} |
|
248 |
||
249 |
@ForceInline |
|
250 |
static $type$ getAcquire(FieldStaticReadOnly handle) { |
|
251 |
return UNSAFE.get$Type$Acquire(handle.base, |
|
252 |
handle.fieldOffset); |
|
253 |
} |
|
254 |
} |
|
255 |
||
256 |
static class FieldStaticReadWrite extends FieldStaticReadOnly { |
|
257 |
||
258 |
FieldStaticReadWrite(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType}) { |
|
259 |
super(base, fieldOffset{#if[Object]?, fieldType}, FieldStaticReadWrite.class); |
|
260 |
} |
|
261 |
||
262 |
@ForceInline |
|
263 |
static void set(FieldStaticReadWrite handle, $type$ value) { |
|
264 |
UNSAFE.put$Type$(handle.base, |
|
265 |
handle.fieldOffset, |
|
266 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
267 |
} |
|
268 |
||
269 |
@ForceInline |
|
270 |
static void setVolatile(FieldStaticReadWrite handle, $type$ value) { |
|
271 |
UNSAFE.put$Type$Volatile(handle.base, |
|
272 |
handle.fieldOffset, |
|
273 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
274 |
} |
|
275 |
||
276 |
@ForceInline |
|
277 |
static void setOpaque(FieldStaticReadWrite handle, $type$ value) { |
|
278 |
UNSAFE.put$Type$Opaque(handle.base, |
|
279 |
handle.fieldOffset, |
|
280 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
281 |
} |
|
282 |
||
283 |
@ForceInline |
|
284 |
static void setRelease(FieldStaticReadWrite handle, $type$ value) { |
|
285 |
UNSAFE.put$Type$Release(handle.base, |
|
286 |
handle.fieldOffset, |
|
287 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
288 |
} |
|
289 |
#if[CAS] |
|
290 |
||
291 |
@ForceInline |
|
292 |
static boolean compareAndSet(FieldStaticReadWrite handle, $type$ expected, $type$ value) { |
|
293 |
return UNSAFE.compareAndSwap$Type$(handle.base, |
|
294 |
handle.fieldOffset, |
|
295 |
{#if[Object]?handle.fieldType.cast(expected):expected}, |
|
296 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
297 |
} |
|
298 |
||
299 |
||
300 |
@ForceInline |
|
301 |
static $type$ compareAndExchangeVolatile(FieldStaticReadWrite handle, $type$ expected, $type$ value) { |
|
302 |
return UNSAFE.compareAndExchange$Type$Volatile(handle.base, |
|
303 |
handle.fieldOffset, |
|
304 |
{#if[Object]?handle.fieldType.cast(expected):expected}, |
|
305 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
306 |
} |
|
307 |
||
308 |
@ForceInline |
|
309 |
static $type$ compareAndExchangeAcquire(FieldStaticReadWrite handle, $type$ expected, $type$ value) { |
|
310 |
return UNSAFE.compareAndExchange$Type$Acquire(handle.base, |
|
311 |
handle.fieldOffset, |
|
312 |
{#if[Object]?handle.fieldType.cast(expected):expected}, |
|
313 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
314 |
} |
|
315 |
||
316 |
@ForceInline |
|
317 |
static $type$ compareAndExchangeRelease(FieldStaticReadWrite handle, $type$ expected, $type$ value) { |
|
318 |
return UNSAFE.compareAndExchange$Type$Release(handle.base, |
|
319 |
handle.fieldOffset, |
|
320 |
{#if[Object]?handle.fieldType.cast(expected):expected}, |
|
321 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
322 |
} |
|
323 |
||
324 |
@ForceInline |
|
325 |
static boolean weakCompareAndSet(FieldStaticReadWrite handle, $type$ expected, $type$ value) { |
|
326 |
return UNSAFE.weakCompareAndSwap$Type$(handle.base, |
|
327 |
handle.fieldOffset, |
|
328 |
{#if[Object]?handle.fieldType.cast(expected):expected}, |
|
329 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
330 |
} |
|
331 |
||
332 |
@ForceInline |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
333 |
static boolean weakCompareAndSetVolatile(FieldStaticReadWrite handle, $type$ expected, $type$ value) { |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
334 |
// 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
|
335 |
return UNSAFE.compareAndSwap$Type$(handle.base, |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
336 |
handle.fieldOffset, |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
337 |
{#if[Object]?handle.fieldType.cast(expected):expected}, |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
338 |
{#if[Object]?handle.fieldType.cast(value):value}); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
339 |
} |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
340 |
|
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
341 |
@ForceInline |
36934 | 342 |
static boolean weakCompareAndSetAcquire(FieldStaticReadWrite handle, $type$ expected, $type$ value) { |
343 |
return UNSAFE.weakCompareAndSwap$Type$Acquire(handle.base, |
|
344 |
handle.fieldOffset, |
|
345 |
{#if[Object]?handle.fieldType.cast(expected):expected}, |
|
346 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
347 |
} |
|
348 |
||
349 |
@ForceInline |
|
350 |
static boolean weakCompareAndSetRelease(FieldStaticReadWrite handle, $type$ expected, $type$ value) { |
|
351 |
return UNSAFE.weakCompareAndSwap$Type$Release(handle.base, |
|
352 |
handle.fieldOffset, |
|
353 |
{#if[Object]?handle.fieldType.cast(expected):expected}, |
|
354 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
355 |
} |
|
356 |
||
357 |
@ForceInline |
|
358 |
static $type$ getAndSet(FieldStaticReadWrite handle, $type$ value) { |
|
359 |
return UNSAFE.getAndSet$Type$(handle.base, |
|
360 |
handle.fieldOffset, |
|
361 |
{#if[Object]?handle.fieldType.cast(value):value}); |
|
362 |
} |
|
363 |
#end[CAS] |
|
364 |
#if[AtomicAdd] |
|
365 |
||
366 |
@ForceInline |
|
367 |
static $type$ getAndAdd(FieldStaticReadWrite handle, $type$ value) { |
|
368 |
return UNSAFE.getAndAdd$Type$(handle.base, |
|
369 |
handle.fieldOffset, |
|
370 |
value); |
|
371 |
} |
|
372 |
||
373 |
@ForceInline |
|
374 |
static $type$ addAndGet(FieldStaticReadWrite handle, $type$ value) { |
|
375 |
return UNSAFE.getAndAdd$Type$(handle.base, |
|
376 |
handle.fieldOffset, |
|
377 |
value) + value; |
|
378 |
} |
|
379 |
#end[AtomicAdd] |
|
380 |
} |
|
381 |
||
382 |
||
383 |
static final class Array extends VarHandle { |
|
384 |
final int abase; |
|
385 |
final int ashift; |
|
386 |
#if[Object] |
|
387 |
final Class<{#if[Object]??:$type$[]}> arrayType; |
|
388 |
final Class<?> componentType; |
|
389 |
#end[Object] |
|
390 |
||
391 |
Array(int abase, int ashift{#if[Object]?, Class<?> arrayType}) { |
|
392 |
super(VarForm.createFromStatic(Array.class), |
|
393 |
{#if[Object]?arrayType:$type$[].class}, {#if[Object]?arrayType.getComponentType():$type$.class}, int.class); |
|
394 |
this.abase = abase; |
|
395 |
this.ashift = ashift; |
|
396 |
#if[Object] |
|
397 |
this.arrayType = {#if[Object]?arrayType:$type$[].class}; |
|
398 |
this.componentType = arrayType.getComponentType(); |
|
399 |
#end[Object] |
|
400 |
} |
|
401 |
||
402 |
@ForceInline |
|
403 |
static $type$ get(Array handle, Object oarray, int index) { |
|
404 |
#if[Object] |
|
405 |
Object[] array = (Object[]) handle.arrayType.cast(oarray); |
|
406 |
#else[Object] |
|
407 |
$type$[] array = ($type$[]) oarray; |
|
408 |
#end[Object] |
|
409 |
return array[index]; |
|
410 |
} |
|
411 |
||
412 |
@ForceInline |
|
413 |
static void set(Array handle, Object oarray, int index, $type$ value) { |
|
414 |
#if[Object] |
|
415 |
Object[] array = (Object[]) handle.arrayType.cast(oarray); |
|
416 |
#else[Object] |
|
417 |
$type$[] array = ($type$[]) oarray; |
|
418 |
#end[Object] |
|
419 |
array[index] = {#if[Object]?handle.componentType.cast(value):value}; |
|
420 |
} |
|
421 |
||
422 |
@ForceInline |
|
423 |
static $type$ getVolatile(Array handle, Object oarray, int index) { |
|
424 |
#if[Object] |
|
425 |
Object[] array = (Object[]) handle.arrayType.cast(oarray); |
|
426 |
#else[Object] |
|
427 |
$type$[] array = ($type$[]) oarray; |
|
428 |
#end[Object] |
|
429 |
return UNSAFE.get$Type$Volatile(array, |
|
38356
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
430 |
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase); |
36934 | 431 |
} |
432 |
||
433 |
@ForceInline |
|
434 |
static void setVolatile(Array handle, Object oarray, int index, $type$ value) { |
|
435 |
#if[Object] |
|
436 |
Object[] array = (Object[]) handle.arrayType.cast(oarray); |
|
437 |
#else[Object] |
|
438 |
$type$[] array = ($type$[]) oarray; |
|
439 |
#end[Object] |
|
440 |
UNSAFE.put$Type$Volatile(array, |
|
38356
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
441 |
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase, |
36934 | 442 |
{#if[Object]?handle.componentType.cast(value):value}); |
443 |
} |
|
444 |
||
445 |
@ForceInline |
|
446 |
static $type$ getOpaque(Array handle, Object oarray, int index) { |
|
447 |
#if[Object] |
|
448 |
Object[] array = (Object[]) handle.arrayType.cast(oarray); |
|
449 |
#else[Object] |
|
450 |
$type$[] array = ($type$[]) oarray; |
|
451 |
#end[Object] |
|
452 |
return UNSAFE.get$Type$Opaque(array, |
|
38356
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
453 |
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase); |
36934 | 454 |
} |
455 |
||
456 |
@ForceInline |
|
457 |
static void setOpaque(Array handle, Object oarray, int index, $type$ value) { |
|
458 |
#if[Object] |
|
459 |
Object[] array = (Object[]) handle.arrayType.cast(oarray); |
|
460 |
#else[Object] |
|
461 |
$type$[] array = ($type$[]) oarray; |
|
462 |
#end[Object] |
|
463 |
UNSAFE.put$Type$Opaque(array, |
|
38356
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
464 |
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase, |
36934 | 465 |
{#if[Object]?handle.componentType.cast(value):value}); |
466 |
} |
|
467 |
||
468 |
@ForceInline |
|
469 |
static $type$ getAcquire(Array handle, Object oarray, int index) { |
|
470 |
#if[Object] |
|
471 |
Object[] array = (Object[]) handle.arrayType.cast(oarray); |
|
472 |
#else[Object] |
|
473 |
$type$[] array = ($type$[]) oarray; |
|
474 |
#end[Object] |
|
475 |
return UNSAFE.get$Type$Acquire(array, |
|
38356
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
476 |
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase); |
36934 | 477 |
} |
478 |
||
479 |
@ForceInline |
|
480 |
static void setRelease(Array handle, Object oarray, int index, $type$ value) { |
|
481 |
#if[Object] |
|
482 |
Object[] array = (Object[]) handle.arrayType.cast(oarray); |
|
483 |
#else[Object] |
|
484 |
$type$[] array = ($type$[]) oarray; |
|
485 |
#end[Object] |
|
486 |
UNSAFE.put$Type$Release(array, |
|
38356
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
487 |
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase, |
36934 | 488 |
{#if[Object]?handle.componentType.cast(value):value}); |
489 |
} |
|
490 |
#if[CAS] |
|
491 |
||
492 |
@ForceInline |
|
493 |
static boolean compareAndSet(Array handle, Object oarray, int index, $type$ expected, $type$ value) { |
|
494 |
#if[Object] |
|
495 |
Object[] array = (Object[]) handle.arrayType.cast(oarray); |
|
496 |
#else[Object] |
|
497 |
$type$[] array = ($type$[]) oarray; |
|
498 |
#end[Object] |
|
499 |
return UNSAFE.compareAndSwap$Type$(array, |
|
38356
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
500 |
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase, |
36934 | 501 |
{#if[Object]?handle.componentType.cast(expected):expected}, |
502 |
{#if[Object]?handle.componentType.cast(value):value}); |
|
503 |
} |
|
504 |
||
505 |
@ForceInline |
|
506 |
static $type$ compareAndExchangeVolatile(Array handle, Object oarray, int index, $type$ expected, $type$ value) { |
|
507 |
#if[Object] |
|
508 |
Object[] array = (Object[]) handle.arrayType.cast(oarray); |
|
509 |
#else[Object] |
|
510 |
$type$[] array = ($type$[]) oarray; |
|
511 |
#end[Object] |
|
512 |
return UNSAFE.compareAndExchange$Type$Volatile(array, |
|
38356
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
513 |
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase, |
36934 | 514 |
{#if[Object]?handle.componentType.cast(expected):expected}, |
515 |
{#if[Object]?handle.componentType.cast(value):value}); |
|
516 |
} |
|
517 |
||
518 |
@ForceInline |
|
519 |
static $type$ compareAndExchangeAcquire(Array handle, Object oarray, int index, $type$ expected, $type$ value) { |
|
520 |
#if[Object] |
|
521 |
Object[] array = (Object[]) handle.arrayType.cast(oarray); |
|
522 |
#else[Object] |
|
523 |
$type$[] array = ($type$[]) oarray; |
|
524 |
#end[Object] |
|
525 |
return UNSAFE.compareAndExchange$Type$Acquire(array, |
|
38356
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
526 |
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase, |
36934 | 527 |
{#if[Object]?handle.componentType.cast(expected):expected}, |
528 |
{#if[Object]?handle.componentType.cast(value):value}); |
|
529 |
} |
|
530 |
||
531 |
@ForceInline |
|
532 |
static $type$ compareAndExchangeRelease(Array handle, Object oarray, int index, $type$ expected, $type$ value) { |
|
533 |
#if[Object] |
|
534 |
Object[] array = (Object[]) handle.arrayType.cast(oarray); |
|
535 |
#else[Object] |
|
536 |
$type$[] array = ($type$[]) oarray; |
|
537 |
#end[Object] |
|
538 |
return UNSAFE.compareAndExchange$Type$Release(array, |
|
38356
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
539 |
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase, |
36934 | 540 |
{#if[Object]?handle.componentType.cast(expected):expected}, |
541 |
{#if[Object]?handle.componentType.cast(value):value}); |
|
542 |
} |
|
543 |
||
544 |
@ForceInline |
|
545 |
static boolean weakCompareAndSet(Array handle, Object oarray, int index, $type$ expected, $type$ value) { |
|
546 |
#if[Object] |
|
547 |
Object[] array = (Object[]) handle.arrayType.cast(oarray); |
|
548 |
#else[Object] |
|
549 |
$type$[] array = ($type$[]) oarray; |
|
550 |
#end[Object] |
|
551 |
return UNSAFE.weakCompareAndSwap$Type$(array, |
|
38356
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
552 |
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase, |
36934 | 553 |
{#if[Object]?handle.componentType.cast(expected):expected}, |
554 |
{#if[Object]?handle.componentType.cast(value):value}); |
|
555 |
} |
|
556 |
||
557 |
@ForceInline |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
558 |
static boolean weakCompareAndSetVolatile(Array handle, Object oarray, int index, $type$ expected, $type$ value) { |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
559 |
#if[Object] |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
560 |
Object[] array = (Object[]) handle.arrayType.cast(oarray); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
561 |
#else[Object] |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
562 |
$type$[] array = ($type$[]) oarray; |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
563 |
#end[Object] |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
564 |
// 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
|
565 |
return UNSAFE.compareAndSwap$Type$(array, |
38358 | 566 |
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase, |
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
567 |
{#if[Object]?handle.componentType.cast(expected):expected}, |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
568 |
{#if[Object]?handle.componentType.cast(value):value}); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
569 |
} |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
570 |
|
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
36934
diff
changeset
|
571 |
@ForceInline |
36934 | 572 |
static boolean weakCompareAndSetAcquire(Array handle, Object oarray, int index, $type$ expected, $type$ value) { |
573 |
#if[Object] |
|
574 |
Object[] array = (Object[]) handle.arrayType.cast(oarray); |
|
575 |
#else[Object] |
|
576 |
$type$[] array = ($type$[]) oarray; |
|
577 |
#end[Object] |
|
578 |
return UNSAFE.weakCompareAndSwap$Type$Acquire(array, |
|
38356
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
579 |
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase, |
36934 | 580 |
{#if[Object]?handle.componentType.cast(expected):expected}, |
581 |
{#if[Object]?handle.componentType.cast(value):value}); |
|
582 |
} |
|
583 |
||
584 |
@ForceInline |
|
585 |
static boolean weakCompareAndSetRelease(Array handle, Object oarray, int index, $type$ expected, $type$ value) { |
|
586 |
#if[Object] |
|
587 |
Object[] array = (Object[]) handle.arrayType.cast(oarray); |
|
588 |
#else[Object] |
|
589 |
$type$[] array = ($type$[]) oarray; |
|
590 |
#end[Object] |
|
591 |
return UNSAFE.weakCompareAndSwap$Type$Release(array, |
|
38356
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
592 |
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase, |
36934 | 593 |
{#if[Object]?handle.componentType.cast(expected):expected}, |
594 |
{#if[Object]?handle.componentType.cast(value):value}); |
|
595 |
} |
|
596 |
||
597 |
@ForceInline |
|
598 |
static $type$ getAndSet(Array handle, Object oarray, int index, $type$ value) { |
|
599 |
#if[Object] |
|
600 |
Object[] array = (Object[]) handle.arrayType.cast(oarray); |
|
601 |
#else[Object] |
|
602 |
$type$[] array = ($type$[]) oarray; |
|
603 |
#end[Object] |
|
604 |
return UNSAFE.getAndSet$Type$(array, |
|
38356
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
605 |
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase, |
36934 | 606 |
{#if[Object]?handle.componentType.cast(value):value}); |
607 |
} |
|
608 |
#end[CAS] |
|
609 |
#if[AtomicAdd] |
|
610 |
||
611 |
@ForceInline |
|
612 |
static $type$ getAndAdd(Array handle, Object oarray, int index, $type$ value) { |
|
613 |
#if[Object] |
|
614 |
Object[] array = (Object[]) handle.arrayType.cast(oarray); |
|
615 |
#else[Object] |
|
616 |
$type$[] array = ($type$[]) oarray; |
|
617 |
#end[Object] |
|
618 |
return UNSAFE.getAndAdd$Type$(array, |
|
38356
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
619 |
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase, |
36934 | 620 |
value); |
621 |
} |
|
622 |
||
623 |
@ForceInline |
|
624 |
static $type$ addAndGet(Array handle, Object oarray, int index, $type$ value) { |
|
625 |
#if[Object] |
|
626 |
Object[] array = (Object[]) handle.arrayType.cast(oarray); |
|
627 |
#else[Object] |
|
628 |
$type$[] array = ($type$[]) oarray; |
|
629 |
#end[Object] |
|
630 |
return UNSAFE.getAndAdd$Type$(array, |
|
38356
1e4ecca97792
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents:
36934
diff
changeset
|
631 |
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase, |
36934 | 632 |
value) + value; |
633 |
} |
|
634 |
#end[AtomicAdd] |
|
635 |
} |
|
636 |
} |