In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
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.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.