This is the mail archive of the java-patches@gcc.gnu.org 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]
Other format: [Raw text]

[gcjx] Patch: FYI: BC-related cleanups


I'm checking this in on the gcjx branch.

This adds the 'itable' for use by the BC ABI and fixes some
BC-related crashes.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* abi.cc (build_direct_class_reference): New method.
	(build_new): Fix type of result.
	(build_class_reference): Fix type of array reference.
	* abi.hh (gcj_abi::build_direct_class_reference): New method.
	(cxx_abi::build_direct_class_reference): Likewise
	(bc_abi::build_direct_class_reference): Declare.
	* classobj.hh (class_object_creator::create_index_table):
	Updated.
	* classobj.cc (create_index_table): Added 'table_decl' argument.
	Fixed computation of constructor contents.
	(create_class_instance): Updated.  Use
	build_direct_class_reference.
	(handle_interfaces): Use build_direct_class_reference.
	* builtins.cc (get_itable_decl): New method.
	* builtins.hh (tree_builtins::get_itable_decl): Declare.
	(tree_builtins::itable_map): New field.

Index: abi.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/abi.cc,v
retrieving revision 1.1.2.19
diff -u -r1.1.2.19 abi.cc
--- abi.cc 3 Apr 2005 23:47:45 -0000 1.1.2.19
+++ abi.cc 3 Apr 2005 23:48:13 -0000
@@ -295,8 +295,8 @@
     {
       assert (obj != NULL_TREE);
 
-//       int slot = current->register_interface_call (meth);
-//       tree itable = builtins->get_itable_decl (current->get ());
+      int slot = current->register_interface_call (meth);
+      tree itable = builtins->get_itable_decl (current->get ());
       abort ();
     }
   // Note that, unlike the C++ ABI, we call final methods via the
@@ -336,9 +336,10 @@
       int slot = current->register_indirect_call (meth);
 
       tree otable = builtins->get_otable_decl (current->get ());
-      tree index = build4 (ARRAY_REF, type_jint, otable,
-			   build_int_cst (type_jint, slot),
-			   NULL_TREE, NULL_TREE);
+      tree index = fold (convert (sizetype,
+				  build4 (ARRAY_REF, type_jint, otable,
+					  build_int_cst (type_jint, slot),
+					  NULL_TREE, NULL_TREE)));
 
       // FIXME: we could do this at link time and have the otable hold
       // a pure byte offset.
@@ -429,9 +430,10 @@
   // FIXME: handle primitive classes
   int index = current->add_class (classname);
   tree cpool = builtins->get_constant_pool_decl (current->get ());
-  return build4 (ARRAY_REF, type_class_ptr,
-		 cpool, build_int_cst (type_jint, index),
-		 NULL_TREE, NULL_TREE);
+  return convert (type_class_ptr, build4 (ARRAY_REF, ptr_type_node,
+					  cpool,
+					  build_int_cst (type_jint, index),
+					  NULL_TREE, NULL_TREE));
 }
 
 tree
@@ -441,9 +443,19 @@
   assert (! klass->primitive_p () && klass != primitive_void_type);
   int index = current->add (assert_cast<model_class *> (klass));
   tree cpool = builtins->get_constant_pool_decl (current->get ());
-  return build4 (ARRAY_REF, type_class_ptr,
-		 cpool, build_int_cst (type_jint, index),
-		 NULL_TREE, NULL_TREE);
+  return convert (type_class_ptr, build4 (ARRAY_REF, ptr_type_node,
+					  cpool,
+					  build_int_cst (type_jint, index),
+					  NULL_TREE, NULL_TREE));
+}
+
+tree
+bc_abi::build_direct_class_reference (tree_builtins *, aot_class *current,
+				      model_type *klass)
+{
+  assert (! klass->primitive_p () && klass != primitive_void_type);
+  int index = current->add (assert_cast<model_class *> (klass));
+  return build_int_cst (type_jint, index);
 }
 
 tree
@@ -453,6 +465,8 @@
 {
   tree allocator = builtin_Jv_AllocObject;
   tree klass_tree = build_class_reference (builtins, current, klass);
+  tree klass_type = builtins->map_type (klass);
+
   // Allocate the object.
   tree n = build3 (CALL_EXPR, TREE_TYPE (TREE_TYPE (allocator)), allocator,
 		   build_tree_list (NULL_TREE,
@@ -461,7 +475,7 @@
 		   NULL_TREE);
   TREE_SIDE_EFFECTS (n) = 1;
 
-  n = build1 (NOP_EXPR, klass_tree, n);
+  n = build1 (NOP_EXPR, klass_type, n);
   TREE_SIDE_EFFECTS (n) = 1;
 
   tree mem = save_expr (n);
@@ -472,7 +486,7 @@
   TREE_SIDE_EFFECTS (n) = 1;
 
   // Yield the new object.
-  n = build2 (COMPOUND_EXPR, klass_tree, n, mem);
+  n = build2 (COMPOUND_EXPR, klass_type, n, mem);
   TREE_SIDE_EFFECTS (n) = 1;
 
   return n;
Index: abi.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/abi.hh,v
retrieving revision 1.1.2.8
diff -u -r1.1.2.8 abi.hh
--- abi.hh 3 Apr 2005 23:47:45 -0000 1.1.2.8
+++ abi.hh 3 Apr 2005 23:48:13 -0000
@@ -94,6 +94,14 @@
 				      aot_class *current,
 				      model_type *other) = 0;
 
+  /// Return a tree representing a reference to another class which is
+  /// suitable for use in the Class object itself.  This is similar to
+  /// build_class_reference() but is only used in Class and must be
+  /// suitable for static emission in a CONSTRUCTOR node.
+  virtual tree build_direct_class_reference (tree_builtins *builtins,
+					     aot_class *current,
+					     model_type *other) = 0;
+
   /// Return an expression that is used to create a new object given
   /// its type, constructor, and arguments to the constructor.
   virtual tree build_new (tree_builtins *builtins,
@@ -142,6 +150,13 @@
 			      aot_class *current,
 			      model_type *other);
 
+  tree build_direct_class_reference (tree_builtins *builtins,
+				     aot_class *current,
+				     model_type *other)
+  {
+    return build_class_reference (builtins, current, other);
+  }
+
   tree build_new (tree_builtins *, aot_class *, model_class *,
 		  model_method *, tree);
 
@@ -183,6 +198,10 @@
 			      aot_class *current,
 			      model_type *other);
 
+  tree build_direct_class_reference (tree_builtins *builtins,
+				     aot_class *current,
+				     model_type *other);
+
   tree build_new (tree_builtins *, aot_class *, model_class *,
 		  model_method *, tree);
 
Index: builtins.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/builtins.cc,v
retrieving revision 1.1.2.28
diff -u -r1.1.2.28 builtins.cc
--- builtins.cc 3 Apr 2005 23:47:45 -0000 1.1.2.28
+++ builtins.cc 3 Apr 2005 23:48:13 -0000
@@ -570,6 +570,22 @@
   return otable_map[klass];
 }
 
+tree
+tree_builtins::get_itable_decl (model_class *klass)
+{
+  if (itable_map.find (klass) == itable_map.end ())
+    {
+      // Note: uses same type as atable.
+      tree decl = build_decl (VAR_DECL, get_symbol (), type_atable);
+      TREE_STATIC (decl) = 1;
+      DECL_ARTIFICIAL (decl) = 1;
+      DECL_IGNORED_P (decl) = 1;
+      itable_map[klass] = decl;
+      pushdecl (decl);
+    }
+  return itable_map[klass];
+}
+
 // FIXME: this whole method should probably migrate into the ABI or
 // into classobj.cc.  There's no need, I think, for it to be a generic
 // part of the builtins.
Index: builtins.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/builtins.hh,v
retrieving revision 1.1.2.13
diff -u -r1.1.2.13 builtins.hh
--- builtins.hh 3 Apr 2005 23:47:45 -0000 1.1.2.13
+++ builtins.hh 3 Apr 2005 23:48:14 -0000
@@ -55,9 +55,10 @@
   // Utf8Const.
   std::map<std::string, tree> utf8map;
 
-  // Registry of otable and atable decls.
+  // Registry of otable, atable, and itable decls.
   std::map<model_class *, tree> atable_map;
   std::map<model_class *, tree> otable_map;
+  std::map<model_class *, tree> itable_map;
 
   // Used when creating symbol names.
   int symbol_count;
@@ -138,6 +139,7 @@
 
   tree get_atable_decl (model_class *);
   tree get_otable_decl (model_class *);
+  tree get_itable_decl (model_class *);
 };
 
 #endif // GCC_TREE_BUILTINS_HH
Index: classobj.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/classobj.cc,v
retrieving revision 1.1.2.19
diff -u -r1.1.2.19 classobj.cc
--- classobj.cc 3 Apr 2005 23:45:06 -0000 1.1.2.19
+++ classobj.cc 3 Apr 2005 23:48:14 -0000
@@ -251,7 +251,8 @@
 void
 class_object_creator::create_index_table (const std::vector<model_element *> &table,
 					  tree &result_table,
-					  tree &result_syms)
+					  tree &result_syms,
+					  tree table_decl)
 {
   tree result_list = NULL_TREE;
 
@@ -262,9 +263,10 @@
       return;
     }
 
+  int index = 0;
   for (std::vector<model_element *>::const_iterator i = table.begin ();
        i != table.end ();
-       ++i)
+       ++i, ++index)
     {
       // We can be looking at a field or a method.
       // FIXME: it would be nice if we could use IMember; it would
@@ -295,22 +297,26 @@
       item.set_field ("signature", desc_tree);
       tree item_tree = item.finish_record ();
 
-      result_list = tree_cons (NULL_TREE, item_tree, result_list);
+      result_list = tree_cons (build_int_cst (type_jint, index), item_tree,
+			       result_list);
     }
 
+  result_list = nreverse (result_list);
+
   tree type
     = build_array_type (type_method_symbol,
 			build_index_type (build_int_cst (type_jint,
 							 table.size ())));
-  result_syms = make_decl (type, result);
+  result_syms = make_decl (type, build_constructor (type, result_list));
 
   tree symtype
     = build_array_type (ptr_type_node,
 			build_index_type (build_int_cst (type_jint,
 							 table.size ())));
-  // FIXME: we need a decl for this somewhere else so that the ABI can
-  // emit references to it...
-  result_table = make_decl (symtype, NULL_TREE);
+
+  TREE_TYPE (table_decl) = symtype;
+  rest_of_decl_compilation (table_decl, 1, 0);
+  result_table = build_address_of (table_decl);
 }
 
 void
@@ -331,8 +337,8 @@
 	   ++i)
 	{
 	  gcj_abi *abi = builtins->find_abi ();
-	  tree one_iface = abi->build_class_reference (builtins, klass,
-						       (*i)->type ());
+	  tree one_iface = abi->build_direct_class_reference (builtins, klass,
+							      (*i)->type ());
 	  result = tree_cons (build_int_cst (type_jint, len), one_iface,
 			      result);
 	  ++len;
@@ -492,7 +498,7 @@
   if (real_class->interface_p ())
     super = global->get_compiler ()->java_lang_Object ();
   if (super)
-    super_tree = abi->build_class_reference (builtins, klass, super);
+    super_tree = abi->build_direct_class_reference (builtins, klass, super);
   inst.set_field ("superclass", super_tree);
 
   inst.set_field ("constants", create_constants ());
@@ -521,15 +527,18 @@
   inst.set_field ("dtable", dtable);
 
   tree table, syms;
-  create_index_table (klass->get_otable (), table, syms);
+  create_index_table (klass->get_otable (), table, syms,
+		      builtins->get_otable_decl (real_class));
   inst.set_field ("otable", table);
   inst.set_field ("otable_syms", syms);
 
-  create_index_table (klass->get_atable (), table, syms);
+  create_index_table (klass->get_atable (), table, syms,
+		      builtins->get_atable_decl (real_class));
   inst.set_field ("atable", table);
   inst.set_field ("atable_syms", syms);
 
-  create_index_table (klass->get_itable (), table, syms);
+  create_index_table (klass->get_itable (), table, syms,
+		      builtins->get_itable_decl (real_class));
   inst.set_field ("itable", table);
   inst.set_field ("itable_syms", syms);
 
Index: classobj.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/classobj.hh,v
retrieving revision 1.1.2.6
diff -u -r1.1.2.6 classobj.hh
--- classobj.hh 8 Mar 2005 00:34:36 -0000 1.1.2.6
+++ classobj.hh 3 Apr 2005 23:48:14 -0000
@@ -71,7 +71,7 @@
   tree create_method_array (model_class *, int &);
   void handle_interfaces (model_class *, tree &, tree &);
   void create_index_table (const std::vector<model_element *> &,
-			   tree &, tree &);
+			   tree &, tree &, tree);
   void create_class_instance (tree);
   tree create_constants ();
   void fill_in_vtable (tree);


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