1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javap/AttributeWriter.java Tue Jun 03 13:26:47 2008 -0700 1.3 @@ -0,0 +1,679 @@ 1.4 +/* 1.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Sun designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Sun in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.26 + * have any questions. 1.27 + */ 1.28 + 1.29 +package com.sun.tools.javap; 1.30 + 1.31 +import java.util.Formatter; 1.32 + 1.33 +import com.sun.tools.classfile.AccessFlags; 1.34 +import com.sun.tools.classfile.AnnotationDefault_attribute; 1.35 +import com.sun.tools.classfile.Attribute; 1.36 +import com.sun.tools.classfile.Attributes; 1.37 +import com.sun.tools.classfile.CharacterRangeTable_attribute; 1.38 +import com.sun.tools.classfile.Code_attribute; 1.39 +import com.sun.tools.classfile.CompilationID_attribute; 1.40 +import com.sun.tools.classfile.ConstantPool; 1.41 +import com.sun.tools.classfile.ConstantPoolException; 1.42 +import com.sun.tools.classfile.ConstantValue_attribute; 1.43 +import com.sun.tools.classfile.DefaultAttribute; 1.44 +import com.sun.tools.classfile.Deprecated_attribute; 1.45 +import com.sun.tools.classfile.EnclosingMethod_attribute; 1.46 +import com.sun.tools.classfile.Exceptions_attribute; 1.47 +import com.sun.tools.classfile.Field; 1.48 +import com.sun.tools.classfile.InnerClasses_attribute; 1.49 +import com.sun.tools.classfile.LineNumberTable_attribute; 1.50 +import com.sun.tools.classfile.LocalVariableTable_attribute; 1.51 +import com.sun.tools.classfile.LocalVariableTypeTable_attribute; 1.52 +import com.sun.tools.classfile.ModuleExportTable_attribute; 1.53 +import com.sun.tools.classfile.ModuleMemberTable_attribute; 1.54 +import com.sun.tools.classfile.Module_attribute; 1.55 +import com.sun.tools.classfile.RuntimeInvisibleAnnotations_attribute; 1.56 +import com.sun.tools.classfile.RuntimeInvisibleParameterAnnotations_attribute; 1.57 +import com.sun.tools.classfile.RuntimeVisibleAnnotations_attribute; 1.58 +import com.sun.tools.classfile.RuntimeVisibleParameterAnnotations_attribute; 1.59 +import com.sun.tools.classfile.Signature_attribute; 1.60 +import com.sun.tools.classfile.SourceDebugExtension_attribute; 1.61 +import com.sun.tools.classfile.SourceFile_attribute; 1.62 +import com.sun.tools.classfile.SourceID_attribute; 1.63 +import com.sun.tools.classfile.StackMapTable_attribute; 1.64 +import com.sun.tools.classfile.StackMap_attribute; 1.65 +import com.sun.tools.classfile.Synthetic_attribute; 1.66 + 1.67 +import static com.sun.tools.classfile.AccessFlags.*; 1.68 + 1.69 +/* 1.70 + * A writer for writing Attributes as text. 1.71 + * 1.72 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 1.73 + * you write code that depends on this, you do so at your own risk. 1.74 + * This code and its internal interfaces are subject to change or 1.75 + * deletion without notice.</b> 1.76 + */ 1.77 +public class AttributeWriter extends BasicWriter 1.78 + implements Attribute.Visitor<Void,Void> 1.79 +{ 1.80 + static AttributeWriter instance(Context context) { 1.81 + AttributeWriter instance = context.get(AttributeWriter.class); 1.82 + if (instance == null) 1.83 + instance = new AttributeWriter(context); 1.84 + return instance; 1.85 + } 1.86 + 1.87 + protected AttributeWriter(Context context) { 1.88 + super(context); 1.89 + context.put(AttributeWriter.class, this); 1.90 + annotationWriter = AnnotationWriter.instance(context); 1.91 + codeWriter = CodeWriter.instance(context); 1.92 + constantWriter = ConstantWriter.instance(context); 1.93 + options = Options.instance(context); 1.94 + } 1.95 + 1.96 + public void write(Object owner, Attribute attr, ConstantPool constant_pool) { 1.97 + if (attr != null) { 1.98 + // null checks 1.99 + owner.getClass(); 1.100 + constant_pool.getClass(); 1.101 + this.constant_pool = constant_pool; 1.102 + this.owner = owner; 1.103 + attr.accept(this, null); 1.104 + } 1.105 + } 1.106 + 1.107 + public void write(Object owner, Attributes attrs, ConstantPool constant_pool) { 1.108 + if (attrs != null) { 1.109 + // null checks 1.110 + owner.getClass(); 1.111 + constant_pool.getClass(); 1.112 + this.constant_pool = constant_pool; 1.113 + this.owner = owner; 1.114 + for (Attribute attr: attrs) 1.115 + attr.accept(this, null); 1.116 + } 1.117 + } 1.118 + 1.119 + public Void visitDefault(DefaultAttribute attr, Void ignore) { 1.120 + byte[] data = attr.info; 1.121 + int i = 0; 1.122 + int j = 0; 1.123 + print(" "); 1.124 + try { 1.125 + print(attr.getName(constant_pool)); 1.126 + } catch (ConstantPoolException e) { 1.127 + report(e); 1.128 + print("attribute name = #" + attr.attribute_name_index); 1.129 + } 1.130 + print(": "); 1.131 + println("length = 0x" + toHex(attr.info.length)); 1.132 + 1.133 + print(" "); 1.134 + 1.135 + while (i < data.length) { 1.136 + print(toHex(data[i], 2)); 1.137 + 1.138 + j++; 1.139 + if (j == 16) { 1.140 + println(); 1.141 + print(" "); 1.142 + j = 0; 1.143 + } else { 1.144 + print(" "); 1.145 + } 1.146 + i++; 1.147 + } 1.148 + println(); 1.149 + return null; 1.150 + } 1.151 + 1.152 + public Void visitAnnotationDefault(AnnotationDefault_attribute attr, Void ignore) { 1.153 + println(" AnnotationDefault: "); 1.154 + print(" default_value: "); 1.155 + annotationWriter.write(attr.default_value); 1.156 + return null; 1.157 + } 1.158 + 1.159 + public Void visitCharacterRangeTable(CharacterRangeTable_attribute attr, Void ignore) { 1.160 + print(" CharacterRangeTable: "); 1.161 + for (int i = 0; i < attr.character_range_table.length; i++) { 1.162 + CharacterRangeTable_attribute.Entry e = attr.character_range_table[i]; 1.163 + print(" " + e.start_pc + ", " + 1.164 + e.end_pc + ", " + 1.165 + Integer.toHexString(e.character_range_start) + ", " + 1.166 + Integer.toHexString(e.character_range_end) + ", " + 1.167 + Integer.toHexString(e.flags) + 1.168 + "\t// "); 1.169 + print(e.start_pc + ", " + 1.170 + e.end_pc + ", " + 1.171 + (e.character_range_start >> 10) + ":" + (e.character_range_start & 0x3ff) + ", " + 1.172 + (e.character_range_end >> 10) + ":" + (e.character_range_end & 0x3ff)); 1.173 + if ((e.flags & CharacterRangeTable_attribute.CRT_STATEMENT) != 0) 1.174 + print(", statement"); 1.175 + if ((e.flags & CharacterRangeTable_attribute.CRT_BLOCK) != 0) 1.176 + print(", block"); 1.177 + if ((e.flags & CharacterRangeTable_attribute.CRT_ASSIGNMENT) != 0) 1.178 + print(", assignment"); 1.179 + if ((e.flags & CharacterRangeTable_attribute.CRT_FLOW_CONTROLLER) != 0) 1.180 + print(", flow-controller"); 1.181 + if ((e.flags & CharacterRangeTable_attribute.CRT_FLOW_TARGET) != 0) 1.182 + print(", flow-target"); 1.183 + if ((e.flags & CharacterRangeTable_attribute.CRT_INVOKE) != 0) 1.184 + print(", invoke"); 1.185 + if ((e.flags & CharacterRangeTable_attribute.CRT_CREATE) != 0) 1.186 + print(", create"); 1.187 + if ((e.flags & CharacterRangeTable_attribute.CRT_BRANCH_TRUE) != 0) 1.188 + print(", branch-true"); 1.189 + if ((e.flags & CharacterRangeTable_attribute.CRT_BRANCH_FALSE) != 0) 1.190 + print(", branch-false"); 1.191 + 1.192 + 1.193 + 1.194 + } 1.195 + return null; 1.196 + } 1.197 + 1.198 + public Void visitCode(Code_attribute attr, Void ignore) { 1.199 + codeWriter.write(attr, constant_pool); 1.200 + println(); 1.201 + return null; 1.202 + } 1.203 + 1.204 + public Void visitCompilationID(CompilationID_attribute attr, Void ignore) { 1.205 + constantWriter.write(attr.compilationID_index); 1.206 + return null; 1.207 + } 1.208 + 1.209 + public Void visitConstantValue(ConstantValue_attribute attr, Void ignore) { 1.210 + if (options.compat) // BUG 6622216 javap names some attributes incorrectly 1.211 + print(" Constant value: "); 1.212 + else 1.213 + print(" ConstantValue: "); 1.214 + constantWriter.write(attr.constantvalue_index); 1.215 + if (!options.compat) // BUG 6622232 javap gets whitespace confused 1.216 + println(); 1.217 + return null; 1.218 + } 1.219 + 1.220 + public Void visitDeprecated(Deprecated_attribute attr, Void ignore) { 1.221 + if (!(options.compat && owner instanceof Field)) // BUG 6622232 javap gets whitespace confused 1.222 + print(" "); 1.223 + println("Deprecated: true"); 1.224 + return null; 1.225 + } 1.226 + 1.227 + public Void visitEnclosingMethod(EnclosingMethod_attribute attr, Void ignore) { 1.228 + print(" EnclosingMethod: #" + attr.class_index + ".#" + attr.method_index 1.229 + + "\t// " + getJavaClassName(attr)); 1.230 + if (attr.method_index != 0) 1.231 + print("." + getMethodName(attr)); 1.232 + println(); 1.233 + return null; 1.234 + } 1.235 + 1.236 + private String getJavaClassName(EnclosingMethod_attribute a) { 1.237 + try { 1.238 + return getJavaName(a.getClassName(constant_pool)); 1.239 + } catch (ConstantPoolException e) { 1.240 + return report(e); 1.241 + } 1.242 + } 1.243 + 1.244 + private String getMethodName(EnclosingMethod_attribute a) { 1.245 + try { 1.246 + return a.getMethodName(constant_pool); 1.247 + } catch (ConstantPoolException e) { 1.248 + return report(e); 1.249 + } 1.250 + } 1.251 + 1.252 + public Void visitExceptions(Exceptions_attribute attr, Void ignore) { 1.253 + println(" Exceptions: "); 1.254 + print(" throws "); 1.255 + for (int i = 0; i < attr.number_of_exceptions; i++) { 1.256 + if (i > 0) 1.257 + print(", "); 1.258 + print(getJavaException(attr, i)); 1.259 + } 1.260 + if (!options.compat) // BUG 6622232 javap gets whitespace confused 1.261 + println(); 1.262 + return null; 1.263 + } 1.264 + 1.265 + String getJavaException(Exceptions_attribute attr, int index) { 1.266 + try { 1.267 + return getJavaName(attr.getException(index, constant_pool)); 1.268 + } catch (ConstantPoolException e) { 1.269 + return report(e); 1.270 + } 1.271 + } 1.272 + 1.273 + public Void visitInnerClasses(InnerClasses_attribute attr, Void ignore) { 1.274 + boolean first = true; 1.275 + if (options.compat) { 1.276 + writeInnerClassHeader(); 1.277 + first = false; 1.278 + } 1.279 + for (int i = 0 ; i < attr.classes.length; i++) { 1.280 + InnerClasses_attribute.Info info = attr.classes[i]; 1.281 + //access 1.282 + AccessFlags access_flags = info.inner_class_access_flags; 1.283 + if (options.compat) { 1.284 + // BUG 6622215: javap ignores certain relevant access flags 1.285 + access_flags = access_flags.ignore(ACC_STATIC | ACC_PROTECTED | ACC_PRIVATE | ACC_INTERFACE | ACC_SYNTHETIC | ACC_ENUM); 1.286 + // BUG 6622232: javap gets whitespace confused 1.287 + print(" "); 1.288 + } 1.289 + if (options.checkAccess(access_flags)) { 1.290 + if (first) { 1.291 + writeInnerClassHeader(); 1.292 + first = false; 1.293 + } 1.294 + if (!options.compat) // BUG 6622232: javap gets whitespace confused 1.295 + print(" "); 1.296 + for (String name: access_flags.getInnerClassModifiers()) 1.297 + print(name + " "); 1.298 + if (info.inner_name_index!=0) { 1.299 + print("#" + info.inner_name_index + "= "); 1.300 + } 1.301 + print("#" + info.inner_class_info_index); 1.302 + if (info.outer_class_info_index != 0) { 1.303 + print(" of #" + info.outer_class_info_index); 1.304 + } 1.305 + print("; //"); 1.306 + if (info.inner_name_index != 0) { 1.307 + print(getInnerName(constant_pool, info) + "="); 1.308 + } 1.309 + constantWriter.write(info.inner_class_info_index); 1.310 + if (info.outer_class_info_index != 0) { 1.311 + print(" of "); 1.312 + constantWriter.write(info.outer_class_info_index); 1.313 + } 1.314 + println(); 1.315 + } 1.316 + } 1.317 + return null; 1.318 + } 1.319 + 1.320 + String getInnerName(ConstantPool constant_pool, InnerClasses_attribute.Info info) { 1.321 + try { 1.322 + return info.getInnerName(constant_pool); 1.323 + } catch (ConstantPoolException e) { 1.324 + return report(e); 1.325 + } 1.326 + } 1.327 + 1.328 + private void writeInnerClassHeader() { 1.329 + print(" "); 1.330 + if (options.compat) // BUG 6622216: javap names some attributes incorrectly 1.331 + print("InnerClass"); 1.332 + else 1.333 + print("InnerClasses"); 1.334 + println(": "); 1.335 + } 1.336 + 1.337 + public Void visitLineNumberTable(LineNumberTable_attribute attr, Void ignore) { 1.338 + println(" LineNumberTable: "); 1.339 + for (LineNumberTable_attribute.Entry entry: attr.line_number_table) { 1.340 + println(" line " + entry.line_number + ": " + entry.start_pc); 1.341 + } 1.342 + return null; 1.343 + } 1.344 + 1.345 + public Void visitLocalVariableTable(LocalVariableTable_attribute attr, Void ignore) { 1.346 + println(" LocalVariableTable: "); 1.347 + println(" Start Length Slot Name Signature"); 1.348 + 1.349 + for (LocalVariableTable_attribute.Entry entry : attr.local_variable_table) { 1.350 + Formatter formatter = new Formatter(); 1.351 + println(formatter.format("%8d %7d %5d %5s %s", 1.352 + entry.start_pc, entry.length, entry.index, 1.353 + constantWriter.stringValue(entry.name_index), 1.354 + constantWriter.stringValue(entry.descriptor_index))); 1.355 + } 1.356 + return null; 1.357 + } 1.358 + 1.359 + public Void visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, Void ignore) { 1.360 + println(" LocalVariableTypeTable: "); 1.361 + println(" Start Length Slot Name Signature"); 1.362 + 1.363 + for (LocalVariableTypeTable_attribute.Entry entry : attr.local_variable_table) { 1.364 + Formatter formatter = new Formatter(); 1.365 + println(formatter.format("%8d %7d %5d %5s %s", 1.366 + entry.start_pc, entry.length, entry.index, 1.367 + constantWriter.stringValue(entry.name_index), 1.368 + constantWriter.stringValue(entry.signature_index))); 1.369 + } 1.370 + return null; 1.371 + } 1.372 + 1.373 + public Void visitModule(Module_attribute attr, Void ignore) { 1.374 + println(" Module: #" + attr.module_name + "\t// " + getModuleName(attr)); 1.375 + return null; 1.376 + } 1.377 + 1.378 + String getModuleName(Module_attribute attr) { 1.379 + try { 1.380 + return attr.getModuleName(constant_pool); 1.381 + } catch (ConstantPoolException e) { 1.382 + return report(e); 1.383 + } 1.384 + } 1.385 + 1.386 + public Void visitModuleExportTable(ModuleExportTable_attribute attr, Void ignore) { 1.387 + println(" ModuleExportTable:"); 1.388 + println(" Types: (" + attr.export_type_table.length + ")"); 1.389 + for (int i = 0; i < attr.export_type_table.length; i++) { 1.390 + println(" #" + attr.export_type_table[i] + "\t// " + getExportTypeName(attr, i)); 1.391 + } 1.392 + return null; 1.393 + } 1.394 + 1.395 + String getExportTypeName(ModuleExportTable_attribute attr, int index) { 1.396 + try { 1.397 + return attr.getExportTypeName(index, constant_pool); 1.398 + } catch (ConstantPoolException e) { 1.399 + return report(e); 1.400 + } 1.401 + } 1.402 + 1.403 + public Void visitModuleMemberTable(ModuleMemberTable_attribute attr, Void ignore) { 1.404 + println(" ModuleMemberTable:"); 1.405 + println(" Packages: (" + attr.package_member_table.length + ")"); 1.406 + for (int i = 0; i < attr.package_member_table.length; i++) { 1.407 + println(" #" + attr.package_member_table[i] + "\t// " + getPackageMemberName(attr, i)); 1.408 + } 1.409 + return null; 1.410 + } 1.411 + 1.412 + String getPackageMemberName(ModuleMemberTable_attribute attr, int index) { 1.413 + try { 1.414 + return attr.getPackageMemberName(index, constant_pool); 1.415 + } catch (ConstantPoolException e) { 1.416 + return report(e); 1.417 + } 1.418 + } 1.419 + 1.420 + public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, Void ignore) { 1.421 + println(" RuntimeVisibleAnnotations: "); 1.422 + for (int i = 0; i < attr.annotations.length; i++) { 1.423 + print(" " + i + ": "); 1.424 + annotationWriter.write(attr.annotations[i]); 1.425 + println(); 1.426 + } 1.427 + return null; 1.428 + } 1.429 + 1.430 + public Void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, Void ignore) { 1.431 + println(" RuntimeInvisibleAnnotations: "); 1.432 + for (int i = 0; i < attr.annotations.length; i++) { 1.433 + print(" " + i + ": "); 1.434 + annotationWriter.write(attr.annotations[i]); 1.435 + println(); 1.436 + } 1.437 + return null; 1.438 + } 1.439 + 1.440 + public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, Void ignore) { 1.441 + println(" RuntimeVisibleParameterAnnotations: "); 1.442 + for (int param = 0; param < attr.parameter_annotations.length; param++) { 1.443 + println(" parameter " + param + ": "); 1.444 + for (int i = 0; i < attr.parameter_annotations[param].length; i++) { 1.445 + print(" " + i + ": "); 1.446 + annotationWriter.write(attr.parameter_annotations[param][i]); 1.447 + println(); 1.448 + } 1.449 + } 1.450 + return null; 1.451 + } 1.452 + 1.453 + public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, Void ignore) { 1.454 + println(" RuntimeInvisibleParameterAnnotations: "); 1.455 + for (int param = 0; param < attr.parameter_annotations.length; param++) { 1.456 + println(" " + param + ": "); 1.457 + for (int i = 0; i < attr.parameter_annotations[param].length; i++) { 1.458 + print(" " + i + ": "); 1.459 + annotationWriter.write(attr.parameter_annotations[param][i]); 1.460 + println(); 1.461 + } 1.462 + } 1.463 + return null; 1.464 + } 1.465 + 1.466 + public Void visitSignature(Signature_attribute attr, Void ignore) { 1.467 + println(" Signature: #" + attr.signature_index + "\t// " + getSignature(attr)); 1.468 + return null; 1.469 + } 1.470 + 1.471 + String getSignature(Signature_attribute info) { 1.472 + try { 1.473 + return info.getSignature(constant_pool); 1.474 + } catch (ConstantPoolException e) { 1.475 + return report(e); 1.476 + } 1.477 + } 1.478 + 1.479 + public Void visitSourceDebugExtension(SourceDebugExtension_attribute attr, Void ignore) { 1.480 + println(" SourceDebugExtension: " + attr.getValue()); 1.481 + return null; 1.482 + } 1.483 + 1.484 + public Void visitSourceFile(SourceFile_attribute attr, Void ignore) { 1.485 + println(" SourceFile: \"" + getSourceFile(attr) + "\""); 1.486 + return null; 1.487 + } 1.488 + 1.489 + private String getSourceFile(SourceFile_attribute attr) { 1.490 + try { 1.491 + return attr.getSourceFile(constant_pool); 1.492 + } catch (ConstantPoolException e) { 1.493 + return report(e); 1.494 + } 1.495 + } 1.496 + 1.497 + public Void visitSourceID(SourceID_attribute attr, Void ignore) { 1.498 + constantWriter.write(attr.sourceID_index); 1.499 + return null; 1.500 + } 1.501 + 1.502 + public Void visitStackMap(StackMap_attribute attr, Void ignore) { 1.503 + println(" StackMap: number_of_entries = " + attr.number_of_entries); 1.504 + 1.505 + StackMapTableWriter w = new StackMapTableWriter(); 1.506 + for (StackMapTable_attribute.stack_map_frame entry : attr.entries) { 1.507 + w.write(entry); 1.508 + } 1.509 + println(); 1.510 + return null; 1.511 + } 1.512 + 1.513 + public Void visitStackMapTable(StackMapTable_attribute attr, Void ignore) { 1.514 + println(" StackMapTable: number_of_entries = " + attr.number_of_entries); 1.515 + 1.516 + StackMapTableWriter w = new StackMapTableWriter(); 1.517 + for (StackMapTable_attribute.stack_map_frame entry : attr.entries) { 1.518 + w.write(entry); 1.519 + } 1.520 + println(); 1.521 + return null; 1.522 + } 1.523 + 1.524 + class StackMapTableWriter // also handles CLDC StackMap attributes 1.525 + implements StackMapTable_attribute.stack_map_frame.Visitor<Void,Void> { 1.526 + public void write(StackMapTable_attribute.stack_map_frame frame) { 1.527 + frame.accept(this, null); 1.528 + } 1.529 + 1.530 + public Void visit_same_frame(StackMapTable_attribute.same_frame frame, Void p) { 1.531 + printHeader(frame); 1.532 + println(" /* same */"); 1.533 + return null; 1.534 + } 1.535 + 1.536 + public Void visit_same_locals_1_stack_item_frame(StackMapTable_attribute.same_locals_1_stack_item_frame frame, Void p) { 1.537 + printHeader(frame); 1.538 + println(" /* same_locals_1_stack_item */"); 1.539 + printMap("stack", frame.stack); 1.540 + return null; 1.541 + } 1.542 + 1.543 + public Void visit_same_locals_1_stack_item_frame_extended(StackMapTable_attribute.same_locals_1_stack_item_frame_extended frame, Void p) { 1.544 + printHeader(frame); 1.545 + println(" /* same_locals_1_stack_item_frame_extended */"); 1.546 + println(" offset_delta = " + frame.offset_delta); 1.547 + printMap("stack", frame.stack); 1.548 + return null; 1.549 + } 1.550 + 1.551 + public Void visit_chop_frame(StackMapTable_attribute.chop_frame frame, Void p) { 1.552 + printHeader(frame); 1.553 + println(" /* chop */"); 1.554 + println(" offset_delta = " + frame.offset_delta); 1.555 + return null; 1.556 + } 1.557 + 1.558 + public Void visit_same_frame_extended(StackMapTable_attribute.same_frame_extended frame, Void p) { 1.559 + printHeader(frame); 1.560 + println(" /* same_frame_extended */"); 1.561 + println(" offset_delta = " + frame.offset_delta); 1.562 + return null; 1.563 + } 1.564 + 1.565 + public Void visit_append_frame(StackMapTable_attribute.append_frame frame, Void p) { 1.566 + printHeader(frame); 1.567 + println(" /* append */"); 1.568 + println(" offset_delta = " + frame.offset_delta); 1.569 + printMap("locals", frame.locals); 1.570 + return null; 1.571 + } 1.572 + 1.573 + public Void visit_full_frame(StackMapTable_attribute.full_frame frame, Void p) { 1.574 + printHeader(frame); 1.575 + if (frame instanceof StackMap_attribute.stack_map_frame) { 1.576 + println(" offset = " + frame.offset_delta); 1.577 + } else { 1.578 + println(" /* full_frame */"); 1.579 + println(" offset_delta = " + frame.offset_delta); 1.580 + } 1.581 + printMap("locals", frame.locals); 1.582 + printMap("stack", frame.stack); 1.583 + return null; 1.584 + } 1.585 + 1.586 + void printHeader(StackMapTable_attribute.stack_map_frame frame) { 1.587 + print(" frame_type = " + frame.frame_type); 1.588 + } 1.589 + 1.590 + void printMap(String name, StackMapTable_attribute.verification_type_info[] map) { 1.591 + print(" " + name + " = ["); 1.592 + for (int i = 0; i < map.length; i++) { 1.593 + StackMapTable_attribute.verification_type_info info = map[i]; 1.594 + int tag = info.tag; 1.595 + switch (tag) { 1.596 + case StackMapTable_attribute.verification_type_info.ITEM_Object: 1.597 + print(" "); 1.598 + constantWriter.write(((StackMapTable_attribute.Object_variable_info) info).cpool_index); 1.599 + break; 1.600 + case StackMapTable_attribute.verification_type_info.ITEM_Uninitialized: 1.601 + print(" " + mapTypeName(tag)); 1.602 + print(" " + ((StackMapTable_attribute.Uninitialized_variable_info) info).offset); 1.603 + break; 1.604 + default: 1.605 + print(" " + mapTypeName(tag)); 1.606 + } 1.607 + print(i == (map.length - 1) ? " " : ","); 1.608 + } 1.609 + println("]"); 1.610 + } 1.611 + 1.612 + String mapTypeName(int tag) { 1.613 + switch (tag) { 1.614 + case StackMapTable_attribute.verification_type_info.ITEM_Top: 1.615 + return "top"; 1.616 + 1.617 + case StackMapTable_attribute.verification_type_info.ITEM_Integer: 1.618 + return "int"; 1.619 + 1.620 + case StackMapTable_attribute.verification_type_info.ITEM_Float: 1.621 + return "float"; 1.622 + 1.623 + case StackMapTable_attribute.verification_type_info.ITEM_Long: 1.624 + return "long"; 1.625 + 1.626 + case StackMapTable_attribute.verification_type_info.ITEM_Double: 1.627 + return "double"; 1.628 + 1.629 + case StackMapTable_attribute.verification_type_info.ITEM_Null: 1.630 + return "null"; 1.631 + 1.632 + case StackMapTable_attribute.verification_type_info.ITEM_UninitializedThis: 1.633 + return "this"; 1.634 + 1.635 + case StackMapTable_attribute.verification_type_info.ITEM_Object: 1.636 + return "CP"; 1.637 + 1.638 + case StackMapTable_attribute.verification_type_info.ITEM_Uninitialized: 1.639 + return "uninitialized"; 1.640 + 1.641 + default: 1.642 + report("unrecognized verification_type_info tag: " + tag); 1.643 + return "[tag:" + tag + "]"; 1.644 + } 1.645 + } 1.646 + } 1.647 + 1.648 + public Void visitSynthetic(Synthetic_attribute attr, Void ignore) { 1.649 + println("Synthetic: true"); 1.650 + return null; 1.651 + } 1.652 + 1.653 + static String getJavaName(String name) { 1.654 + return name.replace('/', '.'); 1.655 + } 1.656 + 1.657 + String toHex(byte b, int w) { 1.658 + if (options.compat) // BUG 6622260: javap prints negative bytes incorrectly in hex 1.659 + return toHex((int) b, w); 1.660 + else 1.661 + return toHex(b & 0xff, w); 1.662 + } 1.663 + 1.664 + static String toHex(int i) { 1.665 + return Integer.toString(i, 16).toUpperCase(); 1.666 + } 1.667 + 1.668 + static String toHex(int i, int w) { 1.669 + String s = Integer.toHexString(i).toUpperCase(); 1.670 + while (s.length() < w) 1.671 + s = "0" + s; 1.672 + return s.toUpperCase(); 1.673 + } 1.674 + 1.675 + private AnnotationWriter annotationWriter; 1.676 + private CodeWriter codeWriter; 1.677 + private ConstantWriter constantWriter; 1.678 + private Options options; 1.679 + 1.680 + private ConstantPool constant_pool; 1.681 + private Object owner; 1.682 +}