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