Class Dump Utility
The clsd utility is a very simple program that prints out each byte of the a class file. It runs the structures and it verifies most of the issues but it does not try to interpret the code like javap and some class dump programs. For example, it shows you the constant pool in excruciating detail.
The class is also a nice example to see how classes are parsed, there is actually very little magic in going through a Java class file. Look at the source code, which is included in the JAR.
Usage
The usage is very simple, you can give a number of file names on the command line:
java -jar clsd <class file>+
The tool does not use the class path so you should really specify a command line.
Example
Assume the following class:
package aQute.helloworld; import org.osgi.framework.*; public class HelloWorld implements BundleActivator { public void start(BundleContext context) throws Exception { System.out.println("Hello World"); } public void stop(BundleContext context) throws Exception { System.out.println("Goodbye World"); } }
Compiling this and the running clsd will give you:
magic cafebabe version 46.0 pool size 42 1 tag(7) constant classs 2 2 tag(1) utf8 'aQute/helloworld/HelloWorld' 3 tag(7) constant classs 4 4 tag(1) utf8 'java/lang/Object' 5 tag(7) constant classs 6 6 tag(1) utf8 'org/osgi/framework/BundleActivator' 7 tag(1) utf8 '<init>' 8 tag(1) utf8 '()V' 9 tag(1) utf8 'Code' 10 tag(10) method ref 3/11 11 tag(12) name and type 7/8 12 tag(1) utf8 'LineNumberTable' 13 tag(1) utf8 'LocalVariableTable' 14 tag(1) utf8 'this' 15 tag(1) utf8 'LaQute/helloworld/HelloWorld;' 16 tag(1) utf8 'start' 17 tag(1) utf8 '(Lorg/osgi/framework/BundleContext;)V' 18 tag(1) utf8 'Exceptions' 19 tag(7) constant classs 20 20 tag(1) utf8 'java/lang/Exception' 21 tag(9) field ref 22/24 22 tag(7) constant classs 23 23 tag(1) utf8 'java/lang/System' 24 tag(12) name and type 25/26 25 tag(1) utf8 'out' 26 tag(1) utf8 'Ljava/io/PrintStream;' 27 tag(8) constant string 28 28 tag(1) utf8 'Hello World' 29 tag(10) method ref 30/32 30 tag(7) constant classs 31 31 tag(1) utf8 'java/io/PrintStream' 32 tag(12) name and type 33/34 33 tag(1) utf8 'println' 34 tag(1) utf8 '(Ljava/lang/String;)V' 35 tag(1) utf8 'context' 36 tag(1) utf8 'Lorg/osgi/framework/BundleContext;' 37 tag(1) utf8 'stop' 38 tag(8) constant string 39 39 tag(1) utf8 'Goodbye World' 40 tag(1) utf8 'SourceFile' 41 tag(1) utf8 'HelloWorld.java' this_class 21 2(#1) super_class 4(#3) interface count 1 interface count interface 6(#1)field count 0 method count 3 method def 1 <init>(#7) ()V(#8) attribute count 1 0: attribute Code(#9) 0: max_stack 1 0: max_locals 1 0: code_length 5 2A B7 00 0A B1 0: exception_table_length 0 0: attribute count 2 0: 0: attribute LineNumberTable(#12) 0: 0: line number table length 1 0: 0: line number table 1: 0/5 0: 1: attribute LocalVariableTable(#13) 0: 1: local variable table length 1 0: 1: 0: 0/5 this(#14) LaQute/helloworld/HelloWorld;(#15) method def 1 start(#16) (Lorg/osgi/framework/BundleContext;)V(#17) attribute count 2 0: attribute Exceptions(#18) 0: number of exceptions 1 0: exceptions 1: java/lang/Exception(#19/c) 1: attribute Code(#9) 1: max_stack 2 1: max_locals 2 1: code_length 9 B2 00 15 12 1B B6 00 1D B1 1: exception_table_length 0 1: attribute count 2 1: 0: attribute LineNumberTable(#12) 1: 0: line number table length 2 1: 0: line number table 2: 0/8 8/9 1: 1: attribute LocalVariableTable(#13) 1: 1: local variable table length 2 1: 1: 0: 0/9 this(#14) LaQute/helloworld/HelloWorld;(#15) 1: 1: 1: 0/9 context(#35) Lorg/osgi/framework/BundleContext;(#36) method def 1 stop(#37) (Lorg/osgi/framework/BundleContext;)V(#17) attribute count 2 0: attribute Exceptions(#18) 0: number of exceptions 1 0: exceptions 1: java/lang/Exception(#19/c) 1: attribute Code(#9) 1: max_stack 2 1: max_locals 2 1: code_length 9 B2 00 15 12 26 B6 00 1D B1 1: exception_table_length 0 1: attribute count 2 1: 0: attribute LineNumberTable(#12) 1: 0: line number table length 2 1: 0: line number table 2: 0/12 8/13 1: 1: attribute LocalVariableTable(#13) 1: 1: local variable table length 2 1: 1: 0: 0/9 this(#14) LaQute/helloworld/HelloWorld;(#15) 1: 1: 1: 0/9 context(#35) Lorg/osgi/framework/BundleContext;(#36) attribute count 1 0: attribute SourceFile(#40) 0: Source file HelloWorld.java(#41)



