Re: Endianness of Java Virtual Machine
- From: Andreas Leitgeb <avl@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: 31 Oct 2007 06:39:54 GMT
karthikbalaguru <karthikbalaguru79@xxxxxxxxx> wrote:
Is 'Java Virtual Machine' Big-Endian ?There are already lots of answers, and I will add one,
Or
Is it independent of Endianness ? (That is Bi-Endian)
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.
.
- Follow-Ups:
- Re: Endianness of Java Virtual Machine
- From: Roedy Green
- Re: Endianness of Java Virtual Machine
- References:
- Endianness of Java Virtual Machine
- From: karthikbalaguru
- Endianness of Java Virtual Machine
- Prev by Date: Re: File Open dialog bug in 1.6.0_03
- Next by Date: Re: To static or not to static
- Previous by thread: Re: Endianness of Java Virtual Machine
- Next by thread: Re: Endianness of Java Virtual Machine
- Index(es):