// Copyright 2000-2005 the Contributors, as shown in the revision logs. // Licensed under the Apache Public Source License 2.0 ("the License"). // You may not use this file except in compliance with the License. // Copyright (C) 2004 Brian Alliet // Based on NanoGoat by Adam Megacz package org.ibex.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.*; public class GCClass { private static final String[] PRE_REF = { "java.lang.Thread.run", "java.security.PrivilegedAction.run" }; // NOTE: This doesn't mean these classes are ignored alltogether // failures to resolve them are just ignored 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.*", "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.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(); // 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); if(m == null) { JavaClass supers[] = c.getSuperClasses(); for(int i=0;i",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.addMethod(mg.getMethod()); } } 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