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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P5
    • Resolution: Won't Fix
    • Affects Version/s: 5.0u1
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      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.

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: