src/share/classes/com/sun/tools/javap/AttributeWriter.java

Tue, 03 Jun 2008 13:26:47 -0700

author
jjg
date
Tue, 03 Jun 2008 13:26:47 -0700
changeset 46
7708bd6d800d
child 52
3cb4fb6e0720
permissions
-rw-r--r--

4075303: Use javap to enquire aboput a specific inner class
4348375: Javap is not internationalized
4459541: "javap -l" shows line numbers as signed short; they should be unsigned
4501660: change diagnostic of -help as 'print this help message and exit'
4776241: unused source file in javap...
4870651: javap should recognize generics, varargs, enum
4876942: javap invoked without args does not print help screen
4880663: javap could output whitespace between class name and opening brace
4975569: javap doesn't print new flag bits
6271787: javap dumps LocalVariableTypeTable attribute in hex, needs to print a table
6305779: javap: support annotations
6439940: Clean up javap implementation
6469569: wrong check of searchpath in JavapEnvironment
6474890: javap does not open .zip files in -classpath
6587786: Javap throws error : "ERROR:Could not find <classname>" for JRE classes
6622215: javap ignores certain relevant access flags
6622216: javap names some attributes incorrectly
6622232: javap gets whitespace confused
6622260: javap prints negative bytes incorrectly in hex
Reviewed-by: ksrini

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

mercurial