langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java
author ohair
Tue, 25 May 2010 15:54:51 -0700
changeset 5520 86e4b9a9da40
parent 4866 21f0ac9e5a20
child 5847 1908176fd6e3
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4866
diff changeset
     2
 * Copyright (c) 1999, 2009, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
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: 4866
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4866
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4866
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4866
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4866
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.jvm;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import com.sun.tools.javac.code.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import com.sun.tools.javac.code.Symbol.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import static com.sun.tools.javac.code.TypeTags.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import static com.sun.tools.javac.jvm.ByteCodes.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import static com.sun.tools.javac.jvm.UninitializedType.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import static com.sun.tools.javac.jvm.ClassWriter.StackMapTableFrame;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
/** An internal structure that corresponds to the code attribute of
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 *  methods in a classfile. The class also provides some utility operations to
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *  generate bytecode instructions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *  you write code that depends on this, you do so at your own risk.
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
public class Code {
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    public final boolean debugCode;
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    public final boolean needStackMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    public enum StackMapFormat {
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
        NONE,
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
        CLDC {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
    55
            Name getAttributeName(Names names) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
                return names.StackMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
        },
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
        JSR202 {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
    60
            Name getAttributeName(Names names) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
                return names.StackMapTable;
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
        };
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
    64
        Name getAttributeName(Names names) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
            return names.empty;
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    final Types types;
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    final Symtab syms;
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
/*---------- classfile fields: --------------- */
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    /** The maximum stack size.
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    public int max_stack = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    /** The maximum number of local variable slots.
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    public int max_locals = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    /** The code buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    public byte[] code = new byte[64];
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    /** the current code pointer.
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    public int cp = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    /** Check the code against VM spec limits; if
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
     *  problems report them and return true.
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    public boolean checkLimits(DiagnosticPosition pos, Log log) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        if (cp > ClassFile.MAX_CODE) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
            log.error(pos, "limit.code");
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        if (max_locals > ClassFile.MAX_LOCALS) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
            log.error(pos, "limit.locals");
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        if (max_stack > ClassFile.MAX_STACK) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
            log.error(pos, "limit.stack");
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    /** A buffer for expression catch data. Each enter is a vector
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     *  of four unsigned shorts.
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    ListBuffer<char[]> catchInfo = new ListBuffer<char[]>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    /** A buffer for line number information. Each entry is a vector
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     *  of two unsigned shorts.
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    List<char[]> lineInfo = List.nil(); // handled in stack fashion
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    /** The CharacterRangeTable
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    public CRTable crt;
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
/*---------- internal fields: --------------- */
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    /** Are we generating code with jumps >= 32K?
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    public boolean fatcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    /** Code generation enabled?
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    private boolean alive = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    /** The current machine state (registers and stack).
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    State state;
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    /** Is it forbidden to compactify code, because something is
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
     *  pointing to current location?
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    private boolean fixedPc = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    /** The next available register.
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    public int nextreg = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
    /** A chain for jumps to be resolved before the next opcode is emitted.
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     *  We do this lazily to avoid jumps to jumps.
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    Chain pendingJumps = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    /** The position of the currently statement, if we are at the
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
     *  start of this statement, NOPOS otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     *  We need this to emit line numbers lazily, which we need to do
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     *  because of jump-to-jump optimization.
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    int pendingStatPos = Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    /** Set true when a stackMap is needed at the current PC. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    boolean pendingStackMap = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    /** The stack map format to be generated. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    StackMapFormat stackMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    /** Switch: emit variable debug info.
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    boolean varDebugInfo;
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    /** Switch: emit line number info.
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
    boolean lineDebugInfo;
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
    /** Emit line number info if map supplied
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    Position.LineMap lineMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    /** The constant pool of the current class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    final Pool pool;
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    final MethodSymbol meth;
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    /** Construct a code object, given the settings of the fatcode,
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     *  debugging info switches and the CharacterRangeTable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
    public Code(MethodSymbol meth,
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
                boolean fatcode,
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
                Position.LineMap lineMap,
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
                boolean varDebugInfo,
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
                StackMapFormat stackMap,
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
                boolean debugCode,
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
                CRTable crt,
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
                Symtab syms,
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
                Types types,
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
                Pool pool) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        this.meth = meth;
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        this.fatcode = fatcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
        this.lineMap = lineMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        this.lineDebugInfo = lineMap != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        this.varDebugInfo = varDebugInfo;
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        this.crt = crt;
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        this.syms = syms;
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        this.types = types;
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
        this.debugCode = debugCode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        this.stackMap = stackMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
        switch (stackMap) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        case CLDC:
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        case JSR202:
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
            this.needStackMap = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
            this.needStackMap = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
        state = new State();
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        lvar = new LocalVar[20];
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        this.pool = pool;
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
/* **************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
 * Typecodes & related stuff
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
    /** Given a type, return its type code (used implicitly in the
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
     *  JVM architecture).
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    public static int typecode(Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        switch (type.tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
        case BYTE: return BYTEcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
        case SHORT: return SHORTcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        case CHAR: return CHARcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        case INT: return INTcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
        case LONG: return LONGcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
        case FLOAT: return FLOATcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        case DOUBLE: return DOUBLEcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        case BOOLEAN: return BYTEcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        case VOID: return VOIDcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
        case CLASS:
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
        case ARRAY:
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
        case METHOD:
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
        case BOT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        case TYPEVAR:
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        case UNINITIALIZED_THIS:
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        case UNINITIALIZED_OBJECT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
            return OBJECTcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
        default: throw new AssertionError("typecode " + type.tag);
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    /** Collapse type code for subtypes of int to INTcode.
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
    public static int truncate(int tc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
        switch (tc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
        case BYTEcode: case SHORTcode: case CHARcode: return INTcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
        default: return tc;
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
    /** The width in bytes of objects of the type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
    public static int width(int typecode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
        switch (typecode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
        case LONGcode: case DOUBLEcode: return 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
        case VOIDcode: return 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
        default: return 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
    public static int width(Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
        return type == null ? 1 : width(typecode(type));
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
    /** The total width taken up by a vector of objects.
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
    public static int width(List<Type> types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        int w = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        for (List<Type> l = types; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
            w = w + width(l.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        return w;
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
    /** Given a type, return its code for allocating arrays of that type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
    public static int arraycode(Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
        switch (type.tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        case BYTE: return 8;
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        case BOOLEAN: return 4;
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
        case SHORT: return 9;
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        case CHAR: return 5;
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
        case INT: return 10;
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
        case LONG: return 11;
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
        case FLOAT: return 6;
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
        case DOUBLE: return 7;
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        case CLASS: return 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
        case ARRAY: return 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
        default: throw new AssertionError("arraycode " + type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
/* **************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
 * Emit code
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
    /** The current output code pointer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
    public int curPc() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
        if (pendingJumps != null) resolvePending();
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
        if (pendingStatPos != Position.NOPOS) markStatBegin();
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
        fixedPc = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
        return cp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
    /** Emit a byte of code.
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
    private  void emit1(int od) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
        if (!alive) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
        if (cp == code.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
            byte[] newcode = new byte[cp * 2];
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
            System.arraycopy(code, 0, newcode, 0, cp);
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
            code = newcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
        code[cp++] = (byte)od;
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
    /** Emit two bytes of code.
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
    private void emit2(int od) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
        if (!alive) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
        if (cp + 2 > code.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
            emit1(od >> 8);
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
            emit1(od);
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
            code[cp++] = (byte)(od >> 8);
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
            code[cp++] = (byte)od;
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
    /** Emit four bytes of code.
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
    public void emit4(int od) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
        if (!alive) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
        if (cp + 4 > code.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
            emit1(od >> 24);
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
            emit1(od >> 16);
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
            emit1(od >> 8);
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
            emit1(od);
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
            code[cp++] = (byte)(od >> 24);
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
            code[cp++] = (byte)(od >> 16);
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
            code[cp++] = (byte)(od >> 8);
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
            code[cp++] = (byte)od;
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
    /** Emit an opcode.
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
    private void emitop(int op) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
        if (pendingJumps != null) resolvePending();
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
        if (alive) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
            if (pendingStatPos != Position.NOPOS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
                markStatBegin();
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
            if (pendingStackMap) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
                pendingStackMap = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
                emitStackMap();
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
            if (debugCode)
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
                System.err.println("emit@" + cp + " stack=" +
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
                                   state.stacksize + ": " +
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
                                   mnem(op));
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
            emit1(op);
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
    void postop() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
        assert alive || state.stacksize == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
    /** Emit a multinewarray instruction.
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
    public void emitMultianewarray(int ndims, int type, Type arrayType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
        emitop(multianewarray);
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
        if (!alive) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
        emit2(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
        emit1(ndims);
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
        state.pop(ndims);
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
        state.push(arrayType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
    /** Emit newarray.
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
    public void emitNewarray(int elemcode, Type arrayType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
        emitop(newarray);
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
        if (!alive) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
        emit1(elemcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
        state.pop(1); // count
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
        state.push(arrayType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
    /** Emit anewarray.
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
    public void emitAnewarray(int od, Type arrayType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
        emitop(anewarray);
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
        if (!alive) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
        emit2(od);
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
        state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
        state.push(arrayType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
    /** Emit an invokeinterface instruction.
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
    public void emitInvokeinterface(int meth, Type mtype) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
        int argsize = width(mtype.getParameterTypes());
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
        emitop(invokeinterface);
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
        if (!alive) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
        emit2(meth);
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
        emit1(argsize + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
        emit1(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
        state.pop(argsize + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
        state.push(mtype.getReturnType());
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
    /** Emit an invokespecial instruction.
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
    public void emitInvokespecial(int meth, Type mtype) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
        int argsize = width(mtype.getParameterTypes());
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
        emitop(invokespecial);
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
        if (!alive) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
        emit2(meth);
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
        Symbol sym = (Symbol)pool.pool[meth];
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
        state.pop(argsize);
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
        if (sym.isConstructor())
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
            state.markInitialized((UninitializedType)state.peek());
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
        state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
        state.push(mtype.getReturnType());
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
    /** Emit an invokestatic instruction.
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
    public void emitInvokestatic(int meth, Type mtype) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
        int argsize = width(mtype.getParameterTypes());
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
        emitop(invokestatic);
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
        if (!alive) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
        emit2(meth);
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
        state.pop(argsize);
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
        state.push(mtype.getReturnType());
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
    /** Emit an invokevirtual instruction.
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
    public void emitInvokevirtual(int meth, Type mtype) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
        int argsize = width(mtype.getParameterTypes());
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
        emitop(invokevirtual);
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
        if (!alive) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
        emit2(meth);
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
        state.pop(argsize + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
        state.push(mtype.getReturnType());
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   459
    /** Emit an invokedynamic instruction.
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   460
     */
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   461
    public void emitInvokedynamic(int desc, Type mtype) {
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   462
        // N.B. this format is under consideration by the JSR 292 EG
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   463
        int argsize = width(mtype.getParameterTypes());
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   464
        emitop(invokedynamic);
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   465
        if (!alive) return;
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   466
        emit2(desc);
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   467
        emit2(0);
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   468
        state.pop(argsize);
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   469
        state.push(mtype.getReturnType());
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   470
    }
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   471
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
    /** Emit an opcode with no operand field.
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
    public void emitop0(int op) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
        emitop(op);
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
        if (!alive) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
        switch (op) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
        case aaload: {
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
            state.pop(1);// index
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
            Type a = state.stack[state.stacksize-1];
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
            state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
            state.push(types.erasure(types.elemtype(a))); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
        case goto_:
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
            markDead();
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
        case nop:
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
        case ineg:
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
        case lneg:
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
        case fneg:
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
        case dneg:
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
        case aconst_null:
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
            state.push(syms.botType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
        case iconst_m1:
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
        case iconst_0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
        case iconst_1:
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
        case iconst_2:
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
        case iconst_3:
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
        case iconst_4:
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
        case iconst_5:
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
        case iload_0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
        case iload_1:
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
        case iload_2:
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
        case iload_3:
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
            state.push(syms.intType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
        case lconst_0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
        case lconst_1:
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
        case lload_0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
        case lload_1:
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
        case lload_2:
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
        case lload_3:
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
            state.push(syms.longType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
        case fconst_0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
        case fconst_1:
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
        case fconst_2:
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
        case fload_0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
        case fload_1:
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
        case fload_2:
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
        case fload_3:
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
            state.push(syms.floatType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
        case dconst_0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
        case dconst_1:
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
        case dload_0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
        case dload_1:
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
        case dload_2:
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
        case dload_3:
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
            state.push(syms.doubleType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
        case aload_0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
            state.push(lvar[0].sym.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
        case aload_1:
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
            state.push(lvar[1].sym.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
        case aload_2:
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
            state.push(lvar[2].sym.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
        case aload_3:
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
            state.push(lvar[3].sym.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
        case iaload:
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
        case baload:
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
        case caload:
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
        case saload:
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
            state.pop(2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
            state.push(syms.intType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
        case laload:
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
            state.pop(2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
            state.push(syms.longType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
        case faload:
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
            state.pop(2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
            state.push(syms.floatType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
        case daload:
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
            state.pop(2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
            state.push(syms.doubleType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
        case istore_0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
        case istore_1:
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
        case istore_2:
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
        case istore_3:
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
        case fstore_0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
        case fstore_1:
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
        case fstore_2:
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
        case fstore_3:
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
        case astore_0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
        case astore_1:
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
        case astore_2:
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
        case astore_3:
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
        case pop:
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
        case lshr:
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
        case lshl:
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
        case lushr:
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
            state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
        case areturn:
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
        case ireturn:
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
        case freturn:
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
            assert state.nlocks == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
            state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
            markDead();
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
        case athrow:
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
            state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
            markDead();
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
        case lstore_0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
        case lstore_1:
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
        case lstore_2:
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
        case lstore_3:
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
        case dstore_0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
        case dstore_1:
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
        case dstore_2:
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
        case dstore_3:
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
        case pop2:
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
            state.pop(2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
        case lreturn:
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
        case dreturn:
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
            assert state.nlocks == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
            state.pop(2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
            markDead();
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
        case dup:
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
            state.push(state.stack[state.stacksize-1]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
        case return_:
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
            assert state.nlocks == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
            markDead();
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
        case arraylength:
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
            state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
            state.push(syms.intType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
        case isub:
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
        case iadd:
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
        case imul:
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
        case idiv:
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
        case imod:
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
        case ishl:
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
        case ishr:
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
        case iushr:
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
        case iand:
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
        case ior:
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
        case ixor:
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
            state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
            // state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
            // state.push(syms.intType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
        case aastore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
            state.pop(3);
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
        case land:
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
        case lor:
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
        case lxor:
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
        case lmod:
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
        case ldiv:
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
        case lmul:
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
        case lsub:
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
        case ladd:
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
            state.pop(2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
        case lcmp:
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
            state.pop(4);
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
            state.push(syms.intType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
        case l2i:
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
            state.pop(2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
            state.push(syms.intType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
        case i2l:
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
            state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
            state.push(syms.longType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
        case i2f:
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
            state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
            state.push(syms.floatType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
        case i2d:
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
            state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
            state.push(syms.doubleType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
        case l2f:
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
            state.pop(2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
            state.push(syms.floatType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
        case l2d:
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
            state.pop(2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
            state.push(syms.doubleType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
        case f2i:
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
            state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
            state.push(syms.intType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
        case f2l:
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
            state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
            state.push(syms.longType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
        case f2d:
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
            state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
            state.push(syms.doubleType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
        case d2i:
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
            state.pop(2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
            state.push(syms.intType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
        case d2l:
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
            state.pop(2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
            state.push(syms.longType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
        case d2f:
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
            state.pop(2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
            state.push(syms.floatType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
        case tableswitch:
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
        case lookupswitch:
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
            state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
            // the caller is responsible for patching up the state
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
        case dup_x1: {
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
            Type val1 = state.pop1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
            Type val2 = state.pop1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
            state.push(val1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
            state.push(val2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
            state.push(val1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
        case bastore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
            state.pop(3);
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
        case int2byte:
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
        case int2char:
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
        case int2short:
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
        case fmul:
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
        case fadd:
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
        case fsub:
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
        case fdiv:
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
        case fmod:
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
            state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   728
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
        case castore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
        case iastore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
        case fastore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
        case sastore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   733
            state.pop(3);
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
        case lastore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
        case dastore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
            state.pop(4);
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
        case dup2:
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
            if (state.stack[state.stacksize-1] != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
                Type value1 = state.pop1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
                Type value2 = state.pop1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
                state.push(value2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
                state.push(value1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
                state.push(value2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   746
                state.push(value1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
                Type value = state.pop2();
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
                state.push(value);
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
                state.push(value);
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
        case dup2_x1:
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
            if (state.stack[state.stacksize-1] != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
                Type value1 = state.pop1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
                Type value2 = state.pop1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
                Type value3 = state.pop1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
                state.push(value2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
                state.push(value1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
                state.push(value3);
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
                state.push(value2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
                state.push(value1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
                Type value1 = state.pop2();
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
                Type value2 = state.pop1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
                state.push(value1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   767
                state.push(value2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
                state.push(value1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
        case dup2_x2:
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
            if (state.stack[state.stacksize-1] != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
                Type value1 = state.pop1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
                Type value2 = state.pop1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
                if (state.stack[state.stacksize-1] != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
                    // form 1
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
                    Type value3 = state.pop1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
                    Type value4 = state.pop1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   779
                    state.push(value2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   780
                    state.push(value1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
                    state.push(value4);
06bc494ca11e Initial load
duke
parents:
diff changeset
   782
                    state.push(value3);
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
                    state.push(value2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
                    state.push(value1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
                    // form 3
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
                    Type value3 = state.pop2();
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
                    state.push(value2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
                    state.push(value1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
                    state.push(value3);
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
                    state.push(value2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
                    state.push(value1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
                Type value1 = state.pop2();
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
                if (state.stack[state.stacksize-1] != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
                    // form 2
06bc494ca11e Initial load
duke
parents:
diff changeset
   798
                    Type value2 = state.pop1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
                    Type value3 = state.pop1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
                    state.push(value1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
                    state.push(value3);
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
                    state.push(value2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
                    state.push(value1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   804
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
                    // form 4
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
                    Type value2 = state.pop2();
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
                    state.push(value1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
                    state.push(value2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
                    state.push(value1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   810
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
        case dup_x2: {
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
            Type value1 = state.pop1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
            if (state.stack[state.stacksize-1] != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
                // form 1
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
                Type value2 = state.pop1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
                Type value3 = state.pop1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
                state.push(value1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
                state.push(value3);
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
                state.push(value2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
                state.push(value1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   824
                // form 2
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
                Type value2 = state.pop2();
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
                state.push(value1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
                state.push(value2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
                state.push(value1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   829
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   830
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   831
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   832
        case fcmpl:
06bc494ca11e Initial load
duke
parents:
diff changeset
   833
        case fcmpg:
06bc494ca11e Initial load
duke
parents:
diff changeset
   834
            state.pop(2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   835
            state.push(syms.intType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   836
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   837
        case dcmpl:
06bc494ca11e Initial load
duke
parents:
diff changeset
   838
        case dcmpg:
06bc494ca11e Initial load
duke
parents:
diff changeset
   839
            state.pop(4);
06bc494ca11e Initial load
duke
parents:
diff changeset
   840
            state.push(syms.intType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   841
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   842
        case swap: {
06bc494ca11e Initial load
duke
parents:
diff changeset
   843
            Type value1 = state.pop1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   844
            Type value2 = state.pop1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   845
            state.push(value1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
            state.push(value2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   847
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   848
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   849
        case dadd:
06bc494ca11e Initial load
duke
parents:
diff changeset
   850
        case dsub:
06bc494ca11e Initial load
duke
parents:
diff changeset
   851
        case dmul:
06bc494ca11e Initial load
duke
parents:
diff changeset
   852
        case ddiv:
06bc494ca11e Initial load
duke
parents:
diff changeset
   853
        case dmod:
06bc494ca11e Initial load
duke
parents:
diff changeset
   854
            state.pop(2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   855
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   856
        case ret:
06bc494ca11e Initial load
duke
parents:
diff changeset
   857
            markDead();
06bc494ca11e Initial load
duke
parents:
diff changeset
   858
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   859
        case wide:
06bc494ca11e Initial load
duke
parents:
diff changeset
   860
            // must be handled by the caller.
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   862
        case monitorenter:
06bc494ca11e Initial load
duke
parents:
diff changeset
   863
        case monitorexit:
06bc494ca11e Initial load
duke
parents:
diff changeset
   864
            state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   865
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   866
06bc494ca11e Initial load
duke
parents:
diff changeset
   867
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   868
            throw new AssertionError(mnem(op));
06bc494ca11e Initial load
duke
parents:
diff changeset
   869
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   870
        postop();
06bc494ca11e Initial load
duke
parents:
diff changeset
   871
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   872
06bc494ca11e Initial load
duke
parents:
diff changeset
   873
    /** Emit an opcode with a one-byte operand field.
06bc494ca11e Initial load
duke
parents:
diff changeset
   874
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   875
    public void emitop1(int op, int od) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   876
        emitop(op);
06bc494ca11e Initial load
duke
parents:
diff changeset
   877
        if (!alive) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   878
        emit1(od);
06bc494ca11e Initial load
duke
parents:
diff changeset
   879
        switch (op) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   880
        case bipush:
06bc494ca11e Initial load
duke
parents:
diff changeset
   881
            state.push(syms.intType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   882
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   883
        case ldc1:
06bc494ca11e Initial load
duke
parents:
diff changeset
   884
            state.push(typeForPool(pool.pool[od]));
06bc494ca11e Initial load
duke
parents:
diff changeset
   885
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   886
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   887
            throw new AssertionError(mnem(op));
06bc494ca11e Initial load
duke
parents:
diff changeset
   888
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   889
        postop();
06bc494ca11e Initial load
duke
parents:
diff changeset
   890
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   891
06bc494ca11e Initial load
duke
parents:
diff changeset
   892
    /** The type of a constant pool entry. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   893
    private Type typeForPool(Object o) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   894
        if (o instanceof Integer) return syms.intType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   895
        if (o instanceof Float) return syms.floatType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   896
        if (o instanceof String) return syms.stringType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   897
        if (o instanceof Long) return syms.longType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   898
        if (o instanceof Double) return syms.doubleType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   899
        if (o instanceof ClassSymbol) return syms.classType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   900
        if (o instanceof Type.ArrayType) return syms.classType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   901
        throw new AssertionError(o);
06bc494ca11e Initial load
duke
parents:
diff changeset
   902
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   903
06bc494ca11e Initial load
duke
parents:
diff changeset
   904
    /** Emit an opcode with a one-byte operand field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   905
     *  widen if field does not fit in a byte.
06bc494ca11e Initial load
duke
parents:
diff changeset
   906
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   907
    public void emitop1w(int op, int od) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   908
        if (od > 0xFF) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   909
            emitop(wide);
06bc494ca11e Initial load
duke
parents:
diff changeset
   910
            emitop(op);
06bc494ca11e Initial load
duke
parents:
diff changeset
   911
            emit2(od);
06bc494ca11e Initial load
duke
parents:
diff changeset
   912
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   913
            emitop(op);
06bc494ca11e Initial load
duke
parents:
diff changeset
   914
            emit1(od);
06bc494ca11e Initial load
duke
parents:
diff changeset
   915
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   916
        if (!alive) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   917
        switch (op) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   918
        case iload:
06bc494ca11e Initial load
duke
parents:
diff changeset
   919
            state.push(syms.intType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   920
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   921
        case lload:
06bc494ca11e Initial load
duke
parents:
diff changeset
   922
            state.push(syms.longType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   923
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   924
        case fload:
06bc494ca11e Initial load
duke
parents:
diff changeset
   925
            state.push(syms.floatType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   926
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   927
        case dload:
06bc494ca11e Initial load
duke
parents:
diff changeset
   928
            state.push(syms.doubleType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   929
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   930
        case aload:
06bc494ca11e Initial load
duke
parents:
diff changeset
   931
            state.push(lvar[od].sym.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   932
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   933
        case lstore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   934
        case dstore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   935
            state.pop(2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   936
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   937
        case istore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   938
        case fstore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   939
        case astore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   940
            state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   941
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   942
        case ret:
06bc494ca11e Initial load
duke
parents:
diff changeset
   943
            markDead();
06bc494ca11e Initial load
duke
parents:
diff changeset
   944
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   945
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   946
            throw new AssertionError(mnem(op));
06bc494ca11e Initial load
duke
parents:
diff changeset
   947
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   948
        postop();
06bc494ca11e Initial load
duke
parents:
diff changeset
   949
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   950
06bc494ca11e Initial load
duke
parents:
diff changeset
   951
    /** Emit an opcode with two one-byte operand fields;
06bc494ca11e Initial load
duke
parents:
diff changeset
   952
     *  widen if either field does not fit in a byte.
06bc494ca11e Initial load
duke
parents:
diff changeset
   953
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   954
    public void emitop1w(int op, int od1, int od2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   955
        if (od1 > 0xFF || od2 < -128 || od2 > 127) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   956
            emitop(wide);
06bc494ca11e Initial load
duke
parents:
diff changeset
   957
            emitop(op);
06bc494ca11e Initial load
duke
parents:
diff changeset
   958
            emit2(od1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   959
            emit2(od2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   960
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   961
            emitop(op);
06bc494ca11e Initial load
duke
parents:
diff changeset
   962
            emit1(od1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   963
            emit1(od2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   964
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   965
        if (!alive) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   966
        switch (op) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   967
        case iinc:
06bc494ca11e Initial load
duke
parents:
diff changeset
   968
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   969
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   970
            throw new AssertionError(mnem(op));
06bc494ca11e Initial load
duke
parents:
diff changeset
   971
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   972
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   973
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
    /** Emit an opcode with a two-byte operand field.
06bc494ca11e Initial load
duke
parents:
diff changeset
   975
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   976
    public void emitop2(int op, int od) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   977
        emitop(op);
06bc494ca11e Initial load
duke
parents:
diff changeset
   978
        if (!alive) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   979
        emit2(od);
06bc494ca11e Initial load
duke
parents:
diff changeset
   980
        switch (op) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   981
        case getstatic:
06bc494ca11e Initial load
duke
parents:
diff changeset
   982
            state.push(((Symbol)(pool.pool[od])).erasure(types));
06bc494ca11e Initial load
duke
parents:
diff changeset
   983
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   984
        case putstatic:
06bc494ca11e Initial load
duke
parents:
diff changeset
   985
            state.pop(((Symbol)(pool.pool[od])).erasure(types));
06bc494ca11e Initial load
duke
parents:
diff changeset
   986
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   987
        case new_:
06bc494ca11e Initial load
duke
parents:
diff changeset
   988
            state.push(uninitializedObject(((Symbol)(pool.pool[od])).erasure(types), cp-3));
06bc494ca11e Initial load
duke
parents:
diff changeset
   989
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   990
        case sipush:
06bc494ca11e Initial load
duke
parents:
diff changeset
   991
            state.push(syms.intType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   992
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   993
        case if_acmp_null:
06bc494ca11e Initial load
duke
parents:
diff changeset
   994
        case if_acmp_nonnull:
06bc494ca11e Initial load
duke
parents:
diff changeset
   995
        case ifeq:
06bc494ca11e Initial load
duke
parents:
diff changeset
   996
        case ifne:
06bc494ca11e Initial load
duke
parents:
diff changeset
   997
        case iflt:
06bc494ca11e Initial load
duke
parents:
diff changeset
   998
        case ifge:
06bc494ca11e Initial load
duke
parents:
diff changeset
   999
        case ifgt:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1000
        case ifle:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1001
            state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1002
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1003
        case if_icmpeq:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1004
        case if_icmpne:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1005
        case if_icmplt:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1006
        case if_icmpge:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1007
        case if_icmpgt:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1008
        case if_icmple:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1009
        case if_acmpeq:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1010
        case if_acmpne:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1011
            state.pop(2);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1012
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1013
        case goto_:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1014
            markDead();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1015
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1016
        case putfield:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1017
            state.pop(((Symbol)(pool.pool[od])).erasure(types));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1018
            state.pop(1); // object ref
06bc494ca11e Initial load
duke
parents:
diff changeset
  1019
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1020
        case getfield:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1021
            state.pop(1); // object ref
06bc494ca11e Initial load
duke
parents:
diff changeset
  1022
            state.push(((Symbol)(pool.pool[od])).erasure(types));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1023
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1024
        case checkcast: {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1025
            state.pop(1); // object ref
06bc494ca11e Initial load
duke
parents:
diff changeset
  1026
            Object o = pool.pool[od];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1027
            Type t = (o instanceof Symbol)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1028
                ? ((Symbol)o).erasure(types)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1029
                : types.erasure(((Type)o));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1030
            state.push(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1031
            break; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1032
        case ldc2w:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1033
            state.push(typeForPool(pool.pool[od]));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1034
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1035
        case instanceof_:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1036
            state.pop(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1037
            state.push(syms.intType);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1038
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1039
        case ldc2:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1040
            state.push(typeForPool(pool.pool[od]));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1041
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1042
        case jsr:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1043
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1044
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1045
            throw new AssertionError(mnem(op));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1046
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1047
        // postop();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1048
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1049
06bc494ca11e Initial load
duke
parents:
diff changeset
  1050
    /** Emit an opcode with a four-byte operand field.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1051
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1052
    public void emitop4(int op, int od) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1053
        emitop(op);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1054
        if (!alive) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1055
        emit4(od);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1056
        switch (op) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1057
        case goto_w:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1058
            markDead();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1059
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1060
        case jsr_w:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1061
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1062
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1063
            throw new AssertionError(mnem(op));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1064
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1065
        // postop();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1066
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1067
06bc494ca11e Initial load
duke
parents:
diff changeset
  1068
    /** Align code pointer to next `incr' boundary.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1069
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1070
    public void align(int incr) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1071
        if (alive)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1072
            while (cp % incr != 0) emitop0(nop);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1073
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1074
06bc494ca11e Initial load
duke
parents:
diff changeset
  1075
    /** Place a byte into code at address pc. Pre: pc + 1 <= cp.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1076
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1077
    private void put1(int pc, int op) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1078
        code[pc] = (byte)op;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1079
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1080
06bc494ca11e Initial load
duke
parents:
diff changeset
  1081
    /** Place two bytes into code at address pc. Pre: pc + 2 <= cp.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1082
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1083
    private void put2(int pc, int od) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1084
        // pre: pc + 2 <= cp
06bc494ca11e Initial load
duke
parents:
diff changeset
  1085
        put1(pc, od >> 8);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1086
        put1(pc+1, od);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1087
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1088
06bc494ca11e Initial load
duke
parents:
diff changeset
  1089
    /** Place four  bytes into code at address pc. Pre: pc + 4 <= cp.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1090
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1091
    public void put4(int pc, int od) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1092
        // pre: pc + 4 <= cp
06bc494ca11e Initial load
duke
parents:
diff changeset
  1093
        put1(pc  , od >> 24);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1094
        put1(pc+1, od >> 16);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1095
        put1(pc+2, od >> 8);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1096
        put1(pc+3, od);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1097
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1098
06bc494ca11e Initial load
duke
parents:
diff changeset
  1099
    /** Return code byte at position pc as an unsigned int.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1100
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1101
    private int get1(int pc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1102
        return code[pc] & 0xFF;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1103
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1104
06bc494ca11e Initial load
duke
parents:
diff changeset
  1105
    /** Return two code bytes at position pc as an unsigned int.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1106
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1107
    private int get2(int pc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1108
        return (get1(pc) << 8) | get1(pc+1);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1109
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1110
06bc494ca11e Initial load
duke
parents:
diff changeset
  1111
    /** Return four code bytes at position pc as an int.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1112
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1113
    public int get4(int pc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1114
        // pre: pc + 4 <= cp
06bc494ca11e Initial load
duke
parents:
diff changeset
  1115
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1116
            (get1(pc) << 24) |
06bc494ca11e Initial load
duke
parents:
diff changeset
  1117
            (get1(pc+1) << 16) |
06bc494ca11e Initial load
duke
parents:
diff changeset
  1118
            (get1(pc+2) << 8) |
06bc494ca11e Initial load
duke
parents:
diff changeset
  1119
            (get1(pc+3));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1120
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1121
06bc494ca11e Initial load
duke
parents:
diff changeset
  1122
    /** Is code generation currently enabled?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1123
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1124
    public boolean isAlive() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1125
        return alive || pendingJumps != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1126
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1127
06bc494ca11e Initial load
duke
parents:
diff changeset
  1128
    /** Switch code generation on/off.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1129
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1130
    public void markDead() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1131
        alive = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1132
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1133
06bc494ca11e Initial load
duke
parents:
diff changeset
  1134
    /** Declare an entry point; return current code pointer
06bc494ca11e Initial load
duke
parents:
diff changeset
  1135
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1136
    public int entryPoint() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1137
        int pc = curPc();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1138
        alive = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1139
        pendingStackMap = needStackMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1140
        return pc;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1141
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1142
06bc494ca11e Initial load
duke
parents:
diff changeset
  1143
    /** Declare an entry point with initial state;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1144
     *  return current code pointer
06bc494ca11e Initial load
duke
parents:
diff changeset
  1145
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1146
    public int entryPoint(State state) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1147
        int pc = curPc();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1148
        alive = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1149
        this.state = state.dup();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1150
        assert state.stacksize <= max_stack;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1151
        if (debugCode) System.err.println("entry point " + state);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1152
        pendingStackMap = needStackMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1153
        return pc;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1154
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1155
06bc494ca11e Initial load
duke
parents:
diff changeset
  1156
    /** Declare an entry point with initial state plus a pushed value;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1157
     *  return current code pointer
06bc494ca11e Initial load
duke
parents:
diff changeset
  1158
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1159
    public int entryPoint(State state, Type pushed) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1160
        int pc = curPc();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1161
        alive = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1162
        this.state = state.dup();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1163
        assert state.stacksize <= max_stack;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1164
        this.state.push(pushed);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1165
        if (debugCode) System.err.println("entry point " + state);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1166
        pendingStackMap = needStackMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1167
        return pc;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1168
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1169
06bc494ca11e Initial load
duke
parents:
diff changeset
  1170
06bc494ca11e Initial load
duke
parents:
diff changeset
  1171
/**************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1172
 * Stack map generation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1173
 *************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1174
06bc494ca11e Initial load
duke
parents:
diff changeset
  1175
    /** An entry in the stack map. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1176
    static class StackMapFrame {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1177
        int pc;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1178
        Type[] locals;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1179
        Type[] stack;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1180
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1181
06bc494ca11e Initial load
duke
parents:
diff changeset
  1182
    /** A buffer of cldc stack map entries. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1183
    StackMapFrame[] stackMapBuffer = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1184
06bc494ca11e Initial load
duke
parents:
diff changeset
  1185
    /** A buffer of compressed StackMapTable entries. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1186
    StackMapTableFrame[] stackMapTableBuffer = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1187
    int stackMapBufferSize = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1188
06bc494ca11e Initial load
duke
parents:
diff changeset
  1189
    /** The last PC at which we generated a stack map. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1190
    int lastStackMapPC = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1191
06bc494ca11e Initial load
duke
parents:
diff changeset
  1192
    /** The last stack map frame in StackMapTable. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1193
    StackMapFrame lastFrame = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1194
06bc494ca11e Initial load
duke
parents:
diff changeset
  1195
    /** The stack map frame before the last one. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1196
    StackMapFrame frameBeforeLast = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1197
06bc494ca11e Initial load
duke
parents:
diff changeset
  1198
    /** Emit a stack map entry.  */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1199
    public void emitStackMap() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1200
        int pc = curPc();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1201
        if (!needStackMap) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1202
06bc494ca11e Initial load
duke
parents:
diff changeset
  1203
06bc494ca11e Initial load
duke
parents:
diff changeset
  1204
06bc494ca11e Initial load
duke
parents:
diff changeset
  1205
        switch (stackMap) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1206
            case CLDC:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1207
                emitCLDCStackMap(pc, getLocalsSize());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1208
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1209
            case JSR202:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1210
                emitStackMapFrame(pc, getLocalsSize());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1211
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1212
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1213
                throw new AssertionError("Should have chosen a stackmap format");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1214
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1215
        // DEBUG code follows
06bc494ca11e Initial load
duke
parents:
diff changeset
  1216
        if (debugCode) state.dump(pc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1217
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1218
06bc494ca11e Initial load
duke
parents:
diff changeset
  1219
    private int getLocalsSize() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1220
        int nextLocal = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1221
        for (int i=max_locals-1; i>=0; i--) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1222
            if (state.defined.isMember(i) && lvar[i] != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1223
                nextLocal = i + width(lvar[i].sym.erasure(types));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1224
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1225
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1226
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1227
        return nextLocal;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1228
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1229
06bc494ca11e Initial load
duke
parents:
diff changeset
  1230
    /** Emit a CLDC stack map frame. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1231
    void emitCLDCStackMap(int pc, int localsSize) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1232
        if (lastStackMapPC == pc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1233
            // drop existing stackmap at this offset
06bc494ca11e Initial load
duke
parents:
diff changeset
  1234
            stackMapBuffer[--stackMapBufferSize] = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1235
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1236
        lastStackMapPC = pc;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1237
06bc494ca11e Initial load
duke
parents:
diff changeset
  1238
        if (stackMapBuffer == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1239
            stackMapBuffer = new StackMapFrame[20];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1240
        } else if (stackMapBuffer.length == stackMapBufferSize) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1241
            StackMapFrame[] newStackMapBuffer =
06bc494ca11e Initial load
duke
parents:
diff changeset
  1242
                new StackMapFrame[stackMapBufferSize << 1];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1243
            System.arraycopy(stackMapBuffer, 0, newStackMapBuffer,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1244
                             0, stackMapBufferSize);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1245
            stackMapBuffer = newStackMapBuffer;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1246
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1247
        StackMapFrame frame =
06bc494ca11e Initial load
duke
parents:
diff changeset
  1248
            stackMapBuffer[stackMapBufferSize++] = new StackMapFrame();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1249
        frame.pc = pc;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1250
06bc494ca11e Initial load
duke
parents:
diff changeset
  1251
        frame.locals = new Type[localsSize];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1252
        for (int i=0; i<localsSize; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1253
            if (state.defined.isMember(i) && lvar[i] != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1254
                Type vtype = lvar[i].sym.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1255
                if (!(vtype instanceof UninitializedType))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1256
                    vtype = types.erasure(vtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1257
                frame.locals[i] = vtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1258
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1259
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1260
        frame.stack = new Type[state.stacksize];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1261
        for (int i=0; i<state.stacksize; i++)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1262
            frame.stack[i] = state.stack[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1263
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1264
06bc494ca11e Initial load
duke
parents:
diff changeset
  1265
    void emitStackMapFrame(int pc, int localsSize) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1266
        if (lastFrame == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1267
            // first frame
06bc494ca11e Initial load
duke
parents:
diff changeset
  1268
            lastFrame = getInitialFrame();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1269
        } else if (lastFrame.pc == pc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1270
            // drop existing stackmap at this offset
06bc494ca11e Initial load
duke
parents:
diff changeset
  1271
            stackMapTableBuffer[--stackMapBufferSize] = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1272
            lastFrame = frameBeforeLast;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1273
            frameBeforeLast = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1274
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1275
06bc494ca11e Initial load
duke
parents:
diff changeset
  1276
        StackMapFrame frame = new StackMapFrame();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1277
        frame.pc = pc;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1278
06bc494ca11e Initial load
duke
parents:
diff changeset
  1279
        int localCount = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1280
        Type[] locals = new Type[localsSize];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1281
        for (int i=0; i<localsSize; i++, localCount++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1282
            if (state.defined.isMember(i) && lvar[i] != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1283
                Type vtype = lvar[i].sym.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1284
                if (!(vtype instanceof UninitializedType))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1285
                    vtype = types.erasure(vtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1286
                locals[i] = vtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1287
                if (width(vtype) > 1) i++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1288
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1289
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1290
        frame.locals = new Type[localCount];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1291
        for (int i=0, j=0; i<localsSize; i++, j++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1292
            assert(j < localCount);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1293
            frame.locals[j] = locals[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1294
            if (width(locals[i]) > 1) i++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1295
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1296
06bc494ca11e Initial load
duke
parents:
diff changeset
  1297
        int stackCount = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1298
        for (int i=0; i<state.stacksize; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1299
            if (state.stack[i] != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1300
                stackCount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1301
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1302
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1303
        frame.stack = new Type[stackCount];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1304
        stackCount = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1305
        for (int i=0; i<state.stacksize; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1306
            if (state.stack[i] != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1307
                frame.stack[stackCount++] = state.stack[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1308
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1309
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1310
06bc494ca11e Initial load
duke
parents:
diff changeset
  1311
        if (stackMapTableBuffer == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1312
            stackMapTableBuffer = new StackMapTableFrame[20];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1313
        } else if (stackMapTableBuffer.length == stackMapBufferSize) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1314
            StackMapTableFrame[] newStackMapTableBuffer =
06bc494ca11e Initial load
duke
parents:
diff changeset
  1315
                new StackMapTableFrame[stackMapBufferSize << 1];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1316
            System.arraycopy(stackMapTableBuffer, 0, newStackMapTableBuffer,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1317
                             0, stackMapBufferSize);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1318
            stackMapTableBuffer = newStackMapTableBuffer;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1319
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1320
        stackMapTableBuffer[stackMapBufferSize++] =
06bc494ca11e Initial load
duke
parents:
diff changeset
  1321
                StackMapTableFrame.getInstance(frame, lastFrame.pc, lastFrame.locals, types);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1322
06bc494ca11e Initial load
duke
parents:
diff changeset
  1323
        frameBeforeLast = lastFrame;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1324
        lastFrame = frame;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1325
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1326
06bc494ca11e Initial load
duke
parents:
diff changeset
  1327
    StackMapFrame getInitialFrame() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1328
        StackMapFrame frame = new StackMapFrame();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1329
        List<Type> arg_types = ((MethodType)meth.externalType(types)).argtypes;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1330
        int len = arg_types.length();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1331
        int count = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1332
        if (!meth.isStatic()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1333
            Type thisType = meth.owner.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1334
            frame.locals = new Type[len+1];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1335
            if (meth.isConstructor() && thisType != syms.objectType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1336
                frame.locals[count++] = UninitializedType.uninitializedThis(thisType);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1337
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1338
                frame.locals[count++] = types.erasure(thisType);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1339
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1340
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1341
            frame.locals = new Type[len];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1342
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1343
        for (Type arg_type : arg_types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1344
            frame.locals[count++] = types.erasure(arg_type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1345
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1346
        frame.pc = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1347
        frame.stack = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1348
        return frame;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1349
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1350
06bc494ca11e Initial load
duke
parents:
diff changeset
  1351
06bc494ca11e Initial load
duke
parents:
diff changeset
  1352
/**************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1353
 * Operations having to do with jumps
06bc494ca11e Initial load
duke
parents:
diff changeset
  1354
 *************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1355
06bc494ca11e Initial load
duke
parents:
diff changeset
  1356
    /** A chain represents a list of unresolved jumps. Jump locations
06bc494ca11e Initial load
duke
parents:
diff changeset
  1357
     *  are sorted in decreasing order.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1358
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1359
    public static class Chain {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1360
06bc494ca11e Initial load
duke
parents:
diff changeset
  1361
        /** The position of the jump instruction.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1362
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1363
        public final int pc;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1364
06bc494ca11e Initial load
duke
parents:
diff changeset
  1365
        /** The machine state after the jump instruction.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1366
         *  Invariant: all elements of a chain list have the same stacksize
06bc494ca11e Initial load
duke
parents:
diff changeset
  1367
         *  and compatible stack and register contents.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1368
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1369
        Code.State state;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1370
06bc494ca11e Initial load
duke
parents:
diff changeset
  1371
        /** The next jump in the list.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1372
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1373
        public final Chain next;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1374
06bc494ca11e Initial load
duke
parents:
diff changeset
  1375
        /** Construct a chain from its jump position, stacksize, previous
06bc494ca11e Initial load
duke
parents:
diff changeset
  1376
         *  chain, and machine state.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1377
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1378
        public Chain(int pc, Chain next, Code.State state) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1379
            this.pc = pc;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1380
            this.next = next;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1381
            this.state = state;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1382
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1383
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1384
06bc494ca11e Initial load
duke
parents:
diff changeset
  1385
    /** Negate a branch opcode.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1386
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1387
    public static int negate(int opcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1388
        if (opcode == if_acmp_null) return if_acmp_nonnull;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1389
        else if (opcode == if_acmp_nonnull) return if_acmp_null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1390
        else return ((opcode + 1) ^ 1) - 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1391
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1392
06bc494ca11e Initial load
duke
parents:
diff changeset
  1393
    /** Emit a jump instruction.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1394
     *  Return code pointer of instruction to be patched.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1395
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1396
    public int emitJump(int opcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1397
        if (fatcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1398
            if (opcode == goto_ || opcode == jsr) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1399
                emitop4(opcode + goto_w - goto_, 0);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1400
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1401
                emitop2(negate(opcode), 8);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1402
                emitop4(goto_w, 0);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1403
                alive = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1404
                pendingStackMap = needStackMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1405
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1406
            return cp - 5;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1407
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1408
            emitop2(opcode, 0);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1409
            return cp - 3;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1410
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1411
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1412
06bc494ca11e Initial load
duke
parents:
diff changeset
  1413
    /** Emit a branch with given opcode; return its chain.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1414
     *  branch differs from jump in that jsr is treated as no-op.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1415
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1416
    public Chain branch(int opcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1417
        Chain result = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1418
        if (opcode == goto_) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1419
            result = pendingJumps;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1420
            pendingJumps = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1421
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1422
        if (opcode != dontgoto && isAlive()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1423
            result = new Chain(emitJump(opcode),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1424
                               result,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1425
                               state.dup());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1426
            fixedPc = fatcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1427
            if (opcode == goto_) alive = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1428
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1429
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1430
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1431
06bc494ca11e Initial load
duke
parents:
diff changeset
  1432
    /** Resolve chain to point to given target.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1433
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1434
    public void resolve(Chain chain, int target) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1435
        boolean changed = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1436
        State newState = state;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1437
        for (; chain != null; chain = chain.next) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1438
            assert state != chain.state;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1439
            assert target > chain.pc || state.stacksize == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1440
            if (target >= cp) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1441
                target = cp;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1442
            } else if (get1(target) == goto_) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1443
                if (fatcode) target = target + get4(target + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1444
                else target = target + get2(target + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1445
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1446
            if (get1(chain.pc) == goto_ &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1447
                chain.pc + 3 == target && target == cp && !fixedPc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1448
                // If goto the next instruction, the jump is not needed:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1449
                // compact the code.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1450
                cp = cp - 3;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1451
                target = target - 3;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1452
                if (chain.next == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1453
                    // This is the only jump to the target. Exit the loop
06bc494ca11e Initial load
duke
parents:
diff changeset
  1454
                    // without setting new state. The code is reachable
06bc494ca11e Initial load
duke
parents:
diff changeset
  1455
                    // from the instruction before goto_.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1456
                    alive = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1457
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1458
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1459
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1460
                if (fatcode)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1461
                    put4(chain.pc + 1, target - chain.pc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1462
                else if (target - chain.pc < Short.MIN_VALUE ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1463
                         target - chain.pc > Short.MAX_VALUE)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1464
                    fatcode = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1465
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1466
                    put2(chain.pc + 1, target - chain.pc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1467
                assert !alive ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1468
                    chain.state.stacksize == newState.stacksize &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1469
                    chain.state.nlocks == newState.nlocks;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1470
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1471
            fixedPc = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1472
            if (cp == target) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1473
                changed = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1474
                if (debugCode)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1475
                    System.err.println("resolving chain state=" + chain.state);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1476
                if (alive) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1477
                    newState = chain.state.join(newState);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1478
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1479
                    newState = chain.state;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1480
                    alive = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1481
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1482
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1483
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1484
        assert !changed || state != newState;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1485
        if (state != newState) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1486
            setDefined(newState.defined);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1487
            state = newState;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1488
            pendingStackMap = needStackMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1489
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1490
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1491
06bc494ca11e Initial load
duke
parents:
diff changeset
  1492
    /** Resolve chain to point to current code pointer.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1493
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1494
    public void resolve(Chain chain) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1495
        assert
06bc494ca11e Initial load
duke
parents:
diff changeset
  1496
            !alive ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1497
            chain==null ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1498
            state.stacksize == chain.state.stacksize &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1499
            state.nlocks == chain.state.nlocks;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1500
        pendingJumps = mergeChains(chain, pendingJumps);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1501
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1502
06bc494ca11e Initial load
duke
parents:
diff changeset
  1503
    /** Resolve any pending jumps.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1504
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1505
    public void resolvePending() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1506
        Chain x = pendingJumps;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1507
        pendingJumps = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1508
        resolve(x, cp);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1509
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1510
06bc494ca11e Initial load
duke
parents:
diff changeset
  1511
    /** Merge the jumps in of two chains into one.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1512
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1513
    public static Chain mergeChains(Chain chain1, Chain chain2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1514
        // recursive merge sort
06bc494ca11e Initial load
duke
parents:
diff changeset
  1515
        if (chain2 == null) return chain1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1516
        if (chain1 == null) return chain2;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1517
        assert
06bc494ca11e Initial load
duke
parents:
diff changeset
  1518
            chain1.state.stacksize == chain2.state.stacksize &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1519
            chain1.state.nlocks == chain2.state.nlocks;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1520
        if (chain1.pc < chain2.pc)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1521
            return new Chain(
06bc494ca11e Initial load
duke
parents:
diff changeset
  1522
                chain2.pc,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1523
                mergeChains(chain1, chain2.next),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1524
                chain2.state);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1525
        return new Chain(
06bc494ca11e Initial load
duke
parents:
diff changeset
  1526
                chain1.pc,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1527
                mergeChains(chain1.next, chain2),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1528
                chain1.state);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1529
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1530
06bc494ca11e Initial load
duke
parents:
diff changeset
  1531
06bc494ca11e Initial load
duke
parents:
diff changeset
  1532
/* **************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1533
 * Catch clauses
06bc494ca11e Initial load
duke
parents:
diff changeset
  1534
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1535
06bc494ca11e Initial load
duke
parents:
diff changeset
  1536
    /** Add a catch clause to code.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1537
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1538
    public void addCatch(
06bc494ca11e Initial load
duke
parents:
diff changeset
  1539
        char startPc, char endPc, char handlerPc, char catchType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1540
        catchInfo.append(new char[]{startPc, endPc, handlerPc, catchType});
06bc494ca11e Initial load
duke
parents:
diff changeset
  1541
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1542
06bc494ca11e Initial load
duke
parents:
diff changeset
  1543
06bc494ca11e Initial load
duke
parents:
diff changeset
  1544
/* **************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1545
 * Line numbers
06bc494ca11e Initial load
duke
parents:
diff changeset
  1546
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1547
06bc494ca11e Initial load
duke
parents:
diff changeset
  1548
    /** Add a line number entry.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1549
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1550
    public void addLineNumber(char startPc, char lineNumber) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1551
        if (lineDebugInfo) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1552
            if (lineInfo.nonEmpty() && lineInfo.head[0] == startPc)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1553
                lineInfo = lineInfo.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1554
            if (lineInfo.isEmpty() || lineInfo.head[1] != lineNumber)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1555
                lineInfo = lineInfo.prepend(new char[]{startPc, lineNumber});
06bc494ca11e Initial load
duke
parents:
diff changeset
  1556
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1557
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1558
06bc494ca11e Initial load
duke
parents:
diff changeset
  1559
    /** Mark beginning of statement.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1560
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1561
    public void statBegin(int pos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1562
        if (pos != Position.NOPOS) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1563
            pendingStatPos = pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1564
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1565
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1566
06bc494ca11e Initial load
duke
parents:
diff changeset
  1567
    /** Force stat begin eagerly
06bc494ca11e Initial load
duke
parents:
diff changeset
  1568
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1569
    public void markStatBegin() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1570
        if (alive && lineDebugInfo) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1571
            int line = lineMap.getLineNumber(pendingStatPos);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1572
            char cp1 = (char)cp;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1573
            char line1 = (char)line;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1574
            if (cp1 == cp && line1 == line)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1575
                addLineNumber(cp1, line1);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1576
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1577
        pendingStatPos = Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1578
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1579
06bc494ca11e Initial load
duke
parents:
diff changeset
  1580
06bc494ca11e Initial load
duke
parents:
diff changeset
  1581
/* **************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1582
 * Simulated VM machine state
06bc494ca11e Initial load
duke
parents:
diff changeset
  1583
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1584
06bc494ca11e Initial load
duke
parents:
diff changeset
  1585
    class State implements Cloneable {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1586
        /** The set of registers containing values. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1587
        Bits defined;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1588
06bc494ca11e Initial load
duke
parents:
diff changeset
  1589
        /** The (types of the) contents of the machine stack. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1590
        Type[] stack;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1591
06bc494ca11e Initial load
duke
parents:
diff changeset
  1592
        /** The first stack position currently unused. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1593
        int stacksize;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1594
06bc494ca11e Initial load
duke
parents:
diff changeset
  1595
        /** The numbers of registers containing locked monitors. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1596
        int[] locks;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1597
        int nlocks;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1598
06bc494ca11e Initial load
duke
parents:
diff changeset
  1599
        State() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1600
            defined = new Bits();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1601
            stack = new Type[16];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1602
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1603
06bc494ca11e Initial load
duke
parents:
diff changeset
  1604
        State dup() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1605
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1606
                State state = (State)super.clone();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1607
                state.defined = defined.dup();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1608
                state.stack = stack.clone();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1609
                if (locks != null) state.locks = locks.clone();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1610
                if (debugCode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1611
                    System.err.println("duping state " + this);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1612
                    dump();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1613
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1614
                return state;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1615
            } catch (CloneNotSupportedException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1616
                throw new AssertionError(ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1617
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1618
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1619
06bc494ca11e Initial load
duke
parents:
diff changeset
  1620
        void lock(int register) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1621
            if (locks == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1622
                locks = new int[20];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1623
            } else if (locks.length == nlocks) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1624
                int[] newLocks = new int[locks.length << 1];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1625
                System.arraycopy(locks, 0, newLocks, 0, locks.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1626
                locks = newLocks;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1627
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1628
            locks[nlocks] = register;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1629
            nlocks++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1630
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1631
06bc494ca11e Initial load
duke
parents:
diff changeset
  1632
        void unlock(int register) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1633
            nlocks--;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1634
            assert locks[nlocks] == register;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1635
            locks[nlocks] = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1636
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1637
06bc494ca11e Initial load
duke
parents:
diff changeset
  1638
        void push(Type t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1639
            if (debugCode) System.err.println("   pushing " + t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1640
            switch (t.tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1641
            case TypeTags.VOID:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1642
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1643
            case TypeTags.BYTE:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1644
            case TypeTags.CHAR:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1645
            case TypeTags.SHORT:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1646
            case TypeTags.BOOLEAN:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1647
                t = syms.intType;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1648
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1649
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1650
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1651
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1652
            if (stacksize+2 >= stack.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1653
                Type[] newstack = new Type[2*stack.length];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1654
                System.arraycopy(stack, 0, newstack, 0, stack.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1655
                stack = newstack;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1656
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1657
            stack[stacksize++] = t;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1658
            switch (width(t)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1659
            case 1:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1660
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1661
            case 2:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1662
                stack[stacksize++] = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1663
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1664
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1665
                throw new AssertionError(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1666
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1667
            if (stacksize > max_stack)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1668
                max_stack = stacksize;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1669
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1670
06bc494ca11e Initial load
duke
parents:
diff changeset
  1671
        Type pop1() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1672
            if (debugCode) System.err.println("   popping " + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1673
            stacksize--;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1674
            Type result = stack[stacksize];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1675
            stack[stacksize] = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1676
            assert result != null && width(result) == 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1677
            return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1678
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1679
06bc494ca11e Initial load
duke
parents:
diff changeset
  1680
        Type peek() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1681
            return stack[stacksize-1];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1682
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1683
06bc494ca11e Initial load
duke
parents:
diff changeset
  1684
        Type pop2() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1685
            if (debugCode) System.err.println("   popping " + 2);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1686
            stacksize -= 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1687
            Type result = stack[stacksize];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1688
            stack[stacksize] = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1689
            assert stack[stacksize+1] == null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1690
            assert result != null && width(result) == 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1691
            return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1692
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1693
06bc494ca11e Initial load
duke
parents:
diff changeset
  1694
        void pop(int n) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1695
            if (debugCode) System.err.println("   popping " + n);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1696
            while (n > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1697
                stack[--stacksize] = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1698
                n--;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1699
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1700
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1701
06bc494ca11e Initial load
duke
parents:
diff changeset
  1702
        void pop(Type t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1703
            pop(width(t));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1704
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1705
06bc494ca11e Initial load
duke
parents:
diff changeset
  1706
        /** Force the top of the stack to be treated as this supertype
06bc494ca11e Initial load
duke
parents:
diff changeset
  1707
         *  of its current type. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1708
        void forceStackTop(Type t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1709
            if (!alive) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1710
            switch (t.tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1711
            case CLASS:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1712
            case ARRAY:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1713
                int width = width(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1714
                Type old = stack[stacksize-width];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1715
                assert types.isSubtype(types.erasure(old),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1716
                                       types.erasure(t));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1717
                stack[stacksize-width] = t;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1718
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1719
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1720
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1721
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1722
06bc494ca11e Initial load
duke
parents:
diff changeset
  1723
        void markInitialized(UninitializedType old) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1724
            Type newtype = old.initializedType();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1725
            for (int i=0; i<stacksize; i++)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1726
                if (stack[i] == old) stack[i] = newtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1727
            for (int i=0; i<lvar.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1728
                LocalVar lv = lvar[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1729
                if (lv != null && lv.sym.type == old) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1730
                    VarSymbol sym = lv.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1731
                    sym = sym.clone(sym.owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1732
                    sym.type = newtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1733
                    LocalVar newlv = lvar[i] = new LocalVar(sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1734
                    // should the following be initialized to cp?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1735
                    newlv.start_pc = lv.start_pc;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1736
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1737
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1738
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1739
06bc494ca11e Initial load
duke
parents:
diff changeset
  1740
        State join(State other) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1741
            defined = defined.andSet(other.defined);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1742
            assert stacksize == other.stacksize;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1743
            assert nlocks == other.nlocks;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1744
            for (int i=0; i<stacksize; ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1745
                Type t = stack[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1746
                Type tother = other.stack[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1747
                Type result =
06bc494ca11e Initial load
duke
parents:
diff changeset
  1748
                    t==tother ? t :
06bc494ca11e Initial load
duke
parents:
diff changeset
  1749
                    types.isSubtype(t, tother) ? tother :
06bc494ca11e Initial load
duke
parents:
diff changeset
  1750
                    types.isSubtype(tother, t) ? t :
06bc494ca11e Initial load
duke
parents:
diff changeset
  1751
                    error();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1752
                int w = width(result);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1753
                stack[i] = result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1754
                if (w == 2) assert stack[i+1] == null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1755
                i += w;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1756
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1757
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1758
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1759
06bc494ca11e Initial load
duke
parents:
diff changeset
  1760
        Type error() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1761
            throw new AssertionError("inconsistent stack types at join point");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1762
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1763
06bc494ca11e Initial load
duke
parents:
diff changeset
  1764
        void dump() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1765
            dump(-1);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1766
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1767
06bc494ca11e Initial load
duke
parents:
diff changeset
  1768
        void dump(int pc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1769
            System.err.print("stackMap for " + meth.owner + "." + meth);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1770
            if (pc == -1)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1771
                System.out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1772
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1773
                System.out.println(" at " + pc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1774
            System.err.println(" stack (from bottom):");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1775
            for (int i=0; i<stacksize; i++)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1776
                System.err.println("  " + i + ": " + stack[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1777
06bc494ca11e Initial load
duke
parents:
diff changeset
  1778
            int lastLocal = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1779
            for (int i=max_locals-1; i>=0; i--) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1780
                if (defined.isMember(i)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1781
                    lastLocal = i;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1782
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1783
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1784
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1785
            if (lastLocal >= 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1786
                System.err.println(" locals:");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1787
            for (int i=0; i<=lastLocal; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1788
                System.err.print("  " + i + ": ");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1789
                if (defined.isMember(i)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1790
                    LocalVar var = lvar[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1791
                    if (var == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1792
                        System.err.println("(none)");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1793
                    } else if (var.sym == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1794
                        System.err.println("UNKNOWN!");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1795
                    else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1796
                        System.err.println("" + var.sym + " of type " +
06bc494ca11e Initial load
duke
parents:
diff changeset
  1797
                                           var.sym.erasure(types));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1798
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1799
                    System.err.println("undefined");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1800
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1801
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1802
            if (nlocks != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1803
                System.err.print(" locks:");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1804
                for (int i=0; i<nlocks; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1805
                    System.err.print(" " + locks[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1806
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1807
                System.err.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1808
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1809
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1810
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1811
06bc494ca11e Initial load
duke
parents:
diff changeset
  1812
    static Type jsrReturnValue = new Type(TypeTags.INT, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1813
06bc494ca11e Initial load
duke
parents:
diff changeset
  1814
06bc494ca11e Initial load
duke
parents:
diff changeset
  1815
/* **************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1816
 * Local variables
06bc494ca11e Initial load
duke
parents:
diff changeset
  1817
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1818
06bc494ca11e Initial load
duke
parents:
diff changeset
  1819
    /** A live range of a local variable. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1820
    static class LocalVar {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1821
        final VarSymbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1822
        final char reg;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1823
        char start_pc = Character.MAX_VALUE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1824
        char length = Character.MAX_VALUE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1825
        LocalVar(VarSymbol v) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1826
            this.sym = v;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1827
            this.reg = (char)v.adr;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1828
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1829
        public LocalVar dup() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1830
            return new LocalVar(sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1831
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1832
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1833
            return "" + sym + " in register " + ((int)reg) + " starts at pc=" + ((int)start_pc) + " length=" + ((int)length);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1834
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1835
    };
06bc494ca11e Initial load
duke
parents:
diff changeset
  1836
06bc494ca11e Initial load
duke
parents:
diff changeset
  1837
    /** Local variables, indexed by register. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1838
    LocalVar[] lvar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1839
06bc494ca11e Initial load
duke
parents:
diff changeset
  1840
    /** Add a new local variable. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1841
    private void addLocalVar(VarSymbol v) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1842
        int adr = v.adr;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1843
        if (adr+1 >= lvar.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1844
            int newlength = lvar.length << 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1845
            if (newlength <= adr) newlength = adr + 10;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1846
            LocalVar[] new_lvar = new LocalVar[newlength];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1847
            System.arraycopy(lvar, 0, new_lvar, 0, lvar.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1848
            lvar = new_lvar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1849
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1850
        assert lvar[adr] == null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1851
        if (pendingJumps != null) resolvePending();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1852
        lvar[adr] = new LocalVar(v);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1853
        state.defined.excl(adr);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1854
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1855
06bc494ca11e Initial load
duke
parents:
diff changeset
  1856
    /** Set the current variable defined state. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1857
    public void setDefined(Bits newDefined) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1858
        if (alive && newDefined != state.defined) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1859
            Bits diff = state.defined.dup().xorSet(newDefined);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1860
            for (int adr = diff.nextBit(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1861
                 adr >= 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1862
                 adr = diff.nextBit(adr+1)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1863
                if (adr >= nextreg)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1864
                    state.defined.excl(adr);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1865
                else if (state.defined.isMember(adr))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1866
                    setUndefined(adr);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1867
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1868
                    setDefined(adr);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1869
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1870
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1871
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1872
06bc494ca11e Initial load
duke
parents:
diff changeset
  1873
    /** Mark a register as being (possibly) defined. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1874
    public void setDefined(int adr) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1875
        LocalVar v = lvar[adr];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1876
        if (v == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1877
            state.defined.excl(adr);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1878
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1879
            state.defined.incl(adr);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1880
            if (cp < Character.MAX_VALUE) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1881
                if (v.start_pc == Character.MAX_VALUE)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1882
                    v.start_pc = (char)cp;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1883
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1884
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1885
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1886
06bc494ca11e Initial load
duke
parents:
diff changeset
  1887
    /** Mark a register as being undefined. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1888
    public void setUndefined(int adr) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1889
        state.defined.excl(adr);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1890
        if (adr < lvar.length &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1891
            lvar[adr] != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1892
            lvar[adr].start_pc != Character.MAX_VALUE) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1893
            LocalVar v = lvar[adr];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1894
            char length = (char)(curPc() - v.start_pc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1895
            if (length > 0 && length < Character.MAX_VALUE) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1896
                lvar[adr] = v.dup();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1897
                v.length = length;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1898
                putVar(v);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1899
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1900
                v.start_pc = Character.MAX_VALUE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1901
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1902
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1903
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1904
06bc494ca11e Initial load
duke
parents:
diff changeset
  1905
    /** End the scope of a variable. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1906
    private void endScope(int adr) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1907
        LocalVar v = lvar[adr];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1908
        if (v != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1909
            lvar[adr] = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1910
            if (v.start_pc != Character.MAX_VALUE) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1911
                char length = (char)(curPc() - v.start_pc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1912
                if (length < Character.MAX_VALUE) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1913
                    v.length = length;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1914
                    putVar(v);
3151
41800a86aad3 6854796: update JSR308 impl with latest code from type-annotations repo
jjg
parents: 3149
diff changeset
  1915
                    fillLocalVarPosition(v);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1916
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1917
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1918
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1919
        state.defined.excl(adr);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1920
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1921
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1922
    private void fillLocalVarPosition(LocalVar lv) {
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1923
        if (lv == null || lv.sym == null
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1924
                || lv.sym.typeAnnotations == null)
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1925
            return;
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1926
        for (Attribute.TypeCompound ta : lv.sym.typeAnnotations) {
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1927
            TypeAnnotationPosition p = ta.position;
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1928
            while (p != null) {
4866
21f0ac9e5a20 6918127: improve handling of TypeAnnotationPosition fields
jjg
parents: 3300
diff changeset
  1929
                p.lvarOffset = new int[] { (int)lv.start_pc };
21f0ac9e5a20 6918127: improve handling of TypeAnnotationPosition fields
jjg
parents: 3300
diff changeset
  1930
                p.lvarLength = new int[] { (int)lv.length };
21f0ac9e5a20 6918127: improve handling of TypeAnnotationPosition fields
jjg
parents: 3300
diff changeset
  1931
                p.lvarIndex = new int[] { (int)lv.reg };
3151
41800a86aad3 6854796: update JSR308 impl with latest code from type-annotations repo
jjg
parents: 3149
diff changeset
  1932
                p.isValidOffset = true;
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1933
                p = p.wildcard_position;
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1934
            }
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1935
        }
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1936
    }
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1937
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1938
    /** Put a live variable range into the buffer to be output to the
06bc494ca11e Initial load
duke
parents:
diff changeset
  1939
     *  class file.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1940
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1941
    void putVar(LocalVar var) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1942
        if (!varDebugInfo) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1943
        if ((var.sym.flags() & Flags.SYNTHETIC) != 0) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1944
        if (varBuffer == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1945
            varBuffer = new LocalVar[20];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1946
        else if (varBufferSize >= varBuffer.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1947
            LocalVar[] newVarBuffer = new LocalVar[varBufferSize*2];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1948
            System.arraycopy(varBuffer, 0, newVarBuffer, 0, varBuffer.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1949
            varBuffer = newVarBuffer;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1950
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1951
        varBuffer[varBufferSize++] = var;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1952
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1953
06bc494ca11e Initial load
duke
parents:
diff changeset
  1954
    /** Previously live local variables, to be put into the variable table. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1955
    LocalVar[] varBuffer;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1956
    int varBufferSize;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1957
06bc494ca11e Initial load
duke
parents:
diff changeset
  1958
    /** Create a new local variable address and return it.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1959
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1960
    private int newLocal(int typecode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1961
        int reg = nextreg;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1962
        int w = width(typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1963
        nextreg = reg + w;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1964
        if (nextreg > max_locals) max_locals = nextreg;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1965
        return reg;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1966
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1967
06bc494ca11e Initial load
duke
parents:
diff changeset
  1968
    private int newLocal(Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1969
        return newLocal(typecode(type));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1970
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1971
06bc494ca11e Initial load
duke
parents:
diff changeset
  1972
    public int newLocal(VarSymbol v) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1973
        int reg = v.adr = newLocal(v.erasure(types));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1974
        addLocalVar(v);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1975
        return reg;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1976
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1977
06bc494ca11e Initial load
duke
parents:
diff changeset
  1978
    /** Start a set of fresh registers.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1979
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1980
    public void newRegSegment() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1981
        nextreg = max_locals;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1982
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1983
06bc494ca11e Initial load
duke
parents:
diff changeset
  1984
    /** End scopes of all variables with registers >= first.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1985
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1986
    public void endScopes(int first) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1987
        int prevNextReg = nextreg;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1988
        nextreg = first;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1989
        for (int i = nextreg; i < prevNextReg; i++) endScope(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1990
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1991
06bc494ca11e Initial load
duke
parents:
diff changeset
  1992
/**************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1993
 * static tables
06bc494ca11e Initial load
duke
parents:
diff changeset
  1994
 *************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1995
06bc494ca11e Initial load
duke
parents:
diff changeset
  1996
    public static String mnem(int opcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1997
        return Mneumonics.mnem[opcode];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1998
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1999
06bc494ca11e Initial load
duke
parents:
diff changeset
  2000
    private static class Mneumonics {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2001
        private final static String[] mnem = new String[ByteCodeCount];
06bc494ca11e Initial load
duke
parents:
diff changeset
  2002
        static {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2003
            mnem[nop] = "nop";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2004
            mnem[aconst_null] = "aconst_null";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2005
            mnem[iconst_m1] = "iconst_m1";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2006
            mnem[iconst_0] = "iconst_0";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2007
            mnem[iconst_1] = "iconst_1";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2008
            mnem[iconst_2] = "iconst_2";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2009
            mnem[iconst_3] = "iconst_3";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2010
            mnem[iconst_4] = "iconst_4";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2011
            mnem[iconst_5] = "iconst_5";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2012
            mnem[lconst_0] = "lconst_0";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2013
            mnem[lconst_1] = "lconst_1";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2014
            mnem[fconst_0] = "fconst_0";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2015
            mnem[fconst_1] = "fconst_1";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2016
            mnem[fconst_2] = "fconst_2";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2017
            mnem[dconst_0] = "dconst_0";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2018
            mnem[dconst_1] = "dconst_1";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2019
            mnem[bipush] = "bipush";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2020
            mnem[sipush] = "sipush";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2021
            mnem[ldc1] = "ldc1";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2022
            mnem[ldc2] = "ldc2";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2023
            mnem[ldc2w] = "ldc2w";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2024
            mnem[iload] = "iload";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2025
            mnem[lload] = "lload";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2026
            mnem[fload] = "fload";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2027
            mnem[dload] = "dload";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2028
            mnem[aload] = "aload";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2029
            mnem[iload_0] = "iload_0";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2030
            mnem[lload_0] = "lload_0";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2031
            mnem[fload_0] = "fload_0";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2032
            mnem[dload_0] = "dload_0";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2033
            mnem[aload_0] = "aload_0";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2034
            mnem[iload_1] = "iload_1";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2035
            mnem[lload_1] = "lload_1";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2036
            mnem[fload_1] = "fload_1";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2037
            mnem[dload_1] = "dload_1";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2038
            mnem[aload_1] = "aload_1";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2039
            mnem[iload_2] = "iload_2";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2040
            mnem[lload_2] = "lload_2";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2041
            mnem[fload_2] = "fload_2";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2042
            mnem[dload_2] = "dload_2";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2043
            mnem[aload_2] = "aload_2";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2044
            mnem[iload_3] = "iload_3";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2045
            mnem[lload_3] = "lload_3";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2046
            mnem[fload_3] = "fload_3";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2047
            mnem[dload_3] = "dload_3";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2048
            mnem[aload_3] = "aload_3";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2049
            mnem[iaload] = "iaload";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2050
            mnem[laload] = "laload";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2051
            mnem[faload] = "faload";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2052
            mnem[daload] = "daload";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2053
            mnem[aaload] = "aaload";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2054
            mnem[baload] = "baload";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2055
            mnem[caload] = "caload";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2056
            mnem[saload] = "saload";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2057
            mnem[istore] = "istore";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2058
            mnem[lstore] = "lstore";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2059
            mnem[fstore] = "fstore";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2060
            mnem[dstore] = "dstore";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2061
            mnem[astore] = "astore";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2062
            mnem[istore_0] = "istore_0";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2063
            mnem[lstore_0] = "lstore_0";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2064
            mnem[fstore_0] = "fstore_0";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2065
            mnem[dstore_0] = "dstore_0";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2066
            mnem[astore_0] = "astore_0";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2067
            mnem[istore_1] = "istore_1";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2068
            mnem[lstore_1] = "lstore_1";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2069
            mnem[fstore_1] = "fstore_1";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2070
            mnem[dstore_1] = "dstore_1";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2071
            mnem[astore_1] = "astore_1";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2072
            mnem[istore_2] = "istore_2";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2073
            mnem[lstore_2] = "lstore_2";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2074
            mnem[fstore_2] = "fstore_2";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2075
            mnem[dstore_2] = "dstore_2";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2076
            mnem[astore_2] = "astore_2";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2077
            mnem[istore_3] = "istore_3";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2078
            mnem[lstore_3] = "lstore_3";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2079
            mnem[fstore_3] = "fstore_3";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2080
            mnem[dstore_3] = "dstore_3";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2081
            mnem[astore_3] = "astore_3";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2082
            mnem[iastore] = "iastore";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2083
            mnem[lastore] = "lastore";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2084
            mnem[fastore] = "fastore";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2085
            mnem[dastore] = "dastore";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2086
            mnem[aastore] = "aastore";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2087
            mnem[bastore] = "bastore";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2088
            mnem[castore] = "castore";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2089
            mnem[sastore] = "sastore";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2090
            mnem[pop] = "pop";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2091
            mnem[pop2] = "pop2";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2092
            mnem[dup] = "dup";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2093
            mnem[dup_x1] = "dup_x1";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2094
            mnem[dup_x2] = "dup_x2";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2095
            mnem[dup2] = "dup2";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2096
            mnem[dup2_x1] = "dup2_x1";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2097
            mnem[dup2_x2] = "dup2_x2";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2098
            mnem[swap] = "swap";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2099
            mnem[iadd] = "iadd";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2100
            mnem[ladd] = "ladd";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2101
            mnem[fadd] = "fadd";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2102
            mnem[dadd] = "dadd";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2103
            mnem[isub] = "isub";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2104
            mnem[lsub] = "lsub";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2105
            mnem[fsub] = "fsub";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2106
            mnem[dsub] = "dsub";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2107
            mnem[imul] = "imul";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2108
            mnem[lmul] = "lmul";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2109
            mnem[fmul] = "fmul";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2110
            mnem[dmul] = "dmul";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2111
            mnem[idiv] = "idiv";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2112
            mnem[ldiv] = "ldiv";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2113
            mnem[fdiv] = "fdiv";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2114
            mnem[ddiv] = "ddiv";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2115
            mnem[imod] = "imod";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2116
            mnem[lmod] = "lmod";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2117
            mnem[fmod] = "fmod";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2118
            mnem[dmod] = "dmod";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2119
            mnem[ineg] = "ineg";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2120
            mnem[lneg] = "lneg";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2121
            mnem[fneg] = "fneg";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2122
            mnem[dneg] = "dneg";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2123
            mnem[ishl] = "ishl";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2124
            mnem[lshl] = "lshl";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2125
            mnem[ishr] = "ishr";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2126
            mnem[lshr] = "lshr";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2127
            mnem[iushr] = "iushr";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2128
            mnem[lushr] = "lushr";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2129
            mnem[iand] = "iand";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2130
            mnem[land] = "land";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2131
            mnem[ior] = "ior";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2132
            mnem[lor] = "lor";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2133
            mnem[ixor] = "ixor";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2134
            mnem[lxor] = "lxor";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2135
            mnem[iinc] = "iinc";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2136
            mnem[i2l] = "i2l";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2137
            mnem[i2f] = "i2f";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2138
            mnem[i2d] = "i2d";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2139
            mnem[l2i] = "l2i";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2140
            mnem[l2f] = "l2f";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2141
            mnem[l2d] = "l2d";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2142
            mnem[f2i] = "f2i";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2143
            mnem[f2l] = "f2l";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2144
            mnem[f2d] = "f2d";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2145
            mnem[d2i] = "d2i";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2146
            mnem[d2l] = "d2l";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2147
            mnem[d2f] = "d2f";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2148
            mnem[int2byte] = "int2byte";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2149
            mnem[int2char] = "int2char";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2150
            mnem[int2short] = "int2short";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2151
            mnem[lcmp] = "lcmp";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2152
            mnem[fcmpl] = "fcmpl";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2153
            mnem[fcmpg] = "fcmpg";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2154
            mnem[dcmpl] = "dcmpl";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2155
            mnem[dcmpg] = "dcmpg";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2156
            mnem[ifeq] = "ifeq";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2157
            mnem[ifne] = "ifne";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2158
            mnem[iflt] = "iflt";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2159
            mnem[ifge] = "ifge";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2160
            mnem[ifgt] = "ifgt";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2161
            mnem[ifle] = "ifle";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2162
            mnem[if_icmpeq] = "if_icmpeq";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2163
            mnem[if_icmpne] = "if_icmpne";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2164
            mnem[if_icmplt] = "if_icmplt";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2165
            mnem[if_icmpge] = "if_icmpge";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2166
            mnem[if_icmpgt] = "if_icmpgt";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2167
            mnem[if_icmple] = "if_icmple";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2168
            mnem[if_acmpeq] = "if_acmpeq";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2169
            mnem[if_acmpne] = "if_acmpne";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2170
            mnem[goto_] = "goto_";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2171
            mnem[jsr] = "jsr";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2172
            mnem[ret] = "ret";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2173
            mnem[tableswitch] = "tableswitch";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2174
            mnem[lookupswitch] = "lookupswitch";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2175
            mnem[ireturn] = "ireturn";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2176
            mnem[lreturn] = "lreturn";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2177
            mnem[freturn] = "freturn";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2178
            mnem[dreturn] = "dreturn";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2179
            mnem[areturn] = "areturn";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2180
            mnem[return_] = "return_";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2181
            mnem[getstatic] = "getstatic";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2182
            mnem[putstatic] = "putstatic";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2183
            mnem[getfield] = "getfield";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2184
            mnem[putfield] = "putfield";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2185
            mnem[invokevirtual] = "invokevirtual";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2186
            mnem[invokespecial] = "invokespecial";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2187
            mnem[invokestatic] = "invokestatic";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2188
            mnem[invokeinterface] = "invokeinterface";
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
  2189
            mnem[invokedynamic] = "invokedynamic";
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2190
            mnem[new_] = "new_";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2191
            mnem[newarray] = "newarray";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2192
            mnem[anewarray] = "anewarray";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2193
            mnem[arraylength] = "arraylength";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2194
            mnem[athrow] = "athrow";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2195
            mnem[checkcast] = "checkcast";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2196
            mnem[instanceof_] = "instanceof_";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2197
            mnem[monitorenter] = "monitorenter";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2198
            mnem[monitorexit] = "monitorexit";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2199
            mnem[wide] = "wide";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2200
            mnem[multianewarray] = "multianewarray";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2201
            mnem[if_acmp_null] = "if_acmp_null";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2202
            mnem[if_acmp_nonnull] = "if_acmp_nonnull";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2203
            mnem[goto_w] = "goto_w";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2204
            mnem[jsr_w] = "jsr_w";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2205
            mnem[breakpoint] = "breakpoint";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2206
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2207
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2208
}