Top Banner
JavaME Connected Device Configure Development Environment and Garbage Collector of Virtual Machine Speaker: Chu, Hua-Rong Advisor: Chung Yung
33

JavaME Connected Device Configure

Jan 02, 2016

Download

Documents

daphne-craig

JavaME Connected Device Configure. Development Environment and Garbage Collector of Virtual Machine. Speaker: Chu, Hua-Rong Advisor: Chung Yung. OUTLINE. CDC implementation overview Build Sun CDC1.0.1 in Ubuntu What happens during the build process Garbage Collector of Sun CVM. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: JavaME  Connected Device Configure

JavaME Connected Device Configure

Development Environment and Garbage Collector of Virtual Machine

Speaker: Chu, Hua-Rong Advisor: Chung Yung

Page 2: JavaME  Connected Device Configure

2

OUTLINE

• CDC implementation overview• Build Sun CDC1.0.1 in Ubuntu• What happens during the build process• Garbage Collector of Sun CVM

Page 3: JavaME  Connected Device Configure

3

IMPLEMENTATION OVERVIEWJavaME CDC

Page 4: JavaME  Connected Device Configure

4

CDC platform Survey

• IBM– WebSphere Everyplace Micro Environment– Support CDC1.1– Ref: 劉惠玲 , 嵌入式系統裝置走向跨平台的推手 - IBM J9, 2007 IBM developerWorks ( ~/cdc/CDC

doc/IBMJ9.ppt )

• Sun – Offical CDC– Mobile & Embedded Community: phoneME Advanced

Page 5: JavaME  Connected Device Configure

5

Sun CDC History

Personal Java (1999)

JavaME CDC1.0 (2001)

JavaME CDC1.1 (2005)

JavaSE for Embedded? (2007)

phoneME Advanced(2008)

Page 6: JavaME  Connected Device Configure

6

Sun CDC family

• JavaME CDC1.0 (based on JavaSE1.3)• JavaME CDC1.0.1 (based on JavaSE1.3.1)• JavaME CDC1.1 (based on JavaSE1.4)– ARM, PowerPC, MIPS, SPARC, x86 (interpreter

only)– Linux, Solaris, Darwin, Win32

• phoneME Advanced MR2 (2008)– ARM, x86– Linux, Windows Mobile, OpenWRT

Page 7: JavaME  Connected Device Configure

7

BUILD SUN CDC 1.0.1 JavaME CDC

Page 8: JavaME  Connected Device Configure

8

PartI: Source Code

• Source Code: – j2me_cdcfp-1_0_1-fcs-src-b12-linux-i686-

14_May_2002.zip– Download: http://jtrue.pl/files/GPS/

Page 9: JavaME  Connected Device Configure

9

PartII: Environment

• Redhat7.1 / Ubuntu 6.06• JDK1.3 / JDK1.4 • egcs6 / gcc3.3 and related C develop tool• ksh

Page 10: JavaME  Connected Device Configure

10

PartIII: Troubleshooting

• Problem: This Version's java code is based on JavaSE 1.3.1.

• Java Compile time error:

• JDK6 javac with option -source 1.4/1.3 is no use• Solution : downgrade to JDK1.4/1.3

../../src/share/classes/java/lang/SecurityManager.java:299: cannot find symbolsymbol : method initCause(java.lang.ClassNotFoundException)location: class java.lang.NoClassDefFoundError synchronized(SecurityManager.class) { ^

Page 11: JavaME  Connected Device Configure

11

PartIII: Troubleshooting

• Problem: GCC4 is restricted for nonstandard C code in this Version.

• C Compile time error:

complie time Error:Checking for test classes to compile ...... ../../build/linux-i686/obj/globals.o../../src/share/javavm/runtime/globals.c:121:1: 錯誤: 粘貼「 . 」和「 nullClassLoaderLock 」不能給出一個有效的預先處理識別字

Page 12: JavaME  Connected Device Configure

12

PartIII: Troubleshooting

• Solution : use GCC3.3(gcc -V3.3 if gcc4 is installed)

change line 117 of /cdcfoundation/src/share/javavm/runtime/globals.c from#define CVM_SYSMUTEX_ENTRY(mutex, name) {&CVMglobals.##mutex, name}#define CVM_SYSMUTEX_ENTRY(mutex, name) {&CVMglobals. mutex, name}

Page 13: JavaME  Connected Device Configure

13

PartIII: Troubleshooting

• Problem: glibc <2.2 is needed in this Version• Linking Time Error:

Linking ../../build/linux-i686/bin/cvm../../build/linux-i686/obj/UNIXProcess_md.o :在函式「 sigchld_handler 」中:../../src/linux/native/java/lang/UNIXProcess_md.c:213: 未定義參考到「__libc_wait 」collect2: ld 回傳 1make: *** [../../build/linux-i686/bin/cvm] Error 1

Page 14: JavaME  Connected Device Configure

14

PartIII: Troubleshooting

• Solution: patch ~/src/linux/native/java/lang/UNIXProcess_md.c

34,53c34< < /* following lines Hacked by Kent Hulick based on< * ftp://people.redhat.com/drepper/libcwait.c< * fixes a broken calls to a removed glibc function:*/< #include < #include < pid_t __libc_wait (int *status)< {< int res;< asm volatile ("pushl %%ebx\n\t"< "movl %2, %%ebx\n\t"< "movl %1, %%eax\n\t"< "int $0x80\n\t"< "popl %%ebx"< : "=a" (res)< : "i" (__NR_wait4), "0" (WAIT_ANY), "c" (status), "d" (0),< "S" (0));< return res;< }< --

Page 15: JavaME  Connected Device Configure

15

PartIV: Preperation&Configure

#sudo su#cd /usr/local/src#wget http://jtrue.pl/files/GPS/j2me_cdcfp-

1_0_1-fcs-src-b12-linux-i686-14_May_2002.zip#unzip j2me_cdcfp-1_0_1-fcs-src-b12-linux-i686-

14_May_2002.zip#unzip cdcfoundation-1_0_1-fcs-src.zip#cd cdcfoundation/build

Page 16: JavaME  Connected Device Configure

16

PartIV: Preperation&Configure

Edit Makefile ./linux/defs.mk :

./linux/defs.mk:#petertc1026

./linux/defs.mk-#CFLAGS_SPEED = -c $(CC_ARCH_FLAGS) $(CCFLAGS) $(CCFLAGS_SPEED) $(CPPFLAGS)

./linux/defs.mk-#CFLAGS_SPACE = -c $(CC_ARCH_FLAGS) $(CCFLAGS) $(CCFLAGS_SPACE) $(CPPFLAGS)

./linux/defs.mk-#SO_CFLAGS = -c $(SO_CC_ARCH_FLAGS) $(CCFLAGS) $(CPPFLAGS)

./linux/defs.mk-CFLAGS_SPEED = -V3.3 -c $(CC_ARCH_FLAGS) $(CCFLAGS) $(CCFLAGS_SPEED) $(CPPFLAGS)

./linux/defs.mk-CFLAGS_SPACE = -V3.3 -c $(CC_ARCH_FLAGS) $(CCFLAGS) $(CCFLAGS_SPACE) $(CPPFLAGS)

./linux/defs.mk-SO_CFLAGS = -V3.3 -c $(SO_CC_ARCH_FLAGS) $(CCFLAGS) $(CPPFLAGS)

Page 17: JavaME  Connected Device Configure

17

PartIV: Preperation&Configure

Edit Makefile ./share/defs.mk :

./share/defs.mk:#petertc1026

./share/defs.mk-#CVM_GNU_TOOLS_PATH=/micro/tools/i686-redhat-linux/gnu/bin

./share/defs.mk-CVM_GNU_TOOLS_PATH=/usr/bin

Page 18: JavaME  Connected Device Configure

18

PartIV: Preperation&Configure

Patch /usr/local/src/cdcfoundation/src/share/javavm/runtime/globals.c:117

//petertc1026/*#define CVM_SYSMUTEX_ENTRY(mutex, name) {&CVMglobals.##mutex, name}*/

#define CVM_SYSMUTEX_ENTRY(mutex, name) {&CVMglobals. mutex, name}

Page 19: JavaME  Connected Device Configure

19

PartIV: Preperation&Configure

Patch /usr/local/src/cdcfoundation/src/linux/native/java/lang/UNIXProcess_md.c:213

34,53c34< < /* following lines Hacked by Kent Hulick based on< * ftp://people.redhat.com/drepper/libcwait.c< * fixes a broken calls to a removed glibc function:*/< #include <errno.h>< #include <sys/syscall.h>< pid_t __libc_wait (int *status)< {< int res;< asm volatile ("pushl %%ebx\n\t"< "movl %2, %%ebx\n\t"< "movl %1, %%eax\n\t"< "int $0x80\n\t"< "popl %%ebx"< : "=a" (res)< : "i" (__NR_wait4), "0" (WAIT_ANY), "c" (status), "d" (0),< "S" (0));< return res;< }<

Page 20: JavaME  Connected Device Configure

20

PartV: Build

#cd linux-i686#make CVM_DEBUG=true

JAVABIN=/usr/java/j2sdk1.4.2_18/bin

Page 21: JavaME  Connected Device Configure

21

PartVI: Demo# bin/cvm -Djava.class.path=testclasses.zip HelloWorld

> GC[SS]: Initialized semi-space gen for generational GC> Size of *each* semispace in bytes=1048576> Limits of generation = [0xb7942200,0xb7b42200)> First semispace = [0xb7942200,0xb7a42200)> Second semispace = [0xb7a42200,0xb7b42200)> GC[MC]: Initialized mark-compact gen for generational GC> Size of the space in bytes=3145728> Limits of generation = [0xb7b42200,0xb7e42200)> GC[generational]: Auxiliary data structures> heapBaseMemoryArea=[0xb7942008,0xb7e42208)> cardTable=[0x8322f90,0x8325790)> objectHeaderTable=[0x8325798,0x8327f98)> summaryTable=[0x8327fa0,0x8331fa0)> Hello world.

Page 22: JavaME  Connected Device Configure

22

WHAT HAPPENS DURING THE BUILD PROCESS

JavaME CDC

Page 23: JavaME  Connected Device Configure

23

Step Utility Input Output

1 javac src/share/classes/*.java build/target_name/btclasses/*.class

2 JavaMemberDepend

build/target_name/btclasses/*.class

build/target_name/generated/javavm/runtime/tranlist.

3 zip build/target_name/generated/javavm/runtime/tranlist

build/target_name/btclasses.zip

4 javac src/share/javavm/test/*.java (Runtime classes CVM test files )

build/target_name/lib/cdc.jar build/target_name/lib/foundation.jar build/target_name/testclasses/*.class

5 zip build/target_name/testclasses/*.class

build/target_name/testclasses.zip

6 javah Runtime classes JNI header files in build/target_name/generated/jni/*.h

7 JavaCodeCompact

build/target_name/btclasses.zip JNI header files in build/target_name/generated/jni/*.hPreloaded class data structuresin build/target_name/generated/javavm/runtime/romjava*.c and romjava.h Additional C file interfaces.

Page 24: JavaME  Connected Device Configure

24

Step Utility Input Output

8 C compiler Native methods and CVMsource (.c) files

Object files in build/target_name/obj/*.o

9 C compiler Preloaded classes in build/target_name/generated/javavm/runtime/romjava*.c

Object files in build/target_name/obj/romjava*.o

A archive utility

Object files in build/target_name/obj/romjava*.o

Object archive file in build/target_name/obj/libromjava.a

B linker Object files in build/target_name/obj/*.o from step 8

Object archive file in build/target_name/obj/libromjava.a from step 10

Virtual machine binary* in build/target_name/bin.

In build/linux-i686/directory• bin/cvm: executable image• lib/cdc.jar: JAR archive, default boot class path• testclasses.zip: a collection of simple tests

Page 25: JavaME  Connected Device Configure

25

GARBAGE COLLECTORJavaME CDC

Page 26: JavaME  Connected Device Configure

26

Build Options

• -CVM_GCCHOICE (Generational/marksweep/semispace)

• default: generational • Example:– -CVM_GCCHOICE=semispace

Page 27: JavaME  Connected Device Configure

27

Runtime Options

• -Xgc:gc_specific_options(In generational is youngGen=nnn in bytes)

• Default: 1M

Page 28: JavaME  Connected Device Configure

28

Runtime Options

• -Xmssize (memory allocation pool)• Default: 4M• Example: – -Xms6291456– -Xms6144k– -Xms6m

Page 29: JavaME  Connected Device Configure

29

Source Organization

• src/share/javavm/include/gc_common.h The shared GC interface.

• src/share/javavm/include/gc/gc_impl.hThe gcimpl GC interface that has to be implemented for each GC.

• src/share/javavm/include/gc/<gcname>/gc_config.h The configuration file for a specific GC.

• src/share/javavm/runtime/gc/<gcname>/gc_impl.c The implementation file for a specific GC.

Page 30: JavaME  Connected Device Configure

30

Execution Flow1. CVM allocates memory using the shared routine CVMgcAllocNewInstance().

2. CVMgcAllocNewInstance() does some processing and calls the GC-specific CVMgcimplAllocObject() to allocate the actual space for the object.

3. CVMgcimplAllocObject() performs the GC and calls the shared routine CVMgcStopTheWorldAndGC() to stop all threads at GC-safe points.

4. CVMgcStopTheWorldAndGC() ensures that all threads rendezvous at GC-safe points. When that is done, it calls the GC implementation CVMgcimplDoGC() to perform the GC action.

5. CVMgcimplDoGC() may call shared GC service routines to scan GC state: For example, CVMgcScanRoots() to scan all roots or CVMobjectWalkRefs() to scan the pointers in a given object or array.

6. When CVMgcimplDoGC() returns, all threads that were stopped at GC points resume execution. Eventually, CVMgcAllocNewInstance() returns and the thread that originally initiated GC resumes execution.

Page 31: JavaME  Connected Device Configure

31

REFERENCEJavaME CDC

Page 32: JavaME  Connected Device Configure

32

CDCFOUNDATION_PORTING_GUIDE.PDF

Page 33: JavaME  Connected Device Configure

33

<!--EOF->JavaME CDC