Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/jcl/src/java.base/share/classes/jdk/internal/misc/Unsafe.java
12558 views
1
/*[INCLUDE-IF Sidecar19-SE]*/
2
/*******************************************************************************
3
* Copyright (c) 2017, 2022 IBM Corp. and others
4
*
5
* This program and the accompanying materials are made available under
6
* the terms of the Eclipse Public License 2.0 which accompanies this
7
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
* or the Apache License, Version 2.0 which accompanies this distribution and
9
* is available at https://www.apache.org/licenses/LICENSE-2.0.
10
*
11
* This Source Code may also be made available under the following
12
* Secondary Licenses when the conditions for such availability set
13
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
* General Public License, version 2 with the GNU Classpath
15
* Exception [1] and GNU General Public License, version 2 with the
16
* OpenJDK Assembly Exception [2].
17
*
18
* [1] https://www.gnu.org/software/classpath/license.html
19
* [2] http://openjdk.java.net/legal/assembly-exception.html
20
*
21
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
22
*******************************************************************************/
23
package jdk.internal.misc;
24
25
import com.ibm.oti.vm.VM;
26
import com.ibm.oti.vm.VMLangAccess;
27
28
import java.lang.reflect.Field;
29
import java.security.ProtectionDomain;
30
import java.util.Objects;
31
/*[IF JAVA_SPEC_VERSION >= 12]*/
32
import java.nio.ByteBuffer;
33
import sun.nio.ch.DirectBuffer;
34
import jdk.internal.ref.Cleaner;
35
/*[ENDIF] JAVA_SPEC_VERSION >= 12 */
36
37
public final class Unsafe {
38
39
/* Prevents this class from being instantiated. */
40
private Unsafe() {}
41
42
/* unsafe instance */
43
private static final Unsafe theUnsafe;
44
45
/**
46
* Represents an invalid field offset value.
47
*/
48
public static final int INVALID_FIELD_OFFSET;
49
50
/**
51
* Starting offset of byte array.
52
*/
53
public static final int ARRAY_BYTE_BASE_OFFSET;
54
55
/**
56
* Starting offset of int array.
57
*/
58
public static final int ARRAY_INT_BASE_OFFSET;
59
60
/**
61
* Starting offset of long array.
62
*/
63
public static final int ARRAY_LONG_BASE_OFFSET;
64
65
/**
66
* Starting offset of float array.
67
*/
68
public static final int ARRAY_FLOAT_BASE_OFFSET;
69
70
/**
71
* Starting offset of double array.
72
*/
73
public static final int ARRAY_DOUBLE_BASE_OFFSET;
74
75
/**
76
* Starting offset of short array.
77
*/
78
public static final int ARRAY_SHORT_BASE_OFFSET;
79
80
/**
81
* Starting offset of char array.
82
*/
83
public static final int ARRAY_CHAR_BASE_OFFSET;
84
85
/**
86
* Starting offset of boolean array.
87
*/
88
public static final int ARRAY_BOOLEAN_BASE_OFFSET;
89
90
/**
91
* Starting offset of Object array.
92
*/
93
public static final int ARRAY_OBJECT_BASE_OFFSET;
94
95
/**
96
* Index size of byte array in bytes.
97
*/
98
public static final int ARRAY_BYTE_INDEX_SCALE;
99
100
/**
101
* Index size of int array in bytes.
102
*/
103
public static final int ARRAY_INT_INDEX_SCALE;
104
105
/**
106
* Index size of long array in bytes.
107
*/
108
public static final int ARRAY_LONG_INDEX_SCALE;
109
110
/**
111
* Index size of float array in bytes.
112
*/
113
public static final int ARRAY_FLOAT_INDEX_SCALE;
114
115
/**
116
* Index size of double array in bytes.
117
*/
118
public static final int ARRAY_DOUBLE_INDEX_SCALE;
119
120
/**
121
* Index size of short array in bytes.
122
*/
123
public static final int ARRAY_SHORT_INDEX_SCALE;
124
125
/**
126
* Index size of char array in bytes.
127
*/
128
public static final int ARRAY_CHAR_INDEX_SCALE;
129
130
/**
131
* Index size of boolean array in bytes.
132
*/
133
public static final int ARRAY_BOOLEAN_INDEX_SCALE;
134
135
/**
136
* Index size of Object array in bytes.
137
*/
138
public static final int ARRAY_OBJECT_INDEX_SCALE;
139
140
/**
141
* Size of address on machine in use.
142
*/
143
public static final int ADDRESS_SIZE;
144
145
/*
146
* internal helpers
147
*/
148
/* true if machine is big endian, false otherwise. */
149
private static final boolean IS_BIG_ENDIAN;
150
/* true if addresses are aligned in memory, false otherwise. */
151
private static final boolean UNALIGNED_ACCESS;
152
153
/* Size of int in bytes. */
154
private static final int BYTES_IN_INT = 4;
155
/* Number of bits in a short. */
156
private static final int BITS_IN_SHORT = 16;
157
/* Number of bits in a byte. */
158
private static final int BITS_IN_BYTE = 8;
159
160
/* 8 bit mask (long) */
161
private static final long BYTE_MASK = 0xFFL;
162
/* 32 bit mask (long) */
163
private static final long INT_MASK = 0xFFFFFFFFL;
164
/* 16 bit mask (long) */
165
private static final long SHORT_MASK = 0xFFFFL;
166
/* 8 bit mask (int) */
167
private static final int BYTE_MASK_INT = (int) BYTE_MASK;
168
/* 16 bit mask (int) */
169
private static final int SHORT_MASK_INT = (int) SHORT_MASK;
170
171
/* Mask aligns offset to be int addressable (all but bottom two bits). */
172
private static final int INT_OFFSET_ALIGN_MASK = 0xFFFFFFFC;
173
174
/*
175
* For int shift instructions (ishr, iushr, ishl), only the low 5 bits of the
176
* shift amount are considered.
177
*/
178
private static final int BC_SHIFT_INT_MASK = 0b11111;
179
180
/*
181
* For long shift instructions (lshr, lushr, lshl) only the low 6 bits of the
182
* shift amount are considered.
183
*/
184
private static final int BC_SHIFT_LONG_MASK = 0b111111;
185
186
/* Mask byte offset of an int. */
187
private static final long BYTE_OFFSET_MASK = 0b11L;
188
189
static {
190
registerNatives();
191
192
theUnsafe = new Unsafe();
193
194
INVALID_FIELD_OFFSET = -1;
195
196
/* All OpenJ9 array types have the same array base offset. To limit
197
* JNI calls arrayBaseOffset is only called once in this block and the
198
* value used for each array base offset variable.
199
*/
200
ARRAY_BYTE_BASE_OFFSET = theUnsafe.arrayBaseOffset(byte[].class);
201
ARRAY_INT_BASE_OFFSET = ARRAY_BYTE_BASE_OFFSET;
202
ARRAY_LONG_BASE_OFFSET = ARRAY_BYTE_BASE_OFFSET;
203
ARRAY_FLOAT_BASE_OFFSET = ARRAY_BYTE_BASE_OFFSET;
204
ARRAY_DOUBLE_BASE_OFFSET = ARRAY_BYTE_BASE_OFFSET;
205
ARRAY_SHORT_BASE_OFFSET = ARRAY_BYTE_BASE_OFFSET;
206
ARRAY_CHAR_BASE_OFFSET = ARRAY_BYTE_BASE_OFFSET;
207
ARRAY_BOOLEAN_BASE_OFFSET = ARRAY_BYTE_BASE_OFFSET;
208
ARRAY_OBJECT_BASE_OFFSET = ARRAY_BYTE_BASE_OFFSET;
209
210
ARRAY_BYTE_INDEX_SCALE = theUnsafe.arrayIndexScale(byte[].class);
211
ARRAY_INT_INDEX_SCALE = theUnsafe.arrayIndexScale(int[].class);
212
ARRAY_LONG_INDEX_SCALE = theUnsafe.arrayIndexScale(long[].class);
213
ARRAY_FLOAT_INDEX_SCALE = theUnsafe.arrayIndexScale(float[].class);
214
ARRAY_DOUBLE_INDEX_SCALE = theUnsafe.arrayIndexScale(double[].class);
215
ARRAY_SHORT_INDEX_SCALE = theUnsafe.arrayIndexScale(short[].class);
216
ARRAY_CHAR_INDEX_SCALE = theUnsafe.arrayIndexScale(char[].class);
217
ARRAY_BOOLEAN_INDEX_SCALE = theUnsafe.arrayIndexScale(boolean[].class);
218
ARRAY_OBJECT_INDEX_SCALE = theUnsafe.arrayIndexScale(Object[].class);
219
220
ADDRESS_SIZE = VM.ADDRESS_SIZE;
221
IS_BIG_ENDIAN = VM.IS_BIG_ENDIAN;
222
223
/* Unaligned access is currently supported on all platforms */
224
UNALIGNED_ACCESS = true;
225
}
226
227
/* Attach jdk.internal.misc.Unsafe natives. */
228
private static native void registerNatives();
229
230
/**
231
* Gets the value of the byte in the obj parameter referenced by offset.
232
* This is a non-volatile operation.
233
*
234
* @param obj object from which to retrieve the value
235
* @param offset position of the value in obj
236
* @return byte value stored in obj
237
*/
238
public native byte getByte(Object obj, long offset);
239
240
/**
241
* Sets the value of the byte in the obj parameter at memory offset.
242
* This is a non-volatile operation.
243
*
244
* @param obj object into which to store the value
245
* @param offset position of the value in obj
246
* @param value byte to store in obj
247
*/
248
public native void putByte(Object obj, long offset, byte value);
249
250
/**
251
* Gets the value of the int in the obj parameter referenced by offset.
252
* This is a non-volatile operation.
253
*
254
* @param obj object from which to retrieve the value
255
* @param offset position of the value in obj
256
* @return int value stored in obj
257
*/
258
public native int getInt(Object obj, long offset);
259
260
/**
261
* Sets the value of the int in the obj parameter at memory offset.
262
* This is a non-volatile operation.
263
*
264
* @param obj object into which to store the value
265
* @param offset position of the value in obj
266
* @param value int to store in obj
267
*/
268
public native void putInt(Object obj, long offset, int value);
269
270
/**
271
* Gets the value of the long in the obj parameter referenced by offset.
272
* This is a non-volatile operation.
273
*
274
* @param obj object from which to retrieve the value
275
* @param offset position of the value in obj
276
* @return long value stored in obj
277
*/
278
public native long getLong(Object obj, long offset);
279
280
/**
281
* Sets the value of the long in the obj parameter at memory offset.
282
* This is a non-volatile operation.
283
*
284
* @param obj object into which to store the value
285
* @param offset position of the value in obj
286
* @param value long to store in obj
287
*/
288
public native void putLong(Object obj, long offset, long value);
289
290
/**
291
* Gets the value of the float in the obj parameter referenced by offset.
292
* This is a non-volatile operation.
293
*
294
* @param obj object from which to retrieve the value
295
* @param offset position of the value in obj
296
* @return float value stored in obj
297
*/
298
public native float getFloat(Object obj, long offset);
299
300
/**
301
* Sets the value of the float in the obj parameter at memory offset.
302
* This is a non-volatile operation.
303
*
304
* @param obj object into which to store the value
305
* @param offset position of the value in obj
306
* @param value float to store in obj
307
*/
308
public native void putFloat(Object obj, long offset, float value);
309
310
/**
311
* Gets the value of the double in the obj parameter referenced by offset.
312
* This is a non-volatile operation.
313
*
314
* @param obj object from which to retrieve the value
315
* @param offset position of the value in obj
316
* @return double value stored in obj
317
*/
318
public native double getDouble(Object obj, long offset);
319
320
/**
321
* Sets the value of the double in the obj parameter at memory offset.
322
* This is a non-volatile operation.
323
*
324
* @param obj object into which to store the value
325
* @param offset position of the value in obj
326
* @param value double to store in obj
327
*/
328
public native void putDouble(Object obj, long offset, double value);
329
330
/**
331
* Gets the value of the short in the obj parameter referenced by offset.
332
* This is a non-volatile operation.
333
*
334
* @param obj object from which to retrieve the value
335
* @param offset position of the value in obj
336
* @return short value stored in obj
337
*/
338
public native short getShort(Object obj, long offset);
339
340
/**
341
* Sets the value of the short in the obj parameter at memory offset.
342
* This is a non-volatile operation.
343
*
344
* @param obj object into which to store the value
345
* @param offset position of the value in obj
346
* @param value short to store in obj
347
*/
348
public native void putShort(Object obj, long offset, short value);
349
350
/**
351
* Gets the value of the char in the obj parameter referenced by offset.
352
* This is a non-volatile operation.
353
*
354
* @param obj object from which to retrieve the value
355
* @param offset position of the value in obj
356
* @return char value stored in obj
357
*/
358
public native char getChar(Object obj, long offset);
359
360
/**
361
* Sets the value of the char in the obj parameter at memory offset.
362
* This is a non-volatile operation.
363
*
364
* @param obj object into which to store the value
365
* @param offset position of the value in obj
366
* @param value char to store in obj
367
*/
368
public native void putChar(Object obj, long offset, char value);
369
370
/**
371
* Gets the value of the boolean in the obj parameter referenced by offset.
372
* This is a non-volatile operation.
373
*
374
* @param obj object from which to retrieve the value
375
* @param offset position of the value in obj
376
* @return boolean value stored in obj
377
*/
378
public native boolean getBoolean(Object obj, long offset);
379
380
/**
381
* Sets the value of the boolean in the obj parameter at memory offset.
382
* This is a non-volatile operation.
383
*
384
* @param obj object into which to store the value
385
* @param offset position of the value in obj
386
* @param value boolean to store in obj
387
*/
388
public native void putBoolean(Object obj, long offset, boolean value);
389
390
/**
391
* Gets the value of the Object in the obj parameter referenced by offset.
392
* This is a non-volatile operation.
393
*
394
* @param obj object from which to retrieve the value
395
* @param offset position of the value in obj
396
* @return Object value stored in obj
397
*/
398
public native Object getObject(Object obj, long offset);
399
400
/**
401
* Sets the value of the Object in the obj parameter at memory offset.
402
* This is a non-volatile operation.
403
*
404
* @param obj object into which to store the value
405
* @param offset position of the value in obj
406
* @param value Object to store in obj
407
*/
408
public native void putObject(Object obj, long offset, Object value);
409
410
/*[IF JAVA_SPEC_VERSION >= 12]*/
411
/**
412
* Gets the value of the Object in the obj parameter referenced by offset.
413
* This is a non-volatile operation.
414
*
415
* @param obj object from which to retrieve the value
416
* @param offset position of the value in obj
417
* @return Object value stored in obj
418
*/
419
public native Object getReference(Object obj, long offset);
420
421
/**
422
* Sets the value of the Object in the obj parameter at memory offset.
423
* This is a non-volatile operation.
424
*
425
* @param obj object into which to store the value
426
* @param offset position of the value in obj
427
* @param value Object to store in obj
428
*/
429
public native void putReference(Object obj, long offset, Object value);
430
/*[ENDIF] JAVA_SPEC_VERSION >= 12 */
431
432
/**
433
* Gets the value of the Object in memory referenced by address.
434
* This is a non-volatile operation.
435
*
436
* NOTE: native implementation is a stub.
437
*
438
* @param address position of the object in memory
439
* @return Object value stored in memory
440
*/
441
public native Object getUncompressedObject(long address);
442
443
/**
444
* Allocates a block of memory
445
*
446
* @param size number of bytes to allocate
447
* @return address of allocated buffer
448
*
449
* @throws IllegalArgumentException if size is negative
450
*/
451
public native long allocateDBBMemory(long size);
452
453
/**
454
* Reallocates a block of memory.
455
*
456
* @param address of old buffer
457
* @param size new size of buffer to allocate
458
* @return address of new buffer
459
*
460
* @throws IllegalArgumentException if size is negative
461
*/
462
public native long reallocateDBBMemory(long address, long size);
463
464
/**
465
* Removes the block from the list. Note that the pointers are located
466
* immediately before the address value.
467
*
468
* @param address of buffer
469
*/
470
public native void freeDBBMemory(long address);
471
472
/**
473
* Returns the size of a page in memory in bytes.
474
*
475
* @return size of memory page
476
*/
477
public native int pageSize();
478
479
/**
480
* Creates a class out of a given array of bytes with a ProtectionDomain.
481
*
482
* @param name binary name of the class, null if the name is not known
483
* @param b a byte array of the class data. The bytes should have the format of a valid
484
* class file as defined by The JVM Spec
485
* @param offset offset of the start of the class data in b
486
* @param bLength length of the class data
487
* @param cl used to load the class being built. If null, the default
488
* system ClassLoader will be used
489
* @param pd ProtectionDomain for new class
490
* @return the Class created from the byte array and ProtectionDomain parameters
491
*
492
* @throws IndexOutOfBoundsException if offset or bLength is negative, or if offset + bLength
493
* is greater than the length of b
494
*/
495
public native Class<?> defineClass0(String name, byte[] b, int offset, int bLength, ClassLoader cl,
496
ProtectionDomain pd);
497
498
/**
499
* Allocate instance of class parameter.
500
*
501
* @param c class to allocate
502
* @return instance of class c
503
*
504
* @throws InstantiationException if class c cannot be instantiated
505
*/
506
public native Object allocateInstance(Class<?> c) throws InstantiationException;
507
508
/**
509
* Throw Throwable parameter.
510
*
511
* @param t Throwable to execute
512
*
513
* @throws NullPointerException if Throwable is null
514
*/
515
public native void throwException(Throwable t);
516
517
/**
518
* Atomically sets the parameter value at offset in obj if the compare value
519
* matches the existing value in the object.
520
* The get operation has memory semantics of getVolatile.
521
* The set operation has the memory semantics of setVolatile.
522
*
523
* @param obj object into which to store the value
524
* @param offset location to compare and store value in obj
525
* @param compareValue value that is expected to be in obj at offset
526
* @param setValue value that will be set in obj at offset if compare is successful
527
* @return boolean value indicating whether the field was updated
528
*/
529
public final native boolean compareAndSetInt(Object obj, long offset, int compareValue, int setValue);
530
531
/**
532
* Atomically sets the parameter value at offset in obj if the compare value
533
* matches the existing value in the object.
534
* The get operation has memory semantics of getVolatile.
535
* The set operation has the memory semantics of setVolatile.
536
*
537
* @param obj object into which to store the value
538
* @param offset location to compare and store value in obj
539
* @param compareValue value that is expected to be in obj at offset
540
* @param exchangeValue value that will be set in obj at offset if compare is successful
541
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
542
*/
543
public final native int compareAndExchangeInt(Object obj, long offset, int compareValue, int exchangeValue);
544
545
/**
546
* Atomically sets the parameter value at offset in obj if the compare value
547
* matches the existing value in the object.
548
* The get operation has memory semantics of getVolatile.
549
* The set operation has the memory semantics of setVolatile.
550
*
551
* @param obj object into which to store the value
552
* @param offset location to compare and store value in obj
553
* @param compareValue value that is expected to be in obj at offset
554
* @param setValue value that will be set in obj at offset if compare is successful
555
* @return boolean value indicating whether the field was updated
556
*/
557
public final native boolean compareAndSetLong(Object obj, long offset, long compareValue, long setValue);
558
559
/**
560
* Atomically sets the parameter value at offset in obj if the compare value
561
* matches the existing value in the object.
562
* The get operation has memory semantics of getVolatile.
563
* The set operation has the memory semantics of setVolatile.
564
*
565
* @param obj object into which to store the value
566
* @param offset location to compare and store value in obj
567
* @param compareValue value that is expected to be in obj at offset
568
* @param exchangeValue value that will be set in obj at offset if compare is successful
569
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
570
*/
571
public final native long compareAndExchangeLong(Object obj, long offset, long compareValue, long exchangeVale);
572
573
/**
574
* Atomically sets the parameter value at offset in obj if the compare value
575
* matches the existing value in the object.
576
* The get operation has memory semantics of getVolatile.
577
* The set operation has the memory semantics of setVolatile.
578
*
579
* @param obj object into which to store the value
580
* @param offset location to compare and store value in obj
581
* @param compareValue value that is expected to be in obj at offset
582
* @param setValue value that will be set in obj at offset if compare is successful
583
* @return boolean value indicating whether the field was updated
584
*/
585
public final native boolean compareAndSetObject(Object obj, long offset, Object compareValue, Object setValue);
586
587
/**
588
* Atomically sets the parameter value at offset in obj if the compare value
589
* matches the existing value in the object.
590
* The get operation has memory semantics of getVolatile.
591
* The set operation has the memory semantics of setVolatile.
592
*
593
* @param obj object into which to store the value
594
* @param offset location to compare and store value in obj
595
* @param compareValue value that is expected to be in obj at offset
596
* @param exchangeValue value that will be set in obj at offset if compare is successful
597
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
598
*/
599
public final native Object compareAndExchangeObject(Object obj, long offset, Object compareValue,
600
Object exchangeValue);
601
602
/*[IF JAVA_SPEC_VERSION >= 12]*/
603
/**
604
* Atomically sets the parameter value at offset in obj if the compare value
605
* matches the existing value in the object.
606
* The get operation has memory semantics of getVolatile.
607
* The set operation has the memory semantics of setVolatile.
608
*
609
* @param obj object into which to store the value
610
* @param offset location to compare and store value in obj
611
* @param compareValue value that is expected to be in obj at offset
612
* @param setValue value that will be set in obj at offset if compare is successful
613
* @return boolean value indicating whether the field was updated
614
*/
615
public final native boolean compareAndSetReference(Object obj, long offset, Object compareValue, Object setValue);
616
617
/**
618
* Atomically sets the parameter value at offset in obj if the compare value
619
* matches the existing value in the object.
620
* The get operation has memory semantics of getVolatile.
621
* The set operation has the memory semantics of setVolatile.
622
*
623
* @param obj object into which to store the value
624
* @param offset location to compare and store value in obj
625
* @param compareValue value that is expected to be in obj at offset
626
* @param exchangeValue value that will be set in obj at offset if compare is successful
627
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
628
*/
629
public final native Object compareAndExchangeReference(Object obj, long offset, Object compareValue,
630
Object exchangeValue);
631
/*[ENDIF] JAVA_SPEC_VERSION >= 12 */
632
633
/**
634
* Atomically gets the value of the byte in the obj parameter referenced by offset.
635
*
636
* @param obj object from which to retrieve the value
637
* @param offset position of the value in obj
638
* @return byte value stored in obj
639
*/
640
public native byte getByteVolatile(Object obj, long offset);
641
642
/**
643
* Atomically sets the value of the byte in the obj parameter at memory offset.
644
*
645
* @param obj object into which to store the value
646
* @param offset position of the value in obj
647
* @param value byte to store in obj
648
*/
649
public native void putByteVolatile(Object obj, long offset, byte value);
650
651
/**
652
* Atomically gets the value of the int in the obj parameter referenced by offset.
653
*
654
* @param obj object from which to retrieve the value
655
* @param offset position of the value in obj
656
* @return int value stored in obj
657
*/
658
public native int getIntVolatile(Object obj, long offset);
659
660
/**
661
* Atomically sets the value of the int in the obj parameter at memory offset.
662
*
663
* @param obj object into which to store the value
664
* @param offset position of the value in obj
665
* @param value int to store in obj
666
*/
667
public native void putIntVolatile(Object obj, long offset, int value);
668
669
/**
670
* Atomically gets the value of the long in the obj parameter referenced by offset.
671
*
672
* @param obj object from which to retrieve the value
673
* @param offset position of the value in obj
674
* @return long value stored in obj
675
*/
676
public native long getLongVolatile(Object obj, long offset);
677
678
/**
679
* Atomically sets the value of the long in the obj parameter at memory offset.
680
*
681
* @param obj object into which to store the value
682
* @param offset position of the value in obj
683
* @param value long to store in obj
684
*/
685
public native void putLongVolatile(Object obj, long offset, long value);
686
687
/**
688
* Atomically gets the value of the float in the obj parameter referenced by offset.
689
*
690
* @param obj object from which to retrieve the value
691
* @param offset position of the value in obj
692
* @return float value stored in obj
693
*/
694
public native float getFloatVolatile(Object obj, long offset);
695
696
/**
697
* Atomically sets the value of the float in the obj parameter at memory offset.
698
*
699
* @param obj object into which to store the value
700
* @param offset position of the value in obj
701
* @param value float to store in obj
702
*/
703
public native void putFloatVolatile(Object obj, long offset, float value);
704
705
/**
706
* Atomically gets the value of the double in the obj parameter referenced by offset.
707
*
708
* @param obj object from which to retrieve the value
709
* @param offset position of the value in obj
710
* @return double value stored in obj
711
*/
712
public native double getDoubleVolatile(Object obj, long offset);
713
714
/**
715
* Atomically sets the value of the double in the obj parameter at memory offset.
716
*
717
* @param obj object into which to store the value
718
* @param offset position of the value in obj
719
* @param value double to store in obj
720
*/
721
public native void putDoubleVolatile(Object obj, long offset, double value);
722
723
/**
724
* Atomically gets the value of the short in the obj parameter referenced by offset.
725
*
726
* @param obj object from which to retrieve the value
727
* @param offset position of the value in obj
728
* @return short value stored in obj
729
*/
730
public native short getShortVolatile(Object obj, long offset);
731
732
/**
733
* Atomically sets the value of the short in the obj parameter at memory offset.
734
*
735
* @param obj object into which to store the value
736
* @param offset position of the value in obj
737
* @param value short to store in obj
738
*/
739
public native void putShortVolatile(Object obj, long offset, short value);
740
741
/**
742
* Atomically gets the value of the char in the obj parameter referenced by offset.
743
*
744
* @param obj object from which to retrieve the value
745
* @param offset position of the value in obj
746
* @return char value stored in obj
747
*/
748
public native char getCharVolatile(Object obj, long offset);
749
750
/**
751
* Atomically sets the value of the char in the obj parameter at memory offset.
752
*
753
* @param obj object into which to store the value
754
* @param offset position of the value in obj
755
* @param value char to store in obj
756
*/
757
public native void putCharVolatile(Object obj, long offset, char value);
758
759
/**
760
* Atomically gets the value of the boolean in the obj parameter referenced by offset.
761
*
762
* @param obj object from which to retrieve the value
763
* @param offset position of the value in obj
764
* @return boolean value stored in obj
765
*/
766
public native boolean getBooleanVolatile(Object obj, long offset);
767
768
/**
769
* Atomically sets the value of the boolean in the obj parameter at memory offset.
770
*
771
* @param obj object into which to store the value
772
* @param offset position of the value in obj
773
* @param value boolean to store in obj
774
*/
775
public native void putBooleanVolatile(Object obj, long offset, boolean value);
776
777
/**
778
* Atomically gets the value of the Object in the obj parameter referenced by offset.
779
*
780
* @param obj object from which to retrieve the value
781
* @param offset position of the value in obj
782
* @return Object value stored in obj
783
*/
784
public native Object getObjectVolatile(Object obj, long offset);
785
786
/**
787
* Atomically sets the value of the Object in the obj parameter at memory offset.
788
*
789
* @param obj object into which to store the value
790
* @param offset position of the value in obj
791
* @param value Object to store in obj
792
*/
793
public native void putObjectVolatile(Object obj, long offset, Object value);
794
795
/*[IF JAVA_SPEC_VERSION >= 12]*/
796
/**
797
* Atomically gets the value of the Object in the obj parameter referenced by offset.
798
*
799
* @param obj object from which to retrieve the value
800
* @param offset position of the value in obj
801
* @return Object value stored in obj
802
*/
803
public native Object getReferenceVolatile(Object obj, long offset);
804
805
/**
806
* Atomically sets the value of the Object in the obj parameter at memory offset.
807
*
808
* @param obj object into which to store the value
809
* @param offset position of the value in obj
810
* @param value Object to store in obj
811
*/
812
public native void putReferenceVolatile(Object obj, long offset, Object value);
813
/*[ENDIF] JAVA_SPEC_VERSION >= 12 */
814
815
/**
816
* Makes permit available for thread parameter.
817
*
818
* @param thread the thread to unpark. If null, method has no effect
819
*/
820
public native void unpark(Object thread);
821
822
/**
823
* Disables current thread unless permit is available. Thread will not be
824
* scheduled until unpark provides permit.
825
*
826
* @param isAbsolute if true park timeout should be absolute
827
* @param time parks for time in ns.
828
* ms is expected if isAbsolute is set to true.
829
*/
830
public native void park(boolean isAbsolute, long time);
831
832
/**
833
* Inserts an acquire memory fence, ensuring that no loads before this fence
834
* are reordered with any loads/stores after the fence.
835
*/
836
public native void loadFence();
837
838
/**
839
* Inserts a release memory fence, ensuring that no stores before this fence
840
* are reordered with any loads/stores after the fence.
841
*/
842
public native void storeFence();
843
844
/**
845
* Inserts a complete memory fence, ensuring that no loads/stores before this
846
* fence are reordered with any loads/stores after the fence.
847
*/
848
public native void fullFence();
849
850
/*
851
* jdk.internal.misc.Unsafe natives
852
*/
853
/*
854
* Allocates a block of memory.
855
* If size passed is 0, no memory will be allocated.
856
*
857
* @param size requested size of memory in bytes
858
* @return starting address of memory
859
*
860
* @throws IllegalArgumentException if size is not valid
861
*/
862
private native long allocateMemory0(long size);
863
864
/*
865
* Reallocates a block of memory.
866
* If size passed is 0, no memory will be allocated.
867
*
868
* @param size requested size of memory in bytes
869
* @return starting address of memory
870
*
871
* @throws IllegalArgumentException if size is not valid
872
*/
873
private native long reallocateMemory0(long address, long size);
874
875
/*
876
* Removes the block from the list. Note that the pointers are located
877
* immediately before the startIndex value.
878
*
879
* @param startIndex memory address
880
*
881
* @throws IllegalArgumentException if startIndex is not valid
882
*/
883
private native void freeMemory0(long startIndex);
884
885
/*
886
* Set object at offset in obj parameter.
887
*
888
* @param obj object into which to store the value
889
* @param startIndex position of the value in obj
890
* @param size the number of bytes to be set to the value
891
* @param replace overwrite memory with this value
892
*
893
* @throws IllegalArgumentException if startIndex is illegal in obj, or if size is invalid
894
*/
895
private native void setMemory0(Object obj, long startIndex, long size, byte replace);
896
897
/*
898
* Copy bytes from source object to destination.
899
*
900
* @param srcObj object to copy from
901
* @param srcOffset location in srcObj to start copy
902
* @param destObj object to copy into
903
* @param destOffset location in destObj to start copy
904
* @param size the number of bytes to be copied
905
*
906
* @throws IllegalArgumentException if srcOffset is illegal in srcObj,
907
* if destOffset is illegal in destObj, or if size is invalid
908
*/
909
private native void copyMemory0(Object srcObj, long srcOffset, Object destObj, long destOffset, long size);
910
911
/*
912
* Copy bytes from source object to destination in reverse order.
913
* Memory is reversed in elementSize chunks.
914
*
915
* @param srcObj object to copy from
916
* @param srcOffset location in srcObj to start copy
917
* @param destObj object to copy into
918
* @param destOffset location in destObj to start copy
919
* @param copySize the number of bytes to be copied, a multiple of elementSize
920
* @param elementSize the size in bytes of elements that will be reversed
921
*
922
* @throws IllegalArgumentException if srcOffset is illegal in srcObj,
923
* if destOffset is illegal in destObj, if copySize is invalid or copySize is not
924
* a multiple of elementSize
925
*/
926
private native void copySwapMemory0(Object srcObj, long srcOffset, Object destObj, long destOffset, long copySize,
927
long elementSize);
928
929
/*
930
* Returns byte offset to field.
931
*
932
* @param field which contains desired class or interface
933
* @return offset to start of class or interface
934
*
935
* @throws IllegalArgumentException if field is static
936
*/
937
private native long objectFieldOffset0(Field field);
938
939
/*[IF JAVA_SPEC_VERSION >= 10]*/
940
/*
941
* Returns byte offset to field.
942
*
943
* @param class with desired field
944
* @param string name of desired field
945
* @return offset to start of class or interface
946
*
947
* @throws IllegalArgumentException if field is static
948
*/
949
private native long objectFieldOffset1(Class<?> c, String fieldName);
950
/*[ENDIF] JAVA_SPEC_VERSION >= 10 */
951
952
/*
953
* Returns byte offset to start of static class or interface.
954
*
955
* @param field which contains desired class or interface
956
* @return offset to start of class or interface
957
*
958
* @throws NullPointerException if field parameter is null
959
* @throws IllegalArgumentException if field is not static
960
*/
961
private native long staticFieldOffset0(Field field);
962
963
/*
964
* Returns class or interface described by static Field.
965
*
966
* @param field contains desired class or interface
967
* @return class or interface in static field
968
*
969
* @throws NullPointerException if field parameter is null
970
* @throws IllegalArgumentException if field is not static
971
*/
972
private native Object staticFieldBase0(Field field);
973
974
/*
975
* Determines whether class has been initialized.
976
*
977
* @param class to verify
978
* @return true if method has not been initialized, false otherwise
979
*/
980
private native boolean shouldBeInitialized0(Class<?> c);
981
982
/*
983
* Initializes class parameter if it has not been already.
984
*
985
* @param c class to initialize if not already
986
*
987
* @throws NullPointerException if class is null
988
*/
989
private native void ensureClassInitialized0(Class<?> c);
990
991
/*
992
* Return offset in array object at which the array data storage begins.
993
*
994
* @param c class array
995
* @return offset at base of array
996
*
997
* @throws NullPointerException if the class parameter is null
998
* @throws IllegalArgumentException if class is not an array
999
*/
1000
private native int arrayBaseOffset0(Class<?> c);
1001
1002
/*
1003
* Return index size of array in bytes.
1004
*
1005
* @param c class array
1006
* @return returns index size of array in bytes
1007
*
1008
* @throws NullPointerException if class is null
1009
* @throws IllegalArgumentException if class is not an array
1010
*/
1011
private native int arrayIndexScale0(Class<?> c);
1012
1013
/* @return size of address on machine in use */
1014
private native int addressSize0();
1015
1016
/*[IF JAVA_SPEC_VERSION < 17]*/
1017
/*
1018
* Define a class without making it known to the class loader.
1019
*
1020
* @param hostingClass the context for class loader + linkage, and
1021
* access control + protection domain
1022
* @param bytecodes class file bytes
1023
* @param constPatches entries that are not "null" are replacements
1024
* for the corresponding const pool entries in the 'bytecodes' data
1025
* @return class created from bytecodes and constPatches
1026
*/
1027
private native Class<?> defineAnonymousClass0(Class<?> hostingClass, byte[] bytecodes, Object[] constPatches);
1028
/*[ENDIF] JAVA_SPEC_VERSION < 17 */
1029
1030
/*
1031
* Get the load average in the system.
1032
*
1033
* NOTE: native implementation is a stub.
1034
*
1035
* @param loadavg array of elements
1036
* @param numberOfElements number of samples
1037
* @return load average
1038
*/
1039
private native int getLoadAverage0(double[] loadavg, int numberOfElements);
1040
1041
/* @return true if addresses are aligned in memory, false otherwise */
1042
private native boolean unalignedAccess0();
1043
1044
/* @return true if machine is big endian, false otherwise */
1045
private native boolean isBigEndian0();
1046
1047
/*[IF JAVA_SPEC_VERSION >= 14]*/
1048
/**
1049
* Make sure that the virtual memory at address "addr" for length "len" has
1050
* been written back from the cache to physical memory.
1051
* Throw RuntimeException if cache flushing is not enabled on the runtime OS.
1052
*
1053
* @param addr address to the start of the block of virtual memory to be flushed
1054
* @param len length of the block of virtual memory to be flushed
1055
* @throws RuntimeException if cache flushing not enabled
1056
*/
1057
public native void writebackMemory(long addr, long len);
1058
1059
/**
1060
* Check if cache writeback is possible on the runtime platform by checking
1061
* if there is OS and/or CPU support.
1062
*
1063
* @return true if cache writeback is possible, else false
1064
*/
1065
public static native boolean isWritebackEnabled();
1066
/*[ENDIF] JAVA_SPEC_VERSION >= 14 */
1067
1068
/**
1069
* Getter for unsafe instance.
1070
*
1071
* @return unsafe instance
1072
*/
1073
public static Unsafe getUnsafe() {
1074
return theUnsafe;
1075
}
1076
1077
/**
1078
* Gets the address in the obj parameter referenced by offset.
1079
* This is a non-volatile operation.
1080
*
1081
* @param obj object from which to retrieve the address
1082
* @param address location to retrieve the address in obj
1083
* @return address stored in obj
1084
*/
1085
public long getAddress(Object obj, long address) {
1086
long result;
1087
1088
if (BYTES_IN_INT == ADDRESS_SIZE) {
1089
result = Integer.toUnsignedLong(getInt(obj, address));
1090
} else {
1091
result = getLong(obj, address);
1092
}
1093
1094
return result;
1095
}
1096
1097
/**
1098
* Sets an address in the obj parameter at memory offset.
1099
* This is a non-volatile operation.
1100
*
1101
* @param obj object into which to store the address
1102
* @param address position to store value in obj
1103
* @param value address to store in obj
1104
*/
1105
public void putAddress(Object obj, long address, long value) {
1106
if (BYTES_IN_INT == ADDRESS_SIZE) {
1107
putInt(obj, address, (int) value);
1108
} else {
1109
putLong(obj, address, value);
1110
}
1111
}
1112
1113
/**
1114
* Gets the value of the byte in memory referenced by offset.
1115
* This is a non-volatile operation.
1116
*
1117
* @param locations where to retrieve value in memory
1118
* @return byte value stored in memory
1119
*/
1120
public byte getByte(long offset) {
1121
return getByte(null, offset);
1122
}
1123
1124
/**
1125
* Sets the value of the byte at memory offset.
1126
* This is a non-volatile operation.
1127
*
1128
* @param offset location to retrieve value in memory
1129
* @param value byte to store in memory
1130
*/
1131
public void putByte(long offset, byte value) {
1132
putByte(null, offset, value);
1133
}
1134
1135
/**
1136
* Gets the value of the int in memory referenced by offset.
1137
* This is a non-volatile operation.
1138
*
1139
* @param offset location to retrieve value in memory
1140
* @return int value stored in memory
1141
*/
1142
public int getInt(long offset) {
1143
return getInt(null, offset);
1144
}
1145
1146
/**
1147
* Sets the value of the int at memory offset.
1148
* This is a non-volatile operation.
1149
*
1150
* @param offset location to retrieve value in memory
1151
* @param value int to store in memory
1152
*/
1153
public void putInt(long offset, int value) {
1154
putInt(null, offset, value);
1155
}
1156
1157
/**
1158
* Gets the value of the long in memory referenced by offset.
1159
* This is a non-volatile operation.
1160
*
1161
* @param offset location to retrieve value in memory
1162
* @return long value stored in memory
1163
*/
1164
public long getLong(long offset) {
1165
return getLong(null, offset);
1166
}
1167
1168
/**
1169
* Sets the value of the long at memory offset.
1170
* This is a non-volatile operation.
1171
*
1172
* @param offset location to retrieve value in memory
1173
* @param value long to store in memory
1174
*/
1175
public void putLong(long offset, long value) {
1176
putLong(null, offset, value);
1177
}
1178
1179
/**
1180
* Gets the value of the float in memory referenced by offset.
1181
* This is a non-volatile operation.
1182
*
1183
* @param offset location to retrieve value in memory
1184
* @return float value stored in memory
1185
*/
1186
public float getFloat(long offset) {
1187
return getFloat(null, offset);
1188
}
1189
1190
/**
1191
* Sets the value of the float at memory offset.
1192
* This is a non-volatile operation.
1193
*
1194
* @param offset location to retrieve value in memory
1195
* @param value float to store in memory
1196
*/
1197
public void putFloat(long offset, float value) {
1198
putFloat(null, offset, value);
1199
}
1200
1201
/**
1202
* Gets the value of the double in memory referenced by offset.
1203
* This is a non-volatile operation.
1204
*
1205
* @param offset location to retrieve value in memory
1206
* @return double value stored in memory
1207
*/
1208
public double getDouble(long offset) {
1209
return getDouble(null, offset);
1210
}
1211
1212
/**
1213
* Sets the value of the double at memory offset.
1214
* This is a non-volatile operation.
1215
*
1216
* @param offset location to retrieve value in memory
1217
* @param value double to store in memory
1218
*/
1219
public void putDouble(long offset, double value) {
1220
putDouble(null, offset, value);
1221
}
1222
1223
/**
1224
* Gets the value of the short in memory referenced by offset.
1225
* This is a non-volatile operation.
1226
*
1227
* @param offset location to retrieve value in memory
1228
* @return short value stored in memory
1229
*/
1230
public short getShort(long offset) {
1231
return getShort(null, offset);
1232
}
1233
1234
/**
1235
* Sets the value of the short at memory offset.
1236
* This is a non-volatile operation.
1237
*
1238
* @param offset location to retrieve value in memory
1239
* @param value short to store in memory
1240
*/
1241
public void putShort(long offset, short value) {
1242
putShort(null, offset, value);
1243
}
1244
1245
/**
1246
* Gets the value of the char in memory referenced by offset.
1247
* This is a non-volatile operation.
1248
*
1249
* @param offset location to retrieve value in memory
1250
* @return char value stored in memory
1251
*/
1252
public char getChar(long offset) {
1253
return getChar(null, offset);
1254
}
1255
1256
/**
1257
* Sets the value of the char at memory offset.
1258
* This is a non-volatile operation.
1259
*
1260
* @param offset location to retrieve value in memory
1261
* @param value char to store in memory
1262
*/
1263
public void putChar(long offset, char value) {
1264
putChar(null, offset, value);
1265
}
1266
1267
/**
1268
* Gets the address value in memory at location of address parameter.
1269
* This is a non-volatile operation.
1270
*
1271
* @param address location to retrieve the address in memory
1272
* @return address stored in obj
1273
*/
1274
public long getAddress(long address) {
1275
return getAddress(null, address);
1276
1277
}
1278
1279
/**
1280
* Sets an address value at the location by the address parameter.
1281
* This is a non-volatile operation.
1282
*
1283
* @param address location to store value in memory
1284
* @param value address to store at address parameter
1285
*/
1286
public void putAddress(long address, long value) {
1287
putAddress(null, address, value);
1288
}
1289
1290
/**
1291
* Allocates a block of memory.
1292
* If size passed is 0, no memory will be allocated.
1293
*
1294
* @param size requested size of memory in bytes
1295
* @return starting address of memory, or 0 if size is 0
1296
*
1297
* @throws OutOfMemoryError if no memory can be allocated
1298
* @throws IllegalArgumentException if size is not valid
1299
*/
1300
public long allocateMemory(long size) {
1301
allocateMemoryChecks(size);
1302
1303
if (0L == size) {
1304
return 0L;
1305
}
1306
1307
long address = allocateMemory0(size);
1308
1309
if (0L == address) {
1310
throw new OutOfMemoryError();
1311
}
1312
1313
return address;
1314
}
1315
1316
/**
1317
* Reallocates a block of memory.
1318
* If size passed is 0, no memory will be allocated.
1319
*
1320
* @param size requested size of memory in bytes
1321
* @return starting address of memory, or 0 if size is 0
1322
*
1323
* @throws OutOfMemoryError if no memory can be allocated
1324
* @throws IllegalArgumentException if size is not valid
1325
*/
1326
public long reallocateMemory(long address, long size) {
1327
reallocateMemoryChecks(address, size);
1328
1329
if (0L == size) {
1330
freeMemory(address);
1331
return 0L;
1332
}
1333
1334
long addressNew;
1335
if (0L == address) {
1336
addressNew = allocateMemory0(size);
1337
} else {
1338
addressNew = reallocateMemory0(address, size);
1339
}
1340
1341
if (0L == addressNew) {
1342
throw new OutOfMemoryError();
1343
}
1344
1345
return addressNew;
1346
}
1347
1348
/**
1349
* Set the byte at the index and size in obj parameter.
1350
*
1351
* @param obj object into which to store the value
1352
* @param startIndex position of the value in obj
1353
* @param size the number of bytes to be set to the value
1354
* @param replace overwrite memory with this value
1355
*
1356
* @throws IllegalArgumentException if startIndex is illegal in obj, or if size is invalid
1357
*/
1358
public void setMemory(Object obj, long startIndex, long size, byte replace) {
1359
setMemoryChecks(obj, startIndex, size, replace);
1360
1361
if (0 != size) {
1362
setMemory0(obj, startIndex, size, replace);
1363
}
1364
}
1365
1366
/**
1367
* Set the byte at the index and size.
1368
*
1369
* @param startAddress location to store value in memory
1370
* @param size the number of bytes to be set to the value
1371
* @param replace overwrite memory with this value
1372
*
1373
* @throws IllegalArgumentException if startIndex is illegal, or if size is invalid
1374
*/
1375
public void setMemory(long startAddress, long size, byte replace) {
1376
setMemory(null, startAddress, size, replace);
1377
}
1378
1379
/**
1380
* Copy bytes from source object to destination.
1381
*
1382
* @param srcObj object to copy from
1383
* @param srcOffset location in srcObj to start copy
1384
* @param destObj object to copy into
1385
* @param destOffset location in destObj to start copy
1386
* @param size the number of bytes to be copied
1387
*
1388
* @throws IllegalArgumentException if srcOffset is illegal in srcObj,
1389
* if destOffset is illegal in destObj, or if size is invalid
1390
*/
1391
public void copyMemory(Object srcObj, long srcOffset, Object destObj, long destOffset, long size) {
1392
copyMemoryChecks(srcObj, srcOffset, destObj, destOffset, size);
1393
1394
if (0 != size) {
1395
copyMemory0(srcObj, srcOffset, destObj, destOffset, size);
1396
}
1397
}
1398
1399
/**
1400
* Copy bytes from source address to destination.
1401
*
1402
* @param srcAddress address to start copy
1403
* @param destAddress address to start copy
1404
* @param size the number of bytes to be copied
1405
*
1406
* @throws IllegalArgumentException if srcAddress or destAddress
1407
* is illegal, or if size is invalid
1408
*/
1409
public void copyMemory(long srcAddress, long destAddress, long size) {
1410
copyMemory(null, srcAddress, null, destAddress, size);
1411
}
1412
1413
/**
1414
* Copy bytes from source object to destination in reverse order.
1415
* Memory is reversed in elementSize chunks.
1416
*
1417
* @param srcObj object to copy from
1418
* @param srcOffset location in srcObj to start copy
1419
* @param destObj object to copy into
1420
* @param destOffset location in destObj to start copy
1421
* @param copySize the number of bytes to be copied, a multiple of elementSize
1422
* @param elementSize the size in bytes of elements that will be reversed
1423
*
1424
* @throws IllegalArgumentException if srcOffset is illegal in srcObj,
1425
* if destOffset is illegal in destObj, if copySize is invalid or copySize is not
1426
* a multiple of elementSize
1427
*/
1428
public void copySwapMemory(Object srcObj, long srcOffset, Object destObj, long destOffset, long copySize,
1429
long elementSize) {
1430
copySwapMemoryChecks(srcObj, srcOffset, destObj, destOffset, copySize, elementSize);
1431
1432
if (0 != copySize) {
1433
copySwapMemory0(srcObj, srcOffset, destObj, destOffset, copySize, elementSize);
1434
}
1435
}
1436
1437
/**
1438
* Copy bytes from source address to destination in reverse order.
1439
* Memory is reversed in elementSize chunks.
1440
*
1441
* @param srcAddress location to start copy
1442
* @param destAddress location to start copy
1443
* @param copySize the number of bytes to be copied, a multiple of elementSize
1444
* @param elementSize the size in bytes of elements that will be reversed
1445
*
1446
* @throws IllegalArgumentException if srcAddress or destAddress is illegal,
1447
* if copySize is invalid or copySize is not a multiple of elementSize
1448
*/
1449
public void copySwapMemory(long srcAddress, long destAddress, long copySize, long elementSize) {
1450
copySwapMemory(null, srcAddress, null, destAddress, copySize, elementSize);
1451
}
1452
1453
/**
1454
* Removes the block from the list. Note that the pointers are located
1455
* immediately before the startIndex value.
1456
*
1457
* @param startIndex memory address
1458
*
1459
* @throws IllegalArgumentException if startIndex is not valid
1460
*/
1461
public void freeMemory(long startIndex) {
1462
freeMemoryChecks(startIndex);
1463
1464
if (0 != startIndex) {
1465
freeMemory0(startIndex);
1466
}
1467
}
1468
1469
/**
1470
* Returns byte offset to field.
1471
*
1472
* @param field which contains desired class or interface
1473
* @return offset to start of class or interface
1474
*
1475
* @throws NullPointerException if field parameter is null
1476
* @throws IllegalArgumentException if field is static
1477
*/
1478
public long objectFieldOffset(Field field) {
1479
Objects.requireNonNull(field);
1480
return objectFieldOffset0(field);
1481
}
1482
1483
/*[IF JAVA_SPEC_VERSION >= 10]*/
1484
/**
1485
* Returns byte offset to field.
1486
*
1487
* @param class with desired field
1488
* @param string name of desired field
1489
* @return offset to start of class or interface
1490
*
1491
* @throws NullPointerException if field parameter is null
1492
* @throws IllegalArgumentException if field is static
1493
*/
1494
public long objectFieldOffset(Class<?> c, String fieldName) {
1495
Objects.requireNonNull(c);
1496
Objects.requireNonNull(fieldName);
1497
return objectFieldOffset1(c, fieldName);
1498
}
1499
/*[ENDIF] JAVA_SPEC_VERSION >= 10 */
1500
1501
/**
1502
* Returns byte offset to start of static class or interface.
1503
*
1504
* @param field which contains desired class or interface
1505
* @return offset to start of class or interface
1506
*
1507
* @throws NullPointerException if field parameter is null
1508
* @throws IllegalArgumentException if field is not static
1509
*/
1510
public long staticFieldOffset(Field field) {
1511
Objects.requireNonNull(field);
1512
return staticFieldOffset0(field);
1513
}
1514
1515
/**
1516
* Returns class or interface described by static Field.
1517
*
1518
* @param field contains desired class or interface
1519
* @return class or interface in static field
1520
*
1521
* @throws NullPointerException if field parameter is null
1522
* @throws IllegalArgumentException if field is not static
1523
*/
1524
public Object staticFieldBase(Field field) {
1525
Objects.requireNonNull(field);
1526
return staticFieldBase0(field);
1527
}
1528
1529
/**
1530
* Determines whether class has been initialized.
1531
*
1532
* @param class to verify
1533
* @return true if method has not been initialized, false otherwise
1534
*
1535
* @throws NullPointerException if class is null
1536
*/
1537
public boolean shouldBeInitialized(Class<?> c) {
1538
Objects.requireNonNull(c);
1539
return shouldBeInitialized0(c);
1540
}
1541
1542
/**
1543
* Initializes class parameter if it has not been already.
1544
*
1545
* @param c class to initialize if not already
1546
*
1547
* @throws NullPointerException if class is null
1548
*/
1549
public void ensureClassInitialized(Class<?> c) {
1550
Objects.requireNonNull(c);
1551
ensureClassInitialized0(c);
1552
}
1553
1554
/**
1555
* Return offset in array object at which the array data storage begins.
1556
*
1557
* @param c class array
1558
* @return offset at base of array
1559
*
1560
* @throws NullPointerException if the class parameter is null
1561
* @throws IllegalArgumentException if class is not an array
1562
*/
1563
public int arrayBaseOffset(Class<?> c) {
1564
Objects.requireNonNull(c);
1565
return arrayBaseOffset0(c);
1566
}
1567
1568
/**
1569
* Return index size of array in bytes.
1570
*
1571
* @param c class array
1572
* @return returns index size of array in bytes
1573
*
1574
* @throws NullPointerException if class is null
1575
* @throws IllegalArgumentException if class is not an array
1576
* @throws RuntimeException if index scale is not a power of 2
1577
*/
1578
public int arrayIndexScale(Class<?> c) {
1579
Objects.requireNonNull(c);
1580
int indexScale = arrayIndexScale0(c);
1581
if (indexScale == 0 || (indexScale & (indexScale - 1)) != 0) {
1582
throw new RuntimeException("The class array index scale is not a power of two");
1583
}
1584
return indexScale;
1585
}
1586
1587
/**
1588
* @return size of address on machine in use
1589
*/
1590
public int addressSize() {
1591
return ADDRESS_SIZE;
1592
}
1593
1594
/**
1595
* Creates a class out of a given array of bytes with a ProtectionDomain.
1596
*
1597
* @param name binary name of the class, null if the name is not known
1598
* @param b a byte array of the class data. The bytes should have the format of a
1599
* valid class file as defined by The JVM Spec
1600
* @param offset offset of the start of the class data in b
1601
* @param bLength length of the class data
1602
* @param cl ClassLoader used to load the class being built. If null, the default
1603
* system ClassLoader will be used
1604
* @param pd ProtectionDomain for new class
1605
* @return class created from the byte array and ProtectionDomain parameters
1606
*
1607
* @throws NullPointerException if b array of data is null
1608
* @throws ArrayIndexOutOfBoundsException if bLength is negative
1609
* @throws IndexOutOfBoundsException if offset + bLength is greater than the
1610
* length of b
1611
*/
1612
public Class<?> defineClass(String name, byte[] b, int offset, int bLength, ClassLoader cl, ProtectionDomain pd) {
1613
Objects.requireNonNull(b);
1614
1615
if (bLength < 0) {
1616
throw new ArrayIndexOutOfBoundsException();
1617
}
1618
1619
Class<?> result = defineClass0(name, b, offset, bLength, cl, pd);
1620
VMLangAccess access = VM.getVMLangAccess();
1621
access.addPackageToList(result, cl);
1622
return result;
1623
}
1624
1625
/*[IF JAVA_SPEC_VERSION < 17]*/
1626
/**
1627
* Define a class without making it known to the class loader.
1628
*
1629
* @param hostingClass the context for class loader + linkage, and
1630
* access control + protection domain
1631
* @param bytecodes class file bytes
1632
* @param constPatches entries that are not "null" are replacements
1633
* for the corresponding const pool entries in the 'bytecodes' data
1634
* @return class created from bytecodes and constPatches
1635
*
1636
* @throws NullPointerException if hostingClass or bytecodes is null
1637
* @throws IllegalArgumentException if hostingClass is an array or primitive
1638
*/
1639
public Class<?> defineAnonymousClass(Class<?> hostingClass, byte[] bytecodes, Object[] constPatches) {
1640
Objects.requireNonNull(hostingClass);
1641
Objects.requireNonNull(bytecodes);
1642
1643
if (hostingClass.isArray() || hostingClass.isPrimitive()) {
1644
throw invalidInput();
1645
}
1646
1647
return defineAnonymousClass0(hostingClass, bytecodes, constPatches);
1648
}
1649
/*[ENDIF] JAVA_SPEC_VERSION < 17 */
1650
1651
/**
1652
* Allocate new array of same type as class parameter and
1653
* length of int parameter.
1654
*
1655
* @param c class of same type as desired array
1656
* @param length desired length of array
1657
* @return allocated array of desired length and type
1658
*
1659
* @throws IllegalArgumentException if class is null, if class
1660
* is not primitive, or if length is negative
1661
*/
1662
public Object allocateUninitializedArray(Class<?> c, int length) {
1663
if (null == c) {
1664
/*[MSG "K0701", "Component type is null"]*/
1665
throw new IllegalArgumentException(com.ibm.oti.util.Msg.getString("K0701")); //$NON-NLS-1$
1666
}
1667
1668
if (!c.isPrimitive()) {
1669
/*[MSG "K0702", "Component type is not primitive"]*/
1670
throw new IllegalArgumentException(com.ibm.oti.util.Msg.getString("K0702")); //$NON-NLS-1$
1671
}
1672
1673
if (length < 0) {
1674
/*[MSG "K0703", "Negative length"]*/
1675
throw new IllegalArgumentException(com.ibm.oti.util.Msg.getString("K0703")); //$NON-NLS-1$
1676
}
1677
1678
return allocateUninitializedArray0(c, length);
1679
}
1680
1681
1682
/**
1683
* Atomically sets the parameter value at offset in obj if the compare value
1684
* matches the existing value in the object.
1685
* The get operation has memory semantics of get.
1686
* The set operation has the memory semantics of set.
1687
*
1688
* @param obj object into which to store the value
1689
* @param offset location to compare and store value in obj
1690
* @param compareValue value that is expected to be in obj at offset
1691
* @param exchangeValue value that will be set in obj at offset if compare is successful
1692
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
1693
*/
1694
public final byte compareAndExchangeByte(Object obj, long offset, byte compareValue, byte exchangeValue) {
1695
return compareAndExchange8bits(obj, offset, compareValue, exchangeValue);
1696
}
1697
1698
/**
1699
* Atomically sets the parameter value at offset in obj if the compare value
1700
* matches the existing value in the object.
1701
* The get operation has memory semantics of getVolatile.
1702
* The set operation has the memory semantics of setVolatile.
1703
*
1704
* @param obj object into which to store the value
1705
* @param offset location to compare and store value in obj
1706
* @param compareValue value that is expected to be in obj at offset
1707
* @param setValue value that will be set in obj at offset if compare is successful
1708
* @return boolean value indicating whether the field was updated
1709
*/
1710
public final boolean compareAndSetByte(Object obj, long offset, byte compareValue, byte setValue) {
1711
byte exchangedValue = compareAndExchangeByte(obj, offset, compareValue, setValue);
1712
return (compareValue == exchangedValue);
1713
}
1714
1715
/**
1716
* Sets the parameter value at offset in obj if the compare value
1717
* matches the existing value in the object.
1718
* The get operation has memory semantics of get.
1719
* The set operation has the memory semantics of set.
1720
*
1721
* @param obj object into which to store the value
1722
* @param offset location to compare and store value in obj
1723
* @param compareValue value that is expected to be in obj at offset
1724
* @param setValue value that will be set in obj at offset if compare is successful
1725
* @return boolean value indicating whether the field was updated
1726
*/
1727
public final boolean weakCompareAndSetByte(Object obj, long offset, byte compareValue, byte setValue) {
1728
return compareAndSetByte(obj, offset, compareValue, setValue);
1729
}
1730
1731
/**
1732
* Sets the parameter value at offset in obj if the compare value
1733
* matches the existing value in the object.
1734
* The get operation has memory semantics of getAcquire.
1735
* The set operation has the memory semantics of set.
1736
*
1737
* @param obj object into which to store the value
1738
* @param offset location to compare and store value in obj
1739
* @param compareValue value that is expected to be in obj at offset
1740
* @param setValue value that will be set in obj at offset if compare is successful
1741
* @return boolean value indicating whether the field was updated
1742
*/
1743
public final boolean weakCompareAndSetByteAcquire(Object obj, long offset, byte compareValue, byte setValue) {
1744
return weakCompareAndSetByte(obj, offset, compareValue, setValue);
1745
}
1746
1747
/**
1748
* Sets the parameter value at offset in obj if the compare value
1749
* matches the existing value in the object.
1750
* The get operation has memory semantics of get.
1751
* The set operation has the memory semantics of setRelease.
1752
*
1753
* @param obj object into which to store the value
1754
* @param offset location to compare and store value in obj
1755
* @param compareValue value that is expected to be in obj at offset
1756
* @param setValue value that will be set in obj at offset if compare is successful
1757
* @return boolean value indicating whether the field was updated
1758
*/
1759
public final boolean weakCompareAndSetByteRelease(Object obj, long offset, byte compareValue, byte setValue) {
1760
return weakCompareAndSetByte(obj, offset, compareValue, setValue);
1761
}
1762
1763
/**
1764
* Sets the parameter value at offset in obj if the compare value
1765
* matches the existing value in the object.
1766
* The get operation has memory semantics of get.
1767
* The set operation has the memory semantics of set.
1768
*
1769
* @param obj object into which to store the value
1770
* @param offset location to compare and store value in obj
1771
* @param compareValue value that is expected to be in obj at offset
1772
* @param setValue value that will be set in obj at offset if compare is successful
1773
* @return boolean value indicating whether the field was updated
1774
*/
1775
public final boolean weakCompareAndSetBytePlain(Object obj, long offset, byte compareValue, byte setValue) {
1776
return weakCompareAndSetByte(obj, offset, compareValue, setValue);
1777
}
1778
1779
/**
1780
* Atomically sets the parameter value at offset in obj if the compare value
1781
* matches the existing value in the object.
1782
* The get operation has memory semantics of getAcquire.
1783
* The set operation has the memory semantics of set.
1784
*
1785
* @param obj object into which to store the value
1786
* @param offset location to compare and store value in obj
1787
* @param compareValue value that is expected to be in obj at offset
1788
* @param exchangeValue value that will be set in obj at offset if compare is successful
1789
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
1790
*/
1791
public final byte compareAndExchangeByteAcquire(Object obj, long offset, byte compareValue, byte exchangeValue) {
1792
return compareAndExchangeByte(obj, offset, compareValue, exchangeValue);
1793
}
1794
1795
/**
1796
* Atomically sets the parameter value at offset in obj if the compare value
1797
* matches the existing value in the object.
1798
* The get operation has memory semantics of get.
1799
* The set operation has the memory semantics of setRelease.
1800
*
1801
* @param obj object into which to store the value
1802
* @param offset location to compare and store value in obj
1803
* @param compareValue value that is expected to be in obj at offset
1804
* @param exchangeValue value that will be set in obj at offset if compare is successful
1805
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
1806
*/
1807
public final byte compareAndExchangeByteRelease(Object obj, long offset, byte compareValue, byte exchangeValue) {
1808
return compareAndExchangeByte(obj, offset, compareValue, exchangeValue);
1809
}
1810
1811
/**
1812
* Atomically sets the parameter value at offset in obj if the compare value
1813
* matches the existing value in the object.
1814
* The get operation has memory semantics of getAcquire.
1815
* The set operation has the memory semantics of set.
1816
*
1817
* @param obj object into which to store the value
1818
* @param offset location to compare and store value in obj
1819
* @param compareValue value that is expected to be in obj at offset
1820
* @param exchangeValue value that will be set in obj at offset if compare is successful
1821
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
1822
*/
1823
public final int compareAndExchangeIntAcquire(Object obj, long offset, int compareValue, int exchangeValue) {
1824
return compareAndExchangeInt(obj, offset, compareValue, exchangeValue);
1825
}
1826
1827
/**
1828
* Atomically sets the parameter value at offset in obj if the compare value
1829
* matches the existing value in the object.
1830
* The get operation has memory semantics of get.
1831
* The set operation has the memory semantics of setRelease.
1832
*
1833
* @param obj object into which to store the value
1834
* @param offset location to compare and store value in obj
1835
* @param compareValue value that is expected to be in obj at offset
1836
* @param exchangeValue value that will be set in obj at offset if compare is successful
1837
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
1838
*/
1839
public final int compareAndExchangeIntRelease(Object obj, long offset, int compareValue, int exchangeValue) {
1840
return compareAndExchangeInt(obj, offset, compareValue, exchangeValue);
1841
}
1842
1843
/**
1844
* Sets the parameter value at offset in obj if the compare value
1845
* matches the existing value in the object.
1846
* The get operation has memory semantics of get.
1847
* The set operation has the memory semantics of set.
1848
*
1849
* @param obj object into which to store the value
1850
* @param offset location to compare and store value in obj
1851
* @param compareValue value that is expected to be in obj at offset
1852
* @param setValue value that will be set in obj at offset if compare is successful
1853
* @return boolean value indicating whether the field was updated
1854
*/
1855
public final boolean weakCompareAndSetIntPlain(Object obj, long offset, int compareValue, int setValue) {
1856
return compareAndSetInt(obj, offset, compareValue, setValue);
1857
}
1858
1859
/**
1860
* Sets the parameter value at offset in obj if the compare value
1861
* matches the existing value in the object.
1862
* The get operation has memory semantics of getAcquire.
1863
* The set operation has the memory semantics of set.
1864
*
1865
* @param obj object into which to store the value
1866
* @param offset location to compare and store value in obj
1867
* @param compareValue value that is expected to be in obj at offset
1868
* @param setValue value that will be set in obj at offset if compare is successful
1869
* @return boolean value indicating whether the field was updated
1870
*/
1871
public final boolean weakCompareAndSetIntAcquire(Object obj, long offset, int compareValue, int setValue) {
1872
return compareAndSetInt(obj, offset, compareValue, setValue);
1873
}
1874
1875
/**
1876
* Sets the parameter value at offset in obj if the compare value
1877
* matches the existing value in the object.
1878
* The get operation has memory semantics of get.
1879
* The set operation has the memory semantics of setRelease.
1880
*
1881
* @param obj object into which to store the value
1882
* @param offset location to compare and store value in obj
1883
* @param compareValue value that is expected to be in obj at offset
1884
* @param setValue value that will be set in obj at offset if compare is successful
1885
* @return boolean value indicating whether the field was updated
1886
*/
1887
public final boolean weakCompareAndSetIntRelease(Object obj, long offset, int compareValue, int setValue) {
1888
return compareAndSetInt(obj, offset, compareValue, setValue);
1889
}
1890
1891
/**
1892
* Sets the parameter value at offset in obj if the compare value
1893
* matches the existing value in the object.
1894
* The get operation has memory semantics of get.
1895
* The set operation has the memory semantics of set.
1896
*
1897
* @param obj object into which to store the value
1898
* @param offset location to compare and store value in obj
1899
* @param compareValue value that is expected to be in obj at offset
1900
* @param setValue value that will be set in obj at offset if compare is successful
1901
* @return boolean value indicating whether the field was updated
1902
*/
1903
public final boolean weakCompareAndSetInt(Object obj, long offset, int compareValue, int setValue) {
1904
return compareAndSetInt(obj, offset, compareValue, setValue);
1905
}
1906
1907
/**
1908
* Atomically sets the parameter value at offset in obj if the compare value
1909
* matches the existing value in the object.
1910
* The get operation has memory semantics of getAcquire.
1911
* The set operation has the memory semantics of set.
1912
*
1913
* @param obj object into which to store the value
1914
* @param offset location to compare and store value in obj
1915
* @param compareValue value that is expected to be in obj at offset
1916
* @param exchangeValue value that will be set in obj at offset if compare is successful
1917
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
1918
*/
1919
public final long compareAndExchangeLongAcquire(Object obj, long offset, long compareValue, long exchangeValue) {
1920
return compareAndExchangeLong(obj, offset, compareValue, exchangeValue);
1921
}
1922
1923
/**
1924
* Atomically sets the parameter value at offset in obj if the compare value
1925
* matches the existing value in the object.
1926
* The get operation has memory semantics of get.
1927
* The set operation has the memory semantics of setRelease.
1928
*
1929
* @param obj object into which to store the value
1930
* @param offset location to compare and store value in obj
1931
* @param compareValue value that is expected to be in obj at offset
1932
* @param exchangeValue value that will be set in obj at offset if compare is successful
1933
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
1934
*/
1935
public final long compareAndExchangeLongRelease(Object obj, long offset, long compareValue, long exchangeValue) {
1936
return compareAndExchangeLong(obj, offset, compareValue, exchangeValue);
1937
}
1938
1939
/**
1940
* Sets the parameter value at offset in obj if the compare value
1941
* matches the existing value in the object.
1942
* The get operation has memory semantics of get.
1943
* The set operation has the memory semantics of set.
1944
*
1945
* @param obj object into which to store the value
1946
* @param offset location to compare and store value in obj
1947
* @param compareValue value that is expected to be in obj at offset
1948
* @param setValue value that will be set in obj at offset if compare is successful
1949
* @return boolean value indicating whether the field was updated
1950
*/
1951
public final boolean weakCompareAndSetLongPlain(Object obj, long offset, long compareValue, long setValue) {
1952
return compareAndSetLong(obj, offset, compareValue, setValue);
1953
}
1954
1955
/**
1956
* Sets the parameter value at offset in obj if the compare value
1957
* matches the existing value in the object.
1958
* The get operation has memory semantics of getAcquire.
1959
* The set operation has the memory semantics of set.
1960
*
1961
* @param obj object into which to store the value
1962
* @param offset location to compare and store value in obj
1963
* @param compareValue value that is expected to be in obj at offset
1964
* @param setValue value that will be set in obj at offset if compare is successful
1965
* @return boolean value indicating whether the field was updated
1966
*/
1967
public final boolean weakCompareAndSetLongAcquire(Object obj, long offset, long compareValue, long setValue) {
1968
return compareAndSetLong(obj, offset, compareValue, setValue);
1969
}
1970
1971
/**
1972
* Sets the parameter value at offset in obj if the compare value
1973
* matches the existing value in the object.
1974
* The get operation has memory semantics of get.
1975
* The set operation has the memory semantics of setRelease.
1976
*
1977
* @param obj object into which to store the value
1978
* @param offset location to compare and store value in obj
1979
* @param compareValue value that is expected to be in obj at offset
1980
* @param setValue value that will be set in obj at offset if compare is successful
1981
* @return boolean value indicating whether the field was updated
1982
*/
1983
public final boolean weakCompareAndSetLongRelease(Object obj, long offset, long compareValue, long setValue) {
1984
return compareAndSetLong(obj, offset, compareValue, setValue);
1985
}
1986
1987
/**
1988
* Sets the parameter value at offset in obj if the compare value
1989
* matches the existing value in the object.
1990
* The get operation has memory semantics of get.
1991
* The set operation has the memory semantics of set.
1992
*
1993
* @param obj object into which to store the value
1994
* @param offset location to compare and store value in obj
1995
* @param compareValue value that is expected to be in obj at offset
1996
* @param setValue value that will be set in obj at offset if compare is successful
1997
* @return boolean value indicating whether the field was updated
1998
*/
1999
public final boolean weakCompareAndSetLong(Object obj, long offset, long compareValue, long setValue) {
2000
return compareAndSetLong(obj, offset, compareValue, setValue);
2001
}
2002
2003
/**
2004
* Atomically sets the parameter value at offset in obj if the compare value
2005
* matches the existing value in the object.
2006
* The get operation has memory semantics of getVolatile.
2007
* The set operation has the memory semantics of setVolatile.
2008
*
2009
* @param obj object into which to store the value
2010
* @param offset location to compare and store value in obj
2011
* @param compareValue value that is expected to be in obj at offset
2012
* @param setValue value that will be set in obj at offset if compare is successful
2013
* @return boolean value indicating whether the field was updated
2014
*/
2015
public final boolean compareAndSetFloat(Object obj, long offset, float compareValue, float setValue) {
2016
return compareAndSetInt(obj, offset, Float.floatToRawIntBits(compareValue), Float.floatToRawIntBits(setValue));
2017
}
2018
2019
/**
2020
* Atomically sets the parameter value at offset in obj if the compare value
2021
* matches the existing value in the object.
2022
* The get operation has memory semantics of get.
2023
* The set operation has the memory semantics of set.
2024
*
2025
* @param obj object into which to store the value
2026
* @param offset location to compare and store value in obj
2027
* @param compareValue value that is expected to be in obj at offset
2028
* @param exchangeValue value that will be set in obj at offset if compare is successful
2029
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
2030
*/
2031
public final float compareAndExchangeFloat(Object obj, long offset, float compareValue, float exchangeValue) {
2032
int result = compareAndExchangeInt(obj, offset, Float.floatToRawIntBits(compareValue),
2033
Float.floatToRawIntBits(exchangeValue));
2034
return Float.intBitsToFloat(result);
2035
}
2036
2037
/**
2038
* Atomically sets the parameter value at offset in obj if the compare value
2039
* matches the existing value in the object.
2040
* The get operation has memory semantics of getAcquire.
2041
* The set operation has the memory semantics of set.
2042
*
2043
* @param obj object into which to store the value
2044
* @param offset location to compare and store value in obj
2045
* @param compareValue value that is expected to be in obj at offset
2046
* @param exchangeValue value that will be set in obj at offset if compare is successful
2047
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
2048
*/
2049
public final float compareAndExchangeFloatAcquire(Object obj, long offset, float compareValue,
2050
float exchangeValue) {
2051
int result = compareAndExchangeIntAcquire(obj, offset, Float.floatToRawIntBits(compareValue),
2052
Float.floatToRawIntBits(exchangeValue));
2053
return Float.intBitsToFloat(result);
2054
}
2055
2056
/**
2057
* Atomically sets the parameter value at offset in obj if the compare value
2058
* matches the existing value in the object.
2059
* The get operation has memory semantics of get.
2060
* The set operation has the memory semantics of setRelease.
2061
*
2062
* @param obj object into which to store the value
2063
* @param offset location to compare and store value in obj
2064
* @param compareValue value that is expected to be in obj at offset
2065
* @param exchangeValue value that will be set in obj at offset if compare is successful
2066
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
2067
*/
2068
public final float compareAndExchangeFloatRelease(Object obj, long offset, float compareValue,
2069
float exchangeValue) {
2070
int result = compareAndExchangeIntRelease(obj, offset, Float.floatToRawIntBits(compareValue),
2071
Float.floatToRawIntBits(exchangeValue));
2072
return Float.intBitsToFloat(result);
2073
}
2074
2075
/**
2076
* Sets the parameter value at offset in obj if the compare value
2077
* matches the existing value in the object.
2078
* The get operation has memory semantics of get.
2079
* The set operation has the memory semantics of set.
2080
*
2081
* @param obj object into which to store the value
2082
* @param offset location to compare and store value in obj
2083
* @param compareValue value that is expected to be in obj at offset
2084
* @param setValue value that will be set in obj at offset if compare is successful
2085
* @return boolean value indicating whether the field was updated
2086
*/
2087
public final boolean weakCompareAndSetFloatPlain(Object obj, long offset, float compareValue, float setValue) {
2088
return weakCompareAndSetIntPlain(obj, offset, Float.floatToRawIntBits(compareValue),
2089
Float.floatToRawIntBits(setValue));
2090
}
2091
2092
/**
2093
* Sets the parameter value at offset in obj if the compare value
2094
* matches the existing value in the object.
2095
* The get operation has memory semantics of getAcquire.
2096
* The set operation has the memory semantics of set.
2097
*
2098
* @param obj object into which to store the value
2099
* @param offset location to compare and store value in obj
2100
* @param compareValue value that is expected to be in obj at offset
2101
* @param setValue value that will be set in obj at offset if compare is successful
2102
* @return boolean value indicating whether the field was updated
2103
*/
2104
public final boolean weakCompareAndSetFloatAcquire(Object obj, long offset, float compareValue, float setValue) {
2105
return weakCompareAndSetIntAcquire(obj, offset, Float.floatToRawIntBits(compareValue),
2106
Float.floatToRawIntBits(setValue));
2107
}
2108
2109
/**
2110
* Sets the parameter value at offset in obj if the compare value
2111
* matches the existing value in the object.
2112
* The get operation has memory semantics of get.
2113
* The set operation has the memory semantics of setRelease.
2114
*
2115
* @param obj object into which to store the value
2116
* @param offset location to compare and store value in obj
2117
* @param compareValue value that is expected to be in obj at offset
2118
* @param setValue value that will be set in obj at offset if compare is successful
2119
* @return boolean value indicating whether the field was updated
2120
*/
2121
public final boolean weakCompareAndSetFloatRelease(Object obj, long offset, float compareValue, float setValue) {
2122
return weakCompareAndSetIntRelease(obj, offset, Float.floatToRawIntBits(compareValue),
2123
Float.floatToRawIntBits(setValue));
2124
}
2125
2126
/**
2127
* Sets the parameter value at offset in obj if the compare value
2128
* matches the existing value in the object.
2129
* The get operation has memory semantics of get.
2130
* The set operation has the memory semantics of set.
2131
*
2132
* @param obj object into which to store the value
2133
* @param offset location to compare and store value in obj
2134
* @param compareValue value that is expected to be in obj at offset
2135
* @param setValue value that will be set in obj at offset if compare is successful
2136
* @return boolean value indicating whether the field was updated
2137
*/
2138
public final boolean weakCompareAndSetFloat(Object obj, long offset, float compareValue, float setValue) {
2139
return weakCompareAndSetInt(obj, offset, Float.floatToRawIntBits(compareValue),
2140
Float.floatToRawIntBits(setValue));
2141
}
2142
2143
/**
2144
* Atomically sets the parameter value at offset in obj if the compare value
2145
* matches the existing value in the object.
2146
* The get operation has memory semantics of getVolatile.
2147
* The set operation has the memory semantics of setVolatile.
2148
*
2149
* @param obj object into which to store the value
2150
* @param offset location to compare and store value in obj
2151
* @param compareValue value that is expected to be in obj at offset
2152
* @param setValue value that will be set in obj at offset if compare is successful
2153
* @return boolean value indicating whether the field was updated
2154
*/
2155
public final boolean compareAndSetDouble(Object obj, long offset, double compareValue, double setValue) {
2156
return compareAndSetLong(obj, offset, Double.doubleToRawLongBits(compareValue),
2157
Double.doubleToRawLongBits(setValue));
2158
}
2159
2160
/**
2161
* Atomically sets the parameter value at offset in obj if the compare value
2162
* matches the existing value in the object.
2163
* The get operation has memory semantics of get.
2164
* The set operation has the memory semantics of set.
2165
*
2166
* @param obj object into which to store the value
2167
* @param offset location to compare and store value in obj
2168
* @param compareValue value that is expected to be in obj at offset
2169
* @param exchangeValue value that will be set in obj at offset if compare is successful
2170
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
2171
*/
2172
public final double compareAndExchangeDouble(Object obj, long offset, double compareValue, double exchangeValue) {
2173
long result = compareAndExchangeLong(obj, offset, Double.doubleToRawLongBits(compareValue),
2174
Double.doubleToRawLongBits(exchangeValue));
2175
return Double.longBitsToDouble(result);
2176
}
2177
2178
/**
2179
* Atomically sets the parameter value at offset in obj if the compare value
2180
* matches the existing value in the object.
2181
* The get operation has memory semantics of getAcquire.
2182
* The set operation has the memory semantics of set.
2183
*
2184
* @param obj object into which to store the value
2185
* @param offset location to compare and store value in obj
2186
* @param compareValue value that is expected to be in obj at offset
2187
* @param exchangeValue value that will be set in obj at offset if compare is successful
2188
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
2189
*/
2190
public final double compareAndExchangeDoubleAcquire(Object obj, long offset, double compareValue,
2191
double exchangeValue) {
2192
long result = compareAndExchangeLongAcquire(obj, offset, Double.doubleToRawLongBits(compareValue),
2193
Double.doubleToRawLongBits(exchangeValue));
2194
return Double.longBitsToDouble(result);
2195
}
2196
2197
/**
2198
* Atomically sets the parameter value at offset in obj if the compare value
2199
* matches the existing value in the object.
2200
* The get operation has memory semantics of get.
2201
* The set operation has the memory semantics of setRelease.
2202
*
2203
* @param obj object into which to store the value
2204
* @param offset location to compare and store value in obj
2205
* @param compareValue value that is expected to be in obj at offset
2206
* @param exchangeValue value that will be set in obj at offset if compare is successful
2207
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
2208
*/
2209
public final double compareAndExchangeDoubleRelease(Object obj, long offset, double compareValue,
2210
double exchangeValue) {
2211
long result = compareAndExchangeLongRelease(obj, offset, Double.doubleToRawLongBits(compareValue),
2212
Double.doubleToRawLongBits(exchangeValue));
2213
return Double.longBitsToDouble(result);
2214
}
2215
2216
/**
2217
* Sets the parameter value at offset in obj if the compare value
2218
* matches the existing value in the object.
2219
* The get operation has memory semantics of get.
2220
* The set operation has the memory semantics of set.
2221
*
2222
* @param obj object into which to store the value
2223
* @param offset location to compare and store value in obj
2224
* @param compareValue value that is expected to be in obj at offset
2225
* @param setValue value that will be set in obj at offset if compare is successful
2226
* @return boolean value indicating whether the field was updated
2227
*/
2228
public final boolean weakCompareAndSetDoublePlain(Object obj, long offset, double compareValue, double swapValue) {
2229
return weakCompareAndSetLongPlain(obj, offset, Double.doubleToRawLongBits(compareValue),
2230
Double.doubleToRawLongBits(swapValue));
2231
}
2232
2233
/**
2234
* Sets the parameter value at offset in obj if the compare value
2235
* matches the existing value in the object.
2236
* The get operation has memory semantics of getAcquire.
2237
* The set operation has the memory semantics of set.
2238
*
2239
* @param obj object into which to store the value
2240
* @param offset location to compare and store value in obj
2241
* @param compareValue value that is expected to be in obj at offset
2242
* @param setValue value that will be set in obj at offset if compare is successful
2243
* @return boolean value indicating whether the field was updated
2244
*/
2245
public final boolean weakCompareAndSetDoubleAcquire(Object obj, long offset, double compareValue,
2246
double swapValue) {
2247
return weakCompareAndSetLongAcquire(obj, offset, Double.doubleToRawLongBits(compareValue),
2248
Double.doubleToRawLongBits(swapValue));
2249
}
2250
2251
/**
2252
* Sets the parameter value at offset in obj if the compare value
2253
* matches the existing value in the object.
2254
* The get operation has memory semantics of get.
2255
* The set operation has the memory semantics of setRelease.
2256
*
2257
* @param obj object into which to store the value
2258
* @param offset location to compare and store value in obj
2259
* @param compareValue value that is expected to be in obj at offset
2260
* @param setValue value that will be set in obj at offset if compare is successful
2261
* @return boolean value indicating whether the field was updated
2262
*/
2263
public final boolean weakCompareAndSetDoubleRelease(Object obj, long offset, double compareValue,
2264
double swapValue) {
2265
return weakCompareAndSetLongRelease(obj, offset, Double.doubleToRawLongBits(compareValue),
2266
Double.doubleToRawLongBits(swapValue));
2267
}
2268
2269
/**
2270
* Sets the parameter value at offset in obj if the compare value
2271
* matches the existing value in the object.
2272
* The get operation has memory semantics of get.
2273
* The set operation has the memory semantics of set.
2274
*
2275
* @param obj object into which to store the value
2276
* @param offset location to compare and store value in obj
2277
* @param compareValue value that is expected to be in obj at offset
2278
* @param setValue value that will be set in obj at offset if compare is successful
2279
* @return boolean value indicating whether the field was updated
2280
*/
2281
public final boolean weakCompareAndSetDouble(Object obj, long offset, double compareValue, double swapValue) {
2282
return weakCompareAndSetLong(obj, offset, Double.doubleToRawLongBits(compareValue),
2283
Double.doubleToRawLongBits(swapValue));
2284
}
2285
2286
/**
2287
* Atomically sets the parameter value at offset in obj if the compare value
2288
* matches the existing value in the object.
2289
* The get operation has memory semantics of get.
2290
* The set operation has the memory semantics of set.
2291
*
2292
* @param obj object into which to store the value
2293
* @param offset location to compare and store value in obj
2294
* @param compareValue value that is expected to be in obj at offset
2295
* @param exchangeValue value that will be set in obj at offset if compare is successful
2296
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
2297
*
2298
* @throws IllegalArgumentException if value at offset spans over multiple aligned words (4 bytes) in memory
2299
*/
2300
public final short compareAndExchangeShort(Object obj, long offset, short compareValue, short exchangeValue) {
2301
compareAndExchange16BitsOffsetChecks(offset);
2302
return compareAndExchange16bits(obj, offset, compareValue, exchangeValue);
2303
}
2304
2305
/**
2306
* Atomically sets the parameter value at offset in obj if the compare value
2307
* matches the existing value in the object.
2308
* The get operation has memory semantics of getVolatile.
2309
* The set operation has the memory semantics of setVolatile.
2310
*
2311
* @param obj object into which to store the value
2312
* @param offset location to compare and store value in obj
2313
* @param compareValue value that is expected to be in obj at offset
2314
* @param setValue value that will be set in obj at offset if compare is successful
2315
* @return boolean value indicating whether the field was updated
2316
*
2317
* @throws IllegalArgumentException if value at offset spans over multiple aligned words (4 bytes) in memory
2318
*/
2319
public final boolean compareAndSetShort(Object obj, long offset, short compareValue, short setValue) {
2320
short exchangedValue = compareAndExchangeShort(obj, offset, compareValue, setValue);
2321
return (compareValue == exchangedValue);
2322
}
2323
2324
/**
2325
* Sets the parameter value at offset in obj if the compare value
2326
* matches the existing value in the object.
2327
* The get operation has memory semantics of get.
2328
* The set operation has the memory semantics of set.
2329
*
2330
* @param obj object into which to store the value
2331
* @param offset location to compare and store value in obj
2332
* @param compareValue value that is expected to be in obj at offset
2333
* @param setValue value that will be set in obj at offset if compare is successful
2334
* @return boolean value indicating whether the field was updated
2335
*
2336
* @throws IllegalArgumentException if value at offset spans over multiple aligned words (4 bytes) in memory
2337
*/
2338
public final boolean weakCompareAndSetShort(Object obj, long offset, short compareValue, short setValue) {
2339
return compareAndSetShort(obj, offset, compareValue, setValue);
2340
}
2341
2342
/**
2343
* Sets the parameter value at offset in obj if the compare value
2344
* matches the existing value in the object.
2345
* The get operation has memory semantics of getAcquire.
2346
* The set operation has the memory semantics of set.
2347
*
2348
* @param obj object into which to store the value
2349
* @param offset location to compare and store value in obj
2350
* @param compareValue value that is expected to be in obj at offset
2351
* @param setValue value that will be set in obj at offset if compare is successful
2352
* @return boolean value indicating whether the field was updated
2353
*
2354
* @throws IllegalArgumentException if value at offset spans over multiple aligned words (4 bytes) in memory
2355
*/
2356
public final boolean weakCompareAndSetShortAcquire(Object obj, long offset, short compareValue, short setValue) {
2357
return weakCompareAndSetShort(obj, offset, compareValue, setValue);
2358
}
2359
2360
/**
2361
* Sets the parameter value at offset in obj if the compare value
2362
* matches the existing value in the object.
2363
* The get operation has memory semantics of get.
2364
* The set operation has the memory semantics of setRelease.
2365
*
2366
* @param obj object into which to store the value
2367
* @param offset location to compare and store value in obj
2368
* @param compareValue value that is expected to be in obj at offset
2369
* @param setValue value that will be set in obj at offset if compare is successful
2370
* @return boolean value indicating whether the field was updated
2371
*
2372
* @throws IllegalArgumentException if value at offset spans over multiple aligned words (4 bytes) in memory
2373
*/
2374
public final boolean weakCompareAndSetShortRelease(Object obj, long offset, short compareValue, short setValue) {
2375
return weakCompareAndSetShort(obj, offset, compareValue, setValue);
2376
}
2377
2378
/**
2379
* Sets the parameter value at offset in obj if the compare value
2380
* matches the existing value in the object.
2381
* The get operation has memory semantics of get.
2382
* The set operation has the memory semantics of set.
2383
*
2384
* @param obj object into which to store the value
2385
* @param offset location to compare and store value in obj
2386
* @param compareValue value that is expected to be in obj at offset
2387
* @param setValue value that will be set in obj at offset if compare is successful
2388
* @return boolean value indicating whether the field was updated
2389
*
2390
* @throws IllegalArgumentException if value at offset spans over multiple aligned words (4 bytes) in memory
2391
*/
2392
public final boolean weakCompareAndSetShortPlain(Object obj, long offset, short compareValue, short setValue) {
2393
return weakCompareAndSetShort(obj, offset, compareValue, setValue);
2394
}
2395
2396
/**
2397
* Atomically sets the parameter value at offset in obj if the compare value
2398
* matches the existing value in the object.
2399
* The get operation has memory semantics of get.
2400
* The set operation has the memory semantics of set.
2401
*
2402
* @param obj object into which to store the value
2403
* @param offset location to compare and store value in obj
2404
* @param compareValue value that is expected to be in obj at offset
2405
* @param exchangeValue value that will be set in obj at offset if compare is successful
2406
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
2407
*
2408
* @throws IllegalArgumentException if value at offset spans over multiple aligned words (4 bytes) in memory
2409
*/
2410
public final short compareAndExchangeShortAcquire(Object obj, long offset, short compareValue,
2411
short exchangeValue) {
2412
return compareAndExchangeShort(obj, offset, compareValue, exchangeValue);
2413
}
2414
2415
/**
2416
* Atomically sets the parameter value at offset in obj if the compare value
2417
* matches the existing value in the object.
2418
* The get operation has memory semantics of get.
2419
* The set operation has the memory semantics of set.
2420
*
2421
* @param obj object into which to store the value
2422
* @param offset location to compare and store value in obj
2423
* @param compareValue value that is expected to be in obj at offset
2424
* @param exchangeValue value that will be set in obj at offset if compare is successful
2425
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
2426
*
2427
* @throws IllegalArgumentException if value at offset spans over multiple aligned words (4 bytes) in memory
2428
*/
2429
public final short compareAndExchangeShortRelease(Object obj, long offset, short compareValue,
2430
short exchangeValue) {
2431
return compareAndExchangeShort(obj, offset, compareValue, exchangeValue);
2432
}
2433
2434
/**
2435
* Atomically sets the parameter value at offset in obj if the compare value
2436
* matches the existing value in the object.
2437
* The get operation has memory semantics of getVolatile.
2438
* The set operation has the memory semantics of setVolatile.
2439
*
2440
* @param obj object into which to store the value
2441
* @param offset location to compare and store value in obj
2442
* @param compareValue value that is expected to be in obj at offset
2443
* @param setValue value that will be set in obj at offset if compare is successful
2444
* @return boolean value indicating whether the field was updated
2445
*
2446
* @throws IllegalArgumentException if value at offset spans over multiple aligned words (4 bytes) in memory
2447
*/
2448
public final boolean compareAndSetChar(Object obj, long offset, char compareValue, char setValue) {
2449
char exchangedValue = compareAndExchangeChar(obj, offset, compareValue, setValue);
2450
return (compareValue == exchangedValue);
2451
}
2452
2453
/**
2454
* Atomically sets the parameter value at offset in obj if the compare value
2455
* matches the existing value in the object.
2456
* The get operation has memory semantics of get.
2457
* The set operation has the memory semantics of set.
2458
*
2459
* @param obj object into which to store the value
2460
* @param offset location to compare and store value in obj
2461
* @param compareValue value that is expected to be in obj at offset
2462
* @param exchangeValue value that will be set in obj at offset if compare is successful
2463
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
2464
*
2465
* @throws IllegalArgumentException if value at offset spans over multiple aligned words (4 bytes) in memory
2466
*/
2467
public final char compareAndExchangeChar(Object obj, long offset, char compareValue, char exchangeValue) {
2468
compareAndExchange16BitsOffsetChecks(offset);
2469
short result = compareAndExchange16bits(obj, offset, compareValue, exchangeValue);
2470
return s2c(result);
2471
}
2472
2473
/**
2474
* Atomically sets the parameter value at offset in obj if the compare value
2475
* matches the existing value in the object.
2476
* The get operation has memory semantics of getAcquire.
2477
* The set operation has the memory semantics of set.
2478
*
2479
* @param obj object into which to store the value
2480
* @param offset location to compare and store value in obj
2481
* @param compareValue value that is expected to be in obj at offset
2482
* @param exchangeValue value that will be set in obj at offset if compare is successful
2483
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
2484
*
2485
* @throws IllegalArgumentException if value at offset spans over multiple aligned words (4 bytes) in memory
2486
*/
2487
public final char compareAndExchangeCharAcquire(Object obj, long offset, char compareValue, char exchangeValue) {
2488
return compareAndExchangeChar(obj, offset, compareValue, exchangeValue);
2489
}
2490
2491
/**
2492
* Atomically sets the parameter value at offset in obj if the compare value
2493
* matches the existing value in the object.
2494
* The get operation has memory semantics of get.
2495
* The set operation has the memory semantics of setRelease.
2496
*
2497
* @param obj object into which to store the value
2498
* @param offset location to compare and store value in obj
2499
* @param compareValue value that is expected to be in obj at offset
2500
* @param exchangeValue value that will be set in obj at offset if compare is successful
2501
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
2502
*
2503
* @throws IllegalArgumentException if value at offset spans over multiple aligned words (4 bytes) in memory
2504
*/
2505
public final char compareAndExchangeCharRelease(Object obj, long offset, char compareValue, char exchangeValue) {
2506
return compareAndExchangeChar(obj, offset, compareValue, exchangeValue);
2507
}
2508
2509
/**
2510
* Sets the parameter value at offset in obj if the compare value
2511
* matches the existing value in the object.
2512
* The get operation has memory semantics of get.
2513
* The set operation has the memory semantics of set.
2514
*
2515
* @param obj object into which to store the value
2516
* @param offset location to compare and store value in obj
2517
* @param compareValue value that is expected to be in obj at offset
2518
* @param setValue value that will be set in obj at offset if compare is successful
2519
* @return boolean value indicating whether the field was updated
2520
*
2521
* @throws IllegalArgumentException if value at offset spans over multiple aligned words (4 bytes) in memory
2522
*/
2523
public final boolean weakCompareAndSetChar(Object obj, long offset, char compareValue, char setValue) {
2524
return compareAndSetChar(obj, offset, compareValue, setValue);
2525
}
2526
2527
/**
2528
* Sets the parameter value at offset in obj if the compare value
2529
* matches the existing value in the object.
2530
* The get operation has memory semantics of getAcquire.
2531
* The set operation has the memory semantics of set.
2532
*
2533
* @param obj object into which to store the value
2534
* @param offset location to compare and store value in obj
2535
* @param compareValue value that is expected to be in obj at offset
2536
* @param setValue value that will be set in obj at offset if compare is successful
2537
* @return boolean value indicating whether the field was updated
2538
*
2539
* @throws IllegalArgumentException if value at offset spans over multiple aligned words (4 bytes) in memory
2540
*/
2541
public final boolean weakCompareAndSetCharAcquire(Object obj, long offset, char compareValue, char setValue) {
2542
return weakCompareAndSetChar(obj, offset, compareValue, setValue);
2543
}
2544
2545
/**
2546
* Sets the parameter value at offset in obj if the compare value
2547
* matches the existing value in the object.
2548
* The get operation has memory semantics of get.
2549
* The set operation has the memory semantics of setRelease.
2550
*
2551
* @param obj object into which to store the value
2552
* @param offset location to compare and store value in obj
2553
* @param compareValue value that is expected to be in obj at offset
2554
* @param setValue value that will be set in obj at offset if compare is successful
2555
* @return boolean value indicating whether the field was updated
2556
*
2557
* @throws IllegalArgumentException if value at offset spans over multiple aligned words (4 bytes) in memory
2558
*/
2559
public final boolean weakCompareAndSetCharRelease(Object obj, long offset, char compareValue, char setValue) {
2560
return weakCompareAndSetChar(obj, offset, compareValue, setValue);
2561
}
2562
2563
/**
2564
* Sets the parameter value at offset in obj if the compare value
2565
* matches the existing value in the object.
2566
* The get operation has memory semantics of get.
2567
* The set operation has the memory semantics of set.
2568
*
2569
* @param obj object into which to store the value
2570
* @param offset location to compare and store value in obj
2571
* @param compareValue value that is expected to be in obj at offset
2572
* @param setValue value that will be set in obj at offset if compare is successful
2573
* @return boolean value indicating whether the field was updated
2574
*
2575
* @throws IllegalArgumentException if value at offset spans over multiple aligned words (4 bytes) in memory
2576
*/
2577
public final boolean weakCompareAndSetCharPlain(Object obj, long offset, char compareValue, char setValue) {
2578
return weakCompareAndSetChar(obj, offset, compareValue, setValue);
2579
}
2580
2581
/**
2582
* Atomically sets the parameter value at offset in obj if the compare value
2583
* matches the existing value in the object.
2584
* The get operation has memory semantics of getVolatile.
2585
* The set operation has the memory semantics of setVolatile.
2586
*
2587
* @param obj object into which to store the value
2588
* @param offset location to compare and store value in obj
2589
* @param compareValue value that is expected to be in obj at offset
2590
* @param setValue value that will be set in obj at offset if compare is successful
2591
* @return boolean value indicating whether the field was updated
2592
*/
2593
public final boolean compareAndSetBoolean(Object obj, long offset, boolean compareValue, boolean setValue) {
2594
return compareAndSetByte(obj, offset, bool2byte(compareValue), bool2byte(setValue));
2595
}
2596
2597
/**
2598
* Atomically sets the parameter value at offset in obj if the compare value
2599
* matches the existing value in the object.
2600
* The get operation has memory semantics of get.
2601
* The set operation has the memory semantics of set.
2602
*
2603
* @param obj object into which to store the value
2604
* @param offset location to compare and store value in obj
2605
* @param compareValue value that is expected to be in obj at offset
2606
* @param exchangeValue value that will be set in obj at offset if compare is successful
2607
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
2608
*/
2609
public final boolean compareAndExchangeBoolean(Object obj, long offset, boolean compareValue,
2610
boolean exchangeValue) {
2611
byte result = compareAndExchange8bits(obj, offset, bool2byte(compareValue), bool2byte(exchangeValue));
2612
return byte2bool(result);
2613
}
2614
2615
/**
2616
* Atomically sets the parameter value at offset in obj if the compare value
2617
* matches the existing value in the object.
2618
* The get operation has memory semantics of getAcquire.
2619
* The set operation has the memory semantics of set.
2620
*
2621
* @param obj object into which to store the value
2622
* @param offset location to compare and store value in obj
2623
* @param compareValue value that is expected to be in obj at offset
2624
* @param exchangeValue value that will be set in obj at offset if compare is successful
2625
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
2626
*/
2627
public final boolean compareAndExchangeBooleanAcquire(Object obj, long offset, boolean compareValue,
2628
boolean exchangeValue) {
2629
byte result = compareAndExchangeByteAcquire(obj, offset, bool2byte(compareValue), bool2byte(exchangeValue));
2630
return byte2bool(result);
2631
}
2632
2633
/**
2634
* Atomically sets the parameter value at offset in obj if the compare value
2635
* matches the existing value in the object.
2636
* The get operation has memory semantics of get.
2637
* The set operation has the memory semantics of setRelease.
2638
*
2639
* @param obj object into which to store the value
2640
* @param offset location to compare and store value in obj
2641
* @param compareValue value that is expected to be in obj at offset
2642
* @param exchangeValue value that will be set in obj at offset if compare is successful
2643
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
2644
*/
2645
public final boolean compareAndExchangeBooleanRelease(Object obj, long offset, boolean compareValue,
2646
boolean exchangeValue) {
2647
byte result = compareAndExchangeByteRelease(obj, offset, bool2byte(compareValue), bool2byte(exchangeValue));
2648
return byte2bool(result);
2649
}
2650
2651
/**
2652
* Sets the parameter value at offset in obj if the compare value
2653
* matches the existing value in the object.
2654
* The get operation has memory semantics of get.
2655
* The set operation has the memory semantics of set.
2656
*
2657
* @param obj object into which to store the value
2658
* @param offset location to compare and store value in obj
2659
* @param compareValue value that is expected to be in obj at offset
2660
* @param setValue value that will be set in obj at offset if compare is successful
2661
* @return boolean value indicating whether the field was updated
2662
*/
2663
public final boolean weakCompareAndSetBoolean(Object obj, long offset, boolean compareValue, boolean setValue) {
2664
return weakCompareAndSetByte(obj, offset, bool2byte(compareValue), bool2byte(setValue));
2665
}
2666
2667
/**
2668
* Sets the parameter value at offset in obj if the compare value
2669
* matches the existing value in the object.
2670
* The get operation has memory semantics of getAcquire.
2671
* The set operation has the memory semantics of set.
2672
*
2673
* @param obj object into which to store the value
2674
* @param offset location to compare and store value in obj
2675
* @param compareValue value that is expected to be in obj at offset
2676
* @param setValue value that will be set in obj at offset if compare is successful
2677
* @return boolean value indicating whether the field was updated
2678
*/
2679
public final boolean weakCompareAndSetBooleanAcquire(Object obj, long offset, boolean compareValue,
2680
boolean setValue) {
2681
return weakCompareAndSetByteAcquire(obj, offset, bool2byte(compareValue), bool2byte(setValue));
2682
}
2683
2684
/**
2685
* Sets the parameter value at offset in obj if the compare value
2686
* matches the existing value in the object.
2687
* The get operation has memory semantics of get.
2688
* The set operation has the memory semantics of setRelease.
2689
*
2690
* @param obj object into which to store the value
2691
* @param offset location to compare and store value in obj
2692
* @param compareValue value that is expected to be in obj at offset
2693
* @param setValue value that will be set in obj at offset if compare is successful
2694
* @return boolean value indicating whether the field was updated
2695
*/
2696
public final boolean weakCompareAndSetBooleanRelease(Object obj, long offset, boolean compareValue,
2697
boolean setValue) {
2698
return weakCompareAndSetByteRelease(obj, offset, bool2byte(compareValue), bool2byte(setValue));
2699
}
2700
2701
/**
2702
* Sets the parameter value at offset in obj if the compare value
2703
* matches the existing value in the object.
2704
* The get operation has memory semantics of get.
2705
* The set operation has the memory semantics of set.
2706
*
2707
* @param obj object into which to store the value
2708
* @param offset location to compare and store value in obj
2709
* @param compareValue value that is expected to be in obj at offset
2710
* @param setValue value that will be set in obj at offset if compare is successful
2711
* @return boolean value indicating whether the field was updated
2712
*/
2713
public final boolean weakCompareAndSetBooleanPlain(Object obj, long offset, boolean compareValue,
2714
boolean setValue) {
2715
return weakCompareAndSetBytePlain(obj, offset, bool2byte(compareValue), bool2byte(setValue));
2716
}
2717
2718
/**
2719
* Atomically sets the parameter value at offset in obj if the compare value
2720
* matches the existing value in the object.
2721
* The get operation has memory semantics of getAcquire.
2722
* The set operation has the memory semantics of set.
2723
*
2724
* @param obj object into which to store the value
2725
* @param offset location to compare and store value in obj
2726
* @param compareValue value that is expected to be in obj at offset
2727
* @param exchangeValue value that will be set in obj at offset if compare is successful
2728
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
2729
*/
2730
public final Object compareAndExchangeObjectAcquire(Object obj, long offset, Object compareValue,
2731
Object exchangeValue) {
2732
return compareAndExchangeObject(obj, offset, compareValue, exchangeValue);
2733
}
2734
2735
/**
2736
* Atomically sets the parameter value at offset in obj if the compare value
2737
* matches the existing value in the object.
2738
* The get operation has memory semantics of get.
2739
* The set operation has the memory semantics of setRelease.
2740
*
2741
* @param obj object into which to store the value
2742
* @param offset location to compare and store value in obj
2743
* @param compareValue value that is expected to be in obj at offset
2744
* @param exchangeValue value that will be set in obj at offset if compare is successful
2745
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
2746
*/
2747
public final Object compareAndExchangeObjectRelease(Object obj, long offset, Object compareValue,
2748
Object exchangeValue) {
2749
return compareAndExchangeObject(obj, offset, compareValue, exchangeValue);
2750
}
2751
2752
/**
2753
* Sets the parameter value at offset in obj if the compare value
2754
* matches the existing value in the object.
2755
* The get operation has memory semantics of get.
2756
* The set operation has the memory semantics of set.
2757
*
2758
* @param obj object into which to store the value
2759
* @param offset location to compare and store value in obj
2760
* @param compareValue value that is expected to be in obj at offset
2761
* @param setValue value that will be set in obj at offset if compare is successful
2762
* @return boolean value indicating whether the field was updated
2763
*/
2764
public final boolean weakCompareAndSetObjectPlain(Object obj, long offset, Object compareValue, Object setValue) {
2765
return compareAndSetObject(obj, offset, compareValue, setValue);
2766
}
2767
2768
/**
2769
* Sets the parameter value at offset in obj if the compare value
2770
* matches the existing value in the object.
2771
* The get operation has memory semantics of getAcquire.
2772
* The set operation has the memory semantics of set.
2773
*
2774
* @param obj object into which to store the value
2775
* @param offset location to compare and store value in obj
2776
* @param compareValue value that is expected to be in obj at offset
2777
* @param setValue value that will be set in obj at offset if compare is successful
2778
* @return boolean value indicating whether the field was updated
2779
*/
2780
public final boolean weakCompareAndSetObjectAcquire(Object obj, long offset, Object compareValue, Object setValue) {
2781
return compareAndSetObject(obj, offset, compareValue, setValue);
2782
}
2783
2784
/**
2785
* Sets the parameter value at offset in obj if the compare value
2786
* matches the existing value in the object.
2787
* The get operation has memory semantics of get.
2788
* The set operation has the memory semantics of setRelease.
2789
*
2790
* @param obj object into which to store the value
2791
* @param offset location to compare and store value in obj
2792
* @param compareValue value that is expected to be in obj at offset
2793
* @param setValue value that will be set in obj at offset if compare is successful
2794
* @return boolean value indicating whether the field was updated
2795
*/
2796
public final boolean weakCompareAndSetObjectRelease(Object obj, long offset, Object compareValue, Object setValue) {
2797
return compareAndSetObject(obj, offset, compareValue, setValue);
2798
}
2799
2800
/**
2801
* Sets the parameter value at offset in obj if the compare value
2802
* matches the existing value in the object.
2803
* The get operation has memory semantics of get.
2804
* The set operation has the memory semantics of set.
2805
*
2806
* @param obj object into which to store the value
2807
* @param offset location to compare and store value in obj
2808
* @param compareValue value that is expected to be in obj at offset
2809
* @param setValue value that will be set in obj at offset if compare is successful
2810
* @return boolean value indicating whether the field was updated
2811
*/
2812
public final boolean weakCompareAndSetObject(Object obj, long offset, Object compareValue, Object setValue) {
2813
return compareAndSetObject(obj, offset, compareValue, setValue);
2814
}
2815
2816
/*[IF JAVA_SPEC_VERSION >= 12]*/
2817
/**
2818
* Atomically sets the parameter value at offset in obj if the compare value
2819
* matches the existing value in the object.
2820
* The get operation has memory semantics of getAcquire.
2821
* The set operation has the memory semantics of set.
2822
*
2823
* @param obj object into which to store the value
2824
* @param offset location to compare and store value in obj
2825
* @param compareValue value that is expected to be in obj at offset
2826
* @param exchangeValue value that will be set in obj at offset if compare is successful
2827
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
2828
*/
2829
public final Object compareAndExchangeReferenceAcquire(Object obj, long offset, Object compareValue,
2830
Object exchangeValue) {
2831
return compareAndExchangeReference(obj, offset, compareValue, exchangeValue);
2832
}
2833
2834
/**
2835
* Atomically sets the parameter value at offset in obj if the compare value
2836
* matches the existing value in the object.
2837
* The get operation has memory semantics of get.
2838
* The set operation has the memory semantics of setRelease.
2839
*
2840
* @param obj object into which to store the value
2841
* @param offset location to compare and store value in obj
2842
* @param compareValue value that is expected to be in obj at offset
2843
* @param exchangeValue value that will be set in obj at offset if compare is successful
2844
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
2845
*/
2846
public final Object compareAndExchangeReferenceRelease(Object obj, long offset, Object compareValue,
2847
Object exchangeValue) {
2848
return compareAndExchangeReference(obj, offset, compareValue, exchangeValue);
2849
}
2850
2851
/**
2852
* Sets the parameter value at offset in obj if the compare value
2853
* matches the existing value in the object.
2854
* The get operation has memory semantics of get.
2855
* The set operation has the memory semantics of set.
2856
*
2857
* @param obj object into which to store the value
2858
* @param offset location to compare and store value in obj
2859
* @param compareValue value that is expected to be in obj at offset
2860
* @param setValue value that will be set in obj at offset if compare is successful
2861
* @return boolean value indicating whether the field was updated
2862
*/
2863
public final boolean weakCompareAndSetReferencePlain(Object obj, long offset, Object compareValue, Object setValue) {
2864
return compareAndSetReference(obj, offset, compareValue, setValue);
2865
}
2866
2867
/**
2868
* Sets the parameter value at offset in obj if the compare value
2869
* matches the existing value in the object.
2870
* The get operation has memory semantics of getAcquire.
2871
* The set operation has the memory semantics of set.
2872
*
2873
* @param obj object into which to store the value
2874
* @param offset location to compare and store value in obj
2875
* @param compareValue value that is expected to be in obj at offset
2876
* @param setValue value that will be set in obj at offset if compare is successful
2877
* @return boolean value indicating whether the field was updated
2878
*/
2879
public final boolean weakCompareAndSetReferenceAcquire(Object obj, long offset, Object compareValue, Object setValue) {
2880
return compareAndSetReference(obj, offset, compareValue, setValue);
2881
}
2882
2883
/**
2884
* Sets the parameter value at offset in obj if the compare value
2885
* matches the existing value in the object.
2886
* The get operation has memory semantics of get.
2887
* The set operation has the memory semantics of setRelease.
2888
*
2889
* @param obj object into which to store the value
2890
* @param offset location to compare and store value in obj
2891
* @param compareValue value that is expected to be in obj at offset
2892
* @param setValue value that will be set in obj at offset if compare is successful
2893
* @return boolean value indicating whether the field was updated
2894
*/
2895
public final boolean weakCompareAndSetReferenceRelease(Object obj, long offset, Object compareValue, Object setValue) {
2896
return compareAndSetReference(obj, offset, compareValue, setValue);
2897
}
2898
2899
/**
2900
* Sets the parameter value at offset in obj if the compare value
2901
* matches the existing value in the object.
2902
* The get operation has memory semantics of get.
2903
* The set operation has the memory semantics of set.
2904
*
2905
* @param obj object into which to store the value
2906
* @param offset location to compare and store value in obj
2907
* @param compareValue value that is expected to be in obj at offset
2908
* @param setValue value that will be set in obj at offset if compare is successful
2909
* @return boolean value indicating whether the field was updated
2910
*/
2911
public final boolean weakCompareAndSetReference(Object obj, long offset, Object compareValue, Object setValue) {
2912
return compareAndSetReference(obj, offset, compareValue, setValue);
2913
}
2914
/*[ENDIF] JAVA_SPEC_VERSION >= 12 */
2915
2916
/**
2917
* Gets the value of the byte in the obj parameter referenced by offset using acquire semantics.
2918
* Preceding loads will not be reordered with subsequent loads/stores.
2919
*
2920
* @param obj object from which to retrieve the value
2921
* @param offset position of the value in obj
2922
* @return byte value stored in obj
2923
*/
2924
public final byte getByteAcquire(Object obj, long offset) {
2925
return getByteVolatile(obj, offset);
2926
}
2927
2928
/**
2929
* Gets the value of the int in the obj parameter referenced by offset using acquire semantics.
2930
* Preceding loads will not be reordered with subsequent loads/stores.
2931
*
2932
* @param obj object from which to retrieve the value
2933
* @param offset position of the value in obj
2934
* @return int value stored in obj
2935
*/
2936
public final int getIntAcquire(Object obj, long offset) {
2937
return getIntVolatile(obj, offset);
2938
}
2939
2940
/**
2941
* Gets the value of the long in the obj parameter referenced by offset using acquire semantics.
2942
* Preceding loads will not be reordered with subsequent loads/stores.
2943
*
2944
* @param obj object from which to retrieve the value
2945
* @param offset position of the value in obj
2946
* @return long value stored in obj
2947
*/
2948
public final long getLongAcquire(Object obj, long offset) {
2949
return getLongVolatile(obj, offset);
2950
}
2951
2952
/**
2953
* Gets the value of the float in the obj parameter referenced by offset using acquire semantics.
2954
* Preceding loads will not be reordered with subsequent loads/stores.
2955
*
2956
* @param obj object from which to retrieve the value
2957
* @param offset position of the value in obj
2958
* @return float value stored in obj
2959
*/
2960
public final float getFloatAcquire(Object obj, long offset) {
2961
return getFloatVolatile(obj, offset);
2962
}
2963
2964
/**
2965
* Gets the value of the double in the obj parameter referenced by offset using acquire semantics.
2966
* Preceding loads will not be reordered with subsequent loads/stores.
2967
*
2968
* @param obj object from which to retrieve the value
2969
* @param offset position of the value in obj
2970
* @return double value stored in obj
2971
*/
2972
public final double getDoubleAcquire(Object obj, long offset) {
2973
return getDoubleVolatile(obj, offset);
2974
}
2975
2976
/**
2977
* Gets the value of the short in the obj parameter referenced by offset using acquire semantics.
2978
* Preceding loads will not be reordered with subsequent loads/stores.
2979
*
2980
* @param obj object from which to retrieve the value
2981
* @param offset position of the value in obj
2982
* @return short value stored in obj
2983
*/
2984
public final short getShortAcquire(Object obj, long offset) {
2985
return getShortVolatile(obj, offset);
2986
}
2987
2988
/**
2989
* Gets the value of the char in the obj parameter referenced by offset using acquire semantics.
2990
* Preceding loads will not be reordered with subsequent loads/stores.
2991
*
2992
* @param obj object from which to retrieve the value
2993
* @param offset position of the value in obj
2994
* @return char value stored in obj
2995
*/
2996
public final char getCharAcquire(Object obj, long offset) {
2997
return getCharVolatile(obj, offset);
2998
}
2999
3000
/**
3001
* Gets the value of the boolean in the obj parameter referenced by offset using acquire semantics.
3002
* Preceding loads will not be reordered with subsequent loads/stores.
3003
*
3004
* @param obj object from which to retrieve the value
3005
* @param offset position of the value in obj
3006
* @return boolean value stored in obj
3007
*/
3008
public final boolean getBooleanAcquire(Object obj, long offset) {
3009
return getBooleanVolatile(obj, offset);
3010
}
3011
3012
/**
3013
* Gets the value of the Object in the obj parameter referenced by offset using acquire semantics.
3014
* Preceding loads will not be reordered with subsequent loads/stores.
3015
*
3016
* @param obj object from which to retrieve the value
3017
* @param offset position of the value in obj
3018
* @return Object value stored in obj
3019
*/
3020
public final Object getObjectAcquire(Object obj, long offset) {
3021
return getObjectVolatile(obj, offset);
3022
}
3023
3024
/*[IF JAVA_SPEC_VERSION >= 12]*/
3025
/**
3026
* Gets the value of the Object in the obj parameter referenced by offset using acquire semantics.
3027
* Preceding loads will not be reordered with subsequent loads/stores.
3028
*
3029
* @param obj object from which to retrieve the value
3030
* @param offset position of the value in obj
3031
* @return Object value stored in obj
3032
*/
3033
public final Object getReferenceAcquire(Object obj, long offset) {
3034
return getReferenceVolatile(obj, offset);
3035
}
3036
/*[ENDIF] JAVA_SPEC_VERSION >= 12 */
3037
3038
/**
3039
* Sets the value of the byte in the obj parameter at memory offset using acquire semantics.
3040
* Preceding stores will not be reordered with subsequent loads/stores.
3041
*
3042
* @param obj object into which to store the value
3043
* @param offset position of the value in obj
3044
* @param value byte to store in obj
3045
*/
3046
public final void putByteRelease(Object obj, long offset, byte value) {
3047
putByteVolatile(obj, offset, value);
3048
}
3049
3050
/**
3051
* Sets the value of the int in the obj parameter at memory offset using acquire semantics.
3052
* Preceding stores will not be reordered with subsequent loads/stores.
3053
*
3054
* @param obj object into which to store the value
3055
* @param offset position of the value in obj
3056
* @param value int to store in obj
3057
*/
3058
public final void putIntRelease(Object obj, long offset, int value) {
3059
putIntVolatile(obj, offset, value);
3060
}
3061
3062
/**
3063
* Sets the value of the long in the obj parameter at memory offset using acquire semantics.
3064
* Preceding stores will not be reordered with subsequent loads/stores.
3065
*
3066
* @param obj object into which to store the value
3067
* @param offset position of the value in obj
3068
* @param value long to store in obj
3069
*/
3070
public final void putLongRelease(Object obj, long offset, long value) {
3071
putLongVolatile(obj, offset, value);
3072
}
3073
3074
/**
3075
* Sets the value of the float in the obj parameter at memory offset using acquire semantics.
3076
* Preceding stores will not be reordered with subsequent loads/stores.
3077
*
3078
* @param obj object into which to store the value
3079
* @param offset position of the value in obj
3080
* @param value float to store in obj
3081
*/
3082
public final void putFloatRelease(Object obj, long offset, float value) {
3083
putFloatVolatile(obj, offset, value);
3084
}
3085
3086
/**
3087
* Sets the value of the double in the obj parameter at memory offset using acquire semantics.
3088
* Preceding stores will not be reordered with subsequent loads/stores.
3089
*
3090
* @param obj object into which to store the value
3091
* @param offset position of the value in obj
3092
* @param value double to store in obj
3093
*/
3094
public final void putDoubleRelease(Object obj, long offset, double value) {
3095
putDoubleVolatile(obj, offset, value);
3096
}
3097
3098
/**
3099
* Sets the value of the short in the obj parameter at memory offset using acquire semantics.
3100
* Preceding stores will not be reordered with subsequent loads/stores.
3101
*
3102
* @param obj object into which to store the value
3103
* @param offset position of the value in obj
3104
* @param value short to store in obj
3105
*/
3106
public final void putShortRelease(Object obj, long offset, short value) {
3107
putShortVolatile(obj, offset, value);
3108
}
3109
3110
/**
3111
* Sets the value of the char in the obj parameter at memory offset using acquire semantics.
3112
* Preceding stores will not be reordered with subsequent loads/stores.
3113
*
3114
* @param obj object into which to store the value
3115
* @param offset position of the value in obj
3116
* @param value char to store in obj
3117
*/
3118
public final void putCharRelease(Object obj, long offset, char value) {
3119
putCharVolatile(obj, offset, value);
3120
}
3121
3122
/**
3123
* Sets the value of the boolean in the obj parameter at memory offset using acquire semantics.
3124
* Preceding stores will not be reordered with subsequent loads/stores.
3125
*
3126
* @param obj object into which to store the value
3127
* @param offset position of the value in obj
3128
* @param value boolean to store in obj
3129
*/
3130
public final void putBooleanRelease(Object obj, long offset, boolean value) {
3131
putBooleanVolatile(obj, offset, value);
3132
}
3133
3134
/**
3135
* Sets the value of the Object in the obj parameter at memory offset using acquire semantics.
3136
* Preceding stores will not be reordered with subsequent loads/stores.
3137
*
3138
* @param obj object into which to store the value
3139
* @param offset position of the value in obj
3140
* @param value Object to store in obj
3141
*/
3142
public final void putObjectRelease(Object obj, long offset, Object value) {
3143
putObjectVolatile(obj, offset, value);
3144
}
3145
3146
/*[IF JAVA_SPEC_VERSION >= 12]*/
3147
/**
3148
* Sets the value of the Object in the obj parameter at memory offset using acquire semantics.
3149
* Preceding stores will not be reordered with subsequent loads/stores.
3150
*
3151
* @param obj object into which to store the value
3152
* @param offset position of the value in obj
3153
* @param value Object to store in obj
3154
*/
3155
public final void putReferenceRelease(Object obj, long offset, Object value) {
3156
putReferenceVolatile(obj, offset, value);
3157
}
3158
/*[ENDIF] JAVA_SPEC_VERSION >= 12 */
3159
3160
/**
3161
* Gets the value of the byte in the obj parameter referenced by offset.
3162
* The operation is in program order, but does enforce ordering with respect to other threads.
3163
*
3164
* @param obj object from which to retrieve the value
3165
* @param offset position of the value in obj
3166
* @return byte value stored in obj
3167
*/
3168
public final byte getByteOpaque(Object obj, long offset) {
3169
return getByteVolatile(obj, offset);
3170
}
3171
3172
/**
3173
* Gets the value of the int in the obj parameter referenced by offset.
3174
* The operation is in program order, but does enforce ordering with respect to other threads.
3175
*
3176
* @param obj object from which to retrieve the value
3177
* @param offset position of the value in obj
3178
* @return int value stored in obj
3179
*/
3180
public final int getIntOpaque(Object obj, long offset) {
3181
return getIntVolatile(obj, offset);
3182
}
3183
3184
/**
3185
* Gets the value of the long in the obj parameter referenced by offset.
3186
* The operation is in program order, but does enforce ordering with respect to other threads.
3187
*
3188
* @param obj object from which to retrieve the value
3189
* @param offset position of the value in obj
3190
* @return long value stored in obj
3191
*/
3192
public final long getLongOpaque(Object obj, long offset) {
3193
return getLongVolatile(obj, offset);
3194
}
3195
3196
/**
3197
* Gets the value of the float in the obj parameter referenced by offset.
3198
* The operation is in program order, but does enforce ordering with respect to other threads.
3199
*
3200
* @param obj object from which to retrieve the value
3201
* @param offset position of the value in obj
3202
* @return float value stored in obj
3203
*/
3204
public final float getFloatOpaque(Object obj, long offset) {
3205
return getFloatVolatile(obj, offset);
3206
}
3207
3208
/**
3209
* Gets the value of the double in the obj parameter referenced by offset.
3210
* The operation is in program order, but does enforce ordering with respect to other threads.
3211
*
3212
* @param obj object from which to retrieve the value
3213
* @param offset position of the value in obj
3214
* @return double value stored in obj
3215
*/
3216
public final double getDoubleOpaque(Object obj, long offset) {
3217
return getDoubleVolatile(obj, offset);
3218
}
3219
3220
/**
3221
* Gets the value of the short in the obj parameter referenced by offset.
3222
* The operation is in program order, but does enforce ordering with respect to other threads.
3223
*
3224
* @param obj object from which to retrieve the value
3225
* @param offset position of the value in obj
3226
* @return short value stored in obj
3227
*/
3228
public final short getShortOpaque(Object obj, long offset) {
3229
return getShortVolatile(obj, offset);
3230
}
3231
3232
/**
3233
* Gets the value of the char in the obj parameter referenced by offset.
3234
* The operation is in program order, but does enforce ordering with respect to other threads.
3235
*
3236
* @param obj object from which to retrieve the value
3237
* @param offset position of the value in obj
3238
* @return char value stored in obj
3239
*/
3240
public final char getCharOpaque(Object obj, long offset) {
3241
return getCharVolatile(obj, offset);
3242
}
3243
3244
/**
3245
* Gets the value of the boolean in the obj parameter referenced by offset.
3246
* The operation is in program order, but does enforce ordering with respect to other threads.
3247
*
3248
* @param obj object from which to retrieve the value
3249
* @param offset position of the value in obj
3250
* @return boolean value stored in obj
3251
*/
3252
public final boolean getBooleanOpaque(Object obj, long offset) {
3253
return getBooleanVolatile(obj, offset);
3254
}
3255
3256
/**
3257
* Gets the value of the Object in the obj parameter referenced by offset.
3258
* The operation is in program order, but does enforce ordering with respect to other threads.
3259
*
3260
* @param obj object from which to retrieve the value
3261
* @param offset position of the value in obj
3262
* @return Object value stored in obj
3263
*/
3264
public final Object getObjectOpaque(Object obj, long offset) {
3265
return getObjectVolatile(obj, offset);
3266
}
3267
3268
/*[IF JAVA_SPEC_VERSION >= 12]*/
3269
/**
3270
* Gets the value of the Object in the obj parameter referenced by offset.
3271
* The operation is in program order, but does enforce ordering with respect to other threads.
3272
*
3273
* @param obj object from which to retrieve the value
3274
* @param offset position of the value in obj
3275
* @return Object value stored in obj
3276
*/
3277
public final Object getReferenceOpaque(Object obj, long offset) {
3278
return getReferenceVolatile(obj, offset);
3279
}
3280
/*[ENDIF] JAVA_SPEC_VERSION >= 12 */
3281
3282
/**
3283
* Sets the value of the byte in the obj parameter at memory offset.
3284
* The operation is in program order, but does enforce ordering with respect to other threads.
3285
*
3286
* @param obj object into which to store the value
3287
* @param offset position of the value in obj
3288
* @param value byte to store in obj
3289
*/
3290
public final void putByteOpaque(Object obj, long offset, byte value) {
3291
putByteVolatile(obj, offset, value);
3292
}
3293
3294
/**
3295
* Sets the value of the int in the obj parameter at memory offset.
3296
* The operation is in program order, but does enforce ordering with respect to other threads.
3297
*
3298
* @param obj object into which to store the value
3299
* @param offset position of the value in obj
3300
* @param value int to store in obj
3301
*/
3302
public final void putIntOpaque(Object obj, long offset, int value) {
3303
putIntVolatile(obj, offset, value);
3304
}
3305
3306
/**
3307
* Sets the value of the long in the obj parameter at memory offset.
3308
* The operation is in program order, but does enforce ordering with respect to other threads.
3309
*
3310
* @param obj object into which to store the value
3311
* @param offset position of the value in obj
3312
* @param value long to store in obj
3313
*/
3314
public final void putLongOpaque(Object obj, long offset, long value) {
3315
putLongVolatile(obj, offset, value);
3316
}
3317
3318
/**
3319
* Sets the value of the float in the obj parameter at memory offset.
3320
* The operation is in program order, but does enforce ordering with respect to other threads.
3321
*
3322
* @param obj object into which to store the value
3323
* @param offset position of the value in obj
3324
* @param value float to store in obj
3325
*/
3326
public final void putFloatOpaque(Object obj, long offset, float value) {
3327
putFloatVolatile(obj, offset, value);
3328
}
3329
3330
/**
3331
* Sets the value of the double in the obj parameter at memory offset.
3332
* The operation is in program order, but does enforce ordering with respect to other threads.
3333
*
3334
* @param obj object into which to store the value
3335
* @param offset position of the value in obj
3336
* @param value double to store in obj
3337
*/
3338
public final void putDoubleOpaque(Object obj, long offset, double value) {
3339
putDoubleVolatile(obj, offset, value);
3340
}
3341
3342
/**
3343
* Sets the value of the short in the obj parameter at memory offset.
3344
* The operation is in program order, but does enforce ordering with respect to other threads.
3345
*
3346
* @param obj object into which to store the value
3347
* @param offset position of the value in obj
3348
* @param value short to store in obj
3349
*/
3350
public final void putShortOpaque(Object obj, long offset, short value) {
3351
putShortVolatile(obj, offset, value);
3352
}
3353
3354
/**
3355
* Sets the value of the char in the obj parameter at memory offset.
3356
* The operation is in program order, but does enforce ordering with respect to other threads.
3357
*
3358
* @param obj object into which to store the value
3359
* @param offset position of the value in obj
3360
* @param value char to store in obj
3361
*/
3362
public final void putCharOpaque(Object obj, long offset, char value) {
3363
putCharVolatile(obj, offset, value);
3364
}
3365
3366
/**
3367
* Sets the value of the boolean in the obj parameter at memory offset.
3368
* The operation is in program order, but does enforce ordering with respect to other threads.
3369
*
3370
* @param obj object into which to store the value
3371
* @param offset position of the value in obj
3372
* @param value boolean to store in obj
3373
*/
3374
public final void putBooleanOpaque(Object obj, long offset, boolean value) {
3375
putBooleanVolatile(obj, offset, value);
3376
}
3377
3378
/**
3379
* Sets the value of the Object in the obj parameter at memory offset.
3380
* The operation is in program order, but does enforce ordering with respect to other threads.
3381
*
3382
* @param obj object into which to store the value
3383
* @param offset position of the value in obj
3384
* @param value Object to store in obj
3385
*/
3386
public final void putObjectOpaque(Object obj, long offset, Object value) {
3387
putObjectVolatile(obj, offset, value);
3388
}
3389
3390
/*[IF JAVA_SPEC_VERSION >= 12]*/
3391
/**
3392
* Sets the value of the Object in the obj parameter at memory offset.
3393
* The operation is in program order, but does enforce ordering with respect to other threads.
3394
*
3395
* @param obj object into which to store the value
3396
* @param offset position of the value in obj
3397
* @param value Object to store in obj
3398
*/
3399
public final void putReferenceOpaque(Object obj, long offset, Object value) {
3400
putReferenceVolatile(obj, offset, value);
3401
}
3402
/*[ENDIF] JAVA_SPEC_VERSION >= 12 */
3403
3404
/**
3405
* Get the load average in the system.
3406
*
3407
* NOTE: native implementation is a stub.
3408
*
3409
* @param loadavg array of elements
3410
* @param numberOfElements number of samples
3411
* @return load average
3412
*
3413
* @throws ArrayIndexOutOfBoundsException if numberOfElements is negative, more than three, or
3414
* the length of the loadavg array is greater than the numberOfElements
3415
*/
3416
public int getLoadAverage(double[] loadavg, int numberOfElements) {
3417
if ((numberOfElements < 0) || (numberOfElements > 3) || (loadavg.length > numberOfElements)) {
3418
throw new ArrayIndexOutOfBoundsException();
3419
}
3420
3421
return getLoadAverage0(loadavg, numberOfElements);
3422
}
3423
3424
/**
3425
* Atomically adds to the current value of the field at offset in obj
3426
* and returns the value of the field prior to the update.
3427
* The get operation has the memory semantics of getVolatile.
3428
* The set operation has the memory semantics of setVolatile.
3429
*
3430
* @param obj object into which to add the value
3431
* @param offset location to add value in obj
3432
* @param value to add to existing value in field
3433
* @return value of field in obj at offset before update
3434
*/
3435
public final byte getAndAddByte(Object obj, long offset, byte value) {
3436
for (;;) {
3437
byte byteAtOffset = getByteVolatile(obj, offset);
3438
if (weakCompareAndSetByte(obj, offset, byteAtOffset, (byte) (byteAtOffset + value))) {
3439
return byteAtOffset;
3440
}
3441
}
3442
}
3443
3444
/**
3445
* Atomically adds to the current value of the field at offset in obj
3446
* and returns the value of the field prior to the update.
3447
* The get operation has the memory semantics of get.
3448
* The set operation has the memory semantics of setRelease.
3449
*
3450
* @param obj object into which to add the value
3451
* @param offset location to add value in obj
3452
* @param value to add to existing value in field
3453
* @return value of field in obj at offset before update
3454
*/
3455
public final byte getAndAddByteRelease(Object obj, long offset, byte value) {
3456
for (;;) {
3457
byte byteAtOffset = getByte(obj, offset);
3458
if (weakCompareAndSetByteRelease(obj, offset, byteAtOffset, (byte) (byteAtOffset + value))) {
3459
return byteAtOffset;
3460
}
3461
}
3462
}
3463
3464
/**
3465
* Atomically adds to the current value of the field at offset in obj
3466
* and returns the value of the field prior to the update.
3467
* The get operation has the memory semantics of getAcquire.
3468
* The set operation has the memory semantics of set.
3469
*
3470
* @param obj object into which to add the value
3471
* @param offset location to add value in obj
3472
* @param value to add to existing value in field
3473
* @return value of field in obj at offset before update
3474
*/
3475
public final byte getAndAddByteAcquire(Object obj, long offset, byte value) {
3476
for (;;) {
3477
byte byteAtOffset = getByteAcquire(obj, offset);
3478
if (weakCompareAndSetByteAcquire(obj, offset, byteAtOffset, (byte) (byteAtOffset + value))) {
3479
return byteAtOffset;
3480
}
3481
}
3482
}
3483
3484
/**
3485
* Atomically adds to the current value of the field at offset in obj
3486
* and returns the value of the field prior to the update.
3487
* The get operation has the memory semantics of getVolatile.
3488
* The set operation has the memory semantics of setVolatile.
3489
*
3490
* @param obj object into which to add the value
3491
* @param offset location to add value in obj
3492
* @param value to add to existing value in field
3493
* @return value of field in obj at offset before update
3494
*/
3495
public final int getAndAddInt(Object obj, long offset, int value) {
3496
for (;;) {
3497
int intAtOffset = getIntVolatile(obj, offset);
3498
if (weakCompareAndSetInt(obj, offset, intAtOffset, intAtOffset + value)) {
3499
return intAtOffset;
3500
}
3501
}
3502
}
3503
3504
/**
3505
* Atomically adds to the current value of the field at offset in obj
3506
* and returns the value of the field prior to the update.
3507
* The get operation has the memory semantics of get.
3508
* The set operation has the memory semantics of setRelease.
3509
*
3510
* @param obj object into which to add the value
3511
* @param offset location to add value in obj
3512
* @param value to add to existing value in field
3513
* @return value of field in obj at offset before update
3514
*/
3515
public final int getAndAddIntRelease(Object obj, long offset, int value) {
3516
for (;;) {
3517
int intAtOffset = getInt(obj, offset);
3518
if (weakCompareAndSetIntRelease(obj, offset, intAtOffset, intAtOffset + value)) {
3519
return intAtOffset;
3520
}
3521
}
3522
}
3523
3524
/**
3525
* Atomically adds to the current value of the field at offset in obj
3526
* and returns the value of the field prior to the update.
3527
* The get operation has the memory semantics of getAcquire.
3528
* The set operation has the memory semantics of set.
3529
*
3530
* @param obj object into which to add the value
3531
* @param offset location to add value in obj
3532
* @param value to add to existing value in field
3533
* @return value of field in obj at offset before update
3534
*/
3535
public final int getAndAddIntAcquire(Object obj, long offset, int value) {
3536
for (;;) {
3537
int intAtOffset = getIntAcquire(obj, offset);
3538
if (weakCompareAndSetIntAcquire(obj, offset, intAtOffset, intAtOffset + value)) {
3539
return intAtOffset;
3540
}
3541
}
3542
}
3543
3544
/**
3545
* Atomically adds to the current value of the field at offset in obj
3546
* and returns the value of the field prior to the update.
3547
* The get operation has the memory semantics of getVolatile.
3548
* The set operation has the memory semantics of setVolatile.
3549
*
3550
* @param obj object into which to add the value
3551
* @param offset location to add value in obj
3552
* @param value to add to existing value in field
3553
* @return value of field in obj at offset before update
3554
*/
3555
public final long getAndAddLong(Object obj, long offset, long value) {
3556
for (;;) {
3557
long longAtOffset = getLongVolatile(obj, offset);
3558
if (weakCompareAndSetLong(obj, offset, longAtOffset, longAtOffset + value)) {
3559
return longAtOffset;
3560
}
3561
}
3562
}
3563
3564
/**
3565
* Atomically adds to the current value of the field at offset in obj
3566
* and returns the value of the field prior to the update.
3567
* The get operation has the memory semantics of get.
3568
* The set operation has the memory semantics of setRelease.
3569
*
3570
* @param obj object into which to add the value
3571
* @param offset location to add value in obj
3572
* @param value to add to existing value in field
3573
* @return value of field in obj at offset before update
3574
*/
3575
public final long getAndAddLongRelease(Object obj, long offset, long value) {
3576
for (;;) {
3577
long longAtOffset = getLong(obj, offset);
3578
if (weakCompareAndSetLongRelease(obj, offset, longAtOffset, longAtOffset + value)) {
3579
return longAtOffset;
3580
}
3581
}
3582
}
3583
3584
/**
3585
* Atomically adds to the current value of the field at offset in obj
3586
* and returns the value of the field prior to the update.
3587
* The get operation has the memory semantics of getAcquire.
3588
* The set operation has the memory semantics of set.
3589
*
3590
* @param obj object into which to add the value
3591
* @param offset location to add value in obj
3592
* @param value to add to existing value in field
3593
* @return value of field in obj at offset before update
3594
*/
3595
public final long getAndAddLongAcquire(Object obj, long offset, long value) {
3596
for (;;) {
3597
long longAtOffset = getLongAcquire(obj, offset);
3598
if (weakCompareAndSetLongAcquire(obj, offset, longAtOffset, longAtOffset + value)) {
3599
return longAtOffset;
3600
}
3601
}
3602
}
3603
3604
/**
3605
* Atomically adds to the current value of the field at offset in obj
3606
* and returns the value of the field prior to the update.
3607
* The get operation has the memory semantics of getVolatile.
3608
* The set operation has the memory semantics of setVolatile.
3609
*
3610
* @param obj object into which to add the value
3611
* @param offset location to add value in obj
3612
* @param value to add to existing value in field
3613
* @return value of field in obj at offset before update
3614
*/
3615
public final float getAndAddFloat(Object obj, long offset, float value) {
3616
for (;;) {
3617
int intAtOffset = getIntVolatile(obj, offset);
3618
float floatAtOffset = Float.intBitsToFloat(intAtOffset);
3619
if (weakCompareAndSetInt(obj, offset, intAtOffset,
3620
Float.floatToRawIntBits(floatAtOffset + value))) {
3621
return floatAtOffset;
3622
}
3623
}
3624
}
3625
3626
/**
3627
* Atomically adds to the current value of the field at offset in obj
3628
* and returns the value of the field prior to the update.
3629
* The get operation has the memory semantics of get.
3630
* The set operation has the memory semantics of setRelease.
3631
*
3632
* @param obj object into which to add the value
3633
* @param offset location to add value in obj
3634
* @param value to add to existing value in field
3635
* @return value of field in obj at offset before update
3636
*/
3637
public final float getAndAddFloatRelease(Object obj, long offset, float value) {
3638
for (;;) {
3639
int intAtOffset = getInt(obj, offset);
3640
float floatAtOffset = Float.intBitsToFloat(intAtOffset);
3641
if (weakCompareAndSetIntRelease(obj, offset, intAtOffset,
3642
Float.floatToRawIntBits(floatAtOffset + value))) {
3643
return floatAtOffset;
3644
}
3645
}
3646
}
3647
3648
/**
3649
* Atomically adds to the current value of the field at offset in obj
3650
* and returns the value of the field prior to the update.
3651
* The get operation has the memory semantics of getAcquire.
3652
* The set operation has the memory semantics of set.
3653
*
3654
* @param obj object into which to add the value
3655
* @param offset location to add value in obj
3656
* @param value to add to existing value in field
3657
* @return value of field in obj at offset before update
3658
*/
3659
public final float getAndAddFloatAcquire(Object obj, long offset, float value) {
3660
for (;;) {
3661
int intAtOffset = getIntAcquire(obj, offset);
3662
float floatAtOffset = Float.intBitsToFloat(intAtOffset);
3663
if (weakCompareAndSetIntAcquire(obj, offset, intAtOffset,
3664
Float.floatToRawIntBits(floatAtOffset + value))) {
3665
return floatAtOffset;
3666
}
3667
}
3668
}
3669
3670
/**
3671
* Atomically adds to the current value of the field at offset in obj
3672
* and returns the value of the field prior to the update.
3673
* The get operation has the memory semantics of getVolatile.
3674
* The set operation has the memory semantics of setVolatile.
3675
*
3676
* @param obj object into which to add the value
3677
* @param offset location to add value in obj
3678
* @param value to add to existing value in field
3679
* @return value of field in obj at offset before update
3680
*/
3681
public final double getAndAddDouble(Object obj, long offset, double value) {
3682
for (;;) {
3683
long longAtOffset = getLongVolatile(obj, offset);
3684
double doubleAtOffset = Double.longBitsToDouble(longAtOffset);
3685
if (weakCompareAndSetLong(obj, offset, longAtOffset,
3686
Double.doubleToRawLongBits(doubleAtOffset + value))) {
3687
return doubleAtOffset;
3688
}
3689
}
3690
}
3691
3692
/**
3693
* Atomically adds to the current value of the field at offset in obj
3694
* and returns the value of the field prior to the update.
3695
* The get operation has the memory semantics of get.
3696
* The set operation has the memory semantics of setRelease.
3697
*
3698
* @param obj object into which to add the value
3699
* @param offset location to add value in obj
3700
* @param value to add to existing value in field
3701
* @return value of field in obj at offset before update
3702
*/
3703
public final double getAndAddDoubleRelease(Object obj, long offset, double value) {
3704
for (;;) {
3705
long longAtOffset = getLong(obj, offset);
3706
double doubleAtOffset = Double.longBitsToDouble(longAtOffset);
3707
if (weakCompareAndSetLongRelease(obj, offset, longAtOffset,
3708
Double.doubleToRawLongBits(doubleAtOffset + value))) {
3709
return doubleAtOffset;
3710
}
3711
}
3712
}
3713
3714
/**
3715
* Atomically adds to the current value of the field at offset in obj
3716
* and returns the value of the field prior to the update.
3717
* The get operation has the memory semantics of getAcquire.
3718
* The set operation has the memory semantics of set.
3719
*
3720
* @param obj object into which to add the value
3721
* @param offset location to add value in obj
3722
* @param value to add to existing value in field
3723
* @return value of field in obj at offset before update
3724
*/
3725
public final double getAndAddDoubleAcquire(Object obj, long offset, double value) {
3726
for (;;) {
3727
long longAtOffset = getLongAcquire(obj, offset);
3728
double doubleAtOffset = Double.longBitsToDouble(longAtOffset);
3729
if (weakCompareAndSetLongAcquire(obj, offset, longAtOffset,
3730
Double.doubleToRawLongBits(doubleAtOffset + value))) {
3731
return doubleAtOffset;
3732
}
3733
}
3734
}
3735
3736
/**
3737
* Atomically adds to the current value of the field at offset in obj
3738
* and returns the value of the field prior to the update.
3739
* The get operation has the memory semantics of getVolatile.
3740
* The set operation has the memory semantics of setVolatile.
3741
*
3742
* @param obj object into which to add the value
3743
* @param offset location to add value in obj
3744
* @param value to add to existing value in field
3745
* @return value of field in obj at offset before update
3746
*/
3747
public final short getAndAddShort(Object obj, long offset, short value) {
3748
for (;;) {
3749
short shortAtOffset = getShortVolatile(obj, offset);
3750
if (weakCompareAndSetShort(obj, offset, shortAtOffset, (short) (shortAtOffset + value))) {
3751
return shortAtOffset;
3752
}
3753
}
3754
}
3755
3756
/**
3757
* Atomically adds to the current value of the field at offset in obj
3758
* and returns the value of the field prior to the update.
3759
* The get operation has the memory semantics of get.
3760
* The set operation has the memory semantics of setRelease.
3761
*
3762
* @param obj object into which to add the value
3763
* @param offset location to add value in obj
3764
* @param value to add to existing value in field
3765
* @return value of field in obj at offset before update
3766
*/
3767
public final short getAndAddShortRelease(Object obj, long offset, short value) {
3768
for (;;) {
3769
short shortAtOffset = getShort(obj, offset);
3770
if (weakCompareAndSetShortRelease(obj, offset, shortAtOffset, (short) (shortAtOffset + value))) {
3771
return shortAtOffset;
3772
}
3773
}
3774
}
3775
3776
/**
3777
* Atomically adds to the current value of the field at offset in obj
3778
* and returns the value of the field prior to the update.
3779
* The get operation has the memory semantics of getAcquire.
3780
* The set operation has the memory semantics of set.
3781
*
3782
* @param obj object into which to add the value
3783
* @param offset location to add value in obj
3784
* @param value to add to existing value in field
3785
* @return value of field in obj at offset before update
3786
*/
3787
public final short getAndAddShortAcquire(Object obj, long offset, short value) {
3788
for (;;) {
3789
short shortAtOffset = getShortAcquire(obj, offset);
3790
if (weakCompareAndSetShortAcquire(obj, offset, shortAtOffset, (short) (shortAtOffset + value))) {
3791
return shortAtOffset;
3792
}
3793
}
3794
}
3795
3796
/**
3797
* Atomically adds to the current value of the field at offset in obj
3798
* and returns the value of the field prior to the update.
3799
* The get operation has the memory semantics of getVolatile.
3800
* The set operation has the memory semantics of setVolatile.
3801
*
3802
* @param obj object into which to add the value
3803
* @param offset location to add value in obj
3804
* @param value to add to existing value in field
3805
* @return value of field in obj at offset before update
3806
*/
3807
public final char getAndAddChar(Object obj, long offset, char value) {
3808
for (;;) {
3809
char charAtOffset = getCharVolatile(obj, offset);
3810
if (weakCompareAndSetChar(obj, offset, charAtOffset, (char) (charAtOffset + value))) {
3811
return charAtOffset;
3812
}
3813
}
3814
}
3815
3816
/**
3817
* Atomically adds to the current value of the field at offset in obj
3818
* and returns the value of the field prior to the update.
3819
* The get operation has the memory semantics of get.
3820
* The set operation has the memory semantics of setRelease.
3821
*
3822
* @param obj object into which to add the value
3823
* @param offset location to add value in obj
3824
* @param value to add to existing value in field
3825
* @return value of field in obj at offset before update
3826
*/
3827
public final char getAndAddCharRelease(Object obj, long offset, char value) {
3828
for (;;) {
3829
char charAtOffset = getChar(obj, offset);
3830
if (weakCompareAndSetCharRelease(obj, offset, charAtOffset, (char) (charAtOffset + value))) {
3831
return charAtOffset;
3832
}
3833
}
3834
}
3835
3836
/**
3837
* Atomically adds to the current value of the field at offset in obj
3838
* and returns the value of the field prior to the update.
3839
* The get operation has the memory semantics of getAcquire.
3840
* The set operation has the memory semantics of set.
3841
*
3842
* @param obj object into which to add the value
3843
* @param offset location to add value in obj
3844
* @param value to add to existing value in field
3845
* @return value of field in obj at offset before update
3846
*/
3847
public final char getAndAddCharAcquire(Object obj, long offset, char value) {
3848
for (;;) {
3849
char charAtOffset = getCharAcquire(obj, offset);
3850
if (weakCompareAndSetCharAcquire(obj, offset, charAtOffset, (char) (charAtOffset + value))) {
3851
return charAtOffset;
3852
}
3853
}
3854
}
3855
3856
/**
3857
* Atomically sets value at offset in obj
3858
* and returns the value of the field prior to the update.
3859
* The get operation has the memory semantics of getVolatile.
3860
* The set operation has the memory semantics of setVolatile.
3861
*
3862
* @param obj object into which to set the value
3863
* @param offset location to set value in obj
3864
* @param value to set in obj memory
3865
* @return value of field in obj at offset before update
3866
*/
3867
public final byte getAndSetByte(Object obj, long offset, byte value) {
3868
for (;;) {
3869
byte byteAtOffset = getByteVolatile(obj, offset);
3870
if (compareAndSetByte(obj, offset, byteAtOffset, value)) {
3871
return byteAtOffset;
3872
}
3873
}
3874
}
3875
3876
/**
3877
* Atomically sets value at offset in obj
3878
* and returns the value of the field prior to the update.
3879
* The get operation has the memory semantics of get.
3880
* The set operation has the memory semantics of setRelease.
3881
*
3882
* @param obj object into which to set the value
3883
* @param offset location to set value in obj
3884
* @param value to set in obj memory
3885
* @return value of field in obj at offset before update
3886
*/
3887
public final byte getAndSetByteRelease(Object obj, long offset, byte value) {
3888
for (;;) {
3889
byte byteAtOffset = getByte(obj, offset);
3890
if (weakCompareAndSetByteRelease(obj, offset, byteAtOffset, value)) {
3891
return byteAtOffset;
3892
}
3893
}
3894
}
3895
3896
/**
3897
* Atomically sets value at offset in obj
3898
* and returns the value of the field prior to the update.
3899
* The get operation has the memory semantics of getAcquire.
3900
* The set operation has the memory semantics of set.
3901
*
3902
* @param obj object into which to set the value
3903
* @param offset location to set value in obj
3904
* @param value to set in obj memory
3905
* @return value of field in obj at offset before update
3906
*/
3907
public final byte getAndSetByteAcquire(Object obj, long offset, byte value) {
3908
for (;;) {
3909
byte byteAtOffset = getByteAcquire(obj, offset);
3910
if (weakCompareAndSetByteAcquire(obj, offset, byteAtOffset, value)) {
3911
return byteAtOffset;
3912
}
3913
}
3914
}
3915
3916
/**
3917
* Atomically sets value at offset in obj
3918
* and returns the value of the field prior to the update.
3919
* The get operation has the memory semantics of getVolatile.
3920
* The set operation has the memory semantics of setVolatile.
3921
*
3922
* @param obj object into which to set the value
3923
* @param offset location to set value in obj
3924
* @param value to set in obj memory
3925
* @return value of field in obj at offset before update
3926
*/
3927
public final int getAndSetInt(Object obj, long offset, int value) {
3928
for (;;) {
3929
int intAtOffset = getIntVolatile(obj, offset);
3930
if (compareAndSetInt(obj, offset, intAtOffset, value)) {
3931
return intAtOffset;
3932
}
3933
}
3934
}
3935
3936
/**
3937
* Atomically sets value at offset in obj
3938
* and returns the value of the field prior to the update.
3939
* The get operation has the memory semantics of get.
3940
* The set operation has the memory semantics of setRelease.
3941
*
3942
* @param obj object into which to set the value
3943
* @param offset location to set value in obj
3944
* @param value to set in obj memory
3945
* @return value of field in obj at offset before update
3946
*/
3947
public final int getAndSetIntRelease(Object obj, long offset, int value) {
3948
for (;;) {
3949
int intAtOffset = getInt(obj, offset);
3950
if (weakCompareAndSetIntRelease(obj, offset, intAtOffset, value)) {
3951
return intAtOffset;
3952
}
3953
}
3954
}
3955
3956
/**
3957
* Atomically sets value at offset in obj
3958
* and returns the value of the field prior to the update.
3959
* The get operation has the memory semantics of getAcquire.
3960
* The set operation has the memory semantics of set.
3961
*
3962
* @param obj object into which to set the value
3963
* @param offset location to set value in obj
3964
* @param value to set in obj memory
3965
* @return value of field in obj at offset before update
3966
*/
3967
public final int getAndSetIntAcquire(Object obj, long offset, int value) {
3968
for (;;) {
3969
int intAtOffset = getIntAcquire(obj, offset);
3970
if (weakCompareAndSetIntAcquire(obj, offset, intAtOffset, value)) {
3971
return intAtOffset;
3972
}
3973
}
3974
}
3975
3976
/**
3977
* Atomically sets value at offset in obj
3978
* and returns the value of the field prior to the update.
3979
* The get operation has the memory semantics of getVolatile.
3980
* The set operation has the memory semantics of setVolatile.
3981
*
3982
* @param obj object into which to set the value
3983
* @param offset location to set value in obj
3984
* @param value to set in obj memory
3985
* @return value of field in obj at offset before update
3986
*/
3987
public final long getAndSetLong(Object obj, long offset, long value) {
3988
for (;;) {
3989
long longAtOffset = getLongVolatile(obj, offset);
3990
if (compareAndSetLong(obj, offset, longAtOffset, value)) {
3991
return longAtOffset;
3992
}
3993
}
3994
}
3995
3996
/**
3997
* Atomically sets value at offset in obj
3998
* and returns the value of the field prior to the update.
3999
* The get operation has the memory semantics of get.
4000
* The set operation has the memory semantics of setRelease.
4001
*
4002
* @param obj object into which to set the value
4003
* @param offset location to set value in obj
4004
* @param value to set in obj memory
4005
* @return value of field in obj at offset before update
4006
*/
4007
public final long getAndSetLongRelease(Object obj, long offset, long value) {
4008
for (;;) {
4009
long longAtOffset = getLong(obj, offset);
4010
if (weakCompareAndSetLongRelease(obj, offset, longAtOffset, value)) {
4011
return longAtOffset;
4012
}
4013
}
4014
}
4015
4016
/**
4017
* Atomically sets value at offset in obj
4018
* and returns the value of the field prior to the update.
4019
* The get operation has the memory semantics of getAcquire.
4020
* The set operation has the memory semantics of set.
4021
*
4022
* @param obj object into which to set the value
4023
* @param offset location to set value in obj
4024
* @param value to set in obj memory
4025
* @return value of field in obj at offset before update
4026
*/
4027
public final long getAndSetLongAcquire(Object obj, long offset, long value) {
4028
for (;;) {
4029
long longAtOffset = getLongAcquire(obj, offset);
4030
if (weakCompareAndSetLongAcquire(obj, offset, longAtOffset, value)) {
4031
return longAtOffset;
4032
}
4033
}
4034
}
4035
4036
/**
4037
* Atomically sets value at offset in obj
4038
* and returns the value of the field prior to the update.
4039
* The get operation has the memory semantics of getVolatile.
4040
* The set operation has the memory semantics of setVolatile.
4041
*
4042
* @param obj object into which to set the value
4043
* @param offset location to set value in obj
4044
* @param value to set in obj memory
4045
* @return value of field in obj at offset before update
4046
*/
4047
public final float getAndSetFloat(Object obj, long offset, float value) {
4048
int result = getAndSetInt(obj, offset, Float.floatToRawIntBits(value));
4049
return Float.intBitsToFloat(result);
4050
}
4051
4052
/**
4053
* Atomically sets value at offset in obj
4054
* and returns the value of the field prior to the update.
4055
* The get operation has the memory semantics of get.
4056
* The set operation has the memory semantics of setRelease.
4057
*
4058
* @param obj object into which to set the value
4059
* @param offset location to set value in obj
4060
* @param value to set in obj memory
4061
* @return value of field in obj at offset before update
4062
*/
4063
public final float getAndSetFloatRelease(Object obj, long offset, float value) {
4064
int result = getAndSetIntRelease(obj, offset, Float.floatToRawIntBits(value));
4065
return Float.intBitsToFloat(result);
4066
}
4067
4068
/**
4069
* Atomically sets value at offset in obj
4070
* and returns the value of the field prior to the update.
4071
* The get operation has the memory semantics of getAcquire.
4072
* The set operation has the memory semantics of set.
4073
*
4074
* @param obj object into which to set the value
4075
* @param offset location to set value in obj
4076
* @param value to set in obj memory
4077
* @return value of field in obj at offset before update
4078
*/
4079
public final float getAndSetFloatAcquire(Object obj, long offset, float value) {
4080
int result = getAndSetIntAcquire(obj, offset, Float.floatToRawIntBits(value));
4081
return Float.intBitsToFloat(result);
4082
}
4083
4084
/**
4085
* Atomically sets value at offset in obj
4086
* and returns the value of the field prior to the update.
4087
* The get operation has the memory semantics of getVolatile.
4088
* The set operation has the memory semantics of setVolatile.
4089
*
4090
* @param obj object into which to set the value
4091
* @param offset location to set value in obj
4092
* @param value to set in obj memory
4093
* @return value of field in obj at offset before update
4094
*/
4095
public final double getAndSetDouble(Object obj, long offset, double value) {
4096
long result = getAndSetLong(obj, offset, Double.doubleToRawLongBits(value));
4097
return Double.longBitsToDouble(result);
4098
}
4099
4100
/**
4101
* Atomically sets value at offset in obj
4102
* and returns the value of the field prior to the update.
4103
* The get operation has the memory semantics of get.
4104
* The set operation has the memory semantics of setRelease.
4105
*
4106
* @param obj object into which to set the value
4107
* @param offset location to set value in obj
4108
* @param value to set in obj memory
4109
* @return value of field in obj at offset before update
4110
*/
4111
public final double getAndSetDoubleRelease(Object obj, long offset, double value) {
4112
long result = getAndSetLongRelease(obj, offset, Double.doubleToRawLongBits(value));
4113
return Double.longBitsToDouble(result);
4114
}
4115
4116
/**
4117
* Atomically sets value at offset in obj
4118
* and returns the value of the field prior to the update.
4119
* The get operation has the memory semantics of getAcquire.
4120
* The set operation has the memory semantics of set.
4121
*
4122
* @param obj object into which to set the value
4123
* @param offset location to set value in obj
4124
* @param value to set in obj memory
4125
* @return value of field in obj at offset before update
4126
*/
4127
public final double getAndSetDoubleAcquire(Object obj, long offset, double value) {
4128
long result = getAndSetLongAcquire(obj, offset, Double.doubleToRawLongBits(value));
4129
return Double.longBitsToDouble(result);
4130
}
4131
4132
/**
4133
* Atomically sets value at offset in obj
4134
* and returns the value of the field prior to the update.
4135
* The get operation has the memory semantics of getVolatile.
4136
* The set operation has the memory semantics of setVolatile.
4137
*
4138
* @param obj object into which to set the value
4139
* @param offset location to set value in obj
4140
* @param value to set in obj memory
4141
* @return value of field in obj at offset before update
4142
*/
4143
public final short getAndSetShort(Object obj, long offset, short value) {
4144
for (;;) {
4145
short shortAtOffset = getShortVolatile(obj, offset);
4146
if (compareAndSetShort(obj, offset, shortAtOffset, value)) {
4147
return shortAtOffset;
4148
}
4149
}
4150
}
4151
4152
/**
4153
* Atomically sets value at offset in obj
4154
* and returns the value of the field prior to the update.
4155
* The get operation has the memory semantics of get.
4156
* The set operation has the memory semantics of setRelease.
4157
*
4158
* @param obj object into which to set the value
4159
* @param offset location to set value in obj
4160
* @param value to set in obj memory
4161
* @return value of field in obj at offset before update
4162
*/
4163
public final short getAndSetShortRelease(Object obj, long offset, short value) {
4164
for (;;) {
4165
short shortAtOffset = getShort(obj, offset);
4166
if (weakCompareAndSetShortRelease(obj, offset, shortAtOffset, value)) {
4167
return shortAtOffset;
4168
}
4169
}
4170
}
4171
4172
/**
4173
* Atomically sets value at offset in obj
4174
* and returns the value of the field prior to the update.
4175
* The get operation has the memory semantics of getAcquire.
4176
* The set operation has the memory semantics of set.
4177
*
4178
* @param obj object into which to set the value
4179
* @param offset location to set value in obj
4180
* @param value to set in obj memory
4181
* @return value of field in obj at offset before update
4182
*/
4183
public final short getAndSetShortAcquire(Object obj, long offset, short value) {
4184
for (;;) {
4185
short shortAtOffset = getShortAcquire(obj, offset);
4186
if (weakCompareAndSetShortAcquire(obj, offset, shortAtOffset, value)) {
4187
return shortAtOffset;
4188
}
4189
}
4190
}
4191
4192
/**
4193
* Atomically sets value at offset in obj
4194
* and returns the value of the field prior to the update.
4195
* The get operation has the memory semantics of getVolatile.
4196
* The set operation has the memory semantics of setVolatile.
4197
*
4198
* @param obj object into which to set the value
4199
* @param offset location to set value in obj
4200
* @param value to set in obj memory
4201
* @return value of field in obj at offset before update
4202
*/
4203
public final char getAndSetChar(Object obj, long offset, char value) {
4204
for (;;) {
4205
char charAtOffset = getCharVolatile(obj, offset);
4206
if (compareAndSetChar(obj, offset, charAtOffset, value)) {
4207
return charAtOffset;
4208
}
4209
}
4210
}
4211
4212
/**
4213
* Atomically sets value at offset in obj
4214
* and returns the value of the field prior to the update.
4215
* The get operation has the memory semantics of get.
4216
* The set operation has the memory semantics of setRelease.
4217
*
4218
* @param obj object into which to set the value
4219
* @param offset location to set value in obj
4220
* @param value to set in obj memory
4221
* @return value of field in obj at offset before update
4222
*/
4223
public final char getAndSetCharRelease(Object obj, long offset, char value) {
4224
for (;;) {
4225
char charAtOffset = getChar(obj, offset);
4226
if (weakCompareAndSetCharRelease(obj, offset, charAtOffset, value)) {
4227
return charAtOffset;
4228
}
4229
}
4230
}
4231
4232
/**
4233
* Atomically sets value at offset in obj
4234
* and returns the value of the field prior to the update.
4235
* The get operation has the memory semantics of getAcquire.
4236
* The set operation has the memory semantics of set.
4237
*
4238
* @param obj object into which to set the value
4239
* @param offset location to set value in obj
4240
* @param value to set in obj memory
4241
* @return value of field in obj at offset before update
4242
*/
4243
public final char getAndSetCharAcquire(Object obj, long offset, char value) {
4244
for (;;) {
4245
char charAtOffset = getCharAcquire(obj, offset);
4246
if (weakCompareAndSetCharAcquire(obj, offset, charAtOffset, value)) {
4247
return charAtOffset;
4248
}
4249
}
4250
}
4251
4252
/**
4253
* Atomically sets value at offset in obj
4254
* and returns the value of the field prior to the update.
4255
* The get operation has the memory semantics of getVolatile.
4256
* The set operation has the memory semantics of setVolatile.
4257
*
4258
* @param obj object into which to set the value
4259
* @param offset location to set value in obj
4260
* @param value to set in obj memory
4261
* @return value of field in obj at offset before update
4262
*/
4263
public final boolean getAndSetBoolean(Object obj, long offset, boolean value) {
4264
byte result = getAndSetByte(obj, offset, bool2byte(value));
4265
return byte2bool(result);
4266
}
4267
4268
/**
4269
* Atomically sets value at offset in obj
4270
* and returns the value of the field prior to the update.
4271
* The get operation has the memory semantics of get.
4272
* The set operation has the memory semantics of setRelease.
4273
*
4274
* @param obj object into which to set the value
4275
* @param offset location to set value in obj
4276
* @param value to set in obj memory
4277
* @return value of field in obj at offset before update
4278
*/
4279
public final boolean getAndSetBooleanRelease(Object obj, long offset, boolean value) {
4280
byte result = getAndSetByteRelease(obj, offset, bool2byte(value));
4281
return byte2bool(result);
4282
}
4283
4284
/**
4285
* Atomically sets value at offset in obj
4286
* and returns the value of the field prior to the update.
4287
* The get operation has the memory semantics of getAcquire.
4288
* The set operation has the memory semantics of set.
4289
*
4290
* @param obj object into which to set the value
4291
* @param offset location to set value in obj
4292
* @param value to set in obj memory
4293
* @return value of field in obj at offset before update
4294
*/
4295
public final boolean getAndSetBooleanAcquire(Object obj, long offset, boolean value) {
4296
byte result = getAndSetByteAcquire(obj, offset, bool2byte(value));
4297
return byte2bool(result);
4298
}
4299
4300
/**
4301
* Atomically sets value at offset in obj
4302
* and returns the value of the field prior to the update.
4303
* The get operation has the memory semantics of getVolatile.
4304
* The set operation has the memory semantics of setVolatile.
4305
*
4306
* @param obj object into which to set the value
4307
* @param offset location to set value in obj
4308
* @param value to set in obj memory
4309
* @return value of field in obj at offset before update
4310
*/
4311
public final Object getAndSetObject(Object obj, long offset, Object value) {
4312
for (;;) {
4313
Object objectAtOffset = getObjectVolatile(obj, offset);
4314
if (compareAndSetObject(obj, offset, objectAtOffset, value)) {
4315
return objectAtOffset;
4316
}
4317
}
4318
}
4319
4320
/**
4321
* Atomically sets value at offset in obj
4322
* and returns the value of the field prior to the update.
4323
* The get operation has the memory semantics of get.
4324
* The set operation has the memory semantics of setRelease.
4325
*
4326
* @param obj object into which to set the value
4327
* @param offset location to set value in obj
4328
* @param value to set in obj memory
4329
* @return value of field in obj at offset before update
4330
*/
4331
public final Object getAndSetObjectRelease(Object obj, long offset, Object value) {
4332
for (;;) {
4333
Object objectAtOffset = getObject(obj, offset);
4334
if (weakCompareAndSetObjectRelease(obj, offset, objectAtOffset, value)) {
4335
return objectAtOffset;
4336
}
4337
}
4338
}
4339
4340
/**
4341
* Atomically sets value at offset in obj
4342
* and returns the value of the field prior to the update.
4343
* The get operation has the memory semantics of getAcquire.
4344
* The set operation has the memory semantics of set.
4345
*
4346
* @param obj object into which to set the value
4347
* @param offset location to set value in obj
4348
* @param value to set in obj memory
4349
* @return value of field in obj at offset before update
4350
*/
4351
public final Object getAndSetObjectAcquire(Object obj, long offset, Object value) {
4352
for (;;) {
4353
Object objectAtOffset = getObjectAcquire(obj, offset);
4354
if (weakCompareAndSetObjectAcquire(obj, offset, objectAtOffset, value)) {
4355
return objectAtOffset;
4356
}
4357
}
4358
}
4359
4360
/*[IF JAVA_SPEC_VERSION >= 12]*/
4361
/**
4362
* Atomically sets value at offset in obj
4363
* and returns the value of the field prior to the update.
4364
* The get operation has the memory semantics of getVolatile.
4365
* The set operation has the memory semantics of setVolatile.
4366
*
4367
* @param obj object into which to set the value
4368
* @param offset location to set value in obj
4369
* @param value to set in obj memory
4370
* @return value of field in obj at offset before update
4371
*/
4372
public final Object getAndSetReference(Object obj, long offset, Object value) {
4373
for (;;) {
4374
Object objectAtOffset = getReferenceVolatile(obj, offset);
4375
if (compareAndSetReference(obj, offset, objectAtOffset, value)) {
4376
return objectAtOffset;
4377
}
4378
}
4379
}
4380
4381
/**
4382
* Atomically sets value at offset in obj
4383
* and returns the value of the field prior to the update.
4384
* The get operation has the memory semantics of get.
4385
* The set operation has the memory semantics of setRelease.
4386
*
4387
* @param obj object into which to set the value
4388
* @param offset location to set value in obj
4389
* @param value to set in obj memory
4390
* @return value of field in obj at offset before update
4391
*/
4392
public final Object getAndSetReferenceRelease(Object obj, long offset, Object value) {
4393
for (;;) {
4394
Object objectAtOffset = getReference(obj, offset);
4395
if (weakCompareAndSetReferenceRelease(obj, offset, objectAtOffset, value)) {
4396
return objectAtOffset;
4397
}
4398
}
4399
}
4400
4401
/**
4402
* Atomically sets value at offset in obj
4403
* and returns the value of the field prior to the update.
4404
* The get operation has the memory semantics of getAcquire.
4405
* The set operation has the memory semantics of set.
4406
*
4407
* @param obj object into which to set the value
4408
* @param offset location to set value in obj
4409
* @param value to set in obj memory
4410
* @return value of field in obj at offset before update
4411
*/
4412
public final Object getAndSetReferenceAcquire(Object obj, long offset, Object value) {
4413
for (;;) {
4414
Object objectAtOffset = getReferenceAcquire(obj, offset);
4415
if (weakCompareAndSetReferenceAcquire(obj, offset, objectAtOffset, value)) {
4416
return objectAtOffset;
4417
}
4418
}
4419
}
4420
/*[ENDIF] JAVA_SPEC_VERSION >= 12 */
4421
4422
/**
4423
* Atomically OR's the given value to the current value of the
4424
* field at offset in obj and returns the value of the field prior
4425
* to the update.
4426
* The get operation has the memory semantics of getVolatile.
4427
* The set operation has the memory semantics of setVolatile.
4428
*
4429
* @param obj object into which to OR the value
4430
* @param offset location to OR value in obj
4431
* @param value to OR to existing value in field
4432
* @return value of field in obj at offset before update
4433
*/
4434
public final byte getAndBitwiseOrByte(Object obj, long offset, byte value) {
4435
for (;;) {
4436
byte byteAtOffset = getByteVolatile(obj, offset);
4437
if (weakCompareAndSetByte(obj, offset, byteAtOffset, (byte) (byteAtOffset | value))) {
4438
return byteAtOffset;
4439
}
4440
}
4441
}
4442
4443
/**
4444
* Atomically OR's the given value to the current value of the
4445
* field at offset in obj and returns the value of the field prior
4446
* to the update.
4447
* The get operation has the memory semantics of get.
4448
* The set operation has the memory semantics of setRelease.
4449
*
4450
* @param obj object into which to OR the value
4451
* @param offset location to OR value in obj
4452
* @param value to OR to existing value in field
4453
* @return value of field in obj at offset before update
4454
*/
4455
public final byte getAndBitwiseOrByteRelease(Object obj, long offset, byte value) {
4456
for (;;) {
4457
byte byteAtOffset = getByte(obj, offset);
4458
if (weakCompareAndSetByteRelease(obj, offset, byteAtOffset, (byte) (byteAtOffset | value))) {
4459
return byteAtOffset;
4460
}
4461
}
4462
}
4463
4464
/**
4465
* Atomically OR's the given value to the current value of the
4466
* field at offset in obj and returns the value of the field prior
4467
* to the update.
4468
* The get operation has the memory semantics of getAcquire.
4469
* The set operation has the memory semantics of set.
4470
*
4471
* @param obj object into which to OR the value
4472
* @param offset location to OR value in obj
4473
* @param value to OR to existing value in field
4474
* @return value of field in obj at offset before update
4475
*/
4476
public final byte getAndBitwiseOrByteAcquire(Object obj, long offset, byte value) {
4477
for (;;) {
4478
byte byteAtOffset = getByte(obj, offset);
4479
if (weakCompareAndSetByteAcquire(obj, offset, byteAtOffset, (byte) (byteAtOffset | value))) {
4480
return byteAtOffset;
4481
}
4482
}
4483
}
4484
4485
/**
4486
* Atomically AND's the given value to the current value of the
4487
* field at offset in obj and returns the value of the field prior
4488
* to the update.
4489
* The get operation has the memory semantics of getVolatile.
4490
* The set operation has the memory semantics of setVolatile.
4491
*
4492
* @param obj object into which to AND the value
4493
* @param offset location to AND value in obj
4494
* @param value to AND to existing value in field
4495
* @return value of field in obj at offset before update
4496
*/
4497
public final byte getAndBitwiseAndByte(Object obj, long offset, byte value) {
4498
for (;;) {
4499
byte byteAtOffset = getByteVolatile(obj, offset);
4500
if (weakCompareAndSetByte(obj, offset, byteAtOffset, (byte) (byteAtOffset & value))) {
4501
return byteAtOffset;
4502
}
4503
}
4504
}
4505
4506
/**
4507
* Atomically AND's the given value to the current value of the
4508
* field at offset in obj and returns the value of the field prior
4509
* to the update.
4510
* The get operation has the memory semantics of get.
4511
* The set operation has the memory semantics of setRelease.
4512
*
4513
* @param obj object into which to AND the value
4514
* @param offset location to AND value in obj
4515
* @param value to AND to existing value in field
4516
* @return value of field in obj at offset before update
4517
*/
4518
public final byte getAndBitwiseAndByteRelease(Object obj, long offset, byte value) {
4519
for (;;) {
4520
byte byteAtOffset = getByte(obj, offset);
4521
if (weakCompareAndSetByteRelease(obj, offset, byteAtOffset, (byte) (byteAtOffset & value))) {
4522
return byteAtOffset;
4523
}
4524
}
4525
}
4526
4527
/**
4528
* Atomically AND's the given value to the current value of the
4529
* field at offset in obj and returns the value of the field prior
4530
* to the update.
4531
* The get operation has the memory semantics of getAcquire.
4532
* The set operation has the memory semantics of set.
4533
*
4534
* @param obj object into which to AND the value
4535
* @param offset location to AND value in obj
4536
* @param value to AND to existing value in field
4537
* @return value of field in obj at offset before update
4538
*/
4539
public final byte getAndBitwiseAndByteAcquire(Object obj, long offset, byte value) {
4540
for (;;) {
4541
byte byteAtOffset = getByte(obj, offset);
4542
if (weakCompareAndSetByteAcquire(obj, offset, byteAtOffset, (byte) (byteAtOffset & value))) {
4543
return byteAtOffset;
4544
}
4545
}
4546
}
4547
4548
/**
4549
* Atomically XOR's the given value to the current value of the
4550
* field at offset in obj and returns the value of the field prior
4551
* to the update.
4552
* The get operation has the memory semantics of getVolatile.
4553
* The set operation has the memory semantics of setVolatile.
4554
*
4555
* @param obj object into which to XOR the value
4556
* @param offset location to XOR value in obj
4557
* @param value to XOR to existing value in field
4558
* @return value of field in obj at offset before update
4559
*/
4560
public final byte getAndBitwiseXorByte(Object obj, long offset, byte value) {
4561
for (;;) {
4562
byte byteAtOffset = getByteVolatile(obj, offset);
4563
if (weakCompareAndSetByte(obj, offset, byteAtOffset, (byte) (byteAtOffset ^ value))) {
4564
return byteAtOffset;
4565
}
4566
}
4567
}
4568
4569
/**
4570
* Atomically XOR's the given value to the current value of the
4571
* field at offset in obj and returns the value of the field prior
4572
* to the update.
4573
* The get operation has the memory semantics of get.
4574
* The set operation has the memory semantics of setRelease.
4575
*
4576
* @param obj object into which to XOR the value
4577
* @param offset location to XOR value in obj
4578
* @param value to XOR to existing value in field
4579
* @return value of field in obj at offset before update
4580
*/
4581
public final byte getAndBitwiseXorByteRelease(Object obj, long offset, byte value) {
4582
for (;;) {
4583
byte byteAtOffset = getByte(obj, offset);
4584
if (weakCompareAndSetByteRelease(obj, offset, byteAtOffset, (byte) (byteAtOffset ^ value))) {
4585
return byteAtOffset;
4586
}
4587
}
4588
}
4589
4590
/**
4591
* Atomically XOR's the given value to the current value of the
4592
* field at offset in obj and returns the value of the field prior
4593
* to the update.
4594
* The get operation has the memory semantics of getAcquire.
4595
* The set operation has the memory semantics of set.
4596
*
4597
* @param obj object into which to XOR the value
4598
* @param offset location to XOR value in obj
4599
* @param value to XOR to existing value in field
4600
* @return value of field in obj at offset before update
4601
*/
4602
public final byte getAndBitwiseXorByteAcquire(Object obj, long offset, byte value) {
4603
for (;;) {
4604
byte byteAtOffset = getByte(obj, offset);
4605
if (weakCompareAndSetByteAcquire(obj, offset, byteAtOffset, (byte) (byteAtOffset ^ value))) {
4606
return byteAtOffset;
4607
}
4608
}
4609
}
4610
4611
/**
4612
* Atomically OR's the given value to the current value of the
4613
* field at offset in obj and returns the value of the field prior
4614
* to the update.
4615
* The get operation has the memory semantics of getVolatile.
4616
* The set operation has the memory semantics of setVolatile.
4617
*
4618
* @param obj object into which to OR the value
4619
* @param offset location to OR value in obj
4620
* @param value to OR to existing value in field
4621
* @return value of field in obj at offset before update
4622
*/
4623
public final int getAndBitwiseOrInt(Object obj, long offset, int value) {
4624
for (;;) {
4625
int intAtOffset = getIntVolatile(obj, offset);
4626
if (weakCompareAndSetInt(obj, offset, intAtOffset, intAtOffset | value)) {
4627
return intAtOffset;
4628
}
4629
}
4630
}
4631
4632
/**
4633
* Atomically OR's the given value to the current value of the
4634
* field at offset in obj and returns the value of the field prior
4635
* to the update.
4636
* The get operation has the memory semantics of get.
4637
* The set operation has the memory semantics of setRelease.
4638
*
4639
* @param obj object into which to OR the value
4640
* @param offset location to OR value in obj
4641
* @param value to OR to existing value in field
4642
* @return value of field in obj at offset before update
4643
*/
4644
public final int getAndBitwiseOrIntRelease(Object obj, long offset, int value) {
4645
for (;;) {
4646
int intAtOffset = getInt(obj, offset);
4647
if (weakCompareAndSetIntRelease(obj, offset, intAtOffset, intAtOffset | value)) {
4648
return intAtOffset;
4649
}
4650
}
4651
}
4652
4653
/**
4654
* Atomically OR's the given value to the current value of the
4655
* field at offset in obj and returns the value of the field prior
4656
* to the update.
4657
* The get operation has the memory semantics of getAcquire.
4658
* The set operation has the memory semantics of set.
4659
*
4660
* @param obj object into which to OR the value
4661
* @param offset location to OR value in obj
4662
* @param value to OR to existing value in field
4663
* @return value of field in obj at offset before update
4664
*/
4665
public final int getAndBitwiseOrIntAcquire(Object obj, long offset, int value) {
4666
for (;;) {
4667
int intAtOffset = getInt(obj, offset);
4668
if (weakCompareAndSetIntAcquire(obj, offset, intAtOffset, intAtOffset | value)) {
4669
return intAtOffset;
4670
}
4671
}
4672
}
4673
4674
/**
4675
* Atomically AND's the given value to the current value of the
4676
* field at offset in obj and returns the value of the field prior
4677
* to the update.
4678
* The get operation has the memory semantics of getVolatile.
4679
* The set operation has the memory semantics of setVolatile.
4680
*
4681
* @param obj object into which to AND the value
4682
* @param offset location to AND value in obj
4683
* @param value to AND to existing value in field
4684
* @return value of field in obj at offset before update
4685
*/
4686
public final int getAndBitwiseAndInt(Object obj, long offset, int value) {
4687
for (;;) {
4688
int intAtOffset = getIntVolatile(obj, offset);
4689
if (weakCompareAndSetInt(obj, offset, intAtOffset, intAtOffset & value)) {
4690
return intAtOffset;
4691
}
4692
}
4693
}
4694
4695
/**
4696
* Atomically AND's the given value to the current value of the
4697
* field at offset in obj and returns the value of the field prior
4698
* to the update.
4699
* The get operation has the memory semantics of get.
4700
* The set operation has the memory semantics of setRelease.
4701
*
4702
* @param obj object into which to AND the value
4703
* @param offset location to AND value in obj
4704
* @param value to AND to existing value in field
4705
* @return value of field in obj at offset before update
4706
*/
4707
public final int getAndBitwiseAndIntRelease(Object obj, long offset, int value) {
4708
for (;;) {
4709
int intAtOffset = getInt(obj, offset);
4710
if (weakCompareAndSetIntRelease(obj, offset, intAtOffset, intAtOffset & value)) {
4711
return intAtOffset;
4712
}
4713
}
4714
}
4715
4716
/**
4717
* Atomically AND's the given value to the current value of the
4718
* field at offset in obj and returns the value of the field prior
4719
* to the update.
4720
* The get operation has the memory semantics of getAcquire.
4721
* The set operation has the memory semantics of set.
4722
*
4723
* @param obj object into which to AND the value
4724
* @param offset location to AND value in obj
4725
* @param value to AND to existing value in field
4726
* @return value of field in obj at offset before update
4727
*/
4728
public final int getAndBitwiseAndIntAcquire(Object obj, long offset, int value) {
4729
for (;;) {
4730
int intAtOffset = getInt(obj, offset);
4731
if (weakCompareAndSetIntAcquire(obj, offset, intAtOffset, intAtOffset & value)) {
4732
return intAtOffset;
4733
}
4734
}
4735
}
4736
4737
/**
4738
* Atomically XOR's the given value to the current value of the
4739
* field at offset in obj and returns the value of the field prior
4740
* to the update.
4741
* The get operation has the memory semantics of getVolatile.
4742
* The set operation has the memory semantics of setVolatile.
4743
*
4744
* @param obj object into which to XOR the value
4745
* @param offset location to XOR value in obj
4746
* @param value to XOR to existing value in field
4747
* @return value of field in obj at offset before update
4748
*/
4749
public final int getAndBitwiseXorInt(Object obj, long offset, int value) {
4750
for (;;) {
4751
int intAtOffset = getIntVolatile(obj, offset);
4752
if (weakCompareAndSetInt(obj, offset, intAtOffset, intAtOffset ^ value)) {
4753
return intAtOffset;
4754
}
4755
}
4756
}
4757
4758
/**
4759
* Atomically XOR's the given value to the current value of the
4760
* field at offset in obj and returns the value of the field prior
4761
* to the update.
4762
* The get operation has the memory semantics of get.
4763
* The set operation has the memory semantics of setRelease.
4764
*
4765
* @param obj object into which to XOR the value
4766
* @param offset location to XOR value in obj
4767
* @param value to XOR to existing value in field
4768
* @return value of field in obj at offset before update
4769
*/
4770
public final int getAndBitwiseXorIntRelease(Object obj, long offset, int value) {
4771
for (;;) {
4772
int intAtOffset = getInt(obj, offset);
4773
if (weakCompareAndSetIntRelease(obj, offset, intAtOffset, intAtOffset ^ value)) {
4774
return intAtOffset;
4775
}
4776
}
4777
}
4778
4779
/**
4780
* Atomically XOR's the given value to the current value of the
4781
* field at offset in obj and returns the value of the field prior
4782
* to the update.
4783
* The get operation has the memory semantics of getAcquire.
4784
* The set operation has the memory semantics of set.
4785
*
4786
* @param obj object into which to XOR the value
4787
* @param offset location to XOR value in obj
4788
* @param value to XOR to existing value in field
4789
* @return value of field in obj at offset before update
4790
*/
4791
public final int getAndBitwiseXorIntAcquire(Object obj, long offset, int value) {
4792
for (;;) {
4793
int intAtOffset = getInt(obj, offset);
4794
if (weakCompareAndSetIntAcquire(obj, offset, intAtOffset, intAtOffset ^ value)) {
4795
return intAtOffset;
4796
}
4797
}
4798
}
4799
4800
/**
4801
* Atomically OR's the given value to the current value of the
4802
* field at offset in obj and returns the value of the field prior
4803
* to the update.
4804
* The get operation has the memory semantics of getVolatile.
4805
* The set operation has the memory semantics of setVolatile.
4806
*
4807
* @param obj object into which to OR the value
4808
* @param offset location to OR value in obj
4809
* @param value to OR to existing value in field
4810
* @return value of field in obj at offset before update
4811
*/
4812
public final long getAndBitwiseOrLong(Object obj, long offset, long value) {
4813
for (;;) {
4814
long longAtOffset = getLongVolatile(obj, offset);
4815
if (weakCompareAndSetLong(obj, offset, longAtOffset, longAtOffset | value)) {
4816
return longAtOffset;
4817
}
4818
}
4819
}
4820
4821
/**
4822
* Atomically OR's the given value to the current value of the
4823
* field at offset in obj and returns the value of the field prior
4824
* to the update.
4825
* The get operation has the memory semantics of get.
4826
* The set operation has the memory semantics of setRelease.
4827
*
4828
* @param obj object into which to OR the value
4829
* @param offset location to OR value in obj
4830
* @param value to OR to existing value in field
4831
* @return value of field in obj at offset before update
4832
*/
4833
public final long getAndBitwiseOrLongRelease(Object obj, long offset, long value) {
4834
for (;;) {
4835
long longAtOffset = getLong(obj, offset);
4836
if (weakCompareAndSetLongRelease(obj, offset, longAtOffset, longAtOffset | value)) {
4837
return longAtOffset;
4838
}
4839
}
4840
}
4841
4842
/**
4843
* Atomically OR's the given value to the current value of the
4844
* field at offset in obj and returns the value of the field prior
4845
* to the update.
4846
* The get operation has the memory semantics of getAcquire.
4847
* The set operation has the memory semantics of set.
4848
*
4849
* @param obj object into which to OR the value
4850
* @param offset location to OR value in obj
4851
* @param value to OR to existing value in field
4852
* @return value of field in obj at offset before update
4853
*/
4854
public final long getAndBitwiseOrLongAcquire(Object obj, long offset, long value) {
4855
for (;;) {
4856
long longAtOffset = getLong(obj, offset);
4857
if (weakCompareAndSetLongAcquire(obj, offset, longAtOffset, longAtOffset | value)) {
4858
return longAtOffset;
4859
}
4860
}
4861
}
4862
4863
/**
4864
* Atomically AND's the given value to the current value of the
4865
* field at offset in obj and returns the value of the field prior
4866
* to the update.
4867
* The get operation has the memory semantics of getVolatile.
4868
* The set operation has the memory semantics of setVolatile.
4869
*
4870
* @param obj object into which to AND the value
4871
* @param offset location to AND value in obj
4872
* @param value to AND to existing value in field
4873
* @return value of field in obj at offset before update
4874
*/
4875
public final long getAndBitwiseAndLong(Object obj, long offset, long value) {
4876
for (;;) {
4877
long longAtOffset = getLongVolatile(obj, offset);
4878
if (weakCompareAndSetLong(obj, offset, longAtOffset, longAtOffset & value)) {
4879
return longAtOffset;
4880
}
4881
}
4882
}
4883
4884
/**
4885
* Atomically AND's the given value to the current value of the
4886
* field at offset in obj and returns the value of the field prior
4887
* to the update.
4888
* The get operation has the memory semantics of get.
4889
* The set operation has the memory semantics of setRelease.
4890
*
4891
* @param obj object into which to AND the value
4892
* @param offset location to AND value in obj
4893
* @param value to AND to existing value in field
4894
* @return value of field in obj at offset before update
4895
*/
4896
public final long getAndBitwiseAndLongRelease(Object obj, long offset, long value) {
4897
for (;;) {
4898
long longAtOffset = getLong(obj, offset);
4899
if (weakCompareAndSetLongRelease(obj, offset, longAtOffset, longAtOffset & value)) {
4900
return longAtOffset;
4901
}
4902
}
4903
}
4904
4905
/**
4906
* Atomically AND's the given value to the current value of the
4907
* field at offset in obj and returns the value of the field prior
4908
* to the update.
4909
* The get operation has the memory semantics of getAcquire.
4910
* The set operation has the memory semantics of set.
4911
*
4912
* @param obj object into which to AND the value
4913
* @param offset location to AND value in obj
4914
* @param value to AND to existing value in field
4915
* @return value of field in obj at offset before update
4916
*/
4917
public final long getAndBitwiseAndLongAcquire(Object obj, long offset, long value) {
4918
for (;;) {
4919
long longAtOffset = getLong(obj, offset);
4920
if (weakCompareAndSetLongAcquire(obj, offset, longAtOffset, longAtOffset & value)) {
4921
return longAtOffset;
4922
}
4923
}
4924
}
4925
4926
/**
4927
* Atomically XOR's the given value to the current value of the
4928
* field at offset in obj and returns the value of the field prior
4929
* to the update.
4930
* The get operation has the memory semantics of getVolatile.
4931
* The set operation has the memory semantics of setVolatile.
4932
*
4933
* @param obj object into which to XOR the value
4934
* @param offset location to XOR value in obj
4935
* @param value to XOR to existing value in field
4936
* @return value of field in obj at offset before update
4937
*/
4938
public final long getAndBitwiseXorLong(Object obj, long offset, long value) {
4939
for (;;) {
4940
long longAtOffset = getLongVolatile(obj, offset);
4941
if (weakCompareAndSetLong(obj, offset, longAtOffset, longAtOffset ^ value)) {
4942
return longAtOffset;
4943
}
4944
}
4945
}
4946
4947
/**
4948
* Atomically XOR's the given value to the current value of the
4949
* field at offset in obj and returns the value of the field prior
4950
* to the update.
4951
* The get operation has the memory semantics of get.
4952
* The set operation has the memory semantics of setRelease.
4953
*
4954
* @param obj object into which to XOR the value
4955
* @param offset location to XOR value in obj
4956
* @param value to XOR to existing value in field
4957
* @return value of field in obj at offset before update
4958
*/
4959
public final long getAndBitwiseXorLongRelease(Object obj, long offset, long value) {
4960
for (;;) {
4961
long longAtOffset = getLong(obj, offset);
4962
if (weakCompareAndSetLongRelease(obj, offset, longAtOffset, longAtOffset ^ value)) {
4963
return longAtOffset;
4964
}
4965
}
4966
}
4967
4968
/**
4969
* Atomically XOR's the given value to the current value of the
4970
* field at offset in obj and returns the value of the field prior
4971
* to the update.
4972
* The get operation has the memory semantics of getAcquire.
4973
* The set operation has the memory semantics of set.
4974
*
4975
* @param obj object into which to XOR the value
4976
* @param offset location to XOR value in obj
4977
* @param value to XOR to existing value in field
4978
* @return value of field in obj at offset before update
4979
*/
4980
public final long getAndBitwiseXorLongAcquire(Object obj, long offset, long value) {
4981
for (;;) {
4982
long longAtOffset = getLong(obj, offset);
4983
if (weakCompareAndSetLongAcquire(obj, offset, longAtOffset, longAtOffset ^ value)) {
4984
return longAtOffset;
4985
}
4986
}
4987
}
4988
4989
/**
4990
* Atomically OR's the given value to the current value of the
4991
* field at offset in obj and returns the value of the field prior
4992
* to the update.
4993
* The get operation has the memory semantics of getVolatile.
4994
* The set operation has the memory semantics of setVolatile.
4995
*
4996
* @param obj object into which to OR the value
4997
* @param offset location to OR value in obj
4998
* @param value to OR to existing value in field
4999
* @return value of field in obj at offset before update
5000
*/
5001
public final short getAndBitwiseOrShort(Object obj, long offset, short value) {
5002
for (;;) {
5003
short shortAtOffset = getShortVolatile(obj, offset);
5004
if (weakCompareAndSetShort(obj, offset, shortAtOffset, (short) (shortAtOffset | value))) {
5005
return shortAtOffset;
5006
}
5007
}
5008
}
5009
5010
/**
5011
* Atomically OR's the given value to the current value of the
5012
* field at offset in obj and returns the value of the field prior
5013
* to the update.
5014
* The get operation has the memory semantics of get.
5015
* The set operation has the memory semantics of setRelease.
5016
*
5017
* @param obj object into which to OR the value
5018
* @param offset location to OR value in obj
5019
* @param value to OR to existing value in field
5020
* @return value of field in obj at offset before update
5021
*/
5022
public final short getAndBitwiseOrShortRelease(Object obj, long offset, short value) {
5023
for (;;) {
5024
short shortAtOffset = getShort(obj, offset);
5025
if (weakCompareAndSetShortRelease(obj, offset, shortAtOffset, (short) (shortAtOffset | value))) {
5026
return shortAtOffset;
5027
}
5028
}
5029
}
5030
5031
/**
5032
* Atomically OR's the given value to the current value of the
5033
* field at offset in obj and returns the value of the field prior
5034
* to the update.
5035
* The get operation has the memory semantics of getAcquire.
5036
* The set operation has the memory semantics of set.
5037
*
5038
* @param obj object into which to OR the value
5039
* @param offset location to OR value in obj
5040
* @param value to OR to existing value in field
5041
* @return value of field in obj at offset before update
5042
*/
5043
public final short getAndBitwiseOrShortAcquire(Object obj, long offset, short value) {
5044
for (;;) {
5045
short shortAtOffset = getShort(obj, offset);
5046
if (weakCompareAndSetShortAcquire(obj, offset, shortAtOffset, (short) (shortAtOffset | value))) {
5047
return shortAtOffset;
5048
}
5049
}
5050
}
5051
5052
/**
5053
* Atomically AND's the given value to the current value of the
5054
* field at offset in obj and returns the value of the field prior
5055
* to the update.
5056
* The get operation has the memory semantics of getVolatile.
5057
* The set operation has the memory semantics of setVolatile.
5058
*
5059
* @param obj object into which to AND the value
5060
* @param offset location to AND value in obj
5061
* @param value to AND to existing value in field
5062
* @return value of field in obj at offset before update
5063
*/
5064
public final short getAndBitwiseAndShort(Object obj, long offset, short value) {
5065
for (;;) {
5066
short shortAtOffset = getShortVolatile(obj, offset);
5067
if (weakCompareAndSetShort(obj, offset, shortAtOffset, (short) (shortAtOffset & value))) {
5068
return shortAtOffset;
5069
}
5070
}
5071
}
5072
5073
/**
5074
* Atomically AND's the given value to the current value of the
5075
* field at offset in obj and returns the value of the field prior
5076
* to the update.
5077
* The get operation has the memory semantics of get.
5078
* The set operation has the memory semantics of setRelease.
5079
*
5080
* @param obj object into which to AND the value
5081
* @param offset location to AND value in obj
5082
* @param value to AND to existing value in field
5083
* @return value of field in obj at offset before update
5084
*/
5085
public final short getAndBitwiseAndShortRelease(Object obj, long offset, short value) {
5086
for (;;) {
5087
short shortAtOffset = getShort(obj, offset);
5088
if (weakCompareAndSetShortRelease(obj, offset, shortAtOffset, (short) (shortAtOffset & value))) {
5089
return shortAtOffset;
5090
}
5091
}
5092
}
5093
5094
/**
5095
* Atomically AND's the given value to the current value of the
5096
* field at offset in obj and returns the value of the field prior
5097
* to the update.
5098
* The get operation has the memory semantics of getAcquire.
5099
* The set operation has the memory semantics of set.
5100
*
5101
* @param obj object into which to AND the value
5102
* @param offset location to AND value in obj
5103
* @param value to AND to existing value in field
5104
* @return value of field in obj at offset before update
5105
*/
5106
public final short getAndBitwiseAndShortAcquire(Object obj, long offset, short value) {
5107
for (;;) {
5108
short shortAtOffset = getShort(obj, offset);
5109
if (weakCompareAndSetShortAcquire(obj, offset, shortAtOffset, (short) (shortAtOffset & value))) {
5110
return shortAtOffset;
5111
}
5112
}
5113
}
5114
5115
/**
5116
* Atomically XOR's the given value to the current value of the
5117
* field at offset in obj and returns the value of the field prior
5118
* to the update.
5119
* The get operation has the memory semantics of getVolatile.
5120
* The set operation has the memory semantics of setVolatile.
5121
*
5122
* @param obj object into which to XOR the value
5123
* @param offset location to XOR value in obj
5124
* @param value to XOR to existing value in field
5125
* @return value of field in obj at offset before update
5126
*/
5127
public final short getAndBitwiseXorShort(Object obj, long offset, short value) {
5128
for (;;) {
5129
short shortAtOffset = getShortVolatile(obj, offset);
5130
if (weakCompareAndSetShort(obj, offset, shortAtOffset, (short) (shortAtOffset ^ value))) {
5131
return shortAtOffset;
5132
}
5133
}
5134
}
5135
5136
/**
5137
* Atomically XOR's the given value to the current value of the
5138
* field at offset in obj and returns the value of the field prior
5139
* to the update.
5140
* The get operation has the memory semantics of get.
5141
* The set operation has the memory semantics of setRelease.
5142
*
5143
* @param obj object into which to XOR the value
5144
* @param offset location to XOR value in obj
5145
* @param value to XOR to existing value in field
5146
* @return value of field in obj at offset before update
5147
*/
5148
public final short getAndBitwiseXorShortRelease(Object obj, long offset, short value) {
5149
for (;;) {
5150
short shortAtOffset = getShort(obj, offset);
5151
if (weakCompareAndSetShortRelease(obj, offset, shortAtOffset, (short) (shortAtOffset ^ value))) {
5152
return shortAtOffset;
5153
}
5154
}
5155
}
5156
5157
/**
5158
* Atomically XOR's the given value to the current value of the
5159
* field at offset in obj and returns the value of the field prior
5160
* to the update.
5161
* The get operation has the memory semantics of getAcquire.
5162
* The set operation has the memory semantics of set.
5163
*
5164
* @param obj object into which to XOR the value
5165
* @param offset location to XOR value in obj
5166
* @param value to XOR to existing value in field
5167
* @return value of field in obj at offset before update
5168
*/
5169
public final short getAndBitwiseXorShortAcquire(Object obj, long offset, short value) {
5170
for (;;) {
5171
short shortAtOffset = getShort(obj, offset);
5172
if (weakCompareAndSetShortAcquire(obj, offset, shortAtOffset, (short) (shortAtOffset ^ value))) {
5173
return shortAtOffset;
5174
}
5175
}
5176
}
5177
5178
/**
5179
* Atomically OR's the given value to the current value of the
5180
* field at offset in obj and returns the value of the field prior
5181
* to the update.
5182
* The get operation has the memory semantics of getVolatile.
5183
* The set operation has the memory semantics of setVolatile.
5184
*
5185
* @param obj object into which to OR the value
5186
* @param offset location to OR value in obj
5187
* @param value to OR to existing value in field
5188
* @return value of field in obj at offset before update
5189
*/
5190
public final char getAndBitwiseOrChar(Object obj, long offset, char value) {
5191
for (;;) {
5192
char charAtOffset = getCharVolatile(obj, offset);
5193
if (weakCompareAndSetChar(obj, offset, charAtOffset, (char) (charAtOffset | value))) {
5194
return charAtOffset;
5195
}
5196
}
5197
}
5198
5199
/**
5200
* Atomically OR's the given value to the current value of the
5201
* field at offset in obj and returns the value of the field prior
5202
* to the update.
5203
* The get operation has the memory semantics of get.
5204
* The set operation has the memory semantics of setRelease.
5205
*
5206
* @param obj object into which to OR the value
5207
* @param offset location to OR value in obj
5208
* @param value to OR to existing value in field
5209
* @return value of field in obj at offset before update
5210
*/
5211
public final char getAndBitwiseOrCharRelease(Object obj, long offset, char value) {
5212
for (;;) {
5213
char charAtOffset = getChar(obj, offset);
5214
if (weakCompareAndSetCharRelease(obj, offset, charAtOffset, (char) (charAtOffset | value))) {
5215
return charAtOffset;
5216
}
5217
}
5218
}
5219
5220
/**
5221
* Atomically OR's the given value to the current value of the
5222
* field at offset in obj and returns the value of the field prior
5223
* to the update.
5224
* The get operation has the memory semantics of getAcquire.
5225
* The set operation has the memory semantics of set.
5226
*
5227
* @param obj object into which to OR the value
5228
* @param offset location to OR value in obj
5229
* @param value to OR to existing value in field
5230
* @return value of field in obj at offset before update
5231
*/
5232
public final char getAndBitwiseOrCharAcquire(Object obj, long offset, char value) {
5233
for (;;) {
5234
char charAtOffset = getChar(obj, offset);
5235
if (weakCompareAndSetCharAcquire(obj, offset, charAtOffset, (char) (charAtOffset | value))) {
5236
return charAtOffset;
5237
}
5238
}
5239
}
5240
5241
/**
5242
* Atomically AND's the given value to the current value of the
5243
* field at offset in obj and returns the value of the field prior
5244
* to the update.
5245
* The get operation has the memory semantics of getVolatile.
5246
* The set operation has the memory semantics of setVolatile.
5247
*
5248
* @param obj object into which to AND the value
5249
* @param offset location to AND value in obj
5250
* @param value to AND to existing value in field
5251
* @return value of field in obj at offset before update
5252
*/
5253
public final char getAndBitwiseAndChar(Object obj, long offset, char value) {
5254
for (;;) {
5255
char charAtOffset = getCharVolatile(obj, offset);
5256
if (weakCompareAndSetChar(obj, offset, charAtOffset, (char) (charAtOffset & value))) {
5257
return charAtOffset;
5258
}
5259
}
5260
}
5261
5262
/**
5263
* Atomically AND's the given value to the current value of the
5264
* field at offset in obj and returns the value of the field prior
5265
* to the update.
5266
* The get operation has the memory semantics of get.
5267
* The set operation has the memory semantics of setRelease.
5268
*
5269
* @param obj object into which to AND the value
5270
* @param offset location to AND value in obj
5271
* @param value to AND to existing value in field
5272
* @return value of field in obj at offset before update
5273
*/
5274
public final char getAndBitwiseAndCharRelease(Object obj, long offset, char value) {
5275
for (;;) {
5276
char charAtOffset = getChar(obj, offset);
5277
if (weakCompareAndSetCharRelease(obj, offset, charAtOffset, (char) (charAtOffset & value))) {
5278
return charAtOffset;
5279
}
5280
}
5281
}
5282
5283
/**
5284
* Atomically AND's the given value to the current value of the
5285
* field at offset in obj and returns the value of the field prior
5286
* to the update.
5287
* The get operation has the memory semantics of getAcquire.
5288
* The set operation has the memory semantics of set.
5289
*
5290
* @param obj object into which to AND the value
5291
* @param offset location to AND value in obj
5292
* @param value to AND to existing value in field
5293
* @return value of field in obj at offset before update
5294
*/
5295
public final char getAndBitwiseAndCharAcquire(Object obj, long offset, char value) {
5296
for (;;) {
5297
char charAtOffset = getChar(obj, offset);
5298
if (weakCompareAndSetCharAcquire(obj, offset, charAtOffset, (char) (charAtOffset & value))) {
5299
return charAtOffset;
5300
}
5301
}
5302
}
5303
5304
/**
5305
* Atomically XOR's the given value to the current value of the
5306
* field at offset in obj and returns the value of the field prior
5307
* to the update.
5308
* The get operation has the memory semantics of getVolatile.
5309
* The set operation has the memory semantics of setVolatile.
5310
*
5311
* @param obj object into which to XOR the value
5312
* @param offset location to XOR value in obj
5313
* @param value to XOR to existing value in field
5314
* @return value of field in obj at offset before update
5315
*/
5316
public final char getAndBitwiseXorChar(Object obj, long offset, char value) {
5317
for (;;) {
5318
char charAtOffset = getCharVolatile(obj, offset);
5319
if (weakCompareAndSetChar(obj, offset, charAtOffset, (char) (charAtOffset ^ value))) {
5320
return charAtOffset;
5321
}
5322
}
5323
}
5324
5325
/**
5326
* Atomically XOR's the given value to the current value of the
5327
* field at offset in obj and returns the value of the field prior
5328
* to the update.
5329
* The get operation has the memory semantics of get.
5330
* The set operation has the memory semantics of setRelease.
5331
*
5332
* @param obj object into which to XOR the value
5333
* @param offset location to XOR value in obj
5334
* @param value to XOR to existing value in field
5335
* @return value of field in obj at offset before update
5336
*/
5337
public final char getAndBitwiseXorCharRelease(Object obj, long offset, char value) {
5338
for (;;) {
5339
char charAtOffset = getChar(obj, offset);
5340
if (weakCompareAndSetCharRelease(obj, offset, charAtOffset, (char) (charAtOffset ^ value))) {
5341
return charAtOffset;
5342
}
5343
}
5344
}
5345
5346
/**
5347
* Atomically XOR's the given value to the current value of the
5348
* field at offset in obj and returns the value of the field prior
5349
* to the update.
5350
* The get operation has the memory semantics of getAcquire.
5351
* The set operation has the memory semantics of set.
5352
*
5353
* @param obj object into which to XOR the value
5354
* @param offset location to XOR value in obj
5355
* @param value to XOR to existing value in field
5356
* @return value of field in obj at offset before update
5357
*/
5358
public final char getAndBitwiseXorCharAcquire(Object obj, long offset, char value) {
5359
for (;;) {
5360
char charAtOffset = getChar(obj, offset);
5361
if (weakCompareAndSetCharAcquire(obj, offset, charAtOffset, (char) (charAtOffset ^ value))) {
5362
return charAtOffset;
5363
}
5364
}
5365
}
5366
5367
/**
5368
* Atomically OR's the given value to the current value of the
5369
* field at offset in obj and returns the value of the field prior
5370
* to the update.
5371
* The get operation has the memory semantics of getVolatile.
5372
* The set operation has the memory semantics of setVolatile.
5373
*
5374
* @param obj object into which to OR the value
5375
* @param offset location to OR value in obj
5376
* @param value to OR to existing value in field
5377
* @return value of field in obj at offset before update
5378
*/
5379
public final boolean getAndBitwiseOrBoolean(Object obj, long offset, boolean value) {
5380
byte result = getAndBitwiseOrByte(obj, offset, bool2byte(value));
5381
return byte2bool(result);
5382
}
5383
5384
/**
5385
* Atomically OR's the given value to the current value of the
5386
* field at offset in obj and returns the value of the field prior
5387
* to the update.
5388
* The get operation has the memory semantics of get.
5389
* The set operation has the memory semantics of setRelease.
5390
*
5391
* @param obj object into which to OR the value
5392
* @param offset location to OR value in obj
5393
* @param value to OR to existing value in field
5394
* @return value of field in obj at offset before update
5395
*/
5396
public final boolean getAndBitwiseOrBooleanRelease(Object obj, long offset, boolean value) {
5397
byte result = getAndBitwiseOrByteRelease(obj, offset, bool2byte(value));
5398
return byte2bool(result);
5399
}
5400
5401
/**
5402
* Atomically OR's the given value to the current value of the
5403
* field at offset in obj and returns the value of the field prior
5404
* to the update.
5405
* The get operation has the memory semantics of getAcquire.
5406
* The set operation has the memory semantics of set.
5407
*
5408
* @param obj object into which to OR the value
5409
* @param offset location to OR value in obj
5410
* @param value to OR to existing value in field
5411
* @return value of field in obj at offset before update
5412
*/
5413
public final boolean getAndBitwiseOrBooleanAcquire(Object obj, long offset, boolean value) {
5414
byte result = getAndBitwiseOrByteAcquire(obj, offset, bool2byte(value));
5415
return byte2bool(result);
5416
}
5417
5418
/**
5419
* Atomically AND's the given value to the current value of the
5420
* field at offset in obj and returns the value of the field prior
5421
* to the update.
5422
* The get operation has the memory semantics of getVolatile.
5423
* The set operation has the memory semantics of setVolatile.
5424
*
5425
* @param obj object into which to AND the value
5426
* @param offset location to AND value in obj
5427
* @param value to AND to existing value in field
5428
* @return value of field in obj at offset before update
5429
*/
5430
public final boolean getAndBitwiseAndBoolean(Object obj, long offset, boolean value) {
5431
byte result = getAndBitwiseAndByte(obj, offset, bool2byte(value));
5432
return byte2bool(result);
5433
}
5434
5435
/**
5436
* Atomically AND's the given value to the current value of the
5437
* field at offset in obj and returns the value of the field prior
5438
* to the update.
5439
* The get operation has the memory semantics of get.
5440
* The set operation has the memory semantics of setRelease.
5441
*
5442
* @param obj object into which to AND the value
5443
* @param offset location to AND value in obj
5444
* @param value to AND to existing value in field
5445
* @return value of field in obj at offset before update
5446
*/
5447
public final boolean getAndBitwiseAndBooleanRelease(Object obj, long offset, boolean value) {
5448
byte result = getAndBitwiseAndByteRelease(obj, offset, bool2byte(value));
5449
return byte2bool(result);
5450
}
5451
5452
/**
5453
* Atomically AND's the given value to the current value of the
5454
* field at offset in obj and returns the value of the field prior
5455
* to the update.
5456
* The get operation has the memory semantics of getAcquire.
5457
* The set operation has the memory semantics of set.
5458
*
5459
* @param obj object into which to AND the value
5460
* @param offset location to AND value in obj
5461
* @param value to AND to existing value in field
5462
* @return value of field in obj at offset before update
5463
*/
5464
public final boolean getAndBitwiseAndBooleanAcquire(Object obj, long offset, boolean value) {
5465
byte result = getAndBitwiseAndByteAcquire(obj, offset, bool2byte(value));
5466
return byte2bool(result);
5467
}
5468
5469
/**
5470
* Atomically XOR's the given value to the current value of the
5471
* field at offset in obj and returns the value of the field prior
5472
* to the update.
5473
* The get operation has the memory semantics of getVolatile.
5474
* The set operation has the memory semantics of setVolatile.
5475
*
5476
* @param obj object into which to XOR the value
5477
* @param offset location to XOR value in obj
5478
* @param value to XOR to existing value in field
5479
* @return value of field in obj at offset before update
5480
*/
5481
public final boolean getAndBitwiseXorBoolean(Object obj, long offset, boolean value) {
5482
byte result = getAndBitwiseXorByte(obj, offset, bool2byte(value));
5483
return byte2bool(result);
5484
}
5485
5486
/**
5487
* Atomically XOR's the given value to the current value of the
5488
* field at offset in obj and returns the value of the field prior
5489
* to the update.
5490
* The get operation has the memory semantics of get.
5491
* The set operation has the memory semantics of setRelease.
5492
*
5493
* @param obj object into which to XOR the value
5494
* @param offset location to XOR value in obj
5495
* @param value to XOR to existing value in field
5496
* @return value of field in obj at offset before update
5497
*/
5498
public final boolean getAndBitwiseXorBooleanRelease(Object obj, long offset, boolean value) {
5499
byte result = getAndBitwiseXorByteRelease(obj, offset, bool2byte(value));
5500
return byte2bool(result);
5501
}
5502
5503
/**
5504
* Atomically XOR's the given value to the current value of the
5505
* field at offset in obj and returns the value of the field prior
5506
* to the update.
5507
* The get operation has the memory semantics of getAcquire.
5508
* The set operation has the memory semantics of set.
5509
*
5510
* @param obj object into which to XOR the value
5511
* @param offset location to XOR value in obj
5512
* @param value to XOR to existing value in field
5513
* @return value of field in obj at offset before update
5514
*/
5515
public final boolean getAndBitwiseXorBooleanAcquire(Object obj, long offset, boolean value) {
5516
byte result = getAndBitwiseXorByteAcquire(obj, offset, bool2byte(value));
5517
return byte2bool(result);
5518
}
5519
5520
/**
5521
* Inserts an acquire memory fence, ensuring that no loads before this fence
5522
* are reordered with any loads/stores after the fence.
5523
*/
5524
public final void loadLoadFence() {
5525
loadFence();
5526
}
5527
5528
/**
5529
* Inserts a release memory fence, ensuring that no stores before this fence
5530
* are reordered with any loads/stores after the fence.
5531
*/
5532
public final void storeStoreFence() {
5533
storeFence();
5534
}
5535
5536
/**
5537
* @return true if machine is big endian, false otherwise
5538
*/
5539
public final boolean isBigEndian() {
5540
return IS_BIG_ENDIAN;
5541
}
5542
5543
/**
5544
* @return true if addresses are aligned in memory, false otherwise
5545
*/
5546
public final boolean unalignedAccess() {
5547
return UNALIGNED_ACCESS;
5548
}
5549
5550
/**
5551
* Gets the value of the int in the obj parameter referenced by offset
5552
* that may be unaligned in memory.
5553
* This is a non-volatile operation.
5554
*
5555
* @param obj object from which to retrieve the value
5556
* @param offset position of the value in obj
5557
* @return int value stored in obj
5558
*/
5559
public final int getIntUnaligned(Object obj, long offset) {
5560
int result = 0;
5561
5562
if (isOffsetIntAligned(offset)) {
5563
result = getInt(obj, offset);
5564
} else if (isOffsetShortAligned(offset)) {
5565
short first = getShort(obj, offset);
5566
short second = getShort(obj, 2L + offset);
5567
result = makeInt(first, second);
5568
} else {
5569
byte first = getByte(obj, offset);
5570
byte second = getByte(obj, 1L + offset);
5571
byte third = getByte(obj, 2L + offset);
5572
byte fourth = getByte(obj, 3L + offset);
5573
result = makeInt(first, second, third, fourth);
5574
}
5575
5576
return result;
5577
}
5578
5579
/**
5580
* Gets the value of the int in the obj parameter referenced by offset
5581
* that may be unaligned in memory. Value may be reversed according to
5582
* the endianness parameter.
5583
* This is a non-volatile operation.
5584
*
5585
* @param obj object from which to retrieve the value
5586
* @param offset position of the value in obj
5587
* @param bigEndian in what endianness value should be returned
5588
* @return int value stored in obj
5589
*/
5590
public final int getIntUnaligned(Object obj, long offset, boolean bigEndian) {
5591
int result = getIntUnaligned(obj, offset);
5592
return convEndian(bigEndian, result);
5593
}
5594
5595
/**
5596
* Gets the value of the long in the obj parameter referenced by offset
5597
* that may be unaligned in memory.
5598
* This is a non-volatile operation.
5599
*
5600
* @param obj object from which to retrieve the value
5601
* @param offset position of the value in obj
5602
* @return long value stored in obj
5603
*/
5604
public final long getLongUnaligned(Object obj, long offset) {
5605
long result = 0;
5606
5607
if (isOffsetLongAligned(offset)) {
5608
result = getLong(obj, offset);
5609
} else if (isOffsetIntAligned(offset)) {
5610
int first = getInt(obj, offset);
5611
int second = getInt(obj, 4L + offset);
5612
result = makeLong(first, second);
5613
} else if (isOffsetShortAligned(offset)) {
5614
short first = getShort(obj, offset);
5615
short second = getShort(obj, 2L + offset);
5616
short third = getShort(obj, 4L + offset);
5617
short fourth = getShort(obj, 6L + offset);
5618
result = makeLong(first, second, third, fourth);
5619
} else {
5620
byte first = getByte(obj, offset);
5621
byte second = getByte(obj, 1L + offset);
5622
byte third = getByte(obj, 2L + offset);
5623
byte fourth = getByte(obj, 3L + offset);
5624
byte fifth = getByte(obj, 4L + offset);
5625
byte sixth = getByte(obj, 5L + offset);
5626
byte seventh = getByte(obj, 6L + offset);
5627
byte eighth = getByte(obj, 7L + offset);
5628
result = makeLong(first, second, third, fourth, fifth, sixth, seventh, eighth);
5629
}
5630
5631
return result;
5632
}
5633
5634
/**
5635
* Gets the value of the long in the obj parameter referenced by offset
5636
* that may be unaligned in memory. Value may be reversed according to
5637
* the endianness parameter.
5638
* This is a non-volatile operation.
5639
*
5640
* @param obj object from which to retrieve the value
5641
* @param offset position of the value in obj
5642
* @param bigEndian in what endianness value should be returned
5643
* @return long value stored in obj
5644
*/
5645
public final long getLongUnaligned(Object obj, long offset, boolean bigEndian) {
5646
long result = getLongUnaligned(obj, offset);
5647
return convEndian(bigEndian, result);
5648
}
5649
5650
/**
5651
* Gets the value of the short in the obj parameter referenced by offset
5652
* that may be unaligned in memory.
5653
* This is a non-volatile operation.
5654
*
5655
* @param obj object from which to retrieve the value
5656
* @param offset position of the value in obj
5657
* @return short value stored in obj
5658
*/
5659
public final short getShortUnaligned(Object obj, long offset) {
5660
short result = 0;
5661
5662
if (isOffsetShortAligned(offset)) {
5663
result = getShort(obj, offset);
5664
} else {
5665
byte first = getByte(obj, offset);
5666
byte second = getByte(obj, 1L + offset);
5667
result = makeShort(first, second);
5668
}
5669
5670
return result;
5671
}
5672
5673
/**
5674
* Gets the value of the short in the obj parameter referenced by offset
5675
* that may be unaligned in memory. Value may be reversed according to
5676
* the endianness parameter.
5677
* This is a non-volatile operation.
5678
*
5679
* @param obj object from which to retrieve the value
5680
* @param offset position of the value in obj
5681
* @param bigEndian in what endianness value should be returned
5682
* @return short value stored in obj
5683
*/
5684
public final short getShortUnaligned(Object obj, long offset, boolean bigEndian) {
5685
short result = getShortUnaligned(obj, offset);
5686
return convEndian(bigEndian, result);
5687
}
5688
5689
/**
5690
* Gets the value of the char in the obj parameter referenced by offset
5691
* that may be unaligned in memory.
5692
* This is a non-volatile operation.
5693
*
5694
* @param obj object from which to retrieve the value
5695
* @param offset position of the value in obj
5696
* @return char value stored in obj
5697
*/
5698
public final char getCharUnaligned(Object obj, long offset) {
5699
char result = 0;
5700
5701
if (isOffsetCharAligned(offset)) {
5702
result = getChar(obj, offset);
5703
} else {
5704
byte first = getByte(obj, offset);
5705
byte second = getByte(obj, 1L + offset);
5706
result = s2c(makeShort(first, second));
5707
}
5708
5709
return result;
5710
}
5711
5712
/**
5713
* Gets the value of the char in the obj parameter referenced by offset
5714
* that may be unaligned in memory. Value may be reversed according to
5715
* the endianness parameter.
5716
* This is a non-volatile operation.
5717
*
5718
* @param obj object into which to retrieve the value
5719
* @param offset position of the value in obj
5720
* @param bigEndian in what endianness value should be returned
5721
* @return char value stored in obj
5722
*/
5723
public final char getCharUnaligned(Object obj, long offset, boolean bigEndian) {
5724
char result = getCharUnaligned(obj, offset);
5725
return convEndian(bigEndian, result);
5726
}
5727
5728
/**
5729
* Sets the value of the int in the obj parameter at memory offset
5730
* that may be unaligned in memory.
5731
* This is a non-volatile operation.
5732
*
5733
* @param obj object into which to store the value
5734
* @param offset position of the value in obj
5735
* @param value int to store in obj
5736
*/
5737
public final void putIntUnaligned(Object obj, long offset, int value) {
5738
if (isOffsetIntAligned(offset)) {
5739
putInt(obj, offset, value);
5740
} else if (isOffsetShortAligned(offset)) {
5741
putIntParts(obj, offset, (short) (value >> 0), (short) (value >>> 16));
5742
} else {
5743
putIntParts(obj, offset, (byte) (value >>> 0), (byte) (value >>> 8), (byte) (value >>> 16),
5744
(byte) (value >>> 24));
5745
}
5746
}
5747
5748
/**
5749
* Sets the value of the int in the obj parameter at memory offset
5750
* that may be unaligned in memory. Value may be reversed according to
5751
* the endianness parameter.
5752
* This is a non-volatile operation.
5753
*
5754
* @param obj object into which to store the value
5755
* @param offset position of the value in obj
5756
* @param value int to store in obj
5757
* @param bigEndian in what endianness value should be set
5758
*/
5759
public final void putIntUnaligned(Object obj, long offset, int value, boolean bigEndian) {
5760
int endianValue = convEndian(bigEndian, value);
5761
putIntUnaligned(obj, offset, endianValue);
5762
}
5763
5764
/**
5765
* Sets the value of the long in the obj parameter at memory offset
5766
* that may be unaligned in memory.
5767
* This is a non-volatile operation.
5768
*
5769
* @param obj object into which to store the value
5770
* @param offset position of the value in obj
5771
* @param value long to store in obj
5772
*/
5773
public final void putLongUnaligned(Object obj, long offset, long value) {
5774
if (isOffsetLongAligned(offset)) {
5775
putLong(obj, offset, value);
5776
} else if (isOffsetIntAligned(offset)) {
5777
putLongParts(obj, offset, (int) (value >> 0), (int) (value >>> 32));
5778
} else if (isOffsetShortAligned(offset)) {
5779
putLongParts(obj, offset, (short) (value >>> 0), (short) (value >>> 16), (short) (value >>> 32),
5780
(short) (value >>> 48));
5781
} else {
5782
putLongParts(obj, offset, (byte) (value >>> 0), (byte) (value >>> 8), (byte) (value >>> 16),
5783
(byte) (value >>> 24), (byte) (value >>> 32), (byte) (value >>> 40), (byte) (value >>> 48),
5784
(byte) (value >>> 56));
5785
}
5786
}
5787
5788
/**
5789
* Sets the value of the long in the obj parameter at memory offset
5790
* that may be unaligned in memory. Value may be reversed according to
5791
* the endianness parameter.
5792
* This is a non-volatile operation.
5793
*
5794
* @param obj object into which to store the value
5795
* @param offset position of the value in obj
5796
* @param value long to store in obj
5797
* @param bigEndian in what endianness value should be set
5798
*/
5799
public final void putLongUnaligned(Object obj, long offset, long value, boolean bigEndian) {
5800
long endianValue = convEndian(bigEndian, value);
5801
putLongUnaligned(obj, offset, endianValue);
5802
}
5803
5804
/**
5805
* Sets the value of the short in the obj parameter at memory offset
5806
* that may be unaligned in memory.
5807
* This is a non-volatile operation.
5808
*
5809
* @param obj object into which to store the value
5810
* @param offset position of the value in obj
5811
* @param value short to store in obj
5812
*/
5813
public final void putShortUnaligned(Object obj, long offset, short value) {
5814
if (isOffsetShortAligned(offset)) {
5815
putShort(obj, offset, value);
5816
} else {
5817
putShortParts(obj, offset, (byte) (value >>> 0), (byte) (value >>> 8));
5818
}
5819
}
5820
5821
/**
5822
* Sets the value of the short in the obj parameter at memory offset
5823
* that may be unaligned in memory. Value may be reversed according to
5824
* the endianness parameter.
5825
* This is a non-volatile operation.
5826
*
5827
* @param obj object into which to store the value
5828
* @param offset position of the value in obj
5829
* @param value short to store in obj
5830
* @param bigEndian in what endianness value should be set
5831
*/
5832
public final void putShortUnaligned(Object obj, long offset, short value, boolean bigEndian) {
5833
short endianValue = convEndian(bigEndian, value);
5834
putShortUnaligned(obj, offset, endianValue);
5835
}
5836
5837
/**
5838
* Sets the value of the char in the obj parameter at memory offset
5839
* that may be unaligned in memory.
5840
* This is a non-volatile operation.
5841
*
5842
* @param obj object into which to store the value
5843
* @param offset position of the value in obj
5844
* @param value char to store in obj
5845
*/
5846
public final void putCharUnaligned(Object obj, long offset, char value) {
5847
putShortUnaligned(obj, offset, c2s(value));
5848
}
5849
5850
/**
5851
* Sets the value of the char in the obj parameter at memory offset
5852
* that may be unaligned in memory. Value may be reversed according to
5853
* the endianness parameter.
5854
* This is a non-volatile operation.
5855
*
5856
* @param obj object into which to store the value
5857
* @param offset position of the value in obj
5858
* @param value char to store in obj
5859
* @param bigEndian in what endianness value should be set
5860
*/
5861
public final void putCharUnaligned(Object obj, long offset, char value, boolean bigEndian) {
5862
char endianValue = convEndian(bigEndian, value);
5863
putCharUnaligned(obj, offset, endianValue);
5864
}
5865
5866
/*[IF JAVA_SPEC_VERSION >= 12]*/
5867
/**
5868
* If incoming ByteBuffer is an instance of sun.nio.ch.DirectBuffer,
5869
* and it is direct, and not a slice or duplicate,
5870
* if it has a cleaner, it is invoked,
5871
* otherwise an IllegalArgumentException is thrown
5872
*
5873
* @param bbo a ByteBuffer object
5874
* @throws IllegalArgumentException as per description above
5875
*/
5876
public void invokeCleaner(ByteBuffer bbo) {
5877
if (bbo instanceof DirectBuffer) {
5878
if (bbo.isDirect()) {
5879
DirectBuffer db = (DirectBuffer)bbo;
5880
if (db.attachment() == null) {
5881
Cleaner cleaner = db.cleaner();
5882
if (cleaner != null) {
5883
cleaner.clean();
5884
}
5885
} else {
5886
/*[MSG "K0706", "This DirectBuffer object is a slice or duplicate"]*/
5887
throw new IllegalArgumentException(com.ibm.oti.util.Msg.getString("K0706")); //$NON-NLS-1$
5888
}
5889
} else {
5890
/*[MSG "K0705", "This DirectBuffer object is not direct"]*/
5891
throw new IllegalArgumentException(com.ibm.oti.util.Msg.getString("K0705")); //$NON-NLS-1$
5892
}
5893
} else {
5894
/*[MSG "K0704", "A sun.nio.ch.DirectBuffer object is expected"]*/
5895
throw new IllegalArgumentException(com.ibm.oti.util.Msg.getString("K0704")); //$NON-NLS-1$
5896
}
5897
}
5898
/*[ENDIF] JAVA_SPEC_VERSION >= 12 */
5899
5900
/*
5901
* Private methods
5902
*/
5903
/* @return true if offset accesses an int that is aligned in memory, else false */
5904
private boolean isOffsetIntAligned(long offset) {
5905
/* Masks bits that must be 0 to be int aligned. */
5906
final long OFFSET_ALIGNED_INT = 0b11L;
5907
return (0L == (OFFSET_ALIGNED_INT & offset));
5908
}
5909
5910
/* @return true if offset accesses a long that is aligned in memory, else false */
5911
private boolean isOffsetLongAligned(long offset) {
5912
/* Masks bits that must be 0 to be long aligned. */
5913
final long OFFSET_ALIGNED_LONG = 0b111L;
5914
return (0L == (OFFSET_ALIGNED_LONG & offset));
5915
}
5916
5917
/* @return true if offset accesses a short that is aligned in memory, else false */
5918
private boolean isOffsetShortAligned(long offset) {
5919
/* Masks bits that must be 0 to be short aligned. */
5920
final long OFFSET_ALIGNED_SHORT = 0b1L;
5921
return (0L == (OFFSET_ALIGNED_SHORT & offset));
5922
}
5923
5924
/* @return true if offset accesses a char that is aligned in memory, else false */
5925
private boolean isOffsetCharAligned(long offset) {
5926
return isOffsetShortAligned(offset);
5927
}
5928
5929
/* @return new instance of IllegalArgumentException. */
5930
private RuntimeException invalidInput() {
5931
return new IllegalArgumentException();
5932
}
5933
5934
/*
5935
* Generic compareAndExchange for 8 bit primitives (byte and boolean).
5936
*
5937
* @param obj object into which to store the value
5938
* @param offset location to compare and store value in obj
5939
* @param compareValue value extended to the size of an int that is
5940
* expected to be in obj at offset
5941
* @param exchangeValue value extended to the size of an int that will
5942
* be set in obj at offset if compare is successful
5943
* @return value in obj at offset before this operation. This will be compareValue
5944
* if the exchange was successful
5945
*/
5946
private final byte compareAndExchange8bits(Object obj, long offset, int compareValue, int exchangeValue) {
5947
byte result;
5948
5949
if ((obj == null) || obj.getClass().isArray()) {
5950
/* mask extended 8 bit type to remove any sign extension for negative values */
5951
compareValue = BYTE_MASK_INT & compareValue;
5952
exchangeValue = BYTE_MASK_INT & exchangeValue;
5953
5954
int byteOffset = pickPos(3, (int) (BYTE_OFFSET_MASK & offset));
5955
int bitOffset = BITS_IN_BYTE * byteOffset;
5956
int primitiveMask = BYTE_MASK_INT << (BC_SHIFT_INT_MASK & bitOffset);
5957
5958
result = (byte) compareAndExchangeForSmallTypesArraysHelper(obj, offset, compareValue, exchangeValue,
5959
bitOffset, primitiveMask);
5960
} else {
5961
/* object is non-null primitive type */
5962
result = (byte) compareAndExchangeForSmallTypesPrimitivesHelper(obj, offset, compareValue, exchangeValue);
5963
}
5964
5965
return result;
5966
}
5967
5968
/*
5969
* Verify that parameters are valid.
5970
*
5971
* @throws IllegalArgumentException if 16 bit primitive would span multiple
5972
* memory blocks
5973
*/
5974
private void compareAndExchange16BitsOffsetChecks(long offset) {
5975
if ((IS_BIG_ENDIAN) && (BYTE_OFFSET_MASK == (BYTE_OFFSET_MASK & offset))) {
5976
/*[MSG "K0700", "Update spans the word, not supported"]*/
5977
throw new IllegalArgumentException(com.ibm.oti.util.Msg.getString("K0700")); //$NON-NLS-1$
5978
}
5979
}
5980
5981
/*
5982
* Generic compareAndExchange for 16 bit primitives (short and char).
5983
*
5984
* @param obj object into which to store the value
5985
* @param offset location to compare and store value in obj
5986
* @param compareValue value extended to the size of an int that is
5987
* expected to be in obj at offset
5988
* @param exchangeValue value extended to the size of an int that will
5989
* be set in obj at offset if compare is successful
5990
* @return value in obj at offset before this operation. This will be compareValue
5991
* if the exchange was successful
5992
*
5993
* @throws IllegalArgumentException if 16 bit type is unaligned in memory
5994
*/
5995
private final short compareAndExchange16bits(Object obj, long offset, int compareValue, int exchangeValue) {
5996
short result;
5997
5998
compareAndExchange16BitsOffsetChecks(offset);
5999
6000
if ((obj == null) || obj.getClass().isArray()) {
6001
/* mask extended 16 bit type to remove any sign extension for negative values */
6002
compareValue = SHORT_MASK_INT & compareValue;
6003
exchangeValue = SHORT_MASK_INT & exchangeValue;
6004
6005
int byteOffset = pickPos(2, (int) (BYTE_OFFSET_MASK & offset));
6006
int bitOffset = BITS_IN_BYTE * byteOffset;
6007
int primitiveMask = SHORT_MASK_INT << (BC_SHIFT_INT_MASK & bitOffset);
6008
6009
result = (short) compareAndExchangeForSmallTypesArraysHelper(obj, offset, compareValue, exchangeValue,
6010
bitOffset, primitiveMask);
6011
} else {
6012
/* object is non-null primitive type */
6013
result = (short) compareAndExchangeForSmallTypesPrimitivesHelper(obj, offset, compareValue, exchangeValue);
6014
}
6015
6016
return result;
6017
}
6018
6019
/*
6020
* Compare and exchange for a primitive and not an array. Method is for
6021
* primitives smaller than an int such as byte, boolean, char, short.
6022
*
6023
* @param obj object into which to store the value
6024
* @param offset location to compare and store value in obj
6025
* @param compareValue value extended to the size of an int that is
6026
* expected to be in obj at offset
6027
* @param exchangeValue value extended to the size of an int that will
6028
* be set in obj at offset if compare is successful
6029
* @return value of the field before this operation extended to the size of
6030
* an int. This will be compareValue if the exchange was successful
6031
*/
6032
private final int compareAndExchangeForSmallTypesPrimitivesHelper(Object obj, long offset, int compareValue,
6033
int exchangeValue) {
6034
return compareAndExchangeInt(obj, offset, compareValue, exchangeValue);
6035
}
6036
6037
/*
6038
* Compare and exchange for an array of primitives. Method is for primitives
6039
* smaller than an int such as byte, boolean, char, short.
6040
*
6041
* @param obj object into which to store the value
6042
* @param offset location to compare and store value in obj
6043
* @param compareValue value extended to the size of an int that is
6044
* expected to be in obj at offset
6045
* @param exchangeValue value extended to the size of an int that will
6046
* be set in obj at offset if compare is successful
6047
* @param bitOffset offset within aligned int to exchanged primitive
6048
* @param primitiveMask masks bits of exchange value in int
6049
* @return value of the field before this operation extended to the size of an int.
6050
* This will be compareValue if the exchange was successful
6051
*/
6052
private final int compareAndExchangeForSmallTypesArraysHelper(Object obj, long offset, int compareValue,
6053
int exchangeValue, int bitOffset, int primitiveMask) {
6054
for (;;) {
6055
int compareCopy = getIntVolatile(obj, offset & INT_OFFSET_ALIGN_MASK);
6056
6057
/* If object's compare value does not match compareValue argument, fail. */
6058
if ((compareValue << (BC_SHIFT_INT_MASK & bitOffset)) != (primitiveMask & compareCopy)) {
6059
return (primitiveMask & compareCopy) >> bitOffset; /* failure */
6060
}
6061
6062
/*
6063
* Insert exchange value in appropriate position to perform int compare and
6064
* exchange.
6065
*/
6066
int exchangeCopy = (~primitiveMask) & compareCopy;
6067
exchangeCopy |= exchangeValue << (BC_SHIFT_INT_MASK & bitOffset);
6068
6069
int result = compareAndExchangeInt(obj, offset & INT_OFFSET_ALIGN_MASK, compareCopy, exchangeCopy);
6070
6071
if (result == compareCopy) {
6072
return compareValue; /* success */
6073
} else {
6074
/*
6075
* An array value has changed so this operation is no longer atomic. If the
6076
* index that changed is the one we are trying to exchange, fail. Otherwise try
6077
* again.
6078
*/
6079
result &= primitiveMask;
6080
if ((primitiveMask & compareCopy) != result) {
6081
return result >>> (BC_SHIFT_INT_MASK & bitOffset); /* failure */
6082
}
6083
}
6084
}
6085
}
6086
6087
/*
6088
* Verify that no bits are set in long past the least
6089
* significant 32.
6090
*
6091
* @return true if no bits past 32 are set, false otherwise
6092
*/
6093
private boolean is32BitClean(long value) {
6094
long shiftedValue = value >>> 32;
6095
return (0L == shiftedValue);
6096
}
6097
6098
/*
6099
* Verify that parameter is a valid size.
6100
*
6101
* @throws IllegalArgumentException if parameter is not valid
6102
*/
6103
private void checkSize(long value) {
6104
if (BYTES_IN_INT == ADDRESS_SIZE) {
6105
if (!is32BitClean(value)) {
6106
throw invalidInput();
6107
}
6108
} else {
6109
if (value < 0) {
6110
throw invalidInput();
6111
}
6112
}
6113
}
6114
6115
/*
6116
* Verify that the address parameter does not exceed the
6117
* maximum possible value of a native address. Address may
6118
* be negative to support sign extended pointers.
6119
*
6120
* @throws IllegalArgumentException if address is invalid
6121
*/
6122
private void checkNativeAddress(long address) {
6123
if (BYTES_IN_INT == ADDRESS_SIZE) {
6124
long shiftedValue = address >> 32;
6125
6126
/* shiftedValue at this point will be either -1 if address
6127
* is at most 32 bits and negative, or 0 if the address is
6128
* 32 bits and positive. The following calculation will only
6129
* equate to zero and pass the check in these two cases.
6130
*/
6131
shiftedValue = (shiftedValue + 1) & -2L;
6132
6133
if (0 != shiftedValue) {
6134
throw invalidInput();
6135
}
6136
}
6137
}
6138
6139
/*
6140
* Verify that parameter is a valid offset in obj.
6141
*
6142
* @throws IllegalArgumentException if offset is invalid
6143
*/
6144
private void checkOffset(Object obj, long offset) {
6145
if (BYTES_IN_INT == ADDRESS_SIZE) {
6146
boolean isClean = is32BitClean(offset);
6147
if (!isClean) {
6148
throw invalidInput();
6149
}
6150
} else {
6151
if (offset < 0) {
6152
throw invalidInput();
6153
}
6154
}
6155
}
6156
6157
/*
6158
* Verify that parameter is a valid offset in obj.
6159
*
6160
* @throws IllegalArgumentException if offset is invalid
6161
*/
6162
private void checkPointer(Object obj, long offset) {
6163
if (null == obj) {
6164
checkNativeAddress(offset);
6165
} else {
6166
checkOffset(obj, offset);
6167
}
6168
}
6169
6170
/*
6171
* Verify that parameter is a valid array.
6172
*
6173
* @throws IllegalArgumentException if verification fails
6174
*/
6175
private void checkPrimitiveArray(Class<?> c) {
6176
Class<?> cType = c.getComponentType();
6177
6178
if (null == cType || !cType.isPrimitive()) {
6179
throw invalidInput();
6180
}
6181
}
6182
6183
/*
6184
* Verify that parameter is a valid offset in obj,
6185
* and obj is a valid array.
6186
*
6187
* @throws IllegalArgumentException if verification fails
6188
*/
6189
private void checkPrimitivePointer(Object obj, long offset) {
6190
checkPointer(obj, offset);
6191
6192
if (null != obj) {
6193
checkPrimitiveArray(obj.getClass());
6194
}
6195
}
6196
6197
/*
6198
* Verify that parameters is a valid size.
6199
*
6200
* @throws IllegalArgumentException if parameter is not valid
6201
*/
6202
private void allocateMemoryChecks(long size) {
6203
checkSize(size);
6204
}
6205
6206
/*
6207
* Verify that parameters are valid.
6208
*
6209
* @throws IllegalArgumentException if parameters are not valid
6210
*/
6211
private void reallocateMemoryChecks(long address, long size) {
6212
checkPointer(null, address);
6213
checkSize(size);
6214
}
6215
6216
/*
6217
* Verify that parameters are valid.
6218
*
6219
* @throws IllegalArgumentException if startIndex is illegal in obj, or
6220
* if size is invalid
6221
*/
6222
private void setMemoryChecks(Object obj, long startIndex, long size, byte replace) {
6223
checkPrimitivePointer(obj, startIndex);
6224
checkSize(size);
6225
}
6226
6227
/*
6228
* Verify that parameters are valid.
6229
*
6230
* @throws IllegalArgumentException if srcOffset is illegal in srcObj,
6231
* if destOffset is illegal in destObj, or if size is invalid
6232
*/
6233
private void copyMemoryChecks(Object srcObj, long srcOffset, Object destObj, long destOffset, long size) {
6234
checkSize(size);
6235
checkPrimitivePointer(srcObj, srcOffset);
6236
checkPrimitivePointer(destObj, destOffset);
6237
}
6238
6239
/*
6240
* Verify that parameters are valid.
6241
*
6242
* @throws IllegalArgumentException if srcOffset is illegal in srcObj,
6243
* if destOffset is illegal in destObj, if copySize is invalid or copySize is not
6244
* a multiple of elementSize
6245
*/
6246
private void copySwapMemoryChecks(Object srcObj, long srcOffset, Object destObj, long destOffset, long copySize,
6247
long elementSize) {
6248
checkSize(copySize);
6249
if ((2 == elementSize) || (4 == elementSize) || (8 == elementSize)) {
6250
if (0 == (copySize % elementSize)) {
6251
checkPrimitivePointer(srcObj, srcOffset);
6252
checkPrimitivePointer(destObj, destOffset);
6253
} else {
6254
throw invalidInput();
6255
}
6256
} else {
6257
throw invalidInput();
6258
}
6259
}
6260
6261
/*
6262
* Verify that parameter is valid.
6263
*
6264
* @throws IllegalArgumentException if parameter is not valid
6265
*/
6266
private void freeMemoryChecks(long startIndex) {
6267
checkPointer(null, startIndex);
6268
}
6269
6270
/*
6271
* Allocate new array of same type as class parameter and
6272
* length of int parameter.
6273
*
6274
* @param c class of same type as desired array
6275
* @param length desired length of array
6276
* @return allocated array of desired length and type, or null
6277
* if class type is not a primitive wrapper
6278
*/
6279
private Object allocateUninitializedArray0(Class<?> c, int length) {
6280
Object result = null;
6281
6282
if (c == Byte.TYPE) {
6283
result = new byte[length];
6284
} else if (c == Boolean.TYPE) {
6285
result = new boolean[length];
6286
} else if (c == Short.TYPE) {
6287
result = new short[length];
6288
} else if (c == Character.TYPE) {
6289
result = new char[length];
6290
} else if (c == Integer.TYPE) {
6291
result = new int[length];
6292
} else if (c == Float.TYPE) {
6293
result = new float[length];
6294
} else if (c == Long.TYPE) {
6295
result = new long[length];
6296
} else if (c == Double.TYPE) {
6297
result = new double[length];
6298
}
6299
6300
return result;
6301
}
6302
6303
/* Convert short primitive to char. */
6304
private char s2c(short value) {
6305
return (char) value;
6306
}
6307
6308
/* Convert char primitive to short. */
6309
private short c2s(char value) {
6310
return (short) value;
6311
}
6312
6313
/* Convert byte primitive to boolean. */
6314
private boolean byte2bool(byte value) {
6315
return (value != 0);
6316
}
6317
6318
/* Convert boolean primitive to byte. */
6319
private byte bool2byte(boolean value) {
6320
return (value) ? (byte) 1 : (byte) 0;
6321
}
6322
6323
/* Throws new instance of IllegalAccessError. */
6324
private static void throwIllegalAccessError() {
6325
throw new IllegalAccessError();
6326
}
6327
6328
/*
6329
* Picks position based on endianness.
6330
*
6331
* @param value total length of object
6332
* @param position little endian position of object
6333
* @return position based on endianness of machine
6334
*/
6335
private static int pickPos(int value, int position) {
6336
return (IS_BIG_ENDIAN) ? (value - position) : (position);
6337
}
6338
6339
/*
6340
* Creates an int by concatenating two shorts where the first parameter is the
6341
* least significant. Ordering is based on endianness of the machine.
6342
*/
6343
private static int makeInt(short arg0, short arg1) {
6344
int result;
6345
result = toUnsignedInt(arg0) << (BC_SHIFT_INT_MASK & pickPos(16, 0));
6346
result |= toUnsignedInt(arg1) << (BC_SHIFT_INT_MASK & pickPos(16, 16));
6347
return result;
6348
}
6349
6350
/*
6351
* Creates an int by concatenating four bytes where the first parameter is the
6352
* least significant. Ordering is based on endianness of the machine.
6353
*/
6354
private static int makeInt(byte arg0, byte arg1, byte arg2, byte arg3) {
6355
int result;
6356
result = toUnsignedInt(arg0) << (BC_SHIFT_INT_MASK & pickPos(24, 0));
6357
result |= toUnsignedInt(arg1) << (BC_SHIFT_INT_MASK & pickPos(24, 8));
6358
result |= toUnsignedInt(arg2) << (BC_SHIFT_INT_MASK & pickPos(24, 16));
6359
result |= toUnsignedInt(arg3) << (BC_SHIFT_INT_MASK & pickPos(24, 24));
6360
return result;
6361
}
6362
6363
/*
6364
* Creates a long by concatenating eight bytes where the first parameter is the least significant.
6365
* Ordering is based on endianness of the machine.
6366
*/
6367
private static long makeLong(byte arg0, byte arg1, byte arg2, byte arg3, byte arg4, byte arg5, byte arg6,
6368
byte arg7) {
6369
long result;
6370
result = toUnsignedLong(arg0) << (BC_SHIFT_LONG_MASK & pickPos(56, 0));
6371
result |= toUnsignedLong(arg1) << (BC_SHIFT_LONG_MASK & pickPos(56, 8));
6372
result |= toUnsignedLong(arg2) << (BC_SHIFT_LONG_MASK & pickPos(56, 16));
6373
result |= toUnsignedLong(arg3) << (BC_SHIFT_LONG_MASK & pickPos(56, 24));
6374
result |= toUnsignedLong(arg4) << (BC_SHIFT_LONG_MASK & pickPos(56, 32));
6375
result |= toUnsignedLong(arg5) << (BC_SHIFT_LONG_MASK & pickPos(56, 40));
6376
result |= toUnsignedLong(arg6) << (BC_SHIFT_LONG_MASK & pickPos(56, 48));
6377
result |= toUnsignedLong(arg7) << (BC_SHIFT_LONG_MASK & pickPos(56, 56));
6378
return result;
6379
}
6380
6381
/*
6382
* Creates a long by concatenating four shorts where the first parameter is the least
6383
* significant. Ordering is based on endianness of the machine.
6384
*/
6385
private static long makeLong(short arg0, short arg1, short arg2, short arg3) {
6386
long result;
6387
result = toUnsignedLong(arg0) << (BC_SHIFT_LONG_MASK & pickPos(48, 0));
6388
result |= toUnsignedLong(arg1) << (BC_SHIFT_LONG_MASK & pickPos(48, 16));
6389
result |= toUnsignedLong(arg2) << (BC_SHIFT_LONG_MASK & pickPos(48, 32));
6390
result |= toUnsignedLong(arg3) << (BC_SHIFT_LONG_MASK & pickPos(48, 48));
6391
return result;
6392
}
6393
6394
/*
6395
* Creates a long by concatenating two integers where the first parameter is the
6396
* least significant. Ordering is based on endianness of the machine.
6397
*/
6398
private static long makeLong(int arg0, int arg1) {
6399
long result;
6400
result = toUnsignedLong(arg0) << (BC_SHIFT_LONG_MASK & pickPos(32, 0));
6401
result |= toUnsignedLong(arg1) << (BC_SHIFT_LONG_MASK & pickPos(32, 32));
6402
return result;
6403
}
6404
6405
/*
6406
* Creates a short by concatenating two bytes where the first parameter is the
6407
* least significant. Ordering is based on endianness of the machine.
6408
*/
6409
private static short makeShort(byte arg0, byte arg1) {
6410
int result;
6411
result = toUnsignedInt(arg0) << (BC_SHIFT_INT_MASK & pickPos(8, 0));
6412
result |= toUnsignedInt(arg1) << (BC_SHIFT_INT_MASK & pickPos(8, 8));
6413
return (short) result;
6414
}
6415
6416
/*
6417
* Pick first parameter if machine is little endian,
6418
* otherwise pick second.
6419
*/
6420
private static byte pick(byte arg0, byte arg1) {
6421
return (IS_BIG_ENDIAN) ? arg1 : arg0;
6422
}
6423
6424
/*
6425
* Pick first parameter if machine is little endian,
6426
* otherwise pick second.
6427
*/
6428
private static short pick(short arg0, short arg1) {
6429
return (IS_BIG_ENDIAN) ? arg1 : arg0;
6430
}
6431
6432
/*
6433
* Pick first parameter if machine is little endian,
6434
* otherwise pick second.
6435
*/
6436
private static int pick(int arg0, int arg1) {
6437
return (IS_BIG_ENDIAN) ? arg1 : arg0;
6438
}
6439
6440
/*
6441
* Insert int value inserted per short into obj at offset. The first short parameter is the
6442
* least significant and will be inserted according to machine endianness.
6443
*/
6444
private void putIntParts(Object obj, long offset, short part1, short part2) {
6445
putShort(obj, 0L + offset, pick(part1, part2));
6446
putShort(obj, 2L + offset, pick(part2, part1));
6447
}
6448
6449
/*
6450
* Insert int value inserted per byte into obj at offset. The first byte parameter is the
6451
* least significant and will be inserted according to machine endianness.
6452
*/
6453
private void putIntParts(Object obj, long offset, byte part1, byte part2, byte part3, byte part4) {
6454
putByte(obj, 0L + offset, pick(part1, part4));
6455
putByte(obj, 1L + offset, pick(part2, part3));
6456
putByte(obj, 2L + offset, pick(part3, part2));
6457
putByte(obj, 3L + offset, pick(part4, part1));
6458
}
6459
6460
/*
6461
* Insert long value inserted per byte into obj at offset. The first byte parameter is the
6462
* least significant and will be inserted according to machine endianness.
6463
*/
6464
private void putLongParts(Object obj, long offset, byte part1, byte part2, byte part3, byte part4, byte part5,
6465
byte part6, byte part7, byte part8) {
6466
putByte(obj, 0L + offset, pick(part1, part8));
6467
putByte(obj, 1L + offset, pick(part2, part7));
6468
putByte(obj, 2L + offset, pick(part3, part6));
6469
putByte(obj, 3L + offset, pick(part4, part5));
6470
putByte(obj, 4L + offset, pick(part5, part4));
6471
putByte(obj, 5L + offset, pick(part6, part3));
6472
putByte(obj, 6L + offset, pick(part7, part2));
6473
putByte(obj, 7L + offset, pick(part8, part1));
6474
}
6475
6476
/*
6477
* Insert long value inserted per short into obj at offset. The first short parameter is the
6478
* least significant and will be inserted according to machine endianness.
6479
*/
6480
private void putLongParts(Object obj, long offset, short part1, short part2, short part3, short part4) {
6481
putShort(obj, 0L + offset, pick(part1, part4));
6482
putShort(obj, 2L + offset, pick(part2, part3));
6483
putShort(obj, 4L + offset, pick(part3, part2));
6484
putShort(obj, 6L + offset, pick(part4, part1));
6485
}
6486
6487
/*
6488
* Insert long value inserted per int into obj at offset. The first int parameter is the
6489
* least significant and will be inserted according to machine endianness.
6490
*/
6491
private void putLongParts(Object obj, long offset, int part1, int part2) {
6492
putInt(obj, 0L + offset, pick(part1, part2));
6493
putInt(obj, 4L + offset, pick(part2, part1));
6494
}
6495
6496
/*
6497
* Insert short value inserted per byte into obj at offset. The first byte parameter is the
6498
* least significant and will be inserted according to machine endianness.
6499
*/
6500
private void putShortParts(Object obj, long offset, byte part1, byte part2) {
6501
putByte(obj, 0L + offset, pick(part1, part2));
6502
putByte(obj, 1L + offset, pick(part2, part1));
6503
}
6504
6505
/* Converts byte to unsigned int. */
6506
private static int toUnsignedInt(byte value) {
6507
int ivalue = value;
6508
return BYTE_MASK_INT & ivalue;
6509
}
6510
6511
/* Converts short to unsigned int. */
6512
private static int toUnsignedInt(short value) {
6513
int ivalue = value;
6514
return SHORT_MASK_INT & ivalue;
6515
}
6516
6517
/* Converts byte to unsigned long. */
6518
private static long toUnsignedLong(byte value) {
6519
long lvalue = value;
6520
return BYTE_MASK & lvalue;
6521
}
6522
6523
/* Converts short to unsigned long. */
6524
private static long toUnsignedLong(short value) {
6525
long lvalue = value;
6526
return SHORT_MASK & lvalue;
6527
}
6528
6529
/* Converts int to unsigned long. */
6530
private static long toUnsignedLong(int value) {
6531
long lvalue = value;
6532
return INT_MASK & lvalue;
6533
}
6534
6535
/* Convert int value according to users endianness preference. Bytes may be reversed. */
6536
private static int convEndian(boolean isBigEndian, int value) {
6537
return (IS_BIG_ENDIAN == isBigEndian) ? value : Integer.reverseBytes(value);
6538
}
6539
6540
/* Convert long value according to users endianness preference. Bytes may be reversed. */
6541
private static long convEndian(boolean isBigEndian, long value) {
6542
return (IS_BIG_ENDIAN == isBigEndian) ? value : Long.reverseBytes(value);
6543
}
6544
6545
/* Convert short value according to users endianness preference. Bytes may be reversed. */
6546
private static short convEndian(boolean isBigEndian, short value) {
6547
return (IS_BIG_ENDIAN == isBigEndian) ? value : Short.reverseBytes(value);
6548
}
6549
6550
/* Converts char value according to users endianness preference. Bytes may be reversed. */
6551
private static char convEndian(boolean isBigEndian, char value) {
6552
return (IS_BIG_ENDIAN == isBigEndian) ? value : Character.reverseBytes(value);
6553
}
6554
6555
/*[IF INLINE-TYPES]*/
6556
/**
6557
* Retrieves the value of the primitive type in the obj parameter referenced by offset.
6558
* The primitive type in obj at the given offset must be flattened.
6559
* This is a non-volatile operation.
6560
*
6561
* @param obj object from which to retrieve the primitive type
6562
* @param offset position of the primitive type in obj
6563
* @param clz the class of primitive type to return
6564
* @return the value of the primitive type stored in obj at the given offset
6565
*/
6566
public native <V> V getValue(Object obj, long offset, Class<?> clz);
6567
6568
/**
6569
* Sets the value of the primitive type in the obj parameter at memory offset.
6570
* Both the new value and the primitive type in obj at the given offset must be flattened.
6571
* This is a non-volatile operation.
6572
*
6573
* @param obj object into which to store the primitive type
6574
* @param offset position of the primitive type in obj
6575
* @param clz the class of the primitive type to store in obj
6576
* @param value primitive type to store in obj
6577
*/
6578
public native <V> void putValue(Object obj, long offset, Class<?> clz, V value);
6579
6580
/**
6581
* Returns the uninitialized default instance of the specified primitive class
6582
*
6583
* @param clz the specificed primitive class
6584
* @return the uninitialized default instance of clz
6585
*/
6586
public native <V> V uninitializedDefaultValue(Class<?> clz);
6587
6588
/**
6589
* Determines the size of the header for a specified primitive class
6590
*
6591
* @param clz the specified primitive class
6592
* @return the size of the header for clz
6593
*/
6594
public native <V> long valueHeaderSize(Class<V> clz);
6595
6596
/**
6597
* Determines whether a class is a flattened array
6598
*
6599
* @param clz the class to check
6600
* @return boolean value indicating whether the class is a flattened array
6601
*/
6602
public native boolean isFlattenedArray(Class<?> clz);
6603
6604
/**
6605
* Determines whether a field is flattened
6606
*
6607
* @param field the field to check
6608
* @return boolean value indicating whether the field is flattened
6609
*/
6610
public native boolean isFlattened(Field field);
6611
6612
/**
6613
* Determines the size of an object in bytes
6614
*
6615
* @param o the object to determine the size of
6616
*/
6617
public native long getObjectSize(Object o);
6618
6619
public final <V> boolean compareAndSetValue(Object obj, long offset, Class<?> clz, V v1, V v2) {
6620
throw OpenJDKCompileStubThrowError();
6621
}
6622
6623
public final <V> Object compareAndExchangeValue(Object obj, long offset, Class<?> clz, V v1, V v2) {
6624
throw OpenJDKCompileStubThrowError();
6625
}
6626
6627
public final <V> Object compareAndExchangeValueAcquire(Object obj, long offset, Class<?> clz, V v1, V v2) {
6628
throw OpenJDKCompileStubThrowError();
6629
}
6630
6631
public final <V> Object compareAndExchangeValueRelease(Object obj, long offset, Class<?> clz, V v1, V v2) {
6632
throw OpenJDKCompileStubThrowError();
6633
}
6634
6635
public final <V> boolean weakCompareAndSetValuePlain(Object obj, long offset, Class<?> clz, V v1, V v2) {
6636
throw OpenJDKCompileStubThrowError();
6637
}
6638
6639
public final <V> boolean weakCompareAndSetValueAcquire(Object obj, long offset, Class<?> clz, V v1, V v2) {
6640
throw OpenJDKCompileStubThrowError();
6641
}
6642
6643
public final <V> boolean weakCompareAndSetValueRelease(Object obj, long offset, Class<?> clz, V v1, V v2) {
6644
throw OpenJDKCompileStubThrowError();
6645
}
6646
6647
public final <V> boolean weakCompareAndSetValue(Object obj, long offset, Class<?> clz, V v1, V v2) {
6648
throw OpenJDKCompileStubThrowError();
6649
}
6650
6651
/**
6652
* Atomically retrieves the primitive type in the obj parameter referenced by offset.
6653
*
6654
* @param obj object from which to retrieve the primitive type
6655
* @param offset position of the primitive type in obj
6656
* @param clz the class of primitive type to return
6657
* @return primitive type stored in obj
6658
*/
6659
public final <V> Object getValueVolatile(Object obj, long offset, Class<?> clz) {
6660
return getValue(obj, offset, clz);
6661
}
6662
6663
/**
6664
* Atomically sets the value of the primitive type in the obj parameter at memory offset.
6665
* This is a non-volatile operation.
6666
*
6667
* @param obj object into which to store the primitive type
6668
* @param offset position of the primitive type in obj
6669
* @param clz the class of the primitive type to store in obj
6670
* @param value primitive type to store in obj
6671
*/
6672
public final <V> void putValueVolatile(Object obj, long offset, Class<?> clz, V v) {
6673
putValue(obj, offset, clz, v);
6674
}
6675
6676
public final <V> Object getValueAcquire(Object obj, long offset, Class<?> clz) {
6677
throw OpenJDKCompileStubThrowError();
6678
}
6679
6680
public final <V> void putValueRelease(Object obj, long offset, Class<?> clz, V v) {
6681
throw OpenJDKCompileStubThrowError();
6682
}
6683
6684
public final <V> Object getValueOpaque(Object obj, long offset, Class<?> clz) {
6685
throw OpenJDKCompileStubThrowError();
6686
}
6687
6688
public final <V> void putValueOpaque(Object obj, long offset, Class<?> clz, V v) {
6689
throw OpenJDKCompileStubThrowError();
6690
}
6691
6692
public final <V> Object getAndSetValue(Object obj, long offset, Class<?> clz, V v) {
6693
throw OpenJDKCompileStubThrowError();
6694
}
6695
6696
public final <V> Object getAndSetValueRelease(Object obj, long offset, Class<?> clz, V v) {
6697
throw OpenJDKCompileStubThrowError();
6698
}
6699
6700
public final <V> Object getAndSetValueAcquire(Object obj, long offset, Class<?> clz, V v) {
6701
throw OpenJDKCompileStubThrowError();
6702
}
6703
6704
/**
6705
* Atomically sets the reference at offset in obj if the compare value
6706
* matches the existing value in the object.
6707
* The get operation has memory semantics of get.
6708
* The set operation has the memory semantics of setRelease.
6709
*
6710
* @param obj object into which to store the value
6711
* @param offset location to compare and store value in obj
6712
* @param clz Class of the obj
6713
* @param compareValue value that is expected to be in obj at offset
6714
* @param setValue value that will be set in obj at offset if compare is successful
6715
* @return boolean value indicating whether the field was updated
6716
*/
6717
public final <V> boolean compareAndSetReference(Object obj, long offset, Class<?> clz, V compareValue, V setValue) {
6718
return compareAndSetReference(obj, offset, compareValue, setValue);
6719
}
6720
6721
/**
6722
* Atomically sets the reference at offset in obj if the compare value
6723
* matches the existing value in the object.
6724
* The get operation has memory semantics of getAcquire.
6725
* The set operation has the memory semantics of set.
6726
*
6727
* @param obj object into which to store the value
6728
* @param offset location to compare and store value in obj
6729
* @param clz Class of the obj
6730
* @param compareValue value that is expected to be in obj at offset
6731
* @param setValue value that will be set in obj at offset if compare is successful
6732
* @return boolean value indicating whether the field was updated
6733
*/
6734
public final <V> boolean weakCompareAndSetReferenceAcquire(Object obj, long offset, Class<?> clz, V compareValue, V setValue) {
6735
return weakCompareAndSetReferenceAcquire(obj, offset, compareValue, setValue);
6736
}
6737
6738
/**
6739
* Sets the reference at offset in obj if the compare value
6740
* matches the existing value in the object.
6741
* The get operation has memory semantics of get.
6742
* The set operation has the memory semantics of setRelease.
6743
*
6744
* @param obj object into which to store the value
6745
* @param offset location to compare and store value in obj
6746
* @param clz Class of the obj
6747
* @param compareValue value that is expected to be in obj at offset
6748
* @param setValue value that will be set in obj at offset if compare is successful
6749
* @return boolean value indicating whether the field was updated
6750
*/
6751
public final <V> boolean weakCompareAndSetReferenceRelease(Object obj, long offset, Class<?> clz, V compareValue, V setValue) {
6752
return weakCompareAndSetReferenceRelease(obj, offset, compareValue, setValue);
6753
}
6754
6755
/**
6756
* Atomically sets the reference at offset in obj if the compare value
6757
* matches the existing value in the object.
6758
* The get operation has memory semantics of getVolatile.
6759
* The set operation has the memory semantics of setVolatile.
6760
*
6761
* @param obj object into which to store the value
6762
* @param offset location to compare and store value in obj
6763
* @param clz Class of the obj
6764
* @param compareValue value that is expected to be in obj at offset
6765
* @param exchangeValue value that will be set in obj at offset if compare is successful
6766
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
6767
*/
6768
public final <V> Object compareAndExchangeReference(Object obj, long offset, Class<?> clz, V compareValue, V exchangeValue) {
6769
return compareAndExchangeReference(obj, offset, compareValue, exchangeValue);
6770
}
6771
6772
/**
6773
* Atomically sets the reference at offset in obj if the compare value
6774
* matches the existing value in the object.
6775
* The get operation has memory semantics of getAcquire.
6776
* The set operation has the memory semantics of set.
6777
*
6778
* @param obj object into which to store the value
6779
* @param offset location to compare and store value in obj
6780
* @param clz Class of the obj
6781
* @param compareValue value that is expected to be in obj at offset
6782
* @param exchangeValue value that will be set in obj at offset if compare is successful
6783
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
6784
*/
6785
public final <V> Object compareAndExchangeReferenceAcquire(Object obj, long offset, Class<?> clz, V compareValue, V exchangeValue) {
6786
return compareAndExchangeReferenceAcquire(obj, offset, compareValue, exchangeValue);
6787
}
6788
6789
/**
6790
* Atomically sets the reference at offset in obj if the compare value
6791
* matches the existing value in the object.
6792
* The get operation has memory semantics of get.
6793
* The set operation has the memory semantics of setRelease.
6794
*
6795
* @param obj object into which to store the value
6796
* @param offset location to compare and store value in obj
6797
* @param clz Class of the obj
6798
* @param compareValue value that is expected to be in obj at offset
6799
* @param exchangeValue value that will be set in obj at offset if compare is successful
6800
* @return value in obj at offset before this operation. This will be compareValue if the exchange was successful
6801
*/
6802
public final <V> Object compareAndExchangeReferenceRelease(Object obj, long offset, Class<?> clz, V compareValue, V exchangeValue) {
6803
return compareAndExchangeReferenceRelease(obj, offset, compareValue, exchangeValue);
6804
}
6805
6806
/**
6807
* Sets the reference at offset in obj if the compare value
6808
* matches the existing value in the object.
6809
* The get operation has memory semantics of get.
6810
* The set operation has the memory semantics of set.
6811
*
6812
* @param obj object into which to store the value
6813
* @param offset location to compare and store value in obj
6814
* @param clz Class of the obj
6815
* @param compareValue value that is expected to be in obj at offset
6816
* @param setValue value that will be set in obj at offset if compare is successful
6817
* @return boolean value indicating whether the field was updated
6818
*/
6819
public final <V> boolean weakCompareAndSetReferencePlain(Object obj, long offset, Class<?> clz, V compareValue, V setValue) {
6820
return weakCompareAndSetReferencePlain(obj, offset, compareValue, setValue);
6821
}
6822
6823
/**
6824
* Sets the reference at offset in obj if the compare value
6825
* matches the existing value in the object.
6826
* The get operation has memory semantics of get.
6827
* The set operation has the memory semantics of set.
6828
*
6829
* @param obj object into which to store the value
6830
* @param offset location to compare and store value in obj
6831
* @param clz Class of the obj
6832
* @param compareValue value that is expected to be in obj at offset
6833
* @param setValue value that will be set in obj at offset if compare is successful
6834
* @return boolean value indicating whether the field was updated
6835
*/
6836
public final <V> boolean weakCompareAndSetReference(Object obj, long offset, Class<?> clz, V compareValue, V setValue) {
6837
return weakCompareAndSetReference(obj, offset, compareValue, setValue);
6838
}
6839
6840
public Object getReferenceVolatile(Object obj, long offset, Class<?> clz) {
6841
// ToDo: this is a temporary implementation - https://github.com/eclipse-openj9/openj9/issues/13614
6842
return getReferenceVolatile(obj, offset);
6843
}
6844
6845
public Object getReference(Object obj, long offset, Class<?> clz) {
6846
// ToDo: this is a temporary implementation - https://github.com/eclipse-openj9/openj9/issues/13614
6847
return getReference(obj, offset);
6848
}
6849
6850
private static InternalError OpenJDKCompileStubThrowError() {
6851
// ToDo: https://github.com/eclipse-openj9/openj9/issues/13614
6852
throw new InternalError("Compile stub invoked! Apart from deliberate reflective access, this should not happen. Please report this to the project so it can be addressed"); //$NON-NLS-1$
6853
}
6854
/*[ENDIF] INLINE-TYPES */
6855
}
6856
6857