* src/vm/jit/parse.cpp,
[cacao.git] / src / vm / jit / verify / typecheck.c
index da521e1b1bc501a9aecf070ba58ea7650c1d3129..00e3cfdea6226839a867092752a4ba86cf93d906 100644 (file)
@@ -1,9 +1,7 @@
 /* src/vm/jit/verify/typecheck.c - typechecking (part of bytecode verification)
 
-   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
-   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
-   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
-   J. Wenninger, Institut f. Computersprachen - TU Wien
+   Copyright (C) 1996-2005, 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Contact: cacao@cacaojvm.org
-
-   Authors: Edwin Steiner
-
-   Changes: Christian Thalinger
-
-   $Id: typecheck.c 6275 2007-01-03 22:39:14Z edwin $
-
 */
 
 /*
@@ -141,28 +131,36 @@ error reporting.
     citeseer.ist.psu.edu/article/coglio03improving.html
 */
 
+
 #include "config.h"
-#include "vm/types.h"
-#include "vm/global.h"
 
 #include <assert.h>
 #include <string.h>
 
+#include "vm/types.h"
+
 #ifdef ENABLE_VERIFIER
 
 #include "mm/memory.h"
+
+#include "native/native.hpp"
+
 #include "toolbox/logging.h"
-#include "native/native.h"
-#include "vm/builtin.h"
-#include "vm/jit/patcher.h"
-#include "vm/loader.h"
-#include "vm/options.h"
-#include "vm/jit/jit.h"
-#include "vm/jit/show.h"
-#include "vm/jit/parse.h"
+
 #include "vm/access.h"
-#include "vm/resolve.h"
-#include "vm/exceptions.h"
+#include "vm/array.hpp"
+#include "vm/jit/builtin.hpp"
+#include "vm/exceptions.hpp"
+#include "vm/global.h"
+#include "vm/globals.hpp"
+#include "vm/loader.hpp"
+#include "vm/options.h"
+#include "vm/primitive.hpp"
+#include "vm/resolve.hpp"
+
+#include "vm/jit/jit.hpp"
+#include "vm/jit/parse.hpp"
+#include "vm/jit/show.hpp"
 
 #include <typecheck-common.h>
 
@@ -415,49 +413,49 @@ handle_multianewarray(verifier_state *state)
 
 static void typecheck_invalidate_locals(verifier_state *state, s4 index, bool twoword)
 {
-       s4 i;
+       s4 javaindex;
        s4 t;
-       s4 mapped;
+       s4 varindex;
        jitdata *jd = state->jd;
        s4 *localmap = jd->local_map;
        varinfo *vars = jd->var;
 
-       i = state->reverselocalmap[index];
+       javaindex = jd->reverselocalmap[index];
 
-       /* invalidate locals of two-word type at index i-1 */
+       /* invalidate locals of two-word type at index javaindex-1 */
 
-       if (i > 0) {
-               localmap += 5 * (i-1);
+       if (javaindex > 0) {
+               localmap += 5 * (javaindex-1);
                for (t=0; t<5; ++t) {
-                       mapped = *localmap++;
-                       if (mapped >= 0 && IS_2_WORD_TYPE(vars[mapped].type)) {
-                               LOG1("invalidate local %d", mapped);
-                               vars[mapped].type = TYPE_VOID;
+                       varindex = *localmap++;
+                       if (varindex >= 0 && IS_2_WORD_TYPE(vars[varindex].type)) {
+                               LOG1("invalidate local %d", varindex);
+                               vars[varindex].type = TYPE_VOID;
                        }
                }
        }
        else {
-               localmap += 5 * i;
+               localmap += 5 * javaindex;
        }
 
-       /* invalidate locals at index i */
+       /* invalidate locals at index javaindex */
 
        for (t=0; t<5; ++t) {
-               mapped = *localmap++;
-               if (mapped >= 0) {
-                       LOG1("invalidate local %d", mapped);
-                       vars[mapped].type = TYPE_VOID;
+               varindex = *localmap++;
+               if (varindex >= 0) {
+                       LOG1("invalidate local %d", varindex);
+                       vars[varindex].type = TYPE_VOID;
                }
        }
 
-       /* if a two-word type is written, invalidate locals at index i+1 */
+       /* if a two-word type is written, invalidate locals at index javaindex+1 */
 
        if (twoword) {
                for (t=0; t<5; ++t) {
-                       mapped = *localmap++;
-                       if (mapped >= 0) {
-                               LOG1("invalidate local %d", mapped);
-                               vars[mapped].type = TYPE_VOID;
+                       varindex = *localmap++;
+                       if (varindex >= 0) {
+                               LOG1("invalidate local %d", varindex);
+                               vars[varindex].type = TYPE_VOID;
                        }
                }
        }
@@ -533,7 +531,6 @@ handle_basic_block(verifier_state *state)
 
        LOGSTR1("\n---- BLOCK %04d ------------------------------------------------\n",state->bptr->nr);
        LOGFLUSH;
-       DOLOG(show_basicblock(jd, state->bptr, SHOW_STACK));
 
        superblockend = false;
        state->bptr->flags = BBFINISHED;
@@ -556,6 +553,7 @@ handle_basic_block(verifier_state *state)
        /* init variable types at the start of this block */
        typevector_copy_inplace(state->bptr->inlocals, jd->var, state->numlocals);
 
+       DOLOG(show_basicblock(jd, state->bptr, SHOW_STACK));
        DOLOG(typecheck_print_vararray(stdout, jd, state->bptr->invars, 
                                state->bptr->indepth));
        DOLOG(typevector_print(stdout, jd->var, state->numlocals));
@@ -681,8 +679,6 @@ bool typecheck(jitdata *jd)
        codegendata    *cd;
        varinfo        *savedlocals;
        verifier_state  state;             /* current state of the verifier */
-       s4              i;
-       s4              t;
 
        /* collect statistics */
 
@@ -744,18 +740,12 @@ bool typecheck(jitdata *jd)
     if (state.initmethod) 
                state.numlocals++; /* VERIFIER_EXTRA_LOCALS */
 
-       state.reverselocalmap = DMNEW(s4, state.validlocals);
-       for (i=0; i<jd->maxlocals; ++i)
-               for (t=0; t<5; ++t) {
-                       s4 mapped = jd->local_map[5*i + t];
-                       if (mapped >= 0)
-                               state.reverselocalmap[mapped] = i;
-               }
-
        DOLOG(
+               s4 i;
+               s4 t;
                LOG("reverselocalmap:");
                for (i=0; i<state.validlocals; ++i) {
-                       LOG2("    %i => javaindex %i", i, state.reverselocalmap[i]);
+                       LOG2("    %i => javaindex %i", i, jd->reverselocalmap[i]);
                });
 
     /* allocate the buffer of active exception handlers */