* src/vm/jit/i386/asmpart.S (asm_replacement_out): Added pv.
authoredwin <none@none>
Thu, 16 Mar 2006 18:38:42 +0000 (18:38 +0000)
committeredwin <none@none>
Thu, 16 Mar 2006 18:38:42 +0000 (18:38 +0000)
* 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
src/vm/jit/i386/asmpart.S
src/vm/jit/replace.c
src/vm/jit/replace.h
src/vm/jit/tools/genoffsets.c
src/vm/jit/x86_64/asmpart.S

index b9cb04413831cad8cbddfe4f76d24a8a5f8a709c..16e0abc4966faec84e6776371fb8793cfe8faa2a 100644 (file)
@@ -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
 
-
index 1967bce77c15b3bbd1c5fa03d62165392414812a..501ab37b56488728eea2ec28cc141e2ad47ee736 100644 (file)
@@ -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              */
index 14d35c269f448826b6f6cf360cdfcf8c477b63af..ae41b779c1a364c8b32e8d9d1fca2c5d7bc2edb1 100644 (file)
 #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; i<count*5; ++i)
                ss->javalocals[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; i<count; ++i)
+               ss->javastack[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; i<code->savedfltcount; ++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; i<INT_REG_CNT; ++i) {
                printf("\t%-3s = %016llx\n",regs[i],(unsigned long long)es->intregs[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; i<ss->javalocalcount; ++i) {
index eb497607eb34eef04a52202ffd4b3c1859fd9a5b..e36e7aa2316707a1b1bc1fc4e28479d3cfe51e73 100644 (file)
@@ -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 ********************************************************/
index 9228601fdf86e31f13e5f4e9ad6890774cea3883..f738b46bc60205268c7cc34b9364c861a7178124 100644 (file)
@@ -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));
 
index e73e7548fa6e9e8e8f030121724b8f525fee8b3e..d03cf2e1ed68cad543d2692a838f4938fad8b387 100644 (file)
@@ -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              */