jdk/src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template
changeset 36933 3e6453e2d833
parent 33665 0599d4cde183
child 40195 a13e4945de1d
equal deleted inserted replaced
36930:74e9f4b90006 36933:3e6453e2d833
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    72         */
    72         */
    73 #else[rw]
    73 #else[rw]
    74         super(cap, lim);
    74         super(cap, lim);
    75         this.isReadOnly = true;
    75         this.isReadOnly = true;
    76 #end[rw]
    76 #end[rw]
       
    77 #if[byte]
       
    78         this.address = arrayBaseOffset;
       
    79 #end[byte]
    77     }
    80     }
    78 
    81 
    79     Heap$Type$Buffer$RW$($type$[] buf, int off, int len) { // package-private
    82     Heap$Type$Buffer$RW$($type$[] buf, int off, int len) { // package-private
    80 #if[rw]
    83 #if[rw]
    81         super(-1, off, off + len, buf.length, buf, 0);
    84         super(-1, off, off + len, buf.length, buf, 0);
    85         */
    88         */
    86 #else[rw]
    89 #else[rw]
    87         super(buf, off, len);
    90         super(buf, off, len);
    88         this.isReadOnly = true;
    91         this.isReadOnly = true;
    89 #end[rw]
    92 #end[rw]
       
    93 #if[byte]
       
    94         this.address = arrayBaseOffset;
       
    95 #end[byte]
    90     }
    96     }
    91 
    97 
    92     protected Heap$Type$Buffer$RW$($type$[] buf,
    98     protected Heap$Type$Buffer$RW$($type$[] buf,
    93                                    int mark, int pos, int lim, int cap,
    99                                    int mark, int pos, int lim, int cap,
    94                                    int off)
   100                                    int off)
   101         */
   107         */
   102 #else[rw]
   108 #else[rw]
   103         super(buf, mark, pos, lim, cap, off);
   109         super(buf, mark, pos, lim, cap, off);
   104         this.isReadOnly = true;
   110         this.isReadOnly = true;
   105 #end[rw]
   111 #end[rw]
       
   112 #if[byte]
       
   113         this.address = arrayBaseOffset + off;
       
   114 #end[byte]
   106     }
   115     }
   107 
   116 
   108     public $Type$Buffer slice() {
   117     public $Type$Buffer slice() {
   109         return new Heap$Type$Buffer$RW$(hb,
   118         return new Heap$Type$Buffer$RW$(hb,
   110                                         -1,
   119                                         -1,
   112                                         this.remaining(),
   121                                         this.remaining(),
   113                                         this.remaining(),
   122                                         this.remaining(),
   114                                         this.position() + offset);
   123                                         this.position() + offset);
   115     }
   124     }
   116 
   125 
       
   126 #if[byte]
       
   127     $Type$Buffer slice(int pos, int lim) {
       
   128         assert (pos >= 0);
       
   129         assert (pos <= lim);
       
   130         int rem = lim - pos;
       
   131         return new Heap$Type$Buffer$RW$(hb,
       
   132                                         -1,
       
   133                                         0,
       
   134                                         rem,
       
   135                                         rem,
       
   136                                         pos + offset);
       
   137     }
       
   138 #end[byte]
       
   139 
   117     public $Type$Buffer duplicate() {
   140     public $Type$Buffer duplicate() {
   118         return new Heap$Type$Buffer$RW$(hb,
   141         return new Heap$Type$Buffer$RW$(hb,
   119                                         this.markValue(),
   142                                         this.markValue(),
   120                                         this.position(),
   143                                         this.position(),
   121                                         this.limit(),
   144                                         this.limit(),
   142         return i + offset;
   165         return i + offset;
   143     }
   166     }
   144 
   167 
   145 #if[byte]
   168 #if[byte]
   146     private long byteOffset(long i) {
   169     private long byteOffset(long i) {
   147         return arrayBaseOffset + i + offset;
   170         return address + i;
   148     }
   171     }
   149 #end[byte]
   172 #end[byte]
   150 
   173 
   151     public $type$ get() {
   174     public $type$ get() {
   152         return hb[ix(nextGetIndex())];
   175         return hb[ix(nextGetIndex())];