After studying Java for a period of time, I believe everyone has been able to understand the importance of jvm, but you may not know much about the instruction system in it. Literally, it is a tool for calling instructions. Regarding some specific content introduction, we will show it to you below and share it with you about the jvm register. Let's enter today's study together.
1. Instruction system description
The JVM instruction system is very similar to other computer instruction systems. At the same time, Java instructions also include two parts: opcode and operand. The opcode is an 8-bit binary number followed by an operand whose length is determined as needed. The operation code is used to specify the nature of the instruction operation (here we explain it in the form of assembly symbols). For example, iload means loading an integer from memory, anewarray means allocating space for a new array, and iand means the "AND" of two integers. ,ret represents process control, returned from a call to a method. When the length exceeds 8 bits, the operand is divided into multiple bytes for storage. For this situation, the JVM adopts the "bigendian" encoding method, that is, the high bits are located in the low bytes. This situation is the same as the encoding method used by Motorola and RISCCPU, but different from the "littleendian" encoding method used by Intel, that is, the low-order bits store the low-order bytes.
The java command system is designed for implementing the Java language. It contains instructions for calling methods and monitoring multi-priority systems. The length of the 8-bit opcodes in the JVM brings the JVM to a maximum of 256 instructions, and now more than 160 instructions are used.
2. Commonly used registers
All CPUs contain a register set that holds system status and information required by the processor. When a virtual machine defines more registers, more information can be obtained from them without accessing the stack or memory, which helps improve running speed. However, if the number of registers in the virtual machine exceeds the number of actual CPUs, then a large amount of processor time will be spent simulating the registers with conventional memory when implementing the virtual machine, which will actually reduce the efficiency of the virtual machine. For this, the JVM only sets the 4 most commonly used registers. They are:
(1) PC program counter
(2) optop operand stack top pointer
(3) frame current execution environment pointer
(4) vars points to the pointer to the first local variable in the current execution environment
All registers are 32 bits. pc is used to record the execution of the program. optop, frame and vars are used to record pointers to the Java stack area.
The above is an introduction to the JVM instruction system of Java. This article mainly focuses on theoretical knowledge points. After learning, you can save the document to facilitate future knowledge review.