From d0c6ecb814b6ee5d933b28a555a9f32dd4228026 Mon Sep 17 00:00:00 2001 From: brian Date: Thu, 27 May 2004 13:15:15 +0000 Subject: [PATCH] prune constant pool darcs-hash:20040527131515-24bed-f61e39a3a8c0cb1a619f4ee227ec60f75a5c33e1.gz --- Makefile | 1 + src/com/brian_web/gcclass/GCClass.java | 71 +++++++++++++++++++++++++------- 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 1322d03..3735cd9 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ Test.class: Test.java test: all Test.class java -cp build:$(bcel_jar) com.brian_web.gcclass.GCClass . stripped Test.main + java -cp stripped Test $(bcel_jar): mkdir -p upstream 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