Endianness of Java Virtual Machine

Discussion in 'Java' started by karthikbalaguru, Oct 30, 2007.

  1. Hi,
    Is 'Java Virtual Machine' Big-Endian ?
    Or
    Is it independent of Endianness ? (That is Bi-Endian)

    Can someone provide some link in the internet that discusses
    more about this ?

    Thx in advans,
    Karthik Balaguru
     
    karthikbalaguru, Oct 30, 2007
    #1
    1. Advertising

  2. karthikbalaguru

    dalouis Guest

    On Oct 30, 5:05 pm, karthikbalaguru <>
    wrote:
    > Hi,
    > Is 'Java Virtual Machine' Big-Endian ?
    > Or
    > Is it independent of Endianness ? (That is Bi-Endian)
    >
    > Can someone provide some link in the internet that discusses
    > more about this ?
    >
    > Thx in advans,
    > Karthik Balaguru


    Endian is something that is determined by the architecture of the
    machine you are running on, therefore it would depend which platform
    you are running the virtual machine on.

    Although Im not sure what difference it would make for you if you are
    writing java code, since java completely hides details such as this
    from you.
     
    dalouis, Oct 30, 2007
    #2
    1. Advertising

  3. karthikbalaguru

    dalouis Guest

    On Oct 30, 5:05 pm, karthikbalaguru <>
    wrote:
    > Hi,
    > Is 'Java Virtual Machine' Big-Endian ?
    > Or
    > Is it independent of Endianness ? (That is Bi-Endian)
    >
    > Can someone provide some link in the internet that discusses
    > more about this ?
    >
    > Thx in advans,
    > Karthik Balaguru


    Endian is something that is determined by the architecture of the
    machine you are running on, therefore it would depend which platform
    you are running the virtual machine on.

    Although Im not sure what difference it would make for you if you are
    writing java code, since java completely hides details such as this
    from you.
     
    dalouis, Oct 30, 2007
    #3
  4. karthikbalaguru wrote:
    > Hi,
    > Is 'Java Virtual Machine' Big-Endian ?
    > Or
    > Is it independent of Endianness ? (That is Bi-Endian)
    >
    > Can someone provide some link in the internet that discusses
    > more about this ?
    >
    > Thx in advans,
    > Karthik Balaguru
    >


    Java is big-endian insofar as its Data{In,Out}putStream assumes
    big-endianness and the class file specification is big-endian. From most
    developers' standpoints, it is endian-agnostic.

    --
    Beware of bugs in the above code; I have only proved it correct, not
    tried it. -- Donald E. Knuth
     
    Joshua Cranmer, Oct 30, 2007
    #4
  5. On Oct 31, 2:12 am, dalouis <> wrote:
    > On Oct 30, 5:05 pm, karthikbalaguru <>
    > wrote:
    >
    > > Hi,
    > > Is 'Java Virtual Machine' Big-Endian ?
    > > Or
    > > Is it independent of Endianness ? (That is Bi-Endian)

    >
    > > Can someone provide some link in the internet that discusses
    > > more about this ?

    >
    > > Thx in advans,
    > > Karthik Balaguru

    >
    > Endian is something that is determined by the architecture of the
    > machine you are running on, therefore it would depend which platform
    > you are running the virtual machine on.
    >
    > Although Im not sure what difference it would make for you if you are
    > writing java code, since java completely hides details such as this
    > from you.


    Actually, I came across a link that states 'Java Virtual Machine is of
    Big-Endian'.
    http://www.intel.com/design/intarch/papers/endian.pdf

    I am eager to know the advantages of such a desing of Java Virtual
    Machine.
    Is there any link / document in the internet that discusses about
    these ?

    Thx in advans,
    Karthik Balaguru
     
    karthikbalaguru, Oct 30, 2007
    #5
  6. karthikbalaguru

    Roedy Green Guest

    On Tue, 30 Oct 2007 14:05:25 -0700, karthikbalaguru
    <> wrote, quoted or indirectly quoted
    someone who said :

    >Is 'Java Virtual Machine' Big-Endian ?
    >Or
    >Is it independent of Endianness ? (That is Bi-Endian)
    >
    >Can someone provide some link in the internet that discusses
    >more about this ?


    see http://mindprod.com/jgloss/endian.html

    Java is designed so the machine internally could be either. You can't
    write a program to tell. However, any DataOutputStream will be big
    endian.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Oct 30, 2007
    #6
  7. karthikbalaguru

    Eric Sosman Guest

    karthikbalaguru wrote On 10/30/07 17:30,:
    > On Oct 31, 2:12 am, dalouis <> wrote:
    >
    >>On Oct 30, 5:05 pm, karthikbalaguru <>
    >>wrote:
    >>
    >>
    >>>Hi,
    >>>Is 'Java Virtual Machine' Big-Endian ?
    >>>Or
    >>>Is it independent of Endianness ? (That is Bi-Endian)

    >>
    >>>Can someone provide some link in the internet that discusses
    >>>more about this ?

    >>
    >>>Thx in advans,
    >>>Karthik Balaguru

    >>
    >>Endian is something that is determined by the architecture of the
    >>machine you are running on, therefore it would depend which platform
    >>you are running the virtual machine on.
    >>
    >>Although Im not sure what difference it would make for you if you are
    >>writing java code, since java completely hides details such as this
    >>from you.

    >
    >
    > Actually, I came across a link that states 'Java Virtual Machine is of
    > Big-Endian'.
    > http://www.intel.com/design/intarch/papers/endian.pdf
    >
    > I am eager to know the advantages of such a desing of Java Virtual
    > Machine.
    > Is there any link / document in the internet that discusses about
    > these ?


    The fact that a document makes a claim doesn't prove
    that the claim is correct ...

    It seems to me that Intel's characterization of the
    JVM as Big-Endian is at best incomplete. The endianness
    of the JVM is unspecified, and implementations for both
    Big-Endian and Little-Endian machines do in fact use the
    platforms' native formats for `int' and so forth. You
    could point to a specific JVM implementation and say that
    it was Big- or Little- or Middle-Endian, but saying that
    "the JVM" has a specific endianness is like saying C++ has
    a specific endianness.

    It is true that the class file format is Big-Endian,
    serialized forms are Big-Endian, and so on. But these are
    best viewed as interchange formats, not as characteristics
    of the JVM's that process them. Your computer -- whatever
    it is -- presumably sends and receives IP packets, whose
    format has a strong Big-Endian flavor; does it follow that
    your computer is Big-Endian? Of course not, and it seems
    equally pointless to point to a Big-Endian class file and
    infer that any JVM that loads it must be Big-Endian.

    --
     
    Eric Sosman, Oct 30, 2007
    #7
  8. On Oct 30, 2:30 pm, karthikbalaguru <>
    wrote:
    > On Oct 31, 2:12 am, dalouis <> wrote:
    >
    >
    >
    > > On Oct 30, 5:05 pm, karthikbalaguru <>
    > > wrote:

    >
    > > > Hi,
    > > > Is 'Java Virtual Machine' Big-Endian ?
    > > > Or
    > > > Is it independent of Endianness ? (That is Bi-Endian)

    >
    > > > Can someone provide some link in the internet that discusses
    > > > more about this ?

    >
    > > > Thx in advans,
    > > > Karthik Balaguru

    >
    > > Endian is something that is determined by the architecture of the
    > > machine you are running on, therefore it would depend which platform
    > > you are running the virtual machine on.

    >
    > > Although Im not sure what difference it would make for you if you are
    > > writing java code, since java completely hides details such as this
    > > from you.

    >
    > Actually, I came across a link that states 'Java Virtual Machine is of
    > Big-Endian'.http://www.intel.com/design/intarch/papers/endian.pdf
    >
    > I am eager to know the advantages of such a desing of Java Virtual
    > Machine.
    > Is there any link / document in the internet that discusses about
    > these ?


    Since Java doesn't expose the representation of its primitive types
    (which is one of two primary applications of endianness), it's
    impossible to tell from examining the behaviour of code which way
    around the bytes are stored in memory from within Java. This means
    that the JVM is free to use whatever order is faster on the computer
    it's running on: on LE machines (like the x86 architecture), that'll
    be little-end-first; on BE machines (like the PowerPC), that would be
    big-end-first.

    However, Java's IO toolkit originally only provided ways to produce
    external representations (the *other* primary application of
    endianness, and the one the IBM whitepaper is probably referring to)
    in big-endian form. Since big-end-first is the standard network byte
    order for integer representation (see the POSIX htonl/htons
    functions), this made sense at the time. The NIO framework includes
    support for mixed- and little-endian IO.
     
    Owen Jacobson, Oct 30, 2007
    #8
  9. karthikbalaguru

    Roedy Green Guest

    On Tue, 30 Oct 2007 14:30:58 -0700, karthikbalaguru
    <> wrote, quoted or indirectly quoted
    someone who said :

    >I am eager to know the advantages of such a desing of Java Virtual
    >Machine.


    That is not quite true. What is true that Java when it talks to the
    outside world always uses big endian. Inside it can be anything.
    Unlike C, external files have a precise standard bit representation.
    This makes it much easier to share files between different platforms
    and different applications.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Oct 31, 2007
    #9
  10. karthikbalaguru <> wrote:
    > Is 'Java Virtual Machine' Big-Endian ?
    > Or
    > Is it independent of Endianness ? (That is Bi-Endian)
    >

    There are already lots of answers, and I will add one,
    that would let you find out the endianess of your
    particular JVM, but it takes some java bytecode
    knowledge:

    Write a java program that defines an integer variable,
    with value 0xaabbccdd, and assign it (with cast) to
    a short and a byte variable, which you have written
    out to System.out.
    Then you compile it, and it would write (always, inde-
    pendent on endianess) the values for 0xccdd and 0xdd.

    Now comes the tricky part:
    in the bytecode there exist instructions to convert the
    intvalue to a byte/short-value, and you'd have to modify
    the class file(*) to do some noop's instead of these
    converting instructions. after that you run the code
    again, and see if the result has changed.
    I haven't tried it myself, but my prediction is, that
    on little-endian platform the result would stay the same,
    whereas on big-endian platforms it would change to 0xaabb
    and 0xaa.

    (*) with help of sun's "javap" (to check the results)
    you could try+error your way there, or you could
    use some disassembler (not a decompiler!) and
    assembler.
     
    Andreas Leitgeb, Oct 31, 2007
    #10
  11. karthikbalaguru

    Roedy Green Guest

    On 31 Oct 2007 06:39:54 GMT, Andreas Leitgeb
    <> wrote, quoted or indirectly quoted
    someone who said :

    >Now comes the tricky part:
    >in the bytecode there exist instructions to convert the
    >intvalue to a byte/short-value, and you'd have to modify
    >the class file(*) to do some noop's instead of these
    >converting instructions. after that you run the code
    >again, and see if the result has changed.


    Just want to clarify here. A careless reader might get the erroneous
    idea the compiler generates different byte code depending on whether
    the target were big on little endian. Definitely not so. The same byte
    code is used on all platforms. The byte code does the same logical
    thing on all platforms. It is just the JVM has different amounts of
    work to implement each byte code on different platforms. Your trick
    exploits this.

    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Oct 31, 2007
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    1,079
    Tim Tyler
    May 9, 2005
  2. pramod
    Replies:
    22
    Views:
    1,848
    Lew Pitcher
    Jan 6, 2004
  3. kelvSYC

    Endianness

    kelvSYC, Jun 3, 2005, in forum: C++
    Replies:
    3
    Views:
    596
    Donovan Rebbechi
    Jun 3, 2005
  4. kelvSYC

    Endianness and streams

    kelvSYC, Jun 5, 2005, in forum: C++
    Replies:
    8
    Views:
    456
    Pete Becker
    Jun 6, 2005
  5. friend.05

    Endianness of machine

    friend.05, Feb 16, 2006, in forum: C Programming
    Replies:
    18
    Views:
    673
    Keith Thompson
    Feb 18, 2006
Loading...

Share This Page