37 * This class provides an immutable implementation for the {@code MemoryAddress} interface. This class contains information
38 * about the segment this address is associated with, as well as an offset into such segment.
39 */
40 public final class MemoryAddressImpl implements MemoryAddress, MemoryAddressProxy {
41
42 private static final Unsafe UNSAFE = Unsafe.getUnsafe();
43
44 private final AbstractMemorySegmentImpl segment;
45 private final long offset;
46
47 public MemoryAddressImpl(long offset) {
48 this.segment = AbstractMemorySegmentImpl.NOTHING;
49 this.offset = offset;
50 }
51
52 public MemoryAddressImpl(AbstractMemorySegmentImpl segment, long offset) {
53 this.segment = Objects.requireNonNull(segment);
54 this.offset = offset;
55 }
56
57 public static void copy(MemoryAddressImpl src, MemoryAddressImpl dst, long size) {
58 src.checkAccess(0, size, true);
59 dst.checkAccess(0, size, false);
60 //check disjoint
61 long offsetSrc = src.unsafeGetOffset();
62 long offsetDst = dst.unsafeGetOffset();
63 Object baseSrc = src.unsafeGetBase();
64 Object baseDst = dst.unsafeGetBase();
65 UNSAFE.copyMemory(baseSrc, offsetSrc, baseDst, offsetDst, size);
66 }
67
68 // MemoryAddress methods
69
70 @Override
71 public long segmentOffset() {
72 if (segment() == null) {
73 throw new UnsupportedOperationException("Address does not have a segment");
74 }
75 return offset;
76 }
77
78 @Override
79 public long toRawLongValue() {
80 if (unsafeGetBase() != null) {
81 throw new UnsupportedOperationException("Not a native address");
82 }
83 return unsafeGetOffset();
84 }
85
86 @Override
87 public MemorySegment segment() {
|
37 * This class provides an immutable implementation for the {@code MemoryAddress} interface. This class contains information
38 * about the segment this address is associated with, as well as an offset into such segment.
39 */
40 public final class MemoryAddressImpl implements MemoryAddress, MemoryAddressProxy {
41
42 private static final Unsafe UNSAFE = Unsafe.getUnsafe();
43
44 private final AbstractMemorySegmentImpl segment;
45 private final long offset;
46
47 public MemoryAddressImpl(long offset) {
48 this.segment = AbstractMemorySegmentImpl.NOTHING;
49 this.offset = offset;
50 }
51
52 public MemoryAddressImpl(AbstractMemorySegmentImpl segment, long offset) {
53 this.segment = Objects.requireNonNull(segment);
54 this.offset = offset;
55 }
56
57 // MemoryAddress methods
58
59 @Override
60 public long segmentOffset() {
61 if (segment() == null) {
62 throw new UnsupportedOperationException("Address does not have a segment");
63 }
64 return offset;
65 }
66
67 @Override
68 public long toRawLongValue() {
69 if (unsafeGetBase() != null) {
70 throw new UnsupportedOperationException("Not a native address");
71 }
72 return unsafeGetOffset();
73 }
74
75 @Override
76 public MemorySegment segment() {
|