Android:javac 与 Dalvik [英] Android: javac vs Dalvik

查看:24
本文介绍了Android:javac 与 Dalvik的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的理解是 Google 不喜欢 Oracle 在 Java ME 中使用 JRE 的许可政策,所以它只是重写了它使用自己的 JVM 规范,模仿 JRE,但行为略有不同,尤其是当它出现时使事情更高效、更安全.

My understanding is that Google didn't like Oracle's licensing policy for using the JRE in Java ME so it just rewrote it using its own JVM specification that mimics the JRE but behaves a little bit differently, especially when it comes to making things more efficient and more secure.

所以,如果我的理解是正确的,这意味着当 javac 在一些 Java 源代码上运行并编译成二进制"时byetcode,一个兼容的 JVM 将解释与 Dalvik 不同的字节码(在某些情况下).这是固有的Dalvik 和其他(兼容)JVM 之间的区别.

So, if my understanding is correct, it means that when javac is ran on some Java source code and compiled into "binary" byetcode, a compliant JVM will interpret that bytecode different than Dalvik will (in some cases). This is the inherent difference between Dalvik and other (compliant) JVMs.

如果到目前为止我说的有任何不正确,请首先纠正我!

If anything I have said so far is incorrect, please begin by correcting me!

现在,如果 Android 带有自己的编译器(它可能),并在不同的(Dalvik 兼容)中编译 Java 源代码比 javac 的方式,然后我就可以理解某些代码(不是用 Android SDK 编译的)在安卓设备:

Now, if Android came with its own compiler (which it might), and compiled Java source in a different (Dalvik-compliant) manner than javac, then I could understand how some code (not compiled with the Android SDK) would not run on an Android device:

MySource.java --> javac --> MySource.class (JRE-compliant) --> JVM --> running Java app
MySource.java --> android-compiler --> MySource.class (Dalvik-compliant) --> Dalvik JVM --> running Android app

但是,看起来您使用javac 来编译Android 应用程序!?!?所以看起来我们有这个:

However, it looks like you use javac to compile Android apps!?!? So it looks like we have this:

MySource.java --> javac --> MySource.class (JRE-compliant) --> JVM --> running Java app
MySource.java --> javac --> MySource.class (JRE-compliant) --> Dalvik JVM --> running Android app (???)

如果用javac将所有源码编译成字节码,那为什么Dalvik不能运行某些类型Java代码?

If javac is used to compile all sources into bytecode, then why is it that Dalvik can't run some types of Java code?

昨天我问了一个非常相似的问题,虽然它在技术上得到了回答(重新阅读我的问题后我明白我只是不够具体)没有人能够解释 Dalvik 固有的东西是什么使得无法运行来自 Google Guice 或 Apache Camel 等项目的 Java 代码.有人告诉我,为了让 Camel 在 Dalvik 上运行,我必须获得 Camel 的源代码,然后它必须使用 Android SDK 构建",但我无法弄清楚这意味着什么或暗示了什么.

I asked a very similar question yesterday and although it was technically answered (after re-reading my question I see I was simply not specific enough) no one was able to explain what it is that's inherent to Dalvik that makes it impossible to run Java code from projects like Google Guice or Apache Camel. I was told that in order to get Camel to run on Dalvik, that I would have to get Camel's source and then it would have to be "built with the Android SDK", but I couldn't get clarity on what that meant or implied.

例如,对于 Camel,你有这个(简化):

With Camel, for instance, you have this (simplified):

RouteBuilder.java --> javac --> RouteBuilder.class --> jartool --> camel-context-2.9.jar --> JVM --> running Camel ESB
RouteBuilder.java --> javac --> RouteBuilder.class --> jartool --> camel-context-2.9.jar --> Dalvik JVM --> doesn't work !!! (???)

显然,Dalvik JVM 内部发生了一些事情,阻止它运行某些类型的 Java 代码.我试图了解哪些类型的 Java 代码在输入"到 Dalvik JVM 中时不会运行.

Clearly, something is happening inside the Dalvik JVM that prevents it from running certain types of Java code. I'm trying to understand what types of Java code will not run when "fed" into the Dalvik JVM.

之前但是 Camel 3.0 将在 Android 上运行!"我知道 - 不是我的问题!

In before "but Camel 3.0 will run on Android!" I know - not my question!

推荐答案

I'm trying to understand what types of Java code will not run when "fed" into the Dalvik JVM.

Dalvik JVM 在以下方面与其他 JVM 不同:

  • 它使用特殊的 DEX 格式来存储应用程序二进制文件 vs. JAR和标准 Java 虚拟机使用的 Pack200 格式.谷歌声称 DEX 生成的二进制文件比 JAR 更小.我觉得他们可以使用 Pack200 取得同样的成功,但他们决定继续使用在这方面有自己的方式

  • It uses special DEX format for storing applications binaries vs. JAR and Pack200 formats used by standard Java virtual machines. Google claims that DEX results in smaller binaries than JAR. I think they could use Pack200 with the same success, but they decided to go their own way in this aspect

Dalvik JVM 针对运行多个 JVM 进程进行了优化同时

Dalvik JVM was optimized for running multiple JVM processes simultaneously

Dalvik JVM 使用基于寄存器的架构与基于堆栈的架构旨在加速执行和的其他 JVM 的架构减少二进制大小

Dalvik JVM uses register-based architecture vs. stack based architecture of other JVMs with intent to speed up execution and to reduce binary sizes

它使用自己的指令集(不是标准的 JVM 字节码)

It uses its own instructions set (not a standard JVM bytecode)

一个可以运行(如果需要)多个独立的 Android 应用程序在单个 JVM 进程中

One can run (if needed) several independent Android applications within a single JVM process

应用程序执行可以跨越多个 Dalvik JVM 进程自然".为了支持它补充:

Application execution can span across several Dalvik JVM processes "naturally". To support this it adds:

  • 基于Parcel和Parcelable的特殊对象序列化机制类.从功能上讲,它的用途与标准 Java 相同可序列化,但会导致更小的数据占用空间,并且可能对类版本的差异更加宽容

  • Special object serialization mechanism based on Parcel and Parcelable classes. Functionally it serves the same purpose as standard Java Serializable, but results in smaller data footprint and is potentially more lenient towards differences in versions of classes

基于Android的特殊方式来执行进程间调用(IPC)Android 界面定义语言 (AIDL)

Special Android way to execute inter process calls (IPC) based on Android Interface Definition Language (AIDL)

直到 Android 2.2 Dalvik JVM 不支持 JIT 编译对 Android 应用程序性能产生不利影响.在 2.2 中添加显着提高常用应用程序的执行速度

Until Android 2.2 Dalvik JVM did not support JIT compilation which adversely impacted Android application performance. Adding it in 2.2 improves markedly execution speed for often used applications

这篇关于Android:javac 与 Dalvik的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆