From 1cedba08e30cab3d05db004db380ee20bb50e98b Mon Sep 17 00:00:00 2001 From: brian Date: Sun, 9 May 2004 21:42:28 +0000 Subject: [PATCH] drop non-instansiated classes darcs-hash:20040509214228-24bed-6f487b24c4fbf9c68d60e3c2bc042d6e6099b2ae.gz --- src/com/brian_web/gcclass/GCClass.java | 48 +++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/src/com/brian_web/gcclass/GCClass.java b/src/com/brian_web/gcclass/GCClass.java index 77b6e12..fdb1cc6 100644 --- a/src/com/brian_web/gcclass/GCClass.java +++ b/src/com/brian_web/gcclass/GCClass.java @@ -20,7 +20,6 @@ import org.apache.bcel.generic.*; import org.apache.bcel.classfile.*; // FEATURE: Rebuild each method with a new constant pool to eliminate extra constant pool entries -// FEATURE: Optimize away INSTANCEOF if the class can never be instansiated public class GCClass { private static final String[] PRE_REF = { @@ -56,6 +55,7 @@ public class GCClass { private final Vector work = new Vector(); private final Hashtable completed = new Hashtable(); private final Hashtable references = new Hashtable(); + private final Hashtable instansiated = new Hashtable(); public GCClass(String classpath) throws ClassNotFoundException { repo = SyntheticRepository.getInstance(new ClassPath(ClassPath.SYSTEM_CLASS_PATH + File.pathSeparator + classpath)); @@ -81,12 +81,14 @@ public class GCClass { return t; } - public final void referenceMethod(String s) throws ClassNotFoundException { + public void referenceMethod(String s) throws ClassNotFoundException { int p = s.lastIndexOf('.'); if(p == -1) throw new IllegalArgumentException("invalid class/method string"); String cs = s.substring(0,p); String ms = s.substring(p+1); + if(ms.equals("")) instansiated.put(new ObjectType(cs),Boolean.TRUE); + JavaClass c = repoGet(cs); Method[] methods = c.getMethods(); for(int i=0;i",Type.VOID,Type.NO_ARGS); if(findMethod(c,clinit) != null) referenceMethod(clinit); } + Method[] methods = c.getMethods(); JavaClass[] supers = c.getSuperClasses(); JavaClass[] interfaces = c.getInterfaces(); - //System.err.println("Fixing up " + t); + + // If a subclass can be instansiated all its superclasses also can + if(instansiated.get(t) != null) { + for(int i=0;i")) return; Method m = findMethod(c,mr); @@ -207,6 +227,8 @@ public class GCClass { for(int n=0;n