find upstream -name config.cache -exec rm {} \;
test -e upstream/mips && make -C upstream/mips clean
-libwing_Linux := -Lupstream/install/i686-pc-linux-gnu/lib/
-libwing_Linux += upstream/install/i686-pc-linux-gnu/lib/libWINGs.a
-libwing_Linux += upstream/install/i686-pc-linux-gnu/lib/libwraster.a
+#libwing_Linux := -Lupstream/install/i686-pc-linux-gnu/lib/
+#libwing_Linux += upstream/install/i686-pc-linux-gnu/lib/libWINGs.a
+#libwing_Linux += upstream/install/i686-pc-linux-gnu/lib/libwraster.a
libwing_Solaris := -Lupstream/install/sparc-sun-solaris2.7/lib/
libwing_Solaris += upstream/install/sparc-sun-solaris2.7/lib/libWINGs.a
jar := $(shell ((type fastjar &>/dev/null) && echo fastjar) || echo jar)
gcj: .install_gcc-3.3_$(target)
- make compile
+# make compile
make build/$(platform)/$(target_bin) link_flags="$(link_flags)" platform=$(platform)
include Makefile.upstream
@make -s $(java_sources:build/java/%.java=build/class/%.class)
.compile: compile
-#.compile: $(java_sources) .jikes .install_mips2java
-# @echo -e "\n\033[1mcompiling .java -> .class: src/**/*.java\033[0m"
-# @rm -f $(java_sources:build/java/%.java=build/class/%.class)
-# mkdir -p build/class
-# cd build/java; for A in `find . -name \*.java`; do mkdir -p ../class/`dirname $$A`; done
-# @./.jikes -Xlint:deprecation $(java_sources)
-# touch .compile
+.compile: $(java_sources) .jikes .install_mips2java
+ @echo -e "\n\033[1mcompiling .java -> .class: src/**/*.java\033[0m"
+ @rm -f $(java_sources:build/java/%.java=build/class/%.class)
+ mkdir -p build/class
+ cd build/java; for A in `find . -name \*.java`; do mkdir -p ../class/`dirname $$A`; done
+ @./.jikes $(java_sources)
+ touch .compile
build/JVM/ibex.jar: .compile build/res/builtin.jar build/class/org/ibex/translators/MIPSApps.class
@echo -e "\n\033[1marchiving .class -> .jar: build/JVM/ibex.jar\033[0m"
upstream/jpeg-6b/build-$(target)/libjpeg.a: .install_jpeg-6b_$(target)
# note: binaries appear in a different order in the dependency line vs the link line
-build/$(platform)/$(target_bin): upstream/jpeg-6b/build-$(target)/libjpeg.a build/$(platform)/builtin.o build/$(platform)/org/ibex/plat/$(platform).cc.o
+build/$(platform)/$(target_bin): .compile build/$(platform)/builtin.o build/$(platform)/org/ibex/plat/$(platform).cc.o upstream/jpeg-6b/build-$(target)/libjpeg.a
@echo -e "\n\033[1mlinking .o -> $(target_bin)\033[0m"
- find upstream/gcc-3.3/build-i686-pc-linux-gnu/i686-pc-linux-gnu/libjava/ \
- -name nat\*.o -or \( -name \*.o -not -name '*[A-Z]*' \) -exec nm {} \; |\
- grep _ZN | c++filt --format java | grep " U " | sed 's_\.class\$$_.class_' | sed 's_ * U __' | sed 's_(.*__' \
- > .natcalls
- make $(java_sources)
+ cd upstream/gcc-3.3/build-$(target)/$(target)/libjava; \
+ (find . -name nat\*.o | grep -v JIS; \
+ echo boehm.o;\
+ echo defineclass.o;\
+ echo exception.o;\
+ echo posix-threads.o;\
+ echo posix.o;\
+ echo prims.o;\
+ echo jni.o;\
+ echo resolve.o;\
+ echo libltdl/ltdl.o;\
+ find java gnu -name \*.o -not -name '*[A-Z]*'; \
+ ) > $(shell pwd)/.natbins
+
+# drop gnu regexp library?
+ cd upstream/gcc-3.3/build-$(target)/$(target)/libjava;\
+ cat $(shell pwd)/.natbins | grep -v shs | grep -v SHS |xargs nm |\
+ grep _ZN | c++filt --format java | grep " U " | sed 's_\.class\$$_.class_' | sed 's_ * U __' | sed 's_(.*__' \
+ > $(shell pwd)/.natcalls
+
+# make $(java_sources)
rm -rf build/pruned; mkdir -p build/pruned
+# rm -rf build/pruned; cd build; ln -s class pruned
javac -classpath lib/bcel-5.1.jar:build/class -d build/class src/org/ibex/util/BytecodePruner.java
rm -f build/$(platform)/ibex.jar
cd build/class; \
-o build/pruned \
`cat .natcalls`
- rm -rf build/pruned/org/ibex/js/*; cp build/java/org/ibex/js/* build/pruned/org/ibex/js/
+# rm -rf build/pruned/org/ibex/js/*; cp build/java/org/ibex/js/* build/pruned/org/ibex/js/
- rm build/pruned/java/lang/System.class
+ rm -f build/pruned/java/lang/System.*
cp upstream/gcc-3.3/src/libjava/java/lang/System.java build/pruned/java/lang/
- rm build/pruned/gnu/gcj/runtime/FirstThread*.class
- cp upstream/gcc-3.3/src/libjava/gnu/gcj/runtime/FirstThread.java build/pruned/gnu/gcj/runtime/
+# rm build/pruned/gnu/gcj/runtime/FirstThread*.*
+# cp upstream/gcc-3.3/src/libjava/gnu/gcj/runtime/FirstThread.java build/pruned/gnu/gcj/runtime/
rm build/pruned/org/ibex/plat/GCJ*.class
cp build/java/org/ibex/plat/GCJ.java build/pruned/org/ibex/plat/
+ rm -rf build/Linux/java
+ rm -rf build/Linux/gnu/gcj
+ rm -rf build/Linux/gnu/java
+ rm -rf build/Linux/gnu/classpath
+
cp upstream/gcc-3.3/build-$(target)/$(target)/libjava/java/lang/Object.class build/pruned/java/lang/
- find build/pruned/gnu/java/locale/ -name 'LocaleInformation_*' -not -name 'LocaleInformation_en.class' -not -name 'LocaleInformation_en_US.class' -exec rm {} \;
+# find build/pruned/gnu/java/locale/ -name 'LocaleInformation_*' -not -name 'LocaleInformation_en.class' -not -name 'LocaleInformation_en_US.class' -exec rm {} \;
# cd build/pruned; fastjar cvf ../../tmp.jar .
-# java -jar lib/jarg.jar -verbose -verboseufm -normlv -normsf -normsy -normin \
-# -normex -nornc -nornf -nornm -nobco tmp.jar
-# cd build/pruned; fastjar xvf ../../tmp.jar
+# java -jar lib/jarg.jar -verbose -verbosern -verboseufm -normlv -normsf -normsy -normin \
+# -nornc -nornf -nornm \
+# -normex -nobco tmp.jar
+# cd build/pruned; rm -rf *; fastjar xvf ../../tmp_s.jar
-# try oneshot compile/link
-# --redefine-sym to merge errorthrowers? or do this in C++?
-# --rename-section to try to merge Utf8 sections?
+# -fnew-ra \
+# -ffunction-sections \
+# -fdata-sections \
+# -fomit-frame-pointer \
+# -fno-force-mem \
+# -fno-force-addr \
+# -fbranch-probabilities \
+# -fno-schedule-insns \
+# -fno-optimize-sibling-calls \
+# -fno-if-conversion \
+# -fno-thread-jumps \
+# -foptimize-static-class-initialization \
+# -fno-store-check \
+# -fno-bounds-check \
+# -fmerge-all-constants \
+# -fno-inline-functions \
+# -finline-limit=1 \
cd build/pruned; \
for A in `find . -name \*.class -or -name \*.java`; do \
echo compiling $$A....; \
../../upstream/install/bin/$(target)-gcj \
- -fdata-sections -ffunction-sections -w -c -Os \
- -fCLASSPATH=../../build/$(platform)/ibex.jar $$A && \
+ -w -c -Os \
+ -fCLASSPATH=../../build/$(platform)/ibex.jar \
+ $$A && \
(mkdir -p ../../build/$(platform)/`dirname $$A`; mv *.o ../../build/$(platform)/`dirname $$A`); \
done
+
+# rm -rf build/Linux/java/security build/Linux/gnu/java/security build/Linux/java/util/jar build/Linux/java/io/Object*
+# rm -rf build/pruned/java/security build/pruned/gnu/java/security build/pruned/java/util/jar build/pruned/java/io/Object*
+
rm -f build/$(platform)/ibex.a
+
cd upstream/gcc-3.3/build-$(target)/$(target)/libjava; \
$(shell pwd)/upstream/install/$(target)/bin/ar cq \
$(shell pwd)/build/$(platform)/ibex.a \
- boehm.o defineclass.o exception.o \
- posix-threads.o posix.o prims.o resolve.o \
- `find . -name nat\*.o | grep -v JIS` \
- `find . -name \*.o -not -name '*[A-Z]*'` \
- `find $(shell pwd)/build/$(platform) -name \*.o`
- PATH=upstream/install/bin:$$PATH upstream/install/bin/$(target)-gcj \
- --main=org.ibex.plat.$(platform) \
- -Lupstream/install/$(target)/lib \
- -Lupstream/install/lib \
- -ffunction-sections -fdata-sections -Os -w -fCLASSPATH=build/$(platform)/ibex.jar \
- build/$(platform)/ibex.a \
- upstream/jpeg-6b/build-$(target)/libjpeg.a \
- $(link_flags) \
+ `find $(shell pwd)/build/$(platform) -name \*.o` \
+ `cat $(shell pwd)/.natbins`
+# --relax,-O2,--no-whole-archive,
+ PATH=upstream/install/bin:$$PATH upstream/install/bin/$(target)-gcj \
+ -Wl,--no-gc-sections,--noinhibit-exec,-rpath,upstream/install/$(target)/lib \
+ -Wl,-nostdlib,--eh-frame-hdr,-m,elf_i386,-dynamic-linker,/lib/ld-linux.so.2 \
+ --main=org.ibex.plat.$(platform) \
+ -Lupstream/install/$(target)/lib \
+ -Lupstream/install/lib \
+ -Os -w \
+ build/$(platform)/ibex.a \
+ upstream/jpeg-6b/build-$(target)/libjpeg.a \
+ $(link_flags) \
upstream/gcc-3.3/build-$(target)/$(target)/boehm-gc/.libs/libgcjgc.a \
- -lz -ldl -lffi \
- -Wl,--noinhibit-exec,--gc-sections \
+ -lz -ldl -lgcc -lm -lpthread -ldl -lgcc -lc -lgcc \
+ upstream/install/bin/../lib/gcc-lib/i686-pc-linux-gnu/3.3/crtend.o \
+ upstream/install/bin/../lib/gcc-lib/i686-pc-linux-gnu/3.3/../../../../i686-pc-linux-gnu/lib/crtn.o \
-o $@
-
-# linker
-# --no-whole-archive,--relax,-O,2
-#
-# -fomit-frame-pointer \
-# -fno-force-mem \
-# -fno-force-addr \
-# -fno-inline-functions \
-# -fnew-ra \
-# -fbranch-probabilities \
-# -finline-limit=1 \
-# -fno-schedule-insns \
-# -fno-optimize-sibling-calls \
-# -fno-if-conversion \
-# -fno-thread-jumps \
-# -fno-hosted \
+# strip build/Linux/ibex.linux
+# ls -l build/Linux/ibex.linux
+# upx-ucl-beta --best build/Linux/ibex.linux
+# ls -l build/Linux/ibex.linux
### Builtin Resources ##############################################################################
cd build/res/fonts/vera; ln -fs ../../../../upstream/vera-1.10/ttf-bitstream-vera-1.10/VeraSe.ttf
build/res/builtin.jar: $(builtin_src:src/%=build/res/%) build/res/fonts/vera
@echo -e "\n\033[1mzipping res/* -> .jar: builtin.jar\033[0m"
- cd build/res; $(jar) cf builtin.jar $(^:build/res/%=%)
+ cd build/res; $(jar) cf builtin.jar org/ibex/builtin/scar.png
+# cd build/res; $(jar) cf builtin.jar $(^:build/res/%=%)
build/$(platform)/builtin.o: build/res/builtin.jar
@echo -e "\n\033[1mwrapping .jar -> .o: resources.o\033[0m"
@(echo "unsigned int builtin_length = "; \
// - if a method is reachable, all the methods it overrides are reachable
+// try eliminating instance methods/fields if no ctor is reachable...
+// distinguish between overloaded forms of a given method
+// slim down the set of loadAllMethod() classes
+// field pruning?
+
// FIXME: nonstatic method invocation or field access implies that object will be constructed (ie hint)
public class BytecodePruner {
+ public static final boolean deleteMethods = false;
+
// FIXME
public static SyntheticRepository repo = null;
public void loadAllMethods(String classname) throws Exception {
visitJavaClass(repo.loadClass(classname));
- Method[] meths = repo.loadClass(classname).getMethods();
+ Method[] meths = getMethods(repo.loadClass(classname));
for(int i=0; i<meths.length; i++) visitJavaMethod(repo.loadClass(classname), meths[i]);
}
public void loadMethod(String classAndMethodName) throws Exception {
String classname = classAndMethodName.substring(0, classAndMethodName.lastIndexOf('.'));
String methodname = classAndMethodName.substring(classAndMethodName.lastIndexOf('.') + 1);
visitJavaClass(repo.loadClass(classname));
- Method[] meths = repo.loadClass(classname).getMethods();
+ Method[] meths = getMethods(repo.loadClass(classname));
for(int i=0; i<meths.length; i++)
if (meths[i].getName().equals(methodname))
visitJavaMethod(repo.loadClass(classname), meths[i]);
} else {
JavaClass cl = repo.loadClass(s[i].substring(0, s[i].lastIndexOf('.')));;
bcp.visitJavaClass(cl);
- Method[] meths = cl.getMethods();
+ Method[] meths = getMethods(cl);
for(int j=0; j<meths.length; j++) {
if (meths[j].getName().equals(s[i].substring(s[i].lastIndexOf('.') + 1)))
bcp.visitJavaMethod(cl, meths[j]);
// we call start(), but the VM calls run()...
bcp.loadMethod("java.lang.Thread.run");
+ bcp.loadMethod("java.util.IdentityHashMap.put");
+ bcp.loadAllMethods("java.lang.SecurityContext");
+ bcp.visitJavaClass(repo.loadClass("java.awt.AWTPermission"));
bcp.loadAllMethods("java.lang.Throwable");
bcp.loadAllMethods("java.io.PrintStream");
+ bcp.loadAllMethods("java.util.PropertyPermission");
+ bcp.loadAllMethods("java.lang.ThreadDeath");
bcp.loadAllMethods("gnu.gcj.runtime.StringBuffer");
bcp.loadAllMethods("java.security.cert.Certificate");
+ bcp.loadAllMethods("java.security.cert.CertificateEncodingException");
bcp.loadMethod("java.util.SimpleTimeZone.useDaylightTime");
bcp.loadMethod("java.util.TimeZone.getAvailableIDs");
bcp.loadMethod("java.util.TimeZone.getDefaultTimeZoneId");
bcp.loadMethod("java.util.Collections$SynchronizedIterator.hasNext");
- bcp.loadMethod("java.util.Hashtable$HashIterator.hasNext");
+ bcp.loadAllMethods("java.util.Hashtable$HashIterator");
+ bcp.loadAllMethods("gnu.gcj.runtime.VMClassLoader");
bcp.visitJavaClass(repo.loadClass("java.util.Stack"));
bcp.visitJavaClass(repo.loadClass("gnu.classpath.Configuration"));
// often called from native subclasses....
bcp.loadAllMethods("org.ibex.Surface");
+ bcp.loadAllMethods("org.ibex.Template$TemplateHelper$1");
+ bcp.loadAllMethods("org.ibex.Surface$DoubleBufferedSurface");
+ bcp.loadAllMethods("org.ibex.Surface$3");
+ bcp.loadAllMethods("org.ibex.Surface$2");
bcp.loadAllMethods("org.ibex.Picture");
bcp.loadAllMethods("org.ibex.PixelBuffer");
bcp.loadAllMethods("org.ibex.Platform");
bcp.loadAllMethods("java.text.NumberFormat");
- Method[] meths = repo.loadClass("org.ibex.plat.Linux").getMethods();
+ Method[] meths = getMethods(repo.loadClass("org.ibex.plat.Linux"));
for(int i=0; i<meths.length; i++) {
if (meths[i].getName().equals("main"))
bcp.visitJavaMethod(repo.loadClass("org.ibex.plat.Linux"), meths[i]);
public static void dump(JavaClass clazz) throws Exception {
if (clazz.getClassName().startsWith("java.sql.")) return;
+ if (!dest.contains(clazz)) return;
ConstantPoolGen newcpg = new ConstantPoolGen(clazz.getConstantPool());
ClassGen cg = new ClassGen(clazz);
// superprune: URLClassLoader, convert.In/Output other than needed, unneeded locales
// reflective metadata is killing us...
- Method[] methods = clazz.getMethods();
+ Method[] methods = getMethods(clazz);
int numMethods = 0;
boolean good = false;
for(int i=0; i<methods.length; i++)
- if (clazz.getClassName().startsWith("gnu.")
- || clazz.getClassName().startsWith("java.lang.")
- || clazz.getClassName().startsWith("java.io.")
- || clazz.getClassName().startsWith("org.ibex.")) {
+ if (clazz.getClassName().startsWith("gnu.gcj.runtime.")
+ || clazz.getClassName().startsWith("java.io.FileDescriptor")
+ || clazz.getClassName().startsWith("org.ibex.")
+ || clazz.getClassName().startsWith("java.lang.")) {
good = true;
} else if (dest.contains(methods[i])) {
if (!methods[i].getName().equals("<clinit>")) good = true;
} else {
- if (methods[i].getCode() != null) {
+ if (methods[i].getCode() == null) {
+ System.out.println(" empty codeblock: " + clazz.getClassName() + "." + methods[i].getName());
+ } else {
System.out.println(" pruning " + clazz.getClassName() + "." + methods[i].getName());
- MethodGen mg = new MethodGen(methods[i], clazz.getClassName(), newcpg);
- mg.removeExceptions();
- InstructionList il = new InstructionList();
- mg.setInstructionList(il);
-
- InstructionHandle ih_0 = il.append(factory.createNew("java.lang.UnsatisfiedLinkError"));
- il.append(InstructionConstants.DUP);
- il.append(factory.createInvoke("java.lang.UnsatisfiedLinkError",
- "<init>", 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();
+ if (!deleteMethods) {
+ MethodGen mg = new MethodGen(methods[i], clazz.getClassName(), newcpg);
+ mg.removeExceptions();
+ InstructionList il = new InstructionList();
+ mg.setInstructionList(il);
+
+ InstructionHandle ih_0 = il.append(factory.createNew("java.lang.UnsatisfiedLinkError"));
+ il.append(InstructionConstants.DUP);
+ il.append(factory.createInvoke("java.lang.UnsatisfiedLinkError",
+ "<init>", 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();
+ } else {
+ cg.removeMethod(methods[i]);
+ }
}
}
if ((clazz.getClassName().startsWith("gnu.java.locale.LocaleInformation") &&
!clazz.getClassName().endsWith("LocaleInformation") &&
!clazz.getClassName().endsWith("LocaleInformation_en_US"))
||
+ ((clazz.getClassName().startsWith("gnu.gcj.convert.Input_") ||
+ clazz.getClassName().startsWith("gnu.gcj.convert.Output_")) &&
+ !(clazz.getClassName().endsWith("ASCII") ||
+ clazz.getClassName().endsWith("UTF8") ||
+ clazz.getClassName().endsWith("iconv") ||
+ clazz.getClassName().endsWith("8859_1")))
+ ||
(!good &&
!clazz.isInterface() &&
!clazz.isAbstract() &&
+ !clazz.getClassName().startsWith("java.io.") &&
+ !clazz.getClassName().startsWith("java.lang.") &&
+ !clazz.getClassName().startsWith("gnu.") &&
!clazz.getClassName().endsWith("Error") &&
!clazz.getClassName().endsWith("Exception") &&
!clazz.getClassName().endsWith("Permission"))) {
- System.out.println("DROPPING " + clazz.getClassName());
- return;
+ //System.out.println("DROPPING " + clazz.getClassName());
+ //return;
}
new File(outdir + "/" + new File(clazz.getClassName().replace('.', '/')).getParent()).mkdirs();
System.out.println("dumping " + clazz.getClassName());
// hashtable of hashsets
public static Hashtable subclasses = new Hashtable();
- public String getMethodSignature(Method m) throws Exception {
- ConstantPoolGen cpg = new ConstantPoolGen(m.getConstantPool());
+ public String getMethodSignature(Method m, ConstantPoolGen cpg) throws Exception {
return m.getName() + m.getSignature();
}
for(int j=0; j<argtypes.length; j++) sig += argtypes[j].getSignature();
return ii.getMethodName(cpg) + "(" + sig + ")" + ii.getReturnType(cpg).getSignature();
}
+
public static int level = 0;
public void visitJavaMethod(JavaClass jc, Method method) throws Exception {
visitJavaClass(jc);
+ if (jc.getClassName().equals("java.util.Date") && method.getName().equals("readObject")) return;
+ //if (jc.getClassName().equals("java.net.URLClassLoader")) return;
+ if (jc.getClassName().indexOf("SharedLib") != -1) return;
+ if (jc.getClassName().indexOf("Datagram") != -1) return;
if (dest.contains(method)) return;
dest.add(method);
level += 2;
for(int i=0; i<level; i++) System.out.print(" ");
- System.out.println(jc.getClassName() + "." + getMethodSignature(method));
- markMethodInSubclasses(jc, method);
ConstantPoolGen cpg = new ConstantPoolGen(method.getConstantPool());
+ System.out.println(jc.getClassName() + "." + getMethodSignature(method, cpg));
+ markMethodInSubclasses(jc, method, cpg);
if (method.getCode() == null) { level -= 2; return; }
byte[] code = method.getCode().getCode();
InstructionList il = new InstructionList(code);
JavaClass c = sig2class(ii.getLoadClassType(cpg).getSignature());
load(ii.getReturnType(cpg));
load(ii.getType(cpg));
- Method[] meths = c.getMethods();
+ Method[] meths = getMethods(c);
boolean good = false;
for(int i2=0; i2<meths.length; i2++) {
- if (getMethodSignature(meths[i2]).equals(ii_sig)) {
+ if (getMethodSignature(meths[i2], cpg).equals(ii_sig)) {
visitJavaMethod(c, meths[i2]);
good = true;
break;
}
- }
- if (!good)
- throw new Exception("couldn't find method " + getMethodSignature(ii, cpg) + " in " + c.getClassName());
+ }
+ if (!good) throw new Exception("couldn't find method " + getMethodSignature(ii, cpg) + " in " + c.getClassName());
}
}
level -= 2;
}
public void visitJavaClass(JavaClass clazz) throws Exception {
-
+ /*
+ if (clazz.getClassName().startsWith("java.security.") &&
+ !clazz.getClassName().equals("java.security.cert.Certificate")) return;
+ */
if (dest.contains(clazz)) return;
dest.add(clazz);
+ ConstantPoolGen cpg = new ConstantPoolGen(clazz.getConstantPool());
String name = clazz.getClassName();
+ System.out.println(clazz.getClassName() + ".class");
JavaClass superclass = clazz.getSuperClass();
-
JavaClass[] interfaces = clazz.getAllInterfaces();
+ for(JavaClass sup = superclass; sup != null; sup = sup.getSuperClass()) {
+ if (subclasses.get(sup) == null) subclasses.put(sup, new HashSet());
+ ((HashSet)subclasses.get(sup)).add(clazz);
+ }
+ for(int i=0; i<interfaces.length; i++) {
+ if (subclasses.get(interfaces[i]) == null) subclasses.put(interfaces[i], new HashSet());
+ ((HashSet)subclasses.get(interfaces[i])).add(clazz);
+ }
+
+ for(JavaClass sup = superclass; sup != null; sup = sup.getSuperClass()) {
+ visitJavaClass(sup);
+ remarkMethods(sup, clazz, cpg);
+ }
+ for(int i=0; i<interfaces.length; i++) {
+ visitJavaClass(interfaces[i]);
+ remarkMethods(interfaces[i], clazz, cpg);
+ }
+
Field[] fields = clazz.getFields();
- Method[] methods = clazz.getMethods();
- System.out.println(clazz.getClassName() + ".class");
- for(int i=0; i<methods.length; i++)
- if (methods[i].getName().equals("<clinit>")) visitJavaMethod(clazz, methods[i]);
+ Method[] methods = getMethods(clazz);
+ for(int i=0; i<fields.length; i++) visitJavaField(fields[i]);
for(int i=0; i<methods.length; i++) {
+ if (methods[i].getName().equals("<clinit>")) visitJavaMethod(clazz, methods[i]);
+
+ // only if ctor reachable (?)
if (methods[i].getName().equals("equals")) visitJavaMethod(clazz, methods[i]);
if (methods[i].getName().equals("hashCode")) visitJavaMethod(clazz, methods[i]);
if (methods[i].getName().equals("finalize")) visitJavaMethod(clazz, methods[i]);
if (methods[i].getName().equals("clone")) visitJavaMethod(clazz, methods[i]);
if (methods[i].getName().equals("toString")) visitJavaMethod(clazz, methods[i]);
}
- for(int i=0; i<fields.length; i++) visitJavaField(fields[i]);
- if (superclass != null) {
- for(JavaClass sup = superclass; sup != null; sup = sup.getSuperClass()) {
- if (subclasses.get(sup) == null) subclasses.put(sup, new HashSet());
- ((HashSet)subclasses.get(sup)).add(clazz);
- visitJavaClass(sup);
- remarkMethods(sup, clazz);
- }
- }
- for(int i=0; i<interfaces.length; i++) {
- if (subclasses.get(interfaces[i]) == null) subclasses.put(interfaces[i], new HashSet());
- ((HashSet)subclasses.get(interfaces[i])).add(clazz);
- visitJavaClass(interfaces[i]);
- remarkMethods(interfaces[i], clazz);
- }
}
- public void markMethodInSubclasses(JavaClass c, Method m, JavaClass subclass) throws Exception {
+ public void markMethodInSubclasses(JavaClass c, Method m, JavaClass subclass, ConstantPoolGen cpg) throws Exception {
if (m.isStatic()) return;
- String sig = getMethodSignature(m);
- Method[] submethods = subclass.getMethods();
+ String sig = getMethodSignature(m, cpg);
+ Method[] submethods = getMethods(subclass);
for(int j=0; j<submethods.length; j++)
- if (getMethodSignature(submethods[j]).equals(sig))
+ if (getMethodSignature(submethods[j], cpg).equals(sig))
visitJavaMethod(subclass, submethods[j]);
}
- public void markMethodInSubclasses(JavaClass c, Method m) throws Exception {
+ public void markMethodInSubclasses(JavaClass c, Method m, ConstantPoolGen cpg) throws Exception {
if (m.isStatic()) return;
HashSet s = (HashSet)subclasses.get(c);
if (s == null) return;
Object[] subclasses = s.toArray();
for(int i=0; i<subclasses.length; i++) {
JavaClass subclass = (JavaClass)subclasses[i];
+ for(int j=0; j<level; j++) System.out.print(" ");
+ System.out.println(" [subclass " + subclass.getClassName() + "]");
if (subclass == c) return;
- markMethodInSubclasses(c, m, subclass);
+ markMethodInSubclasses(c, m, subclass, cpg);
}
}
- public void remarkMethods(JavaClass c) throws Exception {
- Method[] meths = c.getMethods();
- for(int j=0; j<meths.length; j++) if (dest.contains(meths[j])) markMethodInSubclasses(c, meths[j]);
+ public void remarkMethods(JavaClass c, ConstantPoolGen cpg) throws Exception {
+ Method[] meths =getMethods(c);
+ for(int j=0; j<meths.length; j++) if (dest.contains(meths[j])) markMethodInSubclasses(c, meths[j], cpg);
+ }
+
+ public void remarkMethods(JavaClass c, JavaClass target, ConstantPoolGen cpg) throws Exception {
+ Method[] meths = getMethods(c);
+ for(int j=0; j<meths.length; j++) if (dest.contains(meths[j])) markMethodInSubclasses(c, meths[j], target, cpg);
}
- public void remarkMethods(JavaClass c, JavaClass target) throws Exception {
- Method[] meths = c.getMethods();
- for(int j=0; j<meths.length; j++) if (dest.contains(meths[j])) markMethodInSubclasses(c, meths[j], target);
+ public static Hashtable methodsHashtable = new Hashtable();
+ public static Method[] getMethods(JavaClass c) {
+ Method[] ret = (Method[])methodsHashtable.get(c);
+ if (ret == null) methodsHashtable.put(c, ret = c.getMethods());
+ return ret;
}
}