Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java's Virtual Machine's Endianness

What endianness does Java use in its virtual machine? I remember reading somewhere that it depends on the physical machine it's running on, and then other places I have read that it is always, I believe, big endian. Which is correct?

like image 982
JoeCool Avatar asked Jun 11 '09 14:06

JoeCool


People also ask

Is JVM big-endian or little endian?

A JVM can give the appearance of being big-endian from the POV of the bytecode it executes while still actually storing multi-byte values in native endianness.

What are JVM objects?

The Java Virtual Machine contains explicit support for objects. An object is either a dynamically allocated class instance or an array. A reference to an object is considered to have Java Virtual Machine type reference . Values of type reference can be thought of as pointers to objects.

What is native method stack in Java?

5.Native Method Stack Native methods are those which are written in languages other than java. JVM implementations cannot load native methods and can't rely on conventional stacks . It is also associated with each thread.

How does the Java JVM work?

The JVM converts the compiled binary byte code into a specific machine language. Java Virtual machine acts as a subpart of Java Runtime Environment(JRE). The JVM is an abstract machine that works on the top of existing processes. We can implement it in hardware or software.


1 Answers

Multibyte data in the class files are stored big-endian.

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

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

Furthermore, the operand in an bytecode instruction is also big-endian if it spans multiple bytes.

From The Java Virtual Machine Specification, Java SE 7 Edition, Section 2.11: Instruction Set Summary:

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

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

like image 192
coobird Avatar answered Sep 29 '22 03:09

coobird