1. /*
  2. * @(#)Direct-X-Buffer.java 1.45 03/04/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. // -- This file was mechanically generated: Do not edit! -- //
  8. package java.nio;
  9. import sun.misc.Cleaner;
  10. import sun.misc.Unsafe;
  11. import sun.nio.ch.DirectBuffer;
  12. import sun.nio.ch.FileChannelImpl;
  13. class DirectFloatBufferU
  14. extends FloatBuffer
  15. implements DirectBuffer
  16. {
  17. // Cached unsafe-access object
  18. protected static final Unsafe unsafe = Bits.unsafe();
  19. // Cached unaligned-access capability
  20. protected static final boolean unaligned = Bits.unaligned();
  21. // Base address, used in all indexing calculations
  22. // NOTE: moved up to Buffer.java for speed in JNI GetDirectBufferAddress
  23. // protected long address;
  24. // If this buffer is a view of another buffer then we keep a reference to
  25. // that buffer so that its memory isn't freed before we're done with it
  26. protected Object viewedBuffer = null;
  27. public Object viewedBuffer() {
  28. return viewedBuffer;
  29. }
  30. public Cleaner cleaner() { return null; }
  31. // For duplicates and slices
  32. //
  33. DirectFloatBufferU(DirectBuffer db, // package-private
  34. int mark, int pos, int lim, int cap,
  35. int off)
  36. {
  37. super(mark, pos, lim, cap);
  38. address = db.address() + off;
  39. viewedBuffer = db;
  40. }
  41. public FloatBuffer slice() {
  42. int pos = this.position();
  43. int lim = this.limit();
  44. assert (pos <= lim);
  45. int rem = (pos <= lim ? lim - pos : 0);
  46. int off = (pos << 2);
  47. return new DirectFloatBufferU(this, -1, 0, rem, rem, off);
  48. }
  49. public FloatBuffer duplicate() {
  50. return new DirectFloatBufferU(this,
  51. this.markValue(),
  52. this.position(),
  53. this.limit(),
  54. this.capacity(),
  55. 0);
  56. }
  57. public FloatBuffer asReadOnlyBuffer() {
  58. return new DirectFloatBufferRU(this,
  59. this.markValue(),
  60. this.position(),
  61. this.limit(),
  62. this.capacity(),
  63. 0);
  64. }
  65. public long address() {
  66. return address;
  67. }
  68. private long ix(int i) {
  69. return address + (i << 2);
  70. }
  71. public float get() {
  72. return ((unsafe.getFloat(ix(nextGetIndex()))));
  73. }
  74. public float get(int i) {
  75. return ((unsafe.getFloat(ix(checkIndex(i)))));
  76. }
  77. public FloatBuffer get(float[] dst, int offset, int length) {
  78. if ((length << 2) > Bits.JNI_COPY_TO_ARRAY_THRESHOLD) {
  79. checkBounds(offset, length, dst.length);
  80. int pos = position();
  81. int lim = limit();
  82. assert (pos <= lim);
  83. int rem = (pos <= lim ? lim - pos : 0);
  84. if (length > rem)
  85. throw new BufferUnderflowException();
  86. if (order() != ByteOrder.nativeOrder())
  87. Bits.copyToIntArray(ix(pos), dst,
  88. offset << 2,
  89. length << 2);
  90. else
  91. Bits.copyToByteArray(ix(pos), dst,
  92. offset << 2,
  93. length << 2);
  94. position(pos + length);
  95. } else {
  96. super.get(dst, offset, length);
  97. }
  98. return this;
  99. }
  100. public FloatBuffer put(float x) {
  101. unsafe.putFloat(ix(nextPutIndex()), ((x)));
  102. return this;
  103. }
  104. public FloatBuffer put(int i, float x) {
  105. unsafe.putFloat(ix(checkIndex(i)), ((x)));
  106. return this;
  107. }
  108. public FloatBuffer put(FloatBuffer src) {
  109. if (src instanceof DirectFloatBufferU) {
  110. if (src == this)
  111. throw new IllegalArgumentException();
  112. DirectFloatBufferU sb = (DirectFloatBufferU)src;
  113. int spos = sb.position();
  114. int slim = sb.limit();
  115. assert (spos <= slim);
  116. int srem = (spos <= slim ? slim - spos : 0);
  117. int pos = position();
  118. int lim = limit();
  119. assert (pos <= lim);
  120. int rem = (pos <= lim ? lim - pos : 0);
  121. if (srem > rem)
  122. throw new BufferOverflowException();
  123. unsafe.copyMemory(sb.ix(spos), ix(pos), srem << 2);
  124. sb.position(spos + srem);
  125. position(pos + srem);
  126. } else if (!src.isDirect()) {
  127. int spos = src.position();
  128. int slim = src.limit();
  129. assert (spos <= slim);
  130. int srem = (spos <= slim ? slim - spos : 0);
  131. put(src.hb, src.offset + spos, srem);
  132. src.position(spos + srem);
  133. } else {
  134. super.put(src);
  135. }
  136. return this;
  137. }
  138. public FloatBuffer put(float[] src, int offset, int length) {
  139. if ((length << 2) > Bits.JNI_COPY_FROM_ARRAY_THRESHOLD) {
  140. checkBounds(offset, length, src.length);
  141. int pos = position();
  142. int lim = limit();
  143. assert (pos <= lim);
  144. int rem = (pos <= lim ? lim - pos : 0);
  145. if (length > rem)
  146. throw new BufferOverflowException();
  147. if (order() != ByteOrder.nativeOrder())
  148. Bits.copyFromIntArray(src, offset << 2,
  149. ix(pos), length << 2);
  150. else
  151. Bits.copyFromByteArray(src, offset << 2,
  152. ix(pos), length << 2);
  153. position(pos + length);
  154. } else {
  155. super.put(src, offset, length);
  156. }
  157. return this;
  158. }
  159. public FloatBuffer compact() {
  160. int pos = position();
  161. int lim = limit();
  162. assert (pos <= lim);
  163. int rem = (pos <= lim ? lim - pos : 0);
  164. unsafe.copyMemory(ix(pos), ix(0), rem << 2);
  165. position(rem);
  166. limit(capacity());
  167. return this;
  168. }
  169. public boolean isDirect() {
  170. return true;
  171. }
  172. public boolean isReadOnly() {
  173. return false;
  174. }
  175. public ByteOrder order() {
  176. return ((ByteOrder.nativeOrder() != ByteOrder.BIG_ENDIAN)
  177. ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
  178. }
  179. }