安卓:javac的VS的Dalvikjavac、VS、Dalvik

由网友(温柔似你眉眼)分享简介:我的理解是,谷歌不喜欢甲骨文的许可政策使用的JRE中的Java ME所以它只是重写使用它自己的JVM规范的模仿的JRE的行为,但一点点的不同,特别是当它涉及为使事情变得更高效,更安全。所以,如果我的理解是正确的,这意味着当的javac 正在运行的一些Java源代码code和汇编成二进制byet code,一个标准...

我的理解是,谷歌不喜欢甲骨文的许可政策使用的JRE中的Java ME所以它只是重写 使用它自己的JVM规范的模仿的JRE的行为,但一点点的不同,特别是当它涉及 为使事情变得更高效,更安全。

所以,如果我的理解是正确的,这意味着当的javac 正在运行的一些Java源代码code和汇编成二进制 byet code,一个标准的JVM将跨preT该字节code比Dalvik的不同将(在某些情况下)。这是固有的 的Dalvik和其他(兼容)JVM之间的区别。

如果任何事情我都表示,到目前为止是不正确,请纠正我开始了!

现在,Android是否带着自己的编译器(它可能),并在编译的Java源代码不同(Dalvik的标准) 方式比的javac ,那么我可以理解为什么一些code(不与Android的SDK编译)将不会对一个运行 Android设备:

  MySource.java  - > javac的 - > MySource.class(JRE兼容) - > JVM  - >运行Java应用程序
MySource.java  - > Android的编译器 - > MySource.class(Dalvik的标准) - >的Dalvik JVM  - >运行Android应用
 

不过,它看起来像你使用的javac 编译Android应用程序!?!?所以看起来我们有这样的:

  MySource.java  - > javac的 - > MySource.class(JRE兼容) - > JVM  - >运行Java应用程序
MySource.java  - > javac的 - > MySource.class(JRE兼容) - >的Dalvik JVM  - >运行Android应用程序(???)
 

如果的javac 用于编译所有来源为字节code,那么为什么到了的Dalvik不能运行某些类型 Java的code?

我问了一个非常类似的问题昨天,虽然它在技术上回答(在重新阅读我的问题 我知道我只是不够具体),没有人能够解释它是什么,是固有的Dalvik的 使得它不可能来自像谷歌吉斯或Apache Camel的项目运行Java code。有人告诉我,为了让骆驼上的Dalvik运行,那我就一定得骆驼的来源,那么就必须建立了Android SDK,但我无法得到澄清什么意思或暗示的保证

使用骆驼,比如,你有这个(简体):

  RouteBuilder.java  - > javac的 - > RouteBuilder.class  - > jartool  - >骆驼上下文2.9.jar  - > JVM  - >运行骆驼ESB
RouteBuilder.java  - > javac的 - > RouteBuilder.class  - > jartool  - >骆驼上下文2.9.jar  - >的Dalvik JVM  - >不行! (???)
 

很显然,事情是发生在Dalvik JVM中,从运行某些类型的Java code prevents它。 我想了解什么类型的Java code将无法运行时,喂成的Dalvik JVM。

编辑:在之前的!,但骆驼3.0将运行在Android 的我知道 - 不是我的问题。

解决方案

 我想了解什么类型的Java code将无法运行时,喂成的Dalvik JVM。
 

的Dalvik JVM不同于其他JVM在以下几个方面:

它采用特殊的DEX格式,用于存储应用程序二进制文件与JAR 和使用的标准的Java虚拟机Pack200格式。谷歌 声称DEX产生较小的二进制文件比JAR。我认为他们 可以使用Pack200用同样的成功,但他们决定去他们的 在这方面自己的方式

的Dalvik JVM中运行多个JVM进程优化 同时

的Dalvik JVM使用基于寄存器的架构与协议栈 其他JVM意图的架构,以加快执行和 减少二进制文件大小

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

一个可以运行(如果需要)几个独立的Andr​​oid应用 一个JVM进程中

应用程序的执行可以跨多个的Dalvik JVM进程跨越 自然。为了支持这一点, 补充说:

根据包裹和Parcelable特殊对象序列化机制 类。在功能上也有异曲同工之妙的标准Java 序列化的,但会导致更小的数据占用空间,并有可能对在班级版本的差异更为宽松

执行进程间调用(IPC)的特别的Andr​​oid方式的基础上 Android的接口定义语言(AIDL)

到了Android 2.2的Dalvik JVM不支持JIT编译它 不利影响的Andr​​oid应用程序的性能。将它添加在2.2 显着提高执行速度为经常使用的应用程序

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.

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!

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

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 (???)

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

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.

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 !!! (???)

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.

Edit: 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 differs from other JVMs in following aspects:

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 was optimized for running multiple JVM processes simultaneously

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

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

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

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

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

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

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

阅读全文

相关推荐

最新文章