jdk/src/share/classes/java/nio/Direct-X-Buffer.java.template
author coffeys
Thu, 11 Aug 2011 12:40:24 +0100
changeset 10325 b72c20cd583a
parent 7668 d4a77089c587
child 17922 d56eec572de5
permissions -rw-r--r--
7047325: Internal API to improve management of direct buffers Reviewed-by: alanb, mduigou
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10325
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
     2
 * Copyright (c) 2000, 2011, 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;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.misc.Cleaner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.misc.Unsafe;
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 5506
diff changeset
    33
import sun.misc.VM;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.nio.ch.DirectBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
class Direct$Type$Buffer$RW$$BO$
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    extends {#if[byte]?Mapped$Type$Buffer:$Type$Buffer}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    extends Direct$Type$Buffer$BO$
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    implements DirectBuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    // Cached unsafe-access object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    protected static final Unsafe unsafe = Bits.unsafe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
1151
4070cecdb99d 6570619: (bf) DirectByteBuffer.get/put(byte[]) does not scale well
alanb
parents: 1143
diff changeset
    51
    // Cached array base offset
4070cecdb99d 6570619: (bf) DirectByteBuffer.get/put(byte[]) does not scale well
alanb
parents: 1143
diff changeset
    52
    private static final long arrayBaseOffset = (long)unsafe.arrayBaseOffset($type$[].class);
4070cecdb99d 6570619: (bf) DirectByteBuffer.get/put(byte[]) does not scale well
alanb
parents: 1143
diff changeset
    53
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    // Cached unaligned-access capability
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    protected static final boolean unaligned = Bits.unaligned();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    // Base address, used in all indexing calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // NOTE: moved up to Buffer.java for speed in JNI GetDirectBufferAddress
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    //    protected long address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
10325
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
    61
    // 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
    62
    // 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
    63
    // 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
    64
    private final Object att;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
10325
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
    66
    public Object attachment() {
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
    67
        return att;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private static class Deallocator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        implements Runnable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        private static Unsafe unsafe = Unsafe.getUnsafe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        private long address;
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    79
        private long size;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        private int capacity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    82
        private Deallocator(long address, long size, int capacity) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            assert (address != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            this.address = address;
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    85
            this.size = size;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            this.capacity = capacity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            if (address == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                // Paranoia
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            unsafe.freeMemory(address);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            address = 0;
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    96
            Bits.unreserveMemory(size, capacity);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private final Cleaner cleaner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public Cleaner cleaner() { return cleaner; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
#else[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public Cleaner cleaner() { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    // Primary constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    Direct$Type$Buffer$RW$(int cap) {                   // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
#if[rw]
7025
6e002f9a2899 6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents: 6902
diff changeset
   119
        super(-1, 0, cap, cap);
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 5506
diff changeset
   120
        boolean pa = VM.isDirectMemoryPageAligned();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        int ps = Bits.pageSize();
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 5506
diff changeset
   122
        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
   123
        Bits.reserveMemory(size, cap);
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
   124
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        long base = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        try {
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
   127
            base = unsafe.allocateMemory(size);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        } catch (OutOfMemoryError x) {
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
   129
            Bits.unreserveMemory(size, cap);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            throw x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
   132
        unsafe.setMemory(base, size, (byte) 0);
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 5506
diff changeset
   133
        if (pa && (base % ps != 0)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            // Round up to page boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            address = base + ps - (base & (ps - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            address = base;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
   139
        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
   140
        att = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        super(cap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
10325
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   148
    // 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
   149
    // 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
   150
    //
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   151
    Direct$Type$Buffer(long addr, int cap, Object ob) {
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   152
        super(-1, 0, cap, cap);
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   153
        address = addr;
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   154
        cleaner = null;
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   155
        att = ob;
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   156
    }
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   157
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   158
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    // Invoked only by JNI: NewDirectByteBuffer(void*, long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    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
   162
        super(-1, 0, cap, cap);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        address = addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        cleaner = null;
10325
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   165
        att = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    // For memory-mapped buffers -- invoked by FileChannelImpl via reflection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    //
7025
6e002f9a2899 6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents: 6902
diff changeset
   172
    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
   173
                                     FileDescriptor fd,
6e002f9a2899 6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents: 6902
diff changeset
   174
                                     Runnable unmapper)
6e002f9a2899 6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents: 6902
diff changeset
   175
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
#if[rw]
7025
6e002f9a2899 6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents: 6902
diff changeset
   177
        super(-1, 0, cap, cap, fd);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        address = addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        cleaner = Cleaner.create(this, unmapper);
10325
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   180
        att = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
#else[rw]
7025
6e002f9a2899 6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents: 6902
diff changeset
   182
        super(cap, addr, fd, unmapper);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    // For duplicates and slices
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    Direct$Type$Buffer$RW$$BO$(DirectBuffer db,         // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                               int mark, int pos, int lim, int cap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                               int off)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        super(mark, pos, lim, cap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        address = db.address() + off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        cleaner = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
#end[byte]
10325
b72c20cd583a 7047325: Internal API to improve management of direct buffers
coffeys
parents: 7668
diff changeset
   200
        att = db;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        super(db, mark, pos, lim, cap, off);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public $Type$Buffer slice() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        int pos = this.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        int lim = this.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        int rem = (pos <= lim ? lim - pos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        int off = (pos << $LG_BYTES_PER_VALUE$);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        assert (off >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return new Direct$Type$Buffer$RW$$BO$(this, -1, 0, rem, rem, off);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public $Type$Buffer duplicate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return new Direct$Type$Buffer$RW$$BO$(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                                              this.markValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                                              this.position(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                                              this.limit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                                              this.capacity(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                                              0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public $Type$Buffer asReadOnlyBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return new Direct$Type$BufferR$BO$(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                                           this.markValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                                           this.position(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                                           this.limit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                                           this.capacity(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                                           0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return duplicate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public long address() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    private long ix(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        return address + (i << $LG_BYTES_PER_VALUE$);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public $type$ get() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return $fromBits$($swap$(unsafe.get$Swaptype$(ix(nextGetIndex()))));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public $type$ get(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return $fromBits$($swap$(unsafe.get$Swaptype$(ix(checkIndex(i)))));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public $Type$Buffer get($type$[] dst, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if ((length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_TO_ARRAY_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            checkBounds(offset, length, dst.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            int pos = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            int lim = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            int rem = (pos <= lim ? lim - pos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            if (length > rem)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                throw new BufferUnderflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
1151
4070cecdb99d 6570619: (bf) DirectByteBuffer.get/put(byte[]) does not scale well
alanb
parents: 1143
diff changeset
   267
#if[!byte]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            if (order() != ByteOrder.nativeOrder())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                Bits.copyTo$Memtype$Array(ix(pos), dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                                          offset << $LG_BYTES_PER_VALUE$,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                          length << $LG_BYTES_PER_VALUE$);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            else
1151
4070cecdb99d 6570619: (bf) DirectByteBuffer.get/put(byte[]) does not scale well
alanb
parents: 1143
diff changeset
   273
#end[!byte]
4070cecdb99d 6570619: (bf) DirectByteBuffer.get/put(byte[]) does not scale well
alanb
parents: 1143
diff changeset
   274
                Bits.copyToArray(ix(pos), dst, arrayBaseOffset,
4070cecdb99d 6570619: (bf) DirectByteBuffer.get/put(byte[]) does not scale well
alanb
parents: 1143
diff changeset
   275
                                 offset << $LG_BYTES_PER_VALUE$,
4070cecdb99d 6570619: (bf) DirectByteBuffer.get/put(byte[]) does not scale well
alanb
parents: 1143
diff changeset
   276
                                 length << $LG_BYTES_PER_VALUE$);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            position(pos + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            super.get(dst, offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public $Type$Buffer put($type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        unsafe.put$Swaptype$(ix(nextPutIndex()), $swap$($toBits$(x)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public $Type$Buffer put(int i, $type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        unsafe.put$Swaptype$(ix(checkIndex(i)), $swap$($toBits$(x)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    public $Type$Buffer put($Type$Buffer src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (src instanceof Direct$Type$Buffer$BO$) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            if (src == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            Direct$Type$Buffer$RW$$BO$ sb = (Direct$Type$Buffer$RW$$BO$)src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            int spos = sb.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            int slim = sb.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            assert (spos <= slim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            int srem = (spos <= slim ? slim - spos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            int pos = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            int lim = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            int rem = (pos <= lim ? lim - pos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            if (srem > rem)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            unsafe.copyMemory(sb.ix(spos), ix(pos), srem << $LG_BYTES_PER_VALUE$);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            sb.position(spos + srem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            position(pos + srem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        } else if (src.hb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            int spos = src.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            int slim = src.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            assert (spos <= slim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            int srem = (spos <= slim ? slim - spos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            put(src.hb, src.offset + spos, srem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            src.position(spos + srem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            super.put(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    public $Type$Buffer put($type$[] src, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        if ((length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_FROM_ARRAY_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            checkBounds(offset, length, src.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            int pos = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            int lim = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            int rem = (pos <= lim ? lim - pos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            if (length > rem)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
1151
4070cecdb99d 6570619: (bf) DirectByteBuffer.get/put(byte[]) does not scale well
alanb
parents: 1143
diff changeset
   359
#if[!byte]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            if (order() != ByteOrder.nativeOrder())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                Bits.copyFrom$Memtype$Array(src, offset << $LG_BYTES_PER_VALUE$,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                                            ix(pos), length << $LG_BYTES_PER_VALUE$);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            else
1151
4070cecdb99d 6570619: (bf) DirectByteBuffer.get/put(byte[]) does not scale well
alanb
parents: 1143
diff changeset
   364
#end[!byte]
4070cecdb99d 6570619: (bf) DirectByteBuffer.get/put(byte[]) does not scale well
alanb
parents: 1143
diff changeset
   365
                Bits.copyFromArray(src, arrayBaseOffset, offset << $LG_BYTES_PER_VALUE$,
4070cecdb99d 6570619: (bf) DirectByteBuffer.get/put(byte[]) does not scale well
alanb
parents: 1143
diff changeset
   366
                                   ix(pos), length << $LG_BYTES_PER_VALUE$);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            position(pos + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            super.put(src, offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public $Type$Buffer compact() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        int pos = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        int lim = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        int rem = (pos <= lim ? lim - pos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        unsafe.copyMemory(ix(pos), ix(0), rem << $LG_BYTES_PER_VALUE$);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        position(rem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        limit(capacity());
1634
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 1247
diff changeset
   387
        discardMark();
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 boolean isDirect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public boolean isReadOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        return {#if[rw]?false:true};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    public String toString(int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        if ((end > limit()) || (start > end))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            int len = end - start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            char[] ca = new char[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            CharBuffer cb = CharBuffer.wrap(ca);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            CharBuffer db = this.duplicate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            db.position(start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            db.limit(end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            cb.put(db);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            return new String(ca);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        } catch (StringIndexOutOfBoundsException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    // --- Methods to support CharSequence ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
1224
8c1bc7c5dd00 6733145: (bf) CharBuffer.subSequence can be updated to take advantage of covariant returns
martin
parents: 1151
diff changeset
   425
    public CharBuffer subSequence(int start, int end) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        int pos = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        int lim = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        pos = (pos <= lim ? pos : lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        int len = lim - pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        if ((start < 0) || (end > len) || (start > end))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            throw new IndexOutOfBoundsException();
2593
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   434
        return new DirectCharBuffer$RW$$BO$(this,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   435
                                            -1,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   436
                                            pos + start,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   437
                                            pos + end,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   438
                                            capacity(),
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   439
                                            offset);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
#if[!byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    public ByteOrder order() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
#if[boS]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        return ((ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
#end[boS]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
#if[boU]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        return ((ByteOrder.nativeOrder() != ByteOrder.BIG_ENDIAN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
#end[boU]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
#end[!byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    byte _get(int i) {                          // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        return unsafe.getByte(address + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    void _put(int i, byte b) {                  // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        unsafe.putByte(address + i, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    // #BIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    // Binary-data access methods  for short, char, int, long, float,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    // and double will be inserted here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
}