Android之Dalvik

Dalvik是Google公司自己设计用于Android平台的Java虚拟机。Dalvik虚拟机是Google等厂商合作开发的Android移动设备平台的核心组成部分之一。它可以支持已转换为 .dex(即Dalvik Executable)格式的Java应用程序的运行,.dex格式是专为Dalvik设计的一种压缩格式,适合内存和处理器速度有限的系统。Dalvik 经过优化,允许在有限的内存中同时运行多个虚拟机的实例,并且每一个Dalvik 应用作为一个独立的Linux 进程执行。独立的进程可以防止在虚拟机崩溃的时候所有程序都被关闭。

不同于其他堆栈结构的Java虚拟机,dalvik采用的是基于寄存器的架构。
dx工具将部分(但不是全部)Java的.class文件转换成.dex格式。多个类被包含在一个.dex文件中。为了节省空间,各个类文件中重复的字符串和其他常数只在.dex输出中存放一次。Java字节码被转换成Dalvik虚拟机所使用的替代指令集。一个未压缩的.dex文件通常比来自相同.class文件的已压缩.jar文档小。
当被安装到移动设备时,Dalvik可执行文件可能会被修改。为了进一步优化,虚拟机可能会调整文件内部分数据的端序、内联一些函数和简单的结构体、并短路掉一些不必要的操作等。
  自Android 2.2开始,Dalvik支持JIT(just-in-time,即时编译技术)。
  优化后的Dalvik较其他标准虚拟机存在一些不同特性
  ·占用更少空间
  ·为简化翻译,常量池只使用32位索引
  ·标准Java字节码实行8位堆栈指令。Dalvik使用16位指令集直接作用于局部变量。局部变量通常来自4位的“虚拟寄存器”区。这样减少了Dalvik的指令计数,提高了翻译速度。
  当Android启动时,Dalvik VM 监视所有的程序(APK),并且创建依存关系树,为每个程序优化代码并存储在Dalvik缓存中。Dalvik第一次加载后会生成Cache文件,以提供下次快速加载,所以第一次会很慢。
  Dalvik解释器采用预先算好的Goto地址,每个指令对内存的访问都在64字节边界上对齐。这样可以节省一个指令后进行查表的时间。为了强化功能, Dalvik还提供了快速翻译器(Fast Interpreter)


dx是一套工具,可以将 Java .class 转换成 .dex 格式. 一个dex档通常会有多个.class。由于dex有时必须进行最佳化,会使档案大小增加1-4倍,以ODEX结尾。)

Dalvik和标准Java 虚拟机 (JVM)首要差别
Dalvik 基于 寄存器,而 JVM 基于栈。
基于 寄存器虚拟机对于编译后变大的程序来说,在它们执行的时候,花费的时间更短。(Also of register-based VMs allow faster execution times at the expense of programs which are larger after compilation.)
Dalvik和Java运行环境的区别
[2] 1:Dalvik主要是完成对象生命周期管理, 堆栈管理,线程管理,安全和异常管理,以及 垃圾回收等等重要功能。
2:Dalvik负责进程隔离和线程管理,每一个Android应用在底层都会对应一个独立的Dalvik 虚拟机实例,其代码在虚拟机的解释下得以执行。
3:不同于Java 虚拟机运行java 字节码,Dalvik虚拟机运行的是其专有的 文件格式Dex
4:dex 文件格式可以减少整体文件尺寸,提高I/o操作的类查找速度。
5:odex是为了在运行过程中进一步提高性能,对dex文件的进一步优化。
6:所有的Android应用的线程都对应一个Linux线程, 虚拟机因而可以更多的依赖 操作系统线程调度和管理机制
7:有一个特殊的 虚拟机进程Zygote,他是虚拟机实例的孵化器。它在系统启动的时候就会产生,它会完成 虚拟机的初始化,库的加载,预制类库和初始化的操作。如果系统需要一个新的 虚拟机实例,它会迅速复制自身,以最快的数据提供给系统。对于一些只读的系统库,所有 虚拟机实例都和Zygote共享一块内存区域。
8:Dalvik是由Dan Bornstein编写的,名字来源于他的祖先曾经居住过名叫Dalvík的小渔村,村子位于冰岛Eyjafjörður

摘自百度Dalvik

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
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.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值