JVM如何手动使用本机堆栈进行JAVA函数调用 [英] How Does JVM Uses Native Stack Manually For JAVA Function Call

查看:86
本文介绍了JVM如何手动使用本机堆栈进行JAVA函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是参考本文中的答案:

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堆栈与本地堆栈相同",那么,每当在Bytecode中有函数调用而不是JVM代码函数调用时,jvm如何在该堆栈存储器上分配堆栈帧.如果在JVM代码中存在函数调用,则方法局部变量和其他与方法相关的内容将由OS存储在此本机堆栈中.但是,如果字节码指令中有函数调用,那么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. 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.

推荐答案

当Bytecode中有函数调用而不是JVM代码函数调用时,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.

确切地说,JLS中没有指定JVM. JVM可能

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

  • 分配堆栈框架.
  • 将现有的堆栈框架重用于叶子方法.
  • 内联方法,因此不需要它自己的框架.

就字节码而言,方法的不同部分可以具有自己的框架,并且JVM可能在一个方法中分配多个框架,尽管我怀疑它实际上是这样做的.

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代码中存在函数调用,则方法局部变量和其他与方法相关的内容将由OS存储在此本机堆栈中.

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.

但是,如果字节码指令中有一个函数调用,那么JVM如何将本地人手动存储在该本地堆栈中.

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.

这篇关于JVM如何手动使用本机堆栈进行JAVA函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆