441 * If the effective addresses and length are (resp.) even modulo 4 or 2,
442 * the transfer takes place in units of 'int' or 'short'.
443 *
444 * @since 1.7
445 */
446 @HotSpotIntrinsicCandidate
447 public native void copyMemory(Object srcBase, long srcOffset,
448 Object destBase, long destOffset,
449 long bytes);
450 /**
451 * Sets all bytes in a given block of memory to a copy of another
452 * block. This provides a <em>single-register</em> addressing mode,
453 * as discussed in {@link #getInt(Object,long)}.
454 *
455 * Equivalent to {@code copyMemory(null, srcAddress, null, destAddress, bytes)}.
456 */
457 public void copyMemory(long srcAddress, long destAddress, long bytes) {
458 copyMemory(null, srcAddress, null, destAddress, bytes);
459 }
460
461 /**
462 * Copies all elements from one block of memory to another block, byte swapping the
463 * elements on the fly.
464 *
465 * <p>This method determines each block's base address by means of two parameters,
466 * and so it provides (in effect) a <em>double-register</em> addressing mode,
467 * as discussed in {@link #getInt(Object,long)}. When the object reference is null,
468 * the offset supplies an absolute base address.
469 *
470 * @since 9
471 */
472 public native void copySwapMemory(Object srcBase, long srcOffset,
473 Object destBase, long destOffset,
474 long bytes, long elemSize);
475
476 /**
477 * Copies all elements from one block of memory to another block, byte swapping the
478 * elements on the fly.
479 *
480 * This provides a <em>single-register</em> addressing mode, as
481 * discussed in {@link #getInt(Object,long)}.
482 *
483 * Equivalent to {@code copySwapMemory(null, srcAddress, null, destAddress, bytes, elemSize)}.
484 */
485 public void copySwapMemory(long srcAddress, long destAddress, long bytes, long elemSize) {
486 copySwapMemory(null, srcAddress, null, destAddress, bytes, elemSize);
487 }
488
489 /**
490 * Disposes of a block of native memory, as obtained from {@link
491 * #allocateMemory} or {@link #reallocateMemory}. The address passed to
492 * this method may be null, in which case no action is taken.
493 *
494 * @see #allocateMemory
|
441 * If the effective addresses and length are (resp.) even modulo 4 or 2,
442 * the transfer takes place in units of 'int' or 'short'.
443 *
444 * @since 1.7
445 */
446 @HotSpotIntrinsicCandidate
447 public native void copyMemory(Object srcBase, long srcOffset,
448 Object destBase, long destOffset,
449 long bytes);
450 /**
451 * Sets all bytes in a given block of memory to a copy of another
452 * block. This provides a <em>single-register</em> addressing mode,
453 * as discussed in {@link #getInt(Object,long)}.
454 *
455 * Equivalent to {@code copyMemory(null, srcAddress, null, destAddress, bytes)}.
456 */
457 public void copyMemory(long srcAddress, long destAddress, long bytes) {
458 copyMemory(null, srcAddress, null, destAddress, bytes);
459 }
460
461 private boolean isPrimitiveArray(Class<?> c) {
462 Class<?> componentType = c.getComponentType();
463 return componentType != null && componentType.isPrimitive();
464 }
465
466 private native void copySwapMemory0(Object srcBase, long srcOffset,
467 Object destBase, long destOffset,
468 long bytes, long elemSize);
469
470
471 /**
472 * Copies all elements from one block of memory to another block,
473 * *unconditionally* byte swapping the elements on the fly.
474 *
475 * <p>This method determines each block's base address by means of two parameters,
476 * and so it provides (in effect) a <em>double-register</em> addressing mode,
477 * as discussed in {@link #getInt(Object,long)}. When the object reference is null,
478 * the offset supplies an absolute base address.
479 *
480 * @since 9
481 */
482 public void copySwapMemory(Object srcBase, long srcOffset,
483 Object destBase, long destOffset,
484 long bytes, long elemSize) {
485 if (bytes < 0 || srcOffset < 0 || destOffset < 0) {
486 throw new IllegalArgumentException();
487 }
488 if (elemSize != 2 && elemSize != 4 && elemSize != 8) {
489 throw new IllegalArgumentException();
490 }
491 if (bytes % elemSize != 0) {
492 throw new IllegalArgumentException();
493 }
494 if ((srcBase == null && srcOffset == 0) ||
495 (destBase == null && destOffset == 0)) {
496 throw new NullPointerException();
497 }
498
499 // Must be off-heap, or primitive heap arrays
500 if ((srcBase != null && !isPrimitiveArray(srcBase.getClass())) ||
501 (destBase != null && !isPrimitiveArray(destBase.getClass()))) {
502 throw new IllegalArgumentException();
503 }
504
505 // Sanity check size and offsets on 32-bit platforms. Most
506 // significant 32 bits must be zero.
507 if (ADDRESS_SIZE == 4 &&
508 (bytes >>> 32 != 0 || srcOffset >>> 32 != 0 || destOffset >>> 32 != 0)) {
509 throw new IllegalArgumentException();
510 }
511
512 if (bytes == 0) {
513 return;
514 }
515
516 copySwapMemory0(srcBase, srcOffset, destBase, destOffset, bytes, elemSize);
517 }
518
519 /**
520 * Copies all elements from one block of memory to another block, byte swapping the
521 * elements on the fly.
522 *
523 * This provides a <em>single-register</em> addressing mode, as
524 * discussed in {@link #getInt(Object,long)}.
525 *
526 * Equivalent to {@code copySwapMemory(null, srcAddress, null, destAddress, bytes, elemSize)}.
527 */
528 public void copySwapMemory(long srcAddress, long destAddress, long bytes, long elemSize) {
529 copySwapMemory(null, srcAddress, null, destAddress, bytes, elemSize);
530 }
531
532 /**
533 * Disposes of a block of native memory, as obtained from {@link
534 * #allocateMemory} or {@link #reallocateMemory}. The address passed to
535 * this method may be null, in which case no action is taken.
536 *
537 * @see #allocateMemory
|