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.util.Preconditions;
28 import jdk.internal.vm.annotation.ForceInline;
29
30 import java.lang.invoke.VarHandle.VarHandleDesc;
31 import java.util.Objects;
32 import java.util.Optional;
33
34 import static java.lang.invoke.MethodHandleStatics.UNSAFE;
35
36 #warn
37
38 final class VarHandle$Type$s {
39
40 static sealed class FieldInstanceReadOnly extends VarHandle {
41 final long fieldOffset;
42 final Class<?> receiverType;
43 #if[Object]
44 final Class<?> fieldType;
45 #end[Object]
46
47 FieldInstanceReadOnly(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
48 this(receiverType, fieldOffset{#if[Object]?, fieldType}, FieldInstanceReadOnly.FORM, false);
49 }
50
51 protected FieldInstanceReadOnly(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType},
52 VarForm form, boolean exact) {
53 super(form, exact);
54 this.fieldOffset = fieldOffset;
55 this.receiverType = receiverType;
56 #if[Object]
57 this.fieldType = fieldType;
58 #end[Object]
59 }
60
61 @Override
62 public FieldInstanceReadOnly withInvokeExactBehavior() {
63 return hasInvokeExactBehavior()
64 ? this
65 : new FieldInstanceReadOnly(receiverType, fieldOffset{#if[Object]?, fieldType}, vform, true);
66 }
67
68 @Override
69 public FieldInstanceReadOnly withInvokeBehavior() {
70 return !hasInvokeExactBehavior()
71 ? this
72 : new FieldInstanceReadOnly(receiverType, fieldOffset{#if[Object]?, fieldType}, vform, false);
73 }
74
75 @Override
76 final MethodType accessModeTypeUncached(AccessType at) {
77 return at.accessModeType(receiverType, {#if[Object]?fieldType:$type$.class});
78 }
79
80 @Override
81 public Optional<VarHandleDesc> describeConstable() {
82 var receiverTypeRef = receiverType.describeConstable();
83 var fieldTypeRef = {#if[Object]?fieldType:$type$.class}.describeConstable();
84 if (!receiverTypeRef.isPresent() || !fieldTypeRef.isPresent())
85 return Optional.empty();
86
87 // Reflect on this VarHandle to extract the field name
88 String name = VarHandles.getFieldFromReceiverAndOffset(
89 receiverType, fieldOffset, {#if[Object]?fieldType:$type$.class}).getName();
90 return Optional.of(VarHandleDesc.ofField(receiverTypeRef.get(), name, fieldTypeRef.get()));
91 }
92
93 @ForceInline
94 static $type$ get(VarHandle ob, Object holder) {
95 FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
96 return UNSAFE.get$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
97 handle.fieldOffset);
98 }
99
100 @ForceInline
101 static $type$ getVolatile(VarHandle ob, Object holder) {
102 FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
103 return UNSAFE.get$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)),
104 handle.fieldOffset);
105 }
106
107 @ForceInline
108 static $type$ getOpaque(VarHandle ob, Object holder) {
109 FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
110 return UNSAFE.get$Type$Opaque(Objects.requireNonNull(handle.receiverType.cast(holder)),
111 handle.fieldOffset);
112 }
113
114 @ForceInline
115 static $type$ getAcquire(VarHandle ob, Object holder) {
116 FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
117 return UNSAFE.get$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
118 handle.fieldOffset);
119 }
120
121 static final VarForm FORM = new VarForm(FieldInstanceReadOnly.class, Object.class, $type$.class);
122 }
123
124 static final class FieldInstanceReadWrite extends FieldInstanceReadOnly {
125
126 FieldInstanceReadWrite(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
127 this(receiverType, fieldOffset{#if[Object]?, fieldType}, false);
128 }
129
130 private FieldInstanceReadWrite(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType},
131 boolean exact) {
132 super(receiverType, fieldOffset{#if[Object]?, fieldType}, FieldInstanceReadWrite.FORM, exact);
133 }
134
135 @Override
136 public FieldInstanceReadWrite withInvokeExactBehavior() {
137 return hasInvokeExactBehavior()
138 ? this
139 : new FieldInstanceReadWrite(receiverType, fieldOffset{#if[Object]?, fieldType}, true);
140 }
141
142 @Override
143 public FieldInstanceReadWrite withInvokeBehavior() {
144 return !hasInvokeExactBehavior()
145 ? this
146 : new FieldInstanceReadWrite(receiverType, fieldOffset{#if[Object]?, fieldType}, false);
147 }
148
149 @ForceInline
150 static void set(VarHandle ob, Object holder, $type$ value) {
151 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
152 UNSAFE.put$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
153 handle.fieldOffset,
154 {#if[Object]?handle.fieldType.cast(value):value});
155 }
156
157 @ForceInline
158 static void setVolatile(VarHandle ob, Object holder, $type$ value) {
159 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
160 UNSAFE.put$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)),
161 handle.fieldOffset,
162 {#if[Object]?handle.fieldType.cast(value):value});
163 }
164
165 @ForceInline
166 static void setOpaque(VarHandle ob, Object holder, $type$ value) {
167 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
168 UNSAFE.put$Type$Opaque(Objects.requireNonNull(handle.receiverType.cast(holder)),
169 handle.fieldOffset,
170 {#if[Object]?handle.fieldType.cast(value):value});
171 }
172
173 @ForceInline
174 static void setRelease(VarHandle ob, Object holder, $type$ value) {
175 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
176 UNSAFE.put$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
177 handle.fieldOffset,
178 {#if[Object]?handle.fieldType.cast(value):value});
179 }
180 #if[CAS]
181
182 @ForceInline
183 static boolean compareAndSet(VarHandle ob, Object holder, $type$ expected, $type$ value) {
184 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
185 return UNSAFE.compareAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
186 handle.fieldOffset,
187 {#if[Object]?handle.fieldType.cast(expected):expected},
188 {#if[Object]?handle.fieldType.cast(value):value});
189 }
190
191 @ForceInline
192 static $type$ compareAndExchange(VarHandle ob, Object holder, $type$ expected, $type$ value) {
193 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
194 return UNSAFE.compareAndExchange$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
195 handle.fieldOffset,
196 {#if[Object]?handle.fieldType.cast(expected):expected},
197 {#if[Object]?handle.fieldType.cast(value):value});
198 }
199
200 @ForceInline
201 static $type$ compareAndExchangeAcquire(VarHandle ob, Object holder, $type$ expected, $type$ value) {
202 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
203 return UNSAFE.compareAndExchange$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
204 handle.fieldOffset,
205 {#if[Object]?handle.fieldType.cast(expected):expected},
206 {#if[Object]?handle.fieldType.cast(value):value});
207 }
208
209 @ForceInline
210 static $type$ compareAndExchangeRelease(VarHandle ob, Object holder, $type$ expected, $type$ value) {
211 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
212 return UNSAFE.compareAndExchange$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
213 handle.fieldOffset,
214 {#if[Object]?handle.fieldType.cast(expected):expected},
215 {#if[Object]?handle.fieldType.cast(value):value});
216 }
217
218 @ForceInline
219 static boolean weakCompareAndSetPlain(VarHandle ob, Object holder, $type$ expected, $type$ value) {
220 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
221 return UNSAFE.weakCompareAndSet$Type$Plain(Objects.requireNonNull(handle.receiverType.cast(holder)),
222 handle.fieldOffset,
223 {#if[Object]?handle.fieldType.cast(expected):expected},
224 {#if[Object]?handle.fieldType.cast(value):value});
225 }
226
227 @ForceInline
228 static boolean weakCompareAndSet(VarHandle ob, Object holder, $type$ expected, $type$ value) {
229 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
230 return UNSAFE.weakCompareAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
231 handle.fieldOffset,
232 {#if[Object]?handle.fieldType.cast(expected):expected},
233 {#if[Object]?handle.fieldType.cast(value):value});
234 }
235
236 @ForceInline
237 static boolean weakCompareAndSetAcquire(VarHandle ob, Object holder, $type$ expected, $type$ value) {
238 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
239 return UNSAFE.weakCompareAndSet$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
240 handle.fieldOffset,
241 {#if[Object]?handle.fieldType.cast(expected):expected},
242 {#if[Object]?handle.fieldType.cast(value):value});
243 }
244
245 @ForceInline
246 static boolean weakCompareAndSetRelease(VarHandle ob, Object holder, $type$ expected, $type$ value) {
247 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
248 return UNSAFE.weakCompareAndSet$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
249 handle.fieldOffset,
250 {#if[Object]?handle.fieldType.cast(expected):expected},
251 {#if[Object]?handle.fieldType.cast(value):value});
252 }
253
254 @ForceInline
255 static $type$ getAndSet(VarHandle ob, Object holder, $type$ value) {
256 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
257 return UNSAFE.getAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
258 handle.fieldOffset,
259 {#if[Object]?handle.fieldType.cast(value):value});
260 }
261
262 @ForceInline
263 static $type$ getAndSetAcquire(VarHandle ob, Object holder, $type$ value) {
264 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
265 return UNSAFE.getAndSet$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
266 handle.fieldOffset,
267 {#if[Object]?handle.fieldType.cast(value):value});
268 }
269
270 @ForceInline
271 static $type$ getAndSetRelease(VarHandle ob, Object holder, $type$ value) {
272 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
273 return UNSAFE.getAndSet$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
274 handle.fieldOffset,
275 {#if[Object]?handle.fieldType.cast(value):value});
276 }
277 #end[CAS]
278 #if[AtomicAdd]
279
280 @ForceInline
281 static $type$ getAndAdd(VarHandle ob, Object holder, $type$ value) {
282 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
283 return UNSAFE.getAndAdd$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
284 handle.fieldOffset,
285 value);
286 }
287
288 @ForceInline
289 static $type$ getAndAddAcquire(VarHandle ob, Object holder, $type$ value) {
290 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
291 return UNSAFE.getAndAdd$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
292 handle.fieldOffset,
293 value);
294 }
295
370
371 @ForceInline
372 static $type$ getAndBitwiseXorAcquire(VarHandle ob, Object holder, $type$ value) {
373 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
374 return UNSAFE.getAndBitwiseXor$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
375 handle.fieldOffset,
376 value);
377 }
378 #end[Bitwise]
379
380 static final VarForm FORM = new VarForm(FieldInstanceReadWrite.class, Object.class, $type$.class);
381 }
382
383
384 static sealed class FieldStaticReadOnly extends VarHandle {
385 final Class<?> declaringClass;
386 final Object base;
387 final long fieldOffset;
388 #if[Object]
389 final Class<?> fieldType;
390 #end[Object]
391
392 FieldStaticReadOnly(Class<?> declaringClass, Object base, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
393 this(declaringClass, base, fieldOffset{#if[Object]?, fieldType}, FieldStaticReadOnly.FORM, false);
394 }
395
396 protected FieldStaticReadOnly(Class<?> declaringClass, Object base, long fieldOffset{#if[Object]?, Class<?> fieldType},
397 VarForm form, boolean exact) {
398 super(form, exact);
399 this.declaringClass = declaringClass;
400 this.base = base;
401 this.fieldOffset = fieldOffset;
402 #if[Object]
403 this.fieldType = fieldType;
404 #end[Object]
405 }
406
407 @Override
408 public FieldStaticReadOnly withInvokeExactBehavior() {
409 return hasInvokeExactBehavior()
410 ? this
411 : new FieldStaticReadOnly(declaringClass, base, fieldOffset{#if[Object]?, fieldType}, vform, true);
412 }
413
414 @Override
415 public FieldStaticReadOnly withInvokeBehavior() {
416 return !hasInvokeExactBehavior()
417 ? this
418 : new FieldStaticReadOnly(declaringClass, base, fieldOffset{#if[Object]?, fieldType}, vform, false);
419 }
420
421 @Override
422 public Optional<VarHandleDesc> describeConstable() {
423 var fieldTypeRef = {#if[Object]?fieldType:$type$.class}.describeConstable();
424 if (!fieldTypeRef.isPresent())
425 return Optional.empty();
426
427 // Reflect on this VarHandle to extract the field name
428 var staticField = VarHandles.getStaticFieldFromBaseAndOffset(
429 declaringClass, fieldOffset, {#if[Object]?fieldType:$type$.class});
430 var declaringTypeRef = declaringClass.describeConstable();
431 if (!declaringTypeRef.isPresent())
432 return Optional.empty();
433 return Optional.of(VarHandleDesc.ofStaticField(declaringTypeRef.get(), staticField.getName(), fieldTypeRef.get()));
434 }
435
436 @Override
437 final MethodType accessModeTypeUncached(AccessType at) {
438 return at.accessModeType(null, {#if[Object]?fieldType:$type$.class});
439 }
440
441 @ForceInline
442 static $type$ get(VarHandle ob) {
443 FieldStaticReadOnly handle = (FieldStaticReadOnly) ob.target();
444 return UNSAFE.get$Type$(handle.base,
445 handle.fieldOffset);
446 }
447
448 @ForceInline
449 static $type$ getVolatile(VarHandle ob) {
450 FieldStaticReadOnly handle = (FieldStaticReadOnly) ob.target();
451 return UNSAFE.get$Type$Volatile(handle.base,
452 handle.fieldOffset);
453 }
454
455 @ForceInline
456 static $type$ getOpaque(VarHandle ob) {
457 FieldStaticReadOnly handle = (FieldStaticReadOnly) ob.target();
458 return UNSAFE.get$Type$Opaque(handle.base,
459 handle.fieldOffset);
460 }
461
462 @ForceInline
463 static $type$ getAcquire(VarHandle ob) {
464 FieldStaticReadOnly handle = (FieldStaticReadOnly) ob.target();
465 return UNSAFE.get$Type$Acquire(handle.base,
466 handle.fieldOffset);
467 }
468
469 static final VarForm FORM = new VarForm(FieldStaticReadOnly.class, null, $type$.class);
470 }
471
472 static final class FieldStaticReadWrite extends FieldStaticReadOnly {
473
474 FieldStaticReadWrite(Class<?> declaringClass, Object base, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
475 this(declaringClass, base, fieldOffset{#if[Object]?, fieldType}, false);
476 }
477
478 private FieldStaticReadWrite(Class<?> declaringClass, Object base, long fieldOffset{#if[Object]?, Class<?> fieldType},
479 boolean exact) {
480 super(declaringClass, base, fieldOffset{#if[Object]?, fieldType}, FieldStaticReadWrite.FORM, exact);
481 }
482
483 @Override
484 public FieldStaticReadWrite withInvokeExactBehavior() {
485 return hasInvokeExactBehavior()
486 ? this
487 : new FieldStaticReadWrite(declaringClass, base, fieldOffset{#if[Object]?, fieldType}, true);
488 }
489
490 @Override
491 public FieldStaticReadWrite withInvokeBehavior() {
492 return !hasInvokeExactBehavior()
493 ? this
494 : new FieldStaticReadWrite(declaringClass, base, fieldOffset{#if[Object]?, fieldType}, false);
495 }
496
497 @ForceInline
498 static void set(VarHandle ob, $type$ value) {
499 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
500 UNSAFE.put$Type$(handle.base,
501 handle.fieldOffset,
502 {#if[Object]?handle.fieldType.cast(value):value});
503 }
504
505 @ForceInline
506 static void setVolatile(VarHandle ob, $type$ value) {
507 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
508 UNSAFE.put$Type$Volatile(handle.base,
509 handle.fieldOffset,
510 {#if[Object]?handle.fieldType.cast(value):value});
511 }
512
513 @ForceInline
514 static void setOpaque(VarHandle ob, $type$ value) {
515 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
516 UNSAFE.put$Type$Opaque(handle.base,
517 handle.fieldOffset,
518 {#if[Object]?handle.fieldType.cast(value):value});
519 }
520
521 @ForceInline
522 static void setRelease(VarHandle ob, $type$ value) {
523 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
524 UNSAFE.put$Type$Release(handle.base,
525 handle.fieldOffset,
526 {#if[Object]?handle.fieldType.cast(value):value});
527 }
528 #if[CAS]
529
530 @ForceInline
531 static boolean compareAndSet(VarHandle ob, $type$ expected, $type$ value) {
532 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
533 return UNSAFE.compareAndSet$Type$(handle.base,
534 handle.fieldOffset,
535 {#if[Object]?handle.fieldType.cast(expected):expected},
536 {#if[Object]?handle.fieldType.cast(value):value});
537 }
538
539
540 @ForceInline
541 static $type$ compareAndExchange(VarHandle ob, $type$ expected, $type$ value) {
542 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
543 return UNSAFE.compareAndExchange$Type$(handle.base,
544 handle.fieldOffset,
545 {#if[Object]?handle.fieldType.cast(expected):expected},
546 {#if[Object]?handle.fieldType.cast(value):value});
547 }
548
549 @ForceInline
550 static $type$ compareAndExchangeAcquire(VarHandle ob, $type$ expected, $type$ value) {
551 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
552 return UNSAFE.compareAndExchange$Type$Acquire(handle.base,
553 handle.fieldOffset,
554 {#if[Object]?handle.fieldType.cast(expected):expected},
555 {#if[Object]?handle.fieldType.cast(value):value});
556 }
557
558 @ForceInline
559 static $type$ compareAndExchangeRelease(VarHandle ob, $type$ expected, $type$ value) {
560 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
561 return UNSAFE.compareAndExchange$Type$Release(handle.base,
562 handle.fieldOffset,
563 {#if[Object]?handle.fieldType.cast(expected):expected},
564 {#if[Object]?handle.fieldType.cast(value):value});
565 }
566
567 @ForceInline
568 static boolean weakCompareAndSetPlain(VarHandle ob, $type$ expected, $type$ value) {
569 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
570 return UNSAFE.weakCompareAndSet$Type$Plain(handle.base,
571 handle.fieldOffset,
572 {#if[Object]?handle.fieldType.cast(expected):expected},
573 {#if[Object]?handle.fieldType.cast(value):value});
574 }
575
576 @ForceInline
577 static boolean weakCompareAndSet(VarHandle ob, $type$ expected, $type$ value) {
578 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
579 return UNSAFE.weakCompareAndSet$Type$(handle.base,
580 handle.fieldOffset,
581 {#if[Object]?handle.fieldType.cast(expected):expected},
582 {#if[Object]?handle.fieldType.cast(value):value});
583 }
584
585 @ForceInline
586 static boolean weakCompareAndSetAcquire(VarHandle ob, $type$ expected, $type$ value) {
587 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
588 return UNSAFE.weakCompareAndSet$Type$Acquire(handle.base,
589 handle.fieldOffset,
590 {#if[Object]?handle.fieldType.cast(expected):expected},
591 {#if[Object]?handle.fieldType.cast(value):value});
592 }
593
594 @ForceInline
595 static boolean weakCompareAndSetRelease(VarHandle ob, $type$ expected, $type$ value) {
596 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
597 return UNSAFE.weakCompareAndSet$Type$Release(handle.base,
598 handle.fieldOffset,
599 {#if[Object]?handle.fieldType.cast(expected):expected},
600 {#if[Object]?handle.fieldType.cast(value):value});
601 }
602
603 @ForceInline
604 static $type$ getAndSet(VarHandle ob, $type$ value) {
605 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
606 return UNSAFE.getAndSet$Type$(handle.base,
607 handle.fieldOffset,
608 {#if[Object]?handle.fieldType.cast(value):value});
609 }
610
611 @ForceInline
612 static $type$ getAndSetAcquire(VarHandle ob, $type$ value) {
613 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
614 return UNSAFE.getAndSet$Type$Acquire(handle.base,
615 handle.fieldOffset,
616 {#if[Object]?handle.fieldType.cast(value):value});
617 }
618
619 @ForceInline
620 static $type$ getAndSetRelease(VarHandle ob, $type$ value) {
621 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
622 return UNSAFE.getAndSet$Type$Release(handle.base,
623 handle.fieldOffset,
624 {#if[Object]?handle.fieldType.cast(value):value});
625 }
626 #end[CAS]
627 #if[AtomicAdd]
628
629 @ForceInline
630 static $type$ getAndAdd(VarHandle ob, $type$ value) {
631 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
632 return UNSAFE.getAndAdd$Type$(handle.base,
633 handle.fieldOffset,
634 value);
635 }
636
637 @ForceInline
638 static $type$ getAndAddAcquire(VarHandle ob, $type$ value) {
639 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
640 return UNSAFE.getAndAdd$Type$Acquire(handle.base,
641 handle.fieldOffset,
642 value);
643 }
644
711 @ForceInline
712 static $type$ getAndBitwiseXorRelease(VarHandle ob, $type$ value) {
713 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
714 return UNSAFE.getAndBitwiseXor$Type$Release(handle.base,
715 handle.fieldOffset,
716 value);
717 }
718
719 @ForceInline
720 static $type$ getAndBitwiseXorAcquire(VarHandle ob, $type$ value) {
721 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
722 return UNSAFE.getAndBitwiseXor$Type$Acquire(handle.base,
723 handle.fieldOffset,
724 value);
725 }
726 #end[Bitwise]
727
728 static final VarForm FORM = new VarForm(FieldStaticReadWrite.class, null, $type$.class);
729 }
730
731
732 static final class Array extends VarHandle {
733 final int abase;
734 final int ashift;
735 #if[Object]
736 final Class<{#if[Object]??:$type$[]}> arrayType;
737 final Class<?> componentType;
738 #end[Object]
739
740 Array(int abase, int ashift{#if[Object]?, Class<?> arrayType}) {
741 this(abase, ashift{#if[Object]?, arrayType}, false);
742 }
743
744 private Array(int abase, int ashift{#if[Object]?, Class<?> arrayType}, boolean exact) {
745 super(Array.FORM, exact);
746 this.abase = abase;
747 this.ashift = ashift;
748 #if[Object]
749 this.arrayType = {#if[Object]?arrayType:$type$[].class};
750 this.componentType = arrayType.getComponentType();
751 #end[Object]
759 }
760
761 @Override
762 public Array withInvokeBehavior() {
763 return !hasInvokeExactBehavior()
764 ? this
765 : new Array(abase, ashift{#if[Object]?, arrayType}, false);
766 }
767
768 @Override
769 public Optional<VarHandleDesc> describeConstable() {
770 var arrayTypeRef = {#if[Object]?arrayType:$type$[].class}.describeConstable();
771 if (!arrayTypeRef.isPresent())
772 return Optional.empty();
773
774 return Optional.of(VarHandleDesc.ofArray(arrayTypeRef.get()));
775 }
776
777 @Override
778 final MethodType accessModeTypeUncached(AccessType at) {
779 return at.accessModeType({#if[Object]?arrayType:$type$[].class}, {#if[Object]?arrayType.getComponentType():$type$.class}, int.class);
780 }
781
782 #if[Object]
783 @ForceInline
784 static Object runtimeTypeCheck(Array handle, Object[] oarray, Object value) {
785 if (handle.arrayType == oarray.getClass()) {
786 // Fast path: static array type same as argument array type
787 return handle.componentType.cast(value);
788 } else {
789 // Slow path: check value against argument array component type
790 return reflectiveTypeCheck(oarray, value);
791 }
792 }
793
794 @ForceInline
795 static Object reflectiveTypeCheck(Object[] oarray, Object value) {
796 try {
797 return oarray.getClass().getComponentType().cast(value);
798 } catch (ClassCastException e) {
799 throw new ArrayStoreException();
800 }
801 }
802 #end[Object]
803
804 @ForceInline
805 static $type$ get(VarHandle ob, Object oarray, int index) {
806 Array handle = (Array)ob;
807 #if[Object]
808 Object[] array = (Object[]) handle.arrayType.cast(oarray);
809 #else[Object]
810 $type$[] array = ($type$[]) oarray;
811 #end[Object]
812 return array[index];
813 }
814
815 @ForceInline
816 static void set(VarHandle ob, Object oarray, int index, $type$ value) {
817 Array handle = (Array)ob;
818 #if[Object]
819 Object[] array = (Object[]) handle.arrayType.cast(oarray);
820 #else[Object]
821 $type$[] array = ($type$[]) oarray;
822 #end[Object]
823 array[index] = {#if[Object]?handle.componentType.cast(value):value};
824 }
825
826 @ForceInline
827 static $type$ getVolatile(VarHandle ob, Object oarray, int index) {
828 Array handle = (Array)ob;
829 #if[Object]
830 Object[] array = (Object[]) handle.arrayType.cast(oarray);
831 #else[Object]
832 $type$[] array = ($type$[]) oarray;
833 #end[Object]
834 return UNSAFE.get$Type$Volatile(array,
835 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase);
836 }
837
838 @ForceInline
839 static void setVolatile(VarHandle ob, Object oarray, int index, $type$ value) {
840 Array handle = (Array)ob;
841 #if[Object]
842 Object[] array = (Object[]) handle.arrayType.cast(oarray);
843 #else[Object]
844 $type$[] array = ($type$[]) oarray;
845 #end[Object]
846 UNSAFE.put$Type$Volatile(array,
847 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
848 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
849 }
850
851 @ForceInline
852 static $type$ getOpaque(VarHandle ob, Object oarray, int index) {
853 Array handle = (Array)ob;
854 #if[Object]
855 Object[] array = (Object[]) handle.arrayType.cast(oarray);
856 #else[Object]
857 $type$[] array = ($type$[]) oarray;
858 #end[Object]
859 return UNSAFE.get$Type$Opaque(array,
860 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase);
861 }
862
863 @ForceInline
864 static void setOpaque(VarHandle ob, Object oarray, int index, $type$ value) {
865 Array handle = (Array)ob;
866 #if[Object]
867 Object[] array = (Object[]) handle.arrayType.cast(oarray);
868 #else[Object]
869 $type$[] array = ($type$[]) oarray;
870 #end[Object]
871 UNSAFE.put$Type$Opaque(array,
872 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
873 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
874 }
875
876 @ForceInline
877 static $type$ getAcquire(VarHandle ob, Object oarray, int index) {
878 Array handle = (Array)ob;
879 #if[Object]
880 Object[] array = (Object[]) handle.arrayType.cast(oarray);
881 #else[Object]
882 $type$[] array = ($type$[]) oarray;
883 #end[Object]
884 return UNSAFE.get$Type$Acquire(array,
885 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase);
886 }
887
888 @ForceInline
889 static void setRelease(VarHandle ob, Object oarray, int index, $type$ value) {
890 Array handle = (Array)ob;
891 #if[Object]
892 Object[] array = (Object[]) handle.arrayType.cast(oarray);
893 #else[Object]
894 $type$[] array = ($type$[]) oarray;
895 #end[Object]
896 UNSAFE.put$Type$Release(array,
897 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
898 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
899 }
900 #if[CAS]
901
902 @ForceInline
903 static boolean compareAndSet(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
904 Array handle = (Array)ob;
905 #if[Object]
906 Object[] array = (Object[]) handle.arrayType.cast(oarray);
907 #else[Object]
908 $type$[] array = ($type$[]) oarray;
909 #end[Object]
910 return UNSAFE.compareAndSet$Type$(array,
911 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
912 {#if[Object]?handle.componentType.cast(expected):expected},
913 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
914 }
915
916 @ForceInline
917 static $type$ compareAndExchange(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
918 Array handle = (Array)ob;
919 #if[Object]
920 Object[] array = (Object[]) handle.arrayType.cast(oarray);
921 #else[Object]
922 $type$[] array = ($type$[]) oarray;
923 #end[Object]
924 return UNSAFE.compareAndExchange$Type$(array,
925 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
926 {#if[Object]?handle.componentType.cast(expected):expected},
927 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
928 }
929
930 @ForceInline
931 static $type$ compareAndExchangeAcquire(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
932 Array handle = (Array)ob;
933 #if[Object]
934 Object[] array = (Object[]) handle.arrayType.cast(oarray);
935 #else[Object]
936 $type$[] array = ($type$[]) oarray;
937 #end[Object]
938 return UNSAFE.compareAndExchange$Type$Acquire(array,
939 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
940 {#if[Object]?handle.componentType.cast(expected):expected},
941 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
942 }
943
944 @ForceInline
945 static $type$ compareAndExchangeRelease(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
946 Array handle = (Array)ob;
947 #if[Object]
948 Object[] array = (Object[]) handle.arrayType.cast(oarray);
949 #else[Object]
950 $type$[] array = ($type$[]) oarray;
951 #end[Object]
952 return UNSAFE.compareAndExchange$Type$Release(array,
953 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
954 {#if[Object]?handle.componentType.cast(expected):expected},
955 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
956 }
957
958 @ForceInline
959 static boolean weakCompareAndSetPlain(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
960 Array handle = (Array)ob;
961 #if[Object]
962 Object[] array = (Object[]) handle.arrayType.cast(oarray);
963 #else[Object]
964 $type$[] array = ($type$[]) oarray;
965 #end[Object]
966 return UNSAFE.weakCompareAndSet$Type$Plain(array,
967 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
968 {#if[Object]?handle.componentType.cast(expected):expected},
969 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
970 }
971
972 @ForceInline
973 static boolean weakCompareAndSet(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
974 Array handle = (Array)ob;
975 #if[Object]
976 Object[] array = (Object[]) handle.arrayType.cast(oarray);
977 #else[Object]
978 $type$[] array = ($type$[]) oarray;
979 #end[Object]
980 return UNSAFE.weakCompareAndSet$Type$(array,
981 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
982 {#if[Object]?handle.componentType.cast(expected):expected},
983 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
984 }
985
986 @ForceInline
987 static boolean weakCompareAndSetAcquire(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
988 Array handle = (Array)ob;
989 #if[Object]
990 Object[] array = (Object[]) handle.arrayType.cast(oarray);
991 #else[Object]
992 $type$[] array = ($type$[]) oarray;
993 #end[Object]
994 return UNSAFE.weakCompareAndSet$Type$Acquire(array,
995 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
996 {#if[Object]?handle.componentType.cast(expected):expected},
997 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
998 }
999
1000 @ForceInline
1001 static boolean weakCompareAndSetRelease(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1002 Array handle = (Array)ob;
1003 #if[Object]
1004 Object[] array = (Object[]) handle.arrayType.cast(oarray);
1005 #else[Object]
1006 $type$[] array = ($type$[]) oarray;
1007 #end[Object]
1008 return UNSAFE.weakCompareAndSet$Type$Release(array,
1009 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1010 {#if[Object]?handle.componentType.cast(expected):expected},
1011 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1012 }
1013
1014 @ForceInline
1015 static $type$ getAndSet(VarHandle ob, Object oarray, int index, $type$ value) {
1016 Array handle = (Array)ob;
1017 #if[Object]
1018 Object[] array = (Object[]) handle.arrayType.cast(oarray);
1019 #else[Object]
1020 $type$[] array = ($type$[]) oarray;
1021 #end[Object]
1022 return UNSAFE.getAndSet$Type$(array,
1023 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1024 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1025 }
1026
1027 @ForceInline
1028 static $type$ getAndSetAcquire(VarHandle ob, Object oarray, int index, $type$ value) {
1029 Array handle = (Array)ob;
1030 #if[Object]
1031 Object[] array = (Object[]) handle.arrayType.cast(oarray);
1032 #else[Object]
1033 $type$[] array = ($type$[]) oarray;
1034 #end[Object]
1035 return UNSAFE.getAndSet$Type$Acquire(array,
1036 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1037 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1038 }
1039
1040 @ForceInline
1041 static $type$ getAndSetRelease(VarHandle ob, Object oarray, int index, $type$ value) {
1042 Array handle = (Array)ob;
1043 #if[Object]
1044 Object[] array = (Object[]) handle.arrayType.cast(oarray);
1045 #else[Object]
1046 $type$[] array = ($type$[]) oarray;
1047 #end[Object]
1048 return UNSAFE.getAndSet$Type$Release(array,
1049 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1050 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1051 }
1052 #end[CAS]
1053 #if[AtomicAdd]
1054
1055 @ForceInline
1056 static $type$ getAndAdd(VarHandle ob, Object oarray, int index, $type$ value) {
1057 Array handle = (Array)ob;
1058 $type$[] array = ($type$[]) oarray;
1059 return UNSAFE.getAndAdd$Type$(array,
1060 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1061 value);
1062 }
1063
1064 @ForceInline
1065 static $type$ getAndAddAcquire(VarHandle ob, Object oarray, int index, $type$ value) {
1066 Array handle = (Array)ob;
1067 $type$[] array = ($type$[]) oarray;
1068 return UNSAFE.getAndAdd$Type$Acquire(array,
1069 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1145 }
1146
1147 @ForceInline
1148 static $type$ getAndBitwiseXorRelease(VarHandle ob, Object oarray, int index, $type$ value) {
1149 Array handle = (Array)ob;
1150 $type$[] array = ($type$[]) oarray;
1151 return UNSAFE.getAndBitwiseXor$Type$Release(array,
1152 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1153 value);
1154 }
1155
1156 @ForceInline
1157 static $type$ getAndBitwiseXorAcquire(VarHandle ob, Object oarray, int index, $type$ value) {
1158 Array handle = (Array)ob;
1159 $type$[] array = ($type$[]) oarray;
1160 return UNSAFE.getAndBitwiseXor$Type$Acquire(array,
1161 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1162 value);
1163 }
1164 #end[Bitwise]
1165
1166 static final VarForm FORM = new VarForm(Array.class, {#if[Object]?Object[].class:$type$[].class}, {#if[Object]?Object.class:$type$.class}, int.class);
1167 }
1168 }
|
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 #if[Object]
28 import jdk.internal.value.CheckedType;
29 import jdk.internal.value.NullRestrictedCheckedType;
30 import jdk.internal.value.ValueClass;
31 #end[Object]
32 import jdk.internal.util.Preconditions;
33 import jdk.internal.vm.annotation.ForceInline;
34
35 import java.lang.invoke.VarHandle.VarHandleDesc;
36 import java.util.Objects;
37 import java.util.Optional;
38
39 import static java.lang.invoke.MethodHandleStatics.UNSAFE;
40
41 #warn
42
43 final class VarHandle$Type$s {
44
45 static sealed class FieldInstanceReadOnly extends VarHandle {
46 final long fieldOffset;
47 final Class<?> receiverType;
48 #if[Object]
49 final Class<?> fieldType;
50 final CheckedType checkedFieldType;
51 #end[Object]
52
53 FieldInstanceReadOnly(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType, CheckedType checkedFieldType}) {
54 this(receiverType, fieldOffset{#if[Object]?, fieldType, checkedFieldType}, FieldInstanceReadOnly.FORM, false);
55 }
56
57 protected FieldInstanceReadOnly(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType, CheckedType checkedFieldType},
58 VarForm form, boolean exact) {
59 super(form, exact);
60 this.fieldOffset = fieldOffset;
61 this.receiverType = receiverType;
62 #if[Object]
63 this.fieldType = fieldType;
64 this.checkedFieldType = checkedFieldType;
65 #end[Object]
66 }
67
68 @Override
69 public FieldInstanceReadOnly withInvokeExactBehavior() {
70 return hasInvokeExactBehavior()
71 ? this
72 : new FieldInstanceReadOnly(receiverType, fieldOffset{#if[Object]?, fieldType, checkedFieldType}, vform, true);
73 }
74
75 @Override
76 public FieldInstanceReadOnly withInvokeBehavior() {
77 return !hasInvokeExactBehavior()
78 ? this
79 : new FieldInstanceReadOnly(receiverType, fieldOffset{#if[Object]?, fieldType, checkedFieldType}, vform, false);
80 }
81
82 @Override
83 final MethodType accessModeTypeUncached(AccessType at) {
84 return at.accessModeType(receiverType, {#if[Object]?fieldType:$type$.class});
85 }
86
87 @Override
88 public Optional<VarHandleDesc> describeConstable() {
89 var receiverTypeRef = receiverType.describeConstable();
90 var fieldTypeRef = {#if[Object]?fieldType:$type$.class}.describeConstable();
91 if (!receiverTypeRef.isPresent() || !fieldTypeRef.isPresent())
92 return Optional.empty();
93
94 // Reflect on this VarHandle to extract the field name
95 String name = VarHandles.getFieldFromReceiverAndOffset(
96 receiverType, fieldOffset, {#if[Object]?fieldType:$type$.class}).getName();
97 return Optional.of(VarHandleDesc.ofField(receiverTypeRef.get(), name, fieldTypeRef.get()));
98 }
99
100 @ForceInline
101 static $type$ get(VarHandle ob, Object holder) {
102 FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
103 $type$ value = UNSAFE.get$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
104 handle.fieldOffset{#if[Value]?, handle.fieldType});
105 #if[Object]
106 if (value == null && handle.checkedFieldType instanceof NullRestrictedCheckedType) {
107 return ValueClass.zeroInstance(handle.fieldType);
108 }
109 #end[Object]
110 return value;
111 }
112
113 @ForceInline
114 static $type$ getVolatile(VarHandle ob, Object holder) {
115 FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
116 $type$ value = UNSAFE.get$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)),
117 handle.fieldOffset{#if[Value]?, handle.fieldType});
118 #if[Object]
119 if (value == null && handle.checkedFieldType instanceof NullRestrictedCheckedType) {
120 return ValueClass.zeroInstance(handle.fieldType);
121 }
122 #end[Object]
123 return value;
124 }
125
126 @ForceInline
127 static $type$ getOpaque(VarHandle ob, Object holder) {
128 FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
129 $type$ value = UNSAFE.get$Type$Opaque(Objects.requireNonNull(handle.receiverType.cast(holder)),
130 handle.fieldOffset{#if[Value]?, handle.fieldType});
131 #if[Object]
132 if (value == null && handle.checkedFieldType instanceof NullRestrictedCheckedType) {
133 return ValueClass.zeroInstance(handle.fieldType);
134 }
135 #end[Object]
136 return value;
137 }
138
139 @ForceInline
140 static $type$ getAcquire(VarHandle ob, Object holder) {
141 FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
142 $type$ value = UNSAFE.get$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
143 handle.fieldOffset{#if[Value]?, handle.fieldType});
144 #if[Object]
145 if (value == null && handle.checkedFieldType instanceof NullRestrictedCheckedType) {
146 return ValueClass.zeroInstance(handle.fieldType);
147 }
148 #end[Object]
149 return value;
150 }
151
152 static final VarForm FORM = new VarForm(FieldInstanceReadOnly.class, Object.class, $type$.class);
153 }
154
155 static final class FieldInstanceReadWrite extends FieldInstanceReadOnly {
156 FieldInstanceReadWrite(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType, CheckedType checkedFieldType}) {
157 this(receiverType, fieldOffset{#if[Object]?, fieldType, checkedFieldType}, false);
158 }
159
160 private FieldInstanceReadWrite(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType, CheckedType checkedFieldType},
161 boolean exact) {
162 super(receiverType, fieldOffset{#if[Object]?, fieldType, checkedFieldType}, FieldInstanceReadWrite.FORM, exact);
163 }
164
165 @Override
166 public FieldInstanceReadWrite withInvokeExactBehavior() {
167 return hasInvokeExactBehavior()
168 ? this
169 : new FieldInstanceReadWrite(receiverType, fieldOffset{#if[Object]?, fieldType, checkedFieldType}, true);
170 }
171
172 @Override
173 public FieldInstanceReadWrite withInvokeBehavior() {
174 return !hasInvokeExactBehavior()
175 ? this
176 : new FieldInstanceReadWrite(receiverType, fieldOffset{#if[Object]?, fieldType, checkedFieldType}, false);
177 }
178
179 #if[Object]
180 @ForceInline
181 static Object checkCast(FieldInstanceReadWrite handle, $type$ value) {
182 return handle.checkedFieldType.cast(value);
183 }
184 #end[Object]
185
186 @ForceInline
187 static void set(VarHandle ob, Object holder, $type$ value) {
188 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
189 UNSAFE.put$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
190 handle.fieldOffset{#if[Value]?, handle.fieldType},
191 {#if[Object]?checkCast(handle, value):value});
192 }
193
194 @ForceInline
195 static void setVolatile(VarHandle ob, Object holder, $type$ value) {
196 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
197 UNSAFE.put$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)),
198 handle.fieldOffset{#if[Value]?, handle.fieldType},
199 {#if[Object]?checkCast(handle, value):value});
200 }
201
202 @ForceInline
203 static void setOpaque(VarHandle ob, Object holder, $type$ value) {
204 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
205 UNSAFE.put$Type$Opaque(Objects.requireNonNull(handle.receiverType.cast(holder)),
206 handle.fieldOffset{#if[Value]?, handle.fieldType},
207 {#if[Object]?checkCast(handle, value):value});
208 }
209
210 @ForceInline
211 static void setRelease(VarHandle ob, Object holder, $type$ value) {
212 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
213 UNSAFE.put$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
214 handle.fieldOffset{#if[Value]?, handle.fieldType},
215 {#if[Object]?checkCast(handle, value):value});
216 }
217 #if[CAS]
218
219 @ForceInline
220 static boolean compareAndSet(VarHandle ob, Object holder, $type$ expected, $type$ value) {
221 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
222 return UNSAFE.compareAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
223 handle.fieldOffset{#if[Object]?, handle.fieldType},
224 {#if[Object]?checkCast(handle, expected):expected},
225 {#if[Object]?checkCast(handle, value):value});
226 }
227
228 @ForceInline
229 static $type$ compareAndExchange(VarHandle ob, Object holder, $type$ expected, $type$ value) {
230 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
231 return UNSAFE.compareAndExchange$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
232 handle.fieldOffset{#if[Object]?, handle.fieldType},
233 {#if[Object]?checkCast(handle, expected):expected},
234 {#if[Object]?checkCast(handle, value):value});
235 }
236
237 @ForceInline
238 static $type$ compareAndExchangeAcquire(VarHandle ob, Object holder, $type$ expected, $type$ value) {
239 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
240 return UNSAFE.compareAndExchange$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
241 handle.fieldOffset{#if[Object]?, handle.fieldType},
242 {#if[Object]?checkCast(handle, expected):expected},
243 {#if[Object]?checkCast(handle, value):value});
244 }
245
246 @ForceInline
247 static $type$ compareAndExchangeRelease(VarHandle ob, Object holder, $type$ expected, $type$ value) {
248 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
249 return UNSAFE.compareAndExchange$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
250 handle.fieldOffset{#if[Object]?, handle.fieldType},
251 {#if[Object]?checkCast(handle, expected):expected},
252 {#if[Object]?checkCast(handle, value):value});
253 }
254
255 @ForceInline
256 static boolean weakCompareAndSetPlain(VarHandle ob, Object holder, $type$ expected, $type$ value) {
257 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
258 return UNSAFE.weakCompareAndSet$Type$Plain(Objects.requireNonNull(handle.receiverType.cast(holder)),
259 handle.fieldOffset{#if[Object]?, handle.fieldType},
260 {#if[Object]?checkCast(handle, expected):expected},
261 {#if[Object]?checkCast(handle, value):value});
262 }
263
264 @ForceInline
265 static boolean weakCompareAndSet(VarHandle ob, Object holder, $type$ expected, $type$ value) {
266 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
267 return UNSAFE.weakCompareAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
268 handle.fieldOffset{#if[Object]?, handle.fieldType},
269 {#if[Object]?checkCast(handle, expected):expected},
270 {#if[Object]?checkCast(handle, value):value});
271 }
272
273 @ForceInline
274 static boolean weakCompareAndSetAcquire(VarHandle ob, Object holder, $type$ expected, $type$ value) {
275 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
276 return UNSAFE.weakCompareAndSet$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
277 handle.fieldOffset{#if[Object]?, handle.fieldType},
278 {#if[Object]?checkCast(handle, expected):expected},
279 {#if[Object]?checkCast(handle, value):value});
280 }
281
282 @ForceInline
283 static boolean weakCompareAndSetRelease(VarHandle ob, Object holder, $type$ expected, $type$ value) {
284 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
285 return UNSAFE.weakCompareAndSet$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
286 handle.fieldOffset{#if[Object]?, handle.fieldType},
287 {#if[Object]?checkCast(handle, expected):expected},
288 {#if[Object]?checkCast(handle, value):value});
289 }
290
291 @ForceInline
292 static $type$ getAndSet(VarHandle ob, Object holder, $type$ value) {
293 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
294 return UNSAFE.getAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
295 handle.fieldOffset{#if[Value]?, handle.fieldType},
296 {#if[Object]?checkCast(handle, value):value});
297 }
298
299 @ForceInline
300 static $type$ getAndSetAcquire(VarHandle ob, Object holder, $type$ value) {
301 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
302 return UNSAFE.getAndSet$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
303 handle.fieldOffset{#if[Value]?, handle.fieldType},
304 {#if[Object]?checkCast(handle, value):value});
305 }
306
307 @ForceInline
308 static $type$ getAndSetRelease(VarHandle ob, Object holder, $type$ value) {
309 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
310 return UNSAFE.getAndSet$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
311 handle.fieldOffset{#if[Value]?, handle.fieldType},
312 {#if[Object]?checkCast(handle, value):value});
313 }
314 #end[CAS]
315 #if[AtomicAdd]
316
317 @ForceInline
318 static $type$ getAndAdd(VarHandle ob, Object holder, $type$ value) {
319 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
320 return UNSAFE.getAndAdd$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
321 handle.fieldOffset,
322 value);
323 }
324
325 @ForceInline
326 static $type$ getAndAddAcquire(VarHandle ob, Object holder, $type$ value) {
327 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
328 return UNSAFE.getAndAdd$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
329 handle.fieldOffset,
330 value);
331 }
332
407
408 @ForceInline
409 static $type$ getAndBitwiseXorAcquire(VarHandle ob, Object holder, $type$ value) {
410 FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
411 return UNSAFE.getAndBitwiseXor$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
412 handle.fieldOffset,
413 value);
414 }
415 #end[Bitwise]
416
417 static final VarForm FORM = new VarForm(FieldInstanceReadWrite.class, Object.class, $type$.class);
418 }
419
420
421 static sealed class FieldStaticReadOnly extends VarHandle {
422 final Class<?> declaringClass;
423 final Object base;
424 final long fieldOffset;
425 #if[Object]
426 final Class<?> fieldType;
427 final CheckedType checkedFieldType;
428 #end[Object]
429
430 FieldStaticReadOnly(Class<?> declaringClass, Object base, long fieldOffset{#if[Object]?, Class<?> fieldType, CheckedType checkedFieldType}) {
431 this(declaringClass, base, fieldOffset{#if[Object]?, fieldType, checkedFieldType}, FieldStaticReadOnly.FORM, false);
432 }
433
434 protected FieldStaticReadOnly(Class<?> declaringClass, Object base, long fieldOffset{#if[Object]?, Class<?> fieldType, CheckedType checkedFieldType},
435 VarForm form, boolean exact) {
436 super(form, exact);
437 this.declaringClass = declaringClass;
438 this.base = base;
439 this.fieldOffset = fieldOffset;
440 #if[Object]
441 this.fieldType = fieldType;
442 this.checkedFieldType = checkedFieldType;
443 #end[Object]
444 }
445
446 @Override
447 public FieldStaticReadOnly withInvokeExactBehavior() {
448 return hasInvokeExactBehavior()
449 ? this
450 : new FieldStaticReadOnly(declaringClass, base, fieldOffset{#if[Object]?, fieldType, checkedFieldType}, vform, true);
451 }
452
453 @Override
454 public FieldStaticReadOnly withInvokeBehavior() {
455 return !hasInvokeExactBehavior()
456 ? this
457 : new FieldStaticReadOnly(declaringClass, base, fieldOffset{#if[Object]?, fieldType, checkedFieldType}, vform, false);
458 }
459
460 @Override
461 public Optional<VarHandleDesc> describeConstable() {
462 var fieldTypeRef = {#if[Object]?fieldType:$type$.class}.describeConstable();
463 if (!fieldTypeRef.isPresent())
464 return Optional.empty();
465
466 // Reflect on this VarHandle to extract the field name
467 var staticField = VarHandles.getStaticFieldFromBaseAndOffset(
468 declaringClass, fieldOffset, {#if[Object]?fieldType:$type$.class});
469 var declaringTypeRef = declaringClass.describeConstable();
470 if (!declaringTypeRef.isPresent())
471 return Optional.empty();
472 return Optional.of(VarHandleDesc.ofStaticField(declaringTypeRef.get(), staticField.getName(), fieldTypeRef.get()));
473 }
474
475 @Override
476 final MethodType accessModeTypeUncached(AccessType at) {
477 return at.accessModeType(null, {#if[Object]?fieldType:$type$.class});
478 }
479
480 @ForceInline
481 static $type$ get(VarHandle ob) {
482 FieldStaticReadOnly handle = (FieldStaticReadOnly) ob.target();
483 $type$ value = UNSAFE.get$Type$(handle.base,
484 handle.fieldOffset{#if[Value]?, handle.fieldType});
485 #if[Object]
486 if (value == null && handle.checkedFieldType instanceof NullRestrictedCheckedType) {
487 return ValueClass.zeroInstance(handle.fieldType);
488 }
489 #end[Object]
490 return value;
491 }
492
493 @ForceInline
494 static $type$ getVolatile(VarHandle ob) {
495 FieldStaticReadOnly handle = (FieldStaticReadOnly) ob.target();
496 $type$ value = UNSAFE.get$Type$Volatile(handle.base,
497 handle.fieldOffset{#if[Value]?, handle.fieldType});
498 #if[Object]
499 if (value == null && handle.checkedFieldType instanceof NullRestrictedCheckedType) {
500 return ValueClass.zeroInstance(handle.fieldType);
501 }
502 #end[Object]
503 return value;
504 }
505
506 @ForceInline
507 static $type$ getOpaque(VarHandle ob) {
508 FieldStaticReadOnly handle = (FieldStaticReadOnly) ob.target();
509 $type$ value = UNSAFE.get$Type$Opaque(handle.base,
510 handle.fieldOffset{#if[Value]?, handle.fieldType});
511 #if[Object]
512 if (value == null && handle.checkedFieldType instanceof NullRestrictedCheckedType) {
513 return ValueClass.zeroInstance(handle.fieldType);
514 }
515 #end[Object]
516 return value;
517 }
518
519 @ForceInline
520 static $type$ getAcquire(VarHandle ob) {
521 FieldStaticReadOnly handle = (FieldStaticReadOnly) ob.target();
522 $type$ value = UNSAFE.get$Type$Acquire(handle.base,
523 handle.fieldOffset{#if[Value]?, handle.fieldType});
524 #if[Object]
525 if (value == null && handle.checkedFieldType instanceof NullRestrictedCheckedType) {
526 return ValueClass.zeroInstance(handle.fieldType);
527 }
528 #end[Object]
529 return value;
530 }
531
532 static final VarForm FORM = new VarForm(FieldStaticReadOnly.class, null, $type$.class);
533 }
534
535 static final class FieldStaticReadWrite extends FieldStaticReadOnly {
536
537 FieldStaticReadWrite(Class<?> declaringClass, Object base, long fieldOffset{#if[Object]?, Class<?> fieldType, CheckedType checkedFieldType}) {
538 this(declaringClass, base, fieldOffset{#if[Object]?, fieldType, checkedFieldType}, false);
539 }
540
541 private FieldStaticReadWrite(Class<?> declaringClass, Object base, long fieldOffset{#if[Object]?, Class<?> fieldType, CheckedType checkedFieldType},
542 boolean exact) {
543 super(declaringClass, base, fieldOffset{#if[Object]?, fieldType, checkedFieldType}, FieldStaticReadWrite.FORM, exact);
544 }
545
546 @Override
547 public FieldStaticReadWrite withInvokeExactBehavior() {
548 return hasInvokeExactBehavior()
549 ? this
550 : new FieldStaticReadWrite(declaringClass, base, fieldOffset{#if[Object]?, fieldType, checkedFieldType}, true);
551 }
552
553 @Override
554 public FieldStaticReadWrite withInvokeBehavior() {
555 return !hasInvokeExactBehavior()
556 ? this
557 : new FieldStaticReadWrite(declaringClass, base, fieldOffset{#if[Object]?, fieldType, checkedFieldType}, false);
558 }
559
560 #if[Object]
561 @ForceInline
562 static Object checkCast(FieldStaticReadWrite handle, $type$ value) {
563 return handle.checkedFieldType.cast(value);
564 }
565 #end[Object]
566
567 @ForceInline
568 static void set(VarHandle ob, $type$ value) {
569 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
570 UNSAFE.put$Type$(handle.base,
571 handle.fieldOffset{#if[Value]?, handle.fieldType},
572 {#if[Object]?checkCast(handle, value):value});
573 }
574
575 @ForceInline
576 static void setVolatile(VarHandle ob, $type$ value) {
577 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
578 UNSAFE.put$Type$Volatile(handle.base,
579 handle.fieldOffset{#if[Value]?, handle.fieldType},
580 {#if[Object]?checkCast(handle, value):value});
581 }
582
583 @ForceInline
584 static void setOpaque(VarHandle ob, $type$ value) {
585 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
586 UNSAFE.put$Type$Opaque(handle.base,
587 handle.fieldOffset{#if[Value]?, handle.fieldType},
588 {#if[Object]?checkCast(handle, value):value});
589 }
590
591 @ForceInline
592 static void setRelease(VarHandle ob, $type$ value) {
593 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
594 UNSAFE.put$Type$Release(handle.base,
595 handle.fieldOffset{#if[Value]?, handle.fieldType},
596 {#if[Object]?checkCast(handle, value):value});
597 }
598 #if[CAS]
599
600 @ForceInline
601 static boolean compareAndSet(VarHandle ob, $type$ expected, $type$ value) {
602 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
603 return UNSAFE.compareAndSet$Type$(handle.base,
604 handle.fieldOffset{#if[Object]?, handle.fieldType},
605 {#if[Object]?checkCast(handle, expected):expected},
606 {#if[Object]?checkCast(handle, value):value});
607 }
608
609
610 @ForceInline
611 static $type$ compareAndExchange(VarHandle ob, $type$ expected, $type$ value) {
612 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
613 return UNSAFE.compareAndExchange$Type$(handle.base,
614 handle.fieldOffset{#if[Object]?, handle.fieldType},
615 {#if[Object]?checkCast(handle, expected):expected},
616 {#if[Object]?checkCast(handle, value):value});
617 }
618
619 @ForceInline
620 static $type$ compareAndExchangeAcquire(VarHandle ob, $type$ expected, $type$ value) {
621 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
622 return UNSAFE.compareAndExchange$Type$Acquire(handle.base,
623 handle.fieldOffset{#if[Object]?, handle.fieldType},
624 {#if[Object]?checkCast(handle, expected):expected},
625 {#if[Object]?checkCast(handle, value):value});
626 }
627
628 @ForceInline
629 static $type$ compareAndExchangeRelease(VarHandle ob, $type$ expected, $type$ value) {
630 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
631 return UNSAFE.compareAndExchange$Type$Release(handle.base,
632 handle.fieldOffset{#if[Object]?, handle.fieldType},
633 {#if[Object]?checkCast(handle, expected):expected},
634 {#if[Object]?checkCast(handle, value):value});
635 }
636
637 @ForceInline
638 static boolean weakCompareAndSetPlain(VarHandle ob, $type$ expected, $type$ value) {
639 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
640 return UNSAFE.weakCompareAndSet$Type$Plain(handle.base,
641 handle.fieldOffset{#if[Object]?, handle.fieldType},
642 {#if[Object]?checkCast(handle, expected):expected},
643 {#if[Object]?checkCast(handle, value):value});
644 }
645
646 @ForceInline
647 static boolean weakCompareAndSet(VarHandle ob, $type$ expected, $type$ value) {
648 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
649 return UNSAFE.weakCompareAndSet$Type$(handle.base,
650 handle.fieldOffset{#if[Object]?, handle.fieldType},
651 {#if[Object]?checkCast(handle, expected):expected},
652 {#if[Object]?checkCast(handle, value):value});
653 }
654
655 @ForceInline
656 static boolean weakCompareAndSetAcquire(VarHandle ob, $type$ expected, $type$ value) {
657 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
658 return UNSAFE.weakCompareAndSet$Type$Acquire(handle.base,
659 handle.fieldOffset{#if[Object]?, handle.fieldType},
660 {#if[Object]?checkCast(handle, expected):expected},
661 {#if[Object]?checkCast(handle, value):value});
662 }
663
664 @ForceInline
665 static boolean weakCompareAndSetRelease(VarHandle ob, $type$ expected, $type$ value) {
666 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
667 return UNSAFE.weakCompareAndSet$Type$Release(handle.base,
668 handle.fieldOffset{#if[Object]?, handle.fieldType},
669 {#if[Object]?checkCast(handle, expected):expected},
670 {#if[Object]?checkCast(handle, value):value});
671 }
672
673 @ForceInline
674 static $type$ getAndSet(VarHandle ob, $type$ value) {
675 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
676 return UNSAFE.getAndSet$Type$(handle.base,
677 handle.fieldOffset{#if[Value]?, handle.fieldType},
678 {#if[Object]?checkCast(handle, value):value});
679 }
680
681 @ForceInline
682 static $type$ getAndSetAcquire(VarHandle ob, $type$ value) {
683 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
684 return UNSAFE.getAndSet$Type$Acquire(handle.base,
685 handle.fieldOffset{#if[Value]?, handle.fieldType},
686 {#if[Object]?checkCast(handle, value):value});
687 }
688
689 @ForceInline
690 static $type$ getAndSetRelease(VarHandle ob, $type$ value) {
691 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
692 return UNSAFE.getAndSet$Type$Release(handle.base,
693 handle.fieldOffset{#if[Value]?, handle.fieldType},
694 {#if[Object]?checkCast(handle, value):value});
695 }
696 #end[CAS]
697 #if[AtomicAdd]
698
699 @ForceInline
700 static $type$ getAndAdd(VarHandle ob, $type$ value) {
701 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
702 return UNSAFE.getAndAdd$Type$(handle.base,
703 handle.fieldOffset,
704 value);
705 }
706
707 @ForceInline
708 static $type$ getAndAddAcquire(VarHandle ob, $type$ value) {
709 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
710 return UNSAFE.getAndAdd$Type$Acquire(handle.base,
711 handle.fieldOffset,
712 value);
713 }
714
781 @ForceInline
782 static $type$ getAndBitwiseXorRelease(VarHandle ob, $type$ value) {
783 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
784 return UNSAFE.getAndBitwiseXor$Type$Release(handle.base,
785 handle.fieldOffset,
786 value);
787 }
788
789 @ForceInline
790 static $type$ getAndBitwiseXorAcquire(VarHandle ob, $type$ value) {
791 FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
792 return UNSAFE.getAndBitwiseXor$Type$Acquire(handle.base,
793 handle.fieldOffset,
794 value);
795 }
796 #end[Bitwise]
797
798 static final VarForm FORM = new VarForm(FieldStaticReadWrite.class, null, $type$.class);
799 }
800
801 static final class Array extends VarHandle {
802 final int abase;
803 final int ashift;
804 #if[Object]
805 final Class<{#if[Object]??:$type$[]}> arrayType;
806 final Class<?> componentType;
807 #end[Object]
808
809 Array(int abase, int ashift{#if[Object]?, Class<?> arrayType}) {
810 this(abase, ashift{#if[Object]?, arrayType}, false);
811 }
812
813 private Array(int abase, int ashift{#if[Object]?, Class<?> arrayType}, boolean exact) {
814 super(Array.FORM, exact);
815 this.abase = abase;
816 this.ashift = ashift;
817 #if[Object]
818 this.arrayType = {#if[Object]?arrayType:$type$[].class};
819 this.componentType = arrayType.getComponentType();
820 #end[Object]
828 }
829
830 @Override
831 public Array withInvokeBehavior() {
832 return !hasInvokeExactBehavior()
833 ? this
834 : new Array(abase, ashift{#if[Object]?, arrayType}, false);
835 }
836
837 @Override
838 public Optional<VarHandleDesc> describeConstable() {
839 var arrayTypeRef = {#if[Object]?arrayType:$type$[].class}.describeConstable();
840 if (!arrayTypeRef.isPresent())
841 return Optional.empty();
842
843 return Optional.of(VarHandleDesc.ofArray(arrayTypeRef.get()));
844 }
845
846 @Override
847 final MethodType accessModeTypeUncached(AccessType at) {
848 return at.accessModeType({#if[Object]?arrayType:$type$[].class}, {#if[Object]?componentType:$type$.class}, int.class);
849 }
850
851 #if[Object]
852 @ForceInline
853 static Object runtimeTypeCheck(Array handle, Object[] oarray, Object value) {
854 if (handle.arrayType == oarray.getClass()) {
855 // Fast path: static array type same as argument array type
856 return {#if[Value]?ValueClass.componentCheckedType(oarray):handle.componentType}.cast(value);
857 } else {
858 // Slow path: check value against argument array component checked type
859 return reflectiveTypeCheck(oarray, value);
860 }
861 }
862
863 @ForceInline
864 static Object reflectiveTypeCheck(Object[] oarray, Object value) {
865 try {
866 return ValueClass.componentCheckedType(oarray).cast(value);
867 } catch (ClassCastException e) {
868 throw new ArrayStoreException();
869 }
870 }
871 #end[Object]
872
873 @ForceInline
874 static $type$ get(VarHandle ob, Object oarray, int index) {
875 Array handle = (Array)ob;
876 #if[Object]
877 Object[] array = (Object[]) handle.arrayType.cast(oarray);
878 #else[Object]
879 $type$[] array = ($type$[]) oarray;
880 #end[Object]
881 return array[index];
882 }
883
884 @ForceInline
885 static void set(VarHandle ob, Object oarray, int index, $type$ value) {
886 Array handle = (Array)ob;
887 #if[Object]
888 Object[] array = (Object[]) handle.arrayType.cast(oarray);
889 #else[Object]
890 $type$[] array = ($type$[]) oarray;
891 #end[Object]
892 #if[Reference]
893 Class<?> arrayType = oarray.getClass();
894 if (handle.arrayType != arrayType && UNSAFE.isFlatArray(arrayType)) {
895 // delegate to VarHandle of flat array
896 VarHandle vh = VarHandleValues.flatArrayVarHandle(arrayType);
897 vh.set(oarray, index, value);
898 return;
899 }
900 #end[Reference]
901 array[index] = {#if[Object]?runtimeTypeCheck(handle, array, value):value};
902 }
903
904 @ForceInline
905 static $type$ getVolatile(VarHandle ob, Object oarray, int index) {
906 Array handle = (Array)ob;
907 #if[Object]
908 Object[] array = (Object[]) handle.arrayType.cast(oarray);
909 #else[Object]
910 $type$[] array = ($type$[]) oarray;
911 #end[Object]
912 #if[Reference]
913 Class<?> arrayType = oarray.getClass();
914 if (handle.arrayType != arrayType && UNSAFE.isFlatArray(arrayType)) {
915 // delegate to VarHandle of flat array
916 VarHandle vh = VarHandleValues.flatArrayVarHandle(arrayType);
917 return vh.getVolatile(oarray, index);
918 }
919 #end[Reference]
920 return UNSAFE.get$Type$Volatile(array,
921 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType});
922 }
923
924 @ForceInline
925 static void setVolatile(VarHandle ob, Object oarray, int index, $type$ value) {
926 Array handle = (Array)ob;
927 #if[Object]
928 Object[] array = (Object[]) handle.arrayType.cast(oarray);
929 #else[Object]
930 $type$[] array = ($type$[]) oarray;
931 #end[Object]
932 #if[Reference]
933 Class<?> arrayType = oarray.getClass();
934 if (handle.arrayType != arrayType && UNSAFE.isFlatArray(arrayType)) {
935 // delegate to VarHandle of flat array
936 VarHandle vh = VarHandleValues.flatArrayVarHandle(arrayType);
937 vh.setVolatile(oarray, index, value);
938 return;
939 }
940 #end[Reference]
941 UNSAFE.put$Type$Volatile(array,
942 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
943 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
944 }
945
946 @ForceInline
947 static $type$ getOpaque(VarHandle ob, Object oarray, int index) {
948 Array handle = (Array)ob;
949 #if[Object]
950 Object[] array = (Object[]) handle.arrayType.cast(oarray);
951 #else[Object]
952 $type$[] array = ($type$[]) oarray;
953 #end[Object]
954 #if[Reference]
955 Class<?> arrayType = oarray.getClass();
956 if (handle.arrayType != arrayType && UNSAFE.isFlatArray(arrayType)) {
957 // delegate to VarHandle of flat array
958 VarHandle vh = VarHandleValues.flatArrayVarHandle(arrayType);
959 return vh.getOpaque(oarray, index);
960 }
961 #end[Reference]
962 return UNSAFE.get$Type$Opaque(array,
963 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType});
964 }
965
966 @ForceInline
967 static void setOpaque(VarHandle ob, Object oarray, int index, $type$ value) {
968 Array handle = (Array)ob;
969 #if[Object]
970 Object[] array = (Object[]) handle.arrayType.cast(oarray);
971 #else[Object]
972 $type$[] array = ($type$[]) oarray;
973 #end[Object]
974 #if[Reference]
975 Class<?> arrayType = oarray.getClass();
976 if (handle.arrayType != arrayType && UNSAFE.isFlatArray(arrayType)) {
977 // delegate to VarHandle of flat array
978 VarHandle vh = VarHandleValues.flatArrayVarHandle(arrayType);
979 vh.setOpaque(oarray, index, value);
980 return;
981 }
982 #end[Reference]
983 UNSAFE.put$Type$Opaque(array,
984 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
985 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
986 }
987
988 @ForceInline
989 static $type$ getAcquire(VarHandle ob, Object oarray, int index) {
990 Array handle = (Array)ob;
991 #if[Object]
992 Object[] array = (Object[]) handle.arrayType.cast(oarray);
993 #else[Object]
994 $type$[] array = ($type$[]) oarray;
995 #end[Object]
996 #if[Reference]
997 Class<?> arrayType = oarray.getClass();
998 if (handle.arrayType != arrayType && UNSAFE.isFlatArray(arrayType)) {
999 // delegate to VarHandle of flat array
1000 VarHandle vh = VarHandleValues.flatArrayVarHandle(arrayType);
1001 return vh.getAcquire(oarray, index);
1002 }
1003 #end[Reference]
1004 return UNSAFE.get$Type$Acquire(array,
1005 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType});
1006 }
1007
1008 @ForceInline
1009 static void setRelease(VarHandle ob, Object oarray, int index, $type$ value) {
1010 Array handle = (Array)ob;
1011 #if[Object]
1012 Object[] array = (Object[]) handle.arrayType.cast(oarray);
1013 #else[Object]
1014 $type$[] array = ($type$[]) oarray;
1015 #end[Object]
1016 #if[Reference]
1017 Class<?> arrayType = oarray.getClass();
1018 if (handle.arrayType != arrayType && UNSAFE.isFlatArray(arrayType)) {
1019 // delegate to VarHandle of flat array
1020 VarHandle vh = VarHandleValues.flatArrayVarHandle(arrayType);
1021 vh.setRelease(oarray, index, value);
1022 return;
1023 }
1024 #end[Reference]
1025 UNSAFE.put$Type$Release(array,
1026 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
1027 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1028 }
1029 #if[CAS]
1030
1031 @ForceInline
1032 static boolean compareAndSet(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1033 Array handle = (Array)ob;
1034 #if[Object]
1035 Object[] array = (Object[]) handle.arrayType.cast(oarray);
1036 #else[Object]
1037 $type$[] array = ($type$[]) oarray;
1038 #end[Object]
1039 #if[Reference]
1040 Class<?> arrayType = oarray.getClass();
1041 if (handle.arrayType != arrayType && UNSAFE.isFlatArray(arrayType)) {
1042 // delegate to VarHandle of flat array
1043 VarHandle vh = VarHandleValues.flatArrayVarHandle(arrayType);
1044 return vh.compareAndSet(oarray, index, expected, value);
1045 }
1046 #end[Reference]
1047 return UNSAFE.compareAndSet$Type$(array,
1048 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1049 {#if[Object]?handle.componentType.cast(expected):expected},
1050 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1051 }
1052
1053 @ForceInline
1054 static $type$ compareAndExchange(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1055 Array handle = (Array)ob;
1056 #if[Object]
1057 Object[] array = (Object[]) handle.arrayType.cast(oarray);
1058 #else[Object]
1059 $type$[] array = ($type$[]) oarray;
1060 #end[Object]
1061 #if[Reference]
1062 Class<?> arrayType = oarray.getClass();
1063 if (handle.arrayType != arrayType && UNSAFE.isFlatArray(arrayType)) {
1064 // delegate to VarHandle of flat array
1065 VarHandle vh = VarHandleValues.flatArrayVarHandle(arrayType);
1066 return vh.compareAndExchange(oarray, index, expected, value);
1067 }
1068 #end[Reference]
1069 return UNSAFE.compareAndExchange$Type$(array,
1070 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1071 {#if[Object]?handle.componentType.cast(expected):expected},
1072 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1073 }
1074
1075 @ForceInline
1076 static $type$ compareAndExchangeAcquire(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1077 Array handle = (Array)ob;
1078 #if[Object]
1079 Object[] array = (Object[]) handle.arrayType.cast(oarray);
1080 #else[Object]
1081 $type$[] array = ($type$[]) oarray;
1082 #end[Object]
1083 #if[Reference]
1084 Class<?> arrayType = oarray.getClass();
1085 if (handle.arrayType != arrayType && UNSAFE.isFlatArray(arrayType)) {
1086 // delegate to VarHandle of flat array
1087 VarHandle vh = VarHandleValues.flatArrayVarHandle(arrayType);
1088 return vh.compareAndExchangeAcquire(oarray, index, expected, value);
1089 }
1090 #end[Reference]
1091 return UNSAFE.compareAndExchange$Type$Acquire(array,
1092 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1093 {#if[Object]?handle.componentType.cast(expected):expected},
1094 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1095 }
1096
1097 @ForceInline
1098 static $type$ compareAndExchangeRelease(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1099 Array handle = (Array)ob;
1100 #if[Object]
1101 Object[] array = (Object[]) handle.arrayType.cast(oarray);
1102 #else[Object]
1103 $type$[] array = ($type$[]) oarray;
1104 #end[Object]
1105 #if[Reference]
1106 Class<?> arrayType = oarray.getClass();
1107 if (handle.arrayType != arrayType && UNSAFE.isFlatArray(arrayType)) {
1108 // delegate to VarHandle of flat array
1109 VarHandle vh = VarHandleValues.flatArrayVarHandle(arrayType);
1110 return vh.compareAndExchangeRelease(oarray, index, expected, value);
1111 }
1112 #end[Reference]
1113 return UNSAFE.compareAndExchange$Type$Release(array,
1114 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1115 {#if[Object]?handle.componentType.cast(expected):expected},
1116 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1117 }
1118
1119 @ForceInline
1120 static boolean weakCompareAndSetPlain(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1121 Array handle = (Array)ob;
1122 #if[Object]
1123 Object[] array = (Object[]) handle.arrayType.cast(oarray);
1124 #else[Object]
1125 $type$[] array = ($type$[]) oarray;
1126 #end[Object]
1127 #if[Reference]
1128 Class<?> arrayType = oarray.getClass();
1129 if (handle.arrayType != arrayType && UNSAFE.isFlatArray(arrayType)) {
1130 // delegate to VarHandle of flat array
1131 VarHandle vh = VarHandleValues.flatArrayVarHandle(arrayType);
1132 return vh.weakCompareAndSetPlain(oarray, index, expected, value);
1133 }
1134 #end[Reference]
1135 return UNSAFE.weakCompareAndSet$Type$Plain(array,
1136 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1137 {#if[Object]?handle.componentType.cast(expected):expected},
1138 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1139 }
1140
1141 @ForceInline
1142 static boolean weakCompareAndSet(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1143 Array handle = (Array)ob;
1144 #if[Object]
1145 Object[] array = (Object[]) handle.arrayType.cast(oarray);
1146 #else[Object]
1147 $type$[] array = ($type$[]) oarray;
1148 #end[Object]
1149 #if[Reference]
1150 Class<?> arrayType = oarray.getClass();
1151 if (handle.arrayType != arrayType && UNSAFE.isFlatArray(arrayType)) {
1152 // delegate to VarHandle of flat array
1153 VarHandle vh = VarHandleValues.flatArrayVarHandle(arrayType);
1154 return vh.weakCompareAndSet(oarray, index, expected, value);
1155 }
1156 #end[Reference]
1157 return UNSAFE.weakCompareAndSet$Type$(array,
1158 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1159 {#if[Object]?handle.componentType.cast(expected):expected},
1160 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1161 }
1162
1163 @ForceInline
1164 static boolean weakCompareAndSetAcquire(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1165 Array handle = (Array)ob;
1166 #if[Object]
1167 Object[] array = (Object[]) handle.arrayType.cast(oarray);
1168 #else[Object]
1169 $type$[] array = ($type$[]) oarray;
1170 #end[Object]
1171 #if[Reference]
1172 Class<?> arrayType = oarray.getClass();
1173 if (handle.arrayType != arrayType && UNSAFE.isFlatArray(arrayType)) {
1174 // delegate to VarHandle of flat array
1175 VarHandle vh = VarHandleValues.flatArrayVarHandle(arrayType);
1176 return vh.weakCompareAndSetAcquire(oarray, index, expected, value);
1177 }
1178 #end[Reference]
1179 return UNSAFE.weakCompareAndSet$Type$Acquire(array,
1180 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1181 {#if[Object]?handle.componentType.cast(expected):expected},
1182 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1183 }
1184
1185 @ForceInline
1186 static boolean weakCompareAndSetRelease(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1187 Array handle = (Array)ob;
1188 #if[Object]
1189 Object[] array = (Object[]) handle.arrayType.cast(oarray);
1190 #else[Object]
1191 $type$[] array = ($type$[]) oarray;
1192 #end[Object]
1193 #if[Reference]
1194 Class<?> arrayType = oarray.getClass();
1195 if (handle.arrayType != arrayType && UNSAFE.isFlatArray(arrayType)) {
1196 // delegate to VarHandle of flat array
1197 VarHandle vh = VarHandleValues.flatArrayVarHandle(arrayType);
1198 return vh.weakCompareAndSetRelease(oarray, index, expected, value);
1199 }
1200 #end[Reference]
1201 return UNSAFE.weakCompareAndSet$Type$Release(array,
1202 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1203 {#if[Object]?handle.componentType.cast(expected):expected},
1204 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1205 }
1206
1207 @ForceInline
1208 static $type$ getAndSet(VarHandle ob, Object oarray, int index, $type$ value) {
1209 Array handle = (Array)ob;
1210 #if[Object]
1211 Object[] array = (Object[]) handle.arrayType.cast(oarray);
1212 #else[Object]
1213 $type$[] array = ($type$[]) oarray;
1214 #end[Object]
1215 #if[Reference]
1216 Class<?> arrayType = oarray.getClass();
1217 if (handle.arrayType != arrayType && UNSAFE.isFlatArray(arrayType)) {
1218 // delegate to VarHandle of flat array
1219 VarHandle vh = VarHandleValues.flatArrayVarHandle(arrayType);
1220 return vh.getAndSet(oarray, index, value);
1221 }
1222 #end[Reference]
1223 return UNSAFE.getAndSet$Type$(array,
1224 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
1225 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1226 }
1227
1228 @ForceInline
1229 static $type$ getAndSetAcquire(VarHandle ob, Object oarray, int index, $type$ value) {
1230 Array handle = (Array)ob;
1231 #if[Object]
1232 Object[] array = (Object[]) handle.arrayType.cast(oarray);
1233 #else[Object]
1234 $type$[] array = ($type$[]) oarray;
1235 #end[Object]
1236 #if[Reference]
1237 Class<?> arrayType = oarray.getClass();
1238 if (handle.arrayType != arrayType && UNSAFE.isFlatArray(arrayType)) {
1239 // delegate to VarHandle of flat array
1240 VarHandle vh = VarHandleValues.flatArrayVarHandle(arrayType);
1241 return vh.getAndSetAcquire(oarray, index, value);
1242 }
1243 #end[Reference]
1244 return UNSAFE.getAndSet$Type$Acquire(array,
1245 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
1246 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1247 }
1248
1249 @ForceInline
1250 static $type$ getAndSetRelease(VarHandle ob, Object oarray, int index, $type$ value) {
1251 Array handle = (Array)ob;
1252 #if[Object]
1253 Object[] array = (Object[]) handle.arrayType.cast(oarray);
1254 #else[Object]
1255 $type$[] array = ($type$[]) oarray;
1256 #end[Object]
1257 #if[Reference]
1258 Class<?> arrayType = oarray.getClass();
1259 if (handle.arrayType != arrayType && UNSAFE.isFlatArray(arrayType)) {
1260 // delegate to VarHandle of flat array
1261 VarHandle vh = VarHandleValues.flatArrayVarHandle(arrayType);
1262 return vh.getAndSetRelease(oarray, index, value);
1263 }
1264 #end[Reference]
1265 return UNSAFE.getAndSet$Type$Release(array,
1266 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
1267 {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1268 }
1269 #end[CAS]
1270 #if[AtomicAdd]
1271
1272 @ForceInline
1273 static $type$ getAndAdd(VarHandle ob, Object oarray, int index, $type$ value) {
1274 Array handle = (Array)ob;
1275 $type$[] array = ($type$[]) oarray;
1276 return UNSAFE.getAndAdd$Type$(array,
1277 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1278 value);
1279 }
1280
1281 @ForceInline
1282 static $type$ getAndAddAcquire(VarHandle ob, Object oarray, int index, $type$ value) {
1283 Array handle = (Array)ob;
1284 $type$[] array = ($type$[]) oarray;
1285 return UNSAFE.getAndAdd$Type$Acquire(array,
1286 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1362 }
1363
1364 @ForceInline
1365 static $type$ getAndBitwiseXorRelease(VarHandle ob, Object oarray, int index, $type$ value) {
1366 Array handle = (Array)ob;
1367 $type$[] array = ($type$[]) oarray;
1368 return UNSAFE.getAndBitwiseXor$Type$Release(array,
1369 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1370 value);
1371 }
1372
1373 @ForceInline
1374 static $type$ getAndBitwiseXorAcquire(VarHandle ob, Object oarray, int index, $type$ value) {
1375 Array handle = (Array)ob;
1376 $type$[] array = ($type$[]) oarray;
1377 return UNSAFE.getAndBitwiseXor$Type$Acquire(array,
1378 (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1379 value);
1380 }
1381 #end[Bitwise]
1382 static final VarForm FORM = new VarForm(Array.class, {#if[Object]?Object[].class:$type$[].class}, {#if[Object]?Object.class:$type$.class}, int.class);
1383 }
1384 #if[Value]
1385 static final ClassValue<Array> flatArrayVarHandles = new ClassValue<>() {
1386 @Override protected Array computeValue(Class<?> arrayClass) {
1387 assert UNSAFE.isFlatArray(arrayClass);
1388 int aoffset = UNSAFE.arrayBaseOffset(arrayClass);
1389 int ascale = UNSAFE.arrayIndexScale(arrayClass);
1390 int ashift = 31 - Integer.numberOfLeadingZeros(ascale);
1391 return new Array(aoffset, ashift, arrayClass);
1392 }
1393 };
1394 static VarHandle flatArrayVarHandle(Class<?> arrayClass) {
1395 return flatArrayVarHandles.get(arrayClass);
1396 }
1397 #end[Value]
1398 }
|