Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4428189

(bf) View buffers sometimes marked incorrectly as non-direct

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: vrR10176 Date: 03/21/2001



      Api spec says about a view buffer (class java.nio.ByteBuffer):

      "A view buffer is potentially much more efficient because it will
      be direct if, and only if, its backing byte buffer is direct."

      But JVM (jdk1.4.0beta-b56) incorrectly creates in some cases
      non-direct view buffers, while its backing byte buffer is direct.

      For example,

      api spec says (class java.nio.IntBuffer):
      "A int buffer created as a view of a byte buffer will be direct
      if, and only if, the byte buffer itself is direct."

      and (class java.nio.ByteBuffer):
      " public abstract IntBuffer asIntBuffer()
           Creates a view of this byte buffer as an int buffer.

      The content of the new buffer will start at this buffer's current position.
      Changes to this buffer's content will be visible in the new buffer, and vice
      versa; the two buffers' position, limit, and mark values will be independent."

      If int buffer was created by asIntBuffer() method and its backing byte
      buffer is direct, this int buffer must be direct.

      But if position of backing byte buffer is 1,2,3,5,...etc (not a multiple of 4),
      then asIntBuffer() creates non-direct int buffer, if position is 0,4,...etc
      (multiple of 4), then asIntBuffer() creates direct int buffer.
      Although all these int buffers must be direct.


      Similar behavior is observed for other view buffers (ShortBuffer, FloatBuffer, ...).


      To reproduce the issue execute following test.
      ------------ test.java ------------------------
      import java.nio.*;

      public class test {
      public static void main(String argv[]) {
      ByteBuffer buf = ByteBuffer.allocateDirect(8);
      System.out.println("Byte buffer is direct: " + buf.isDirect());
      for(int i=0; i<6; i++){
      buf.position(i);
      IntBuffer intBuf = buf.asIntBuffer();
      System.out.println("Position: " + i + " Int buffer is direct: " + intBuf.isDirect());
      }
      }
      }

      ------------ Logs ------------------------
      $ java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b56)
      Java HotSpot(TM) Client VM (build 1.4-beta-B56, mixed mode)

      $javac test.java

      $java -Xfuture test
      Byte buffer is direct: true
      Position: 0 Int buffer is direct: true
      Position: 1 Int buffer is direct: false
      Position: 2 Int buffer is direct: false
      Position: 3 Int buffer is direct: false
      Position: 4 Int buffer is direct: true
      Position: 5 Int buffer is direct: false

      ------------------------------------------


      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            iris Iris Clark
            Reporter:
            rslasunw Rsla Rsla (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: