langtools/src/share/classes/com/sun/tools/javac/jvm/Items.java
author jjg
Mon, 10 Jan 2011 15:08:31 -0800
changeset 8032 e1aa25ccdabb
parent 7681 1f0819a3341f
child 8036 17b976649c61
permissions -rw-r--r--
6396503: javac should not require assertions enabled Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
     2
 * Copyright (c) 1999, 2011, 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
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    /** Make an item representing an indexed expression.
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     *  @param type    The expression's type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    Item makeIndexedItem(Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        return new IndexedItem(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    /** Make an item representing a local variable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     *  @param v    The represented variable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    LocalItem makeLocalItem(VarSymbol v) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        return new LocalItem(v.erasure(types), v.adr);
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 anonymous variable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     *  @param type  The represented variable's type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     *  @param reg   The represented variable's register.
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    private LocalItem makeLocalItem(Type type, int reg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        return new LocalItem(type, reg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    /** Make an item representing a static variable or method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     *  @param member   The represented symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    Item makeStaticItem(Symbol member) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        return new StaticItem(member);
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   142
    /** Make an item representing a dynamically invoked method.
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   143
     *  @param member   The represented symbol.
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   144
     */
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   145
    Item makeDynamicItem(Symbol member) {
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   146
        return new DynamicItem(member);
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   147
    }
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   148
10
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
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   467
    /** An item representing a dynamic call site.
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   468
     */
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   469
    class DynamicItem extends StaticItem {
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   470
        DynamicItem(Symbol member) {
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   471
            super(member);
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   472
            Assert.check(member.owner == syms.invokeDynamicType.tsym);
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   473
        }
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   474
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   475
        Item load() {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   476
            Assert.error();
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   477
            return null;
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   478
        }
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   479
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   480
        void store() {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   481
            Assert.error();
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   482
        }
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   483
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   484
        Item invoke() {
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   485
            // assert target.hasNativeInvokeDynamic();
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   486
            MethodType mtype = (MethodType)member.erasure(types);
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   487
            int rescode = Code.typecode(mtype.restype);
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   488
            ClassFile.NameAndType descr = new ClassFile.NameAndType(member.name, mtype);
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   489
            code.emitInvokedynamic(pool.put(descr), mtype);
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   490
            return stackItem[rescode];
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   491
        }
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   492
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   493
        public String toString() {
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   494
            return "dynamic(" + member + ")";
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   495
        }
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   496
    }
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   497
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   498
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
    /** An item representing an instance variable or method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
    class MemberItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
        /** The represented symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
        Symbol member;
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
        /** Flag that determines whether or not access is virtual.
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
        boolean nonvirtual;
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
        MemberItem(Symbol member, boolean nonvirtual) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
            super(Code.typecode(member.erasure(types)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
            this.member = member;
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
            this.nonvirtual = nonvirtual;
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
            code.emitop2(getfield, pool.put(member));
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
        void store() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
            code.emitop2(putfield, pool.put(member));
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
        Item invoke() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
            MethodType mtype = (MethodType)member.externalType(types);
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
            int rescode = Code.typecode(mtype.restype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
            if ((member.owner.flags() & Flags.INTERFACE) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
                code.emitInvokeinterface(pool.put(member), mtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
            } else if (nonvirtual) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
                code.emitInvokespecial(pool.put(member), mtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
                code.emitInvokevirtual(pool.put(member), mtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
            return stackItem[rescode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
        void duplicate() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
            stackItem[OBJECTcode].duplicate();
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
        void drop() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
            stackItem[OBJECTcode].drop();
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
        void stash(int toscode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
            stackItem[OBJECTcode].stash(toscode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
        int width() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
            return 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
            return "member(" + member + (nonvirtual ? " nonvirtual)" : ")");
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
    /** An item representing a literal.
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
    class ImmediateItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
        /** The literal's value.
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
        Object value;
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
        ImmediateItem(Type type, Object value) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
            super(Code.typecode(type));
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
            this.value = value;
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
        private void ldc() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
            int idx = pool.put(value);
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
            if (typecode == LONGcode || typecode == DOUBLEcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
                code.emitop2(ldc2w, idx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
            } else if (idx <= 255) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
                code.emitop1(ldc1, idx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
                code.emitop2(ldc2, idx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
            switch (typecode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
            case INTcode: case BYTEcode: case SHORTcode: case CHARcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
                int ival = ((Number)value).intValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
                if (-1 <= ival && ival <= 5)
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
                    code.emitop0(iconst_0 + ival);
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
                else if (Byte.MIN_VALUE <= ival && ival <= Byte.MAX_VALUE)
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
                    code.emitop1(bipush, ival);
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
                else if (Short.MIN_VALUE <= ival && ival <= Short.MAX_VALUE)
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
                    code.emitop2(sipush, ival);
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
                    ldc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
            case LONGcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
                long lval = ((Number)value).longValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
                if (lval == 0 || lval == 1)
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
                    code.emitop0(lconst_0 + (int)lval);
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
                    ldc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
            case FLOATcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
                float fval = ((Number)value).floatValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
                if (isPosZero(fval) || fval == 1.0 || fval == 2.0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
                    code.emitop0(fconst_0 + (int)fval);
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
                else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
                    ldc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
            case DOUBLEcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
                double dval = ((Number)value).doubleValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
                if (isPosZero(dval) || dval == 1.0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
                    code.emitop0(dconst_0 + (int)dval);
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
                else
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
            case OBJECTcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
                ldc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
            default:
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   623
                Assert.error();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
        //where
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
            /** Return true iff float number is positive 0.
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
             */
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
            private boolean isPosZero(float x) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
                return x == 0.0f && 1.0f / x > 0.0f;
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
            /** Return true iff double number is positive 0.
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
             */
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
            private boolean isPosZero(double x) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
                return x == 0.0d && 1.0d / x > 0.0d;
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
        CondItem mkCond() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
            int ival = ((Number)value).intValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
            return makeCondItem(ival != 0 ? goto_ : dontgoto);
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
        Item coerce(int targetcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
            if (typecode == targetcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
                return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
                switch (targetcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
                case INTcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
                    if (Code.truncate(typecode) == INTcode)
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
                        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
                    else
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
                        return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
                            syms.intType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
                            ((Number)value).intValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
                case LONGcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
                    return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
                        syms.longType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
                        ((Number)value).longValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
                case FLOATcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
                    return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
                        syms.floatType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
                        ((Number)value).floatValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
                case DOUBLEcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
                    return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
                        syms.doubleType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
                        ((Number)value).doubleValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
                case BYTEcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
                    return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
                        syms.byteType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
                        (int)(byte)((Number)value).intValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
                case CHARcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
                    return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
                        syms.charType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
                        (int)(char)((Number)value).intValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
                case SHORTcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
                    return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
                        syms.shortType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
                        (int)(short)((Number)value).intValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
                default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
                    return super.coerce(targetcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
            return "immediate(" + value + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
    /** An item representing an assignment expressions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
    class AssignItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
        /** The item representing the assignment's left hand side.
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
        Item lhs;
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
        AssignItem(Item lhs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
            super(lhs.typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
            this.lhs = lhs;
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
            lhs.stash(typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
            lhs.store();
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
        void duplicate() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
            load().duplicate();
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
        void drop() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
            lhs.store();
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
        void stash(int toscode) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   719
            Assert.error();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
        int width() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
            return lhs.width() + Code.width(typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
            return "assign(lhs = " + lhs + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
   728
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
    /** An item representing a conditional or unconditional jump.
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   733
    class CondItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
        /** A chain encomassing all jumps that can be taken
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
         *  if the condition evaluates to true.
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
        Chain trueJumps;
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
        /** A chain encomassing all jumps that can be taken
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
         *  if the condition evaluates to false.
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
        Chain falseJumps;
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
        /** The jump's opcode.
06bc494ca11e Initial load
duke
parents:
diff changeset
   746
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
        int opcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
        /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
         *  An abstract syntax tree of this item. It is needed
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
         *  for branch entries in 'CharacterRangeTable' attribute.
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
        JCTree tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
        CondItem(int opcode, Chain truejumps, Chain falsejumps) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
            super(BYTEcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
            this.opcode = opcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
            this.trueJumps = truejumps;
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
            this.falseJumps = falsejumps;
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
            Chain trueChain = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
            Chain falseChain = jumpFalse();
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
            if (!isFalse()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
                code.resolve(trueJumps);
06bc494ca11e Initial load
duke
parents:
diff changeset
   767
                code.emitop0(iconst_1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
                trueChain = code.branch(goto_);
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
            if (falseChain != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
                code.resolve(falseChain);
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
                code.emitop0(iconst_0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
            code.resolve(trueChain);
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
        void duplicate() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   779
            load().duplicate();
06bc494ca11e Initial load
duke
parents:
diff changeset
   780
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
06bc494ca11e Initial load
duke
parents:
diff changeset
   782
        void drop() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
            load().drop();
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
        void stash(int toscode) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   787
            Assert.error();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
        CondItem mkCond() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
        Chain jumpTrue() {
5004
6c2694dc2da0 6929544: langtools source code uses statics qualified by instance variables
jjg
parents: 2723
diff changeset
   795
            if (tree == null) return Code.mergeChains(trueJumps, code.branch(opcode));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
            // we should proceed further in -Xjcov mode only
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
            int startpc = code.curPc();
5004
6c2694dc2da0 6929544: langtools source code uses statics qualified by instance variables
jjg
parents: 2723
diff changeset
   798
            Chain c = Code.mergeChains(trueJumps, code.branch(opcode));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
            code.crt.put(tree, CRTable.CRT_BRANCH_TRUE, startpc, code.curPc());
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
            return c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
        Chain jumpFalse() {
5004
6c2694dc2da0 6929544: langtools source code uses statics qualified by instance variables
jjg
parents: 2723
diff changeset
   804
            if (tree == null) return Code.mergeChains(falseJumps, code.branch(Code.negate(opcode)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
            // we should proceed further in -Xjcov mode only
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
            int startpc = code.curPc();
5004
6c2694dc2da0 6929544: langtools source code uses statics qualified by instance variables
jjg
parents: 2723
diff changeset
   807
            Chain c = Code.mergeChains(falseJumps, code.branch(Code.negate(opcode)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
            code.crt.put(tree, CRTable.CRT_BRANCH_FALSE, startpc, code.curPc());
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
            return c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   810
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
        CondItem negate() {
5004
6c2694dc2da0 6929544: langtools source code uses statics qualified by instance variables
jjg
parents: 2723
diff changeset
   813
            CondItem c = new CondItem(Code.negate(opcode), falseJumps, trueJumps);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
            c.tree = tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
            return c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
        int width() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
            // a CondItem doesn't have a size on the stack per se.
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
            throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
        boolean isTrue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   824
            return falseJumps == null && opcode == goto_;
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
        boolean isFalse() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
            return trueJumps == null && opcode == dontgoto;
06bc494ca11e Initial load
duke
parents:
diff changeset
   829
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   830
06bc494ca11e Initial load
duke
parents:
diff changeset
   831
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   832
            return "cond(" + Code.mnem(opcode) + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
   833
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   834
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   835
}