< prev index next >

src/java.base/share/classes/java/lang/invoke/X-VarHandleSegmentView.java.template

Print this page

 26 
 27 import jdk.internal.foreign.AbstractMemorySegmentImpl;
 28 import jdk.internal.misc.ScopedMemoryAccess;
 29 import jdk.internal.vm.annotation.ForceInline;
 30 
 31 import java.lang.foreign.MemorySegment;
 32 import java.lang.ref.Reference;
 33 
 34 import java.util.Objects;
 35 
 36 import static java.lang.invoke.MethodHandleStatics.UNSAFE;
 37 
 38 #warn
 39 
 40 final class VarHandleSegmentAs$Type$s extends VarHandleSegmentViewBase {
 41 
 42     static final boolean BE = UNSAFE.isBigEndian();
 43 
 44     static final ScopedMemoryAccess SCOPED_MEMORY_ACCESS = ScopedMemoryAccess.getScopedMemoryAccess();
 45 
 46     static final int VM_ALIGN = $BoxType$.BYTES - 1;
 47 
 48     static final VarForm FORM = new VarForm(VarHandleSegmentAs$Type$s.class, MemorySegment.class, $type$.class, long.class);
 49 
 50     VarHandleSegmentAs$Type$s(boolean be, long length, long alignmentMask, boolean exact) {
 51         super(FORM, be, length, alignmentMask, exact);
 52     }
 53 
 54     @Override
 55     final MethodType accessModeTypeUncached(VarHandle.AccessType accessType) {
 56         return accessType.accessModeType(MemorySegment.class, $type$.class, long.class);
 57     }
 58 
 59     @Override
 60     public VarHandleSegmentAs$Type$s withInvokeExactBehavior() {
 61         return hasInvokeExactBehavior() ?
 62                 this :
 63                 new VarHandleSegmentAs$Type$s(be, length, alignmentMask, true);
 64     }
 65 
 66     @Override

 87     @ForceInline
 88     static $type$ convEndian(boolean big, $type$ n) {
 89         return n;
 90     }
 91 #else[byte]
 92     @ForceInline
 93     static $type$ convEndian(boolean big, $type$ n) {
 94         return big == BE ? n : $BoxType$.reverseBytes(n);
 95     }
 96 #end[byte]
 97 #end[floatingPoint]
 98 
 99     @ForceInline
100     static AbstractMemorySegmentImpl checkAddress(Object obb, long offset, long length, boolean ro) {
101         AbstractMemorySegmentImpl oo = (AbstractMemorySegmentImpl)Objects.requireNonNull(obb);
102         oo.checkAccess(offset, length, ro);
103         return oo;
104     }
105 
106     @ForceInline
107     static long offset(AbstractMemorySegmentImpl bb, long offset, long alignmentMask) {
108         long address = offsetNoVMAlignCheck(bb, offset, alignmentMask);
109         if ((address & VM_ALIGN) != 0) {
110             throw VarHandleSegmentViewBase.newIllegalArgumentExceptionForMisalignedAccess(address);
111         }
112         return address;
113     }
114 
115     @ForceInline
116     static long offsetNoVMAlignCheck(AbstractMemorySegmentImpl bb, long offset, long alignmentMask) {
117         long base = bb.unsafeGetOffset();
118         long address = base + offset;
119         long maxAlignMask = bb.maxAlignMask();
120         if (((address | maxAlignMask) & alignmentMask) != 0) {
121             throw VarHandleSegmentViewBase.newIllegalArgumentExceptionForMisalignedAccess(address);
122         }
123         return address;
124     }
125 
126     @ForceInline
127     static $type$ get(VarHandle ob, Object obb, long base) {
128         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
129         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, true);
130 #if[floatingPoint]
131         $rawType$ rawValue = SCOPED_MEMORY_ACCESS.get$RawType$Unaligned(bb.sessionImpl(),
132                 bb.unsafeGetBase(),
133                 offsetNoVMAlignCheck(bb, base, handle.alignmentMask),
134                 handle.be);
135         return $Type$.$rawType$BitsTo$Type$(rawValue);
136 #else[floatingPoint]
137 #if[byte]
138         return SCOPED_MEMORY_ACCESS.get$Type$(bb.sessionImpl(),
139                 bb.unsafeGetBase(),
140                 offsetNoVMAlignCheck(bb, base, handle.alignmentMask));
141 #else[byte]
142         return SCOPED_MEMORY_ACCESS.get$Type$Unaligned(bb.sessionImpl(),
143                 bb.unsafeGetBase(),
144                 offsetNoVMAlignCheck(bb, base, handle.alignmentMask),
145                 handle.be);
146 #end[byte]
147 #end[floatingPoint]
148     }
149 
150     @ForceInline
151     static void set(VarHandle ob, Object obb, long base, $type$ value) {
152         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
153         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
154 #if[floatingPoint]
155         SCOPED_MEMORY_ACCESS.put$RawType$Unaligned(bb.sessionImpl(),
156                 bb.unsafeGetBase(),
157                 offsetNoVMAlignCheck(bb, base, handle.alignmentMask),
158                 $Type$.$type$ToRaw$RawType$Bits(value),
159                 handle.be);
160 #else[floatingPoint]
161 #if[byte]
162         SCOPED_MEMORY_ACCESS.put$Type$(bb.sessionImpl(),
163                 bb.unsafeGetBase(),
164                 offsetNoVMAlignCheck(bb, base, handle.alignmentMask),
165                 value);
166 #else[byte]
167         SCOPED_MEMORY_ACCESS.put$Type$Unaligned(bb.sessionImpl(),
168                 bb.unsafeGetBase(),
169                 offsetNoVMAlignCheck(bb, base, handle.alignmentMask),
170                 value,
171                 handle.be);
172 #end[byte]
173 #end[floatingPoint]
174     }
175 
176     @ForceInline
177     static $type$ getVolatile(VarHandle ob, Object obb, long base) {
178         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
179         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, true);
180         return convEndian(handle.be,
181                           SCOPED_MEMORY_ACCESS.get$RawType$Volatile(bb.sessionImpl(),
182                                   bb.unsafeGetBase(),
183                                   offset(bb, base, handle.alignmentMask)));
184     }
185 
186     @ForceInline
187     static void setVolatile(VarHandle ob, Object obb, long base, $type$ value) {
188         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
189         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
190         SCOPED_MEMORY_ACCESS.put$RawType$Volatile(bb.sessionImpl(),
191                 bb.unsafeGetBase(),
192                 offset(bb, base, handle.alignmentMask),
193                 convEndian(handle.be, value));
194     }
195 
196     @ForceInline
197     static $type$ getAcquire(VarHandle ob, Object obb, long base) {
198         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
199         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, true);
200         return convEndian(handle.be,
201                           SCOPED_MEMORY_ACCESS.get$RawType$Acquire(bb.sessionImpl(),
202                                   bb.unsafeGetBase(),
203                                   offset(bb, base, handle.alignmentMask)));
204     }
205 
206     @ForceInline
207     static void setRelease(VarHandle ob, Object obb, long base, $type$ value) {
208         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
209         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
210         SCOPED_MEMORY_ACCESS.put$RawType$Release(bb.sessionImpl(),
211                 bb.unsafeGetBase(),
212                 offset(bb, base, handle.alignmentMask),
213                 convEndian(handle.be, value));
214     }
215 
216     @ForceInline
217     static $type$ getOpaque(VarHandle ob, Object obb, long base) {
218         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
219         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, true);
220         return convEndian(handle.be,
221                           SCOPED_MEMORY_ACCESS.get$RawType$Opaque(bb.sessionImpl(),
222                                   bb.unsafeGetBase(),
223                                   offset(bb, base, handle.alignmentMask)));
224     }
225 
226     @ForceInline
227     static void setOpaque(VarHandle ob, Object obb, long base, $type$ value) {
228         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
229         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
230         SCOPED_MEMORY_ACCESS.put$RawType$Opaque(bb.sessionImpl(),
231                 bb.unsafeGetBase(),
232                 offset(bb, base, handle.alignmentMask),
233                 convEndian(handle.be, value));
234     }
235 #if[CAS]
236 
237     @ForceInline
238     static boolean compareAndSet(VarHandle ob, Object obb, long base, $type$ expected, $type$ value) {
239         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
240         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
241         return SCOPED_MEMORY_ACCESS.compareAndSet$RawType$(bb.sessionImpl(),
242                 bb.unsafeGetBase(),
243                 offset(bb, base, handle.alignmentMask),
244                 convEndian(handle.be, expected), convEndian(handle.be, value));
245     }
246 
247     @ForceInline
248     static $type$ compareAndExchange(VarHandle ob, Object obb, long base, $type$ expected, $type$ value) {
249         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
250         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
251         return convEndian(handle.be,
252                           SCOPED_MEMORY_ACCESS.compareAndExchange$RawType$(bb.sessionImpl(),
253                                   bb.unsafeGetBase(),
254                                   offset(bb, base, handle.alignmentMask),
255                                   convEndian(handle.be, expected), convEndian(handle.be, value)));
256     }
257 
258     @ForceInline
259     static $type$ compareAndExchangeAcquire(VarHandle ob, Object obb, long base, $type$ expected, $type$ value) {
260         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
261         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
262         return convEndian(handle.be,
263                           SCOPED_MEMORY_ACCESS.compareAndExchange$RawType$Acquire(bb.sessionImpl(),
264                                   bb.unsafeGetBase(),
265                                   offset(bb, base, handle.alignmentMask),
266                                   convEndian(handle.be, expected), convEndian(handle.be, value)));
267     }
268 
269     @ForceInline
270     static $type$ compareAndExchangeRelease(VarHandle ob, Object obb, long base, $type$ expected, $type$ value) {
271         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
272         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
273         return convEndian(handle.be,
274                           SCOPED_MEMORY_ACCESS.compareAndExchange$RawType$Release(bb.sessionImpl(),
275                                   bb.unsafeGetBase(),
276                                   offset(bb, base, handle.alignmentMask),
277                                   convEndian(handle.be, expected), convEndian(handle.be, value)));
278     }
279 
280     @ForceInline
281     static boolean weakCompareAndSetPlain(VarHandle ob, Object obb, long base, $type$ expected, $type$ value) {
282         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
283         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
284         return SCOPED_MEMORY_ACCESS.weakCompareAndSet$RawType$Plain(bb.sessionImpl(),
285                 bb.unsafeGetBase(),
286                 offset(bb, base, handle.alignmentMask),
287                 convEndian(handle.be, expected), convEndian(handle.be, value));
288     }
289 
290     @ForceInline
291     static boolean weakCompareAndSet(VarHandle ob, Object obb, long base, $type$ expected, $type$ value) {
292         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
293         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
294         return SCOPED_MEMORY_ACCESS.weakCompareAndSet$RawType$(bb.sessionImpl(),
295                 bb.unsafeGetBase(),
296                 offset(bb, base, handle.alignmentMask),
297                 convEndian(handle.be, expected), convEndian(handle.be, value));
298     }
299 
300     @ForceInline
301     static boolean weakCompareAndSetAcquire(VarHandle ob, Object obb, long base, $type$ expected, $type$ value) {
302         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
303         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
304         return SCOPED_MEMORY_ACCESS.weakCompareAndSet$RawType$Acquire(bb.sessionImpl(),
305                 bb.unsafeGetBase(),
306                 offset(bb, base, handle.alignmentMask),
307                 convEndian(handle.be, expected), convEndian(handle.be, value));
308     }
309 
310     @ForceInline
311     static boolean weakCompareAndSetRelease(VarHandle ob, Object obb, long base, $type$ expected, $type$ value) {
312         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
313         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
314         return SCOPED_MEMORY_ACCESS.weakCompareAndSet$RawType$Release(bb.sessionImpl(),
315                 bb.unsafeGetBase(),
316                 offset(bb, base, handle.alignmentMask),
317                 convEndian(handle.be, expected), convEndian(handle.be, value));
318     }
319 
320     @ForceInline
321     static $type$ getAndSet(VarHandle ob, Object obb, long base, $type$ value) {
322         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
323         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
324         return convEndian(handle.be,
325                           SCOPED_MEMORY_ACCESS.getAndSet$RawType$(bb.sessionImpl(),
326                                   bb.unsafeGetBase(),
327                                   offset(bb, base, handle.alignmentMask),
328                                   convEndian(handle.be, value)));
329     }
330 
331     @ForceInline
332     static $type$ getAndSetAcquire(VarHandle ob, Object obb, long base, $type$ value) {
333         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
334         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
335         return convEndian(handle.be,
336                           SCOPED_MEMORY_ACCESS.getAndSet$RawType$Acquire(bb.sessionImpl(),
337                                   bb.unsafeGetBase(),
338                                   offset(bb, base, handle.alignmentMask),
339                                   convEndian(handle.be, value)));
340     }
341 
342     @ForceInline
343     static $type$ getAndSetRelease(VarHandle ob, Object obb, long base, $type$ value) {
344         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
345         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
346         return convEndian(handle.be,
347                           SCOPED_MEMORY_ACCESS.getAndSet$RawType$Release(bb.sessionImpl(),
348                                   bb.unsafeGetBase(),
349                                   offset(bb, base, handle.alignmentMask),
350                                   convEndian(handle.be, value)));
351     }
352 #end[CAS]
353 #if[AtomicAdd]
354 
355     @ForceInline
356     static $type$ getAndAdd(VarHandle ob, Object obb, long base, $type$ delta) {
357         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
358         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
359         if (handle.be == BE) {
360             return SCOPED_MEMORY_ACCESS.getAndAdd$RawType$(bb.sessionImpl(),
361                     bb.unsafeGetBase(),
362                     offset(bb, base, handle.alignmentMask),
363                     delta);
364         } else {
365             return getAndAddConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), delta);
366         }
367     }
368 
369     @ForceInline
370     static $type$ getAndAddAcquire(VarHandle ob, Object obb, long base, $type$ delta) {
371         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
372         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
373         if (handle.be == BE) {
374             return SCOPED_MEMORY_ACCESS.getAndAdd$RawType$Acquire(bb.sessionImpl(),
375                     bb.unsafeGetBase(),
376                     offset(bb, base, handle.alignmentMask),
377                     delta);
378         } else {
379             return getAndAddConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), delta);
380         }
381     }
382 
383     @ForceInline
384     static $type$ getAndAddRelease(VarHandle ob, Object obb, long base, $type$ delta) {
385         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
386         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
387         if (handle.be == BE) {
388             return SCOPED_MEMORY_ACCESS.getAndAdd$RawType$Release(bb.sessionImpl(),
389                     bb.unsafeGetBase(),
390                     offset(bb, base, handle.alignmentMask),
391                     delta);
392         } else {
393             return getAndAddConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), delta);
394         }
395     }
396 
397     @ForceInline
398     static $type$ getAndAddConvEndianWithCAS(AbstractMemorySegmentImpl  bb, long offset, $type$ delta) {
399         $type$ nativeExpectedValue, expectedValue;
400         Object base = bb.unsafeGetBase();
401         do {
402             nativeExpectedValue = SCOPED_MEMORY_ACCESS.get$RawType$Volatile(bb.sessionImpl(),base, offset);
403             expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue);
404         } while (!SCOPED_MEMORY_ACCESS.weakCompareAndSet$RawType$(bb.sessionImpl(),base, offset,
405                 nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue + delta)));
406         return expectedValue;
407     }
408 #end[AtomicAdd]
409 #if[Bitwise]
410 
411     @ForceInline
412     static $type$ getAndBitwiseOr(VarHandle ob, Object obb, long base, $type$ value) {
413         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
414         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
415         if (handle.be == BE) {
416             return SCOPED_MEMORY_ACCESS.getAndBitwiseOr$RawType$(bb.sessionImpl(),
417                     bb.unsafeGetBase(),
418                     offset(bb, base, handle.alignmentMask),
419                     value);
420         } else {
421             return getAndBitwiseOrConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), value);
422         }
423     }
424 
425     @ForceInline
426     static $type$ getAndBitwiseOrRelease(VarHandle ob, Object obb, long base, $type$ value) {
427         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
428         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
429         if (handle.be == BE) {
430             return SCOPED_MEMORY_ACCESS.getAndBitwiseOr$RawType$Release(bb.sessionImpl(),
431                     bb.unsafeGetBase(),
432                     offset(bb, base, handle.alignmentMask),
433                     value);
434         } else {
435             return getAndBitwiseOrConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), value);
436         }
437     }
438 
439     @ForceInline
440     static $type$ getAndBitwiseOrAcquire(VarHandle ob, Object obb, long base, $type$ value) {
441         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
442         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
443         if (handle.be == BE) {
444             return SCOPED_MEMORY_ACCESS.getAndBitwiseOr$RawType$Acquire(bb.sessionImpl(),
445                     bb.unsafeGetBase(),
446                     offset(bb, base, handle.alignmentMask),
447                     value);
448         } else {
449             return getAndBitwiseOrConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), value);
450         }
451     }
452 
453     @ForceInline
454     static $type$ getAndBitwiseOrConvEndianWithCAS(AbstractMemorySegmentImpl  bb, long offset, $type$ value) {
455         $type$ nativeExpectedValue, expectedValue;
456         Object base = bb.unsafeGetBase();
457         do {
458             nativeExpectedValue = SCOPED_MEMORY_ACCESS.get$RawType$Volatile(bb.sessionImpl(),base, offset);
459             expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue);
460         } while (!SCOPED_MEMORY_ACCESS.weakCompareAndSet$RawType$(bb.sessionImpl(),base, offset,
461                 nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue | value)));
462         return expectedValue;
463     }
464 
465     @ForceInline
466     static $type$ getAndBitwiseAnd(VarHandle ob, Object obb, long base, $type$ value) {
467         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
468         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
469         if (handle.be == BE) {
470             return SCOPED_MEMORY_ACCESS.getAndBitwiseAnd$RawType$(bb.sessionImpl(),
471                     bb.unsafeGetBase(),
472                     offset(bb, base, handle.alignmentMask),
473                     value);
474         } else {
475             return getAndBitwiseAndConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), value);
476         }
477     }
478 
479     @ForceInline
480     static $type$ getAndBitwiseAndRelease(VarHandle ob, Object obb, long base, $type$ value) {
481         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
482         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
483         if (handle.be == BE) {
484             return SCOPED_MEMORY_ACCESS.getAndBitwiseAnd$RawType$Release(bb.sessionImpl(),
485                     bb.unsafeGetBase(),
486                     offset(bb, base, handle.alignmentMask),
487                     value);
488         } else {
489             return getAndBitwiseAndConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), value);
490         }
491     }
492 
493     @ForceInline
494     static $type$ getAndBitwiseAndAcquire(VarHandle ob, Object obb, long base, $type$ value) {
495         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
496         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
497         if (handle.be == BE) {
498             return SCOPED_MEMORY_ACCESS.getAndBitwiseAnd$RawType$Acquire(bb.sessionImpl(),
499                     bb.unsafeGetBase(),
500                     offset(bb, base, handle.alignmentMask),
501                     value);
502         } else {
503             return getAndBitwiseAndConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), value);
504         }
505     }
506 
507     @ForceInline
508     static $type$ getAndBitwiseAndConvEndianWithCAS(AbstractMemorySegmentImpl  bb, long offset, $type$ value) {
509         $type$ nativeExpectedValue, expectedValue;
510         Object base = bb.unsafeGetBase();
511         do {
512             nativeExpectedValue = SCOPED_MEMORY_ACCESS.get$RawType$Volatile(bb.sessionImpl(),base, offset);
513             expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue);
514         } while (!SCOPED_MEMORY_ACCESS.weakCompareAndSet$RawType$(bb.sessionImpl(),base, offset,
515                 nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue & value)));
516         return expectedValue;
517     }
518 
519 
520     @ForceInline
521     static $type$ getAndBitwiseXor(VarHandle ob, Object obb, long base, $type$ value) {
522         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
523         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
524         if (handle.be == BE) {
525             return SCOPED_MEMORY_ACCESS.getAndBitwiseXor$RawType$(bb.sessionImpl(),
526                     bb.unsafeGetBase(),
527                     offset(bb, base, handle.alignmentMask),
528                     value);
529         } else {
530             return getAndBitwiseXorConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), value);
531         }
532     }
533 
534     @ForceInline
535     static $type$ getAndBitwiseXorRelease(VarHandle ob, Object obb, long base, $type$ value) {
536         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
537         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
538         if (handle.be == BE) {
539             return SCOPED_MEMORY_ACCESS.getAndBitwiseXor$RawType$Release(bb.sessionImpl(),
540                     bb.unsafeGetBase(),
541                     offset(bb, base, handle.alignmentMask),
542                     value);
543         } else {
544             return getAndBitwiseXorConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), value);
545         }
546     }
547 
548     @ForceInline
549     static $type$ getAndBitwiseXorAcquire(VarHandle ob, Object obb, long base, $type$ value) {
550         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
551         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
552         if (handle.be == BE) {
553             return SCOPED_MEMORY_ACCESS.getAndBitwiseXor$RawType$Acquire(bb.sessionImpl(),
554                     bb.unsafeGetBase(),
555                     offset(bb, base, handle.alignmentMask),
556                     value);
557         } else {
558             return getAndBitwiseXorConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), value);
559         }
560     }
561 
562     @ForceInline
563     static $type$ getAndBitwiseXorConvEndianWithCAS(AbstractMemorySegmentImpl  bb, long offset, $type$ value) {
564         $type$ nativeExpectedValue, expectedValue;
565         Object base = bb.unsafeGetBase();
566         do {
567             nativeExpectedValue = SCOPED_MEMORY_ACCESS.get$RawType$Volatile(bb.sessionImpl(),base, offset);
568             expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue);
569         } while (!SCOPED_MEMORY_ACCESS.weakCompareAndSet$RawType$(bb.sessionImpl(),base, offset,
570                 nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue ^ value)));
571         return expectedValue;
572     }
573 #end[Bitwise]
574 }

 26 
 27 import jdk.internal.foreign.AbstractMemorySegmentImpl;
 28 import jdk.internal.misc.ScopedMemoryAccess;
 29 import jdk.internal.vm.annotation.ForceInline;
 30 
 31 import java.lang.foreign.MemorySegment;
 32 import java.lang.ref.Reference;
 33 
 34 import java.util.Objects;
 35 
 36 import static java.lang.invoke.MethodHandleStatics.UNSAFE;
 37 
 38 #warn
 39 
 40 final class VarHandleSegmentAs$Type$s extends VarHandleSegmentViewBase {
 41 
 42     static final boolean BE = UNSAFE.isBigEndian();
 43 
 44     static final ScopedMemoryAccess SCOPED_MEMORY_ACCESS = ScopedMemoryAccess.getScopedMemoryAccess();
 45 
 46     static final int NON_PLAIN_ACCESS_MIN_ALIGN_MASK = $BoxType$.BYTES - 1;
 47 
 48     static final VarForm FORM = new VarForm(VarHandleSegmentAs$Type$s.class, MemorySegment.class, $type$.class, long.class);
 49 
 50     VarHandleSegmentAs$Type$s(boolean be, long length, long alignmentMask, boolean exact) {
 51         super(FORM, be, length, alignmentMask, exact);
 52     }
 53 
 54     @Override
 55     final MethodType accessModeTypeUncached(VarHandle.AccessType accessType) {
 56         return accessType.accessModeType(MemorySegment.class, $type$.class, long.class);
 57     }
 58 
 59     @Override
 60     public VarHandleSegmentAs$Type$s withInvokeExactBehavior() {
 61         return hasInvokeExactBehavior() ?
 62                 this :
 63                 new VarHandleSegmentAs$Type$s(be, length, alignmentMask, true);
 64     }
 65 
 66     @Override

 87     @ForceInline
 88     static $type$ convEndian(boolean big, $type$ n) {
 89         return n;
 90     }
 91 #else[byte]
 92     @ForceInline
 93     static $type$ convEndian(boolean big, $type$ n) {
 94         return big == BE ? n : $BoxType$.reverseBytes(n);
 95     }
 96 #end[byte]
 97 #end[floatingPoint]
 98 
 99     @ForceInline
100     static AbstractMemorySegmentImpl checkAddress(Object obb, long offset, long length, boolean ro) {
101         AbstractMemorySegmentImpl oo = (AbstractMemorySegmentImpl)Objects.requireNonNull(obb);
102         oo.checkAccess(offset, length, ro);
103         return oo;
104     }
105 
106     @ForceInline
107     static long offsetNonPlain(AbstractMemorySegmentImpl bb, long offset, long alignmentMask) {
108         if ((alignmentMask & NON_PLAIN_ACCESS_MIN_ALIGN_MASK) != NON_PLAIN_ACCESS_MIN_ALIGN_MASK) {
109             throw VarHandleSegmentViewBase.newUnsupportedAccessModeForAlignment(alignmentMask + 1);

110         }
111         return offsetPlain(bb, offset, alignmentMask);
112     }
113 
114     @ForceInline
115     static long offsetPlain(AbstractMemorySegmentImpl bb, long offset, long alignmentMask) {
116         long base = bb.unsafeGetOffset();
117         long address = base + offset;
118         long maxAlignMask = bb.maxAlignMask();
119         if (((address | maxAlignMask) & alignmentMask) != 0) {
120             throw VarHandleSegmentViewBase.newIllegalArgumentExceptionForMisalignedAccess(address);
121         }
122         return address;
123     }
124 
125     @ForceInline
126     static $type$ get(VarHandle ob, Object obb, long base) {
127         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
128         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, true);
129 #if[floatingPoint]
130         $rawType$ rawValue = SCOPED_MEMORY_ACCESS.get$RawType$Unaligned(bb.sessionImpl(),
131                 bb.unsafeGetBase(),
132                 offsetPlain(bb, base, handle.alignmentMask),
133                 handle.be);
134         return $Type$.$rawType$BitsTo$Type$(rawValue);
135 #else[floatingPoint]
136 #if[byte]
137         return SCOPED_MEMORY_ACCESS.get$Type$(bb.sessionImpl(),
138                 bb.unsafeGetBase(),
139                 offsetPlain(bb, base, handle.alignmentMask));
140 #else[byte]
141         return SCOPED_MEMORY_ACCESS.get$Type$Unaligned(bb.sessionImpl(),
142                 bb.unsafeGetBase(),
143                 offsetPlain(bb, base, handle.alignmentMask),
144                 handle.be);
145 #end[byte]
146 #end[floatingPoint]
147     }
148 
149     @ForceInline
150     static void set(VarHandle ob, Object obb, long base, $type$ value) {
151         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
152         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
153 #if[floatingPoint]
154         SCOPED_MEMORY_ACCESS.put$RawType$Unaligned(bb.sessionImpl(),
155                 bb.unsafeGetBase(),
156                 offsetPlain(bb, base, handle.alignmentMask),
157                 $Type$.$type$ToRaw$RawType$Bits(value),
158                 handle.be);
159 #else[floatingPoint]
160 #if[byte]
161         SCOPED_MEMORY_ACCESS.put$Type$(bb.sessionImpl(),
162                 bb.unsafeGetBase(),
163                 offsetPlain(bb, base, handle.alignmentMask),
164                 value);
165 #else[byte]
166         SCOPED_MEMORY_ACCESS.put$Type$Unaligned(bb.sessionImpl(),
167                 bb.unsafeGetBase(),
168                 offsetPlain(bb, base, handle.alignmentMask),
169                 value,
170                 handle.be);
171 #end[byte]
172 #end[floatingPoint]
173     }
174 
175     @ForceInline
176     static $type$ getVolatile(VarHandle ob, Object obb, long base) {
177         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
178         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, true);
179         return convEndian(handle.be,
180                           SCOPED_MEMORY_ACCESS.get$RawType$Volatile(bb.sessionImpl(),
181                                   bb.unsafeGetBase(),
182                                   offsetNonPlain(bb, base, handle.alignmentMask)));
183     }
184 
185     @ForceInline
186     static void setVolatile(VarHandle ob, Object obb, long base, $type$ value) {
187         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
188         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
189         SCOPED_MEMORY_ACCESS.put$RawType$Volatile(bb.sessionImpl(),
190                 bb.unsafeGetBase(),
191                 offsetNonPlain(bb, base, handle.alignmentMask),
192                 convEndian(handle.be, value));
193     }
194 
195     @ForceInline
196     static $type$ getAcquire(VarHandle ob, Object obb, long base) {
197         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
198         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, true);
199         return convEndian(handle.be,
200                           SCOPED_MEMORY_ACCESS.get$RawType$Acquire(bb.sessionImpl(),
201                                   bb.unsafeGetBase(),
202                                   offsetNonPlain(bb, base, handle.alignmentMask)));
203     }
204 
205     @ForceInline
206     static void setRelease(VarHandle ob, Object obb, long base, $type$ value) {
207         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
208         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
209         SCOPED_MEMORY_ACCESS.put$RawType$Release(bb.sessionImpl(),
210                 bb.unsafeGetBase(),
211                 offsetNonPlain(bb, base, handle.alignmentMask),
212                 convEndian(handle.be, value));
213     }
214 
215     @ForceInline
216     static $type$ getOpaque(VarHandle ob, Object obb, long base) {
217         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
218         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, true);
219         return convEndian(handle.be,
220                           SCOPED_MEMORY_ACCESS.get$RawType$Opaque(bb.sessionImpl(),
221                                   bb.unsafeGetBase(),
222                                   offsetNonPlain(bb, base, handle.alignmentMask)));
223     }
224 
225     @ForceInline
226     static void setOpaque(VarHandle ob, Object obb, long base, $type$ value) {
227         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
228         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
229         SCOPED_MEMORY_ACCESS.put$RawType$Opaque(bb.sessionImpl(),
230                 bb.unsafeGetBase(),
231                 offsetNonPlain(bb, base, handle.alignmentMask),
232                 convEndian(handle.be, value));
233     }
234 #if[CAS]
235 
236     @ForceInline
237     static boolean compareAndSet(VarHandle ob, Object obb, long base, $type$ expected, $type$ value) {
238         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
239         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
240         return SCOPED_MEMORY_ACCESS.compareAndSet$RawType$(bb.sessionImpl(),
241                 bb.unsafeGetBase(),
242                 offsetNonPlain(bb, base, handle.alignmentMask),
243                 convEndian(handle.be, expected), convEndian(handle.be, value));
244     }
245 
246     @ForceInline
247     static $type$ compareAndExchange(VarHandle ob, Object obb, long base, $type$ expected, $type$ value) {
248         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
249         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
250         return convEndian(handle.be,
251                           SCOPED_MEMORY_ACCESS.compareAndExchange$RawType$(bb.sessionImpl(),
252                                   bb.unsafeGetBase(),
253                                   offsetNonPlain(bb, base, handle.alignmentMask),
254                                   convEndian(handle.be, expected), convEndian(handle.be, value)));
255     }
256 
257     @ForceInline
258     static $type$ compareAndExchangeAcquire(VarHandle ob, Object obb, long base, $type$ expected, $type$ value) {
259         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
260         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
261         return convEndian(handle.be,
262                           SCOPED_MEMORY_ACCESS.compareAndExchange$RawType$Acquire(bb.sessionImpl(),
263                                   bb.unsafeGetBase(),
264                                   offsetNonPlain(bb, base, handle.alignmentMask),
265                                   convEndian(handle.be, expected), convEndian(handle.be, value)));
266     }
267 
268     @ForceInline
269     static $type$ compareAndExchangeRelease(VarHandle ob, Object obb, long base, $type$ expected, $type$ value) {
270         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
271         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
272         return convEndian(handle.be,
273                           SCOPED_MEMORY_ACCESS.compareAndExchange$RawType$Release(bb.sessionImpl(),
274                                   bb.unsafeGetBase(),
275                                   offsetNonPlain(bb, base, handle.alignmentMask),
276                                   convEndian(handle.be, expected), convEndian(handle.be, value)));
277     }
278 
279     @ForceInline
280     static boolean weakCompareAndSetPlain(VarHandle ob, Object obb, long base, $type$ expected, $type$ value) {
281         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
282         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
283         return SCOPED_MEMORY_ACCESS.weakCompareAndSet$RawType$Plain(bb.sessionImpl(),
284                 bb.unsafeGetBase(),
285                 offsetNonPlain(bb, base, handle.alignmentMask),
286                 convEndian(handle.be, expected), convEndian(handle.be, value));
287     }
288 
289     @ForceInline
290     static boolean weakCompareAndSet(VarHandle ob, Object obb, long base, $type$ expected, $type$ value) {
291         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
292         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
293         return SCOPED_MEMORY_ACCESS.weakCompareAndSet$RawType$(bb.sessionImpl(),
294                 bb.unsafeGetBase(),
295                 offsetNonPlain(bb, base, handle.alignmentMask),
296                 convEndian(handle.be, expected), convEndian(handle.be, value));
297     }
298 
299     @ForceInline
300     static boolean weakCompareAndSetAcquire(VarHandle ob, Object obb, long base, $type$ expected, $type$ value) {
301         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
302         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
303         return SCOPED_MEMORY_ACCESS.weakCompareAndSet$RawType$Acquire(bb.sessionImpl(),
304                 bb.unsafeGetBase(),
305                 offsetNonPlain(bb, base, handle.alignmentMask),
306                 convEndian(handle.be, expected), convEndian(handle.be, value));
307     }
308 
309     @ForceInline
310     static boolean weakCompareAndSetRelease(VarHandle ob, Object obb, long base, $type$ expected, $type$ value) {
311         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
312         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
313         return SCOPED_MEMORY_ACCESS.weakCompareAndSet$RawType$Release(bb.sessionImpl(),
314                 bb.unsafeGetBase(),
315                 offsetNonPlain(bb, base, handle.alignmentMask),
316                 convEndian(handle.be, expected), convEndian(handle.be, value));
317     }
318 
319     @ForceInline
320     static $type$ getAndSet(VarHandle ob, Object obb, long base, $type$ value) {
321         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
322         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
323         return convEndian(handle.be,
324                           SCOPED_MEMORY_ACCESS.getAndSet$RawType$(bb.sessionImpl(),
325                                   bb.unsafeGetBase(),
326                                   offsetNonPlain(bb, base, handle.alignmentMask),
327                                   convEndian(handle.be, value)));
328     }
329 
330     @ForceInline
331     static $type$ getAndSetAcquire(VarHandle ob, Object obb, long base, $type$ value) {
332         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
333         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
334         return convEndian(handle.be,
335                           SCOPED_MEMORY_ACCESS.getAndSet$RawType$Acquire(bb.sessionImpl(),
336                                   bb.unsafeGetBase(),
337                                   offsetNonPlain(bb, base, handle.alignmentMask),
338                                   convEndian(handle.be, value)));
339     }
340 
341     @ForceInline
342     static $type$ getAndSetRelease(VarHandle ob, Object obb, long base, $type$ value) {
343         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
344         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
345         return convEndian(handle.be,
346                           SCOPED_MEMORY_ACCESS.getAndSet$RawType$Release(bb.sessionImpl(),
347                                   bb.unsafeGetBase(),
348                                   offsetNonPlain(bb, base, handle.alignmentMask),
349                                   convEndian(handle.be, value)));
350     }
351 #end[CAS]
352 #if[AtomicAdd]
353 
354     @ForceInline
355     static $type$ getAndAdd(VarHandle ob, Object obb, long base, $type$ delta) {
356         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
357         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
358         if (handle.be == BE) {
359             return SCOPED_MEMORY_ACCESS.getAndAdd$RawType$(bb.sessionImpl(),
360                     bb.unsafeGetBase(),
361                     offsetNonPlain(bb, base, handle.alignmentMask),
362                     delta);
363         } else {
364             return getAndAddConvEndianWithCAS(bb, offsetNonPlain(bb, base, handle.alignmentMask), delta);
365         }
366     }
367 
368     @ForceInline
369     static $type$ getAndAddAcquire(VarHandle ob, Object obb, long base, $type$ delta) {
370         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
371         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
372         if (handle.be == BE) {
373             return SCOPED_MEMORY_ACCESS.getAndAdd$RawType$Acquire(bb.sessionImpl(),
374                     bb.unsafeGetBase(),
375                     offsetNonPlain(bb, base, handle.alignmentMask),
376                     delta);
377         } else {
378             return getAndAddConvEndianWithCAS(bb, offsetNonPlain(bb, base, handle.alignmentMask), delta);
379         }
380     }
381 
382     @ForceInline
383     static $type$ getAndAddRelease(VarHandle ob, Object obb, long base, $type$ delta) {
384         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
385         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
386         if (handle.be == BE) {
387             return SCOPED_MEMORY_ACCESS.getAndAdd$RawType$Release(bb.sessionImpl(),
388                     bb.unsafeGetBase(),
389                     offsetNonPlain(bb, base, handle.alignmentMask),
390                     delta);
391         } else {
392             return getAndAddConvEndianWithCAS(bb, offsetNonPlain(bb, base, handle.alignmentMask), delta);
393         }
394     }
395 
396     @ForceInline
397     static $type$ getAndAddConvEndianWithCAS(AbstractMemorySegmentImpl  bb, long offset, $type$ delta) {
398         $type$ nativeExpectedValue, expectedValue;
399         Object base = bb.unsafeGetBase();
400         do {
401             nativeExpectedValue = SCOPED_MEMORY_ACCESS.get$RawType$Volatile(bb.sessionImpl(),base, offset);
402             expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue);
403         } while (!SCOPED_MEMORY_ACCESS.weakCompareAndSet$RawType$(bb.sessionImpl(),base, offset,
404                 nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue + delta)));
405         return expectedValue;
406     }
407 #end[AtomicAdd]
408 #if[Bitwise]
409 
410     @ForceInline
411     static $type$ getAndBitwiseOr(VarHandle ob, Object obb, long base, $type$ value) {
412         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
413         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
414         if (handle.be == BE) {
415             return SCOPED_MEMORY_ACCESS.getAndBitwiseOr$RawType$(bb.sessionImpl(),
416                     bb.unsafeGetBase(),
417                     offsetNonPlain(bb, base, handle.alignmentMask),
418                     value);
419         } else {
420             return getAndBitwiseOrConvEndianWithCAS(bb, offsetNonPlain(bb, base, handle.alignmentMask), value);
421         }
422     }
423 
424     @ForceInline
425     static $type$ getAndBitwiseOrRelease(VarHandle ob, Object obb, long base, $type$ value) {
426         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
427         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
428         if (handle.be == BE) {
429             return SCOPED_MEMORY_ACCESS.getAndBitwiseOr$RawType$Release(bb.sessionImpl(),
430                     bb.unsafeGetBase(),
431                     offsetNonPlain(bb, base, handle.alignmentMask),
432                     value);
433         } else {
434             return getAndBitwiseOrConvEndianWithCAS(bb, offsetNonPlain(bb, base, handle.alignmentMask), value);
435         }
436     }
437 
438     @ForceInline
439     static $type$ getAndBitwiseOrAcquire(VarHandle ob, Object obb, long base, $type$ value) {
440         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
441         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
442         if (handle.be == BE) {
443             return SCOPED_MEMORY_ACCESS.getAndBitwiseOr$RawType$Acquire(bb.sessionImpl(),
444                     bb.unsafeGetBase(),
445                     offsetNonPlain(bb, base, handle.alignmentMask),
446                     value);
447         } else {
448             return getAndBitwiseOrConvEndianWithCAS(bb, offsetNonPlain(bb, base, handle.alignmentMask), value);
449         }
450     }
451 
452     @ForceInline
453     static $type$ getAndBitwiseOrConvEndianWithCAS(AbstractMemorySegmentImpl  bb, long offset, $type$ value) {
454         $type$ nativeExpectedValue, expectedValue;
455         Object base = bb.unsafeGetBase();
456         do {
457             nativeExpectedValue = SCOPED_MEMORY_ACCESS.get$RawType$Volatile(bb.sessionImpl(),base, offset);
458             expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue);
459         } while (!SCOPED_MEMORY_ACCESS.weakCompareAndSet$RawType$(bb.sessionImpl(),base, offset,
460                 nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue | value)));
461         return expectedValue;
462     }
463 
464     @ForceInline
465     static $type$ getAndBitwiseAnd(VarHandle ob, Object obb, long base, $type$ value) {
466         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
467         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
468         if (handle.be == BE) {
469             return SCOPED_MEMORY_ACCESS.getAndBitwiseAnd$RawType$(bb.sessionImpl(),
470                     bb.unsafeGetBase(),
471                     offsetNonPlain(bb, base, handle.alignmentMask),
472                     value);
473         } else {
474             return getAndBitwiseAndConvEndianWithCAS(bb, offsetNonPlain(bb, base, handle.alignmentMask), value);
475         }
476     }
477 
478     @ForceInline
479     static $type$ getAndBitwiseAndRelease(VarHandle ob, Object obb, long base, $type$ value) {
480         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
481         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
482         if (handle.be == BE) {
483             return SCOPED_MEMORY_ACCESS.getAndBitwiseAnd$RawType$Release(bb.sessionImpl(),
484                     bb.unsafeGetBase(),
485                     offsetNonPlain(bb, base, handle.alignmentMask),
486                     value);
487         } else {
488             return getAndBitwiseAndConvEndianWithCAS(bb, offsetNonPlain(bb, base, handle.alignmentMask), value);
489         }
490     }
491 
492     @ForceInline
493     static $type$ getAndBitwiseAndAcquire(VarHandle ob, Object obb, long base, $type$ value) {
494         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
495         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
496         if (handle.be == BE) {
497             return SCOPED_MEMORY_ACCESS.getAndBitwiseAnd$RawType$Acquire(bb.sessionImpl(),
498                     bb.unsafeGetBase(),
499                     offsetNonPlain(bb, base, handle.alignmentMask),
500                     value);
501         } else {
502             return getAndBitwiseAndConvEndianWithCAS(bb, offsetNonPlain(bb, base, handle.alignmentMask), value);
503         }
504     }
505 
506     @ForceInline
507     static $type$ getAndBitwiseAndConvEndianWithCAS(AbstractMemorySegmentImpl  bb, long offset, $type$ value) {
508         $type$ nativeExpectedValue, expectedValue;
509         Object base = bb.unsafeGetBase();
510         do {
511             nativeExpectedValue = SCOPED_MEMORY_ACCESS.get$RawType$Volatile(bb.sessionImpl(),base, offset);
512             expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue);
513         } while (!SCOPED_MEMORY_ACCESS.weakCompareAndSet$RawType$(bb.sessionImpl(),base, offset,
514                 nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue & value)));
515         return expectedValue;
516     }
517 
518 
519     @ForceInline
520     static $type$ getAndBitwiseXor(VarHandle ob, Object obb, long base, $type$ value) {
521         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
522         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
523         if (handle.be == BE) {
524             return SCOPED_MEMORY_ACCESS.getAndBitwiseXor$RawType$(bb.sessionImpl(),
525                     bb.unsafeGetBase(),
526                     offsetNonPlain(bb, base, handle.alignmentMask),
527                     value);
528         } else {
529             return getAndBitwiseXorConvEndianWithCAS(bb, offsetNonPlain(bb, base, handle.alignmentMask), value);
530         }
531     }
532 
533     @ForceInline
534     static $type$ getAndBitwiseXorRelease(VarHandle ob, Object obb, long base, $type$ value) {
535         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
536         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
537         if (handle.be == BE) {
538             return SCOPED_MEMORY_ACCESS.getAndBitwiseXor$RawType$Release(bb.sessionImpl(),
539                     bb.unsafeGetBase(),
540                     offsetNonPlain(bb, base, handle.alignmentMask),
541                     value);
542         } else {
543             return getAndBitwiseXorConvEndianWithCAS(bb, offsetNonPlain(bb, base, handle.alignmentMask), value);
544         }
545     }
546 
547     @ForceInline
548     static $type$ getAndBitwiseXorAcquire(VarHandle ob, Object obb, long base, $type$ value) {
549         VarHandleSegmentViewBase handle = (VarHandleSegmentViewBase)ob;
550         AbstractMemorySegmentImpl bb = checkAddress(obb, base, handle.length, false);
551         if (handle.be == BE) {
552             return SCOPED_MEMORY_ACCESS.getAndBitwiseXor$RawType$Acquire(bb.sessionImpl(),
553                     bb.unsafeGetBase(),
554                     offsetNonPlain(bb, base, handle.alignmentMask),
555                     value);
556         } else {
557             return getAndBitwiseXorConvEndianWithCAS(bb, offsetNonPlain(bb, base, handle.alignmentMask), value);
558         }
559     }
560 
561     @ForceInline
562     static $type$ getAndBitwiseXorConvEndianWithCAS(AbstractMemorySegmentImpl  bb, long offset, $type$ value) {
563         $type$ nativeExpectedValue, expectedValue;
564         Object base = bb.unsafeGetBase();
565         do {
566             nativeExpectedValue = SCOPED_MEMORY_ACCESS.get$RawType$Volatile(bb.sessionImpl(),base, offset);
567             expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue);
568         } while (!SCOPED_MEMORY_ACCESS.weakCompareAndSet$RawType$(bb.sessionImpl(),base, offset,
569                 nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue ^ value)));
570         return expectedValue;
571     }
572 #end[Bitwise]
573 }
< prev index next >