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: preparation fixes for BC


I'm checking this in on the gcjx branch.

This fixes a couple of little bugs and also changes gcj to assign more
readable names for some of the symbols it generates internally.  This
make it a bit simpler to read the assembly.

BC compilation still doesn't work but this patch lays some of the
groundwork; for 'hello world' I think all we need is to actually
implement field resolution.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* hooks.hh (builtin_Jv_ResolvePoolEntry): Declare.
	* decl.cc (initialize_builtins): Define __builtin_expect.
	(initialize_builtin_functions): Define _Jv_ResolvePoolEntry.
	(builtin_Jv_ResolvePoolEntry): Define.
	* classobj.hh (class_object_creator::make_decl): Updated.
	(class_object_creator::create_index_table): Likewise.
	* classobj.cc (create_index_table): Added 'prefix' argument.
	Give name to symbol table.  Use fully qualified class name.
	(make_decl): Added 'name' argument.
	(create_class_instance): Updated.
	* builtins.cc (washed_name): New method.
	(get_itable_decl): Use it.
	(get_otable_decl): Likewise.
	(get_atable_decl): Likewise.
	(get_constant_pool_decl): Likewise.
	(map_utf8const): Pass correct length to build_string.
	* builtins.hh (tree_builtins::washed_name): Declare.

Index: abi.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/abi.cc,v
retrieving revision 1.1.2.26
diff -u -r1.1.2.26 abi.cc
--- abi.cc 12 Oct 2005 17:14:30 -0000 1.1.2.26
+++ abi.cc 14 Oct 2005 19:27:41 -0000
@@ -489,6 +489,10 @@
     {
       assert (obj == NULL_TREE);
 
+      // FIXME: must call _Jv_ResolvePoolEntry and ought to cache the
+      // result.  In this case... it seems that we do not need an
+      // atable entry, but instead a constant pool entry.
+
       tree atable = builtins->get_atable_decl (current->get ());
       tree atable_ref = build4 (ARRAY_REF, ptr_type_node, atable,
 				build_int_cst (type_jint, slot),
@@ -536,6 +540,8 @@
 bc_abi::build_class_reference (tree_builtins *builtins, aot_class *current,
 			       const std::string &classname)
 {
+  // FIXME: direct reference to 'current'.
+
   // FIXME: handle primitive classes
   int index = current->add_class (classname);
   tree cpool = builtins->get_constant_pool_decl (current->get ());
@@ -550,6 +556,15 @@
 			       model_type *klass)
 {
   assert (! klass->primitive_p () && klass != primitive_void_type);
+
+  // Build a direct reference to the current class, otherwise go via
+  // the constant pool.
+  if (current->get () == klass)
+    {
+      tree class_obj = builtins->map_class_object (current->get ());
+      return build1 (ADDR_EXPR, type_class_ptr, class_obj);
+    }
+
   int index = current->add (assert_cast<model_class *> (klass));
   tree cpool = builtins->get_constant_pool_decl (current->get ());
   return convert (type_class_ptr, build4 (ARRAY_REF, ptr_type_node,
Index: builtins.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/builtins.cc,v
retrieving revision 1.1.2.38
diff -u -r1.1.2.38 builtins.cc
--- builtins.cc 12 Oct 2005 17:14:30 -0000 1.1.2.38
+++ builtins.cc 14 Oct 2005 19:27:41 -0000
@@ -464,7 +464,7 @@
       utf.set_field ("hash", build_int_cst (type_jushort, hash & 0xffff));
       utf.set_field ("length", build_int_cst (type_jushort, value.length ()));
 
-      tree str = build_string (value.length () + 1, value.c_str ());
+      tree str = build_string (value.length (), value.c_str ());
       tree strtype = TREE_TYPE (find_decl (type, "data"));
       TREE_TYPE (str) = strtype;
       TREE_CONSTANT (str) = 1;
@@ -542,7 +542,7 @@
     {
       tree type = build_array_type (ptr_type_node,
 				    build_index_type (integer_zero_node));
-      tree decl = build_decl (VAR_DECL, get_symbol (), type);
+      tree decl = build_decl (VAR_DECL, washed_name ("_cpool_", klass), type);
       TREE_STATIC (decl) = 1;
       DECL_ARTIFICIAL (decl) = 1;
       DECL_IGNORED_P (decl) = 1;
@@ -557,7 +557,8 @@
 {
   if (atable_map.find (klass) == atable_map.end ())
     {
-      tree decl = build_decl (VAR_DECL, get_symbol (), type_atable);
+      tree decl = build_decl (VAR_DECL, washed_name ("_atable_", klass),
+			      type_atable);
       TREE_STATIC (decl) = 1;
       DECL_ARTIFICIAL (decl) = 1;
       DECL_IGNORED_P (decl) = 1;
@@ -572,7 +573,8 @@
 {
   if (otable_map.find (klass) == otable_map.end ())
     {
-      tree decl = build_decl (VAR_DECL, get_symbol (), type_otable);
+      tree decl = build_decl (VAR_DECL, washed_name ("_otable_", klass),
+			      type_otable);
       TREE_STATIC (decl) = 1;
       DECL_ARTIFICIAL (decl) = 1;
       DECL_IGNORED_P (decl) = 1;
@@ -588,7 +590,8 @@
   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 decl = build_decl (VAR_DECL, washed_name ("_itable_", klass),
+			      type_atable);
       TREE_STATIC (decl) = 1;
       DECL_ARTIFICIAL (decl) = 1;
       DECL_IGNORED_P (decl) = 1;
@@ -811,6 +814,14 @@
 }
 
 tree
+tree_builtins::washed_name (const std::string &prefix, model_class *klass)
+{
+  std::string result = klass->get_fully_qualified_name ();
+  replace_all (result, '.', '_');
+  return get_identifier ((prefix + result).c_str ());
+}
+
+tree
 tree_builtins::build_class_init (model_class *klass)
 {
   aot_class *wrapper = get_class (klass);
Index: builtins.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/builtins.hh,v
retrieving revision 1.1.2.18
diff -u -r1.1.2.18 builtins.hh
--- builtins.hh 12 Oct 2005 13:27:29 -0000 1.1.2.18
+++ builtins.hh 14 Oct 2005 19:27:41 -0000
@@ -168,6 +168,10 @@
     // Why do we do this?
     return join (split (m->get_descriptor (), '/'), '.');
   }
+
+  // Return an identifier node that includes a "washed" form of the
+  // class name and the given prefix.
+  tree washed_name (const std::string &prefix, model_class *klass);
 };
 
 #endif // GCC_JAVA_BUILTINS_HH
Index: classobj.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/classobj.cc,v
retrieving revision 1.1.2.29
diff -u -r1.1.2.29 classobj.cc
--- classobj.cc 13 Oct 2005 01:18:07 -0000 1.1.2.29
+++ classobj.cc 14 Oct 2005 19:27:42 -0000
@@ -82,9 +82,11 @@
 
 
 tree
-class_object_creator::make_decl (tree type, tree value)
+class_object_creator::make_decl (tree type, tree value, tree name)
 {
-  tree decl = build_decl (VAR_DECL, builtins->get_symbol (), type);
+  if (name == NULL_TREE)
+    name = builtins->get_symbol ();
+  tree decl = build_decl (VAR_DECL, name, type);
   DECL_INITIAL (decl) = value;
   TREE_STATIC (decl) = 1;
   DECL_ARTIFICIAL (decl) = 1;
@@ -240,7 +242,8 @@
 }
 
 void
-class_object_creator::create_index_table (const std::vector<model_element *> &table,
+class_object_creator::create_index_table (const char *prefix,
+					  const std::vector<model_element *> &table,
 					  tree &result_table,
 					  tree &result_syms,
 					  tree table_decl)
@@ -266,14 +269,16 @@
       if (dynamic_cast<model_field *> (*i))
 	{
 	  model_field *field = assert_cast<model_field *> (*i);
-	  class_desc = tree_builtins::get_descriptor (field->get_declaring_class ());
+	  class_desc
+	    = field->get_declaring_class ()->get_fully_qualified_name ();
 	  name = field->get_name ();
 	  descriptor = tree_builtins::get_descriptor (field->type ());
 	}
       else
 	{
 	  model_method *method = assert_cast<model_method *> (*i);
-	  class_desc = tree_builtins::get_descriptor (method->get_declaring_class ());
+	  class_desc
+	    = method->get_declaring_class ()->get_fully_qualified_name ();
 	  name = method->get_name ();
 	  descriptor = tree_builtins::get_descriptor (method);
 	}
@@ -298,7 +303,8 @@
     = build_array_type (type_method_symbol,
 			build_index_type (build_int_cst (type_jint,
 							 table.size ())));
-  result_syms = make_decl (type, build_constructor (type, result_list));
+  result_syms = make_decl (type, build_constructor (type, result_list),
+			   builtins->washed_name (prefix, klass->get ()));
 
   // Note that the table itself has an extra element for the status.
   // FIXME: itable is double the size.
@@ -562,17 +568,17 @@
   inst.set_field ("dtable", dtable);
 
   tree table, syms;
-  create_index_table (klass->get_otable (), table, syms,
+  create_index_table ("_otable_syms_", 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 ("_atable_syms_", 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 ("_itable_syms_", 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.9
diff -u -r1.1.2.9 classobj.hh
--- classobj.hh 17 Apr 2005 21:29:28 -0000 1.1.2.9
+++ classobj.hh 14 Oct 2005 19:27:42 -0000
@@ -63,14 +63,14 @@
   // The resulting tree.
   tree result;
 
-  tree make_decl (tree, tree);
+  tree make_decl (tree, tree, tree = NULL_TREE);
   tree create_one_field_record (model_field *);
   tree create_field_array (model_class *, int &, int &);
   tree create_one_method_record (model_method *);
   tree create_method_throws (model_method *);
   tree create_method_array (model_class *, int &);
   void handle_interfaces (model_class *, tree &, tree &);
-  void create_index_table (const std::vector<model_element *> &,
+  void create_index_table (const char *, const std::vector<model_element *> &,
 			   tree &, tree &, tree);
   void create_class_instance (tree);
   tree create_constants ();
Index: decl.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/decl.cc,v
retrieving revision 1.1.2.24
diff -u -r1.1.2.24 decl.cc
--- decl.cc 4 Oct 2005 21:53:54 -0000 1.1.2.24
+++ decl.cc 14 Oct 2005 19:27:42 -0000
@@ -173,6 +173,7 @@
 tree builtin_Jv_remI;
 tree builtin_Jv_divJ;
 tree builtin_Jv_remJ;
+tree builtin_Jv_ResolvePoolEntry;
 
 // Vtables for primitive types.
 tree boolean_array_vtable;
@@ -821,6 +822,15 @@
 			      0, NOT_BUILT_IN, NULL, NULL_TREE);
   builtin_Jv_remJ
     = build_address_of (builtin_Jv_remJ);
+
+  t = tree_cons (NULL_TREE, type_class_ptr,
+		 tree_cons (NULL_TREE, type_jint, void_list_node));
+  builtin_Jv_ResolvePoolEntry
+    = gcjx::builtin_function ("_Jv_ResolvePoolEntry",
+			      build_function_type (ptr_type_node, t),
+			      0, NOT_BUILT_IN, NULL, NULL_TREE);
+  DECL_IS_PURE (builtin_Jv_ResolvePoolEntry) = 1;
+  builtin_Jv_ResolvePoolEntry = build_address_of (builtin_Jv_ResolvePoolEntry);
 }
 
 static void
@@ -981,6 +991,13 @@
   define_builtin (BUILT_IN_TAN, "__builtin_tan",
 		  double_ftype_double, "_ZN4java4lang4Math3tanEd");
 
+  t = tree_cons (NULL_TREE, boolean_type_node,
+		 tree_cons (NULL_TREE, boolean_type_node, void_list_node));
+  tree boolean_ftype_boolean_boolean
+    = build_function_type (boolean_type_node, t);
+  define_builtin (BUILT_IN_EXPECT, "__builtin_expect",
+		  boolean_ftype_boolean_boolean, "__builtin_expect");
+
   // Only on trunk for now.
   // build_common_builtin_nodes ();
 }
Index: hooks.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/hooks.hh,v
retrieving revision 1.1.2.13
diff -u -r1.1.2.13 hooks.hh
--- hooks.hh 4 Oct 2005 21:53:54 -0000 1.1.2.13
+++ hooks.hh 14 Oct 2005 19:27:42 -0000
@@ -86,6 +86,7 @@
 extern GTY (()) tree builtin_Jv_remI;
 extern GTY (()) tree builtin_Jv_divJ;
 extern GTY (()) tree builtin_Jv_remJ;
+extern GTY (()) tree builtin_Jv_ResolvePoolEntry;
 extern GTY (()) tree boolean_array_vtable;
 extern GTY (()) tree byte_array_vtable;
 extern GTY (()) tree char_array_vtable;


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