dalvik vm internals
play

Dalvik VM Internals Dan Bornstein Google Intro Memory CPU - PowerPoint PPT Presentation

Dalvik VM Internals Dan Bornstein Google Intro Memory CPU Advice Conclusion Dalvk, Iceland The Big Picture The Big Picture What is the Dalvik VM? It is a virtual machine to run on a slow CPU with relatively


  1. Dalvik VM Internals Dan Bornstein Google

  2. • Intro • Memory • CPU • Advice • Conclusion

  3. Dalvík, Iceland

  4. The Big Picture

  5. The Big Picture

  6. What is the Dalvik VM? It is a virtual machine to… • run on a slow CPU • with relatively little RAM • on an OS without swap space • while powered by a battery

  7. What is the Dalvik VM? It is a virtual machine to… • run on a slow CPU • with relatively little RAM • on an OS without swap space • while powered by a battery

  8. Memory Efficiency • Intro • Memory • CPU • Advice • Conclusion

  9. Problem: Memory Efficiency • total system RAM: 64 MB • available RAM after low-level startup: 40 MB • available RAM after high-level services have started: 20 MB • multiple independent mutually-suspicious processes • separate address spaces, separate memory • large system library: 10 MB jar)

  10. Problem: Memory Efficiency • total system RAM: 64 MB • available RAM after low-level startup: 40 MB • available RAM after high-level services have started: 20 MB • multiple independent mutually-suspicious processes • separate address spaces, separate memory • large system library: 10 MB

  11. Dex File Anatomy header "Hello World" "Lcom/google/Blort;" int "println" string_ids String[] … com.google.Blort … type_ids void fn(int) double fn(Object, int) proto_ids String.offset String fn() Integer.MAX_VALUE … … field_ids PrintStream.println(…) Collection.size() method_ids … class_defs data

  12. Dex File Anatomy header "Hello World" "Lcom/google/Blort;" int "println" string_ids String[] … com.google.Blort … type_ids void fn(int) double fn(Object, int) proto_ids String.offset String fn() Integer.MAX_VALUE … … field_ids PrintStream.println(…) Collection.size() method_ids … class_defs data

  13. Dex File Anatomy header "Hello World" "Lcom/google/Blort;" int "println" string_ids String[] … com.google.Blort … type_ids void fn(int) double fn(Object, int) proto_ids String.offset String fn() Integer.MAX_VALUE … … field_ids PrintStream.println(…) Collection.size() method_ids … class_defs data

  14. Dex File Anatomy header "Hello World" "Lcom/google/Blort;" int "println" string_ids String[] … com.google.Blort … type_ids void fn(int) double fn(Object, int) proto_ids String.offset String fn() Integer.MAX_VALUE … … field_ids PrintStream.println(…) Collection.size() method_ids … class_defs data

  15. Dex File Anatomy .jar file .class file heterogeneous .dex file constant pool string_ids constant pool other data type_ids constant pool .class file proto_ids constant pool heterogeneous field_ids constant pool constant pool method_ids other data constant pool .class file heterogeneous other data constant pool other data

  16. Shared Constant Pool public interface Zapper { public String zap(String s, Object o); } public class Blort implements Zapper { public String zap(String s, Object o) { ...; } } public class ZapUser { public void useZap(Zapper z) { z.zap(...); } }

  17. Shared Constant Pool Original .class files class Zapper class Blort "Zapper" "SourceFile" "Blort" "Zapper" "zap" "java/lang/Object" method ref "zap" "LineNumberTable" "Zapper.java" "Blort.java" "(Ljava/lang/String;Ljava/lang/ "(Ljava/lang/String;Ljava/lang/ Object;)Ljava/lang/String;" "Code" Object;)Ljava/lang/String;" method ref "java/lang/Object" "SourceFile" "<init>" "()V" class ZapUser "ZapUser" "Zapper" "ZapUser.java" method ref "zap" "LineNumberTable" "(Ljava/lang/String;Ljava/lang/ Object;)Ljava/lang/String;" "Code" method ref "java/lang/Object" "SourceFile" "<init>" "()V" "useZap" "(LZapper;)V"

  18. Shared Constant Pool Original .class files class Zapper class Blort "Zapper" "SourceFile" "Blort" "Zapper" "zap" "java/lang/Object" method ref "zap" "LineNumberTable" "Zapper.java" "Blort.java" "(Ljava/lang/String;Ljava/lang/ "(Ljava/lang/String;Ljava/lang/ Object;)Ljava/lang/String;" "Code" Object;)Ljava/lang/String;" method ref "java/lang/Object" "SourceFile" "<init>" "()V" class ZapUser "ZapUser" "Zapper" "ZapUser.java" method ref "zap" "LineNumberTable" "(Ljava/lang/String;Ljava/lang/ Object;)Ljava/lang/String;" "Code" method ref "java/lang/Object" "SourceFile" "<init>" "()V" "useZap" "(LZapper;)V"

  19. Shared Constant Pool Original .class files class Zapper class Blort "Zapper" "SourceFile" "Blort" "Zapper" "zap" "java/lang/Object" method ref "zap" "LineNumberTable" "Zapper.java" "Blort.java" "(Ljava/lang/String;Ljava/lang/ "(Ljava/lang/String;Ljava/lang/ Object;)Ljava/lang/String;" "Code" Object;)Ljava/lang/String;" method ref "java/lang/Object" "SourceFile" "<init>" "()V" class ZapUser "ZapUser" "Zapper" "ZapUser.java" method ref "zap" "LineNumberTable" "(Ljava/lang/String;Ljava/lang/ Object;)Ljava/lang/String;" "Code" method ref "java/lang/Object" "SourceFile" "<init>" "()V" "useZap" "(LZapper;)V"

  20. Shared Constant Pool .dex file method id "useZap" "Blort.java" "Zapper.java" proto id "LZapUser;" "ZapUser.java" method id "LZapper;" "<init>" proto id "V" method id method id method id "LBlort;" method id "zap" method id proto id "Ljava/lang/String;" "Ljava/lang/Object;"

  21. Shared Constant Pool Memory is saved via… • minimal repetition • per-type pools (implicit typing) • implicit labeling

  22. Size Comparison common system libraries ( U ) 21445320 — 100% ( U ) uncompressed jar file ( J ) 10662048 — 50% ( J ) compressed jar file ( D ) 10311972 — 48% ( D ) uncompressed dex file web browser app ( U ) 470312 — 100% ( J ) 232065 — 49% ( D ) 209248 — 44% alarm clock app ( U ) 119200 — 100% ( J ) 61658 — 52% ( D ) 53020 — 44%

  23. 4 Kinds Of Memory • clean vs. dirty • clean: mmap() ed and unwritten • dirty: malloc() ed • shared vs. private • shared: used by many processes • private: used by only one process

  24. 4 Kinds Of Memory • clean (shared or private) • common dex files (libraries) • application-specific dex files • shared dirty • ??? • private dirty • application “live” dex structures • application heap

  25. Enter The Zygote • nascent VM process • starts at boot time • preloads and preinitializes classes • fork() s on command

  26. Enter The Zygote Zygote Maps Zygote heap Maps dex file Browser (shared dirty, (mmap()ed) copy-on-write; Browser dex file Home rarely written) (mmap()ed) Home dex file Maps live code and heap (mmap()ed) Browser live core library dex (private dirty) code and heap files Home live code (private dirty) shared from and heap (mmap()ed) Zygote shared from (private dirty) Zygote shared from Zygote "live" core libraries (shared dirty; read-only)

  27. 4 Kinds Of Memory • clean (shared or private) • common dex files (libraries) • application-specific dex files • shared dirty • library “live” dex structures • shared copy-on-write heap (mostly not written) • private dirty • application “live” dex structures • application heap

  28. GC And Sharing embedded separated mark bits mark bits mark bits object data object data parallel mark bits object data mark bits object data object data mark bits object data object data . . . . . .

  29. GC And Sharing • separate process, separate heaps, separate GCs • GCs must be independent • GC should respect the sharing!

  30. GC And Sharing Mark bits kept separate from other heap memory. object data parallel • avoids un-sharing pages mark bits object data • better small cache behavior • doesn ’ t waste memory object data object data . . .

  31. CPU Efficiency • Intro • Memory • CPU • Advice • Conclusion

  32. Problem: CPU Efficiency • CPU speed: 250-500MHz • bus speed: 100MHz • data cache: 16-32K • available RAM for apps: 20 MB

  33. No JIT • usually doesn ’ t matter • lots of native code • system provides libs for graphics, media • JNI available • hardware support common (graphics, audio)

  34. Install-Time Work • verification • dex structures aren ’ t “lying” • valid indices • valid offsets • code can ’ t misbehave

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend