Java Virtual Machine Enthusiasm

What is the point of using Java in your virtual machine? I remember reading somewhere that it depends on the physical machine on which it works, and then in other places that I read, that it is always, I think, a big endian. What is right?

+28
java virtual-machine endianness
Jun 11 '09 at 14:47
source share
2 answers

Multibyte data in class files is stored by big-endian.

From Java Virtual Machine Specification, Java SE 7 Version , Chapter 4: class File Format :

A class file consists of a stream of 8-bit bytes. All 16-bit, 32-bit, and 64-bit values ​​are constructed by reading in two, four, and eight consecutive 8-bit bytes, respectively. Multibyte data items are always stored in a large order, where bytes are high.

In addition, the operand in the bytecode instruction is also big-endian if it spans several bytes.

From Java Virtual Machine Specification, Java SE 7 , Section 2.11: Brief Description of the Instruction Set :

If the operand contains more than one byte in size, then it is stored in big-endian First order the first byte. For example, an unsigned 16-bit index in local variables is stored as two unsigned bytes, byte1 and byte2 , such that its value (byte1 << 8) | byte2 (byte1 << 8) | byte2 .

So yes, I think it can be said that the Java virtual machine uses big-endian.

+29
Jun 11 '09 at 14:50
source share

The actual operational data stored in the current process will almost certainly correspond to the ultimate goal of the execution process. Typically, file formats (including class files) will be in network order (big end).

As a rule, it is difficult to say what the machine does under it, since it abstracts from the virtual machine. You cannot cast short[] to byte[] , as you can in C and C ++. java.nio.ByteOrder.nativeOrder () should give you the main goal. The corresponding endianess is useful when using non-byte NIO buffers.

+14
Jun 11 '09 at 15:08
source share



All Articles