From 916f7fb188df31094d1f78e67bc16b89c4b7a76d Mon Sep 17 00:00:00 2001 From: brian Date: Sun, 9 May 2004 07:46:04 +0000 Subject: [PATCH] initial 2 darcs-hash:20040509074604-24bed-3effbeb10c65c7d6e60f132e29c1c0197b3bb04f.gz --- src/com/brian_web/gcclass/GCClass.java | 351 ++++++++++++++++++++++++++++++++ 1 file changed, 351 insertions(+) create mode 100644 src/com/brian_web/gcclass/GCClass.java diff --git a/src/com/brian_web/gcclass/GCClass.java b/src/com/brian_web/gcclass/GCClass.java new file mode 100644 index 0000000..54a902c --- /dev/null +++ b/src/com/brian_web/gcclass/GCClass.java @@ -0,0 +1,351 @@ +// Copyright (C) 2004 Brian Alliet + +// Based on NanoGoat by Adam Megac + +// Copyright (C) 2004 Adam Megacz all rights reserved. +// +// You may modify, copy, and redistribute this code under the terms of +// the GNU Library Public License version 2.1, with the exception of +// the portion of clause 6a after the semicolon (aka the "obnoxious +// relink clause") + +package com.brian_web.gcclass; + +import java.util.*; +import java.io.*; + +import org.apache.bcel.Constants; +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 { + // This is called outside pure java so we don't see the call + private static final String[] PRE_REF = { "java.lang.Thread.run" }; + // The JDK uses some voodoo under the hood to implement these methods + private static final String[] IGNORED_METHODS = { + "java.net.SocketImpl.setOption(ILjava/lang/Object;)V", + "java.net.SocketImpl.getOption(I)Ljava/lang/Object;", + "java.awt.geom.*", + "apple.awt.*" + }; + + 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.exit(1); + } + GCClass gc = new GCClass(args[0]); + for(int i=2;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); + for(int i=0;i")) return; + + Method m = findMethod(c,mr); + if(m == null) { + JavaClass supers[] = c.getSuperClasses(); + for(int i=0;i",Type.VOID, new Type[]{Type.STRING},Constants.INVOKESPECIAL)); + il.append(InstructionConstants.ATHROW); + mg.setMaxStack(); + mg.setMaxLocals(); + cg.replaceMethod(m,mg.getMethod()); + } + } else { + //System.err.println("Keeping method " + mr); + } + } + + Field[] fields = c.getFields(); + for(int i=0;i