1
2
3
4 package joeq.Main;
5
6 import java.util.Arrays;
7 import java.util.Iterator;
8 import java.io.PrintStream;
9 import joeq.Class.PrimordialClassLoader;
10 import joeq.Class.jq_Class;
11 import joeq.Class.jq_InstanceField;
12 import joeq.Class.jq_InstanceMethod;
13 import joeq.Class.jq_StaticField;
14 import joeq.Class.jq_StaticMethod;
15 import joeq.Class.jq_Type;
16 import joeq.UTF.Utf8;
17
18 /***
19 * @author John Whaley <jwhaley@alum.mit.edu>
20 * @version $Id: ClassDump.java 1931 2004-09-22 22:17:47Z joewhaley $
21 */
22 public abstract class ClassDump {
23
24 public static void main(String[] args) {
25 HostedVM.initialize();
26
27 String classname;
28 if (args.length > 0) classname = args[0];
29 else classname = "Ljoeq/Main/jq;";
30
31 jq_Class c = (jq_Class)PrimordialClassLoader.loader.getOrCreateBSType(classname);
32 System.out.println("Loading "+c+"...");
33 c.load();
34 System.out.println("Verifying "+c+"...");
35 c.verify();
36 System.out.println("Preparing "+c+"...");
37 c.prepare();
38 System.out.println("Initializing static fields of "+c+"...");
39 c.sf_initialize();
40
41
42 dumpClass(System.out, c);
43
44
45
46
47
48 compileClass(System.out, c);
49 }
50
51 public static void compileClass(PrintStream out, jq_Class t) {
52 Iterator it;
53 for(it = Arrays.asList(t.getDeclaredStaticMethods()).iterator();
54 it.hasNext(); ) {
55 jq_StaticMethod c = (jq_StaticMethod)it.next();
56 if (c.getBytecode() == null) continue;
57
58 {
59 out.println(c.toString());
60 joeq.Compiler.Quad.ControlFlowGraph cfg = joeq.Compiler.Quad.CodeCache.getCode(c);
61 System.out.println(cfg.fullDump());
62 }
63 }
64 for(it = Arrays.asList(t.getDeclaredInstanceMethods()).iterator();
65 it.hasNext(); ) {
66 jq_InstanceMethod c = (jq_InstanceMethod)it.next();
67 if (c.isAbstract()) continue;
68 if (c.getBytecode() == null) continue;
69
70 {
71 out.println(c.toString());
72 joeq.Compiler.Quad.ControlFlowGraph cfg = joeq.Compiler.Quad.CodeCache.getCode(c);
73 System.out.println(cfg.fullDump());
74 }
75 }
76 }
77
78 public static void dumpType(PrintStream out, jq_Type t) {
79 if (t.isClassType()) out.print("class ");
80 if (t.isArrayType()) out.print("array ");
81 if (t.isPrimitiveType()) out.print("primitive ");
82 out.print(t.getName());
83 }
84
85 public static void dumpClass(PrintStream out, jq_Class t) {
86 dumpType(out, t);
87 out.println();
88 out.println("state: "+t.getState());
89
90 if (t.isLoaded()) {
91 out.println("java class file version "+(int)t.getMajorVersion()+"."+(int)t.getMinorVersion());
92 out.println("source file name: "+t.getSourceFile());
93 out.print("access flags: ");
94 if (t.isPublic()) out.print("public ");
95 if (t.isFinal()) out.print("final ");
96 if (t.isSpecial()) out.print("special ");
97 if (t.isInterface()) out.print("interface ");
98 if (t.isAbstract()) out.print("abstract ");
99 if (t.isSynthetic()) out.print("synthetic ");
100 if (t.isDeprecated()) out.print("deprecated ");
101 out.println();
102 out.println("superclass: "+t.getSuperclass().getName());
103 Iterator it;
104 out.print("known subclasses: ");
105 for(it = Arrays.asList(t.getSubClasses()).iterator();
106 it.hasNext(); ) {
107 jq_Class c = (jq_Class)it.next();
108 out.print(c.getName()+" ");
109 }
110 out.println();
111 out.print("declared interfaces: ");
112 for(it = Arrays.asList(t.getDeclaredInterfaces()).iterator();
113 it.hasNext(); ) {
114 jq_Class c = (jq_Class)it.next();
115 out.print(c.getName()+" ");
116 }
117 out.println();
118 out.print("declared instance fields: ");
119 for(it = Arrays.asList(t.getDeclaredInstanceFields()).iterator();
120 it.hasNext(); ) {
121 jq_InstanceField c = (jq_InstanceField)it.next();
122 out.print(c.getName()+" ");
123 }
124 out.println();
125 out.print("declared static fields: ");
126 for(it = Arrays.asList(t.getDeclaredStaticFields()).iterator();
127 it.hasNext(); ) {
128 jq_StaticField c = (jq_StaticField)it.next();
129 out.print(c.getName()+" ");
130 }
131 out.println();
132 out.print("declared instance methods: ");
133 for(it = Arrays.asList(t.getDeclaredInstanceMethods()).iterator();
134 it.hasNext(); ) {
135 jq_InstanceMethod c = (jq_InstanceMethod)it.next();
136 out.println(c.getName()+" ");
137 out.println("method attributes:");
138 for(Iterator it2 = c.getAttributes().keySet().iterator();
139 it2.hasNext(); ) {
140 Utf8 key = (Utf8)it2.next();
141 out.print("\t"+key);
142 byte[] val = t.getAttribute(key);
143 out.println(": "+((val!=null)?"(length "+val.length+")\t":"\t")+val);
144 }
145 }
146 out.println();
147 out.print("declared static methods: ");
148 for(it = Arrays.asList(t.getDeclaredStaticMethods()).iterator();
149 it.hasNext(); ) {
150 jq_StaticMethod c = (jq_StaticMethod)it.next();
151 out.println(c.getName()+" ");
152 out.println("method attributes:");
153 for(Iterator it2 = c.getAttributes().keySet().iterator();
154 it2.hasNext(); ) {
155 Utf8 key = (Utf8)it2.next();
156 out.print("\t"+key);
157 byte[] val = t.getAttribute(key);
158 out.println(": "+((val!=null)?"(length "+val.length+")\t":"\t")+val);
159 }
160 }
161 out.println();
162 out.print("class initializer: ");
163 if (t.getClassInitializer() != null) out.println("present");
164 else out.println("absent");
165 out.println("constant pool size: "+t.getCPCount());
166 out.println("attributes:");
167 for(it = t.getAttributes();
168 it.hasNext(); ) {
169 Utf8 key = (Utf8)it.next();
170 byte[] val = t.getAttribute(key);
171 out.println("\t"+key+": (length "+val.length+")\t"+val);
172 }
173 }
174 if (t.isPrepared()) {
175 Iterator it;
176 out.print("interfaces: ");
177 for(it = Arrays.asList(t.getInterfaces()).iterator();
178 it.hasNext(); ) {
179 jq_Class c = (jq_Class)it.next();
180 out.print(c+" ");
181 }
182 out.println();
183 out.print("virtual methods: ");
184 for(it = Arrays.asList(t.getVirtualMethods()).iterator();
185 it.hasNext(); ) {
186 jq_InstanceMethod c = (jq_InstanceMethod)it.next();
187 out.print(c+" ");
188 }
189 out.println();
190 }
191 if (t.isSFInitialized()) {
192 }
193 if (t.isClsInitialized()) {
194 }
195
196 }
197 }