为什么android是建立在VM(Dalvik)之上的
我很好奇是什么让谷歌选择在java VM上开发android的框架。
在近 6 个月为 Android 编写代码的过程中,我观察到在资源有限的平台中的 VM 上运行代码非常慢。这涉及到很多开销。我知道java是可移植的等等,难道根本不可能使用本机语言并获得VM提供的性能和功能吗?对于面向性能的应用程序,最终仍然要编写本机代码并用 JNI 包装它,
那么为什么谷歌选择这个特定的堆栈:
- 基于 Arm 的核心(可以理解,ARM 是移动设备的最佳选择)
- Linux(开源)
- Java VM(我的问题)
编辑:我知道 java - JVM 在我的服务器上与 C++ 应用程序运行相同,但在 android 上则不然。 对于 android 来说,情况并非如此 - 根据我的经验,用 JNI 包装的 C++ 代码运行速度比 java 代码快得多(注意我什至检查了 java 中静态块中完全相同的代码)我会同意你的观点在任何其他平台上回答。
I am curious to know what made google choose to develop android's framework on java VM.
In the process of writing code for android for nearly 6 months now, I observed that running code on a VM in a resource limited platform is really slow. There is a lot of overhead involved. I know that java is portable etc etc, is it not possible at all to use native languages and get both performance and features offered by a VM ? For performance oriented applications one still ends up writing native code and wrap it with JNI,
So why did google choose this particular stack :
- Arm based core (understandable, ARM is the best for mobile devices)
- Linux (Open source)
- Java VM (My question)
EDIT : I know java - JVM runs on par with C++ applications on my server, but not on android.
With respect to android its not the case - As a matter of my experience, a C++ code wrapped with JNI runs far faster than java code (note I have even checked with exact same code from a static block in java) I will agree with your answer on any other platform.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Dalvik VM 使用自己的字节码,而不是 Java 字节码。它的设计速度非常快(相对而言)。我认为其标题中的“VM”部分有点转移注意力,因为人们倾向于认为无论如何它都会“慢”。您自己说过,您正在使用“资源有限的平台”——这可能是导致性能下降的主要原因,比 Dalvik VM 更严重。
免责声明:我不是任何方面、形式或形式的 Dalvik 或 Android 专家。然而,人们似乎倾向于基于“它使用虚拟机”和“你用 Java 编写应用程序”等想法对 Android 做出很多假设,而无需进一步研究该平台。
请观看此视频,了解有关 Dalvik VM 内部结构的更多信息(来自 Google I/O) 2008)。
The Dalvik VM uses its own bytecode, not Java bytecode. It's designed to be very fast (relatively speaking). I think the "VM" part of its title is a bit of a red herring, as people tend to assume that it will be "slow" no matter what. You said it yourself, you're working with a "resource-limited platform" -- that's likely your main cause of slow performance, much more so than the Dalvik VM.
Disclaimer: I am not an expert on Dalvik or Android in any way, shape, or form. However, it seems like people can tend to make a lot of assumptions about Android based on ideas like "it uses a VM" and "you write applications in Java", without looking into the platform further than that.
See this video for more information than you probably ever wanted to know on the Dalvik VM Internals (from Google I/O 2008).
1) 据我所知,Java 是大学甚至高中/同等学历中最普遍教授的语言。它在专业领域得到广泛使用,并且背后有大量代码库,可以帮助开发人员更快地创建更高质量的应用程序。
2) 与本机代码相比,开销并没有那么大,特别是对于经过 JIT 优化并由设计得更好的 gc 进行监控的精心设计的代码。
确实,我认为仅凭这两个原因就可以证明为什么选择 Java 作为 Android 支持的主要语言。
1) Java is, as far as I know, the most universally taught language in universities and even high schools/equivalent. It is used widely in the professional world and has a lot of codebase behind it to help ease developers into creating more quality apps, faster.
2) The overhead is not that great vs. native code, especially with well designed code that is JIT optimized and being monitored by an ever-more-well-designed-gc.
Really, I think these two reasons alone can justify why Java was chosen as the primary language to be supported on Android.
我认为关键在于,不要以与桌面或服务器虚拟化相同的方式来考虑 Java VM——它们非常不同。在最基本的层面上,Java VM(在本例中为 Dalvik)只是“编译器”生成的字节码到本机机器代码之间的转换层。它是一个虚拟机——但它没有与在 VirtualBox 中运行 Ubuntu 相同的开销。
I think the key, is to not think about the Java VM in the same sense that you think of for Destkop or Server virtualization -- they're very different. At the most basic level, the Java VM (in this case Dalvik) is simply a translation layer between the bytecode generated by the "compiler" into native machine code. It is a virtual machine -- but it doesn't have the same overhead as say, running Ubuntu in VirtualBox.
Java 应用程序已被证明(并非总是)与用 C、C++ 等语言编写的应用程序一样快速、流畅地运行。请参阅此 参考,查看 PDF。许多人说 java 和 vm 很慢,但实际上并没有太多证据或细节 - 本参考文献详细介绍了
Java 是一种广为人知的语言,并且很容易掌握。将android sdk和工具交给所有这些了解Java的人手中已经使android市场具有为用户提供大量应用程序的巨大潜力。
免责声明:我不是这方面的专家,只是我的2分钱
Java applications have been proven(not always) to run just as quickly and smoothly as applications written in languages like c, c++, etc. See this reference, check out the PDFs. Many people say that java and the vm is slow without actually much proof or details - and this reference goes into some detail
Java is a widely known language and it's easy to pick up. putting the android sdk and tools in the hands of all these people who know Java already allows the android market to have a great potential of supplying its users with a large quantity of applications.
disclaimer: i'm no expert on this matter, just my 2 cents