JVM study notes - bytecode instruction

 JVM study notes - bytecode instruction

Bytecode

1 is signal 0 and the computer can only recognize, through different combinations of 0 and 1 is generated over the digital operation. Further, different combinations also produced by a variety of characters. Likewise, machine instructions may be produced by various different combinations. At different times, different vendors, consisting of a collection of machine instructions is different. But, after all, it is the underlying hardware CPU instruction set compatible extensions usually way ahead of evolving. And machine code is the nearest coded CPU instruction set, the CPU can be directly interpreted instruction, machine code must be coupled with the underlying hardware.

Question: If a programmer because of different hardware platforms need to write multiple sets of code, which is very very collapse. Java's mission is write once, execute everywhere. On different operating systems, different hardware platforms, can not modify the code can be executed smoothly.

 

How to achieve cross-platform JAVA?

Any problem in computer engineering field can be solved by adding an intermediate layer. Therefore, the intermediate codes have emerged, i.e. "bytecode" (Bytecode). All Java instruction has about 200, a byte (8 bits) may be stored 256 different instruction information, such byte is called a byte code (Bytecode). In the process of executing code, the JVM byte code interpreted shielding dependence on the underlying operating system; the JVM bytecode compiler may be performed, if a hot code by the JIT would dynamically compiled into machine code to improve execution effectiveness.

 

Bytecode instruction

To facilitate memory, the JVM and also improvements in assembly language bytecode machine language by means of a method as mnemonic memory efficiently designs a Opcode Mnemonic using special words to mark these numbers. As ICONST_0 behalf 00000011, namely, hexadecimal is 0x03, etc.

The main bytecode instructions are as follows:

1. Load or store instruction

In a stack frame, by the instruction data transmission back and forth between the table and the operand stack local variable stack frame of the virtual machine, the common command is as follows:

1) A local variables load operation into the stack. As ILOAD (int type of the local variables onto the stack) and ALOAD (local variable object reference onto the stack) and the like.

2) operating the stack to store the local variable table. As ISTORE, ASTORE like.

3) The operation of the constant loaded into the top of the stack, which is an extremely high-frequency use instructions. As ICONST, BIPUSH, SIPUSH, LDC and the like.

     * ICONST number is loaded (Iconst and the loading limit BIPUSH) -1 to 5.

     * BIPUSH, i.e. Byte ImmdiatePUSH, according to a number between -128 and -127.

     * SIPUSH, namely Short Immediate PUSH, load -32768 to 32767

     * LDC, i.e. Load Constant, when -2147483618 2147483647 or a character string, JVM using LDC instruction onto the stack.

2. Operation Instructions

Of two values ​​on stack frame calculates the operation, the writing operation and the results stack, such as IADD, IMUL like.

3. Type Conversion

Display switching two different types of values. The I2L, D2F like.

 

4. Object creation and access instructions

According to create classes object initialization method calls related instructions, common instructions as follows:

1) Create Object command. The NEW, NEWARRAY like.

2) access attribute command. As GETFIELD, PUTFIELD, GETSTATIC like.

3) Check the strength of the type of instruction. As INSTANCEOF, CHECKCAST like.

The management instruction operand stack

Providing direct control of the JVM stack operation instruction, common command follows:

1) pop operations. I.e., one element, such as POP, POP2 i.e. two elements.

2) Copy and the top element onto the stack. As DUP.

 

The method calls and returns instruction

Common instructions are as follows:

1) INVOKEVIRTUAL instruction: call object instance of the method.

2) INVOKESPECIAL instruction: call instance initialization method, private methods, a method of the parent class.

3) INVOKESTATIC instruction: call the static class method.

4) RETURN instruction: VOID return type.

 

7. synchronization command

ACC_SYNCHRONIZED flag JVM to use the synchronization method of the structure, there MONITORENTER instruction set and semantics MONITOREXIT support synchronized.

 

 

 

Reference books - "a highly efficient code" Chapter IV into the JVM

 

Guess you like

Origin www.cnblogs.com/deepSleeping/p/11423032.html