author | duke |
Wed, 05 Jul 2017 20:46:50 +0200 | |
changeset 32264 | 58af228a68fa |
parent 30846 | 2b3f379840f0 |
permissions | -rw-r--r-- |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
1 |
/* |
15385 | 2 |
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
4 |
* |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
10 |
* |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
15 |
* accompanied this code). |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
16 |
* |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
20 |
* |
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
24 |
*/ |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
25 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
26 |
package com.sun.tools.javap; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
27 |
|
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
28 |
import java.util.ArrayList; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
29 |
import java.util.List; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
30 |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
31 |
import com.sun.tools.classfile.AccessFlags; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
32 |
import com.sun.tools.classfile.Code_attribute; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
33 |
import com.sun.tools.classfile.ConstantPool; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
34 |
import com.sun.tools.classfile.ConstantPoolException; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
35 |
import com.sun.tools.classfile.DescriptorException; |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
36 |
import com.sun.tools.classfile.Instruction; |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
37 |
import com.sun.tools.classfile.Instruction.TypeKind; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
38 |
import com.sun.tools.classfile.Method; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
39 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
40 |
/* |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
41 |
* Write the contents of a Code attribute. |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
42 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
43 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
44 |
* If you write code that depends on this, you do so at your own risk. |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
45 |
* This code and its internal interfaces are subject to change or |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
46 |
* deletion without notice.</b> |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
47 |
*/ |
14056 | 48 |
public class CodeWriter extends BasicWriter { |
49 |
public static CodeWriter instance(Context context) { |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
50 |
CodeWriter instance = context.get(CodeWriter.class); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
51 |
if (instance == null) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
52 |
instance = new CodeWriter(context); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
53 |
return instance; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
54 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
55 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
56 |
protected CodeWriter(Context context) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
57 |
super(context); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
58 |
context.put(CodeWriter.class, this); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
59 |
attrWriter = AttributeWriter.instance(context); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
60 |
classWriter = ClassWriter.instance(context); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
61 |
constantWriter = ConstantWriter.instance(context); |
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
62 |
sourceWriter = SourceWriter.instance(context); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
63 |
tryBlockWriter = TryBlockWriter.instance(context); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
64 |
stackMapWriter = StackMapWriter.instance(context); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
65 |
localVariableTableWriter = LocalVariableTableWriter.instance(context); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
66 |
localVariableTypeTableWriter = LocalVariableTypeTableWriter.instance(context); |
15385 | 67 |
typeAnnotationWriter = TypeAnnotationWriter.instance(context); |
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
68 |
options = Options.instance(context); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
69 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
70 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
71 |
void write(Code_attribute attr, ConstantPool constant_pool) { |
3546 | 72 |
println("Code:"); |
73 |
indent(+1); |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
74 |
writeVerboseHeader(attr, constant_pool); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
75 |
writeInstrs(attr); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
76 |
writeExceptionTable(attr); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
77 |
attrWriter.write(attr, attr.attributes, constant_pool); |
3546 | 78 |
indent(-1); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
79 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
80 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
81 |
public void writeVerboseHeader(Code_attribute attr, ConstantPool constant_pool) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
82 |
Method method = classWriter.getMethod(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
83 |
String argCount; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
84 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
85 |
int n = method.descriptor.getParameterCount(constant_pool); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
86 |
if (!method.access_flags.is(AccessFlags.ACC_STATIC)) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
87 |
++n; // for 'this' |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
88 |
argCount = Integer.toString(n); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
89 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
90 |
argCount = report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
91 |
} catch (DescriptorException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
92 |
argCount = report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
93 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
94 |
|
3546 | 95 |
println("stack=" + attr.max_stack + |
96 |
", locals=" + attr.max_locals + |
|
97 |
", args_size=" + argCount); |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
98 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
99 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
100 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
101 |
public void writeInstrs(Code_attribute attr) { |
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
102 |
List<InstructionDetailWriter> detailWriters = getDetailWriters(attr); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
103 |
|
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
104 |
for (Instruction instr: attr.getInstructions()) { |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
105 |
try { |
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
106 |
for (InstructionDetailWriter w: detailWriters) |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
107 |
w.writeDetails(instr); |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
108 |
writeInstr(instr); |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
109 |
} catch (ArrayIndexOutOfBoundsException e) { |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
110 |
println(report("error at or after byte " + instr.getPC())); |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
111 |
break; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
112 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
113 |
} |
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
114 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
115 |
for (InstructionDetailWriter w: detailWriters) |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
116 |
w.flush(); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
117 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
118 |
|
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
119 |
public void writeInstr(Instruction instr) { |
3553
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
3552
diff
changeset
|
120 |
print(String.format("%4d: %-13s ", instr.getPC(), instr.getMnemonic())); |
4411
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
121 |
// compute the number of indentations for the body of multi-line instructions |
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
122 |
// This is 6 (the width of "%4d: "), divided by the width of each indentation level, |
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
123 |
// and rounded up to the next integer. |
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
124 |
int indentWidth = options.indentWidth; |
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
125 |
int indent = (6 + indentWidth - 1) / indentWidth; |
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
126 |
instr.accept(instructionPrinter, indent); |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
127 |
println(); |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
128 |
} |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
129 |
// where |
4411
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
130 |
Instruction.KindVisitor<Void,Integer> instructionPrinter = |
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
131 |
new Instruction.KindVisitor<Void,Integer>() { |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
132 |
|
4411
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
133 |
public Void visitNoOperands(Instruction instr, Integer indent) { |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
134 |
return null; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
135 |
} |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
136 |
|
4411
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
137 |
public Void visitArrayType(Instruction instr, TypeKind kind, Integer indent) { |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
138 |
print(" " + kind.name); |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
139 |
return null; |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
140 |
} |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
141 |
|
4411
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
142 |
public Void visitBranch(Instruction instr, int offset, Integer indent) { |
3546 | 143 |
print((instr.getPC() + offset)); |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
144 |
return null; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
145 |
} |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
146 |
|
4411
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
147 |
public Void visitConstantPoolRef(Instruction instr, int index, Integer indent) { |
3552
a4b8b89bdc9c
6868548: remove spurious ';' from after constant pool entries
jjg
parents:
3546
diff
changeset
|
148 |
print("#" + index); |
3546 | 149 |
tab(); |
150 |
print("// "); |
|
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
151 |
printConstant(index); |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
152 |
return null; |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
153 |
} |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
154 |
|
4411
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
155 |
public Void visitConstantPoolRefAndValue(Instruction instr, int index, int value, Integer indent) { |
3552
a4b8b89bdc9c
6868548: remove spurious ';' from after constant pool entries
jjg
parents:
3546
diff
changeset
|
156 |
print("#" + index + ", " + value); |
3546 | 157 |
tab(); |
158 |
print("// "); |
|
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
159 |
printConstant(index); |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
160 |
return null; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
161 |
} |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
162 |
|
4411
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
163 |
public Void visitLocal(Instruction instr, int index, Integer indent) { |
3546 | 164 |
print(index); |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
165 |
return null; |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
166 |
} |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
167 |
|
4411
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
168 |
public Void visitLocalAndValue(Instruction instr, int index, int value, Integer indent) { |
3546 | 169 |
print(index + ", " + value); |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
170 |
return null; |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
171 |
} |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
172 |
|
4411
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
173 |
public Void visitLookupSwitch(Instruction instr, |
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
174 |
int default_, int npairs, int[] matches, int[] offsets, Integer indent) { |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
175 |
int pc = instr.getPC(); |
3546 | 176 |
print("{ // " + npairs); |
4411
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
177 |
indent(indent); |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
178 |
for (int i = 0; i < npairs; i++) { |
4411
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
179 |
print(String.format("%n%12d: %d", matches[i], (pc + offsets[i]))); |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
180 |
} |
4411
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
181 |
print("\n default: " + (pc + default_) + "\n}"); |
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
182 |
indent(-indent); |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
183 |
return null; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
184 |
} |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
185 |
|
4411
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
186 |
public Void visitTableSwitch(Instruction instr, |
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
187 |
int default_, int low, int high, int[] offsets, Integer indent) { |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
188 |
int pc = instr.getPC(); |
4411
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
189 |
print("{ // " + low + " to " + high); |
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
190 |
indent(indent); |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
191 |
for (int i = 0; i < offsets.length; i++) { |
4411
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
192 |
print(String.format("%n%12d: %d", (low + i), (pc + offsets[i]))); |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
193 |
} |
4411
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
194 |
print("\n default: " + (pc + default_) + "\n}"); |
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
195 |
indent(-indent); |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
196 |
return null; |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
197 |
} |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
198 |
|
4411
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
199 |
public Void visitValue(Instruction instr, int value, Integer indent) { |
3546 | 200 |
print(value); |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
201 |
return null; |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
202 |
} |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
203 |
|
4411
84c397e2ee67
6902264: fix indentation of tableswitch and lookupswitch
jjg
parents:
3553
diff
changeset
|
204 |
public Void visitUnknown(Instruction instr, Integer indent) { |
2512
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
205 |
return null; |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
206 |
} |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
207 |
}; |
70eb5f17c5f8
6819246: improve support for decoding instructions in classfile library
jjg
parents:
735
diff
changeset
|
208 |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
209 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
210 |
public void writeExceptionTable(Code_attribute attr) { |
20236
32da2c913ac4
8024127: javac, Code_attribute.exception_table_langth should be Code_attribute.exception_table_length
alundblad
parents:
15385
diff
changeset
|
211 |
if (attr.exception_table_length > 0) { |
3546 | 212 |
println("Exception table:"); |
213 |
indent(+1); |
|
214 |
println(" from to target type"); |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
215 |
for (int i = 0; i < attr.exception_table.length; i++) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
216 |
Code_attribute.Exception_data handler = attr.exception_table[i]; |
3546 | 217 |
print(String.format(" %5d %5d %5d", |
218 |
handler.start_pc, handler.end_pc, handler.handler_pc)); |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
219 |
print(" "); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
220 |
int catch_type = handler.catch_type; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
221 |
if (catch_type == 0) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
222 |
println("any"); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
223 |
} else { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
224 |
print("Class "); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
225 |
println(constantWriter.stringValue(catch_type)); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
226 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
227 |
} |
3546 | 228 |
indent(-1); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
229 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
230 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
231 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
232 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
233 |
private void printConstant(int index) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
234 |
constantWriter.write(index); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
235 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
236 |
|
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
237 |
private List<InstructionDetailWriter> getDetailWriters(Code_attribute attr) { |
22163 | 238 |
List<InstructionDetailWriter> detailWriters = new ArrayList<>(); |
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
239 |
if (options.details.contains(InstructionDetailWriter.Kind.SOURCE)) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
240 |
sourceWriter.reset(classWriter.getClassFile(), attr); |
6578
964b4d71d26f
6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
5847
diff
changeset
|
241 |
if (sourceWriter.hasSource()) |
964b4d71d26f
6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
5847
diff
changeset
|
242 |
detailWriters.add(sourceWriter); |
964b4d71d26f
6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
5847
diff
changeset
|
243 |
else |
964b4d71d26f
6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
5847
diff
changeset
|
244 |
println("(Source code not available)"); |
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
245 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
246 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
247 |
if (options.details.contains(InstructionDetailWriter.Kind.LOCAL_VARS)) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
248 |
localVariableTableWriter.reset(attr); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
249 |
detailWriters.add(localVariableTableWriter); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
250 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
251 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
252 |
if (options.details.contains(InstructionDetailWriter.Kind.LOCAL_VAR_TYPES)) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
253 |
localVariableTypeTableWriter.reset(attr); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
254 |
detailWriters.add(localVariableTypeTableWriter); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
255 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
256 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
257 |
if (options.details.contains(InstructionDetailWriter.Kind.STACKMAPS)) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
258 |
stackMapWriter.reset(attr); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
259 |
stackMapWriter.writeInitialDetails(); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
260 |
detailWriters.add(stackMapWriter); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
261 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
262 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
263 |
if (options.details.contains(InstructionDetailWriter.Kind.TRY_BLOCKS)) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
264 |
tryBlockWriter.reset(attr); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
265 |
detailWriters.add(tryBlockWriter); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
266 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
267 |
|
15385 | 268 |
if (options.details.contains(InstructionDetailWriter.Kind.TYPE_ANNOS)) { |
269 |
typeAnnotationWriter.reset(attr); |
|
270 |
detailWriters.add(typeAnnotationWriter); |
|
271 |
} |
|
272 |
||
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
273 |
return detailWriters; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
274 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
275 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
276 |
private AttributeWriter attrWriter; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
277 |
private ClassWriter classWriter; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
278 |
private ConstantWriter constantWriter; |
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
279 |
private LocalVariableTableWriter localVariableTableWriter; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
280 |
private LocalVariableTypeTableWriter localVariableTypeTableWriter; |
15385 | 281 |
private TypeAnnotationWriter typeAnnotationWriter; |
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
282 |
private SourceWriter sourceWriter; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
283 |
private StackMapWriter stackMapWriter; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
284 |
private TryBlockWriter tryBlockWriter; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
2512
diff
changeset
|
285 |
private Options options; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
286 |
} |