src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template
author bpb
Thu, 28 Feb 2019 12:05:59 -0800
changeset 53959 1542e63eb537
parent 53901 0448cb38c418
child 54107 1d7aec80147a
permissions -rw-r--r--
5071718: (bf) Add ByteBuffer.slice(int offset, int length) Reviewed-by: alanb, bchristi, darcy, rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
53855
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
     2
 * Copyright (c) 2000, 2019, 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
53959
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53901
diff changeset
    30
import java.util.Objects;
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53901
diff changeset
    31
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * A read/write Heap$Type$Buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * A read-only Heap$Type$Buffer.  This class extends the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * read/write class, overriding the mutation methods to throw a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * ReadOnlyBufferException} and overriding the view-buffer methods to return an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * instance of this class rather than of the superclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
class Heap$Type$Buffer$RW$
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    extends {#if[ro]?Heap}$Type$Buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
{
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    46
    // Cached array base offset
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    47
    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
    48
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    49
    // Cached array base offset
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    50
    private static final long ARRAY_INDEX_SCALE = UNSAFE.arrayIndexScale($type$[].class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    // For speed these fields are actually declared in X-Buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    // these declarations are here as documentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    protected final $type$[] hb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    protected final int offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    Heap$Type$Buffer$RW$(int cap, int lim) {            // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        super(-1, 0, lim, cap, new $type$[cap], 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        hb = new $type$[cap];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        offset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        */
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    68
        this.address = ARRAY_BASE_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        super(cap, lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        this.isReadOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    Heap$Type$Buffer$RW$($type$[] buf, int off, int len) { // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        super(-1, off, off + len, buf.length, buf, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        hb = buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        offset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        */
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    82
        this.address = ARRAY_BASE_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        super(buf, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        this.isReadOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    protected Heap$Type$Buffer$RW$($type$[] buf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                   int mark, int pos, int lim, int cap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                   int off)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        super(mark, pos, lim, cap, buf, off);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        hb = buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        offset = off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        */
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    99
        this.address = ARRAY_BASE_OFFSET + off * ARRAY_INDEX_SCALE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        super(buf, mark, pos, lim, cap, off);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        this.isReadOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public $Type$Buffer slice() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        return new Heap$Type$Buffer$RW$(hb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                        -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                                        0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                        this.remaining(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                                        this.remaining(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                        this.position() + offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
53959
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53901
diff changeset
   115
    @Override
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53901
diff changeset
   116
    public $Type$Buffer slice(int index, int length) {
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53901
diff changeset
   117
        Objects.checkIndex(index, limit() + 1);
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53901
diff changeset
   118
        Objects.checkIndex(length, limit() - index + 1);
36933
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   119
        return new Heap$Type$Buffer$RW$(hb,
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   120
                                        -1,
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   121
                                        0,
53959
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53901
diff changeset
   122
                                        length,
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53901
diff changeset
   123
                                        length,
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53901
diff changeset
   124
                                        index + offset);
36933
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   125
    }
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
53855
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   184
    public $Type$Buffer get(int index, $type$[] dst, int offset, int length) {
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   185
        Objects.checkFromIndexSize(index, length, limit());
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   186
        Objects.checkFromIndexSize(offset, length, dst.length);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   187
        System.arraycopy(hb, ix(index), dst, offset, length);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   188
        return this;
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   189
    }
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   190
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public boolean isDirect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public boolean isReadOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        return {#if[rw]?false:true};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public $Type$Buffer put($type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        hb[ix(nextPutIndex())] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public $Type$Buffer put(int i, $type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        hb[ix(checkIndex(i))] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public $Type$Buffer put($type$[] src, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        checkBounds(offset, length, src.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        if (length > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        System.arraycopy(src, offset, hb, ix(position()), length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        position(position() + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public $Type$Buffer put($Type$Buffer src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if (src instanceof Heap$Type$Buffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            if (src == this)
31873
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 30338
diff changeset
   236
                throw createSameBufferException();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            Heap$Type$Buffer sb = (Heap$Type$Buffer)src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            int n = sb.remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            if (n > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            System.arraycopy(sb.hb, sb.ix(sb.position()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                             hb, ix(position()), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            sb.position(sb.position() + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            position(position() + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        } else if (src.isDirect()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            int n = src.remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            if (n > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            src.get(hb, ix(position()), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            position(position() + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            super.put(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
53855
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   260
    public $Type$Buffer put(int index, $type$[] src, int offset, int length) {
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   261
#if[rw]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   262
        Objects.checkFromIndexSize(index, length, limit());
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   263
        Objects.checkFromIndexSize(offset, length, src.length);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   264
        System.arraycopy(src, offset, hb, ix(index), length);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   265
        return this;
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   266
#else[rw]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   267
        throw new ReadOnlyBufferException();
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   268
#end[rw]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   269
    }
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   270
53901
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   271
#if[char]
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   272
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   273
    public $Type$Buffer put(String src, int start, int end) {
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   274
        int length = end - start;
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   275
        checkBounds(start, length, src.length());
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   276
        if (isReadOnly())
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   277
            throw new ReadOnlyBufferException();
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   278
        int pos = position();
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   279
        int lim = limit();
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   280
        int rem = (pos <= lim) ? lim - pos : 0;
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   281
        if (length > rem)
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   282
            throw new BufferOverflowException();
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   283
        src.getChars(start, end, hb, ix(pos));
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   284
        position(pos + length);
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   285
        return this;
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   286
    }
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   287
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   288
#end[char]
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   289
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public $Type$Buffer compact() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        System.arraycopy(hb, ix(position()), hb, ix(0), remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        position(remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        limit(capacity());
1634
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 1247
diff changeset
   295
        discardMark();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    byte _get(int i) {                          // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        return hb[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    void _put(int i, byte b) {                  // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        hb[i] = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    // char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public char getChar() {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   323
        return UNSAFE.getCharUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public char getChar(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   327
        return UNSAFE.getCharUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    public $Type$Buffer putChar(char x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   334
        UNSAFE.putCharUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    public $Type$Buffer putChar(int i, char x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   343
        UNSAFE.putCharUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    public CharBuffer asCharBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        int size = this.remaining() >> 1;
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   352
        long addr = address + position();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                ? (CharBuffer)(new ByteBufferAsCharBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                                                               size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   359
                                                               addr))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                : (CharBuffer)(new ByteBufferAsCharBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                                                               size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   365
                                                               addr)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    // short
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public short getShort() {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   374
        return UNSAFE.getShortUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public short getShort(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   378
        return UNSAFE.getShortUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    public $Type$Buffer putShort(short x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   385
        UNSAFE.putShortUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public $Type$Buffer putShort(int i, short x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   394
        UNSAFE.putShortUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    public ShortBuffer asShortBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        int size = this.remaining() >> 1;
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   403
        long addr = address + position();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                ? (ShortBuffer)(new ByteBufferAsShortBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                                                                 size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   410
                                                                 addr))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                : (ShortBuffer)(new ByteBufferAsShortBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                                                                 size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   416
                                                                 addr)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    // int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public int getInt() {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   425
        return UNSAFE.getIntUnaligned(hb, byteOffset(nextGetIndex(4)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    public int getInt(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   429
        return UNSAFE.getIntUnaligned(hb, byteOffset(checkIndex(i, 4)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    public $Type$Buffer putInt(int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   436
        UNSAFE.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    public $Type$Buffer putInt(int i, int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   445
        UNSAFE.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    public IntBuffer asIntBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        int size = this.remaining() >> 2;
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   454
        long addr = address + position();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                ? (IntBuffer)(new ByteBufferAsIntBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                                                             -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                                                             0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                                                             size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                                                             size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   461
                                                             addr))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                : (IntBuffer)(new ByteBufferAsIntBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                                                             -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                                                             0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                                                             size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                                             size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   467
                                                             addr)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    // long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    public long getLong() {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   476
        return UNSAFE.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    public long getLong(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   480
        return UNSAFE.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    public $Type$Buffer putLong(long x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   487
        UNSAFE.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
#end[rw]
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 $Type$Buffer putLong(int i, long x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   496
        UNSAFE.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    public LongBuffer asLongBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        int size = this.remaining() >> 3;
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   505
        long addr = address + position();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                ? (LongBuffer)(new ByteBufferAsLongBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                                                               size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   512
                                                               addr))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                : (LongBuffer)(new ByteBufferAsLongBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                                                               size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   518
                                                               addr)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    // float
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    public float getFloat() {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   527
        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
   528
        return Float.intBitsToFloat(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    public float getFloat(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   532
        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
   533
        return Float.intBitsToFloat(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    public $Type$Buffer putFloat(float x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   540
        int y = Float.floatToRawIntBits(x);
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   541
        UNSAFE.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), y, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    public $Type$Buffer putFloat(int i, float x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   550
        int y = Float.floatToRawIntBits(x);
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   551
        UNSAFE.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), y, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    public FloatBuffer asFloatBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        int size = this.remaining() >> 2;
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   560
        long addr = address + position();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                ? (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                                                                 size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   567
                                                                 addr))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                : (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                                                                 size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   573
                                                                 addr)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    // double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    public double getDouble() {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   582
        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
   583
        return Double.longBitsToDouble(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    public double getDouble(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   587
        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
   588
        return Double.longBitsToDouble(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    public $Type$Buffer putDouble(double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   595
        long y = Double.doubleToRawLongBits(x);
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   596
        UNSAFE.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), y, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    public $Type$Buffer putDouble(int i, double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   605
        long y = Double.doubleToRawLongBits(x);
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   606
        UNSAFE.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), y, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    public DoubleBuffer asDoubleBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        int size = this.remaining() >> 3;
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   615
        long addr = address + position();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                ? (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                                                                   -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                                                                   0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                                                                   size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                                                                   size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   622
                                                                   addr))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                : (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                                                                   -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                                                                   0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                                                                   size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                                                                   size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   628
                                                                   addr)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    String toString(int start, int end) {               // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            return new String(hb, start + offset, end - start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        } catch (StringIndexOutOfBoundsException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    // --- Methods to support CharSequence ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
1224
8c1bc7c5dd00 6733145: (bf) CharBuffer.subSequence can be updated to take advantage of covariant returns
martin
parents: 2
diff changeset
   648
    public CharBuffer subSequence(int start, int end) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        if ((start < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            || (end > length())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            || (start > end))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            throw new IndexOutOfBoundsException();
2593
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   653
        int pos = position();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        return new HeapCharBuffer$RW$(hb,
2593
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   655
                                      -1,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   656
                                      pos + start,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   657
                                      pos + end,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   658
                                      capacity(),
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   659
                                      offset);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
#if[!byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    public ByteOrder order() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        return ByteOrder.nativeOrder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    }
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   670
#end[!byte]
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   671
#if[char]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   673
    ByteOrder charRegionOrder() {
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   674
        return order();
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   675
    }
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   676
#end[char]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
}