深入理解Android Dalvik虚拟机

需积分: 50 4 下载量 155 浏览量 更新于2024-07-16 收藏 4.99MB PDF 举报
"深入理解Android Dalvik虚拟机及其与Java虚拟机的差异" Android Dalvik虚拟机是Android操作系统中用于执行应用程序的关键组件。它不同于标准的Java虚拟机(JVM),而是专门为Android平台定制,旨在优化在移动设备上的性能和资源利用率。 **Dalvik虚拟机的特点** 1. **体积小,内存占用低**:Dalvik虚拟机的设计考虑了移动设备的硬件限制,因此它的体积小,运行时占用的内存空间相较于传统JVM更少。 2. **DEX文件格式**:Dalvik使用DEX(Dalvik Executable)文件格式,这是一种优化过的二进制格式,相比于Java的.class文件,DEX文件更紧凑,加载和执行速度更快。 3. **32位索引常量池**:Dalvik的常量池使用32位索引,这使得查找类方法、字段名和常量的效率更高。 4. **基于寄存器的架构**:与JVM的栈式架构不同,Dalvik采用寄存器架构,这减少了内存访问,提高了执行效率。 5. **功能完善**:Dalvik虚拟机提供了对象生命周期管理、堆栈管理、线程管理、安全与异常管理以及垃圾回收等核心功能,确保了应用的正常运行。 6. **每个进程一个虚拟机实例**:在Android系统中,每个应用程序都在其自己的进程中运行,因此每个进程都有一个独立的Dalvik虚拟机实例,增强了应用的隔离性和安全性。 **Dalvik虚拟机与Java虚拟机的区别** 1. **字节码类型**:Java虚拟机运行的是Java字节码,而Dalvik运行的是专为Android优化的Dalvik字节码,它是由Java字节码预先转换得到的。 2. **预编译与解释执行**:Java程序在JVM上是即时编译(JIT)或提前编译(AOT),而Dalvik通常先将所有代码转换为DEX格式,然后在设备上解释执行,但后期版本的Android引入了ART(Android RunTime),采用了预先编译的方式。 3. **内存模型**:Dalvik的寄存器模型与JVM的栈模型相比,更利于减少内存操作,提高执行速度。 4. **运行环境**:Dalvik是针对移动设备优化的,而JVM设计时考虑的是通用计算环境,因此在某些特定功能和性能优化上有所不同。 5. **兼容性**:由于字节码格式和执行方式的差异,Dalvik虚拟机与Java虚拟机并不兼容,无法直接运行彼此的字节码。 Android Dalvik虚拟机是Android系统能够高效运行Java应用程序的关键技术,它的设计和实现充分考虑了移动设备的资源有限性和性能需求。随着Android的发展,Dalvik逐渐被ART取代,但其设计理念和对移动平台的优化策略仍对Android系统有深远影响。
2010-05-19 上传
Android虚拟机Dalvik完整源码,宝贵资源,欢迎下载! This directory contains the Dalvik virtual machine and core class library, as well as related tools, libraries, and tests. A note about the licenses and header comments --------------------------------------------- Much of the code under this directory originally came from the Apache Harmony project, and as such contains the standard Apache header comment. Some of the code was written originally for the Android project, and as such contains the standard Android header comment. Some files contain code from both projects. In these cases, the header comment is a combination of the other two, and the portions of the code from Harmony are identified as indicated in the comment. Here is the combined header comment: /* * Copyright (C) The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * ---------- * * Portions of the code surrounded by "// BEGIN Harmony code" and * "// END Harmony code" are copyrighted and licensed separately, as * follows: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Native SH call bridge --------------------- Native SH call bridge is written by Shin-ichiro KAWASAKI and Contributed to Android by Hitachi, Ltd. and Renesas Solutions Corp.