src/java.base/share/classes/java/nio/ByteBufferAs-X-Buffer.java.template
author psandoz
Wed, 20 Dec 2017 09:14:52 -0800
changeset 48356 29e165bdf669
parent 47216 71c04702a3d5
child 53959 1542e63eb537
permissions -rw-r--r--
8193085: Vectorize the nio Buffer equals and compareTo implementations Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
40180
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
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
40180
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
    30
import jdk.internal.misc.Unsafe;
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
    31
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
class ByteBufferAs$Type$Buffer$RW$$BO$                  // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    extends {#if[ro]?ByteBufferAs}$Type$Buffer{#if[ro]?$BO$}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    protected final ByteBuffer bb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb) {   // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        super(-1, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
              bb.remaining() >> $LG_BYTES_PER_VALUE$,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
              bb.remaining() >> $LG_BYTES_PER_VALUE$);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        this.bb = bb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        // enforce limit == capacity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        int cap = this.capacity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        this.limit(cap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        int pos = this.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        assert (pos <= cap);
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
    54
        address = bb.address;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        super(bb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                                     int mark, int pos, int lim, int cap,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
    62
                                     long addr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        super(mark, pos, lim, cap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        this.bb = bb;
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
    67
        address = addr;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
    68
        assert address >= bb.address;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
#else[rw]
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
    70
        super(bb, mark, pos, lim, cap, addr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    74
    @Override
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    75
    Object base() {
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    76
        return bb.hb;
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    77
    }
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    78
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public $Type$Buffer slice() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        int pos = this.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        int lim = this.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        int rem = (pos <= lim ? lim - pos : 0);
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
    84
        long addr = byteOffset(pos);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
    85
        return new ByteBufferAs$Type$Buffer$RW$$BO$(bb, -1, 0, rem, rem, addr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public $Type$Buffer duplicate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                                    this.markValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                                    this.position(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                                    this.limit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                                                    this.capacity(),
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
    94
                                                    address);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public $Type$Buffer asReadOnlyBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return new ByteBufferAs$Type$BufferR$BO$(bb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                                 this.markValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                                                 this.position(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                                                 this.limit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                                                 this.capacity(),
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
   104
                                                 address);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return duplicate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
   112
    private int ix(int i) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
   113
        int off = (int) (address - bb.address);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
   114
        return (i << $LG_BYTES_PER_VALUE$) + off;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
   117
    protected long byteOffset(long i) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
   118
        return (i << $LG_BYTES_PER_VALUE$) + address;
40180
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   119
    }
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   120
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public $type$ get() {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   122
        $memtype$ x = UNSAFE.get$Memtype$Unaligned(bb.hb, byteOffset(nextGetIndex()),
40180
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   123
            {#if[boB]?true:false});
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   124
        return $fromBits$(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public $type$ get(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   128
        $memtype$ x = UNSAFE.get$Memtype$Unaligned(bb.hb, byteOffset(checkIndex(i)),
40180
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   129
            {#if[boB]?true:false});
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   130
        return $fromBits$(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
17922
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   133
#if[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   134
   $type$ getUnchecked(int i) {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   135
        $memtype$ x = UNSAFE.get$Memtype$Unaligned(bb.hb, byteOffset(i),
40180
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   136
            {#if[boB]?true:false});
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   137
        return $fromBits$(x);
17922
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   138
    }
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   139
#end[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   140
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public $Type$Buffer put($type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
#if[rw]
40180
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   145
        $memtype$ y = $toBits$(x);
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   146
        UNSAFE.put$Memtype$Unaligned(bb.hb, byteOffset(nextPutIndex()), y,
40180
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   147
            {#if[boB]?true:false});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public $Type$Buffer put(int i, $type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
#if[rw]
40180
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   156
        $memtype$ y = $toBits$(x);
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   157
        UNSAFE.put$Memtype$Unaligned(bb.hb, byteOffset(checkIndex(i)), y,
40180
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   158
            {#if[boB]?true:false});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public $Type$Buffer compact() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        int pos = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        int lim = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        int rem = (pos <= lim ? lim - pos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        ByteBuffer db = bb.duplicate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        db.limit(ix(lim));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        db.position(ix(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        ByteBuffer sb = db.slice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        sb.position(pos << $LG_BYTES_PER_VALUE$);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        sb.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        position(rem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        limit(capacity());
1634
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 1247
diff changeset
   180
        discardMark();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public boolean isDirect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return bb.isDirect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public boolean isReadOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return {#if[rw]?false:true};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public String toString(int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if ((end > limit()) || (start > end))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            int len = end - start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            char[] ca = new char[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            CharBuffer cb = CharBuffer.wrap(ca);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            CharBuffer db = this.duplicate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            db.position(start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            db.limit(end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            cb.put(db);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            return new String(ca);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        } catch (StringIndexOutOfBoundsException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    // --- Methods to support CharSequence ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
1224
8c1bc7c5dd00 6733145: (bf) CharBuffer.subSequence can be updated to take advantage of covariant returns
martin
parents: 2
diff changeset
   217
    public CharBuffer subSequence(int start, int end) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        int pos = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        int lim = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        pos = (pos <= lim ? pos : lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        int len = lim - pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if ((start < 0) || (end > len) || (start > end))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            throw new IndexOutOfBoundsException();
2593
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   226
        return new ByteBufferAsCharBuffer$RW$$BO$(bb,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   227
                                                  -1,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   228
                                                  pos + start,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   229
                                                  pos + end,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   230
                                                  capacity(),
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
   231
                                                  address);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public ByteOrder order() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
#if[boB]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return ByteOrder.BIG_ENDIAN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
#end[boB]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
#if[boL]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return ByteOrder.LITTLE_ENDIAN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
#end[boL]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   246
#if[char]
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   247
    ByteOrder charRegionOrder() {
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   248
        return order();
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   249
    }
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   250
#end[char]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
}