src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template
author bpb
Wed, 13 Mar 2019 11:12:22 -0700
changeset 54107 1d7aec80147a
parent 53959 1542e63eb537
child 54129 deb99f13c6cd
permissions -rw-r--r--
8219597: (bf) Heap buffer state changes could provoke unexpected exceptions Reviewed-by: alanb, 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() {
54107
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   107
        int rem = this.remaining();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return new Heap$Type$Buffer$RW$(hb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                                        -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                        0,
54107
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   111
                                        rem,
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   112
                                        rem,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                                        this.position() + offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
53959
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53901
diff changeset
   116
    @Override
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53901
diff changeset
   117
    public $Type$Buffer slice(int index, int length) {
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53901
diff changeset
   118
        Objects.checkIndex(index, limit() + 1);
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53901
diff changeset
   119
        Objects.checkIndex(length, limit() - index + 1);
36933
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   120
        return new Heap$Type$Buffer$RW$(hb,
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   121
                                        -1,
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   122
                                        0,
53959
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
                                        length,
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53901
diff changeset
   125
                                        index + offset);
36933
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   126
    }
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   127
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public $Type$Buffer duplicate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        return new Heap$Type$Buffer$RW$(hb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                                        this.markValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                        this.position(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                                        this.limit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                        this.capacity(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                                        offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public $Type$Buffer asReadOnlyBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        return new Heap$Type$BufferR(hb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                     this.markValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                     this.position(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                                     this.limit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                                     this.capacity(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                     offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return duplicate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    protected int ix(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return i + offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   156
#if[byte]
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   157
    private long byteOffset(long i) {
36933
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 33665
diff changeset
   158
        return address + i;
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   159
    }
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   160
#end[byte]
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   161
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public $type$ get() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        return hb[ix(nextGetIndex())];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public $type$ get(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return hb[ix(checkIndex(i))];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
17922
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   170
#if[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   171
    $type$ getUnchecked(int i) {
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   172
	return hb[ix(i)];
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   173
    }
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   174
#end[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   175
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public $Type$Buffer get($type$[] dst, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        checkBounds(offset, length, dst.length);
54107
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   178
        int pos = position();
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   179
        if (length > limit() - pos)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            throw new BufferUnderflowException();
54107
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   181
        System.arraycopy(hb, ix(pos), dst, offset, length);
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   182
        position(pos + length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
53855
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   186
    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
   187
        Objects.checkFromIndexSize(index, length, limit());
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   188
        Objects.checkFromIndexSize(offset, length, dst.length);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   189
        System.arraycopy(hb, ix(index), dst, offset, length);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   190
        return this;
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   191
    }
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   192
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public boolean isDirect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public boolean isReadOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        return {#if[rw]?false:true};
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($type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        hb[ix(nextPutIndex())] = 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(int i, $type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        hb[ix(checkIndex(i))] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public $Type$Buffer put($type$[] src, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        checkBounds(offset, length, src.length);
54107
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   224
        int pos = position();
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   225
        if (length > limit() - pos)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            throw new BufferOverflowException();
54107
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   227
        System.arraycopy(src, offset, hb, ix(pos), length);
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   228
        position(pos + length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public $Type$Buffer put($Type$Buffer src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (src instanceof Heap$Type$Buffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            if (src == this)
31873
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 30338
diff changeset
   239
                throw createSameBufferException();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            Heap$Type$Buffer sb = (Heap$Type$Buffer)src;
54107
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   241
            int pos = position();
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   242
            int sbpos = sb.position();
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   243
            int n = sb.limit() - sbpos;
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   244
            if (n > limit() - pos)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                throw new BufferOverflowException();
54107
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   246
            System.arraycopy(sb.hb, sb.ix(sbpos),
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   247
                             hb, ix(pos), n);
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   248
            sb.position(sbpos + n);
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   249
            position(pos + n);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        } else if (src.isDirect()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            int n = src.remaining();
54107
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   252
            int pos = position();
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   253
            if (n > limit() - pos)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                throw new BufferOverflowException();
54107
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   255
            src.get(hb, ix(pos), n);
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   256
            position(pos + n);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            super.put(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
53855
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   266
    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
   267
#if[rw]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   268
        Objects.checkFromIndexSize(index, length, limit());
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   269
        Objects.checkFromIndexSize(offset, length, src.length);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   270
        System.arraycopy(src, offset, hb, ix(index), length);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   271
        return this;
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   272
#else[rw]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   273
        throw new ReadOnlyBufferException();
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   274
#end[rw]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   275
    }
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 48356
diff changeset
   276
53901
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   277
#if[char]
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   278
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   279
    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
   280
        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
   281
        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
   282
        if (isReadOnly())
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   283
            throw new ReadOnlyBufferException();
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   284
        int pos = position();
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   285
        int lim = limit();
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   286
        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
   287
        if (length > rem)
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   288
            throw new BufferOverflowException();
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   289
        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
   290
        position(pos + length);
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   291
        return this;
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   292
    }
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   293
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   294
#end[char]
0448cb38c418 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
bpb
parents: 53855
diff changeset
   295
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public $Type$Buffer compact() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
#if[rw]
54107
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   298
        int pos = position();
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   299
        int rem = limit() - pos;
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   300
        System.arraycopy(hb, ix(pos), hb, ix(0), rem);
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   301
        position(rem);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        limit(capacity());
1634
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 1247
diff changeset
   303
        discardMark();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    byte _get(int i) {                          // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return hb[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    void _put(int i, byte b) {                  // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        hb[i] = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    // char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public char getChar() {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   331
        return UNSAFE.getCharUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    public char getChar(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   335
        return UNSAFE.getCharUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
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
    public $Type$Buffer putChar(char x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   342
        UNSAFE.putCharUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public $Type$Buffer putChar(int i, char x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   351
        UNSAFE.putCharUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public CharBuffer asCharBuffer() {
54107
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   359
        int pos = position();
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   360
        int size = (limit() - pos) >> 1;
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   361
        long addr = address + pos;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                ? (CharBuffer)(new ByteBufferAsCharBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                                                               size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   368
                                                               addr))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                : (CharBuffer)(new ByteBufferAsCharBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                                                               size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   374
                                                               addr)));
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    // short
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    public short getShort() {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   383
        return UNSAFE.getShortUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    public short getShort(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   387
        return UNSAFE.getShortUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public $Type$Buffer putShort(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(nextPutIndex(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 $Type$Buffer putShort(int i, short x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   403
        UNSAFE.putShortUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    public ShortBuffer asShortBuffer() {
54107
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   411
        int pos = position();
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   412
        int size = (limit() - pos) >> 1;
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   413
        long addr = address + pos;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                ? (ShortBuffer)(new ByteBufferAsShortBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                                                                 size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   420
                                                                 addr))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                : (ShortBuffer)(new ByteBufferAsShortBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                                                                 size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   426
                                                                 addr)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    // int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    public int getInt() {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   435
        return UNSAFE.getIntUnaligned(hb, byteOffset(nextGetIndex(4)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    public int getInt(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   439
        return UNSAFE.getIntUnaligned(hb, byteOffset(checkIndex(i, 4)), 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
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    public $Type$Buffer putInt(int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   446
        UNSAFE.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    public $Type$Buffer putInt(int i, int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   455
        UNSAFE.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    public IntBuffer asIntBuffer() {
54107
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   463
        int pos = position();
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   464
        int size = (limit() - pos) >> 2;
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   465
        long addr = address + pos;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                ? (IntBuffer)(new ByteBufferAsIntBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                                                             -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                                             0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                                                             size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                                                             size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   472
                                                             addr))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                : (IntBuffer)(new ByteBufferAsIntBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                                                             -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                                                             0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                                                             size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                                                             size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   478
                                                             addr)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    // long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    public long getLong() {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   487
        return UNSAFE.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    public long getLong(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   491
        return UNSAFE.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian);
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
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    public $Type$Buffer putLong(long x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   498
        UNSAFE.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    public $Type$Buffer putLong(int i, long x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
#if[rw]
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   507
        UNSAFE.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    public LongBuffer asLongBuffer() {
54107
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   515
        int pos = position();
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   516
        int size = (limit() - pos) >> 3;
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   517
        long addr = address + pos;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                ? (LongBuffer)(new ByteBufferAsLongBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                                                               size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   524
                                                               addr))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                : (LongBuffer)(new ByteBufferAsLongBuffer$RW$L(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
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    // float
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    public float getFloat() {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   539
        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
   540
        return Float.intBitsToFloat(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    public float getFloat(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   544
        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
   545
        return Float.intBitsToFloat(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    public $Type$Buffer putFloat(float x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   552
        int y = Float.floatToRawIntBits(x);
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   553
        UNSAFE.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), y, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    public $Type$Buffer putFloat(int i, float x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   562
        int y = Float.floatToRawIntBits(x);
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   563
        UNSAFE.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), y, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    public FloatBuffer asFloatBuffer() {
54107
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   571
        int pos = position();
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   572
        int size = (limit() - pos) >> 2;
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   573
        long addr = address + pos;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                ? (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                                                                 size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   580
                                                                 addr))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                : (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                                                                 size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   586
                                                                 addr)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    // double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    public double getDouble() {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   595
        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
   596
        return Double.longBitsToDouble(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    public double getDouble(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   600
        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
   601
        return Double.longBitsToDouble(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    public $Type$Buffer putDouble(double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   608
        long y = Double.doubleToRawLongBits(x);
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   609
        UNSAFE.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), y, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    public $Type$Buffer putDouble(int i, double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   618
        long y = Double.doubleToRawLongBits(x);
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   619
        UNSAFE.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), y, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    public DoubleBuffer asDoubleBuffer() {
54107
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   627
        int pos = position();
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   628
        int size = (limit() - pos) >> 3;
1d7aec80147a 8219597: (bf) Heap buffer state changes could provoke unexpected exceptions
bpb
parents: 53959
diff changeset
   629
        long addr = address + pos;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                ? (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                                                                   -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                                                                   0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                                                                   size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                                                                   size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   636
                                                                   addr))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                : (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                                                                   -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                                                                   0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                                                                   size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                                                                   size,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 36933
diff changeset
   642
                                                                   addr)));
2
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
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    String toString(int start, int end) {               // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            return new String(hb, start + offset, end - start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        } catch (StringIndexOutOfBoundsException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    // --- Methods to support CharSequence ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
1224
8c1bc7c5dd00 6733145: (bf) CharBuffer.subSequence can be updated to take advantage of covariant returns
martin
parents: 2
diff changeset
   662
    public CharBuffer subSequence(int start, int end) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        if ((start < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            || (end > length())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            || (start > end))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            throw new IndexOutOfBoundsException();
2593
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   667
        int pos = position();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        return new HeapCharBuffer$RW$(hb,
2593
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   669
                                      -1,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   670
                                      pos + start,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   671
                                      pos + end,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   672
                                      capacity(),
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   673
                                      offset);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
#if[!byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    public ByteOrder order() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        return ByteOrder.nativeOrder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    }
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   684
#end[!byte]
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   685
#if[char]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   687
    ByteOrder charRegionOrder() {
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   688
        return order();
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   689
    }
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   690
#end[char]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
}