Get the App
SLTechnology News&Howtos  ›  Development  › 

Where does 10 of (aquib) * 10 exist in jdk1.8?

Shulou Source: shulou.com Published: 2022-06-03 04:57:56 09月21日 Update

Today, I would like to talk to you about where 10% of jdk1.8 * 10 exists. Maybe many people don't know much about it. In order to make you understand better, the editor summarizes the following content for you. I hope you can get something from this article.

Today I saw a very interesting question: (aquib) * where is the storage of * 10 ~ (10)? Is it a constant pool? If it is a constant pool, when doing an operation, it is found through a pointer, right?

Some answer: 10 is in the constant pool, which has been moved to metaspace after jdk1.8.

To verify that this answer is correct, it is easy to write a test method that can be concluded by looking at the compiled bytecode instructions through javap.

The source code of the test method is as follows:

Private int m (int a, int b) {int r = a * b * 10; return r;}

Use javap to view the compiled bytecode as follows:

Private int m (int, int); descriptor: (II) I flags: ACC_PRIVATE Code: stack=2, locals=4, args_size=3 0: iload_1 1: iload_2 2: imul 3: bipush 10 5: imul 6: istore_3 7: iload_3 8: ireturn

The author flipped through the JVM bytecode instruction table, and the relevant instructions are shown in the following figure.

A bytecode instruction consists of an opcode and zero or more operands, which are compiled and written into the Code property of the method. The operands are either immediate numbers, indexes to constants in the constant pool of class file structures, or offsets of jump target instructions.

If the number 10 is x, the following conclusions can be drawn:

When x is in the interval [- 1 ~ 5], x is compiled directly into the code attribute of the method as the Operand of the iconst instruction.

When x is in the range [- 128127], x is also compiled directly into the code attribute of the method. As the Operand of the bipush instruction, the value range is [- 128127] because the Operand of the bipush instruction can only be one byte.

When x is in the interval [- 32768], x is also compiled directly into the code attribute of the method. As the Operand of the sipush instruction, the range of values is [- 32768] because the Operand of the sipush instruction has two bytes.

Otherwise, x will be compiled into the constant pool of class and push from the constant pool (metaspace) to the Operand stack through the ldc instruction during the operation.

After reading the above, do you have any further understanding of the existence of 10 of (aquib) * 10 in jdk1.8? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Instruction constant Operand compilation byte method property content interval or space conclusion range test operation interesting two multiple point pointer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Linux OPPO Reno MariaDB Shulou Tech Info