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]

Symbol visibility for gcj


This changes the symbol export rules for gcj-built DSOs.  We no longer
output symbols for:

private static methods
private static fields
private classes
vtables (except java.lang.Class)
class$$ fields

This reduces the number of symbols in libgcj.so from 87509 to 66209, a
saving of 20%.

I've attached the list of symbols that are no longer emitted.  

I don't believe it should cause any problems, but it is possible that
this will break some code that was using CNI to access private symbols
inside a DSO.  I don't think we care about that.

Andrew.



2007-03-23  Andrew Haley  <aph@redhat.com>

	* jvgenmain.c (main): Change main to use class$, not class$$.
	(do_mangle_classname): Likewise.
	* class.c (hide): New function.
	(add_field): Hide everything that shouldn't be visible outside a
	DSO.
	(build_static_class_ref): Likewise.
	(build_classdollar_field): Likewise.
	(make_class_data): Likewise.
	(layout_class_method): Likewise.
	
Index: class.c
===================================================================
--- class.c	(revision 123084)
+++ class.c	(working copy)
@@ -691,6 +691,13 @@
   return fntype;
 }
 
+static void
+hide (tree decl)
+{
+  DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
+  DECL_VISIBILITY_SPECIFIED (decl) = 1;
+}
+
 tree
 add_method_1 (tree this_class, int access_flags, tree name, tree function_type)
 {
@@ -801,6 +808,10 @@
       /* Always make field externally visible.  This is required so
 	 that native methods can always access the field.  */
       TREE_PUBLIC (field) = 1;
+      /* Hide everything that shouldn't be visible outside a DSO.  */
+      if (flag_indirect_classes
+	  || (FIELD_PRIVATE (field)))
+	hide (field);
       /* Considered external unless we are compiling it into this
 	 object file.  */
       DECL_EXTERNAL (field) = (is_compiled_class (class) != 2);
@@ -958,7 +969,11 @@
       decl = build_decl (VAR_DECL, decl_name, class_type_node);
       TREE_STATIC (decl) = 1;
       if (! flag_indirect_classes)
-	TREE_PUBLIC (decl) = 1;
+	{
+	  TREE_PUBLIC (decl) = 1;
+	  if (CLASS_PRIVATE (TYPE_NAME (type)))
+	    hide (decl);
+	}
       DECL_IGNORED_P (decl) = 1;
       DECL_ARTIFICIAL (decl) = 1;
       if (is_compiled_class (type) == 1)
@@ -997,6 +1012,7 @@
       TREE_CONSTANT (decl) = 1;
       TREE_READONLY (decl) = 1;
       TREE_PUBLIC (decl) = 1;
+      hide (decl);
       DECL_IGNORED_P (decl) = 1;
       DECL_ARTIFICIAL (decl) = 1;
       MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
@@ -1684,6 +1700,10 @@
 
       TREE_PUBLIC (dtable_decl) = 1;
       DECL_INITIAL (dtable_decl) = dtable;
+      /* The only dispatch table exported from a DSO is the dispatch
+	 table for java.lang.Class.  */
+      if (DECL_NAME (type_decl) != id_class)
+	hide (dtable_decl);
       if (! flag_indirect_classes)
 	rest_of_decl_compilation (dtable_decl, 1, 0);
       /* Maybe we're compiling Class as the first class.  If so, set
@@ -2553,6 +2573,10 @@
 
   TREE_PUBLIC (method_decl) = 1;
 
+  if (flag_indirect_classes
+      || (METHOD_PRIVATE (method_decl) && METHOD_STATIC (method_decl)))
+    hide (method_decl);
+
   /* Considered external unless it is being compiled into this object
      file, or it was already flagged as external.  */
   if (!DECL_EXTERNAL (method_decl))
Index: jvgenmain.c
===================================================================
--- jvgenmain.c	(revision 123084)
+++ jvgenmain.c	(working copy)
@@ -143,8 +143,8 @@
     fprintf (stream, "   JvRunMainName (\"%s\", argc, argv);\n", classname);
   else
     {
-      fprintf (stream, "   extern void *%s;\n", mangled_classname);
-      fprintf (stream, "   JvRunMain (%s, argc, argv);\n", mangled_classname);
+      fprintf (stream, "   extern char %s;\n", mangled_classname);
+      fprintf (stream, "   JvRunMain (&%s, argc, argv);\n", mangled_classname);
     }
   fprintf (stream, "}\n");
   if (stream != stdout && fclose (stream) != 0)
@@ -176,7 +176,7 @@
 	count++;
     }
   append_gpp_mangled_name (&ptr [-count], count);
-  obstack_grow (mangle_obstack, "7class$$E", strlen ("7class$$E"));
+  obstack_grow (mangle_obstack, "6class$E", strlen ("6class$E"));
   obstack_1grow (mangle_obstack, '\0');
   return obstack_finish (mangle_obstack);
 }


Attachment: nosyms.gz
Description: Binary data


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