在 Android 上运行 Java 字节码 - 在 DalvikVM 之上的 Sun JVM

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/670987/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 17:41:02  来源:igfitidea点击:

Running Java bytecode on the Android - Sun JVM on top of DalvikVM

javaandroidclojurejvm

提问by George

Since both the java implementation (OpenJDK) and Android's virtual machine DalvikVM are opensource it must be possible to implement Sun's JavaVM on top Google's DalvikVM. This would make it possible to run JVM based apps and languages (Clojure, Jython) out-of-the-box on the android.

由于 java 实现 ( OpenJDK) 和 Android 的虚拟机 DalvikVM 都是开源的,因此必须可以在 Google 的 DalvikVM 之上实现 Sun 的 JavaVM。这将使Clojure, Jython在 android 上开箱即用地运行基于 JVM 的应用程序和语言 ( )成为可能。

Is there an ongoing effort to produce such an implementation of the Sun JVM?

是否一直在努力产生 Sun JVM 的这种实现?

采纳答案by TofuBeer

The OpenJDK makes use of native code so it would be a non-trivial port... there is at least one VM (JikesRVM) that is written in Java, unfortunately it is not a completely working implementation of Java.

OpenJDK 使用本机代码,因此它将是一个重要的端口......至少有一个用 Java 编写的VM ( JikesRVM),不幸的是,它不是 Java 的完整实现。

Since DalvikVM runs classes that were converted from .class files it should be possible to convert the classes over. Then the "only" issue is when languages generate bytecode on the fly - for that it would require the extra step of converting the generated bytecode over to the DalvikVM format while the program is running on the DalvikVM.

由于 DalvikVM 运行从 .class 文件转换而来的类,因此应该可以转换这些类。那么“唯一”的问题是语言在运行中生成字节码时 - 为此,当程序在 DalvikVM 上运行时,需要额外的步骤将生成的字节码转换为 DalvikVM 格式。

Hmmm.... sort of a JITT (Just In Time Translator) that covertes class files to a DalvikVM files at runtime on the phone. I wonder how slow that would be.

嗯......有点像 JITT(即时翻译器),它在手机上运行时将类文件转换为 DalvikVM 文件。我想知道那会有多慢。

回答by Peter Lawrey

I don't think the problem is technical. In theory you can migrate OpenJDK to the iPhone for example, but there are legal restriction in place.

我不认为问题出在技术上。例如,理论上您可以将 OpenJDK 迁移到 iPhone,但存在法律限制。

回答by George

In the meantime I have found a possible solution (only JavaME):

与此同时,我找到了一个可能的解决方案(仅限 JavaME):

回答by George

Porting OpenJDK to Android platform is possible. There are effort like : Shark, Zero and caciocavallo that vastly ease the port process (= no ASM, simple AWT peer). Plus Android is nothing but a linux kernel behind. The only question is when will it be done by anybody ?

将 OpenJDK 移植到 Android 平台是可能的。有一些努力,如:Shark、Zero 和 caciocavallo,它们极大地简化了端口过程(= 没有 ASM,简单的 AWT 对等点)。此外,Android 只不过是背后的 linux 内核。唯一的问题是什么时候有人会这样做?

By the way, both iphones and android phones got Jazelle compatible processor, somebody with very strong processor hacking skills would be very welcome to add Jazelle support to OpenJDK. Doing so, we could choose between : very light resource acceleration (Jazelle) and JIT ;-)

顺便说一句,iphone 和 android 手机都有兼容 Jazelle 的处理器,非常欢迎具有非常强大的处理器黑客技能的人为 OpenJDK 添加 Jazelle 支持。这样做,我们可以选择:非常轻的资源加速(Jazelle)和 JIT ;-)

About iPhone, it is the same thing : a port is possible. Only Apple has put a section in the the iPhone license that clearly forbid VM usage. As per European law, to me, this license section is unlegal. Two reasons : You can not force/link buy of two of your product. Here I tune and Iphones are linked. You can not refuse to sell something that you can sell. Here as soon as a VM would be build for iPhone, if it is refused to be put on the iTune store, then this point will apply. Is there anybody that want to chalenge Apple licence legality on earth ? I don't think so, unhappy people will be flying to Android or any other platform.

关于 iPhone,这是同样的事情:端口是可能的。只有 Apple 在 iPhone 许可证中加入了一段明确禁止 VM 使用的部分。根据欧洲法律,对我来说,这个许可部分是非法的。两个原因:您不能强制/链接购买您的两个产品。这里我调和 Iphones 是有联系的。你不能拒绝出售你可以出售的东西。在这里,一旦为 iPhone 构建了一个 VM,如果它被拒绝放在 iTune 商店中,那么这一点将适用。地球上有没有人想挑战苹果许可的合法性?我不这么认为,不开心的人会飞到 Android 或任何其他平台上。

回答by jan

technically it should be possible to interpret hotspot byte-code on dalvik vm or dalvik's byte-code on hotspot, but it will never be efficient (not mentioning elegant) design for a long run. the cost of doing that might become very high especially with respect to maintenance in the future evolution of such a split ecosystem.

从技术上讲,应该可以在 dalvik vm 上解释热点字节码或在热点上解释 dalvik 的字节码,但从长远来看,它永远不会是高效的(更不用说优雅的)设计了。这样做的成本可能会变得非常高,尤其是在这种分裂生态系统未来演变的维护方面。

i think, from the very beginning, dalvik vm is a matter of power/market control rather than innovative effort to improve java virtual machine ecosystem. dalvik vm and hotspot vm are lake two highway bridges across the same river build in parallel five meters from each other. it divides and brings confusion to java technological ecosystem.

我认为,从一开始,dalvik vm 就是一个权力/市场控制问题,而不是改进 java 虚拟机生态系统的创新努力。dalvik vm 和 hotspot vm 是跨越同一条河流的湖两座公路桥,彼此平行,相距五米。它分裂并给 Java 技术生态系统带来了混乱。

google is, in my opinion, definitely the technological leader with innovative contributions over last decade that dwarf far more conservative oracle, but in this very subject they have shaken the java ecosystem in nearly destructive way. we (programmers) should strive for a single uniform solution to this problem. that is the main idea behind the concept of "virtual machine" anyway - it should not belong to neither google nor oracle.

在我看来,谷歌绝对是在过去十年中做出创新贡献的技术领导者,使保守的预言机相形见绌,但在这个主题上,他们以近乎破坏性的方式动摇了 Java 生态系统。我们(程序员)应该为这个问题争取一个统一的解决方案。无论如何,这就是“虚拟机”概念背后的主要思想——它不应该属于谷歌或甲骨文。

回答by user3258608

See http://davy.preuveneers.be/phoneme/for MIDP, Foundation and Personal Profile jvms for Android ARM apks. (Thank you Davy!!!)

有关适用于 Android ARM apk 的 MIDP、Foundation 和 Personal Profile jvms,请参阅http://davy.preuveneers.be/phoneme/。(谢谢戴维!!!)

I have repackaged the Foundation jvm for command line use and host it at vkfox.com/android/bin/foundation-jvm.bin for your pleasure. One could use the eclipse compiler in the JavaIDEdroid free app, or the old kopi or kopisusu compilers with this jvm, togeather with the stubbed cdc + foundation jar file from a J2ME jdk for an onboard development system. Using the features of TerminalIDE -- console and sun compiler -- with indicated ref jars would also get you there. This is essentially equivalent to a headless jdk1.4 with the possibility of MIDP or awt graphics.

我重新打包了 Foundation jvm 以供命令行使用,并将其托管在 vkfox.com/android/bin/foundation-jvm.bin 上,以供您欣赏。可以使用 JavaIDEdroid 免费应用程序中的 eclipse 编译器,或带有此 jvm 的旧 kopi 或 kopisusu 编译器,以及来自 J2ME jdk 的存根 cdc + 基础 jar 文件,用于板载开发系统。使用 TerminalIDE 的功能——控制台和 sun 编译器——以及指定的 ref jars 也会让你到达那里。这本质上等同于具有 MIDP 或 awt 图形可能性的无头 jdk1.4。

回答by user908510

try GNURoot app (proot ptrace container) with debian Wheezy;
apt-get update
apt-get install openjdk-7-jre
/usr/lib/jvm/java-7-openjdk-armel/jre/bin/java ...
(including long path)

使用 debian Wheezy 尝试 GNURoot 应用程序(proot ptrace 容器);
apt-get update
apt-get install openjdk-7-jre
/usr/lib/jvm/java-7-openjdk-armel/jre/bin/java ...
(包括长路径)