SlideShare a Scribd company logo
1 of 39
Download to read offline
Android is
   NOT just
'Java on Linux'
     2011.5.22
     2011.10.26 updated

  Tetsuyuki Kobayashi

                          1
Let's talk about inside of Android.




          http://www.kmckk.co.jp/eng/kzma9/           2
          http://www.kmckk.co.jp/eng/jet_index.html
Who am I?
   20+ years involved in embedded systems
       10 years in real time OS, such as iTRON
       10 years in embedded Java Virtual Machine
       Now GCC, Linux, QEMU, Android, …
   Blogs
       http://d.hatena.ne.jp/embedded/ (Personal)
       http://blog.kmckk.com/ (Corporate)
       http://kobablog.wordpress.com/(English)
   Twitter
       @tetsu_koba
                                                     3
Android is NOT just
               'Java on Linux'
   Android uses Linux kernel. Only kernel.
       User land is totally different from usual Linux
        system.
   Android applications are written in Java
    language.
       Class libraries are similar to Java SE but not
        equal.
   Dalvik VM eats only dex code
       need to translate from Java byte code in
        advance                                           4
Let's explore inside of Android

   Assuming you know Linux and Java
    very well :)




                                       5
Today's topic

 Android system architecture
 Init – runtime – Zygoto


 Dalvik VM


 Android specific kernel

  drivers
 How to build Android

                                6
Today's topic

 Android system architecture
 Init – runtime – Zygoto


 Dalvik VM


 Android specific kernel drivers


 How to build Android




                                    7
System architecture




                      8
Java is the first class citizen in
                 Android
   Dalvik VM is the center of Android
    runtime.
   Almost all daemon services are written in
    Java.
   Application life cycle is described by
    Java API


                                           9
Java is the first class citizen in
                Android
   NDK
       native library called from Java via JNI
       This is just a library. Application life
        cycle is the same as Java.
   Native activity
       Only C/C++ to make Apps. (just hidden
        JNI part into system.)
       not short-cut for C/C++
                                                   10
Typical Directory Tree of Android
                                                  ro: mounted as read only
       / /(root)
           (root)    initrd (ro)
                                                  rw: mounted as read and write


                                    yaffs2 (ro)
                      /system
                       /system                                 bin

                                                               etc

                                                               lib
                       /data        yaffs2 (rw)
                        /data
                                                               usr


                      /cache        yaffs2 (rw)
                       /cache



                    /mnt/sdcard     removable storage (rw)
                     /mnt/sdcard


 cf. Usual Linux system assumes all file system are read/writable.           11
Today's topic

 Android system architecture
 Init – runtime – Zygoto


 Dalvik VM


 Android specific kernel

  drivers
 How to build Android

                                12
Boot sequence




                                                                      13
quoted from http://hmtsay.blogspot.com/2010/10/android-startup.html
init
   located on /init
       need kernel boot parameter to add
        “init=/init”
   Static linked.
     cf. typical linux init is dynamic

      linked.
     Doesn't affect even dynamic link

      system collapsed.
   http://blog.kmckk.com/archives/3137191.html   14
Bionic

   The standard libraries
       libc, libm, pthread, dynamic linker
       linker has implicit crash dump function
       http://kobablog.wordpress.com/2011/05/12/debuggerd-of-android/
   Came from *BSD, not glibc
   Currently, doesn't support C++ exception
    and RTTI.
       latest NDK supports these by static linking.
                                                                     15
Prelinking

   Locate dynamic link libraries ahead of
    time.
   'apriori' command. Different from 'prelink'
    command from Red Hat.
   Optimized for small embedded system
       Allocate fixed address to libraries .
       Assume 3GB memory space is large enough
        to put all libraries together.
       Assume not adding/removing libraries.  16
Prelink map
build/core/prelink-linux-arm.map
 #   0xC0000000   -   0xFFFFFFFF   Kernel
 #   0xB0100000   -   0xBFFFFFFF   Thread 0 Stack
 #   0xB0000000   -   0xB00FFFFF   Linker
 #   0xA0000000   -   0xBFFFFFFF   Prelinked System Libraries
 #   0x90000000   -   0x9FFFFFFF   Prelinked App Libraries
 #   0x80000000   -   0x8FFFFFFF   Non-prelinked Libraries
 #   0x40000000   -   0x7FFFFFFF   mmap'd stuff
 #   0x10000000   -   0x3FFFFFFF   Thread Stacks
 #   0x00000000   -   0x0FFFFFFF   .text / .data / heap



 # core system libraries
 libdl.so                      0xAFF00000   #   [<64K]
 libc.so                       0xAFD00000   #   [~2M]
 libstdc++.so                  0xAFC00000   #   [<64K]
 libm.so                       0xAFB00000   #   [~1M]
 liblog.so                     0xAFA00000   #   [<64K]
 libcutils.so                  0xAF900000   #   [~1M]
 libthread_db.so               0xAF800000   #   [<64K]
 libz.so                       0xAF700000   #   [~1M]
 libevent.so                   0xAF600000   #   [???]
 libssl.so                     0xAF400000   #   [~2M]
 libcrypto.so                  0xAF000000   #   [~4M]
 libsysutils.so                0xAEF00000   #   [~1M]
    ...                                                         17
Zygote




quoted from http://worms.zoology.wisc.edu/dd2/echino/cleavage/intro.html

                                                                           18
Zygote
                                            fork



Zygote process                                       Child process

                classes        classes                                  classes        classes
              classes        classes
                          dynamic link                                classes        classes
                                                                                  dynamic link
Dalvik VM   classes        libraries                 Dalvik VM      classes         libraries




                                           classes        classes
                                         classes        classes
                                                     dynamic link
                   Dalvik VM           classes         libraries


Physical memory space                                 (Actually these are mapped by pages.)
                                                                                                19
Zygote
   Zygote process preloads typical (approx. 1800)
    classes and dynamic link libraries so that
    childlen start quickly.
   Copy-on-write
       Only when new process writes page, new page is
        allocated.
       All pages not be written are shared among all
        zygote children.
   Exec system call is not used in zygote.
       Exec wipes the page mapping table of the process.
       It means exec discards zygote cache.             20
UID, GID of Applications
   UID(user id) and GID(group id) is used for
    managing multi-user in usual Linux
    system.
   Android use this mechanism to isolate
    applications.
       Each application has unique UID.
       Can not read/write other application's files.
   Zygote is running as UID=0 (root). After
    forking child process, its UID is changed
    by setuid system call.                              21
Today's topic

 Android system architecture
 Init – runtime – Zygoto


 Dalvik VM


 Android specific kernel

  drivers
 How to build Android

                                22
Dalvik VM
   executes dex code, which is translated
    from Java byte code
   16bit, register based
        cf. Java bytecode is 8bit, stack based
   has JIT from Android 2.2 (Froyo)
        http://blog.kmckk.com/archives/2691473.html
   has concurrent GC from Android 2.3
    (Gingerbread)
   http://source.android.com/tech/dalvik/
                                                       23
Java class libraries
   Different from Java ME, which is used in
    traditional Japanese phone.
   Similar to Java SE. But not equal.
       Different window/graphics. No AWT, No
        Swing.
       No RMI.
   Take care to use user defined class loader
       dynamic generated classes doesn't work
        because Dalvik VM doesn't eat Java class
        files but Dex files.                       24
Caveats of NDK programming
   Dynamic libraries built by NDK are linked
    with application process.
       forked from Zygote but UID != 0 (root).
       consider about permissions.
   Don't use fork & exec system calls.
     Back ground process should be made as
      android .app.Service.
   Don't use GCC's TLS extension (__thread).
       Simple Android dynamic linker does not support it.
       java.lang.ThreadLocal is available in Java.          25
3 commands to invoke Dalvik VM

   /system/bin/app_process
       This is the 'Zygote' process.
   /system/bin/dalvikvm
       Similar to usual 'java' command.
       Try 'dalvikvm -h' to show command line help.
   /system/bin/dvz
       Send request to Zygote process.
   See my blog (Sorry in Japanese)
       http://blog.kmckk.com/archives/3551546.html
                                                       26
Today's topic

 Android system architecture
 Init – runtime – Zygoto


 Dalvik VM


 Android specific kernel

  drivers
 How to build Android

                                27
Linux kernel
   Many common Linux device drivers are
    available.
   Android specific kernel drivers
        binder
        ashmem
        wake lock
        logger
         …
   http://elinux.org/Android_Kernel_Features

   These source code is not yet merged to
    kernel main line repository.                28
Binder
   /dev/binder
   Base of Inter Process Method Invocation
   Not for general purpose. Tuned for specific
    transaction.
   Multi-thread aware
        Have internal data per thread
        (CF. Socket have internal data per fd.)
   Doesn't use ”write” and ”read” system calls.
    Write and read at once by ”ioctl”.
   http://blog.kmckk.com/archives/3676340.html    29
Ashmem
   Android / Anonymous SHared MEMory
    subsystem
       $(TOP)/system/core/cutils/ashmem.h
                 int ashmem_create_region(const char *name, size_t size)
                    → returns fd
                 int ashmem_set_prot_region(int fd, int prot)
                 int ashmem_pin_region(int fd, size_t offset, size_t len)
                 int ashmem_unpin_region(int fd, size_t offset, size_t len)
   Kernel reclaims not ‘pin’ ed memory
   Similar to weak reference of Java. Useful to
    implement cache.
   android.os.MemoryFile from Java program
                                                                               30
Wake lock

   Lock to prevent entering sleep mode.
   My memos
       http://blog.kmckk.com/archives/3298375.html
       http://blog.kmckk.com/archives/3304836.html
   eLinux wiki
       http://elinux.org/Android_Power_Management




                                                      31
Alarm

   kernel implementation to support
    Android's AlarmManager.
   Wake up even when it was in sleep mode.




                                          32
Low memory killer

   At the shortage of memory, the kernel
    select a process seems low priority and
    kill it. (!!)
   It's OK. because specification in the
    Android application life cycle, application
    should be preserve its own status.
   http://blog.kmckk.com/archives/2795577.html




                                                  33
Logger

   Android has unique system-wide log
    system
   http://blog.kmckk.com/archives/2936958.html

    http://elinux.org/Android_Logging_System




                                                  34
Overview of Android Logging System
                                                                                    Target
                                  Java program
                                   Java program                    System.out
                                                                   /System.err

                                                       com.android.internal.os
       Native program             android.util.Log      com.android.internal.os               Host
        Native program             android.util.Log      AndroidPrintStream
                                                          AndroidPrintStream

                                                                                                DDMS
                                                                                  stdout
                                                              logcat
                                                               logcat
       stdout          liblog
       /stderr           liblog                                                               adbserver
                                                                                  adbd
                                                                                   adbd        adbserver
User

Kernel                                                                                         adb logcat

                                  main     64KB       radio
                                            logger
                                             logger           64KB
         /dev/log/main                                                      /dev/log/main
         /dev/log/radio            event                                    /dev/log/radio
                                                      system
         /dev/log/event                     256KB                           /dev/log/event
         /dev/log/system                                      64KB          /dev/log/system            35
Today's topic

 Android system architecture
 Init – runtime – Zygoto


 Dalvik VM


 Android specific kernel

  drivers
 How to build Android

                                36
How to build Android
   All source code is available for download
       except Google specific services (Google
        map, Android market, … )
   Easy to download source and build them
   See AOSP web site
       http://source.android.com/
   Or, my blog
       http://blog.kmckk.com/archives/3722957.html
                                                  37
Conclusion

   Android system architecture is totally
    different from normal Linux systems.
   Android uses Linux kernel only,
    further more, adding android specific
    kernel drivers.
   Designed for Java applications.
   Tuned for small system.
                                             38
Q&A




Thank you for listening!
Any comments to blogs are welcome.

                                     39

More Related Content

What's hot

Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesChris Simmonds
 
Android's Multimedia Framework
Android's Multimedia FrameworkAndroid's Multimedia Framework
Android's Multimedia FrameworkOpersys inc.
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux DevelopersOpersys inc.
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Opersys inc.
 
Android OTA updates
Android OTA updatesAndroid OTA updates
Android OTA updatesGary Bisson
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessNanik Tolaram
 
Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debuggingUtkarsh Mankad
 
The Android graphics path, in depth
The Android graphics path, in depthThe Android graphics path, in depth
The Android graphics path, in depthChris Simmonds
 
Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Opersys inc.
 
Android media framework overview
Android media framework overviewAndroid media framework overview
Android media framework overviewJerrin George
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALOpersys inc.
 
Android Storage - Vold
Android Storage - VoldAndroid Storage - Vold
Android Storage - VoldWilliam Lee
 

What's hot (20)

Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot images
 
Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)
 
Android's Multimedia Framework
Android's Multimedia FrameworkAndroid's Multimedia Framework
Android's Multimedia Framework
 
Introduction to Android Window System
Introduction to Android Window SystemIntroduction to Android Window System
Introduction to Android Window System
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Low Level View of Android System Architecture
Low Level View of Android System ArchitectureLow Level View of Android System Architecture
Low Level View of Android System Architecture
 
Android OTA updates
Android OTA updatesAndroid OTA updates
Android OTA updates
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting Process
 
Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debugging
 
The Android graphics path, in depth
The Android graphics path, in depthThe Android graphics path, in depth
The Android graphics path, in depth
 
Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013
 
Embedded Android : System Development - Part I
Embedded Android : System Development - Part IEmbedded Android : System Development - Part I
Embedded Android : System Development - Part I
 
Binder: Android IPC
Binder: Android IPCBinder: Android IPC
Binder: Android IPC
 
Android media framework overview
Android media framework overviewAndroid media framework overview
Android media framework overview
 
Android Binder: Deep Dive
Android Binder: Deep DiveAndroid Binder: Deep Dive
Android Binder: Deep Dive
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HAL
 
Applied Computer Science Concepts in Android
Applied Computer Science Concepts in AndroidApplied Computer Science Concepts in Android
Applied Computer Science Concepts in Android
 
Android Storage - Vold
Android Storage - VoldAndroid Storage - Vold
Android Storage - Vold
 

Similar to Android is NOT just 'Java on Linux'

Introduction to the Android NDK
Introduction to the Android NDKIntroduction to the Android NDK
Introduction to the Android NDKBeMyApp
 
Multithreading in Android
Multithreading in AndroidMultithreading in Android
Multithreading in Androidcoolmirza143
 
Java Hates Linux. Deal With It.
Java Hates Linux.  Deal With It.Java Hates Linux.  Deal With It.
Java Hates Linux. Deal With It.Greg Banks
 
Curso de Desenvolvimento Mobile - Android - Stack
Curso de Desenvolvimento Mobile - Android - StackCurso de Desenvolvimento Mobile - Android - Stack
Curso de Desenvolvimento Mobile - Android - StackJackson F. de A. Mafra
 
Running native code on Android #OSDCfr 2012
Running native code on Android #OSDCfr 2012Running native code on Android #OSDCfr 2012
Running native code on Android #OSDCfr 2012Cédric Deltheil
 
Let's Containerize New York with Docker!
Let's Containerize New York with Docker!Let's Containerize New York with Docker!
Let's Containerize New York with Docker!Jérôme Petazzoni
 
Techtalks: taking docker to production
Techtalks: taking docker to productionTechtalks: taking docker to production
Techtalks: taking docker to productionmuayyad alsadi
 
Android OS Porting: Introduction
Android OS Porting: IntroductionAndroid OS Porting: Introduction
Android OS Porting: IntroductionJollen Chen
 
One RubyStack to Rule them All
One RubyStack to Rule them AllOne RubyStack to Rule them All
One RubyStack to Rule them Allelliando dias
 
NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)Ron Munitz
 
Dalvik Vm &amp; Jit
Dalvik Vm &amp; JitDalvik Vm &amp; Jit
Dalvik Vm &amp; JitAnkit Somani
 
Dalvik Vm &amp; Jit
Dalvik Vm &amp; JitDalvik Vm &amp; Jit
Dalvik Vm &amp; JitAnkit Somani
 
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)JiandSon
 

Similar to Android is NOT just 'Java on Linux' (20)

Understanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual MachineUnderstanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual Machine
 
olibc: Another C Library optimized for Embedded Linux
olibc: Another C Library optimized for Embedded Linuxolibc: Another C Library optimized for Embedded Linux
olibc: Another C Library optimized for Embedded Linux
 
Introduction to the Android NDK
Introduction to the Android NDKIntroduction to the Android NDK
Introduction to the Android NDK
 
Multithreading in Android
Multithreading in AndroidMultithreading in Android
Multithreading in Android
 
Java Hates Linux. Deal With It.
Java Hates Linux.  Deal With It.Java Hates Linux.  Deal With It.
Java Hates Linux. Deal With It.
 
App container rkt
App container rktApp container rkt
App container rkt
 
Logging system of Android
Logging system of AndroidLogging system of Android
Logging system of Android
 
Curso de Desenvolvimento Mobile - Android - Stack
Curso de Desenvolvimento Mobile - Android - StackCurso de Desenvolvimento Mobile - Android - Stack
Curso de Desenvolvimento Mobile - Android - Stack
 
Running native code on Android #OSDCfr 2012
Running native code on Android #OSDCfr 2012Running native code on Android #OSDCfr 2012
Running native code on Android #OSDCfr 2012
 
Logging system of Android
Logging system of AndroidLogging system of Android
Logging system of Android
 
Let's Containerize New York with Docker!
Let's Containerize New York with Docker!Let's Containerize New York with Docker!
Let's Containerize New York with Docker!
 
Getting Native with NDK
Getting Native with NDKGetting Native with NDK
Getting Native with NDK
 
JOSA TechTalk: Taking Docker to Production
JOSA TechTalk: Taking Docker to ProductionJOSA TechTalk: Taking Docker to Production
JOSA TechTalk: Taking Docker to Production
 
Techtalks: taking docker to production
Techtalks: taking docker to productionTechtalks: taking docker to production
Techtalks: taking docker to production
 
Android OS Porting: Introduction
Android OS Porting: IntroductionAndroid OS Porting: Introduction
Android OS Porting: Introduction
 
One RubyStack to Rule them All
One RubyStack to Rule them AllOne RubyStack to Rule them All
One RubyStack to Rule them All
 
NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)
 
Dalvik Vm &amp; Jit
Dalvik Vm &amp; JitDalvik Vm &amp; Jit
Dalvik Vm &amp; Jit
 
Dalvik Vm &amp; Jit
Dalvik Vm &amp; JitDalvik Vm &amp; Jit
Dalvik Vm &amp; Jit
 
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
 

More from Tetsuyuki Kobayashi

Try new transport protocol SRT (ver. 2)
Try new transport protocol SRT  (ver. 2)Try new transport protocol SRT  (ver. 2)
Try new transport protocol SRT (ver. 2)Tetsuyuki Kobayashi
 
Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機
Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機
Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機Tetsuyuki Kobayashi
 
WebOS Open Source Edition を試してみた
WebOS Open Source Edition を試してみたWebOS Open Source Edition を試してみた
WebOS Open Source Edition を試してみたTetsuyuki Kobayashi
 
Linuxのユーザーランドをinitから全てまるごとgolangで書く
Linuxのユーザーランドをinitから全てまるごとgolangで書くLinuxのユーザーランドをinitから全てまるごとgolangで書く
Linuxのユーザーランドをinitから全てまるごとgolangで書くTetsuyuki Kobayashi
 
組み込みLinuxでのGolangのススメ(Go con版)
組み込みLinuxでのGolangのススメ(Go con版)組み込みLinuxでのGolangのススメ(Go con版)
組み込みLinuxでのGolangのススメ(Go con版)Tetsuyuki Kobayashi
 
組み込みLinuxでのGolangのススメ
組み込みLinuxでのGolangのススメ組み込みLinuxでのGolangのススメ
組み込みLinuxでのGolangのススメTetsuyuki Kobayashi
 
Tricky implementation of Go ARM soft float
Tricky implementation of Go ARM soft floatTricky implementation of Go ARM soft float
Tricky implementation of Go ARM soft floatTetsuyuki Kobayashi
 
Simple and efficient way to get the last log using MMAP
Simple and efficient way to get the last log using MMAPSimple and efficient way to get the last log using MMAP
Simple and efficient way to get the last log using MMAPTetsuyuki Kobayashi
 
Basic of virtual memory of Linux
Basic of virtual memory of LinuxBasic of virtual memory of Linux
Basic of virtual memory of LinuxTetsuyuki Kobayashi
 
ADB(Android Debug Bridge): How it works?
ADB(Android Debug Bridge): How it works?ADB(Android Debug Bridge): How it works?
ADB(Android Debug Bridge): How it works?Tetsuyuki Kobayashi
 
Inter-process communication of Android
Inter-process communication of AndroidInter-process communication of Android
Inter-process communication of AndroidTetsuyuki Kobayashi
 

More from Tetsuyuki Kobayashi (20)

some topic of ffmpeg
some topic of ffmpeg some topic of ffmpeg
some topic of ffmpeg
 
New VIdeo CODEC AV1
New VIdeo CODEC AV1 New VIdeo CODEC AV1
New VIdeo CODEC AV1
 
Try new transport protocol SRT (ver. 2)
Try new transport protocol SRT  (ver. 2)Try new transport protocol SRT  (ver. 2)
Try new transport protocol SRT (ver. 2)
 
Try new transport protocol SRT
Try new transport protocol SRTTry new transport protocol SRT
Try new transport protocol SRT
 
Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機
Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機
Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機
 
WebOS Open Source Edition を試してみた
WebOS Open Source Edition を試してみたWebOS Open Source Edition を試してみた
WebOS Open Source Edition を試してみた
 
Linuxのユーザーランドをinitから全てまるごとgolangで書く
Linuxのユーザーランドをinitから全てまるごとgolangで書くLinuxのユーザーランドをinitから全てまるごとgolangで書く
Linuxのユーザーランドをinitから全てまるごとgolangで書く
 
組み込みLinuxでのGolangのススメ(Go con版)
組み込みLinuxでのGolangのススメ(Go con版)組み込みLinuxでのGolangのススメ(Go con版)
組み込みLinuxでのGolangのススメ(Go con版)
 
組み込みLinuxでのGolangのススメ
組み込みLinuxでのGolangのススメ組み込みLinuxでのGolangのススメ
組み込みLinuxでのGolangのススメ
 
Tricky implementation of Go ARM soft float
Tricky implementation of Go ARM soft floatTricky implementation of Go ARM soft float
Tricky implementation of Go ARM soft float
 
ARM 64bit has come!
ARM 64bit has come!ARM 64bit has come!
ARM 64bit has come!
 
Virtual memory 20070222-en
Virtual memory 20070222-enVirtual memory 20070222-en
Virtual memory 20070222-en
 
Simple and efficient way to get the last log using MMAP
Simple and efficient way to get the last log using MMAPSimple and efficient way to get the last log using MMAP
Simple and efficient way to get the last log using MMAP
 
Tips of Malloc & Free
Tips of Malloc & FreeTips of Malloc & Free
Tips of Malloc & Free
 
Basic of virtual memory of Linux
Basic of virtual memory of LinuxBasic of virtual memory of Linux
Basic of virtual memory of Linux
 
Patch101
Patch101Patch101
Patch101
 
ADB(Android Debug Bridge): How it works?
ADB(Android Debug Bridge): How it works?ADB(Android Debug Bridge): How it works?
ADB(Android Debug Bridge): How it works?
 
Tweaking Google TV emulator
Tweaking Google TV emulatorTweaking Google TV emulator
Tweaking Google TV emulator
 
Inter-process communication of Android
Inter-process communication of AndroidInter-process communication of Android
Inter-process communication of Android
 
Android ipm 20110409
Android ipm 20110409Android ipm 20110409
Android ipm 20110409
 

Recently uploaded

MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sectoritnewsafrica
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 

Recently uploaded (20)

MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 

Android is NOT just 'Java on Linux'

  • 1. Android is NOT just 'Java on Linux' 2011.5.22 2011.10.26 updated Tetsuyuki Kobayashi 1
  • 2. Let's talk about inside of Android. http://www.kmckk.co.jp/eng/kzma9/ 2 http://www.kmckk.co.jp/eng/jet_index.html
  • 3. Who am I?  20+ years involved in embedded systems  10 years in real time OS, such as iTRON  10 years in embedded Java Virtual Machine  Now GCC, Linux, QEMU, Android, …  Blogs  http://d.hatena.ne.jp/embedded/ (Personal)  http://blog.kmckk.com/ (Corporate)  http://kobablog.wordpress.com/(English)  Twitter  @tetsu_koba 3
  • 4. Android is NOT just 'Java on Linux'  Android uses Linux kernel. Only kernel.  User land is totally different from usual Linux system.  Android applications are written in Java language.  Class libraries are similar to Java SE but not equal.  Dalvik VM eats only dex code  need to translate from Java byte code in advance 4
  • 5. Let's explore inside of Android  Assuming you know Linux and Java very well :) 5
  • 6. Today's topic  Android system architecture  Init – runtime – Zygoto  Dalvik VM  Android specific kernel drivers  How to build Android 6
  • 7. Today's topic  Android system architecture  Init – runtime – Zygoto  Dalvik VM  Android specific kernel drivers  How to build Android 7
  • 9. Java is the first class citizen in Android  Dalvik VM is the center of Android runtime.  Almost all daemon services are written in Java.  Application life cycle is described by Java API 9
  • 10. Java is the first class citizen in Android  NDK  native library called from Java via JNI  This is just a library. Application life cycle is the same as Java.  Native activity  Only C/C++ to make Apps. (just hidden JNI part into system.)  not short-cut for C/C++ 10
  • 11. Typical Directory Tree of Android ro: mounted as read only / /(root) (root) initrd (ro) rw: mounted as read and write yaffs2 (ro) /system /system bin etc lib /data yaffs2 (rw) /data usr /cache yaffs2 (rw) /cache /mnt/sdcard removable storage (rw) /mnt/sdcard cf. Usual Linux system assumes all file system are read/writable. 11
  • 12. Today's topic  Android system architecture  Init – runtime – Zygoto  Dalvik VM  Android specific kernel drivers  How to build Android 12
  • 13. Boot sequence 13 quoted from http://hmtsay.blogspot.com/2010/10/android-startup.html
  • 14. init  located on /init  need kernel boot parameter to add “init=/init”  Static linked.  cf. typical linux init is dynamic linked.  Doesn't affect even dynamic link system collapsed.  http://blog.kmckk.com/archives/3137191.html 14
  • 15. Bionic  The standard libraries  libc, libm, pthread, dynamic linker  linker has implicit crash dump function  http://kobablog.wordpress.com/2011/05/12/debuggerd-of-android/  Came from *BSD, not glibc  Currently, doesn't support C++ exception and RTTI.  latest NDK supports these by static linking. 15
  • 16. Prelinking  Locate dynamic link libraries ahead of time.  'apriori' command. Different from 'prelink' command from Red Hat.  Optimized for small embedded system  Allocate fixed address to libraries .  Assume 3GB memory space is large enough to put all libraries together.  Assume not adding/removing libraries. 16
  • 17. Prelink map build/core/prelink-linux-arm.map # 0xC0000000 - 0xFFFFFFFF Kernel # 0xB0100000 - 0xBFFFFFFF Thread 0 Stack # 0xB0000000 - 0xB00FFFFF Linker # 0xA0000000 - 0xBFFFFFFF Prelinked System Libraries # 0x90000000 - 0x9FFFFFFF Prelinked App Libraries # 0x80000000 - 0x8FFFFFFF Non-prelinked Libraries # 0x40000000 - 0x7FFFFFFF mmap'd stuff # 0x10000000 - 0x3FFFFFFF Thread Stacks # 0x00000000 - 0x0FFFFFFF .text / .data / heap # core system libraries libdl.so 0xAFF00000 # [<64K] libc.so 0xAFD00000 # [~2M] libstdc++.so 0xAFC00000 # [<64K] libm.so 0xAFB00000 # [~1M] liblog.so 0xAFA00000 # [<64K] libcutils.so 0xAF900000 # [~1M] libthread_db.so 0xAF800000 # [<64K] libz.so 0xAF700000 # [~1M] libevent.so 0xAF600000 # [???] libssl.so 0xAF400000 # [~2M] libcrypto.so 0xAF000000 # [~4M] libsysutils.so 0xAEF00000 # [~1M] ... 17
  • 19. Zygote fork Zygote process Child process classes classes classes classes classes classes dynamic link classes classes dynamic link Dalvik VM classes libraries Dalvik VM classes libraries classes classes classes classes dynamic link Dalvik VM classes libraries Physical memory space (Actually these are mapped by pages.) 19
  • 20. Zygote  Zygote process preloads typical (approx. 1800) classes and dynamic link libraries so that childlen start quickly.  Copy-on-write  Only when new process writes page, new page is allocated.  All pages not be written are shared among all zygote children.  Exec system call is not used in zygote.  Exec wipes the page mapping table of the process.  It means exec discards zygote cache. 20
  • 21. UID, GID of Applications  UID(user id) and GID(group id) is used for managing multi-user in usual Linux system.  Android use this mechanism to isolate applications.  Each application has unique UID.  Can not read/write other application's files.  Zygote is running as UID=0 (root). After forking child process, its UID is changed by setuid system call. 21
  • 22. Today's topic  Android system architecture  Init – runtime – Zygoto  Dalvik VM  Android specific kernel drivers  How to build Android 22
  • 23. Dalvik VM  executes dex code, which is translated from Java byte code  16bit, register based  cf. Java bytecode is 8bit, stack based  has JIT from Android 2.2 (Froyo)  http://blog.kmckk.com/archives/2691473.html  has concurrent GC from Android 2.3 (Gingerbread)  http://source.android.com/tech/dalvik/ 23
  • 24. Java class libraries  Different from Java ME, which is used in traditional Japanese phone.  Similar to Java SE. But not equal.  Different window/graphics. No AWT, No Swing.  No RMI.  Take care to use user defined class loader  dynamic generated classes doesn't work because Dalvik VM doesn't eat Java class files but Dex files. 24
  • 25. Caveats of NDK programming  Dynamic libraries built by NDK are linked with application process.  forked from Zygote but UID != 0 (root).  consider about permissions.  Don't use fork & exec system calls.  Back ground process should be made as android .app.Service.  Don't use GCC's TLS extension (__thread).  Simple Android dynamic linker does not support it.  java.lang.ThreadLocal is available in Java. 25
  • 26. 3 commands to invoke Dalvik VM  /system/bin/app_process  This is the 'Zygote' process.  /system/bin/dalvikvm  Similar to usual 'java' command.  Try 'dalvikvm -h' to show command line help.  /system/bin/dvz  Send request to Zygote process.  See my blog (Sorry in Japanese)  http://blog.kmckk.com/archives/3551546.html 26
  • 27. Today's topic  Android system architecture  Init – runtime – Zygoto  Dalvik VM  Android specific kernel drivers  How to build Android 27
  • 28. Linux kernel  Many common Linux device drivers are available.  Android specific kernel drivers  binder  ashmem  wake lock  logger  …  http://elinux.org/Android_Kernel_Features  These source code is not yet merged to kernel main line repository. 28
  • 29. Binder  /dev/binder  Base of Inter Process Method Invocation  Not for general purpose. Tuned for specific transaction.  Multi-thread aware  Have internal data per thread  (CF. Socket have internal data per fd.)  Doesn't use ”write” and ”read” system calls. Write and read at once by ”ioctl”.  http://blog.kmckk.com/archives/3676340.html 29
  • 30. Ashmem  Android / Anonymous SHared MEMory subsystem  $(TOP)/system/core/cutils/ashmem.h  int ashmem_create_region(const char *name, size_t size) → returns fd  int ashmem_set_prot_region(int fd, int prot)  int ashmem_pin_region(int fd, size_t offset, size_t len)  int ashmem_unpin_region(int fd, size_t offset, size_t len)  Kernel reclaims not ‘pin’ ed memory  Similar to weak reference of Java. Useful to implement cache.  android.os.MemoryFile from Java program 30
  • 31. Wake lock  Lock to prevent entering sleep mode.  My memos  http://blog.kmckk.com/archives/3298375.html  http://blog.kmckk.com/archives/3304836.html  eLinux wiki  http://elinux.org/Android_Power_Management 31
  • 32. Alarm  kernel implementation to support Android's AlarmManager.  Wake up even when it was in sleep mode. 32
  • 33. Low memory killer  At the shortage of memory, the kernel select a process seems low priority and kill it. (!!)  It's OK. because specification in the Android application life cycle, application should be preserve its own status.  http://blog.kmckk.com/archives/2795577.html 33
  • 34. Logger  Android has unique system-wide log system  http://blog.kmckk.com/archives/2936958.html  http://elinux.org/Android_Logging_System 34
  • 35. Overview of Android Logging System Target Java program Java program System.out /System.err com.android.internal.os Native program android.util.Log com.android.internal.os Host Native program android.util.Log AndroidPrintStream AndroidPrintStream DDMS stdout logcat logcat stdout liblog /stderr liblog adbserver adbd adbd adbserver User Kernel adb logcat main 64KB radio logger logger 64KB /dev/log/main /dev/log/main /dev/log/radio event /dev/log/radio system /dev/log/event 256KB /dev/log/event /dev/log/system 64KB /dev/log/system 35
  • 36. Today's topic  Android system architecture  Init – runtime – Zygoto  Dalvik VM  Android specific kernel drivers  How to build Android 36
  • 37. How to build Android  All source code is available for download  except Google specific services (Google map, Android market, … )  Easy to download source and build them  See AOSP web site  http://source.android.com/  Or, my blog  http://blog.kmckk.com/archives/3722957.html 37
  • 38. Conclusion  Android system architecture is totally different from normal Linux systems.  Android uses Linux kernel only, further more, adding android specific kernel drivers.  Designed for Java applications.  Tuned for small system. 38
  • 39. Q&A Thank you for listening! Any comments to blogs are welcome. 39