X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=inline;f=src%2Fcom%2Fbrian_web%2Fgcclass%2FGCClass.java;fp=src%2Fcom%2Fbrian_web%2Fgcclass%2FGCClass.java;h=b17c5b521de8a2a4140e45d002e7ad9962fb1f04;hb=d0c6ecb814b6ee5d933b28a555a9f32dd4228026;hp=5b8397016fb8e141142a3a0552ce9886d72bdf0d;hpb=8d0fd7ec906c821fdf92fd2045d128ff8e8306ae;p=org.ibex.gcclass.git diff --git a/src/com/brian_web/gcclass/GCClass.java b/src/com/brian_web/gcclass/GCClass.java index 5b83970..b17c5b5 100644 --- a/src/com/brian_web/gcclass/GCClass.java +++ b/src/com/brian_web/gcclass/GCClass.java @@ -19,8 +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 - public class GCClass { private static final String[] PRE_REF = { "java.lang.Thread.run", @@ -297,30 +295,53 @@ public class GCClass { } private void dumpClass(JavaClass c, Hashtable refs, boolean staticOnly, File file) throws IOException { - ClassGen cg = new ClassGen(c); - Method[] methods= c.getMethods(); + ClassGen oldCG = new ClassGen(c); + ConstantPoolGen oldCP = oldCG.getConstantPool(); + + ConstantPoolGen cp = new ConstantPoolGen(); + ClassGen cg = new ClassGen(c.getClassName(),c.getSuperclassName(),c.getSourceFileName(),c.getAccessFlags(),c.getInterfaceNames(),cp); + + Method[] methods= oldCG.getMethods(); for(int i=0;i",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