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 checkSegment(); 37 $memtype$ x = UNSAFE.get$Memtype$Unaligned(null, a, bigEndian); 38 return $fromBits$(x); 39 } finally { 40 Reference.reachabilityFence(this); 41 } 42 } 43 44 public $type$ get$Type$() { 45 try { 46 return get$Type$(ix(nextGetIndex($BYTES_PER_VALUE$))); 47 } finally { 48 Reference.reachabilityFence(this); 49 } 50 } 51 52 public $type$ get$Type$(int i) { 53 try { 54 return get$Type$(ix(checkIndex(i, $BYTES_PER_VALUE$))); 55 } finally { 56 Reference.reachabilityFence(this); 57 } 58 } 59 60 #end[rw] 61 62 private ByteBuffer put$Type$(long a, $type$ x) { 63 #if[rw] 64 try { 65 checkSegment(); 66 $memtype$ y = $toBits$(x); 67 UNSAFE.put$Memtype$Unaligned(null, a, y, bigEndian); 68 } finally { 69 Reference.reachabilityFence(this); 70 } 71 return this; 72 #else[rw] 73 throw new ReadOnlyBufferException(); 74 #end[rw] 75 } 76 77 public ByteBuffer put$Type$($type$ x) { 78 #if[rw] 79 put$Type$(ix(nextPutIndex($BYTES_PER_VALUE$)), x); 80 return this; 81 #else[rw] 82 throw new ReadOnlyBufferException(); 83 #end[rw] 84 } 85 86 public ByteBuffer put$Type$(int i, $type$ x) { 87 #if[rw] 88 put$Type$(ix(checkIndex(i, $BYTES_PER_VALUE$)), x); 89 return this; 90 #else[rw] 91 throw new ReadOnlyBufferException(); 92 #end[rw] 93 } 94 95 public $Type$Buffer as$Type$Buffer() { 96 int off = this.position(); 97 int lim = this.limit(); 98 assert (off <= lim); 99 int rem = (off <= lim ? lim - off : 0); 100 101 int size = rem >> $LG_BYTES_PER_VALUE$; 102 if (!UNALIGNED && ((address + off) % $BYTES_PER_VALUE$ != 0)) { 103 return (bigEndian 104 ? ($Type$Buffer)(new ByteBufferAs$Type$Buffer$RW$B(this, 105 -1, 106 0, 107 size, 108 size, 109 address + off, segment)) 110 : ($Type$Buffer)(new ByteBufferAs$Type$Buffer$RW$L(this, 111 -1, 112 0, 113 size, 114 size, 115 address + off, segment))); 116 } else { 117 return (nativeByteOrder 118 ? ($Type$Buffer)(new Direct$Type$Buffer$RW$U(this, 119 -1, 120 0, 121 size, 122 size, 123 off, segment)) 124 : ($Type$Buffer)(new Direct$Type$Buffer$RW$S(this, 125 -1, 126 0, 127 size, 128 size, 129 off, segment))); 130 } 131 } 132 133 #end 134 135 }