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