简体   繁体   English

JVM如何手动使用本机堆栈进行JAVA函数调用

[英]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 这是参考本文中的答案: JVM堆栈,堆和线程如何映射到物理内存或操作系统

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. 如果是这种情况,它会说“ JVM堆栈与本地堆栈相同”,那么,每当在Bytecode中有函数调用而不是JVM代码函数调用时,jvm如何在该堆栈存储器上分配堆栈帧。 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. 如果在JVM代码中存在函数调用,则OS将将方法局部变量和其他与方法相关的内容存储在此本机堆栈中。 But if there is a function call in bytecode instruction how does JVM manually stores locals in that native stacks. 但是,如果字节码指令中有函数调用,那么JVM如何手动将本地变量存储在该本地堆栈中。

how jvm allocates stack frames on this stack memory whenever there is a function call in Bytecode and not the JVM code function call. 每当Bytecode中有函数调用而不是JVM代码函数调用时,jvm如何在此堆栈存储器上分配堆栈帧。

Exactly what the JVM isn't specified in the JLS. 确切地说,JLS中没有指定JVM。 The JVM might JVM可能

  • 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. 在字节码方面,方法的不同部分可以有自己的框架,并且JVM可能在一个方法中分配多个框架,尽管我怀疑它实际上是这样做的。

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. 如果在JVM代码中存在函数调用,则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. 但是,如果字节码指令中有函数调用,那么JVM如何手动将本地变量存储在该本地堆栈中。

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. 唯一的区别是在减少局部变量的数量方面发生了多少优化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM