[gcjx] Patch: FYI: handle reference to Class object

Tom Tromey tromey@redhat.com
Sun Feb 13 04:14:00 GMT 2005


I'm checking this in on the gcjx branch.

This updates some code to be smarter about referring to a Class
object, adding a new abi method to handle a case we need.  This area
could stand a revamp, since one of the build_class_reference overloads
is kind of bogus, but like many things that will wait.

Tom

# 
# patch "gcc/gcc/java/ChangeLog"
#  from [3053b23975dadc7566ab5ae4cb9a1c78b1839612]
#    to [5ef8565b3f02d225c2864e00df356ab8201bd9ec]
# 
# patch "gcc/gcc/java/abi.cc"
#  from [0c8cecca21a803bf53970ee8d02223a92460ea00]
#    to [5bd0aed22793dddd30eef0fa5844dfe3980992fd]
# 
# patch "gcc/gcc/java/abi.hh"
#  from [c515fad0e163073cbf5fda78c56f401ee145e750]
#    to [9245a816df8b825751ccd79bb4067f8f83f80b7e]
# 
# patch "gcc/gcc/java/builtins.cc"
#  from [dd0ee449d75ced40ebabb24bf519fb76a7f5d513]
#    to [cca8ac8d41e018def9c0c39a573624ad4f2ee865]
# 
# patch "gcc/gcc/java/builtins.hh"
#  from [a4ff5bcc8baed5e7273157b055bc060e52edd1ee]
#    to [7b627129323852ce85bbcaef30e9aa31a4b86e90]
# 
# patch "gcc/gcc/java/classobj.cc"
#  from [9ac15b71e14bae18bd69400f3a0f53cc05c692ba]
#    to [d1cfc1d394422d9232ea6d1e5eef62ca52acff66]
# 
# patch "gcc/gcc/java/decl.cc"
#  from [7d914f40358ad4dbea1b2cfc18247365d558068c]
#    to [f0ac0df73f09521bf65f1b96e196d62f6e546bde]
# 
--- gcc/gcc/java/ChangeLog
+++ gcc/gcc/java/ChangeLog
@@ -1,5 +1,14 @@
 2005-02-09  Tom Tromey  <tromey@redhat.com>
 
+	* abi.cc (build_class_reference): New methods.
+	* builtins.cc (map_class_object): New method.
+	* builtins.hh (tree_builtins::classobj_map): New field.
+	(tree_builtins::map_class_object): Declare.
+	* classobj.cc (make_decl): Don't create another constructor.
+	(create_class_instance): Use map_class_object.  Correctly handle
+	'super'.
+	(create_index_table): Temporarily set results to null.
+
 	* classobj.cc (make_decl): Set decl assembler name on class
 	record.
 	* builtins.cc (get_class_object_name): New method.
--- gcc/gcc/java/abi.cc
+++ gcc/gcc/java/abi.cc
@@ -156,6 +156,15 @@
 }
 
 tree
+cxx_abi::build_class_reference (tree_builtins *builtins,
+				aot_class *,
+				model_class *klass)
+{
+  tree class_obj = builtins->map_class_object (klass);
+  return build1 (ADDR_EXPR, type_class_ptr, class_obj);
+}
+
+tree
 cxx_abi::build_new (tree_builtins *builtins, aot_class *current,
 		    tree klass, tree constructor, tree arguments)
 {
@@ -223,12 +232,20 @@
 tree
 bc_abi::build_class_reference (tree_builtins *, aot_class *current, tree klass)
 {
-  return NULL_TREE;
+  abort ();
 }
 
 tree
+bc_abi::build_class_reference (tree_builtins *,
+			       aot_class *,
+			       model_class *)
+{
+  abort ();
+}
+
+tree
 bc_abi::build_new (tree_builtins *builtins, aot_class *current,
 		   tree klass, tree constructor, tree arguments)
 {
-  return NULL_TREE;
+  abort ();
 }
--- gcc/gcc/java/abi.hh
+++ gcc/gcc/java/abi.hh
@@ -87,8 +87,14 @@
   /// Return a tree representing a reference to some other class.
   virtual tree build_class_reference (tree_builtins *builtins,
 				      aot_class *current,
+				      // FIXME: should take a string here
 				      tree other) = 0;
 
+  /// Return a tree representing a reference to some other class.
+  virtual tree build_class_reference (tree_builtins *builtins,
+				      aot_class *current,
+				      model_class *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,
@@ -122,6 +128,10 @@
 
   tree build_class_reference (tree_builtins *, aot_class *, tree);
 
+  tree build_class_reference (tree_builtins *builtins,
+			      aot_class *current,
+			      model_class *other);
+
   tree build_new (tree_builtins *, aot_class *, tree, tree, tree);
 
   tree get_size_in_bytes (tree klass)
@@ -153,6 +163,10 @@
 
   tree build_class_reference (tree_builtins *, aot_class *, tree);
 
+  tree build_class_reference (tree_builtins *builtins,
+			      aot_class *current,
+			      model_class *other);
+
   tree build_new (tree_builtins *, aot_class *, tree, tree, tree);
 
   tree get_size_in_bytes (tree klass)
--- gcc/gcc/java/builtins.cc
+++ gcc/gcc/java/builtins.cc
@@ -252,6 +252,24 @@
 }
 
 tree
+tree_builtins::map_class_object (model_class *klass)
+{
+  if (classobj_map.find (klass) == classobj_map.end ())
+    {
+      tree decl = build_decl (VAR_DECL, NULL_TREE, type_class);
+      TREE_STATIC (decl) = 1;
+      DECL_ARTIFICIAL (decl) = 1;
+      DECL_IGNORED_P (decl) = 1;
+      // FIXME: DECL_EXTERNAL ?
+      SET_DECL_ASSEMBLER_NAME (decl,
+			       get_identifier (get_class_object_name (klass).c_str ()));
+
+      classobj_map[klass] = decl;
+    }
+  return classobj_map[klass];
+}
+
+tree
 tree_builtins::map_param_or_var (tree_code type, tree context,
 				 model_variable_decl *var)
 {
--- gcc/gcc/java/builtins.hh
+++ gcc/gcc/java/builtins.hh
@@ -29,6 +29,10 @@
   // This maps our types to gcc types.
   std::map<model_type *, tree> typemap;
 
+  // This maps classes to their class objects.
+  // FIXME: perhaps this should be attached to the gcc type somehow?
+  std::map<model_class *, tree> classobj_map;
+
   // This maps a method to its corresponding gcc tree.
   std::map<model_method *, tree> methodmap;
 
@@ -77,6 +81,7 @@
 
   tree map_method_call (aot_class *, tree, tree, model_method *, bool);
   tree map_new (model_class *, tree, tree);
+  tree map_class_object (model_class *);
 
   /// Memoize a utf8const.
   tree map_utf8const (const std::string &);
--- gcc/gcc/java/classobj.cc
+++ gcc/gcc/java/classobj.cc
@@ -85,7 +85,7 @@
 class_object_creator::make_decl (tree type, tree value)
 {
   tree decl = build_decl (VAR_DECL, NULL_TREE, type);
-  DECL_INITIAL (decl) = build_constructor (type, value);
+  DECL_INITIAL (decl) = value;
   TREE_STATIC (decl) = 1;
   DECL_ARTIFICIAL (decl) = 1;
   DECL_IGNORED_P (decl) = 1;
@@ -194,6 +194,8 @@
     }
 
   // FIXME create the tables and update the arguments
+  result_table = null_pointer_node;
+  result_syms = null_pointer_node;
 }
 
 void
@@ -263,12 +265,16 @@
     mods &= ~ACC_ACCESS;
   inst.set_field ("accflags", build_int_cst (type_jushort, mods));
 
+  tree super_tree = null_pointer_node;
   model_class *super = real_class->get_superclass ();
   if (real_class->interface_p ())
     super = global->get_compiler ()->java_lang_Object ();
-  inst.set_field ("superclass",
-		  super ? builtins->map_type (real_class->get_superclass ())
-		  : null_pointer_node);
+  if (super)
+    {
+      gcj_abi *abi = builtins->find_abi (super);
+      super_tree = abi->build_class_reference (builtins, klass, super);
+    }
+  inst.set_field ("superclass", super_tree);
 
   inst.set_field ("constants", null_pointer_node);  // FIXME
 
@@ -330,5 +336,9 @@
 
   tree init = inst.finish_record ();
 
-  result = make_decl (type_class, init);
+  result = builtins->map_class_object (klass->get ());
+  DECL_INITIAL (result) = init;
+  rest_of_decl_compilation (result, 1, 0);
+
+  result = build1 (ADDR_EXPR, type_class_ptr, result);
 }
--- gcc/gcc/java/decl.cc
+++ gcc/gcc/java/decl.cc
@@ -715,6 +715,8 @@
 static void
 initialize_version ()
 {
+  // FIXME: this is wrong, must parse version.c.
+  // Take from gcj.
   int version = __GNUC__ * 10000 + __GNUC_MINOR__ * 10;
   if (flag_indirect_dispatch)
     version += 5;



More information about the Java-patches mailing list