简体   繁体   English

Java 编译器和 JVM 是用哪种语言编写的?

[英]In which language are the Java compiler and JVM written?

Java编译器( javac )、虚拟机 (JVM) 和java starter 是用哪些语言编写的?

The precise phrasing of the question is slightly misleading: it is not "the JVM" or "the compiler" as there are multiple JVM vendors (jrockit is one, IBM another) and multiple compilers out there.这个问题的准确措辞有点误导:它不是“JVM”“编译器”,因为有多个 JVM 供应商(jrockit 是一个,IBM 是另一个)和多个编译器

  • The Sun JVM is written in C , although this need not be the case - the JVM as it runs on your machine is a platform-dependent executable and hence could have been originally written in any language.太阳JVM写在C ,虽然这不是必须的情况下-因为它运行在您的机器上是依赖于平台的可执行文件,因此本来最初写在任何语言的JVM。 For example, the original IBM JVM was written in Smalltalk例如,最初的 IBM JVM 是用Smalltalk编写的

  • The Java libraries ( java.lang , java.util etc, often referred to as the Java API ) are themselves written in Java, although methods marked as native will have been written in C or C++ . Java 库( java.langjava.util等,通常称为Java API )本身是用 Java 编写的,尽管标记为native方法将是用CC++编写的。

  • I believe that the Java compiler provided by Sun is also written in Java.相信Sun提供的Java编译器也是用Java编写的。 (Although again, there are multiple compilers out there) (尽管同样,那里有多个编译器)

The very first Java compiler was developed by Sun Microsystems and was written in C using some libraries from C++.第一个 Java 编译器是由 Sun Microsystems 开发的,是使用 C++ 中的一些库用 C 编写的。 Today, the Java compiler is written in Java, while the JRE is written in C.今天,Java 编译器是用 Java 编写的,而 JRE 是用 C 编写的。

We can imagine how the Java compiler was written in Java like this:我们可以想象 Java 编译器是如何用 Java 编写的:

The Java compiler is written as a Java program and then compiled with the Java compiler written in C(the first Java compiler). Java 编译器是作为 Java 程序编写的,然后用 C 语言编写的 Java 编译器(第一个 Java 编译器)进行编译。 Thus we can use the newly compiled Java compiler(written in Java) to compile Java programs.这样我们就可以使用新编译的Java编译器(用Java编写)来编译Java程序。

From Java Docs来自Java 文档

The compiler is written in Java and the runtime is written in ANSI C编译器用 Java 编写,运行时用 ANSI C 编写

Actually the Oracle JVM is written in C++, not C.实际上,Oracle JVM 是用 C++ 编写的,而不是 C。

Take a look at the HotSpot JVM code here: http://openjdk.java.net/groups/hotspot/在此处查看 HotSpot JVM 代码: http : //openjdk.java.net/groups/hotspot/

原则上几乎任何东西,通常是 C

This link should answer your question 这个链接应该可以回答你的问题

It seems the compiler is now written in Java, but the runtime is written in ANSI C似乎编译器现在是用 Java 编写的,但运行时是用 ANSI C 编写的

Jikes RVM , a self-hosting JVM used extensively for research purposes is written in Java. Jikes RVM是一种广泛用于研究目的的自托管 JVM,它是用 Java 编写的。 It's not the one people run on their desktops, but it's way up there on my list of "now let's show off the general power of the language."它不是人们在他们的桌面上运行的那个,但它在我的“现在让我们炫耀该语言的一般力量”的列表中名列前茅。

Supposing you're talking about the Hotspot JVM, which is iirc provided by Sun, it is written in C++.假设您在谈论 Hotspot JVM,它是 Sun 提供的 iirc,它是用 C++ 编写的。 For more info on the various virtual machines for Java, you can check this link .有关 Java 的各种虚拟机的更多信息,您可以查看此链接 javac , like most Java compilers, is written in Java. javac与大多数 Java 编译器一样,是用 Java 编写的。

  • When Java was introduced by Sun Microsystem, the java compiler was written in C using some libraries from C++.当 Sun Microsystem 引入 Java 时, Java 编译器是使用 C++ 中的一些库用 C 编写的。
  • As there is a concept in Compiler Design called Bootstrapping, Mostly it is used in Compiler Development, Bootstrapping is the process of writing a compiler(Or Assembler) In the source programming language which it is intended to compile.由于编译器设计中有一个概念称为 Bootstrapping,它主要用于编译器开发, Bootstrapping是在要编译的源编程语言中编写编译器(或汇编器)的过程。 It is used to produce a self-hosting compiler.它用于生成自托管编译器。 The development of compilers for new Programming languages first developed in an existing language and then rewritten in the new language and compiled by itself.为新的编程语言开发编译器首先用现有语言开发,然后用新语言重写并自行编译。 That's why today, Java compiler is written in Java itself .这就是为什么今天,Java 编译器是用 Java 本身编写的
  • Java Virtual Machine: Java virtual machine is an abstract machine. Java虚拟机: Java虚拟机是一个抽象的机器。 Like a real computing machine, It has an instruction set and manipulates various memory areas of runtime.像真正的计算机器一样,它有一个指令集并操纵运行时的各种内存区域。 Usually, JVM interprets the byte code into Machine code.通常,JVM 将字节码解释为机器码。

(For More Information You can check this link: https://docs.oracle.com/javase/specs/jvms/se7/html/ ) (有关更多信息,您可以查看此链接: https : //docs.oracle.com/javase/specs/jvms/se7/html/

On most operating systems, JVMs are written in ISO C++. 在大多数操作系统上,JVM是用ISO C ++编写的。 I doubt ANSI C is used, as it's an entirely different language that is quite antiquated nowadays. 我怀疑是否使用了ANSI C,因为它是一种完全不同的语言,现在相当陈旧。

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

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