Mon, 03 Mar 2014 16:08:06 +0400
8032869: remove support for legacy options in javap
Reviewed-by: ksrini
jjg@46 | 1 | /* |
jjg@1521 | 2 | * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. |
jjg@46 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@46 | 4 | * |
jjg@46 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@46 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
jjg@46 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
jjg@46 | 10 | * |
jjg@46 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@46 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@46 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@46 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@46 | 15 | * accompanied this code). |
jjg@46 | 16 | * |
jjg@46 | 17 | * You should have received a copy of the GNU General Public License version |
jjg@46 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@46 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@46 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
jjg@46 | 24 | */ |
jjg@46 | 25 | |
jjg@46 | 26 | package com.sun.tools.javap; |
jjg@46 | 27 | |
jjg@46 | 28 | import java.util.Formatter; |
jjg@46 | 29 | |
jjg@46 | 30 | import com.sun.tools.classfile.AccessFlags; |
jjg@46 | 31 | import com.sun.tools.classfile.AnnotationDefault_attribute; |
jjg@46 | 32 | import com.sun.tools.classfile.Attribute; |
jjg@46 | 33 | import com.sun.tools.classfile.Attributes; |
ksrini@826 | 34 | import com.sun.tools.classfile.BootstrapMethods_attribute; |
jjg@46 | 35 | import com.sun.tools.classfile.CharacterRangeTable_attribute; |
jjg@46 | 36 | import com.sun.tools.classfile.Code_attribute; |
jjg@46 | 37 | import com.sun.tools.classfile.CompilationID_attribute; |
jjg@46 | 38 | import com.sun.tools.classfile.ConstantPool; |
jjg@46 | 39 | import com.sun.tools.classfile.ConstantPoolException; |
jjg@46 | 40 | import com.sun.tools.classfile.ConstantValue_attribute; |
jjg@46 | 41 | import com.sun.tools.classfile.DefaultAttribute; |
jjg@46 | 42 | import com.sun.tools.classfile.Deprecated_attribute; |
jjg@46 | 43 | import com.sun.tools.classfile.EnclosingMethod_attribute; |
jjg@46 | 44 | import com.sun.tools.classfile.Exceptions_attribute; |
jjg@46 | 45 | import com.sun.tools.classfile.InnerClasses_attribute; |
jjg@46 | 46 | import com.sun.tools.classfile.LineNumberTable_attribute; |
jjg@46 | 47 | import com.sun.tools.classfile.LocalVariableTable_attribute; |
jjg@46 | 48 | import com.sun.tools.classfile.LocalVariableTypeTable_attribute; |
jjg@1473 | 49 | import com.sun.tools.classfile.MethodParameters_attribute; |
jjg@46 | 50 | import com.sun.tools.classfile.RuntimeInvisibleAnnotations_attribute; |
jjg@46 | 51 | import com.sun.tools.classfile.RuntimeInvisibleParameterAnnotations_attribute; |
jjg@1521 | 52 | import com.sun.tools.classfile.RuntimeInvisibleTypeAnnotations_attribute; |
jjg@46 | 53 | import com.sun.tools.classfile.RuntimeVisibleAnnotations_attribute; |
jjg@46 | 54 | import com.sun.tools.classfile.RuntimeVisibleParameterAnnotations_attribute; |
jjg@1521 | 55 | import com.sun.tools.classfile.RuntimeVisibleTypeAnnotations_attribute; |
jjg@46 | 56 | import com.sun.tools.classfile.Signature_attribute; |
jjg@46 | 57 | import com.sun.tools.classfile.SourceDebugExtension_attribute; |
jjg@46 | 58 | import com.sun.tools.classfile.SourceFile_attribute; |
jjg@46 | 59 | import com.sun.tools.classfile.SourceID_attribute; |
jjg@46 | 60 | import com.sun.tools.classfile.StackMapTable_attribute; |
jjg@46 | 61 | import com.sun.tools.classfile.StackMap_attribute; |
jjg@46 | 62 | import com.sun.tools.classfile.Synthetic_attribute; |
jjg@46 | 63 | |
jjg@46 | 64 | import static com.sun.tools.classfile.AccessFlags.*; |
jjg@46 | 65 | |
jjg@46 | 66 | /* |
jjg@46 | 67 | * A writer for writing Attributes as text. |
jjg@46 | 68 | * |
jjg@581 | 69 | * <p><b>This is NOT part of any supported API. |
jjg@581 | 70 | * If you write code that depends on this, you do so at your own risk. |
jjg@46 | 71 | * This code and its internal interfaces are subject to change or |
jjg@46 | 72 | * deletion without notice.</b> |
jjg@46 | 73 | */ |
jjg@46 | 74 | public class AttributeWriter extends BasicWriter |
jjg@46 | 75 | implements Attribute.Visitor<Void,Void> |
jjg@46 | 76 | { |
jjg@300 | 77 | public static AttributeWriter instance(Context context) { |
jjg@46 | 78 | AttributeWriter instance = context.get(AttributeWriter.class); |
jjg@46 | 79 | if (instance == null) |
jjg@46 | 80 | instance = new AttributeWriter(context); |
jjg@46 | 81 | return instance; |
jjg@46 | 82 | } |
jjg@46 | 83 | |
jjg@46 | 84 | protected AttributeWriter(Context context) { |
jjg@46 | 85 | super(context); |
jjg@46 | 86 | context.put(AttributeWriter.class, this); |
jjg@46 | 87 | annotationWriter = AnnotationWriter.instance(context); |
jjg@46 | 88 | codeWriter = CodeWriter.instance(context); |
jjg@46 | 89 | constantWriter = ConstantWriter.instance(context); |
jjg@46 | 90 | options = Options.instance(context); |
jjg@46 | 91 | } |
jjg@46 | 92 | |
jjg@46 | 93 | public void write(Object owner, Attribute attr, ConstantPool constant_pool) { |
jjg@46 | 94 | if (attr != null) { |
jjg@46 | 95 | // null checks |
jjg@46 | 96 | owner.getClass(); |
jjg@46 | 97 | constant_pool.getClass(); |
jjg@46 | 98 | this.constant_pool = constant_pool; |
jjg@46 | 99 | this.owner = owner; |
jjg@46 | 100 | attr.accept(this, null); |
jjg@46 | 101 | } |
jjg@46 | 102 | } |
jjg@46 | 103 | |
jjg@46 | 104 | public void write(Object owner, Attributes attrs, ConstantPool constant_pool) { |
jjg@46 | 105 | if (attrs != null) { |
jjg@46 | 106 | // null checks |
jjg@46 | 107 | owner.getClass(); |
jjg@46 | 108 | constant_pool.getClass(); |
jjg@46 | 109 | this.constant_pool = constant_pool; |
jjg@46 | 110 | this.owner = owner; |
jjg@46 | 111 | for (Attribute attr: attrs) |
jjg@46 | 112 | attr.accept(this, null); |
jjg@46 | 113 | } |
jjg@46 | 114 | } |
jjg@46 | 115 | |
jjg@46 | 116 | public Void visitDefault(DefaultAttribute attr, Void ignore) { |
vromero@1874 | 117 | if (attr.reason != null) { |
vromero@1874 | 118 | report(attr.reason); |
vromero@1874 | 119 | } |
jjg@46 | 120 | byte[] data = attr.info; |
jjg@46 | 121 | int i = 0; |
jjg@46 | 122 | int j = 0; |
jjg@46 | 123 | print(" "); |
jjg@46 | 124 | try { |
jjg@46 | 125 | print(attr.getName(constant_pool)); |
jjg@46 | 126 | } catch (ConstantPoolException e) { |
jjg@46 | 127 | report(e); |
jjg@46 | 128 | print("attribute name = #" + attr.attribute_name_index); |
jjg@46 | 129 | } |
jjg@46 | 130 | print(": "); |
jjg@46 | 131 | println("length = 0x" + toHex(attr.info.length)); |
jjg@46 | 132 | |
jjg@46 | 133 | print(" "); |
jjg@46 | 134 | |
jjg@46 | 135 | while (i < data.length) { |
jjg@46 | 136 | print(toHex(data[i], 2)); |
jjg@46 | 137 | |
jjg@46 | 138 | j++; |
jjg@46 | 139 | if (j == 16) { |
jjg@46 | 140 | println(); |
jjg@46 | 141 | print(" "); |
jjg@46 | 142 | j = 0; |
jjg@46 | 143 | } else { |
jjg@46 | 144 | print(" "); |
jjg@46 | 145 | } |
jjg@46 | 146 | i++; |
jjg@46 | 147 | } |
jjg@46 | 148 | println(); |
jjg@46 | 149 | return null; |
jjg@46 | 150 | } |
jjg@46 | 151 | |
jjg@46 | 152 | public Void visitAnnotationDefault(AnnotationDefault_attribute attr, Void ignore) { |
jjg@348 | 153 | println("AnnotationDefault:"); |
jjg@348 | 154 | indent(+1); |
jjg@348 | 155 | print("default_value: "); |
jjg@46 | 156 | annotationWriter.write(attr.default_value); |
jjg@348 | 157 | indent(-1); |
jjg@46 | 158 | return null; |
jjg@46 | 159 | } |
jjg@46 | 160 | |
ksrini@826 | 161 | public Void visitBootstrapMethods(BootstrapMethods_attribute attr, Void p) { |
ksrini@826 | 162 | println(Attribute.BootstrapMethods + ":"); |
ksrini@826 | 163 | for (int i = 0; i < attr.bootstrap_method_specifiers.length ; i++) { |
ksrini@826 | 164 | BootstrapMethods_attribute.BootstrapMethodSpecifier bsm = attr.bootstrap_method_specifiers[i]; |
ksrini@826 | 165 | indent(+1); |
ksrini@826 | 166 | print(i + ": #" + bsm.bootstrap_method_ref + " "); |
ksrini@826 | 167 | println(constantWriter.stringValue(bsm.bootstrap_method_ref)); |
ksrini@826 | 168 | indent(+1); |
ksrini@826 | 169 | println("Method arguments:"); |
ksrini@826 | 170 | indent(+1); |
ksrini@826 | 171 | for (int j = 0; j < bsm.bootstrap_arguments.length; j++) { |
ksrini@826 | 172 | print("#" + bsm.bootstrap_arguments[j] + " "); |
ksrini@826 | 173 | println(constantWriter.stringValue(bsm.bootstrap_arguments[j])); |
ksrini@826 | 174 | } |
ksrini@826 | 175 | indent(-3); |
ksrini@826 | 176 | } |
ksrini@826 | 177 | return null; |
ksrini@826 | 178 | } |
ksrini@826 | 179 | |
jjg@46 | 180 | public Void visitCharacterRangeTable(CharacterRangeTable_attribute attr, Void ignore) { |
jjg@348 | 181 | println("CharacterRangeTable:"); |
jjg@348 | 182 | indent(+1); |
jjg@46 | 183 | for (int i = 0; i < attr.character_range_table.length; i++) { |
jjg@46 | 184 | CharacterRangeTable_attribute.Entry e = attr.character_range_table[i]; |
jjg@777 | 185 | print(String.format(" %2d, %2d, %6x, %6x, %4x", |
jjg@777 | 186 | e.start_pc, e.end_pc, |
jjg@777 | 187 | e.character_range_start, e.character_range_end, |
jjg@777 | 188 | e.flags)); |
jjg@348 | 189 | tab(); |
jjg@777 | 190 | print(String.format("// %2d, %2d, %4d:%02d, %4d:%02d", |
jjg@777 | 191 | e.start_pc, e.end_pc, |
jjg@777 | 192 | (e.character_range_start >> 10), (e.character_range_start & 0x3ff), |
jjg@777 | 193 | (e.character_range_end >> 10), (e.character_range_end & 0x3ff))); |
jjg@46 | 194 | if ((e.flags & CharacterRangeTable_attribute.CRT_STATEMENT) != 0) |
jjg@46 | 195 | print(", statement"); |
jjg@46 | 196 | if ((e.flags & CharacterRangeTable_attribute.CRT_BLOCK) != 0) |
jjg@46 | 197 | print(", block"); |
jjg@46 | 198 | if ((e.flags & CharacterRangeTable_attribute.CRT_ASSIGNMENT) != 0) |
jjg@46 | 199 | print(", assignment"); |
jjg@46 | 200 | if ((e.flags & CharacterRangeTable_attribute.CRT_FLOW_CONTROLLER) != 0) |
jjg@46 | 201 | print(", flow-controller"); |
jjg@46 | 202 | if ((e.flags & CharacterRangeTable_attribute.CRT_FLOW_TARGET) != 0) |
jjg@46 | 203 | print(", flow-target"); |
jjg@46 | 204 | if ((e.flags & CharacterRangeTable_attribute.CRT_INVOKE) != 0) |
jjg@46 | 205 | print(", invoke"); |
jjg@46 | 206 | if ((e.flags & CharacterRangeTable_attribute.CRT_CREATE) != 0) |
jjg@46 | 207 | print(", create"); |
jjg@46 | 208 | if ((e.flags & CharacterRangeTable_attribute.CRT_BRANCH_TRUE) != 0) |
jjg@46 | 209 | print(", branch-true"); |
jjg@46 | 210 | if ((e.flags & CharacterRangeTable_attribute.CRT_BRANCH_FALSE) != 0) |
jjg@46 | 211 | print(", branch-false"); |
jjg@777 | 212 | println(); |
jjg@46 | 213 | } |
jjg@348 | 214 | indent(-1); |
jjg@46 | 215 | return null; |
jjg@46 | 216 | } |
jjg@46 | 217 | |
jjg@46 | 218 | public Void visitCode(Code_attribute attr, Void ignore) { |
jjg@46 | 219 | codeWriter.write(attr, constant_pool); |
jjg@46 | 220 | return null; |
jjg@46 | 221 | } |
jjg@46 | 222 | |
jjg@46 | 223 | public Void visitCompilationID(CompilationID_attribute attr, Void ignore) { |
jjg@46 | 224 | constantWriter.write(attr.compilationID_index); |
jjg@46 | 225 | return null; |
jjg@46 | 226 | } |
jjg@46 | 227 | |
jjg@46 | 228 | public Void visitConstantValue(ConstantValue_attribute attr, Void ignore) { |
kizune@2289 | 229 | print("ConstantValue: "); |
jjg@46 | 230 | constantWriter.write(attr.constantvalue_index); |
jjg@348 | 231 | println(); |
jjg@46 | 232 | return null; |
jjg@46 | 233 | } |
jjg@46 | 234 | |
jjg@46 | 235 | public Void visitDeprecated(Deprecated_attribute attr, Void ignore) { |
jjg@46 | 236 | println("Deprecated: true"); |
jjg@46 | 237 | return null; |
jjg@46 | 238 | } |
jjg@46 | 239 | |
jjg@46 | 240 | public Void visitEnclosingMethod(EnclosingMethod_attribute attr, Void ignore) { |
jjg@348 | 241 | print("EnclosingMethod: #" + attr.class_index + ".#" + attr.method_index); |
jjg@348 | 242 | tab(); |
jjg@348 | 243 | print("// " + getJavaClassName(attr)); |
jjg@46 | 244 | if (attr.method_index != 0) |
jjg@46 | 245 | print("." + getMethodName(attr)); |
jjg@46 | 246 | println(); |
jjg@46 | 247 | return null; |
jjg@46 | 248 | } |
jjg@46 | 249 | |
jjg@46 | 250 | private String getJavaClassName(EnclosingMethod_attribute a) { |
jjg@46 | 251 | try { |
jjg@46 | 252 | return getJavaName(a.getClassName(constant_pool)); |
jjg@46 | 253 | } catch (ConstantPoolException e) { |
jjg@46 | 254 | return report(e); |
jjg@46 | 255 | } |
jjg@46 | 256 | } |
jjg@46 | 257 | |
jjg@46 | 258 | private String getMethodName(EnclosingMethod_attribute a) { |
jjg@46 | 259 | try { |
jjg@46 | 260 | return a.getMethodName(constant_pool); |
jjg@46 | 261 | } catch (ConstantPoolException e) { |
jjg@46 | 262 | return report(e); |
jjg@46 | 263 | } |
jjg@46 | 264 | } |
jjg@46 | 265 | |
jjg@46 | 266 | public Void visitExceptions(Exceptions_attribute attr, Void ignore) { |
jjg@348 | 267 | println("Exceptions:"); |
jjg@348 | 268 | indent(+1); |
jjg@348 | 269 | print("throws "); |
jjg@46 | 270 | for (int i = 0; i < attr.number_of_exceptions; i++) { |
jjg@46 | 271 | if (i > 0) |
jjg@46 | 272 | print(", "); |
jjg@46 | 273 | print(getJavaException(attr, i)); |
jjg@46 | 274 | } |
jjg@348 | 275 | println(); |
jjg@348 | 276 | indent(-1); |
jjg@46 | 277 | return null; |
jjg@46 | 278 | } |
jjg@46 | 279 | |
jjg@52 | 280 | private String getJavaException(Exceptions_attribute attr, int index) { |
jjg@46 | 281 | try { |
jjg@46 | 282 | return getJavaName(attr.getException(index, constant_pool)); |
jjg@46 | 283 | } catch (ConstantPoolException e) { |
jjg@46 | 284 | return report(e); |
jjg@46 | 285 | } |
jjg@46 | 286 | } |
jjg@46 | 287 | |
jjg@46 | 288 | public Void visitInnerClasses(InnerClasses_attribute attr, Void ignore) { |
jjg@46 | 289 | boolean first = true; |
jjg@46 | 290 | for (int i = 0 ; i < attr.classes.length; i++) { |
jjg@46 | 291 | InnerClasses_attribute.Info info = attr.classes[i]; |
jjg@46 | 292 | //access |
jjg@46 | 293 | AccessFlags access_flags = info.inner_class_access_flags; |
jjg@46 | 294 | if (options.checkAccess(access_flags)) { |
jjg@46 | 295 | if (first) { |
jjg@46 | 296 | writeInnerClassHeader(); |
jjg@46 | 297 | first = false; |
jjg@46 | 298 | } |
jjg@348 | 299 | print(" "); |
jjg@46 | 300 | for (String name: access_flags.getInnerClassModifiers()) |
jjg@46 | 301 | print(name + " "); |
jjg@46 | 302 | if (info.inner_name_index!=0) { |
jjg@46 | 303 | print("#" + info.inner_name_index + "= "); |
jjg@46 | 304 | } |
jjg@46 | 305 | print("#" + info.inner_class_info_index); |
jjg@46 | 306 | if (info.outer_class_info_index != 0) { |
jjg@46 | 307 | print(" of #" + info.outer_class_info_index); |
jjg@46 | 308 | } |
jjg@46 | 309 | print("; //"); |
jjg@46 | 310 | if (info.inner_name_index != 0) { |
jjg@46 | 311 | print(getInnerName(constant_pool, info) + "="); |
jjg@46 | 312 | } |
jjg@46 | 313 | constantWriter.write(info.inner_class_info_index); |
jjg@46 | 314 | if (info.outer_class_info_index != 0) { |
jjg@46 | 315 | print(" of "); |
jjg@46 | 316 | constantWriter.write(info.outer_class_info_index); |
jjg@46 | 317 | } |
jjg@46 | 318 | println(); |
jjg@46 | 319 | } |
jjg@46 | 320 | } |
jjg@348 | 321 | if (!first) |
jjg@348 | 322 | indent(-1); |
jjg@46 | 323 | return null; |
jjg@46 | 324 | } |
jjg@46 | 325 | |
jjg@46 | 326 | String getInnerName(ConstantPool constant_pool, InnerClasses_attribute.Info info) { |
jjg@46 | 327 | try { |
jjg@46 | 328 | return info.getInnerName(constant_pool); |
jjg@46 | 329 | } catch (ConstantPoolException e) { |
jjg@46 | 330 | return report(e); |
jjg@46 | 331 | } |
jjg@46 | 332 | } |
jjg@46 | 333 | |
jjg@46 | 334 | private void writeInnerClassHeader() { |
kizune@2289 | 335 | println("InnerClasses:"); |
jjg@348 | 336 | indent(+1); |
jjg@46 | 337 | } |
jjg@46 | 338 | |
jjg@46 | 339 | public Void visitLineNumberTable(LineNumberTable_attribute attr, Void ignore) { |
jjg@348 | 340 | println("LineNumberTable:"); |
jjg@348 | 341 | indent(+1); |
jjg@46 | 342 | for (LineNumberTable_attribute.Entry entry: attr.line_number_table) { |
jjg@348 | 343 | println("line " + entry.line_number + ": " + entry.start_pc); |
jjg@46 | 344 | } |
jjg@348 | 345 | indent(-1); |
jjg@46 | 346 | return null; |
jjg@46 | 347 | } |
jjg@46 | 348 | |
jjg@46 | 349 | public Void visitLocalVariableTable(LocalVariableTable_attribute attr, Void ignore) { |
jjg@348 | 350 | println("LocalVariableTable:"); |
jjg@348 | 351 | indent(+1); |
jjg@348 | 352 | println("Start Length Slot Name Signature"); |
jjg@46 | 353 | for (LocalVariableTable_attribute.Entry entry : attr.local_variable_table) { |
vromero@1872 | 354 | println(String.format("%5d %7d %5d %5s %s", |
jjg@46 | 355 | entry.start_pc, entry.length, entry.index, |
jjg@46 | 356 | constantWriter.stringValue(entry.name_index), |
jjg@46 | 357 | constantWriter.stringValue(entry.descriptor_index))); |
jjg@46 | 358 | } |
jjg@348 | 359 | indent(-1); |
jjg@46 | 360 | return null; |
jjg@46 | 361 | } |
jjg@46 | 362 | |
jjg@46 | 363 | public Void visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, Void ignore) { |
jjg@348 | 364 | println("LocalVariableTypeTable:"); |
jjg@348 | 365 | indent(+1); |
jjg@348 | 366 | println("Start Length Slot Name Signature"); |
jjg@46 | 367 | for (LocalVariableTypeTable_attribute.Entry entry : attr.local_variable_table) { |
jjg@348 | 368 | println(String.format("%5d %7d %5d %5s %s", |
jjg@46 | 369 | entry.start_pc, entry.length, entry.index, |
jjg@46 | 370 | constantWriter.stringValue(entry.name_index), |
jjg@46 | 371 | constantWriter.stringValue(entry.signature_index))); |
jjg@46 | 372 | } |
jjg@348 | 373 | indent(-1); |
jjg@46 | 374 | return null; |
jjg@46 | 375 | } |
jjg@46 | 376 | |
jjg@1473 | 377 | private static final String format = "%-31s%s"; |
jjg@1473 | 378 | |
jjg@1473 | 379 | public Void visitMethodParameters(MethodParameters_attribute attr, |
jjg@1473 | 380 | Void ignore) { |
jjg@1473 | 381 | |
jjg@1473 | 382 | final String header = String.format(format, "Name", "Flags"); |
jjg@1473 | 383 | println("MethodParameters:"); |
jjg@1473 | 384 | indent(+1); |
jjg@1473 | 385 | println(header); |
jjg@1473 | 386 | for (MethodParameters_attribute.Entry entry : |
jjg@1473 | 387 | attr.method_parameter_table) { |
mcimadamore@1565 | 388 | String namestr = |
mcimadamore@1565 | 389 | entry.name_index != 0 ? |
mcimadamore@1565 | 390 | constantWriter.stringValue(entry.name_index) : "<no name>"; |
jjg@1473 | 391 | String flagstr = |
mcimadamore@1565 | 392 | (0 != (entry.flags & ACC_FINAL) ? "final " : "") + |
mcimadamore@1565 | 393 | (0 != (entry.flags & ACC_MANDATED) ? "mandated " : "") + |
mcimadamore@1565 | 394 | (0 != (entry.flags & ACC_SYNTHETIC) ? "synthetic" : ""); |
mcimadamore@1565 | 395 | println(String.format(format, namestr, flagstr)); |
jjg@1473 | 396 | } |
jjg@1473 | 397 | indent(-1); |
jjg@1473 | 398 | return null; |
jjg@1473 | 399 | } |
jjg@1473 | 400 | |
jjg@46 | 401 | public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, Void ignore) { |
jjg@348 | 402 | println("RuntimeVisibleAnnotations:"); |
jjg@348 | 403 | indent(+1); |
jjg@46 | 404 | for (int i = 0; i < attr.annotations.length; i++) { |
jjg@348 | 405 | print(i + ": "); |
jjg@46 | 406 | annotationWriter.write(attr.annotations[i]); |
jjg@46 | 407 | println(); |
jjg@46 | 408 | } |
jjg@348 | 409 | indent(-1); |
jjg@46 | 410 | return null; |
jjg@46 | 411 | } |
jjg@46 | 412 | |
jjg@46 | 413 | public Void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, Void ignore) { |
jjg@348 | 414 | println("RuntimeInvisibleAnnotations:"); |
jjg@348 | 415 | indent(+1); |
jjg@46 | 416 | for (int i = 0; i < attr.annotations.length; i++) { |
jjg@348 | 417 | print(i + ": "); |
jjg@46 | 418 | annotationWriter.write(attr.annotations[i]); |
jjg@46 | 419 | println(); |
jjg@46 | 420 | } |
jjg@348 | 421 | indent(-1); |
jjg@46 | 422 | return null; |
jjg@46 | 423 | } |
jjg@46 | 424 | |
jjg@1521 | 425 | public Void visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, Void ignore) { |
jjg@1521 | 426 | println("RuntimeVisibleTypeAnnotations:"); |
jjg@1521 | 427 | indent(+1); |
jjg@1521 | 428 | for (int i = 0; i < attr.annotations.length; i++) { |
jjg@1521 | 429 | print(i + ": "); |
jjg@1521 | 430 | annotationWriter.write(attr.annotations[i]); |
jjg@1521 | 431 | println(); |
jjg@1521 | 432 | } |
jjg@1521 | 433 | indent(-1); |
jjg@1521 | 434 | return null; |
jjg@1521 | 435 | } |
jjg@1521 | 436 | |
jjg@1521 | 437 | public Void visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute attr, Void ignore) { |
jjg@1521 | 438 | println("RuntimeInvisibleTypeAnnotations:"); |
jjg@1521 | 439 | indent(+1); |
jjg@1521 | 440 | for (int i = 0; i < attr.annotations.length; i++) { |
jjg@1521 | 441 | print(i + ": "); |
jjg@1521 | 442 | annotationWriter.write(attr.annotations[i]); |
jjg@1521 | 443 | println(); |
jjg@1521 | 444 | } |
jjg@1521 | 445 | indent(-1); |
jjg@1521 | 446 | return null; |
jjg@1521 | 447 | } |
jjg@1521 | 448 | |
jjg@46 | 449 | public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, Void ignore) { |
jjg@348 | 450 | println("RuntimeVisibleParameterAnnotations:"); |
jjg@348 | 451 | indent(+1); |
jjg@46 | 452 | for (int param = 0; param < attr.parameter_annotations.length; param++) { |
jjg@348 | 453 | println("parameter " + param + ": "); |
jjg@348 | 454 | indent(+1); |
jjg@46 | 455 | for (int i = 0; i < attr.parameter_annotations[param].length; i++) { |
jjg@348 | 456 | print(i + ": "); |
jjg@46 | 457 | annotationWriter.write(attr.parameter_annotations[param][i]); |
jjg@46 | 458 | println(); |
jjg@46 | 459 | } |
jjg@348 | 460 | indent(-1); |
jjg@46 | 461 | } |
jjg@348 | 462 | indent(-1); |
jjg@46 | 463 | return null; |
jjg@46 | 464 | } |
jjg@46 | 465 | |
jjg@46 | 466 | public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, Void ignore) { |
jjg@348 | 467 | println("RuntimeInvisibleParameterAnnotations:"); |
jjg@348 | 468 | indent(+1); |
jjg@46 | 469 | for (int param = 0; param < attr.parameter_annotations.length; param++) { |
jjg@348 | 470 | println(param + ": "); |
jjg@348 | 471 | indent(+1); |
jjg@46 | 472 | for (int i = 0; i < attr.parameter_annotations[param].length; i++) { |
jjg@348 | 473 | print(i + ": "); |
jjg@46 | 474 | annotationWriter.write(attr.parameter_annotations[param][i]); |
jjg@46 | 475 | println(); |
jjg@46 | 476 | } |
jjg@348 | 477 | indent(-1); |
jjg@46 | 478 | } |
jjg@348 | 479 | indent(-1); |
jjg@46 | 480 | return null; |
jjg@46 | 481 | } |
jjg@46 | 482 | |
jjg@46 | 483 | public Void visitSignature(Signature_attribute attr, Void ignore) { |
jjg@348 | 484 | print("Signature: #" + attr.signature_index); |
jjg@348 | 485 | tab(); |
jjg@348 | 486 | println("// " + getSignature(attr)); |
jjg@46 | 487 | return null; |
jjg@46 | 488 | } |
jjg@46 | 489 | |
jjg@46 | 490 | String getSignature(Signature_attribute info) { |
jjg@46 | 491 | try { |
jjg@46 | 492 | return info.getSignature(constant_pool); |
jjg@46 | 493 | } catch (ConstantPoolException e) { |
jjg@46 | 494 | return report(e); |
jjg@46 | 495 | } |
jjg@46 | 496 | } |
jjg@46 | 497 | |
jjg@46 | 498 | public Void visitSourceDebugExtension(SourceDebugExtension_attribute attr, Void ignore) { |
vromero@1877 | 499 | println("SourceDebugExtension:"); |
vromero@1877 | 500 | indent(+1); |
vromero@1877 | 501 | for (String s: attr.getValue().split("[\r\n]+")) { |
vromero@1877 | 502 | println(s); |
vromero@1877 | 503 | } |
vromero@1877 | 504 | indent(-1); |
jjg@46 | 505 | return null; |
jjg@46 | 506 | } |
jjg@46 | 507 | |
jjg@46 | 508 | public Void visitSourceFile(SourceFile_attribute attr, Void ignore) { |
jjg@348 | 509 | println("SourceFile: \"" + getSourceFile(attr) + "\""); |
jjg@46 | 510 | return null; |
jjg@46 | 511 | } |
jjg@46 | 512 | |
jjg@46 | 513 | private String getSourceFile(SourceFile_attribute attr) { |
jjg@46 | 514 | try { |
jjg@46 | 515 | return attr.getSourceFile(constant_pool); |
jjg@46 | 516 | } catch (ConstantPoolException e) { |
jjg@46 | 517 | return report(e); |
jjg@46 | 518 | } |
jjg@46 | 519 | } |
jjg@46 | 520 | |
jjg@46 | 521 | public Void visitSourceID(SourceID_attribute attr, Void ignore) { |
jjg@46 | 522 | constantWriter.write(attr.sourceID_index); |
jjg@46 | 523 | return null; |
jjg@46 | 524 | } |
jjg@46 | 525 | |
jjg@46 | 526 | public Void visitStackMap(StackMap_attribute attr, Void ignore) { |
jjg@348 | 527 | println("StackMap: number_of_entries = " + attr.number_of_entries); |
jjg@348 | 528 | indent(+1); |
jjg@46 | 529 | StackMapTableWriter w = new StackMapTableWriter(); |
jjg@46 | 530 | for (StackMapTable_attribute.stack_map_frame entry : attr.entries) { |
jjg@46 | 531 | w.write(entry); |
jjg@46 | 532 | } |
jjg@348 | 533 | indent(-1); |
jjg@46 | 534 | return null; |
jjg@46 | 535 | } |
jjg@46 | 536 | |
jjg@46 | 537 | public Void visitStackMapTable(StackMapTable_attribute attr, Void ignore) { |
jjg@348 | 538 | println("StackMapTable: number_of_entries = " + attr.number_of_entries); |
jjg@348 | 539 | indent(+1); |
jjg@46 | 540 | StackMapTableWriter w = new StackMapTableWriter(); |
jjg@46 | 541 | for (StackMapTable_attribute.stack_map_frame entry : attr.entries) { |
jjg@46 | 542 | w.write(entry); |
jjg@46 | 543 | } |
jjg@348 | 544 | indent(-1); |
jjg@46 | 545 | return null; |
jjg@46 | 546 | } |
jjg@46 | 547 | |
jjg@46 | 548 | class StackMapTableWriter // also handles CLDC StackMap attributes |
jjg@46 | 549 | implements StackMapTable_attribute.stack_map_frame.Visitor<Void,Void> { |
jjg@46 | 550 | public void write(StackMapTable_attribute.stack_map_frame frame) { |
jjg@46 | 551 | frame.accept(this, null); |
jjg@46 | 552 | } |
jjg@46 | 553 | |
jjg@46 | 554 | public Void visit_same_frame(StackMapTable_attribute.same_frame frame, Void p) { |
kizune@2266 | 555 | printHeader(frame, "/* same */"); |
jjg@46 | 556 | return null; |
jjg@46 | 557 | } |
jjg@46 | 558 | |
jjg@46 | 559 | public Void visit_same_locals_1_stack_item_frame(StackMapTable_attribute.same_locals_1_stack_item_frame frame, Void p) { |
kizune@2266 | 560 | printHeader(frame, "/* same_locals_1_stack_item */"); |
jjg@348 | 561 | indent(+1); |
jjg@46 | 562 | printMap("stack", frame.stack); |
jjg@348 | 563 | indent(-1); |
jjg@46 | 564 | return null; |
jjg@46 | 565 | } |
jjg@46 | 566 | |
jjg@46 | 567 | public Void visit_same_locals_1_stack_item_frame_extended(StackMapTable_attribute.same_locals_1_stack_item_frame_extended frame, Void p) { |
kizune@2266 | 568 | printHeader(frame, "/* same_locals_1_stack_item_frame_extended */"); |
jjg@348 | 569 | indent(+1); |
jjg@348 | 570 | println("offset_delta = " + frame.offset_delta); |
jjg@46 | 571 | printMap("stack", frame.stack); |
jjg@348 | 572 | indent(-1); |
jjg@46 | 573 | return null; |
jjg@46 | 574 | } |
jjg@46 | 575 | |
jjg@46 | 576 | public Void visit_chop_frame(StackMapTable_attribute.chop_frame frame, Void p) { |
kizune@2266 | 577 | printHeader(frame, "/* chop */"); |
jjg@348 | 578 | indent(+1); |
jjg@348 | 579 | println("offset_delta = " + frame.offset_delta); |
jjg@348 | 580 | indent(-1); |
jjg@46 | 581 | return null; |
jjg@46 | 582 | } |
jjg@46 | 583 | |
jjg@46 | 584 | public Void visit_same_frame_extended(StackMapTable_attribute.same_frame_extended frame, Void p) { |
kizune@2266 | 585 | printHeader(frame, "/* same_frame_extended */"); |
jjg@348 | 586 | indent(+1); |
jjg@348 | 587 | println("offset_delta = " + frame.offset_delta); |
jjg@348 | 588 | indent(-1); |
jjg@46 | 589 | return null; |
jjg@46 | 590 | } |
jjg@46 | 591 | |
jjg@46 | 592 | public Void visit_append_frame(StackMapTable_attribute.append_frame frame, Void p) { |
kizune@2266 | 593 | printHeader(frame, "/* append */"); |
vromero@1872 | 594 | indent(+1); |
vromero@1872 | 595 | println("offset_delta = " + frame.offset_delta); |
jjg@46 | 596 | printMap("locals", frame.locals); |
kizune@2264 | 597 | indent(-1); |
jjg@46 | 598 | return null; |
jjg@46 | 599 | } |
jjg@46 | 600 | |
jjg@46 | 601 | public Void visit_full_frame(StackMapTable_attribute.full_frame frame, Void p) { |
jjg@46 | 602 | if (frame instanceof StackMap_attribute.stack_map_frame) { |
kizune@2266 | 603 | printHeader(frame, "offset = " + frame.offset_delta); |
jjg@348 | 604 | indent(+1); |
jjg@46 | 605 | } else { |
kizune@2266 | 606 | printHeader(frame, "/* full_frame */"); |
jjg@348 | 607 | indent(+1); |
jjg@348 | 608 | println("offset_delta = " + frame.offset_delta); |
jjg@46 | 609 | } |
jjg@46 | 610 | printMap("locals", frame.locals); |
jjg@46 | 611 | printMap("stack", frame.stack); |
jjg@348 | 612 | indent(-1); |
jjg@46 | 613 | return null; |
jjg@46 | 614 | } |
jjg@46 | 615 | |
kizune@2266 | 616 | void printHeader(StackMapTable_attribute.stack_map_frame frame, String extra) { |
kizune@2266 | 617 | print("frame_type = " + frame.frame_type + " "); |
kizune@2266 | 618 | println(extra); |
jjg@46 | 619 | } |
jjg@46 | 620 | |
jjg@46 | 621 | void printMap(String name, StackMapTable_attribute.verification_type_info[] map) { |
jjg@348 | 622 | print(name + " = ["); |
jjg@46 | 623 | for (int i = 0; i < map.length; i++) { |
jjg@46 | 624 | StackMapTable_attribute.verification_type_info info = map[i]; |
jjg@46 | 625 | int tag = info.tag; |
jjg@46 | 626 | switch (tag) { |
jjg@46 | 627 | case StackMapTable_attribute.verification_type_info.ITEM_Object: |
jjg@46 | 628 | print(" "); |
jjg@46 | 629 | constantWriter.write(((StackMapTable_attribute.Object_variable_info) info).cpool_index); |
jjg@46 | 630 | break; |
jjg@46 | 631 | case StackMapTable_attribute.verification_type_info.ITEM_Uninitialized: |
jjg@46 | 632 | print(" " + mapTypeName(tag)); |
jjg@46 | 633 | print(" " + ((StackMapTable_attribute.Uninitialized_variable_info) info).offset); |
jjg@46 | 634 | break; |
jjg@46 | 635 | default: |
jjg@46 | 636 | print(" " + mapTypeName(tag)); |
jjg@46 | 637 | } |
jjg@46 | 638 | print(i == (map.length - 1) ? " " : ","); |
jjg@46 | 639 | } |
jjg@46 | 640 | println("]"); |
jjg@46 | 641 | } |
jjg@46 | 642 | |
jjg@46 | 643 | String mapTypeName(int tag) { |
jjg@46 | 644 | switch (tag) { |
jjg@46 | 645 | case StackMapTable_attribute.verification_type_info.ITEM_Top: |
jjg@46 | 646 | return "top"; |
jjg@46 | 647 | |
jjg@46 | 648 | case StackMapTable_attribute.verification_type_info.ITEM_Integer: |
jjg@46 | 649 | return "int"; |
jjg@46 | 650 | |
jjg@46 | 651 | case StackMapTable_attribute.verification_type_info.ITEM_Float: |
jjg@46 | 652 | return "float"; |
jjg@46 | 653 | |
jjg@46 | 654 | case StackMapTable_attribute.verification_type_info.ITEM_Long: |
jjg@46 | 655 | return "long"; |
jjg@46 | 656 | |
jjg@46 | 657 | case StackMapTable_attribute.verification_type_info.ITEM_Double: |
jjg@46 | 658 | return "double"; |
jjg@46 | 659 | |
jjg@46 | 660 | case StackMapTable_attribute.verification_type_info.ITEM_Null: |
jjg@46 | 661 | return "null"; |
jjg@46 | 662 | |
jjg@46 | 663 | case StackMapTable_attribute.verification_type_info.ITEM_UninitializedThis: |
jjg@46 | 664 | return "this"; |
jjg@46 | 665 | |
jjg@46 | 666 | case StackMapTable_attribute.verification_type_info.ITEM_Object: |
jjg@46 | 667 | return "CP"; |
jjg@46 | 668 | |
jjg@46 | 669 | case StackMapTable_attribute.verification_type_info.ITEM_Uninitialized: |
jjg@46 | 670 | return "uninitialized"; |
jjg@46 | 671 | |
jjg@46 | 672 | default: |
jjg@46 | 673 | report("unrecognized verification_type_info tag: " + tag); |
jjg@46 | 674 | return "[tag:" + tag + "]"; |
jjg@46 | 675 | } |
jjg@46 | 676 | } |
jjg@46 | 677 | } |
jjg@46 | 678 | |
jjg@46 | 679 | public Void visitSynthetic(Synthetic_attribute attr, Void ignore) { |
jjg@46 | 680 | println("Synthetic: true"); |
jjg@46 | 681 | return null; |
jjg@46 | 682 | } |
jjg@46 | 683 | |
jjg@46 | 684 | static String getJavaName(String name) { |
jjg@46 | 685 | return name.replace('/', '.'); |
jjg@46 | 686 | } |
jjg@46 | 687 | |
jjg@46 | 688 | String toHex(byte b, int w) { |
kizune@2289 | 689 | return toHex(b & 0xff, w); |
jjg@46 | 690 | } |
jjg@46 | 691 | |
jjg@46 | 692 | static String toHex(int i) { |
jjg@46 | 693 | return Integer.toString(i, 16).toUpperCase(); |
jjg@46 | 694 | } |
jjg@46 | 695 | |
jjg@46 | 696 | static String toHex(int i, int w) { |
jjg@46 | 697 | String s = Integer.toHexString(i).toUpperCase(); |
jjg@46 | 698 | while (s.length() < w) |
jjg@46 | 699 | s = "0" + s; |
jjg@46 | 700 | return s.toUpperCase(); |
jjg@46 | 701 | } |
jjg@46 | 702 | |
jjg@46 | 703 | private AnnotationWriter annotationWriter; |
jjg@46 | 704 | private CodeWriter codeWriter; |
jjg@46 | 705 | private ConstantWriter constantWriter; |
jjg@46 | 706 | private Options options; |
jjg@46 | 707 | |
jjg@46 | 708 | private ConstantPool constant_pool; |
jjg@46 | 709 | private Object owner; |
jjg@46 | 710 | } |