1 /* 2 * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package java.lang.invoke; 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 67 public VarHandleSegmentAs$Type$s withInvokeBehavior() { 68 return !hasInvokeExactBehavior() ? 69 this : 70 new VarHandleSegmentAs$Type$s(be, length, alignmentMask, false); 71 } 72 73 #if[floatingPoint] 74 @ForceInline 75 static $rawType$ convEndian(boolean big, $type$ v) { 76 $rawType$ rv = $Type$.$type$ToRaw$RawType$Bits(v); 77 return big == BE ? rv : $RawBoxType$.reverseBytes(rv); 78 } 79 80 @ForceInline 81 static $type$ convEndian(boolean big, $rawType$ rv) { 82 rv = big == BE ? rv : $RawBoxType$.reverseBytes(rv); 83 return $Type$.$rawType$BitsTo$Type$(rv); 84 } 85 #else[floatingPoint] 86 #if[byte] 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 }