1 / 22

移动系统中的 Java 虚拟机

移动系统中的 Java 虚拟机. 徐伟刚. Java 简介. Java 是一种面向对象的编程语言 一次编译,到处运行 全世界有超过 1000 万 Java 开发者. Java 发展简介 -Sun. 1995 年 Sun 公司发布 Java 语言 1996 年发布 JDK1.0 1999 年发布 J2SE 、 J2EE 、 J2ME 标准 2006 年 Sun 以 OpenJDK 开源 Java 2009 年 Oracle 收购 Sun. Java 发展简介 - 移动 Java. J2ME: Nokia 、 Jblend 、 Mirand Android. 矛盾.

jera
Télécharger la présentation

移动系统中的 Java 虚拟机

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 移动系统中的Java虚拟机 徐伟刚

  2. Java简介 • Java是一种面向对象的编程语言 • 一次编译,到处运行 • 全世界有超过1000万Java开发者

  3. Java发展简介-Sun • 1995年Sun公司发布Java语言 1996年发布JDK1.0 1999年发布J2SE、J2EE、J2ME标准 2006年Sun以OpenJDK开源Java 2009年Oracle收购Sun

  4. Java发展简介-移动Java • J2ME: Nokia、Jblend、Mirand Android

  5. 矛盾 • Java虚拟机的性能追求 • 移动系统的限制 • CPU – 芯片厂商技术能力 • 内存 – 价格 • 功耗 – 无持久电源

  6. Java虚拟机架构 stack compiler interpreter heap binary loader binary convertor JIT thread binary optimizer Debugger & profiler JNI format engine mechanism Java虚拟机架构

  7. Java虚拟机-指令体系 • Java使用与平台指令无关的字节码 • 虚拟机解释执行字节码

  8. Java虚拟机-指令模式

  9. Java虚拟机-指令体系 以java代码为例: a = b + c 栈式指令: ILOAD c ILOAD b IADD ISTORE a 寄存器式指令: l_add a, b, c

  10. Java虚拟机-解释器指令分发 for(;;) { ins = fetch_next_instruction(); switch(ins) { case OP_001: handle_OP_001; break; case OP_002: handle_OP_002; break; …… } } switch-case version

  11. Java虚拟机-解释器指令分发 handle_addresses[]; …… pre-calculate_handle_addresses(); …… for(;;) { ins = fetch_next_instruction(); gotohandle_addresses[ins]; } goto-address version

  12. Java虚拟机-解释器指令分发 #define GOTO_OPCODE(_reg) add pc, rIBASE, _reg, lsl #6 …… .balign 64 .L_OP_001: FETCH_ADVANCE_INST GET_INST_OPCODE(ip) GOTO_OPCODE(ip) .balign 64 .L_OP_002: GOTO_OPCODE(ip) …… align-goto version(Dalvik ARM)

  13. Java虚拟机-JIT JIT compiler interpreter Just in time compiler – 及时将热代码翻译成目标机器指令执行 instruction decode fetch instruction compile queue flow graph N hot spot compiled Y SSA Y N code generator interpret instruction execute code cache code cache

  14. Java虚拟机-JIT优化点 • 消除指令分发 • 使用物理寄存器 • 基于目标指令优化 • 基于动态信息优化

  15. Java虚拟机-JIT优化点示例 a = b + c; e= a + d; fectch_op load R1 <- b load R2 <- c R3 = R1 + R2 store a <- R3 goto_next_op fectch_op load R1 <- a load R2 <- d R3 = R1 + R2 store e <- R3 goto_next_op load R1 <- b load R2 <- c R3 = R1+ R2 load R4 <- d R5= R3 + R4 store e <- R5

  16. Java虚拟机-对象访问 • Java对象 vs C指针 • gc影响 • resolve

  17. Java虚拟机-内存 • gc指标-吞吐量、碎片率 • 没有最好,只有最合适

  18. Java虚拟机-内存 移动vs非移动

  19. Java虚拟机-安装预优化 • 提前resolve • 函数inline/JIT inline

  20. Java虚拟机-功耗 • 受目标芯片架构限制 • 例如ARM ? Thumb?

  21. Java虚拟机-发展 • 编译器优化 • 动态特性 • 字节码native化 • 定制化内存管理

  22. 谢谢

More Related