【原创】Modularize Romized Native Code Table Generated By JCC Tool

Modularize Romized Native Code Table Generated By JCC Tool

 

Ming He (Simon)


 
Abstract

 

Java Code Compact tool (abbr. JCC, also known as ROMizer) is one of the most important tools of integrating Java features into J2ME KVM. JCC tool converts the Java class files to native code (C or C++) by producing a native code table (usually named as ROMJava.c), then compiles and links the table with the KVM. In this way, the KVM can run at full speed on a certain platform, and its start - up time can get reduced considerably.

Conventionally, JCC tool converts all the involved Java class files into a single native code table—ROMJava.c, thus a “huge” table will be produced and get compiled to a single object rather than multiple objects. Moreover, all the class files of the Java features built with the KVM will be loaded into the memory together, even those features that will not be used during once execution.

This paper analyses the working mechanism of JCC tool, explains some difficult points during JCC tool converts Java class files to native code. Finally a solution is introduced about converting the class files of designated Java features to multiple native code tables, and then compiling them to multiple independent objects. In this way, all the built Java features will produce several native objects, each one in moderate size. And the KVM can load needed objects dynamically, and allocate memory for a certain Java feature only when it is used. That is to say, the native code table generated by JCC tool, which is mapping to some certain Java features (including JSR or OEM features), can be modularized and the footprint of KVM execution can be customized according to practical requirements.

 

Keywords:     JCC ROMize  KVM     J2ME

 


1               Introduction

Java Code Compact tool--abbr. JCC, also known as ROMizer--is one of the most significant tools of integrating Java features into J2ME KVM. JCC tool converts the Java class files to native code (C or C++) by producing a native code table (usually named as ROMJava.c), then compiles and links the table with the KVM. In this way, the KVM can run at full speed on a certain platform, and its start-up time can get reduced considerably.

Conventionally, JCC tool converts all the involved Java class files into a single native code table—ROMJava.c, thus a “huge” table will be produced and get compiled to a single object rather than multiple objects. Moreover, all the class files of the Java features built with the KVM will be loaded into the memory together, even those features that will not be used during once execution.

This paper attempts to improve the working mechanism of JCC tool and find a solution about modularizing the ROMized native code table generated by JCC tool. In this way, all the Java features, which are built with the KVM, will produce several native objects, each one in moderate size. And the KVM can load needed objects dynamically, and allocate memory for a certain Java feature only when it is used.

2               General Description of JCC tool

In JCC tool, the class com.mot.tools.j2me.jcc.JavaCodeCompact is the main class and entry point of the ROMizing process.

The invoker instantiates a JavaCodeCompact object and passes some parameters to it (including ClassPath, classes’ names to be ROMized and the output name of ROMized native code table). And then the JavaCodeCompact object will read byte-codes from those class files, analyze fields, methods and constants of each class, and references across each other. Finally, the JavaCodeCompact object will create a class writer and drive it to output all the required information to the native code table. Refer to Figure-1 for the flow chart of JCC tool.

2.1         Flow Chart

 

Figure-1 Flow chart of JCC tool


3.1         General Idea of Modularizing

In general, modularizing the ROMized native code table will follow the ROMizing process of original JCC tool, that is will follow the flow chart of Figure-1 . While the key point is to add a special flag for the interested class (class that we want to ROMize to an independent native code table) and its related fields, methods, interfaces and other types of class components. Then when outputting the native code table, only those class components with set flag will be output actually.

Thus, the ROMized native code table—ROMJava.c and the built object will be in moderate size, much smaller than the huge one generated by the original JCC tool. Also, the smaller native code table will consume less memory at runtime.

3.2         Read Required Class Files

As shown in Figure-1 , all read classes need to be resolved for its fields, methods, interfaces and other types of class components, and references between each other. So only reading the content of interested classes into the memory is not enough. Other classes relating to the interested classes, especially the super class and some basic classes such as java/lang/Object and java/lang/Class , are also required to be read into the memory for the resolving process.

A convenient and safe method of reading required class files is to read the classes that belong to CLDC and MIDP [1] , and the super classes of the interested classes. In this way, although the ClassInfo (see Figure - 1 ) vector’s size maybe not decrease, it would not lead all these classes to be output to the ROMized native code table.

3.3         Add Flag for Interested Classes

Adding specific flags to the interested classes is the key step in the process of modularizing the ROMized native code table. ClassInfo objects of interested classes and their super classes, and all of their class components (including fields, methods, attributes and etc.) need to be picked up and marked as interested.  Specially, class java/lang/Object is the root class of any class, so its ClassInfo object and all its class components also need to be marked as interested.

Figure - 2 shows the methods in which adding flag for the interested classes.

 

 

 

 

Figure - 2 Methods of Adding Flag for Interested Classes

3.4           Output Classes with Flag to ROMized Native Code Table

Just like the original JCC tool does, the native code table is constituted in memory now, with interested classes marked. When the table is output to ROMJava.c, only those elements with flag in the table will be output actually, and the others will be discarded.

Figure - 3 shows the methods in which the interested classes with flag and their class components are output to the ROMized native code table.

 

 

Figure - 3 Methods of Outputting Interested Classes with Flag Set

4               Conclusion

Using the solution introduced in Setion-3 , only the class files of designated Java feature will get ROMized to the native code table, and then get built to an independent object. Thus all the Java features, which are built with the KVM, can produce several native objects, each one in moderate size. And the KVM can load needed objects dynamically, and allocate memory for a certain Java feature only when it is used.

That is to say, the modularization of ROMized native code table is basically implemented via this solution.

 

-----------------------------------------------------------

Acknowledgements

N/A

References

Sun Microsystems Inc. 1999. Reference Implementation of “Java Code Compact” Tool. v1.52.

 

James Gosling, Bill Joy, Guy Steele and Gilad Bracha. 2000. The Java™ Language Specification, Second Edition. ADDISON-WESLEY .

 

探矽工作室 .  2003.  深入嵌入式 Java 虚拟机 .  中国铁道出版社 .

 



[1] CLDC: Connected Limited Device Configuration

MIDP: Mobile Information Device Profile

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值