This is the mail archive of the java@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]

Re: statically linked executable size


Ranjit Mathew writes:
 > -----BEGIN PGP SIGNED MESSAGE-----
 > Hash: SHA1
 > 
 > Andrew Haley wrote:
 > > Ranjit Mathew writes:
 > >  > 
 > >  > There are so many classes whose presence in the executable is
 > >  > something that I cannot readily account for - for example, why
 > >  > is javax.swing.JToolBar needed to print "Hello World" on the
 > >  > console?
 > > 
 > > This one comes up every once in a while, and there's a technique for
 > > finding out.
 > > 
 > >  $ gcj -static Hello.java --main=Hello -Wl,-Map,Hello.map
 > 
 > Thanks. I don't know why I didn't remember to use this.
 > 
 > What seems to happen is that we have java.lang.SecurityManager
 > that directly uses java.awt.AWTPermission. This means that the
 > object file for the *entire* java.awt package gets pulled in,
 > since we compile a package at a time, which leads to a whole
 > lot of new references that need to be satisfied and so on
 > ad nauseum.
 > 
 > Now I can see how JToolBar gets pulled in.

OK, I see it.

Now comes the question: how shall we fix this?  We can either 

* compile SecurityManager.java BC 
* or we can make a gcj-specific change (more Classpath divergence)
* or we can compile AWTPermission separately from the rest of AWT
* put each class in its own section (but that's only ELF afaiaa)

Making SecurityManager.java BC probably won't work when statically
linking, because its dependencies would not be included in the final
binary.

I've appended the fix for SecurityManager, but that doesn't help at
all because java.text.Bidi uses java.awt.font.NumericShaper.  However,
nothing actually _refers_ to java.text.Bidi. so putting classes into
separate objects when statically linking would solve that particular
problem.

Most of this seems to me to be perverse dependencies in the _design_
of the Java(tm) library, not something we can fix.  Why is
NumericShaper in AWT, anyway?

Andrew.


Index: SecurityManager.java
===================================================================
--- SecurityManager.java	(revision 115033)
+++ SecurityManager.java	(working copy)
@@ -38,10 +38,10 @@
 
 package java.lang;
 
-import java.awt.AWTPermission;
 import java.io.File;
 import java.io.FileDescriptor;
 import java.io.FilePermission;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.Member;
 import java.net.InetAddress;
 import java.net.SocketPermission;
@@ -827,7 +827,7 @@
       throw new NullPointerException();
     try
       {
-        checkPermission(new AWTPermission("showWindowWithoutWarningBanner"));
+        checkPermission(getAWTPermission("showWindowWithoutWarningBanner"));
         return true;
       }
     catch (SecurityException e)
@@ -865,7 +865,7 @@
    */
   public void checkSystemClipboardAccess()
   {
-    checkPermission(new AWTPermission("accessClipboard"));
+    checkPermission(getAWTPermission("accessClipboard"));
   }
 
   /**
@@ -881,7 +881,7 @@
    */
   public void checkAwtEventQueueAccess()
   {
-    checkPermission(new AWTPermission("accessEventQueue"));
+    checkPermission(getAWTPermission("accessEventQueue"));
   }
 
   /**
@@ -1053,6 +1053,25 @@
         packageName = index < 0 ? "" : packageName.substring(0, index);
       }
   }
+
+  /* GCJ Specific: don't emit a static reference to AWTPermission;
+     this would cause all of AWT to be included when linking
+     statically.  */
+  static private Permission getAWTPermission(String s)
+  {
+    try
+      {
+	Class c = Class.forName("java.awt.AWTPermission");
+	Class[] argTypes = {String.class};
+	Constructor m = c.getConstructor(argTypes);
+	Object args[] = {s};
+	return (Permission)m.newInstance(args);
+      }
+    catch (Exception e)
+      {
+	throw new Error(e);
+      }
+  }
 } // class SecurityManager
 
 // XXX This class is unnecessary.


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