- created jitcache-arm-x86 branch
[cacao.git] / src / vm / resolve.c
index 76eb3192937976e437f120b35b0a8d2ee95e0e3c..a98388550e533d90431e95ef0b5bd482492122a2 100644 (file)
@@ -1,9 +1,7 @@
 /* src/vm/resolve.c - resolving classes/interfaces/fields/methods
 
-   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: Christan Thalinger
-
-   $Id: resolve.c 5655 2006-10-03 20:44:46Z edwin $
-
 */
 
 
 
 #include <assert.h>
 
+#include "vm/types.h"
+
 #include "mm/memory.h"
-#include "vm/resolve.h"
+
 #include "vm/access.h"
-#include "vm/classcache.h"
-#include "vm/descriptor.h"
 #include "vm/exceptions.h"
 #include "vm/global.h"
-#include "vm/linker.h"
-#include "vm/loader.h"
-#include "vm/options.h"
-#include "vm/stringlocal.h"
+#include "vm/primitive.h"
+#include "vm/resolve.h"
+
 #include "vm/jit/jit.h"
 #include "vm/jit/verify/typeinfo.h"
 
+#include "vmcore/classcache.h"
+#include "vmcore/descriptor.h"
+#include "vmcore/linker.h"
+#include "vmcore/loader.h"
+#include "vmcore/options.h"
+
 
 /******************************************************************************/
 /* DEBUG HELPERS                                                              */
 
 /*#define RESOLVE_VERBOSE*/
 
+/* resolve_handle_pending_exception ********************************************
+
+   Convert a pending ClassNotFoundException into a
+   NoClassDefFoundError if requested.
+
+   See: hotspot/src/share/vm/classfile/systemDictionary.cpp
+   (handle_resolution_exception)
+
+   ARGUMENTS:
+       classname .... name of the class currently resolved
+       throwError ... if true throw a NoClassDefFoundError instead of
+                      a ClassNotFoundException
+
+*******************************************************************************/
+
+void resolve_handle_pending_exception(bool throwError)
+{
+       java_handle_t *e;
+
+       /* Get the current exception. */
+
+       e = exceptions_get_exception();
+
+       if (e != NULL) {
+               if (throwError == true) {
+                       /* Convert ClassNotFoundException to
+                          NoClassDefFoundError. */
+
+                       if (builtin_instanceof(e, class_java_lang_ClassNotFoundException)) {
+                               /* Clear exception, because we are calling Java code
+                                  again. */
+
+                               exceptions_clear_exception();
+
+                               /* create new error */
+
+                               exceptions_throw_noclassdeffounderror_cause(e);
+                       }
+                       else {
+                               return;
+                       }
+               }
+               else {
+                       /* An exception conversion was not requested.  Simply
+                          return. */
+
+                       return;
+               }
+       }
+}
+
+
 /******************************************************************************/
 /* CLASS RESOLUTION                                                           */
 /******************************************************************************/
@@ -104,10 +151,13 @@ bool resolve_class_from_name(classinfo *referer,
                                                         bool link,
                                                         classinfo **result)
 {
-       classinfo *cls = NULL;
-       char *utf_ptr;
-       int len;
-       
+       classinfo *cls;
+       char      *utf_ptr;
+       int        len;
+       char      *msg;
+       s4         msglen;
+       utf       *u;
+
        assert(result);
        assert(referer);
        assert(classname);
@@ -173,10 +223,12 @@ bool resolve_class_from_name(classinfo *referer,
 #endif
 
                /* load the class */
-               if (!cls) {
-                       if (!(cls = load_class_from_classloader(classname,
-                                                                                                       referer->classloader)))
-                               return false; /* exception */
+
+               if (cls == NULL) {
+                       cls = load_class_from_classloader(classname, referer->classloader);
+
+                       if (cls == NULL)
+                               return false;
                }
        }
 
@@ -189,19 +241,27 @@ bool resolve_class_from_name(classinfo *referer,
 #endif
        
        /* check access rights of referer to refered class */
+
        if (checkaccess && !access_is_accessible_class(referer,cls)) {
-               int msglen;
-               char *message;
-
-               msglen = utf_bytes(cls->name) + utf_bytes(referer->name) + 100;
-               message = MNEW(char, msglen);
-               strcpy(message, "class is not accessible (");
-               utf_cat_classname(message, cls->name);
-               strcat(message, " from ");
-               utf_cat_classname(message, referer->name);
-               strcat(message, ")");
-               *exceptionptr = new_exception_message(string_java_lang_IllegalAccessException, message);
-               MFREE(message,char,msglen);
+               msglen =
+                       utf_bytes(cls->name) +
+                       utf_bytes(referer->name) +
+                       100;
+
+               msg = MNEW(char, msglen);
+
+               strcpy(msg, "class is not accessible (");
+               utf_cat_classname(msg, cls->name);
+               strcat(msg, " from ");
+               utf_cat_classname(msg, referer->name);
+               strcat(msg, ")");
+
+               u = utf_new_char(msg);
+
+               MFREE(msg, char, msglen);
+
+               exceptions_throw_illegalaccessexception(u);
+
                return false; /* exception */
        }
 
@@ -264,7 +324,10 @@ bool resolve_classref(methodinfo *refmethod,
 /* resolve_classref_or_classinfo ***********************************************
  
    Resolve a symbolic class reference if necessary
-  
+
+   NOTE: If given, refmethod->clazz is used as the referring class.
+         Otherwise, cls.ref->referer is used.
+
    IN:
        refmethod........the method from which resolution was triggered
                         (may be NULL if not applicable)
@@ -298,6 +361,7 @@ bool resolve_classref_or_classinfo(methodinfo *refmethod,
                                                                   classinfo **result)
 {
        classinfo         *c;
+       classinfo         *referer;
        
        assert(cls.any);
        assert(mode == resolveEager || mode == resolveLazy);
@@ -314,7 +378,18 @@ bool resolve_classref_or_classinfo(methodinfo *refmethod,
        if (IS_CLASSREF(cls)) {
                /* we must resolve this reference */
 
-               if (!resolve_class_from_name(cls.ref->referer, refmethod, cls.ref->name,
+               /* determine which class to use as the referer */
+
+               /* Common cases are refmethod == NULL or both referring classes */
+               /* being the same, so the referer usually is cls.ref->referer.    */
+               /* There is one important case where it is not: When we do a      */
+               /* deferred assignability check to a formal argument of a method, */
+               /* we must use refmethod->clazz (the caller's class) to resolve   */
+               /* the type of the formal argument.                               */
+
+               referer = (refmethod) ? refmethod->clazz : cls.ref->referer;
+
+               if (!resolve_class_from_name(referer, refmethod, cls.ref->name,
                                                                         mode, checkaccess, link, &c))
                        goto return_exception;
 
@@ -349,6 +424,33 @@ bool resolve_classref_or_classinfo(methodinfo *refmethod,
 }
 
 
+/* resolve_classref_or_classinfo_eager *****************************************
+   Resolve a symbolic class reference eagerly if necessary.
+   No attempt is made to link the class.
+
+   IN:
+       cls..............class reference or classinfo
+       checkaccess......if true, access rights to the class are checked
+  
+   RETURN VALUE:
+       classinfo *......the resolved class
+       NULL.............an exception has been thrown
+   
+*******************************************************************************/
+
+classinfo *resolve_classref_or_classinfo_eager(classref_or_classinfo cls,
+                                                                                          bool checkaccess)
+{
+       classinfo *c;
+
+       if (!resolve_classref_or_classinfo(NULL, cls, resolveEager, checkaccess, false, &c))
+               return NULL;
+
+       return c;
+}
+
+
 /* resolve_class_from_typedesc *************************************************
  
    Return a classinfo * for the given type descriptor
@@ -397,12 +499,16 @@ bool resolve_class_from_typedesc(typedesc *d, bool checkaccess, bool link, class
        }
        else {
                /* a primitive type */
-               cls = primitivetype_table[d->decltype].class_primitive;
+
+               cls = primitive_class_get_by_type(d->decltype);
+
                assert(cls->state & CLASS_LOADED);
+
                if (!(cls->state & CLASS_LINKED))
                        if (!link_class(cls))
                                return false; /* exception */
        }
+
        assert(cls);
        assert(cls->state & CLASS_LOADED);
        assert(!link || (cls->state & CLASS_LINKED));
@@ -459,9 +565,12 @@ static resolve_result_t resolve_subtype_check(methodinfo *refmethod,
                                                                                          resolve_mode_t mode,
                                                                                          resolve_err_t error)
 {
-       classinfo *subclass;
-       typeinfo subti;
-       typecheck_result r;
+       classinfo        *subclass;
+       typeinfo_t          subti;
+       typecheck_result  r;
+       char             *msg;
+       s4                msglen;
+       utf              *u;
 
        assert(refmethod);
        assert(subtype.any);
@@ -475,7 +584,7 @@ static resolve_result_t resolve_subtype_check(methodinfo *refmethod,
                /* the subclass could not be resolved. therefore we are sure that  */
                /* no instances of this subclass will ever exist -> skip this test */
                /* XXX this assumes that class loading has invariant results (as in JVM spec) */
-               *exceptionptr = NULL;
+               exceptions_clear_exception();
                return resolveSucceeded;
        }
        if (!subclass)
@@ -516,27 +625,38 @@ check_again:
        if (!r) {
                /* sub class relationship is false */
 
-               char *message;
-               int msglen;
-
 #if defined(RESOLVE_VERBOSE)
                printf("SUBTYPE CHECK FAILED!\n");
 #endif
 
-               msglen = utf_bytes(subclass->name) + utf_bytes(CLASSREF_OR_CLASSINFO_NAME(supertype)) + 200;
-               message = MNEW(char, msglen);
-               strcpy(message, (error == resolveIllegalAccessError) ?
-                               "illegal access to protected member ("
-                               : "subtype constraint violated (");
-               utf_cat_classname(message, subclass->name);
-               strcat(message, " is not a subclass of ");
-               utf_cat_classname(message, CLASSREF_OR_CLASSINFO_NAME(supertype));
-               strcat(message, ")");
+               msglen =
+                       utf_bytes(subclass->name) +
+                       utf_bytes(CLASSREF_OR_CLASSINFO_NAME(supertype))
+                       + 200;
+
+               msg = MNEW(char, msglen);
+
+               strcpy(msg, (error == resolveIllegalAccessError) ?
+                          "illegal access to protected member (" :
+                          "subtype constraint violated (");
+
+               utf_cat_classname(msg, subclass->name);
+               strcat(msg, " is not a subclass of ");
+               utf_cat_classname(msg, CLASSREF_OR_CLASSINFO_NAME(supertype));
+               strcat(msg, ")");
+
+               u = utf_new_char(msg);
+
                if (error == resolveIllegalAccessError)
-                       *exceptionptr = new_exception_message(string_java_lang_IllegalAccessException, message);
+                       exceptions_throw_illegalaccessexception(u);
                else
-                       *exceptionptr = exceptions_new_linkageerror(message, NULL);
-               MFREE(message, char, msglen);
+                       exceptions_throw_linkageerror(msg, NULL);
+
+               /* ATTENTION: We probably need msg for
+                  exceptions_throw_linkageerror. */
+
+               MFREE(msg, char, msglen);
+
                return resolveFailed; /* exception */
        }
 
@@ -580,7 +700,7 @@ check_again:
 
 #if defined(ENABLE_VERIFIER)
 static resolve_result_t resolve_lazy_subtype_checks(methodinfo *refmethod,
-                                                                                                       typeinfo *subtinfo,
+                                                                                                       typeinfo_t *subtinfo,
                                                                                                        classref_or_classinfo supertype,
                                                                                                        resolve_err_t error)
 {
@@ -618,7 +738,7 @@ static resolve_result_t resolve_lazy_subtype_checks(methodinfo *refmethod,
 
        if (supertype.cls == class_java_lang_Object
                || (CLASSREF_OR_CLASSINFO_NAME(supertype) == utf_java_lang_Object
-                       && refmethod->class->classloader == NULL))
+                       && refmethod->clazz->classloader == NULL))
        {
                return resolveSucceeded;
        }
@@ -926,6 +1046,32 @@ classinfo * resolve_class_eager(unresolved_class *ref)
 }
 #endif /* ENABLE_VERIFIER */
 
+/* resolve_class_eager_no_access_check *****************************************
+   Resolve an unresolved class reference eagerly. The class is also linked.
+   Access rights are _not_ checked.
+  
+   IN:
+       ref..............struct containing the reference
+   
+   RETURN VALUE:
+       classinfo * to the class, or
+          NULL if an exception has been thrown
+   
+*******************************************************************************/
+
+#ifdef ENABLE_VERIFIER
+classinfo * resolve_class_eager_no_access_check(unresolved_class *ref)
+{
+       classinfo *c;
+
+       if (!resolve_class(ref, resolveEager, false, &c))
+               return NULL;
+
+       return c;
+}
+#endif /* ENABLE_VERIFIER */
+
 /******************************************************************************/
 /* FIELD RESOLUTION                                                           */
 /******************************************************************************/
@@ -939,8 +1085,10 @@ classinfo * resolve_class_eager(unresolved_class *ref)
           fieldref.........the field reference
           container........the class where the field was found
           fi...............the fieldinfo of the resolved field
-          opc..............opcode of the {GET,PUT}{STATIC,FIELD} instruction
-          iptr.............field instruction or NULL
+          instanceti.......instance typeinfo, if available
+          valueti..........value typeinfo, if available
+          isstatic.........true if this is a *STATIC* instruction
+          isput............true if this is a PUT* instruction
   
    RETURN VALUE:
        resolveSucceeded....everything ok
@@ -950,79 +1098,39 @@ classinfo * resolve_class_eager(unresolved_class *ref)
 *******************************************************************************/
 
 #if defined(ENABLE_VERIFIER)
-resolve_result_t resolve_field_verifier_checks(jitdata *jd,
-                                                                                          methodinfo *refmethod,
+resolve_result_t resolve_field_verifier_checks(methodinfo *refmethod,
                                                                                           constant_FMIref *fieldref,
                                                                                           classinfo *container,
                                                                                           fieldinfo *fi,
-                                                                                          s4 opc,
-                                                                                          instruction *iptr)
+                                                                                          typeinfo_t *instanceti,
+                                                                                          typeinfo_t *valueti,
+                                                                                          bool isstatic,
+                                                                                          bool isput)
 {
-       classinfo *declarer;
-       classinfo *referer;
-       resolve_result_t result;
-       bool isstatic = false;
-       bool isput = false;
-       varinfo *instanceslot = NULL;
-       varinfo *valueslot = NULL;
+       classinfo         *declarer;
+       classinfo         *referer;
+       resolve_result_t   result;
        constant_classref *fieldtyperef;
+       char              *msg;
+       s4                 msglen;
+       utf               *u;
 
        assert(refmethod);
        assert(fieldref);
        assert(container);
        assert(fi);
-       assert(!iptr || jd);
 
        /* get the classinfos and the field type */
 
-       referer = refmethod->class;
+       referer = refmethod->clazz;
        assert(referer);
 
-       declarer = fi->class;
+       declarer = fi->clazz;
        assert(declarer);
        assert(referer->state & CLASS_LINKED);
 
        fieldtyperef = fieldref->parseddesc.fd->classref;
 
-       /* get opcode dependent values */
-
-       switch (opc) {
-               case ICMD_PUTFIELD:
-                       isput = true;
-                       if (iptr) {
-                               valueslot = VAROP(iptr->sx.s23.s2);
-                               instanceslot = VAROP(iptr->s1);
-                       }
-                       break;
-
-               case ICMD_PUTFIELDCONST:
-                       isput = true;
-                       if (iptr)
-                               instanceslot = VAROP(iptr->s1);
-                       break;
-
-               case ICMD_PUTSTATIC:
-                       isput = true;
-                       isstatic = true;
-                       if (iptr)
-                               valueslot = VAROP(iptr->s1);
-                       break;
-
-               case ICMD_PUTSTATICCONST:
-                       isput = true;
-                       isstatic = true;
-                       break;
-
-               case ICMD_GETFIELD:
-                       if (iptr)
-                               instanceslot = VAROP(iptr->s1);
-                       break;
-
-               case ICMD_GETSTATIC:
-                       isstatic = true;
-                       break;
-       }
-
        /* check static */
 
 #if true != 1
@@ -1031,76 +1139,83 @@ resolve_result_t resolve_field_verifier_checks(jitdata *jd,
 
        if (((fi->flags & ACC_STATIC) != 0) != isstatic) {
                /* a static field is accessed via an instance, or vice versa */
-               *exceptionptr =
-                       new_exception_message(string_java_lang_IncompatibleClassChangeError,
-                               (fi->flags & ACC_STATIC) ? "static field accessed via instance"
-                                                        : "instance field  accessed without instance");
+               exceptions_throw_incompatibleclasschangeerror(declarer,
+                                                                                                         (fi->flags & ACC_STATIC)
+                                                                                                         ? "static field accessed via instance"
+                                                                                                         : "instance field  accessed without instance");
+
                return resolveFailed;
        }
 
        /* check access rights */
 
        if (!access_is_accessible_member(referer,declarer,fi->flags)) {
-               int msglen;
-               char *message;
-
-               msglen = utf_bytes(declarer->name) + utf_bytes(fi->name) + utf_bytes(referer->name) + 100;
-               message = MNEW(char, msglen);
-               strcpy(message, "field is not accessible (");
-               utf_cat_classname(message, declarer->name);
-               strcat(message, ".");
-               utf_cat(message, fi->name);
-               strcat(message, " from ");
-               utf_cat_classname(message, referer->name);
-               strcat(message, ")");
-               *exceptionptr = new_exception_message(string_java_lang_IllegalAccessException, message);
-               MFREE(message,char,msglen);
+               msglen =
+                       utf_bytes(declarer->name) +
+                       utf_bytes(fi->name) +
+                       utf_bytes(referer->name) +
+                       100;
+
+               msg = MNEW(char, msglen);
+
+               strcpy(msg, "field is not accessible (");
+               utf_cat_classname(msg, declarer->name);
+               strcat(msg, ".");
+               utf_cat(msg, fi->name);
+               strcat(msg, " from ");
+               utf_cat_classname(msg, referer->name);
+               strcat(msg, ")");
+
+               u = utf_new_char(msg);
+
+               MFREE(msg, char, msglen);
+
+               exceptions_throw_illegalaccessexception(u);
+
                return resolveFailed; /* exception */
        }
 
        /* for non-static methods we have to check the constraints on the         */
        /* instance type                                                          */
 
-       if (instanceslot) {
-               typeinfo *insttip;
-               typeinfo tinfo;
+       if (instanceti) {
+               typeinfo_t *insttip;
+               typeinfo_t tinfo;
 
                /* The instanceslot must contain a reference to a non-array type */
 
-               assert(instanceslot->type == TYPE_ADR); /* checked earlier */
-
-               if (!TYPEINFO_IS_REFERENCE(instanceslot->typeinfo)) {
+               if (!TYPEINFO_IS_REFERENCE(*instanceti)) {
                        exceptions_throw_verifyerror(refmethod, "illegal instruction: field access on non-reference");
                        return resolveFailed;
                }
-               if (TYPEINFO_IS_ARRAY(instanceslot->typeinfo)) {
+               if (TYPEINFO_IS_ARRAY(*instanceti)) {
                        exceptions_throw_verifyerror(refmethod, "illegal instruction: field access on array");
                        return resolveFailed;
                }
 
-               if (isput && TYPEINFO_IS_NEWOBJECT(instanceslot->typeinfo))
+               if (isput && TYPEINFO_IS_NEWOBJECT(*instanceti))
                {
                        /* The instruction writes a field in an uninitialized object. */
                        /* This is only allowed when a field of an uninitialized 'this' object is */
                        /* written inside an initialization method                                */
 
                        classinfo *initclass;
-                       instruction *ins = (instruction *) TYPEINFO_NEWOBJECT_INSTRUCTION(instanceslot->typeinfo);
+                       instruction *ins = (instruction *) TYPEINFO_NEWOBJECT_INSTRUCTION(*instanceti);
 
                        if (ins != NULL) {
-                               exceptions_throw_verifyerror(refmethod,"accessing field of uninitialized object");
+                               exceptions_throw_verifyerror(refmethod, "accessing field of uninitialized object");
                                return resolveFailed;
                        }
 
-                       /* XXX check that class of field == refmethod->class */
+                       /* XXX check that class of field == refmethod->clazz */
                        initclass = referer; /* XXX classrefs */
                        assert(initclass->state & CLASS_LINKED);
 
-                       typeinfo_init_classinfo(&tinfo,initclass);
+                       typeinfo_init_classinfo(&tinfo, initclass);
                        insttip = &tinfo;
                }
                else {
-                       insttip = &(instanceslot->typeinfo);
+                       insttip = instanceti;
                }
 
                result = resolve_lazy_subtype_checks(refmethod,
@@ -1115,7 +1230,7 @@ resolve_result_t resolve_field_verifier_checks(jitdata *jd,
                if (((fi->flags & ACC_PROTECTED) != 0) && !SAME_PACKAGE(declarer,referer))
                {
                        result = resolve_lazy_subtype_checks(refmethod,
-                                       &(instanceslot->typeinfo),
+                                       instanceti,
                                        CLASSREF_OR_CLASSINFO(referer),
                                        resolveIllegalAccessError);
                        if (result != resolveSucceeded)
@@ -1126,12 +1241,12 @@ resolve_result_t resolve_field_verifier_checks(jitdata *jd,
 
        /* for PUT* instructions we have to check the constraints on the value type */
 
-       if (valueslot && valueslot->type == TYPE_ADR) {
+       if (valueti) {
                assert(fieldtyperef);
 
                /* check subtype constraints */
                result = resolve_lazy_subtype_checks(refmethod,
-                               &(valueslot->typeinfo),
+                               valueti,
                                CLASSREF_OR_CLASSINFO(fieldtyperef),
                                resolveLinkageError);
 
@@ -1149,7 +1264,7 @@ resolve_result_t resolve_field_verifier_checks(jitdata *jd,
                        return resolveFailed;
        }
 
-       /* XXX impose loading constraing on instance? */
+       /* XXX impose loading constraint on instance? */
 
        /* everything ok */
        return resolveSucceeded;
@@ -1159,10 +1274,14 @@ resolve_result_t resolve_field_verifier_checks(jitdata *jd,
 /* resolve_field_lazy **********************************************************
  
    Resolve an unresolved field reference lazily
+
+   NOTE: This function does NOT do any verification checks. In case of a
+         successful resolution, you must call resolve_field_verifier_checks
+                in order to perform the necessary checks!
   
    IN:
-       iptr.............instruction containing the field reference
           refmethod........the referer method
+          fieldref.........the field reference
   
    RETURN VALUE:
        resolveSucceeded.....the reference has been resolved
@@ -1171,35 +1290,24 @@ resolve_result_t resolve_field_verifier_checks(jitdata *jd,
    
 *******************************************************************************/
 
-resolve_result_t resolve_field_lazy(jitdata *jd,
-                                                                               instruction *iptr,
-                                                                               methodinfo *refmethod)
+resolve_result_t resolve_field_lazy(methodinfo *refmethod,
+                                                                       constant_FMIref *fieldref)
 {
        classinfo *referer;
        classinfo *container;
        fieldinfo *fi;
-       constant_FMIref *fieldref;
-       resolve_result_t result;
 
-       assert(iptr);
        assert(refmethod);
 
        /* the class containing the reference */
 
-       referer = refmethod->class;
+       referer = refmethod->clazz;
        assert(referer);
 
-       /* get the field reference */
-
-       INSTRUCTION_GET_FIELDREF(iptr, fieldref);
-
        /* check if the field itself is already resolved */
 
-       if (IS_FMIREF_RESOLVED(fieldref)) {
-               fi = fieldref->p.field;
-               container = fi->class;
-               goto resolved_the_field;
-       }
+       if (IS_FMIREF_RESOLVED(fieldref))
+               return resolveSucceeded;
 
        /* first we must resolve the class containg the field */
 
@@ -1227,7 +1335,7 @@ resolve_result_t resolve_field_lazy(jitdata *jd,
                /* this error must not be reported now. (It will be reported   */
                /* if eager resolving of this field is ever tried.)           */
 
-               *exceptionptr = NULL;
+               exceptions_clear_exception();
                return resolveDeferred; /* be lazy */
        }
 
@@ -1235,19 +1343,6 @@ resolve_result_t resolve_field_lazy(jitdata *jd,
 
        fieldref->p.field = fi;
 
-resolved_the_field:
-
-#if defined(ENABLE_VERIFIER)
-       if (JITDATA_HAS_FLAG_VERIFY(jd)) {
-               result = resolve_field_verifier_checks(jd,
-                               refmethod, fieldref, container, fi,
-                               iptr->opc, iptr);
-
-               if (result != resolveSucceeded)
-                       return result;
-       }
-#endif /* defined(ENABLE_VERIFIER) */
-
        /* everything ok */
        return resolveSucceeded;
 }
@@ -1299,13 +1394,13 @@ bool resolve_field(unresolved_field *ref,
 
        /* the class containing the reference */
 
-       referer = ref->referermethod->class;
+       referer = ref->referermethod->clazz;
        assert(referer);
 
        /* check if the field itself is already resolved */
        if (IS_FMIREF_RESOLVED(ref->fieldref)) {
                fi = ref->fieldref->p.field;
-               container = fi->class;
+               container = fi->clazz;
                goto resolved_the_field;
        }
 
@@ -1339,7 +1434,7 @@ bool resolve_field(unresolved_field *ref,
                        /* this error must not be reported now. (It will be reported   */
                        /* if eager resolving of this field is ever tried.)           */
 
-                       *exceptionptr = NULL;
+                       exceptions_clear_exception();
                        return true; /* be lazy */
                }
 
@@ -1355,18 +1450,20 @@ resolved_the_field:
        /* Checking opt_verify is ok here, because the NULL iptr guarantees */
        /* that no missing parts of an instruction will be accessed.        */
        if (opt_verify) {
-               checkresult = resolve_field_verifier_checks(NULL,
+               checkresult = resolve_field_verifier_checks(
                                ref->referermethod,
                                ref->fieldref,
                                container,
                                fi,
-                               (ref->flags & RESOLVE_STATIC) ? ICMD_GETSTATIC : ICMD_GETFIELD,
-                               NULL);
+                               NULL, /* instanceti, handled by constraints below */
+                               NULL, /* valueti, handled by constraints below  */
+                               (ref->flags & RESOLVE_STATIC) != 0, /* isstatic */
+                               (ref->flags & RESOLVE_PUTFIELD) != 0 /* isput */);
 
                if (checkresult != resolveSucceeded)
                        return (bool) checkresult;
 
-               declarer = fi->class;
+               declarer = fi->clazz;
                assert(declarer);
                assert(declarer->state & CLASS_LOADED);
                assert(declarer->state & CLASS_LINKED);
@@ -1471,10 +1568,10 @@ methodinfo * resolve_method_invokespecial_lookup(methodinfo *refmethod,
 
        /* get referer and declarer classes */
 
-       referer = refmethod->class;
+       referer = refmethod->clazz;
        assert(referer);
 
-       declarer = mi->class;
+       declarer = mi->clazz;
        assert(declarer);
        assert(referer->state & CLASS_LINKED);
 
@@ -1496,13 +1593,15 @@ methodinfo * resolve_method_invokespecial_lookup(methodinfo *refmethod,
                /* lookup starting with the direct super class of referer      */
 
                if ((referer->flags & ACC_SUPER) != 0) {
-                       mi = class_resolvemethod(referer->super.cls,
+                       mi = class_resolvemethod(referer->super,
                                                                         mi->name,
                                                                         mi->descriptor);
 
                        if (mi == NULL) {
                                /* the spec calls for an AbstractMethodError in this case */
+
                                exceptions_throw_abstractmethoderror();
+
                                return NULL;
                        }
                }
@@ -1519,10 +1618,8 @@ methodinfo * resolve_method_invokespecial_lookup(methodinfo *refmethod,
    IN:
        refmethod........the method containing the reference
           methodref........the method reference
-          container........the class where the method was found
           mi...............the methodinfo of the resolved method
           invokestatic.....true if the method is invoked by INVOKESTATIC
-          iptr.............the invoke instruction, or NULL
   
    RETURN VALUE:
        resolveSucceeded....everything ok
@@ -1532,30 +1629,19 @@ methodinfo * resolve_method_invokespecial_lookup(methodinfo *refmethod,
 *******************************************************************************/
 
 #if defined(ENABLE_VERIFIER)
-resolve_result_t resolve_method_verifier_checks(jitdata *jd,
-                                                                                               methodinfo *refmethod,
+resolve_result_t resolve_method_verifier_checks(methodinfo *refmethod,
                                                                                                constant_FMIref *methodref,
-                                                                                               classinfo *container,
                                                                                                methodinfo *mi,
-                                                                                               bool invokestatic,
-                                                                                               bool invokespecial,
-                                                                                               instruction *iptr)
+                                                                                               bool invokestatic)
 {
        classinfo *declarer;
        classinfo *referer;
-       resolve_result_t result;
-       int instancecount;
-       typedesc *paramtypes;
-       int i;
-       varinfo *instanceslot = NULL;
-       varinfo *param;
-       methoddesc *md;
-       typeinfo tinfo;
-       int type;
+       char      *msg;
+       s4         msglen;
+       utf       *u;
 
        assert(refmethod);
        assert(methodref);
-       assert(container);
        assert(mi);
 
 #ifdef RESOLVE_VERBOSE
@@ -1565,144 +1651,301 @@ resolve_result_t resolve_method_verifier_checks(jitdata *jd,
 
        /* get the classinfos and the method descriptor */
 
-       referer = refmethod->class;
+       referer = refmethod->clazz;
        assert(referer);
 
-       declarer = mi->class;
+       declarer = mi->clazz;
        assert(declarer);
-       assert(referer->state & CLASS_LINKED);
-
-       md = methodref->parseddesc.md;
-       assert(md);
-       assert(md->params);
-
-       instancecount = (invokestatic) ? 0 : 1;
 
        /* check static */
 
        if (((mi->flags & ACC_STATIC) != 0) != (invokestatic != false)) {
                /* a static method is accessed via an instance, or vice versa */
-               *exceptionptr =
-                       new_exception_message(string_java_lang_IncompatibleClassChangeError,
-                               (mi->flags & ACC_STATIC) ? "static method called via instance"
-                                                        : "instance method called without instance");
+               exceptions_throw_incompatibleclasschangeerror(declarer,
+                                                                                                         (mi->flags & ACC_STATIC)
+                                                                                                         ? "static method called via instance"
+                                                                                                         : "instance method called without instance");
+
                return resolveFailed;
        }
 
        /* check access rights */
 
        if (!access_is_accessible_member(referer,declarer,mi->flags)) {
-               int msglen;
-               char *message;
-
                /* XXX clean this up. this should be in exceptions.c */
-               msglen = utf_bytes(declarer->name) + utf_bytes(mi->name) +
-                       utf_bytes(mi->descriptor) + utf_bytes(referer->name) + 100;
-               message = MNEW(char, msglen);
-               strcpy(message, "method is not accessible (");
-               utf_cat_classname(message, declarer->name);
-               strcat(message, ".");
-               utf_cat(message, mi->name);
-               utf_cat(message, mi->descriptor);
-               strcat(message," from ");
-               utf_cat_classname(message, referer->name);
-               strcat(message,")");
-               *exceptionptr = new_exception_message(string_java_lang_IllegalAccessException, message);
-               MFREE(message, char, msglen);
+
+               msglen =
+                       utf_bytes(declarer->name) +
+                       utf_bytes(mi->name) +
+                       utf_bytes(mi->descriptor) +
+                       utf_bytes(referer->name) +
+                       100;
+
+               msg = MNEW(char, msglen);
+
+               strcpy(msg, "method is not accessible (");
+               utf_cat_classname(msg, declarer->name);
+               strcat(msg, ".");
+               utf_cat(msg, mi->name);
+               utf_cat(msg, mi->descriptor);
+               strcat(msg, " from ");
+               utf_cat_classname(msg, referer->name);
+               strcat(msg, ")");
+
+               u = utf_new_char(msg);
+
+               MFREE(msg, char, msglen);
+
+               exceptions_throw_illegalaccessexception(u);
+
                return resolveFailed; /* exception */
        }
 
-       if (iptr) {
-               /* for non-static methods we have to check the constraints on the         */
-               /* instance type                                                          */
+       /* everything ok */
+
+       return resolveSucceeded;
+}
+#endif /* defined(ENABLE_VERIFIER) */
 
-               assert(jd);
 
-               if (!invokestatic) {
-                       instanceslot = VAR(iptr->sx.s23.s2.args[0]);
-               }
+/* resolve_method_instance_type_checks *****************************************
+
+   Check the instance type of a method invocation.
 
-               assert((instanceslot && instancecount == 1) || invokestatic);
+   IN:
+       refmethod........the method containing the reference
+          mi...............the methodinfo of the resolved method
+          instanceti.......typeinfo of the instance slot
+          invokespecial....true if the method is invoked by INVOKESPECIAL
 
-               /* record subtype constraints for the instance type, if any */
-               if (instanceslot) {
-                       typeinfo *tip;
+   RETURN VALUE:
+       resolveSucceeded....everything ok
+          resolveDeferred.....tests could not be done, have been deferred
+       resolveFailed.......exception has been thrown
 
-                       assert(instanceslot->type == TYPE_ADR);
+*******************************************************************************/
 
-                       if (invokespecial &&
-                                       TYPEINFO_IS_NEWOBJECT(instanceslot->typeinfo))
-                       {   /* XXX clean up */
-                               instruction *ins = (instruction *) TYPEINFO_NEWOBJECT_INSTRUCTION(instanceslot->typeinfo);
-                               classref_or_classinfo initclass = (ins) ? ins[-1].sx.val.c
-                                                                                        : CLASSREF_OR_CLASSINFO(refmethod->class);
-                               tip = &tinfo;
-                               if (!typeinfo_init_class(tip,initclass))
-                                       return false;
-                       }
-                       else {
-                               tip = &(instanceslot->typeinfo);
-                       }
+#if defined(ENABLE_VERIFIER)
+resolve_result_t resolve_method_instance_type_checks(methodinfo *refmethod,
+                                                                                                        methodinfo *mi,
+                                                                                                        typeinfo_t *instanceti,
+                                                                                                        bool invokespecial)
+{
+       typeinfo_t         tinfo;
+       typeinfo_t        *tip;
+       resolve_result_t result;
+
+       if (invokespecial && TYPEINFO_IS_NEWOBJECT(*instanceti))
+       {   /* XXX clean up */
+               instruction *ins = (instruction *) TYPEINFO_NEWOBJECT_INSTRUCTION(*instanceti);
+               classref_or_classinfo initclass = (ins) ? ins[-1].sx.val.c
+                                                                        : CLASSREF_OR_CLASSINFO(refmethod->clazz);
+               tip = &tinfo;
+               if (!typeinfo_init_class(tip, initclass))
+                       return false;
+       }
+       else {
+               tip = instanceti;
+       }
+
+       result = resolve_lazy_subtype_checks(refmethod,
+                                                                                tip,
+                                                                                CLASSREF_OR_CLASSINFO(mi->clazz),
+                                                                                resolveLinkageError);
+       if (result != resolveSucceeded)
+               return result;
 
+       /* check protected access */
+
+       /* XXX use other `declarer` than mi->clazz? */
+       if (((mi->flags & ACC_PROTECTED) != 0)
+                       && !SAME_PACKAGE(mi->clazz, refmethod->clazz))
+       {
+               result = resolve_lazy_subtype_checks(refmethod,
+                               tip,
+                               CLASSREF_OR_CLASSINFO(refmethod->clazz),
+                               resolveIllegalAccessError);
+               if (result != resolveSucceeded)
+                       return result;
+       }
+
+       /* everything ok */
+
+       return resolveSucceeded;
+}
+#endif /* defined(ENABLE_VERIFIER) */
+
+
+/* resolve_method_param_type_checks ********************************************
+
+   Check non-instance parameter types of a method invocation.
+
+   IN:
+          jd...............jitdata of the method doing the call
+       refmethod........the method containing the reference
+          iptr.............the invoke instruction
+          mi...............the methodinfo of the resolved method
+          invokestatic.....true if the method is invoked by INVOKESTATIC
+
+   RETURN VALUE:
+       resolveSucceeded....everything ok
+          resolveDeferred.....tests could not be done, have been deferred
+       resolveFailed.......exception has been thrown
+
+*******************************************************************************/
+
+#if defined(ENABLE_VERIFIER)
+resolve_result_t resolve_method_param_type_checks(jitdata *jd, 
+                                                                                                 methodinfo *refmethod,
+                                                                                                 instruction *iptr, 
+                                                                                                 methodinfo *mi,
+                                                                                                 bool invokestatic)
+{
+       varinfo         *param;
+       resolve_result_t result;
+       methoddesc      *md;
+       typedesc        *paramtypes;
+       s4               type;
+       s4               instancecount;
+       s4               i;
+
+       assert(jd);
+
+       instancecount = (invokestatic) ? 0 : 1;
+
+       /* check subtype constraints for TYPE_ADR parameters */
+
+       md = mi->parseddesc;
+       paramtypes = md->paramtypes;
+
+       for (i = md->paramcount-1-instancecount; i>=0; --i) {
+               param = VAR(iptr->sx.s23.s2.args[i+instancecount]);
+               type = md->paramtypes[i+instancecount].type;
+
+               assert(param);
+               assert(type == param->type);
+
+               if (type == TYPE_ADR) {
                        result = resolve_lazy_subtype_checks(refmethod,
-                                                                                                tip,
-                                                                                                CLASSREF_OR_CLASSINFO(container),
-                                                                                                resolveLinkageError);
+                                       &(param->typeinfo),
+                                       CLASSREF_OR_CLASSINFO(paramtypes[i+instancecount].classref),
+                                       resolveLinkageError);
                        if (result != resolveSucceeded)
                                return result;
+               }
+       }
 
-                       /* check protected access */
+       /* everything ok */
 
-                       if (((mi->flags & ACC_PROTECTED) != 0) && !SAME_PACKAGE(declarer,referer))
-                       {
-                               result = resolve_lazy_subtype_checks(refmethod,
-                                               tip,
-                                               CLASSREF_OR_CLASSINFO(referer),
-                                               resolveIllegalAccessError);
-                               if (result != resolveSucceeded)
-                                       return result;
-                       }
+       return resolveSucceeded;
+}
+#endif /* defined(ENABLE_VERIFIER) */
 
-               }
 
-               /* check subtype constraints for TYPE_ADR parameters */
+/* resolve_method_param_type_checks_stackbased *********************************
+
+   Check non-instance parameter types of a method invocation.
+
+   IN:
+       refmethod........the method containing the reference
+          mi...............the methodinfo of the resolved method
+          invokestatic.....true if the method is invoked by INVOKESTATIC
+          stack............TOS before the INVOKE instruction
 
-               assert(md->paramcount == methodref->parseddesc.md->paramcount);
-               paramtypes = md->paramtypes;
+   RETURN VALUE:
+       resolveSucceeded....everything ok
+          resolveDeferred.....tests could not be done, have been deferred
+       resolveFailed.......exception has been thrown
 
-               for (i = md->paramcount-1-instancecount; i>=0; --i) {
-                       param = VAR(iptr->sx.s23.s2.args[i+instancecount]);
-                       type = md->paramtypes[i+instancecount].type;
+*******************************************************************************/
 
-                       assert(param);
-                       assert(type == param->type);
+#if defined(ENABLE_VERIFIER)
+resolve_result_t resolve_method_param_type_checks_stackbased(
+               methodinfo *refmethod, 
+               methodinfo *mi,
+               bool invokestatic, 
+               typedescriptor_t *stack)
+{
+       typedescriptor_t  *param;
+       resolve_result_t result;
+       methoddesc      *md;
+       typedesc        *paramtypes;
+       s4               type;
+       s4               instancecount;
+       s4               i;
 
-                       if (type == TYPE_ADR) {
-                               result = resolve_lazy_subtype_checks(refmethod,
-                                               &(param->typeinfo),
-                                               CLASSREF_OR_CLASSINFO(paramtypes[i+instancecount].classref),
-                                               resolveLinkageError);
-                               if (result != resolveSucceeded)
-                                       return result;
-                       }
+       instancecount = (invokestatic) ? 0 : 1;
+
+       /* check subtype constraints for TYPE_ADR parameters */
+
+       md = mi->parseddesc;
+       paramtypes = md->paramtypes;
+
+       param = stack - (md->paramslots - 1 - instancecount);
+
+       for (i = instancecount; i < md->paramcount; ++i) {
+               type = md->paramtypes[i].type;
+
+               assert(type == param->type);
+
+               if (type == TYPE_ADR) {
+                       result = resolve_lazy_subtype_checks(refmethod,
+                                       &(param->typeinfo),
+                                       CLASSREF_OR_CLASSINFO(paramtypes[i].classref),
+                                       resolveLinkageError);
+                       if (result != resolveSucceeded)
+                               return result;
                }
 
-       } /* if (iptr) */
+               param += (IS_2_WORD_TYPE(type)) ? 2 : 1;
+       }
+
+       /* everything ok */
+
+       return resolveSucceeded;
+}
+#endif /* defined(ENABLE_VERIFIER) */
+
+
+/* resolve_method_loading_constraints ******************************************
+
+   Impose loading constraints on the parameters and return type of the
+   given method.
+
+   IN:
+       referer..........the class refering to the method
+          mi...............the method
+
+   RETURN VALUE:
+       true................everything ok
+          false...............an exception has been thrown
+
+*******************************************************************************/
+
+#if defined(ENABLE_VERIFIER)
+bool resolve_method_loading_constraints(classinfo *referer,
+                                                                               methodinfo *mi)
+{
+       methoddesc *md;
+       typedesc   *paramtypes;
+       utf        *name;
+       s4          i;
+       s4          instancecount;
 
        /* impose loading constraints on parameters (including instance) */
 
+       md = mi->parseddesc;
        paramtypes = md->paramtypes;
+       instancecount = (mi->flags & ACC_STATIC) / ACC_STATIC;
 
        for (i = 0; i < md->paramcount; i++) {
                if (i < instancecount || paramtypes[i].type == TYPE_ADR) {
-                       utf *name;
-
                        if (i < instancecount) {
                                /* The type of the 'this' pointer is the class containing */
                                /* the method definition. Since container is the same as, */
                                /* or a subclass of declarer, we also constrain declarer  */
                                /* by transitivity of loading constraints.                */
-                               name = container->name;
+                               name = mi->clazz->name;
                        }
                        else {
                                name = paramtypes[i].classref->name;
@@ -1711,8 +1954,8 @@ resolve_result_t resolve_method_verifier_checks(jitdata *jd,
                        /* The caller (referer) and the callee (container) must agree */
                        /* on the types of the parameters.                            */
                        if (!classcache_add_constraint(referer->classloader,
-                                                                                  container->classloader, name))
-                               return resolveFailed; /* exception */
+                                                                                  mi->clazz->classloader, name))
+                               return false; /* exception */
                }
        }
 
@@ -1721,23 +1964,31 @@ resolve_result_t resolve_method_verifier_checks(jitdata *jd,
        if (md->returntype.type == TYPE_ADR) {
                /* The caller (referer) and the callee (container) must agree */
                /* on the return type.                                        */
-               if (!classcache_add_constraint(referer->classloader,container->classloader,
-                               md->returntype.classref->name))
-                       return resolveFailed; /* exception */
+               if (!classcache_add_constraint(referer->classloader,
+                                       mi->clazz->classloader,
+                                       md->returntype.classref->name))
+                       return false; /* exception */
        }
 
        /* everything ok */
-       return resolveSucceeded;
+
+       return true;
 }
 #endif /* defined(ENABLE_VERIFIER) */
 
+
 /* resolve_method_lazy *********************************************************
  
    Resolve an unresolved method reference lazily
   
+   NOTE: This function does NOT do any verification checks. In case of a
+         successful resolution, you must call resolve_method_verifier_checks
+                in order to perform the necessary checks!
+  
    IN:
-       iptr.............instruction containing the method reference
           refmethod........the referer method
+          methodref........the method reference
+          invokespecial....true if this is an INVOKESPECIAL instruction
   
    RETURN VALUE:
        resolveSucceeded.....the reference has been resolved
@@ -1746,17 +1997,14 @@ resolve_result_t resolve_method_verifier_checks(jitdata *jd,
    
 *******************************************************************************/
 
-resolve_result_t resolve_method_lazy(jitdata *jd,
-                                                                                instruction *iptr,
-                                                                                methodinfo *refmethod)
+resolve_result_t resolve_method_lazy(methodinfo *refmethod,
+                                                                        constant_FMIref *methodref,
+                                                                        bool invokespecial)
 {
        classinfo *referer;
        classinfo *container;
        methodinfo *mi;
-       constant_FMIref *methodref;
-       resolve_result_t result;
 
-       assert(iptr);
        assert(refmethod);
 
 #ifdef RESOLVE_VERBOSE
@@ -1765,20 +2013,13 @@ resolve_result_t resolve_method_lazy(jitdata *jd,
 
        /* the class containing the reference */
 
-       referer = refmethod->class;
+       referer = refmethod->clazz;
        assert(referer);
 
-       /* the method reference */
-
-       INSTRUCTION_GET_METHODREF(iptr, methodref);
-
        /* check if the method itself is already resolved */
 
-       if (IS_FMIREF_RESOLVED(methodref)) {
-               mi = methodref->p.method;
-               container = mi->class;
-               goto resolved_the_method;
-       }
+       if (IS_FMIREF_RESOLVED(methodref))
+               return resolveSucceeded;
 
        /* first we must resolve the class containg the method */
 
@@ -1814,11 +2055,11 @@ resolve_result_t resolve_method_lazy(jitdata *jd,
                /* this error must not be reported now. (It will be reported   */
                /* if eager resolving of this method is ever tried.)           */
 
-               *exceptionptr = NULL;
+               exceptions_clear_exception();
                return resolveDeferred; /* be lazy */
        }
 
-       if (iptr->opc == ICMD_INVOKESPECIAL) {
+       if (invokespecial) {
                mi = resolve_method_invokespecial_lookup(refmethod, mi);
                if (!mi)
                        return resolveFailed; /* exception */
@@ -1834,31 +2075,8 @@ resolve_result_t resolve_method_lazy(jitdata *jd,
 
        methodref->p.method = mi;
 
-resolved_the_method:
-
-#if defined(ENABLE_VERIFIER)
-       if (JITDATA_HAS_FLAG_VERIFY(jd)) {
-               result = resolve_method_verifier_checks(jd,
-                                                                                               refmethod, methodref,
-                                                                                               container,
-                                                                                               mi,
-                                                                                               iptr->opc == ICMD_INVOKESTATIC,
-                                                                                               iptr->opc == ICMD_INVOKESPECIAL,
-                                                                                               iptr);
-               if (result != resolveSucceeded)
-                       return result;
-       }
-#endif /* defined(ENABLE_VERIFIER) */
-
-       /* if this call is monomorphic, turn it into an INVOKESPECIAL */
-
-       if ((iptr->opc == ICMD_INVOKEVIRTUAL)
-               && (mi->flags & (ACC_FINAL | ACC_PRIVATE)))
-       {
-               iptr->opc = ICMD_INVOKESPECIAL;
-       }
-
        /* succeed */
+
        return resolveSucceeded;
 }
 
@@ -1909,14 +2127,14 @@ bool resolve_method(unresolved_method *ref, resolve_mode_t mode, methodinfo **re
 
        /* the class containing the reference */
 
-       referer = ref->referermethod->class;
+       referer = ref->referermethod->clazz;
        assert(referer);
 
        /* check if the method itself is already resolved */
 
        if (IS_FMIREF_RESOLVED(ref->methodref)) {
                mi = ref->methodref->p.method;
-               container = mi->class;
+               container = mi->clazz;
                goto resolved_the_method;
        }
 
@@ -1956,7 +2174,7 @@ bool resolve_method(unresolved_method *ref, resolve_mode_t mode, methodinfo **re
                        /* this error must not be reported now. (It will be reported   */
                        /* if eager resolving of this method is ever tried.)           */
 
-                       *exceptionptr = NULL;
+                       exceptions_clear_exception();
                        return true; /* be lazy */
                }
 
@@ -1984,23 +2202,23 @@ bool resolve_method(unresolved_method *ref, resolve_mode_t mode, methodinfo **re
 resolved_the_method:
 
 #ifdef ENABLE_VERIFIER
-       /* Checking opt_verify is ok here, because the NULL iptr guarantees */
-       /* that no missing parts of an instruction will be accessed.        */
        if (opt_verify) {
 
-               checkresult = resolve_method_verifier_checks(NULL,
+               checkresult = resolve_method_verifier_checks(
                                ref->referermethod,
                                ref->methodref,
-                               container,
                                mi,
-                               (ref->flags & RESOLVE_STATIC),
-                               (ref->flags & RESOLVE_SPECIAL),
-                               NULL);
+                               (ref->flags & RESOLVE_STATIC));
 
                if (checkresult != resolveSucceeded)
                        return (bool) checkresult;
 
-               declarer = mi->class;
+               /* impose loading constraints on params and return type */
+
+               if (!resolve_method_loading_constraints(referer, mi))
+                       return false;
+
+               declarer = mi->clazz;
                assert(declarer);
                assert(referer->state & CLASS_LINKED);
 
@@ -2023,7 +2241,7 @@ resolved_the_method:
 
                /* check subtype constraints for TYPE_ADR parameters */
 
-               assert(mi->parseddesc->paramcount == ref->methodref->parseddesc.md->paramcount);
+               assert(mi == ref->methodref->p.method || mi->parseddesc->paramcount == ref->methodref->parseddesc.md->paramcount);
                paramtypes = mi->parseddesc->paramtypes;
 
                for (i = 0; i < mi->parseddesc->paramcount-instancecount; i++) {
@@ -2091,7 +2309,7 @@ methodinfo * resolve_method_eager(unresolved_method *ref)
 static bool unresolved_subtype_set_from_typeinfo(classinfo *referer,
                                                                                                 methodinfo *refmethod,
                                                                                                 unresolved_subtype_set *stset,
-                                                                                                typeinfo *tinfo,
+                                                                                                typeinfo_t *tinfo,
                                                                                                 utf *declaredclassname)
 {
        int count;
@@ -2195,7 +2413,7 @@ empty_set:
 #ifdef ENABLE_VERIFIER
 unresolved_class * create_unresolved_class(methodinfo *refmethod,
                                                                                   constant_classref *classref,
-                                                                                  typeinfo *valuetype)
+                                                                                  typeinfo_t *valuetype)
 {
        unresolved_class *ref;
 
@@ -2226,7 +2444,7 @@ unresolved_class * create_unresolved_class(methodinfo *refmethod,
 }
 #endif /* ENABLE_VERIFIER */
 
-/* create_unresolved_field *****************************************************
+/* resolve_create_unresolved_field *********************************************
  
    Create an unresolved_field struct for the given field access instruction
   
@@ -2241,9 +2459,9 @@ unresolved_class * create_unresolved_class(methodinfo *refmethod,
 
 *******************************************************************************/
 
-unresolved_field * create_unresolved_field(classinfo *referer,
-                                                                                          methodinfo *refmethod,
-                                                                                          instruction *iptr)
+unresolved_field * resolve_create_unresolved_field(classinfo *referer,
+                                                                                                  methodinfo *refmethod,
+                                                                                                  instruction *iptr)
 {
        unresolved_field *ref;
        constant_FMIref *fieldref = NULL;
@@ -2300,7 +2518,6 @@ unresolved_field * create_unresolved_field(classinfo *referer,
        printf("    desc   : ");utf_fprint_printable_ascii(stdout,fieldref->descriptor);fputc('\n',stdout);
        printf("    type   : ");descriptor_debug_print_typedesc(stdout,fieldref->parseddesc.fd);
        fputc('\n',stdout);
-       /*printf("    opcode : %d %s\n",iptr->opc,icmd_names[iptr->opc]);*/
 #endif
 
        ref->fieldref = fieldref;
@@ -2308,7 +2525,7 @@ unresolved_field * create_unresolved_field(classinfo *referer,
        return ref;
 }
 
-/* constrain_unresolved_field **********************************************
+/* resolve_constrain_unresolved_field ******************************************
  
    Record subtype constraints for a field access.
   
@@ -2316,7 +2533,8 @@ unresolved_field * create_unresolved_field(classinfo *referer,
        ref..............the unresolved_field structure of the access
        referer..........the class containing the reference
           refmethod........the method triggering the resolution (if any)
-          iptr.............the {GET,PUT}{FIELD,STATIC}{,CONST} instruction
+          instanceti.......instance typeinfo, if available
+          valueti..........value typeinfo, if available
 
    RETURN VALUE:
        true.............everything ok
@@ -2324,17 +2542,16 @@ unresolved_field * create_unresolved_field(classinfo *referer,
 
 *******************************************************************************/
 
-#ifdef ENABLE_VERIFIER
-bool constrain_unresolved_field(jitdata *jd,
-                                                                       unresolved_field *ref,
-                                                                       classinfo *referer, methodinfo *refmethod,
-                                                                       instruction *iptr)
+#if defined(ENABLE_VERIFIER)
+bool resolve_constrain_unresolved_field(unresolved_field *ref,
+                                                                               classinfo *referer, 
+                                                                               methodinfo *refmethod,
+                                                                           typeinfo_t *instanceti,
+                                                                           typeinfo_t *valueti)
 {
        constant_FMIref *fieldref;
-       varinfo *instanceslot = NULL;
        int type;
-       typeinfo tinfo;
-       typeinfo *tip = NULL;
+       typeinfo_t tinfo;
        typedesc *fd;
 
        assert(ref);
@@ -2352,73 +2569,57 @@ bool constrain_unresolved_field(jitdata *jd,
        printf("    desc   : ");utf_fprint_printable_ascii(stdout,fieldref->descriptor);fputc('\n',stdout);
        printf("    type   : ");descriptor_debug_print_typedesc(stdout,fieldref->parseddesc.fd);
        fputc('\n',stdout);
-       /*printf("    opcode : %d %s\n",iptr[0].opc,icmd_names[iptr[0].opc]);*/
 #endif
 
-       switch (iptr[0].opc) {
-               case ICMD_PUTFIELD:
-                       instanceslot = VAROP(iptr->s1);
-                       tip = &(VAROP(iptr->sx.s23.s2)->typeinfo);
-                       break;
-
-               case ICMD_PUTFIELDCONST:
-                       instanceslot = VAROP(iptr->s1);
-                       break;
-
-               case ICMD_PUTSTATIC:
-                       tip = &(VAROP(iptr->s1)->typeinfo);
-                       break;
-
-               case ICMD_GETFIELD:
-                       instanceslot = VAROP(iptr->s1);
-                       break;
-       }
-
-       assert(instanceslot || ((ref->flags & RESOLVE_STATIC) != 0));
+       assert(instanceti || ((ref->flags & RESOLVE_STATIC) != 0));
        fd = fieldref->parseddesc.fd;
        assert(fd);
 
        /* record subtype constraints for the instance type, if any */
-       if (instanceslot) {
-               typeinfo *insttip;
+       if (instanceti) {
+               typeinfo_t *insttip;
 
                /* The instanceslot must contain a reference to a non-array type */
-               if (!TYPEINFO_IS_REFERENCE(instanceslot->typeinfo)) {
-                       exceptions_throw_verifyerror(refmethod, "illegal instruction: field access on non-reference");
+               if (!TYPEINFO_IS_REFERENCE(*instanceti)) {
+                       exceptions_throw_verifyerror(refmethod, 
+                                       "illegal instruction: field access on non-reference");
                        return false;
                }
-               if (TYPEINFO_IS_ARRAY(instanceslot->typeinfo)) {
-                       exceptions_throw_verifyerror(refmethod, "illegal instruction: field access on array");
+               if (TYPEINFO_IS_ARRAY(*instanceti)) {
+                       exceptions_throw_verifyerror(refmethod, 
+                                       "illegal instruction: field access on array");
                        return false;
                }
 
                if (((ref->flags & RESOLVE_PUTFIELD) != 0) &&
-                               TYPEINFO_IS_NEWOBJECT(instanceslot->typeinfo))
+                               TYPEINFO_IS_NEWOBJECT(*instanceti))
                {
                        /* The instruction writes a field in an uninitialized object. */
                        /* This is only allowed when a field of an uninitialized 'this' object is */
                        /* written inside an initialization method                                */
 
                        classinfo *initclass;
-                       instruction *ins = (instruction *) TYPEINFO_NEWOBJECT_INSTRUCTION(instanceslot->typeinfo);
+                       instruction *ins = (instruction *) TYPEINFO_NEWOBJECT_INSTRUCTION(*instanceti);
 
                        if (ins != NULL) {
-                               exceptions_throw_verifyerror(refmethod,"accessing field of uninitialized object");
+                               exceptions_throw_verifyerror(refmethod, 
+                                               "accessing field of uninitialized object");
                                return false;
                        }
-                       /* XXX check that class of field == refmethod->class */
-                       initclass = refmethod->class; /* XXX classrefs */
+                       /* XXX check that class of field == refmethod->clazz */
+                       initclass = refmethod->clazz; /* XXX classrefs */
                        assert(initclass->state & CLASS_LOADED);
                        assert(initclass->state & CLASS_LINKED);
 
-                       typeinfo_init_classinfo(&tinfo,initclass);
+                       typeinfo_init_classinfo(&tinfo, initclass);
                        insttip = &tinfo;
                }
                else {
-                       insttip = &(instanceslot->typeinfo);
+                       insttip = instanceti;
                }
-               if (!unresolved_subtype_set_from_typeinfo(referer,refmethod,
-                                       &(ref->instancetypes),insttip, FIELDREF_CLASSNAME(fieldref)))
+               if (!unresolved_subtype_set_from_typeinfo(referer, refmethod,
+                                       &(ref->instancetypes), insttip, 
+                                       FIELDREF_CLASSNAME(fieldref)))
                        return false;
        }
        else {
@@ -2428,20 +2629,10 @@ bool constrain_unresolved_field(jitdata *jd,
        /* record subtype constraints for the value type, if any */
        type = fd->type;
        if (type == TYPE_ADR && ((ref->flags & RESOLVE_PUTFIELD) != 0)) {
-               if (!tip) {
-                       /* we have a PUTSTATICCONST or PUTFIELDCONST with TYPE_ADR */
-                       tip = &tinfo;
-                       if (iptr->sx.val.anyptr) {
-                               assert(class_java_lang_String);
-                               assert(class_java_lang_String->state & CLASS_LOADED);
-                               assert(class_java_lang_String->state & CLASS_LINKED);
-                               typeinfo_init_classinfo(&tinfo,class_java_lang_String);
-                       }
-                       else
-                               TYPEINFO_INIT_NULLTYPE(tinfo);
-               }
-               if (!unresolved_subtype_set_from_typeinfo(referer,refmethod,
-                                       &(ref->valueconstraints),tip,fieldref->parseddesc.fd->classref->name))
+               assert(valueti);
+               if (!unresolved_subtype_set_from_typeinfo(referer, refmethod,
+                                       &(ref->valueconstraints), valueti, 
+                                       fieldref->parseddesc.fd->classref->name))
                        return false;
        }
        else {
@@ -2452,7 +2643,7 @@ bool constrain_unresolved_field(jitdata *jd,
 }
 #endif /* ENABLE_VERIFIER */
 
-/* create_unresolved_method ****************************************************
+/* resolve_create_unresolved_method ********************************************
  
    Create an unresolved_method struct for the given method invocation
   
@@ -2467,39 +2658,35 @@ bool constrain_unresolved_field(jitdata *jd,
 
 *******************************************************************************/
 
-unresolved_method * create_unresolved_method(classinfo *referer,
-                                                                                                methodinfo *refmethod,
-                                                                                                instruction *iptr)
+unresolved_method * resolve_create_unresolved_method(classinfo *referer,
+                                                                                                        methodinfo *refmethod,
+                                                                                                        constant_FMIref *methodref,
+                                                                                                        bool invokestatic,
+                                                                                                        bool invokespecial)
 {
        unresolved_method *ref;
-       constant_FMIref *methodref;
-       bool staticmethod;
 
-       methodref = iptr->sx.s23.s3.fmiref;
        assert(methodref);
-       staticmethod = (iptr->opc == ICMD_INVOKESTATIC);
 
 #ifdef RESOLVE_VERBOSE
        printf("create_unresolved_method\n");
        printf("    referer: ");utf_fprint_printable_ascii(stdout,referer->name);fputc('\n',stdout);
        printf("    rmethod: ");utf_fprint_printable_ascii(stdout,refmethod->name);fputc('\n',stdout);
        printf("    rmdesc : ");utf_fprint_printable_ascii(stdout,refmethod->descriptor);fputc('\n',stdout);
-/*     printf("    class  : ");utf_fprint_printable_ascii(stdout,methodref->p.classref->name);fputc('\n',stdout);*/
        printf("    name   : ");utf_fprint_printable_ascii(stdout,methodref->name);fputc('\n',stdout);
        printf("    desc   : ");utf_fprint_printable_ascii(stdout,methodref->descriptor);fputc('\n',stdout);
-       /*printf("    opcode : %d %s\n",iptr->opc,icmd_names[iptr->opc]);*/
 #endif
 
        /* allocate params if necessary */
        if (!methodref->parseddesc.md->params)
                if (!descriptor_params_from_paramtypes(methodref->parseddesc.md,
-                                       (staticmethod) ? ACC_STATIC : ACC_NONE))
+                                       (invokestatic) ? ACC_STATIC : ACC_NONE))
                        return NULL;
 
        /* create the data structure */
        ref = NEW(unresolved_method);
-       ref->flags = ((staticmethod) ? RESOLVE_STATIC : 0)
-                          | ((iptr->opc == ICMD_INVOKESPECIAL) ? RESOLVE_SPECIAL : 0);
+       ref->flags = ((invokestatic) ? RESOLVE_STATIC : 0)
+                          | ((invokespecial) ? RESOLVE_SPECIAL : 0);
        ref->referermethod = refmethod;
        ref->methodref = methodref;
        ref->paramconstraints = NULL;
@@ -2508,9 +2695,10 @@ unresolved_method * create_unresolved_method(classinfo *referer,
        return ref;
 }
 
-/* constrain_unresolved_method *********************************************
+
+/* resolve_constrain_unresolved_method_instance ********************************
  
-   Record subtype constraints for the arguments of a method call.
+   Record subtype constraints for the instance argument of a method call.
   
    IN:
        ref..............the unresolved_method structure of the call
@@ -2524,78 +2712,102 @@ unresolved_method * create_unresolved_method(classinfo *referer,
 
 *******************************************************************************/
 
-#ifdef ENABLE_VERIFIER
-bool constrain_unresolved_method(jitdata *jd,
-                                                                        unresolved_method *ref,
-                                                                        classinfo *referer, methodinfo *refmethod,
-                                                                        instruction *iptr)
+#if defined(ENABLE_VERIFIER)
+bool resolve_constrain_unresolved_method_instance(unresolved_method *ref,
+                                                                                                 methodinfo *refmethod,
+                                                                                                 typeinfo_t *instanceti,
+                                                                                                 bool invokespecial)
 {
-       constant_FMIref *methodref;
+       constant_FMIref   *methodref;
        constant_classref *instanceref;
-       varinfo *instanceslot = NULL;
-       varinfo *param;
-       methoddesc *md;
-       typeinfo tinfo;
-       int i,j;
-       int type;
-       int instancecount;
+       typeinfo_t           tinfo;
+       typeinfo_t          *tip;
 
        assert(ref);
        methodref = ref->methodref;
        assert(methodref);
-       md = methodref->parseddesc.md;
-       assert(md);
-       assert(md->params != NULL);
 
        /* XXX clean this up */
        instanceref = IS_FMIREF_RESOLVED(methodref)
-               ? class_get_self_classref(methodref->p.method->class)
+               ? class_get_self_classref(methodref->p.method->clazz)
                : methodref->p.classref;
 
 #ifdef RESOLVE_VERBOSE
-       printf("constrain_unresolved_method\n");
-       printf("    referer: "); class_println(referer);
+       printf("resolve_constrain_unresolved_method_instance\n");
        printf("    rmethod: "); method_println(refmethod);
        printf("    mref   : "); method_methodref_println(methodref);
-       /*printf("    opcode : %d %s\n",iptr[0].opc,icmd_names[iptr[0].opc]);*/
 #endif
 
-       if ((ref->flags & RESOLVE_STATIC) == 0) {
-               /* find the instance slot under all the parameter slots on the stack */
-               instanceslot = VAR(iptr->sx.s23.s2.args[0]);
-               instancecount = 1;
+       /* record subtype constraints for the instance type, if any */
+
+       if (invokespecial && TYPEINFO_IS_NEWOBJECT(*instanceti))
+       {   /* XXX clean up */
+               instruction *ins = (instruction *) TYPEINFO_NEWOBJECT_INSTRUCTION(*instanceti);
+               classref_or_classinfo initclass = (ins) ? ins[-1].sx.val.c
+                                                                        : CLASSREF_OR_CLASSINFO(refmethod->clazz);
+               tip = &tinfo;
+               if (!typeinfo_init_class(tip, initclass))
+                       return false;
        }
        else {
-               instancecount = 0;
+               tip = instanceti;
        }
 
-       assert((instanceslot && instancecount==1) || ((ref->flags & RESOLVE_STATIC) != 0));
+       if (!unresolved_subtype_set_from_typeinfo(refmethod->clazz, refmethod,
+                               &(ref->instancetypes),tip,instanceref->name))
+               return false;
 
-       /* record subtype constraints for the instance type, if any */
-       if (instanceslot) {
-               typeinfo *tip;
-
-               assert(instanceslot->type == TYPE_ADR);
-
-               if (iptr[0].opc == ICMD_INVOKESPECIAL &&
-                               TYPEINFO_IS_NEWOBJECT(instanceslot->typeinfo))
-               {   /* XXX clean up */
-                       instruction *ins = (instruction *) TYPEINFO_NEWOBJECT_INSTRUCTION(instanceslot->typeinfo);
-                       classref_or_classinfo initclass = (ins) ? ins[-1].sx.val.c
-                                                                                : CLASSREF_OR_CLASSINFO(refmethod->class);
-                       tip = &tinfo;
-                       if (!typeinfo_init_class(tip,initclass))
-                               return false;
-               }
-               else {
-                       tip = &(instanceslot->typeinfo);
-               }
-               if (!unresolved_subtype_set_from_typeinfo(referer,refmethod,
-                                       &(ref->instancetypes),tip,instanceref->name))
-                       return false;
-       }
+       return true;
+}
+#endif /* defined(ENABLE_VERIFIER) */
+
+
+/* resolve_constrain_unresolved_method_params  *********************************
+   Record subtype constraints for the non-instance arguments of a method call.
+  
+   IN:
+       jd...............current jitdata (for looking up variables)
+       ref..............the unresolved_method structure of the call
+          refmethod........the method triggering the resolution (if any)
+          iptr.............the INVOKE* instruction
+
+   RETURN VALUE:
+       true.............everything ok
+          false............an exception has been thrown
+
+*******************************************************************************/
+
+#if defined(ENABLE_VERIFIER)
+bool resolve_constrain_unresolved_method_params(jitdata *jd,
+                                                                                               unresolved_method *ref,
+                                                                                               methodinfo *refmethod,
+                                                                                               instruction *iptr)
+{
+       constant_FMIref *methodref;
+       varinfo *param;
+       methoddesc *md;
+       int i,j;
+       int type;
+       int instancecount;
+
+       assert(ref);
+       methodref = ref->methodref;
+       assert(methodref);
+       md = methodref->parseddesc.md;
+       assert(md);
+       assert(md->params != NULL);
+
+#ifdef RESOLVE_VERBOSE
+       printf("resolve_constrain_unresolved_method_params\n");
+       printf("    rmethod: "); method_println(refmethod);
+       printf("    mref   : "); method_methodref_println(methodref);
+#endif
+
+       instancecount = (ref->flags & RESOLVE_STATIC) ? 0 : 1;
 
        /* record subtype constraints for the parameter types, if any */
+
        for (i=md->paramcount-1-instancecount; i>=0; --i) {
                param = VAR(iptr->sx.s23.s2.args[i+instancecount]);
                type = md->paramtypes[i+instancecount].type;
@@ -2610,7 +2822,7 @@ bool constrain_unresolved_method(jitdata *jd,
                                        UNRESOLVED_SUBTYPE_SET_EMTPY(ref->paramconstraints[j]);
                        }
                        assert(ref->paramconstraints);
-                       if (!unresolved_subtype_set_from_typeinfo(referer,refmethod,
+                       if (!unresolved_subtype_set_from_typeinfo(refmethod->clazz, refmethod,
                                                ref->paramconstraints + i,&(param->typeinfo),
                                                md->paramtypes[i+instancecount].classref->name))
                                return false;
@@ -2625,6 +2837,84 @@ bool constrain_unresolved_method(jitdata *jd,
 }
 #endif /* ENABLE_VERIFIER */
 
+
+/* resolve_constrain_unresolved_method_params_stackbased ***********************
+   Record subtype constraints for the non-instance arguments of a method call.
+  
+   IN:
+       ref..............the unresolved_method structure of the call
+          refmethod........the method triggering the resolution (if any)
+          stack............TOS before the INVOKE instruction
+
+   RETURN VALUE:
+       true.............everything ok
+          false............an exception has been thrown
+
+*******************************************************************************/
+
+#if defined(ENABLE_VERIFIER)
+bool resolve_constrain_unresolved_method_params_stackbased(
+               unresolved_method *ref,
+               methodinfo *refmethod,
+               typedescriptor_t *stack)
+{
+       constant_FMIref *methodref;
+       typedescriptor_t *param;
+       methoddesc *md;
+       int i,j;
+       int type;
+       int instancecount;
+
+       assert(ref);
+       methodref = ref->methodref;
+       assert(methodref);
+       md = methodref->parseddesc.md;
+       assert(md);
+       assert(md->params != NULL);
+
+#ifdef RESOLVE_VERBOSE
+       printf("resolve_constrain_unresolved_method_params_stackbased\n");
+       printf("    rmethod: "); method_println(refmethod);
+       printf("    mref   : "); method_methodref_println(methodref);
+#endif
+
+       instancecount = (ref->flags & RESOLVE_STATIC) ? 0 : 1;
+
+       /* record subtype constraints for the parameter types, if any */
+
+       param = stack - (md->paramslots - 1 - instancecount);
+
+       for (i = instancecount; i < md->paramcount; ++i) {
+               type = md->paramtypes[i].type;
+
+               assert(type == param->type);
+
+               if (type == TYPE_ADR) {
+                       if (!ref->paramconstraints) {
+                               ref->paramconstraints = MNEW(unresolved_subtype_set,md->paramcount);
+                               for (j = 0; j < i - instancecount; ++j)
+                                       UNRESOLVED_SUBTYPE_SET_EMTPY(ref->paramconstraints[j]);
+                       }
+                       assert(ref->paramconstraints);
+                       if (!unresolved_subtype_set_from_typeinfo(refmethod->clazz, refmethod,
+                                               ref->paramconstraints + i - instancecount,&(param->typeinfo),
+                                               md->paramtypes[i].classref->name))
+                               return false;
+               }
+               else {
+                       if (ref->paramconstraints)
+                               UNRESOLVED_SUBTYPE_SET_EMTPY(ref->paramconstraints[i]);
+               }
+
+               param += (IS_2_WORD_TYPE(type)) ? 2 : 1;
+       }
+
+       return true;
+}
+#endif /* ENABLE_VERIFIER */
+
+
 /******************************************************************************/
 /* FREEING MEMORY                                                             */
 /******************************************************************************/
@@ -2790,7 +3080,7 @@ void unresolved_field_debug_dump(unresolved_field *ref,FILE *file)
        fprintf(file,"unresolved_field(%p):\n",(void *)ref);
        if (ref) {
                fprintf(file,"    referer   : ");
-               utf_fprint_printable_ascii(file,ref->referermethod->class->name); fputc('\n',file);
+               utf_fprint_printable_ascii(file,ref->referermethod->clazz->name); fputc('\n',file);
                fprintf(file,"    refmethod : ");
                utf_fprint_printable_ascii(file,ref->referermethod->name); fputc('\n',file);
                fprintf(file,"    refmethodd: ");
@@ -2828,7 +3118,7 @@ void unresolved_method_debug_dump(unresolved_method *ref,FILE *file)
        fprintf(file,"unresolved_method(%p):\n",(void *)ref);
        if (ref) {
                fprintf(file,"    referer   : ");
-               utf_fprint_printable_ascii(file,ref->referermethod->class->name); fputc('\n',file);
+               utf_fprint_printable_ascii(file,ref->referermethod->clazz->name); fputc('\n',file);
                fprintf(file,"    refmethod : ");
                utf_fprint_printable_ascii(file,ref->referermethod->name); fputc('\n',file);
                fprintf(file,"    refmethodd: ");
@@ -2858,6 +3148,7 @@ void unresolved_method_debug_dump(unresolved_method *ref,FILE *file)
 }
 #endif /* !defined(NDEBUG) */
 
+
 /*
  * These are local overrides for various environment variables in Emacs.
  * Please do not remove this and leave it at the end of the file, where
@@ -2871,4 +3162,3 @@ void unresolved_method_debug_dump(unresolved_method *ref,FILE *file)
  * End:
  * vim:noexpandtab:sw=4:ts=4:
  */
-