简体   繁体   English

JVM中的本机堆栈和缓存代码

[英]Native stack and Cache code in JVM

Java byte code is interpreted however this is not as fast as directly executing native code on the JVM's host CPU. 解释了Java字节代码,但是它不如直接在JVM的主机CPU上执行本机代码那样快。 To improve performance the Oracle Hotspot VM looks for “hot” areas of byte code that are executed regularly and compiles these to native code. 为了提高性能,Oracle Hotspot VM查找定期执行的字节码“热”区域,并将其编译为本机代码。 The native code is then stored in the code cache in non-heap memory. 然后将本机代码存储在非堆内存中的代码缓存中。 In this way the Hotspot VM tries to choose the most appropriate way to trade-off the extra time it takes to compile code verses the extra time it take to execute interpreted code. 通过这种方式,Hotspot VM尝试选择最合适的方式来权衡编译代码所花费的额外时间与执行解释代码所花费的额外时间。

Not all JVMs support native methods, however, those that do typically create a per thread native method stack. 并非所有的JVM都支持本机方法,但是,那些通常会创建每个线程本机方法堆栈的JVM。 If a JVM has been implemented using a C-linkage model for Java Native Invocation (JNI) then the native stack will be a C stack. 如果使用Java本地调用(JNI)的C链接模型实现了JVM,则本地堆栈将是C堆栈。 In this case the order of arguments and return value will be identical in the native stack to typical C program. 在这种情况下,参数和返回值的顺序在本机堆栈中与典型的C程序相同。 A native method can typically (depending on the JVM implementation) call back into the JVM and invoke a Java method. 通常,本机方法可以(取决于JVM实现)回调到JVM并调用Java方法。 Such a native to Java invocation will occur on the stack (normal Java stack); 这样的Java调用本机将在堆栈(普通Java堆栈)上发生; the thread will leave the native stack and create a new frame on the stack (normal Java stack). 该线程将离开本机堆栈,并在堆栈上创建一个新框架(普通Java堆栈)。

What does it mean native as for Code cache and native stack? 对于代码缓存和本机堆栈,本机意味着什么? When I write a program on Ubuntu and run it on Eclipse, and the program runs endlesly a loop in which there is some code, will this code go to code cache? 当我在Ubuntu上编写程序并在Eclipse上运行时,该程序无端地运行着有一些代码的循环,这些代码是否会进入代码缓存? Will it be recompiled to some native language and which, when I am using Ubuntu, Oracle Java 1.7, I have Intel i5 processor. 是否可以将其重新编译为某种本地语言,并且在我使用Ubuntu,Oracle Java 1.7时使用的是Intel i5处理器。 The same question about Oracle JVM7 - is it written in C? 关于Oracle JVM7的相同问题-它是用C编写的吗? When native stack would be used and what exactly mean native in this case, when I have Ubuntu and Oracle Java 1.7 ? 当我使用Ubuntu和Oracle Java 1.7时,什么时候使用本机堆栈?在这种情况下,本机到底是什么意思?

As far as I understand JVM creates a separate stack for native methods bind to Java code via JNI. 据我了解,JVM为通过JNI绑定到Java代码的本机方法创建了单独的堆栈。 It has been done so because those methods has their own stack specifications. 这样做是因为这些方法具有自己的堆栈规范。 But it all depends on JVM implementation, it also could be that there is no separate stack for Native methods. 但这完全取决于JVM的实现,也可能是没有用于本机方法的单独堆栈。

You can take a look at this article: http://www.artima.com/insidejvm/ed2/jvm9.html 您可以看一下这篇文章: http : //www.artima.com/insidejvm/ed2/jvm9.html

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

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