[kaffe] CVS kaffe (hkraemer): fixed invocations of java.lang.Object methods via INVOKEINTERFACE

Kaffe CVS cvs-commits at kaffe.org
Sun Jul 25 09:43:17 PDT 2004


PatchSet 5016 
Date: 2004/07/25 16:33:47
Author: hkraemer
Branch: HEAD
Tag: (none) 
Log:
fixed invocations of java.lang.Object methods via INVOKEINTERFACE

Members: 
	ChangeLog:1.2575->1.2576 
	kaffe/kaffevm/kaffe.def:1.31->1.32 
	kaffe/kaffevm/lookup.c:1.37->1.38 
	kaffe/kaffevm/soft.c:1.64->1.65 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2575 kaffe/ChangeLog:1.2576
--- kaffe/ChangeLog:1.2575	Sun Jul 25 15:36:39 2004
+++ kaffe/ChangeLog	Sun Jul 25 16:33:47 2004
@@ -1,3 +1,19 @@
+2004-07-25  Helmer Kraemer  <hkraemer at freenet.de>
+
+	* kaffe/kaffevm/soft.c (soft_lookupinterfacemethod): 
+	Removed handling of invocations on java.lang.Object methods.
+
+	* kaffe/kaffevm/kaffe.def (INVOKEINTERFACE):
+	Simplified invocations on java.lang.Object methods by using
+	the object's dispatch table as in INVOKEVIRTUAL.
+
+	* kaffe/kaffevm/lookup.c (getMethodSignatureClass):
+	When resolving an interface method, search superinterfaces before
+	java.lang.Object. That way, we don't find the wrong method when
+	a superinterface overrides a method from java.lang.Object.
+
+	Reported by: Benja Fallenstein <b.fallenstein at gmx.de>
+	
 2004-07-25  Dalibor Topic  <robilad at kaffe.org>
 
 	* libraries/clib/awt/classpath-gtk/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c
Index: kaffe/kaffe/kaffevm/kaffe.def
diff -u kaffe/kaffe/kaffevm/kaffe.def:1.31 kaffe/kaffe/kaffevm/kaffe.def:1.32
--- kaffe/kaffe/kaffevm/kaffe.def:1.31	Sat Mar 27 19:02:19 2004
+++ kaffe/kaffe/kaffevm/kaffe.def	Sun Jul 25 16:33:49 2004
@@ -2912,6 +2912,8 @@
 
 define_insn(INVOKEINTERFACE)
 {
+	Method *m;
+
 	/*
 	 * ..., obj, ..args.., -> ...
 	 */
@@ -2947,13 +2949,33 @@
 	else {
 		idx = (uint8)getpc(2) - 1;
 
+
+		/*
+		 * if we invoke a method from java.lang.Object, we can directly use the
+		 * dispatch table.
+		 */
+		m = findMethodLocal(ObjectClass, method_method()->name, method_sig());
+
 		check_null(INVOKEINTERFACE, stack(idx), 34);
 
 		check_stack_ref(idx);
 
 		slot_alloctmp(tmp);
-		softcall_lookupinterfacemethod(tmp, method_method(), stack(idx));
 
+		if (m != NULL) {
+			/* Find dispatch table in object */
+			load_offset_ref(tmp, stack(idx),
+					method_dtable_offset);
+
+			/* Check method table for cached entry */
+			load_offset_ref(tmp, tmp,
+					DTABLE_METHODOFFSET + 
+					m->idx *
+					DTABLE_METHODSIZE);
+		} else {
+			softcall_lookupinterfacemethod(tmp, method_method(), stack(idx));
+		}
+		
 		/* Push arguments & object */
 		build_call_frame(method_sig(), stack(idx), idx);
 		idx++;
@@ -2969,7 +2991,7 @@
 
 		/* Pop args */
 		popargs();
-
+		
 		end_func_sync();
 		METHOD_RETURN_VALUE();
 	}
Index: kaffe/kaffe/kaffevm/lookup.c
diff -u kaffe/kaffe/kaffevm/lookup.c:1.37 kaffe/kaffe/kaffevm/lookup.c:1.38
--- kaffe/kaffe/kaffevm/lookup.c:1.37	Sat Jul 17 07:57:14 2004
+++ kaffe/kaffe/kaffevm/lookup.c	Sun Jul 25 16:33:49 2004
@@ -99,28 +99,40 @@
 		/* Find method - we don't use findMethod(...) yet since this
 		 * will initialise our class (and we don't want to do that).
 		 */
-		mptr = 0;
-		for (; class != 0; class = class->superclass) {
+		if (isSpecial != 2) {
+			/* method resolution for INVOKEVIRTUAL or INVOKESPECIAL.
+			 * Since we make sure that the dispatch table of a class
+			 * contains all methods of all implemented interfaces, we
+			 * don't need to search superinterfaces here.
+			 */
+			for (; class != 0; class = class->superclass) {
+				mptr = findMethodLocal(class, name, sig);
+				if (mptr != NULL) {
+					call->method = mptr;
+					break;
+				}
+			}
+		} else {
+			/* method resolution for INVOKEINTERFACE. First search the
+			 * interface itself, then its superinterfaces and finally
+			 * java.lang.Object.
+			 */
+			class = call->class;
 			mptr = findMethodLocal(class, name, sig);
-			if (mptr != NULL) {
-				call->method = mptr;
-				break;
+			if (mptr == NULL) {
+				for (i = class->total_interface_len - 1; i >= 0; i--) {
+					mptr = findMethodLocal(class->interfaces[i], name, sig);
+					if (mptr != 0) {
+						break;
+					}
+				}
+
+				if (mptr == NULL) {
+					mptr = findMethodLocal(call->class->superclass, name, sig);
+				}
 			}
+			call->method = mptr;
 		}
-
-                /* If we've not found anything and we're searching interfaces,
-                 * search them too.
-                 */
-                if (mptr == 0 && isSpecial == 2) {
-                        class = call->class;
-                        for (i = class->total_interface_len - 1; i >= 0; i--) {
-                                mptr = findMethodLocal(class->interfaces[i], name, sig);
-                                if (mptr != 0) {
-                                        call->method = mptr;
-                                        break;
-                                }
-                        }
-                }
 	}
 
 	/* Calculate in's and out's */
Index: kaffe/kaffe/kaffevm/soft.c
diff -u kaffe/kaffe/kaffevm/soft.c:1.64 kaffe/kaffe/kaffevm/soft.c:1.65
--- kaffe/kaffe/kaffevm/soft.c:1.64	Tue Jul  6 17:16:13 2004
+++ kaffe/kaffe/kaffevm/soft.c	Sun Jul 25 16:33:49 2004
@@ -264,12 +264,6 @@
 		}
 	}
 #endif
-
-	/* handle invocations on java.lang.Object methods via INVOKEINTERFACE */
-	if (implementors == 0 || i > implementors[0]) {
-		goto notfound;
-	}
-
 	/* skip word at the beginning of itable2dtable */
 	ncode = cls->itable2dtable[implementors[i] + idx + 1];
 
@@ -282,40 +276,10 @@
 	 * given that they should be rare---minus possible DoS.)
 	 */
 	if (ncode == (void *)-1) {
-		goto notfound;
+		return NULL;
 	}
 	assert(ncode != NULL);
 	return (ncode);
-
-notfound:
-	/*
-	 * Compilers following the latest version of the JLS emit a
-	 * INVOKEINTERFACE instruction for methods that aren't defined in
-	 * an interface, but inherited from Object.
-	 *
-	 * In this case, the JVM must
-	 * a) check that the object really implements the interface given
-	 * b) find and invoke the method on object.
-	 *
-	 * The best way to jit that would be a checkcast <interface_type>
-	 * followed by an INVOKEVIRTUAL.
-	 *
-	 * For now, we simply detect the case where an object method is called
-	 * and find it by hand using its (name, signature).
-	 */
-	if (ifclass == ObjectClass) {
-		Method* objm = CLASS_METHODS(ifclass) + idx;
-		errorInfo info;
-
-		meth = findMethod(cls, objm->name, METHOD_SIG(objm), &info);
-		if (meth == 0) {
-			throwError(&info);
-		}
-		return (METHOD_INDIRECTMETHOD(meth));
-	}
-	meth = CLASS_METHODS(ifclass) + idx;
-	soft_nosuchmethod(cls, meth->name, METHOD_SIG(meth));
-	return (0);
 }
 
 inline




More information about the kaffe mailing list