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