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

(bf) java.nio.Bits.byteOrder() makes invalid architectural assumptions

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P5 P5
    • None
    • 5.0u1
    • core-libs
    • generic
    • generic

      The following code snippet from java/nio/Bits.byteOrder() makes an invalid
      assumption that native bytes are 8 bits long and that native longs occupy
      exactly 8 bytes. This assumption is, of course, erroneous on our 36/72- and
      48-bit machines.

      unsafe.putLong(a, 0x0102030405060708L);
      byte b = unsafe.getByte(a);
      switch (b) {
      case 0x01: byteOrder = ByteOrder.BIG_ENDIAN; break;
      case 0x08: byteOrder = ByteOrder.LITTLE_ENDIAN; break;
      default:
      throw new Error("Unknown byte order");

      The incorrect code appears in both 1.4.2_05 and 1.5.0 b57 (and probably
      everything since 1.4.0).

      We think the correct approach would be to implement the big/little endian
      determination as a native method, probably in java.lang.Unsafe.

            Unassigned Unassigned
            clucasius Carlos Lucasius (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: