Java 如何创建自定义JVM?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/731143/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create custom JVM?
提问by ianmac45
I was reading item #6.10 on http://www.cafeaulait.org/javafaq.htmland I began wondering how the big players go about creating their own implementation of a JVM. Would an experimental something or another be possible (and feasible) for one guy?
我正在http://www.cafeaulait.org/javafaq.html上阅读第 6.10 项,我开始想知道大玩家是如何创建他们自己的 JVM 实现的。对于一个人来说,实验性的东西是否可能(并且可行)?
采纳答案by michael aubert
technically, all the information people need to create a new JVM is in the public specifications for the language and the targetted platform. A JVM would need to behave differently depending on whether it is meant to run on a desktop computer or a mobile phone, even if the bytecode interpretation would be largely identical.
从技术上讲,人们创建新 JVM 所需的所有信息都在语言和目标平台的公共规范中。JVM 需要有不同的行为,这取决于它是打算在台式机还是手机上运行,即使字节码解释在很大程度上是相同的。
A few places to start looking for information:
几个开始寻找信息的地方:
http://en.wikipedia.org/wiki/List_of_Java_virtual_machines
Reading The "Java Virtual Machine Specification" by Tim Lindholm
http://www.jcp.org/en/jsr/detail?id=30
http://en.wikipedia.org/wiki/List_of_Java_virtual_machines
阅读 Tim Lindholm 的“Java 虚拟机规范”
http://www.jcp.org/en/jsr/detail?id=30
From what I have seen of JVM implementations by Sun, IBM or smaller companies like Esmertec, writing a simple JVM is a several man-months project but adding JSR after JSR to support more functionality can take years afterwards.
从我所看到的 Sun、IBM 或像 Esmertec 这样的小公司的 JVM 实现来看,编写一个简单的 JVM 是一个几个人工月的项目,但在 JSR 之后添加 JSR 以支持更多功能可能需要数年时间。
Now, if all you need is a simple bytecode interpreter, it's not that bad, but it's still quite a bit of code to write.
现在,如果您只需要一个简单的字节码解释器,那还不错,但仍然需要编写相当多的代码。
回答by Vincent De Baere
For one thing, you may want to have a look at Apache HarmonyThey have come a long way, so their project history may actually give you a good idea on the effort required. I myself would not bet on it being feasible for one guy
一方面,您可能想看看Apache Harmony他们已经取得了长足的进步,因此他们的项目历史实际上可能会让您对所需的工作有一个很好的了解。我自己不会打赌它对一个人来说是可行的
回答by Tom Hawtin - tackline
I understand that, currently, the big players license the Java library from Sun. They then add their own refinements. The main difference between implementations is the bytecode->machine code compiler.
据我所知,目前,大公司从 Sun 获得 Java 库的许可。然后他们添加自己的改进。实现之间的主要区别是字节码->机器码编译器。
回答by Kai
A handmade JVM would be a great way to learn about virtual machines in general, the issues of program language design (through the JVM spec), and the nitty gritty of parsing and so forth.
手工制作的 JVM 将是学习虚拟机一般知识、程序语言设计问题(通过 JVM 规范)以及解析的本质等的好方法。
If you choose to take it in that direction, you could also explore optimizations, which is where it can get interesting, and you can take research papers and implement their algorithms.
如果您选择朝这个方向发展,您还可以探索优化,这是它变得有趣的地方,您可以撰写研究论文并实现他们的算法。
That being said, if you're less interested in the long and arduous task of creating a VM from scratch, you might want to modify an existing open source VM like Kaffe. It will show you what a virtual machine does, but not necessarily how Java code works in Sun's JVM:
话虽如此,如果您对从头开始创建 VM 的漫长而艰巨的任务不感兴趣,您可能想要修改现有的开源 VM,例如Kaffe。它将向您展示虚拟机的作用,但不一定展示 Java 代码在 Sun 的 JVM 中的工作方式:
Kaffe is a clean room implementation of the Java virtual machine, plus the associated class libraries needed to provide a Java runtime environment.
Kaffe 是 Java 虚拟机的洁净室实现,以及提供 Java 运行时环境所需的相关类库。
This way, you could study the details, but dive in to implementing more interesting features.
通过这种方式,您可以研究细节,但可以深入实现更有趣的功能。