In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "what is the method of JVM Operand stack". In daily operation, I believe that many people have doubts about the method of JVM Operand stack. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "what is the method of JVM Operand stack?" Next, please follow the editor to study!
Like the local variable area, the Operand stack is organized into an array in terms of word length. But unlike the former, it is not accessed through an index, but through standard stack operations-stack and off-stack. For example, if an instruction pushes a value into the Operand stack, another instruction can pop that value later to use it.
Virtual machines store data in the Operand stack in the same way as in the local variable area: storage such as int, long, float, double, reference, and returnType. Values of types byte, short, and char are also converted to int before being pushed into the Operand stack.
Unlike program counters, Java virtual machines do not have registers, and program counters cannot be directly accessed by program instructions. The instructions of the Java virtual machine get the operands from the Operand stack rather than from the register, so its operation is stack-based rather than register-based. Although instructions can also obtain operands from other places, such as following the bytes following the opcode (the bytes representing instructions) from the byte stream, or from the constant pool, the operands are mainly obtained from the Operand stack.
The virtual machine uses the Operand stack as its workspace-- where most instructions eject data, perform operations, and then press the results back into the Operand stack. For example, the iadd instruction pops up two integers from the Operand stack to perform the addition operation, and the result is pressed back into the Operand stack. Take a look at the following example, which demonstrates how the virtual machine adds two local variables of type int and saves the result to the third local variable:
Beginiload_0 / / push the int in local variable 0 onto the stackiload_1 / / push the int in local variable 1 onto the stackiadd / / pop two ints, add them, push resultistore_2 / / pop int, store into local variable 2
In this bytecode sequence, the first two instructions iload_0 and iload_1 push integers stored in local variables with indexes of 0 and 1 into the Operand stack, and then the iadd instruction pops up the two integers from the Operand stack and pushes the result into the Operand stack. The fourth instruction, istore_2, pops up the result from the Operand stack and stores it to the location where the local variable area index is 2. Figure 5-10 illustrates in detail the state changes of local variables and Operand stacks during this process, and the unused areas of local variables and Operand stacks are represented by blanks.
At this point, the study of "what is the method of JVM Operand stack" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.