调用本机代码时JVM是否会停止? [英] Does JVM halt when calling native code?

查看:121
本文介绍了调用本机代码时JVM是否会停止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Java的字节码调用机器代码时是否有任何性能影响?由于机器代码是非托管的,并且它没有意识到Java的内部结构,这可能导致JVM的内部调度程序暂停或类似的东西?

Are there any performance implications when calling machine code from Java's bytecode? Since machine code is "unmanaged", and it is not "aware" of Java's internals, maybe this causes JVM's internal schedulers to pause or something like that?

我是新的到Java,所以也许这甚至不相关,请帮忙。

I am new to Java, so maybe this is not even relevant, please help.

我知道在Erlang中他们有这个问题,VM在调用时基本上停止了机器代码。我希望Java不是这种情况。是吗?

I know that in Erlang they have this problem, where the VM basically stops while it is making calls to machine code. I hope this is not the case with Java. Is it?

推荐答案

运行本机代码的线程不会停止JVM。

Threads running native code will not halt JVM.

调用JNI方法后,Java线程切换到 _thread_in_native 状态。在安全点操作期间不计算处于此状态的线程,即当发生stop-the-world事件时(如垃圾收集),JVM不会停止这些线程。相反,本机状态的线程无法阻止JVM,除非它们执行JNI上行调用。当本机方法返回时,线程切换回 _thread_in_Java 状态。

As soon as JNI method is called, Java thread switches to _thread_in_native state. Threads in this state are not counted during safepoint operations, i.e. when a stop-the-world event occurs (like garbage collection), JVM does not stop these threads. Conversely, threads in native state cannot stop JVM unless they perform a JNI upcall. When a native method returns, the thread switches back to _thread_in_Java state.

这篇关于调用本机代码时JVM是否会停止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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