synced back up; 126k
authoradam <adam@megacz.com>
Wed, 25 Feb 2004 09:43:36 +0000 (09:43 +0000)
committeradam <adam@megacz.com>
Wed, 25 Feb 2004 09:43:36 +0000 (09:43 +0000)
darcs-hash:20040225094336-5007d-e4c4c59d1dbf7a1705435aea9ad29fcc0bd78382.gz

Makefile
src/org/ibex/plat/GCJ.java
src/org/ibex/util/BytecodePruner.java

index 7f3c4dc..5fb91ff 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -286,7 +286,12 @@ build/$(platform)/$(target_bin): upstream/jpeg-6b/build-$(target)/libjpeg.a
        cd upstream/gcc-3.3/build-$(target)/$(target)/libjava;           \
                $(shell pwd)/upstream/install/$(target)/bin/ar cq        \
                        $(shell pwd)/build/$(platform)/ibex.a            \
-                       `find $(shell pwd)/build/$(platform) -name \*.o` \
+                       `find $(shell pwd)/build/$(platform) -name \*.o`
+
+       rm -f build/$(platform)/natibex.a
+       cd upstream/gcc-3.3/build-$(target)/$(target)/libjava;           \
+               $(shell pwd)/upstream/install/$(target)/bin/ar cq        \
+                       $(shell pwd)/build/$(platform)/natibex.a         \
                        `cat $(shell pwd)/.natbins`
 # --relax,-O2,--no-whole-archive,
        PATH=upstream/install/bin:$$PATH upstream/install/bin/$(target)-gcj          \
@@ -296,9 +301,10 @@ build/$(platform)/$(target_bin): upstream/jpeg-6b/build-$(target)/libjpeg.a
                -Lupstream/install/$(target)/lib                                     \
                -Lupstream/install/lib                                               \
                -Os -w                                                               \
-               -Wl,--whole-archive \
+               -Wl,--whole-archive                                                  \
                build/$(platform)/ibex.a                                             \
-               -Wl,--no-whole-archive \
+               -Wl,--no-whole-archive                                               \
+               build/$(platform)/natibex.a                                          \
                upstream/jpeg-6b/build-$(target)/libjpeg.a                           \
                $(link_flags)                                                        \
                upstream/gcc-3.3/build-$(target)/$(target)/boehm-gc/.libs/libgcjgc.a \
index e68dc29..8954660 100644 (file)
@@ -10,26 +10,6 @@ import java.security.cert.*;
 /** common superclass for all platforms that use GCJ to compile a native binary */
 public abstract class GCJ extends Platform {
 
-    // static references to these classes ensure that the linker will include them
-    /*
-    public static Object c1 = new gnu.java.locale.Calendar();
-    public static Object c2 = new java.util.GregorianCalendar();
-    public static Object c3n = new gnu.gcj.convert.Input_ASCII();
-    public static Object c4 = new gnu.gcj.convert.Input_UTF8();
-    public static Object c5 = new gnu.gcj.convert.Input_8859_1();
-    public static Object c7 = new gnu.gcj.convert.Output_ASCII();
-    public static Object c6 = new gnu.java.locale.LocaleInformation();
-    public static Object c10 = new gnu.gcj.protocol.http.Handler();
-    public static Object c11 = new gnu.gcj.protocol.jar.Handler();
-    public static Object c12 = new java.security.cert.Certificate("foo") { 
-            public byte[] getEncoded() throws CertificateEncodingException { return null; }
-            public void verify(PublicKey key) { }
-            public void verify(PublicKey key, String sigProvider) { }
-            public String toString() { return "foocert"; }
-            public PublicKey getPublicKey() { return null; }
-        };
-    */
-
     protected native InputStream _getBuiltinInputStream();
 
     protected native void _decodeJPEG(InputStream is, Picture p);
index 519fa13..eb3040c 100644 (file)
@@ -22,7 +22,8 @@ public class BytecodePruner {
     public void loadAllMethods(String classname) throws Exception {
         visitJavaClass(repo.loadClass(classname));
         Method[] meths = getMethods(repo.loadClass(classname));
-        for(int i=0; i<meths.length; i++) visitJavaMethod(repo.loadClass(classname), meths[i]);
+        for(int i=0; i<meths.length; i++)
+            visitJavaMethod(repo.loadClass(classname), meths[i]);
     }
 
     public void loadField(String classAndMethodName) throws Exception {
@@ -136,10 +137,13 @@ public class BytecodePruner {
         cg.setMajor(46);
         cg.setMinor(0);
         cg.setConstantPool(newcpg);
+
+        // we can only prune static fields (to avoid altering object layout, which is hardcoded into
+        // CNI code), but that's okay since instance fields don't contribute to binary size
         Field[] fields = clazz.getFields();
         for(int i=0; i<fields.length; i++)
-            if (!dest.contains(fields[i]) && false) { 
-                System.out.println("  pruning " + clazz.getClassName() + "." + fields[i].getName());
+            if (!dest.contains(fields[i]) && fields[i].isStatic()) { 
+                System.out.println("  pruning field " + clazz.getClassName() + "." + fields[i].getName());
                 cg.removeField(fields[i]);
             }
 
@@ -240,6 +244,11 @@ public class BytecodePruner {
         // gcj bug; gcj can't compile this method from a .class file input
         //if (jc.getClassName().equals("java.lang.System") && method.getName().equals("runFinalizersOnExit")) return;
 
+        // HACK (okay?)
+        // not inferrable: CNI call to abstract method
+        if (jc.getClassName().equals("java.util.TimeZone") && method.getName().equals("getDefaultTimeZoneId"))
+            loadMethod("java.util.SimpleTimeZone.useDaylightTime");
+        
         dest.add(method);
         level += 2;
         for(int i=0; i<level; i++) System.out.print(" ");
@@ -254,6 +263,24 @@ public class BytecodePruner {
             Instruction instr = instructions[i];
             if (instr instanceof LoadClass) load(((LoadClass)instr).getLoadClassType(cpg));
             if (instr instanceof CPInstruction) load(((CPInstruction)instr).getType(cpg));
+            if (instr instanceof TypedInstruction) {
+                try { load(((TypedInstruction)instr).getType(cpg)); } catch (Exception e) { /* DELIBERATE */ }
+            }
+            if (instr instanceof NEW) {
+                for(int j=0; j<level; j++) System.out.print(" ");
+                loadMethod(((NEW)instr).getLoadClassType(cpg).getClassName() + ".<init>");
+            }
+            if (instr instanceof org.apache.bcel.generic.FieldOrMethod)
+                load(((org.apache.bcel.generic.FieldOrMethod)instr).getClassType(cpg));
+            if (instr instanceof org.apache.bcel.generic.FieldInstruction) {
+                load(((org.apache.bcel.generic.FieldInstruction)instr).getFieldType(cpg));
+                load(((org.apache.bcel.generic.FieldInstruction)instr).getType(cpg));
+                String fieldName = ((org.apache.bcel.generic.FieldInstruction)instr).getFieldName(cpg);
+                JavaClass jc2 = repo.loadClass(((ObjectType)((org.apache.bcel.generic.FieldInstruction)instr).
+                                                getLoadClassType(cpg)).getClassName());
+                Field[] fields = jc2.getFields();
+                for(int j=0; j<fields.length; j++) if (fields[j].getName().equals(fieldName)) visitJavaField(fields[j]);
+            }
             if (instr instanceof InvokeInstruction) {
                 InvokeInstruction ii = (InvokeInstruction)instr;
                 String ii_sig = getMethodSignature(ii, cpg);
@@ -320,11 +347,14 @@ public class BytecodePruner {
         }
 
         Field[] fields = clazz.getFields();
+        for(int i=0; i<fields.length; i++) {
+            if (!fields[i].isStatic())
+                visitJavaField(fields[i]);
+        }
+
         Method[] methods = getMethods(clazz);
-        for(int i=0; i<fields.length; i++) visitJavaField(fields[i]);
         for(int i=0; i<methods.length; i++) {
             if (methods[i].getName().equals("<clinit>")) visitJavaMethod(clazz, methods[i]);
-
             // only if ctor reachable (?)
             if (methods[i].getName().equals("equals")) visitJavaMethod(clazz, methods[i]);
             if (methods[i].getName().equals("hashCode")) visitJavaMethod(clazz, methods[i]);