在具体探索squawk build系统的使用方法之前,先研究一下squawk根目录下d和dd这两个总脚本。
通过d/dd脚本(dd为debug模式),我们可以:
* rebuild build system 通过上次提到的builder/bld.sh实现
* rebuild java native access code 通过上次提到的builder/nbld.sh实现
* rebuild CSystem SquawkVM绝大部分是用java写的,有一小部分是C写的,叫CSystem
* run cldc/imp tck 注意TCK为商业软件,需另外取得
* launch squawk with debug agent,大概是用于spotlet application开发,单步,断点之类
* ...
* 调用build.jar编译squawk源代码 (这是默认功能)
上次说到builder目录生成两个文件:build.jar,build-commands.jar,前者是后者的简单封装。
除了使用d/dd之外,我们也可以手动执行build.jar进行编译,看一下:
(蓝色是控制台输入,黑色是输出,灰色是我的注释)
$ java -jar build.jar --help
java -jar build.jar [ build-options] [ target | command [ command_options ] ]
where build-options include:
不重要,略去,有些指定javac,gcc编译器的参数之类的选项...
The supported targets are: 所谓target就是重要一些的command
cldc compiles the Java sources in ./cldc/src, ./cldc/phoneme, ./cldc/retroweaver and ./cldc/native
这是VM的Java实现部分,不包含C代码
cldc-native-declarations compiles the Java sources in ./cldc-native-declarations/src
这个目录下的代码用java抽象类或者接口加annotation用来表示一个C语言头文件,
例如:@Includes("")
这个技术叫Java Native Access,是比KNI,JNI更新的技术,或者说替代技术。
其CLDC版本实现在com.sun.cldc.jna.*包中,其它详见:https://jna.dev.java.net/
debugger compiles the Java sources in ./debugger/src
debugger-proxy compiles the Java sources in ./debugger-proxy/src
因为debugger和vm不可能同时跑在目标板上,嵌入式jvm都需要remote debug,一般情况下还不如system.out好用
hosted-support compiles the Java sources in ./hosted-support/src
j2se vm和squawk互连工具。在pc环境中运行squawk的时候,其i/o功能是通过启动一个j2se embedded vm实例,并将i/o任务转交给j2se模拟实现的。似乎是这样。
imp compiles the Java sources in ./imp/src and ./imp/phoneme
imp是没有GUI的midp
javatest-device compiles the Java sources in ./javatest-device/src
跑在device上的一个程序,它一个一个地下载TCK测试例,运行,返回测试结果,删除,再下载...如此反复
mapper compiles the Java sources in ./mapper/src
squawk的图形化分析工具,包含heap dump,profile分析,trace工具等,在j2se环境下使用
romizer compiles the Java sources in ./romizer/src
romizer静态地对于需要romize的classes调用translator工具,然后将host VM的内存状态保存为image映像(也称suite),
ssl compiles the Java sources in ./ssl/src
ssl相关
translator compiles the Java sources in ./translator/src
translator将class/jar文件转换成suite(一种可以被烧写到device flash中,并且被加载成read-only memory的映像)
target设备中一般不存放class/jar,因为classloading,unzip是很费时间和资源的
vm2c compiles the Java sources in ./vm2c/src
有些.java文件里用了一个叫@vm2c的annotation,大概是把一些java method转换成c的实现,用于加速,需进一步调查。
The supported commands are: 除了target都叫command,没有本质区别
JNAGen Imports C code into Java
Mnemonics generates the file translator/src/com/sun/squawk/vm/Mnemonics.java
OPC generates the file cldc/src/com/sun/squawk/vm/OPC.java
OperandStackEffect generates the file translator/src/com/sun/squawk/vm/OperandStackEffect.java
SwitchDotC generates the file vmcore/src/vm/switch.c.spp
Verifier generates the file translator/src/com/sun/squawk/translator/ir/verifier/Verifier.java
arm_asm_tests << no description available >>
cldc-native-declarations-gen Imports C code into Java
clean cleans one or more targets (all targets if no argument is given)
这个我喜欢,整个世界清静了
comp_test << no description available >>
copyjavacard3 copies the source code from the javacard3 source tree into ours in order to be able to compile it to run on Squawk
copyphoneme copies the source code from the phoneME source tree into ours in order to be able to compile cldc and imp
documentor builds Squawk document library including API javadoc
export exports the Squawk CVS controlled distribution to a jar file
gctf filter that converts method addresses in a garbage collector trace to signatures
genspec generates the Squawk bytecode specification in doc/spec
hexdump hex file dump
ht2html converts a heap trace to a set of HTML files
jam << no description available >>
jvmenv displays required environment variables for running the Squawk VM
makeapi creates source, classes and HTML describing API of a suite
makeplatformstubs << no description available >>
map suite file symbolic mapper/disassembler
omfconv object memory file endianess converter
profileviewer the Squawk VM execution profile GUI viewer
rom processes a collection of modules to produce the bootstrap suite and Squawk VM executable
romize processes a number of classes to produce a .suite file
这两个重要,生成device squawk vm
runvm2c runs the VM Java source file to C converter
sdproxy Debugger proxy for translating between Squawk VM and normal JDPA debuggers
spp preprocesses one or more *.spp files
squawk/vmcore/src/vm是vm的native实现代码,squawk.c.spp是main入口,具体情况,再单独开一篇日记。
还有数个C文件包含了类似#if的特殊预处理记号/*if[ABC]*/,这种文件以*.c.spp作为扩展名。
其作用,我猜测是这样:一般用makefile编译环境,compile time的变量配置很简单,类似这样:make DEBUG=true ABC=false ...
但由于Squawk不使用makefile系统,它无法方面地把make过程中的环境变量代换成C编译器可接受的预处理宏,才发明了这个蹩脚的方案,做预处理的动作。
squawk use Java based launcher to start Squawk VM
squawk.jar (re)builds squawk.jar (the classes required by the embedded JVM in Squawk)
这个两就是host-support相关
systemproperties shows the default system properties
打印host pc的环境变量
traceviewer the Squawk VM execution trace GUI viewer
启动traceviewer工具
uei Builds the Unified Emulator Interface(UEI) module
似乎有个squawk模拟器
user-clean clean a user-project
user-compile compile a user-project
user-run run a user-project
user-suite link a user-project
最后4个是开发用户应用程序时用的
看一个典型编译过程:
$ java -jar build.jar
[running copyphoneme...] 借用了一些phoneme的代码
[building cldc-native-declarations...] 编译JNA模块
[running cldc-native-declarations-gen...]
Skipping generation JNA files in ./cldc-native-declarations
[building cldc...] 编译cldc的java部分
[building debugger...]
[building translator...] 编译tranlator工具
[building hosted-support...] 编译j2se squawk互连工具
[running squawk.jar...] squawk.jar实际上是host-support,即j2se squawk互连工具,为什么要run?不清楚
[building debugger-proxy...]
[building imp...]
[building javatest-device...]
[building mapper...]
[building romizer...] 编译romizer工具
[building ssl...]
[building vm2c...]
到这里,各种工具都编译好了。下面是使用这些工具生成squawk
$ java -jar build.jar rom translator
[running rom...]
[running romize...]
Loaded suite stripping settings from squawk.library.properties
Loaded class excludes list from squawk.exclude
[translating suite squawk [closed: false, parent: null] ...] 转换成suite
[Including resource: META-INF/MANIFEST.MF]
Romizer processed 516 classes and generated 6 files.
[preprocessing with forced JAVA5SYNTAX for vm2c]
[running runvm2c...] 处理java5 annotation风格的@vm2c的源代码
[compiling floating point sources in vmcore/src/vm/fp ...] 编译fp的c实现
[compiling native verification sources in vmcore/src/vm/util ...] 编译sha.c
[compiling 'vmcore/src/vm/squawk.c' ...] 编译squawk的native部分
[linking 'squawk' ...] 连接成可执行程序
[running squawk.jar...] squawk.jar实际上是host-support,即j2se squawk互连工具,为什么要run?不清楚
下篇日记我会从squawk的main函数开始,简单分析一下squawk的启动过程
阅读(1126) | 评论(0) | 转发(0) |