This is the mail archive of the java-discuss@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: jboolean / _Jv_InstanceOf / .class compiler problem


Alexandre Petit-Bianco wrote:

> Bryce McKinlay writes:
>
> > I don't have a test case outside the context of the _Jv_IsInstanceOf
> > call. With my new implementation of this method (in the constant
> > time patch), its result value never gets set properly (debugger
> > shows random garbage values), and so "instanceof" always returns
> > true. But this only occurs when dealing with code compiled from
> > .class files. The source compiler and interpreter are unaffected.
>
> I definitely should look into that. I need the full patch. A test case
> would be nice too.

Here is the gcj patch. The runtime patch is here:
http://sourceware.cygnus.com/ml/java-patches/2000-q1/msg00138.html

There's a test case in cvs at
libgcj/libjava/testsuite/libjava.lang/InterfaceDispatch.java

The method that exhibits the problem is _Jv_IsAssignableFrom() in
natClass.cc. You might want to make it non-inline for debugging.

regards

  [ bryce ]

Index: parse.y
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/parse.y,v
retrieving revision 1.135
diff -u -r1.135 parse.y
--- parse.y	2000/02/15 22:54:21	1.135
+++ parse.y	2000/02/17 08:24:17
@@ -7523,7 +7523,7 @@
 
 	case INVOKE_INTERFACE:
 	  dtable = invoke_build_dtable (1, args);
-	  func = build_invokeinterface (dtable, DECL_NAME (method), signature);
+	  func = build_invokeinterface (dtable, method);
 	  break;
 
 	default:
Index: java-tree.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/java-tree.h,v
retrieving revision 1.52
diff -u -r1.52 java-tree.h
--- java-tree.h	2000/02/09 14:08:44	1.52
+++ java-tree.h	2000/02/17 08:24:23
@@ -537,7 +537,7 @@
 extern tree build_known_method_ref PARAMS ((tree, tree, tree, tree, tree));
 extern tree build_class_init PARAMS ((tree, tree));
 extern tree build_invokevirtual PARAMS ((tree, tree));
-extern tree build_invokeinterface PARAMS ((tree, tree, tree));
+extern tree build_invokeinterface PARAMS ((tree, tree));
 extern tree invoke_build_dtable PARAMS ((int, tree));
 extern tree build_field_ref PARAMS ((tree, tree, tree));
 extern void pushdecl_force_head PARAMS ((tree));
Index: decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/decl.c,v
retrieving revision 1.46
diff -u -r1.46 decl.c
--- decl.c	2000/02/09 20:38:02	1.46
+++ decl.c	2000/02/17 08:24:32
@@ -660,6 +660,9 @@
   PUSH_FIELD (class_type_node, field, "interface_count", short_type_node);
   PUSH_FIELD (class_type_node, field, "state", byte_type_node);
   PUSH_FIELD (class_type_node, field, "thread", ptr_type_node);
+  PUSH_FIELD (class_type_node, field, "depth", short_type_node);
+  PUSH_FIELD (class_type_node, field, "ancestors", ptr_type_node);
+  PUSH_FIELD (class_type_node, field, "idt", ptr_type_node);  
   for (t = TYPE_FIELDS (class_type_node);  t != NULL_TREE;  t = TREE_CHAIN (t))
     FIELD_PRIVATE (t) = 1;
   push_super_field (class_type_node, object_type_node);
@@ -814,9 +817,9 @@
 			0, NOT_BUILT_IN, NULL_PTR);
   t = tree_cons (NULL_TREE, ptr_type_node,
 		 tree_cons (NULL_TREE, ptr_type_node,
-			    tree_cons (NULL_TREE, ptr_type_node, endlink)));
+			    tree_cons (NULL_TREE, int_type_node, endlink)));
   soft_lookupinterfacemethod_node 
-    = builtin_function ("_Jv_LookupInterfaceMethod",
+    = builtin_function ("_Jv_LookupInterfaceMethodIdx",
 			build_function_type (ptr_type_node, t),
 			0, NOT_BUILT_IN, NULL_PTR);
   t = tree_cons (NULL_TREE, double_type_node,
Index: class.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/class.c,v
retrieving revision 1.53
diff -u -r1.53 class.c
--- class.c	2000/01/21 20:57:00	1.53
+++ class.c	2000/02/17 08:24:40
@@ -1341,6 +1341,9 @@
   PUSH_FIELD_VALUE (cons, "state", integer_zero_node);
 
   PUSH_FIELD_VALUE (cons, "thread", null_pointer_node);
+  PUSH_FIELD_VALUE (cons, "depth", integer_zero_node);
+  PUSH_FIELD_VALUE (cons, "ancestors", null_pointer_node);
+  PUSH_FIELD_VALUE (cons, "idt", null_pointer_node);
 
   FINISH_RECORD_CONSTRUCTOR (cons);
 
Index: expr.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/expr.c,v
retrieving revision 1.58
diff -u -r1.58 expr.c
--- expr.c	2000/02/09 14:08:44	1.58
+++ expr.c	2000/02/17 08:24:56
@@ -1596,11 +1596,15 @@
 }
 
 tree
-build_invokeinterface (dtable, method_name, method_signature)
-     tree dtable, method_name, method_signature;
+build_invokeinterface (dtable, method)
+     tree dtable, method;
 {
   static tree class_ident = NULL_TREE;
   tree lookup_arg;
+  tree interface;
+  tree idx;
+  tree meth;
+  int i;
 
   /* We expand invokeinterface here.  _Jv_LookupInterfaceMethod() will
      ensure that the selected method exists, is public and not
@@ -1612,14 +1616,25 @@
   dtable = build1 (INDIRECT_REF, dtable_type, dtable);
   dtable = build (COMPONENT_REF, class_ptr_type, dtable,
 		  lookup_field (&dtable_type, class_ident));
-  lookup_arg = build_tree_list (NULL_TREE, 
-				(build_utf8_ref 
-				 (unmangle_classname
-				  (IDENTIFIER_POINTER(method_signature),
-				   IDENTIFIER_LENGTH(method_signature)))));
+
+  interface = DECL_CONTEXT (method);
+  
+  i = 1;
+  for (meth = TYPE_METHODS (interface); ; meth = TREE_CHAIN (meth), i++)
+    {
+      if (meth == method)
+        {
+	  idx = build_int_2 (i, 0);
+	  break;
+	}
+      if (meth == NULL_TREE)
+        fatal ("internal error in build_invokeinterface");
+    }
+
   lookup_arg = tree_cons (NULL_TREE, dtable,
-			  tree_cons (NULL_TREE, build_utf8_ref (method_name),
-				     lookup_arg));
+                          tree_cons (NULL_TREE, build_class_ref (interface),
+			             build_tree_list (NULL_TREE, idx)));
+				     			  
   return build (CALL_EXPR, ptr_type_node, 
 		build_address_of (soft_lookupinterfacemethod_node),
 		lookup_arg, NULL_TREE);
@@ -1718,7 +1733,7 @@
       if (opcode == OPCODE_invokevirtual)
 	func = build_invokevirtual (dtable, method);
       else
-	func = build_invokeinterface (dtable, method_name, method_signature);
+	func = build_invokeinterface (dtable, method);
     }
   func = build1 (NOP_EXPR, build_pointer_type (method_type), func);
   call = build (CALL_EXPR, TREE_TYPE (method_type), func, arg_list, NULL_TREE);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]