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
26 package java.nio;
27
28 import jdk.internal.HotSpotIntrinsicCandidate;
29 import jdk.internal.access.JavaNioAccess;
30 import jdk.internal.access.SharedSecrets;
31 import jdk.internal.access.foreign.MemorySegmentProxy;
32 import jdk.internal.misc.Unsafe;
33 import jdk.internal.vm.annotation.ForceInline;
34
35 import java.util.Spliterator;
36
37 /**
38 * A container for data of a specific primitive type.
39 *
40 * <p> A buffer is a linear, finite sequence of elements of a specific
41 * primitive type. Aside from its content, the essential properties of a
42 * buffer are its capacity, limit, and position: </p>
43 *
44 * <blockquote>
45 *
46 * <p> A buffer's <i>capacity</i> is the number of elements it contains. The
47 * capacity of a buffer is never negative and never changes. </p>
48 *
49 * <p> A buffer's <i>limit</i> is the index of the first element that should
50 * not be read or written. A buffer's limit is never negative and is never
51 * greater than its capacity. </p>
52 *
741 final int markValue() { // package-private
742 return mark;
743 }
744
745 final void discardMark() { // package-private
746 mark = -1;
747 }
748
749 @ForceInline
750 final void checkSegment() {
751 if (segment != null) {
752 segment.checkValidState();
753 }
754 }
755
756 static {
757 // setup access to this package in SharedSecrets
758 SharedSecrets.setJavaNioAccess(
759 new JavaNioAccess() {
760 @Override
761 public JavaNioAccess.BufferPool getDirectBufferPool() {
762 return Bits.BUFFER_POOL;
763 }
764
765 @Override
766 public ByteBuffer newDirectByteBuffer(long addr, int cap, Object obj, MemorySegmentProxy segment) {
767 return new DirectByteBuffer(addr, cap, obj, segment);
768 }
769
770 @Override
771 public ByteBuffer newHeapByteBuffer(byte[] hb, int offset, int capacity, MemorySegmentProxy segment) {
772 return new HeapByteBuffer(hb, offset, capacity, segment);
773 }
774
775 @Override
776 public Object getBufferBase(ByteBuffer bb) {
777 return bb.base();
778 }
779
780 @Override
781 public long getBufferAddress(ByteBuffer bb) {
|
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
26 package java.nio;
27
28 import jdk.internal.HotSpotIntrinsicCandidate;
29 import jdk.internal.access.JavaNioAccess;
30 import jdk.internal.access.SharedSecrets;
31 import jdk.internal.access.foreign.MemorySegmentProxy;
32 import jdk.internal.misc.Unsafe;
33 import jdk.internal.misc.VM.BufferPool;
34 import jdk.internal.vm.annotation.ForceInline;
35
36 import java.util.Spliterator;
37
38 /**
39 * A container for data of a specific primitive type.
40 *
41 * <p> A buffer is a linear, finite sequence of elements of a specific
42 * primitive type. Aside from its content, the essential properties of a
43 * buffer are its capacity, limit, and position: </p>
44 *
45 * <blockquote>
46 *
47 * <p> A buffer's <i>capacity</i> is the number of elements it contains. The
48 * capacity of a buffer is never negative and never changes. </p>
49 *
50 * <p> A buffer's <i>limit</i> is the index of the first element that should
51 * not be read or written. A buffer's limit is never negative and is never
52 * greater than its capacity. </p>
53 *
742 final int markValue() { // package-private
743 return mark;
744 }
745
746 final void discardMark() { // package-private
747 mark = -1;
748 }
749
750 @ForceInline
751 final void checkSegment() {
752 if (segment != null) {
753 segment.checkValidState();
754 }
755 }
756
757 static {
758 // setup access to this package in SharedSecrets
759 SharedSecrets.setJavaNioAccess(
760 new JavaNioAccess() {
761 @Override
762 public BufferPool getDirectBufferPool() {
763 return Bits.BUFFER_POOL;
764 }
765
766 @Override
767 public ByteBuffer newDirectByteBuffer(long addr, int cap, Object obj, MemorySegmentProxy segment) {
768 return new DirectByteBuffer(addr, cap, obj, segment);
769 }
770
771 @Override
772 public ByteBuffer newHeapByteBuffer(byte[] hb, int offset, int capacity, MemorySegmentProxy segment) {
773 return new HeapByteBuffer(hb, offset, capacity, segment);
774 }
775
776 @Override
777 public Object getBufferBase(ByteBuffer bb) {
778 return bb.base();
779 }
780
781 @Override
782 public long getBufferAddress(ByteBuffer bb) {
|