* src/vm/resolve.c (resolve_method_type_checks): Split up into
authoredwin <none@none>
Mon, 9 Oct 2006 23:53:42 +0000 (23:53 +0000)
committeredwin <none@none>
Mon, 9 Oct 2006 23:53:42 +0000 (23:53 +0000)
two new functions.

(resolve_method_instance_type_checks): New function.

(resolve_method_param_type_checks): New function.

* src/vm/resolve.h (resolve_method_type_checks): Removed.
(resolve_method_instance_type_checks): New function.
(resolve_method_param_type_checks): New function.

* src/vm/jit/verify/typecheck.c (verify_invocation): Call
resolve_method_instance_type_checks and
resolve_method_param_type_checks.

src/vm/jit/verify/typecheck.c
src/vm/resolve.c
src/vm/resolve.h

index ea66a5d54c619c845eabfb5d34fbfc4d5556bb1a..dcdcf7fee5519c5cc427998a031006201bc129e8 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes: Christian Thalinger
 
-   $Id: typecheck.c 5727 2006-10-09 23:17:56Z edwin $
+   $Id: typecheck.c 5729 2006-10-09 23:53:42Z edwin $
 
 */
 
@@ -986,12 +986,16 @@ verify_invocation(verifier_state *state)
 
        /* check types of parameters */
 
-       if (result == resolveSucceeded) {
-               result = resolve_method_type_checks(jd, state->m, 
-                                                                                       state->iptr, mi,
-                                                                                       invokestatic,
-                                                                                       invokespecial);
-       }
+       if (result == resolveSucceeded && !invokestatic)
+               result = resolve_method_instance_type_checks(
+                               state->m, mi, 
+                               &(VAR(state->iptr->sx.s23.s2.args[0])->typeinfo), 
+                               invokespecial);
+
+       if (result == resolveSucceeded)
+               result = resolve_method_param_type_checks(
+                               jd, state->m, state->iptr,
+                               mi, invokestatic);
 
        /* impose loading constraints */
 
index a6d6e51dfa3dfdfee5271b6a4aaa305227ec4004..b4611857735a95359c4392c138f618e99fad29a7 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes: Christan Thalinger
 
-   $Id: resolve.c 5728 2006-10-09 23:21:37Z edwin $
+   $Id: resolve.c 5729 2006-10-09 23:53:42Z edwin $
 
 */
 
@@ -1535,16 +1535,14 @@ resolve_result_t resolve_method_verifier_checks(methodinfo *refmethod,
 #endif /* defined(ENABLE_VERIFIER) */
 
 
-/* resolve_method_type_checks **************************************************
+/* resolve_method_instance_type_checks *****************************************
 
-   Check parameter types of a method invocation.
+   Check the instance type 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
+          instanceti.......typeinfo of the instance slot
           invokespecial....true if the method is invoked by INVOKESPECIAL
 
    RETURN VALUE:
@@ -1555,80 +1553,92 @@ resolve_result_t resolve_method_verifier_checks(methodinfo *refmethod,
 *******************************************************************************/
 
 #if defined(ENABLE_VERIFIER)
-resolve_result_t resolve_method_type_checks(jitdata *jd, 
-                                                                                       methodinfo *refmethod,
-                                                                                       instruction *iptr, 
-                                                                                       methodinfo *mi,
-                                                                                       bool invokestatic,
-                                                                                       bool invokespecial)
+resolve_result_t resolve_method_instance_type_checks(methodinfo *refmethod,
+                                                                                                        methodinfo *mi,
+                                                                                                        typeinfo *instanceti,
+                                                                                                        bool invokespecial)
 {
-       varinfo         *instanceslot;
-       varinfo         *param;
        typeinfo         tinfo;
+       typeinfo        *tip;
        resolve_result_t result;
-       methoddesc      *md;
-       typedesc        *paramtypes;
-       s4               type;
-       s4               instancecount;
-       s4               i;
 
-       /* for non-static methods we have to check the constraints on the         */
-       /* instance type                                                          */
-
-       assert(jd);
-
-       if (invokestatic) {
-               instancecount = 0;
-               instanceslot = NULL;
+       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->class);
+               tip = &tinfo;
+               if (!typeinfo_init_class(tip, initclass))
+                       return false;
        }
        else {
-               instancecount = 1;
-               instanceslot = VAR(iptr->sx.s23.s2.args[0]);
+               tip = instanceti;
        }
 
-       assert((instanceslot && instancecount == 1) || invokestatic);
-
-       /* record subtype constraints for the instance type, if any */
-       if (instanceslot) {
-               typeinfo *tip;
-
-               assert(instanceslot->type == TYPE_ADR);
+       result = resolve_lazy_subtype_checks(refmethod,
+                                                                                tip,
+                                                                                CLASSREF_OR_CLASSINFO(mi->class),
+                                                                                resolveLinkageError);
+       if (result != resolveSucceeded)
+               return result;
 
-               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);
-               }
+       /* check protected access */
 
+       /* XXX use other `declarer` than mi->class? */
+       if (((mi->flags & ACC_PROTECTED) != 0)
+                       && !SAME_PACKAGE(mi->class, refmethod->class))
+       {
                result = resolve_lazy_subtype_checks(refmethod,
-                                                                                        tip,
-                                                                                        CLASSREF_OR_CLASSINFO(mi->class),
-                                                                                        resolveLinkageError);
+                               tip,
+                               CLASSREF_OR_CLASSINFO(refmethod->class),
+                               resolveIllegalAccessError);
                if (result != resolveSucceeded)
                        return result;
+       }
 
-               /* check protected access */
+       /* everything ok */
 
-               /* XXX use other `declarer` than mi->class? */
-               if (((mi->flags & ACC_PROTECTED) != 0) 
-                               && !SAME_PACKAGE(mi->class, refmethod->class))
-               {
-                       result = resolve_lazy_subtype_checks(refmethod,
-                                       tip,
-                                       CLASSREF_OR_CLASSINFO(refmethod->class),
-                                       resolveIllegalAccessError);
-                       if (result != resolveSucceeded)
-                               return result;
-               }
+       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 */
 
index 3694157dc0285e6dca895c4a4bcbc500252230ac..3f1b181a8eeae43665417274da522c31534f46d1 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes:
 
-   $Id: resolve.h 5727 2006-10-09 23:17:56Z edwin $
+   $Id: resolve.h 5729 2006-10-09 23:53:42Z edwin $
 
 */
 
@@ -190,7 +190,7 @@ resolve_result_t resolve_method_lazy(methodinfo *refmethod,
 resolve_result_t resolve_field_lazy(methodinfo *refmethod,
                                                                        constant_FMIref *fieldref);
 
-#ifdef ENABLE_VERIFIER
+#if defined(ENABLE_VERIFIER)
 resolve_result_t resolve_field_verifier_checks(methodinfo *refmethod,
                                                                                           constant_FMIref *fieldref,
                                                                                           classinfo *container,
@@ -211,12 +211,16 @@ resolve_result_t resolve_method_verifier_checks(methodinfo *refmethod,
                                                                                                methodinfo *mi,
                                                                                                bool invokestatic);
 
-resolve_result_t resolve_method_type_checks(jitdata *jd, 
-                                                                                       methodinfo *refmethod,
-                                                                                       instruction *iptr, 
-                                                                                       methodinfo *mi,
-                                                                                       bool invokestatic,
-                                                                                       bool invokespecial);
+resolve_result_t resolve_method_instance_type_checks(methodinfo *refmethod,
+                                                                                                        methodinfo *mi,
+                                                                                                        typeinfo *instanceti,
+                                                                                                        bool invokespecial);
+
+resolve_result_t resolve_method_param_type_checks(jitdata *jd, 
+                                                                                                 methodinfo *refmethod,
+                                                                                                 instruction *iptr, 
+                                                                                                 methodinfo *mi,
+                                                                                                 bool invokestatic);
 
 bool resolve_method_loading_constraints(classinfo *referer,
                                                                                methodinfo *mi);
@@ -225,7 +229,7 @@ bool constrain_unresolved_method(jitdata *jd,
                                                                         unresolved_method *ref, classinfo *referer,
                                                                         methodinfo *refmethod, instruction *iptr);
 
-#endif
+#endif /* defined(ENABLE_VERIFIER) */
 
 #ifndef NDEBUG
 void unresolved_class_debug_dump(unresolved_class *ref,FILE *file);