X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fcom%2Fbrian_web%2Fgcclass%2FGCClass.java;h=b17c5b521de8a2a4140e45d002e7ad9962fb1f04;hb=d0c6ecb814b6ee5d933b28a555a9f32dd4228026;hp=597159126f0e3c1339f8cbfbf4de27aa25076e32;hpb=55790e1e51cf5bbb5cbec3f0526c56dfbf5c0db7;p=org.ibex.gcclass.git diff --git a/src/com/brian_web/gcclass/GCClass.java b/src/com/brian_web/gcclass/GCClass.java index 5971591..b17c5b5 100644 --- a/src/com/brian_web/gcclass/GCClass.java +++ b/src/com/brian_web/gcclass/GCClass.java @@ -1,6 +1,6 @@ // Copyright (C) 2004 Brian Alliet -// Based on NanoGoat by Adam Megac +// Based on NanoGoat by Adam Megacz // Copyright (C) 2004 Adam Megacz all rights reserved. // @@ -19,9 +19,6 @@ import org.apache.bcel.util.*; 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 = { "java.lang.Thread.run", @@ -43,7 +40,7 @@ public class GCClass { public static void main(String[] args) throws Exception { if(args.length < 3) { - System.err.println("Usage GCClass classpath outdir entrypoint1 ... [ entrypoint n]"); + System.err.println("Usage GCClass classpath outdir entrypoint1 ... [ entrypoint n]"); System.exit(1); } GCClass gc = new GCClass(args[0]); @@ -56,11 +53,21 @@ 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 { - System.err.println(ClassPath.SYSTEM_CLASS_PATH + File.pathSeparator + classpath); - repo = SyntheticRepository.getInstance(new ClassPath(ClassPath.SYSTEM_CLASS_PATH + File.pathSeparator + classpath)); - for(int i=0;i"))) + 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); @@ -194,7 +243,7 @@ public class GCClass { String pat = IGNORED_METHODS[i]; if(pat.endsWith("*") ? sig.startsWith(pat.substring(0,pat.length()-1)) : sig.equals(pat)) return; } - throw new Exn("Couldn't find " + sig); + throw new ClassNotFoundException("" + mr + " not found (but the class was)"); } Code code = m.getCode(); @@ -208,12 +257,14 @@ public class GCClass { for(int n=0;n",Type.VOID, new Type[]{Type.STRING},Constants.INVOKESPECIAL)); + if(false) { + il.append(new PUSH(cg.getConstantPool(),"" + mr + " has been pruned")); + il.append(fac.createInvoke("java.lang.UnsatisfiedLinkError","",Type.VOID, new Type[]{Type.STRING},Constants.INVOKESPECIAL)); + } else { + il.append(fac.createInvoke("java.lang.UnsatisfiedLinkError","",Type.VOID,Type.NO_ARGS,Constants.INVOKESPECIAL)); + } il.append(InstructionConstants.ATHROW); mg.setMaxStack(); mg.setMaxLocals(); - cg.replaceMethod(m,mg.getMethod()); + cg.addMethod(mg.getMethod()); } - } else { - //System.err.println("Keeping method " + mr); + } else { + MethodGen mg = new MethodGen(m,cg.getClassName(),oldCP); + mg.setConstantPool(cp); + if(mg.getInstructionList() != null) mg.getInstructionList().replaceConstantPool(oldCP, cp); + + Attribute[] attrs = m.getAttributes(); + for(int j=0;j