java - Java Bootstrapped 的编译器?

标签 java compiler-construction javac bootstrapping

Java的编译器是Bootstrapped的吗?

如果是自举的,第一个 java 编译器是如何编写的?

最佳答案

这是一个有趣的问题。当前来自 Oracle 的 javac 编译器,它只是许多 (1)一个编译器,实际上是用 Java 编写的,这意味着,是的,你可以认为它是自举的,假设您的定义意味着“已经被自举,以便它现在可以自行编译”(2)

虚拟机本身主要是从内存中用 C++ 编写的,因此,在引导编译器的同时,构建 JRE 需要 C++ 编译器。


(1) GCJ 是另一个,它恰好是用 C 编写的,所以它取决于您指的是哪个编译器。

(2) 您问题中的单词“bootstapped”可以有多种理解方式。如果您对“自举”的定义是“必须自举才能获得工作编译器”,那么答案是否定的。


至于第一个 Java 编译器是如何在引导之前编写的,这仍然迷失在时间的迷雾中(或者 Gosling 等人的想法)。

鉴于无需任何花哨的 OO 概念即可相对轻松地编写编译器,我猜测是他们只是用 C 或 C++ 编写了第一个(或几个)。

this entry from the Wayback Machine 似乎证实了这一点:

The team's efforts kicked off the development of a new object-oriented programming language that Gosling called Oak, after the tree outside his window. Loosely based on C++, the language was stripped down to a bare minimum in order to be compatible with the limited space the chips in handheld devices would offer, and was designed to allow programmers to more easily support dynamic, changeable hardware.

然后,

Arthur van Hoff wrote an Oak compiler entirely in Oak instead of in C. Naughton and Jonathan Payne built an Oak-ready browser called "WebRunner." The first applet -- Duke waving back at his parents over the Internet -- was born.

此外,来自Patrick Naughton's epilogue在他的书“The java Handbook”(我的粗体)中:

Now that we had a plan of record, to ship Oak in source form on the net, things got much more productive. We started focusing on fixing all of the loose ends in the language. Jonathan Payne was working on optimizing the interpreter. Arthur van Hoff rewrote the compiler in Oak itself, replacing the C version that James originally wrote. This was also a good test of the environment since this compiler was the largest single Oak program ever written. A fair number of burned out engineers were using this time as paid vacation by Sun, but for the most part the core team ignored them and got back to work.

因此,看起来“Java”(Oak) 编译器的原始版本是用 C 编写的,然后从那里引导。

关于java - Java Bootstrapped 的编译器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9221912/

相关文章:

java - 我的 Prim 算法无法正确生成迷宫

java - 可以使用 `String.length()` 来查看两个 String 对象中哪一个更大?

visual-studio - 在编译时检测编译器版本

haskell - GHC 部分评估和单独编译

java - 在 Java8 中使用 lambda 排序和创建映射

java - 递归和不变性

c++ - 假设安装了 GCC 和 G++ 如何编译使用 boost 库的文件? (线程)

java - 无法将我的 .java 转换为 .class

java - java jre 与 jdk 的替代方案

java - 使用jar中的类路径类使用javac和java编译并运行