98 *
99 * @apiNote two addresses might be considered equal despite their associated segments differ. This
100 * can happen, for instance, if the segment associated with one address is a <em>slice</em>
101 * (see {@link MemorySegment#asSlice(long, long)}) of the segment associated with the other address. Moreover,
102 * two addresses might be considered equals despite differences in the temporal bounds associated with their
103 * corresponding segments.
104 *
105 * @param that the object to be compared for equality with this address.
106 * @return {@code true} if the specified object is equal to this address.
107 */
108 @Override
109 boolean equals(Object that);
110
111 /**
112 * Returns the hash code value for this address.
113 * @return the hash code value for this address.
114 */
115 @Override
116 int hashCode();
117
118 /**
119 * Perform bulk copy from source address to target address. More specifically, the bytes at addresses {@code src}
120 * through {@code src.addOffset(bytes - 1)} are copied into addresses {@code dst} through {@code dst.addOffset(bytes - 1)}.
121 * If the source and address ranges overlap, then the copying is performed as if the bytes at addresses {@code src}
122 * through {@code src.addOffset(bytes - 1)} were first copied into a temporary segment with size {@code bytes},
123 * and then the contents of the temporary segment were copied into the bytes at addresses {@code dst} through
124 * {@code dst.addOffset(bytes - 1)}.
125 * <p>
126 * The result of a bulk copy is unspecified if, in the uncommon case, the source and target address ranges do not
127 * overlap, but refer to overlapping regions of the same backing storage using different addresses. For example,
128 * this may occur if the same file is {@link MemorySegment#mapFromPath mapped} to two segments.
129 *
130 * @param src the source address.
131 * @param dst the target address.
132 * @param bytes the number of bytes to be copied.
133 * @throws IndexOutOfBoundsException if {@code bytes < 0}, or if it is greater than the size of the segments
134 * associated with either {@code src} or {@code dst}.
135 * @throws IllegalStateException if either the source address or the target address belong to memory segments
136 * which have been already closed, or if access occurs from a thread other than the thread owning either segment.
137 * @throws UnsupportedOperationException if either {@code src} or {@code dst} do not feature required access modes;
138 * more specifically, {@code src} should be associated with a segment with {@link MemorySegment#READ} access mode,
139 * while {@code dst} should be associated with a segment with {@link MemorySegment#WRITE} access mode.
140 */
141 static void copy(MemoryAddress src, MemoryAddress dst, long bytes) {
142 MemoryAddressImpl.copy((MemoryAddressImpl)src, (MemoryAddressImpl)dst, bytes);
143 }
144
145 /**
146 * The <em>unchecked</em> memory address instance modelling the {@code NULL} address. This address is <em>not</em> backed by
147 * a memory segment and hence it cannot be dereferenced.
148 */
149 MemoryAddress NULL = new MemoryAddressImpl( 0L);
150
151 /**
152 * Obtain a new <em>unchecked</em> memory address instance from given long address. The returned address is <em>not</em> backed by
153 * a memory segment and hence it cannot be dereferenced.
154 * @param value the long address.
155 * @return the new memory address instance.
156 */
157 static MemoryAddress ofLong(long value) {
158 return value == 0 ?
159 NULL :
160 new MemoryAddressImpl(value);
161 }
162
163 }
|
98 *
99 * @apiNote two addresses might be considered equal despite their associated segments differ. This
100 * can happen, for instance, if the segment associated with one address is a <em>slice</em>
101 * (see {@link MemorySegment#asSlice(long, long)}) of the segment associated with the other address. Moreover,
102 * two addresses might be considered equals despite differences in the temporal bounds associated with their
103 * corresponding segments.
104 *
105 * @param that the object to be compared for equality with this address.
106 * @return {@code true} if the specified object is equal to this address.
107 */
108 @Override
109 boolean equals(Object that);
110
111 /**
112 * Returns the hash code value for this address.
113 * @return the hash code value for this address.
114 */
115 @Override
116 int hashCode();
117
118 /**
119 * The <em>unchecked</em> memory address instance modelling the {@code NULL} address. This address is <em>not</em> backed by
120 * a memory segment and hence it cannot be dereferenced.
121 */
122 MemoryAddress NULL = new MemoryAddressImpl( 0L);
123
124 /**
125 * Obtain a new <em>unchecked</em> memory address instance from given long address. The returned address is <em>not</em> backed by
126 * a memory segment and hence it cannot be dereferenced.
127 * @param value the long address.
128 * @return the new memory address instance.
129 */
130 static MemoryAddress ofLong(long value) {
131 return value == 0 ?
132 NULL :
133 new MemoryAddressImpl(value);
134 }
135
136 }
|