简体   繁体   English

Java编译器是JVM的一部分吗?

[英]Is the java compiler part of the JVM?

I was reading some posts about JVM and found some confusing information. 我正在阅读一些有关JVM的文章,并发现了一些令人困惑的信息。

for example here: http://www.cs.cmu.edu/~jcarroll/15-100-s05/supps/basics/history.html 例如在这里: http : //www.cs.cmu.edu/~jcarroll/15-100-s05/supps/basics/history.html

it says "In fact, the Java compiler is often called the JVM compiler (for Java Virtual Machine)". 它说:“实际上,Java编译器通常被称为JVM编译器(对于Java虚拟机)”。

Further more, I could not find the exact answer if the java compiler is part of the JVM or not. 此外,如果Java编译器是否是JVM的一部分,我将找不到确切的答案。 I know that the the JVM is an interpreter, but i read that it does some compiling too. 我知道JVM是解释器,但我读到它也做了一些编译。 Also, as far as i know, JVM is part of JRE; 而且,据我所知,JVM是JRE的一部分。 javac part of JDK and JRE part of JDK. JDK的javac部分和JDK的JRE部分。

So is javac part of JVM? 那么javac是JVM的一部分吗? I think it's not, but not sure though. 我认为不是,但是不确定。

That is mainly about terminology, wording. 这主要是关于术语,措辞。

There is the java binary executable (and some subtle variations of it, such as javaw). java 二进制可执行文件 (以及它的一些细微变化,例如javaw)。 That is the java virtual machine! 那就是java虚拟机! You invoke that binary, and a JVM gets launched (see here for all the glory details). 您调用该二进制文件,然后启动JVM(有关所有荣耀的详细信息,请参见此处 )。

In essence: 在本质上:

  • a JRE contains a JVM (the aforementioned java binary) JRE包含JVM(上述java二进制文件)
  • a JDK contains a JVM, and the tools and libraries to develop for Java (so: java and javac ) JDK包含一个JVM, 以及为Java 开发的工具和库(因此: javajavac

Finally: using the term "JVM compiler" for javac is wrong and misleading. 最后:对于javac使用术语“ JVM编译器”是错误的并且具有误导性。 javac turns java source code into java bytecode, which then can be executed by the JVM. javac将Java源代码转换为Java字节码,然后可由JVM执行。 But just to be really complete here: most JVM implementations also contain a "just in time" compiler component to transform byte code into native machine code to improve performance. 但这里要真正完成的是:大多数JVM实现包含“及时”编译器组件,用于将字节代码转换为本地机器代码以提高性能。

Some JVMs will perform JIT (Just in Time )compilations to optimize java byte code. 一些JVM将执行JIT(Just in Time)编译,以优化Java字节码。 In addition it is possible to do this in code 另外,可以在代码中执行此操作

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); JavaCompiler编译器= ToolProvider.getSystemJavaCompiler();

however traditionally the compiler was part of the JDK and applications were distributed with the JRE which does not contain a javac 但是传统上,编译器是JDK的一部分,并且应用程序是随不包含Javac的JRE一起分发的

Though "Java compiler is often called the JVM compiler (for Java Virtual Machine)" might be misleading, it still holds because javac essentially converts Java source code to byte code for JVM to be run which then interprets it to machine readable instruction depending on the platform 尽管“ Java编译器通常被称为JVM编译器(用于Java虚拟机)”可能会引起误解,但它仍然成立,因为javac本质上将Java源代码转换为字节代码以供JVM运行,然后根据Javac将其解释为机器可读指令。平台

As javac is a compiler for JVM, it is not a part of it. 由于javac是JVM的编译器,因此它不是其中的一部分。

But as Ghostcat states referring javac as JVM compiler is misleading as JVM has got its own Just-In-Time Compilation implementation 但是正如Ghostcat指出的那样,将Javac称为JVM编译器会产生误导,因为JVM拥有自己的即时编译实现

Hope this adds to the earlier answers 希望这能为早先的答案增色

Meanwhile, I found this image which illustrates exactly where the java compiler is situated and that it is part of JDK but not part of JVM or JRE: 同时,我找到了该图像,该图像准确地说明了Java编译器所在的位置,并且它是JDK的一部分,而不是JVM或JRE的一部分:

图表

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

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