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