langtools/src/share/classes/com/sun/tools/javac/jvm/Items.java
author mcimadamore
Sat, 17 Nov 2012 19:01:03 +0000
changeset 14547 86d8d242b0c4
parent 14443 91c05eb19277
child 16801 e2de240b437f
permissions -rw-r--r--
8003280: Add lambda tests Summary: Turn on lambda expression, method reference and default method support Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
     2
 * Copyright (c) 1999, 2012, 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: 5004
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: 5004
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: 5004
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5004
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5004
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.jvm;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import com.sun.tools.javac.code.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import com.sun.tools.javac.code.Symbol.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.tools.javac.code.Type.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.tools.javac.jvm.Code.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.tree.JCTree;
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
    33
import com.sun.tools.javac.util.Assert;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import static com.sun.tools.javac.jvm.ByteCodes.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
/** A helper class for code generation. Items are objects
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 *  that stand for addressable entities in the bytecode. Each item
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 *  supports a fixed protocol for loading the item on the stack, storing
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *  into it, converting it into a jump condition, and several others.
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *  There are many individual forms of items, such as local, static,
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *  indexed, or instance variables, values on the top of stack, the
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *  special values this or super, etc. Individual items are represented as
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 *  inner classes in class Items.
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    46
 *  <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
    47
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
public class Items {
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    /** The current constant pool.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    Pool pool;
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    /** The current code buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    Code code;
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    /** The current symbol table.
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    Symtab syms;
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    /** Type utilities. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    Types types;
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    /** Items that exist only once (flyweight pattern).
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    private final Item voidItem;
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    private final Item thisItem;
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    private final Item superItem;
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    private final Item[] stackItem = new Item[TypeCodeCount];
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    public Items(Pool pool, Code code, Symtab syms, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        this.code = code;
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        this.pool = pool;
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        this.types = types;
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        voidItem = new Item(VOIDcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
                public String toString() { return "void"; }
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
            };
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        thisItem = new SelfItem(false);
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        superItem = new SelfItem(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        for (int i = 0; i < VOIDcode; i++) stackItem[i] = new StackItem(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        stackItem[VOIDcode] = voidItem;
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        this.syms = syms;
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    /** Make a void item
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    Item makeVoidItem() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        return voidItem;
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    /** Make an item representing `this'.
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    Item makeThisItem() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        return thisItem;
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    /** Make an item representing `super'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    Item makeSuperItem() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        return superItem;
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    /** Make an item representing a value on stack.
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     *  @param type    The value's type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    Item makeStackItem(Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        return stackItem[Code.typecode(type)];
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   113
    /** Make an item representing a dynamically invoked method.
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   114
     *  @param member   The represented symbol.
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   115
     */
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   116
    Item makeDynamicItem(Symbol member) {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   117
        return new DynamicItem(member);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   118
    }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   119
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    /** Make an item representing an indexed expression.
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     *  @param type    The expression's type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    Item makeIndexedItem(Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        return new IndexedItem(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    /** Make an item representing a local variable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     *  @param v    The represented variable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    LocalItem makeLocalItem(VarSymbol v) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        return new LocalItem(v.erasure(types), v.adr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    /** Make an item representing a local anonymous variable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
     *  @param type  The represented variable's type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     *  @param reg   The represented variable's register.
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    private LocalItem makeLocalItem(Type type, int reg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        return new LocalItem(type, reg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    /** Make an item representing a static variable or method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     *  @param member   The represented symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    Item makeStaticItem(Symbol member) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        return new StaticItem(member);
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    /** Make an item representing an instance variable or method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
     *  @param member       The represented symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     *  @param nonvirtual   Is the reference not virtual? (true for constructors
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
     *                      and private members).
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    Item makeMemberItem(Symbol member, boolean nonvirtual) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
        return new MemberItem(member, nonvirtual);
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    /** Make an item representing a literal.
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
     *  @param type     The literal's type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
     *  @param value    The literal's value.
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    Item makeImmediateItem(Type type, Object value) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
        return new ImmediateItem(type, value);
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    /** Make an item representing an assignment expression.
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     *  @param lhs      The item representing the assignment's left hand side.
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    Item makeAssignItem(Item lhs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        return new AssignItem(lhs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
    /** Make an item representing a conditional or unconditional jump.
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     *  @param opcode      The jump's opcode.
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     *  @param trueJumps   A chain encomassing all jumps that can be taken
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     *                     if the condition evaluates to true.
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     *  @param falseJumps  A chain encomassing all jumps that can be taken
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     *                     if the condition evaluates to false.
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    CondItem makeCondItem(int opcode, Chain trueJumps, Chain falseJumps) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        return new CondItem(opcode, trueJumps, falseJumps);
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    /** Make an item representing a conditional or unconditional jump.
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     *  @param opcode      The jump's opcode.
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    CondItem makeCondItem(int opcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        return makeCondItem(opcode, null, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
    /** The base class of all items, which implements default behavior.
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
    abstract class Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        /** The type code of values represented by this item.
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
        int typecode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        Item(int typecode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
            this.typecode = typecode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
        /** Generate code to load this item onto stack.
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
            throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        /** Generate code to store top of stack into this item.
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
        void store() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
            throw new AssertionError("store unsupported: " + this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        /** Generate code to invoke method represented by this item.
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
        Item invoke() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
            throw new AssertionError(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
        /** Generate code to use this item twice.
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
        void duplicate() {}
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
        /** Generate code to avoid having to use this item.
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        void drop() {}
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
        /** Generate code to stash a copy of top of stack - of typecode toscode -
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
         *  under this item.
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
        void stash(int toscode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
            stackItem[toscode].duplicate();
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        /** Generate code to turn item into a testable condition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
        CondItem mkCond() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
            load();
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
            return makeCondItem(ifne);
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        /** Generate code to coerce item to given type code.
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
         *  @param targetcode    The type code to coerce to.
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        Item coerce(int targetcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
            if (typecode == targetcode)
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
                return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
            else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
                load();
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
                int typecode1 = Code.truncate(typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
                int targetcode1 = Code.truncate(targetcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
                if (typecode1 != targetcode1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
                    int offset = targetcode1 > typecode1 ? targetcode1 - 1
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
                        : targetcode1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
                    code.emitop0(i2l + typecode1 * 3 + offset);
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
                if (targetcode != targetcode1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
                    code.emitop0(int2byte + targetcode - BYTEcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
                return stackItem[targetcode];
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
        /** Generate code to coerce item to given type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
         *  @param targettype    The type to coerce to.
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        Item coerce(Type targettype) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
            return coerce(Code.typecode(targettype));
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
        /** Return the width of this item on stack as a number of words.
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
        int width() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
            return 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        public abstract String toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
    /** An item representing a value on stack.
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
    class StackItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        StackItem(int typecode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
            super(typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        void duplicate() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
            code.emitop0(width() == 2 ? dup2 : dup);
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
        void drop() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
            code.emitop0(width() == 2 ? pop2 : pop);
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
        void stash(int toscode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
            code.emitop0(
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
                (width() == 2 ? dup_x2 : dup_x1) + 3 * (Code.width(toscode) - 1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
        int width() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
            return Code.width(typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
            return "stack(" + typecodeNames[typecode] + ")";
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
    /** An item representing an indexed expression.
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
    class IndexedItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
        IndexedItem(Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
            super(Code.typecode(type));
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
            code.emitop0(iaload + typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
        void store() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
            code.emitop0(iastore + typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
        void duplicate() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
            code.emitop0(dup2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
        void drop() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
            code.emitop0(pop2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
        void stash(int toscode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
            code.emitop0(dup_x2 + 3 * (Code.width(toscode) - 1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
        int width() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
            return 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
            return "indexed(" + ByteCodes.typecodeNames[typecode] + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
    /** An item representing `this' or `super'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
    class SelfItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
        /** Flag which determines whether this item represents `this' or `super'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
        boolean isSuper;
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
        SelfItem(boolean isSuper) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
            super(OBJECTcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
            this.isSuper = isSuper;
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
            code.emitop0(aload_0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
            return isSuper ? "super" : "this";
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
    /** An item representing a local variable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
    class LocalItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
        /** The variable's register.
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
        int reg;
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
        /** The variable's type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
        Type type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
        LocalItem(Type type, int reg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
            super(Code.typecode(type));
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   390
            Assert.check(reg >= 0);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
            this.type = type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
            this.reg = reg;
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
            if (reg <= 3)
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
                code.emitop0(iload_0 + Code.truncate(typecode) * 4 + reg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
                code.emitop1w(iload + Code.truncate(typecode), reg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
        void store() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
            if (reg <= 3)
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
                code.emitop0(istore_0 + Code.truncate(typecode) * 4 + reg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
                code.emitop1w(istore + Code.truncate(typecode), reg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
            code.setDefined(reg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
        void incr(int x) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
            if (typecode == INTcode && x >= -32768 && x <= 32767) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
                code.emitop1w(iinc, reg, x);
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
                load();
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
                if (x >= 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
                    makeImmediateItem(syms.intType, x).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
                    code.emitop0(iadd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
                    makeImmediateItem(syms.intType, -x).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
                    code.emitop0(isub);
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
                makeStackItem(syms.intType).coerce(typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
                store();
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
            return "localItem(type=" + type + "; reg=" + reg + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
    /** An item representing a static variable or method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
    class StaticItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
        /** The represented symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
        Symbol member;
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
        StaticItem(Symbol member) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
            super(Code.typecode(member.erasure(types)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
            this.member = member;
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
            code.emitop2(getstatic, pool.put(member));
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
        void store() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
            code.emitop2(putstatic, pool.put(member));
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
        Item invoke() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
            MethodType mtype = (MethodType)member.erasure(types);
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
            int rescode = Code.typecode(mtype.restype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
            code.emitInvokestatic(pool.put(member), mtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
            return stackItem[rescode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
            return "static(" + member + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   467
    /** An item representing a dynamic call site.
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   468
     */
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   469
    class DynamicItem extends StaticItem {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   470
        DynamicItem(Symbol member) {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   471
            super(member);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   472
        }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   473
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   474
        Item load() {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   475
            assert false;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   476
            return null;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   477
        }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   478
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   479
        void store() {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   480
            assert false;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   481
        }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   482
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   483
        Item invoke() {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   484
            // assert target.hasNativeInvokeDynamic();
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   485
            MethodType mtype = (MethodType)member.erasure(types);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   486
            int rescode = Code.typecode(mtype.restype);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   487
            code.emitInvokedynamic(pool.put(member), mtype);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   488
            return stackItem[rescode];
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   489
        }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   490
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   491
        public String toString() {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   492
            return "dynamic(" + member + ")";
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   493
        }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   494
    }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 8036
diff changeset
   495
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
    /** An item representing an instance variable or method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
    class MemberItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
        /** The represented symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
        Symbol member;
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
        /** Flag that determines whether or not access is virtual.
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
        boolean nonvirtual;
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
        MemberItem(Symbol member, boolean nonvirtual) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
            super(Code.typecode(member.erasure(types)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
            this.member = member;
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
            this.nonvirtual = nonvirtual;
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
            code.emitop2(getfield, pool.put(member));
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
        void store() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
            code.emitop2(putfield, pool.put(member));
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
        Item invoke() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
            MethodType mtype = (MethodType)member.externalType(types);
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
            int rescode = Code.typecode(mtype.restype);
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14046
diff changeset
   526
            if ((member.owner.flags() & Flags.INTERFACE) != 0 && !nonvirtual) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
                code.emitInvokeinterface(pool.put(member), mtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
            } else if (nonvirtual) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
                code.emitInvokespecial(pool.put(member), mtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
                code.emitInvokevirtual(pool.put(member), mtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
            return stackItem[rescode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
        void duplicate() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
            stackItem[OBJECTcode].duplicate();
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
        void drop() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
            stackItem[OBJECTcode].drop();
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
        void stash(int toscode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
            stackItem[OBJECTcode].stash(toscode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
        int width() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
            return 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
            return "member(" + member + (nonvirtual ? " nonvirtual)" : ")");
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
    /** An item representing a literal.
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
    class ImmediateItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
        /** The literal's value.
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
        Object value;
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
        ImmediateItem(Type type, Object value) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
            super(Code.typecode(type));
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
            this.value = value;
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
        private void ldc() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
            int idx = pool.put(value);
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
            if (typecode == LONGcode || typecode == DOUBLEcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
                code.emitop2(ldc2w, idx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
            } else if (idx <= 255) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
                code.emitop1(ldc1, idx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
                code.emitop2(ldc2, idx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
            switch (typecode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
            case INTcode: case BYTEcode: case SHORTcode: case CHARcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
                int ival = ((Number)value).intValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
                if (-1 <= ival && ival <= 5)
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
                    code.emitop0(iconst_0 + ival);
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
                else if (Byte.MIN_VALUE <= ival && ival <= Byte.MAX_VALUE)
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
                    code.emitop1(bipush, ival);
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
                else if (Short.MIN_VALUE <= ival && ival <= Short.MAX_VALUE)
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
                    code.emitop2(sipush, ival);
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
                    ldc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
            case LONGcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
                long lval = ((Number)value).longValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
                if (lval == 0 || lval == 1)
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
                    code.emitop0(lconst_0 + (int)lval);
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
                    ldc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
            case FLOATcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
                float fval = ((Number)value).floatValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
                if (isPosZero(fval) || fval == 1.0 || fval == 2.0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
                    code.emitop0(fconst_0 + (int)fval);
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
                else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
                    ldc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
            case DOUBLEcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
                double dval = ((Number)value).doubleValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
                if (isPosZero(dval) || dval == 1.0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
                    code.emitop0(dconst_0 + (int)dval);
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
                    ldc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
            case OBJECTcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
                ldc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
            default:
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   620
                Assert.error();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
        //where
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
            /** Return true iff float number is positive 0.
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
             */
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
            private boolean isPosZero(float x) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
                return x == 0.0f && 1.0f / x > 0.0f;
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
            /** Return true iff double number is positive 0.
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
             */
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
            private boolean isPosZero(double x) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
                return x == 0.0d && 1.0d / x > 0.0d;
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
        CondItem mkCond() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
            int ival = ((Number)value).intValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
            return makeCondItem(ival != 0 ? goto_ : dontgoto);
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
        Item coerce(int targetcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
            if (typecode == targetcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
                return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
                switch (targetcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
                case INTcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
                    if (Code.truncate(typecode) == INTcode)
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
                        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
                    else
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
                        return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
                            syms.intType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
                            ((Number)value).intValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
                case LONGcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
                    return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
                        syms.longType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
                        ((Number)value).longValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
                case FLOATcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
                    return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
                        syms.floatType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
                        ((Number)value).floatValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
                case DOUBLEcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
                    return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
                        syms.doubleType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
                        ((Number)value).doubleValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
                case BYTEcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
                    return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
                        syms.byteType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
                        (int)(byte)((Number)value).intValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
                case CHARcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
                    return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
                        syms.charType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
                        (int)(char)((Number)value).intValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
                case SHORTcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
                    return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
                        syms.shortType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
                        (int)(short)((Number)value).intValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
                default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
                    return super.coerce(targetcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
            return "immediate(" + value + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
    /** An item representing an assignment expressions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
    class AssignItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
        /** The item representing the assignment's left hand side.
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
        Item lhs;
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
        AssignItem(Item lhs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
            super(lhs.typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
            this.lhs = lhs;
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
            lhs.stash(typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
            lhs.store();
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
        void duplicate() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
            load().duplicate();
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
        void drop() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
            lhs.store();
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
        void stash(int toscode) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   716
            Assert.error();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
        int width() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
            return lhs.width() + Code.width(typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
            return "assign(lhs = " + lhs + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
06bc494ca11e Initial load
duke
parents:
diff changeset
   728
    /** An item representing a conditional or unconditional jump.
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
    class CondItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
        /** A chain encomassing all jumps that can be taken
06bc494ca11e Initial load
duke
parents:
diff changeset
   733
         *  if the condition evaluates to true.
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
        Chain trueJumps;
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
        /** A chain encomassing all jumps that can be taken
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
         *  if the condition evaluates to false.
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
        Chain falseJumps;
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
        /** The jump's opcode.
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
        int opcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
06bc494ca11e Initial load
duke
parents:
diff changeset
   746
        /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
         *  An abstract syntax tree of this item. It is needed
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
         *  for branch entries in 'CharacterRangeTable' attribute.
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
        JCTree tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
        CondItem(int opcode, Chain truejumps, Chain falsejumps) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
            super(BYTEcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
            this.opcode = opcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
            this.trueJumps = truejumps;
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
            this.falseJumps = falsejumps;
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
            Chain trueChain = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
            Chain falseChain = jumpFalse();
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
            if (!isFalse()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
                code.resolve(trueJumps);
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
                code.emitop0(iconst_1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
                trueChain = code.branch(goto_);
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   767
            if (falseChain != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
                code.resolve(falseChain);
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
                code.emitop0(iconst_0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
            code.resolve(trueChain);
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
        void duplicate() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
            load().duplicate();
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
06bc494ca11e Initial load
duke
parents:
diff changeset
   779
        void drop() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   780
            load().drop();
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   782
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
        void stash(int toscode) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   784
            Assert.error();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
        CondItem mkCond() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
        Chain jumpTrue() {
5004
6c2694dc2da0 6929544: langtools source code uses statics qualified by instance variables
jjg
parents: 2723
diff changeset
   792
            if (tree == null) return Code.mergeChains(trueJumps, code.branch(opcode));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
            // we should proceed further in -Xjcov mode only
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
            int startpc = code.curPc();
5004
6c2694dc2da0 6929544: langtools source code uses statics qualified by instance variables
jjg
parents: 2723
diff changeset
   795
            Chain c = Code.mergeChains(trueJumps, code.branch(opcode));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
            code.crt.put(tree, CRTable.CRT_BRANCH_TRUE, startpc, code.curPc());
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
            return c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   798
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
        Chain jumpFalse() {
5004
6c2694dc2da0 6929544: langtools source code uses statics qualified by instance variables
jjg
parents: 2723
diff changeset
   801
            if (tree == null) return Code.mergeChains(falseJumps, code.branch(Code.negate(opcode)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
            // we should proceed further in -Xjcov mode only
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
            int startpc = code.curPc();
5004
6c2694dc2da0 6929544: langtools source code uses statics qualified by instance variables
jjg
parents: 2723
diff changeset
   804
            Chain c = Code.mergeChains(falseJumps, code.branch(Code.negate(opcode)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
            code.crt.put(tree, CRTable.CRT_BRANCH_FALSE, startpc, code.curPc());
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
            return c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
        CondItem negate() {
5004
6c2694dc2da0 6929544: langtools source code uses statics qualified by instance variables
jjg
parents: 2723
diff changeset
   810
            CondItem c = new CondItem(Code.negate(opcode), falseJumps, trueJumps);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
            c.tree = tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
            return c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
        int width() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
            // a CondItem doesn't have a size on the stack per se.
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
            throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
        boolean isTrue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
            return falseJumps == null && opcode == goto_;
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
06bc494ca11e Initial load
duke
parents:
diff changeset
   824
        boolean isFalse() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
            return trueJumps == null && opcode == dontgoto;
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   829
            return "cond(" + Code.mnem(opcode) + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
   830
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   831
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   832
}