📜  JVM 和 DVM 的区别

📅  最后修改于: 2021-09-12 11:10:43             🧑  作者: Mango

JVM是在不同平台上运行Java代码的虚拟机。它充当程序和运行Java代码的平台之间的抽象层。 Java代码的可移植性之所以成为可能,是因为有了 JVM。 javac 编译器将源代码文件(Java文件)转换为与机器/平台无关的中间Java字节码格式。然后将此中间文件提供给目标机器/平台,在那里它被翻译成机器代码。 JVM 支持多主机架构,这也是Java应用程序被称为WORA(Write Once Run Anywhere)的原因

JVM(Java 虚拟机)

DVM(Dalvik 虚拟机)

DVM 是执行 Android 应用程序的虚拟机。 javac 编译器生成的Java字节码(.class 文件)被转换成Dalvik 字节码,使应用程序源文件在 DVM 上可执行。由于 Android 设备具有一定的处理能力、内存和电池寿命,因此 DVM 设计原则旨在优化自身,使其即使在低内存/低功耗设备上也能快速加载并流畅运行。此虚拟机在同一设备上运行多个实例时非常高效。

DVM(Dalvik 虚拟机)

差异表

JVM(Java Virtual Machine)

DVM(Dalvik Virtual Machine)

Stack-based VM that performs arithmetic and logic operations through push and pop operands. The result of operations is stored in stack memory. Register-based VM that uses registers located in the CPU to perform arithmetic and logic operations.
Java source code is compiled into Java bytecode format(.class file) that further translates into machine code. Source code files are first of all compiled into Java bytecode format like JVM. Further, the DEX compiler(dx tool) converts the Java bytecode into Dalvik bytecode(classes.dex) file that will be used to create the .apk file.
More information is required to the VM for data loading and manipulation as well as method loading in the stack data structure. Instruction size is larger as it needs to encode the source and destination register of the VM.
Compiled bytecode size is compact because the location of the operand is implicitly on the operand stack. Compiled bytecode size is larger as each instruction needs all implicit operands.
The executable file for the device is .jar file. The executable file for the device is .apk file.
A single instance of JVM is configured with shared processes and memory space in order to run all deployed applications. The device runs multiple DVM instances with a separate process in shared memory space to deploy the code of each application. 
Supports multiple operating systems like Linux, Windows, and Mac OS. Support only the Android operation system.
想要一个更快节奏和更具竞争力的环境来学习 Android 的基础知识吗?
单击此处前往由我们的专家精心策划的指南,旨在让您立即做好行业准备!