Date post: | 21-Dec-2015 |
Category: |
Documents |
View: | 212 times |
Download: | 0 times |
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 11
1. Introduction1. Introduction
• Leaking abstractionsLeaking abstractions• Structure of a mobile deviceStructure of a mobile device
– HardwareHardware– Basic software concepts and run-time Basic software concepts and run-time
infrastructureinfrastructure– Software stack and installationSoftware stack and installation
• SummarySummary
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 22
Example: Null-terminating stringExample: Null-terminating string
char * strcat(char * c1, char * c2)char * strcat(char * c1, char * c2){{ int i, j; int i, j; while(i = 0; 0 != c1[i]; i++);while(i = 0; 0 != c1[i]; i++); while(j = 0; 0 != c2[j]; j++, i++) while(j = 0; 0 != c2[j]; j++, i++) c1[i] = c2[j];c1[i] = c2[j]; c1[i+1] = 0;c1[i+1] = 0; return c1;return c1;}}
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 33
Leaking abstractionLeaking abstraction
• Leaking abstraction reveals the details of an Leaking abstraction reveals the details of an implementation in some special caseimplementation in some special case– TCP/IP when connection is terminally brokenTCP/IP when connection is terminally broken– SQL can be terribly slow in some queries that are SQL can be terribly slow in some queries that are
poorly organizedpoorly organized– Run-time infrastructure can behave in a complex Run-time infrastructure can behave in a complex
fashionfashion– ……
• Are there leak-proof abstractions?Are there leak-proof abstractions?
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 44
Leaking abstractions and mobile Leaking abstractions and mobile devicesdevices
• Scarce resourcesScarce resources– Memory, processor, bandwidth, disk, etc.Memory, processor, bandwidth, disk, etc.– Implementation becomes visible more easily as there is only Implementation becomes visible more easily as there is only
limited reservelimited reserve
• Resource allocation responsibilityResource allocation responsibility– White-box resource managementWhite-box resource management– Black-box resource managementBlack-box resource management
• In the end, the programmer still holds all the strings in In the end, the programmer still holds all the strings in both approachesboth approaches– Infrastructure’s effect must be taken into account!Infrastructure’s effect must be taken into account!
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 55
White-box resource managementWhite-box resource management
• Assumes an educated developer who always Assumes an educated developer who always anticipates the implementation and performs anticipates the implementation and performs necessary actions in any resource allocationnecessary actions in any resource allocation– Avoids leaking abstractions by giving control and Avoids leaking abstractions by giving control and
responsibility to the programmer responsibility to the programmer
• Patterns (and antipatterns) of resource managementPatterns (and antipatterns) of resource management• Coding style, idioms and standardsCoding style, idioms and standards• Example systemsExample systems
– CC– C++C++
• Errors and their effect?Errors and their effect?
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 66
Black-box resource managementBlack-box resource management
• Assumes an infrastructure that allows and lives with Assumes an infrastructure that allows and lives with any allocation strategy for the programmerany allocation strategy for the programmer– However, leaking abstractions of the infrastructure remain a However, leaking abstractions of the infrastructure remain a
problem that must be solved by the programmerproblem that must be solved by the programmer
• Example systems: Example systems: – JavaJava– C# C#
(Btw., when do Java and/or C# abstractions leak?)(Btw., when do Java and/or C# abstractions leak?)– Scripting languages (Python, JavaScript)Scripting languages (Python, JavaScript)– Web runtime (e.g. widgets)Web runtime (e.g. widgets)
• Error cases?Error cases?
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 77
Content and goalsContent and goals
• Leaking abstractionsLeaking abstractions• Structure of a mobile deviceStructure of a mobile device
– HardwareHardware– Basic software concepts and run-time Basic software concepts and run-time
infrastructureinfrastructure– Software stack and installationSoftware stack and installation
• SummarySummary
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 88
Processor
Accelerator
Memory
Cache
Cache
Peripherals
Sample HardwareSample Hardware
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 99
Another Sample HardwareAnother Sample Hardware
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 1010
ProcessingUnit 1
Nokia Terminal Architecture (NoTA) Nokia Terminal Architecture (NoTA)
((http://en.wikipedia.org/wiki/Network_on_Terminal_Architecture)http://en.wikipedia.org/wiki/Network_on_Terminal_Architecture)B
us
Memory, peripherals, etc.
ProcessingUnit 2
ProcessingUnit n
…
Memory, peripherals, etc.
Memory, peripherals, etc.
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 1111
Hardware – Components Hardware – Components
• Processor executes instructions that manipulate memoryProcessor executes instructions that manipulate memory– ARMARM
• Accelerators (DSP, custom) provide enhanced computation Accelerators (DSP, custom) provide enhanced computation facilitiesfacilities
• Memory stores program and data (RAM: 32Mb-128Mb; 64Mb a Memory stores program and data (RAM: 32Mb-128Mb; 64Mb a common figure, ROM: 32Mb-64Mb; ever increasing)common figure, ROM: 32Mb-64Mb; ever increasing)– ROM, RAM; Flash (NOR flash is direct memory space, NAND flash ROM, RAM; Flash (NOR flash is direct memory space, NAND flash
is like a disk)is like a disk)– Memory management unit (MMU) helps in organizing memory Memory management unit (MMU) helps in organizing memory
usageusage– Paging becoming an option as the size of the flash disk increases; Paging becoming an option as the size of the flash disk increases;
some devices use real hard drivessome devices use real hard drives• Peripherals provide an access to the outside worldPeripherals provide an access to the outside world
– Bluetooth, radio interface, screen, additional memory, battery, ...Bluetooth, radio interface, screen, additional memory, battery, ...
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 1212
Memory hierarchyMemory hierarchy
Processor’s internal memory locations
Cache
Main memory
Disk/flash memory for permanent data
Remote storage accessible via network
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 1313
Memory Allocation: What Is Memory Allocation: What Is Allocated Where?Allocated Where?
• ConstantsConstants– ROM if enabledROM if enabled
• Program binariesProgram binaries– ROM (in-place execution; how about e.g. code encryption ROM (in-place execution; how about e.g. code encryption
for protection or upgrades?)for protection or upgrades?)– RAM (additional RAM required for programs)RAM (additional RAM required for programs)
• DataData– RAMRAM– Saving to disk/flash memory? What would the user be Saving to disk/flash memory? What would the user be
expecting?expecting?
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 1414
Content and goalsContent and goals
• Leaking abstractionsLeaking abstractions• Structure of a mobile deviceStructure of a mobile device
– HardwareHardware– Basic software concepts and run-time Basic software concepts and run-time
infrastructureinfrastructure– Software stack and installationSoftware stack and installation
• SummarySummary
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 1515
Basic Software ConceptsBasic Software Concepts
• Hardware abstraction layer, HALHardware abstraction layer, HAL• Kernel Kernel
– Scheduling (pre-emptive, non-pre-emptive)Scheduling (pre-emptive, non-pre-emptive)– Interrupt handlingInterrupt handling
• Device drivers for providing access to hardwareDevice drivers for providing access to hardware– Physical vs. logical driversPhysical vs. logical drivers
• Processes for resource reservationProcesses for resource reservation– Files, semaphores, etc.Files, semaphores, etc.
• Threads as units of executionThreads as units of execution– Individual flows of controlIndividual flows of control
• Virtual machine when neededVirtual machine when needed
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 1616
Example: Symbian OSExample: Symbian OS
User library
Kernel executive
Variant DLLs Device drivers
HWHW
Kernelserver
Fileserver
Userthread
Driver i/f DLL
Userthread
Nullthread
EFSRV.DLL
User side
Kernel side
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 1717
Example: Mobile JavaExample: Mobile JavaVirtual MachineVirtual Machine
Java VM Classloader
*.class*.class
*.class*.class
loads
Runtime data
App.area*
Classarea
Stack
Heap
* App. area includes e.g. Program Counter
loads classes into
Executionengine
Bytecodeinterpreter
Scheduler
Memorymanager
calls
use
garbagecollection
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 1818
Content and goalsContent and goals
• Leaking abstractionsLeaking abstractions• Structure of a mobile deviceStructure of a mobile device
– HardwareHardware– Basic software concepts and run-time Basic software concepts and run-time
infrastructureinfrastructure– Software stack and installationSoftware stack and installation
• SummarySummary
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 1919
Software StackSoftware Stack
Application Facilities- Applications- UI and application specific libraries
Middleware- Communications stacks- Abstract access to lower-level facilities
Low-level Software- Kernel - Device drivers
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 2020
Common device-specific Common device-specific concernsconcerns
• Device-inflicted variance of software Device-inflicted variance of software – Different screen sizes and typesDifferent screen sizes and types– Provided performance (accelerators etc)Provided performance (accelerators etc)– Amount of memoryAmount of memory– Etc.Etc.
• Stability of interfaces between different releases (and Stability of interfaces between different releases (and individual devices)individual devices)
• Binary compatibility between different releasesBinary compatibility between different releases• Compatibility between different generations of Compatibility between different generations of
systemssystems• Supported standardsSupported standards
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 2121
Development Process (binary)Development Process (binary)
Mobile device
Emulator
Developmentworkstation
Emulatorrunnable
Emulatorcompilation
Devicerunnable Cross-
compilation
Deviceinstallable
Devicerunnable
Sourcecode
Packing
Download
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 2222
Different approaches to Different approaches to cross-compilationcross-compilation
• MIDP JavaMIDP Java– Direct Direct
generation generation of runnable of runnable bytecodesbytecodes
– Same in Same in laptop and laptop and devicedevice
• SymbianSymbian– Emulator to Emulator to
test on PCtest on PC– Different Different
compiler for compiler for actual actual devicedevice
• MaemoMaemo– Scratchbox Scratchbox
cross-cross-compilation compilation installed for installed for developmentdevelopment
– Possible to Possible to define what define what output is output is generatedgenerated
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 2323
Development Process (scripting)Development Process (scripting)
Mobile device
Emulator
Developmentworkstation
Emulatorrunnable
Emulatorcompilation Packaging
Deviceinstallable
Devicerunnable
Sourcecode
Download
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 2424
Development Process (web)Development Process (web)
Emulator
Developmentworkstation
Emulatorrunnable
Emulatorcompilation
Sourcecode
Mobile device
Devicerunnable
Download
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 2525
Content and goalsContent and goals
• Leaking abstractionsLeaking abstractions• Structure of a mobile deviceStructure of a mobile device
– HardwareHardware– Basic software concepts and run-time Basic software concepts and run-time
infrastructureinfrastructure– Software stackSoftware stack
• SummarySummary
Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 2626
SummarySummary
• Mobile devices’ programming hardened due to Mobile devices’ programming hardened due to leaking abstractionsleaking abstractions
• Basic architectureBasic architecture– Processor, memory hierarchy, auxiliariesProcessor, memory hierarchy, auxiliaries– Operating system, middleware, applicationsOperating system, middleware, applications– Infrastructure reuse preferableInfrastructure reuse preferable
• Programmer may be responsible for allocating Programmer may be responsible for allocating variables to memory and data to disk (in particular variables to memory and data to disk (in particular binary apps)binary apps)
• Overhead in run-time infrastructure – performance Overhead in run-time infrastructure – performance may vary!may vary!– Virtual function tablesVirtual function tables– Virtual machinesVirtual machines