* src/vm/jit/stack.c (stack_javalocals_store): New function.
authoredwin <none@none>
Mon, 27 Nov 2006 15:15:54 +0000 (15:15 +0000)
committeredwin <none@none>
Mon, 27 Nov 2006 15:15:54 +0000 (15:15 +0000)
* src/vm/jit/stack.h (stack_javalocals_store): Likewise.

* src/vm/jit/inline/inline.c (inline_clone_instruction): Use
stack_javalocals_store.

* src/vm/jit/replace.c (replace_create_replacement_points): Use
stack_javalocals_store. Other cleanups.

src/vm/jit/inline/inline.c
src/vm/jit/replace.c
src/vm/jit/stack.c
src/vm/jit/stack.h

index f1c4fcf7a2d6375260d15c1f5bc789af11ac9c01..8313d04e0738436e6031441e453acdf1dd0da577 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes:
 
-   $Id: inline.c 6059 2006-11-27 15:03:54Z edwin $
+   $Id: inline.c 6062 2006-11-27 15:15:54Z edwin $
 
 */
 
@@ -1200,19 +1200,7 @@ clone_call:
                case ICMD_FSTORE:
                case ICMD_DSTORE:
                case ICMD_ASTORE:
-                       /* XXX share code with stack.c */
-                       j = n_iptr->dst.varindex;
-                       i = n_iptr->sx.s23.s3.javaindex;
-                       if (i != UNUSED) {
-                               if (n_iptr->flags.bits & INS_FLAG_RETADDR)
-                                       iln->javalocals[i] = n_iptr->sx.s23.s2.retaddrnr;
-                               else
-                                       iln->javalocals[i] = j;
-                               if (n_iptr->flags.bits & INS_FLAG_KILL_PREV)
-                                       iln->javalocals[i-1] = UNUSED;
-                               if (n_iptr->flags.bits & INS_FLAG_KILL_NEXT)
-                                       iln->javalocals[i+1] = UNUSED;
-                       }
+                       stack_javalocals_store(n_iptr, iln->javalocals);
                        break;
        }
 }
index 2120fba07124e9a13f355528d0fda409c2e3c5fd..5e83b50cd037b07f362e8440403bf3078041933e 100644 (file)
@@ -306,6 +306,19 @@ static void replace_create_replacement_point(jitdata *jd,
    
 *******************************************************************************/
 
+#define CLEAR_javalocals(array, method)                              \
+    do {                                                             \
+        for (i=0; i<(method)->maxlocals; ++i)                        \
+            (array)[i] = UNUSED;                                     \
+    } while (0)
+
+#define COUNT_javalocals(array, method, counter)                     \
+    do {                                                             \
+        for (i=0; i<(method)->maxlocals; ++i)                        \
+            if ((array)[i] != UNUSED)                                \
+                               (counter)++;                                         \
+    } while (0)
+
 bool replace_create_replacement_points(jitdata *jd)
 {
        codeinfo        *code;
@@ -372,8 +385,7 @@ bool replace_create_replacement_points(jitdata *jd)
                if (bptr->javalocals)
                        MCOPY(javalocals, bptr->javalocals, s4, m->maxlocals);
                else
-                       for (i=0; i<m->maxlocals; ++i)
-                               javalocals[i] = UNUSED;
+                       CLEAR_javalocals(javalocals, m);
 
                /* iterate over the instructions */
 
@@ -389,9 +401,7 @@ bool replace_create_replacement_points(jitdata *jd)
                                case ICMD_INVOKEINTERFACE:
                                        INSTRUCTION_GET_METHODDESC(iptr, md);
                                        count++;
-                                       for (i=0; i<m->maxlocals; ++i)
-                                               if (javalocals[i] != UNUSED)
-                                                       alloccount++;
+                                       COUNT_javalocals(javalocals, m, alloccount);
                                        alloccount += iptr->s1.argcount;
                                        if (iinfo)
                                                alloccount -= iinfo->throughcount;
@@ -402,19 +412,7 @@ bool replace_create_replacement_points(jitdata *jd)
                                case ICMD_FSTORE:
                                case ICMD_DSTORE:
                                case ICMD_ASTORE:
-                                       /* XXX share code with stack.c */
-                                       j = iptr->dst.varindex;
-                                       i = iptr->sx.s23.s3.javaindex;
-                                       if (i != UNUSED) {
-                                               if (iptr->flags.bits & INS_FLAG_RETADDR)
-                                                       javalocals[i] = iptr->sx.s23.s2.retaddrnr;
-                                               else
-                                                       javalocals[i] = j;
-                                               if (iptr->flags.bits & INS_FLAG_KILL_PREV)
-                                                       javalocals[i-1] = UNUSED;
-                                               if (iptr->flags.bits & INS_FLAG_KILL_NEXT)
-                                                       javalocals[i+1] = UNUSED;
-                                       }
+                                       stack_javalocals_store(iptr, javalocals);
                                        break;
 
                                case ICMD_IRETURN:
@@ -432,9 +430,7 @@ bool replace_create_replacement_points(jitdata *jd)
                                        iinfo = iptr->sx.s23.s3.inlineinfo;
 
                                        count++;
-                                       for (i=0; i<m->maxlocals; ++i)
-                                               if (javalocals[i] != UNUSED)
-                                                       alloccount++;
+                                       COUNT_javalocals(javalocals, m, alloccount);
                                        alloccount += iinfo->stackvarscount;
                                        if (iinfo->synclocal != UNUSED)
                                                alloccount++;
@@ -445,8 +441,7 @@ bool replace_create_replacement_points(jitdata *jd)
 #if !defined(NDEBUG)
                                        else
                                                /* javalocals will be set at next block start */
-                                               for (i=0; i<m->maxlocals; ++i)
-                                                       javalocals[i] = UNUSED;
+                                               CLEAR_javalocals(javalocals, m);
 #endif
                                        break;
 
@@ -460,9 +455,7 @@ bool replace_create_replacement_points(jitdata *jd)
                                                jl = bptr->next->javalocals;
                                        }
                                        count++;
-                                       for (i=0; i<m->maxlocals; ++i)
-                                               if (jl[i] != UNUSED)
-                                                       alloccount++;
+                                       COUNT_javalocals(jl, m, alloccount);
                                        break;
 
                                case ICMD_INLINE_END:
@@ -490,9 +483,7 @@ bool replace_create_replacement_points(jitdata *jd)
                                if (bptr->inlineinfo)
                                        alloccount -= bptr->inlineinfo->throughcount;
 
-                               for (i=0; i<bptr->method->maxlocals; ++i)
-                                       if (bptr->javalocals[i] != UNUSED)
-                                               alloccount++;
+                               COUNT_javalocals(bptr->javalocals, bptr->method, alloccount);
                        }
                }
 
@@ -531,8 +522,7 @@ bool replace_create_replacement_points(jitdata *jd)
                if (bptr->javalocals)
                        MCOPY(javalocals, bptr->javalocals, s4, m->maxlocals);
                else
-                       for (i=0; i<m->maxlocals; ++i)
-                               javalocals[i] = UNUSED;
+                       CLEAR_javalocals(javalocals, m);
 
                /* create replacement points at targets of backward branches */
 
@@ -570,19 +560,7 @@ bool replace_create_replacement_points(jitdata *jd)
                                case ICMD_FSTORE:
                                case ICMD_DSTORE:
                                case ICMD_ASTORE:
-                                       /* XXX share code with stack.c */
-                                       j = iptr->dst.varindex;
-                                       i = iptr->sx.s23.s3.javaindex;
-                                       if (i != UNUSED) {
-                                               if (iptr->flags.bits & INS_FLAG_RETADDR)
-                                                       javalocals[i] = iptr->sx.s23.s2.retaddrnr;
-                                               else
-                                                       javalocals[i] = j;
-                                               if (iptr->flags.bits & INS_FLAG_KILL_PREV)
-                                                       javalocals[i-1] = UNUSED;
-                                               if (iptr->flags.bits & INS_FLAG_KILL_NEXT)
-                                                       javalocals[i+1] = UNUSED;
-                                       }
+                                       stack_javalocals_store(iptr, javalocals);
                                        break;
 
                                case ICMD_IRETURN:
@@ -627,8 +605,7 @@ bool replace_create_replacement_points(jitdata *jd)
 #if !defined(NDEBUG)
                                        else
                                                /* javalocals will be set at next block start */
-                                               for (i=0; i<m->maxlocals; ++i)
-                                                       javalocals[i] = UNUSED;
+                                               CLEAR_javalocals(javalocals, m);
 #endif
                                        break;
 
index d437d5422d3b972ee7b771b52619f50ef77db5a6..52193bf13266cc728c0ebe799384aaa34a9efc92 100644 (file)
@@ -29,7 +29,7 @@
             Christian Thalinger
             Christian Ullrich
 
-   $Id: stack.c 6055 2006-11-27 14:39:58Z edwin $
+   $Id: stack.c 6062 2006-11-27 15:15:54Z edwin $
 
 */
 
@@ -4814,6 +4814,39 @@ throw_stack_category_error:
 }
 
 
+/* stack_javalocals_store ******************************************************
+   Model the effect of a ?STORE instruction upon the given javalocals array.
+  
+   IN:
+       iptr.............the ?STORE instruction
+          javalocals.......the javalocals array to modify
+  
+*******************************************************************************/
+
+void stack_javalocals_store(instruction *iptr, s4 *javalocals)
+{
+       s4 idx;  /* index into the jd->var array */
+       s4 j;    /* java local index             */
+
+       idx = iptr->dst.varindex;
+       j = iptr->sx.s23.s3.javaindex;
+
+       if (j != UNUSED) {
+               if (iptr->flags.bits & INS_FLAG_RETADDR)
+                       javalocals[j] = iptr->sx.s23.s2.retaddrnr;
+               else
+                       javalocals[j] = idx;
+
+               if (iptr->flags.bits & INS_FLAG_KILL_PREV)
+                       javalocals[j-1] = UNUSED;
+
+               if (iptr->flags.bits & INS_FLAG_KILL_NEXT)
+                       javalocals[j+1] = UNUSED;
+       }
+}
+
+
 /* functions for verbose stack analysis output ********************************/
 
 #if defined(STACK_VERBOSE)
index c30a063f5e210fffc4c0b9e79d6ba73df6085c98..a754941cd445bf2bba42b2e9aed8e0c66668d091 100644 (file)
@@ -29,7 +29,7 @@
    Changes: Christian Ullrich
                        Edwin Steiner
 
-   $Id: stack.h 5785 2006-10-15 22:25:54Z edwin $
+   $Id: stack.h 6062 2006-11-27 15:15:54Z edwin $
 
 */
 
@@ -133,6 +133,8 @@ bool stack_init(void);
 
 bool stack_analyse(jitdata *jd);
 
+void stack_javalocals_store(instruction *iptr, s4 *javalocals);
+
 #endif /* _STACK_H */