langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java
author emc
Thu, 10 Oct 2013 20:12:08 -0400
changeset 21010 5ffe0d8a5e24
parent 19941 8b91e8eb2d20
child 21021 04429d0cb744
permissions -rw-r--r--
8008762: Type annotation on inner class in anonymous class show up as regular type annotations 8015257: type annotation with TYPE_USE and FIELD attributed differently if repeated. 8013409: test failures for type annotations Summary: Fixes to address some problems in type annotations Reviewed-by: jfranck, jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
     2
 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
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: 5492
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: 5492
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
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;
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
    27
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.util.List;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.code.*;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
    34
import com.sun.tools.javac.code.Attribute.TypeCompound;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
    35
import com.sun.tools.javac.code.Symbol.VarSymbol;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import com.sun.tools.javac.comp.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import com.sun.tools.javac.tree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import com.sun.tools.javac.code.Symbol.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import com.sun.tools.javac.code.Type.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import com.sun.tools.javac.jvm.Code.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import com.sun.tools.javac.jvm.Items.*;
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 11314
diff changeset
    43
import com.sun.tools.javac.tree.EndPosTable;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
import com.sun.tools.javac.tree.JCTree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
import static com.sun.tools.javac.code.Flags.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
import static com.sun.tools.javac.code.Kinds.*;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
    48
import static com.sun.tools.javac.code.TypeTag.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
import static com.sun.tools.javac.jvm.ByteCodes.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
import static com.sun.tools.javac.jvm.CRTFlags.*;
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 11055
diff changeset
    51
import static com.sun.tools.javac.main.Option.*;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
    52
import static com.sun.tools.javac.tree.JCTree.Tag.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
/** This pass maps flat Java (i.e. without inner classes) to bytecodes.
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    56
 *  <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
    57
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
public class Gen extends JCTree.Visitor {
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    protected static final Context.Key<Gen> genKey =
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
        new Context.Key<Gen>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    private final Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    private final Symtab syms;
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    private final Check chk;
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    private final Resolve rs;
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    private final TreeMaker make;
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
    70
    private final Names names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    private final Target target;
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    private final Type stringBufferType;
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    private final Map<Type,Symbol> stringBufferAppend;
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    private Name accessDollar;
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    private final Types types;
14721
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
    76
    private final Lower lower;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    /** Switch: GJ mode?
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    private final boolean allowGenerics;
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    /** Set when Miranda method stubs are to be generated. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    private final boolean generateIproxies;
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    /** Format of stackmap tables to be generated. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    private final Code.StackMapFormat stackMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    /** A type that serves as the expected type for all method expressions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    private final Type methodType;
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    public static Gen instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
        Gen instance = context.get(genKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
            instance = new Gen(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
    99
    /** Constant pool, reset by genClass.
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14721
diff changeset
   100
     */
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14721
diff changeset
   101
    private Pool pool;
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14721
diff changeset
   102
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
   103
    /** LVTRanges info.
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
   104
     */
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
   105
    private LVTRanges lvtRanges;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
   106
21010
5ffe0d8a5e24 8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents: 19941
diff changeset
   107
    private final boolean typeAnnoAsserts;
5ffe0d8a5e24 8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents: 19941
diff changeset
   108
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    protected Gen(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        context.put(genKey, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
   112
        names = Names.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        log = Log.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        syms = Symtab.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
        chk = Check.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        rs = Resolve.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        make = TreeMaker.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        target = Target.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        types = Types.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        methodType = new MethodType(null, null, null, syms.methodClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        allowGenerics = Source.instance(context).allowGenerics();
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        stringBufferType = target.useStringBuilder()
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
            ? syms.stringBuilderType
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
            : syms.stringBufferType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        stringBufferAppend = new HashMap<Type,Symbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
        accessDollar = names.
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
            fromString("access" + target.syntheticNameChar());
14721
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   128
        lower = Lower.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        Options options = Options.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        lineDebugInfo =
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6354
diff changeset
   132
            options.isUnset(G_CUSTOM) ||
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6354
diff changeset
   133
            options.isSet(G_CUSTOM, "lines");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
        varDebugInfo =
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6354
diff changeset
   135
            options.isUnset(G_CUSTOM)
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6354
diff changeset
   136
            ? options.isSet(G)
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6354
diff changeset
   137
            : options.isSet(G_CUSTOM, "vars");
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
   138
        if (varDebugInfo) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
   139
            lvtRanges = LVTRanges.instance(context);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
   140
        }
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6354
diff changeset
   141
        genCrt = options.isSet(XJCOV);
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6354
diff changeset
   142
        debugCode = options.isSet("debugcode");
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6354
diff changeset
   143
        allowInvokedynamic = target.hasInvokedynamic() || options.isSet("invokedynamic");
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14721
diff changeset
   144
        pool = new Pool(types);
21010
5ffe0d8a5e24 8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents: 19941
diff changeset
   145
        typeAnnoAsserts = options.isSet("TypeAnnotationAsserts");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
        generateIproxies =
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
            target.requiresIproxy() ||
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6354
diff changeset
   149
            options.isSet("miranda");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        if (target.generateStackMapTable()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
            // ignore cldc because we cannot have both stackmap formats
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
            this.stackMap = StackMapFormat.JSR202;
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
            if (target.generateCLDCStackmap()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
                this.stackMap = StackMapFormat.CLDC;
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
                this.stackMap = StackMapFormat.NONE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
        // by default, avoid jsr's for simple finalizers
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
        int setjsrlimit = 50;
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
        String jsrlimitString = options.get("jsrlimit");
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        if (jsrlimitString != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
                setjsrlimit = Integer.parseInt(jsrlimitString);
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
            } catch (NumberFormatException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
                // ignore ill-formed numbers for jsrlimit
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
        this.jsrlimit = setjsrlimit;
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
        this.useJsrLocally = false; // reset in visitTry
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    /** Switches
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    private final boolean lineDebugInfo;
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
    private final boolean varDebugInfo;
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    private final boolean genCrt;
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
    private final boolean debugCode;
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1264
diff changeset
   182
    private final boolean allowInvokedynamic;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    /** Default limit of (approximate) size of finalizer to inline.
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     *  Zero means always use jsr.  100 or greater means never use
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     *  jsr.
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    private final int jsrlimit;
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
    /** True if jsr is used.
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    private boolean useJsrLocally;
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    /** Code buffer, set by genMethod.
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    private Code code;
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
    /** Items structure, set by genMethod.
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
    private Items items;
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
    /** Environment for symbol lookup, set by genClass
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
    private Env<AttrContext> attrEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
    /** The top level tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
    private JCCompilationUnit toplevel;
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
    /** The number of code-gen errors in this class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
    private int nerrs = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   214
    /** An object containing mappings of syntax trees to their
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   215
     *  ending source positions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
     */
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   217
    EndPosTable endPosTable;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
    /** Generate code to load an integer constant.
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
     *  @param n     The integer to be loaded.
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
    void loadIntConst(int n) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
        items.makeImmediateItem(syms.intType, n).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    /** The opcode that loads a zero constant of a given type code.
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
     *  @param tc   The given type code (@see ByteCode).
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
    public static int zero(int tc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        switch(tc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        case INTcode: case BYTEcode: case SHORTcode: case CHARcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
            return iconst_0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
        case LONGcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
            return lconst_0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        case FLOATcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
            return fconst_0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
        case DOUBLEcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
            return dconst_0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
            throw new AssertionError("zero");
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    /** The opcode that loads a one constant of a given type code.
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
     *  @param tc   The given type code (@see ByteCode).
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    public static int one(int tc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
        return zero(tc) + 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
    /** Generate code to load -1 of the given type code (either int or long).
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
     *  @param tc   The given type code (@see ByteCode).
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
    void emitMinusOne(int tc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
        if (tc == LONGcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
            items.makeImmediateItem(syms.longType, new Long(-1)).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
            code.emitop0(iconst_m1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
    /** Construct a symbol to reflect the qualifying type that should
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
     *  appear in the byte code as per JLS 13.1.
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
     *
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13077
diff changeset
   265
     *  For {@literal target >= 1.2}: Clone a method with the qualifier as owner (except
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
     *  for those cases where we need to work around VM bugs).
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
     *
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13077
diff changeset
   268
     *  For {@literal target <= 1.1}: If qualified variable or method is defined in a
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
     *  non-accessible class, clone it with the qualifier class as owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
     *  @param sym    The accessed symbol
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
     *  @param site   The qualifier's type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
    Symbol binaryQualifier(Symbol sym, Type site) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
   276
        if (site.hasTag(ARRAY)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
            if (sym == syms.lengthVar ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
                sym.owner != syms.arrayClass)
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
                return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
            // array clone can be qualified by the array type in later targets
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
            Symbol qualifier = target.arrayBinaryCompatibility()
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
                ? new ClassSymbol(Flags.PUBLIC, site.tsym.name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
                                  site, syms.noSymbol)
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
                : syms.objectType.tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
            return sym.clone(qualifier);
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        if (sym.owner == site.tsym ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
            (sym.flags() & (STATIC | SYNTHETIC)) == (STATIC | SYNTHETIC)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
            return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
        if (!target.obeyBinaryCompatibility())
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
            return rs.isAccessible(attrEnv, (TypeSymbol)sym.owner)
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
                ? sym
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
                : sym.clone(site.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
        if (!target.interfaceFieldsBinaryCompatibility()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
            if ((sym.owner.flags() & INTERFACE) != 0 && sym.kind == VAR)
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
                return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
        // leave alone methods inherited from Object
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 9300
diff changeset
   303
        // JLS 13.1.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
        if (sym.owner == syms.objectType.tsym)
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
            return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
        if (!target.interfaceObjectOverridesBinaryCompatibility()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
            if ((sym.owner.flags() & INTERFACE) != 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
                syms.objectType.tsym.members().lookup(sym.name).scope != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
                return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
        return sym.clone(site.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
    /** Insert a reference to given type in the constant pool,
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
     *  checking for an array with too many dimensions;
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
     *  return the reference's index.
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
     *  @param type   The type for which a reference is inserted.
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
    int makeRef(DiagnosticPosition pos, Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
        checkDimension(pos, type);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   323
        if (type.isAnnotated()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   324
            // Treat annotated types separately - we don't want
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   325
            // to collapse all of them - at least for annotated
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   326
            // exceptions.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   327
            // TODO: review this.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   328
            return pool.put((Object)type);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   329
        } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   330
            return pool.put(type.hasTag(CLASS) ? (Object)type.tsym : (Object)type);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   331
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
    /** Check if the given type is an array with too many dimensions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
    private void checkDimension(DiagnosticPosition pos, Type t) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
   337
        switch (t.getTag()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
        case METHOD:
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
            checkDimension(pos, t.getReturnType());
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
            for (List<Type> args = t.getParameterTypes(); args.nonEmpty(); args = args.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
                checkDimension(pos, args.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
        case ARRAY:
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
            if (types.dimensions(t) > ClassFile.MAX_DIMENSIONS) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
                log.error(pos, "limit.dimensions");
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
                nerrs++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
    /** Create a tempory variable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
     *  @param type   The variable's type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
    LocalItem makeTemp(Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
        VarSymbol v = new VarSymbol(Flags.SYNTHETIC,
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
                                    names.empty,
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
                                    type,
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
                                    env.enclMethod.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
        code.newLocal(v);
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
        return items.makeLocalItem(v);
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
    /** Generate code to call a non-private method or constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
     *  @param pos         Position to be used for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
     *  @param site        The type of which the method is a member.
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
     *  @param name        The method's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
     *  @param argtypes    The method's argument types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
     *  @param isStatic    A flag that indicates whether we call a
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
     *                     static or instance method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
    void callMethod(DiagnosticPosition pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
                    Type site, Name name, List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
                    boolean isStatic) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
        Symbol msym = rs.
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
            resolveInternalMethod(pos, attrEnv, site, name, argtypes, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
        if (isStatic) items.makeStaticItem(msym).invoke();
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
        else items.makeMemberItem(msym, name == names.init).invoke();
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
    /** Is the given method definition an access method
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
     *  resulting from a qualified super? This is signified by an odd
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
     *  access code.
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
    private boolean isAccessSuper(JCMethodDecl enclMethod) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
            (enclMethod.mods.flags & SYNTHETIC) != 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
            isOddAccessName(enclMethod.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
    /** Does given name start with "access$" and end in an odd digit?
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
    private boolean isOddAccessName(Name name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
            name.startsWith(accessDollar) &&
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
   398
            (name.getByteAt(name.getByteLength() - 1) & 1) == 1;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
/* ************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
 * Non-local exits
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
 *************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
    /** Generate code to invoke the finalizer associated with given
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
     *  environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
     *  Any calls to finalizers are appended to the environments `cont' chain.
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
     *  Mark beginning of gap in catch all range for finalizer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
    void genFinalizer(Env<GenContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
        if (code.isAlive() && env.info.finalize != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
            env.info.finalize.gen();
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
    /** Generate code to call all finalizers of structures aborted by
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
     *  a non-local
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
     *  exit.  Return target environment of the non-local exit.
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
     *  @param target      The tree representing the structure that's aborted
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
     *  @param env         The environment current at the non-local exit.
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
    Env<GenContext> unwind(JCTree target, Env<GenContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
        Env<GenContext> env1 = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
        while (true) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
            genFinalizer(env1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
            if (env1.tree == target) break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
            env1 = env1.next;
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
        return env1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
    /** Mark end of gap in catch-all range for finalizer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
     *  @param env   the environment which might contain the finalizer
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
     *               (if it does, env.info.gaps != null).
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
    void endFinalizerGap(Env<GenContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
        if (env.info.gaps != null && env.info.gaps.length() % 2 == 1)
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
   437
            env.info.gaps.append(code.curCP());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
    /** Mark end of all gaps in catch-all ranges for finalizers of environments
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
     *  lying between, and including to two environments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
     *  @param from    the most deeply nested environment to mark
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
     *  @param to      the least deeply nested environment to mark
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
    void endFinalizerGaps(Env<GenContext> from, Env<GenContext> to) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
        Env<GenContext> last = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
        while (last != to) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
            endFinalizerGap(from);
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
            last = from;
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
            from = from.next;
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
    /** Do any of the structures aborted by a non-local exit have
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
     *  finalizers that require an empty stack?
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
     *  @param target      The tree representing the structure that's aborted
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
     *  @param env         The environment current at the non-local exit.
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
    boolean hasFinally(JCTree target, Env<GenContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
        while (env.tree != target) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
   461
            if (env.tree.hasTag(TRY) && env.info.finalize.hasFinalizer())
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
            env = env.next;
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
/* ************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
 * Normalizing class-members.
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
 *************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14046
diff changeset
   472
    /** Distribute member initializer code into constructors and {@code <clinit>}
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
     *  method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
     *  @param defs         The list of class member declarations.
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
     *  @param c            The enclosing class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
    List<JCTree> normalizeDefs(List<JCTree> defs, ClassSymbol c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
        ListBuffer<JCStatement> initCode = new ListBuffer<JCStatement>();
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   479
        ListBuffer<Attribute.TypeCompound> initTAs = new ListBuffer<Attribute.TypeCompound>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
        ListBuffer<JCStatement> clinitCode = new ListBuffer<JCStatement>();
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   481
        ListBuffer<Attribute.TypeCompound> clinitTAs = new ListBuffer<Attribute.TypeCompound>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
        ListBuffer<JCTree> methodDefs = new ListBuffer<JCTree>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
        // Sort definitions into three listbuffers:
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
        //  - initCode for instance initializers
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
        //  - clinitCode for class initializers
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
        //  - methodDefs for method definitions
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
        for (List<JCTree> l = defs; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
            JCTree def = l.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
            switch (def.getTag()) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
   490
            case BLOCK:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
                JCBlock block = (JCBlock)def;
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
                if ((block.flags & STATIC) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
                    clinitCode.append(block);
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
                    initCode.append(block);
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
                break;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
   497
            case METHODDEF:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
                methodDefs.append(def);
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
                break;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
   500
            case VARDEF:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
                JCVariableDecl vdef = (JCVariableDecl) def;
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
                VarSymbol sym = vdef.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
                checkDimension(vdef.pos(), sym.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
                if (vdef.init != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
                    if ((sym.flags() & STATIC) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
                        // Always initialize instance variables.
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
                        JCStatement init = make.at(vdef.pos()).
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
                            Assignment(sym, vdef.init);
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
                        initCode.append(init);
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   510
                        endPosTable.replaceTree(vdef, init);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   511
                        initTAs.addAll(getAndRemoveNonFieldTAs(sym));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
                    } else if (sym.getConstValue() == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
                        // Initialize class (static) variables only if
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
                        // they are not compile-time constants.
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
                        JCStatement init = make.at(vdef.pos).
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
                            Assignment(sym, vdef.init);
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
                        clinitCode.append(init);
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   518
                        endPosTable.replaceTree(vdef, init);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   519
                        clinitTAs.addAll(getAndRemoveNonFieldTAs(sym));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
                        checkStringConstant(vdef.init.pos(), sym.getConstValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
            default:
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   526
                Assert.error();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
        // Insert any instance initializers into all constructors.
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
        if (initCode.length() != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
            List<JCStatement> inits = initCode.toList();
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
   532
            initTAs.addAll(c.getInitTypeAttributes());
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   533
            List<Attribute.TypeCompound> initTAlist = initTAs.toList();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
            for (JCTree t : methodDefs) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   535
                normalizeMethod((JCMethodDecl)t, inits, initTAlist);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
        // If there are class initializers, create a <clinit> method
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
        // that contains them as its body.
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
        if (clinitCode.length() != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
            MethodSymbol clinit = new MethodSymbol(
15710
5792a085da41 7166455: javac doesn't set ACC_STRICT bit on <clinit> for strictfp class
vromero
parents: 15385
diff changeset
   542
                STATIC | (c.flags() & STRICTFP),
5792a085da41 7166455: javac doesn't set ACC_STRICT bit on <clinit> for strictfp class
vromero
parents: 15385
diff changeset
   543
                names.clinit,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
                new MethodType(
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
                    List.<Type>nil(), syms.voidType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
                    List.<Type>nil(), syms.methodClass),
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
                c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
            c.members().enter(clinit);
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
            List<JCStatement> clinitStats = clinitCode.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
            JCBlock block = make.at(clinitStats.head.pos()).Block(0, clinitStats);
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
            block.endpos = TreeInfo.endPos(clinitStats.last());
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
            methodDefs.append(make.MethodDef(clinit, block));
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   553
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   554
            if (!clinitTAs.isEmpty())
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
   555
                clinit.appendUniqueTypeAttributes(clinitTAs.toList());
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
   556
            if (!c.getClassInitTypeAttributes().isEmpty())
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
   557
                clinit.appendUniqueTypeAttributes(c.getClassInitTypeAttributes());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
        // Return all method definitions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
        return methodDefs.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   563
    private List<Attribute.TypeCompound> getAndRemoveNonFieldTAs(VarSymbol sym) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   564
        List<TypeCompound> tas = sym.getRawTypeAttributes();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   565
        ListBuffer<Attribute.TypeCompound> fieldTAs = new ListBuffer<Attribute.TypeCompound>();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   566
        ListBuffer<Attribute.TypeCompound> nonfieldTAs = new ListBuffer<Attribute.TypeCompound>();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   567
        for (TypeCompound ta : tas) {
21010
5ffe0d8a5e24 8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents: 19941
diff changeset
   568
            if (ta.getPosition().type == TargetType.FIELD) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   569
                fieldTAs.add(ta);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   570
            } else {
21010
5ffe0d8a5e24 8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents: 19941
diff changeset
   571
                if (typeAnnoAsserts) {
5ffe0d8a5e24 8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents: 19941
diff changeset
   572
                    Assert.error("Type annotation does not have a valid positior");
5ffe0d8a5e24 8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents: 19941
diff changeset
   573
                }
5ffe0d8a5e24 8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents: 19941
diff changeset
   574
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   575
                nonfieldTAs.add(ta);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   576
            }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   577
        }
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
   578
        sym.setTypeAttributes(fieldTAs.toList());
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   579
        return nonfieldTAs.toList();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   580
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   581
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
    /** Check a constant value and report if it is a string that is
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
     *  too large.
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
    private void checkStringConstant(DiagnosticPosition pos, Object constValue) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
        if (nerrs != 0 || // only complain about a long string once
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
            constValue == null ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
            !(constValue instanceof String) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
            ((String)constValue).length() < Pool.MAX_STRING_LENGTH)
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
        log.error(pos, "limit.string");
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
        nerrs++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
    /** Insert instance initializer code into initial constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
     *  @param md        The tree potentially representing a
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
     *                   constructor's definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
     *  @param initCode  The list of instance initializer statements.
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   599
     *  @param initTAs  Type annotations from the initializer expression.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
     */
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   601
    void normalizeMethod(JCMethodDecl md, List<JCStatement> initCode, List<TypeCompound> initTAs) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
        if (md.name == names.init && TreeInfo.isInitialConstructor(md)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
            // We are seeing a constructor that does not call another
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
            // constructor of the same class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
            List<JCStatement> stats = md.body.stats;
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
            ListBuffer<JCStatement> newstats = new ListBuffer<JCStatement>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
            if (stats.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
                // Copy initializers of synthetic variables generated in
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
                // the translation of inner classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
                while (TreeInfo.isSyntheticInit(stats.head)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
                    newstats.append(stats.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
                    stats = stats.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
                // Copy superclass constructor call
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
                newstats.append(stats.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
                stats = stats.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
                // Copy remaining synthetic initializers.
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
                while (stats.nonEmpty() &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
                       TreeInfo.isSyntheticInit(stats.head)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
                    newstats.append(stats.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
                    stats = stats.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
                // Now insert the initializer code.
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
                newstats.appendList(initCode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
                // And copy all remaining statements.
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
                while (stats.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
                    newstats.append(stats.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
                    stats = stats.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
            md.body.stats = newstats.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
            if (md.body.endpos == Position.NOPOS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
                md.body.endpos = TreeInfo.endPos(md.body.stats.last());
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
   635
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
   636
            md.sym.appendUniqueTypeAttributes(initTAs);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
/* ********************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
 * Adding miranda methods
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
 *********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
    /** Add abstract methods for all methods defined in one of
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
     *  the interfaces of a given class,
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
     *  provided they are not already implemented in the class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
     *  @param c      The class whose interfaces are searched for methods
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
     *                for which Miranda methods should be added.
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
    void implementInterfaceMethods(ClassSymbol c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
        implementInterfaceMethods(c, c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
    /** Add abstract methods for all methods defined in one of
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
     *  the interfaces of a given class,
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
     *  provided they are not already implemented in the class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
     *  @param c      The class whose interfaces are searched for methods
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
     *                for which Miranda methods should be added.
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
     *  @param site   The class in which a definition may be needed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
    void implementInterfaceMethods(ClassSymbol c, ClassSymbol site) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
        for (List<Type> l = types.interfaces(c.type); l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
            ClassSymbol i = (ClassSymbol)l.head.tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
            for (Scope.Entry e = i.members().elems;
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
                 e != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
                 e = e.sibling)
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
            {
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
                if (e.sym.kind == MTH && (e.sym.flags() & STATIC) == 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
                {
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
                    MethodSymbol absMeth = (MethodSymbol)e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
                    MethodSymbol implMeth = absMeth.binaryImplementation(site, types);
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
                    if (implMeth == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
                        addAbstractMethod(site, absMeth);
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
                    else if ((implMeth.flags() & IPROXY) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
                        adjustAbstractMethod(site, implMeth, absMeth);
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
            implementInterfaceMethods(i, site);
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
    /** Add an abstract methods to a class
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
     *  which implicitly implements a method defined in some interface
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
     *  implemented by the class. These methods are called "Miranda methods".
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
     *  Enter the newly created method into its enclosing class scope.
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
     *  Note that it is not entered into the class tree, as the emitter
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
     *  doesn't need to see it there to emit an abstract method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
     *  @param c      The class to which the Miranda method is added.
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
     *  @param m      The interface method symbol for which a Miranda method
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
     *                is added.
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
    private void addAbstractMethod(ClassSymbol c,
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
                                   MethodSymbol m) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
        MethodSymbol absMeth = new MethodSymbol(
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
            m.flags() | IPROXY | SYNTHETIC, m.name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
            m.type, // was c.type.memberType(m), but now only !generics supported
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
            c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
        c.members().enter(absMeth); // add to symbol table
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
    private void adjustAbstractMethod(ClassSymbol c,
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
                                      MethodSymbol pm,
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
                                      MethodSymbol im) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
        MethodType pmt = (MethodType)pm.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
        Type imt = types.memberType(c.type, im);
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
        pmt.thrown = chk.intersect(pmt.getThrownTypes(), imt.getThrownTypes());
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
/* ************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
 * Traversal methods
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
 *************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
    /** Visitor argument: The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
    Env<GenContext> env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
    /** Visitor argument: The expected type (prototype).
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
    Type pt;
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
    /** Visitor result: The item representing the computed value.
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
    Item result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
06bc494ca11e Initial load
duke
parents:
diff changeset
   728
    /** Visitor method: generate code for a definition, catching and reporting
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
     *  any completion failures.
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
     *  @param tree    The definition to be visited.
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
     *  @param env     The environment current at the definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   733
    public void genDef(JCTree tree, Env<GenContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
        Env<GenContext> prevEnv = this.env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
            this.env = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
            tree.accept(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
        } catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
            chk.completionError(tree.pos(), ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
            this.env = prevEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
    /** Derived visitor method: check whether CharacterRangeTable
06bc494ca11e Initial load
duke
parents:
diff changeset
   746
     *  should be emitted, if so, put a new entry into CRTable
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
     *  and call method to generate bytecode.
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
     *  If not, just call method to generate bytecode.
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14046
diff changeset
   749
     *  @see    #genStat(JCTree, Env)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
     *  @param  tree     The tree to be visited.
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
     *  @param  env      The environment to use.
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
     *  @param  crtFlags The CharacterRangeTable flags
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
     *                   indicating type of the entry.
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
    public void genStat(JCTree tree, Env<GenContext> env, int crtFlags) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
        if (!genCrt) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
            genStat(tree, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
        }
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
   761
        int startpc = code.curCP();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
        genStat(tree, env);
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14721
diff changeset
   763
        if (tree.hasTag(Tag.BLOCK)) crtFlags |= CRT_BLOCK;
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
   764
        code.crt.put(tree, crtFlags, startpc, code.curCP());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
06bc494ca11e Initial load
duke
parents:
diff changeset
   767
    /** Derived visitor method: generate code for a statement.
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
    public void genStat(JCTree tree, Env<GenContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
        if (code.isAlive()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
            code.statBegin(tree.pos);
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
            genDef(tree, env);
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
   773
        } else if (env.info.isSwitch && tree.hasTag(VARDEF)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
            // variables whose declarations are in a switch
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
            // can be used even if the decl is unreachable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
            code.newLocal(((JCVariableDecl) tree).sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   779
06bc494ca11e Initial load
duke
parents:
diff changeset
   780
    /** Derived visitor method: check whether CharacterRangeTable
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
     *  should be emitted, if so, put a new entry into CRTable
06bc494ca11e Initial load
duke
parents:
diff changeset
   782
     *  and call method to generate bytecode.
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
     *  If not, just call method to generate bytecode.
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
     *  @see    #genStats(List, Env)
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
     *  @param  trees    The list of trees to be visited.
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
     *  @param  env      The environment to use.
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
     *  @param  crtFlags The CharacterRangeTable flags
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
     *                   indicating type of the entry.
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
    public void genStats(List<JCStatement> trees, Env<GenContext> env, int crtFlags) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
        if (!genCrt) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
            genStats(trees, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
        if (trees.length() == 1) {        // mark one statement with the flags
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
            genStat(trees.head, env, crtFlags | CRT_STATEMENT);
06bc494ca11e Initial load
duke
parents:
diff changeset
   798
        } else {
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
   799
            int startpc = code.curCP();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
            genStats(trees, env);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
   801
            code.crt.put(trees, crtFlags, startpc, code.curCP());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   804
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
    /** Derived visitor method: generate code for a list of statements.
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
    public void genStats(List<? extends JCTree> trees, Env<GenContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
        for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
            genStat(l.head, env, CRT_STATEMENT);
06bc494ca11e Initial load
duke
parents:
diff changeset
   810
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
    /** Derived visitor method: check whether CharacterRangeTable
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
     *  should be emitted, if so, put a new entry into CRTable
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
     *  and call method to generate bytecode.
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
     *  If not, just call method to generate bytecode.
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14046
diff changeset
   816
     *  @see    #genCond(JCTree,boolean)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
     *  @param  tree     The tree to be visited.
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
     *  @param  crtFlags The CharacterRangeTable flags
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
     *                   indicating type of the entry.
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
    public CondItem genCond(JCTree tree, int crtFlags) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
        if (!genCrt) return genCond(tree, false);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
   824
        int startpc = code.curCP();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
        CondItem item = genCond(tree, (crtFlags & CRT_FLOW_CONTROLLER) != 0);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
   826
        code.crt.put(tree, crtFlags, startpc, code.curCP());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
        return item;
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   829
06bc494ca11e Initial load
duke
parents:
diff changeset
   830
    /** Derived visitor method: generate code for a boolean
06bc494ca11e Initial load
duke
parents:
diff changeset
   831
     *  expression in a control-flow context.
06bc494ca11e Initial load
duke
parents:
diff changeset
   832
     *  @param _tree         The expression to be visited.
06bc494ca11e Initial load
duke
parents:
diff changeset
   833
     *  @param markBranches The flag to indicate that the condition is
06bc494ca11e Initial load
duke
parents:
diff changeset
   834
     *                      a flow controller so produced conditions
06bc494ca11e Initial load
duke
parents:
diff changeset
   835
     *                      should contain a proper tree to generate
06bc494ca11e Initial load
duke
parents:
diff changeset
   836
     *                      CharacterRangeTable branches for them.
06bc494ca11e Initial load
duke
parents:
diff changeset
   837
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   838
    public CondItem genCond(JCTree _tree, boolean markBranches) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   839
        JCTree inner_tree = TreeInfo.skipParens(_tree);
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
   840
        if (inner_tree.hasTag(CONDEXPR)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   841
            JCConditional tree = (JCConditional)inner_tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   842
            CondItem cond = genCond(tree.cond, CRT_FLOW_CONTROLLER);
06bc494ca11e Initial load
duke
parents:
diff changeset
   843
            if (cond.isTrue()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   844
                code.resolve(cond.trueJumps);
06bc494ca11e Initial load
duke
parents:
diff changeset
   845
                CondItem result = genCond(tree.truepart, CRT_FLOW_TARGET);
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
                if (markBranches) result.tree = tree.truepart;
06bc494ca11e Initial load
duke
parents:
diff changeset
   847
                return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   848
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   849
            if (cond.isFalse()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   850
                code.resolve(cond.falseJumps);
06bc494ca11e Initial load
duke
parents:
diff changeset
   851
                CondItem result = genCond(tree.falsepart, CRT_FLOW_TARGET);
06bc494ca11e Initial load
duke
parents:
diff changeset
   852
                if (markBranches) result.tree = tree.falsepart;
06bc494ca11e Initial load
duke
parents:
diff changeset
   853
                return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   854
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   855
            Chain secondJumps = cond.jumpFalse();
06bc494ca11e Initial load
duke
parents:
diff changeset
   856
            code.resolve(cond.trueJumps);
06bc494ca11e Initial load
duke
parents:
diff changeset
   857
            CondItem first = genCond(tree.truepart, CRT_FLOW_TARGET);
06bc494ca11e Initial load
duke
parents:
diff changeset
   858
            if (markBranches) first.tree = tree.truepart;
06bc494ca11e Initial load
duke
parents:
diff changeset
   859
            Chain falseJumps = first.jumpFalse();
06bc494ca11e Initial load
duke
parents:
diff changeset
   860
            code.resolve(first.trueJumps);
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
            Chain trueJumps = code.branch(goto_);
06bc494ca11e Initial load
duke
parents:
diff changeset
   862
            code.resolve(secondJumps);
06bc494ca11e Initial load
duke
parents:
diff changeset
   863
            CondItem second = genCond(tree.falsepart, CRT_FLOW_TARGET);
06bc494ca11e Initial load
duke
parents:
diff changeset
   864
            CondItem result = items.makeCondItem(second.opcode,
5004
6c2694dc2da0 6929544: langtools source code uses statics qualified by instance variables
jjg
parents: 4875
diff changeset
   865
                                      Code.mergeChains(trueJumps, second.trueJumps),
6c2694dc2da0 6929544: langtools source code uses statics qualified by instance variables
jjg
parents: 4875
diff changeset
   866
                                      Code.mergeChains(falseJumps, second.falseJumps));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   867
            if (markBranches) result.tree = tree.falsepart;
06bc494ca11e Initial load
duke
parents:
diff changeset
   868
            return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   869
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   870
            CondItem result = genExpr(_tree, syms.booleanType).mkCond();
06bc494ca11e Initial load
duke
parents:
diff changeset
   871
            if (markBranches) result.tree = _tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   872
            return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   873
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   874
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   875
14721
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   876
    /** Visitor class for expressions which might be constant expressions.
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   877
     *  This class is a subset of TreeScanner. Intended to visit trees pruned by
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   878
     *  Lower as long as constant expressions looking for references to any
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   879
     *  ClassSymbol. Any such reference will be added to the constant pool so
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   880
     *  automated tools can detect class dependencies better.
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   881
     */
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   882
    class ClassReferenceVisitor extends JCTree.Visitor {
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   883
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   884
        @Override
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   885
        public void visitTree(JCTree tree) {}
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   886
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   887
        @Override
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   888
        public void visitBinary(JCBinary tree) {
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   889
            tree.lhs.accept(this);
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   890
            tree.rhs.accept(this);
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   891
        }
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   892
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   893
        @Override
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   894
        public void visitSelect(JCFieldAccess tree) {
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   895
            if (tree.selected.type.hasTag(CLASS)) {
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   896
                makeRef(tree.selected.pos(), tree.selected.type);
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   897
            }
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   898
        }
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   899
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   900
        @Override
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   901
        public void visitIdent(JCIdent tree) {
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   902
            if (tree.sym.owner instanceof ClassSymbol) {
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   903
                pool.put(tree.sym.owner);
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   904
            }
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   905
        }
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   906
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   907
        @Override
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   908
        public void visitConditional(JCConditional tree) {
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   909
            tree.cond.accept(this);
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   910
            tree.truepart.accept(this);
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   911
            tree.falsepart.accept(this);
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   912
        }
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   913
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   914
        @Override
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   915
        public void visitUnary(JCUnary tree) {
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   916
            tree.arg.accept(this);
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   917
        }
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   918
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   919
        @Override
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   920
        public void visitParens(JCParens tree) {
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   921
            tree.expr.accept(this);
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   922
        }
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   923
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   924
        @Override
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   925
        public void visitTypeCast(JCTypeCast tree) {
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   926
            tree.expr.accept(this);
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   927
        }
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   928
    }
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   929
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   930
    private ClassReferenceVisitor classReferenceVisitor = new ClassReferenceVisitor();
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   931
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   932
    /** Visitor method: generate code for an expression, catching and reporting
06bc494ca11e Initial load
duke
parents:
diff changeset
   933
     *  any completion failures.
06bc494ca11e Initial load
duke
parents:
diff changeset
   934
     *  @param tree    The expression to be visited.
06bc494ca11e Initial load
duke
parents:
diff changeset
   935
     *  @param pt      The expression's expected type (proto-type).
06bc494ca11e Initial load
duke
parents:
diff changeset
   936
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   937
    public Item genExpr(JCTree tree, Type pt) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   938
        Type prevPt = this.pt;
06bc494ca11e Initial load
duke
parents:
diff changeset
   939
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   940
            if (tree.type.constValue() != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   941
                // Short circuit any expressions which are constants
14721
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
   942
                tree.accept(classReferenceVisitor);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   943
                checkStringConstant(tree.pos(), tree.type.constValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   944
                result = items.makeImmediateItem(tree.type, tree.type.constValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   945
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   946
                this.pt = pt;
06bc494ca11e Initial load
duke
parents:
diff changeset
   947
                tree.accept(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   948
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   949
            return result.coerce(pt);
06bc494ca11e Initial load
duke
parents:
diff changeset
   950
        } catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   951
            chk.completionError(tree.pos(), ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   952
            code.state.stacksize = 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   953
            return items.makeStackItem(pt);
06bc494ca11e Initial load
duke
parents:
diff changeset
   954
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   955
            this.pt = prevPt;
06bc494ca11e Initial load
duke
parents:
diff changeset
   956
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   957
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   958
06bc494ca11e Initial load
duke
parents:
diff changeset
   959
    /** Derived visitor method: generate code for a list of method arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   960
     *  @param trees    The argument expressions to be visited.
06bc494ca11e Initial load
duke
parents:
diff changeset
   961
     *  @param pts      The expression's expected types (i.e. the formal parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   962
     *                  types of the invoked method).
06bc494ca11e Initial load
duke
parents:
diff changeset
   963
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   964
    public void genArgs(List<JCExpression> trees, List<Type> pts) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   965
        for (List<JCExpression> l = trees; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   966
            genExpr(l.head, pts.head).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
   967
            pts = pts.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   968
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   969
        // require lists be of same length
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   970
        Assert.check(pts.isEmpty());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   971
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   972
06bc494ca11e Initial load
duke
parents:
diff changeset
   973
/* ************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
 * Visitor methods for statements and definitions
06bc494ca11e Initial load
duke
parents:
diff changeset
   975
 *************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   976
06bc494ca11e Initial load
duke
parents:
diff changeset
   977
    /** Thrown when the byte code size exceeds limit.
06bc494ca11e Initial load
duke
parents:
diff changeset
   978
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   979
    public static class CodeSizeOverflow extends RuntimeException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   980
        private static final long serialVersionUID = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   981
        public CodeSizeOverflow() {}
06bc494ca11e Initial load
duke
parents:
diff changeset
   982
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   983
06bc494ca11e Initial load
duke
parents:
diff changeset
   984
    public void visitMethodDef(JCMethodDecl tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   985
        // Create a new local environment that points pack at method
06bc494ca11e Initial load
duke
parents:
diff changeset
   986
        // definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   987
        Env<GenContext> localEnv = env.dup(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   988
        localEnv.enclMethod = tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   989
        // The expected type of every return statement in this method
06bc494ca11e Initial load
duke
parents:
diff changeset
   990
        // is the method's return type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   991
        this.pt = tree.sym.erasure(types).getReturnType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   992
06bc494ca11e Initial load
duke
parents:
diff changeset
   993
        checkDimension(tree.pos(), tree.sym.erasure(types));
06bc494ca11e Initial load
duke
parents:
diff changeset
   994
        genMethod(tree, localEnv, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
   995
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   996
//where
06bc494ca11e Initial load
duke
parents:
diff changeset
   997
        /** Generate code for a method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   998
         *  @param tree     The tree representing the method definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   999
         *  @param env      The environment current for the method body.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1000
         *  @param fatcode  A flag that indicates whether all jumps are
06bc494ca11e Initial load
duke
parents:
diff changeset
  1001
         *                  within 32K.  We first invoke this method under
06bc494ca11e Initial load
duke
parents:
diff changeset
  1002
         *                  the assumption that fatcode == false, i.e. all
06bc494ca11e Initial load
duke
parents:
diff changeset
  1003
         *                  jumps are within 32K.  If this fails, fatcode
06bc494ca11e Initial load
duke
parents:
diff changeset
  1004
         *                  is set to true and we try again.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1005
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1006
        void genMethod(JCMethodDecl tree, Env<GenContext> env, boolean fatcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1007
            MethodSymbol meth = tree.sym;
18653
1407564fb956 8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents: 18010
diff changeset
  1008
            int extras = 0;
1407564fb956 8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents: 18010
diff changeset
  1009
            // Count up extra parameters
1407564fb956 8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents: 18010
diff changeset
  1010
            if (meth.isConstructor()) {
1407564fb956 8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents: 18010
diff changeset
  1011
                extras++;
1407564fb956 8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents: 18010
diff changeset
  1012
                if (meth.enclClass().isInner() &&
1407564fb956 8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents: 18010
diff changeset
  1013
                    !meth.enclClass().isStatic()) {
1407564fb956 8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents: 18010
diff changeset
  1014
                    extras++;
1407564fb956 8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents: 18010
diff changeset
  1015
                }
1407564fb956 8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents: 18010
diff changeset
  1016
            } else if ((tree.mods.flags & STATIC) == 0) {
1407564fb956 8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents: 18010
diff changeset
  1017
                extras++;
1407564fb956 8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents: 18010
diff changeset
  1018
            }
1407564fb956 8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents: 18010
diff changeset
  1019
            //      System.err.println("Generating " + meth + " in " + meth.owner); //DEBUG
1407564fb956 8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents: 18010
diff changeset
  1020
            if (Code.width(types.erasure(env.enclMethod.sym.type).getParameterTypes()) + extras >
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1021
                ClassFile.MAX_PARAMETERS) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1022
                log.error(tree.pos(), "limit.parameters");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1023
                nerrs++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1024
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1025
06bc494ca11e Initial load
duke
parents:
diff changeset
  1026
            else if (tree.body != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1027
                // Create a new code structure and initialize it.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1028
                int startpcCrt = initCode(tree, env, fatcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1029
06bc494ca11e Initial load
duke
parents:
diff changeset
  1030
                try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1031
                    genStat(tree.body, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1032
                } catch (CodeSizeOverflow e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1033
                    // Failed due to code limit, try again with jsr/ret
06bc494ca11e Initial load
duke
parents:
diff changeset
  1034
                    startpcCrt = initCode(tree, env, fatcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1035
                    genStat(tree.body, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1036
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1037
06bc494ca11e Initial load
duke
parents:
diff changeset
  1038
                if (code.state.stacksize != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1039
                    log.error(tree.body.pos(), "stack.sim.error", tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1040
                    throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1041
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1042
06bc494ca11e Initial load
duke
parents:
diff changeset
  1043
                // If last statement could complete normally, insert a
06bc494ca11e Initial load
duke
parents:
diff changeset
  1044
                // return at the end.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1045
                if (code.isAlive()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1046
                    code.statBegin(TreeInfo.endPos(tree.body));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1047
                    if (env.enclMethod == null ||
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
  1048
                        env.enclMethod.sym.type.getReturnType().hasTag(VOID)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1049
                        code.emitop0(return_);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1050
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1051
                        // sometime dead code seems alive (4415991);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1052
                        // generate a small loop instead
06bc494ca11e Initial load
duke
parents:
diff changeset
  1053
                        int startpc = code.entryPoint();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1054
                        CondItem c = items.makeCondItem(goto_);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1055
                        code.resolve(c.jumpTrue(), startpc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1056
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1057
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1058
                if (genCrt)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1059
                    code.crt.put(tree.body,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1060
                                 CRT_BLOCK,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1061
                                 startpcCrt,
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1062
                                 code.curCP());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1063
06bc494ca11e Initial load
duke
parents:
diff changeset
  1064
                code.endScopes(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1065
06bc494ca11e Initial load
duke
parents:
diff changeset
  1066
                // If we exceeded limits, panic
06bc494ca11e Initial load
duke
parents:
diff changeset
  1067
                if (code.checkLimits(tree.pos(), log)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1068
                    nerrs++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1069
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1070
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1071
06bc494ca11e Initial load
duke
parents:
diff changeset
  1072
                // If we generated short code but got a long jump, do it again
06bc494ca11e Initial load
duke
parents:
diff changeset
  1073
                // with fatCode = true.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1074
                if (!fatcode && code.fatcode) genMethod(tree, env, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1075
06bc494ca11e Initial load
duke
parents:
diff changeset
  1076
                // Clean up
06bc494ca11e Initial load
duke
parents:
diff changeset
  1077
                if(stackMap == StackMapFormat.JSR202) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1078
                    code.lastFrame = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1079
                    code.frameBeforeLast = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1080
                }
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents: 10457
diff changeset
  1081
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1082
                // Compress exception table
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents: 10457
diff changeset
  1083
                code.compressCatchTable();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1084
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1085
                // Fill in type annotation positions for exception parameters
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1086
                code.fillExceptionParameterPositions();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1087
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1088
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1089
06bc494ca11e Initial load
duke
parents:
diff changeset
  1090
        private int initCode(JCMethodDecl tree, Env<GenContext> env, boolean fatcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1091
            MethodSymbol meth = tree.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1092
06bc494ca11e Initial load
duke
parents:
diff changeset
  1093
            // Create a new code structure.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1094
            meth.code = code = new Code(meth,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1095
                                        fatcode,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1096
                                        lineDebugInfo ? toplevel.lineMap : null,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1097
                                        varDebugInfo,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1098
                                        stackMap,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1099
                                        debugCode,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1100
                                        genCrt ? new CRTable(tree, env.toplevel.endPositions)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1101
                                               : null,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1102
                                        syms,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1103
                                        types,
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1104
                                        pool,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1105
                                        varDebugInfo ? lvtRanges : null);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1106
            items = new Items(pool, code, syms, types);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1107
            if (code.debugCode) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1108
                System.err.println(meth + " for body " + tree);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1109
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1110
06bc494ca11e Initial load
duke
parents:
diff changeset
  1111
            // If method is not static, create a new local variable address
06bc494ca11e Initial load
duke
parents:
diff changeset
  1112
            // for `this'.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1113
            if ((tree.mods.flags & STATIC) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1114
                Type selfType = meth.owner.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1115
                if (meth.isConstructor() && selfType != syms.objectType)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1116
                    selfType = UninitializedType.uninitializedThis(selfType);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1117
                code.setDefined(
06bc494ca11e Initial load
duke
parents:
diff changeset
  1118
                        code.newLocal(
06bc494ca11e Initial load
duke
parents:
diff changeset
  1119
                            new VarSymbol(FINAL, names._this, selfType, meth.owner)));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1120
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1121
06bc494ca11e Initial load
duke
parents:
diff changeset
  1122
            // Mark all parameters as defined from the beginning of
06bc494ca11e Initial load
duke
parents:
diff changeset
  1123
            // the method.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1124
            for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1125
                checkDimension(l.head.pos(), l.head.sym.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1126
                code.setDefined(code.newLocal(l.head.sym));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1127
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1128
06bc494ca11e Initial load
duke
parents:
diff changeset
  1129
            // Get ready to generate code for method body.
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1130
            int startpcCrt = genCrt ? code.curCP() : 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1131
            code.entryPoint();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1132
06bc494ca11e Initial load
duke
parents:
diff changeset
  1133
            // Suppress initial stackmap
06bc494ca11e Initial load
duke
parents:
diff changeset
  1134
            code.pendingStackMap = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1135
06bc494ca11e Initial load
duke
parents:
diff changeset
  1136
            return startpcCrt;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1137
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1138
06bc494ca11e Initial load
duke
parents:
diff changeset
  1139
    public void visitVarDef(JCVariableDecl tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1140
        VarSymbol v = tree.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1141
        code.newLocal(v);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1142
        if (tree.init != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1143
            checkStringConstant(tree.init.pos(), v.getConstValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1144
            if (v.getConstValue() == null || varDebugInfo) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1145
                genExpr(tree.init, v.erasure(types)).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1146
                items.makeLocalItem(v).store();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1147
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1148
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1149
        checkDimension(tree.pos(), v.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1150
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1151
06bc494ca11e Initial load
duke
parents:
diff changeset
  1152
    public void visitSkip(JCSkip tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1153
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1154
06bc494ca11e Initial load
duke
parents:
diff changeset
  1155
    public void visitBlock(JCBlock tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1156
        int limit = code.nextreg;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1157
        Env<GenContext> localEnv = env.dup(tree, new GenContext());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1158
        genStats(tree.stats, localEnv);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1159
        // End the scope of all block-local variables in variable info.
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  1160
        if (!env.tree.hasTag(METHODDEF)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1161
            code.statBegin(tree.endpos);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1162
            code.endScopes(limit);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1163
            code.pendingStatPos = Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1164
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1165
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1166
06bc494ca11e Initial load
duke
parents:
diff changeset
  1167
    public void visitDoLoop(JCDoWhileLoop tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1168
        genLoop(tree, tree.body, tree.cond, List.<JCExpressionStatement>nil(), false);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1169
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1170
06bc494ca11e Initial load
duke
parents:
diff changeset
  1171
    public void visitWhileLoop(JCWhileLoop tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1172
        genLoop(tree, tree.body, tree.cond, List.<JCExpressionStatement>nil(), true);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1173
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1174
06bc494ca11e Initial load
duke
parents:
diff changeset
  1175
    public void visitForLoop(JCForLoop tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1176
        int limit = code.nextreg;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1177
        genStats(tree.init, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1178
        genLoop(tree, tree.body, tree.cond, tree.step, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1179
        code.endScopes(limit);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1180
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1181
    //where
06bc494ca11e Initial load
duke
parents:
diff changeset
  1182
        /** Generate code for a loop.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1183
         *  @param loop       The tree representing the loop.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1184
         *  @param body       The loop's body.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1185
         *  @param cond       The loop's controling condition.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1186
         *  @param step       "Step" statements to be inserted at end of
06bc494ca11e Initial load
duke
parents:
diff changeset
  1187
         *                    each iteration.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1188
         *  @param testFirst  True if the loop test belongs before the body.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1189
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1190
        private void genLoop(JCStatement loop,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1191
                             JCStatement body,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1192
                             JCExpression cond,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1193
                             List<JCExpressionStatement> step,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1194
                             boolean testFirst) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1195
            Env<GenContext> loopEnv = env.dup(loop, new GenContext());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1196
            int startpc = code.entryPoint();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1197
            if (testFirst) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1198
                CondItem c;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1199
                if (cond != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1200
                    code.statBegin(cond.pos);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1201
                    c = genCond(TreeInfo.skipParens(cond), CRT_FLOW_CONTROLLER);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1202
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1203
                    c = items.makeCondItem(goto_);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1204
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1205
                Chain loopDone = c.jumpFalse();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1206
                code.resolve(c.trueJumps);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1207
                genStat(body, loopEnv, CRT_STATEMENT | CRT_FLOW_TARGET);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1208
                if (varDebugInfo) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1209
                    checkLoopLocalVarRangeEnding(loop, body,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1210
                            LoopLocalVarRangeEndingPoint.BEFORE_STEPS);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1211
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1212
                code.resolve(loopEnv.info.cont);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1213
                genStats(step, loopEnv);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1214
                if (varDebugInfo) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1215
                    checkLoopLocalVarRangeEnding(loop, body,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1216
                            LoopLocalVarRangeEndingPoint.AFTER_STEPS);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1217
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1218
                code.resolve(code.branch(goto_), startpc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1219
                code.resolve(loopDone);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1220
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1221
                genStat(body, loopEnv, CRT_STATEMENT | CRT_FLOW_TARGET);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1222
                if (varDebugInfo) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1223
                    checkLoopLocalVarRangeEnding(loop, body,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1224
                            LoopLocalVarRangeEndingPoint.BEFORE_STEPS);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1225
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1226
                code.resolve(loopEnv.info.cont);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1227
                genStats(step, loopEnv);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1228
                if (varDebugInfo) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1229
                    checkLoopLocalVarRangeEnding(loop, body,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1230
                            LoopLocalVarRangeEndingPoint.AFTER_STEPS);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1231
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1232
                CondItem c;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1233
                if (cond != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1234
                    code.statBegin(cond.pos);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1235
                    c = genCond(TreeInfo.skipParens(cond), CRT_FLOW_CONTROLLER);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1236
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1237
                    c = items.makeCondItem(goto_);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1238
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1239
                code.resolve(c.jumpTrue(), startpc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1240
                code.resolve(c.falseJumps);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1241
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1242
            code.resolve(loopEnv.info.exit);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1243
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1244
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1245
        private enum LoopLocalVarRangeEndingPoint {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1246
            BEFORE_STEPS,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1247
            AFTER_STEPS,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1248
        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1249
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1250
        /**
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1251
         *  Checks whether we have reached an alive range ending point for local
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1252
         *  variables after a loop.
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1253
         *
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1254
         *  Local variables alive range ending point for loops varies depending
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1255
         *  on the loop type. The range can be closed before or after the code
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1256
         *  for the steps sentences has been generated.
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1257
         *
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1258
         *  - While loops has no steps so in that case the range is closed just
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1259
         *  after the body of the loop.
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1260
         *
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1261
         *  - For-like loops may have steps so as long as the steps sentences
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1262
         *  can possibly contain non-synthetic local variables, the alive range
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1263
         *  for local variables must be closed after the steps in this case.
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1264
        */
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1265
        private void checkLoopLocalVarRangeEnding(JCTree loop, JCTree body,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1266
                LoopLocalVarRangeEndingPoint endingPoint) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1267
            if (varDebugInfo && lvtRanges.containsKey(code.meth, body)) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1268
                switch (endingPoint) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1269
                    case BEFORE_STEPS:
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1270
                        if (!loop.hasTag(FORLOOP)) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1271
                            code.closeAliveRanges(body);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1272
                        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1273
                        break;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1274
                    case AFTER_STEPS:
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1275
                        if (loop.hasTag(FORLOOP)) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1276
                            code.closeAliveRanges(body);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1277
                        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1278
                        break;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1279
                }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1280
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1281
        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1282
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1283
    public void visitForeachLoop(JCEnhancedForLoop tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1284
        throw new AssertionError(); // should have been removed by Lower.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1285
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1286
06bc494ca11e Initial load
duke
parents:
diff changeset
  1287
    public void visitLabelled(JCLabeledStatement tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1288
        Env<GenContext> localEnv = env.dup(tree, new GenContext());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1289
        genStat(tree.body, localEnv, CRT_STATEMENT);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1290
        code.resolve(localEnv.info.exit);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1291
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1292
06bc494ca11e Initial load
duke
parents:
diff changeset
  1293
    public void visitSwitch(JCSwitch tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1294
        int limit = code.nextreg;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
  1295
        Assert.check(!tree.selector.type.hasTag(CLASS));
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1296
        int startpcCrt = genCrt ? code.curCP() : 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1297
        Item sel = genExpr(tree.selector, syms.intType);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1298
        List<JCCase> cases = tree.cases;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1299
        if (cases.isEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1300
            // We are seeing:  switch <sel> {}
06bc494ca11e Initial load
duke
parents:
diff changeset
  1301
            sel.load().drop();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1302
            if (genCrt)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1303
                code.crt.put(TreeInfo.skipParens(tree.selector),
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1304
                             CRT_FLOW_CONTROLLER, startpcCrt, code.curCP());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1305
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1306
            // We are seeing a nonempty switch.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1307
            sel.load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1308
            if (genCrt)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1309
                code.crt.put(TreeInfo.skipParens(tree.selector),
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1310
                             CRT_FLOW_CONTROLLER, startpcCrt, code.curCP());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1311
            Env<GenContext> switchEnv = env.dup(tree, new GenContext());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1312
            switchEnv.info.isSwitch = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1313
06bc494ca11e Initial load
duke
parents:
diff changeset
  1314
            // Compute number of labels and minimum and maximum label values.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1315
            // For each case, store its label in an array.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1316
            int lo = Integer.MAX_VALUE;  // minimum label.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1317
            int hi = Integer.MIN_VALUE;  // maximum label.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1318
            int nlabels = 0;               // number of labels.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1319
06bc494ca11e Initial load
duke
parents:
diff changeset
  1320
            int[] labels = new int[cases.length()];  // the label array.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1321
            int defaultIndex = -1;     // the index of the default clause.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1322
06bc494ca11e Initial load
duke
parents:
diff changeset
  1323
            List<JCCase> l = cases;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1324
            for (int i = 0; i < labels.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1325
                if (l.head.pat != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1326
                    int val = ((Number)l.head.pat.type.constValue()).intValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1327
                    labels[i] = val;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1328
                    if (val < lo) lo = val;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1329
                    if (hi < val) hi = val;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1330
                    nlabels++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1331
                } else {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1332
                    Assert.check(defaultIndex == -1);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1333
                    defaultIndex = i;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1334
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1335
                l = l.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1336
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1337
06bc494ca11e Initial load
duke
parents:
diff changeset
  1338
            // Determine whether to issue a tableswitch or a lookupswitch
06bc494ca11e Initial load
duke
parents:
diff changeset
  1339
            // instruction.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1340
            long table_space_cost = 4 + ((long) hi - lo + 1); // words
06bc494ca11e Initial load
duke
parents:
diff changeset
  1341
            long table_time_cost = 3; // comparisons
06bc494ca11e Initial load
duke
parents:
diff changeset
  1342
            long lookup_space_cost = 3 + 2 * (long) nlabels;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1343
            long lookup_time_cost = nlabels;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1344
            int opcode =
06bc494ca11e Initial load
duke
parents:
diff changeset
  1345
                nlabels > 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1346
                table_space_cost + 3 * table_time_cost <=
06bc494ca11e Initial load
duke
parents:
diff changeset
  1347
                lookup_space_cost + 3 * lookup_time_cost
06bc494ca11e Initial load
duke
parents:
diff changeset
  1348
                ?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1349
                tableswitch : lookupswitch;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1350
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1351
            int startpc = code.curCP();    // the position of the selector operation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1352
            code.emitop0(opcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1353
            code.align(4);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1354
            int tableBase = code.curCP();  // the start of the jump table
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1355
            int[] offsets = null;          // a table of offsets for a lookupswitch
06bc494ca11e Initial load
duke
parents:
diff changeset
  1356
            code.emit4(-1);                // leave space for default offset
06bc494ca11e Initial load
duke
parents:
diff changeset
  1357
            if (opcode == tableswitch) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1358
                code.emit4(lo);            // minimum label
06bc494ca11e Initial load
duke
parents:
diff changeset
  1359
                code.emit4(hi);            // maximum label
06bc494ca11e Initial load
duke
parents:
diff changeset
  1360
                for (long i = lo; i <= hi; i++) {  // leave space for jump table
06bc494ca11e Initial load
duke
parents:
diff changeset
  1361
                    code.emit4(-1);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1362
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1363
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1364
                code.emit4(nlabels);    // number of labels
06bc494ca11e Initial load
duke
parents:
diff changeset
  1365
                for (int i = 0; i < nlabels; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1366
                    code.emit4(-1); code.emit4(-1); // leave space for lookup table
06bc494ca11e Initial load
duke
parents:
diff changeset
  1367
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1368
                offsets = new int[labels.length];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1369
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1370
            Code.State stateSwitch = code.state.dup();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1371
            code.markDead();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1372
06bc494ca11e Initial load
duke
parents:
diff changeset
  1373
            // For each case do:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1374
            l = cases;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1375
            for (int i = 0; i < labels.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1376
                JCCase c = l.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1377
                l = l.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1378
06bc494ca11e Initial load
duke
parents:
diff changeset
  1379
                int pc = code.entryPoint(stateSwitch);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1380
                // Insert offset directly into code or else into the
06bc494ca11e Initial load
duke
parents:
diff changeset
  1381
                // offsets table.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1382
                if (i != defaultIndex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1383
                    if (opcode == tableswitch) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1384
                        code.put4(
06bc494ca11e Initial load
duke
parents:
diff changeset
  1385
                            tableBase + 4 * (labels[i] - lo + 3),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1386
                            pc - startpc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1387
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1388
                        offsets[i] = pc - startpc;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1389
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1390
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1391
                    code.put4(tableBase, pc - startpc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1392
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1393
06bc494ca11e Initial load
duke
parents:
diff changeset
  1394
                // Generate code for the statements in this case.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1395
                genStats(c.stats, switchEnv, CRT_FLOW_TARGET);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1396
                if (varDebugInfo && lvtRanges.containsKey(code.meth, c.stats.last())) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1397
                    code.closeAliveRanges(c.stats.last());
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1398
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1399
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1400
06bc494ca11e Initial load
duke
parents:
diff changeset
  1401
            // Resolve all breaks.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1402
            code.resolve(switchEnv.info.exit);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1403
06bc494ca11e Initial load
duke
parents:
diff changeset
  1404
            // If we have not set the default offset, we do so now.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1405
            if (code.get4(tableBase) == -1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1406
                code.put4(tableBase, code.entryPoint(stateSwitch) - startpc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1407
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1408
06bc494ca11e Initial load
duke
parents:
diff changeset
  1409
            if (opcode == tableswitch) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1410
                // Let any unfilled slots point to the default case.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1411
                int defaultOffset = code.get4(tableBase);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1412
                for (long i = lo; i <= hi; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1413
                    int t = (int)(tableBase + 4 * (i - lo + 3));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1414
                    if (code.get4(t) == -1)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1415
                        code.put4(t, defaultOffset);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1416
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1417
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1418
                // Sort non-default offsets and copy into lookup table.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1419
                if (defaultIndex >= 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1420
                    for (int i = defaultIndex; i < labels.length - 1; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1421
                        labels[i] = labels[i+1];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1422
                        offsets[i] = offsets[i+1];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1423
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1424
                if (nlabels > 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1425
                    qsort2(labels, offsets, 0, nlabels - 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1426
                for (int i = 0; i < nlabels; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1427
                    int caseidx = tableBase + 8 * (i + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1428
                    code.put4(caseidx, labels[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1429
                    code.put4(caseidx + 4, offsets[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1430
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1431
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1432
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1433
        code.endScopes(limit);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1434
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1435
//where
06bc494ca11e Initial load
duke
parents:
diff changeset
  1436
        /** Sort (int) arrays of keys and values
06bc494ca11e Initial load
duke
parents:
diff changeset
  1437
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1438
       static void qsort2(int[] keys, int[] values, int lo, int hi) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1439
            int i = lo;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1440
            int j = hi;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1441
            int pivot = keys[(i+j)/2];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1442
            do {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1443
                while (keys[i] < pivot) i++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1444
                while (pivot < keys[j]) j--;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1445
                if (i <= j) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1446
                    int temp1 = keys[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1447
                    keys[i] = keys[j];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1448
                    keys[j] = temp1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1449
                    int temp2 = values[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1450
                    values[i] = values[j];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1451
                    values[j] = temp2;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1452
                    i++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1453
                    j--;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1454
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1455
            } while (i <= j);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1456
            if (lo < j) qsort2(keys, values, lo, j);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1457
            if (i < hi) qsort2(keys, values, i, hi);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1458
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1459
06bc494ca11e Initial load
duke
parents:
diff changeset
  1460
    public void visitSynchronized(JCSynchronized tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1461
        int limit = code.nextreg;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1462
        // Generate code to evaluate lock and save in temporary variable.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1463
        final LocalItem lockVar = makeTemp(syms.objectType);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1464
        genExpr(tree.lock, tree.lock.type).load().duplicate();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1465
        lockVar.store();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1466
06bc494ca11e Initial load
duke
parents:
diff changeset
  1467
        // Generate code to enter monitor.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1468
        code.emitop0(monitorenter);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1469
        code.state.lock(lockVar.reg);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1470
06bc494ca11e Initial load
duke
parents:
diff changeset
  1471
        // Generate code for a try statement with given body, no catch clauses
06bc494ca11e Initial load
duke
parents:
diff changeset
  1472
        // in a new environment with the "exit-monitor" operation as finalizer.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1473
        final Env<GenContext> syncEnv = env.dup(tree, new GenContext());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1474
        syncEnv.info.finalize = new GenFinalizer() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1475
            void gen() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1476
                genLast();
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1477
                Assert.check(syncEnv.info.gaps.length() % 2 == 0);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1478
                syncEnv.info.gaps.append(code.curCP());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1479
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1480
            void genLast() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1481
                if (code.isAlive()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1482
                    lockVar.load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1483
                    code.emitop0(monitorexit);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1484
                    code.state.unlock(lockVar.reg);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1485
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1486
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1487
        };
06bc494ca11e Initial load
duke
parents:
diff changeset
  1488
        syncEnv.info.gaps = new ListBuffer<Integer>();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1489
        genTry(tree.body, List.<JCCatch>nil(), syncEnv);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1490
        code.endScopes(limit);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1491
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1492
06bc494ca11e Initial load
duke
parents:
diff changeset
  1493
    public void visitTry(final JCTry tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1494
        // Generate code for a try statement with given body and catch clauses,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1495
        // in a new environment which calls the finally block if there is one.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1496
        final Env<GenContext> tryEnv = env.dup(tree, new GenContext());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1497
        final Env<GenContext> oldEnv = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1498
        if (!useJsrLocally) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1499
            useJsrLocally =
06bc494ca11e Initial load
duke
parents:
diff changeset
  1500
                (stackMap == StackMapFormat.NONE) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1501
                (jsrlimit <= 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1502
                jsrlimit < 100 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1503
                estimateCodeComplexity(tree.finalizer)>jsrlimit);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1504
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1505
        tryEnv.info.finalize = new GenFinalizer() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1506
            void gen() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1507
                if (useJsrLocally) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1508
                    if (tree.finalizer != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1509
                        Code.State jsrState = code.state.dup();
5004
6c2694dc2da0 6929544: langtools source code uses statics qualified by instance variables
jjg
parents: 4875
diff changeset
  1510
                        jsrState.push(Code.jsrReturnValue);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1511
                        tryEnv.info.cont =
06bc494ca11e Initial load
duke
parents:
diff changeset
  1512
                            new Chain(code.emitJump(jsr),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1513
                                      tryEnv.info.cont,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1514
                                      jsrState);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1515
                    }
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1516
                    Assert.check(tryEnv.info.gaps.length() % 2 == 0);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1517
                    tryEnv.info.gaps.append(code.curCP());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1518
                } else {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1519
                    Assert.check(tryEnv.info.gaps.length() % 2 == 0);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1520
                    tryEnv.info.gaps.append(code.curCP());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1521
                    genLast();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1522
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1523
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1524
            void genLast() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1525
                if (tree.finalizer != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1526
                    genStat(tree.finalizer, oldEnv, CRT_BLOCK);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1527
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1528
            boolean hasFinalizer() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1529
                return tree.finalizer != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1530
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1531
        };
06bc494ca11e Initial load
duke
parents:
diff changeset
  1532
        tryEnv.info.gaps = new ListBuffer<Integer>();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1533
        genTry(tree.body, tree.catchers, tryEnv);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1534
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1535
    //where
06bc494ca11e Initial load
duke
parents:
diff changeset
  1536
        /** Generate code for a try or synchronized statement
06bc494ca11e Initial load
duke
parents:
diff changeset
  1537
         *  @param body      The body of the try or synchronized statement.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1538
         *  @param catchers  The lis of catch clauses.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1539
         *  @param env       the environment current for the body.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1540
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1541
        void genTry(JCTree body, List<JCCatch> catchers, Env<GenContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1542
            int limit = code.nextreg;
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1543
            int startpc = code.curCP();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1544
            Code.State stateTry = code.state.dup();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1545
            genStat(body, env, CRT_BLOCK);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1546
            int endpc = code.curCP();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1547
            boolean hasFinalizer =
06bc494ca11e Initial load
duke
parents:
diff changeset
  1548
                env.info.finalize != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1549
                env.info.finalize.hasFinalizer();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1550
            List<Integer> gaps = env.info.gaps.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1551
            code.statBegin(TreeInfo.endPos(body));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1552
            genFinalizer(env);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1553
            code.statBegin(TreeInfo.endPos(env.tree));
19923
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1554
            Chain exitChain = code.branch(goto_);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1555
            if (varDebugInfo && lvtRanges.containsKey(code.meth, body)) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1556
                code.closeAliveRanges(body);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1557
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1558
            endFinalizerGap(env);
19923
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1559
            if (startpc != endpc) for (List<JCCatch> l = catchers; l.nonEmpty(); l = l.tail) {
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1560
                // start off with exception on stack
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1561
                code.entryPoint(stateTry, l.head.param.sym.type);
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1562
                genCatch(l.head, env, startpc, endpc, gaps);
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1563
                genFinalizer(env);
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1564
                if (hasFinalizer || l.tail.nonEmpty()) {
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1565
                    code.statBegin(TreeInfo.endPos(env.tree));
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1566
                    exitChain = Code.mergeChains(exitChain,
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1567
                                                 code.branch(goto_));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1568
                }
19923
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1569
                endFinalizerGap(env);
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1570
            }
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1571
            if (hasFinalizer) {
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1572
                // Create a new register segement to avoid allocating
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1573
                // the same variables in finalizers and other statements.
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1574
                code.newRegSegment();
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1575
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1576
                // Add a catch-all clause.
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1577
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1578
                // start off with exception on stack
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1579
                int catchallpc = code.entryPoint(stateTry, syms.throwableType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1580
19923
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1581
                // Register all exception ranges for catch all clause.
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1582
                // The range of the catch all clause is from the beginning
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1583
                // of the try or synchronized block until the present
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1584
                // code pointer excluding all gaps in the current
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1585
                // environment's GenContext.
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1586
                int startseg = startpc;
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1587
                while (env.info.gaps.nonEmpty()) {
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1588
                    int endseg = env.info.gaps.next().intValue();
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1589
                    registerCatch(body.pos(), startseg, endseg,
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1590
                                  catchallpc, 0);
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1591
                    startseg = env.info.gaps.next().intValue();
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1592
                }
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1593
                code.statBegin(TreeInfo.finalizerPos(env.tree));
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1594
                code.markStatBegin();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1595
19923
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1596
                Item excVar = makeTemp(syms.throwableType);
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1597
                excVar.store();
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1598
                genFinalizer(env);
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1599
                excVar.load();
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1600
                registerCatch(body.pos(), startseg,
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1601
                              env.info.gaps.next().intValue(),
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1602
                              catchallpc, 0);
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1603
                code.emitop0(athrow);
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1604
                code.markDead();
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1605
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1606
                // If there are jsr's to this finalizer, ...
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1607
                if (env.info.cont != null) {
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1608
                    // Resolve all jsr's.
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1609
                    code.resolve(env.info.cont);
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1610
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1611
                    // Mark statement line number
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1612
                    code.statBegin(TreeInfo.finalizerPos(env.tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1613
                    code.markStatBegin();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1614
19923
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1615
                    // Save return address.
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1616
                    LocalItem retVar = makeTemp(syms.throwableType);
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1617
                    retVar.store();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1618
19923
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1619
                    // Generate finalizer code.
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1620
                    env.info.finalize.genLast();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1621
19923
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1622
                    // Return.
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1623
                    code.emitop1w(ret, retVar.reg);
4895f15b3845 8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents: 19247
diff changeset
  1624
                    code.markDead();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1625
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1626
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1627
            // Resolve all breaks.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1628
            code.resolve(exitChain);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1629
06bc494ca11e Initial load
duke
parents:
diff changeset
  1630
            code.endScopes(limit);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1631
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1632
06bc494ca11e Initial load
duke
parents:
diff changeset
  1633
        /** Generate code for a catch clause.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1634
         *  @param tree     The catch clause.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1635
         *  @param env      The environment current in the enclosing try.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1636
         *  @param startpc  Start pc of try-block.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1637
         *  @param endpc    End pc of try-block.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1638
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1639
        void genCatch(JCCatch tree,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1640
                      Env<GenContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1641
                      int startpc, int endpc,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1642
                      List<Integer> gaps) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1643
            if (startpc != endpc) {
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5004
diff changeset
  1644
                List<JCExpression> subClauses = TreeInfo.isMultiCatch(tree) ?
9300
c2de4dd9853b 7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents: 8036
diff changeset
  1645
                        ((JCTypeUnion)tree.param.vartype).alternatives :
6354
f50c012cd1f0 6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents: 5857
diff changeset
  1646
                        List.of(tree.param.vartype);
f50c012cd1f0 6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents: 5857
diff changeset
  1647
                while (gaps.nonEmpty()) {
f50c012cd1f0 6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents: 5857
diff changeset
  1648
                    for (JCExpression subCatch : subClauses) {
f50c012cd1f0 6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents: 5857
diff changeset
  1649
                        int catchType = makeRef(tree.pos(), subCatch.type);
f50c012cd1f0 6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents: 5857
diff changeset
  1650
                        int end = gaps.head.intValue();
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5004
diff changeset
  1651
                        registerCatch(tree.pos(),
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1652
                                      startpc,  end, code.curCP(),
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5004
diff changeset
  1653
                                      catchType);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1654
                        if (subCatch.type.isAnnotated()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1655
                            // All compounds share the same position, simply update the
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1656
                            // first one.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1657
                            subCatch.type.getAnnotationMirrors().head.position.type_index = catchType;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1658
                        }
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5004
diff changeset
  1659
                    }
6354
f50c012cd1f0 6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents: 5857
diff changeset
  1660
                    gaps = gaps.tail;
f50c012cd1f0 6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents: 5857
diff changeset
  1661
                    startpc = gaps.head.intValue();
f50c012cd1f0 6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents: 5857
diff changeset
  1662
                    gaps = gaps.tail;
f50c012cd1f0 6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents: 5857
diff changeset
  1663
                }
f50c012cd1f0 6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents: 5857
diff changeset
  1664
                if (startpc < endpc) {
f50c012cd1f0 6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents: 5857
diff changeset
  1665
                    for (JCExpression subCatch : subClauses) {
f50c012cd1f0 6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents: 5857
diff changeset
  1666
                        int catchType = makeRef(tree.pos(), subCatch.type);
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5004
diff changeset
  1667
                        registerCatch(tree.pos(),
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1668
                                      startpc, endpc, code.curCP(),
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5004
diff changeset
  1669
                                      catchType);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1670
                        if (subCatch.type.isAnnotated()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1671
                            // All compounds share the same position, simply update the
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1672
                            // first one.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1673
                            subCatch.type.getAnnotationMirrors().head.position.type_index = catchType;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1674
                        }
6354
f50c012cd1f0 6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents: 5857
diff changeset
  1675
                    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1676
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1677
                VarSymbol exparam = tree.param.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1678
                code.statBegin(tree.pos);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1679
                code.markStatBegin();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1680
                int limit = code.nextreg;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1681
                int exlocal = code.newLocal(exparam);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1682
                items.makeLocalItem(exparam).store();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1683
                code.statBegin(TreeInfo.firstStatPos(tree.body));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1684
                genStat(tree.body, env, CRT_BLOCK);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1685
                code.endScopes(limit);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1686
                code.statBegin(TreeInfo.endPos(tree.body));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1687
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1688
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1689
06bc494ca11e Initial load
duke
parents:
diff changeset
  1690
        /** Register a catch clause in the "Exceptions" code-attribute.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1691
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1692
        void registerCatch(DiagnosticPosition pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1693
                           int startpc, int endpc,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1694
                           int handler_pc, int catch_type) {
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents: 10457
diff changeset
  1695
            char startpc1 = (char)startpc;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents: 10457
diff changeset
  1696
            char endpc1 = (char)endpc;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents: 10457
diff changeset
  1697
            char handler_pc1 = (char)handler_pc;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents: 10457
diff changeset
  1698
            if (startpc1 == startpc &&
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents: 10457
diff changeset
  1699
                endpc1 == endpc &&
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents: 10457
diff changeset
  1700
                handler_pc1 == handler_pc) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents: 10457
diff changeset
  1701
                code.addCatch(startpc1, endpc1, handler_pc1,
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents: 10457
diff changeset
  1702
                              (char)catch_type);
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents: 10457
diff changeset
  1703
            } else {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents: 10457
diff changeset
  1704
                if (!useJsrLocally && !target.generateStackMapTable()) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents: 10457
diff changeset
  1705
                    useJsrLocally = true;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents: 10457
diff changeset
  1706
                    throw new CodeSizeOverflow();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1707
                } else {
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents: 10457
diff changeset
  1708
                    log.error(pos, "limit.code.too.large.for.try.stmt");
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents: 10457
diff changeset
  1709
                    nerrs++;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1710
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1711
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1712
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1713
06bc494ca11e Initial load
duke
parents:
diff changeset
  1714
    /** Very roughly estimate the number of instructions needed for
06bc494ca11e Initial load
duke
parents:
diff changeset
  1715
     *  the given tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1716
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1717
    int estimateCodeComplexity(JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1718
        if (tree == null) return 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1719
        class ComplexityScanner extends TreeScanner {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1720
            int complexity = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1721
            public void scan(JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1722
                if (complexity > jsrlimit) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1723
                super.scan(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1724
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1725
            public void visitClassDef(JCClassDecl tree) {}
06bc494ca11e Initial load
duke
parents:
diff changeset
  1726
            public void visitDoLoop(JCDoWhileLoop tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1727
                { super.visitDoLoop(tree); complexity++; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1728
            public void visitWhileLoop(JCWhileLoop tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1729
                { super.visitWhileLoop(tree); complexity++; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1730
            public void visitForLoop(JCForLoop tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1731
                { super.visitForLoop(tree); complexity++; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1732
            public void visitSwitch(JCSwitch tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1733
                { super.visitSwitch(tree); complexity+=5; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1734
            public void visitCase(JCCase tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1735
                { super.visitCase(tree); complexity++; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1736
            public void visitSynchronized(JCSynchronized tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1737
                { super.visitSynchronized(tree); complexity+=6; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1738
            public void visitTry(JCTry tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1739
                { super.visitTry(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1740
                  if (tree.finalizer != null) complexity+=6; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1741
            public void visitCatch(JCCatch tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1742
                { super.visitCatch(tree); complexity+=2; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1743
            public void visitConditional(JCConditional tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1744
                { super.visitConditional(tree); complexity+=2; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1745
            public void visitIf(JCIf tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1746
                { super.visitIf(tree); complexity+=2; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1747
            // note: for break, continue, and return we don't take unwind() into account.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1748
            public void visitBreak(JCBreak tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1749
                { super.visitBreak(tree); complexity+=1; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1750
            public void visitContinue(JCContinue tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1751
                { super.visitContinue(tree); complexity+=1; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1752
            public void visitReturn(JCReturn tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1753
                { super.visitReturn(tree); complexity+=1; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1754
            public void visitThrow(JCThrow tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1755
                { super.visitThrow(tree); complexity+=1; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1756
            public void visitAssert(JCAssert tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1757
                { super.visitAssert(tree); complexity+=5; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1758
            public void visitApply(JCMethodInvocation tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1759
                { super.visitApply(tree); complexity+=2; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1760
            public void visitNewClass(JCNewClass tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1761
                { scan(tree.encl); scan(tree.args); complexity+=2; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1762
            public void visitNewArray(JCNewArray tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1763
                { super.visitNewArray(tree); complexity+=5; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1764
            public void visitAssign(JCAssign tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1765
                { super.visitAssign(tree); complexity+=1; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1766
            public void visitAssignop(JCAssignOp tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1767
                { super.visitAssignop(tree); complexity+=2; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1768
            public void visitUnary(JCUnary tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1769
                { complexity+=1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1770
                  if (tree.type.constValue() == null) super.visitUnary(tree); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1771
            public void visitBinary(JCBinary tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1772
                { complexity+=1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1773
                  if (tree.type.constValue() == null) super.visitBinary(tree); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1774
            public void visitTypeTest(JCInstanceOf tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1775
                { super.visitTypeTest(tree); complexity+=1; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1776
            public void visitIndexed(JCArrayAccess tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1777
                { super.visitIndexed(tree); complexity+=1; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1778
            public void visitSelect(JCFieldAccess tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1779
                { super.visitSelect(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1780
                  if (tree.sym.kind == VAR) complexity+=1; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1781
            public void visitIdent(JCIdent tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1782
                if (tree.sym.kind == VAR) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1783
                    complexity+=1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1784
                    if (tree.type.constValue() == null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1785
                        tree.sym.owner.kind == TYP)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1786
                        complexity+=1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1787
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1788
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1789
            public void visitLiteral(JCLiteral tree)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1790
                { complexity+=1; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1791
            public void visitTree(JCTree tree) {}
06bc494ca11e Initial load
duke
parents:
diff changeset
  1792
            public void visitWildcard(JCWildcard tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1793
                throw new AssertionError(this.getClass().getName());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1794
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1795
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1796
        ComplexityScanner scanner = new ComplexityScanner();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1797
        tree.accept(scanner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1798
        return scanner.complexity;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1799
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1800
06bc494ca11e Initial load
duke
parents:
diff changeset
  1801
    public void visitIf(JCIf tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1802
        int limit = code.nextreg;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1803
        Chain thenExit = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1804
        CondItem c = genCond(TreeInfo.skipParens(tree.cond),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1805
                             CRT_FLOW_CONTROLLER);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1806
        Chain elseChain = c.jumpFalse();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1807
        if (!c.isFalse()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1808
            code.resolve(c.trueJumps);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1809
            genStat(tree.thenpart, env, CRT_STATEMENT | CRT_FLOW_TARGET);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1810
            thenExit = code.branch(goto_);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1811
            if (varDebugInfo && lvtRanges.containsKey(code.meth, tree.thenpart)) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1812
                code.closeAliveRanges(tree.thenpart,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1813
                        thenExit != null && tree.elsepart == null ? thenExit.pc : code.cp);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1814
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1815
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1816
        if (elseChain != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1817
            code.resolve(elseChain);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1818
            if (tree.elsepart != null) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1819
                genStat(tree.elsepart, env,CRT_STATEMENT | CRT_FLOW_TARGET);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1820
                if (varDebugInfo && lvtRanges.containsKey(code.meth, tree.elsepart)) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1821
                    code.closeAliveRanges(tree.elsepart);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1822
                }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1823
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1824
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1825
        code.resolve(thenExit);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1826
        code.endScopes(limit);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1827
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1828
06bc494ca11e Initial load
duke
parents:
diff changeset
  1829
    public void visitExec(JCExpressionStatement tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1830
        // Optimize x++ to ++x and x-- to --x.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1831
        JCExpression e = tree.expr;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1832
        switch (e.getTag()) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  1833
            case POSTINC:
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  1834
                ((JCUnary) e).setTag(PREINC);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1835
                break;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  1836
            case POSTDEC:
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  1837
                ((JCUnary) e).setTag(PREDEC);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1838
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1839
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1840
        genExpr(tree.expr, tree.expr.type).drop();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1841
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1842
06bc494ca11e Initial load
duke
parents:
diff changeset
  1843
    public void visitBreak(JCBreak tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1844
        Env<GenContext> targetEnv = unwind(tree.target, env);
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1845
        Assert.check(code.state.stacksize == 0);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1846
        targetEnv.info.addExit(code.branch(goto_));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1847
        endFinalizerGaps(env, targetEnv);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1848
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1849
06bc494ca11e Initial load
duke
parents:
diff changeset
  1850
    public void visitContinue(JCContinue tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1851
        Env<GenContext> targetEnv = unwind(tree.target, env);
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1852
        Assert.check(code.state.stacksize == 0);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1853
        targetEnv.info.addCont(code.branch(goto_));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1854
        endFinalizerGaps(env, targetEnv);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1855
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1856
06bc494ca11e Initial load
duke
parents:
diff changeset
  1857
    public void visitReturn(JCReturn tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1858
        int limit = code.nextreg;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1859
        final Env<GenContext> targetEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1860
        if (tree.expr != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1861
            Item r = genExpr(tree.expr, pt).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1862
            if (hasFinally(env.enclMethod, env)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1863
                r = makeTemp(pt);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1864
                r.store();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1865
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1866
            targetEnv = unwind(env.enclMethod, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1867
            r.load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1868
            code.emitop0(ireturn + Code.truncate(Code.typecode(pt)));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1869
        } else {
18658
55e4c45e091c 7008643: inlined finally clauses confuse debuggers
vromero
parents: 18653
diff changeset
  1870
            /*  If we have a statement like:
55e4c45e091c 7008643: inlined finally clauses confuse debuggers
vromero
parents: 18653
diff changeset
  1871
             *
55e4c45e091c 7008643: inlined finally clauses confuse debuggers
vromero
parents: 18653
diff changeset
  1872
             *  return;
55e4c45e091c 7008643: inlined finally clauses confuse debuggers
vromero
parents: 18653
diff changeset
  1873
             *
55e4c45e091c 7008643: inlined finally clauses confuse debuggers
vromero
parents: 18653
diff changeset
  1874
             *  we need to store the code.pendingStatPos value before generating
55e4c45e091c 7008643: inlined finally clauses confuse debuggers
vromero
parents: 18653
diff changeset
  1875
             *  the finalizer.
55e4c45e091c 7008643: inlined finally clauses confuse debuggers
vromero
parents: 18653
diff changeset
  1876
             */
55e4c45e091c 7008643: inlined finally clauses confuse debuggers
vromero
parents: 18653
diff changeset
  1877
            int tmpPos = code.pendingStatPos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1878
            targetEnv = unwind(env.enclMethod, env);
18658
55e4c45e091c 7008643: inlined finally clauses confuse debuggers
vromero
parents: 18653
diff changeset
  1879
            code.pendingStatPos = tmpPos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1880
            code.emitop0(return_);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1881
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1882
        endFinalizerGaps(env, targetEnv);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1883
        code.endScopes(limit);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1884
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1885
06bc494ca11e Initial load
duke
parents:
diff changeset
  1886
    public void visitThrow(JCThrow tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1887
        genExpr(tree.expr, tree.expr.type).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1888
        code.emitop0(athrow);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1889
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1890
06bc494ca11e Initial load
duke
parents:
diff changeset
  1891
/* ************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1892
 * Visitor methods for expressions
06bc494ca11e Initial load
duke
parents:
diff changeset
  1893
 *************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1894
06bc494ca11e Initial load
duke
parents:
diff changeset
  1895
    public void visitApply(JCMethodInvocation tree) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1896
        setTypeAnnotationPositions(tree.pos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1897
        // Generate code for method.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1898
        Item m = genExpr(tree.meth, methodType);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1899
        // Generate code for all arguments, where the expected types are
06bc494ca11e Initial load
duke
parents:
diff changeset
  1900
        // the parameters of the method's external type (that is, any implicit
06bc494ca11e Initial load
duke
parents:
diff changeset
  1901
        // outer instance of a super(...) call appears as first parameter).
16807
b442b47d3ae9 8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents: 16801
diff changeset
  1902
        MethodSymbol msym = (MethodSymbol)TreeInfo.symbol(tree.meth);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1903
        genArgs(tree.args,
16807
b442b47d3ae9 8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents: 16801
diff changeset
  1904
                msym.externalType(types).getParameterTypes());
b442b47d3ae9 8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents: 16801
diff changeset
  1905
        if (!msym.isDynamic()) {
b442b47d3ae9 8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents: 16801
diff changeset
  1906
            code.statBegin(tree.pos);
b442b47d3ae9 8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents: 16801
diff changeset
  1907
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1908
        result = m.invoke();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1909
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1910
06bc494ca11e Initial load
duke
parents:
diff changeset
  1911
    public void visitConditional(JCConditional tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1912
        Chain thenExit = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1913
        CondItem c = genCond(tree.cond, CRT_FLOW_CONTROLLER);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1914
        Chain elseChain = c.jumpFalse();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1915
        if (!c.isFalse()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1916
            code.resolve(c.trueJumps);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1917
            int startpc = genCrt ? code.curCP() : 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1918
            genExpr(tree.truepart, pt).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1919
            code.state.forceStackTop(tree.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1920
            if (genCrt) code.crt.put(tree.truepart, CRT_FLOW_TARGET,
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1921
                                     startpc, code.curCP());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1922
            thenExit = code.branch(goto_);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1923
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1924
        if (elseChain != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1925
            code.resolve(elseChain);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1926
            int startpc = genCrt ? code.curCP() : 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1927
            genExpr(tree.falsepart, pt).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1928
            code.state.forceStackTop(tree.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1929
            if (genCrt) code.crt.put(tree.falsepart, CRT_FLOW_TARGET,
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  1930
                                     startpc, code.curCP());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1931
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1932
        code.resolve(thenExit);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1933
        result = items.makeStackItem(pt);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1934
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1935
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1936
    private void setTypeAnnotationPositions(int treePos) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1937
        MethodSymbol meth = code.meth;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1938
        boolean initOrClinit = code.meth.getKind() == javax.lang.model.element.ElementKind.CONSTRUCTOR
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1939
                || code.meth.getKind() == javax.lang.model.element.ElementKind.STATIC_INIT;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1940
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1941
        for (Attribute.TypeCompound ta : meth.getRawTypeAttributes()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1942
            if (ta.hasUnknownPosition())
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1943
                ta.tryFixPosition();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1944
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1945
            if (ta.position.matchesPos(treePos))
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1946
                ta.position.updatePosOffset(code.cp);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1947
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1948
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1949
        if (!initOrClinit)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1950
            return;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1951
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1952
        for (Attribute.TypeCompound ta : meth.owner.getRawTypeAttributes()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1953
            if (ta.hasUnknownPosition())
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1954
                ta.tryFixPosition();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1955
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1956
            if (ta.position.matchesPos(treePos))
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1957
                ta.position.updatePosOffset(code.cp);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1958
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1959
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1960
        ClassSymbol clazz = meth.enclClass();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1961
        for (Symbol s : new com.sun.tools.javac.model.FilteredMemberList(clazz.members())) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1962
            if (!s.getKind().isField())
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1963
                continue;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1964
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1965
            for (Attribute.TypeCompound ta : s.getRawTypeAttributes()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1966
                if (ta.hasUnknownPosition())
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1967
                    ta.tryFixPosition();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1968
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1969
                if (ta.position.matchesPos(treePos))
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1970
                    ta.position.updatePosOffset(code.cp);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1971
            }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1972
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16807
diff changeset
  1973
    }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1974
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1975
    public void visitNewClass(JCNewClass tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1976
        // Enclosing instances or anonymous classes should have been eliminated
06bc494ca11e Initial load
duke
parents:
diff changeset
  1977
        // by now.
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1978
        Assert.check(tree.encl == null && tree.def == null);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1979
        setTypeAnnotationPositions(tree.pos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1980
06bc494ca11e Initial load
duke
parents:
diff changeset
  1981
        code.emitop2(new_, makeRef(tree.pos(), tree.type));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1982
        code.emitop0(dup);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1983
06bc494ca11e Initial load
duke
parents:
diff changeset
  1984
        // Generate code for all arguments, where the expected types are
06bc494ca11e Initial load
duke
parents:
diff changeset
  1985
        // the parameters of the constructor's external type (that is,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1986
        // any implicit outer instance appears as first parameter).
06bc494ca11e Initial load
duke
parents:
diff changeset
  1987
        genArgs(tree.args, tree.constructor.externalType(types).getParameterTypes());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1988
06bc494ca11e Initial load
duke
parents:
diff changeset
  1989
        items.makeMemberItem(tree.constructor, true).invoke();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1990
        result = items.makeStackItem(tree.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1991
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1992
06bc494ca11e Initial load
duke
parents:
diff changeset
  1993
    public void visitNewArray(JCNewArray tree) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1994
        setTypeAnnotationPositions(tree.pos);
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1995
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1996
        if (tree.elems != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1997
            Type elemtype = types.elemtype(tree.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1998
            loadIntConst(tree.elems.length());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1999
            Item arr = makeNewArray(tree.pos(), tree.type, 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2000
            int i = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2001
            for (List<JCExpression> l = tree.elems; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2002
                arr.duplicate();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2003
                loadIntConst(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2004
                i++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2005
                genExpr(l.head, elemtype).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2006
                items.makeIndexedItem(elemtype).store();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2007
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2008
            result = arr;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2009
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2010
            for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2011
                genExpr(l.head, syms.intType).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2012
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2013
            result = makeNewArray(tree.pos(), tree.type, tree.dims.length());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2014
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2015
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2016
//where
06bc494ca11e Initial load
duke
parents:
diff changeset
  2017
        /** Generate code to create an array with given element type and number
06bc494ca11e Initial load
duke
parents:
diff changeset
  2018
         *  of dimensions.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2019
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2020
        Item makeNewArray(DiagnosticPosition pos, Type type, int ndims) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2021
            Type elemtype = types.elemtype(type);
7630
850c97ee59f2 4917091: javac rejects array over 128 in length
jjg
parents: 7074
diff changeset
  2022
            if (types.dimensions(type) > ClassFile.MAX_DIMENSIONS) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2023
                log.error(pos, "limit.dimensions");
06bc494ca11e Initial load
duke
parents:
diff changeset
  2024
                nerrs++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2025
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2026
            int elemcode = Code.arraycode(elemtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2027
            if (elemcode == 0 || (elemcode == 1 && ndims == 1)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2028
                code.emitAnewarray(makeRef(pos, elemtype), type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2029
            } else if (elemcode == 1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2030
                code.emitMultianewarray(ndims, makeRef(pos, type), type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2031
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2032
                code.emitNewarray(elemcode, type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2033
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2034
            return items.makeStackItem(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2035
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2036
06bc494ca11e Initial load
duke
parents:
diff changeset
  2037
    public void visitParens(JCParens tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2038
        result = genExpr(tree.expr, tree.expr.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2039
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2040
06bc494ca11e Initial load
duke
parents:
diff changeset
  2041
    public void visitAssign(JCAssign tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2042
        Item l = genExpr(tree.lhs, tree.lhs.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2043
        genExpr(tree.rhs, tree.lhs.type).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2044
        result = items.makeAssignItem(l);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2045
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2046
06bc494ca11e Initial load
duke
parents:
diff changeset
  2047
    public void visitAssignop(JCAssignOp tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2048
        OperatorSymbol operator = (OperatorSymbol) tree.operator;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2049
        Item l;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2050
        if (operator.opcode == string_add) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2051
            // Generate code to make a string buffer
06bc494ca11e Initial load
duke
parents:
diff changeset
  2052
            makeStringBuffer(tree.pos());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2053
06bc494ca11e Initial load
duke
parents:
diff changeset
  2054
            // Generate code for first string, possibly save one
06bc494ca11e Initial load
duke
parents:
diff changeset
  2055
            // copy under buffer
06bc494ca11e Initial load
duke
parents:
diff changeset
  2056
            l = genExpr(tree.lhs, tree.lhs.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2057
            if (l.width() > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2058
                code.emitop0(dup_x1 + 3 * (l.width() - 1));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2059
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2060
06bc494ca11e Initial load
duke
parents:
diff changeset
  2061
            // Load first string and append to buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2062
            l.load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2063
            appendString(tree.lhs);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2064
06bc494ca11e Initial load
duke
parents:
diff changeset
  2065
            // Append all other strings to buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2066
            appendStrings(tree.rhs);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2067
06bc494ca11e Initial load
duke
parents:
diff changeset
  2068
            // Convert buffer to string.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2069
            bufferToString(tree.pos());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2070
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2071
            // Generate code for first expression
06bc494ca11e Initial load
duke
parents:
diff changeset
  2072
            l = genExpr(tree.lhs, tree.lhs.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2073
06bc494ca11e Initial load
duke
parents:
diff changeset
  2074
            // If we have an increment of -32768 to +32767 of a local
06bc494ca11e Initial load
duke
parents:
diff changeset
  2075
            // int variable we can use an incr instruction instead of
06bc494ca11e Initial load
duke
parents:
diff changeset
  2076
            // proceeding further.
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  2077
            if ((tree.hasTag(PLUS_ASG) || tree.hasTag(MINUS_ASG)) &&
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2078
                l instanceof LocalItem &&
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
  2079
                tree.lhs.type.getTag().isSubRangeOf(INT) &&
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
  2080
                tree.rhs.type.getTag().isSubRangeOf(INT) &&
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2081
                tree.rhs.type.constValue() != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2082
                int ival = ((Number) tree.rhs.type.constValue()).intValue();
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  2083
                if (tree.hasTag(MINUS_ASG)) ival = -ival;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2084
                ((LocalItem)l).incr(ival);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2085
                result = l;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2086
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2087
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2088
            // Otherwise, duplicate expression, load one copy
06bc494ca11e Initial load
duke
parents:
diff changeset
  2089
            // and complete binary operation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2090
            l.duplicate();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2091
            l.coerce(operator.type.getParameterTypes().head).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2092
            completeBinop(tree.lhs, tree.rhs, operator).coerce(tree.lhs.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2093
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2094
        result = items.makeAssignItem(l);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2095
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2096
06bc494ca11e Initial load
duke
parents:
diff changeset
  2097
    public void visitUnary(JCUnary tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2098
        OperatorSymbol operator = (OperatorSymbol)tree.operator;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  2099
        if (tree.hasTag(NOT)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2100
            CondItem od = genCond(tree.arg, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2101
            result = od.negate();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2102
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2103
            Item od = genExpr(tree.arg, operator.type.getParameterTypes().head);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2104
            switch (tree.getTag()) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  2105
            case POS:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2106
                result = od.load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2107
                break;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  2108
            case NEG:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2109
                result = od.load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2110
                code.emitop0(operator.opcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2111
                break;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  2112
            case COMPL:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2113
                result = od.load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2114
                emitMinusOne(od.typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2115
                code.emitop0(operator.opcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2116
                break;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  2117
            case PREINC: case PREDEC:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2118
                od.duplicate();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2119
                if (od instanceof LocalItem &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  2120
                    (operator.opcode == iadd || operator.opcode == isub)) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  2121
                    ((LocalItem)od).incr(tree.hasTag(PREINC) ? 1 : -1);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2122
                    result = od;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2123
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2124
                    od.load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2125
                    code.emitop0(one(od.typecode));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2126
                    code.emitop0(operator.opcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2127
                    // Perform narrowing primitive conversion if byte,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2128
                    // char, or short.  Fix for 4304655.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2129
                    if (od.typecode != INTcode &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  2130
                        Code.truncate(od.typecode) == INTcode)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2131
                      code.emitop0(int2byte + od.typecode - BYTEcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2132
                    result = items.makeAssignItem(od);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2133
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2134
                break;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  2135
            case POSTINC: case POSTDEC:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2136
                od.duplicate();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2137
                if (od instanceof LocalItem &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  2138
                    (operator.opcode == iadd || operator.opcode == isub)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2139
                    Item res = od.load();
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  2140
                    ((LocalItem)od).incr(tree.hasTag(POSTINC) ? 1 : -1);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2141
                    result = res;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2142
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2143
                    Item res = od.load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2144
                    od.stash(od.typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2145
                    code.emitop0(one(od.typecode));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2146
                    code.emitop0(operator.opcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2147
                    // Perform narrowing primitive conversion if byte,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2148
                    // char, or short.  Fix for 4304655.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2149
                    if (od.typecode != INTcode &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  2150
                        Code.truncate(od.typecode) == INTcode)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2151
                      code.emitop0(int2byte + od.typecode - BYTEcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2152
                    od.store();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2153
                    result = res;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2154
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2155
                break;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  2156
            case NULLCHK:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2157
                result = od.load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2158
                code.emitop0(dup);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2159
                genNullCheck(tree.pos());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2160
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2161
            default:
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  2162
                Assert.error();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2163
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2164
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2165
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2166
06bc494ca11e Initial load
duke
parents:
diff changeset
  2167
    /** Generate a null check from the object value at stack top. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2168
    private void genNullCheck(DiagnosticPosition pos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2169
        callMethod(pos, syms.objectType, names.getClass,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2170
                   List.<Type>nil(), false);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2171
        code.emitop0(pop);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2172
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2173
06bc494ca11e Initial load
duke
parents:
diff changeset
  2174
    public void visitBinary(JCBinary tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2175
        OperatorSymbol operator = (OperatorSymbol)tree.operator;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2176
        if (operator.opcode == string_add) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2177
            // Create a string buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2178
            makeStringBuffer(tree.pos());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2179
            // Append all strings to buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2180
            appendStrings(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2181
            // Convert buffer to string.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2182
            bufferToString(tree.pos());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2183
            result = items.makeStackItem(syms.stringType);
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  2184
        } else if (tree.hasTag(AND)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2185
            CondItem lcond = genCond(tree.lhs, CRT_FLOW_CONTROLLER);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2186
            if (!lcond.isFalse()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2187
                Chain falseJumps = lcond.jumpFalse();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2188
                code.resolve(lcond.trueJumps);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2189
                CondItem rcond = genCond(tree.rhs, CRT_FLOW_TARGET);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2190
                result = items.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2191
                    makeCondItem(rcond.opcode,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2192
                                 rcond.trueJumps,
5004
6c2694dc2da0 6929544: langtools source code uses statics qualified by instance variables
jjg
parents: 4875
diff changeset
  2193
                                 Code.mergeChains(falseJumps,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2194
                                                  rcond.falseJumps));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2195
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2196
                result = lcond;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2197
            }
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  2198
        } else if (tree.hasTag(OR)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2199
            CondItem lcond = genCond(tree.lhs, CRT_FLOW_CONTROLLER);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2200
            if (!lcond.isTrue()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2201
                Chain trueJumps = lcond.jumpTrue();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2202
                code.resolve(lcond.falseJumps);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2203
                CondItem rcond = genCond(tree.rhs, CRT_FLOW_TARGET);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2204
                result = items.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2205
                    makeCondItem(rcond.opcode,
5004
6c2694dc2da0 6929544: langtools source code uses statics qualified by instance variables
jjg
parents: 4875
diff changeset
  2206
                                 Code.mergeChains(trueJumps, rcond.trueJumps),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2207
                                 rcond.falseJumps);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2208
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2209
                result = lcond;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2210
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2211
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2212
            Item od = genExpr(tree.lhs, operator.type.getParameterTypes().head);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2213
            od.load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2214
            result = completeBinop(tree.lhs, tree.rhs, operator);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2215
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2216
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2217
//where
06bc494ca11e Initial load
duke
parents:
diff changeset
  2218
        /** Make a new string buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2219
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2220
        void makeStringBuffer(DiagnosticPosition pos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2221
            code.emitop2(new_, makeRef(pos, stringBufferType));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2222
            code.emitop0(dup);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2223
            callMethod(
06bc494ca11e Initial load
duke
parents:
diff changeset
  2224
                pos, stringBufferType, names.init, List.<Type>nil(), false);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2225
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2226
06bc494ca11e Initial load
duke
parents:
diff changeset
  2227
        /** Append value (on tos) to string buffer (on tos - 1).
06bc494ca11e Initial load
duke
parents:
diff changeset
  2228
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2229
        void appendString(JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2230
            Type t = tree.type.baseType();
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
  2231
            if (!t.isPrimitive() && t.tsym != syms.stringType.tsym) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2232
                t = syms.objectType;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2233
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2234
            items.makeMemberItem(getStringBufferAppend(tree, t), false).invoke();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2235
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2236
        Symbol getStringBufferAppend(JCTree tree, Type t) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  2237
            Assert.checkNull(t.constValue());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2238
            Symbol method = stringBufferAppend.get(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2239
            if (method == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2240
                method = rs.resolveInternalMethod(tree.pos(),
06bc494ca11e Initial load
duke
parents:
diff changeset
  2241
                                                  attrEnv,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2242
                                                  stringBufferType,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2243
                                                  names.append,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2244
                                                  List.of(t),
06bc494ca11e Initial load
duke
parents:
diff changeset
  2245
                                                  null);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2246
                stringBufferAppend.put(t, method);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2247
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2248
            return method;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2249
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2250
06bc494ca11e Initial load
duke
parents:
diff changeset
  2251
        /** Add all strings in tree to string buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2252
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2253
        void appendStrings(JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2254
            tree = TreeInfo.skipParens(tree);
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  2255
            if (tree.hasTag(PLUS) && tree.type.constValue() == null) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2256
                JCBinary op = (JCBinary) tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2257
                if (op.operator.kind == MTH &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  2258
                    ((OperatorSymbol) op.operator).opcode == string_add) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2259
                    appendStrings(op.lhs);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2260
                    appendStrings(op.rhs);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2261
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2262
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2263
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2264
            genExpr(tree, tree.type).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2265
            appendString(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2266
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2267
06bc494ca11e Initial load
duke
parents:
diff changeset
  2268
        /** Convert string buffer on tos to string.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2269
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2270
        void bufferToString(DiagnosticPosition pos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2271
            callMethod(
06bc494ca11e Initial load
duke
parents:
diff changeset
  2272
                pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2273
                stringBufferType,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2274
                names.toString,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2275
                List.<Type>nil(),
06bc494ca11e Initial load
duke
parents:
diff changeset
  2276
                false);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2277
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2278
06bc494ca11e Initial load
duke
parents:
diff changeset
  2279
        /** Complete generating code for operation, with left operand
06bc494ca11e Initial load
duke
parents:
diff changeset
  2280
         *  already on stack.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2281
         *  @param lhs       The tree representing the left operand.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2282
         *  @param rhs       The tree representing the right operand.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2283
         *  @param operator  The operator symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2284
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2285
        Item completeBinop(JCTree lhs, JCTree rhs, OperatorSymbol operator) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2286
            MethodType optype = (MethodType)operator.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2287
            int opcode = operator.opcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2288
            if (opcode >= if_icmpeq && opcode <= if_icmple &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  2289
                rhs.type.constValue() instanceof Number &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  2290
                ((Number) rhs.type.constValue()).intValue() == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2291
                opcode = opcode + (ifeq - if_icmpeq);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2292
            } else if (opcode >= if_acmpeq && opcode <= if_acmpne &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  2293
                       TreeInfo.isNull(rhs)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2294
                opcode = opcode + (if_acmp_null - if_acmpeq);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2295
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2296
                // The expected type of the right operand is
06bc494ca11e Initial load
duke
parents:
diff changeset
  2297
                // the second parameter type of the operator, except for
06bc494ca11e Initial load
duke
parents:
diff changeset
  2298
                // shifts with long shiftcount, where we convert the opcode
06bc494ca11e Initial load
duke
parents:
diff changeset
  2299
                // to a short shift and the expected type to int.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2300
                Type rtype = operator.erasure(types).getParameterTypes().tail.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2301
                if (opcode >= ishll && opcode <= lushrl) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2302
                    opcode = opcode + (ishl - ishll);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2303
                    rtype = syms.intType;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2304
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2305
                // Generate code for right operand and load.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2306
                genExpr(rhs, rtype).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2307
                // If there are two consecutive opcode instructions,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2308
                // emit the first now.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2309
                if (opcode >= (1 << preShift)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2310
                    code.emitop0(opcode >> preShift);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2311
                    opcode = opcode & 0xFF;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2312
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2313
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2314
            if (opcode >= ifeq && opcode <= if_acmpne ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  2315
                opcode == if_acmp_null || opcode == if_acmp_nonnull) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2316
                return items.makeCondItem(opcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2317
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2318
                code.emitop0(opcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2319
                return items.makeStackItem(optype.restype);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2320
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2321
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2322
06bc494ca11e Initial load
duke
parents:
diff changeset
  2323
    public void visitTypeCast(JCTypeCast tree) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  2324
        setTypeAnnotationPositions(tree.pos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2325
        result = genExpr(tree.expr, tree.clazz.type).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2326
        // Additional code is only needed if we cast to a reference type
06bc494ca11e Initial load
duke
parents:
diff changeset
  2327
        // which is not statically a supertype of the expression's type.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2328
        // For basic types, the coerce(...) in genExpr(...) will do
06bc494ca11e Initial load
duke
parents:
diff changeset
  2329
        // the conversion.
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
  2330
        if (!tree.clazz.type.isPrimitive() &&
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2331
            types.asSuper(tree.expr.type, tree.clazz.type.tsym) == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2332
            code.emitop2(checkcast, makeRef(tree.pos(), tree.clazz.type));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2333
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2334
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2335
06bc494ca11e Initial load
duke
parents:
diff changeset
  2336
    public void visitWildcard(JCWildcard tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2337
        throw new AssertionError(this.getClass().getName());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2338
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2339
06bc494ca11e Initial load
duke
parents:
diff changeset
  2340
    public void visitTypeTest(JCInstanceOf tree) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  2341
        setTypeAnnotationPositions(tree.pos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2342
        genExpr(tree.expr, tree.expr.type).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2343
        code.emitop2(instanceof_, makeRef(tree.pos(), tree.clazz.type));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2344
        result = items.makeStackItem(syms.booleanType);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2345
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2346
06bc494ca11e Initial load
duke
parents:
diff changeset
  2347
    public void visitIndexed(JCArrayAccess tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2348
        genExpr(tree.indexed, tree.indexed.type).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2349
        genExpr(tree.index, syms.intType).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2350
        result = items.makeIndexedItem(tree.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2351
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2352
06bc494ca11e Initial load
duke
parents:
diff changeset
  2353
    public void visitIdent(JCIdent tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2354
        Symbol sym = tree.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2355
        if (tree.name == names._this || tree.name == names._super) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2356
            Item res = tree.name == names._this
06bc494ca11e Initial load
duke
parents:
diff changeset
  2357
                ? items.makeThisItem()
06bc494ca11e Initial load
duke
parents:
diff changeset
  2358
                : items.makeSuperItem();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2359
            if (sym.kind == MTH) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2360
                // Generate code to address the constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2361
                res.load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2362
                res = items.makeMemberItem(sym, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2363
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2364
            result = res;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2365
        } else if (sym.kind == VAR && sym.owner.kind == MTH) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2366
            result = items.makeLocalItem((VarSymbol)sym);
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13844
diff changeset
  2367
        } else if (isInvokeDynamic(sym)) {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13844
diff changeset
  2368
            result = items.makeDynamicItem(sym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2369
        } else if ((sym.flags() & STATIC) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2370
            if (!isAccessSuper(env.enclMethod))
06bc494ca11e Initial load
duke
parents:
diff changeset
  2371
                sym = binaryQualifier(sym, env.enclClass.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2372
            result = items.makeStaticItem(sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2373
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2374
            items.makeThisItem().load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2375
            sym = binaryQualifier(sym, env.enclClass.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2376
            result = items.makeMemberItem(sym, (sym.flags() & PRIVATE) != 0);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2377
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2378
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2379
06bc494ca11e Initial load
duke
parents:
diff changeset
  2380
    public void visitSelect(JCFieldAccess tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2381
        Symbol sym = tree.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2382
06bc494ca11e Initial load
duke
parents:
diff changeset
  2383
        if (tree.name == names._class) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  2384
            Assert.check(target.hasClassLiterals());
16801
e2de240b437f 4965689: class literal code wastes a byte
vromero
parents: 15710
diff changeset
  2385
            code.emitLdc(makeRef(tree.pos(), tree.selected.type));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2386
            result = items.makeStackItem(pt);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2387
            return;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  2388
       }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2389
06bc494ca11e Initial load
duke
parents:
diff changeset
  2390
        Symbol ssym = TreeInfo.symbol(tree.selected);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2391
06bc494ca11e Initial load
duke
parents:
diff changeset
  2392
        // Are we selecting via super?
06bc494ca11e Initial load
duke
parents:
diff changeset
  2393
        boolean selectSuper =
06bc494ca11e Initial load
duke
parents:
diff changeset
  2394
            ssym != null && (ssym.kind == TYP || ssym.name == names._super);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2395
06bc494ca11e Initial load
duke
parents:
diff changeset
  2396
        // Are we accessing a member of the superclass in an access method
06bc494ca11e Initial load
duke
parents:
diff changeset
  2397
        // resulting from a qualified super?
06bc494ca11e Initial load
duke
parents:
diff changeset
  2398
        boolean accessSuper = isAccessSuper(env.enclMethod);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2399
06bc494ca11e Initial load
duke
parents:
diff changeset
  2400
        Item base = (selectSuper)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2401
            ? items.makeSuperItem()
06bc494ca11e Initial load
duke
parents:
diff changeset
  2402
            : genExpr(tree.selected, tree.selected.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2403
06bc494ca11e Initial load
duke
parents:
diff changeset
  2404
        if (sym.kind == VAR && ((VarSymbol) sym).getConstValue() != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2405
            // We are seeing a variable that is constant but its selecting
06bc494ca11e Initial load
duke
parents:
diff changeset
  2406
            // expression is not.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2407
            if ((sym.flags() & STATIC) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2408
                if (!selectSuper && (ssym == null || ssym.kind != TYP))
06bc494ca11e Initial load
duke
parents:
diff changeset
  2409
                    base = base.load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2410
                base.drop();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2411
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2412
                base.load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2413
                genNullCheck(tree.selected.pos());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2414
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2415
            result = items.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2416
                makeImmediateItem(sym.type, ((VarSymbol) sym).getConstValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2417
        } else {
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13844
diff changeset
  2418
            if (isInvokeDynamic(sym)) {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13844
diff changeset
  2419
                result = items.makeDynamicItem(sym);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13844
diff changeset
  2420
                return;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13844
diff changeset
  2421
            } else if (!accessSuper) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2422
                sym = binaryQualifier(sym, tree.selected.type);
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13844
diff changeset
  2423
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2424
            if ((sym.flags() & STATIC) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2425
                if (!selectSuper && (ssym == null || ssym.kind != TYP))
06bc494ca11e Initial load
duke
parents:
diff changeset
  2426
                    base = base.load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2427
                base.drop();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2428
                result = items.makeStaticItem(sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2429
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2430
                base.load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2431
                if (sym == syms.lengthVar) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2432
                    code.emitop0(arraylength);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2433
                    result = items.makeStackItem(syms.intType);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2434
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2435
                    result = items.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2436
                        makeMemberItem(sym,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2437
                                       (sym.flags() & PRIVATE) != 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  2438
                                       selectSuper || accessSuper);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2439
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2440
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2441
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2442
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2443
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13844
diff changeset
  2444
    public boolean isInvokeDynamic(Symbol sym) {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13844
diff changeset
  2445
        return sym.kind == MTH && ((MethodSymbol)sym).isDynamic();
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13844
diff changeset
  2446
    }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13844
diff changeset
  2447
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2448
    public void visitLiteral(JCLiteral tree) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
  2449
        if (tree.type.hasTag(BOT)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2450
            code.emitop0(aconst_null);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2451
            if (types.dimensions(pt) > 1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2452
                code.emitop2(checkcast, makeRef(tree.pos(), pt));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2453
                result = items.makeStackItem(pt);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2454
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2455
                result = items.makeStackItem(tree.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2456
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2457
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2458
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
  2459
            result = items.makeImmediateItem(tree.type, tree.value);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2460
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2461
06bc494ca11e Initial load
duke
parents:
diff changeset
  2462
    public void visitLetExpr(LetExpr tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2463
        int limit = code.nextreg;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2464
        genStats(tree.defs, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2465
        result = genExpr(tree.expr, tree.expr.type).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2466
        code.endScopes(limit);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2467
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2468
14721
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
  2469
    private void generateReferencesToPrunedTree(ClassSymbol classSymbol, Pool pool) {
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
  2470
        List<JCTree> prunedInfo = lower.prunedTree.get(classSymbol);
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
  2471
        if (prunedInfo != null) {
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
  2472
            for (JCTree prunedTree: prunedInfo) {
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
  2473
                prunedTree.accept(classReferenceVisitor);
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
  2474
            }
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
  2475
        }
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
  2476
    }
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
  2477
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2478
/* ************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  2479
 * main method
06bc494ca11e Initial load
duke
parents:
diff changeset
  2480
 *************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  2481
06bc494ca11e Initial load
duke
parents:
diff changeset
  2482
    /** Generate code for a class definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2483
     *  @param env   The attribution environment that belongs to the
06bc494ca11e Initial load
duke
parents:
diff changeset
  2484
     *               outermost class containing this class definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2485
     *               We need this for resolving some additional symbols.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2486
     *  @param cdef  The tree representing the class definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2487
     *  @return      True if code is generated with no errors.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2488
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2489
    public boolean genClass(Env<AttrContext> env, JCClassDecl cdef) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2490
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2491
            attrEnv = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2492
            ClassSymbol c = cdef.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2493
            this.toplevel = env.toplevel;
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  2494
            this.endPosTable = toplevel.endPositions;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2495
            // If this is a class definition requiring Miranda methods,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2496
            // add them.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2497
            if (generateIproxies &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  2498
                (c.flags() & (INTERFACE|ABSTRACT)) == ABSTRACT
06bc494ca11e Initial load
duke
parents:
diff changeset
  2499
                && !allowGenerics // no Miranda methods available with generics
06bc494ca11e Initial load
duke
parents:
diff changeset
  2500
                )
06bc494ca11e Initial load
duke
parents:
diff changeset
  2501
                implementInterfaceMethods(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2502
            cdef.defs = normalizeDefs(cdef.defs, c);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2503
            c.pool = pool;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2504
            pool.reset();
14721
071e3587f212 7153958: add constant pool reference to class containing inlined constants
vromero
parents: 14359
diff changeset
  2505
            generateReferencesToPrunedTree(c, pool);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2506
            Env<GenContext> localEnv =
06bc494ca11e Initial load
duke
parents:
diff changeset
  2507
                new Env<GenContext>(cdef, new GenContext());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2508
            localEnv.toplevel = env.toplevel;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2509
            localEnv.enclClass = cdef;
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2510
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2511
            /*  We must not analyze synthetic methods
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2512
             */
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2513
            if (varDebugInfo && (cdef.sym.flags() & SYNTHETIC) == 0) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2514
                try {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2515
                    LVTAssignAnalyzer lvtAssignAnalyzer = LVTAssignAnalyzer.make(
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2516
                            lvtRanges, syms, names);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2517
                    lvtAssignAnalyzer.analyzeTree(localEnv);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2518
                } catch (Throwable e) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2519
                    throw e;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2520
                }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2521
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2522
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2523
            for (List<JCTree> l = cdef.defs; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2524
                genDef(l.head, localEnv);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2525
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2526
            if (pool.numEntries() > Pool.MAX_ENTRIES) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2527
                log.error(cdef.pos(), "limit.pool");
06bc494ca11e Initial load
duke
parents:
diff changeset
  2528
                nerrs++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2529
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2530
            if (nerrs != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2531
                // if errors, discard code
06bc494ca11e Initial load
duke
parents:
diff changeset
  2532
                for (List<JCTree> l = cdef.defs; l.nonEmpty(); l = l.tail) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10811
diff changeset
  2533
                    if (l.head.hasTag(METHODDEF))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2534
                        ((JCMethodDecl) l.head).sym.code = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2535
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2536
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2537
            cdef.defs = List.nil(); // discard trees
06bc494ca11e Initial load
duke
parents:
diff changeset
  2538
            return nerrs == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2539
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2540
            // note: this method does NOT support recursion.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2541
            attrEnv = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2542
            this.env = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2543
            toplevel = null;
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  2544
            endPosTable = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2545
            nerrs = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2546
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2547
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2548
06bc494ca11e Initial load
duke
parents:
diff changeset
  2549
/* ************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  2550
 * Auxiliary classes
06bc494ca11e Initial load
duke
parents:
diff changeset
  2551
 *************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  2552
06bc494ca11e Initial load
duke
parents:
diff changeset
  2553
    /** An abstract class for finalizer generation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2554
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2555
    abstract class GenFinalizer {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2556
        /** Generate code to clean up when unwinding. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2557
        abstract void gen();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2558
06bc494ca11e Initial load
duke
parents:
diff changeset
  2559
        /** Generate code to clean up at last. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2560
        abstract void genLast();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2561
06bc494ca11e Initial load
duke
parents:
diff changeset
  2562
        /** Does this finalizer have some nontrivial cleanup to perform? */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2563
        boolean hasFinalizer() { return true; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2564
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2565
06bc494ca11e Initial load
duke
parents:
diff changeset
  2566
    /** code generation contexts,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2567
     *  to be used as type parameter for environments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2568
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2569
    static class GenContext {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2570
06bc494ca11e Initial load
duke
parents:
diff changeset
  2571
        /** A chain for all unresolved jumps that exit the current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2572
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2573
        Chain exit = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2574
06bc494ca11e Initial load
duke
parents:
diff changeset
  2575
        /** A chain for all unresolved jumps that continue in the
06bc494ca11e Initial load
duke
parents:
diff changeset
  2576
         *  current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2577
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2578
        Chain cont = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2579
06bc494ca11e Initial load
duke
parents:
diff changeset
  2580
        /** A closure that generates the finalizer of the current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2581
         *  Only set for Synchronized and Try contexts.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2582
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2583
        GenFinalizer finalize = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2584
06bc494ca11e Initial load
duke
parents:
diff changeset
  2585
        /** Is this a switch statement?  If so, allocate registers
06bc494ca11e Initial load
duke
parents:
diff changeset
  2586
         * even when the variable declaration is unreachable.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2587
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2588
        boolean isSwitch = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2589
06bc494ca11e Initial load
duke
parents:
diff changeset
  2590
        /** A list buffer containing all gaps in the finalizer range,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2591
         *  where a catch all exception should not apply.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2592
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2593
        ListBuffer<Integer> gaps = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2594
06bc494ca11e Initial load
duke
parents:
diff changeset
  2595
        /** Add given chain to exit chain.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2596
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2597
        void addExit(Chain c)  {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2598
            exit = Code.mergeChains(c, exit);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2599
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2600
06bc494ca11e Initial load
duke
parents:
diff changeset
  2601
        /** Add given chain to cont chain.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2602
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2603
        void addCont(Chain c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2604
            cont = Code.mergeChains(c, cont);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2605
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2606
    }
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2607
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2608
    static class LVTAssignAnalyzer
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2609
        extends Flow.AbstractAssignAnalyzer<LVTAssignAnalyzer.LVTAssignPendingExit> {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2610
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2611
        final LVTBits lvtInits;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2612
        final LVTRanges lvtRanges;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2613
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2614
        /*  This class is anchored to a context dependent tree. The tree can
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2615
         *  vary inside the same instruction for example in the switch instruction
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2616
         *  the same FlowBits instance can be anchored to the whole tree, or
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2617
         *  to a given case. The aim is to always anchor the bits to the tree
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2618
         *  capable of closing a DA range.
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2619
         */
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2620
        static class LVTBits extends Bits {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2621
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2622
            enum BitsOpKind {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2623
                INIT,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2624
                CLEAR,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2625
                INCL_BIT,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2626
                EXCL_BIT,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2627
                ASSIGN,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2628
                AND_SET,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2629
                OR_SET,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2630
                DIFF_SET,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2631
                XOR_SET,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2632
                INCL_RANGE,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2633
                EXCL_RANGE,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2634
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2635
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2636
            JCTree currentTree;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2637
            LVTAssignAnalyzer analyzer;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2638
            private int[] oldBits = null;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2639
            BitsState stateBeforeOp;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2640
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2641
            LVTBits() {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2642
                super(false);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2643
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2644
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2645
            LVTBits(int[] bits, BitsState initState) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2646
                super(bits, initState);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2647
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2648
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2649
            @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2650
            public void clear() {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2651
                generalOp(null, -1, BitsOpKind.CLEAR);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2652
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2653
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2654
            @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2655
            protected void internalReset() {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2656
                super.internalReset();
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2657
                oldBits = null;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2658
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2659
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2660
            @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2661
            public Bits assign(Bits someBits) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2662
                // bits can be null
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2663
                oldBits = bits;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2664
                stateBeforeOp = currentState;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2665
                super.assign(someBits);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2666
                changed();
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2667
                return this;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2668
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2669
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2670
            @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2671
            public void excludeFrom(int start) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2672
                generalOp(null, start, BitsOpKind.EXCL_RANGE);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2673
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2674
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2675
            @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2676
            public void excl(int x) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2677
                Assert.check(x >= 0);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2678
                generalOp(null, x, BitsOpKind.EXCL_BIT);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2679
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2680
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2681
            @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2682
            public Bits andSet(Bits xs) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2683
               return generalOp(xs, -1, BitsOpKind.AND_SET);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2684
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2685
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2686
            @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2687
            public Bits orSet(Bits xs) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2688
                return generalOp(xs, -1, BitsOpKind.OR_SET);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2689
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2690
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2691
            @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2692
            public Bits diffSet(Bits xs) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2693
                return generalOp(xs, -1, BitsOpKind.DIFF_SET);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2694
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2695
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2696
            @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2697
            public Bits xorSet(Bits xs) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2698
                return generalOp(xs, -1, BitsOpKind.XOR_SET);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2699
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2700
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2701
            private Bits generalOp(Bits xs, int i, BitsOpKind opKind) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2702
                Assert.check(currentState != BitsState.UNKNOWN);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2703
                oldBits = dupBits();
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2704
                stateBeforeOp = currentState;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2705
                switch (opKind) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2706
                    case AND_SET:
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2707
                        super.andSet(xs);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2708
                        break;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2709
                    case OR_SET:
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2710
                        super.orSet(xs);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2711
                        break;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2712
                    case XOR_SET:
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2713
                        super.xorSet(xs);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2714
                        break;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2715
                    case DIFF_SET:
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2716
                        super.diffSet(xs);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2717
                        break;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2718
                    case CLEAR:
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2719
                        super.clear();
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2720
                        break;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2721
                    case EXCL_BIT:
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2722
                        super.excl(i);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2723
                        break;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2724
                    case EXCL_RANGE:
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2725
                        super.excludeFrom(i);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2726
                        break;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2727
                }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2728
                changed();
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2729
                return this;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2730
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2731
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2732
            /*  The tree we need to anchor the bits instance to.
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2733
             */
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2734
            LVTBits at(JCTree tree) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2735
                this.currentTree = tree;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2736
                return this;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2737
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2738
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2739
            /*  If the instance should be changed but the tree is not a closing
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2740
             *  tree then a reset is needed or the former tree can mistakingly be
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2741
             *  used.
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2742
             */
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2743
            LVTBits resetTree() {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2744
                this.currentTree = null;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2745
                return this;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2746
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2747
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2748
            /** This method will be called after any operation that causes a change to
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2749
             *  the bits. Subclasses can thus override it in order to extract information
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2750
             *  from the changes produced to the bits by the given operation.
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2751
             */
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2752
            public void changed() {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2753
                if (currentTree != null &&
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2754
                        stateBeforeOp != BitsState.UNKNOWN &&
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2755
                        trackTree(currentTree)) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2756
                    List<VarSymbol> locals =
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2757
                            analyzer.lvtRanges
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2758
                            .getVars(analyzer.currentMethod, currentTree);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2759
                    locals = locals != null ?
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2760
                            locals : List.<VarSymbol>nil();
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2761
                    for (JCVariableDecl vardecl : analyzer.vardecls) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2762
                        //once the first is null, the rest will be so.
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2763
                        if (vardecl == null) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2764
                            break;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2765
                        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2766
                        if (trackVar(vardecl.sym) && bitChanged(vardecl.sym.adr)) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2767
                            locals = locals.prepend(vardecl.sym);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2768
                        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2769
                    }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2770
                    if (!locals.isEmpty()) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2771
                        analyzer.lvtRanges.setEntry(analyzer.currentMethod,
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2772
                                currentTree, locals);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2773
                    }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2774
                }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2775
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2776
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2777
            boolean bitChanged(int x) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2778
                boolean isMemberOfBits = isMember(x);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2779
                int[] tmp = bits;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2780
                bits = oldBits;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2781
                boolean isMemberOfOldBits = isMember(x);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2782
                bits = tmp;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2783
                return (!isMemberOfBits && isMemberOfOldBits);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2784
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2785
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2786
            boolean trackVar(VarSymbol var) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2787
                return (var.owner.kind == MTH &&
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2788
                        (var.flags() & (PARAMETER | HASINIT)) == 0 &&
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2789
                        analyzer.trackable(var));
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2790
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2791
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2792
            boolean trackTree(JCTree tree) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2793
                switch (tree.getTag()) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2794
                    // of course a method closes the alive range of a local variable.
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2795
                    case METHODDEF:
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2796
                    // for while loops we want only the body
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2797
                    case WHILELOOP:
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2798
                        return false;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2799
                }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2800
                return true;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2801
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2802
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2803
        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2804
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2805
        public class LVTAssignPendingExit extends Flow.AssignAnalyzer.AssignPendingExit {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2806
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2807
            LVTAssignPendingExit(JCTree tree, final Bits inits, final Bits uninits) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2808
                super(tree, inits, uninits);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2809
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2810
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2811
            @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2812
            public void resolveJump(JCTree tree) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2813
                lvtInits.at(tree);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2814
                super.resolveJump(tree);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2815
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2816
        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2817
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2818
        private LVTAssignAnalyzer(LVTRanges lvtRanges, Symtab syms, Names names) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2819
            super(new LVTBits(), syms, names);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2820
            lvtInits = (LVTBits)inits;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2821
            this.lvtRanges = lvtRanges;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2822
        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2823
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2824
        public static LVTAssignAnalyzer make(LVTRanges lvtRanges, Symtab syms, Names names) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2825
            LVTAssignAnalyzer result = new LVTAssignAnalyzer(lvtRanges, syms, names);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2826
            result.lvtInits.analyzer = result;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2827
            return result;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2828
        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2829
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2830
        @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2831
        protected void markDead(JCTree tree) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2832
            lvtInits.at(tree).inclRange(returnadr, nextadr);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2833
            super.markDead(tree);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2834
        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2835
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2836
        @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2837
        protected void merge(JCTree tree) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2838
            lvtInits.at(tree);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2839
            super.merge(tree);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2840
        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2841
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2842
        boolean isSyntheticOrMandated(Symbol sym) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2843
            return (sym.flags() & (SYNTHETIC | MANDATED)) != 0;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2844
        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2845
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2846
        @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2847
        protected boolean trackable(VarSymbol sym) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2848
            if (isSyntheticOrMandated(sym)) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2849
                //fast check to avoid tracking synthetic or mandated variables
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2850
                return false;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2851
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2852
            return super.trackable(sym);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2853
        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2854
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2855
        @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2856
        protected void initParam(JCVariableDecl def) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2857
            if (!isSyntheticOrMandated(def.sym)) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2858
                super.initParam(def);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2859
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2860
        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2861
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2862
        @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2863
        protected void assignToInits(JCTree tree, Bits bits) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2864
            lvtInits.at(tree);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2865
            lvtInits.assign(bits);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2866
        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2867
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2868
        @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2869
        protected void andSetInits(JCTree tree, Bits bits) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2870
            lvtInits.at(tree);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2871
            lvtInits.andSet(bits);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2872
        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2873
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2874
        @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2875
        protected void orSetInits(JCTree tree, Bits bits) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2876
            lvtInits.at(tree);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2877
            lvtInits.orSet(bits);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2878
        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2879
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2880
        @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2881
        protected void exclVarFromInits(JCTree tree, int adr) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2882
            lvtInits.at(tree);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2883
            lvtInits.excl(adr);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2884
        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2885
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2886
        @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2887
        protected LVTAssignPendingExit createNewPendingExit(JCTree tree, Bits inits, Bits uninits) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2888
            return new LVTAssignPendingExit(tree, inits, uninits);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2889
        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2890
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2891
        MethodSymbol currentMethod;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2892
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2893
        @Override
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2894
        public void visitMethodDef(JCMethodDecl tree) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2895
            if ((tree.sym.flags() & (SYNTHETIC | GENERATEDCONSTR)) != 0) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2896
                return;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2897
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2898
            if (tree.name.equals(names.clinit)) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2899
                return;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2900
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2901
            boolean enumClass = (tree.sym.owner.flags() & ENUM) != 0;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2902
            if (enumClass &&
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2903
                    (tree.name.equals(names.valueOf) ||
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2904
                    tree.name.equals(names.values) ||
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2905
                    tree.name.equals(names.init))) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2906
                return;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2907
            }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2908
            currentMethod = tree.sym;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2909
            super.visitMethodDef(tree);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2910
        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2911
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2912
    }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19923
diff changeset
  2913
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2914
}