src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template
author bpb
Fri, 15 Mar 2019 16:24:07 -0700 (2019-03-15)
changeset 54151 d2f8b7b33013
parent 54129 deb99f13c6cd
child 57804 9b7b9f16dfd9
permissions -rw-r--r--
8219876: (bf) Improve IndexOutOfBoundsException messages in $Type$Buffer classes Reviewed-by: alanb, rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
53855
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
     2
 * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#warn This file is preprocessed before being compiled
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
package java.nio;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
7025
6e002f9a2899 6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents: 6902
diff changeset
    30
import java.io.FileDescriptor;
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
    31
import java.lang.ref.Reference;
53855
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
    32
import java.util.Objects;
34882
ce2a8ec851c1 8145544: Move sun.misc.VM to jdk.internal.misc
chegar
parents: 33660
diff changeset
    33
import jdk.internal.misc.VM;
35641
da165fd9c886 8148117: Move sun.misc.Cleaner to jdk.internal.ref
chegar
parents: 34882
diff changeset
    34
import jdk.internal.ref.Cleaner;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.nio.ch.DirectBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
class Direct$Type$Buffer$RW$$BO$
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    extends {#if[byte]?Mapped$Type$Buffer:$Type$Buffer}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    extends Direct$Type$Buffer$BO$
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    implements DirectBuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
1151
4070cecdb99d 6570619: (bf) DirectByteBuffer.get/put(byte[]) does not scale well
alanb
parents: 1143
diff changeset
    49
    // Cached array base offset
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    50
    private static final long ARRAY_BASE_OFFSET = UNSAFE.arrayBaseOffset($type$[].class);
1151
4070cecdb99d 6570619: (bf) DirectByteBuffer.get/put(byte[]) does not scale well
alanb
parents: 1143
diff changeset
    51
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    // Cached unaligned-access capability
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    53
    protected static final boolean UNALIGNED = Bits.unaligned();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    // Base address, used in all indexing calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    // NOTE: moved up to Buffer.java for speed in JNI GetDirectBufferAddress
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    //    protected long address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
10325
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
    59
    // An object attached to this buffer. If this buffer is a view of another
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
    60
    // buffer then we use this field to keep a reference to that buffer to
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
    61
    // ensure that its memory isn't freed before we are done with it.
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
    62
    private final Object att;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
10325
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
    64
    public Object attachment() {
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
    65
        return att;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static class Deallocator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        implements Runnable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        private long address;
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    75
        private long size;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        private int capacity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    78
        private Deallocator(long address, long size, int capacity) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            assert (address != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            this.address = address;
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    81
            this.size = size;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            this.capacity = capacity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            if (address == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                // Paranoia
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            }
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
    90
            UNSAFE.freeMemory(address);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            address = 0;
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    92
            Bits.unreserveMemory(size, capacity);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private final Cleaner cleaner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public Cleaner cleaner() { return cleaner; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
#else[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public Cleaner cleaner() { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
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
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    // Primary constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    Direct$Type$Buffer$RW$(int cap) {                   // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
#if[rw]
7025
6e002f9a2899 6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents: 6902
diff changeset
   115
        super(-1, 0, cap, cap);
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 5506
diff changeset
   116
        boolean pa = VM.isDirectMemoryPageAligned();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        int ps = Bits.pageSize();
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 5506
diff changeset
   118
        long size = Math.max(1L, (long)cap + (pa ? ps : 0));
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
   119
        Bits.reserveMemory(size, cap);
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
   120
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        long base = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        try {
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   123
            base = UNSAFE.allocateMemory(size);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        } catch (OutOfMemoryError x) {
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
   125
            Bits.unreserveMemory(size, cap);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            throw x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   128
        UNSAFE.setMemory(base, size, (byte) 0);
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 5506
diff changeset
   129
        if (pa && (base % ps != 0)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            // Round up to page boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            address = base + ps - (base & (ps - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            address = base;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
   135
        cleaner = Cleaner.create(this, new Deallocator(base, size, cap));
10325
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   136
        att = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        super(cap);
36933
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 36222
diff changeset
   139
        this.isReadOnly = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
10325
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   145
    // Invoked to construct a direct ByteBuffer referring to the block of
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   146
    // memory. A given arbitrary object may also be attached to the buffer.
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   147
    //
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   148
    Direct$Type$Buffer(long addr, int cap, Object ob) {
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   149
        super(-1, 0, cap, cap);
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   150
        address = addr;
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   151
        cleaner = null;
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   152
        att = ob;
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   153
    }
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   154
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   155
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    // Invoked only by JNI: NewDirectByteBuffer(void*, long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    private Direct$Type$Buffer(long addr, int cap) {
7025
6e002f9a2899 6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents: 6902
diff changeset
   159
        super(-1, 0, cap, cap);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        address = addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        cleaner = null;
10325
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   162
        att = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    // For memory-mapped buffers -- invoked by FileChannelImpl via reflection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    //
7025
6e002f9a2899 6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents: 6902
diff changeset
   169
    protected Direct$Type$Buffer$RW$(int cap, long addr,
6e002f9a2899 6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents: 6902
diff changeset
   170
                                     FileDescriptor fd,
6e002f9a2899 6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents: 6902
diff changeset
   171
                                     Runnable unmapper)
6e002f9a2899 6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents: 6902
diff changeset
   172
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
#if[rw]
7025
6e002f9a2899 6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents: 6902
diff changeset
   174
        super(-1, 0, cap, cap, fd);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        address = addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        cleaner = Cleaner.create(this, unmapper);
10325
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   177
        att = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
#else[rw]
7025
6e002f9a2899 6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents: 6902
diff changeset
   179
        super(cap, addr, fd, unmapper);
36933
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 36222
diff changeset
   180
        this.isReadOnly = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    // For duplicates and slices
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    Direct$Type$Buffer$RW$$BO$(DirectBuffer db,         // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                               int mark, int pos, int lim, int cap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                               int off)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        super(mark, pos, lim, cap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        address = db.address() + off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        cleaner = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
#end[byte]
51318
60f9b6b5ad86 8208362: (bf) Long chains created by direct Buffer::slice
fweimer
parents: 49210
diff changeset
   198
        Object attachment = db.attachment();
60f9b6b5ad86 8208362: (bf) Long chains created by direct Buffer::slice
fweimer
parents: 49210
diff changeset
   199
        att = (attachment == null ? db : attachment);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        super(db, mark, pos, lim, cap, off);
36933
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 36222
diff changeset
   202
        this.isReadOnly = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   206
    @Override
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   207
    Object base() {
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   208
        return null;
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   209
    }
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   210
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public $Type$Buffer slice() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        int pos = this.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        int lim = this.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        int rem = (pos <= lim ? lim - pos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        int off = (pos << $LG_BYTES_PER_VALUE$);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        assert (off >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return new Direct$Type$Buffer$RW$$BO$(this, -1, 0, rem, rem, off);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
53959
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53855
diff changeset
   221
    @Override
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53855
diff changeset
   222
    public $Type$Buffer slice(int index, int length) {
54129
deb99f13c6cd 8220614: (bf) Buffer absolute slice methods should use Objects.checkFromIndexSize()
bpb
parents: 53959
diff changeset
   223
        Objects.checkFromIndexSize(index, length, limit());
53959
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53855
diff changeset
   224
        return new Direct$Type$Buffer$RW$$BO$(this,
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53855
diff changeset
   225
                                              -1,
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53855
diff changeset
   226
                                              0,
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53855
diff changeset
   227
                                              length,
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53855
diff changeset
   228
                                              length,
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53855
diff changeset
   229
                                              index);
36933
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 36222
diff changeset
   230
    }
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 36222
diff changeset
   231
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public $Type$Buffer duplicate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return new Direct$Type$Buffer$RW$$BO$(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                                              this.markValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                                              this.position(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                                              this.limit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                                              this.capacity(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                                              0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public $Type$Buffer asReadOnlyBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return new Direct$Type$BufferR$BO$(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                                           this.markValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                                           this.position(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                                           this.limit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                                           this.capacity(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                                           0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        return duplicate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public long address() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    private long ix(int i) {
33300
bb014fdf246b 8130891: (bf) More direct buffering
bpb
parents: 31873
diff changeset
   261
        return address + ((long)i << $LG_BYTES_PER_VALUE$);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public $type$ get() {
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   265
        try {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   266
            return $fromBits$($swap$(UNSAFE.get$Swaptype$(ix(nextGetIndex()))));
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   267
        } finally {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   268
            Reference.reachabilityFence(this);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   269
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public $type$ get(int i) {
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   273
        try {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   274
            return $fromBits$($swap$(UNSAFE.get$Swaptype$(ix(checkIndex(i)))));
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   275
        } finally {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   276
            Reference.reachabilityFence(this);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   277
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
17922
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 10325
diff changeset
   280
#if[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 10325
diff changeset
   281
    $type$ getUnchecked(int i) {
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   282
        try {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   283
            return $fromBits$($swap$(UNSAFE.get$Swaptype$(ix(i))));
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   284
        } finally {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   285
            Reference.reachabilityFence(this);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   286
        }
17922
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 10325
diff changeset
   287
    }
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 10325
diff changeset
   288
#end[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 10325
diff changeset
   289
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public $Type$Buffer get($type$[] dst, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
#if[rw]
33300
bb014fdf246b 8130891: (bf) More direct buffering
bpb
parents: 31873
diff changeset
   292
        if (((long)length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_TO_ARRAY_THRESHOLD) {
54151
d2f8b7b33013 8219876: (bf) Improve IndexOutOfBoundsException messages in $Type$Buffer classes
bpb
parents: 54129
diff changeset
   293
            Objects.checkFromIndexSize(offset, length, dst.length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            int pos = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            int lim = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            int rem = (pos <= lim ? lim - pos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            if (length > rem)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                throw new BufferUnderflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   301
            long dstOffset = ARRAY_BASE_OFFSET + ((long)offset << $LG_BYTES_PER_VALUE$);
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   302
            try {
1151
4070cecdb99d 6570619: (bf) DirectByteBuffer.get/put(byte[]) does not scale well
alanb
parents: 1143
diff changeset
   303
#if[!byte]
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   304
                if (order() != ByteOrder.nativeOrder())
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   305
                    UNSAFE.copySwapMemory(null,
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   306
                                          ix(pos),
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   307
                                          dst,
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   308
                                          dstOffset,
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   309
                                          (long)length << $LG_BYTES_PER_VALUE$,
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   310
                                          (long)1 << $LG_BYTES_PER_VALUE$);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   311
                else
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   312
#end[!byte]
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   313
                    UNSAFE.copyMemory(null,
36222
dfed693e648b 8149596: Remove java.nio.Bits copy wrapper methods
mikael
parents: 35641
diff changeset
   314
                                      ix(pos),
dfed693e648b 8149596: Remove java.nio.Bits copy wrapper methods
mikael
parents: 35641
diff changeset
   315
                                      dst,
dfed693e648b 8149596: Remove java.nio.Bits copy wrapper methods
mikael
parents: 35641
diff changeset
   316
                                      dstOffset,
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   317
                                      (long)length << $LG_BYTES_PER_VALUE$);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   318
            } finally {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   319
                Reference.reachabilityFence(this);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   320
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            position(pos + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            super.get(dst, offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
53855
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   331
    public $Type$Buffer get(int index, $type$[] dst, int offset, int length) {
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   332
#if[rw]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   333
        if (((long)length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_TO_ARRAY_THRESHOLD) {
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   334
            Objects.checkFromIndexSize(index, length, limit());
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   335
            Objects.checkFromIndexSize(offset, length, dst.length);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   336
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   337
            long dstOffset = ARRAY_BASE_OFFSET + ((long)offset << $LG_BYTES_PER_VALUE$);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   338
            try {
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   339
#if[!byte]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   340
                if (order() != ByteOrder.nativeOrder())
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   341
                    UNSAFE.copySwapMemory(null,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   342
                                          ix(index),
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   343
                                          dst,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   344
                                          dstOffset,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   345
                                          (long)length << $LG_BYTES_PER_VALUE$,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   346
                                          (long)1 << $LG_BYTES_PER_VALUE$);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   347
                else
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   348
#end[!byte]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   349
                    UNSAFE.copyMemory(null,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   350
                                      ix(index),
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   351
                                      dst,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   352
                                      dstOffset,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   353
                                      (long)length << $LG_BYTES_PER_VALUE$);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   354
            } finally {
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   355
                Reference.reachabilityFence(this);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   356
            }
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   357
        } else {
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   358
            super.get(index, dst, offset, length);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   359
        }
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   360
        return this;
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   361
#else[rw]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   362
        throw new ReadOnlyBufferException();
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   363
#end[rw]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   364
    }
2
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
    public $Type$Buffer put($type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
#if[rw]
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   369
        try {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   370
            UNSAFE.put$Swaptype$(ix(nextPutIndex()), $swap$($toBits$(x)));
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   371
        } finally {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   372
            Reference.reachabilityFence(this);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   373
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    public $Type$Buffer put(int i, $type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
#if[rw]
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   382
        try {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   383
            UNSAFE.put$Swaptype$(ix(checkIndex(i)), $swap$($toBits$(x)));
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   384
        } finally {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   385
            Reference.reachabilityFence(this);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   386
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    public $Type$Buffer put($Type$Buffer src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        if (src instanceof Direct$Type$Buffer$BO$) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            if (src == this)
31873
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 25859
diff changeset
   397
                throw createSameBufferException();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            Direct$Type$Buffer$RW$$BO$ sb = (Direct$Type$Buffer$RW$$BO$)src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            int spos = sb.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            int slim = sb.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            assert (spos <= slim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            int srem = (spos <= slim ? slim - spos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            int pos = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            int lim = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            int rem = (pos <= lim ? lim - pos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            if (srem > rem)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                throw new BufferOverflowException();
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   412
            try {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   413
                UNSAFE.copyMemory(sb.ix(spos), ix(pos), (long)srem << $LG_BYTES_PER_VALUE$);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   414
            } finally {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   415
                Reference.reachabilityFence(sb);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   416
                Reference.reachabilityFence(this);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   417
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            sb.position(spos + srem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            position(pos + srem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        } else if (src.hb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            int spos = src.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            int slim = src.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            assert (spos <= slim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            int srem = (spos <= slim ? slim - spos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            put(src.hb, src.offset + spos, srem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            src.position(spos + srem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            super.put(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        throw new ReadOnlyBufferException();
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    public $Type$Buffer put($type$[] src, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
#if[rw]
33300
bb014fdf246b 8130891: (bf) More direct buffering
bpb
parents: 31873
diff changeset
   441
        if (((long)length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_FROM_ARRAY_THRESHOLD) {
54151
d2f8b7b33013 8219876: (bf) Improve IndexOutOfBoundsException messages in $Type$Buffer classes
bpb
parents: 54129
diff changeset
   442
            Objects.checkFromIndexSize(offset, length, src.length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            int pos = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            int lim = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            int rem = (pos <= lim ? lim - pos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            if (length > rem)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   450
            long srcOffset = ARRAY_BASE_OFFSET + ((long)offset << $LG_BYTES_PER_VALUE$);
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   451
            try {
1151
4070cecdb99d 6570619: (bf) DirectByteBuffer.get/put(byte[]) does not scale well
alanb
parents: 1143
diff changeset
   452
#if[!byte]
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   453
                if (order() != ByteOrder.nativeOrder())
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   454
                    UNSAFE.copySwapMemory(src,
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   455
                                          srcOffset,
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   456
                                          null,
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   457
                                          ix(pos),
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   458
                                          (long)length << $LG_BYTES_PER_VALUE$,
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   459
                                          (long)1 << $LG_BYTES_PER_VALUE$);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   460
                else
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   461
#end[!byte]
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   462
                    UNSAFE.copyMemory(src,
36222
dfed693e648b 8149596: Remove java.nio.Bits copy wrapper methods
mikael
parents: 35641
diff changeset
   463
                                      srcOffset,
dfed693e648b 8149596: Remove java.nio.Bits copy wrapper methods
mikael
parents: 35641
diff changeset
   464
                                      null,
dfed693e648b 8149596: Remove java.nio.Bits copy wrapper methods
mikael
parents: 35641
diff changeset
   465
                                      ix(pos),
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   466
                                      (long)length << $LG_BYTES_PER_VALUE$);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   467
            } finally {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   468
                Reference.reachabilityFence(this);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   469
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            position(pos + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            super.put(src, offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
53855
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   480
    public $Type$Buffer put(int index, $type$[] src, int offset, int length) {
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   481
#if[rw]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   482
        if (((long)length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_FROM_ARRAY_THRESHOLD) {
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   483
            Objects.checkFromIndexSize(index, length, limit());
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   484
            Objects.checkFromIndexSize(offset, length, src.length);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   485
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   486
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   487
            long srcOffset = ARRAY_BASE_OFFSET + ((long)offset << $LG_BYTES_PER_VALUE$);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   488
            try {
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   489
#if[!byte]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   490
                if (order() != ByteOrder.nativeOrder())
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   491
                    UNSAFE.copySwapMemory(src,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   492
                                          srcOffset,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   493
                                          null,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   494
                                          ix(index),
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   495
                                          (long)length << $LG_BYTES_PER_VALUE$,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   496
                                          (long)1 << $LG_BYTES_PER_VALUE$);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   497
                else
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   498
#end[!byte]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   499
                    UNSAFE.copyMemory(src,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   500
                                      srcOffset,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   501
                                      null,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   502
                                      ix(index),
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   503
                                      (long)length << $LG_BYTES_PER_VALUE$);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   504
            } finally {
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   505
                Reference.reachabilityFence(this);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   506
            }
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   507
        } else {
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   508
            super.put(index, src, offset, length);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   509
        }
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   510
        return this;
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   511
#else[rw]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   512
        throw new ReadOnlyBufferException();
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   513
#end[rw]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   514
    }
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   515
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    public $Type$Buffer compact() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        int pos = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        int lim = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        int rem = (pos <= lim ? lim - pos : 0);
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   522
        try {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   523
            UNSAFE.copyMemory(ix(pos), ix(0), (long)rem << $LG_BYTES_PER_VALUE$);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   524
        } finally {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   525
            Reference.reachabilityFence(this);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   526
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        position(rem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        limit(capacity());
1634
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 1247
diff changeset
   529
        discardMark();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    public boolean isDirect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    public boolean isReadOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        return {#if[rw]?false:true};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    public String toString(int start, int end) {
54151
d2f8b7b33013 8219876: (bf) Improve IndexOutOfBoundsException messages in $Type$Buffer classes
bpb
parents: 54129
diff changeset
   548
        Objects.checkFromToIndex(start, end, limit());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            int len = end - start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            char[] ca = new char[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            CharBuffer cb = CharBuffer.wrap(ca);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            CharBuffer db = this.duplicate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            db.position(start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            db.limit(end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            cb.put(db);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            return new String(ca);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        } catch (StringIndexOutOfBoundsException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    // --- Methods to support CharSequence ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
1224
8c1bc7c5dd00 6733145: (bf) CharBuffer.subSequence can be updated to take advantage of covariant returns
martin
parents: 1151
diff changeset
   566
    public CharBuffer subSequence(int start, int end) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        int pos = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        int lim = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        pos = (pos <= lim ? pos : lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        int len = lim - pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
54151
d2f8b7b33013 8219876: (bf) Improve IndexOutOfBoundsException messages in $Type$Buffer classes
bpb
parents: 54129
diff changeset
   573
        Objects.checkFromToIndex(start, end, len);
2593
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   574
        return new DirectCharBuffer$RW$$BO$(this,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   575
                                            -1,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   576
                                            pos + start,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   577
                                            pos + end,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   578
                                            capacity(),
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   579
                                            offset);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
#if[!byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    public ByteOrder order() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
#if[boS]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        return ((ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
#end[boS]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
#if[boU]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        return ((ByteOrder.nativeOrder() != ByteOrder.BIG_ENDIAN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
#end[boU]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
#end[!byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   601
#if[char]
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   602
    ByteOrder charRegionOrder() {
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   603
        return order();
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   604
    }
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   605
#end[char]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    // #BIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    // Binary-data access methods  for short, char, int, long, float,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    // and double will be inserted here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
}