Suggestion for optimized compilation of Anonymous inner classes [message #88512] |
Sat, 23 August 2003 07:46  |
Eclipse User |
|
|
|
Hello,
As Outlined in the section "Application footprint" of
http://java.sun.com/docs/white/delegates.html
a optimzed class format may reduce the size of the JAR-archive.
Usually the class of AL (see below) is compiled to a classfile
Class$1 (for example):
class Class {
ActionListener AL = new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
}
}
My suggestion is to achieve the "optimzed class format" with an compiler switch,
which compiles the class above as (pseudo code):
class Class {
ActionListener AL = (ActionListener)syntheticMethod$0("....CompressedClassFile.... ");
ActionListener syntheticMethod$0(final String sCompressedClassFile) {
try {
final byte[] byClassFile = uncompressClassFile(sCompressedClassFile)
return (ActionListener)getClass().getClassLoader().defineClass(byCl assFile).newInstance();
} catch(Exception e) {
throw new ClassNotFoundException(e);
}
}
byte[] uncompressClassFile$0(String sClassfile) {
// Short uncompression algorithm
}
}
or in words:
The compiler generates a compressed class file for an (not nessesary) anoymoues inner class,
and exactly one decompression method (identical in each toplevel class); and finally it replaces
the new-statement with a call to an decompression method.
Possible Problems:
[1] Keep Obfucuraters working
[2] Don't use more space then without the compiler switch
[3] Constant Pool Access for the decompression method
I think all this problems are solveable, and in most cases the compiled classes are
much smaller and class loading of inner classes may become much faster.
If such a technic exists allready: please let me know where I can read about it.
Kind Regards
mle
|
|
|
|
Powered by
FUDForum. Page generated in 0.03887 seconds