diff -aruN shujit-0.2.2/ChangeLog shujit/ChangeLog --- shujit-0.2.2/ChangeLog Sat Oct 3 19:09:06 1998 +++ shujit/ChangeLog Sat Oct 10 19:38:50 1998 @@ -1,15 +1,37 @@ $Id$ +[19981010] + +32bit 整数の除算 (idiv 命令) で、state 4 に限り、 +披除数を 64bit に符号拡張 (x86 の CDQ 命令) するのを忘れていた。修整。 +Swing の JTextArea, JTextField で文字が描画されないバグの遠因となっていた。 +(code.c) + +32bit 整数の除算 (idiv 命令) で、披除数を 64bit に符号拡張する前に +EDX レジスタを無駄に 0 クリアしていたのを省いた。 +(code.c) + +[19981005] + +Linux では、libc の種類によって +マクロ RESOLVE_SYMBOL_ON_CODE を変えるようにした。 +(compiler.h) + +[19981004] + +compiledCode() -> assembledCode() と関数名を変えた。 +(code.c, compile.c, compiler.[hc], gentable.rb) + [19981003] -dlopen(..., RTLD_LAZY) で得た関数の本当のアドレスを、 +dlopen(..., RTLD_LAZY) でロードしたライブラリ中の関数のアドレスを、 その関数を実行する前に得られるか (Linux libc5)、得られないか (FreeBSD) に 依存しないコードとした。変数 `sym_関数名' の導入。 (compiler.c, compiler.h, compile.c) libc5 の環境では dlopen(), dlsym() でアドレスを得た関数のコードを 書き換えられるので、あらかじめ関数のアドレスを解決、書き込んでいたが、 -書き換え可能を仮定するのを止めた。 +コードが書き換え可能であることを仮定するのを止めた。 マクロ RESOLVE_SYMBOL_ON_CODE を #undef。 glibc2 対応の一環でもある。 (compiler.h) @@ -20,6 +42,7 @@ 呼び出されたメソッドがコンパイルされる際、コンパイル中に 起こる別のメソッド呼び出しによって引数が破壊されることがある問題に対処。 +AWT で左端の MenuBar の文字が表示されないバグの遠因となっていた。 (invoker.c) [19980928] @@ -135,10 +158,10 @@ (code.c, compile.c) iinc 命令に対する native コードを、 - mov 増分,register - add register,変数 + MOV 増分,register + ADD register,変数 から - add 増分,変数 + ADD 増分,変数 に変更。 (code.c, compile.c) @@ -157,7 +180,7 @@ (opcodes.pl) クロック数の計測に備えて x86tsc.o をリンクするようにした。 -x86 の rdtsc 命令を使う。 +x86 の RDTSC 命令を使う。 (Makefile) ldiv, lrem, instanceof 命令のコードを多少高速化。 @@ -204,7 +227,7 @@ [19980711] -compiled code を C で記述した第 1版が +pre-assembled code を C で記述した第 1版が あまりに遅い (インタプリタより ;_;) ので、アセンブラを使って書き直し開始。 [19980710] diff -aruN shujit-0.2.2/README shujit/README --- shujit-0.2.2/README Sat Oct 3 19:31:54 1998 +++ shujit/README Sat Oct 10 19:41:10 1998 @@ -1,5 +1,5 @@ shuJIT: JIT compiler for Sun JVM/x86 - http://www.shudo.net/shujit/ + http://www.shudo.net/jit/ SHUDO Kazuyuki * What this is @@ -59,8 +59,7 @@ * Bugs and Problems -Any comments and bug reports are welcome. -Please write to shudoh@muraoka.info.waseda.ac.jp. +Any comments and bug reports are welcome. Please write to me. * Copying @@ -74,7 +73,8 @@ Thanks all folks around me and the following people: OHARA Takuzo (compilation of GNU binutils) -TANAKA Keishiro (testing on FreeBSD) +TANAKA Keishiro (test on FreeBSD) +MIURA Toshitaka (preparation of FreeBSD) and my wife Mari. diff -aruN shujit-0.2.2/benchmark shujit/benchmark --- shujit-0.2.2/benchmark Sat Oct 3 12:10:39 1998 +++ shujit/benchmark Sun Oct 4 13:02:41 1998 @@ -14,9 +14,9 @@ E2 1MB 暗号化 plain TYA shuJIT -128 789 306 350(285) msec -192 791 307 343(280) msec -256 791 300 345(281) msec +128 789 318 370(291) msec +192 791 310 362(280) msec +256 791 311 367(289) msec ()内は NO_CHECK 版 CaffeineMark 3.0 diff -aruN shujit-0.2.2/code.c shujit/code.c --- shujit-0.2.2/code.c Sat Sep 26 15:30:25 1998 +++ shujit/code.c Sat Oct 10 19:32:51 1998 @@ -15,7 +15,7 @@ #include "code.h" -volatile void compiledCode( +volatile void assembledCode( JHandle *o, struct methodblock *mb, int args_size, ExecEnv *ee #ifdef RUNTIME_DEBUG , int runtime_debug @@ -1446,7 +1446,6 @@ INT_TEST(VOP, 1, %edx);\ __asm__("popl %eax\n\t"\ "movl %edx,%ecx\n\t"\ - "xorl %edx,%edx\n\t"\ "cdq\n\t"\ "idivl %ecx\n\t"\ "movl " #RESULT_REG ",%ecx");\ @@ -1454,7 +1453,6 @@ CODE(opc_i##VOP, i##VOP, ST2, ST3) {\ INT_TEST(VOP, 2, %ecx);\ __asm__("movl %edx,%eax\n\t"\ - "xorl %edx,%edx\n\t"\ "cdq\n\t"\ "idivl %ecx\n\t"\ "movl " #RESULT_REG ",%ecx");\ @@ -1462,7 +1460,6 @@ CODE(opc_i##VOP, i##VOP, ST3, ST3) {\ INT_TEST(VOP, 3, %ecx);\ __asm__("popl %eax\n\t"\ - "xorl %edx,%edx\n\t"\ "cdq\n\t"\ "idivl %ecx\n\t" /* %eax ... %edx = %edx:%eax / %ecx */\ "movl " #RESULT_REG ",%ecx");\ @@ -1471,7 +1468,7 @@ INT_TEST(VOP, 4, %edx);\ __asm__("movl %ecx,%eax\n\t"\ "movl %edx,%ecx\n\t"\ - "xorl %edx,%edx\n\t"\ + "cdq\n\t"\ "idivl %ecx\n\t"\ "movl " #RESULT_REG ",%ecx");\ } diff -aruN shujit-0.2.2/compile.c shujit/compile.c --- shujit-0.2.2/compile.c Sat Oct 3 10:57:20 1998 +++ shujit/compile.c Sun Oct 4 12:30:38 1998 @@ -721,7 +721,7 @@ writeToBuffer(cc, - (unsigned char *)compiledCode + codep->offset, codep->length); + (unsigned char *)assembledCode + codep->offset, codep->length); pctable->nativeoff = nativeoff; bufp = lastBufend(cc); @@ -812,8 +812,9 @@ opc_stateto0 + tgtstate, laststate, pctable->byteoff, nativeoff); i++; - writeToBuffer(cc, (unsigned char *)compiledCode + transcodep->offset, - transcodep->length); + writeToBuffer(cc, + (unsigned char *)assembledCode + transcodep->offset, + transcodep->length); nativeoff += transcodep->length; /* jmp X(4byte) */ { @@ -832,7 +833,7 @@ opc_stateto0 + tgtstate, laststate, pctable->byteoff, nativeoff); i++; - writeToBuffer(cc, (unsigned char *)compiledCode + transcodep->offset, + writeToBuffer(cc, (unsigned char *)assembledCode + transcodep->offset, transcodep->length); nativeoff += transcodep->length; @@ -1468,7 +1469,7 @@ tgttable = pctableGet(cc, byteoff + defoff); tblp[0] = tgttable->nativeoff; codep = &code_table[opc_goto_st0 + tgttable->state][after_state]; - tblp[1] = (int32_t)(((unsigned char *)compiledCode) + codep->offset); + tblp[1] = (int32_t)(((unsigned char *)assembledCode) + codep->offset); #ifdef COMPILE_DEBUG { unsigned int boff = byteoff + defoff; @@ -1485,7 +1486,8 @@ tgttable = pctableGet(cc, byteoff + off); tblp[0] = tgttable->nativeoff; codep = &code_table[opc_goto_st0 + tgttable->state][after_state]; - tblp[1] = (int32_t)(((unsigned char *)compiledCode) + codep->offset); + tblp[1] = + (int32_t)(((unsigned char *)assembledCode) + codep->offset); #ifdef COMPILE_DEBUG { unsigned int boff = byteoff + off; @@ -1541,7 +1543,8 @@ tgttable = pctableGet(cc, byteoff + off); tblp[1] = tgttable->nativeoff; codep = &code_table[opc_goto_st0 + tgttable->state][after_state]; - tblp[2] = (int32_t)(((unsigned char *)compiledCode) + codep->offset); + tblp[2] = + (int32_t)(((unsigned char *)assembledCode) + codep->offset); #ifdef COMPILE_DEBUG { unsigned int boff = byteoff + off; @@ -1559,7 +1562,7 @@ tblp[0] = 0; tblp[1] = tgttable->nativeoff; codep = &code_table[opc_goto_st0 + tgttable->state][after_state]; - tblp[2] = (int32_t)(((unsigned char *)compiledCode) + codep->offset); + tblp[2] = (int32_t)(((unsigned char *)assembledCode) + codep->offset); #ifdef COMPILE_DEBUG { unsigned int boff = byteoff + defoff; @@ -1606,7 +1609,7 @@ fflush(stdout); #endif argptr = - ((unsigned char *)compiledCode) + codep->offset + funcp->offset; + ((unsigned char *)assembledCode) + codep->offset + funcp->offset; if (!((opc_goto_st0 <= opcode) && (opcode < opc_goto_st0 + NSTATES))) { /* native code for the opcodes is never copied and is executed at original place */ diff -aruN shujit-0.2.2/compiler.c shujit/compiler.c --- shujit-0.2.2/compiler.c Sat Oct 3 11:25:54 1998 +++ shujit/compiler.c Sat Oct 10 19:08:17 1998 @@ -122,7 +122,7 @@ #ifdef __FreeBSD__ /* to get addresses of functions in lib[cm] with sysDynamicLink() */ - /* libc for __divdi3, moddi3, printf, fflush */ + /* libc for __divdi3, __moddi3, printf, fflush */ if (!sysAddDLSegment("/usr/lib/libc.so.3.1")) { if (!sysAddDLSegment("/usr/lib/libc.so.3.0")) { printf("fatal: JIT compiler can't find libc.so.3.1 or 3.0.\n" @@ -158,7 +158,7 @@ #endif #ifdef RESOLVE_SYMBOL_ON_CODE - /* resolve function symbols in pre-assembled code (compiledCode()) */ + /* resolve function symbols in pre-assembled code (assembledCode()) */ initFunctionSymbols(); #endif diff -aruN shujit-0.2.2/compiler.h shujit/compiler.h --- shujit-0.2.2/compiler.h Sat Oct 3 18:53:26 1998 +++ shujit/compiler.h Mon Oct 5 11:50:26 1998 @@ -79,13 +79,19 @@ /* * OS dependent macro definition */ -# undef RESOLVE_SYMBOL_ON_CODE #if defined (linux) # define EXECUTEJAVA_IN_ASM +# if defined __GLIBC__ && __GLIBC__ >= 2 +# undef RESOLVE_SYMBOL_ON_CODE +# else +# define RESOLVE_SYMBOL_ON_CODE +# endif #elif defined (__FreeBSD__) # undef EXECUTEJAVA_IN_ASM +# undef RESOLVE_SYMBOL_ON_CODE #else # undef EXECUTEJAVA_IN_ASM +# undef RESOLVE_SYMBOL_ON_CODE #endif @@ -198,7 +204,7 @@ * Global Functions */ /* in code.c */ -extern volatile void compiledCode( +extern volatile void assembledCode( JHandle *o, struct methodblock *mb, int args_size, ExecEnv *ee #ifdef RUNTIME_DEBUG ,int runtime_debug diff -aruN shujit-0.2.2/gentable.rb shujit/gentable.rb --- shujit-0.2.2/gentable.rb Sat Sep 26 15:36:21 1998 +++ shujit/gentable.rb Sun Oct 4 12:32:50 1998 @@ -62,13 +62,13 @@ break if /^Disassembly/ end -# search beginning of the function compiledCode() +# search beginning of the function assembledCode() start_addr = -1 while gets() chomp!() elems = split() - if elems[1] =~ /compiledCode>:/ + if elems[1] =~ /assembledCode>:/ gets() elems = split() $_ = elems[0] diff -aruN shujit-0.2.2/invoker.c shujit/invoker.c --- shujit-0.2.2/invoker.c Thu Oct 1 20:45:16 1998 +++ shujit/invoker.c Sat Oct 10 19:39:09 1998 @@ -31,8 +31,12 @@ monitorEnter(key); /* compile the called method */ +#if 0 /* this check is not needed. */ if (!(mb->CompiledCode) && !(mb->fb.access & (ACC_ABSTRACT | ACC_NATIVE))) { +#else + { +#endif #ifdef COMPILE_DEBUG printf(" now compiling.\n"); fflush(stdout); #endif @@ -40,8 +44,12 @@ ee->current_frame->optop += args_size; /* to save real args */ /* not to be broken args by method invocation during compilation */ - if (compileMethod(mb)) { - /* fail to compile.. */ + if (!compileMethod(mb)) { + /* success */ + ee->current_frame->optop -= args_size; /* restore real optop */ + } + else { + /* fail to compile... */ ee->current_frame->optop -= args_size; /* restore real optop */ #ifdef COMPILE_DEBUG printf(" compilation failed...\n"); fflush(stdout); @@ -50,7 +58,6 @@ access2invoker(mb->fb.access); goto candi_method_done; } - ee->current_frame->optop -= args_size; /* restore real optop */ } candi_method_done: @@ -89,15 +96,15 @@ # if 1 runtime_debug = 1; # else - if ((!strcmp(cbName(mb->fb.clazz), "sun/io/CharToByteISO8859_1")) + if ((!strcmp(cbName(mb->fb.clazz), "com/sun/java/swing/text/PlainView")) + && (!strcmp(mb->fb.name, "paint"))) + runtime_debug = 1; + else if ((!strcmp(cbName(mb->fb.clazz), "sun/io/CharToByteISO8859_1")) && (!strcmp(mb->fb.name, "convert"))) runtime_debug = 1; else if ((!strcmp(cbName(mb->fb.clazz), "java/lang/FloatingDecimal")) && (!strcmp(mb->fb.name, "toJavaFormatString"))) runtime_debug = 1; - else if ((!strcmp(cbName(mb->fb.clazz), "E2.E2_Algorithm")) - && (!strcmp(mb->fb.name, "blockEncrypt"))) - runtime_debug = 1; else runtime_debug = 0; # endif @@ -134,15 +141,14 @@ /* restack from JVM stack to native stack */ { - struct methodblock *prev_method; - - prev_method = old_frame->current_method; - if (!prev_method) goto restack; - if (prev_method->fb.access & ACC_MACHINE_COMPILED) { - /* is expected to be equal to if (prev_method->CompiledCode) */ - /* called by compiled method */ - frame->vars = (stack_item *)old_frame->returnpc; - goto restack_done; + struct methodblock *prev_method = old_frame->current_method; + if (prev_method) { + if (prev_method->fb.access & ACC_MACHINE_COMPILED) { + /* is expected to be equal to if (prev_method->CompiledCode) */ + /* called by compiled method */ + frame->vars = (stack_item *)old_frame->returnpc; + goto restack_done; + } } /* called by normal Java or native method */ diff -aruN shujit-0.2.2/memo shujit/memo --- shujit-0.2.2/memo Sat Oct 3 18:53:57 1998 +++ shujit/memo Sun Oct 4 13:06:12 1998 @@ -1,7 +1,10 @@ 最適化 - - VolanoMark を試す。 + - スタック上の要素の性質 (例: 配列のサイズ) を trace し、 + 省ける各種チェック (例: 添字の範囲) を省く。仮想スタックライブラリを用意。 - stack 上の倍精度浮動小数点数を 8バイト境界に align する。 + - VolanoMark を試す。 - CM3 に対する compiled code を見る。 + - クロック数を計測。 - invoke{,Synchronized}JavaMethod() の呼び出し回数を減らす。 JavaFrame を C のスタック上に確保する。 障害: @@ -11,7 +14,6 @@ - JavaFrame の作成を省く。 - Object# の呼び出しを削除する。 invokeignored_quick への recode 条件を調べる。 - - クロック数を計測。 - bytecode の静的最適化。 invokeignored_quick への変換。 [ifa]store{,_N}, [ifa]load{,_N} で、メモリからの読みだしを省く。