From: adam Date: Tue, 13 Jul 2004 02:17:45 +0000 (+0000) Subject: removed NanoGoat X-Git-Url: http://git.megacz.com/?p=org.ibex.util.git;a=commitdiff_plain;h=d231d80267c8202c46a033f0a2f3831d04b56043 removed NanoGoat darcs-hash:20040713021745-5007d-d12370b7fcd69440024f4efcb5e47f56c1c39a23.gz --- diff --git a/src/org/ibex/util/NanoGoat.java b/src/org/ibex/util/NanoGoat.java deleted file mode 100644 index 2b5b772..0000000 --- a/src/org/ibex/util/NanoGoat.java +++ /dev/null @@ -1,475 +0,0 @@ -package org.ibex.util; -import java.util.*; -import java.io.*; -import java.util.zip.*; -import org.apache.bcel.*; -import org.apache.bcel.generic.*; -import org.apache.bcel.classfile.*; -import org.apache.bcel.util.*; - -public class NanoGoat { - - public static final boolean deleteMethods = false; - public static SyntheticRepository repo = null; - public static HashSet dest = new HashSet(); - public static HashSet constructed = new HashSet(); - public static String outdir = "."; - public static Hashtable subclasses = new Hashtable(); - public static Hashtable uponconstruction = new Hashtable(); - public static Hashtable mark_if_constructed = new Hashtable(); - public static int level = 0; - - public NanoGoat() { } - - public void loadAllMethods(String classname) throws Exception { - visitJavaClass(repo.loadClass(classname)); - Method[] meths = getMethods(repo.loadClass(classname)); - for(int i=0; i")) - isconstructed = true; - - // we can only prune static fields (to avoid altering object layout, which is hardcoded into - // CNI code), but that's okay since instance fields don't contribute to binary size - Field[] fields = clazz.getFields(); - for(int i=0; i", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL)); - il.append(InstructionConstants.ATHROW); - mg.setMaxStack(); - mg.setMaxLocals(); - mg.removeExceptions(); - mg.removeLocalVariables(); - mg.removeExceptionHandlers(); - mg.removeLineNumbers(); - cg.replaceMethod(methods[i], mg.getMethod()); - il.dispose(); - } - } - } - - // FIXME: chain up to superclass' ... that might remove the need for this hack - // FIXME: gcj compiling in jar-at-a-time mode can't be convinced to let classes outside the jar override - // the ones inside the jar - good = true; - - if (!good && !clazz.isAbstract() && !clazz.isInterface()) { - System.out.println("DROPPING " + clazz.getClassName()); - JavaClass[] ifaces = clazz.getInterfaces(); - String[] ifacestrings = new String[ifaces.length]; - for(int i=0; i 0 && (sig.charAt(0) == 'L' || sig.charAt(0) == '[')) { - if (sig.charAt(0) == 'L') sig = sig.substring(1, sig.length() - 1); - else if (sig.charAt(0) == '[') sig = sig.substring(1, sig.length()); - } - if (sig.length() <= 1) return null; - if (sig.equals("")) return null; - if (sig.startsWith(" 0 && (sig.charAt(0) == 'L' || sig.charAt(0) == '[')) { - if (sig.charAt(0) == 'L') sig = sig.substring(1, sig.length() - 1); - else if (sig.charAt(0) == '[') sig = sig.substring(1, sig.length()); - } - if (sig.length() <= 1) return; - if (sig.equals("")) return; - if (sig.startsWith("") && jc.getClassName().startsWith("java.lang.reflect.")) return; - - if (dest.contains(method)) return; - dest.add(method); - - if (method.getName().equals("") && jc.getSuperClass() != null) - loadMethod(jc.getSuperClass().getClassName() + "."); - - if (method.isStatic() || method.getName().equals("")) loadMethod(jc.getClassName() + "."); - if (method.getName().equals("")) { - // FIXME: generalize to all perinstancemethods - constructed.add(jc); - HashSet hs = (HashSet)uponconstruction.get(jc); - if (hs != null) { - Iterator it = hs.iterator(); - while(it.hasNext()) visitJavaMethod(jc, (Method)it.next()); - } - loadMethod(jc.getClassName() + ".equals"); - loadMethod(jc.getClassName() + ".hashCode"); - loadMethod(jc.getClassName() + ".toString"); - loadMethod(jc.getClassName() + ".finalize"); - loadMethod(jc.getClassName() + ".clone"); - } - - ConstantPoolGen cpg = new ConstantPoolGen(method.getConstantPool()); - if (!method.isStatic() && !constructed.contains(jc)) { - HashSet hs = (HashSet)uponconstruction.get(jc); - if (hs == null) uponconstruction.put(jc, hs = new HashSet()); - hs.add(method); - markMethodInSubclasses(jc, method, cpg); - dest.remove(method); - return; - } - - level += 2; - for(int i=0; i"); - } - if (instr instanceof CPInstruction) load(((CPInstruction)instr).getType(cpg)); - if (instr instanceof TypedInstruction) load(((TypedInstruction)instr).getType(cpg)); - if (instr instanceof NEW) loadMethod(((NEW)instr).getLoadClassType(cpg).getClassName() + "."); - if (instr instanceof org.apache.bcel.generic.FieldOrMethod) - load(((org.apache.bcel.generic.FieldOrMethod)instr).getClassType(cpg)); - if (instr instanceof org.apache.bcel.generic.FieldInstruction) { - load(((org.apache.bcel.generic.FieldInstruction)instr).getFieldType(cpg)); - load(((org.apache.bcel.generic.FieldInstruction)instr).getType(cpg)); - String fieldName = ((org.apache.bcel.generic.FieldInstruction)instr).getFieldName(cpg); - JavaClass jc2 = repo.loadClass(((ObjectType)((org.apache.bcel.generic.FieldInstruction)instr). - getLoadClassType(cpg)).getClassName()); - Field[] fields = jc2.getFields(); - for(int j=0; j"); - } - - public void visitJavaClass(JavaClass clazz) throws Exception { - if (dest.contains(clazz)) return; - dest.add(clazz); - - ConstantPoolGen cpg = new ConstantPoolGen(clazz.getConstantPool()); - level += 2; - for(int i=0; i")) return; - if (m.getName().equals("equals")) return; - if (m.getName().equals("hashCode")) return; - if (m.getName().equals("clone")) return; - if (m.getName().equals("finalize")) return; - if (m.getName().equals("toString")) return; - String sig = getMethodSignature(m, cpg); - Method[] submethods = getMethods(subclass); - for(int j=0; j")) return; - HashSet s = (HashSet)subclasses.get(c); - if (s == null) return; - Object[] subclasses = s.toArray(); - for(int i=0; i