langtools/src/share/classes/com/sun/tools/javap/StackMapWriter.java
author jjg
Tue, 19 May 2009 13:53:00 -0700
changeset 2980 f391c41bae7e
parent 2979 ea39317acd3d
child 5520 86e4b9a9da40
permissions -rw-r--r--
6843013: missing files in fix for 6824493 Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2979
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
     1
/*
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
     2
 * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
     4
 *
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    10
 *
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    15
 * accompanied this code).
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    16
 *
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    20
 *
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    23
 * have any questions.
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    24
 */
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    25
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    26
package com.sun.tools.javap;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    27
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    28
import com.sun.tools.classfile.AccessFlags;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    29
import java.util.HashMap;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    30
import java.util.Map;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    31
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    32
import com.sun.tools.classfile.Attribute;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    33
import com.sun.tools.classfile.Code_attribute;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    34
import com.sun.tools.classfile.ConstantPool;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    35
import com.sun.tools.classfile.ConstantPoolException;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    36
import com.sun.tools.classfile.Descriptor;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    37
import com.sun.tools.classfile.Descriptor.InvalidDescriptor;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    38
import com.sun.tools.classfile.Instruction;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    39
import com.sun.tools.classfile.Method;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    40
import com.sun.tools.classfile.StackMapTable_attribute;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    41
import com.sun.tools.classfile.StackMapTable_attribute.*;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    42
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    43
import static com.sun.tools.classfile.StackMapTable_attribute.verification_type_info.*;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    44
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    45
/**
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    46
 * Annotate instructions with stack map.
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    47
 *
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    48
 *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    49
 *  you write code that depends on this, you do so at your own risk.
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    50
 *  This code and its internal interfaces are subject to change or
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    51
 *  deletion without notice.</b>
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    52
 */
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    53
public class StackMapWriter extends InstructionDetailWriter {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    54
    static StackMapWriter instance(Context context) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    55
        StackMapWriter instance = context.get(StackMapWriter.class);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    56
        if (instance == null)
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    57
            instance = new StackMapWriter(context);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    58
        return instance;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    59
    }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    60
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    61
    protected StackMapWriter(Context context) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    62
        super(context);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    63
        context.put(StackMapWriter.class, this);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    64
        classWriter = ClassWriter.instance(context);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    65
    }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    66
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    67
    public void reset(Code_attribute attr) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    68
        setStackMap((StackMapTable_attribute) attr.attributes.get(Attribute.StackMapTable));
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    69
    }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    70
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    71
    void setStackMap(StackMapTable_attribute attr) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    72
        if (attr == null) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    73
            map = null;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    74
            return;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    75
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    76
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    77
        Method m = classWriter.getMethod();
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    78
        Descriptor d = m.descriptor;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    79
        String[] args;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    80
        try {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    81
            ConstantPool cp = classWriter.getClassFile().constant_pool;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    82
            String argString = d.getParameterTypes(cp);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    83
            args = argString.substring(1, argString.length() - 1).split("[, ]+");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    84
        } catch (ConstantPoolException e) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    85
            return;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    86
        } catch (InvalidDescriptor e) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    87
            return;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    88
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    89
        boolean isStatic = m.access_flags.is(AccessFlags.ACC_STATIC);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    90
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    91
        verification_type_info[] initialLocals = new verification_type_info[(isStatic ? 0 : 1) + args.length];
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    92
        if (!isStatic)
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    93
            initialLocals[0] = new CustomVerificationTypeInfo("this");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    94
        for (int i = 0; i < args.length; i++) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    95
            initialLocals[(isStatic ? 0 : 1) + i] =
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    96
                    new CustomVerificationTypeInfo(args[i].replace(".", "/"));
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    97
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    98
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    99
        map = new HashMap<Integer, StackMap>();
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   100
        StackMapBuilder builder = new StackMapBuilder();
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   101
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   102
        // using -1 as the pc for the initial frame effectively compensates for
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   103
        // the difference in behavior for the first stack map frame (where the
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   104
        // pc offset is just offset_delta) compared to subsequent frames (where
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   105
        // the pc offset is always offset_delta+1).
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   106
        int pc = -1;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   107
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   108
        map.put(pc, new StackMap(initialLocals, empty));
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   109
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   110
        for (int i = 0; i < attr.entries.length; i++)
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   111
            pc = attr.entries[i].accept(builder, pc);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   112
    }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   113
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   114
    public void writeInitialDetails() {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   115
        writeDetails(-1);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   116
    }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   117
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   118
    public void writeDetails(Instruction instr) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   119
        writeDetails(instr.getPC());
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   120
    }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   121
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   122
    private void writeDetails(int pc) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   123
        if (map == null)
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   124
            return;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   125
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   126
        StackMap m = map.get(pc);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   127
        if (m != null) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   128
            print("StackMap locals: ", m.locals);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   129
            print("StackMap stack: ", m.stack);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   130
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   131
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   132
    }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   133
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   134
    void print(String label, verification_type_info[] entries) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   135
        print(label);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   136
        for (int i = 0; i < entries.length; i++) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   137
            print(" ");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   138
            print(entries[i]);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   139
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   140
        println();
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   141
    }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   142
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   143
    void print(verification_type_info entry) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   144
        if (entry == null) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   145
            print("ERROR");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   146
            return;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   147
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   148
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   149
        switch (entry.tag) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   150
            case -1:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   151
                print(((CustomVerificationTypeInfo) entry).text);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   152
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   153
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   154
            case ITEM_Top:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   155
                print("top");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   156
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   157
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   158
            case ITEM_Integer:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   159
                print("int");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   160
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   161
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   162
            case ITEM_Float:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   163
                print("float");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   164
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   165
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   166
            case ITEM_Long:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   167
                print("long");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   168
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   169
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   170
            case ITEM_Double:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   171
                print("double");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   172
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   173
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   174
            case ITEM_Null:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   175
                print("null");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   176
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   177
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   178
            case ITEM_UninitializedThis:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   179
                print("uninit_this");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   180
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   181
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   182
            case ITEM_Object:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   183
                try {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   184
                    ConstantPool cp = classWriter.getClassFile().constant_pool;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   185
                    ConstantPool.CONSTANT_Class_info class_info = cp.getClassInfo(((Object_variable_info) entry).cpool_index);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   186
                    print(cp.getUTF8Value(class_info.name_index));
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   187
                } catch (ConstantPoolException e) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   188
                    print("??");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   189
                }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   190
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   191
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   192
            case ITEM_Uninitialized:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   193
                print(((Uninitialized_variable_info) entry).offset);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   194
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   195
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   196
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   197
    }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   198
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   199
    private Map<Integer, StackMap> map;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   200
    private ClassWriter classWriter;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   201
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   202
    class StackMapBuilder
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   203
            implements StackMapTable_attribute.stack_map_frame.Visitor<Integer, Integer> {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   204
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   205
        public Integer visit_same_frame(same_frame frame, Integer pc) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   206
            int new_pc = pc + frame.getOffsetDelta() + 1;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   207
            StackMap m = map.get(pc);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   208
            assert (m != null);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   209
            map.put(new_pc, m);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   210
            return new_pc;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   211
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   212
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   213
        public Integer visit_same_locals_1_stack_item_frame(same_locals_1_stack_item_frame frame, Integer pc) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   214
            int new_pc = pc + frame.getOffsetDelta() + 1;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   215
            StackMap prev = map.get(pc);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   216
            assert (prev != null);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   217
            StackMap m = new StackMap(prev.locals, frame.stack);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   218
            map.put(new_pc, m);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   219
            return new_pc;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   220
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   221
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   222
        public Integer visit_same_locals_1_stack_item_frame_extended(same_locals_1_stack_item_frame_extended frame, Integer pc) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   223
            int new_pc = pc + frame.getOffsetDelta() + 1;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   224
            StackMap prev = map.get(pc);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   225
            assert (prev != null);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   226
            StackMap m = new StackMap(prev.locals, frame.stack);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   227
            map.put(new_pc, m);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   228
            return new_pc;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   229
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   230
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   231
        public Integer visit_chop_frame(chop_frame frame, Integer pc) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   232
            int new_pc = pc + frame.getOffsetDelta() + 1;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   233
            StackMap prev = map.get(pc);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   234
            assert (prev != null);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   235
            int k = 251 - frame.frame_type;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   236
            verification_type_info[] new_locals = new verification_type_info[prev.locals.length - k];
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   237
            System.arraycopy(prev.locals, 0, new_locals, 0, new_locals.length);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   238
            StackMap m = new StackMap(new_locals, empty);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   239
            map.put(new_pc, m);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   240
            return new_pc;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   241
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   242
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   243
        public Integer visit_same_frame_extended(same_frame_extended frame, Integer pc) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   244
            int new_pc = pc + frame.getOffsetDelta();
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   245
            StackMap m = map.get(pc);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   246
            assert (m != null);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   247
            map.put(new_pc, m);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   248
            return new_pc;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   249
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   250
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   251
        public Integer visit_append_frame(append_frame frame, Integer pc) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   252
            int new_pc = pc + frame.getOffsetDelta() + 1;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   253
            StackMap prev = map.get(pc);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   254
            assert (prev != null);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   255
            verification_type_info[] new_locals = new verification_type_info[prev.locals.length + frame.locals.length];
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   256
            System.arraycopy(prev.locals, 0, new_locals, 0, prev.locals.length);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   257
            System.arraycopy(frame.locals, 0, new_locals, prev.locals.length, frame.locals.length);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   258
            StackMap m = new StackMap(new_locals, empty);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   259
            map.put(new_pc, m);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   260
            return new_pc;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   261
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   262
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   263
        public Integer visit_full_frame(full_frame frame, Integer pc) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   264
            int new_pc = pc + frame.getOffsetDelta() + 1;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   265
            StackMap m = new StackMap(frame.locals, frame.stack);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   266
            map.put(new_pc, m);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   267
            return new_pc;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   268
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   269
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   270
    }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   271
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   272
    class StackMap {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   273
        StackMap(verification_type_info[] locals, verification_type_info[] stack) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   274
            this.locals = locals;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   275
            this.stack = stack;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   276
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   277
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   278
        private final verification_type_info[] locals;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   279
        private final verification_type_info[] stack;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   280
    }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   281
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   282
    class CustomVerificationTypeInfo extends verification_type_info {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   283
        public CustomVerificationTypeInfo(String text) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   284
            super(-1);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   285
            this.text = text;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   286
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   287
        private String text;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   288
    }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   289
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   290
    private final verification_type_info[] empty = { };
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   291
}