Dalvik

Dalvik

Dalvik 字节码

JVM 基于栈架构,程序run时频繁栈上读写数据,耗费CPU时间 \(Java\;\xrightarrow{\mathrm{javac 编译}}.class\)

\[JVM\xrightarrow{\mathrm{解码}.class}run\;Java\;program\]

Dalvik 虚拟机基于寄存器架构

\[Java\;\xrightarrow{android\;sdk/dx}.dex(Dalvik\;Executable)\]

dex 反编译得到.smali

dex 优化体积

Dalvik 指令

寄存器

字节码类型

方法

1
2
3
4
5
public void onResume() {
    super.onResume();
    n();
    m();
}
.method public onResume()V
    .locals 0

    .line 485
    invoke-super {p0}, Lcom/awesapp/isafe/core/ToolbarActivity;->onResume()V

    .line 486
    invoke-direct {p0}, Lcom/awesapp/isafe/core/MainActivity;->n()V

    .line 487
    invoke-direct {p0}, Lcom/awesapp/isafe/core/MainActivity;->m()V

    return-void
.end method

字段

1
2
3
4
5
6
7
8
9
public static g a;
private long A;
MusicPlayerBottomSheetFragment c;
boolean d;
private ImageView l;

private BottomSheetBehavior<LinearLayout> m;
@BindView(2131296417)
DrawerLayout mDrawerLayout;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# static fields
.field public static a:Lcom/awesapp/isafe/svs/a/g;

# instance fields
.field private A:J

.field c:Lcom/awesapp/isafe/musicplayer/MusicPlayerBottomSheetFragment;

.field d:Z

.field private l:Landroid/widget/ImageView;

.field private m:Landroid/support/design/widget/BottomSheetBehavior;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Landroid/support/design/widget/BottomSheetBehavior<",
            "Landroid/widget/LinearLayout;",
            ">;"
        }
    .end annotation
.end field

.field mDrawerLayout:Landroid/support/v4/widget/DrawerLayout;
    .annotation build Lbutterknife/BindView;
        value = 0x7f0900a1
    .end annotation
.end field

nop

move

return

const

操作指令

数组指令

异常

跳转

goto

switch

if

字段操作

方法调用

运算

内部类 xx$xx

ART

Andorid 5才开始使用的虚拟机,兼容Dalvik的特性。AOT(ahead of time)特性:安装APK时候将dex转换成ART使用的机器码。ART将dex转成oat文件。天生支持多dex,可以省略合包过程。加快APP冷启动速度。

JVM::运行的是.java编译后的.class文件

Dalvik:

  • 打包过程中.java通过javac编译后的.class文件。
  • 但是Dalvik只执行dex文件,dx将.class文件转换.dex
  • 启动时候:.dex转换成可快速运行的机器码,multi dex还需要合包,所以启动慢

分区

image-20221127211413685

data分区

image-20221127211501971

system分区

image-20221127212141907