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

Direct{Double,Float}Buffers change values if buffer order != native order (x86)

XMLWordPrintable

    • b16
    • x86
    • linux, windows_2000



        Name: rmT116609 Date: 01/16/2003


        FULL PRODUCT VERSION :
        java version "1.4.1_01"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
        Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)

        FULL OPERATING SYSTEM VERSION :
        Microsoft Windows 2000 [Version 5.00.2195]

        ADDITIONAL OPERATING SYSTEMS :
        Microsoft Windows XP [Version 5.1.2600]


        A DESCRIPTION OF THE PROBLEM :
        If you put double numbers into a direct DoubleBuffer and then get them back out, some specific numbers change slightly. The attached program has one example of such number.

        One out of several thousand numbers generated with Math.random() produces this behavior. The difference between the "before" and "after" numbers converted to long bits is always in the same bit x800.


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. Run attached program.


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        Actual Results:
        before = 0.5121609353879392 3fe0639f5478f57f
        after = 0.5121609353881665 3fe0639f5478fd7f
        before ^ after = 800

        Expected Results:
        The same numbers before and after.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.nio.ByteBuffer;
        import java.nio.DoubleBuffer;

        public class BugDemo {
            public static void main(String[] args) {
                double before = 0.5121609353879392;
                // put before into buffer and then get it back
                DoubleBuffer buffer = ByteBuffer.allocateDirect(8).asDoubleBuffer();
                buffer.put(0, before);
                double after = buffer.get(0);
                // print out results
                long beforeBits = Double.doubleToLongBits(before);
                long afterBits = Double.doubleToLongBits(after);
                System.out.println("before = " + before + " " + Long.toHexString
        (beforeBits));
                System.out.println("after = " + after + " " + Long.toHexString
        (afterBits));
                System.out.println("before ^ after = " + Long.toHexString(beforeBits ^
        afterBits));
            }
        }

        ---------- END SOURCE ----------
        (Review ID: 167220)
        ======================================================================

              mr Mark Reinhold
              rmandalasunw Ranjith Mandala (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: