当JVM执行Java应用程序时,操作系统的作用是什么?为什么我们需要操作系统? [英] What is the role of the OS when JVM executes a Java application? And why do we need the OS?

查看:150
本文介绍了当JVM执行Java应用程序时,操作系统的作用是什么?为什么我们需要操作系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在互联网上做了一些阅读,有些人说Java应用程序是由java虚拟机(JVM)执行的。 执行这个词让我感到困惑。据我所知,操作系统可以执行非Java应用程序(即:用C,C ++编写)。在较低级别,这意味着OS将二进制程序加载到内存中,然后指示CPU执行内存中的指令。

I have done some reading on the internet and some people say that Java application is executed by the java virtual machine (JVM). The word "execute" confuses me a little bit. As I know, a non-Java application (i.e: written in C, C++...) can be executed by the Operating system. At the lower level, it means the OS will load the binary program into memory, then direct the CPU to execute instructions in memory.

现在使用JVM,会发生什么?据我所知,操作系统首先会调用JVM(包含运行时环境)。从那时起,JVM将为应用程序生成一个(或多个)线程。我想知道操作系统的角色是否会再次发挥作用?在我看来,JVM已绕过操作系统并直接指示CPU执行应用程序。如果是这样,为什么我们需要操作系统?

So now with a JVM, what would happen? As I know, JVM (contains a run-time environment) would be called first by the OS. From that point on, the JVM will spawns one (or many) threads for the application. I wonder if the role of the OS comes into play any more? It seems to me that the JVM has "by-passed" the OS and directly instruct the CPU to execute the application. If so, why do we need the OS?

稍微进一步,JVM将使用其JIT将应用程序的字节代码编译成机器代码,然后执行那些机器码。由于它已经是机器码,我们是否还需要JVM?因为操作系统可以指示CPU执行这些机器代码,而不是JVM。我在这里犯了什么错误吗?

Taking a little bit further, the JVM will use its JIT to compile the application's byte codes into machine codes, then execute those machine codes. Since it is already machine codes, do we need the JVM any more? Because instead of JVM, the OS can be able to instruct the CPU to execute those machine codes. Am I making any mistake here?

我想从这里的人那里学到更多东西。如果我错了,请纠正我。非常感谢你!

I would like to learn more from people here. Please correct me if I am wrong. Thank you so much!

推荐答案

我们需要操作系统来完成C或C ++程序的所有工作。默认情况下,JVM还会执行一些操作,但它不会替换操作系统所做的任何操作。唯一的区别可能是有时你有你的代码 [调用] JVM [调用] OS ,或者使用已编译的代码,您可以您的代码 [调用] OS

We need the OS for all the things a C or C++ program would. The JVM does a few more things by default, but it doesn't replace anything the OS does. The only difference might be that sometimes you have Your Code [calls the] JVM [calls the] OS, or with compiled code you can have Your Code [calls the] OS

同样在C ++中你可能有你的代码 [调用] Boost [调用] 操作系统

Similarly in C++ you might have Your Code [calls the] Boost [calls the] OS.

当你的程序在本机代码中运行时,它不会不需要JVM。这很好,因为JVM知道何时退回并让应用程序运行。但是,并非所有程序都会在应用程序的剩余生命周期内编译为本机代码,因此您仍然需要它。

When your program is running in native code, it doesn't need the JVM as such. This is good because the JVM knows when to "stand back" and let the application run. However, not all the program will be compiled to native code for the rest of the life of the application, so you still need it.

可以使用内核-pass设备/驱动程序与JNI,但Java不直接支持这种功能。

Its is possible to use kernel by-pass devices/drivers with JNI, but Java doesn't directly support this sort of feature.

这篇关于当JVM执行Java应用程序时,操作系统的作用是什么?为什么我们需要操作系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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