Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android VM

Android VM

Delvik / ART

wagyu298

March 03, 2016
Tweet

More Decks by wagyu298

Other Decks in Programming

Transcript

  1. Android VM @wagyu298

  2. Android VM ≠ Java VM

  3. Android VM Delvik: Android 4.4 ART: Android 5.0 or later

  4. Hardware • Nexus 5X (Android) • Qualcomm® Snapdragon™ 808 ϓϩηοα

    1.8 GHz ϔΩαίΞ 64 Ϗοτ • 2GB LPDDR3 • ࠷৽͸ARM8ɺݹ͍σόΠε͸ARMҎ֎ʹ͸MIPS΍x86 CPUͷ΋ͷ΋͋Δ • ϚϧνCPUରԠʹVM͸༗ར • iPhone 6s • A9 • 2GB LPDDR4 • ಉ͘͡ARM8ɺݹ͍iPhone΋͢΂ͯARMޓ׵ • ୯ҰΞʔΩςΫνϟͳͷͰɺXcode͔Β࣮ߦՄೳόΠφϦΛग़ྗ͢Δ • 64bitରԠͷͨΊɺ32bitόΠφϦΛ64bitόΠφϦΛ࡞੒͢ΔΑ͏ʹͳͬͨ
  5. Android VM • Delvik: Android 4.4 • ART: Android 5.0

    or later • https://source.android.com/devices/tech/dalvik/ index.html
  6. Android VM https://ja.wikipedia.org/wiki/Android_Runtime

  7. Delvik • ϨδελϕʔεͷόʔνϟϧϚγϯʢJava VM͸ελοΫϕʔεʣ • ARM8͸31ݸͷ64bit൚༻Ϩδελͱ32ݸͷ128bitුಈখ਺఺Ϩδε λ͕࢖༻ՄೳͰARM7ͱൺ΂Delvikʹ༗ར • ௿ϝϞϦ؀ڥʹ࠷దԽ •

    ಈ࡞͢ΔόΠτίʔυ͸DexϑΥʔϚοτͰJavaόΠτίʔυͰ͸ͳ͍ ͨΊɺDelvik VM͸Java VMͰ͸ͳ͍ • Javaޓ׵ੑςετΛ௨ա͍ͯ͠ͳ͍ͷͰɺJava™Λ࢖༻Ͱ͖ͳ͍ • dxίϚϯυͰ.classϑΝΠϧΛ.dexϑΝΠϧʹม׵͢Δ • APKʹ͸ෳ਺ʢ௨ৗ1ͭʣͷ.dexϑΝΠϧؚ͕·ΕΔ • Android 2.1͔Β͸JIT΋αϙʔτ
  8. Dex Specs • https://source.android.com/devices/tech/dalvik/dex- format.html

  9. ART • AOT (Ahead-Of-Time) ίϯύΠϧ • ࣮ߦલʢΠϯετʔϧ࣌ʣʹ.dexϑΝΠϧΛELF dynamic objectʹม׵ •

    ࣮ߦ଎౓͕޲্͍ͯ͠Δ͕ɺAOTͷੑ্࣭ΞϓϦͷΠϯε τʔϧʹ͕͔͔࣌ؒΔΑ͏ʹͳΓ࣮ߦϑΝΠϧαΠζ΋େ ͖͘ͳ͍ͬͯΔ • dex2oatʢdexΛELFʹม׵͢ΔίϚϯυʣ͸LLVMͰ࣮૷ • JITίϯύΠϥ΋෇ଐ͍ͯ͠Δ͕ɺDelvikͷ࣮૷ͱҧ͍͋·Γ ࠷దԽ͞Ε͍ͯͳ͍
  10. Zygote • AndroidΞϓϦͷىಈϓϩηε • Androidࣗମ͸LinuxϚγϯͰ͋ΓɺσόΠεىಈ࣌͸/ init͔Β࢝·ΔҰ࿈ͷىಈϓϩηε͕ී௨ʹ࣮ߦ͞Εɺ/ init.rcεΫϦϓτ͔Βىಈ͞ΕΔίϚϯυapp_process ͷ͜ͱ • https://android.googlesource.com/platform/system/

    core/+/master/rootdir/init.zygote64_32.rc
  11. Zygote • zygoteϓϩηε͸ΞϓϦىಈʹඞཁͳ͢΂ͯͷϥΠϒ ϥϦ͕dynamic link͞Ε͓ͯΓɺࢠϓϩηεΛforkͯ͠ ʢexecͤͣʹʣΞϓϦΛىಈ͢Δ • app_process͸zygoteϞʔυͰىಈ͞ΕΔͱ com.android.internal.os.ZygoteInitΛ࣮ߦ͢Δ •

    https://android.googlesource.com/platform/ frameworks/base/+/master/cmds/app_process/ app_main.cpp
  12. Zygote • ZygoteInit͸͋ʔͩ͜ʔͩͨ͋͠ͱ • https://android.googlesource.com/platform/frameworks/ base/+/master/core/java/com/android/internal/os/ ZygoteInit.java • app_processͷAppRuntimeΫϥεΛܦ༝͠AndroidRuntime͔ ΒActivityThreadΫϥεͷmainؔ਺Λݺͼग़͢ɻ

    • https://android.googlesource.com/platform/frameworks/ base/+/master/core/jni/AndroidRuntime.cpp • https://android.googlesource.com/platform/frameworks/ base/+/master/core/java/android/app/ActivityThread.java
  13. References • http://d.hatena.ne.jp/embedded/20131104/p1 • http://blog.kmckk.com/archives/3551546.html • http://blog.kmckk.com/archives/4164432.html • http://elinux.org/Android_Zygote_Startup •

    http://crimsonwoods.hatenablog.com/entry/ 2014/11/10/013025 • http://blog.hermit4.info/2011/01/zygote.html • http://dsas.blog.klab.org/archives/52003951.html