src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template
author bpb
Thu, 28 Feb 2019 12:05:59 -0800
changeset 53959 1542e63eb537
parent 53855 7c362992527a
child 54129 deb99f13c6cd
permissions -rw-r--r--
5071718: (bf) Add ByteBuffer.slice(int offset, int length) Reviewed-by: alanb, bchristi, darcy, 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) {
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53855
diff changeset
   223
        Objects.checkIndex(index, limit() + 1);
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53855
diff changeset
   224
        Objects.checkIndex(length, limit() - index + 1);
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53855
diff changeset
   225
        return new Direct$Type$Buffer$RW$$BO$(this,
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53855
diff changeset
   226
                                              -1,
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53855
diff changeset
   227
                                              0,
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
                                              length,
1542e63eb537 5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents: 53855
diff changeset
   230
                                              index);
36933
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 36222
diff changeset
   231
    }
3e6453e2d833 8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents: 36222
diff changeset
   232
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public $Type$Buffer duplicate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return new Direct$Type$Buffer$RW$$BO$(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                                              this.markValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                                              this.position(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                                              this.limit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                                              this.capacity(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                                              0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public $Type$Buffer asReadOnlyBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return new Direct$Type$BufferR$BO$(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                                           this.markValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                                           this.position(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                                           this.limit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                                           this.capacity(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                                           0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return duplicate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public long address() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    private long ix(int i) {
33300
bb014fdf246b 8130891: (bf) More direct buffering
bpb
parents: 31873
diff changeset
   262
        return address + ((long)i << $LG_BYTES_PER_VALUE$);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public $type$ get() {
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   266
        try {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   267
            return $fromBits$($swap$(UNSAFE.get$Swaptype$(ix(nextGetIndex()))));
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   268
        } finally {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   269
            Reference.reachabilityFence(this);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   270
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public $type$ get(int i) {
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   274
        try {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   275
            return $fromBits$($swap$(UNSAFE.get$Swaptype$(ix(checkIndex(i)))));
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   276
        } finally {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   277
            Reference.reachabilityFence(this);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   278
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
17922
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 10325
diff changeset
   281
#if[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 10325
diff changeset
   282
    $type$ getUnchecked(int i) {
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   283
        try {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   284
            return $fromBits$($swap$(UNSAFE.get$Swaptype$(ix(i))));
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   285
        } finally {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   286
            Reference.reachabilityFence(this);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   287
        }
17922
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 10325
diff changeset
   288
    }
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 10325
diff changeset
   289
#end[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 10325
diff changeset
   290
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public $Type$Buffer get($type$[] dst, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
#if[rw]
33300
bb014fdf246b 8130891: (bf) More direct buffering
bpb
parents: 31873
diff changeset
   293
        if (((long)length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_TO_ARRAY_THRESHOLD) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            checkBounds(offset, length, dst.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            int pos = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            int lim = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            int rem = (pos <= lim ? lim - pos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            if (length > rem)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                throw new BufferUnderflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   302
            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
   303
            try {
1151
4070cecdb99d 6570619: (bf) DirectByteBuffer.get/put(byte[]) does not scale well
alanb
parents: 1143
diff changeset
   304
#if[!byte]
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   305
                if (order() != ByteOrder.nativeOrder())
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   306
                    UNSAFE.copySwapMemory(null,
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   307
                                          ix(pos),
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   308
                                          dst,
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   309
                                          dstOffset,
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   310
                                          (long)length << $LG_BYTES_PER_VALUE$,
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   311
                                          (long)1 << $LG_BYTES_PER_VALUE$);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   312
                else
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   313
#end[!byte]
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   314
                    UNSAFE.copyMemory(null,
36222
dfed693e648b 8149596: Remove java.nio.Bits copy wrapper methods
mikael
parents: 35641
diff changeset
   315
                                      ix(pos),
dfed693e648b 8149596: Remove java.nio.Bits copy wrapper methods
mikael
parents: 35641
diff changeset
   316
                                      dst,
dfed693e648b 8149596: Remove java.nio.Bits copy wrapper methods
mikael
parents: 35641
diff changeset
   317
                                      dstOffset,
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   318
                                      (long)length << $LG_BYTES_PER_VALUE$);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   319
            } finally {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   320
                Reference.reachabilityFence(this);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   321
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            position(pos + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            super.get(dst, offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
53855
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   332
    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
   333
#if[rw]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   334
        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
   335
            Objects.checkFromIndexSize(index, length, limit());
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   336
            Objects.checkFromIndexSize(offset, length, dst.length);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   337
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   338
            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
   339
            try {
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   340
#if[!byte]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   341
                if (order() != ByteOrder.nativeOrder())
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   342
                    UNSAFE.copySwapMemory(null,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   343
                                          ix(index),
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   344
                                          dst,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   345
                                          dstOffset,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   346
                                          (long)length << $LG_BYTES_PER_VALUE$,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   347
                                          (long)1 << $LG_BYTES_PER_VALUE$);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   348
                else
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   349
#end[!byte]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   350
                    UNSAFE.copyMemory(null,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   351
                                      ix(index),
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   352
                                      dst,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   353
                                      dstOffset,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   354
                                      (long)length << $LG_BYTES_PER_VALUE$);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   355
            } finally {
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   356
                Reference.reachabilityFence(this);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   357
            }
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   358
        } else {
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   359
            super.get(index, dst, offset, length);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   360
        }
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   361
        return this;
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   362
#else[rw]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   363
        throw new ReadOnlyBufferException();
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   364
#end[rw]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   365
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    public $Type$Buffer put($type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
#if[rw]
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   370
        try {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   371
            UNSAFE.put$Swaptype$(ix(nextPutIndex()), $swap$($toBits$(x)));
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   372
        } finally {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   373
            Reference.reachabilityFence(this);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   374
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public $Type$Buffer put(int i, $type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
#if[rw]
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   383
        try {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   384
            UNSAFE.put$Swaptype$(ix(checkIndex(i)), $swap$($toBits$(x)));
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   385
        } finally {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   386
            Reference.reachabilityFence(this);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   387
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    public $Type$Buffer put($Type$Buffer src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        if (src instanceof Direct$Type$Buffer$BO$) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            if (src == this)
31873
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 25859
diff changeset
   398
                throw createSameBufferException();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            Direct$Type$Buffer$RW$$BO$ sb = (Direct$Type$Buffer$RW$$BO$)src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            int spos = sb.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            int slim = sb.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            assert (spos <= slim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            int srem = (spos <= slim ? slim - spos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            int pos = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            int lim = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            int rem = (pos <= lim ? lim - pos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            if (srem > rem)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                throw new BufferOverflowException();
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   413
            try {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   414
                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
   415
            } finally {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   416
                Reference.reachabilityFence(sb);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   417
                Reference.reachabilityFence(this);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   418
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            sb.position(spos + srem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            position(pos + srem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        } else if (src.hb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            int spos = src.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            int slim = src.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            assert (spos <= slim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            int srem = (spos <= slim ? slim - spos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            put(src.hb, src.offset + spos, srem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            src.position(spos + srem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            super.put(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public $Type$Buffer put($type$[] src, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
#if[rw]
33300
bb014fdf246b 8130891: (bf) More direct buffering
bpb
parents: 31873
diff changeset
   442
        if (((long)length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_FROM_ARRAY_THRESHOLD) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            checkBounds(offset, length, src.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            int pos = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            int lim = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            int rem = (pos <= lim ? lim - pos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            if (length > rem)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   451
            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
   452
            try {
1151
4070cecdb99d 6570619: (bf) DirectByteBuffer.get/put(byte[]) does not scale well
alanb
parents: 1143
diff changeset
   453
#if[!byte]
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   454
                if (order() != ByteOrder.nativeOrder())
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   455
                    UNSAFE.copySwapMemory(src,
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   456
                                          srcOffset,
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   457
                                          null,
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   458
                                          ix(pos),
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   459
                                          (long)length << $LG_BYTES_PER_VALUE$,
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   460
                                          (long)1 << $LG_BYTES_PER_VALUE$);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   461
                else
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   462
#end[!byte]
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   463
                    UNSAFE.copyMemory(src,
36222
dfed693e648b 8149596: Remove java.nio.Bits copy wrapper methods
mikael
parents: 35641
diff changeset
   464
                                      srcOffset,
dfed693e648b 8149596: Remove java.nio.Bits copy wrapper methods
mikael
parents: 35641
diff changeset
   465
                                      null,
dfed693e648b 8149596: Remove java.nio.Bits copy wrapper methods
mikael
parents: 35641
diff changeset
   466
                                      ix(pos),
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   467
                                      (long)length << $LG_BYTES_PER_VALUE$);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   468
            } finally {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   469
                Reference.reachabilityFence(this);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   470
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            position(pos + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            super.put(src, offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
53855
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   481
    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
   482
#if[rw]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   483
        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
   484
            Objects.checkFromIndexSize(index, length, limit());
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   485
            Objects.checkFromIndexSize(offset, length, src.length);
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
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   488
            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
   489
            try {
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   490
#if[!byte]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   491
                if (order() != ByteOrder.nativeOrder())
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   492
                    UNSAFE.copySwapMemory(src,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   493
                                          srcOffset,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   494
                                          null,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   495
                                          ix(index),
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   496
                                          (long)length << $LG_BYTES_PER_VALUE$,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   497
                                          (long)1 << $LG_BYTES_PER_VALUE$);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   498
                else
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   499
#end[!byte]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   500
                    UNSAFE.copyMemory(src,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   501
                                      srcOffset,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   502
                                      null,
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   503
                                      ix(index),
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   504
                                      (long)length << $LG_BYTES_PER_VALUE$);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   505
            } finally {
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   506
                Reference.reachabilityFence(this);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   507
            }
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   508
        } else {
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   509
            super.put(index, src, offset, length);
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   510
        }
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   511
        return this;
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   512
#else[rw]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   513
        throw new ReadOnlyBufferException();
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   514
#end[rw]
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   515
    }
7c362992527a 5029431: (bf) Add absolute bulk put and get methods
bpb
parents: 51318
diff changeset
   516
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    public $Type$Buffer compact() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        int pos = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        int lim = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        int rem = (pos <= lim ? lim - pos : 0);
49210
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   523
        try {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   524
            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
   525
        } finally {
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   526
            Reference.reachabilityFence(this);
7c795d301dbf 8199462: Use Reference.reachabilityFence in direct ByteBuffer methods
psandoz
parents: 48356
diff changeset
   527
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        position(rem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        limit(capacity());
1634
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 1247
diff changeset
   530
        discardMark();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    public boolean isDirect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    public boolean isReadOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        return {#if[rw]?false:true};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    public String toString(int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        if ((end > limit()) || (start > end))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            int len = end - start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            char[] ca = new char[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            CharBuffer cb = CharBuffer.wrap(ca);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            CharBuffer db = this.duplicate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            db.position(start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            db.limit(end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            cb.put(db);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            return new String(ca);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        } catch (StringIndexOutOfBoundsException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    // --- Methods to support CharSequence ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
1224
8c1bc7c5dd00 6733145: (bf) CharBuffer.subSequence can be updated to take advantage of covariant returns
martin
parents: 1151
diff changeset
   568
    public CharBuffer subSequence(int start, int end) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        int pos = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        int lim = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        pos = (pos <= lim ? pos : lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        int len = lim - pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        if ((start < 0) || (end > len) || (start > end))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            throw new IndexOutOfBoundsException();
2593
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   577
        return new DirectCharBuffer$RW$$BO$(this,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   578
                                            -1,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   579
                                            pos + start,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   580
                                            pos + end,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   581
                                            capacity(),
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   582
                                            offset);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
#if[!byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    public ByteOrder order() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
#if[boS]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        return ((ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
#end[boS]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
#if[boU]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        return ((ByteOrder.nativeOrder() != ByteOrder.BIG_ENDIAN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
#end[boU]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
#end[!byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
48356
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   604
#if[char]
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   605
    ByteOrder charRegionOrder() {
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   606
        return order();
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   607
    }
29e165bdf669 8193085: Vectorize the nio Buffer equals and compareTo implementations
psandoz
parents: 47216
diff changeset
   608
#end[char]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    // #BIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    // Binary-data access methods  for short, char, int, long, float,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    // and double will be inserted here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
}