[gcjx] Patch: FYI: mangle name of Class object

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


I'm checking this in on the gcjx branch.

Right now we name the Class object as if it were a static field named
"class$".  Although this has never actually caused us any problems,
today I think this is wrong, since it could in theory lead to name
clash.  Nevertheless I'm not fixing this at the moment, just
implementing it.

Tom

# 
# patch "gcc/gcc/java/ChangeLog"
#  from [1e921377e1dfe6a6b40dcd60b91880c37cc0905c]
#    to [3053b23975dadc7566ab5ae4cb9a1c78b1839612]
# 
# patch "gcc/gcc/java/builtins.cc"
#  from [ca6ba9642408e40ddf9602ca9bd90c24476fe971]
#    to [dd0ee449d75ced40ebabb24bf519fb76a7f5d513]
# 
# patch "gcc/gcc/java/builtins.hh"
#  from [c3d1aefd52cba4b6a2f9a3d165e9b8951527340f]
#    to [a4ff5bcc8baed5e7273157b055bc060e52edd1ee]
# 
# patch "gcc/gcc/java/classobj.cc"
#  from [f61c32620667b37790ad1c5760c9c88e73b51d8a]
#    to [9ac15b71e14bae18bd69400f3a0f53cc05c692ba]
# 
# patch "gcc/gcjx/ChangeLog"
#  from [d7e70152cd5994bd311a70767589c147bc65c97e]
#    to [f10c0aee4b72c4534336756fbe8daea66564140b]
# 
# patch "gcc/gcjx/aot/mangle.cc"
#  from [18af9c37cbf77b58dce35b15d2d55a7743873479]
#    to [781cfd57dfa645b288e28d43559a06f90fba88e6]
# 
# patch "gcc/gcjx/aot/mangle.hh"
#  from [158ff5f7a0e0e1df5745fb68abd65899c8007a0f]
#    to [1e55422e1f6c15db74245ccf35eac91dd006d9c8]
# 
--- gcc/gcc/java/ChangeLog
+++ gcc/gcc/java/ChangeLog
@@ -1,5 +1,10 @@
 2005-02-09  Tom Tromey  <tromey@redhat.com>
 
+	* classobj.cc (make_decl): Set decl assembler name on class
+	record.
+	* builtins.cc (get_class_object_name): New method.
+	* builtins.hh (tree_builtins::get_class_object_name): Declare.
+
 	* decl.cc (build_class_type): Register itable, itable_syms,
 	assertion_table, engine.
 	* builtins.cc (map_utf8const): New method.
--- gcc/gcc/java/builtins.cc
+++ gcc/gcc/java/builtins.cc
@@ -21,6 +21,7 @@
 
 // This include must come first.
 #include "java/glue.hh"
+#include "aot/mangle.hh"
 
 tree_builtins::tree_builtins ()
   : aot_class_factory ()
@@ -470,3 +471,10 @@
     }
   abort ();
 }
+
+std::string
+tree_builtins::get_class_object_name (model_class *klass)
+{
+  mangler m (klass, "class$");
+  return m.get ();
+}
--- gcc/gcc/java/builtins.hh
+++ gcc/gcc/java/builtins.hh
@@ -97,6 +97,9 @@
   void initialize_type_map ();
 
   gcj_abi *find_abi (model_type *);
+
+  /// Return the mangled name of the class object for a given class.
+  std::string get_class_object_name (model_class *);
 };
 
 #endif // GCC_TREE_BUILTINS_HH
--- gcc/gcc/java/classobj.cc
+++ gcc/gcc/java/classobj.cc
@@ -89,6 +89,8 @@
   TREE_STATIC (decl) = 1;
   DECL_ARTIFICIAL (decl) = 1;
   DECL_IGNORED_P (decl) = 1;
+  SET_DECL_ASSEMBLER_NAME (decl,
+			   get_identifier (builtins->get_class_object_name (klass->get ()).c_str ()));
   rest_of_decl_compilation (decl, 1, 0);
 
   return build1 (ADDR_EXPR, build_pointer_type (type), decl);
--- gcc/gcjx/ChangeLog
+++ gcc/gcjx/ChangeLog
@@ -1,3 +1,8 @@
+2005-02-09  Tom Tromey  <tromey@redhat.com>
+
+	* aot/mangle.cc (mangler): New constructor.
+	* aot/mangle.hh (mangler): Declare.
+
 2005-02-08  Tom Tromey  <tromey@redhat.com>
 
 	* model/method.cc (model_method): Updated.
--- gcc/gcjx/aot/mangle.cc
+++ gcc/gcjx/aot/mangle.cc
@@ -249,3 +249,11 @@
   update (f->get_name ());
   result += "E";
 }
+
+mangler::mangler (model_class *declaring, const std::string &fieldname)
+  : result ("_Z")
+{
+  update (declaring, false);
+  update (fieldname);
+  result += "E";
+}
--- gcc/gcjx/aot/mangle.hh
+++ gcc/gcjx/aot/mangle.hh
@@ -53,6 +53,10 @@
 
   mangler (model_field *);
 
+  // This is a way to create a mangled name for a non-existing field,
+  // given its declaring class.
+  mangler (model_class *, const std::string &);
+
   std::string get () const
   {
     return result;



More information about the Java-patches mailing list