Chapter 10 stack and local variables operation

10.1 Constant stacking is
a lot of code to perform the operation constant push operation. Opcode before performing the constant push operation, the following three methods specified constant value: constant value implicitly included in the internal operation code, a constant value in the bytecode stream as operands immediately following the operation code, constant or taken from the constant pool.

Some self-operation code indicating the type and value of the constant of the stack, e.g., iconst_1 opcode informing a Java virtual machine is a type of int number of people to stack pressure. Java Virtual Machine defines some of these opcodes for different types of data is often pressure on people of various stacks. With respect to the instruction fetch operands from or directed bytecode stream constant pool, the above instructions are redundant instructions, but they are more efficient. Because these instructions only occupies one byte of space in the byte stream, they improve the efficiency bytecode, and Xue size less bytecode. Human pressure to the stack type int and float opcode values ​​as shown in Table 10-1.

Opcodes shown in Table 10-1 in the press-fitting type int and float Zhan, int, and is a word length of the float. The length of each Java stack location is a word length (at least 32 bits wide). Thus, each time a press-type float int person or stack, it will occupy a position.

Operation code as shown in Table 10-2 long and double pressure values ​​to find people. long and double value is a 64 bit length. Whenever the value of a long or a double stack type is pressed person, which will occupy two positions.

Another operation code can be a constant implicit declaration onto the stack. As shown in Table 10-3, aconst_null opcode of a null object reference type stack pressure on people.

As mentioned above, the object reference format depends on the specific Java virtual machine implementation. An object reference might lay its wonderful name to point to garbage collection heap Java objects. An empty object reference point to indicate a currently not subject to any valid object reference variables. Process assigned to a null object reference variable f will be used aconst_nuli opcode.

As shown in Table 10-4 two opcodes for an integer constant pressure on people stack, the value of the integer constant byte within the valid range of data types and short, these two operations by using a code immediately following the operation operand after the code explicitly specified constants to be pushed onto the stack. Immediately following the opcode byte, or short type is extended to an int value before people stack pressure. The int type value pushed onto the stack operation and actually replaces the short type byte value onto the top of stack operation.

 

Three operation code as shown in Table 10-5 taken out from the constant in the constant pool is then pressed people stack. These opcodes using operands constant pool index, Java virtual machine through a given index to find the corresponding constant pool entry, and determines the type of the values ​​of these constants, and push them people stack.

 

Constant pool index is an unsigned value, it follows directly behind the opcode in the byte stream. ldc_w ldc and a two-word operation code to an item onto the stack, or that is an int, a value of type float, or an object reference of type String. Idc and the difference between ldc_w comprising: ldc index because there is only one word length, it can only point to 1-255 in the constant pool (constant pool position 0 is not used) in a range of positions. And an index ldc_w two byte length, and therefore, it can point to any position of the constant pool contains long type or double type (occupying two bytes length). The constant pressure from the removed human constant pool looking opcode as shown in Table 10-5.


All Java source code string literals eventually stored as an entry in the constant pool. If the same application multiple classes use the same string literal, then the text will appear in the string to use all of its class in the class file. For example, if there are three classes using the string literal "Harumph! 'Then this string will appear at three constant pool of the class file. The method can use these classes or ldc_w instruction Idc to a point with a" Harumph ! "String object reference value onto the stack.

As described in Chapter 8, Java Virtual Machine all the text characters in the same character as the same procedure of processing a String object. In other words, if you use more than one class with a string literal, such as "Harumph!", Java virtual machine will only have to create a "Harumph!" String objects to represent the value of all string literals.

When the virtual machine parsing a string literal constant pool entry, it "detention" string. First, the virtual machine checks the characters in the string order has already been detained. If so, then the virtual machine will use the reference string has custody of the same. Otherwise, it will create a new String object, have been added to the collection of strings to the detention of a reference to the new String object, then, then assigns a reference to this new string has been detained.

10.2 General stack operations

Although most instructions Java virtual machine instruction set only deal with a particular type, but there are some instructions can be independent of the type of operation to find. As described in Chapter 5, the general (non-type) instruction can not be used to decompose the value is two words long. These instructions shown in Table 10-6.

 

 

10.3 local variables onto the stack

Several operation code for the type int and float stack local variable type pressure people. Some opcode implicitly points to a position of local variables commonly used. For example, iload_0 the local variable type int read into location 0. While the other were a local variable local variable index read from the first byte immediately following the opcode position opcode stack pressure on people.

The float and an int type human stack local variable pressure operation code shown in Table 10-7.

Table 10-8 lists the instruction types long and double types of local variable stack pressure on people. These instructions move data to the word length of the segment from the operand stack local variable stack frame section.

The local variables onto the stack last person opcode operand segment groups to the moving object reference (a word size of the footprint) segment from the local variable stack frame. These opcodes are shown in Table 10-9

10.4 pop top stack element, which is assigned to the local variable

Local variables for each operation code in terms pushed onto the stack, there is to find the corresponding pop top element and stored into a local variable operation code. Eject operation performed by the Opcode Mnemonic Opcode Mnemonic pressure people stack operations performed in the "save" to "load" represent manner. Table 10-10 shows the pop looking from the top of the operand type and fioat int type value and stores it in a local variable operation code. These opcodes to move from the top of the stack of local variables - the value of a word length.

10.5 wide instruction

Unsigned 8-bit index local variables (such that subsequent instructions iload index), the number of local variables in a method is limited to 256 or less. A wide single instruction can be 8-bit index extended by 8 bits can be extended so that limit the number of local variables to 65,536. Other modified wide opcode opcode. Wide instructions using the instruction can be executed unsigned 8-bit index local variables, such as the front or the like iload. In the following the two bytes following the operation code and the wide modified opcodes unsigned 16-bit index points to local variables.

Table 10-13 lists all the commands that can be modified Wide operation code (with two exceptions) two instruction exception (Iinc and ret) will be discussed in a later section. iinc command and its wide variable will be discussed in Chapter 12. ret instruction and its wide variable discussed in Chapter 18.

When the authentication sequence comprises a wide bytecode instructions, the modified wide instruction operation code looks like - of the wide operand transfer. Jump instruction and does not allow direct jump instruction to be modified over wide opcode. For example, if a byte stream includes the following instruction sequence

wide iload 257

Then the byte stream sequence of this method does not allow any other opcodes directly jump to iload opcode. In this case, iload opcode must always be performed as a wide operand opcode.

javac compiler into a local variable from the source file and a stack frame 0 | location is locally halo, b into the position of the stack frame 2 and 3, the fiboNum placed in position 4 and 5. Whenever a successive calculated Fibonacci number, javac compiler will store this number to fiboNum variable. Accordingly, when the operation will find Fibonacci sequence | ong form Type values ​​stored in the local variables in the 4 and 5 positions.

It may be noted, long storage type value is divided into two, lower (0 to 31) stored in the first position, Gao bits (32 to 63) located in the second position. For example, low fiboNum local variable stored in variable positions 4, Gao bits are stored in a local variable in position 5. Zhan operand in the same, when a long type value is pushed onto the stack, the lower will be the first to be pushed onto the stack, and then turn to the next high level.

Keep in mind that: this represents a value of type long way just a simulation of the Java virtual machine implemented in the pending local variables and operand looking in. As described in Chapter 5, specification does not specify any particular method to determine how long type and placement type double word in the stack frame.

 

Guess you like

Origin www.cnblogs.com/mongotea/p/11980063.html