際際滷

際際滷Share a Scribd company logo
Android os
1. INTRODUCTION
2. ARCHITECTURE
3. Dalvik Virtual Machine(DVM)
4. Process Management
5. Memory Management
6. Application and Service Lifecycle
 Android is Mobile(Device) Based OS.
 Which is based on Linux 2.6 kernel.
 Android Inc.(founded in 2003 and is based in Palo

Alto, California) which operated as subsidiary of Google and
later purchased by Google in 2005.

 OHA Est. 5th Nov 2007, led by Google, open Source.

 Open source under the Apache 2 license.
 Android was publicly announced in 2007 and first phone was

sold on October 2008.

 HTC was First to deliver ANDROID Mobile Device.
Android os


Linux kernel



Libraries



Android run time
 core libraries
 Dalvik virtual machine



Application layer



Application protocol
Android os
 Acts as an abstraction layer between the hardware and the
rest of the software stack.

 Relies on Linux version 2.6 for core system services such as
security, memory management, process management,
network stack, and driver model.
 Works as a HAL (Hardware Abstraction Layer or
rather Hardware Annotation Library)
System C library - implementation of the C library (libc).
Media Libraries - based on PacketVideo's Open CORE.
Surface Manager - composites 2D and 3D graphic layers
LibWebCore - a modern embeddable web view.
SGL - the underlying 2D graphics engine.
3D libraries - based on OpenGL ES 1.0 APIs; the libraries use
hardware 3D acceleration.
 FreeType - bitmap and vector font rendering
 SQLite - a powerful and lightweight relational database
engine .
 Includes a set of core libraries of JAVA that provides most of
the functionality
 Runs in its own process, with its own instance of the Dalvik
Virtual Machine
 The Dalvik VM executes files in the Dvbalvik Executable
(.dex)
 Compact and efficient than class files
 Limited memory and battery power
 Access location information, run background services, set
alarms, add notifications to the status bar, and much, much
more.
 Build an application, including lists, grids, text boxes,
buttons, and even an embeddable web browser
 Providing access to non-code resources such as localized
strings, graphics, and layout files.
 Activity manager manages application life cycle.
 Content provider Enable applications access data from
other applications.
 resource manager which gives us access to non court
resources such as localized strings or various others, we can
layout so many resources, we can have in the form of PNG,
BMP as well as XML so resource manager helps us to get
access to those non code resources.
 Notification manager which helps us to display custom
alerts on status bar.
 location managers it handles information about the location.
 telephony manager which handles information about telephony.
Android os
Android os
Stack Based
Virtual Machine(ex.JVM)
POP 20
POP 7
ADD 20, 7, result
PUSH result
Register Based
Virtual Machine(ex.DVM)

Add R3,R1,R2
 A special Java Virtual Machine(VM) designed
to run with limited system resource.
 It is basically a virtual machine for embedded
devices, which like any other virtual machine,
is a byte code interpreter.
 it means it is low on memory, comparatively
slower and runs on battery power.
 Google is modify DVM according to the
Android OS is named as Dalvik Turbo
virtual machine.
 Java class file are converted into .dex Files
that Dalvik executes
 Java byte code is converted into Dalvik bytecode during this process
 For each application android creates a new process with
single thread of execution(i.e. main thread)
 By default all the components run in same thread(main
thread) If not developer explicitly creates a new thread.
 In low memory situations a process is decide to kill based
upon the number of inactive components of that
process.
 A process which have more number of inactive components
should be killed 鍖rst.
 A process is treated as foreground if any of components
of process holds following states.
 An activity which is interacting with user. When an
activity calls methods like onstart(), onresume().
 When a service is interacting with foreground activity.
 When a service is started using startForeground().
 when a service is executing any of the methods like
onCreate(),onStart(), onDestroy().
 Visible, but inactive processes are those hosting
visible Activities. As the name suggests, visible
Activities are visible, but they arent in the foreground
or responding to user events.
 This happens when an Activity is only partially obscured
(by a non-full-screen or transparent Activity).
 There are generally very few visible processes, and
theyll only be killed in extreme circumstances to allow
active processes to continue.
 An activity which is not interacting with user. But it is
still visible to user, when an activity running method like
onPause().
 Processes hosting Services that have been started.
Services support ongoing processing that should
continue without a visible interface.
 Because Services dont interact directly with the user,
they receive a slightly lower priority than visible
Activities.
 They are still considered to be foreground processes and
wont be killed unless resources are needed for active or
visible processes.
 When a service is started using startService().
 Eg: playing music in background, downloading 鍖le from
internet.
 Processes hosting Activities that arent visible and that
dont have any Services that have been started are
considered background processes.
 There will generally be a large number of background
processes that Android will kill using a last-seen-firstkilled pattern to obtain resources for foreground
processes.
 When an activity running method like onStop().
i.e currently user is not interacting with that activity.
 Whenever a process decided to kill, it stores the state of
activity. So whenever next time user wants that activity,
we can restore the previous state of activity.
 To improve overall system performance, Android often
retains applications in memory after they have reached
the end of their lifetimes.
 Android maintains this cache to improve the start-up
time of applications when theyre re-launched.
 These processes are routinely killed as required.
 When a process does not have any active component.
 Caching of empty process inside memory, reduces
relaunching of application once again if user wants that
application in future.
 Page-based memory management
 Virtual address to physical address mapping
 No virtual memory
 Androids process and memory management is a little unusual.
 Like Java and .NET, Android uses its own run time and virtual machine
to manage application memory.
 Unlike either of these frameworks, the Android run time also manages
the process lifetimes.
 Android ensures application responsiveness by stopping and killing
processes as necessary to free resources for higher-priority applications.
 Each Android application runs in a separate process within its own Dalvik
instance, relinquishing all responsibility for memory and process
management to the Android run time, which stops and kills processes as
necessary to manage resources.

 Dalvik Virtual Machine Dalvik is a register-based virtual machine thats
been optimized to ensure that a device can run multiple instances
efficiently. It relies on the Linux kernel for threading and low-level
memory management.
 The order in which processes are killed to
reclaim resources is determined by the
priority of the hosted applications. An
applications priority is equal to its highestpriority component.
 Where two applications have the same
priority, the process that has been at a lower
priority longest will be killed first.

 Process priority is also affected by interprocess dependencies
 if an application has a dependency on a
Service or Content Provider supplied by a
second application, the secondary
application will have at least as high a
priority as the application it supports.
 All Android applications will remain running
and in memory until the system needs its
resources for other applications.
 Application run in their own processes (VM, PID)
 Processes are started and stopped as needed to run an
application's components
 Processes may be killed to reclaim resources
Android os
Android os
Thank You

More Related Content

Android os

  • 2. 1. INTRODUCTION 2. ARCHITECTURE 3. Dalvik Virtual Machine(DVM) 4. Process Management 5. Memory Management 6. Application and Service Lifecycle
  • 3. Android is Mobile(Device) Based OS. Which is based on Linux 2.6 kernel. Android Inc.(founded in 2003 and is based in Palo Alto, California) which operated as subsidiary of Google and later purchased by Google in 2005. OHA Est. 5th Nov 2007, led by Google, open Source. Open source under the Apache 2 license. Android was publicly announced in 2007 and first phone was sold on October 2008. HTC was First to deliver ANDROID Mobile Device.
  • 5. Linux kernel Libraries Android run time core libraries Dalvik virtual machine Application layer Application protocol
  • 7. Acts as an abstraction layer between the hardware and the rest of the software stack. Relies on Linux version 2.6 for core system services such as security, memory management, process management, network stack, and driver model. Works as a HAL (Hardware Abstraction Layer or rather Hardware Annotation Library)
  • 8. System C library - implementation of the C library (libc). Media Libraries - based on PacketVideo's Open CORE. Surface Manager - composites 2D and 3D graphic layers LibWebCore - a modern embeddable web view. SGL - the underlying 2D graphics engine. 3D libraries - based on OpenGL ES 1.0 APIs; the libraries use hardware 3D acceleration. FreeType - bitmap and vector font rendering SQLite - a powerful and lightweight relational database engine .
  • 9. Includes a set of core libraries of JAVA that provides most of the functionality Runs in its own process, with its own instance of the Dalvik Virtual Machine The Dalvik VM executes files in the Dvbalvik Executable (.dex) Compact and efficient than class files Limited memory and battery power
  • 10. Access location information, run background services, set alarms, add notifications to the status bar, and much, much more. Build an application, including lists, grids, text boxes, buttons, and even an embeddable web browser Providing access to non-code resources such as localized strings, graphics, and layout files. Activity manager manages application life cycle. Content provider Enable applications access data from other applications.
  • 11. resource manager which gives us access to non court resources such as localized strings or various others, we can layout so many resources, we can have in the form of PNG, BMP as well as XML so resource manager helps us to get access to those non code resources. Notification manager which helps us to display custom alerts on status bar. location managers it handles information about the location. telephony manager which handles information about telephony.
  • 14. Stack Based Virtual Machine(ex.JVM) POP 20 POP 7 ADD 20, 7, result PUSH result
  • 16. A special Java Virtual Machine(VM) designed to run with limited system resource. It is basically a virtual machine for embedded devices, which like any other virtual machine, is a byte code interpreter. it means it is low on memory, comparatively slower and runs on battery power. Google is modify DVM according to the Android OS is named as Dalvik Turbo virtual machine. Java class file are converted into .dex Files that Dalvik executes Java byte code is converted into Dalvik bytecode during this process
  • 17. For each application android creates a new process with single thread of execution(i.e. main thread) By default all the components run in same thread(main thread) If not developer explicitly creates a new thread. In low memory situations a process is decide to kill based upon the number of inactive components of that process. A process which have more number of inactive components should be killed 鍖rst.
  • 18. A process is treated as foreground if any of components of process holds following states. An activity which is interacting with user. When an activity calls methods like onstart(), onresume(). When a service is interacting with foreground activity. When a service is started using startForeground(). when a service is executing any of the methods like onCreate(),onStart(), onDestroy().
  • 19. Visible, but inactive processes are those hosting visible Activities. As the name suggests, visible Activities are visible, but they arent in the foreground or responding to user events. This happens when an Activity is only partially obscured (by a non-full-screen or transparent Activity). There are generally very few visible processes, and theyll only be killed in extreme circumstances to allow active processes to continue. An activity which is not interacting with user. But it is still visible to user, when an activity running method like onPause().
  • 20. Processes hosting Services that have been started. Services support ongoing processing that should continue without a visible interface. Because Services dont interact directly with the user, they receive a slightly lower priority than visible Activities. They are still considered to be foreground processes and wont be killed unless resources are needed for active or visible processes. When a service is started using startService(). Eg: playing music in background, downloading 鍖le from internet.
  • 21. Processes hosting Activities that arent visible and that dont have any Services that have been started are considered background processes. There will generally be a large number of background processes that Android will kill using a last-seen-firstkilled pattern to obtain resources for foreground processes. When an activity running method like onStop(). i.e currently user is not interacting with that activity. Whenever a process decided to kill, it stores the state of activity. So whenever next time user wants that activity, we can restore the previous state of activity.
  • 22. To improve overall system performance, Android often retains applications in memory after they have reached the end of their lifetimes. Android maintains this cache to improve the start-up time of applications when theyre re-launched. These processes are routinely killed as required. When a process does not have any active component. Caching of empty process inside memory, reduces relaunching of application once again if user wants that application in future.
  • 23. Page-based memory management Virtual address to physical address mapping No virtual memory
  • 24. Androids process and memory management is a little unusual. Like Java and .NET, Android uses its own run time and virtual machine to manage application memory. Unlike either of these frameworks, the Android run time also manages the process lifetimes. Android ensures application responsiveness by stopping and killing processes as necessary to free resources for higher-priority applications. Each Android application runs in a separate process within its own Dalvik instance, relinquishing all responsibility for memory and process management to the Android run time, which stops and kills processes as necessary to manage resources. Dalvik Virtual Machine Dalvik is a register-based virtual machine thats been optimized to ensure that a device can run multiple instances efficiently. It relies on the Linux kernel for threading and low-level memory management.
  • 25. The order in which processes are killed to reclaim resources is determined by the priority of the hosted applications. An applications priority is equal to its highestpriority component. Where two applications have the same priority, the process that has been at a lower priority longest will be killed first. Process priority is also affected by interprocess dependencies if an application has a dependency on a Service or Content Provider supplied by a second application, the secondary application will have at least as high a priority as the application it supports. All Android applications will remain running and in memory until the system needs its resources for other applications.
  • 26. Application run in their own processes (VM, PID) Processes are started and stopped as needed to run an application's components Processes may be killed to reclaim resources

Editor's Notes

  • #4: Open Handset Alliance(OHA)
  • #5: TheOpen Handset Alliance(OHA) is aconsortiumof 84[1]firms to developopen standardsformobile devices. Member firms include Google,HTC,Sony,Dell,Intel,Motorola,Qualcomm,Texas Instruments,Samsung Electronics,LG Electronics,T-Mobile,Sprint Corporation, Nvidia andWind River Systems.The OHA was established on 6 November 2007, led byGooglewith 34 members including mobile handset makers,applicationdevelopers, some mobile carriers and chip makers.Android, the flagship software of the alliance, is based on an open source license and has competed against mobile platformsfromApple,Microsoft,Nokia(Symbian),HP(formerlyPalm),Samsung Electronics/Intel(Tizen,bada), andBlackberry.Members of OHA are not allowed to produce phones that run incompatible versions of Android.
  • #10: Includes a set of core libraries that provides most of the functionality-JAVAEvery Android application runs in its own processDalvik VM executes files in the (.dex) formatDevice can run multiple VMs efficiently.==================================================All applications written in Java and converted to the Dalvik executable .dex.Every android app runs its own process, with its own instance of the Dalvik virtual machine.Not a traditional JVM, but a custom VM designed to run multiple instances efficiently on a single device.VM uses Linux kernel to handle low-level functionality including security, threading, process and memory managemet.
  • #11: Activity Manager :Manages the lifecycle of applicationsContent provider : Enable applications access data from other applicationsResource Manager :Providing access to non-code resourcesWindow ManagerNotification managerSQLite Databases: relational database library for storing and managing complex dataFiles: you can create, write, and read files from the local storage or external media (SD Cards)FileOutputStream, FileInputStream, and Resources classes.=======================================================Set of core applications including an email client, SMS program, calendar, maps, browser, contacts.All applications are written using the Java programming language.Built in and user apps.Can replace built in apps.
  • #12: Activity Manager :Manages the lifecycle of applicationsContent provider : Enable applications access data from other applicationsResource Manager :Providing access to non-code resourcesWindow ManagerNotification managerSQLite Databases: relational database library for storing and managing complex dataFiles: you can create, write, and read files from the local storage or external media (SD Cards)FileOutputStream, FileInputStream, and Resources classes.=======================================================Set of core applications including an email client, SMS program, calendar, maps, browser, contacts.All applications are written using the Java programming language.Built in and user apps.Can replace built in apps.
  • #14: Activity Manager :Manages the lifecycle of applicationsContent provider : Enable applications access data from other applicationsResource Manager :Providing access to non-code resourcesWindow ManagerNotification managerSQLite Databases: relational database library for storing and managing complex dataFiles: you can create, write, and read files from the local storage or external media (SD Cards)FileOutputStream, FileInputStream, and Resources classes.=======================================================Set of core applications including an email client, SMS program, calendar, maps, browser, contacts.All applications are written using the Java programming language.Built in and user apps.Can replace built in apps.
  • #15: A stack based virtual machine implements the general features described as needed by a virtual machine in the points above, but the memory structure where the operands are stored is a stack data structure. Operations are carried out by popping data from the stack, processing them and pushing in back the results in LIFO (Last in First Out) fashion. In a stack based virtual machine, the operation of adding two numbers would usually be carried out in the following manner (where 20, 7, and result are the operands):Because of the PUSH and POP operations, four lines of instructions is needed to carry out an addition operation.An advantage of the stack based model is that the operands are addressed implicitly by the stack pointer (SP in above image). This means that the Virtual machine does not need to know the operand addresses explicitly, as calling the stack pointer will give (Pop) the next operand. In stack based VMs, all the arithmetic and logic operations are carried out via Pushing and Popping the operands and results in the stack.
  • #16: As I mentioned earlier, there is no POP or PUSH operations, so the instruction for adding is just one line.But unlike the stack, we need to explicitly mention the addresses of the operands as R1, R2, and R3.The advantage here is that the overhead of pushing to and popping from a stack is non-existent, and instructions in a register based VM execute faster within the instruction dispatch loop.Another advantage of the register based model is that it allows for some optimizations that cannot be done in the stack based approach. One such instance is when there are common sub expressions in the code, the register model can calculate it once and store the result in a register for future use when the sub expression comes up again, which reduces the cost of recalculating the expression.The problem with a register based model is that the average register instruction is larger than an average stack instruction, as we need to specify the operand addresses explicitly.Whereas the instructions for a stack machine is short due to the stack pointer, the respective register machine instructions need to contain operand locations, and results in larger register code compared to stack code.
  • #17: Every Android application runs in its own process, with its own instance of the Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently. The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimised for minimal memory footprint. The VM is register-based, and runs classes compiled by a Java language compiler that have been transformed into the .dex format by the included dx tool.Android programs are compiled into .dex (Dalvik Executable) files, which are in turn zipped into a single .apk file on the device. .dex files can be created by automatically translating compiled applications written in the Java programming language.
  • #24: Page based Memory management:揃Extracts the page number concern.揃Extract the offset to be used.揃Check that the page number is within the address space of the process.揃Add offset to resulting physical page number.揃Access the memory location.============================================Physical addressing means that your program actually knows the real layout of RAM. When you access a variable at address 0x8746b3, that's where it's really stored in the physical RAM chips.With virtual addressing, all application memory accesses go to a page table, which then maps from the virtual to the physical address. So every application has its own "private" address space, and no program can read or write to another program's memory. This is calledsegmentation.Virtual addressing has many benefits. It protects programs from crashing each other through poor pointer manipulation, etc. Because each program has its own distinct virtual memory set, no program can read another's data - this is both a safety and a security plus. Virtual memory also enablespaging, where a program's physical RAM may be stored on a disk (or, now, slower flash) when not in use, then called back when an application attempts to access the page. Also, since only one program may be resident at a particularphysicalpage, in a physical paging system, either a) all programs must be compiled to load at different memory addresses or b) every program must use Position-Independent Code, or c) some sets of programs cannot run simultaneously.The physical-virtual mapping may be done in software (with hardware support for memory traps) or in pure hardware. Sometimes even the page tables themselves are on a special set of hardware memory. I don't know off the top of my head which embedded system does what, but every desktop has a hardware TLB (Translation Lookaside Buffer, basically a cache for the virtual-physical mappings) and some now have advanced Memory Mapping Units that help with virtual machines and the like.The only downsides of virtual memory are added complexity in the hardware implementation and slower performance.