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 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 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 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 }