1/*
2 * Copyright (c) 2015, 2017, 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 */
25package java.lang.invoke;
26
27import jdk.internal.util.Preconditions;
28import jdk.internal.vm.annotation.ForceInline;
29
30import java.util.Objects;
31
32import static java.lang.invoke.MethodHandleStatics.UNSAFE;
33
34#warn
35
36final 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.FORM);
47        }
48
49        protected FieldInstanceReadOnly(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType},
50                                        VarForm form) {
51            super(form);
52            this.fieldOffset = fieldOffset;
53            this.receiverType = receiverType;
54#if[Object]
55            this.fieldType = fieldType;
56#end[Object]
57        }
58
59        @Override
60        final MethodType accessModeTypeUncached(AccessMode accessMode) {
61            return accessMode.at.accessModeType(receiverType, {#if[Object]?fieldType:$type$.class});
62        }
63
64        @ForceInline
65        static $type$ get(FieldInstanceReadOnly handle, Object holder) {
66            return UNSAFE.get$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
67                                 handle.fieldOffset);
68        }
69
70        @ForceInline
71        static $type$ getVolatile(FieldInstanceReadOnly handle, Object holder) {
72            return UNSAFE.get$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)),
73                                 handle.fieldOffset);
74        }
75
76        @ForceInline
77        static $type$ getOpaque(FieldInstanceReadOnly handle, Object holder) {
78            return UNSAFE.get$Type$Opaque(Objects.requireNonNull(handle.receiverType.cast(holder)),
79                                 handle.fieldOffset);
80        }
81
82        @ForceInline
83        static $type$ getAcquire(FieldInstanceReadOnly handle, Object holder) {
84            return UNSAFE.get$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
85                                 handle.fieldOffset);
86        }
87
88        static final VarForm FORM = new VarForm(FieldInstanceReadOnly.class, Object.class, $type$.class);
89    }
90
91    static final class FieldInstanceReadWrite extends FieldInstanceReadOnly {
92
93        FieldInstanceReadWrite(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
94            super(receiverType, fieldOffset{#if[Object]?, fieldType}, FieldInstanceReadWrite.FORM);
95        }
96
97        @ForceInline
98        static void set(FieldInstanceReadWrite handle, Object holder, $type$ value) {
99            UNSAFE.put$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
100                             handle.fieldOffset,
101                             {#if[Object]?handle.fieldType.cast(value):value});
102        }
103
104        @ForceInline
105        static void setVolatile(FieldInstanceReadWrite handle, Object holder, $type$ value) {
106            UNSAFE.put$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)),
107                                     handle.fieldOffset,
108                                     {#if[Object]?handle.fieldType.cast(value):value});
109        }
110
111        @ForceInline
112        static void setOpaque(FieldInstanceReadWrite handle, Object holder, $type$ value) {
113            UNSAFE.put$Type$Opaque(Objects.requireNonNull(handle.receiverType.cast(holder)),
114                                   handle.fieldOffset,
115                                   {#if[Object]?handle.fieldType.cast(value):value});
116        }
117
118        @ForceInline
119        static void setRelease(FieldInstanceReadWrite handle, Object holder, $type$ value) {
120            UNSAFE.put$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
121                                    handle.fieldOffset,
122                                    {#if[Object]?handle.fieldType.cast(value):value});
123        }
124#if[CAS]
125
126        @ForceInline
127        static boolean compareAndSet(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
128            return UNSAFE.compareAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
129                                               handle.fieldOffset,
130                                               {#if[Object]?handle.fieldType.cast(expected):expected},
131                                               {#if[Object]?handle.fieldType.cast(value):value});
132        }
133
134        @ForceInline
135        static $type$ compareAndExchange(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
136            return UNSAFE.compareAndExchange$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
137                                               handle.fieldOffset,
138                                               {#if[Object]?handle.fieldType.cast(expected):expected},
139                                               {#if[Object]?handle.fieldType.cast(value):value});
140        }
141
142        @ForceInline
143        static $type$ compareAndExchangeAcquire(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
144            return UNSAFE.compareAndExchange$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
145                                               handle.fieldOffset,
146                                               {#if[Object]?handle.fieldType.cast(expected):expected},
147                                               {#if[Object]?handle.fieldType.cast(value):value});
148        }
149
150        @ForceInline
151        static $type$ compareAndExchangeRelease(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
152            return UNSAFE.compareAndExchange$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
153                                               handle.fieldOffset,
154                                               {#if[Object]?handle.fieldType.cast(expected):expected},
155                                               {#if[Object]?handle.fieldType.cast(value):value});
156        }
157
158        @ForceInline
159        static boolean weakCompareAndSetPlain(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
160            return UNSAFE.weakCompareAndSet$Type$Plain(Objects.requireNonNull(handle.receiverType.cast(holder)),
161                                               handle.fieldOffset,
162                                               {#if[Object]?handle.fieldType.cast(expected):expected},
163                                               {#if[Object]?handle.fieldType.cast(value):value});
164        }
165
166        @ForceInline
167        static boolean weakCompareAndSet(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
168            return UNSAFE.weakCompareAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
169                                               handle.fieldOffset,
170                                               {#if[Object]?handle.fieldType.cast(expected):expected},
171                                               {#if[Object]?handle.fieldType.cast(value):value});
172        }
173
174        @ForceInline
175        static boolean weakCompareAndSetAcquire(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
176            return UNSAFE.weakCompareAndSet$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
177                                               handle.fieldOffset,
178                                               {#if[Object]?handle.fieldType.cast(expected):expected},
179                                               {#if[Object]?handle.fieldType.cast(value):value});
180        }
181
182        @ForceInline
183        static boolean weakCompareAndSetRelease(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
184            return UNSAFE.weakCompareAndSet$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
185                                               handle.fieldOffset,
186                                               {#if[Object]?handle.fieldType.cast(expected):expected},
187                                               {#if[Object]?handle.fieldType.cast(value):value});
188        }
189
190        @ForceInline
191        static $type$ getAndSet(FieldInstanceReadWrite handle, Object holder, $type$ value) {
192            return UNSAFE.getAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
193                                          handle.fieldOffset,
194                                          {#if[Object]?handle.fieldType.cast(value):value});
195        }
196
197        @ForceInline
198        static $type$ getAndSetAcquire(FieldInstanceReadWrite handle, Object holder, $type$ value) {
199            return UNSAFE.getAndSet$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
200                                          handle.fieldOffset,
201                                          {#if[Object]?handle.fieldType.cast(value):value});
202        }
203
204        @ForceInline
205        static $type$ getAndSetRelease(FieldInstanceReadWrite handle, Object holder, $type$ value) {
206            return UNSAFE.getAndSet$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
207                                          handle.fieldOffset,
208                                          {#if[Object]?handle.fieldType.cast(value):value});
209        }
210#end[CAS]
211#if[AtomicAdd]
212
213        @ForceInline
214        static $type$ getAndAdd(FieldInstanceReadWrite handle, Object holder, $type$ value) {
215            return UNSAFE.getAndAdd$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
216                                       handle.fieldOffset,
217                                       value);
218        }
219
220        @ForceInline
221        static $type$ getAndAddAcquire(FieldInstanceReadWrite handle, Object holder, $type$ value) {
222            return UNSAFE.getAndAdd$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
223                                       handle.fieldOffset,
224                                       value);
225        }
226
227        @ForceInline
228        static $type$ getAndAddRelease(FieldInstanceReadWrite handle, Object holder, $type$ value) {
229            return UNSAFE.getAndAdd$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
230                                       handle.fieldOffset,
231                                       value);
232        }
233
234#end[AtomicAdd]
235#if[Bitwise]
236
237        @ForceInline
238        static $type$ getAndBitwiseOr(FieldInstanceReadWrite handle, Object holder, $type$ value) {
239            return UNSAFE.getAndBitwiseOr$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
240                                       handle.fieldOffset,
241                                       value);
242        }
243
244        @ForceInline
245        static $type$ getAndBitwiseOrRelease(FieldInstanceReadWrite handle, Object holder, $type$ value) {
246            return UNSAFE.getAndBitwiseOr$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
247                                       handle.fieldOffset,
248                                       value);
249        }
250
251        @ForceInline
252        static $type$ getAndBitwiseOrAcquire(FieldInstanceReadWrite handle, Object holder, $type$ value) {
253            return UNSAFE.getAndBitwiseOr$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
254                                       handle.fieldOffset,
255                                       value);
256        }
257
258        @ForceInline
259        static $type$ getAndBitwiseAnd(FieldInstanceReadWrite handle, Object holder, $type$ value) {
260            return UNSAFE.getAndBitwiseAnd$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
261                                       handle.fieldOffset,
262                                       value);
263        }
264
265        @ForceInline
266        static $type$ getAndBitwiseAndRelease(FieldInstanceReadWrite handle, Object holder, $type$ value) {
267            return UNSAFE.getAndBitwiseAnd$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
268                                       handle.fieldOffset,
269                                       value);
270        }
271
272        @ForceInline
273        static $type$ getAndBitwiseAndAcquire(FieldInstanceReadWrite handle, Object holder, $type$ value) {
274            return UNSAFE.getAndBitwiseAnd$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
275                                       handle.fieldOffset,
276                                       value);
277        }
278
279        @ForceInline
280        static $type$ getAndBitwiseXor(FieldInstanceReadWrite handle, Object holder, $type$ value) {
281            return UNSAFE.getAndBitwiseXor$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
282                                       handle.fieldOffset,
283                                       value);
284        }
285
286        @ForceInline
287        static $type$ getAndBitwiseXorRelease(FieldInstanceReadWrite handle, Object holder, $type$ value) {
288            return UNSAFE.getAndBitwiseXor$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
289                                       handle.fieldOffset,
290                                       value);
291        }
292
293        @ForceInline
294        static $type$ getAndBitwiseXorAcquire(FieldInstanceReadWrite handle, Object holder, $type$ value) {
295            return UNSAFE.getAndBitwiseXor$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
296                                       handle.fieldOffset,
297                                       value);
298        }
299#end[Bitwise]
300
301        static final VarForm FORM = new VarForm(FieldInstanceReadWrite.class, Object.class, $type$.class);
302    }
303
304
305    static class FieldStaticReadOnly extends VarHandle {
306        final Object base;
307        final long fieldOffset;
308#if[Object]
309        final Class<?> fieldType;
310#end[Object]
311
312        FieldStaticReadOnly(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
313            this(base, fieldOffset{#if[Object]?, fieldType}, FieldStaticReadOnly.FORM);
314        }
315
316        protected FieldStaticReadOnly(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType},
317                                      VarForm form) {
318            super(form);
319            this.base = base;
320            this.fieldOffset = fieldOffset;
321#if[Object]
322            this.fieldType = fieldType;
323#end[Object]
324        }
325
326        @Override
327        final MethodType accessModeTypeUncached(AccessMode accessMode) {
328            return accessMode.at.accessModeType(null, {#if[Object]?fieldType:$type$.class});
329        }
330
331        @ForceInline
332        static $type$ get(FieldStaticReadOnly handle) {
333            return UNSAFE.get$Type$(handle.base,
334                                 handle.fieldOffset);
335        }
336
337        @ForceInline
338        static $type$ getVolatile(FieldStaticReadOnly handle) {
339            return UNSAFE.get$Type$Volatile(handle.base,
340                                 handle.fieldOffset);
341        }
342
343        @ForceInline
344        static $type$ getOpaque(FieldStaticReadOnly handle) {
345            return UNSAFE.get$Type$Opaque(handle.base,
346                                 handle.fieldOffset);
347        }
348
349        @ForceInline
350        static $type$ getAcquire(FieldStaticReadOnly handle) {
351            return UNSAFE.get$Type$Acquire(handle.base,
352                                 handle.fieldOffset);
353        }
354
355        static final VarForm FORM = new VarForm(FieldStaticReadOnly.class, null, $type$.class);
356    }
357
358    static final class FieldStaticReadWrite extends FieldStaticReadOnly {
359
360        FieldStaticReadWrite(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
361            super(base, fieldOffset{#if[Object]?, fieldType}, FieldStaticReadWrite.FORM);
362        }
363
364        @ForceInline
365        static void set(FieldStaticReadWrite handle, $type$ value) {
366            UNSAFE.put$Type$(handle.base,
367                             handle.fieldOffset,
368                             {#if[Object]?handle.fieldType.cast(value):value});
369        }
370
371        @ForceInline
372        static void setVolatile(FieldStaticReadWrite handle, $type$ value) {
373            UNSAFE.put$Type$Volatile(handle.base,
374                                     handle.fieldOffset,
375                                     {#if[Object]?handle.fieldType.cast(value):value});
376        }
377
378        @ForceInline
379        static void setOpaque(FieldStaticReadWrite handle, $type$ value) {
380            UNSAFE.put$Type$Opaque(handle.base,
381                                   handle.fieldOffset,
382                                   {#if[Object]?handle.fieldType.cast(value):value});
383        }
384
385        @ForceInline
386        static void setRelease(FieldStaticReadWrite handle, $type$ value) {
387            UNSAFE.put$Type$Release(handle.base,
388                                    handle.fieldOffset,
389                                    {#if[Object]?handle.fieldType.cast(value):value});
390        }
391#if[CAS]
392
393        @ForceInline
394        static boolean compareAndSet(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
395            return UNSAFE.compareAndSet$Type$(handle.base,
396                                               handle.fieldOffset,
397                                               {#if[Object]?handle.fieldType.cast(expected):expected},
398                                               {#if[Object]?handle.fieldType.cast(value):value});
399        }
400
401
402        @ForceInline
403        static $type$ compareAndExchange(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
404            return UNSAFE.compareAndExchange$Type$(handle.base,
405                                               handle.fieldOffset,
406                                               {#if[Object]?handle.fieldType.cast(expected):expected},
407                                               {#if[Object]?handle.fieldType.cast(value):value});
408        }
409
410        @ForceInline
411        static $type$ compareAndExchangeAcquire(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
412            return UNSAFE.compareAndExchange$Type$Acquire(handle.base,
413                                               handle.fieldOffset,
414                                               {#if[Object]?handle.fieldType.cast(expected):expected},
415                                               {#if[Object]?handle.fieldType.cast(value):value});
416        }
417
418        @ForceInline
419        static $type$ compareAndExchangeRelease(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
420            return UNSAFE.compareAndExchange$Type$Release(handle.base,
421                                               handle.fieldOffset,
422                                               {#if[Object]?handle.fieldType.cast(expected):expected},
423                                               {#if[Object]?handle.fieldType.cast(value):value});
424        }
425
426        @ForceInline
427        static boolean weakCompareAndSetPlain(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
428            return UNSAFE.weakCompareAndSet$Type$Plain(handle.base,
429                                               handle.fieldOffset,
430                                               {#if[Object]?handle.fieldType.cast(expected):expected},
431                                               {#if[Object]?handle.fieldType.cast(value):value});
432        }
433
434        @ForceInline
435        static boolean weakCompareAndSet(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
436            return UNSAFE.weakCompareAndSet$Type$(handle.base,
437                                               handle.fieldOffset,
438                                               {#if[Object]?handle.fieldType.cast(expected):expected},
439                                               {#if[Object]?handle.fieldType.cast(value):value});
440        }
441
442        @ForceInline
443        static boolean weakCompareAndSetAcquire(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
444            return UNSAFE.weakCompareAndSet$Type$Acquire(handle.base,
445                                               handle.fieldOffset,
446                                               {#if[Object]?handle.fieldType.cast(expected):expected},
447                                               {#if[Object]?handle.fieldType.cast(value):value});
448        }
449
450        @ForceInline
451        static boolean weakCompareAndSetRelease(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
452            return UNSAFE.weakCompareAndSet$Type$Release(handle.base,
453                                               handle.fieldOffset,
454                                               {#if[Object]?handle.fieldType.cast(expected):expected},
455                                               {#if[Object]?handle.fieldType.cast(value):value});
456        }
457
458        @ForceInline
459        static $type$ getAndSet(FieldStaticReadWrite handle, $type$ value) {
460            return UNSAFE.getAndSet$Type$(handle.base,
461                                          handle.fieldOffset,
462                                          {#if[Object]?handle.fieldType.cast(value):value});
463        }
464
465        @ForceInline
466        static $type$ getAndSetAcquire(FieldStaticReadWrite handle, $type$ value) {
467            return UNSAFE.getAndSet$Type$Acquire(handle.base,
468                                          handle.fieldOffset,
469                                          {#if[Object]?handle.fieldType.cast(value):value});
470        }
471
472        @ForceInline
473        static $type$ getAndSetRelease(FieldStaticReadWrite handle, $type$ value) {
474            return UNSAFE.getAndSet$Type$Release(handle.base,
475                                          handle.fieldOffset,
476                                          {#if[Object]?handle.fieldType.cast(value):value});
477        }
478#end[CAS]
479#if[AtomicAdd]
480
481        @ForceInline
482        static $type$ getAndAdd(FieldStaticReadWrite handle, $type$ value) {
483            return UNSAFE.getAndAdd$Type$(handle.base,
484                                       handle.fieldOffset,
485                                       value);
486        }
487
488        @ForceInline
489        static $type$ getAndAddAcquire(FieldStaticReadWrite handle, $type$ value) {
490            return UNSAFE.getAndAdd$Type$Acquire(handle.base,
491                                       handle.fieldOffset,
492                                       value);
493        }
494
495        @ForceInline
496        static $type$ getAndAddRelease(FieldStaticReadWrite handle, $type$ value) {
497            return UNSAFE.getAndAdd$Type$Release(handle.base,
498                                       handle.fieldOffset,
499                                       value);
500        }
501#end[AtomicAdd]
502#if[Bitwise]
503
504        @ForceInline
505        static $type$ getAndBitwiseOr(FieldStaticReadWrite handle, $type$ value) {
506            return UNSAFE.getAndBitwiseOr$Type$(handle.base,
507                                       handle.fieldOffset,
508                                       value);
509        }
510
511        @ForceInline
512        static $type$ getAndBitwiseOrRelease(FieldStaticReadWrite handle, $type$ value) {
513            return UNSAFE.getAndBitwiseOr$Type$Release(handle.base,
514                                       handle.fieldOffset,
515                                       value);
516        }
517
518        @ForceInline
519        static $type$ getAndBitwiseOrAcquire(FieldStaticReadWrite handle, $type$ value) {
520            return UNSAFE.getAndBitwiseOr$Type$Acquire(handle.base,
521                                       handle.fieldOffset,
522                                       value);
523        }
524
525        @ForceInline
526        static $type$ getAndBitwiseAnd(FieldStaticReadWrite handle, $type$ value) {
527            return UNSAFE.getAndBitwiseAnd$Type$(handle.base,
528                                       handle.fieldOffset,
529                                       value);
530        }
531
532        @ForceInline
533        static $type$ getAndBitwiseAndRelease(FieldStaticReadWrite handle, $type$ value) {
534            return UNSAFE.getAndBitwiseAnd$Type$Release(handle.base,
535                                       handle.fieldOffset,
536                                       value);
537        }
538
539        @ForceInline
540        static $type$ getAndBitwiseAndAcquire(FieldStaticReadWrite handle, $type$ value) {
541            return UNSAFE.getAndBitwiseAnd$Type$Acquire(handle.base,
542                                       handle.fieldOffset,
543                                       value);
544        }
545
546        @ForceInline
547        static $type$ getAndBitwiseXor(FieldStaticReadWrite handle, $type$ value) {
548            return UNSAFE.getAndBitwiseXor$Type$(handle.base,
549                                       handle.fieldOffset,
550                                       value);
551        }
552
553        @ForceInline
554        static $type$ getAndBitwiseXorRelease(FieldStaticReadWrite handle, $type$ value) {
555            return UNSAFE.getAndBitwiseXor$Type$Release(handle.base,
556                                       handle.fieldOffset,
557                                       value);
558        }
559
560        @ForceInline
561        static $type$ getAndBitwiseXorAcquire(FieldStaticReadWrite handle, $type$ value) {
562            return UNSAFE.getAndBitwiseXor$Type$Acquire(handle.base,
563                                       handle.fieldOffset,
564                                       value);
565        }
566#end[Bitwise]
567
568        static final VarForm FORM = new VarForm(FieldStaticReadWrite.class, null, $type$.class);
569    }
570
571
572    static final class Array extends VarHandle {
573        final int abase;
574        final int ashift;
575#if[Object]
576        final Class<{#if[Object]??:$type$[]}> arrayType;
577        final Class<?> componentType;
578#end[Object]
579
580        Array(int abase, int ashift{#if[Object]?, Class<?> arrayType}) {
581            super(Array.FORM);
582            this.abase = abase;
583            this.ashift = ashift;
584#if[Object]
585            this.arrayType = {#if[Object]?arrayType:$type$[].class};
586            this.componentType = arrayType.getComponentType();
587#end[Object]
588        }
589
590        @Override
591        final MethodType accessModeTypeUncached(AccessMode accessMode) {
592            return accessMode.at.accessModeType({#if[Object]?arrayType:$type$[].class}, {#if[Object]?arrayType.getComponentType():$type$.class}, int.class);
593        }
594
595#if[Object]
596        @ForceInline
597        static Object runtimeTypeCheck(Array handle, Object[] oarray, Object value) {
598            if (handle.arrayType == oarray.getClass()) {
599                // Fast path: static array type same as argument array type
600                return handle.componentType.cast(value);
601            } else {
602                // Slow path: check value against argument array component type
603                return reflectiveTypeCheck(oarray, value);
604            }
605        }
606
607        @ForceInline
608        static Object reflectiveTypeCheck(Object[] oarray, Object value) {
609            try {
610                return oarray.getClass().getComponentType().cast(value);
611            } catch (ClassCastException e) {
612                throw new ArrayStoreException();
613            }
614        }
615#end[Object]
616
617        @ForceInline
618        static $type$ get(Array handle, Object oarray, int index) {
619#if[Object]
620            Object[] array = (Object[]) handle.arrayType.cast(oarray);
621#else[Object]
622            $type$[] array = ($type$[]) oarray;
623#end[Object]
624            return array[index];
625        }
626
627        @ForceInline
628        static void set(Array handle, Object oarray, int index, $type$ value) {
629#if[Object]
630            Object[] array = (Object[]) handle.arrayType.cast(oarray);
631#else[Object]
632            $type$[] array = ($type$[]) oarray;
633#end[Object]
634            array[index] = {#if[Object]?handle.componentType.cast(value):value};
635        }
636
637        @ForceInline
638        static $type$ getVolatile(Array handle, Object oarray, int index) {
639#if[Object]
640            Object[] array = (Object[]) handle.arrayType.cast(oarray);
641#else[Object]
642            $type$[] array = ($type$[]) oarray;
643#end[Object]
644            return UNSAFE.get$Type$Volatile(array,
645                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase);
646        }
647
648        @ForceInline
649        static void setVolatile(Array handle, Object oarray, int index, $type$ value) {
650#if[Object]
651            Object[] array = (Object[]) handle.arrayType.cast(oarray);
652#else[Object]
653            $type$[] array = ($type$[]) oarray;
654#end[Object]
655            UNSAFE.put$Type$Volatile(array,
656                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
657                    {#if[Object]?runtimeTypeCheck(handle, array, value):value});
658        }
659
660        @ForceInline
661        static $type$ getOpaque(Array handle, Object oarray, int index) {
662#if[Object]
663            Object[] array = (Object[]) handle.arrayType.cast(oarray);
664#else[Object]
665            $type$[] array = ($type$[]) oarray;
666#end[Object]
667            return UNSAFE.get$Type$Opaque(array,
668                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase);
669        }
670
671        @ForceInline
672        static void setOpaque(Array handle, Object oarray, int index, $type$ value) {
673#if[Object]
674            Object[] array = (Object[]) handle.arrayType.cast(oarray);
675#else[Object]
676            $type$[] array = ($type$[]) oarray;
677#end[Object]
678            UNSAFE.put$Type$Opaque(array,
679                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
680                    {#if[Object]?runtimeTypeCheck(handle, array, value):value});
681        }
682
683        @ForceInline
684        static $type$ getAcquire(Array handle, Object oarray, int index) {
685#if[Object]
686            Object[] array = (Object[]) handle.arrayType.cast(oarray);
687#else[Object]
688            $type$[] array = ($type$[]) oarray;
689#end[Object]
690            return UNSAFE.get$Type$Acquire(array,
691                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase);
692        }
693
694        @ForceInline
695        static void setRelease(Array handle, Object oarray, int index, $type$ value) {
696#if[Object]
697            Object[] array = (Object[]) handle.arrayType.cast(oarray);
698#else[Object]
699            $type$[] array = ($type$[]) oarray;
700#end[Object]
701            UNSAFE.put$Type$Release(array,
702                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
703                    {#if[Object]?runtimeTypeCheck(handle, array, value):value});
704        }
705#if[CAS]
706
707        @ForceInline
708        static boolean compareAndSet(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
709#if[Object]
710            Object[] array = (Object[]) handle.arrayType.cast(oarray);
711#else[Object]
712            $type$[] array = ($type$[]) oarray;
713#end[Object]
714            return UNSAFE.compareAndSet$Type$(array,
715                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
716                    {#if[Object]?handle.componentType.cast(expected):expected},
717                    {#if[Object]?runtimeTypeCheck(handle, array, value):value});
718        }
719
720        @ForceInline
721        static $type$ compareAndExchange(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
722#if[Object]
723            Object[] array = (Object[]) handle.arrayType.cast(oarray);
724#else[Object]
725            $type$[] array = ($type$[]) oarray;
726#end[Object]
727            return UNSAFE.compareAndExchange$Type$(array,
728                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
729                    {#if[Object]?handle.componentType.cast(expected):expected},
730                    {#if[Object]?runtimeTypeCheck(handle, array, value):value});
731        }
732
733        @ForceInline
734        static $type$ compareAndExchangeAcquire(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
735#if[Object]
736            Object[] array = (Object[]) handle.arrayType.cast(oarray);
737#else[Object]
738            $type$[] array = ($type$[]) oarray;
739#end[Object]
740            return UNSAFE.compareAndExchange$Type$Acquire(array,
741                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
742                    {#if[Object]?handle.componentType.cast(expected):expected},
743                    {#if[Object]?runtimeTypeCheck(handle, array, value):value});
744        }
745
746        @ForceInline
747        static $type$ compareAndExchangeRelease(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
748#if[Object]
749            Object[] array = (Object[]) handle.arrayType.cast(oarray);
750#else[Object]
751            $type$[] array = ($type$[]) oarray;
752#end[Object]
753            return UNSAFE.compareAndExchange$Type$Release(array,
754                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
755                    {#if[Object]?handle.componentType.cast(expected):expected},
756                    {#if[Object]?runtimeTypeCheck(handle, array, value):value});
757        }
758
759        @ForceInline
760        static boolean weakCompareAndSetPlain(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
761#if[Object]
762            Object[] array = (Object[]) handle.arrayType.cast(oarray);
763#else[Object]
764            $type$[] array = ($type$[]) oarray;
765#end[Object]
766            return UNSAFE.weakCompareAndSet$Type$Plain(array,
767                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
768                    {#if[Object]?handle.componentType.cast(expected):expected},
769                    {#if[Object]?runtimeTypeCheck(handle, array, value):value});
770        }
771
772        @ForceInline
773        static boolean weakCompareAndSet(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
774#if[Object]
775            Object[] array = (Object[]) handle.arrayType.cast(oarray);
776#else[Object]
777            $type$[] array = ($type$[]) oarray;
778#end[Object]
779            return UNSAFE.weakCompareAndSet$Type$(array,
780                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
781                    {#if[Object]?handle.componentType.cast(expected):expected},
782                    {#if[Object]?runtimeTypeCheck(handle, array, value):value});
783        }
784
785        @ForceInline
786        static boolean weakCompareAndSetAcquire(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
787#if[Object]
788            Object[] array = (Object[]) handle.arrayType.cast(oarray);
789#else[Object]
790            $type$[] array = ($type$[]) oarray;
791#end[Object]
792            return UNSAFE.weakCompareAndSet$Type$Acquire(array,
793                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
794                    {#if[Object]?handle.componentType.cast(expected):expected},
795                    {#if[Object]?runtimeTypeCheck(handle, array, value):value});
796        }
797
798        @ForceInline
799        static boolean weakCompareAndSetRelease(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
800#if[Object]
801            Object[] array = (Object[]) handle.arrayType.cast(oarray);
802#else[Object]
803            $type$[] array = ($type$[]) oarray;
804#end[Object]
805            return UNSAFE.weakCompareAndSet$Type$Release(array,
806                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
807                    {#if[Object]?handle.componentType.cast(expected):expected},
808                    {#if[Object]?runtimeTypeCheck(handle, array, value):value});
809        }
810
811        @ForceInline
812        static $type$ getAndSet(Array handle, Object oarray, int index, $type$ value) {
813#if[Object]
814            Object[] array = (Object[]) handle.arrayType.cast(oarray);
815#else[Object]
816            $type$[] array = ($type$[]) oarray;
817#end[Object]
818            return UNSAFE.getAndSet$Type$(array,
819                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
820                    {#if[Object]?runtimeTypeCheck(handle, array, value):value});
821        }
822
823        @ForceInline
824        static $type$ getAndSetAcquire(Array handle, Object oarray, int index, $type$ value) {
825#if[Object]
826            Object[] array = (Object[]) handle.arrayType.cast(oarray);
827#else[Object]
828            $type$[] array = ($type$[]) oarray;
829#end[Object]
830            return UNSAFE.getAndSet$Type$Acquire(array,
831                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
832                    {#if[Object]?runtimeTypeCheck(handle, array, value):value});
833        }
834
835        @ForceInline
836        static $type$ getAndSetRelease(Array handle, Object oarray, int index, $type$ value) {
837#if[Object]
838            Object[] array = (Object[]) handle.arrayType.cast(oarray);
839#else[Object]
840            $type$[] array = ($type$[]) oarray;
841#end[Object]
842            return UNSAFE.getAndSet$Type$Release(array,
843                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
844                    {#if[Object]?runtimeTypeCheck(handle, array, value):value});
845        }
846#end[CAS]
847#if[AtomicAdd]
848
849        @ForceInline
850        static $type$ getAndAdd(Array handle, Object oarray, int index, $type$ value) {
851            $type$[] array = ($type$[]) oarray;
852            return UNSAFE.getAndAdd$Type$(array,
853                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
854                    value);
855        }
856
857        @ForceInline
858        static $type$ getAndAddAcquire(Array handle, Object oarray, int index, $type$ value) {
859            $type$[] array = ($type$[]) oarray;
860            return UNSAFE.getAndAdd$Type$Acquire(array,
861                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
862                    value);
863        }
864
865        @ForceInline
866        static $type$ getAndAddRelease(Array handle, Object oarray, int index, $type$ value) {
867            $type$[] array = ($type$[]) oarray;
868            return UNSAFE.getAndAdd$Type$Release(array,
869                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
870                    value);
871        }
872#end[AtomicAdd]
873#if[Bitwise]
874
875        @ForceInline
876        static $type$ getAndBitwiseOr(Array handle, Object oarray, int index, $type$ value) {
877            $type$[] array = ($type$[]) oarray;
878            return UNSAFE.getAndBitwiseOr$Type$(array,
879                                       (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
880                                       value);
881        }
882
883        @ForceInline
884        static $type$ getAndBitwiseOrRelease(Array handle, Object oarray, int index, $type$ value) {
885            $type$[] array = ($type$[]) oarray;
886            return UNSAFE.getAndBitwiseOr$Type$Release(array,
887                                       (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
888                                       value);
889        }
890
891        @ForceInline
892        static $type$ getAndBitwiseOrAcquire(Array handle, Object oarray, int index, $type$ value) {
893            $type$[] array = ($type$[]) oarray;
894            return UNSAFE.getAndBitwiseOr$Type$Acquire(array,
895                                       (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
896                                       value);
897        }
898
899        @ForceInline
900        static $type$ getAndBitwiseAnd(Array handle, Object oarray, int index, $type$ value) {
901            $type$[] array = ($type$[]) oarray;
902            return UNSAFE.getAndBitwiseAnd$Type$(array,
903                                       (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
904                                       value);
905        }
906
907        @ForceInline
908        static $type$ getAndBitwiseAndRelease(Array handle, Object oarray, int index, $type$ value) {
909            $type$[] array = ($type$[]) oarray;
910            return UNSAFE.getAndBitwiseAnd$Type$Release(array,
911                                       (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
912                                       value);
913        }
914
915        @ForceInline
916        static $type$ getAndBitwiseAndAcquire(Array handle, Object oarray, int index, $type$ value) {
917            $type$[] array = ($type$[]) oarray;
918            return UNSAFE.getAndBitwiseAnd$Type$Acquire(array,
919                                       (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
920                                       value);
921        }
922
923        @ForceInline
924        static $type$ getAndBitwiseXor(Array handle, Object oarray, int index, $type$ value) {
925            $type$[] array = ($type$[]) oarray;
926            return UNSAFE.getAndBitwiseXor$Type$(array,
927                                       (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
928                                       value);
929        }
930
931        @ForceInline
932        static $type$ getAndBitwiseXorRelease(Array handle, Object oarray, int index, $type$ value) {
933            $type$[] array = ($type$[]) oarray;
934            return UNSAFE.getAndBitwiseXor$Type$Release(array,
935                                       (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
936                                       value);
937        }
938
939        @ForceInline
940        static $type$ getAndBitwiseXorAcquire(Array handle, Object oarray, int index, $type$ value) {
941            $type$[] array = ($type$[]) oarray;
942            return UNSAFE.getAndBitwiseXor$Type$Acquire(array,
943                                       (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
944                                       value);
945        }
946#end[Bitwise]
947
948        static final VarForm FORM = new VarForm(Array.class, {#if[Object]?Object[].class:$type$[].class}, {#if[Object]?Object.class:$type$.class}, int.class);
949    }
950}
951