langtools/src/jdk.jdeps/share/classes/com/sun/tools/javap/StackMapWriter.java
author mchung
Wed, 27 May 2015 13:25:18 -0700
changeset 30846 2b3f379840f0
parent 25874 langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/StackMapWriter.java@83c19f00452c
permissions -rw-r--r--
8074432: Move jdeps and javap to jdk.jdeps module Reviewed-by: jjg, alanb, erikj
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
/*
16560
c6c7f0c26568 8010361: fix some langtools findbugs issues
jjg
parents: 14049
diff changeset
     2
 * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
2979
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
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2979
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2979
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2979
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2979
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
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2979
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2979
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2979
diff changeset
    23
 * questions.
2979
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
14049
3207422a0f9b 7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac
jjg
parents: 5847
diff changeset
    28
import java.util.Arrays;
2979
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
14049
3207422a0f9b 7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac
jjg
parents: 5847
diff changeset
    32
import com.sun.tools.classfile.AccessFlags;
2979
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    33
import com.sun.tools.classfile.Attribute;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    34
import com.sun.tools.classfile.Code_attribute;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    35
import com.sun.tools.classfile.ConstantPool;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    36
import com.sun.tools.classfile.ConstantPoolException;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    37
import com.sun.tools.classfile.Descriptor;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    38
import com.sun.tools.classfile.Descriptor.InvalidDescriptor;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    39
import com.sun.tools.classfile.Instruction;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    40
import com.sun.tools.classfile.Method;
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
import com.sun.tools.classfile.StackMapTable_attribute.*;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    43
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    44
import static com.sun.tools.classfile.StackMapTable_attribute.verification_type_info.*;
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
/**
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    47
 * Annotate instructions with stack map.
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    48
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    49
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    50
 *  If you write code that depends on this, you do so at your own risk.
2979
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    51
 *  This code and its internal interfaces are subject to change or
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    52
 *  deletion without notice.</b>
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    53
 */
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    54
public class StackMapWriter extends InstructionDetailWriter {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    55
    static StackMapWriter instance(Context context) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    56
        StackMapWriter instance = context.get(StackMapWriter.class);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    57
        if (instance == null)
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    58
            instance = new StackMapWriter(context);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    59
        return instance;
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
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    62
    protected StackMapWriter(Context context) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    63
        super(context);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    64
        context.put(StackMapWriter.class, this);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    65
        classWriter = ClassWriter.instance(context);
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
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    68
    public void reset(Code_attribute attr) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    69
        setStackMap((StackMapTable_attribute) attr.attributes.get(Attribute.StackMapTable));
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
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    72
    void setStackMap(StackMapTable_attribute attr) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    73
        if (attr == null) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    74
            map = null;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    75
            return;
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
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    78
        Method m = classWriter.getMethod();
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    79
        Descriptor d = m.descriptor;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    80
        String[] args;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    81
        try {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    82
            ConstantPool cp = classWriter.getClassFile().constant_pool;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    83
            String argString = d.getParameterTypes(cp);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    84
            args = argString.substring(1, argString.length() - 1).split("[, ]+");
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16560
diff changeset
    85
        } catch (ConstantPoolException | InvalidDescriptor e) {
2979
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    86
            return;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    87
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    88
        boolean isStatic = m.access_flags.is(AccessFlags.ACC_STATIC);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    89
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    90
        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
    91
        if (!isStatic)
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    92
            initialLocals[0] = new CustomVerificationTypeInfo("this");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    93
        for (int i = 0; i < args.length; i++) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    94
            initialLocals[(isStatic ? 0 : 1) + i] =
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    95
                    new CustomVerificationTypeInfo(args[i].replace(".", "/"));
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    96
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    97
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
    98
        map = new HashMap<>();
2979
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    99
        StackMapBuilder builder = new StackMapBuilder();
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   100
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   101
        // 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
   102
        // 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
   103
        // pc offset is just offset_delta) compared to subsequent frames (where
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   104
        // the pc offset is always offset_delta+1).
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   105
        int pc = -1;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   106
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   107
        map.put(pc, new StackMap(initialLocals, empty));
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   108
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   109
        for (int i = 0; i < attr.entries.length; i++)
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   110
            pc = attr.entries[i].accept(builder, pc);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   111
    }
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
    public void writeInitialDetails() {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   114
        writeDetails(-1);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   115
    }
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
    public void writeDetails(Instruction instr) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   118
        writeDetails(instr.getPC());
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   119
    }
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
    private void writeDetails(int pc) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   122
        if (map == null)
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   123
            return;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   124
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   125
        StackMap m = map.get(pc);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   126
        if (m != null) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   127
            print("StackMap locals: ", m.locals);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   128
            print("StackMap stack: ", m.stack);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   129
        }
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
    void print(String label, verification_type_info[] entries) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   134
        print(label);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   135
        for (int i = 0; i < entries.length; i++) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   136
            print(" ");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   137
            print(entries[i]);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   138
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   139
        println();
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   140
    }
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
    void print(verification_type_info entry) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   143
        if (entry == null) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   144
            print("ERROR");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   145
            return;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   146
        }
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
        switch (entry.tag) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   149
            case -1:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   150
                print(((CustomVerificationTypeInfo) entry).text);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   151
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   152
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   153
            case ITEM_Top:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   154
                print("top");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   155
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   156
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   157
            case ITEM_Integer:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   158
                print("int");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   159
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   160
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   161
            case ITEM_Float:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   162
                print("float");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   163
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   164
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   165
            case ITEM_Long:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   166
                print("long");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   167
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   168
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   169
            case ITEM_Double:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   170
                print("double");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   171
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   172
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   173
            case ITEM_Null:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   174
                print("null");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   175
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   176
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   177
            case ITEM_UninitializedThis:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   178
                print("uninit_this");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   179
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   180
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   181
            case ITEM_Object:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   182
                try {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   183
                    ConstantPool cp = classWriter.getClassFile().constant_pool;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   184
                    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
   185
                    print(cp.getUTF8Value(class_info.name_index));
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   186
                } catch (ConstantPoolException e) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   187
                    print("??");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   188
                }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   189
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   190
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   191
            case ITEM_Uninitialized:
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   192
                print(((Uninitialized_variable_info) entry).offset);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   193
                break;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   194
        }
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
    private Map<Integer, StackMap> map;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   199
    private ClassWriter classWriter;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   200
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   201
    class StackMapBuilder
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   202
            implements StackMapTable_attribute.stack_map_frame.Visitor<Integer, Integer> {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   203
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   204
        public Integer visit_same_frame(same_frame frame, Integer pc) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   205
            int new_pc = pc + frame.getOffsetDelta() + 1;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   206
            StackMap m = map.get(pc);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   207
            assert (m != null);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   208
            map.put(new_pc, m);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   209
            return new_pc;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   210
        }
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
        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
   213
            int new_pc = pc + frame.getOffsetDelta() + 1;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   214
            StackMap prev = map.get(pc);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   215
            assert (prev != null);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   216
            StackMap m = new StackMap(prev.locals, frame.stack);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   217
            map.put(new_pc, m);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   218
            return new_pc;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   219
        }
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
        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
   222
            int new_pc = pc + frame.getOffsetDelta() + 1;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   223
            StackMap prev = map.get(pc);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   224
            assert (prev != null);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   225
            StackMap m = new StackMap(prev.locals, frame.stack);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   226
            map.put(new_pc, m);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   227
            return new_pc;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   228
        }
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
        public Integer visit_chop_frame(chop_frame frame, Integer pc) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   231
            int new_pc = pc + frame.getOffsetDelta() + 1;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   232
            StackMap prev = map.get(pc);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   233
            assert (prev != null);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   234
            int k = 251 - frame.frame_type;
14049
3207422a0f9b 7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac
jjg
parents: 5847
diff changeset
   235
            verification_type_info[] new_locals = Arrays.copyOf(prev.locals, prev.locals.length - k);
2979
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   236
            StackMap m = new StackMap(new_locals, empty);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   237
            map.put(new_pc, m);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   238
            return new_pc;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   239
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   240
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   241
        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
   242
            int new_pc = pc + frame.getOffsetDelta();
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   243
            StackMap m = map.get(pc);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   244
            assert (m != null);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   245
            map.put(new_pc, m);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   246
            return new_pc;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   247
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   248
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   249
        public Integer visit_append_frame(append_frame frame, Integer pc) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   250
            int new_pc = pc + frame.getOffsetDelta() + 1;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   251
            StackMap prev = map.get(pc);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   252
            assert (prev != null);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   253
            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
   254
            System.arraycopy(prev.locals, 0, new_locals, 0, prev.locals.length);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   255
            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
   256
            StackMap m = new StackMap(new_locals, empty);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   257
            map.put(new_pc, m);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   258
            return new_pc;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   259
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   260
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   261
        public Integer visit_full_frame(full_frame frame, Integer pc) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   262
            int new_pc = pc + frame.getOffsetDelta() + 1;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   263
            StackMap m = new StackMap(frame.locals, frame.stack);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   264
            map.put(new_pc, m);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   265
            return new_pc;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   266
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   267
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
16560
c6c7f0c26568 8010361: fix some langtools findbugs issues
jjg
parents: 14049
diff changeset
   270
    static class StackMap {
2979
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   271
        StackMap(verification_type_info[] locals, verification_type_info[] stack) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   272
            this.locals = locals;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   273
            this.stack = stack;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   274
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   275
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   276
        private final verification_type_info[] locals;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   277
        private final verification_type_info[] stack;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   278
    }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   279
16560
c6c7f0c26568 8010361: fix some langtools findbugs issues
jjg
parents: 14049
diff changeset
   280
    static class CustomVerificationTypeInfo extends verification_type_info {
2979
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   281
        public CustomVerificationTypeInfo(String text) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   282
            super(-1);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   283
            this.text = text;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   284
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   285
        private String 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
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   288
    private final verification_type_info[] empty = { };
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   289
}