1 /*
   2  * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #warn This file is preprocessed before being compiled
  27 
  28 class XXX {
  29 
  30 #begin
  31 
  32 #if[rw]
  33 
  34     private $type$ get$Type$(long a) {
  35         try {
  36             $memtype$ x = UNSAFE.get$Memtype$Unaligned(null, a, bigEndian);
  37             return $fromBits$(x);
  38         } finally {
  39             Reference.reachabilityFence(this);
  40         }
  41     }
  42 
  43     public $type$ get$Type$() {
  44         try {
  45             return get$Type$(ix(nextGetIndex($BYTES_PER_VALUE$)));
  46         } finally {
  47             Reference.reachabilityFence(this);
  48         }
  49     }
  50 
  51     public $type$ get$Type$(int i) {
  52         try {
  53             return get$Type$(ix(checkIndex(i, $BYTES_PER_VALUE$)));
  54         } finally {
  55             Reference.reachabilityFence(this);
  56         }
  57     }
  58 
  59 #end[rw]
  60 
  61     private ByteBuffer put$Type$(long a, $type$ x) {
  62 #if[rw]
  63         try {
  64             $memtype$ y = $toBits$(x);
  65             UNSAFE.put$Memtype$Unaligned(null, a, y, bigEndian);
  66         } finally {
  67             Reference.reachabilityFence(this);
  68         }
  69         return this;
  70 #else[rw]
  71         throw new ReadOnlyBufferException();
  72 #end[rw]
  73     }
  74 
  75     public ByteBuffer put$Type$($type$ x) {
  76 #if[rw]
  77         put$Type$(ix(nextPutIndex($BYTES_PER_VALUE$)), x);
  78         return this;
  79 #else[rw]
  80         throw new ReadOnlyBufferException();
  81 #end[rw]
  82     }
  83 
  84     public ByteBuffer put$Type$(int i, $type$ x) {
  85 #if[rw]
  86         put$Type$(ix(checkIndex(i, $BYTES_PER_VALUE$)), x);
  87         return this;
  88 #else[rw]
  89         throw new ReadOnlyBufferException();
  90 #end[rw]
  91     }
  92 
  93     public $Type$Buffer as$Type$Buffer() {
  94         int off = this.position();
  95         int lim = this.limit();
  96         assert (off <= lim);
  97         int rem = (off <= lim ? lim - off : 0);
  98 
  99         int size = rem >> $LG_BYTES_PER_VALUE$;
 100         if (!UNALIGNED && ((address + off) % $BYTES_PER_VALUE$ != 0)) {
 101             return (bigEndian
 102                     ? ($Type$Buffer)(new ByteBufferAs$Type$Buffer$RW$B(this,
 103                                                                        -1,
 104                                                                        0,
 105                                                                        size,
 106                                                                        size,
 107                                                                        address + off))
 108                     : ($Type$Buffer)(new ByteBufferAs$Type$Buffer$RW$L(this,
 109                                                                        -1,
 110                                                                        0,
 111                                                                        size,
 112                                                                        size,
 113                                                                        address + off)));
 114         } else {
 115             return (nativeByteOrder
 116                     ? ($Type$Buffer)(new Direct$Type$Buffer$RW$U(this,
 117                                                                  -1,
 118                                                                  0,
 119                                                                  size,
 120                                                                  size,
 121                                                                  off))
 122                     : ($Type$Buffer)(new Direct$Type$Buffer$RW$S(this,
 123                                                                  -1,
 124                                                                  0,
 125                                                                  size,
 126                                                                  size,
 127                                                                  off)));
 128         }
 129     }
 130 
 131 #end
 132 
 133 }