From 5b5336d8693718bbd0141e5a6bed00826b1226db Mon Sep 17 00:00:00 2001 From: stefan Date: Thu, 15 May 2003 15:04:35 +0000 Subject: [PATCH] Allow native function tracing --- alpha/asmpart.S | 73 +++++++++++++++++++++++++++++++-- alpha/ngen.c | 106 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 155 insertions(+), 24 deletions(-) diff --git a/alpha/asmpart.S b/alpha/asmpart.S index 62905ff9a..1ce86bae5 100644 --- a/alpha/asmpart.S +++ b/alpha/asmpart.S @@ -104,6 +104,8 @@ .globl asm_initialize_thread_stack .globl asm_switchstackandcall .globl asm_getcallingmethod + .globl asm_builtin_trace + .globl asm_builtin_exittrace /*************************** imported variables *******************************/ @@ -1165,9 +1167,74 @@ pv_ok2: +/*********************** function asm_builtin_trace **************************** +* * +* Intended to be called from the native stub. Saves all argument registers * +* and calls builtin_trace_args. * +* * +*******************************************************************************/ + .ent asm_builtin_trace +asm_builtin_trace: + ldgp gp,0(pv) + lda sp,-112(sp) + stq itmp1,0(sp) + stq ra,8(sp) + stq a0,16(sp) + stq a1,24(sp) + stq a2,32(sp) + stq a3,40(sp) + stq a4,48(sp) + stq a5,56(sp) + stt $f16,64(sp) + stt $f17,72(sp) + stt $f18,80(sp) + stt $f19,88(sp) + stt $f20,96(sp) + stt $f21,104(sp) + + jsr ra,builtin_trace_args + + ldq ra,8(sp) + ldq a0,16(sp) + ldq a1,24(sp) + ldq a2,32(sp) + ldq a3,40(sp) + ldq a4,48(sp) + ldq a5,56(sp) + ldt $f16,64(sp) + ldt $f17,72(sp) + ldt $f18,80(sp) + ldt $f19,88(sp) + ldt $f20,96(sp) + ldt $f21,104(sp) + lda sp,112(sp) + jmp zero,(ra) + + .end asm_builtin_trace + + +/********************* function asm_builtin_exittrace ************************** +* * +* Intended to be called from the native stub. Saves return value and calls * +* builtin_displaymethodstop. * +* * +*******************************************************************************/ + .ent asm_builtin_exittrace +asm_builtin_exittrace: + ldgp gp,0(pv) + lda sp,-24(sp) + stq ra,0(sp) + stq v0,8(sp) + stt $f0,16(sp) + + jsr ra,builtin_displaymethodstop + + ldq ra,0(sp) + ldq v0,8(sp) + ldt $f0,16(sp) + lda sp,24(sp) + jmp zero,(ra) - - - + .end asm_builtin_exittrace diff --git a/alpha/ngen.c b/alpha/ngen.c index 8ced53e4a..2a7f4aa5a 100644 --- a/alpha/ngen.c +++ b/alpha/ngen.c @@ -11,7 +11,7 @@ Authors: Andreas Krall EMAIL: cacao@complang.tuwien.ac.at Reinhard Grafl EMAIL: cacao@complang.tuwien.ac.at - Last Change: $Id: ngen.c 277 2003-05-09 19:36:04Z stefan $ + Last Change: $Id: ngen.c 309 2003-05-15 15:04:35Z stefan $ *******************************************************************************/ @@ -455,7 +455,7 @@ static void gen_mcode() to arguments on stack. ToDo: save floating point registers !!!!!!!!! */ - if (runverbose && isleafmethod) { + if (runverbose) { M_LDA (REG_SP, REG_SP, -(14*8)); M_AST(REG_RA, REG_SP, 1*8); @@ -548,6 +548,7 @@ static void gen_mcode() /* call trace function */ +#if 0 if (runverbose && !isleafmethod) { M_LDA (REG_SP, REG_SP, -8); p = dseg_addaddress (method); @@ -559,6 +560,7 @@ static void gen_mcode() M_LDA(REG_PV, REG_RA, -(int)((u1*) mcodeptr - mcodebase)); M_LDA(REG_SP, REG_SP, 8); } +#endif /* call monitorenter function */ @@ -2993,6 +2995,7 @@ nowperformreturn: M_ALD(argintregs[0], REG_PV, a); M_MOV(REG_RESULT, argintregs[1]); M_FLTMOVE(REG_FRESULT, argfltregs[2]); + M_FLTMOVE(REG_FRESULT, argfltregs[3]); a = dseg_addaddress ((void*) (builtin_displaymethodstop)); M_ALD(REG_PV, REG_PV, a); M_JSR (REG_RA, REG_PV); @@ -3748,12 +3751,42 @@ void removecompilerstub (u1 *stub) *******************************************************************************/ -#define NATIVESTUBSIZE 18 +#define NATIVESTUBSIZE 34 +#define NATIVESTUBOFFSET 8 u1 *createnativestub (functionptr f, methodinfo *m) { + int disp; u8 *s = CNEW (u8, NATIVESTUBSIZE); /* memory to hold the stub */ - s4 *p = (s4*) s; /* code generation pointer */ + u8 *cs = s + NATIVESTUBOFFSET; + s4 *p = (s4*) (cs); /* code generation pointer */ + + *(cs-1) = (u8) f; /* address of native method */ + *(cs-2) = (u8) (&exceptionptr); /* address of exceptionptr */ + *(cs-3) = (u8) asm_handle_nat_exception; /* addr of asm exception handler */ + *(cs-4) = (u8) (&env); /* addr of jni_environement */ + *(cs-5) = (u8) asm_builtin_trace; + *(cs-6) = (u8) m; + *(cs-7) = (u8) asm_builtin_exittrace; + *(cs-8) = (u8) builtin_trace_exception; + + printf("stub: "); + utf_display(m->class->name); + printf("."); + utf_display(m->name); + printf(" 0x%p\n", cs); + + M_LDA (REG_SP, REG_SP, -8); /* build up stackframe */ + M_AST (REG_RA, REG_SP, 0); /* store return address */ + + if (runverbose) { + M_ALD(REG_ITMP1, REG_PV, -6*8); + M_ALD(REG_PV, REG_PV, -5*8); + + M_JSR(REG_RA, REG_PV); + disp = -(int) (p - (s4*) cs)*4; + M_LDA(REG_PV, REG_RA, disp); + } reg_init(); @@ -3772,41 +3805,72 @@ u1 *createnativestub (functionptr f, methodinfo *m) M_MOV (argintregs[0],argintregs[1]); M_FMOV (argfltregs[0],argfltregs[1]); - M_ALD (argintregs[0], REG_PV, 17*8); /* load adress of jni_environement */ - - M_LDA (REG_SP, REG_SP, -8); /* build up stackframe */ - M_AST (REG_RA, REG_SP, 0); /* store return address */ + M_ALD (argintregs[0], REG_PV, -4*8);/* load adress of jni_environement */ - M_ALD (REG_PV, REG_PV, 14*8); /* load adress of native method */ + M_ALD (REG_PV, REG_PV, -1*8); /* load adress of native method */ M_JSR (REG_RA, REG_PV); /* call native method */ - M_LDA (REG_PV, REG_RA, -15*4); /* recompute pv from ra */ - M_ALD (REG_ITMP3, REG_PV, 15*8); /* get address of exceptionptr */ + disp = -(int) (p - (s4*) cs)*4; + M_LDA (REG_PV, REG_RA, disp); /* recompute pv from ra */ + M_ALD (REG_ITMP3, REG_PV, -2*8); /* get address of exceptionptr */ - M_ALD (REG_RA, REG_SP, 0); /* load return address */ M_ALD (REG_ITMP1, REG_ITMP3, 0); /* load exception into reg. itmp1 */ + M_BNEZ (REG_ITMP1, + 3 + (runverbose ? 6 : 0)); /* if no exception then return */ + + if (runverbose) { + M_ALD(argintregs[0], REG_PV, -6*8); + M_MOV(REG_RESULT, argintregs[1]); + M_FMOV(REG_FRESULT, argfltregs[2]); + M_FMOV(REG_FRESULT, argfltregs[3]); + M_ALD(REG_PV, REG_PV, -7*8); + M_JSR(REG_RA, REG_PV); + } + M_ALD (REG_RA, REG_SP, 0); /* load return address */ M_LDA (REG_SP, REG_SP, 8); /* remove stackframe */ - M_BNEZ (REG_ITMP1, 1); /* if no exception then return */ M_RET (REG_ZERO, REG_RA); /* return to caller */ M_AST (REG_ZERO, REG_ITMP3, 0); /* store NULL into exceptionptr */ + + if (runverbose) { + M_LDA(REG_SP, REG_SP, -8); + M_AST(REG_ITMP1, REG_SP, 0); + M_MOV(REG_ITMP1, argintregs[0]); + M_ALD(argintregs[1], REG_PV, -6*8); + M_ALD(argintregs[2], REG_SP, 0); + M_CLR(argintregs[3]); + M_ALD(REG_PV, REG_PV, -8*8); + M_JSR(REG_RA, REG_PV); + disp = -(int) (p - (s4*) cs)*4; + M_LDA (REG_PV, REG_RA, disp); + M_ALD(REG_ITMP1, REG_SP, 0); + M_LDA(REG_SP, REG_SP, 8); + } + + M_ALD (REG_RA, REG_SP, 0); /* load return address */ + M_LDA (REG_SP, REG_SP, 8); /* remove stackframe */ + M_LDA (REG_ITMP2, REG_RA, -4); /* move fault address into reg. itmp2 */ - M_ALD (REG_ITMP3, REG_PV,16*8); /* load asm exception handler address */ + M_ALD (REG_ITMP3, REG_PV, -3*8); /* load asm exception handler address */ M_JMP (REG_ZERO, REG_ITMP3); /* jump to asm exception handler */ - - s[14] = (u8) f; /* address of native method */ - s[15] = (u8) (&exceptionptr); /* address of exceptionptr */ - s[16] = (u8) (asm_handle_nat_exception); /* addr of asm exception handler */ - s[17] = (u8) (&env); /* addr of jni_environement */ + +#if 0 + { + static int stubprinted; + if (!stubprinted) + printf("stubsize: %d/2\n", (int) (p - (s4*) s)); + stubprinted = 1; + } +#endif #ifdef STATISTICS count_nstub_len += NATIVESTUBSIZE * 8; #endif - return (u1*) s; + return (u1*) (s + NATIVESTUBOFFSET); } /* function: removenativestub ************************************************** @@ -3817,7 +3881,7 @@ u1 *createnativestub (functionptr f, methodinfo *m) void removenativestub (u1 *stub) { - CFREE (stub, NATIVESTUBSIZE * 8); + CFREE ((u8*) stub - NATIVESTUBOFFSET, NATIVESTUBSIZE * 8); } -- 2.25.1