jdk/src/jdk.rmic/share/classes/sun/tools/asm/Instruction.java
author jcoomes
Wed, 10 Sep 2014 13:01:13 -0700
changeset 26842 5081db39f634
parent 25859 3317bb8137f4
permissions -rw-r--r--
8057824: methods to copy allocation context statistics Reviewed-by: mikael, jmasa, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
19226
d5febab8765d 8022479: clean up warnings from sun.tools.asm
smarks
parents: 5506
diff changeset
     2
 * Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.tools.asm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.tools.java.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.DataOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * An Java instruction
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * WARNING: The contents of this source file are not part of any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * supported API.  Code that depends on them does so at its own risk:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * they are subject to change or removal without notice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
class Instruction implements Constants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    long where;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    int pc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    int opc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    Object value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    Instruction next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
//JCOV
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    boolean flagCondInverted;        /* if true, the condition  is reversed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                                   relatively of source code */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    boolean flagNoCovered = false; /* if true, the command will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                                   ignored for coverage */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public Instruction(long where, int opc, Object value, boolean flagCondInverted) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        this.where = where;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        this.opc = opc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        this.flagCondInverted = flagCondInverted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public Instruction(boolean flagNoCovered, long where, int opc, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        this.where = where;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        this.opc = opc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        this.flagNoCovered = flagNoCovered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public Instruction(long where, int opc, boolean flagNoCovered) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        this.where = where;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        this.opc = opc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        this.flagNoCovered = flagNoCovered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
//end JCOV
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public Instruction(long where, int opc, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        this.where = where;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        this.opc = opc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * When deciding between a lookupswitch and a tableswitch, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * value is used in determining how much size increase is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * acceptable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public static final double SWITCHRATIO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        // Set SWITCHRATIO from the property javac.switchratio
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        // if it exists and is reasonable.  Otherwise, set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        // SWITCHRATIO to 1.5, meaning that we will accept a 1.5x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        // blowup (for the instruction) to use a tableswitch instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        // of a lookupswitch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        double ratio = 1.5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        String valStr = System.getProperty("javac.switchratio");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if (valStr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                double temp = Double.valueOf(valStr).doubleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                if (!(Double.isNaN(temp) || temp < 0.0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    ratio = temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            } catch (NumberFormatException ee) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        SWITCHRATIO = ratio;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Accessor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public int getOpcode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return pc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public Object getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public void setValue(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Optimize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    void optimize(Environment env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        switch (opc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
          case opc_istore: case opc_lstore: case opc_fstore:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
          case opc_dstore: case opc_astore:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            // Don't keep the LocalVariable info around, unless we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            // are actually going to generate a local variable table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            if ((value instanceof LocalVariable) && !env.debug_vars()) {
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 19226
diff changeset
   145
                value = ((LocalVariable)value).slot;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
          case opc_goto: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            Label lbl = (Label)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            value = lbl = lbl.getDestination();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            if (lbl == next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                // goto to the next instruction, obsolete
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                opc = opc_dead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            // We optimize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            //          goto Tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            //          ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            //    Tag:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            //          return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            // except when we're generating debuggable code.  When
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            // we're generating debuggable code, we leave it alone,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            // in order to provide better stepping behavior.  Consider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            // a method the end of which looks like this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            //          ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            //          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            //      }   // end of loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            //  }   // end of method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            // If we optimize the goto away, we'll be left with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            // single instruction (return) and the need to ascribe that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            // instruction to two source lines (the break statement and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            // the method's right curly).  Can't get there from here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            // Depending on which line-number ascription we choose, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            // stepping user will step directly from the break statement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            // back into the caller of the method (case 1) or from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            // statement that precedes the break statement to the method's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            // right curly (case 2).  Similarly, he'll be able to set a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            // breakpoint on the break statement (case 1) or the method's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            // right curly (case 2), but not on both.  Neither case 1 nor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            // case 2 is desirable.  .We want him to see both the break
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            // statement and the method's right curly when stepping,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            // and we want him to be able to set a breakpoint on either or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            // both.  So we suppress the optimization when generating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            // debuggable code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            // (Above notes from brucek@eng in JDK1.0.2, copied here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            //  by kelly.ohair@eng for JDK1.1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            // With the changes to allow -O and -g at the same time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            // I've changed the condition to be whether optimization is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            // on instead of the debugging flag being off.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            //     - david.stoutamire@eng for 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            if (lbl.next != null && env.opt()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                switch (lbl.next.opc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                  case opc_return:  case opc_ireturn: case opc_lreturn:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                  case opc_freturn: case opc_dreturn: case opc_areturn:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    // goto to return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    opc = lbl.next.opc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    value = lbl.next.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
          case opc_ifeq:   case opc_ifne:   case opc_ifgt:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
          case opc_ifge:   case opc_iflt:   case opc_ifle:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
          case opc_ifnull: case opc_ifnonnull:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            value = ((Label)value).getDestination();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            if (value == next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                // branch to next instruction, obsolete
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                opc = opc_pop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            if ((next.opc == opc_goto) && (value == next.next)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                // Conditional branch over goto, invert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                // Note that you can't invert all conditions, condition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                // results for float/double compares are not invertable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                switch (opc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                  case opc_ifeq:      opc = opc_ifne; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                  case opc_ifne:      opc = opc_ifeq; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                  case opc_iflt:      opc = opc_ifge; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                  case opc_ifle:      opc = opc_ifgt; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                  case opc_ifgt:      opc = opc_ifle; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                  case opc_ifge:      opc = opc_iflt; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                  case opc_ifnull:    opc = opc_ifnonnull; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                  case opc_ifnonnull: opc = opc_ifnull; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
//JCOV
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                flagCondInverted = !flagCondInverted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
//end JCOV
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                value = next.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                next.opc = opc_dead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
          case opc_if_acmpeq:   case opc_if_acmpne:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
          case opc_if_icmpeq:   case opc_if_icmpne:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
          case opc_if_icmpgt:   case opc_if_icmpge:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
          case opc_if_icmplt:   case opc_if_icmple:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            value = ((Label)value).getDestination();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            if (value == next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                // branch to next instruction, obsolete
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                opc = opc_pop2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            if ((next.opc == opc_goto) && (value == next.next)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                // Conditional branch over goto, invert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                switch (opc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                  case opc_if_acmpeq: opc = opc_if_acmpne; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                  case opc_if_acmpne: opc = opc_if_acmpeq; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                  case opc_if_icmpeq: opc = opc_if_icmpne; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                  case opc_if_icmpne: opc = opc_if_icmpeq; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                  case opc_if_icmpgt: opc = opc_if_icmple; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                  case opc_if_icmpge: opc = opc_if_icmplt; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                  case opc_if_icmplt: opc = opc_if_icmpge; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                  case opc_if_icmple: opc = opc_if_icmpgt; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
//JCOV
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                flagCondInverted = !flagCondInverted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
//end JCOV
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                value = next.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                next.opc = opc_dead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
          case opc_tableswitch:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
          case opc_lookupswitch: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            SwitchData sw = (SwitchData)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            sw.defaultLabel = sw.defaultLabel.getDestination();
19226
d5febab8765d 8022479: clean up warnings from sun.tools.asm
smarks
parents: 5506
diff changeset
   277
            for (Enumeration<Integer> e = sw.tab.keys() ; e.hasMoreElements() ; ) {
d5febab8765d 8022479: clean up warnings from sun.tools.asm
smarks
parents: 5506
diff changeset
   278
                Integer k = e.nextElement();
d5febab8765d 8022479: clean up warnings from sun.tools.asm
smarks
parents: 5506
diff changeset
   279
                Label lbl = sw.tab.get(k);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                sw.tab.put(k, lbl.getDestination());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            // Compute the approximate sizes of a tableswitch and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            // lookupswitch.  Decide which one we want to generate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            long range = (long)sw.maxValue - (long)sw.minValue + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            long entries = sw.tab.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            long tableSize = 4 + range;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            long lookupSize = 3 + 2 * entries;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            if (tableSize <= lookupSize * SWITCHRATIO) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                opc = opc_tableswitch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                opc = opc_lookupswitch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Collect constants into the constant table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    void collect(ConstantPool tab) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        switch (opc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
          case opc_istore:      case opc_lstore:        case opc_fstore:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
          case opc_dstore:      case opc_astore:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            if (value instanceof LocalVariable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                MemberDefinition field = ((LocalVariable)value).field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                tab.put(field.getName().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                tab.put(field.getType().getTypeSignature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
          case opc_new:                 case opc_putfield:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
          case opc_putstatic:           case opc_getfield:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
          case opc_getstatic:           case opc_invokevirtual:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
          case opc_invokespecial:       case opc_invokestatic:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
          case opc_invokeinterface:     case opc_instanceof:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
          case opc_checkcast:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            tab.put(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
          case opc_anewarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            tab.put(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
          case opc_multianewarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            tab.put(((ArrayData)value).type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
          case opc_ldc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
          case opc_ldc_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            if (value instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                int v = ((Integer)value).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                if ((v >= -1) && (v <= 5)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                    opc = opc_iconst_0 + v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                } else if ((v >= -(1 << 7)) && (v < (1 << 7))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    opc = opc_bipush;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                } else if ((v >= -(1 << 15)) && (v < (1 << 15))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    opc = opc_sipush;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            } else if (value instanceof Float) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                float v = ((Float)value).floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                if (v == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    if (Float.floatToIntBits(v) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                        opc = opc_fconst_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                } else if (v == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                    opc = opc_fconst_1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                } else if (v == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    opc = opc_fconst_2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            tab.put(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
          case opc_ldc2_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            if (value instanceof Long) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                long v = ((Long)value).longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                if (v == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    opc = opc_lconst_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                } else if (v == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    opc = opc_lconst_1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            } else if (value instanceof Double) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                double v = ((Double)value).doubleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                if (v == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                    if (Double.doubleToLongBits(v) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                        opc = opc_dconst_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                } else if (v == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    opc = opc_dconst_1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            tab.put(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
          case opc_try:
19226
d5febab8765d 8022479: clean up warnings from sun.tools.asm
smarks
parents: 5506
diff changeset
   392
            for (Enumeration<CatchData> e = ((TryData)value).catches.elements() ; e.hasMoreElements() ;) {
d5febab8765d 8022479: clean up warnings from sun.tools.asm
smarks
parents: 5506
diff changeset
   393
                CatchData cd = e.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                if (cd.getType() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    tab.put(cd.getType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
          case opc_nop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            if ((value != null) && (value instanceof ClassDeclaration))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                tab.put(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * Balance the stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    int balance() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        switch (opc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
          case opc_dead:        case opc_label:         case opc_iinc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
          case opc_arraylength: case opc_laload:        case opc_daload:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
          case opc_nop:         case opc_ineg:          case opc_fneg:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
          case opc_lneg:        case opc_dneg:          case opc_i2f:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
          case opc_f2i:         case opc_l2d:           case opc_d2l:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
          case opc_i2b:         case opc_i2c:           case opc_i2s:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
          case opc_jsr:         case opc_goto:          case opc_jsr_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
          case opc_goto_w:      case opc_return:        case opc_ret:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
          case opc_instanceof:  case opc_checkcast:     case opc_newarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
          case opc_anewarray:   case opc_try:           case opc_swap:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
          case opc_ldc:         case opc_ldc_w:         case opc_bipush:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
          case opc_sipush:      case opc_aconst_null:   case opc_iconst_m1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
          case opc_iconst_0:    case opc_iconst_1:      case opc_iconst_2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
          case opc_iconst_3:    case opc_iconst_4:      case opc_iconst_5:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
          case opc_fconst_0:    case opc_fconst_1:      case opc_fconst_2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
          case opc_iload:       case opc_fload:         case opc_aload:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
          case opc_dup:         case opc_dup_x1:        case opc_dup_x2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
          case opc_i2l:         case opc_i2d:           case opc_f2l:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
          case opc_f2d:         case opc_new:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
          case opc_lload:       case opc_dload:         case opc_dup2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
          case opc_dup2_x1:     case opc_dup2_x2:       case opc_ldc2_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
          case opc_lconst_0:    case opc_lconst_1:      case opc_dconst_0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
          case opc_dconst_1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
          case opc_istore:      case opc_fstore:        case opc_astore:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
          case opc_iaload:      case opc_faload:        case opc_aaload:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
          case opc_baload:      case opc_caload:        case opc_saload:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
          case opc_pop:         case opc_iadd:          case opc_fadd:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
          case opc_isub:        case opc_fsub:          case opc_imul:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
          case opc_fmul:        case opc_idiv:          case opc_fdiv:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
          case opc_irem:        case opc_frem:          case opc_ishl:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
          case opc_ishr:        case opc_iushr:         case opc_lshl:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
          case opc_lshr:        case opc_lushr:         case opc_iand:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
          case opc_ior:         case opc_ixor:          case opc_l2i:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
          case opc_l2f:         case opc_d2i:           case opc_d2f:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
          case opc_ifeq:        case opc_ifne:          case opc_iflt:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
          case opc_ifle:        case opc_ifgt:          case opc_ifge:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
          case opc_ifnull:      case opc_ifnonnull:     case opc_fcmpl:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
          case opc_fcmpg:       case opc_ireturn:       case opc_freturn:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
          case opc_areturn:     case opc_tableswitch:   case opc_lookupswitch:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
          case opc_athrow:      case opc_monitorenter:  case opc_monitorexit:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
          case opc_lstore:      case opc_dstore:        case opc_pop2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
          case opc_ladd:        case opc_dadd:          case opc_lsub:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
          case opc_dsub:        case opc_lmul:          case opc_dmul:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
          case opc_ldiv:        case opc_ddiv:          case opc_lrem:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
          case opc_drem:        case opc_land:          case opc_lor:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
          case opc_lxor:        case opc_if_acmpeq:     case opc_if_acmpne:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
          case opc_if_icmpeq:   case opc_if_icmpne:     case opc_if_icmplt:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
          case opc_if_icmple:   case opc_if_icmpgt:     case opc_if_icmpge:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
          case opc_lreturn:     case opc_dreturn:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            return -2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
          case opc_iastore:     case opc_fastore:       case opc_aastore:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
          case opc_bastore:     case opc_castore:       case opc_sastore:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
          case opc_lcmp:        case opc_dcmpl:         case opc_dcmpg:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            return -3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
          case opc_lastore:     case opc_dastore:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            return -4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
          case opc_multianewarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            return 1 - ((ArrayData)value).nargs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
          case opc_getfield:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            return ((MemberDefinition)value).getType().stackSize() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
          case opc_putfield:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            return -1 - ((MemberDefinition)value).getType().stackSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
          case opc_getstatic:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            return ((MemberDefinition)value).getType().stackSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
          case opc_putstatic:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            return -((MemberDefinition)value).getType().stackSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
          case opc_invokevirtual:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
          case opc_invokespecial:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
          case opc_invokeinterface:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            return ((MemberDefinition)value).getType().getReturnType().stackSize() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                   (((MemberDefinition)value).getType().stackSize() + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
          case opc_invokestatic:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            return ((MemberDefinition)value).getType().getReturnType().stackSize() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                   (((MemberDefinition)value).getType().stackSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        throw new CompilerError("invalid opcode: " + toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * Return the size of the instruction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    int size(ConstantPool tab) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        switch (opc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
          case opc_try:         case opc_label:         case opc_dead:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
          case opc_bipush:      case opc_newarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
          case opc_sipush:      case opc_goto:          case opc_jsr:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
          case opc_ifeq:        case opc_ifne:          case opc_ifgt:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
          case opc_ifge:        case opc_iflt:          case opc_ifle:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
          case opc_ifnull:      case opc_ifnonnull:     case opc_if_acmpeq:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
          case opc_if_acmpne:   case opc_if_icmpeq:     case opc_if_icmpne:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
          case opc_if_icmpgt:   case opc_if_icmpge:     case opc_if_icmplt:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
          case opc_if_icmple:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            return 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
          case opc_ldc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
          case opc_ldc_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            if (tab.index(value) < 256) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                opc = opc_ldc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                opc = opc_ldc_w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                return 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
          case opc_iload:       case opc_lload:         case opc_fload:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
          case opc_dload:       case opc_aload: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            int v = ((Number)value).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            if (v < 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                if (v < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                    throw new CompilerError("invalid slot: " + toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                        + "\nThis error possibly resulted from poorly constructed class paths.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                opc = opc_iload_0 + (opc - opc_iload) * 4 + v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            } else if (v <= 255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                opc += 256;     // indicate wide variant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                return 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
           case opc_iinc: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
               int register = ((int[])value)[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
               int increment = ((int[])value)[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
               if (register < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                   throw new CompilerError("invalid slot: " + toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
               if (register <= 255 && (((byte)increment) == increment)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                   return 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
               } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                   opc += 256;          // indicate wide variant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                   return 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
          case opc_istore:      case opc_lstore:        case opc_fstore:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
          case opc_dstore:      case opc_astore: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            int v = (value instanceof Number) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                ((Number)value).intValue() : ((LocalVariable)value).slot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            if (v < 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                if (v < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                    throw new CompilerError("invalid slot: " + toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                opc = opc_istore_0 + (opc - opc_istore) * 4 + v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            } else if (v <= 255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                opc += 256;     // indicate wide variant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                return 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
          case opc_ret: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
              int v = ((Number)value).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
              if (v <= 255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                  if (v < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                      throw new CompilerError("invalid slot: " + toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                  return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
              } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                  opc += 256;   // indicate wide variant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                  return 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
          case opc_ldc2_w:              case opc_new:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
          case opc_putstatic:           case opc_getstatic:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
          case opc_putfield:            case opc_getfield:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
          case opc_invokevirtual:       case opc_invokespecial:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
          case opc_invokestatic:        case opc_instanceof:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
          case opc_checkcast:           case opc_anewarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            return 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
          case opc_multianewarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            return 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
          case opc_invokeinterface:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
          case opc_goto_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
          case opc_jsr_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            return 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
          case opc_tableswitch: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            SwitchData sw = (SwitchData)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            int n = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            for(; ((pc + n) % 4) != 0 ; n++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            return n + 16 + (sw.maxValue - sw.minValue) * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
          case opc_lookupswitch: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            SwitchData sw = (SwitchData)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            int n = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            for(; ((pc + n) % 4) != 0 ; n++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            return n + 8 + sw.tab.size() * 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
          case opc_nop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            if ((value != null) && !(value instanceof Integer))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        // most opcodes are only 1 byte long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * Generate code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     */
19226
d5febab8765d 8022479: clean up warnings from sun.tools.asm
smarks
parents: 5506
diff changeset
   644
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    void write(DataOutputStream out, ConstantPool tab) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        switch (opc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
          case opc_try:         case opc_label:         case opc_dead:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
          case opc_bipush:      case opc_newarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
          case opc_iload:       case opc_lload:         case opc_fload:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
          case opc_dload:       case opc_aload:         case opc_ret:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            out.writeByte(opc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            out.writeByte(((Number)value).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
          case opc_iload + 256:         case opc_lload + 256:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
          case opc_fload + 256:         case opc_dload + 256:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
          case opc_aload + 256:         case opc_ret   + 256:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            out.writeByte(opc_wide);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            out.writeByte(opc - 256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            out.writeShort(((Number)value).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
          case opc_istore:      case opc_lstore:        case opc_fstore:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
          case opc_dstore:      case opc_astore:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            out.writeByte(opc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            out.writeByte((value instanceof Number) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                          ((Number)value).intValue() : ((LocalVariable)value).slot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
          case opc_istore + 256:        case opc_lstore + 256:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
          case opc_fstore + 256:        case opc_dstore + 256:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
          case opc_astore + 256:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            out.writeByte(opc_wide);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            out.writeByte(opc - 256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            out.writeShort((value instanceof Number) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                      ((Number)value).intValue() : ((LocalVariable)value).slot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
          case opc_sipush:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            out.writeByte(opc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            out.writeShort(((Number)value).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
          case opc_ldc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            out.writeByte(opc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            out.writeByte(tab.index(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
          case opc_ldc_w:               case opc_ldc2_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
          case opc_new:                 case opc_putstatic:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
          case opc_getstatic:           case opc_putfield:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
          case opc_getfield:            case opc_invokevirtual:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
          case opc_invokespecial:       case opc_invokestatic:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
          case opc_instanceof:          case opc_checkcast:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            out.writeByte(opc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            out.writeShort(tab.index(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
          case opc_iinc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            out.writeByte(opc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            out.writeByte(((int[])value)[0]); // register
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            out.writeByte(((int[])value)[1]); // increment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
          case opc_iinc + 256:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            out.writeByte(opc_wide);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            out.writeByte(opc - 256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            out.writeShort(((int[])value)[0]); // register
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            out.writeShort(((int[])value)[1]); // increment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
          case opc_anewarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            out.writeByte(opc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            out.writeShort(tab.index(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
          case opc_multianewarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            out.writeByte(opc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            out.writeShort(tab.index(((ArrayData)value).type));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            out.writeByte(((ArrayData)value).nargs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
          case opc_invokeinterface:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            out.writeByte(opc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            out.writeShort(tab.index(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            out.writeByte(((MemberDefinition)value).getType().stackSize() + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            out.writeByte(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
          case opc_goto:        case opc_jsr:           case opc_ifeq:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
          case opc_ifne:        case opc_ifgt:          case opc_ifge:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
          case opc_iflt:        case opc_ifle:          case opc_ifnull:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
          case opc_ifnonnull:   case opc_if_acmpeq:     case opc_if_acmpne:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
          case opc_if_icmpeq:   case opc_if_icmpne:     case opc_if_icmpgt:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
          case opc_if_icmpge:   case opc_if_icmplt:     case opc_if_icmple:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            out.writeByte(opc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            out.writeShort(((Instruction)value).pc - pc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
          case opc_goto_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
          case opc_jsr_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            out.writeByte(opc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            out.writeLong(((Instruction)value).pc - pc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
          case opc_tableswitch: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            SwitchData sw = (SwitchData)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            out.writeByte(opc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            for(int n = 1 ; ((pc + n) % 4) != 0 ; n++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                out.writeByte(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            out.writeInt(sw.defaultLabel.pc - pc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            out.writeInt(sw.minValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            out.writeInt(sw.maxValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            for (int n = sw.minValue ; n <= sw.maxValue ; n++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                Label lbl = sw.get(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                int target_pc = (lbl != null) ? lbl.pc : sw.defaultLabel.pc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                out.writeInt(target_pc - pc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
          case opc_lookupswitch: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            SwitchData sw = (SwitchData)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            out.writeByte(opc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            int n = pc + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            for(; (n % 4) != 0 ; n++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                out.writeByte(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            out.writeInt(sw.defaultLabel.pc - pc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            out.writeInt(sw.tab.size());
19226
d5febab8765d 8022479: clean up warnings from sun.tools.asm
smarks
parents: 5506
diff changeset
   774
            for (Enumeration<Integer> e = sw.sortedKeys(); e.hasMoreElements() ; ) {
d5febab8765d 8022479: clean up warnings from sun.tools.asm
smarks
parents: 5506
diff changeset
   775
                Integer v = e.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                out.writeInt(v.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                out.writeInt(sw.get(v).pc - pc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
          case opc_nop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                if (value instanceof Integer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                    out.writeByte(((Integer)value).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                    out.writeShort(tab.index(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            // fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            out.writeByte(opc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * toString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        String prefix = (where >> WHEREOFFSETBITS) + ":\t";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        switch (opc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
          case opc_try:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            return prefix + "try " + ((TryData)value).getEndLabel().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
          case opc_dead:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            return prefix + "dead";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
          case opc_iinc: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            int register = ((int[])value)[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            int increment = ((int[])value)[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            return prefix + opcNames[opc] + " " + register + ", " + increment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                if (value instanceof Label) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                    return prefix + opcNames[opc] + " " + value.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                } else if (value instanceof Instruction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                    return prefix + opcNames[opc] + " " + value.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                } else if (value instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                    return prefix + opcNames[opc] + " \"" + value + "\"";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                    return prefix + opcNames[opc] + " " + value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
              return prefix + opcNames[opc];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
}