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        @ForceInline
596        static $type$ get(Array handle, Object oarray, int index) {
597#if[Object]
598            Object[] array = (Object[]) handle.arrayType.cast(oarray);
599#else[Object]
600            $type$[] array = ($type$[]) oarray;
601#end[Object]
602            return array[index];
603        }
604
605        @ForceInline
606        static void set(Array handle, Object oarray, int index, $type$ value) {
607#if[Object]
608            Object[] array = (Object[]) handle.arrayType.cast(oarray);
609#else[Object]
610            $type$[] array = ($type$[]) oarray;
611#end[Object]
612            array[index] = {#if[Object]?handle.componentType.cast(value):value};
613        }
614
615        @ForceInline
616        static $type$ getVolatile(Array handle, Object oarray, int index) {
617#if[Object]
618            Object[] array = (Object[]) handle.arrayType.cast(oarray);
619#else[Object]
620            $type$[] array = ($type$[]) oarray;
621#end[Object]
622            return UNSAFE.get$Type$Volatile(array,
623                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase);
624        }
625
626        @ForceInline
627        static void setVolatile(Array handle, Object oarray, int index, $type$ value) {
628#if[Object]
629            Object[] array = (Object[]) handle.arrayType.cast(oarray);
630#else[Object]
631            $type$[] array = ($type$[]) oarray;
632#end[Object]
633            UNSAFE.put$Type$Volatile(array,
634                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
635                    {#if[Object]?handle.componentType.cast(value):value});
636        }
637
638        @ForceInline
639        static $type$ getOpaque(Array handle, Object oarray, int index) {
640#if[Object]
641            Object[] array = (Object[]) handle.arrayType.cast(oarray);
642#else[Object]
643            $type$[] array = ($type$[]) oarray;
644#end[Object]
645            return UNSAFE.get$Type$Opaque(array,
646                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase);
647        }
648
649        @ForceInline
650        static void setOpaque(Array handle, Object oarray, int index, $type$ value) {
651#if[Object]
652            Object[] array = (Object[]) handle.arrayType.cast(oarray);
653#else[Object]
654            $type$[] array = ($type$[]) oarray;
655#end[Object]
656            UNSAFE.put$Type$Opaque(array,
657                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
658                    {#if[Object]?handle.componentType.cast(value):value});
659        }
660
661        @ForceInline
662        static $type$ getAcquire(Array handle, Object oarray, int index) {
663#if[Object]
664            Object[] array = (Object[]) handle.arrayType.cast(oarray);
665#else[Object]
666            $type$[] array = ($type$[]) oarray;
667#end[Object]
668            return UNSAFE.get$Type$Acquire(array,
669                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase);
670        }
671
672        @ForceInline
673        static void setRelease(Array handle, Object oarray, int index, $type$ value) {
674#if[Object]
675            Object[] array = (Object[]) handle.arrayType.cast(oarray);
676#else[Object]
677            $type$[] array = ($type$[]) oarray;
678#end[Object]
679            UNSAFE.put$Type$Release(array,
680                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
681                    {#if[Object]?handle.componentType.cast(value):value});
682        }
683#if[CAS]
684
685        @ForceInline
686        static boolean compareAndSet(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
687#if[Object]
688            Object[] array = (Object[]) handle.arrayType.cast(oarray);
689#else[Object]
690            $type$[] array = ($type$[]) oarray;
691#end[Object]
692            return UNSAFE.compareAndSet$Type$(array,
693                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
694                    {#if[Object]?handle.componentType.cast(expected):expected},
695                    {#if[Object]?handle.componentType.cast(value):value});
696        }
697
698        @ForceInline
699        static $type$ compareAndExchange(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
700#if[Object]
701            Object[] array = (Object[]) handle.arrayType.cast(oarray);
702#else[Object]
703            $type$[] array = ($type$[]) oarray;
704#end[Object]
705            return UNSAFE.compareAndExchange$Type$(array,
706                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
707                    {#if[Object]?handle.componentType.cast(expected):expected},
708                    {#if[Object]?handle.componentType.cast(value):value});
709        }
710
711        @ForceInline
712        static $type$ compareAndExchangeAcquire(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
713#if[Object]
714            Object[] array = (Object[]) handle.arrayType.cast(oarray);
715#else[Object]
716            $type$[] array = ($type$[]) oarray;
717#end[Object]
718            return UNSAFE.compareAndExchange$Type$Acquire(array,
719                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
720                    {#if[Object]?handle.componentType.cast(expected):expected},
721                    {#if[Object]?handle.componentType.cast(value):value});
722        }
723
724        @ForceInline
725        static $type$ compareAndExchangeRelease(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
726#if[Object]
727            Object[] array = (Object[]) handle.arrayType.cast(oarray);
728#else[Object]
729            $type$[] array = ($type$[]) oarray;
730#end[Object]
731            return UNSAFE.compareAndExchange$Type$Release(array,
732                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
733                    {#if[Object]?handle.componentType.cast(expected):expected},
734                    {#if[Object]?handle.componentType.cast(value):value});
735        }
736
737        @ForceInline
738        static boolean weakCompareAndSetPlain(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
739#if[Object]
740            Object[] array = (Object[]) handle.arrayType.cast(oarray);
741#else[Object]
742            $type$[] array = ($type$[]) oarray;
743#end[Object]
744            return UNSAFE.weakCompareAndSet$Type$Plain(array,
745                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
746                    {#if[Object]?handle.componentType.cast(expected):expected},
747                    {#if[Object]?handle.componentType.cast(value):value});
748        }
749
750        @ForceInline
751        static boolean weakCompareAndSet(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
752#if[Object]
753            Object[] array = (Object[]) handle.arrayType.cast(oarray);
754#else[Object]
755            $type$[] array = ($type$[]) oarray;
756#end[Object]
757            return UNSAFE.weakCompareAndSet$Type$(array,
758                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
759                    {#if[Object]?handle.componentType.cast(expected):expected},
760                    {#if[Object]?handle.componentType.cast(value):value});
761        }
762
763        @ForceInline
764        static boolean weakCompareAndSetAcquire(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
765#if[Object]
766            Object[] array = (Object[]) handle.arrayType.cast(oarray);
767#else[Object]
768            $type$[] array = ($type$[]) oarray;
769#end[Object]
770            return UNSAFE.weakCompareAndSet$Type$Acquire(array,
771                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
772                    {#if[Object]?handle.componentType.cast(expected):expected},
773                    {#if[Object]?handle.componentType.cast(value):value});
774        }
775
776        @ForceInline
777        static boolean weakCompareAndSetRelease(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
778#if[Object]
779            Object[] array = (Object[]) handle.arrayType.cast(oarray);
780#else[Object]
781            $type$[] array = ($type$[]) oarray;
782#end[Object]
783            return UNSAFE.weakCompareAndSet$Type$Release(array,
784                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
785                    {#if[Object]?handle.componentType.cast(expected):expected},
786                    {#if[Object]?handle.componentType.cast(value):value});
787        }
788
789        @ForceInline
790        static $type$ getAndSet(Array handle, Object oarray, int index, $type$ value) {
791#if[Object]
792            Object[] array = (Object[]) handle.arrayType.cast(oarray);
793#else[Object]
794            $type$[] array = ($type$[]) oarray;
795#end[Object]
796            return UNSAFE.getAndSet$Type$(array,
797                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
798                    {#if[Object]?handle.componentType.cast(value):value});
799        }
800
801        @ForceInline
802        static $type$ getAndSetAcquire(Array handle, Object oarray, int index, $type$ value) {
803#if[Object]
804            Object[] array = (Object[]) handle.arrayType.cast(oarray);
805#else[Object]
806            $type$[] array = ($type$[]) oarray;
807#end[Object]
808            return UNSAFE.getAndSet$Type$Acquire(array,
809                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
810                    {#if[Object]?handle.componentType.cast(value):value});
811        }
812
813        @ForceInline
814        static $type$ getAndSetRelease(Array handle, Object oarray, int index, $type$ value) {
815#if[Object]
816            Object[] array = (Object[]) handle.arrayType.cast(oarray);
817#else[Object]
818            $type$[] array = ($type$[]) oarray;
819#end[Object]
820            return UNSAFE.getAndSet$Type$Release(array,
821                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
822                    {#if[Object]?handle.componentType.cast(value):value});
823        }
824#end[CAS]
825#if[AtomicAdd]
826
827        @ForceInline
828        static $type$ getAndAdd(Array handle, Object oarray, int index, $type$ value) {
829            $type$[] array = ($type$[]) oarray;
830            return UNSAFE.getAndAdd$Type$(array,
831                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
832                    value);
833        }
834
835        @ForceInline
836        static $type$ getAndAddAcquire(Array handle, Object oarray, int index, $type$ value) {
837            $type$[] array = ($type$[]) oarray;
838            return UNSAFE.getAndAdd$Type$Acquire(array,
839                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
840                    value);
841        }
842
843        @ForceInline
844        static $type$ getAndAddRelease(Array handle, Object oarray, int index, $type$ value) {
845            $type$[] array = ($type$[]) oarray;
846            return UNSAFE.getAndAdd$Type$Release(array,
847                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
848                    value);
849        }
850#end[AtomicAdd]
851#if[Bitwise]
852
853        @ForceInline
854        static $type$ getAndBitwiseOr(Array handle, Object oarray, int index, $type$ value) {
855            $type$[] array = ($type$[]) oarray;
856            return UNSAFE.getAndBitwiseOr$Type$(array,
857                                       (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
858                                       value);
859        }
860
861        @ForceInline
862        static $type$ getAndBitwiseOrRelease(Array handle, Object oarray, int index, $type$ value) {
863            $type$[] array = ($type$[]) oarray;
864            return UNSAFE.getAndBitwiseOr$Type$Release(array,
865                                       (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
866                                       value);
867        }
868
869        @ForceInline
870        static $type$ getAndBitwiseOrAcquire(Array handle, Object oarray, int index, $type$ value) {
871            $type$[] array = ($type$[]) oarray;
872            return UNSAFE.getAndBitwiseOr$Type$Acquire(array,
873                                       (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
874                                       value);
875        }
876
877        @ForceInline
878        static $type$ getAndBitwiseAnd(Array handle, Object oarray, int index, $type$ value) {
879            $type$[] array = ($type$[]) oarray;
880            return UNSAFE.getAndBitwiseAnd$Type$(array,
881                                       (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
882                                       value);
883        }
884
885        @ForceInline
886        static $type$ getAndBitwiseAndRelease(Array handle, Object oarray, int index, $type$ value) {
887            $type$[] array = ($type$[]) oarray;
888            return UNSAFE.getAndBitwiseAnd$Type$Release(array,
889                                       (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
890                                       value);
891        }
892
893        @ForceInline
894        static $type$ getAndBitwiseAndAcquire(Array handle, Object oarray, int index, $type$ value) {
895            $type$[] array = ($type$[]) oarray;
896            return UNSAFE.getAndBitwiseAnd$Type$Acquire(array,
897                                       (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
898                                       value);
899        }
900
901        @ForceInline
902        static $type$ getAndBitwiseXor(Array handle, Object oarray, int index, $type$ value) {
903            $type$[] array = ($type$[]) oarray;
904            return UNSAFE.getAndBitwiseXor$Type$(array,
905                                       (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
906                                       value);
907        }
908
909        @ForceInline
910        static $type$ getAndBitwiseXorRelease(Array handle, Object oarray, int index, $type$ value) {
911            $type$[] array = ($type$[]) oarray;
912            return UNSAFE.getAndBitwiseXor$Type$Release(array,
913                                       (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
914                                       value);
915        }
916
917        @ForceInline
918        static $type$ getAndBitwiseXorAcquire(Array handle, Object oarray, int index, $type$ value) {
919            $type$[] array = ($type$[]) oarray;
920            return UNSAFE.getAndBitwiseXor$Type$Acquire(array,
921                                       (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
922                                       value);
923        }
924#end[Bitwise]
925
926        static final VarForm FORM = new VarForm(Array.class, {#if[Object]?Object[].class:$type$[].class}, {#if[Object]?Object.class:$type$.class}, int.class);
927    }
928}
929