1 /*
2 * Copyright (c) 2000, 2015, 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
439 * by the address and length parameters. If the effective addresses and
440 * length are all even modulo 8, the transfer takes place in 'long' units.
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 * Disposes of a block of native memory, as obtained from {@link
463 * #allocateMemory} or {@link #reallocateMemory}. The address passed to
464 * this method may be null, in which case no action is taken.
465 *
466 * @see #allocateMemory
467 */
468 public native void freeMemory(long address);
469
470 /// random queries
471
472 /**
473 * This constant differs from all results that will ever be returned from
474 * {@link #staticFieldOffset}, {@link #objectFieldOffset},
475 * or {@link #arrayBaseOffset}.
476 */
477 public static final int INVALID_FIELD_OFFSET = -1;
478
|
1 /*
2 * Copyright (c) 2000, 2016, 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
439 * by the address and length parameters. If the effective addresses and
440 * length are all even modulo 8, the transfer takes place in 'long' units.
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
538 */
539 public native void freeMemory(long address);
540
541 /// random queries
542
543 /**
544 * This constant differs from all results that will ever be returned from
545 * {@link #staticFieldOffset}, {@link #objectFieldOffset},
546 * or {@link #arrayBaseOffset}.
547 */
548 public static final int INVALID_FIELD_OFFSET = -1;
549
|