+ All Categories
Home > Documents > Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure...

Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure...

Date post: 21-Dec-2015
Category:
View: 212 times
Download: 0 times
Share this document with a friend
26
Mobiiliohjelmointi, kevät Mobiiliohjelmointi, kevät 2009 2009 1 1. Introduction 1. Introduction Leaking abstractions Leaking abstractions Structure of a mobile device Structure of a mobile device Hardware Hardware Basic software concepts and run-time Basic software concepts and run-time infrastructure infrastructure Software stack and installation Software stack and installation Summary Summary
Transcript
Page 1: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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

Page 2: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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;}}

Page 3: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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?

Page 4: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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!

Page 5: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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?

Page 6: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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?

Page 7: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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

Page 8: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 88

Processor

Accelerator

Memory

Cache

Cache

Peripherals

Sample HardwareSample Hardware

Page 9: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 99

Another Sample HardwareAnother Sample Hardware

Page 10: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –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.

Page 11: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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, ...

Page 12: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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

Page 13: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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?

Page 14: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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

Page 15: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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

Page 16: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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

Page 17: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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

Page 18: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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

Page 19: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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

Page 20: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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

Page 21: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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

Page 22: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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

Page 23: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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

Page 24: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

Mobiiliohjelmointi, kevät 2009Mobiiliohjelmointi, kevät 2009 2424

Development Process (web)Development Process (web)

Emulator

Developmentworkstation

Emulatorrunnable

Emulatorcompilation

Sourcecode

Mobile device

Devicerunnable

Download

Page 25: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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

Page 26: Mobiiliohjelmointi, kevät 2009 1 1. Introduction Leaking abstractionsLeaking abstractions Structure of a mobile deviceStructure of a mobile device –Hardware.

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


Recommended