src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template
author psandoz
Wed, 20 Dec 2017 09:14:52 -0800
changeset 48356 29e165bdf669
parent 47216 71c04702a3d5
child 53855 7c362992527a
permissions -rw-r--r--
8193085: Vectorize the nio Buffer equals and compareTo implementations Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
36933
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
     2
 * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#warn This file is preprocessed before being compiled
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
package java.nio;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * A read/write Heap$Type$Buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * A read-only Heap$Type$Buffer.  This class extends the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * read/write class, overriding the mutation methods to throw a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * ReadOnlyBufferException} and overriding the view-buffer methods to return an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * instance of this class rather than of the superclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
class Heap$Type$Buffer$RW$
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    extends {#if[ro]?Heap}$Type$Buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
{
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    44
    // Cached array base offset
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    45
    private static final long ARRAY_BASE_OFFSET = UNSAFE.arrayBaseOffset($type$[].class);
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    46
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    47
    // Cached array base offset
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    48
    private static final long ARRAY_INDEX_SCALE = UNSAFE.arrayIndexScale($type$[].class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    // For speed these fields are actually declared in X-Buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    // these declarations are here as documentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    protected final $type$[] hb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    protected final int offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    Heap$Type$Buffer$RW$(int cap, int lim) {            // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        super(-1, 0, lim, cap, new $type$[cap], 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        hb = new $type$[cap];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        offset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        */
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    66
        this.address = ARRAY_BASE_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        super(cap, lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        this.isReadOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    Heap$Type$Buffer$RW$($type$[] buf, int off, int len) { // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        super(-1, off, off + len, buf.length, buf, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        hb = buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        offset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        */
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    80
        this.address = ARRAY_BASE_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        super(buf, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        this.isReadOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    protected Heap$Type$Buffer$RW$($type$[] buf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                                   int mark, int pos, int lim, int cap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                   int off)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        super(mark, pos, lim, cap, buf, off);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        hb = buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        offset = off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        */
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    97
        this.address = ARRAY_BASE_OFFSET + off * ARRAY_INDEX_SCALE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        super(buf, mark, pos, lim, cap, off);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        this.isReadOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public $Type$Buffer slice() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        return new Heap$Type$Buffer$RW$(hb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                                        -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                                        0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                        this.remaining(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                                        this.remaining(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                        this.position() + offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
36933
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   113
#if[byte]
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   114
    $Type$Buffer slice(int pos, int lim) {
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   115
        assert (pos >= 0);
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   116
        assert (pos <= lim);
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   117
        int rem = lim - pos;
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   118
        return new Heap$Type$Buffer$RW$(hb,
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   119
                                        -1,
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   120
                                        0,
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   121
                                        rem,
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   122
                                        rem,
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   123
                                        pos + offset);
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   124
    }
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   125
#end[byte]
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   126
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public $Type$Buffer duplicate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return new Heap$Type$Buffer$RW$(hb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                        this.markValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                                        this.position(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                        this.limit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                                        this.capacity(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                        offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public $Type$Buffer asReadOnlyBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        return new Heap$Type$BufferR(hb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                                     this.markValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                     this.position(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                     this.limit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                                     this.capacity(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                                     offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return duplicate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    protected int ix(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return i + offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   155
#if[byte]
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   156
    private long byteOffset(long i) {
36933
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   157
        return address + i;
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   158
    }
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   159
#end[byte]
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   160
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public $type$ get() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        return hb[ix(nextGetIndex())];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public $type$ get(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return hb[ix(checkIndex(i))];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
17922
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   169
#if[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   170
    $type$ getUnchecked(int i) {
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   171
	return hb[ix(i)];
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   172
    }
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   173
#end[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   174
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public $Type$Buffer get($type$[] dst, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        checkBounds(offset, length, dst.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (length > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            throw new BufferUnderflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        System.arraycopy(hb, ix(position()), dst, offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        position(position() + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public boolean isDirect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public boolean isReadOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        return {#if[rw]?false:true};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public $Type$Buffer put($type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        hb[ix(nextPutIndex())] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public $Type$Buffer put(int i, $type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        hb[ix(checkIndex(i))] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public $Type$Buffer put($type$[] src, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        checkBounds(offset, length, src.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        if (length > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        System.arraycopy(src, offset, hb, ix(position()), length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        position(position() + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public $Type$Buffer put($Type$Buffer src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        if (src instanceof Heap$Type$Buffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            if (src == this)
31873
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 30338
diff changeset
   229
                throw createSameBufferException();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            Heap$Type$Buffer sb = (Heap$Type$Buffer)src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            int n = sb.remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            if (n > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            System.arraycopy(sb.hb, sb.ix(sb.position()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                             hb, ix(position()), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            sb.position(sb.position() + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            position(position() + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        } else if (src.isDirect()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            int n = src.remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            if (n > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            src.get(hb, ix(position()), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            position(position() + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            super.put(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public $Type$Buffer compact() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        System.arraycopy(hb, ix(position()), hb, ix(0), remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        position(remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        limit(capacity());
1634
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 1247
diff changeset
   258
        discardMark();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    byte _get(int i) {                          // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return hb[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    void _put(int i, byte b) {                  // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        hb[i] = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    // char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public char getChar() {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   286
        return UNSAFE.getCharUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public char getChar(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   290
        return UNSAFE.getCharUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public $Type$Buffer putChar(char x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   297
        UNSAFE.putCharUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public $Type$Buffer putChar(int i, char x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   306
        UNSAFE.putCharUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public CharBuffer asCharBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        int size = this.remaining() >> 1;
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   315
        long addr = address + position();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                ? (CharBuffer)(new ByteBufferAsCharBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                                                               size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   322
                                                               addr))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                : (CharBuffer)(new ByteBufferAsCharBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                                                               size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   328
                                                               addr)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    // short
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    public short getShort() {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   337
        return UNSAFE.getShortUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    public short getShort(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   341
        return UNSAFE.getShortUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public $Type$Buffer putShort(short x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   348
        UNSAFE.putShortUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    public $Type$Buffer putShort(int i, short x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   357
        UNSAFE.putShortUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public ShortBuffer asShortBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        int size = this.remaining() >> 1;
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   366
        long addr = address + position();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                ? (ShortBuffer)(new ByteBufferAsShortBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                                                                 size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   373
                                                                 addr))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                : (ShortBuffer)(new ByteBufferAsShortBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                                                                 size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   379
                                                                 addr)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    // int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    public int getInt() {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   388
        return UNSAFE.getIntUnaligned(hb, byteOffset(nextGetIndex(4)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    public int getInt(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   392
        return UNSAFE.getIntUnaligned(hb, byteOffset(checkIndex(i, 4)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    public $Type$Buffer putInt(int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   399
        UNSAFE.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    public $Type$Buffer putInt(int i, int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   408
        UNSAFE.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    public IntBuffer asIntBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        int size = this.remaining() >> 2;
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   417
        long addr = address + position();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                ? (IntBuffer)(new ByteBufferAsIntBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                                                             -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                                                             0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                                                             size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                                                             size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   424
                                                             addr))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                : (IntBuffer)(new ByteBufferAsIntBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                                                             -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                                                             0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                                                             size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                                                             size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   430
                                                             addr)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    // long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    public long getLong() {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   439
        return UNSAFE.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    public long getLong(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   443
        return UNSAFE.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    public $Type$Buffer putLong(long x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   450
        UNSAFE.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    public $Type$Buffer putLong(int i, long x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   459
        UNSAFE.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    public LongBuffer asLongBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        int size = this.remaining() >> 3;
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   468
        long addr = address + position();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                ? (LongBuffer)(new ByteBufferAsLongBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                                                               size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   475
                                                               addr))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                : (LongBuffer)(new ByteBufferAsLongBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                                                               size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   481
                                                               addr)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    // float
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    public float getFloat() {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   490
        int x = UNSAFE.getIntUnaligned(hb, byteOffset(nextGetIndex(4)), bigEndian);
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   491
        return Float.intBitsToFloat(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    public float getFloat(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   495
        int x = UNSAFE.getIntUnaligned(hb, byteOffset(checkIndex(i, 4)), bigEndian);
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   496
        return Float.intBitsToFloat(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    public $Type$Buffer putFloat(float x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   503
        int y = Float.floatToRawIntBits(x);
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   504
        UNSAFE.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), y, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    public $Type$Buffer putFloat(int i, float x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   513
        int y = Float.floatToRawIntBits(x);
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   514
        UNSAFE.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), y, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    public FloatBuffer asFloatBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        int size = this.remaining() >> 2;
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   523
        long addr = address + position();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                ? (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                                                                 size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   530
                                                                 addr))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                : (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                                                                 size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   536
                                                                 addr)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    // double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    public double getDouble() {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   545
        long x = UNSAFE.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian);
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   546
        return Double.longBitsToDouble(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    public double getDouble(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   550
        long x = UNSAFE.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian);
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   551
        return Double.longBitsToDouble(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    public $Type$Buffer putDouble(double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   558
        long y = Double.doubleToRawLongBits(x);
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   559
        UNSAFE.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), y, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    public $Type$Buffer putDouble(int i, double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   568
        long y = Double.doubleToRawLongBits(x);
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   569
        UNSAFE.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), y, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    public DoubleBuffer asDoubleBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        int size = this.remaining() >> 3;
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   578
        long addr = address + position();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                ? (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                                                                   -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                                                                   0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                                                                   size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                                                                   size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   585
                                                                   addr))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                : (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                                                                   -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                                                                   0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                                                                   size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                                                                   size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   591
                                                                   addr)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    String toString(int start, int end) {               // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            return new String(hb, start + offset, end - start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        } catch (StringIndexOutOfBoundsException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    // --- Methods to support CharSequence ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
1224
8c1bc7c5dd00 6733145: (bf) CharBuffer.subSequence can be updated to take advantage of covariant returns
martin
parents: 2
diff changeset
   611
    public CharBuffer subSequence(int start, int end) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        if ((start < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            || (end > length())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            || (start > end))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            throw new IndexOutOfBoundsException();
2593
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   616
        int pos = position();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        return new HeapCharBuffer$RW$(hb,
2593
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   618
                                      -1,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   619
                                      pos + start,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   620
                                      pos + end,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   621
                                      capacity(),
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   622
                                      offset);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
#if[!byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    public ByteOrder order() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        return ByteOrder.nativeOrder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    }
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   633
#end[!byte]
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   634
#if[char]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   636
    ByteOrder charRegionOrder() {
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   637
        return order();
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   638
    }
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   639
#end[char]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
}