diff options
author | michelou <michelou@epfl.ch> | 2010-12-30 23:32:18 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2010-12-30 23:32:18 +0000 |
commit | 096bc81a90b746ea3fa8a5bd8eb9009c08a71082 (patch) | |
tree | 5df06808f3f561311865a70adff6abbb8ca2ec07 /src/intellij | |
parent | c0bfbce726c9cb74154ee9f30166feb97bfd0331 (diff) | |
download | scala-096bc81a90b746ea3fa8a5bd8eb9009c08a71082.tar.gz scala-096bc81a90b746ea3fa8a5bd8eb9009c08a71082.tar.bz2 scala-096bc81a90b746ea3fa8a5bd8eb9009c08a71082.zip |
fixed (and extended) bytecode reader
IMPORTANT NOTE
Modifying code of the FJBG library is a very sensitive task since its
write operations are eg. used by the Scala compiler. This SVN commit
affects (should affect) only the read operations (which did never
work) of the FJBG library.
Changes include:
- fixed several killer bugs in the bytecode reader (see below).
- added missing input stream constructors in several Attribute
classes (eg. JBootstrapInvokeDynamic, JEnclosingMethodAttribute,
JInnerClassesAttribute) together with the corresponding
class registrations in class JAttributeFactory. - added
classes JExceptionsTable, JLocalVariableTableAttribute and
JStackMapTableAttribute (including corresponding factory methods in
class FJBGContext). - overriden method toString in most classes to
support output format similar to javap (see below). - did some code
cleanup (tabs, etc..).
Bug fixes include:
- fixed incorrect stream.readInt() in JSourceFileAttribute
constructor. - fixed missing code.lineNumbers initialization in
JLineNumberTableAttribute constructor. - fixed incorrect code in class
util.ByteArray constructor (stream). - added method setCode in class
JMethod to link them together.
Output of decoded bytecode:
The added toString() methods return javap-like formatted strings for
the decoded data, eg. for the LocalVariableTable attribute you get
the following output: ... LocalVariableTable: Start Length Slot Name
Signature 0 6 0 this LTest$; 0 6 1 args [Ljava/lang/String;
Executing the following Java code will produce decoded bytecode in a
format similar to the command line "javap -p -v -classpath <cpath>
<classes>":
static void printClass(String filePath) throws Exception {
FJBGContext fjbgContext = new FJBGContext(49, 0);
DataInputStream in = new DataInputStream(new FileInputStream(filePath));
JClass jclass = fjbgContext.JClass(in);
System.out.println(jclass);
in.close();
}
Mainly for providing a demonstrator of the FJBG reader we added to
the FJBG library the main class ch.epfl.lamp.fjbg.Main which behaves
similarly to javap, the class file disassembler of the J2SE SDK.
For instance the following commands produce (more or less) the same
output:
~$ scala ch.epfl.lamp.fjbg.Main -classpath classes 'Test javap -p -v$'
~$ -classpath classes 'Test $'
In several cases fjbg.Main will provide more information for access
flags (eg. brigde methods) and class file attributes (eg. enclosing
methods).
TODO
- integration of FJBGContext.JLocalVariableTableAttribute into the JVM
backend of the Scala compiler (cleaner handling of local variables).
- The source code of the FJBG library is currently generated using
the compiler option "-source 1.4"; moving to source release 1.5 would
allow further code improvements like: List --> List<T> (cast removals)
StringBuffer --> StringBuilder (faster implementation) /*@Override*/ -->
@Override
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
Diffstat (limited to 'src/intellij')
0 files changed, 0 insertions, 0 deletions