JVM Stack Variables

I understand that the JVM creates a stack for each thread and that Stack contains calls to other methods as the thread calls them. I do not understand when he says that Stack will also have local variables and partial results. I thought that global and local variables (primitives and links) would exist on the heap, and not on Stack, can anyone think what this means? Secondly, it speaks of partial results, does this mean that when switching flows, half of the results (copies) from local variables and instances occur?

thanks

-Abidi

+4
source share
2 answers

Each JVM has a runtime stack. Each frame of the method contains

  • A reference to the Java class containing this method.
  • The operand stack for storing temporary values.
  • An array of local variables for storing function arguments and temporary results.

This array of local variables exists so that when the function is first called, the arguments to this function can be stored somewhere. An array of local variables does not actually store all local variables declared in the Java source code; rather, it is rather a temporary buffer for storing references to Java objects declared elsewhere in the heap, or for storing values ​​referenced many times so that placing them in the execution stack would be slow or inefficient.

In short, you are correct that locals and globals are stored on the heap. The "local variables" array in Java streams does not match these local networks, but rather scratches the space used by the stream when interpreting the bytecode for this method.

+5
source

Each JVM has a runtime stack. Each frame of the method contains

A reference to the Java class containing that method. An operand stack for holding temporary values. A "local variables" array for holding function arguments and temporary results. 

This array of local variables exists so that when the function is first called, the arguments to this function can be stored somewhere. An array of local variables does not actually store all local variables declared in the Java source code; rather, it is rather a temporary buffer for storing references to Java objects declared elsewhere in the heap, or for storing values ​​referenced many times so that placing them in the execution stack would be slow or inefficient.

In short, you are correct that locals and globals are stored on the heap. The "local variables" array in Java streams does not match these local networks, but rather scratches the space used by the stream when interpreting the bytecode for this method.

0
source

Source: https://habr.com/ru/post/1345369/


All Articles