X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fcom%2Fbrian_web%2Fgcclass%2FGCClass.java;h=86b427148c326658e189f8929049a98f722b8646;hb=6c5c8ed617e9e8f793cfbe9f0117440bfcb9a0a3;hp=77b6e122111fbc75c5f3e6ac5479e4de1d47c71e;hpb=94ca00b8891f6707c1b0a2133cc94517694d0c62;p=org.ibex.gcclass.git diff --git a/src/com/brian_web/gcclass/GCClass.java b/src/com/brian_web/gcclass/GCClass.java index 77b6e12..86b4271 100644 --- a/src/com/brian_web/gcclass/GCClass.java +++ b/src/com/brian_web/gcclass/GCClass.java @@ -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", @@ -38,16 +35,25 @@ public class GCClass { "java.security.*" }; + private static final String[] IGNORED_FIELDS = { + "java.io.ObjectInputStream.SUBCLASS_IMPLEMENTATION_PERMISSION" + }; + private static final String[] NO_OUTPUT = { "java", "javax", "sun", "com.sun", "apple", "com.apple" }; 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]); - for(int i=2;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); @@ -193,7 +282,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(); @@ -207,15 +296,44 @@ 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