diff -aruN shujit-0.3.8/ChangeLog shujit/ChangeLog --- shujit-0.3.8/ChangeLog Sat Aug 28 18:35:57 1999 +++ shujit/ChangeLog Thu Sep 9 13:58:06 1999 @@ -1,5 +1,70 @@ $Id$ +[19990909] + +0.3.9 リリース。 + +[19990908] + +構造体 sigcontext の取得方法を変更。 +単純に最初の 2回は探索するのを止め、オフセットが有効かどうかを毎回判定し、 +無効なら探索するようにした。 +signalHandler() (compiler.c) 中の、 +signal 発生時に実行されていたのは compiled code であるという仮定を除去。 +(compiler.c) + +構造体 sigcontext を探索するための key として、 +linux ではレジスタ gs, fs, es, ds、FreeBSD では es, ds, cs, ss を用いてきた。 +これを gs, fs, es, ds で統一した。 +(compiler.c, compiler.h) + +implements しているはずの interface を implements していない場合に +getInterfaceMethod() (runtime.c) で invokeInterfaceError() を呼んで +IncompatibleClassChangeError を生成する。 +その際に、invokeInterfaceError() にきちんとプログラムカウンタを +渡すようにした。 +(runtime.c, compiler.h) + +[19990907] + +変数 runtime_debug と同様に、compile_debug を設けた。 +(compile.c, computil.c) + +makePCTable() 中で参照するより後 (updateStates()) で +CompilerContext.may_throw を更新していた。 +これを processAnOpcode() 中で更新するように修整。 +(compile.c) + +JIT コンパイル中の排他処理のために Class クラスのオブジェクトの +モニタを取得していたところ、JIT コンパイラ用のモニタを用意した。 +構造体 CodeInfo にメンバ monitor を用意。 +(compiler.h, invoker.c) + +processAnOpcode() (compile.c) にて CompilerContext.may_throw を更新する際、 +変数 code_opcode ではなく調整前の opcode を参照していた。 +(compile.c) + +[19990903] + +processAnOpcode() (compile.c) から、 +stack state の設定を updateStates() として分離した。 +これに伴い、processAnOpcode() の引数も変更。 +peephole 最適化への布石。 +(compile.c) + +[19990830] + +内部命令 exc_handler を exc_new と exc_handler に分け、 +メソッドが例外表を持たない場合は exc_handler を生成しないようにした。 +(compiler.h, code.c, compile.c) + +[19990829] + +例外を throw し得るバイトコード命令を含むメソッドに対して、 +内部命令 exc_handler を生成するようにした。 +そのためにマクロ OPC_THROW, OPC_SIGNAL を用意。 +(compiler.h, code.c, compile.c) + [19990828] configure を gcc 2.9X に対応させた。 @@ -13,6 +78,29 @@ (code.c) 0.3.8 リリース。 + +final フィールドへのアクセスで +きちんと IllegalAccessError が throw されるようにした。 +本来はバイトコードベリファイアがはじくべきか? +内部命令 throw_illegalaccess を設け、processAnOpcode() (compile.c) にて +final フィールドへの putfield* を throw_illegalaccess に変換するようにした。 +内部命令 exception_handler を生成するかしないかの判定を、 +makePCTable() (compile.c) 中で直接行うのではなく、 +構造体 CompilerContext のメンバ may_throw を参照するようにした。 +(compiler.h, code.c, compile.c) + +invokeinterface 命令でもきちんと SIGSEGV が発生するように、 +*obj を触るコードを追加した。(cf. 19990826 の invokespecial) +NetBeans の動作テストで問題が判明した。 +(code.c) + +関数呼び出し内で例外が発生したかどうかのチェックを +自己書き換えでスキップしていなかった。スキップするようにした。 +(code.c) + +getInterfaceMethod() (runtime.c) 呼び出し後の例外チェックは +一度行われればよいため、自己書き換えでスキップするようにした。 +(code.c) [19990827] diff -aruN shujit-0.3.8/GNUmakefile shujit/GNUmakefile --- shujit-0.3.8/GNUmakefile Sat Aug 28 19:05:38 1999 +++ shujit/GNUmakefile Thu Sep 9 14:09:36 1999 @@ -10,8 +10,8 @@ # environment -JDK_VER = 12 -J_INCDIR = /usr/local/java/include-old +JDK_VER = 11 +J_INCDIR = /usr/local/java/include GCC27 = @@ -49,7 +49,7 @@ INCDIR = -I${J_INCDIR} -I${J_INCDIR}/genunix -I${J_INCDIR}/linux -I${J_INCDIR}/freebsd -I/usr/local/include OPTFLAGS = -O2 -CDEBUGFLAGS =# -g -DRUNTIME_DEBUG# -DCOMPILE_DEBUG# -DNO_CHECK +CDEBUGFLAGS =# -g -DCOMPILE_DEBUG# -DRUNTIME_DEBUG# -DNO_CHECK NOOPTCFLAGS = -pipe -fPIC ${CDEBUGFLAGS} ${INCDIR} CFLAGS = ${OPTFLAGS} ${NOOPTCFLAGS} LIBS = diff -aruN shujit-0.3.8/GNUmakefile.in shujit/GNUmakefile.in --- shujit-0.3.8/GNUmakefile.in Tue Aug 24 16:37:21 1999 +++ shujit/GNUmakefile.in Sun Aug 29 05:23:06 1999 @@ -49,7 +49,7 @@ INCDIR = -I${J_INCDIR} -I${J_INCDIR}/genunix -I${J_INCDIR}/linux -I${J_INCDIR}/freebsd -I/usr/local/include OPTFLAGS = -O2 -CDEBUGFLAGS =# -g -DRUNTIME_DEBUG# -DCOMPILE_DEBUG# -DNO_CHECK +CDEBUGFLAGS =# -g -DCOMPILE_DEBUG# -DRUNTIME_DEBUG# -DNO_CHECK NOOPTCFLAGS = -pipe -fPIC ${CDEBUGFLAGS} ${INCDIR} CFLAGS = ${OPTFLAGS} ${NOOPTCFLAGS} LIBS = diff -aruN shujit-0.3.8/README shujit/README --- shujit-0.3.8/README Sat Aug 21 18:25:32 1999 +++ shujit/README Thu Sep 9 14:03:00 1999 @@ -18,7 +18,7 @@ - JDK 1.1.7v1a, egcs 1.1.2, libc5.4.38 and Linux 2.0.35 - FreeBSD - - JDK 1.1.8 (ELF, V99-7-19), egcs 1.1.2, FreeBSD 3.2R + - JDK 1.1.8 (ELF, V99-7-19), gcc 2.95.1, FreeBSD 3.2R * Installation diff -aruN shujit-0.3.8/code.c shujit/code.c --- shujit-0.3.8/code.c Sat Aug 28 19:05:29 1999 +++ shujit/code.c Thu Sep 9 04:36:37 1999 @@ -328,16 +328,8 @@ "ret"); } - /* exception handler */ - /* eax,edx may be ename,DetailMessage */ - CODE(opc_exc_handler, exc_handler, STANY, STSTA, 0) { -#ifdef METAVM - /* clear remote flag */ - asm("movl %0,%%edi\n\t" - "movb $0," EE_REMOTE_FLAG(%%edi) - : : "m" (ee)); -#endif - + /* instantiate an exception */ + CODE(opc_exc_new, exc_new, STANY, STSTA, 0) { /* call SingalError() if it has not called yet */ asm("movl %0,%%edi" : : "m" (ee)); asm("cmpb $0," EE_EXCEPTIONKIND(%edi) "\n\t" @@ -349,6 +341,17 @@ "call " SYMBOL(SignalError) "@PLT\n\t" "addl $12,%%esp" : : "m" (ee)); asm("exc_signal_error_done:"); + } + + /* exception handler */ + /* eax,edx may be ename,DetailMessage */ + CODE(opc_exc_handler, exc_handler, STANY, STSTA, 0) { +#ifdef METAVM + /* clear remote flag */ + asm("movl %0,%%edi\n\t" + "movb $0," EE_REMOTE_FLAG(%%edi) + : : "m" (ee)); +#endif #ifdef RUNTIME_DEBUG asm("pushl %0" : : "m" (runtime_debug)); @@ -474,7 +477,7 @@ "addl $4,%esp") #endif /* JDK_VER */ - CODE(opc_syncenter, syncenter, STANY, STSTA, 0) { + CODE(opc_syncenter, syncenter, STANY, STSTA, OPC_THROW) { /* monitorEnter(obj_monitor(o)); */ #ifdef SET_FRAME_MONITOR /* frame->monitor = (struct sys_mon *)o */ @@ -533,10 +536,21 @@ CODE_FPPC(double, "andl $0xfcff,%eax\n\torl $0x0200,%eax"); CODE_FPPC(ext, "orl $0x0300,%eax"); - /* nop */ - CODE(opc_nop, nop, STANY, STSTA, 0) { + /* throw IllegalAccessError */ +#define CODE_ILLEGALACCESS(STATE) \ + CODE(opc_throw_illegalaccess, throw_illegalaccess, ST##STATE, ST0, OPC_THROW) {\ + SIGNAL_ERROR1(IllegalAccessError, "FinalAccessed", STATE);\ } + CODE_ILLEGALACCESS(0); + CODE_ILLEGALACCESS(1); + CODE_ILLEGALACCESS(2); + CODE_ILLEGALACCESS(3); + CODE_ILLEGALACCESS(4); + + /* nop */ + CODE(opc_nop, nop, STANY, STSTA, 0) {} + /* iconst_0 */ CODE(opc_iconst_0, [ifa]const_0, ST0, ST1, 0) { asm("xorl %edx,%edx"); } CODE(opc_iconst_0, [ifa]const_0, ST1, ST2, 0) { asm("xorl %ecx,%ecx"); } @@ -974,7 +988,7 @@ /* array_check */ #if 0 - CODE(opc_array_check, array_check, ST[24], ST[24], 1) { + CODE(opc_array_check, array_check, ST[24], ST[24], OPC_SIGNAL) { if (!h) { SIGNAL_ERROR0(NullPointerException); } if ((index < 0) || (index >= obj_length(h))) { @@ -1048,10 +1062,10 @@ /* destroy %edi */ /* edi = obj_length(handle) */ - CODE(opc_array_check, array_check, ST2, ST2, 1) { + CODE(opc_array_check, array_check, ST2, ST2, OPC_SIGNAL) { ARRAY_CHECK(%edx, %ecx, "arychk_st2", 2); } - CODE(opc_array_check, array_check, ST4, ST4, 1) { + CODE(opc_array_check, array_check, ST4, ST4, OPC_SIGNAL) { ARRAY_CHECK(%ecx, %edx, "arychk_st4", 4); } @@ -1106,14 +1120,14 @@ # define METAVM_ALOAD(HANDLE, SLOT, TGT, LABEL, STATE) #endif /* METAVM_NO_ARRAY */ - CODE(opc_iaload, [ifa]aload, ST2, ST1, 0) { + CODE(opc_iaload, [ifa]aload, ST2, ST1, OPC_THROW) { METAVM_ALOAD(%edx, %ecx, %edx, "iaload_st2", 0); UNHAND(%edx, %eax); asm("movl (%eax,%ecx,4),%edx"); asm("iaload_st2_done:"); BIPUSH_DEBUG1(%edx); } - CODE(opc_iaload, [ifa]aload, ST4, ST3, 0) { + CODE(opc_iaload, [ifa]aload, ST4, ST3, OPC_THROW) { METAVM_ALOAD(%ecx, %edx, %ecx, "iaload_st4", 0); UNHAND(%ecx, %eax); asm("movl (%eax,%edx,4),%ecx"); @@ -1161,7 +1175,7 @@ # define METAVM_ALOAD2(HANDLE, SLOT, TGT_LOW, TGT_HIGH, LABEL, STATE) #endif /* METAVM_NO_ARRAY */ - CODE(opc_laload, [ld]aload, ST2, ST4, 0) { + CODE(opc_laload, [ld]aload, ST2, ST4, OPC_THROW) { METAVM_ALOAD2(%edx, %ecx, %edx, %ecx, "laload_st2", 2); UNHAND(%edx, %eax); asm("leal (%eax,%ecx,8),%edi\n\t" @@ -1170,7 +1184,7 @@ asm("laload_st2_done:"); LDC2_W_DEBUG1(%edx, %ecx); } - CODE(opc_laload, [ld]aload, ST4, ST2, 0) { + CODE(opc_laload, [ld]aload, ST4, ST2, OPC_THROW) { METAVM_ALOAD2(%ecx, %edx, %ecx, %edx, "laload_st4", 4); UNHAND(%ecx, %eax); asm("leal (%eax,%edx,8),%edi\n\t" @@ -1182,14 +1196,14 @@ /* baload */ /* compile: fill_cache, array_check, baload */ - CODE(opc_baload, baload, ST2, ST1, 0) { + CODE(opc_baload, baload, ST2, ST1, OPC_THROW) { METAVM_ALOAD(%edx, %ecx, %edx, "baload_st2", 0); UNHAND(%edx, %eax); asm("movsbl (%eax,%ecx),%edx"); asm("baload_st2_done:"); BIPUSH_DEBUG1(%edx); } - CODE(opc_baload, baload, ST4, ST3, 0) { + CODE(opc_baload, baload, ST4, ST3, OPC_THROW) { METAVM_ALOAD(%ecx, %edx, %ecx, "baload_st4", 0); UNHAND(%ecx, %eax); asm("movsbl (%eax,%edx),%ecx"); @@ -1199,14 +1213,14 @@ /* caload */ /* compile: fill_cache, array_check, caload */ - CODE(opc_caload, caload, ST2, ST1, 0) { + CODE(opc_caload, caload, ST2, ST1, OPC_THROW) { METAVM_ALOAD(%edx, %ecx, %edx, "caload_st2", 0); UNHAND(%edx, %eax); asm("movzwl (%eax,%ecx,2),%edx"); asm("caload_st2_done:"); BIPUSH_DEBUG1(%edx); } - CODE(opc_caload, caload, ST4, ST3, 0) { + CODE(opc_caload, caload, ST4, ST3, OPC_THROW) { METAVM_ALOAD(%ecx, %edx, %ecx, "caload_st4", 0); UNHAND(%ecx, %eax); asm("movzwl (%eax,%edx,2),%ecx"); @@ -1216,14 +1230,14 @@ /* saload */ /* compile: fill_cache, array_check, saload */ - CODE(opc_saload, saload, ST2, ST1, 0) { + CODE(opc_saload, saload, ST2, ST1, OPC_THROW) { METAVM_ALOAD(%edx, %ecx, %edx, "saload_st2", 0); UNHAND(%edx, %eax); asm("movswl (%eax,%ecx,2),%edx"); asm("saload_st2_done:"); BIPUSH_DEBUG1(%edx); } - CODE(opc_saload, saload, ST4, ST3, 0) { + CODE(opc_saload, saload, ST4, ST3, OPC_THROW) { METAVM_ALOAD(%ecx, %edx, %ecx, "saload_st4", 0); UNHAND(%ecx, %eax); asm("movswl (%eax,%edx,2),%ecx"); @@ -1402,13 +1416,13 @@ # define METAVM_ASTORE(HANDLE, SLOT, VAL, LABEL, STATE) #endif /* METAVM_NO_ARRAY */ - CODE(opc_iastore, [ifa]astore, ST2, ST0, 0) { + CODE(opc_iastore, [ifa]astore, ST2, ST0, OPC_THROW) { METAVM_ASTORE(%edx, %ecx, %eax, "iastore_st2", 2); UNHAND(%edx, %edi); asm("movl %eax,(%edi,%ecx,4)"); /* array->body[ecx] = eax */ asm("iastore_st2_done:"); } - CODE(opc_iastore, [ifa]astore, ST4, ST0, 0) { + CODE(opc_iastore, [ifa]astore, ST4, ST0, OPC_THROW) { METAVM_ASTORE(%ecx, %edx, %eax, "iastore_st4", 4); UNHAND(%ecx, %edi); asm("movl %eax,(%edi,%edx,4)"); /* array->body[edx] = eax */ @@ -1467,7 +1481,7 @@ # define AASTORE_TEST(OBJ, HANDLE, STATE) #endif /* NO_CHECK */ - CODE(opc_aastore, aastore, ST2, ST0, 0) { + CODE(opc_aastore, aastore, ST2, ST0, OPC_THROW) { METAVM_ASTORE(%edx, %ecx, %eax, "aastore_st2", 2); METAVM_AASTORE(%edx); /* edi = obj_length(%edx) */ UNHAND(%edx, %edx); @@ -1475,7 +1489,7 @@ asm("movl %eax,(%edx,%ecx,4)");/* array->body[ecx] = eax */ asm("aastore_st2_done:"); } - CODE(opc_aastore, aastore, ST4, ST0, 0) { + CODE(opc_aastore, aastore, ST4, ST0, OPC_THROW) { METAVM_ASTORE(%ecx, %edx, %eax, "aastore_st4", 4); METAVM_AASTORE(%ecx); /* edi = obj_length(%edx) */ UNHAND(%ecx, %ecx); @@ -1529,7 +1543,7 @@ #endif /* METAVM_NO_ARRAY */ #define CODE_LASTORE(OPTOP1_REG, OPTOP2_REG, STATE) \ - CODE(opc_lastore, [ld]astore, ST##STATE, ST0, 1) {\ + CODE(opc_lastore, [ld]astore, ST##STATE, ST0, OPC_SIGNAL) {\ asm("popl %eax\n\t"\ "movl (%esp),%edi");\ METAVM_ASTORE2(%edi, %eax, OPTOP1_REG, OPTOP2_REG, "lastore_st" #STATE, STATE);\ @@ -1548,14 +1562,14 @@ /* bastore */ /* compile: iastore1, fill_cache, array_check, bastore */ - CODE(opc_bastore, bastore, ST2, ST0, 0) { + CODE(opc_bastore, bastore, ST2, ST0, OPC_THROW) { METAVM_ASTORE(%edx, %ecx, %eax, "bastore_st2", 2); UNHAND(%edx, %edi); asm("movb %al,(%edi,%ecx)"); asm("bastore_st2_done:"); BIPUSH_DEBUG1(%eax); } - CODE(opc_bastore, bastore, ST4, ST0, 0) { + CODE(opc_bastore, bastore, ST4, ST0, OPC_THROW) { METAVM_ASTORE(%ecx, %edx, %eax, "bastore_st4", 4); UNHAND(%ecx, %edi); asm("movb %al,(%edi,%edx)"); @@ -1565,14 +1579,14 @@ /* castore */ /* compile: iastore1, fill_cache, array_check, castore */ - CODE(opc_castore, castore, ST2, ST0, 0) { + CODE(opc_castore, castore, ST2, ST0, OPC_THROW) { METAVM_ASTORE(%edx, %ecx, %eax, "castore_st2", 2); UNHAND(%edx, %edi); asm("movw %ax,(%edi,%ecx,2)"); asm("castore_st2_done:"); BIPUSH_DEBUG1(%eax); } - CODE(opc_castore, castore, ST4, ST0, 0) { + CODE(opc_castore, castore, ST4, ST0, OPC_THROW) { METAVM_ASTORE(%ecx, %edx, %eax, "castore_st4", 2); UNHAND(%ecx, %edi); asm("movw %ax,(%edi,%edx,2)"); @@ -1582,14 +1596,14 @@ /* sastore */ /* compile: iastore1, fill_cache, array_check, sastore */ - CODE(opc_sastore, sastore, ST2, ST0, 0) { + CODE(opc_sastore, sastore, ST2, ST0, OPC_THROW) { METAVM_ASTORE(%edx, %ecx, %eax, "sastore_st2", 2); UNHAND(%edx, %edi); asm("movw %ax,(%edi,%ecx,2)"); asm("sastore_st2_done:"); BIPUSH_DEBUG1(%eax); } - CODE(opc_sastore, sastore, ST4, ST0, 0) { + CODE(opc_sastore, sastore, ST4, ST0, OPC_THROW) { METAVM_ASTORE(%ecx, %edx, %eax, "sastore_st4", 4); UNHAND(%ecx, %edi); asm("movw %ax,(%edi,%edx,2)"); @@ -1880,7 +1894,7 @@ #endif #define CODE_ARITH_INT_TEST(VOP, RESULT_REG, SYM) \ - CODE(opc_i##VOP, i##VOP, ST0, ST3, 1) {\ + CODE(opc_i##VOP, i##VOP, ST0, ST3, OPC_SIGNAL) {\ asm("popl %ecx"); /* now state 3 */\ asm("popl %eax");\ ARITH_INT_DEBUG1(%eax, %ecx, SYM);\ @@ -1890,7 +1904,7 @@ "i" #VOP "_st0_done:"\ "movl " #RESULT_REG ",%ecx");\ }\ - CODE(opc_i##VOP, i##VOP, ST1, ST3, 1) {\ + CODE(opc_i##VOP, i##VOP, ST1, ST3, OPC_SIGNAL) {\ asm("popl %eax\n\t"\ "movl %edx,%ecx");\ ARITH_INT_DEBUG1(%eax, %ecx, SYM);\ @@ -1900,7 +1914,7 @@ "i" #VOP "_st1_done:"\ "movl " #RESULT_REG ",%ecx");\ }\ - CODE(opc_i##VOP, i##VOP, ST2, ST3, 1) {\ + CODE(opc_i##VOP, i##VOP, ST2, ST3, OPC_SIGNAL) {\ asm("movl %edx,%eax");\ ARITH_INT_DEBUG1(%eax, %ecx, SYM);\ INT_TEST(VOP, "i" #VOP "_st2", 2, %ecx);\ @@ -1909,7 +1923,7 @@ "i" #VOP "_st2_done:"\ "movl " #RESULT_REG ",%ecx");\ }\ - CODE(opc_i##VOP, i##VOP, ST3, ST3, 1) {\ + CODE(opc_i##VOP, i##VOP, ST3, ST3, OPC_SIGNAL) {\ asm("popl %eax");\ ARITH_INT_DEBUG1(%eax, %ecx, SYM);\ INT_TEST(VOP, "i" #VOP "_st3", 3, %ecx);\ @@ -1918,7 +1932,7 @@ "i" #VOP "_st3_done:"\ "movl " #RESULT_REG ",%ecx");\ }\ - CODE(opc_i##VOP, i##VOP, ST4, ST3, 1) {\ + CODE(opc_i##VOP, i##VOP, ST4, ST3, OPC_SIGNAL) {\ asm("movl %ecx,%eax\n\t"\ "movl %edx,%ecx");\ ARITH_INT_DEBUG1(%eax, %ecx, SYM);\ @@ -2112,27 +2126,27 @@ #endif #define CODE_ARITH_LONG_TEST(VOP, ROP, SYM) \ - CODE(opc_l##VOP, l##VOP, ST0, ST2, 1) {\ + CODE(opc_l##VOP, l##VOP, ST0, ST2, OPC_SIGNAL) {\ asm("popl %ecx\n\t"\ "popl %edx"); /* now state 2 */\ LONG_TEST_ST24(VOP, "l" #VOP "_st0", 0);\ ARITH_LONG_CALL_ST24(ROP, %ecx, %edx, SYM);\ }\ - CODE(opc_l##VOP, l##VOP, ST1, ST2, 1) {\ + CODE(opc_l##VOP, l##VOP, ST1, ST2, OPC_SIGNAL) {\ asm("popl %ecx"); /* now state 4 */\ LONG_TEST_ST24(VOP, "l" #VOP "_st1", 1);\ ARITH_LONG_CALL_ST24(ROP, %edx, %ecx, SYM);\ }\ - CODE(opc_l##VOP, l##VOP, ST2, ST2, 1) {\ + CODE(opc_l##VOP, l##VOP, ST2, ST2, OPC_SIGNAL) {\ LONG_TEST_ST24(VOP, "l" #VOP "_st2", 2);\ ARITH_LONG_CALL_ST24(ROP, %ecx, %edx, SYM);\ }\ - CODE(opc_l##VOP, l##VOP, ST3, ST2, 1) {\ + CODE(opc_l##VOP, l##VOP, ST3, ST2, OPC_SIGNAL) {\ asm("popl %edx"); /* now state 2 */\ LONG_TEST_ST24(VOP, "l" #VOP "_st3", 3);\ ARITH_LONG_CALL_ST24(ROP, %ecx, %edx, SYM);\ }\ - CODE(opc_l##VOP, l##VOP, ST4, ST2, 1) {\ + CODE(opc_l##VOP, l##VOP, ST4, ST2, OPC_SIGNAL) {\ LONG_TEST_ST24(VOP, "l" #VOP "_st4", 4);\ ARITH_LONG_CALL_ST24(ROP, %edx, %ecx, SYM);\ } @@ -3559,7 +3573,7 @@ /* getstatic */ /* const: address */ /* stuff to rewrite code for opc_{get,put}static */ -#define GETSTATIC_REWRITE_OFFSET "0x19" +#define GETSTATIC_REWRITE_OFFSET "0x29" #if defined(INITCLASS_IN_COMPILING) || defined(NO_REWRITE) # define INITCLASS_GETSTATIC(LABEL, STATE) @@ -3569,7 +3583,7 @@ /*asm("nop\n\tnop\n\tnop\n\tnop");*/\ asm("jmp " LABEL "_call_initclass\n\t"\ "jmp " LABEL "_initclass_done\n\t"\ - LABEL "_call_initclass:");\ + LABEL "_call_initclass:");\ \ asm("pushl %edx\n\tpushl %ecx"); /* save */\ asm("pushl %edi");\ @@ -3578,6 +3592,11 @@ "addl $8,%esp");\ asm("popl %ecx\n\tpopl %edx"); /* restore */\ \ + /* exc. check */\ + asm("testl %eax,%eax\n\t"\ + "jz " LABEL "_initclass_done");\ + SIGNAL_ERROR_JUMP(STATE);\ + \ /* rewrite */\ asm("call 0\n\t"\ "popl %edi");\ @@ -3586,36 +3605,31 @@ "movb $0x90,(%edi)\n\t"\ "movb $0x90,1(%edi)");\ \ - /* exc. check */\ - asm("testl %eax,%eax\n\t"\ - "jz " LABEL "_initclass_done");\ - SIGNAL_ERROR_JUMP(STATE);\ - \ asm(LABEL "_initclass_done:") #endif /* INITCLASS_IN_COMPILING || NO_REWRITE */ - CODE(opc_getstatic, getstatic, ST0, ST1, 0) { + CODE(opc_getstatic, getstatic, ST0, ST1, OPC_THROW) { INITCLASS_GETSTATIC("getstatic_st0", 0); asm("movl (" STR(CONST) "),%edx"); BIPUSH_DEBUG1(%edx); } - CODE(opc_getstatic, getstatic, ST1, ST2, 0) { + CODE(opc_getstatic, getstatic, ST1, ST2, OPC_THROW) { INITCLASS_GETSTATIC("getstatic_st1", 1); asm("movl (" STR(CONST) "),%ecx"); BIPUSH_DEBUG1(%ecx); } - CODE(opc_getstatic, getstatic, ST2, ST4, 0) { + CODE(opc_getstatic, getstatic, ST2, ST4, OPC_THROW) { INITCLASS_GETSTATIC("getstatic_st2", 2); asm("pushl %edx\n\t" /* now state 3 */ "movl (" STR(CONST) "),%edx"); BIPUSH_DEBUG1(%edx); } - CODE(opc_getstatic, getstatic, ST3, ST4, 0) { + CODE(opc_getstatic, getstatic, ST3, ST4, OPC_THROW) { INITCLASS_GETSTATIC("getstatic_st3", 3); asm("movl (" STR(CONST) "),%edx"); BIPUSH_DEBUG1(%edx); } - CODE(opc_getstatic, getstatic, ST4, ST2, 0) { + CODE(opc_getstatic, getstatic, ST4, ST2, OPC_THROW) { INITCLASS_GETSTATIC("getstatic_st4", 4); asm("pushl %ecx\n\t" /* now state 1 */ "movl (" STR(CONST) "),%ecx"); @@ -3626,27 +3640,27 @@ #define GETSTATIC2_ST0(LOW_REG, HIGH_REG) \ asm("movl (" STR(CONST) ")," #LOW_REG "\n\t"\ "movl (" STR(CONST) ")," #HIGH_REG) - CODE(opc_getstatic2, getstatic2, ST0, ST2, 0) { + CODE(opc_getstatic2, getstatic2, ST0, ST2, OPC_THROW) { INITCLASS_GETSTATIC("getstatic2_st0", 0); GETSTATIC2_ST0(%ecx, %edx); } - CODE(opc_getstatic2, getstatic2, ST1, ST2, 0) { + CODE(opc_getstatic2, getstatic2, ST1, ST2, OPC_THROW) { asm("pushl %edx"); /* now state 0 */ INITCLASS_GETSTATIC("getstatic2_st1", 0); GETSTATIC2_ST0(%ecx, %edx); } - CODE(opc_getstatic2, getstatic2, ST2, ST4, 0) { + CODE(opc_getstatic2, getstatic2, ST2, ST4, OPC_THROW) { asm("pushl %edx\n\t"\ "pushl %ecx"); /* now state 0 */\ INITCLASS_GETSTATIC("getstatic2_st2", 0); GETSTATIC2_ST0(%edx, %ecx); } - CODE(opc_getstatic2, getstatic2, ST3, ST4, 0) { + CODE(opc_getstatic2, getstatic2, ST3, ST4, OPC_THROW) { asm("pushl %ecx"); /* now state 0 */\ INITCLASS_GETSTATIC("getstatic2_st3", 0); GETSTATIC2_ST0(%edx, %ecx); } - CODE(opc_getstatic2, getstatic2, ST4, ST2, 0) { + CODE(opc_getstatic2, getstatic2, ST4, ST2, OPC_THROW) { asm("pushl %ecx\n\t"\ "pushl %edx"); /* now state 0 */\ INITCLASS_GETSTATIC("getstatic2_st4", 0); @@ -3655,28 +3669,28 @@ /* putstatic */ /* const: address */ - CODE(opc_putstatic, putstatic, ST0, ST0, 0) { + CODE(opc_putstatic, putstatic, ST0, ST0, OPC_THROW) { INITCLASS_GETSTATIC("putstatic_st0", 0); asm("popl %edx\n\t" /* now state 1 */ "movl %edx,(" STR(CONST) ")"); BIPUSH_DEBUG1(%edx); } - CODE(opc_putstatic, putstatic, ST1, ST0, 0) { + CODE(opc_putstatic, putstatic, ST1, ST0, OPC_THROW) { INITCLASS_GETSTATIC("putstatic_st1", 1); asm("movl %edx,(" STR(CONST) ")"); BIPUSH_DEBUG1(%edx); } - CODE(opc_putstatic, putstatic, ST2, ST1, 0) { + CODE(opc_putstatic, putstatic, ST2, ST1, OPC_THROW) { INITCLASS_GETSTATIC("putstatic_st2", 2); asm("movl %ecx,(" STR(CONST) ")"); BIPUSH_DEBUG1(%ecx); } - CODE(opc_putstatic, putstatic, ST3, ST0, 0) { + CODE(opc_putstatic, putstatic, ST3, ST0, OPC_THROW) { INITCLASS_GETSTATIC("putstatic_st3", 3); asm("movl %ecx,(" STR(CONST) ")"); BIPUSH_DEBUG1(%ecx); } - CODE(opc_putstatic, putstatic, ST4, ST3, 0) { + CODE(opc_putstatic, putstatic, ST4, ST3, OPC_THROW) { INITCLASS_GETSTATIC("putstatic_st4", 4); asm("movl %edx,(" STR(CONST) ")"); BIPUSH_DEBUG1(%edx); @@ -3688,27 +3702,27 @@ "movl " #OPTOP2_REG ",(" STR(CONST) ")") /* now state 0 */ - CODE(opc_putstatic2, putstatic2, ST0, ST0, 0) { + CODE(opc_putstatic2, putstatic2, ST0, ST0, OPC_THROW) { INITCLASS_GETSTATIC("putstatic2_st0", 0); asm("popl %ecx\n\t" "popl %edx"); /* now state 2 */ PUTSTATIC2(%ecx, %edx); } - CODE(opc_putstatic2, putstatic2, ST1, ST0, 0) { + CODE(opc_putstatic2, putstatic2, ST1, ST0, OPC_THROW) { INITCLASS_GETSTATIC("putstatic2_st1", 1); asm("popl %ecx"); /* now state 4 */ PUTSTATIC2(%edx, %ecx); } - CODE(opc_putstatic2, putstatic2, ST2, ST0, 0) { + CODE(opc_putstatic2, putstatic2, ST2, ST0, OPC_THROW) { INITCLASS_GETSTATIC("putstatic2_st2", 2); PUTSTATIC2(%ecx, %edx); } - CODE(opc_putstatic2, putstatic2, ST3, ST0, 0) { + CODE(opc_putstatic2, putstatic2, ST3, ST0, OPC_THROW) { INITCLASS_GETSTATIC("putstatic2_st3", 3); asm("popl %edx"); /* now state 2 */ PUTSTATIC2(%ecx, %edx); } - CODE(opc_putstatic2, putstatic2, ST4, ST0, 0) { + CODE(opc_putstatic2, putstatic2, ST4, ST0, OPC_THROW) { INITCLASS_GETSTATIC("putstatic2_st4", 4); PUTSTATIC2(%edx, %ecx); } @@ -3727,7 +3741,7 @@ #endif /* NO_CHECK */ /* eax = index */ - CODE(opc_getfield, getfield, ST0, ST3, 1) { + CODE(opc_getfield, getfield, ST0, ST3, OPC_SIGNAL) { asm("popl %edx"); /* now state 1 */ FIELD_ACC(%edx, getfield, 0); METAVM_GETFIELD(%edx, %eax, %ecx, "getfield_st0", 0); @@ -3735,28 +3749,28 @@ asm("getfield_st0_done:"); ILOAD_DEBUG1(%ecx); } - CODE(opc_getfield, getfield, ST1, ST3, 1) { + CODE(opc_getfield, getfield, ST1, ST3, OPC_SIGNAL) { FIELD_ACC(%edx, getfield, 1); METAVM_GETFIELD(%edx, %eax, %ecx, "getfield_st1", 0); OBJ_GETSLOT(%edx, %eax, %ecx); asm("getfield_st1_done:"); ILOAD_DEBUG1(%ecx); } - CODE(opc_getfield, getfield, ST2, ST2, 1) { + CODE(opc_getfield, getfield, ST2, ST2, OPC_SIGNAL) { FIELD_ACC(%ecx, getfield, 2); METAVM_GETFIELD(%ecx, %eax, %ecx, "getfield_st2", 1); OBJ_GETSLOT(%ecx, %eax, %ecx); asm("getfield_st2_done:"); ILOAD_DEBUG1(%ecx); } - CODE(opc_getfield, getfield, ST3, ST1, 1) { + CODE(opc_getfield, getfield, ST3, ST1, OPC_SIGNAL) { FIELD_ACC(%ecx, getfield, 3); METAVM_GETFIELD(%ecx, %eax, %edx, "getfield_st3", 0); OBJ_GETSLOT(%ecx, %eax, %edx); asm("getfield_st3_done:"); ILOAD_DEBUG1(%edx); } - CODE(opc_getfield, getfield, ST4, ST4, 1) { + CODE(opc_getfield, getfield, ST4, ST4, OPC_SIGNAL) { FIELD_ACC(%edx, getfield, 4); METAVM_GETFIELD(%edx, %eax, %edx, "getfield_st4", 3); OBJ_GETSLOT(%edx, %eax, %edx); @@ -3765,7 +3779,7 @@ } /* const: slot */ - CODE(opc_getfield2, getfield2, ST0, ST2, 1) { + CODE(opc_getfield2, getfield2, ST0, ST2, OPC_SIGNAL) { asm("popl %edx"); /* now state 1 */ FIELD_ACC(%edx, getfield2, 0); METAVM_GETFIELD2(%edx, %eax, %ecx, %edx, "getfield2_st0", 1); @@ -3773,14 +3787,14 @@ asm("getfield2_st0_done:"); LLOAD_DEBUG1(%ecx, %edx); } - CODE(opc_getfield2, getfield2, ST1, ST2, 1) { + CODE(opc_getfield2, getfield2, ST1, ST2, OPC_SIGNAL) { FIELD_ACC(%edx, getfield2, 1); METAVM_GETFIELD2(%edx, %eax, %ecx, %edx, "getfield2_st1", 2); OBJ_GETSLOT2(%edx, %eax, %ecx, %edx); asm("getfield2_st1_done:"); LLOAD_DEBUG1(%ecx, %edx); } - CODE(opc_getfield2, getfield2, ST2, ST4, 1) { + CODE(opc_getfield2, getfield2, ST2, ST4, OPC_SIGNAL) { asm("pushl %edx"); /* now state 3 */ FIELD_ACC(%ecx, getfield2, 2); METAVM_GETFIELD2(%ecx, %eax, %edx, %ecx, "getfield2_st2", 2); @@ -3788,14 +3802,14 @@ asm("getfield2_st2_done:"); LLOAD_DEBUG1(%edx, %ecx); } - CODE(opc_getfield2, getfield2, ST3, ST4, 1) { + CODE(opc_getfield2, getfield2, ST3, ST4, OPC_SIGNAL) { FIELD_ACC(%ecx, getfield2, 3); METAVM_GETFIELD2(%ecx, %eax, %edx, %ecx, "getfield2_st3", 3); OBJ_GETSLOT2(%ecx, %eax, %edx, %ecx); asm("getfield2_st3_done:"); LLOAD_DEBUG1(%edx, %ecx); } - CODE(opc_getfield2, getfield2, ST4, ST2, 1) { + CODE(opc_getfield2, getfield2, ST4, ST2, OPC_SIGNAL) { asm("pushl %ecx"); /* now state 1 */ FIELD_ACC(%edx, getfield2, 4); METAVM_GETFIELD2(%edx, %eax, %ecx, %edx, "getfield2_st4", 4); @@ -3812,27 +3826,27 @@ OBJ_SETSLOT(OPTOP2_REG, %eax, OPTOP1_REG);\ asm("putfield_st" #STATE "_done:") - CODE(opc_putfield, putfield, ST0, ST0, 1) { + CODE(opc_putfield, putfield, ST0, ST0, OPC_SIGNAL) { asm("popl %ecx\n\t" "popl %edx"); /* now state 2 */ PUTFIELD_ST24(%ecx, %edx, 0); ILOAD_DEBUG1(%ecx); } - CODE(opc_putfield, putfield, ST1, ST0, 1) { + CODE(opc_putfield, putfield, ST1, ST0, OPC_SIGNAL) { asm("popl %ecx"); /* now state 4 */ PUTFIELD_ST24(%edx, %ecx, 1); ILOAD_DEBUG1(%edx); } - CODE(opc_putfield, putfield, ST2, ST0, 1) { + CODE(opc_putfield, putfield, ST2, ST0, OPC_SIGNAL) { PUTFIELD_ST24(%ecx, %edx, 2); ILOAD_DEBUG1(%ecx); } - CODE(opc_putfield, putfield, ST3, ST0, 1) { + CODE(opc_putfield, putfield, ST3, ST0, OPC_SIGNAL) { asm("popl %edx"); /* now state 2 */ PUTFIELD_ST24(%ecx, %edx, 3); ILOAD_DEBUG1(%ecx); } - CODE(opc_putfield, putfield, ST4, ST0, 1) { + CODE(opc_putfield, putfield, ST4, ST0, OPC_SIGNAL) { PUTFIELD_ST24(%edx, %ecx, 4); ILOAD_DEBUG1(%edx); } @@ -3847,23 +3861,23 @@ \ LLOAD_DEBUG1(OPTOP1_REG, OPTOP2_REG) - CODE(opc_putfield2, putfield2, ST0, ST0, 1) { + CODE(opc_putfield2, putfield2, ST0, ST0, OPC_SIGNAL) { asm("popl %ecx\n\t" "popl %edx"); /* now state 2 */ PUTFIELD2_ST24(%ecx, %edx, 0); } - CODE(opc_putfield2, putfield2, ST1, ST0, 1) { + CODE(opc_putfield2, putfield2, ST1, ST0, OPC_SIGNAL) { asm("popl %ecx"); /* now state 4 */ PUTFIELD2_ST24(%edx, %ecx, 1); } - CODE(opc_putfield2, putfield2, ST2, ST0, 1) { + CODE(opc_putfield2, putfield2, ST2, ST0, OPC_SIGNAL) { PUTFIELD2_ST24(%ecx, %edx, 2); } - CODE(opc_putfield2, putfield2, ST3, ST0, 1) { + CODE(opc_putfield2, putfield2, ST3, ST0, OPC_SIGNAL) { asm("popl %edx"); /* now state 2 */ PUTFIELD2_ST24(%ecx, %edx, 3); } - CODE(opc_putfield2, putfield2, ST4, ST0, 1) { + CODE(opc_putfield2, putfield2, ST4, ST0, OPC_SIGNAL) { PUTFIELD2_ST24(%edx, %ecx, 4); } @@ -4054,24 +4068,24 @@ /* needs eax:return value, ecx:args_size */ -#define CODE_INVOKE(vop, VOP, THROW_EXC) \ - CODE(opc_invoke##vop, invoke##vop, ST0, ST0, THROW_EXC) {\ +#define CODE_INVOKE(vop, VOP, OPC_FLAG) \ + CODE(opc_invoke##vop, invoke##vop, ST0, ST0, OPC_FLAG) {\ INVOKE_ST0(VOP, #vop "_st0");\ }\ - CODE(opc_invoke##vop, invoke##vop, ST1, ST0, THROW_EXC) {\ + CODE(opc_invoke##vop, invoke##vop, ST1, ST0, OPC_FLAG) {\ asm("pushl %edx"); /* now state 0 */\ INVOKE_ST0(VOP, #vop "_st1");\ }\ - CODE(opc_invoke##vop, invoke##vop, ST2, ST0, THROW_EXC) {\ + CODE(opc_invoke##vop, invoke##vop, ST2, ST0, OPC_FLAG) {\ asm("pushl %edx\n\t"\ "pushl %ecx"); /* now state 0 */\ INVOKE_ST0(VOP, #vop "_st2");\ }\ - CODE(opc_invoke##vop, invoke##vop, ST3, ST0, THROW_EXC) {\ + CODE(opc_invoke##vop, invoke##vop, ST3, ST0, OPC_FLAG) {\ asm("pushl %ecx"); /* now state 0 */\ INVOKE_ST0(VOP, #vop "_st3");\ }\ - CODE(opc_invoke##vop, invoke##vop, ST4, ST0, THROW_EXC) {\ + CODE(opc_invoke##vop, invoke##vop, ST4, ST0, OPC_FLAG) {\ asm("pushl %ecx\n\t"\ "pushl %edx"); /* now state 0 */\ INVOKE_ST0(VOP, #vop "_st4");\ @@ -4079,7 +4093,7 @@ /* stuff to rewrite code for opc_new */ -# define INVOKE_REWRITE_OFFSET "0x1c" +# define INVOKE_REWRITE_OFFSET "0x2c" #if defined(INITCLASS_IN_COMPILING) || defined(NO_REWRITE) # define INITCLASS_INVOKE(MB, LABEL) @@ -4088,14 +4102,20 @@ /*asm("nop\n\tnop\n\tnop\n\tnop");*/\ asm("jmp " LABEL "_call_initclass\n\t"\ "jmp " LABEL "_initclass_done\n\t"\ - LABEL "_call_initclass:");\ + LABEL "_call_initclass:");\ \ asm("pushl %eax\n\tpushl %edx\n\tpushl %ecx"); /* save */\ asm("pushl " METHOD_CLAZZ(MB));\ asm("pushl %0" : : "m" (ee)); /* ee */\ asm("call " SYMBOL(once_InitClass) "@PLT\n\t"\ "addl $8,%esp");\ - asm("popl %ecx\n\tpopl %edx\n\tpopl %eax"); /* restore */\ + asm("popl %ecx\n\tpopl %edx"); /* restore */\ + \ + /* exc. check */\ + asm("testl %eax,%eax\n\t"\ + "popl %eax\n\t" /* restore */\ + "jz " LABEL "_initclass_done");\ + SIGNAL_ERROR_JUMP(0);\ \ /* rewrite */\ asm("call 0\n\t"\ @@ -4166,12 +4186,29 @@ #define VARSPACE_STATIC(LABEL) asm("movl $" STR(CONST) ",%edi") #define METAVM_INVOKE_STATIC(LABEL) /* nothing */ -#define TGTOBJ_INTERFACE(LABEL, STATE) TGTOBJ_VIRTUAL(LABEL, STATE) +#define TGTOBJ_INTERFACE(LABEL, STATE) \ + TGTOBJ_VIRTUAL(LABEL, STATE);\ + asm("movl (%edx),%eax") + /* may cause SIGSEGV */ + +#define INVINTF_REWRITE_OFFSET "0x19" + +#define INVINTF_REWRITE1(LABEL) \ + asm("jmp " LABEL "_getintf_exc\n\t"\ + "jmp " LABEL "_getintf_done\n\t"\ + LABEL "_getintf_exc:") +#define INVINTF_REWRITE2(LABEL) \ + asm("call 0\n\t"\ + "popl %edi"); /* here, can break edi */\ + asm("subl $" INVINTF_REWRITE_OFFSET ",%edi\n\t"\ + "movb $0x90,(%edi)\n\t"\ + "movl $0x90,1(%edi)"); #define METHODBLOCK_INTERFACE(LABEL) \ /* get methodblock: call getInterfaceMethod() */\ asm("pushl %ecx\n\tpushl %edx"); /* save */\ /*FUNCCALL_IN(0);*/\ + asm("pushl %0" : : "m" (bytepcoff));/* bytepcoff */\ asm("pushl $" STR(CONST) "\n\t" /* guessptr */\ "pushl $" STR(CONST) "\n\t" /* imethod */\ "pushl %edx"); /* obj */\ @@ -4180,9 +4217,12 @@ /*FUNCCALL_OUT(0);*/\ asm("popl %edx\n\tpopl %ecx"); /* restore */\ \ + INVINTF_REWRITE1(LABEL);\ asm("testl %eax,%eax\n\t"\ "jnz " LABEL "_getintf_done");\ SIGNAL_ERROR_JUMP(0);\ + INVINTF_REWRITE2(LABEL);\ + \ asm(LABEL "_getintf_done:") #define VARSPACE_INTERFACE(LABEL) VARSPACE_VIRTUAL(LABEL) @@ -4192,18 +4232,18 @@ # define CALL_GETINTFMETHOD \ asm("pushl %0" : : "m" (runtime_debug));\ asm("call " SYMBOL(getInterfaceMethod) "@PLT\n\t"\ - "addl $20,%esp") + "addl $24,%esp") #else # define CALL_GETINTFMETHOD \ asm("call " SYMBOL(getInterfaceMethod) "@PLT\n\t"\ - "addl $16,%esp") + "addl $20,%esp") #endif - CODE_INVOKE(virtual, VIRTUAL, 1); - CODE_INVOKE(special, SPECIAL, 1); - CODE_INVOKE(static, STATIC, 0); - CODE_INVOKE(interface, INTERFACE, 1); + CODE_INVOKE(virtual, VIRTUAL, OPC_SIGNAL); + CODE_INVOKE(special, SPECIAL, OPC_SIGNAL); + CODE_INVOKE(static, STATIC, OPC_THROW); + CODE_INVOKE(interface, INTERFACE, OPC_SIGNAL); #if 0 /* how to get methodblock */ # if 0 @@ -4216,53 +4256,17 @@ /* invokevirtual_quick */ /* const: args_size, methodIndex, retsize */ - CODE_INVOKE(virtual_quick, VIRTUAL, 1); + CODE_INVOKE(virtual_quick, VIRTUAL, OPC_SIGNAL); /* invokevirtualobject_quick */ /* const: args_size, methodIndex, retsize */ - CODE_INVOKE(virtualobject_quick, VIRTUAL, 1); + CODE_INVOKE(virtualobject_quick, VIRTUAL, OPC_SIGNAL); /* xxxunusedxxx */ CODE(opc_xxxunusedxxx, xxxunusesxxx, STANY, STSTA, 0) {} /* new */ /* cosnt: cb */ -#ifndef NO_CHECK -# define NEW_TEST(CB_REG, LABEL, STATE) \ - /* call VerifyClassAccess() */\ - \ - asm("pushl " #CB_REG);\ - FUNCCALL_IN(STATE);\ - \ - asm("pushl $1\n\t" /* classloader_only */\ - "pushl " #CB_REG); /* new_class */\ - /* %eax = ee->current_frame->current_method */\ - {\ - register ExecEnv *cur_ee asm("eax");\ - cur_ee = ee;\ - }\ - asm("movl " EE_CURRENTFRAME(%eax) ",%edi\n\t"\ - "movl " FRAME_CURRENTMETHOD(%edi) ",%eax");\ - {\ - register struct methodblock *method asm("eax");\ - if (method)\ - asm("pushl %0" : : "m" (method->fb.clazz));\ - else\ - asm("pushl $0");\ - }\ - asm("call " SYMBOL(VerifyClassAccess) "@PLT\n\t"\ - "addl $12,%esp");\ - FUNCCALL_OUT(STATE);\ - asm("popl " #CB_REG);\ - \ - asm("testl %eax,%eax\n\t"\ - "jnz " LABEL "_testok");\ - SIGNAL_ERROR0(IllegalAccessError, STATE);\ - asm(LABEL "_testok:") -#else -# define NEW_TEST(CB_REG, LABEL, STATE) -#endif - #ifdef RUNTIME_DEBUG # define NEW_DEBUG1(CB_REG) \ if (runtime_debug) {\ @@ -4339,7 +4343,7 @@ #endif /* METAVM */ /* stuff to rewrite code for opc_new */ -#define NEW_REWRITE_OFFSET "0x19" +#define NEW_REWRITE_OFFSET "0x29" #ifndef NO_REWRITE # define NEW_REWRITE(CB_REG, LABEL, STATE) \ @@ -4355,6 +4359,11 @@ "addl $8,%esp");\ asm("popl %ecx\n\tpopl %edx"); /* restore */\ \ + /* exc. check */\ + asm("testl %eax,%eax\n\t"\ + "jz " LABEL "_done_once");\ + SIGNAL_ERROR_JUMP(STATE);\ + \ /* rewrite */\ asm("call 0\n\t"\ "popl %edi");\ @@ -4363,11 +4372,6 @@ "movb $0x90,(%edi)\n\t"\ "movb $0x90,1(%edi)");\ \ - /* exc. check */\ - asm("testl %eax,%eax\n\t"\ - "jz " LABEL "_done_once");\ - SIGNAL_ERROR_JUMP(STATE);\ - \ asm(LABEL "_done_once:") #else # define NEW_REWRITE(CB_REG, LABEL, STATE) @@ -4395,20 +4399,20 @@ asm("movl %eax," #DST_REG) - CODE(opc_new, new, ST0, ST1, 0) { + CODE(opc_new, new, ST0, ST1, OPC_THROW) { NEW(%edx, %edx, "new_st0", 0); } - CODE(opc_new, new, ST1, ST2, 0) { + CODE(opc_new, new, ST1, ST2, OPC_THROW) { NEW(%ecx, %ecx, "new_st1", 1); } - CODE(opc_new, new, ST2, ST4, 0) { + CODE(opc_new, new, ST2, ST4, OPC_THROW) { asm("pushl %edx"); /* now state 3 */ NEW(%edx, %edx, "new_st2", 3); } - CODE(opc_new, new, ST3, ST4, 0) { + CODE(opc_new, new, ST3, ST4, OPC_THROW) { NEW(%edx, %edx, "new_st3", 3); } - CODE(opc_new, new, ST4, ST2, 0) { + CODE(opc_new, new, ST4, ST2, OPC_THROW) { asm("pushl %ecx"); /* now state 1 */ NEW(%ecx, %ecx, "new_st4", 1); } @@ -4505,20 +4509,20 @@ asm(LABEL "_done:\n\t"\ "movl %eax," #OPTOP1_REG) /* store to dst. */ - CODE(opc_newarray, newarray, ST0, ST1, 0) { + CODE(opc_newarray, newarray, ST0, ST1, OPC_THROW) { asm("popl %edx"); /* now state 1 */ NEWARRAY(%edx, "newarray_st0", 1); } - CODE(opc_newarray, newarray, ST1, ST1, 0) { + CODE(opc_newarray, newarray, ST1, ST1, OPC_THROW) { NEWARRAY(%edx, "newarray_st1", 1); } - CODE(opc_newarray, newarray, ST2, ST2, 0) { + CODE(opc_newarray, newarray, ST2, ST2, OPC_THROW) { NEWARRAY(%ecx, "newarray_st2", 2); } - CODE(opc_newarray, newarray, ST3, ST3, 0) { + CODE(opc_newarray, newarray, ST3, ST3, OPC_THROW) { NEWARRAY(%ecx, "newarray_st3", 3); } - CODE(opc_newarray, newarray, ST4, ST4, 0) { + CODE(opc_newarray, newarray, ST4, ST4, OPC_THROW) { NEWARRAY(%edx, "newarray_st4", 4); } @@ -4586,17 +4590,17 @@ asm(LABEL "_done:\n\t"\ "movl %eax," #OPTOP1_REG) /* store to dst. */ - CODE(opc_anewarray, anewarray, ST0, ST1, 0) { + CODE(opc_anewarray, anewarray, ST0, ST1, OPC_THROW) { asm("popl %edx"); /* now state 1 */ ANEWARRAY(%edx, "anewarray_st0", 1); } - CODE(opc_anewarray, anewarray, ST1, ST1, 0) { + CODE(opc_anewarray, anewarray, ST1, ST1, OPC_THROW) { ANEWARRAY(%edx, "anewarray_st1", 1); } - CODE(opc_anewarray, anewarray, ST2, ST2, 0) { + CODE(opc_anewarray, anewarray, ST2, ST2, OPC_THROW) { ANEWARRAY(%ecx, "anewarray_st2", 2); } - CODE(opc_anewarray, anewarray, ST3, ST3, 0) { + CODE(opc_anewarray, anewarray, ST3, ST3, OPC_THROW) { ANEWARRAY(%ecx, "anewarray_st3", 3); } CODE(opc_anewarray, anewarray, ST4, ST4, 0) { @@ -4624,32 +4628,32 @@ # define METAVM_ARRAYLENGTH(HANDLE, DST, LABEL, STATE) #endif /* METAVM */ - CODE(opc_arraylength, arraylength, ST0, ST3, 1) { + CODE(opc_arraylength, arraylength, ST0, ST3, OPC_SIGNAL) { asm("popl %edx"); /* now state 1 */ NULL_TEST(%edx, "arylen_null_st0", 1); METAVM_ARRAYLENGTH(%edx, %ecx, "arraylength_st0", 0); OBJ_LENGTH(%edx, %ecx); asm("arraylength_st0_done:"); } - CODE(opc_arraylength, arraylength, ST1, ST3, 1) { + CODE(opc_arraylength, arraylength, ST1, ST3, OPC_SIGNAL) { NULL_TEST(%edx, "arylen_null_st1", 1); METAVM_ARRAYLENGTH(%edx, %ecx, "arraylength_st1", 0); OBJ_LENGTH(%edx, %ecx); asm("arraylength_st1_done:"); } - CODE(opc_arraylength, arraylength, ST2, ST2, 1) { + CODE(opc_arraylength, arraylength, ST2, ST2, OPC_SIGNAL) { NULL_TEST(%ecx, "arylen_null_st2", 2); METAVM_ARRAYLENGTH(%ecx, %ecx, "arraylength_st2", 1); OBJ_LENGTH(%ecx, %ecx); asm("arraylength_st2_done:"); } - CODE(opc_arraylength, arraylength, ST3, ST1, 1) { + CODE(opc_arraylength, arraylength, ST3, ST1, OPC_SIGNAL) { NULL_TEST(%ecx, "arylen_null_st3", 3); METAVM_ARRAYLENGTH(%ecx, %edx, "arraylength_st3", 0); OBJ_LENGTH(%ecx, %edx); asm("arraylength_st3_done:"); } - CODE(opc_arraylength, arraylength, ST4, ST4, 1) { + CODE(opc_arraylength, arraylength, ST4, ST4, OPC_SIGNAL) { NULL_TEST(%edx, "arylen_null_st4", 4); METAVM_ARRAYLENGTH(%edx, %edx, "arraylength_st4", 3); OBJ_LENGTH(%edx, %edx); @@ -4673,20 +4677,20 @@ bytepcoff = BYTEPCOFF;\ asm("jmp " STR(ADDR_EXC)) - CODE(opc_athrow, athrow, ST0, ST1, 1) { + CODE(opc_athrow, athrow, ST0, ST1, OPC_SIGNAL) { asm("popl %edx"); /* now state 1 */ ATHROW(%edx, 0); } - CODE(opc_athrow, athrow, ST1, ST1, 1) { + CODE(opc_athrow, athrow, ST1, ST1, OPC_SIGNAL) { ATHROW(%edx, 1); } - CODE(opc_athrow, athrow, ST2, ST2, 1) { + CODE(opc_athrow, athrow, ST2, ST2, OPC_SIGNAL) { ATHROW(%ecx, 2); } - CODE(opc_athrow, athrow, ST3, ST3, 1) { + CODE(opc_athrow, athrow, ST3, ST3, OPC_SIGNAL) { ATHROW(%ecx, 3); } - CODE(opc_athrow, athrow, ST4, ST4, 1) { + CODE(opc_athrow, athrow, ST4, ST4, OPC_SIGNAL) { ATHROW(%edx, 4); } @@ -4771,20 +4775,20 @@ SIGNAL_ERROR0(ClassCastException, STATE);\ asm(LABEL "_done:") - CODE(opc_checkcast, checkcast, ST0, ST1, 0) { + CODE(opc_checkcast, checkcast, ST0, ST1, OPC_THROW) { asm("popl %edx"); /* now state 1 */ CHECKCAST(%edx, "checkcast_st0", 1); } - CODE(opc_checkcast, checkcast, ST1, ST1, 0) { + CODE(opc_checkcast, checkcast, ST1, ST1, OPC_THROW) { CHECKCAST(%edx, "checkcast_st1", 1); } - CODE(opc_checkcast, checkcast, ST2, ST2, 0) { + CODE(opc_checkcast, checkcast, ST2, ST2, OPC_THROW) { CHECKCAST(%ecx, "checkcast_st2", 2); } - CODE(opc_checkcast, checkcast, ST3, ST3, 0) { + CODE(opc_checkcast, checkcast, ST3, ST3, OPC_THROW) { CHECKCAST(%ecx, "checkcast_st3", 3); } - CODE(opc_checkcast, checkcast, ST4, ST4, 0) { + CODE(opc_checkcast, checkcast, ST4, ST4, OPC_THROW) { CHECKCAST(%edx, "checkcast_st4", 4); } @@ -4881,20 +4885,20 @@ MONITOR_DEBUG; #define CODE_MONITOR(vop, FUNCNAME, METAVM_FUNCNAME) \ - CODE(opc_##vop, ##vop, ST0, ST0, 1) {\ + CODE(opc_##vop, ##vop, ST0, ST0, OPC_SIGNAL) {\ asm("popl %edx"); /* now state 1 */\ MONITOR(%edx, FUNCNAME, METAVM_FUNCNAME, #vop "_st0", 0);\ }\ - CODE(opc_##vop, ##vop, ST1, ST0, 1) {\ + CODE(opc_##vop, ##vop, ST1, ST0, OPC_SIGNAL) {\ MONITOR(%edx, FUNCNAME, METAVM_FUNCNAME, #vop "_st1", 0);\ }\ - CODE(opc_##vop, ##vop, ST2, ST1, 1) {\ + CODE(opc_##vop, ##vop, ST2, ST1, OPC_SIGNAL) {\ MONITOR(%ecx, FUNCNAME, METAVM_FUNCNAME, #vop "_st2", 1);\ }\ - CODE(opc_##vop, ##vop, ST3, ST0, 1) {\ + CODE(opc_##vop, ##vop, ST3, ST0, OPC_SIGNAL) {\ MONITOR(%ecx, FUNCNAME, METAVM_FUNCNAME, #vop "_st3", 0);\ }\ - CODE(opc_##vop, ##vop, ST4, ST3, 1) {\ + CODE(opc_##vop, ##vop, ST4, ST3, OPC_SIGNAL) {\ MONITOR(%edx, FUNCNAME, METAVM_FUNCNAME, #vop "_st4", 3);\ } @@ -4998,23 +5002,23 @@ MULTIANEWARRAY_TEST(STATE);\ asm("movl %eax," #DST_REG) - CODE(opc_multianewarray, multianewarray, ST0, ST1, 0) { + CODE(opc_multianewarray, multianewarray, ST0, ST1, OPC_THROW) { MULTIANEWARRAY_ST0(%edx, "multianewarray_st0", 0); } - CODE(opc_multianewarray, multianewarray, ST1, ST1, 0) { + CODE(opc_multianewarray, multianewarray, ST1, ST1, OPC_THROW) { asm("pushl %edx"); /* now state 0 */ MULTIANEWARRAY_ST0(%edx, "multianewarray_st1", 1); } - CODE(opc_multianewarray, multianewarray, ST2, ST1, 0) { + CODE(opc_multianewarray, multianewarray, ST2, ST1, OPC_THROW) { asm("pushl %edx\n\t" "pushl %ecx"); /* now state 0 */ MULTIANEWARRAY_ST0(%edx, "multianewarray_st2", 2); } - CODE(opc_multianewarray, multianewarray, ST3, ST1, 0) { + CODE(opc_multianewarray, multianewarray, ST3, ST1, OPC_THROW) { asm("pushl %ecx"); /* now state 0 */ MULTIANEWARRAY_ST0(%edx, "multianewarray_st3", 3); } - CODE(opc_multianewarray, multianewarray, ST4, ST1, 0) { + CODE(opc_multianewarray, multianewarray, ST4, ST1, OPC_THROW) { asm("pushl %ecx\n\t" "pushl %edx"); /* now state 0 */ MULTIANEWARRAY_ST0(%edx, "multianewarray_st4", 4); @@ -5038,23 +5042,23 @@ "leal (%esp,%edi,4),%esp") #define CODE_INVOKEIGNORED(suffix, SUFFIX) \ - CODE(opc_invokeignored_##suffix, invokeignored_##suffix, ST0, ST0, 0) {\ + CODE(opc_invokeignored_##suffix, invokeignored_##suffix, ST0, ST0, OPC_THROW) {\ INVOKEIGNORED_##SUFFIX##_ST0(0);\ }\ - CODE(opc_invokeignored_##suffix, invokeignored_##suffix, ST1, ST0, 0) {\ + CODE(opc_invokeignored_##suffix, invokeignored_##suffix, ST1, ST0, OPC_THROW) {\ asm("pushl %edx"); /* now state 0 */\ INVOKEIGNORED_##SUFFIX##_ST0(1);\ }\ - CODE(opc_invokeignored_##suffix, invokeignored_##suffix, ST2, ST0, 0) {\ + CODE(opc_invokeignored_##suffix, invokeignored_##suffix, ST2, ST0, OPC_THROW) {\ asm("pushl %edx\n\t"\ "pushl %ecx"); /* now state 0 */\ INVOKEIGNORED_##SUFFIX##_ST0(2);\ }\ - CODE(opc_invokeignored_##suffix, invokeignored_##suffix, ST3, ST0, 0) {\ + CODE(opc_invokeignored_##suffix, invokeignored_##suffix, ST3, ST0, OPC_THROW) {\ asm("pushl %ecx"); /* now state 0 */\ INVOKEIGNORED_##SUFFIX##_ST0(3);\ }\ - CODE(opc_invokeignored_##suffix, invokeignored_##suffix, ST4, ST0, 0) {\ + CODE(opc_invokeignored_##suffix, invokeignored_##suffix, ST4, ST0, OPC_THROW) {\ asm("pushl %ecx\n\t"\ "pushl %edx"); /* now state 0 */\ INVOKEIGNORED_##SUFFIX##_ST0(4);\ diff -aruN shujit-0.3.8/compile.c shujit/compile.c --- shujit-0.3.8/compile.c Fri Aug 27 01:54:01 1999 +++ shujit/compile.c Wed Sep 8 00:06:29 1999 @@ -54,8 +54,8 @@ */ static int makePCTable(CompilerContext *cc); -static int processAnOpcode(CompilerContext *cc, int opcode, - int *statep, int32_t *byteoffp); +static int processAnOpcode(CompilerContext *cc, int opcode, int32_t *byteoffp); +static void updateStates(CompilerContext *cc); static int writeCode(CompilerContext *cc); static void resolveJumpInstructions(CompilerContext *cc); static void resolveExcRetSw(CompilerContext *cc); @@ -73,31 +73,44 @@ int compileMethod(struct methodblock *mb) { CompilerContext *cc; CodeInfo *info = (CodeInfo *)mb->CompiledCodeInfo; +#ifdef COMPILE_DEBUG + int compile_debug; +#endif if (!info) { printf("WARNING: method->CompiledCodeInfo is NULL. (compileMethod())\n"); fflush(stdout); } + cc = getCompilerContext(mb); #ifdef COMPILE_DEBUG - printf("\n"); - printf("compileMethod() called.\n %s#%s %s\n", - cbName(fieldclass(&mb->fb)), mb->fb.name, mb->fb.signature); - { - int acc = mb->fb.access; - printf(" access: 0x%x", acc); - if (acc & ACC_NATIVE) printf(" native"); -/* if (acc & ACC_MACHINE_COMPILED) printf(" machine_compiled");*/ - if (acc & ACC_PUBLIC) printf(" public"); - if (acc & ACC_PRIVATE) printf(" private"); - if (acc & ACC_PROTECTED) printf(" protected"); - if (acc & ACC_STATIC) printf(" static"); - if (acc & ACC_FINAL) printf(" final"); - if (acc & ACC_SYNCHRONIZED) printf(" synchronized"); - if (acc & ACC_ABSTRACT) printf(" abstract"); + compile_debug = cc->compile_debug; + if (compile_debug) { + showCompilerContext(cc); + } +#endif + +#ifdef COMPILE_DEBUG + if (compile_debug) { printf("\n"); + printf("cmlMtd() called.\n %s#%s %s\n", + cbName(fieldclass(&mb->fb)), mb->fb.name, mb->fb.signature); + { + int acc = mb->fb.access; + printf(" access: 0x%x", acc); + if (acc & ACC_NATIVE) printf(" native"); +/* if (acc & ACC_MACHINE_COMPILED) printf(" machine_compiled");*/ + if (acc & ACC_PUBLIC) printf(" public"); + if (acc & ACC_PRIVATE) printf(" private"); + if (acc & ACC_PROTECTED) printf(" protected"); + if (acc & ACC_STATIC) printf(" static"); + if (acc & ACC_FINAL) printf(" final"); + if (acc & ACC_SYNCHRONIZED) printf(" synchronized"); + if (acc & ACC_ABSTRACT) printf(" abstract"); + printf("\n"); + } + fflush(stdout); } - fflush(stdout); #endif @@ -108,11 +121,6 @@ } - cc = getCompilerContext(mb); -#ifdef COMPILE_DEBUG - showCompilerContext(cc); -#endif - #ifdef CODE_DB if (OPT_SETQ(OPT_CODEDB)) { if (readCompiledCode(db, db_page, cc)) @@ -121,8 +129,9 @@ #endif /* CODE_DB */ /* compile */ - if (makePCTable(cc)) goto compile_failed; /* an exception occurred. */ - if (writeCode(cc)) goto compile_failed; /* an exception occurred. */ + if (makePCTable(cc)) goto compile_failed; + updateStates(cc); + if (writeCode(cc)) goto compile_failed; resolveJumpInstructions(cc); resolveExcRetSw(cc); @@ -130,8 +139,10 @@ { int code_size = cc->bufp - cc->buffer; #ifdef COMPILE_DEBUG - printf("compileMethod(): generated code size = 0x%x(%d)\n", + if (compile_debug) { + printf("cmplMtd(): generated code size = 0x%x(%d)\n", code_size, code_size); + } #endif info->code_size = code_size; @@ -141,8 +152,10 @@ mb->CompiledCode = code; } #ifdef COMPILE_DEBUG - printf(" mb->CompiledCode: 0x%08x\n", (int)mb->CompiledCode); - fflush(stdout); + if (compile_debug) { + printf(" mb->CompiledCode: 0x%08x\n", (int)mb->CompiledCode); + fflush(stdout); + } #endif } @@ -249,10 +262,12 @@ #ifdef COMPILE_DEBUG - printf("compileMethod() done.\n %s#%s %s\n", + if (compile_debug) { + printf("cmplMtd() done.\n %s#%s %s\n", cbName(fieldclass(&mb->fb)), mb->fb.name, mb->fb.signature); - printf(" CompiledCode: 0x%08x\n", (int)mb->CompiledCode); - fflush(stdout); + printf(" code: 0x%08x\n", (int)mb->CompiledCode); + fflush(stdout); + } #endif return 0; @@ -280,7 +295,7 @@ * Freeing method related stuffs. */ void freeMethod(struct methodblock *mb) { - void *info, *code; + void *code; #ifdef COMPILE_DEBUG printf("freeMethod(): "); if (mb) @@ -320,24 +335,26 @@ int remaked = 0; /* makePCTable() is retried once at least */ int opcode; - int state = 0; +#ifdef COMPILE_DEBUG + int compile_debug = cc->compile_debug; +#endif makepctable_start: dummy_byteoff = -1; - if (processAnOpcode(cc, opc_methodhead, &state, &dummy_byteoff)) + if (processAnOpcode(cc, opc_methodhead, &dummy_byteoff)) return 1; if (!is_fpupc_double && (OPT_SETQ(OPT_FRCSTRICTFP) || (!OPT_SETQ(OPT_IGNSTRICTFP) && (mb->fb.access & ACC_STRICT)))) { - if (processAnOpcode(cc, opc_strictenter, &state, &dummy_byteoff)) + if (processAnOpcode(cc, opc_strictenter, &dummy_byteoff)) return 1; - if (processAnOpcode(cc, opc_fppc_double, &state, &dummy_byteoff)) + if (processAnOpcode(cc, opc_fppc_double, &dummy_byteoff)) return 1; } if (mb->fb.access & ACC_SYNCHRONIZED) - if (processAnOpcode(cc, opc_syncenter, &state, &dummy_byteoff)) + if (processAnOpcode(cc, opc_syncenter, &dummy_byteoff)) return 1; while (byteoff < endoff) { @@ -347,38 +364,38 @@ switch (opcode) { case opc_iaload: case opc_laload: case opc_faload: case opc_daload: case opc_aaload: case opc_baload: case opc_caload: case opc_saload: - if (processAnOpcode(cc, opc_fill_cache, &state, &byteoff)) + if (processAnOpcode(cc, opc_fill_cache, &byteoff)) return 1; - if (processAnOpcode(cc, opc_array_check, &state, &byteoff)) + if (processAnOpcode(cc, opc_array_check, &byteoff)) return 1; - if (processAnOpcode(cc, opcode, &state, &byteoff)) + if (processAnOpcode(cc, opcode, &byteoff)) return 1; break; case opc_lstore: case opc_dstore: - if (processAnOpcode(cc, opc_fill_cache, &state, &byteoff)) + if (processAnOpcode(cc, opc_fill_cache, &byteoff)) return 1; - if (processAnOpcode(cc, opcode, &state, &byteoff)) + if (processAnOpcode(cc, opcode, &byteoff)) return 1; break; case opc_iastore: case opc_fastore: case opc_aastore: case opc_bastore: case opc_castore: case opc_sastore: - if (processAnOpcode(cc, opc_iastore1, &state, &byteoff)) + if (processAnOpcode(cc, opc_iastore1, &byteoff)) return 1; - if (processAnOpcode(cc, opc_fill_cache, &state, &byteoff)) + if (processAnOpcode(cc, opc_fill_cache, &byteoff)) return 1; - if (processAnOpcode(cc, opc_array_check, &state, &byteoff)) + if (processAnOpcode(cc, opc_array_check, &byteoff)) return 1; - if (processAnOpcode(cc, opcode, &state, &byteoff)) + if (processAnOpcode(cc, opcode, &byteoff)) return 1; break; case opc_lastore: case opc_dastore: - if (processAnOpcode(cc, opc_fill_cache, &state, &byteoff)) + if (processAnOpcode(cc, opc_fill_cache, &byteoff)) return 1; - if (processAnOpcode(cc, opcode, &state, &byteoff)) + if (processAnOpcode(cc, opcode, &byteoff)) return 1; break; default: - if (processAnOpcode(cc, opcode, &state, &byteoff)) + if (processAnOpcode(cc, opcode, &byteoff)) return 1; break; } @@ -388,10 +405,12 @@ /* The method being compiled is called. */ /* It's possible that bytecode of the method is changed ! */ #ifdef COMPILE_DEBUG - printf("restart makePCTable()\n" - " because the method is called during being compiled: %s#%s %s\n", - cbName(mb->fb.clazz), mb->fb.name, mb->fb.signature); - fflush(stdout); + if (compile_debug) { + printf("restart makePCTable()\n" + " because the method is called during being compiled: %s#%s %s\n", + cbName(mb->fb.clazz), mb->fb.name, mb->fb.signature); + fflush(stdout); + } #endif byteoff = 0; @@ -405,34 +424,50 @@ dummy_byteoff = ~(1 << 31); /* exception handler */ + if (cc->may_throw) { + if (processAnOpcode(cc, opc_exc_new, &dummy_byteoff)) + return 1; + } +#ifdef COMPILE_DEBUG + else { + if (compile_debug) { + printf("exc_new omitted: %s#%s %s\n", + cbName(mb->fb.clazz), mb->fb.name, mb->fb.signature); + fflush(stdout); + } + } +#endif + if (mb->exception_table_length > 0) { - if (processAnOpcode(cc, opc_exc_handler, &state, &dummy_byteoff)) + if (processAnOpcode(cc, opc_exc_handler, &dummy_byteoff)) return 1; } #ifdef COMPILE_DEBUG else { - printf("exc handler omitted: %s#%s %s\n", + if (compile_debug) { + printf("exc_handler omitted: %s#%s %s\n", cbName(mb->fb.clazz), mb->fb.name, mb->fb.signature); - fflush(stdout); + fflush(stdout); + } } #endif /* method tail */ - if (processAnOpcode(cc, opc_epilogue, &state, &dummy_byteoff)) + if (processAnOpcode(cc, opc_epilogue, &dummy_byteoff)) return 1; if (mb->fb.access & ACC_SYNCHRONIZED) - if (processAnOpcode(cc, opc_syncexit, &state, &dummy_byteoff)) + if (processAnOpcode(cc, opc_syncexit, &dummy_byteoff)) return 1; if (!is_fpupc_double && (OPT_SETQ(OPT_FRCSTRICTFP) || (!OPT_SETQ(OPT_IGNSTRICTFP) && (mb->fb.access & ACC_STRICT)))) { - if (processAnOpcode(cc, opc_strictexit, &state, &dummy_byteoff)) + if (processAnOpcode(cc, opc_strictexit, &dummy_byteoff)) return 1; } - if (processAnOpcode(cc, opc_methodtail, &state, &dummy_byteoff)) + if (processAnOpcode(cc, opc_methodtail, &dummy_byteoff)) return 1; return 0; @@ -443,24 +478,27 @@ * returns: true if an exception occurred. */ static int processAnOpcode(CompilerContext *cc, int opcode, - int *statep, int32_t *byteoffp) { - int state = *statep; - + int32_t *byteoffp) { struct methodblock *mb = cc->mb; + CodeInfo *info = (CodeInfo *)mb->CompiledCodeInfo; cp_item_type *constant_pool = cbConstantPool(fieldclass(&mb->fb)); unsigned char *type_table = constant_pool[CONSTANT_POOL_TYPE_TABLE_INDEX].type; unsigned char *bytepc = mb->code + *byteoffp; int code_opcode; - CodeTable *codep; +#ifdef COMPILE_DEBUG + int compile_debug = cc->compile_debug; +#endif #ifdef COMPILE_DEBUG - printf("procAnOpc(): %s(0x%02x,%d) st:%d\n", + if (compile_debug) { + printf("procOpc(): %s(0x%02x,%d)\n", ((opcode > opc_nonnull_quick) ? "(null)" : opcode_symbol[opcode]), - opcode, opcode, state); - printf(" b off: 0x%x(%d)\n", *byteoffp, *byteoffp); - fflush(stdout); + opcode, opcode); + printf(" b off: 0x%x(%d)\n", *byteoffp, *byteoffp); + fflush(stdout); + } #endif if (!mb->code) { @@ -662,6 +700,29 @@ } } + /* throwing IllegalAccessError if putfield or putstatic to final field */ + if ((code_opcode == opc_putfield) || (code_opcode == opc_putfield2) || + (code_opcode == opc_putstatic) || (code_opcode == opc_putstatic2)) { + if ((opcode == opc_putfield_quick) || (opcode == opc_putfield2_quick) || + (opcode == opc_putstatic_quick) || (opcode == opc_putstatic2_quick)) { +#ifdef COMPILE_DEBUG + printf( + "putfield*_quick found. cannot get an index of constant pool.\n"); + fflush(stdout); +#endif + } + else { /* ..field, ..field_quick_w */ + /* the field must be already resolved above */ + int index = GET_UINT16(bytepc + 1); + struct fieldblock *fb = constant_pool[index].fb; + + if (fb->access & ACC_FINAL) { + struct methodblock *src_mb = cc->mb; + if (!src_mb || (fieldclass(&src_mb->fb) != fieldclass(fb))) + code_opcode = opc_throw_illegalaccess; + } + } + } #ifdef SPECIAL_INLINING /* special inlining */ @@ -680,7 +741,9 @@ if (!strcmp(cbName(fieldclass(&method->fb)), "java/lang/Math")) { char *mname = method->fb.name; # ifdef COMPILE_DEBUG - printf(" invocation of a method of java.lang.Math#%s.\n", mname); + if (compile_debug) { + printf(" invocation of a method of java.lang.Math#%s.\n", mname); + } # endif if (!strcmp(mname, "sqrt")) code_opcode = opc_sqrt; else if (!strcmp(mname, "sin")) code_opcode = opc_sin; @@ -698,28 +761,32 @@ #if 1 - /* adjust to invokespecial if invokevirtual private method */ + /* translate invokevirtual to invokespecial */ if (opcode == opc_invokevirtual) { unsigned index = GET_UINT16(bytepc + 1); struct methodblock *method; if (!CONSTANT_POOL_TYPE_TABLE_IS_RESOLVED(type_table, index)) { int res_result; #if COMPILE_DEBUG - printf(" resolving cp[%d] type: %d.\n", index, + if (compile_debug) { + printf(" resolving cp[%d] type: %d.\n", index, CONSTANT_POOL_TYPE_TABLE_GET_TYPE(type_table, index)); - fflush(stdout); + fflush(stdout); + } #endif res_result = ResolveClassConstantFromClass2(fieldclass(&mb->fb), index, cc->ee, 1 << CONSTANT_Methodref, FALSE); #if COMPILE_DEBUG - printf(" resolving cp[%d] done.\n", index); - if (exceptionOccurred(cc->ee)) { - JHandle *exc = cc->ee->exception.exc; - printf("exception occurred: %s\n", + if (compile_debug) { + printf(" resolving cp[%d] done.\n", index); + if (exceptionOccurred(cc->ee)) { + JHandle *exc = cc->ee->exception.exc; + printf("exception occurred: %s\n", cbName(exc->methods->classdescriptor)); - showExcStackTrace(exc); + showExcStackTrace(exc); + } + fflush(stdout); } - fflush(stdout); #endif if (!res_result) return 1; } @@ -727,7 +794,9 @@ if (method->fb.access & (ACC_PRIVATE | ACC_FINAL)) { #ifdef COMPILE_DEBUG - printf(" adjust invokevirtual private method to invokespecial.\n"); + if (compile_debug) { + printf(" adjust invokevirtual private method to invokespecial.\n"); + } #endif code_opcode = opc_invokespecial; } @@ -746,21 +815,25 @@ if (!CONSTANT_POOL_TYPE_TABLE_IS_RESOLVED(type_table, index)) { int res_result; #if COMPILE_DEBUG - printf(" resolving cp[%d] type: %d.\n", index, + if (compile_debug) { + printf(" resolving cp[%d] type: %d.\n", index, CONSTANT_POOL_TYPE_TABLE_GET_TYPE(type_table, index)); - fflush(stdout); + fflush(stdout); + } #endif res_result = ResolveClassConstantFromClass2(fieldclass(&mb->fb), index, cc->ee, 1 << CONSTANT_Methodref, FALSE); #if COMPILE_DEBUG - printf(" resolving cp[%d] done.\n", index); - if (exceptionOccurred(cc->ee)) { - JHandle *exc = cc->ee->exception.exc; - printf("exception occurred: %s\n", + if (compile_debug) { + printf(" resolving cp[%d] done.\n", index); + if (exceptionOccurred(cc->ee)) { + JHandle *exc = cc->ee->exception.exc; + printf("exception occurred: %s\n", cbName(exc->methods->classdescriptor)); - showExcStackTrace(exc); + showExcStackTrace(exc); + } + fflush(stdout); } - fflush(stdout); #endif if (!res_result) return 1; } @@ -797,25 +870,28 @@ #ifdef COMPILE_DEBUG - if (code_opcode != opcode) { - printf(" adj opc 0x%02x(%d) to 0x%02x(%d)\n", + if (compile_debug) { + if (code_opcode != opcode) { + printf(" adj opc 0x%02x(%d) to 0x%02x(%d)\n", opcode, opcode, code_opcode, code_opcode); - fflush(stdout); + fflush(stdout); + } } #endif /* register opcode, bytepc, state to the table */ - pctableAdd(cc, code_opcode, state, *byteoffp, -1); - codep = &code_table[code_opcode][state]; -#ifdef COMPILE_DEBUG - printf(" next st:%d\n", codep->last_state); fflush(stdout); -#endif + pctableAdd(cc, code_opcode, -1, *byteoffp, -1); + + /* confirm whether the method may throw an exception */ + /* cc->may_throw should be initialized in execution of makePCTable() */ + { + CodeTable *codep = &code_table[code_opcode][0]; + if (((unsigned char *)assembledCode + codep->offset)[-1] & OPC_THROW_MASK) + cc->may_throw = TRUE; + } - /* - * update bytecode PC and state - */ /* update bytecode PC */ if (opcode <= opc_nonnull_quick) { @@ -851,26 +927,63 @@ } /* switch (opcode) */ } /* if (opcode <= opc_nonnull_quick) */ + return 0; +} - /* update state */ - state = codep->last_state; - if (state != STSTA) { - switch (code_opcode) { + +static void updateStates(CompilerContext *cc) { + pcentry *pctable; + int pctablelen = cc->pctablelen; + CodeTable *codep; + int opcode; + int state; + int i; +#ifdef COMPILE_DEBUG + int compile_debug = cc->compile_debug; +#endif + +#ifdef COMPILE_DEBUG + if (compile_debug) { + printf("updateStates():\n"); + } +#endif + state = 0; + for (i = 0; i < pctablelen; i++) { + pctable = cc->pctable + i; + opcode = pctable->opcode; + codep = &code_table[opcode][state]; + + pctable->state = state; +#ifdef COMPILE_DEBUG + if (compile_debug) { + printf(" %s(0x%02x,%d)\tst:%d\n", + ((opcode > opc_nonnull_quick) ? "(null)" : opcode_symbol[opcode]), + opcode, opcode, state); + } +#endif + + if (codep->last_state != STSTA) { + switch (opcode) { /* jump instructions */ - case opc_goto: - case opc_jsr: - case opc_ret: - case opc_tableswitch: - case opc_lookupswitch: - *statep = STATE_AFTER_JUMP; - break; - default: - *statep = state; - break; + case opc_goto: + case opc_jsr: + case opc_ret: + case opc_tableswitch: + case opc_lookupswitch: + state = STATE_AFTER_JUMP; + break; + default: + state = codep->last_state; + break; + } } } - - return 0; +#ifdef COMPILE_DEBUG + if (compile_debug) { + printf("updateStates() done\n"); + fflush(stdout); + } +#endif } @@ -878,8 +991,14 @@ struct CatchFrame_w_state *cf; int i; #ifdef COMPILE_DEBUG - printf("makeExcTable() called.\n"); - fflush(stdout); + int compile_debug = cc->compile_debug; +#endif + +#ifdef COMPILE_DEBUG + if (compile_debug) { + printf("makeExcTable() called.\n"); + fflush(stdout); + } #endif cf = (CatchFrame_w_state *)cc->mb->exception_table; @@ -893,8 +1012,10 @@ cf++; } #ifdef COMPILE_DEBUG - printf("makeExcTable() done.\n"); - fflush(stdout); + if (compile_debug) { + printf("makeExcTable() done.\n"); + fflush(stdout); + } #endif } @@ -915,10 +1036,16 @@ CodeTable *codep; unsigned char *bufp; int insn_head_off; #ifdef COMPILE_DEBUG - printf("writeCode called: %s#%s %s.\n", + int compile_debug = cc->compile_debug; +#endif + +#ifdef COMPILE_DEBUG + if (compile_debug) { + printf("writeCode called: %s#%s %s.\n", cbName(mb->fb.clazz), mb->fb.name, mb->fb.signature); - printf(" type_table: 0x%x\n", (int)type_table); - fflush(stdout); + printf(" type_table: 0x%x\n", (int)type_table); + fflush(stdout); + } #endif for (i = 0; i < cc->pctablelen; i++) { @@ -928,23 +1055,28 @@ bytepc = mb->code + pctable->byteoff; #ifdef COMPILE_DEBUG - printf("writeCode(): %s(0x%02x,%d) st:%d\n", + if (compile_debug) { + printf("writeCode(): %s(0x%02x,%d) st:%d\n", ((opcode > opc_nonnull_quick) ? "(null)" : opcode_symbol[opcode]), opcode, opcode, state); - printf(" off: b 0x%x(%d) n 0x%x(%d)\n", + printf(" off: b 0x%x(%d) n 0x%x(%d)\n", pctable->byteoff, pctable->byteoff, nativeoff, nativeoff); - fflush(stdout); + fflush(stdout); + } #endif codep = &code_table[opcode][state]; #ifdef COMPILE_DEBUG - printf(" len native: 0x%x(%d)\n", codep->length, codep->length); - fflush(stdout); + if (compile_debug) { + printf(" len native: 0x%x(%d)\n", codep->length, codep->length); + fflush(stdout); + } #endif - if (opcode == opc_exc_handler) { - info->exc_handler_nativeoff = nativeoff; + if ((opcode == opc_exc_new) || (opcode == opc_exc_handler)) { + if (!(info->exc_handler_nativeoff)) /* not established yet */ + info->exc_handler_nativeoff = nativeoff; } else if (opcode == opc_epilogue) { info->finish_return_nativeoff = nativeoff; @@ -963,15 +1095,17 @@ pctable->nativeoff = nativeoff; #ifdef EXC_BY_SIGNAL - if (nativecode[-1]) { - /* these native code may throw - NullPointerException or ArithmeticException */ + /* treat throw table */ + if (nativecode[-1] & OPC_SIGNAL_MASK) { + /* these native code may send SIGSEGV or SIGFPE */ throwtableAdd(info, nativeoff, (uint16_t)codep->length, - (unsigned char)pctable->byteoff, (unsigned char)opcode); + (unsigned char)pctable->byteoff, (unsigned char)opcode); #ifdef COMPILE_DEBUG - printf("throwtableAdd(): opc %x, byte 0x%x, native 0x%x - 0x%x\n", - opcode, pctable->byteoff, nativeoff, nativeoff + codep->length); - fflush(stdout); + if (compile_debug) { + printf("throwtableAdd(): opc %x, byte 0x%x, native 0x%x - 0x%x\n", + opcode, pctable->byteoff, nativeoff, nativeoff + codep->length); + fflush(stdout); + } #endif } #endif /* EXC_BY_SIGNAL */ @@ -994,10 +1128,12 @@ if (last_state == STSTA) last_state = state; #ifdef COMPILE_DEBUG - printf(" jump instruction: %s(0x%x,%d)\n", + if (compile_debug) { + printf(" jump instruction: %s(0x%x,%d)\n", opcode_symbol[*bytepc], *bytepc, *bytepc); - printf(" last state: %d\n", last_state); - fflush(stdout); + printf(" last state: %d\n", last_state); + fflush(stdout); + } #endif if (opcode == opc_ret) { tgtstate = STATE_AFTER_JUMP; @@ -1014,7 +1150,7 @@ tgttable = pctableGet(cc, tgtoff); tgtstate = tgttable->state; #ifdef COMPILE_DEBUG - { + if (compile_debug) { int tgtop = tgttable->opcode; printf(" target %s(0x%x,%d) offset: 0x%x(%d), state: %d\n", ((tgtop > opc_nonnull_quick)?"(null)":opcode_symbol[tgtop]), @@ -1117,19 +1253,25 @@ case opc_bipush: v = (signed char)bytepc[1]; #ifdef COMPILE_DEBUG - printf(" const: %d\n", v); fflush(stdout); + if (compile_debug) { + printf(" const: %d\n", v); fflush(stdout); + } #endif break; case opc_sipush: v = GET_INT16(bytepc + 1); #ifdef COMPILE_DEBUG - printf(" const: %d\n", v); fflush(stdout); + if (compile_debug) { + printf(" const: %d\n", v); fflush(stdout); + } #endif break; case opc_ldc: v = bytepc[1]; #ifdef COMPILE_DEBUG - printf(" index: %d\n", v); fflush(stdout); + if (compile_debug) { + printf(" index: %d\n", v); fflush(stdout); + } #endif if (!CONSTANT_POOL_TYPE_TABLE_IS_RESOLVED(type_table, v)) if (!ResolveClassConstantFromClass2(fieldclass(&mb->fb), v, cc->ee, @@ -1145,7 +1287,9 @@ case opc_ldc_w: v = GET_UINT16(bytepc + 1); #ifdef COMPILE_DEBUG - printf(" index: %d\n", v); fflush(stdout); + if (compile_debug) { + printf(" index: %d\n", v); fflush(stdout); + } #endif if (!CONSTANT_POOL_TYPE_TABLE_IS_RESOLVED(type_table, v)) if (!ResolveClassConstantFromClass2(fieldclass(&mb->fb), v, cc->ee, @@ -1161,7 +1305,9 @@ case opc_ldc_quick: v = bytepc[1]; #ifdef COMPILE_DEBUG - printf(" index: %d\n", v); fflush(stdout); + if (compile_debug) { + printf(" index: %d\n", v); fflush(stdout); + } #endif if (CONSTANT_POOL_TYPE_TABLE_GET_TYPE(type_table, v) == CONSTANT_String) @@ -1171,7 +1317,9 @@ case opc_ldc_w_quick: v = GET_UINT16(bytepc + 1); #ifdef COMPILE_DEBUG - printf(" index: %d\n", v); fflush(stdout); + if (compile_debug) { + printf(" index: %d\n", v); fflush(stdout); + } #endif if (CONSTANT_POOL_TYPE_TABLE_GET_TYPE(type_table, v) == CONSTANT_String) @@ -1193,7 +1341,9 @@ int32_t cp_entry1 = constant_pool[index].i; int32_t cp_entry2 = constant_pool[index + 1].i; #ifdef COMPILE_DEBUG - printf(" index: %d\n", index); fflush(stdout); + if (compile_debug) { + printf(" index: %d\n", index); fflush(stdout); + } #endif if (*bytepc == opc_ldc2_w) { @@ -1222,7 +1372,9 @@ else index = bytepc[1]; #ifdef COMPILE_DEBUG - printf(" index: %d\n", index); fflush(stdout); + if (compile_debug) { + printf(" index: %d\n", index); fflush(stdout); + } #endif #ifdef RUNTIME_DEBUG memcpy(bufp + constant_table[opcode][state][1], &index, 4); @@ -1241,7 +1393,9 @@ else index = bytepc[1]; #ifdef COMPILE_DEBUG - printf(" index: %d\n", index); fflush(stdout); + if (compile_debug) { + printf(" index: %d\n", index); fflush(stdout); + } #endif index = (index + 1) * -4; memcpy(bufp + constant_table[opcode][state][0], &index, 4); @@ -1299,7 +1453,9 @@ constbyte = ((signed char *)bytepc)[2]; } #ifdef COMPILE_DEBUG - printf(" vars[%d] += %d\n", index, constbyte); fflush(stdout); + if (compile_debug) { + printf(" vars[%d] += %d\n", index, constbyte); fflush(stdout); + } #endif index *= -4; #ifdef RUNTIME_DEBUG @@ -1319,8 +1475,10 @@ case opc_jsr: #ifdef COMPILE_DEBUG - printf(" next native offset: 0x%x(%d)\n", nextoff, nextoff); - fflush(stdout); + if (compile_debug) { + printf(" next native offset: 0x%x(%d)\n", nextoff, nextoff); + fflush(stdout); + } #endif memcpy(bufp + constant_table[opcode][state][0], &nextoff, 4); break; @@ -1331,7 +1489,9 @@ int32_t l = (int32_t)ntohl((unsigned long)argp[1]); int32_t h = (int32_t)ntohl((unsigned long)argp[2]); #ifdef COMPILE_DEBUG - printf(" low: %d, high: %d\n", l, h); fflush(stdout); + if (compile_debug) { + printf(" low: %d, high: %d\n", l, h); fflush(stdout); + } #endif memcpy(bufp + constant_table[opcode][state][0], &l, 4); memcpy(bufp + constant_table[opcode][state][1], &h, 4); @@ -1343,7 +1503,9 @@ int32_t *argp = (int32_t *)ALIGNUP32(bytepc + 1); int32_t npairs = (int32_t)ntohl((unsigned long)argp[1]); #ifdef COMPILE_DEBUG - printf(" npairs: %d\n", npairs); fflush(stdout); + if (compile_debug) { + printf(" npairs: %d\n", npairs); fflush(stdout); + } #endif memcpy(bufp + constant_table[opcode][state][0], &npairs, 4); } @@ -1351,9 +1513,14 @@ #ifdef COMPILE_DEBUG # define CONST_GETMEMBER_DEBUG1 \ - printf(" %s#%s\n", cbName(fb->clazz), fb->name);\ - fflush(stdout) -# define CONST_GETMEMBER_DEBUG2 printf(" slot: %d\n", slot); fflush(stdout) + if (compile_debug) {\ + printf(" %s#%s\n", cbName(fb->clazz), fb->name);\ + fflush(stdout);\ + } +# define CONST_GETMEMBER_DEBUG2 \ + if (compile_debug) {\ + printf(" slot: %d\n", slot); fflush(stdout);\ + } #else # define CONST_GETMEMBER_DEBUG1 # define CONST_GETMEMBER_DEBUG2 @@ -1436,25 +1603,31 @@ #ifdef COMPILE_DEBUG # define WC_CONST_INVOKE_DEBUG1() \ - printf(" not resolved yet.\n"); fflush(stdout) + if (compile_debug) {\ + printf(" not resolved yet.\n"); fflush(stdout);\ + } # define WC_CONST_INVOKE_DEBUG2() \ - method = constant_pool[index].mb;\ - printf(" clz initialized: %s\n",\ + if (compile_debug) {\ + method = constant_pool[index].mb;\ + printf(" clz initialized: %s\n",\ (CB_INITIALIZED(method->fb.clazz) ? "true" : "false"));\ - if (!(method->CompiledCodeInfo)) {\ - printf(" WARNING: method->CompiledCodeInfo is NULL. (writeCode())\n");\ - fflush(stdout);\ + if (!(method->CompiledCodeInfo)) {\ + printf(" WARNING: method->CompiledCodeInfo is NULL. (writeCode())\n");\ + fflush(stdout);\ + }\ } # define WC_CONST_INVOKE_DEBUG3(VIRTUALP) \ - printf(" %s#%s %s\n", cbName(method->fb.clazz), method->fb.name,\ + if (compile_debug) {\ + printf(" %s#%s %s\n", cbName(method->fb.clazz), method->fb.name,\ method->fb.signature);\ - fflush(stdout);\ - printf(" args_size, ret_size, localvar_space: %d, %d, %d\n",\ + fflush(stdout);\ + printf(" args_size, ret_size, localvar_space: %d, %d, %d\n",\ args_size, ret_size, localvar_space);\ - fflush(stdout);\ - if (VIRTUALP)\ - printf(" offset in table: %d\n", method->fb.u.offset);\ - fflush(stdout) + fflush(stdout);\ + if (VIRTUALP)\ + printf(" offset in table: %d\n", method->fb.u.offset);\ + fflush(stdout);\ + } #else # define WC_CONST_INVOKE_DEBUG1() # define WC_CONST_INVOKE_DEBUG2() @@ -1544,7 +1717,9 @@ { int32_t type = bytepc[1]; #ifdef COMPILE_DEBUG - printf(" type: %d\n", type); fflush(stdout); + if (compile_debug) { + printf(" type: %d\n", type); fflush(stdout); + } #endif memcpy(bufp + constant_table[opcode][state][0], &type, 4); } @@ -1554,8 +1729,10 @@ { int32_t dimensions = bytepc[3]; #ifdef COMPILE_DEBUG - printf(" index: %d\n dimensions: %d\n", index, dimensions); - fflush(stdout); + if (compile_debug) { + printf(" index: %d\n dimensions: %d\n", index, dimensions); + fflush(stdout); + } #endif memcpy(bufp + constant_table[opcode][state][0], &dimensions, 4); } @@ -1565,7 +1742,9 @@ { int32_t args_size = bytepc[1]; #ifdef COMPILE_DEBUG - printf(" args_size: %d\n", args_size); fflush(stdout); + if (compile_debug) { + printf(" args_size: %d\n", args_size); fflush(stdout); + } #endif memcpy(bufp + constant_table[opcode][state][0], &args_size, 4); } @@ -1584,10 +1763,12 @@ method = constant_pool[index].mb; args_size = method->args_size; #ifdef COMPILE_DEBUG - printf(" %s#%s %s\n", cbName(method->fb.clazz), method->fb.name, + if (compile_debug) { + printf(" %s#%s %s\n", cbName(method->fb.clazz), method->fb.name, method->fb.signature); - printf(" args_size: %d\n", args_size); - fflush(stdout); + printf(" args_size: %d\n", args_size); + fflush(stdout); + } #endif #if defined(INITCLASS_IN_COMPILING) || defined(NO_REWRITE) memcpy(bufp + constant_table[opcode][state][0], &args_size, 4); @@ -1603,9 +1784,11 @@ } /* for (i = 0; i < cc->pctablelen; i++) */ #ifdef COMPILE_DEBUG - printf("writeCode done: %s#%s %s.\n", + if (compile_debug) { + printf("writeCode done: %s#%s %s.\n", cbName(mb->fb.clazz), mb->fb.name, mb->fb.signature); - fflush(stdout); + fflush(stdout); + } #endif return 0; } @@ -1626,6 +1809,9 @@ CodeTable *codep; unsigned char *bufp; +#ifdef COMPILE_DEBUG + int compile_debug = cc->compile_debug; +#endif for (i = 0; i < cc->pctablelen; i++) { pctable = cc->pctable + i; @@ -1635,19 +1821,23 @@ nativeoff = pctable->nativeoff; #ifdef COMPILE_DEBUG - printf("resolveDynConst(): %s(0x%02x,%d) st:%d\n", + if (compile_debug) { + printf("resolveDynConst(): %s(0x%02x,%d) st:%d\n", ((opcode > opc_nonnull_quick) ? "(null)" : opcode_symbol[opcode]), opcode, opcode, state); - printf(" off: b 0x%x(%d) n 0x%x(%d)\n", + printf(" off: b 0x%x(%d) n 0x%x(%d)\n", pctable->byteoff, pctable->byteoff, nativeoff, nativeoff); - fflush(stdout); + fflush(stdout); + } #endif codep = &code_table[opcode][state]; #ifdef COMPILE_DEBUG - printf(" len native: 0x%x(%d)\n", codep->length, codep->length); - fflush(stdout); + if (compile_debug) { + printf(" len native: 0x%x(%d)\n", codep->length, codep->length); + fflush(stdout); + } #endif /* resolve constants */ @@ -1666,7 +1856,9 @@ case opc_ldc: v = bytepc[1]; #ifdef COMPILE_DEBUG - printf(" index: %d\n", v); fflush(stdout); + if (compile_debug) { + printf(" index: %d\n", v); fflush(stdout); + } #endif if (!CONSTANT_POOL_TYPE_TABLE_IS_RESOLVED(type_table, v)) if (!ResolveClassConstantFromClass2(fieldclass(&mb->fb), v, cc->ee, @@ -1682,7 +1874,9 @@ case opc_ldc_w: v = GET_UINT16(bytepc + 1); #ifdef COMPILE_DEBUG - printf(" index: %d\n", v); fflush(stdout); + if (compile_debug) { + printf(" index: %d\n", v); fflush(stdout); + } #endif if (!CONSTANT_POOL_TYPE_TABLE_IS_RESOLVED(type_table, v)) if (!ResolveClassConstantFromClass2(fieldclass(&mb->fb), v, cc->ee, @@ -1698,7 +1892,9 @@ case opc_ldc_quick: v = bytepc[1]; #ifdef COMPILE_DEBUG - printf(" index: %d\n", v); fflush(stdout); + if (compile_debug) { + printf(" index: %d\n", v); fflush(stdout); + } #endif if (CONSTANT_POOL_TYPE_TABLE_GET_TYPE(type_table, v) != CONSTANT_String) @@ -1708,7 +1904,9 @@ case opc_ldc_w_quick: v = GET_UINT16(bytepc + 1); #ifdef COMPILE_DEBUG - printf(" index: %d\n", v); fflush(stdout); + if (compile_debug) { + printf(" index: %d\n", v); fflush(stdout); + } #endif if (CONSTANT_POOL_TYPE_TABLE_GET_TYPE(type_table, v) != CONSTANT_String) @@ -1731,7 +1929,9 @@ struct fieldblock *fb; OBJECT *addr; #ifdef COMPILE_DEBUG - printf(" index: %d\n", index); fflush(stdout); + if (compile_debug) { + printf(" index: %d\n", index); fflush(stdout); + } #endif if (!CONSTANT_POOL_TYPE_TABLE_IS_RESOLVED(type_table, index)) { if (!ResolveClassConstantFromClass2( @@ -1742,7 +1942,9 @@ } fb = constant_pool[index].fb; #ifdef COMPILE_DEBUG - printf(" %s#%s\n", cbName(fb->clazz), fb->name); fflush(stdout); + if (compile_debug) { + printf(" %s#%s\n", cbName(fb->clazz), fb->name); fflush(stdout); + } #endif { ClassClass *cb = fb->clazz; @@ -1767,7 +1969,9 @@ struct fieldblock *fb; stack_item *addr; #ifdef COMPILE_DEBUG - printf(" index: %d\n", index); fflush(stdout); + if (compile_debug) { + printf(" index: %d\n", index); fflush(stdout); + } #endif if (!CONSTANT_POOL_TYPE_TABLE_IS_RESOLVED(type_table, index)) { if (!ResolveClassConstantFromClass2( @@ -1778,7 +1982,9 @@ } fb = constant_pool[index].fb; #ifdef COMPILE_DEBUG - printf(" %s#%s\n", cbName(fb->clazz), fb->name); fflush(stdout); + if (compile_debug) { + printf(" %s#%s\n", cbName(fb->clazz), fb->name); fflush(stdout); + } #endif { ClassClass *cb = fb->clazz; @@ -1811,9 +2017,11 @@ #ifdef COMPILE_DEBUG # define RC_CONST_INVOKE_DEBUG1 \ - printf(" %s#%s %s\n", cbName(method->fb.clazz), method->fb.name,\ + if (compile_debug) {\ + printf(" %s#%s %s\n", cbName(method->fb.clazz), method->fb.name,\ method->fb.signature);\ - fflush(stdout) + fflush(stdout);\ + } #else # define RC_CONST_INVOKE_DEBUG1 #endif @@ -1863,8 +2071,14 @@ RC_CONST_INVOKE(interface, 0, 1); #ifdef COMPILE_DEBUG -# define CONST_NEW_DEBUG1 printf(" index: %d\n", index); fflush(stdout); -# define CONST_NEW_DEBUG2 printf(" name: %s\n", cbName(cb)); fflush(stdout); +# define CONST_NEW_DEBUG1 \ + if (compile_debug) {\ + printf(" index: %d\n", index); fflush(stdout);\ + } +# define CONST_NEW_DEBUG2 \ + if (compile_debug) {\ + printf(" name: %s\n", cbName(cb)); fflush(stdout);\ + } #else # define CONST_NEW_DEBUG1 # define CONST_NEW_DEBUG2 @@ -1938,30 +2152,36 @@ if (!CONSTANT_POOL_TYPE_TABLE_IS_RESOLVED(type_table, index)) { int res_result; #if COMPILE_DEBUG - printf(" resolving cp[%d] type: %d.\n", index, + if (compile_debug) { + printf(" resolving cp[%d] type: %d.\n", index, CONSTANT_POOL_TYPE_TABLE_GET_TYPE(type_table, index)); - fflush(stdout); + fflush(stdout); + } #endif res_result = ResolveClassConstantFromClass2( fieldclass(&mb->fb), index, cc->ee, 1 << CONSTANT_Class, FALSE); #if COMPILE_DEBUG - printf(" resolving cp[%d] done.\n", index); - if (exceptionOccurred(cc->ee)) { - JHandle *exc = cc->ee->exception.exc; - printf("exception occurred: %s\n", + if (compile_debug) { + printf(" resolving cp[%d] done.\n", index); + if (exceptionOccurred(cc->ee)) { + JHandle *exc = cc->ee->exception.exc; + printf("exception occurred: %s\n", cbName(exc->methods->classdescriptor)); - showExcStackTrace(exc); + showExcStackTrace(exc); + } + fflush(stdout); } - fflush(stdout); #endif if (!res_result) return 1; } } cb = constant_pool[index].clazz; #ifdef COMPILE_DEBUG - printf(" clazz: %s\n", cbName(cb)); fflush(stdout); + if (compile_debug) { + printf(" clazz: %s\n", cbName(cb)); fflush(stdout); + } #endif memcpy(bufp + constant_table[opcode][state][1], &cb, 4); #if defined(METAVM) && !defined(METAVM_NO_ARRAY) @@ -1986,8 +2206,10 @@ } /* for (i = 0; i < cc->pctablelen; i++) */ #ifdef COMPILE_DEBUG - printf("resolveDynConst() done.\n"); - fflush(stdout); + if (compile_debug) { + printf("resolveDynConst() done.\n"); + fflush(stdout); + } #endif return 0; } @@ -1998,6 +2220,9 @@ jpentry *jptable = cc->jptable; jpentry *jptable_end = jptable + cc->jptablelen; +#ifdef COMPILE_DEBUG + int compile_debug = cc->compile_debug; +#endif while (jptable < jptable_end) { unsigned int argoff = jptable->argoff; @@ -2005,10 +2230,12 @@ unsigned int tgtoff = tgttable->nativeoff; int32_t arg = tgtoff - (argoff + 4); #ifdef COMPILE_DEBUG - printf("resolveJpInst(): arg. offset: 0x%x(%d)\n", argoff, argoff); - printf(" target offset: byte 0x%x(%d), native 0x%x(%d)\n", + if (compile_debug) { + printf("resolveJpInst(): arg. offset: 0x%x(%d)\n", argoff, argoff); + printf(" target offset: byte 0x%x(%d), native 0x%x(%d)\n", jptable->tgtoff, jptable->tgtoff, tgtoff, tgtoff); - fflush(stdout); + fflush(stdout); + } #endif memcpy(nativeCode + argoff, &arg, 4); @@ -2029,12 +2256,15 @@ pcentry *pctable_end = pctable + cc->pctablelen; int i; +#ifdef COMPILE_DEBUG + int compile_debug = cc->compile_debug; +#endif while (pctable < pctable_end) { int opcode = pctable->opcode; int state = pctable->state; #ifdef COMPILE_DEBUG - { + if (compile_debug) { int byteoff = pctable->byteoff; int nativeoff = pctable->nativeoff; @@ -2053,10 +2283,12 @@ uint32_t byteoff = pctable->byteoff; while (bytepc_table[opcode][state][i] > 0) { #ifdef COMPILE_DEBUG - printf(" res. bytecode PC at 0x%x(%d) + %d: 0x%x(%d)\n", + if (compile_debug) { + printf(" res. bytecode PC at 0x%x(%d) + %d: 0x%x(%d)\n", pctable->nativeoff, pctable->nativeoff, bytepc_table[opcode][state][i], byteoff, byteoff); - fflush(stdout); + fflush(stdout); + } #endif memcpy(nativeCode + pctable->nativeoff + bytepc_table[opcode][state][i], &byteoff, 4); @@ -2074,10 +2306,12 @@ arg_off = pctable->nativeoff + jumpexc_table[opcode][state][i]; relative_off = exc_off - (arg_off + 4); #ifdef COMPILE_DEBUG - printf(" res. jump to exc.handler at 0x%x(%d) + %d: 0x%x(%d)\n", + if (compile_debug) { + printf(" res. jump to exc.handler at 0x%x(%d) + %d: 0x%x(%d)\n", pctable->nativeoff, pctable->nativeoff, jumpexc_table[opcode][state][i], exc_off, exc_off); - fflush(stdout); + fflush(stdout); + } #endif memcpy(nativeCode + arg_off, &relative_off, 4); i++; @@ -2094,10 +2328,12 @@ arg_off = pctable->nativeoff + jumpret_table[opcode][state][i]; relative_off = fin_off - (arg_off + 4); #ifdef COMPILE_DEBUG - printf(" res. jump to fin.of method at 0x%x(%d) + %d: 0x%x(%d)\n", + if (compile_debug) { + printf(" res. jump to fin.of method at 0x%x(%d) + %d: 0x%x(%d)\n", pctable->nativeoff, pctable->nativeoff, jumpret_table[opcode][state][i], fin_off, fin_off); - fflush(stdout); + fflush(stdout); + } #endif memcpy(nativeCode + arg_off, &relative_off, 4); i++; @@ -2121,7 +2357,9 @@ int last_state = code_table[opcode][state].last_state; int i; #ifdef COMPILE_DEBUG - printf(" low: %d, high: %d\n", l, h); fflush(stdout); + if (compile_debug) { + printf(" low: %d, high: %d\n", l, h); fflush(stdout); + } #endif cc->bufp = (unsigned char *)ALIGNUP32(cc->bufp); @@ -2144,7 +2382,7 @@ codep = &code_table[opc_goto_st0 + tgttable->state][last_state]; tblp[1] = (int32_t)(((unsigned char *)assembledCode) + codep->offset); #ifdef COMPILE_DEBUG - { + if (compile_debug) { unsigned int boff = byteoff + defoff; printf(" default: byte 0x%x(%d), native 0x%x(%d)\n", boff, boff, tblp[0], tblp[0]); @@ -2162,7 +2400,7 @@ tblp[1] = (int32_t)(((unsigned char *)assembledCode) + codep->offset); #ifdef COMPILE_DEBUG - { + if (compile_debug) { unsigned int boff = byteoff + off; printf(" %3d: offset: byte 0x%x(%d), native 0x%x(%d)\n", l + i, boff, boff, tblp[0], tblp[0]); @@ -2188,7 +2426,9 @@ int last_state = code_table[opcode][state].last_state; #ifdef COMPILE_DEBUG - printf(" npairs: %d\n", npairs); fflush(stdout); + if (compile_debug) { + printf(" npairs: %d\n", npairs); fflush(stdout); + } #endif cc->bufp = (unsigned char *)ALIGNUP32(cc->bufp); @@ -2219,7 +2459,7 @@ tblp[2] = (int32_t)(((unsigned char *)assembledCode) + codep->offset); #ifdef COMPILE_DEBUG - { + if (compile_debug) { unsigned int boff = byteoff + off; printf(" match: %d, offset: byte 0x%x(%d), native 0x%x(%d)\n", match, boff, boff, tblp[1], tblp[1]); @@ -2237,7 +2477,7 @@ codep = &code_table[opc_goto_st0 + tgttable->state][last_state]; tblp[2] = (int32_t)(((unsigned char *)assembledCode) + codep->offset); #ifdef COMPILE_DEBUG - { + if (compile_debug) { unsigned int boff = byteoff + defoff; printf(" default offset: byte 0x%x(%d), native 0x%x(%d)\n", boff, boff, tblp[1], tblp[1]); diff -aruN shujit-0.3.8/compiler.c shujit/compiler.c --- shujit-0.3.8/compiler.c Fri Aug 27 03:18:36 1999 +++ shujit/compiler.c Thu Sep 9 14:00:27 1999 @@ -56,16 +56,10 @@ bool_t is_fpupc_double = FALSE; #if (defined(EXC_BY_SIGNAL) || defined(GET_SIGCONTEXT)) && defined(SEARCH_SIGCONTEXT) -# ifdef linux unsigned short reg_gs; unsigned short reg_fs; -# endif unsigned short reg_es; unsigned short reg_ds; -# ifdef __FreeBSD__ -unsigned short reg_cs; -unsigned short reg_ss; -# endif #endif /* (EXC_BY_SIGNAL || GET_SIGCONTEXT) && SEARCH_SIGCONTEXT */ #ifdef CODE_DB @@ -340,26 +334,13 @@ #if (defined(EXC_BY_SIGNAL) || defined(GET_SIGCONTEXT))&& defined(SEARCH_SIGCONTEXT) -#ifdef linux asm("movw %%gs,%0" : "=m" (reg_gs)); asm("movw %%fs,%0" : "=m" (reg_fs)); -#endif asm("movw %%es,%0" : "=m" (reg_es)); asm("movw %%ds,%0" : "=m" (reg_ds)); -#ifdef __FreeBSD__ - asm("movw %%cs,%0" : "=m" (reg_cs)); - asm("movw %%ss,%0" : "=m" (reg_ss)); -#endif - #ifdef RUNTIME_DEBUG -#ifdef linux printf("segment registers (gs,fs,es,ds): %04x, %04x, %04x, %04x\n", reg_gs, reg_fs, reg_es, reg_ds); -#endif /* linux */ -#ifdef __FreeBSD__ - printf("segment registers (es,ds,cs,ss): %04x, %04x, %04x, %04x\n", - reg_es, reg_ds, reg_cs, reg_ss); -#endif /* __FreeBSD__ */ fflush(stdout); #endif #endif /* (EXC_BY_SIGNAL || GET_SIGCONTEXT) && SEARCH_SIGCONTEXT */ @@ -430,10 +411,10 @@ ClassClass **clazzptr; int i; -#if JDK_VER < 12 - BINCLASS_LOCK(); -#else +#if JDK_VER >= 12 BINCLASS_LOCK(sysThreadSelf()); +#else + BINCLASS_LOCK(); #endif #ifdef COMPILE_DEBUG printf("%d classes is already loaded.\n", nbinclasses); @@ -446,10 +427,10 @@ #endif initializeClass(*clazzptr); } -#if JDK_VER < 12 - BINCLASS_UNLOCK(); -#else +#if JDK_VER >= 12 BINCLASS_UNLOCK(sysThreadSelf()); +#else + BINCLASS_UNLOCK(); #endif } @@ -654,13 +635,8 @@ #endif #if defined(EXC_BY_SIGNAL) || defined(GET_SIGCONTEXT) # ifdef SEARCH_SIGCONTEXT - static int sc_offset = -1; - static int sc_search_times = 2; -#if 1 - int32_t *ptr = ((int32_t *)&sig) - 1; -#else - int32_t *ptr = ((int32_t *)&uc); -#endif + static int sc_offset = 0; + int32_t *ptr = ((int32_t *)&sig) + 1; # endif /* SEARCH_SIGCONTEXT */ SIGCONTEXT *sc = NULL; struct methodblock *mb; @@ -673,14 +649,16 @@ #endif /* EXC_BY_SIGNAL */ #if 0 +#if 1 + signal(sig, SIG_DFL); +#else { struct sigaction sigAct; sigAct.sa_handler = SIG_DFL; sigemptyset(&sigAct.sa_mask); sigaction(sig, &sigAct, (struct sigaction *)NULL); } -#else - signal(sig, SIG_DFL); +#endif #endif #if defined(RUNTIME_DEBUG) || defined(COMPILE_DEBUG) @@ -689,55 +667,48 @@ #if defined(EXC_BY_SIGNAL) || defined(GET_SIGCONTEXT) - /* get methodblock */ -#if 1 - mb = EE()->current_frame->current_method; - /* EBP is broken on FreeBSD ??? */ -#else - mb = (struct methodblock *) *(((int32_t *)sc->SC_EBP) + 3); - /* mb is second argument of assembledCode(): 0xc(%ebp) */ -#endif - codeinfo = (CodeInfo *)(mb->CompiledCodeInfo); - - #ifndef SEARCH_SIGCONTEXT sc = (SIGCONTEXT *)uc; #else /* get signal context */ - if (--sc_search_times < 0) { - sc = (SIGCONTEXT *)(ptr + sc_offset); - } - else { /* must search */ + sc = (SIGCONTEXT *)(ptr + sc_offset); + +# ifdef __FreeBSD__ + if ( !(sc->SC_GS & 0xffff == reg_gs) || !(sc->SC_FS & 0xffff == reg_fs) || + !(sc->SC_ES & 0xffff == reg_es) || !(sc->SC_DS & 0xffff == reg_ds) ) { +# else + if ( !(sc->SC_GS == reg_gs) || !(sc->SC_FS == reg_fs) || + !(sc->SC_ES == reg_es) || !(sc->SC_DS == reg_ds) ) { +# endif /* __FreeBSD__ */ + /* search signal context */ +#ifdef RUNTIME_DEBUG + printf("sc_offset(%d) is obsolete, search.\n", sc_offset); + fflush(stdout); +#endif #define SC_SEARCH_WIDTH 50 - for (sc_offset = 0; sc_offset < SC_SEARCH_WIDTH - 3; sc_offset++) { -#if defined(linux) - if ( (*((unsigned short *)(ptr)) == reg_gs) && - (*((unsigned short *)(ptr + 1)) == reg_fs) && - (*((unsigned short *)(ptr + 2)) == reg_es) && - (*((unsigned short *)(ptr + 3)) == reg_ds) ) - break; -#elif defined(__FreeBSD__) - if ( (*((unsigned short *)(ptr)) == reg_es) && - (*((unsigned short *)(ptr + 1)) == reg_ds) && - (*((unsigned short *)(ptr + 2)) == reg_cs) && - (*((unsigned short *)(ptr + 3)) == reg_ss) ) { - sc_offset -= 7; - ptr -= 7; + for (sc_offset = 0; sc_offset < SC_SEARCH_WIDTH; sc_offset++) { +# ifdef __FreeBSD__ + if ( (((SIGCONTEXT *)ptr)->SC_GS & 0xffff == reg_gs) && + (((SIGCONTEXT *)ptr)->SC_FS & 0xffff == reg_fs) && + (((SIGCONTEXT *)ptr)->SC_ES & 0xffff == reg_es) && + (((SIGCONTEXT *)ptr)->SC_DS & 0xffff == reg_ds) ) +# else + if ( (((SIGCONTEXT *)ptr)->SC_GS == reg_gs) && + (((SIGCONTEXT *)ptr)->SC_FS == reg_fs) && + (((SIGCONTEXT *)ptr)->SC_ES == reg_es) && + (((SIGCONTEXT *)ptr)->SC_DS == reg_ds) ) +# endif /* __FreeBSD__ */ break; - } -#else - if (0) break; -#endif else ptr += 1; } + if (sc_offset >= SC_SEARCH_WIDTH) { + printf("FATAL: cannot find signal context on stack."); + JVM_Exit(1); + } #if defined(RUNTIME_DEBUG) || defined(COMPILE_DEBUG) printf("sc_offset: %d\n", sc_offset); #endif - if (sc_offset >= (SC_SEARCH_WIDTH - 3)) { - printf("FATAL: cannot find struct sigcontext on stack."); - JVM_Exit(1); - } sc = (SIGCONTEXT *)ptr; } #endif /* SEARCH_SIGCONTEXT*/ @@ -746,24 +717,20 @@ printf("sigcontext: 0x%08x\n", (int)sc); fflush(stdout); showSigcontext(sc); #endif -#endif /* EXC_BY_SIGNAL */ +#endif /* EXC_BY_SIGNAL || GET_SIGCONTEXT */ + +#if defined(EXC_BY_SIGNAL) || defined(GET_SIGCONTEXT) + if ((sig != SIGSEGV) && (sig != SIGFPE)) return FALSE; + mb = EE()->current_frame->current_method; + if (!mb) return FALSE; #if defined(RUNTIME_DEBUG) || defined(COMPILE_DEBUG) printf("method(0x%x)", (int)mb); fflush(stdout); - if (!mb) { - printf("\n"); fflush(stdout); - goto signal_handler_error; - } - printf(": %s#%s %s\n", - cbName(mb->fb.clazz), mb->fb.name, mb->fb.signature); + printf(": %s#%s %s\n", cbName(mb->fb.clazz), mb->fb.name, mb->fb.signature); fflush(stdout); - - showStackFrames(EE()); #endif - - -#if defined(EXC_BY_SIGNAL) || defined(GET_SIGCONTEXT) + if (!mb->CompiledCode) return FALSE; /* not compiled */ native_off = ((uint32_t)sc->SC_EIP) - ((uint32_t)mb->CompiledCode); #ifdef RUNTIME_DEBUG @@ -771,8 +738,9 @@ fflush(stdout); #endif #ifndef EXC_BY_SIGNAL - JVM_Exit(1); + return FALSE; #else + codeinfo = (CodeInfo *)(mb->CompiledCodeInfo); tentry = throwtableGet(codeinfo, native_off); #if defined(RUNTIME_DEBUG) || defined(COMPILE_DEBUG) printf("throwentry: "); @@ -783,7 +751,7 @@ else printf("(null)\n"); fflush(stdout); -#endif /* RUNTIME_DEBUG */ +#endif /* RUNTIME_DEBUG || COMPILE_DEBUG */ #define IP_SEARCH_WIDTH 50 if (!tentry) { /* search EIP in native code */ @@ -814,7 +782,7 @@ } #ifdef NULLEXC_BY_SIGNAL - if ((sig == SIGSEGV) || (sig == SIGBUS)) { + if (sig == SIGSEGV) { /* NullPointerException occurred */ SignalError(NULL, JAVAPKG "NullPointerException", 0); /* set ee->exception.exc, exception object */ @@ -885,11 +853,12 @@ } + /* jump to exc_new or exc_handler in compiled code */ + /* re-initialize signal handler associated with raised signal */ { - struct sigaction sigAct; - sigAct = sigActForHandler; + struct sigaction sigAct = sigActForHandler; sigaction(sig, &sigAct, (struct sigaction *)NULL); } @@ -939,9 +908,11 @@ # endif /* JDK_VER */ /* jump to exception handler */ -#endif /* ! EXC_BY_SIGNAL */ +#endif /* EXC_BY_SIGNAL */ #endif /* EXC_BY_SIGNAL || GET_SIGCONTEXT */ + return FALSE; + signal_handler_error: fprintf(stderr, "Signal %d\n", sig); fflush(stderr); @@ -981,7 +952,7 @@ fflush(stderr); } #endif - return FALSE; + JVM_Exit(1); } diff -aruN shujit-0.3.8/compiler.h shujit/compiler.h --- shujit-0.3.8/compiler.h Sat Aug 28 18:02:26 1999 +++ shujit/compiler.h Thu Sep 9 04:26:39 1999 @@ -32,64 +32,67 @@ /* * Internal Opcodes */ -#define opc_invokeignored_static 230 /* 0xe6 */ - -#define opc_fmul_strict 231 /* 0xe7 */ -#define opc_dmul_strict 232 -#define opc_fdiv_strict 233 -#define opc_ddiv_strict 234 - -#define opc_getstatic2 235 /* 0xeb */ -#define opc_putstatic2 236 -#define opc_getfield2 237 -#define opc_putfield2 238 - -#define opc_methodhead 239 /* 0xef */ -#define opc_epilogue 240 -#define opc_exc_handler 241 -#define opc_methodtail 242 -#define opc_syncenter 243 -#define opc_syncexit 244 -#define opc_strictenter 245 -#define opc_strictexit 246 - -#define opc_fppc_single 247 /* 0xf7 */ -#define opc_fppc_double 248 -#define opc_fppc_ext 249 - -#define opc_fill_cache 250 /* 0xfa */ -#define opc_array_check 251 - -#define opc_iastore1 252 /* 0xfc */ -#define opc_lastore1 253 - #define opc_impdep1 254 /* 0xfe */ #define opc_impdep2 255 -#define opc_stateto0 256 /* 0x100 */ -#define opc_stateto1 257 -#define opc_stateto2 258 -#define opc_stateto3 259 -#define opc_stateto4 260 - -#define opc_goto_st0 261 /* 0x105 */ -#define opc_goto_st1 262 -#define opc_goto_st2 263 -#define opc_goto_st3 264 -#define opc_goto_st4 265 - -#define opc_sqrt 266 /* 0x10a */ -#define opc_sin 267 -#define opc_cos 268 -#define opc_tan 269 -#define opc_atan2 270 -#define opc_atan 271 -#define opc_exp 272 -#define opc_log 273 -#define opc_floor 274 -#define opc_ceil 275 +#define opc_methodhead 256 /* 0x100 */ +#define opc_epilogue 257 +#define opc_exc_new 258 +#define opc_exc_handler 259 +#define opc_methodtail 260 +#define opc_syncenter 261 +#define opc_syncexit 262 +#define opc_strictenter 263 +#define opc_strictexit 264 + +#define opc_fppc_single 265 /* 0x109 */ +#define opc_fppc_double 266 +#define opc_fppc_ext 267 + +#define opc_throw_illegalaccess 268 + +#define opc_fill_cache 269 /* 0x10d */ +#define opc_array_check 270 + +#define opc_invokeignored_static 271 /* 0x10f */ + +#define opc_fmul_strict 272 /* 0x110 */ +#define opc_dmul_strict 273 +#define opc_fdiv_strict 274 +#define opc_ddiv_strict 275 + +#define opc_getstatic2 276 /* 0x114 */ +#define opc_putstatic2 277 +#define opc_getfield2 278 +#define opc_putfield2 279 + +#define opc_iastore1 280 /* 0x118 */ +#define opc_lastore1 281 + +#define opc_stateto0 282 /* 0x11a */ +#define opc_stateto1 283 +#define opc_stateto2 284 +#define opc_stateto3 285 +#define opc_stateto4 286 + +#define opc_goto_st0 287 /* 0x11f */ +#define opc_goto_st1 288 +#define opc_goto_st2 289 +#define opc_goto_st3 290 +#define opc_goto_st4 291 + +#define opc_sqrt 292 /* 0x122 */ +#define opc_sin 293 +#define opc_cos 294 +#define opc_tan 295 +#define opc_atan2 296 +#define opc_atan 297 +#define opc_exp 298 +#define opc_log 299 +#define opc_floor 300 +#define opc_ceil 301 -#define NOPCODES 276 +#define NOPCODES 302 /* 0x12e */ /* offerred by Sun */ @@ -191,6 +194,12 @@ # define SC_EIP eip # define SC_EBP ebp # define SC_ESP esp +# define SC_GS gs +# define SC_FS fs +# define SC_ES es +# define SC_DS ds +# define SC_CS cs +# define SC_SS ss # define SC_TRAPNO trapno # define SC_ERR err # elif defined(__FreeBSD__) @@ -204,6 +213,12 @@ # define SC_EIP sc_eip # define SC_EBP sc_ebp # define SC_ESP sc_esp +# define SC_GS sc_gs +# define SC_FS sc_fs +# define SC_ES sc_es +# define SC_DS sc_ds +# define SC_CS sc_cs +# define SC_SS sc_ss # define SC_TRAPNO sc_trapno # define SC_ERR sc_err # else @@ -216,6 +231,12 @@ # define SC_EIP eip # define SC_EBP ebp # define SC_ESP esp +# define SC_GS gs +# define SC_FS fs +# define SC_ES es +# define SC_DS ds +# define SC_CS cs +# define SC_SS ss # define SC_TRAPNO trapno # define SC_ERR err # endif @@ -242,6 +263,15 @@ #endif /* CODE_DB */ +#define OPC_THROW_MASK 0x1 +#define OPC_SIGNAL_MASK 0x2 + +#define OPC_THROW 0x1 + /* the opcode may throw a throwable with SIGNAL_ERROR*() */ +#define OPC_SIGNAL 0x3 + /* the opcode may send a signal: SIGSEGV or SIGFPE */ + + /* * Complement macros */ @@ -269,8 +299,12 @@ #endif /* JDK_VER */ #if JDK_VER >= 12 +# define SYS_MONITOR_ENTER(SELF, MON) sysMonitorEnter(SELF, MON) +# define SYS_MONITOR_EXIT(SELF, MON) sysMonitorExit(SELF, MON) # define CB_INITIALIZED(CB) (CCIs((CB), Initialized)) #else +# define SYS_MONITOR_ENTER(SELF, MON) sysMonitorEnter(MON) +# define SYS_MONITOR_EXIT(SELF, MON) sysMonitorExit(MON) # define CB_INITIALIZED(CB) (CCIs((CB), Resolved)) #endif /* JDK_VER */ @@ -358,6 +392,8 @@ /* old fasion native methods not wrapped by stub */ #endif /* DIRECT_INV_NATIVE */ + sys_mon_t *monitor; + /* below members are specific to JIT compiled code */ int32_t code_size; int32_t invocation_count; @@ -389,6 +425,7 @@ typedef struct compiler_context { ExecEnv *ee; struct methodblock *mb; + bool_t may_throw; /* the method may throw exceptions */ /* buffer for compiled code */ #define DEFAULT_BUF_SIZE 8192 @@ -410,6 +447,10 @@ jpentry *jptable; struct compiler_context *next; + +#ifdef COMPILE_DEBUG + int compile_debug; +#endif } CompilerContext; @@ -625,8 +666,9 @@ #ifdef RUNTIME_DEBUG int runtime_debug, #endif - ExecEnv *ee, - JHandle *obj, struct methodblock *imethod, unsigned char *guessptr); + ExecEnv *ee, JHandle *obj, + struct methodblock *imethod, unsigned char *guessptr, + int32_t bytepcoff); extern JHandle *multianewarray( #ifdef RUNTIME_DEBUG int runtime_debug, diff -aruN shujit-0.3.8/computil.c shujit/computil.c --- shujit-0.3.8/computil.c Wed Aug 25 11:32:37 1999 +++ shujit/computil.c Tue Sep 7 23:15:59 1999 @@ -137,11 +137,6 @@ static CompilerContext *newCompilerContext(struct methodblock *mb) { CompilerContext *cc; -#ifdef COMPILE_DEBUG - printf("newCompilerContext(): mb is 0x%08x(%s)\n", - (int)mb, (mb ? mb->fb.name : "(null)")); - fflush(stdout); -#endif cc = (CompilerContext *)sysMalloc(sizeof(CompilerContext)); if (!cc) { #ifdef COMPILE_DEBUG @@ -194,9 +189,25 @@ static void resetCompilerContext(CompilerContext *cc, struct methodblock *mb) { - cc->ee = EE(); +#ifdef COMPILE_DEBUG +# if 1 + cc->compile_debug = debugp(mb); +# else + cc->compile_debug = 1; +# endif +#endif + +#ifdef COMPILE_DEBUG + if (cc->compile_debug) { + printf("resetCompilerContext(): mb is 0x%08x(%s)\n", + (int)mb, (mb ? mb->fb.name : "(null)")); + fflush(stdout); + } +#endif + cc->ee = EE(); cc->mb = mb; + cc->may_throw = FALSE; cc->bufp = cc->buffer; @@ -372,10 +383,15 @@ void jptableAdd(CompilerContext *cc, unsigned int tgtoff, unsigned int argoff) { jpentry *entryp; +#ifdef COMPILE_DEBUG + int compile_debug = cc->compile_debug; +#endif if (cc->jptablelen >= cc->jptablesize) { /* extend table size */ #ifdef COMPILE_DEBUG - printf("jptableAdd(): extending jump table.\n"); fflush(stdout); + if (compile_debug) { + printf("jptableAdd(): extending jump table.\n"); fflush(stdout); + } #endif do { cc->jptablesize <<= 1; @@ -384,8 +400,10 @@ cc->jptable = (jpentry *)sysRealloc(cc->jptable, sizeof(jpentry) * cc->jptablesize); #ifdef COMPILE_DEBUG - printf("jptableAdd() extending done: 0x%x\n", (int)(cc->jptable)); - fflush(stdout); + if (compile_debug) { + printf("jptableAdd() extending done: 0x%x\n", (int)(cc->jptable)); + fflush(stdout); + } #endif } @@ -399,6 +417,7 @@ CodeInfo *prepareCompiledCodeInfo(ExecEnv *ee, struct methodblock *method) { CodeInfo *info; + if (!method->fb.clazz) { #ifdef COMPILE_DEBUG printf("prepCmpldCodeInfo: methodblock %x is not initialized.\n", @@ -407,12 +426,18 @@ #endif return NULL; } + info = (CodeInfo *)method->CompiledCodeInfo; if (!info) { - info = (CodeInfo *)sysMalloc(sizeof(CodeInfo)); - memset(info, 0, sizeof(CodeInfo)); /* fill zero into CodeInfo */ + info = (CodeInfo *)sysCalloc(1, sizeof(CodeInfo)); method->CompiledCodeInfo = (void *)info; } + + if (!info->monitor) { + info->monitor = (sys_mon_t *)sysCalloc(1, sysMonitorSizeof()); + sysMonitorInit(info->monitor); + } + if (!info->argsizes) { #define AS_BUF_SIZE 256 char *sig = method->fb.signature + 1; @@ -488,6 +513,10 @@ void freeCompiledCodeInfo(CodeInfo *info) { if (info) { + if (info->monitor) { + sysMonitorDestroy(info->monitor); + sysFree(info->monitor); + } #ifdef EXC_BY_SIGNAL if (info->throwtable) sysFree(info->throwtable); #endif /* EXC_BY_SIGNAL */ diff -aruN shujit-0.3.8/gentable.rb shujit/gentable.rb --- shujit-0.3.8/gentable.rb Mon Aug 23 03:00:25 1999 +++ shujit/gentable.rb Mon Aug 30 13:04:18 1999 @@ -4,7 +4,7 @@ CONST_C_FNAME = 'constants.c' CONST_H_FNAME = 'constants.h' -NOPCODES = 276 +NOPCODES = 302 NSTATES = 5 STANY = 5 STSTA = 5 diff -aruN shujit-0.3.8/invoker.c shujit/invoker.c --- shujit-0.3.8/invoker.c Sat Aug 28 16:56:03 1999 +++ shujit/invoker.c Wed Sep 8 00:02:09 1999 @@ -40,18 +40,31 @@ bool_t compileAndInvokeMethod( JHandle *o, struct methodblock *mb, int args_size, ExecEnv *ee, stack_item *var_base) { +#if JDK_VER >= 12 + sys_thread_t *self = EE2SysThread(ee); +#endif + sys_mon_t *mon; + + CodeInfo *info; int access; int compilation_result; - MONITOR_T key; int invocation_count; +#ifdef RUNTIME_DEBUG + int runtime_debug = 0; - key = obj_monitor(fieldclass(&mb->fb)); + if (ee->current_frame) { + runtime_debug = debugp(ee->current_frame->current_method); + } +#endif + + info = (CodeInfo *)mb->CompiledCodeInfo; + mon = info->monitor; #ifdef COMPILE_DEBUG printf("\n"); - printf("compileAndInvokeMethod() called by %x:\n %s#%s %s\n", - (int)sysThreadSelf(), + printf("cmpl&InvMtd: %s#%s %s\n", cbName(mb->fb.clazz), mb->fb.name, mb->fb.signature); + printf(" sys_th: %x sys_mon_t *: %x\n", (int)sysThreadSelf(), (int)mon); fflush(stdout); #if 1 if (debugp(mb)) { @@ -71,13 +84,11 @@ access = mb->fb.access; /* compile the called method */ - monitorEnter2(ee, key); + SYS_MONITOR_ENTER(self, mon); { - CodeInfo *info; void *invoker; /* add an invocation counter */ - info = (CodeInfo *)mb->CompiledCodeInfo; invocation_count = info->invocation_count; invocation_count++; info->invocation_count = invocation_count; @@ -90,7 +101,7 @@ #ifdef COMPILE_DEBUG printf(" already compiled.\n"); fflush(stdout); #endif - monitorExit2(ee, key); + SYS_MONITOR_EXIT(self, mon); goto compilation_done; } else if ((invoker != sym_compileAndInvokeMethod) /* being compiled */ @@ -99,7 +110,7 @@ || (!compiler_enabled) /* compiler is disabled */ #endif /* IGNORE_DISABLE */ ) { - monitorExit2(ee, key); + SYS_MONITOR_EXIT(self, mon); goto candi_call_normal_method; } } @@ -110,7 +121,7 @@ #ifdef COMPILE_DEBUG printf(" now compile.\n"); fflush(stdout); #endif - monitorExit2(ee, key); + SYS_MONITOR_EXIT(self, mon); { JavaFrame *frame = ee->current_frame; @@ -178,13 +189,19 @@ #endif /* HPROF */ #ifdef RUNTIME_DEBUG - printf("call ExecuteJava(invoker.c): %s#%s.\n", - cbName(mb->fb.clazz), mb->fb.name); fflush(stdout); + if (runtime_debug) { + printf("call ExecJava(invoker.c): %s#%s.\n", + cbName(mb->fb.clazz), mb->fb.name); + fflush(stdout); + } #endif exec_ret = ExecuteJava(mb->code, ee); #ifdef RUNTIME_DEBUG - printf("ExecuteJava(invoker.c) done: %s#%s.\n", - cbName(mb->fb.clazz), mb->fb.name); fflush(stdout); + if (runtime_debug) { + printf("ExecJava done(invoker.c): %s#%s.\n", + cbName(mb->fb.clazz), mb->fb.name); + fflush(stdout); + } #endif cur_frame = ee->current_frame; old_optop = cur_frame->optop; @@ -197,7 +214,7 @@ ee->current_frame = cur_frame; if (!exec_ret) { #ifdef RUNTIME_DEBUG - printf(" ExecuteJava() returned false.\n"); + printf(" interpreter returned false.\n"); if (exceptionOccurred(ee)) printf(" clazz of exc: %s\n", cbName(ee->exception.exc->methods->classdescriptor)); @@ -210,23 +227,25 @@ /* This operation is required only with x86 assembly ver. of executeJava.c */ retsize = ((CodeInfo *)mb->CompiledCodeInfo)->ret_size; -# ifdef RUNTIME_DEBUG - printf(" retsize: %d\n", retsize); fflush(stdout); -# endif if (retsize != 0) { optop = cur_frame->optop; if (retsize == 1) { optop[0] = old_optop[-1]; # ifdef RUNTIME_DEBUG - printf(" optop[0]: %08x\n", optop[0].i); fflush(stdout); + if (runtime_debug) { + printf(" optop[0]: %08x\n", optop[0].i); + fflush(stdout); + } # endif optop++; } else { /* retsize == 2 */ optop[0] = old_optop[-2]; optop[1] = old_optop[-1]; # ifdef RUNTIME_DEBUG - printf(" optop[0,1]: %08x,%08x\n", optop[0].i, optop[1].i); - fflush(stdout); + if (runtime_debug) { + printf(" optop[0,1]: %08x,%08x\n", optop[0].i, optop[1].i); + fflush(stdout); + } # endif optop += 2; } @@ -492,51 +511,45 @@ int debugp(struct methodblock *mb) { int runtime_debug = 0; -# if 1 + if (!mb) return 0; + +# if 0 runtime_debug = 1; # else if ((!strcmp(cbName(mb->fb.clazz), "sun/tools/java/Constants")) && (!strcmp(mb->fb.name, ""))) runtime_debug = 1; - -#if 0 - else if ((!strcmp(cbName(mb->fb.clazz), "javax/swing/UIManager")) - && (!strcmp(mb->fb.name, "maybeInitialize"))) + else if ((!strcmp(cbName(mb->fb.clazz), "com/netbeans/developer/impl/NbPlaces")) + && (!strcmp(mb->fb.name, "projectDesktop"))) runtime_debug = 1; - - else if ((!strcmp(cbName(mb->fb.clazz), "sun/applet/AppletViewer")) - && (!strcmp(mb->fb.name, ""))) - runtime_debug = 1; - else if ((!strcmp(cbName(mb->fb.clazz), "sun/applet/AppletPanel")) - && (!strcmp(mb->fb.name, "sendEvent"))) + else if ((!strcmp(cbName(mb->fb.clazz), "com/netbeans/developer/impl/NbProjectOperation")) + && (!strcmp(mb->fb.name, "getProjectDesktop"))) runtime_debug = 1; - else if ((!strcmp(cbName(mb->fb.clazz), "sun/applet/AppletPanel")) - && (!strcmp(mb->fb.name, "getNextEvent"))) + else if ((!strcmp(cbName(mb->fb.clazz), "java/lang/Thread")) + && (!strcmp(mb->fb.name, "interrupt"))) runtime_debug = 1; - else if ((!strcmp(cbName(mb->fb.clazz), "sun/awt/motif/MFramePeer")) - && (!strcmp(mb->fb.name, ""))) + else if ((!strcmp(cbName(mb->fb.clazz), "java/awt/MediaTracker")) + && (!strcmp(mb->fb.name, "waitForID"))) runtime_debug = 1; - else if ((!strcmp(cbName(mb->fb.clazz), "sun/awt/motif/MToolkit")) - && (!strcmp(mb->fb.name, "createFrame"))) + else if ((!strcmp(cbName(mb->fb.clazz), "com/netbeans/developer/impl/actions/SaveSettingsAction")) + && (!strcmp(mb->fb.name, "isEnabled"))) runtime_debug = 1; - else if ((!strcmp(cbName(mb->fb.clazz), "java/awt/Frame")) - && (!strcmp(mb->fb.name, "addNotify"))) + else if ((!strcmp(cbName(mb->fb.clazz), "org/openide/actions/SaveAction")) + && (!strcmp(mb->fb.name, "getName"))) runtime_debug = 1; - else if ((!strcmp(cbName(mb->fb.clazz), "java/awt/Window")) - && (!strcmp(mb->fb.name, "pack"))) + else if ((!strcmp(cbName(mb->fb.clazz), "java/awt/EventQueue")) + && (!strcmp(mb->fb.name, "invokeAndWait"))) runtime_debug = 1; - - else if ((!strcmp(cbName(mb->fb.clazz), "java/lang/Thread")) - && (!strcmp(mb->fb.name, ""))) + else if ((!strcmp(cbName(mb->fb.clazz), "org/openide/util/Mutex")) + && (!strcmp(mb->fb.name, "doEventAccess"))) runtime_debug = 1; - else if ((!strcmp(cbName(mb->fb.clazz), "java/lang/Thread")) - && (!strcmp(mb->fb.name, "init"))) + else if ((!strcmp(cbName(mb->fb.clazz), "java/beans/beancontext/BeanContextSupport")) + && (!strcmp(mb->fb.name, "getChildVisibility"))) runtime_debug = 1; - else if ((!strcmp(cbName(mb->fb.clazz), "java/lang/Thread")) - && (!strcmp(mb->fb.name, "exit"))) + else if ((!strcmp(cbName(mb->fb.clazz), "java/beans/beancontext/BeanContextSupport")) + && (!strcmp(mb->fb.name, "add"))) runtime_debug = 1; -#endif - +#if 0 else if (!strcmp(mb->fb.name, "main")) runtime_debug = 1; else if (!strcmp(mb->fb.name, "start")) @@ -544,6 +557,7 @@ else if (!strcmp(mb->fb.name, "run")) runtime_debug = 1; #endif +#endif /* 0 or 1 */ return runtime_debug; diff -aruN shujit-0.3.8/metavm/GNUmakefile shujit/metavm/GNUmakefile --- shujit-0.3.8/metavm/GNUmakefile Sat Aug 28 19:05:38 1999 +++ shujit/metavm/GNUmakefile Thu Sep 9 14:09:36 1999 @@ -3,8 +3,8 @@ # environment -JDK_VER = 12 -J_INCDIR = /usr/local/java/include-old +JDK_VER = 11 +J_INCDIR = /usr/local/java/include # command diff -aruN shujit-0.3.8/runtime.c shujit/runtime.c --- shujit-0.3.8/runtime.c Sat Aug 28 18:01:58 1999 +++ shujit/runtime.c Thu Sep 9 04:37:01 1999 @@ -36,6 +36,16 @@ * show contents of structure sigcontext */ void showSigcontext(SIGCONTEXT *sc) { + printf("SS: %04x, CS: %04x, DS: %04x, ES: %04x, FS: %04x, GS: %04x\n", +#if defined(__FreeBSD__) + sc->sc_ss & 0xffff, sc->sc_cs & 0xffff, + sc->sc_ds & 0xffff, sc->sc_es & 0xffff, + sc->sc_fs & 0xffff, sc->sc_gs & 0xffff +#else + sc->ss, sc->cs, sc->ds, sc->es, sc->fs, sc->gs +#endif + ); + printf("EAX: %08x, ECX: %08x, EDX: %08x, EBX: %08x\n", sc->SC_EAX, sc->SC_ECX, sc->SC_EDX, sc->SC_EBX); @@ -64,16 +74,6 @@ *(eip+14),*(eip+15)); } - printf("SS: %04x, CS: %04x, DS: %04x, ES: %04x, FS: %04x, GS: %04x\n", -#if defined(__FreeBSD__) - sc->sc_ss & 0xffff, sc->sc_cs & 0xffff, - sc->sc_ds & 0xffff, sc->sc_es & 0xffff, - sc->sc_fs & 0xffff, sc->sc_gs & 0xffff -#else - sc->ss, sc->cs, sc->ds, sc->es, sc->fs, sc->gs -#endif - ); - printf("trapno: %02x\n", sc->SC_TRAPNO); fflush(stdout); @@ -82,7 +82,7 @@ /* - * returns: return value size. -1 if an exception occurred. + * returns: TRUE if success, FALSE if failure. */ int invocationHelper( JHandle *obj, struct methodblock *method, int args_size, ExecEnv *ee, @@ -273,26 +273,28 @@ #ifdef RUNTIME_DEBUG # define PUSH_CONSTSTR(STR) asm("pushl %0" : : "m" (STR) : "esi") - printf("call JNI: %s#%s %s\n", + if (runtime_debug) { + printf("call JNI: %s#%s %s\n", cbName(method->fb.clazz), method->fb.name, method->fb.signature); - printf(" argsize: %x\n", argsize); - printf(" old_frame: %x\n", old_frame); - printf(" optop: %x\n", optop); - printf(" ee,env: %x,%x\n", ee,env); - printf(" obj: %x ((var_base): %x)\n", obj, var_base[0].i); - printf(" code: %x\n", method->code); - printf(" is_static: %x\n", is_static); - fflush(stdout); + printf(" argsize: %x\n", argsize); + printf(" old_frame: %x\n", old_frame); + printf(" optop: %x\n", optop); + printf(" ee,env: %x,%x\n", ee,env); + printf(" obj: %x ((var_base): %x)\n", obj, var_base[0].i); + printf(" code: %x\n", method->code); + printf(" is_static: %x\n", is_static); + fflush(stdout); - asm("pushl %eax\n\t" - "leal 4(%esp),%eax"); - asm("pushal"); - asm("pushl %eax"); - PUSH_CONSTSTR(" ESP: %x\n"); - asm("call " SYMBOL(printf) "@PLT\n\t" - "addl $8,%esp"); - asm("popal"); - asm("popl %eax"); + asm("pushl %eax\n\t" + "leal 4(%esp),%eax"); + asm("pushal"); + asm("pushl %eax"); + PUSH_CONSTSTR(" ESP: %x\n"); + asm("call " SYMBOL(printf) "@PLT\n\t" + "addl $8,%esp"); + asm("popal"); + asm("popl %eax"); + } #endif /* esi: src addr., edi: dst addr. */ asm("movl %0,%%edx\n\t" /* edx = argsize */ @@ -321,13 +323,15 @@ : : "m" (is_static) : "edx", "esi", "ecx", "edi"); #ifdef RUNTIME_DEBUG - asm("pushal\n\t" - "pushl (%ecx)\n\t" - "pushl %ecx"); - PUSH_CONSTSTR(" obj: %x, (obj): %x\n"); - asm("call printf@PLT\n\t" - "addl $12,%esp"); - asm("popal"); + if (runtime_debug) { + asm("pushal\n\t" + "pushl (%ecx)\n\t" + "pushl %ecx"); + PUSH_CONSTSTR(" obj: %x, (obj): %x\n"); + asm("call printf@PLT\n\t" + "addl $12,%esp"); + asm("popal"); + } #endif asm("movl %0,%%edx" : : "m" (terse_sig) : "edx"); /* edx = terse_sig */ @@ -346,12 +350,14 @@ "movl %%eax,(%%edi)\n\t" #ifdef RUNTIME_DEBUG : : : "ecx", "eax"); - asm("pushal\n\t" - "pushl %eax"); - PUSH_CONSTSTR(" argobj: %x\n"); - asm("call printf@PLT\n\t" - "addl $8,%esp"); - asm("popal"); + if (runtime_debug) { + asm("pushal\n\t" + "pushl %eax"); + PUSH_CONSTSTR(" argobj: %x\n"); + asm("call printf@PLT\n\t" + "addl $8,%esp"); + asm("popal"); + } asm( #endif "subl $4,%%esi\n\t" @@ -361,12 +367,14 @@ "movl (%%esi),%%eax\n\t" #ifdef RUNTIME_DEBUG : : : "esi", "edi", "eax"); - asm("pushal\n\t" - "pushl %eax"); - PUSH_CONSTSTR(" arg32: %x\n"); - asm("call printf@PLT\n\t" - "addl $8,%esp"); - asm("popal"); + if (runtime_debug) { + asm("pushal\n\t" + "pushl %eax"); + PUSH_CONSTSTR(" arg32: %x\n"); + asm("call printf@PLT\n\t" + "addl $8,%esp"); + asm("popal"); + } asm( #endif "subl $4,%%esi\n\t" @@ -380,12 +388,14 @@ "movl %%eax,4(%%edi)\n\t" #ifdef RUNTIME_DEBUG : : : "esi", "edi", "eax"); - asm("pushal\n\t" - "pushl 4(%edi)\n\tpushl (%edi)"); - PUSH_CONSTSTR(" arg64: %x %x\n"); - asm("call printf@PLT\n\t" - "addl $12,%esp"); - asm("popal"); + if (runtime_debug) { + asm("pushal\n\t" + "pushl 4(%edi)\n\tpushl (%edi)"); + PUSH_CONSTSTR(" arg64: %x %x\n"); + asm("call printf@PLT\n\t" + "addl $12,%esp"); + asm("popal"); + } asm( #endif "subl $8,%%esi\n\t" @@ -395,15 +405,17 @@ : : : "ecx", "eax", "esi", "edi"); #ifdef RUNTIME_DEBUG - asm("pushl %eax\n\t" - "leal 4(%esp),%eax\n\t" - "pushal"); - asm("pushl 16(%eax)\n\tpushl 12(%eax)\n\t" - "pushl 8(%eax)\n\tpushl 4(%eax)\n\tpushl (%eax)"); - PUSH_CONSTSTR(" (esp): %x %x %x %x %x\n"); - asm("call printf@PLT\n\t" - "addl $24,%esp"); - asm("popal\n\tpopl %eax"); + if (runtime_debug) { + asm("pushl %eax\n\t" + "leal 4(%esp),%eax\n\t" + "pushal"); + asm("pushl 16(%eax)\n\tpushl 12(%eax)\n\t" + "pushl 8(%eax)\n\tpushl 4(%eax)\n\tpushl (%eax)"); + PUSH_CONSTSTR(" (esp): %x %x %x %x %x\n"); + asm("call printf@PLT\n\t" + "addl $24,%esp"); + asm("popal\n\tpopl %eax"); + } #endif /* call Java_...() */ asm("movl %%edx,%%edi\n\t" /* save terse_sig */ @@ -413,32 +425,38 @@ : : "m" (code), "m" (argsize) : "edx", "edi", "ecx", "esp"); #ifdef RUNTIME_DEBUG - asm("subl $200,%esp\n\tpushal"); - asm("pushl %edx\n\tpushl %eax"); - PUSH_CONSTSTR(" eax:edx %x:%x\n"); - asm("call printf@PLT\n\t" - "addl $12,%esp"); - asm("popal\n\taddl $200,%esp"); + if (runtime_debug) { + asm("subl $200,%esp\n\tpushal"); + asm("pushl %edx\n\tpushl %eax"); + PUSH_CONSTSTR(" eax:edx %x:%x\n"); + asm("call printf@PLT\n\t" + "addl $12,%esp"); + asm("popal\n\taddl $200,%esp"); + } #endif #ifdef RUNTIME_DEBUG - asm("subl $200,%esp\n\tpushal\n\t" - "pushl %ecx"); - PUSH_CONSTSTR(" argsize: %x\n"); - asm("call printf@PLT\n\t" - "addl $8,%esp"); - asm("popal\n\taddl $200,%esp"); + if (runtime_debug) { + asm("subl $200,%esp\n\tpushal\n\t" + "pushl %ecx"); + PUSH_CONSTSTR(" argsize: %x\n"); + asm("call printf@PLT\n\t" + "addl $8,%esp"); + asm("popal\n\taddl $200,%esp"); + } #endif asm("xorl %%ecx,%%ecx\n\t" /* ecx = 0 */ "movb (%%edi),%%cl\n\t" #ifdef RUNTIME_DEBUG : : "m"(obj) : "ecx"); - asm("subl $200,%esp\n\tpushal\n\t" - "pushl %ecx"); - PUSH_CONSTSTR(" terse ret: %x\n"); - asm("call printf@PLT\n\t" - "addl $8,%esp"); - asm("popal\n\taddl $200,%esp"); + if (runtime_debug) { + asm("subl $200,%esp\n\tpushal\n\t" + "pushl %ecx"); + PUSH_CONSTSTR(" terse ret: %x\n"); + asm("call printf@PLT\n\t" + "addl $8,%esp"); + asm("popal\n\taddl $200,%esp"); + } asm( #endif "movl %0,%%esi\n\t" /* esi = optop */ @@ -451,12 +469,14 @@ "jniret_obj:\n\t" #ifdef RUNTIME_DEBUG : : : "eax"); - asm("subl $200,%esp\n\tpushal\n\t" - "pushl %eax"); - PUSH_CONSTSTR(" retobj: %x\n"); - asm("call printf@PLT\n\t" - "addl $8,%esp"); - asm("popal\n\taddl $200,%esp"); + if (runtime_debug) { + asm("subl $200,%esp\n\tpushal\n\t" + "pushl %eax"); + PUSH_CONSTSTR(" retobj: %x\n"); + asm("call printf@PLT\n\t" + "addl $8,%esp"); + asm("popal\n\taddl $200,%esp"); + } asm( #endif "testl %%eax,%%eax\n\t" @@ -465,12 +485,14 @@ "jniret_int32:\n\t" #ifdef RUNTIME_DEBUG : : : "eax"); - asm("subl $200,%esp\n\tpushal\n\t" - "pushl %eax"); - PUSH_CONSTSTR(" ret32: %x\n"); - asm("call printf@PLT\n\t" - "addl $8,%esp"); - asm("popal\n\taddl $200,%esp"); + if (runtime_debug) { + asm("subl $200,%esp\n\tpushal\n\t" + "pushl %eax"); + PUSH_CONSTSTR(" ret32: %x\n"); + asm("call printf@PLT\n\t" + "addl $8,%esp"); + asm("popal\n\taddl $200,%esp"); + } asm( #endif "movl %%eax,(%%esi)\n\t" /* *optop = eax */ @@ -486,12 +508,14 @@ "movl %%edx,4(%%esi)\n\t" #ifdef RUNTIME_DEBUG : : : "eax"); - asm("subl $200,%esp\n\tpushal\n\t" - "pushl 4(%esi)\n\tpushl (%esi)"); - PUSH_CONSTSTR(" ret64: %08x %08x\n"); - asm("call printf@PLT\n\t" - "addl $12,%esp"); - asm("popal\n\taddl $200,%esp"); + if (runtime_debug) { + asm("subl $200,%esp\n\tpushal\n\t" + "pushl 4(%esi)\n\tpushl (%esi)"); + PUSH_CONSTSTR(" ret64: %08x %08x\n"); + asm("call printf@PLT\n\t" + "addl $12,%esp"); + asm("popal\n\taddl $200,%esp"); + } asm( #endif "jmp jniret_done\n\t" @@ -557,9 +581,11 @@ int argsize; #ifdef RUNTIME_DEBUG - printf("call NMI: %s#%s %s\n", + if (runtime_debug) { + printf("call NMI: %s#%s %s\n", cbName(method->fb.clazz), method->fb.name, method->fb.signature); - fflush(stdout); + fflush(stdout); + } #endif info = (CodeInfo *)method->CompiledCodeInfo; code = info->code; @@ -574,7 +600,10 @@ code = (char *)symbolInSystemClassLoader(buf); #ifdef RUNTIME_DEBUG - printf(" func: %s (%x)\n", buf, code); fflush(stdout); + if (runtime_debug) { + printf(" func: %s (%x)\n", buf, code); + fflush(stdout); + } #endif if (!code) goto invoke_via_invoker; info->code = code; @@ -722,9 +751,11 @@ monitorExit2(ee, obj_monitor(obj)); #ifdef RUNTIME_DEBUG - printf("done NMI: %s#%s %s\n", + if (runtime_debug) { + printf("done NMI: %s#%s %s\n", cbName(method->fb.clazz), method->fb.name, method->fb.signature); - fflush(stdout); + fflush(stdout); + } #endif return !(exceptionOccurred(ee)); } @@ -766,13 +797,19 @@ #endif /* HPROF */ #ifdef RUNTIME_DEBUG - printf("call ExecuteJava(runtime.c): %s#%s.\n", - cbName(method->fb.clazz), method->fb.name); fflush(stdout); + if (runtime_debug) { + printf("call ExecuteJava(runtime.c): %s#%s.\n", + cbName(method->fb.clazz), method->fb.name); + fflush(stdout); + } #endif exec_ret = ExecuteJava(method->code, ee); #ifdef RUNTIME_DEBUG - printf("ExecuteJava(runtime.c) done: %s#%s.\n", - cbName(method->fb.clazz), method->fb.name); fflush(stdout); + if (runtime_debug) { + printf("ExecuteJava(runtime.c) done: %s#%s.\n", + cbName(method->fb.clazz), method->fb.name); + fflush(stdout); + } #endif cur_frame = ee->current_frame; /* load */ old_optop = cur_frame->optop; @@ -785,11 +822,13 @@ ee->current_frame = cur_frame; if (!exec_ret) { #ifdef RUNTIME_DEBUG - printf(" ExecuteJava() returned false.\n"); - if (exceptionOccurred(ee)) - printf(" clazz of exc: %s\n", + if (runtime_debug) { + printf(" ExecuteJava() returned false.\n"); + if (exceptionOccurred(ee)) + printf(" clazz of exc: %s\n", cbName(ee->exception.exc->methods->classdescriptor)); - fflush(stdout); + fflush(stdout); + } #endif return FALSE; } @@ -839,8 +878,9 @@ #ifdef RUNTIME_DEBUG int runtime_debug, #endif - ExecEnv *ee, - JHandle *obj, struct methodblock *imethod, unsigned char *guessptr) { + ExecEnv *ee, JHandle *obj, + struct methodblock *imethod, unsigned char *guessptr, + int32_t bytepcoff) { struct methodblock *method; ClassClass *intfClazz; unsigned int offset; @@ -894,7 +934,15 @@ imtable->itable[guess].classdescriptor != intfClazz) { for (guess = imtable->icount - 1; ;guess--) { if (guess < 0) { - invokeInterfaceError(ee, NULL, cb, intfClazz); + unsigned char *pc = NULL; + if (ee) { + JavaFrame *cur_frame = ee->current_frame; + if (cur_frame) { + struct methodblock *cur_mb = cur_frame->current_method; + pc = cur_mb->code + bytepcoff; + } + } + invokeInterfaceError(ee, pc, cb, intfClazz); return NULL; } if (imtable->itable[guess].classdescriptor == intfClazz) { @@ -1236,10 +1284,10 @@ ClassClass *cb; int i, j; -#if JDK_VER < 12 - BINCLASS_LOCK(); -#else +#if JDK_VER >= 12 BINCLASS_LOCK(sysThreadSelf()); +#else + BINCLASS_LOCK(); #endif for (i = nbinclasses; --i >= 0; ) { cb = binclasses[i]; @@ -1262,10 +1310,10 @@ mb = 0; done: -#if JDK_VER < 12 - BINCLASS_UNLOCK(); -#else +#if JDK_VER >= 12 BINCLASS_UNLOCK(sysThreadSelf()); +#else + BINCLASS_UNLOCK(); #endif return mb; } diff -aruN shujit-0.3.8/txt/memo shujit/txt/memo --- shujit-0.3.8/txt/memo Fri Aug 27 17:01:17 1999 +++ shujit/txt/memo Tue Sep 7 23:17:12 1999 @@ -95,6 +95,9 @@ javac の、フックをかけられる箇所を探す。-> Jikes を改造? Done + - final フィールドへの putfield, putstatic で + IllegalAccessError が発生するようにする。 + 本来は bytecode verifier がはねるべき? - native methods を invoker を経由せず直接呼び出す。 - compiled code から getInterfaceMethod() を呼び出した際の例外チェック。 - adaptive compilation @@ -169,10 +172,7 @@ - Mauve プロジェクト known bugs - - 何かの理由でメソッドのコンパイルが失敗した際、 - - final フィールドへの putfield, putstatic で - IllegalAccessError が発生しない。 - 本来は bytecode verifier がはねるべき? + - 何かの理由でメソッドのコンパイルが失敗した場合に… - 無限ループ実行中のスレッドが、 他スレッドから Thread#stop() しても実行停止しない。 (genunix/java/green_threads/src/threads_md.c: @@ -180,9 +180,14 @@ 他の JIT (Win32, Sol2) with Green Threads ではどうか調べる。 TYA 1.0 でも同じ現象が起きる。 -TYA 1.0 の bugs +TYA 1.4 の bugs - 上記 known bugs。:) - - 5 次元以上の配列を作成するコードをコンパイルできない。 + - final フィールドへの putfield, putstatic で + IllegalAccessError が発生しない。 + - IncompatibleChangeError が発生すべき状況で + NullPointerException が発生する。 + - クラス初期化のタイミングが言語仕様と異なる。 + - 5 次元以上の配列を作成するコードをコンパイルできない。JVM ごと終了する。 JDK 1.1.6, Version 2 (by Steve Byrne) - native method, sun.awt.motif.MChoicePeer#pReshape (IIII)V @@ -298,7 +303,9 @@ processAnOpcode() 代替 opcode を求める opcode, state, bytecode PC を表に登録 - state, bytecode PC を update + bytecode PC を update + updateStates() + stack state を設定 writeCode() writeForAnOpcode() native code をバッファに書く