jdk/src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template
author aph
Tue, 31 Mar 2015 12:30:52 -0700
changeset 30338 957ee8b5a33a
parent 25859 3317bb8137f4
child 31873 87b015c2cd36
permissions -rw-r--r--
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods Summary: Use unaligned Unsafe loads and stores for ByteBuffer access on platforms which support unaligned access. Add intrinsics for Unsafe.{get,put}-X-Unaligned methods. Reviewed-by: dholmes, jrose, psandoz, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
     2
 * Copyright (c) 2000, 2015, 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
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
    30
import sun.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]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    Heap$Type$Buffer$RW$($type$[] buf, int off, int len) { // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        super(-1, off, off + len, buf.length, buf, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        hb = buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        offset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        super(buf, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        this.isReadOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    protected Heap$Type$Buffer$RW$($type$[] buf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                                   int mark, int pos, int lim, int cap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                                   int off)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        super(mark, pos, lim, cap, buf, off);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        hb = buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        offset = off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        super(buf, mark, pos, lim, cap, off);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        this.isReadOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public $Type$Buffer slice() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        return new Heap$Type$Buffer$RW$(hb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                        -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                                        0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                        this.remaining(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                                        this.remaining(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                                        this.position() + offset);
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 duplicate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        return new Heap$Type$Buffer$RW$(hb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                        this.markValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                                        this.position(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                                        this.limit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                                        this.capacity(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                                        offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public $Type$Buffer asReadOnlyBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return new Heap$Type$BufferR(hb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                     this.markValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                                     this.position(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                     this.limit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                                     this.capacity(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                     offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return duplicate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    protected int ix(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return i + offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   145
#if[byte]
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   146
    private long byteOffset(long i) {
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   147
        return arrayBaseOffset + i + offset;
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   148
    }
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   149
#end[byte]
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   150
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public $type$ get() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return hb[ix(nextGetIndex())];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public $type$ get(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return hb[ix(checkIndex(i))];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
17922
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   159
#if[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   160
    $type$ getUnchecked(int i) {
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   161
	return hb[ix(i)];
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   162
    }
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   163
#end[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   164
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public $Type$Buffer get($type$[] dst, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        checkBounds(offset, length, dst.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (length > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            throw new BufferUnderflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        System.arraycopy(hb, ix(position()), dst, offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        position(position() + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public boolean isDirect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public boolean isReadOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return {#if[rw]?false:true};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public $Type$Buffer put($type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        hb[ix(nextPutIndex())] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public $Type$Buffer put(int i, $type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        hb[ix(checkIndex(i))] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public $Type$Buffer put($type$[] src, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        checkBounds(offset, length, src.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (length > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        System.arraycopy(src, offset, hb, ix(position()), length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        position(position() + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public $Type$Buffer put($Type$Buffer src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (src instanceof Heap$Type$Buffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            if (src == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            Heap$Type$Buffer sb = (Heap$Type$Buffer)src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            int n = sb.remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            if (n > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            System.arraycopy(sb.hb, sb.ix(sb.position()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                             hb, ix(position()), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            sb.position(sb.position() + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            position(position() + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        } else if (src.isDirect()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            int n = src.remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            if (n > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            src.get(hb, ix(position()), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            position(position() + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            super.put(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public $Type$Buffer compact() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        System.arraycopy(hb, ix(position()), hb, ix(0), remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        position(remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        limit(capacity());
1634
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 1247
diff changeset
   248
        discardMark();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    byte _get(int i) {                          // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return hb[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    void _put(int i, byte b) {                  // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        hb[i] = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    // char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public char getChar() {
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   276
        return unsafe.getCharUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public char getChar(int i) {
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   280
        return unsafe.getCharUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public $Type$Buffer putChar(char x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   287
        unsafe.putCharUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        return this;
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
    public $Type$Buffer putChar(int i, char x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   296
        unsafe.putCharUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public CharBuffer asCharBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        int size = this.remaining() >> 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        int off = offset + position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                ? (CharBuffer)(new ByteBufferAsCharBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                                                               off))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                : (CharBuffer)(new ByteBufferAsCharBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                                                               off)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    // short
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public short getShort() {
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   327
        return unsafe.getShortUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public short getShort(int i) {
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   331
        return unsafe.getShortUnaligned(hb, byteOffset(checkIndex(i, 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
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    public $Type$Buffer putShort(short x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   338
        unsafe.putShortUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    public $Type$Buffer putShort(int i, short x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   347
        unsafe.putShortUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    public ShortBuffer asShortBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        int size = this.remaining() >> 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        int off = offset + position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                ? (ShortBuffer)(new ByteBufferAsShortBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                                                                 off))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                : (ShortBuffer)(new ByteBufferAsShortBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                                                                 off)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    // int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public int getInt() {
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   378
        return unsafe.getIntUnaligned(hb, byteOffset(nextGetIndex(4)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public int getInt(int i) {
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   382
        return unsafe.getIntUnaligned(hb, byteOffset(checkIndex(i, 4)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    public $Type$Buffer putInt(int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   389
        unsafe.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    public $Type$Buffer putInt(int i, int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   398
        unsafe.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    public IntBuffer asIntBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        int size = this.remaining() >> 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        int off = offset + position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                ? (IntBuffer)(new ByteBufferAsIntBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                                                             -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                                                             0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                                                             size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                                                             size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                                                             off))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                : (IntBuffer)(new ByteBufferAsIntBuffer$RW$L(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,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                                                             off)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    // long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    public long getLong() {
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   429
        return unsafe.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    public long getLong(int i) {
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   433
        return unsafe.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    public $Type$Buffer putLong(long x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   440
        unsafe.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    public $Type$Buffer putLong(int i, long x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   449
        unsafe.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), x, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    public LongBuffer asLongBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        int size = this.remaining() >> 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        int off = offset + position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                ? (LongBuffer)(new ByteBufferAsLongBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                                                               off))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                : (LongBuffer)(new ByteBufferAsLongBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                                                               off)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    // float
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    public float getFloat() {
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   480
        int x = unsafe.getIntUnaligned(hb, byteOffset(nextPutIndex(4)), bigEndian);
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   481
        return Float.intBitsToFloat(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    public float getFloat(int i) {
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   485
        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
   486
        return Float.intBitsToFloat(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    public $Type$Buffer putFloat(float x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   493
        int y = Float.floatToRawIntBits(x);
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   494
        unsafe.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), y, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    public $Type$Buffer putFloat(int i, float x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   503
        int y = Float.floatToRawIntBits(x);
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   504
        unsafe.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), y, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    public FloatBuffer asFloatBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        int size = this.remaining() >> 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        int off = offset + position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                ? (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                                                                 off))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                : (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                                                                 off)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    // double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    public double getDouble() {
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   535
        long x = unsafe.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian);
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   536
        return Double.longBitsToDouble(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    public double getDouble(int i) {
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   540
        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
   541
        return Double.longBitsToDouble(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    public $Type$Buffer putDouble(double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   548
        long y = Double.doubleToRawLongBits(x);
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   549
        unsafe.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), y, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    public $Type$Buffer putDouble(int i, double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
#if[rw]
30338
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   558
        long y = Double.doubleToRawLongBits(x);
957ee8b5a33a 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 25859
diff changeset
   559
        unsafe.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), y, bigEndian);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    public DoubleBuffer asDoubleBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        int size = this.remaining() >> 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        int off = offset + position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                ? (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                                                                   -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                                                                   0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                                                                   size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                                                                   size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                                                                   off))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                : (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                                                                   -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                                                                   0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                                                                   size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                                                                   size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                                                                   off)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    String toString(int start, int end) {               // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            return new String(hb, start + offset, end - start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        } catch (StringIndexOutOfBoundsException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    // --- Methods to support CharSequence ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
1224
8c1bc7c5dd00 6733145: (bf) CharBuffer.subSequence can be updated to take advantage of covariant returns
martin
parents: 2
diff changeset
   601
    public CharBuffer subSequence(int start, int end) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        if ((start < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            || (end > length())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            || (start > end))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            throw new IndexOutOfBoundsException();
2593
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   606
        int pos = position();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        return new HeapCharBuffer$RW$(hb,
2593
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   608
                                      -1,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   609
                                      pos + start,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   610
                                      pos + end,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   611
                                      capacity(),
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   612
                                      offset);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
#if[!byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    public ByteOrder order() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        return ByteOrder.nativeOrder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
#end[!byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
}