From 56f36393b3193056068f0f3712360d9929aec170 Mon Sep 17 00:00:00 2001 From: edwin Date: Thu, 16 Mar 2006 18:38:42 +0000 Subject: [PATCH] * src/vm/jit/i386/asmpart.S (asm_replacement_out): Added pv. * src/vm/jit/x86_64/asmpart.S (asm_replacement_out): Added pv. * src/vm/jit/replace.c (replace_read_executionstate) (replace_write_executionstate): Prepared for alpha. Some cleanup. * src/vm/jit/replace.c (replace_write_executionstate): Calculate stack pointer from given stack base. (replace_executionstate_println): Added pv. (replace_sourcestate_println): Added stackbase. * src/vm/jit/replace.h (executionstate): Added pv. (sourcestate): Added stackbase. * src/vm/jit/tools/genoffsets.c (main): Added offes_pv. * doc/stack_frames.txt: Clarifications. --- doc/stack_frames.txt | 12 ++-- src/vm/jit/i386/asmpart.S | 5 +- src/vm/jit/replace.c | 118 ++++++++++++++++++++++++++-------- src/vm/jit/replace.h | 4 ++ src/vm/jit/tools/genoffsets.c | 3 +- src/vm/jit/x86_64/asmpart.S | 5 +- 6 files changed, 112 insertions(+), 35 deletions(-) diff --git a/doc/stack_frames.txt b/doc/stack_frames.txt index b9cb04413..16e0abc49 100644 --- a/doc/stack_frames.txt +++ b/doc/stack_frames.txt @@ -26,7 +26,7 @@ V | u8[] ^ callee-saved float registers | u4[] ^ callee-saved integer registers V -| >>>> sp on method entry <<<< +| >>>> sp on method entry, stack base for replacement <<<< | V u4 return address | u4[] arguments on stack @@ -44,13 +44,13 @@ V >>>> sp in method (after initial sub) <<<< | u8[] v arguments for calling methods \__ rd->memuse slots V u8[] v local variable slots allocated on stack / | -| u8 synchronized object / saved return value (only for synched methods) -V u8 alignment dummy slot (in non-leaf methods to ensure +| u8 v synchronized object / saved return value (only for synched methods) +V u8[0..1] alignment dummy slot (in non-leaf methods to ensure | 16-byte alignment of stack) | u8[] ^ callee-saved float registers V u8[] ^ callee-saved integer registers | -| >>>> sp on method entry <<<< +| >>>> sp on method entry, stack base for replacement <<<< V | u8 return address | u8[] arguments on stack @@ -72,6 +72,9 @@ V u8[] v local variable slots allocated on stack / V | u8[] ^ callee-saved float registers | u8[] ^ callee-saved integer registers +V +| >>>> !!!replacement code regards this point as stack base!!! <<<< +| V u8 ^ saved return address (only for non-leaf methods) | | >>>> sp on method entry <<<< @@ -80,4 +83,3 @@ V | V - diff --git a/src/vm/jit/i386/asmpart.S b/src/vm/jit/i386/asmpart.S index 1967bce77..501ab37b5 100644 --- a/src/vm/jit/i386/asmpart.S +++ b/src/vm/jit/i386/asmpart.S @@ -31,7 +31,7 @@ Changes: Joseph Wenninger Edwin Steiner - $Id: asmpart.S 4623 2006-03-16 00:05:18Z edwin $ + $Id: asmpart.S 4643 2006-03-16 18:38:42Z edwin $ */ @@ -590,6 +590,9 @@ asm_replacement_out: add $(sizeexecutionstate + REPLACEMENT_ROOM + 4),itmp1 mov itmp1,(offes_sp)(sp) + /* pv must be looked up via AVL tree */ + movl $0,(offes_pv)(sp) + /* call replace_me */ mov -4(itmp1),itmp1 /* rplpoint * */ push sp /* arg1: execution state */ diff --git a/src/vm/jit/replace.c b/src/vm/jit/replace.c index 14d35c269..ae41b779c 100644 --- a/src/vm/jit/replace.c +++ b/src/vm/jit/replace.c @@ -47,6 +47,12 @@ #include "vm/jit/disass.h" #include "arch.h" +/*** constants used internally ************************************************/ + +#define TOP_IS_NORMAL 0 +#define TOP_IS_ON_STACK 1 +#define TOP_IS_IN_ITMP1 2 + /* replace_create_replacement_points ******************************************* Create the replacement points for the given code. @@ -334,6 +340,7 @@ static void replace_read_executionstate(rplpoint *rp,executionstate *es, int allocs; rplalloc *ra; methoddesc *md; + int topslot; #ifdef HAS_4BYTE_STACKSLOT u4 *sp; u4 *basesp; @@ -345,8 +352,9 @@ static void replace_read_executionstate(rplpoint *rp,executionstate *es, code = rp->code; m = code->m; md = m->parseddesc; + topslot = TOP_IS_NORMAL; - /* calculate stack pointers */ + /* stack pointers */ #ifdef HAS_4BYTE_STACKSLOT sp = (u4*) es->sp; @@ -354,12 +362,32 @@ static void replace_read_executionstate(rplpoint *rp,executionstate *es, sp = (u8*) es->sp; #endif - /* XXX only on i386? */ - if (rp->type == BBTYPE_SBR) + /* on some architectures the returnAddress is passed on the stack by JSR */ + +#if defined(__I386__) || defined(__X86_64__) + if (rp->type == BBTYPE_SBR) { sp++; + topslot = TOP_IS_ON_STACK; + } +#endif + + /* in some cases the top stack slot is passed in REG_ITMP1 */ + + if ( (rp->type == BBTYPE_EXH) +#if defined(__ALPHA__) + || (rp->type == BBTYPE_SBR) +#endif + ) + { + topslot = TOP_IS_IN_ITMP1; + } + + /* calculate base stack pointer */ basesp = sp + code_get_stack_frame_size(code); + ss->stackbase = (u1*) basesp; + /* read local variables */ count = m->maxlocals; @@ -370,7 +398,14 @@ static void replace_read_executionstate(rplpoint *rp,executionstate *es, /* mark values as undefined */ for (i=0; ijavalocals[i] = (u8) 0x00dead0000dead00ULL; + + /* some entries in the intregs array are not meaningful */ + es->intregs[REG_ITMP3] = (u8) 0x11dead1111dead11ULL; + es->intregs[REG_SP ] = (u8) 0x11dead1111dead11ULL; +#ifdef REG_PV + es->intregs[REG_PV ] = (u8) 0x11dead1111dead11ULL; #endif +#endif /* NDEBUG */ ra = code->regalloc; @@ -411,12 +446,18 @@ static void replace_read_executionstate(rplpoint *rp,executionstate *es, ss->javastackdepth = count; ss->javastack = DMNEW(u8,count); +#ifndef NDEBUG + /* mark values as undefined */ + for (i=0; ijavastack[i] = (u8) 0x00dead0000dead00ULL; +#endif + i = 0; ra = rp->regalloc; /* the first stack slot is special in SBR and EXH blocks */ - if (rp->type == BBTYPE_SBR) { + if (topslot == TOP_IS_ON_STACK) { assert(count); ss->javastack[i] = sp[-1]; @@ -424,15 +465,17 @@ static void replace_read_executionstate(rplpoint *rp,executionstate *es, i++; ra++; } - else if (rp->type == BBTYPE_EXH) { + else if (topslot == TOP_IS_IN_ITMP1) { assert(count); - ss->javastack[i] = es->intregs[REG_ITMP1]; /* XXX all platforms? */ + ss->javastack[i] = es->intregs[REG_ITMP1]; count--; i++; ra++; } + /* read remaining stack slots */ + for (; count--; ra++, i++) { assert(ra->next); @@ -459,6 +502,15 @@ static void replace_read_executionstate(rplpoint *rp,executionstate *es, ss->savedintregs[i] = *--basesp; } + /* read unused callee saved flt regs */ + + count = FLT_SAV_CNT; + for (i=0; count > code->savedfltcount; ++i) { + assert(i < FLT_REG_CNT); + if (nregdescfloat[i] == REG_SAV) + ss->savedfltregs[--count] = es->fltregs[i]; + } + /* read saved flt regs */ for (i=0; isavedfltcount; ++i) { @@ -470,15 +522,6 @@ static void replace_read_executionstate(rplpoint *rp,executionstate *es, ss->savedfltregs[i] = *(u8*)basesp; } - /* read unused callee saved flt regs */ - - count = FLT_SAV_CNT; - for (i=0; count > code->savedfltcount; ++i) { - assert(i < FLT_REG_CNT); - if (nregdescfloat[i] == REG_SAV) - ss->savedfltregs[--count] = es->fltregs[i]; - } - /* read slots used for synchronization */ count = code_get_sync_slot_count(code); @@ -504,7 +547,8 @@ static void replace_read_executionstate(rplpoint *rp,executionstate *es, *******************************************************************************/ -static void replace_write_executionstate(rplpoint *rp,executionstate *es,sourcestate *ss) +static void replace_write_executionstate(rplpoint *rp,executionstate *es, + sourcestate *ss) { methodinfo *m; codeinfo *code; @@ -514,6 +558,7 @@ static void replace_write_executionstate(rplpoint *rp,executionstate *es,sources int allocs; rplalloc *ra; methoddesc *md; + int topslot; #ifdef HAS_4BYTE_STACKSLOT u4 *sp; u4 *basesp; @@ -526,18 +571,34 @@ static void replace_write_executionstate(rplpoint *rp,executionstate *es,sources m = code->m; md = m->parseddesc; - /* calculate stack pointers */ - + /* calculate stack pointer */ + #ifdef HAS_4BYTE_STACKSLOT - sp = (u4*) es->sp; + basesp = (u4*) ss->stackbase; #else - sp = (u8*) es->sp; + basesp = (u8*) ss->stackbase; #endif + + sp = basesp - code_get_stack_frame_size(code); - if (rp->type == BBTYPE_SBR) - sp++; + /* on some architectures the returnAddress is passed on the stack by JSR */ + +#if defined(__I386__) || defined(__X86_64__) + if (rp->type == BBTYPE_SBR) { + topslot = TOP_IS_ON_STACK; + } +#endif - basesp = sp + code_get_stack_frame_size(code); + /* in some cases the top stack slot is passed in REG_ITMP1 */ + + if ( (rp->type == BBTYPE_EXH) +#if defined(__ALPHA__) + || (rp->type == BBTYPE_SBR) +#endif + ) + { + topslot = TOP_IS_IN_ITMP1; + } /* in debug mode, invalidate stack frame first */ @@ -596,7 +657,7 @@ static void replace_write_executionstate(rplpoint *rp,executionstate *es,sources /* the first stack slot is special in SBR and EXH blocks */ - if (rp->type == BBTYPE_SBR) { + if (topslot == TOP_IS_ON_STACK) { assert(count); sp[-1] = ss->javastack[i]; @@ -604,14 +665,16 @@ static void replace_write_executionstate(rplpoint *rp,executionstate *es,sources i++; ra++; } - else if (rp->type == BBTYPE_EXH) { + else if (topslot == TOP_IS_IN_ITMP1) { assert(count); - es->intregs[REG_ITMP1] = ss->javastack[i]; /* XXX all platforms? */ + es->intregs[REG_ITMP1] = ss->javastack[i]; count--; i++; ra++; } + + /* write remaining stack slots */ for (; count--; ra++, i++) { assert(ra->next); @@ -859,6 +922,7 @@ void replace_executionstate_println(executionstate *es,codeinfo *code) printf("executionstate %p:\n",(void*)es); printf("\tpc = %p\n",(void*)es->pc); printf("\tsp = %p\n",(void*)es->sp); + printf("\tpv = %p\n",(void*)es->pv); for (i=0; iintregs[i]); } @@ -911,7 +975,7 @@ void replace_sourcestate_println(sourcestate *ss) return; } - printf("sourcestate %p:\n",(void*)ss); + printf("sourcestate %p: stackbase=%p\n",(void*)ss,(void*)ss->stackbase); printf("\tlocals (%d):\n",ss->javalocalcount); for (i=0; ijavalocalcount; ++i) { diff --git a/src/vm/jit/replace.h b/src/vm/jit/replace.h index eb497607e..e36e7aa23 100644 --- a/src/vm/jit/replace.h +++ b/src/vm/jit/replace.h @@ -79,6 +79,8 @@ struct rplpoint { struct executionstate { u1 *pc; /* program counter */ u1 *sp; /* stack pointer within method */ + u1 *pv; /* procedure value. NULL means */ + /* search the AVL tree */ u8 intregs[INT_REG_CNT]; /* register values */ u8 fltregs[FLT_REG_CNT]; /* register values */ @@ -98,6 +100,8 @@ struct sourcestate { u8 *syncslots; s4 syncslotcount; + + u1 *stackbase; }; /*** prototypes ********************************************************/ diff --git a/src/vm/jit/tools/genoffsets.c b/src/vm/jit/tools/genoffsets.c index 9228601fd..f738b46bc 100644 --- a/src/vm/jit/tools/genoffsets.c +++ b/src/vm/jit/tools/genoffsets.c @@ -28,7 +28,7 @@ Changes: Edwin Steiner - $Id: genoffsets.c 4623 2006-03-16 00:05:18Z edwin $ + $Id: genoffsets.c 4643 2006-03-16 18:38:42Z edwin $ */ @@ -84,6 +84,7 @@ int main(int argc, char **argv) printf("#define offes_pc %3d\n", (s4) OFFSET(executionstate, pc)); printf("#define offes_sp %3d\n", (s4) OFFSET(executionstate, sp)); + printf("#define offes_pv %3d\n", (s4) OFFSET(executionstate, pv)); printf("#define offes_intregs %3d\n", (s4) OFFSET(executionstate, intregs)); printf("#define offes_fltregs %3d\n", (s4) OFFSET(executionstate, fltregs)); diff --git a/src/vm/jit/x86_64/asmpart.S b/src/vm/jit/x86_64/asmpart.S index e73e7548f..d03cf2e1e 100644 --- a/src/vm/jit/x86_64/asmpart.S +++ b/src/vm/jit/x86_64/asmpart.S @@ -30,7 +30,7 @@ Changes: Edwin Steiner - $Id: asmpart.S 4623 2006-03-16 00:05:18Z edwin $ + $Id: asmpart.S 4643 2006-03-16 18:38:42Z edwin $ */ @@ -682,6 +682,9 @@ asm_replacement_out: add $(sizeexecutionstate + REPLACEMENT_ROOM + 8),itmp1 mov itmp1,(offes_sp)(sp) + /* pv must be looked up via AVL tree */ + movq $0,(offes_pv)(sp) + /* call replace_me */ mov -8(itmp1),a0 /* rplpoint * */ mov sp,a1 /* arg1: execution state */ -- 2.25.1