How Does JVM Uses Native Stack Manually For JAVA Function Call

This is with reference to the answer in this post: How JVM stack, heap and threads are mapped to physical memory or operation system

it says "JVM stack is the same a native stack" if that is the case then how jvm allocates stack frames on this stack memory whenever there is a function call in Bytecode and not the JVM code function call. If there is a function call in JVM code then the method local variables and other method related stuff will be stored in this native stack by OS. But if there is a function call in bytecode instruction how does JVM manually stores locals in that native stacks.


how jvm allocates stack frames on this stack memory whenever there is a function call in Bytecode and not the JVM code function call.

Exactly what the JVM isn't specified in the JLS. The JVM might

  • allocate a stack frame.
  • reuse an existing stack frame for a leaf method.
  • inline a method so it doesn't require it's own frame.
  • In terms of byte code, different portions of a method can have their own frames, and the JVM might allocate multiple frames in a method, though I doubt it actually does this.

    If there is a function call in JVM code then the method local variables and other method related stuff will be stored in this native stack by OS.

    Always, unless the variable is optimise away in which case it doesn't get stored anywhere.

    But if there is a function call in bytecode instruction how does JVM manually stores locals in that native stacks.

    The byte code has to run on a real machine and it has to use the stack to store it's information, this doesn't change dramatically based on whether it running in interpreted byte code or compiled native code. The only difference is how much optimisation has occurred in reducing the number of local variables.

    链接地址: http://www.djcxy.com/p/82746.html

    上一篇: 正在运行的JVM程序中有多少种类型的堆栈?

    下一篇: JVM如何手动使用本地堆栈进行JAVA函数调用