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