This is the mail archive of the java-patches@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]

PATCH: Compiler support for new interface dispatch


This patch implements the compiler side of my constant time interface-dispatch
and type checking code.

It:

- adds three new fields to the class data (which are currently left empty, they
are set by the runtime during class preparation/linking)
- changes build_invokeinterface to generate calls to the new
_Jv_LookupInterfaceMethod()

enjoy

  [ bryce ]


1999-12-09  Bryce McKinlay  <bryce@albatross.co.nz>

        * decl.c (init_decl_processing): Added new class fields `depth',
        `ancestors', and `idt' to class_type_node.
        * class.c (make_class_data): Push initial values for new fields.
        * java-tree.h: Updated prototype for `build_invokeinterface'.
        * expr.c (build_invokeinterface): Changed parameters to accept
        `method' tree. Calculate index of `method' in its declaring
        interface. Build call to _Jv_LookupInterfaceMethod using new
        parameters `iface' and `idx'.
        (expand_invoke): Call `build_invokeinterface' with new parameters.
        * parse.y (patch_invoke): Call `build_invokeinterface' with new
        parameters.


diff -u gcc-2.95.2-clean/gcc/java/class.c gcc-2.95.2/gcc/java/class.c
--- gcc-2.95.2-clean/gcc/java/class.c	Thu Dec  9 20:36:09 1999
+++ gcc-2.95.2/gcc/java/class.c	Thu Dec  9 20:22:47 1999
@@ -1191,6 +1191,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);
 
diff -u gcc-2.95.2-clean/gcc/java/decl.c gcc-2.95.2/gcc/java/decl.c
--- gcc-2.95.2-clean/gcc/java/decl.c	Thu Dec  9 20:36:09 1999
+++ gcc-2.95.2/gcc/java/decl.c	Thu Dec  9 20:23:01 1999
@@ -651,6 +651,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);
@@ -787,7 +790,7 @@
 			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",
 			build_function_type (ptr_type_node, t),
diff -u gcc-2.95.2-clean/gcc/java/expr.c gcc-2.95.2/gcc/java/expr.c
--- gcc-2.95.2-clean/gcc/java/expr.c	Thu Dec  9 20:36:09 1999
+++ gcc-2.95.2/gcc/java/expr.c	Thu Dec  9 20:24:07 1999
@@ -1582,11 +1582,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
@@ -1598,14 +1602,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);
@@ -1703,7 +1718,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);
diff -u gcc-2.95.2-clean/gcc/java/java-tree.h gcc-2.95.2/gcc/java/java-tree.h
--- gcc-2.95.2-clean/gcc/java/java-tree.h	Thu Dec  9 20:36:09 1999
+++ gcc-2.95.2/gcc/java/java-tree.h	Thu Dec  9 20:21:51 1999
@@ -546,7 +546,7 @@
 extern tree build_known_method_ref PROTO ((tree, tree, tree, tree, tree));
 extern tree build_class_init PROTO ((tree, tree));
 extern tree build_invokevirtual PROTO ((tree, tree));
-extern tree build_invokeinterface PROTO ((tree, tree, tree));
+extern tree build_invokeinterface PROTO ((tree, tree));
 extern tree invoke_build_dtable PROTO ((int, tree));
 extern tree build_field_ref PROTO ((tree, tree, tree));
 extern void pushdecl_force_head PROTO ((tree));
diff -u gcc-2.95.2-clean/gcc/java/parse.c gcc-2.95.2/gcc/java/parse.c
--- gcc-2.95.2-clean/gcc/java/parse.c	Thu Dec  9 20:36:09 1999
+++ gcc-2.95.2/gcc/java/parse.c	Thu Dec  9 20:21:51 1999
@@ -10085,7 +10085,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:
diff -u gcc-2.95.2-clean/gcc/java/parse.y gcc-2.95.2/gcc/java/parse.y
--- gcc-2.95.2-clean/gcc/java/parse.y	Thu Dec  9 20:36:09 1999
+++ gcc-2.95.2/gcc/java/parse.y	Thu Dec  9 20:21:51 1999
@@ -7432,7 +7432,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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]