1 cheng-chun hsu training for new students 2009/9/11

Post on 14-Dec-2015

215 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

1

Platform Optimization

Cheng-Chun Hsu

Training for New Students

2009/9/11

2

Outline First Part

Introduction of Java Introduction of Garbage Collection

Second Part Introduction of Actor Model

Third Part CVM’s Implementation

(Linux, Windows Mobile, Andes Platform, Windows)

2009/9/11

3

Java Version J2SE J2EE J2ME

2009/9/11

4

ArchitectureDesktop Low-end

devicesEnterprise High-end

devicesSmartCards

Optional

packages

Foundation

profile

CDC

Personal

profile

JavaCard

Card VM

MIDP

Optionalpackages

CLDC

KVMKVMJava Virtual MachineJava Virtual Machine

Java 2 Micro Edition (J2ME)

Optionalpackages

JEE

Optionalpackages

JSE

CVMCVM

2009/9/11

5

Configuration and Profile

2009/9/11

6

Java Compile Processes

2009/9/11

7

Outline First Part

Introduction of Java Introduction of Garbage Collection

Second Part Introduction of Actor Model

Third Part CVM’s Implementation

(Linux, Windows Mobile, Andes Platform, Windows)

2009/9/11

8

Garbage Collection

2009/9/11

9

G.C. Benefits No dangling references No memory leaks Greater programmer productivity

Ex: Java, C#

2009/9/11

10

Related G.C. G.C. stage

Identify (must pause time) Collect

When is the G.C. happened ?1) Allocate new object (not enough memory)2) System idle3) System.gc( )4) Intialization

2009/9/11

11

Kind of G.C.• Classical G.C.

1. Mark and Sweep (Tracing)2. Copying Collection (Semi-space)3. Reference Counting => cyclic problem

• Advanced G.C. 1. Generational Collection => hybrid

algorithm2. Incremental Collection => real-time

system)2009/9/11

12

Mark-Sweep Collectors (Graph) DFS(x)

2009/9/11

13

Mark-Sweep Algo. Marking phase

Starting from the roots, set the mark bit on all live cells.

Sweep phase Return all unmarked cells to the free list. Reset the mark bit on all marked cells.

2009/9/11

14

Features If less garbage, then high speed Disadvantage

Memory has internal fragment. Must be pause.

2009/9/11

15

Semi-Space (Graph) From-space, To-space

2009/9/11

16

Features If much garbage, then high

performance Advantage

Only visits live objects (therefore fast) No fragmentation and fast allocation

Disadvantage Only from-space used Must be pause

2009/9/11

17

Reference Counting (Graph) Counting pointers and cyclic structure

2009/9/11

18

Features Advantage

Quickly Disadvantage

Cannot reclaim cyclic structure Maintain a counter per chunk Extra space requirements Fragmentation

2009/9/11

19

Generational (Graph) Old generation (mark-compact) New generation (copying)

2009/9/11

20

Outline First Part

Introduction of Java Introduction of Garbage Collection

Second Part Introduction of Actor Model

Third Part CVM’s Implementation

(Linux, Windows Mobile, Andes Platform, Windows)

2009/9/11

Object-Reference Graph

21

4

5

7

8

6

2

3

1

2009/9/11

22

Actor Model Graph

A

CB D

H

FE

G

I

2009/9/11

Compare Two SystemsObject-Oriented System Actor System

Passive Active

Heavy Sightly

Have suitable storage No stacks, heap, register

Computation has independent threads of control manipulating the object they refer to.

Thread of control is encapsulated in the object itself.

Thread of control is important.

Thread of control is unimportant.

232009/9/11

24

Actor Model Actor

The universe consists of autonomous computation agents.

Garbage Actor Unable to receive a message from or

send a message to the root actor.

2009/9/11

25

States of Actors Active()

An actor which is either processing a message or has message pending in its mail-queue.

Blocked() An actor that is waiting for the arrival of a

message to its empty mail queue. Root()

An actor that is always considered as non-garbage.

2009/9/11

26

Communication between Actors Each actor has a unique mail address. Communication is asynchronous. Message for an actor are buffer in a mail

queue.

2009/9/11

27

Three Behaviors in The Actor System Create

Create a new actor. Send

Send a message into other mail queue. Ready

Prepare process next message in mail queue.

2009/9/11

Two Types of Transformations in The Actor System The state of an individual actor

The topology of the system of actors

28

BA A B

A AB B

2009/9/11

29

Garbage Collection Algorithm for Actor Model Is-Black Push-Pull Table-Driven Dickman GCE

2009/9/11

Is-Black (Initialization)

30

B FA C ED

B FA C ED

2009/9/11

Is-Black (first)

31

B FA C ED

B FA C ED

2009/9/11

Is-Black (secand)

32

B FA C ED

B FA C ED

2009/9/11

Is-Black (third)

33

B FA C ED

B FA C ED

2009/9/11

34

A

CB D

H

FE

G

I

Push-Pull (Initialization)

2009/9/11

Puller

35

A

CB D

H

FE

G

I

2009/9/11

Pusher

36

A

CB D

H

FE

G

I

2009/9/11

Termination

37

A

CB D

H

FE

G

I

2009/9/11

38

Table-Driven

A

CB D

H

FE

G

I

2009/9/11

39

Table-Driven

A

CB D

H

FE

G

I

2009/9/11

40

Table-Drivenb R(b)

C A

D A

F A

F E

D G

a F(A)

A E

E A

A G

G A

2009/9/11

41

Outline First Part

Introduction of Java Introduction of Garbage Collection

Second Part Introduction of Actor Model

Third Part CVM’s Implementation

(Linux, Windows Mobile, Andes Platform, Windows)

2009/9/11

42

CDC Documents CDC Porting Guide (Ch6) CDC Build Guide CDC Runtime Guide CDC Dynamic Compiler

2009/9/11

43

Linux1. Install JDK 1.4.2.19 (or default JDK 1.7.0 in Fedora 8)

(set path “export PATH=$PATH:$HOME/j2sdk1.4.2_19/bin” )

2. Extract “phoneme_advanced-mr2-dev-src-b97-20_nov_2008.zip”

3. Input “cd phoneme_advanced_mr2/cdc/build/ linux-x86-generic”

4. Input “make”, after run “cvm”

Next, move to the Eclipse(Please refer to “cvm環境建置和指令 for linux.doc”)

2009/9/11

44

Windows Mobile1. Install JDK 1.4.2.19(set path “C:\j2sdk1.4.2_19\bin;”)2. Install Pocket PC 2003 SDK3. Install Embedded Visual C++ 44. Install Embedded Visual C++ 4.0 SP35. Install Cygwin (include gcc, g++, zip, flex, bison,

packages)6. Extract “phoneme_advanced-mr2-dev-src-win32-b34-

04_oct_2007.zip”7. Open “Cygwin”8. Input “cd phoneme_advanced_mr2/cdc/build/win32-x86-

ppc03”9. Input “make”

2009/9/11

45

Windows MobileConnect PDA1. Install ActiveSync 4.5 (synchronize between PC

and PDA)2. Install WindowsMobilePowerToys.msi (use

cmd.exe in the PDA)3. After, go to “C:\Program Files\Windows Mobile

Developer Power Toys\PPC_Command_Shell\arm”

4. Copy all files to the PDA’s “windows” folder

2009/9/11

46

Windows MobileRun an example of “cvm”1. After compiler successfully, copy “win32-x86-ppc03”

folder to your root of “SD Card”2. Open “notepad”3. Input 255#“\SD Card\win32-x86-ppc03\bin\cvm.exe”

–cp “\SD Card\win32-x86-ppc03\testclasses.zip” HelloWorld

4. Save the file, and set file name “EX_helloworld.lnk”5. Go to SD card folder of PDA, after run

“EX_helloworld.lnk”6. Wait for a long time, and then show “HelloWorld.”

2009/9/11

47

Andes Platform1. Install JDK 1.4.2.19 (set path “C:\j2sdk1.4.2_19\

bin;”)2. Install andesight-1_3_1-windows

(complete installation and include Cygwin)3. Extract “pmea-mr2-b114-nds32-20090602.zip”

to “C:\”, and then produce the folder “pmea”4. Open “Cygwin”5. Input “export

PATH=$PATH:/cygdrive/c/Andestech/AndeSight/toolchains/nds32-elf-n1213-s-full/bin”

2009/9/11

48

Andes Platform (con.)6. Input “nds32-elf-gcc”, and then show “nds32-elf-

gcc: no input files”7. Input “mkdir /pmea”8. Input “mount c:/pmea /pmea”9. Input “cd pmea/cdc/build/linux-nds32-xc5”10. Input “make”

Next, upload and test PMEA to the Andes platform. (Please refer to “教育改進計畫課程實驗模組 -Java Virtual Machine-2009-06-02.doc”)

2009/9/11

49

Windows1. Install JDK 1.4.2.19 (set path “C:\j2sdk1.4.2_19\bin;”)2. Install Microsoft Platform SDK for Windows Server 2003 R2

(install location “C:\Program Files\Microsoft Platform SDK”)3. Install Visual C++ 2005 express(vc8)

(install location “C:\Program Files\Microsoft Visual Studio 8”)4. Install Cygwin(include gcc, g++, zip, flex, bison, packages)5. Extract “phoneme_advanced-mr2-dev-src-win32-b34-

04_oct_2007.zip”6. Open “Cygwin”7. Input “cd phoneme_advanced_mr2/cdc/build/win32-x86-

vc8”8. Input “make”, after run “cvm”

2009/9/11

50

How to run ? Run

bin/cvm –cp testclasses.zip HelloWorld Change G.C.

make CVM_GCCHOICE=semispace/generational/marksweep

View CVM’s options bin/cvm -XshowBuildOptions

Build Java program Javac -target 1.4 -source 1.4 -bootclasspath /home/test-

cdc/btclasses.zip MyApp.java

(More information, refer to “cvm環境建置和指令 for linux.doc”)2009/9/11

51

Reference Books

深入嵌入式 Java虛擬機器 Inside KVM Java虛擬機深入解析 SCJP 6.0/5.0猛虎出閘

Document CDC Porting Guide

2009/9/11

52

Reference Official Website of PhoneME

https://phoneme.dev.java.net/ phoneME for Windows Mobile

http://www.cs.kuleuven.be/~davy/phoneme/ Richard Jones

http://www.ssw.uni-linz.ac.at/Teaching/Lectures/Sem/2005/

ActorFoundry http://osl.cs.uiuc.edu/research?

action=topic&topic=Actor+Systems2009/9/11

53

Reference Keywords

J2ME, CDC/CLDC, CVM/KVM, Java Virtual Machine, Garbage Collection, Memory Management, Mark-Sweep, Semi-Space, Reference Counting, Generational, Actor Model, Active Objects, Push-Pull, Is-Black

2009/9/11

top related