author | chegar |
Thu, 17 Oct 2019 20:53:35 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58678 | 9cf78a70fa4f |
parent 54894 | 382101e97784 |
child 58679 | 9c3209ff7550 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
54762 | 2 |
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
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 |
|
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
28 |
import com.sun.tools.javac.jvm.PoolConstant.LoadableConstant; |
45220 | 29 |
import com.sun.tools.javac.tree.TreeInfo.PosKind; |
10 | 30 |
import com.sun.tools.javac.util.*; |
31 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
|
32 |
import com.sun.tools.javac.util.List; |
|
33 |
import com.sun.tools.javac.code.*; |
|
17578 | 34 |
import com.sun.tools.javac.code.Attribute.TypeCompound; |
35 |
import com.sun.tools.javac.code.Symbol.VarSymbol; |
|
10 | 36 |
import com.sun.tools.javac.comp.*; |
37 |
import com.sun.tools.javac.tree.*; |
|
38 |
||
39 |
import com.sun.tools.javac.code.Symbol.*; |
|
40 |
import com.sun.tools.javac.code.Type.*; |
|
41 |
import com.sun.tools.javac.jvm.Code.*; |
|
42 |
import com.sun.tools.javac.jvm.Items.*; |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45316
diff
changeset
|
43 |
import com.sun.tools.javac.resources.CompilerProperties.Errors; |
13077 | 44 |
import com.sun.tools.javac.tree.EndPosTable; |
10 | 45 |
import com.sun.tools.javac.tree.JCTree.*; |
46 |
||
47 |
import static com.sun.tools.javac.code.Flags.*; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
27123
diff
changeset
|
48 |
import static com.sun.tools.javac.code.Kinds.Kind.*; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
49 |
import static com.sun.tools.javac.code.TypeTag.*; |
10 | 50 |
import static com.sun.tools.javac.jvm.ByteCodes.*; |
51 |
import static com.sun.tools.javac.jvm.CRTFlags.*; |
|
11314 | 52 |
import static com.sun.tools.javac.main.Option.*; |
10950 | 53 |
import static com.sun.tools.javac.tree.JCTree.Tag.*; |
10 | 54 |
|
55 |
/** This pass maps flat Java (i.e. without inner classes) to bytecodes. |
|
56 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
57 |
* <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
|
58 |
* If you write code that depends on this, you do so at your own risk. |
10 | 59 |
* This code and its internal interfaces are subject to change or |
60 |
* deletion without notice.</b> |
|
61 |
*/ |
|
62 |
public class Gen extends JCTree.Visitor { |
|
22163 | 63 |
protected static final Context.Key<Gen> genKey = new Context.Key<>(); |
10 | 64 |
|
65 |
private final Log log; |
|
66 |
private final Symtab syms; |
|
67 |
private final Check chk; |
|
68 |
private final Resolve rs; |
|
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 | 71 |
private final Target target; |
43765
f2f8bfe6bcb5
8169200: Gen has a reference to Flow that is not used, should be removed
vromero
parents:
42828
diff
changeset
|
72 |
private final Name accessDollar; |
10 | 73 |
private final Types types; |
14721
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
74 |
private final Lower lower; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
75 |
private final Annotate annotate; |
35424 | 76 |
private final StringConcat concat; |
10 | 77 |
|
78 |
/** Format of stackmap tables to be generated. */ |
|
79 |
private final Code.StackMapFormat stackMap; |
|
80 |
||
81 |
/** A type that serves as the expected type for all method expressions. |
|
82 |
*/ |
|
83 |
private final Type methodType; |
|
84 |
||
85 |
public static Gen instance(Context context) { |
|
86 |
Gen instance = context.get(genKey); |
|
87 |
if (instance == null) |
|
88 |
instance = new Gen(context); |
|
89 |
return instance; |
|
90 |
} |
|
91 |
||
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
92 |
/** Constant pool writer, set by genClass. |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14721
diff
changeset
|
93 |
*/ |
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
94 |
final PoolWriter poolWriter; |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14721
diff
changeset
|
95 |
|
10 | 96 |
protected Gen(Context context) { |
97 |
context.put(genKey, this); |
|
98 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
99 |
names = Names.instance(context); |
10 | 100 |
log = Log.instance(context); |
101 |
syms = Symtab.instance(context); |
|
102 |
chk = Check.instance(context); |
|
103 |
rs = Resolve.instance(context); |
|
104 |
make = TreeMaker.instance(context); |
|
105 |
target = Target.instance(context); |
|
106 |
types = Types.instance(context); |
|
35424 | 107 |
concat = StringConcat.instance(context); |
108 |
||
10 | 109 |
methodType = new MethodType(null, null, null, syms.methodClass); |
110 |
accessDollar = names. |
|
111 |
fromString("access" + target.syntheticNameChar()); |
|
14721
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
112 |
lower = Lower.instance(context); |
10 | 113 |
|
114 |
Options options = Options.instance(context); |
|
115 |
lineDebugInfo = |
|
6721 | 116 |
options.isUnset(G_CUSTOM) || |
117 |
options.isSet(G_CUSTOM, "lines"); |
|
10 | 118 |
varDebugInfo = |
6721 | 119 |
options.isUnset(G_CUSTOM) |
120 |
? options.isSet(G) |
|
121 |
: options.isSet(G_CUSTOM, "vars"); |
|
122 |
genCrt = options.isSet(XJCOV); |
|
39599 | 123 |
debugCode = options.isSet("debug.code"); |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49280
diff
changeset
|
124 |
disableVirtualizedPrivateInvoke = options.isSet("disableVirtualizedPrivateInvoke"); |
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
125 |
poolWriter = new PoolWriter(types, names); |
10 | 126 |
|
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
127 |
// ignore cldc because we cannot have both stackmap formats |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
128 |
this.stackMap = StackMapFormat.JSR202; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
129 |
annotate = Annotate.instance(context); |
10 | 130 |
} |
131 |
||
132 |
/** Switches |
|
133 |
*/ |
|
134 |
private final boolean lineDebugInfo; |
|
135 |
private final boolean varDebugInfo; |
|
136 |
private final boolean genCrt; |
|
137 |
private final boolean debugCode; |
|
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49280
diff
changeset
|
138 |
private boolean disableVirtualizedPrivateInvoke; |
10 | 139 |
|
140 |
/** Code buffer, set by genMethod. |
|
141 |
*/ |
|
142 |
private Code code; |
|
143 |
||
144 |
/** Items structure, set by genMethod. |
|
145 |
*/ |
|
146 |
private Items items; |
|
147 |
||
148 |
/** Environment for symbol lookup, set by genClass |
|
149 |
*/ |
|
150 |
private Env<AttrContext> attrEnv; |
|
151 |
||
152 |
/** The top level tree. |
|
153 |
*/ |
|
154 |
private JCCompilationUnit toplevel; |
|
155 |
||
156 |
/** The number of code-gen errors in this class. |
|
157 |
*/ |
|
158 |
private int nerrs = 0; |
|
159 |
||
11055 | 160 |
/** An object containing mappings of syntax trees to their |
161 |
* ending source positions. |
|
10 | 162 |
*/ |
11055 | 163 |
EndPosTable endPosTable; |
10 | 164 |
|
52794
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
165 |
boolean inCondSwitchExpression; |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
166 |
Chain switchExpressionTrueChain; |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
167 |
Chain switchExpressionFalseChain; |
52936
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
168 |
List<LocalItem> stackBeforeSwitchExpression; |
58678 | 169 |
LocalItem switchResult; |
52794
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
170 |
|
10 | 171 |
/** Generate code to load an integer constant. |
172 |
* @param n The integer to be loaded. |
|
173 |
*/ |
|
174 |
void loadIntConst(int n) { |
|
175 |
items.makeImmediateItem(syms.intType, n).load(); |
|
176 |
} |
|
177 |
||
178 |
/** The opcode that loads a zero constant of a given type code. |
|
179 |
* @param tc The given type code (@see ByteCode). |
|
180 |
*/ |
|
181 |
public static int zero(int tc) { |
|
182 |
switch(tc) { |
|
183 |
case INTcode: case BYTEcode: case SHORTcode: case CHARcode: |
|
184 |
return iconst_0; |
|
185 |
case LONGcode: |
|
186 |
return lconst_0; |
|
187 |
case FLOATcode: |
|
188 |
return fconst_0; |
|
189 |
case DOUBLEcode: |
|
190 |
return dconst_0; |
|
191 |
default: |
|
192 |
throw new AssertionError("zero"); |
|
193 |
} |
|
194 |
} |
|
195 |
||
196 |
/** The opcode that loads a one constant of a given type code. |
|
197 |
* @param tc The given type code (@see ByteCode). |
|
198 |
*/ |
|
199 |
public static int one(int tc) { |
|
200 |
return zero(tc) + 1; |
|
201 |
} |
|
202 |
||
203 |
/** Generate code to load -1 of the given type code (either int or long). |
|
204 |
* @param tc The given type code (@see ByteCode). |
|
205 |
*/ |
|
206 |
void emitMinusOne(int tc) { |
|
207 |
if (tc == LONGcode) { |
|
37635
9834489579e5
8145468: update java.lang APIs with new deprecations
smarks
parents:
36269
diff
changeset
|
208 |
items.makeImmediateItem(syms.longType, Long.valueOf(-1)).load(); |
10 | 209 |
} else { |
210 |
code.emitop0(iconst_m1); |
|
211 |
} |
|
212 |
} |
|
213 |
||
214 |
/** Construct a symbol to reflect the qualifying type that should |
|
215 |
* appear in the byte code as per JLS 13.1. |
|
216 |
* |
|
13844 | 217 |
* For {@literal target >= 1.2}: Clone a method with the qualifier as owner (except |
10 | 218 |
* for those cases where we need to work around VM bugs). |
219 |
* |
|
13844 | 220 |
* For {@literal target <= 1.1}: If qualified variable or method is defined in a |
10 | 221 |
* non-accessible class, clone it with the qualifier class as owner. |
222 |
* |
|
223 |
* @param sym The accessed symbol |
|
224 |
* @param site The qualifier's type. |
|
225 |
*/ |
|
226 |
Symbol binaryQualifier(Symbol sym, Type site) { |
|
227 |
||
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
228 |
if (site.hasTag(ARRAY)) { |
10 | 229 |
if (sym == syms.lengthVar || |
230 |
sym.owner != syms.arrayClass) |
|
231 |
return sym; |
|
232 |
// array clone can be qualified by the array type in later targets |
|
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
233 |
Symbol qualifier = new ClassSymbol(Flags.PUBLIC, site.tsym.name, |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
234 |
site, syms.noSymbol); |
10 | 235 |
return sym.clone(qualifier); |
236 |
} |
|
237 |
||
238 |
if (sym.owner == site.tsym || |
|
239 |
(sym.flags() & (STATIC | SYNTHETIC)) == (STATIC | SYNTHETIC)) { |
|
240 |
return sym; |
|
241 |
} |
|
242 |
||
243 |
// 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
|
244 |
// JLS 13.1. |
10 | 245 |
if (sym.owner == syms.objectType.tsym) |
246 |
return sym; |
|
247 |
||
248 |
return sym.clone(site.tsym); |
|
249 |
} |
|
250 |
||
251 |
/** Insert a reference to given type in the constant pool, |
|
252 |
* checking for an array with too many dimensions; |
|
253 |
* return the reference's index. |
|
254 |
* @param type The type for which a reference is inserted. |
|
255 |
*/ |
|
256 |
int makeRef(DiagnosticPosition pos, Type type) { |
|
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
257 |
return poolWriter.putClass(checkDimension(pos, type)); |
10 | 258 |
} |
259 |
||
260 |
/** Check if the given type is an array with too many dimensions. |
|
261 |
*/ |
|
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
262 |
private Type checkDimension(DiagnosticPosition pos, Type t) { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
263 |
checkDimensionInternal(pos, t); |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
264 |
return t; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
265 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
266 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
267 |
private void checkDimensionInternal(DiagnosticPosition pos, Type t) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
268 |
switch (t.getTag()) { |
10 | 269 |
case METHOD: |
270 |
checkDimension(pos, t.getReturnType()); |
|
271 |
for (List<Type> args = t.getParameterTypes(); args.nonEmpty(); args = args.tail) |
|
272 |
checkDimension(pos, args.head); |
|
273 |
break; |
|
274 |
case ARRAY: |
|
275 |
if (types.dimensions(t) > ClassFile.MAX_DIMENSIONS) { |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45316
diff
changeset
|
276 |
log.error(pos, Errors.LimitDimensions); |
10 | 277 |
nerrs++; |
278 |
} |
|
279 |
break; |
|
280 |
default: |
|
281 |
break; |
|
282 |
} |
|
283 |
} |
|
284 |
||
285 |
/** Create a tempory variable. |
|
286 |
* @param type The variable's type. |
|
287 |
*/ |
|
288 |
LocalItem makeTemp(Type type) { |
|
289 |
VarSymbol v = new VarSymbol(Flags.SYNTHETIC, |
|
290 |
names.empty, |
|
291 |
type, |
|
292 |
env.enclMethod.sym); |
|
293 |
code.newLocal(v); |
|
294 |
return items.makeLocalItem(v); |
|
295 |
} |
|
296 |
||
297 |
/** Generate code to call a non-private method or constructor. |
|
298 |
* @param pos Position to be used for error reporting. |
|
299 |
* @param site The type of which the method is a member. |
|
300 |
* @param name The method's name. |
|
301 |
* @param argtypes The method's argument types. |
|
302 |
* @param isStatic A flag that indicates whether we call a |
|
303 |
* static or instance method. |
|
304 |
*/ |
|
305 |
void callMethod(DiagnosticPosition pos, |
|
306 |
Type site, Name name, List<Type> argtypes, |
|
307 |
boolean isStatic) { |
|
308 |
Symbol msym = rs. |
|
309 |
resolveInternalMethod(pos, attrEnv, site, name, argtypes, null); |
|
310 |
if (isStatic) items.makeStaticItem(msym).invoke(); |
|
311 |
else items.makeMemberItem(msym, name == names.init).invoke(); |
|
312 |
} |
|
313 |
||
314 |
/** Is the given method definition an access method |
|
315 |
* resulting from a qualified super? This is signified by an odd |
|
316 |
* access code. |
|
317 |
*/ |
|
318 |
private boolean isAccessSuper(JCMethodDecl enclMethod) { |
|
319 |
return |
|
320 |
(enclMethod.mods.flags & SYNTHETIC) != 0 && |
|
321 |
isOddAccessName(enclMethod.name); |
|
322 |
} |
|
323 |
||
324 |
/** Does given name start with "access$" and end in an odd digit? |
|
325 |
*/ |
|
326 |
private boolean isOddAccessName(Name name) { |
|
327 |
return |
|
328 |
name.startsWith(accessDollar) && |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
329 |
(name.getByteAt(name.getByteLength() - 1) & 1) == 1; |
10 | 330 |
} |
331 |
||
332 |
/* ************************************************************************ |
|
333 |
* Non-local exits |
|
334 |
*************************************************************************/ |
|
335 |
||
336 |
/** Generate code to invoke the finalizer associated with given |
|
337 |
* environment. |
|
338 |
* Any calls to finalizers are appended to the environments `cont' chain. |
|
339 |
* Mark beginning of gap in catch all range for finalizer. |
|
340 |
*/ |
|
341 |
void genFinalizer(Env<GenContext> env) { |
|
342 |
if (code.isAlive() && env.info.finalize != null) |
|
343 |
env.info.finalize.gen(); |
|
344 |
} |
|
345 |
||
346 |
/** Generate code to call all finalizers of structures aborted by |
|
347 |
* a non-local |
|
348 |
* exit. Return target environment of the non-local exit. |
|
349 |
* @param target The tree representing the structure that's aborted |
|
350 |
* @param env The environment current at the non-local exit. |
|
351 |
*/ |
|
352 |
Env<GenContext> unwind(JCTree target, Env<GenContext> env) { |
|
353 |
Env<GenContext> env1 = env; |
|
354 |
while (true) { |
|
355 |
genFinalizer(env1); |
|
356 |
if (env1.tree == target) break; |
|
357 |
env1 = env1.next; |
|
358 |
} |
|
359 |
return env1; |
|
360 |
} |
|
361 |
||
362 |
/** Mark end of gap in catch-all range for finalizer. |
|
363 |
* @param env the environment which might contain the finalizer |
|
364 |
* (if it does, env.info.gaps != null). |
|
365 |
*/ |
|
366 |
void endFinalizerGap(Env<GenContext> env) { |
|
367 |
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
|
368 |
env.info.gaps.append(code.curCP()); |
10 | 369 |
} |
370 |
||
371 |
/** Mark end of all gaps in catch-all ranges for finalizers of environments |
|
372 |
* lying between, and including to two environments. |
|
373 |
* @param from the most deeply nested environment to mark |
|
374 |
* @param to the least deeply nested environment to mark |
|
375 |
*/ |
|
376 |
void endFinalizerGaps(Env<GenContext> from, Env<GenContext> to) { |
|
377 |
Env<GenContext> last = null; |
|
378 |
while (last != to) { |
|
379 |
endFinalizerGap(from); |
|
380 |
last = from; |
|
381 |
from = from.next; |
|
382 |
} |
|
383 |
} |
|
384 |
||
385 |
/** Do any of the structures aborted by a non-local exit have |
|
386 |
* finalizers that require an empty stack? |
|
387 |
* @param target The tree representing the structure that's aborted |
|
388 |
* @param env The environment current at the non-local exit. |
|
389 |
*/ |
|
390 |
boolean hasFinally(JCTree target, Env<GenContext> env) { |
|
391 |
while (env.tree != target) { |
|
10950 | 392 |
if (env.tree.hasTag(TRY) && env.info.finalize.hasFinalizer()) |
10 | 393 |
return true; |
394 |
env = env.next; |
|
395 |
} |
|
396 |
return false; |
|
397 |
} |
|
398 |
||
399 |
/* ************************************************************************ |
|
400 |
* Normalizing class-members. |
|
401 |
*************************************************************************/ |
|
402 |
||
14259 | 403 |
/** Distribute member initializer code into constructors and {@code <clinit>} |
10 | 404 |
* method. |
405 |
* @param defs The list of class member declarations. |
|
406 |
* @param c The enclosing class. |
|
407 |
*/ |
|
408 |
List<JCTree> normalizeDefs(List<JCTree> defs, ClassSymbol c) { |
|
22163 | 409 |
ListBuffer<JCStatement> initCode = new ListBuffer<>(); |
410 |
ListBuffer<Attribute.TypeCompound> initTAs = new ListBuffer<>(); |
|
411 |
ListBuffer<JCStatement> clinitCode = new ListBuffer<>(); |
|
412 |
ListBuffer<Attribute.TypeCompound> clinitTAs = new ListBuffer<>(); |
|
413 |
ListBuffer<JCTree> methodDefs = new ListBuffer<>(); |
|
10 | 414 |
// Sort definitions into three listbuffers: |
415 |
// - initCode for instance initializers |
|
416 |
// - clinitCode for class initializers |
|
417 |
// - methodDefs for method definitions |
|
418 |
for (List<JCTree> l = defs; l.nonEmpty(); l = l.tail) { |
|
419 |
JCTree def = l.head; |
|
420 |
switch (def.getTag()) { |
|
10950 | 421 |
case BLOCK: |
10 | 422 |
JCBlock block = (JCBlock)def; |
423 |
if ((block.flags & STATIC) != 0) |
|
424 |
clinitCode.append(block); |
|
27230
361efbfa3079
8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
27224
diff
changeset
|
425 |
else if ((block.flags & SYNTHETIC) == 0) |
10 | 426 |
initCode.append(block); |
427 |
break; |
|
10950 | 428 |
case METHODDEF: |
10 | 429 |
methodDefs.append(def); |
430 |
break; |
|
10950 | 431 |
case VARDEF: |
10 | 432 |
JCVariableDecl vdef = (JCVariableDecl) def; |
433 |
VarSymbol sym = vdef.sym; |
|
434 |
checkDimension(vdef.pos(), sym.type); |
|
435 |
if (vdef.init != null) { |
|
436 |
if ((sym.flags() & STATIC) == 0) { |
|
437 |
// Always initialize instance variables. |
|
438 |
JCStatement init = make.at(vdef.pos()). |
|
439 |
Assignment(sym, vdef.init); |
|
440 |
initCode.append(init); |
|
11055 | 441 |
endPosTable.replaceTree(vdef, init); |
17578 | 442 |
initTAs.addAll(getAndRemoveNonFieldTAs(sym)); |
10 | 443 |
} else if (sym.getConstValue() == null) { |
444 |
// Initialize class (static) variables only if |
|
445 |
// they are not compile-time constants. |
|
446 |
JCStatement init = make.at(vdef.pos). |
|
447 |
Assignment(sym, vdef.init); |
|
448 |
clinitCode.append(init); |
|
11055 | 449 |
endPosTable.replaceTree(vdef, init); |
17578 | 450 |
clinitTAs.addAll(getAndRemoveNonFieldTAs(sym)); |
10 | 451 |
} else { |
452 |
checkStringConstant(vdef.init.pos(), sym.getConstValue()); |
|
31000
18bc6fadeb4e
8073372: Redundant CONSTANT_Class entry not generated for inlined constant
vromero
parents:
30406
diff
changeset
|
453 |
/* if the init contains a reference to an external class, add it to the |
18bc6fadeb4e
8073372: Redundant CONSTANT_Class entry not generated for inlined constant
vromero
parents:
30406
diff
changeset
|
454 |
* constant's pool |
18bc6fadeb4e
8073372: Redundant CONSTANT_Class entry not generated for inlined constant
vromero
parents:
30406
diff
changeset
|
455 |
*/ |
18bc6fadeb4e
8073372: Redundant CONSTANT_Class entry not generated for inlined constant
vromero
parents:
30406
diff
changeset
|
456 |
vdef.init.accept(classReferenceVisitor); |
10 | 457 |
} |
458 |
} |
|
459 |
break; |
|
460 |
default: |
|
8032 | 461 |
Assert.error(); |
10 | 462 |
} |
463 |
} |
|
464 |
// Insert any instance initializers into all constructors. |
|
465 |
if (initCode.length() != 0) { |
|
466 |
List<JCStatement> inits = initCode.toList(); |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17578
diff
changeset
|
467 |
initTAs.addAll(c.getInitTypeAttributes()); |
17578 | 468 |
List<Attribute.TypeCompound> initTAlist = initTAs.toList(); |
10 | 469 |
for (JCTree t : methodDefs) { |
17578 | 470 |
normalizeMethod((JCMethodDecl)t, inits, initTAlist); |
10 | 471 |
} |
472 |
} |
|
473 |
// If there are class initializers, create a <clinit> method |
|
474 |
// that contains them as its body. |
|
475 |
if (clinitCode.length() != 0) { |
|
476 |
MethodSymbol clinit = new MethodSymbol( |
|
15710
5792a085da41
7166455: javac doesn't set ACC_STRICT bit on <clinit> for strictfp class
vromero
parents:
15385
diff
changeset
|
477 |
STATIC | (c.flags() & STRICTFP), |
5792a085da41
7166455: javac doesn't set ACC_STRICT bit on <clinit> for strictfp class
vromero
parents:
15385
diff
changeset
|
478 |
names.clinit, |
10 | 479 |
new MethodType( |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41029
diff
changeset
|
480 |
List.nil(), syms.voidType, |
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41029
diff
changeset
|
481 |
List.nil(), syms.methodClass), |
10 | 482 |
c); |
483 |
c.members().enter(clinit); |
|
484 |
List<JCStatement> clinitStats = clinitCode.toList(); |
|
485 |
JCBlock block = make.at(clinitStats.head.pos()).Block(0, clinitStats); |
|
486 |
block.endpos = TreeInfo.endPos(clinitStats.last()); |
|
487 |
methodDefs.append(make.MethodDef(clinit, block)); |
|
17578 | 488 |
|
489 |
if (!clinitTAs.isEmpty()) |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17578
diff
changeset
|
490 |
clinit.appendUniqueTypeAttributes(clinitTAs.toList()); |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17578
diff
changeset
|
491 |
if (!c.getClassInitTypeAttributes().isEmpty()) |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17578
diff
changeset
|
492 |
clinit.appendUniqueTypeAttributes(c.getClassInitTypeAttributes()); |
10 | 493 |
} |
494 |
// Return all method definitions. |
|
495 |
return methodDefs.toList(); |
|
496 |
} |
|
497 |
||
17578 | 498 |
private List<Attribute.TypeCompound> getAndRemoveNonFieldTAs(VarSymbol sym) { |
499 |
List<TypeCompound> tas = sym.getRawTypeAttributes(); |
|
22163 | 500 |
ListBuffer<Attribute.TypeCompound> fieldTAs = new ListBuffer<>(); |
501 |
ListBuffer<Attribute.TypeCompound> nonfieldTAs = new ListBuffer<>(); |
|
17578 | 502 |
for (TypeCompound ta : tas) { |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
503 |
Assert.check(ta.getPosition().type != TargetType.UNKNOWN); |
21010
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
19941
diff
changeset
|
504 |
if (ta.getPosition().type == TargetType.FIELD) { |
17578 | 505 |
fieldTAs.add(ta); |
506 |
} else { |
|
507 |
nonfieldTAs.add(ta); |
|
508 |
} |
|
509 |
} |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17578
diff
changeset
|
510 |
sym.setTypeAttributes(fieldTAs.toList()); |
17578 | 511 |
return nonfieldTAs.toList(); |
512 |
} |
|
513 |
||
10 | 514 |
/** Check a constant value and report if it is a string that is |
515 |
* too large. |
|
516 |
*/ |
|
517 |
private void checkStringConstant(DiagnosticPosition pos, Object constValue) { |
|
518 |
if (nerrs != 0 || // only complain about a long string once |
|
519 |
constValue == null || |
|
520 |
!(constValue instanceof String) || |
|
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
521 |
((String)constValue).length() < PoolWriter.MAX_STRING_LENGTH) |
10 | 522 |
return; |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45316
diff
changeset
|
523 |
log.error(pos, Errors.LimitString); |
10 | 524 |
nerrs++; |
525 |
} |
|
526 |
||
527 |
/** Insert instance initializer code into initial constructor. |
|
528 |
* @param md The tree potentially representing a |
|
529 |
* constructor's definition. |
|
530 |
* @param initCode The list of instance initializer statements. |
|
17578 | 531 |
* @param initTAs Type annotations from the initializer expression. |
10 | 532 |
*/ |
17578 | 533 |
void normalizeMethod(JCMethodDecl md, List<JCStatement> initCode, List<TypeCompound> initTAs) { |
10 | 534 |
if (md.name == names.init && TreeInfo.isInitialConstructor(md)) { |
535 |
// We are seeing a constructor that does not call another |
|
536 |
// constructor of the same class. |
|
537 |
List<JCStatement> stats = md.body.stats; |
|
22163 | 538 |
ListBuffer<JCStatement> newstats = new ListBuffer<>(); |
10 | 539 |
|
540 |
if (stats.nonEmpty()) { |
|
541 |
// Copy initializers of synthetic variables generated in |
|
542 |
// the translation of inner classes. |
|
543 |
while (TreeInfo.isSyntheticInit(stats.head)) { |
|
544 |
newstats.append(stats.head); |
|
545 |
stats = stats.tail; |
|
546 |
} |
|
547 |
// Copy superclass constructor call |
|
548 |
newstats.append(stats.head); |
|
549 |
stats = stats.tail; |
|
550 |
// Copy remaining synthetic initializers. |
|
551 |
while (stats.nonEmpty() && |
|
552 |
TreeInfo.isSyntheticInit(stats.head)) { |
|
553 |
newstats.append(stats.head); |
|
554 |
stats = stats.tail; |
|
555 |
} |
|
556 |
// Now insert the initializer code. |
|
557 |
newstats.appendList(initCode); |
|
558 |
// And copy all remaining statements. |
|
559 |
while (stats.nonEmpty()) { |
|
560 |
newstats.append(stats.head); |
|
561 |
stats = stats.tail; |
|
562 |
} |
|
563 |
} |
|
564 |
md.body.stats = newstats.toList(); |
|
565 |
if (md.body.endpos == Position.NOPOS) |
|
566 |
md.body.endpos = TreeInfo.endPos(md.body.stats.last()); |
|
17578 | 567 |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17578
diff
changeset
|
568 |
md.sym.appendUniqueTypeAttributes(initTAs); |
10 | 569 |
} |
570 |
} |
|
571 |
||
572 |
/* ************************************************************************ |
|
573 |
* Traversal methods |
|
574 |
*************************************************************************/ |
|
575 |
||
576 |
/** Visitor argument: The current environment. |
|
577 |
*/ |
|
578 |
Env<GenContext> env; |
|
579 |
||
580 |
/** Visitor argument: The expected type (prototype). |
|
581 |
*/ |
|
582 |
Type pt; |
|
583 |
||
584 |
/** Visitor result: The item representing the computed value. |
|
585 |
*/ |
|
586 |
Item result; |
|
587 |
||
588 |
/** Visitor method: generate code for a definition, catching and reporting |
|
589 |
* any completion failures. |
|
590 |
* @param tree The definition to be visited. |
|
591 |
* @param env The environment current at the definition. |
|
592 |
*/ |
|
593 |
public void genDef(JCTree tree, Env<GenContext> env) { |
|
594 |
Env<GenContext> prevEnv = this.env; |
|
595 |
try { |
|
596 |
this.env = env; |
|
597 |
tree.accept(this); |
|
598 |
} catch (CompletionFailure ex) { |
|
599 |
chk.completionError(tree.pos(), ex); |
|
600 |
} finally { |
|
601 |
this.env = prevEnv; |
|
602 |
} |
|
603 |
} |
|
604 |
||
605 |
/** Derived visitor method: check whether CharacterRangeTable |
|
606 |
* should be emitted, if so, put a new entry into CRTable |
|
607 |
* and call method to generate bytecode. |
|
608 |
* If not, just call method to generate bytecode. |
|
14259 | 609 |
* @see #genStat(JCTree, Env) |
10 | 610 |
* |
611 |
* @param tree The tree to be visited. |
|
612 |
* @param env The environment to use. |
|
613 |
* @param crtFlags The CharacterRangeTable flags |
|
614 |
* indicating type of the entry. |
|
615 |
*/ |
|
616 |
public void genStat(JCTree tree, Env<GenContext> env, int crtFlags) { |
|
617 |
if (!genCrt) { |
|
618 |
genStat(tree, env); |
|
619 |
return; |
|
620 |
} |
|
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
621 |
int startpc = code.curCP(); |
10 | 622 |
genStat(tree, env); |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14721
diff
changeset
|
623 |
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
|
624 |
code.crt.put(tree, crtFlags, startpc, code.curCP()); |
10 | 625 |
} |
626 |
||
627 |
/** Derived visitor method: generate code for a statement. |
|
628 |
*/ |
|
629 |
public void genStat(JCTree tree, Env<GenContext> env) { |
|
630 |
if (code.isAlive()) { |
|
631 |
code.statBegin(tree.pos); |
|
632 |
genDef(tree, env); |
|
10950 | 633 |
} else if (env.info.isSwitch && tree.hasTag(VARDEF)) { |
10 | 634 |
// variables whose declarations are in a switch |
635 |
// can be used even if the decl is unreachable. |
|
636 |
code.newLocal(((JCVariableDecl) tree).sym); |
|
637 |
} |
|
638 |
} |
|
639 |
||
640 |
/** Derived visitor method: check whether CharacterRangeTable |
|
641 |
* should be emitted, if so, put a new entry into CRTable |
|
642 |
* and call method to generate bytecode. |
|
643 |
* If not, just call method to generate bytecode. |
|
644 |
* @see #genStats(List, Env) |
|
645 |
* |
|
646 |
* @param trees The list of trees to be visited. |
|
647 |
* @param env The environment to use. |
|
648 |
* @param crtFlags The CharacterRangeTable flags |
|
649 |
* indicating type of the entry. |
|
650 |
*/ |
|
651 |
public void genStats(List<JCStatement> trees, Env<GenContext> env, int crtFlags) { |
|
652 |
if (!genCrt) { |
|
653 |
genStats(trees, env); |
|
654 |
return; |
|
655 |
} |
|
656 |
if (trees.length() == 1) { // mark one statement with the flags |
|
657 |
genStat(trees.head, env, crtFlags | CRT_STATEMENT); |
|
658 |
} else { |
|
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
659 |
int startpc = code.curCP(); |
10 | 660 |
genStats(trees, env); |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
661 |
code.crt.put(trees, crtFlags, startpc, code.curCP()); |
10 | 662 |
} |
663 |
} |
|
664 |
||
665 |
/** Derived visitor method: generate code for a list of statements. |
|
666 |
*/ |
|
667 |
public void genStats(List<? extends JCTree> trees, Env<GenContext> env) { |
|
668 |
for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail) |
|
669 |
genStat(l.head, env, CRT_STATEMENT); |
|
670 |
} |
|
671 |
||
672 |
/** Derived visitor method: check whether CharacterRangeTable |
|
673 |
* should be emitted, if so, put a new entry into CRTable |
|
674 |
* and call method to generate bytecode. |
|
675 |
* If not, just call method to generate bytecode. |
|
14259 | 676 |
* @see #genCond(JCTree,boolean) |
10 | 677 |
* |
678 |
* @param tree The tree to be visited. |
|
679 |
* @param crtFlags The CharacterRangeTable flags |
|
680 |
* indicating type of the entry. |
|
681 |
*/ |
|
682 |
public CondItem genCond(JCTree tree, int crtFlags) { |
|
683 |
if (!genCrt) return genCond(tree, false); |
|
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
684 |
int startpc = code.curCP(); |
10 | 685 |
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
|
686 |
code.crt.put(tree, crtFlags, startpc, code.curCP()); |
10 | 687 |
return item; |
688 |
} |
|
689 |
||
690 |
/** Derived visitor method: generate code for a boolean |
|
691 |
* expression in a control-flow context. |
|
692 |
* @param _tree The expression to be visited. |
|
693 |
* @param markBranches The flag to indicate that the condition is |
|
694 |
* a flow controller so produced conditions |
|
695 |
* should contain a proper tree to generate |
|
696 |
* CharacterRangeTable branches for them. |
|
697 |
*/ |
|
698 |
public CondItem genCond(JCTree _tree, boolean markBranches) { |
|
699 |
JCTree inner_tree = TreeInfo.skipParens(_tree); |
|
10950 | 700 |
if (inner_tree.hasTag(CONDEXPR)) { |
10 | 701 |
JCConditional tree = (JCConditional)inner_tree; |
702 |
CondItem cond = genCond(tree.cond, CRT_FLOW_CONTROLLER); |
|
703 |
if (cond.isTrue()) { |
|
704 |
code.resolve(cond.trueJumps); |
|
705 |
CondItem result = genCond(tree.truepart, CRT_FLOW_TARGET); |
|
706 |
if (markBranches) result.tree = tree.truepart; |
|
707 |
return result; |
|
708 |
} |
|
709 |
if (cond.isFalse()) { |
|
710 |
code.resolve(cond.falseJumps); |
|
711 |
CondItem result = genCond(tree.falsepart, CRT_FLOW_TARGET); |
|
712 |
if (markBranches) result.tree = tree.falsepart; |
|
713 |
return result; |
|
714 |
} |
|
715 |
Chain secondJumps = cond.jumpFalse(); |
|
716 |
code.resolve(cond.trueJumps); |
|
717 |
CondItem first = genCond(tree.truepart, CRT_FLOW_TARGET); |
|
718 |
if (markBranches) first.tree = tree.truepart; |
|
719 |
Chain falseJumps = first.jumpFalse(); |
|
720 |
code.resolve(first.trueJumps); |
|
721 |
Chain trueJumps = code.branch(goto_); |
|
722 |
code.resolve(secondJumps); |
|
723 |
CondItem second = genCond(tree.falsepart, CRT_FLOW_TARGET); |
|
724 |
CondItem result = items.makeCondItem(second.opcode, |
|
5004
6c2694dc2da0
6929544: langtools source code uses statics qualified by instance variables
jjg
parents:
4875
diff
changeset
|
725 |
Code.mergeChains(trueJumps, second.trueJumps), |
6c2694dc2da0
6929544: langtools source code uses statics qualified by instance variables
jjg
parents:
4875
diff
changeset
|
726 |
Code.mergeChains(falseJumps, second.falseJumps)); |
10 | 727 |
if (markBranches) result.tree = tree.falsepart; |
728 |
return result; |
|
52794
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
729 |
} else if (inner_tree.hasTag(SWITCH_EXPRESSION)) { |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
730 |
boolean prevInCondSwitchExpression = inCondSwitchExpression; |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
731 |
Chain prevSwitchExpressionTrueChain = switchExpressionTrueChain; |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
732 |
Chain prevSwitchExpressionFalseChain = switchExpressionFalseChain; |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
733 |
try { |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
734 |
inCondSwitchExpression = true; |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
735 |
switchExpressionTrueChain = null; |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
736 |
switchExpressionFalseChain = null; |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
737 |
try { |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
738 |
doHandleSwitchExpression((JCSwitchExpression) inner_tree); |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
739 |
} catch (CompletionFailure ex) { |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
740 |
chk.completionError(_tree.pos(), ex); |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
741 |
code.state.stacksize = 1; |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
742 |
} |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
743 |
CondItem result = items.makeCondItem(goto_, |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
744 |
switchExpressionTrueChain, |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
745 |
switchExpressionFalseChain); |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
746 |
if (markBranches) result.tree = _tree; |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
747 |
return result; |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
748 |
} finally { |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
749 |
inCondSwitchExpression = prevInCondSwitchExpression; |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
750 |
switchExpressionTrueChain = prevSwitchExpressionTrueChain; |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
751 |
switchExpressionFalseChain = prevSwitchExpressionFalseChain; |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
752 |
} |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
753 |
} else if (inner_tree.hasTag(LETEXPR) && ((LetExpr) inner_tree).needsCond) { |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
754 |
LetExpr tree = (LetExpr) inner_tree; |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
755 |
int limit = code.nextreg; |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
756 |
int prevLetExprStart = code.setLetExprStackPos(code.state.stacksize); |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
757 |
try { |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
758 |
genStats(tree.defs, env); |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
759 |
} finally { |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
760 |
code.setLetExprStackPos(prevLetExprStart); |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
761 |
} |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
762 |
CondItem result = genCond(tree.expr, markBranches); |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
763 |
code.endScopes(limit); |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
764 |
return result; |
10 | 765 |
} else { |
766 |
CondItem result = genExpr(_tree, syms.booleanType).mkCond(); |
|
767 |
if (markBranches) result.tree = _tree; |
|
768 |
return result; |
|
769 |
} |
|
770 |
} |
|
771 |
||
35424 | 772 |
public Code getCode() { |
773 |
return code; |
|
774 |
} |
|
775 |
||
776 |
public Items getItems() { |
|
777 |
return items; |
|
778 |
} |
|
779 |
||
780 |
public Env<AttrContext> getAttrEnv() { |
|
781 |
return attrEnv; |
|
782 |
} |
|
783 |
||
14721
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
784 |
/** 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
|
785 |
* 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
|
786 |
* 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
|
787 |
* 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
|
788 |
* automated tools can detect class dependencies better. |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
789 |
*/ |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
790 |
class ClassReferenceVisitor extends JCTree.Visitor { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
791 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
792 |
@Override |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
793 |
public void visitTree(JCTree tree) {} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
794 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
795 |
@Override |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
796 |
public void visitBinary(JCBinary tree) { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
797 |
tree.lhs.accept(this); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
798 |
tree.rhs.accept(this); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
799 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
800 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
801 |
@Override |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
802 |
public void visitSelect(JCFieldAccess tree) { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
803 |
if (tree.selected.type.hasTag(CLASS)) { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
804 |
makeRef(tree.selected.pos(), tree.selected.type); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
805 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
806 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
807 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
808 |
@Override |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
809 |
public void visitIdent(JCIdent tree) { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
810 |
if (tree.sym.owner instanceof ClassSymbol) { |
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
811 |
poolWriter.putClass((ClassSymbol)tree.sym.owner); |
14721
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
812 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
813 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
814 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
815 |
@Override |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
816 |
public void visitConditional(JCConditional tree) { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
817 |
tree.cond.accept(this); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
818 |
tree.truepart.accept(this); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
819 |
tree.falsepart.accept(this); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
820 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
821 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
822 |
@Override |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
823 |
public void visitUnary(JCUnary tree) { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
824 |
tree.arg.accept(this); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
825 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
826 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
827 |
@Override |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
828 |
public void visitParens(JCParens tree) { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
829 |
tree.expr.accept(this); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
830 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
831 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
832 |
@Override |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
833 |
public void visitTypeCast(JCTypeCast tree) { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
834 |
tree.expr.accept(this); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
835 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
836 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
837 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
838 |
private ClassReferenceVisitor classReferenceVisitor = new ClassReferenceVisitor(); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
839 |
|
10 | 840 |
/** Visitor method: generate code for an expression, catching and reporting |
841 |
* any completion failures. |
|
842 |
* @param tree The expression to be visited. |
|
843 |
* @param pt The expression's expected type (proto-type). |
|
844 |
*/ |
|
845 |
public Item genExpr(JCTree tree, Type pt) { |
|
846 |
Type prevPt = this.pt; |
|
847 |
try { |
|
848 |
if (tree.type.constValue() != null) { |
|
849 |
// Short circuit any expressions which are constants |
|
14721
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
850 |
tree.accept(classReferenceVisitor); |
10 | 851 |
checkStringConstant(tree.pos(), tree.type.constValue()); |
54762 | 852 |
Symbol sym = TreeInfo.symbol(tree); |
853 |
if (sym != null && isConstantDynamic(sym)) { |
|
854 |
result = items.makeDynamicItem(sym); |
|
855 |
} else { |
|
856 |
result = items.makeImmediateItem(tree.type, tree.type.constValue()); |
|
857 |
} |
|
10 | 858 |
} else { |
859 |
this.pt = pt; |
|
860 |
tree.accept(this); |
|
861 |
} |
|
862 |
return result.coerce(pt); |
|
863 |
} catch (CompletionFailure ex) { |
|
864 |
chk.completionError(tree.pos(), ex); |
|
865 |
code.state.stacksize = 1; |
|
866 |
return items.makeStackItem(pt); |
|
867 |
} finally { |
|
868 |
this.pt = prevPt; |
|
869 |
} |
|
870 |
} |
|
871 |
||
54762 | 872 |
public boolean isConstantDynamic(Symbol sym) { |
873 |
return sym.kind == VAR && |
|
874 |
sym instanceof DynamicVarSymbol && |
|
875 |
((DynamicVarSymbol)sym).isDynamic(); |
|
876 |
} |
|
877 |
||
10 | 878 |
/** Derived visitor method: generate code for a list of method arguments. |
879 |
* @param trees The argument expressions to be visited. |
|
880 |
* @param pts The expression's expected types (i.e. the formal parameter |
|
881 |
* types of the invoked method). |
|
882 |
*/ |
|
883 |
public void genArgs(List<JCExpression> trees, List<Type> pts) { |
|
884 |
for (List<JCExpression> l = trees; l.nonEmpty(); l = l.tail) { |
|
885 |
genExpr(l.head, pts.head).load(); |
|
886 |
pts = pts.tail; |
|
887 |
} |
|
888 |
// require lists be of same length |
|
8032 | 889 |
Assert.check(pts.isEmpty()); |
10 | 890 |
} |
891 |
||
892 |
/* ************************************************************************ |
|
893 |
* Visitor methods for statements and definitions |
|
894 |
*************************************************************************/ |
|
895 |
||
896 |
/** Thrown when the byte code size exceeds limit. |
|
897 |
*/ |
|
898 |
public static class CodeSizeOverflow extends RuntimeException { |
|
899 |
private static final long serialVersionUID = 0; |
|
900 |
public CodeSizeOverflow() {} |
|
901 |
} |
|
902 |
||
903 |
public void visitMethodDef(JCMethodDecl tree) { |
|
904 |
// Create a new local environment that points pack at method |
|
905 |
// definition. |
|
906 |
Env<GenContext> localEnv = env.dup(tree); |
|
907 |
localEnv.enclMethod = tree; |
|
908 |
// The expected type of every return statement in this method |
|
909 |
// is the method's return type. |
|
910 |
this.pt = tree.sym.erasure(types).getReturnType(); |
|
911 |
||
912 |
checkDimension(tree.pos(), tree.sym.erasure(types)); |
|
913 |
genMethod(tree, localEnv, false); |
|
914 |
} |
|
915 |
//where |
|
916 |
/** Generate code for a method. |
|
917 |
* @param tree The tree representing the method definition. |
|
918 |
* @param env The environment current for the method body. |
|
919 |
* @param fatcode A flag that indicates whether all jumps are |
|
920 |
* within 32K. We first invoke this method under |
|
921 |
* the assumption that fatcode == false, i.e. all |
|
922 |
* jumps are within 32K. If this fails, fatcode |
|
923 |
* is set to true and we try again. |
|
924 |
*/ |
|
925 |
void genMethod(JCMethodDecl tree, Env<GenContext> env, boolean fatcode) { |
|
926 |
MethodSymbol meth = tree.sym; |
|
18653
1407564fb956
8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents:
18010
diff
changeset
|
927 |
int extras = 0; |
1407564fb956
8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents:
18010
diff
changeset
|
928 |
// Count up extra parameters |
1407564fb956
8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents:
18010
diff
changeset
|
929 |
if (meth.isConstructor()) { |
1407564fb956
8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents:
18010
diff
changeset
|
930 |
extras++; |
1407564fb956
8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents:
18010
diff
changeset
|
931 |
if (meth.enclClass().isInner() && |
1407564fb956
8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents:
18010
diff
changeset
|
932 |
!meth.enclClass().isStatic()) { |
1407564fb956
8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents:
18010
diff
changeset
|
933 |
extras++; |
1407564fb956
8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents:
18010
diff
changeset
|
934 |
} |
1407564fb956
8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents:
18010
diff
changeset
|
935 |
} else if ((tree.mods.flags & STATIC) == 0) { |
1407564fb956
8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents:
18010
diff
changeset
|
936 |
extras++; |
1407564fb956
8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents:
18010
diff
changeset
|
937 |
} |
1407564fb956
8014230: Compilation incorrectly succeeds with inner class constructor with 254 parameters
emc
parents:
18010
diff
changeset
|
938 |
// 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
|
939 |
if (Code.width(types.erasure(env.enclMethod.sym.type).getParameterTypes()) + extras > |
10 | 940 |
ClassFile.MAX_PARAMETERS) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45316
diff
changeset
|
941 |
log.error(tree.pos(), Errors.LimitParameters); |
10 | 942 |
nerrs++; |
943 |
} |
|
944 |
||
945 |
else if (tree.body != null) { |
|
946 |
// Create a new code structure and initialize it. |
|
947 |
int startpcCrt = initCode(tree, env, fatcode); |
|
948 |
||
949 |
try { |
|
950 |
genStat(tree.body, env); |
|
951 |
} catch (CodeSizeOverflow e) { |
|
952 |
// Failed due to code limit, try again with jsr/ret |
|
953 |
startpcCrt = initCode(tree, env, fatcode); |
|
954 |
genStat(tree.body, env); |
|
955 |
} |
|
956 |
||
957 |
if (code.state.stacksize != 0) { |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45316
diff
changeset
|
958 |
log.error(tree.body.pos(), Errors.StackSimError(tree.sym)); |
10 | 959 |
throw new AssertionError(); |
960 |
} |
|
961 |
||
962 |
// If last statement could complete normally, insert a |
|
963 |
// return at the end. |
|
964 |
if (code.isAlive()) { |
|
965 |
code.statBegin(TreeInfo.endPos(tree.body)); |
|
966 |
if (env.enclMethod == null || |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
967 |
env.enclMethod.sym.type.getReturnType().hasTag(VOID)) { |
10 | 968 |
code.emitop0(return_); |
969 |
} else { |
|
970 |
// sometime dead code seems alive (4415991); |
|
971 |
// generate a small loop instead |
|
972 |
int startpc = code.entryPoint(); |
|
973 |
CondItem c = items.makeCondItem(goto_); |
|
974 |
code.resolve(c.jumpTrue(), startpc); |
|
975 |
} |
|
976 |
} |
|
977 |
if (genCrt) |
|
978 |
code.crt.put(tree.body, |
|
979 |
CRT_BLOCK, |
|
980 |
startpcCrt, |
|
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
981 |
code.curCP()); |
10 | 982 |
|
983 |
code.endScopes(0); |
|
984 |
||
985 |
// If we exceeded limits, panic |
|
986 |
if (code.checkLimits(tree.pos(), log)) { |
|
987 |
nerrs++; |
|
988 |
return; |
|
989 |
} |
|
990 |
||
991 |
// If we generated short code but got a long jump, do it again |
|
992 |
// with fatCode = true. |
|
993 |
if (!fatcode && code.fatcode) genMethod(tree, env, true); |
|
994 |
||
995 |
// Clean up |
|
996 |
if(stackMap == StackMapFormat.JSR202) { |
|
997 |
code.lastFrame = null; |
|
998 |
code.frameBeforeLast = null; |
|
999 |
} |
|
10811
4d4ed480210e
7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
10457
diff
changeset
|
1000 |
|
15385 | 1001 |
// Compress exception table |
10811
4d4ed480210e
7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
10457
diff
changeset
|
1002 |
code.compressCatchTable(); |
15385 | 1003 |
|
1004 |
// Fill in type annotation positions for exception parameters |
|
1005 |
code.fillExceptionParameterPositions(); |
|
10 | 1006 |
} |
1007 |
} |
|
1008 |
||
1009 |
private int initCode(JCMethodDecl tree, Env<GenContext> env, boolean fatcode) { |
|
1010 |
MethodSymbol meth = tree.sym; |
|
1011 |
||
1012 |
// Create a new code structure. |
|
1013 |
meth.code = code = new Code(meth, |
|
1014 |
fatcode, |
|
1015 |
lineDebugInfo ? toplevel.lineMap : null, |
|
1016 |
varDebugInfo, |
|
1017 |
stackMap, |
|
1018 |
debugCode, |
|
1019 |
genCrt ? new CRTable(tree, env.toplevel.endPositions) |
|
1020 |
: null, |
|
1021 |
syms, |
|
1022 |
types, |
|
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
1023 |
poolWriter); |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
1024 |
items = new Items(poolWriter, code, syms, types); |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
1025 |
if (code.debugCode) { |
10 | 1026 |
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
|
1027 |
} |
10 | 1028 |
|
1029 |
// If method is not static, create a new local variable address |
|
1030 |
// for `this'. |
|
1031 |
if ((tree.mods.flags & STATIC) == 0) { |
|
1032 |
Type selfType = meth.owner.type; |
|
1033 |
if (meth.isConstructor() && selfType != syms.objectType) |
|
1034 |
selfType = UninitializedType.uninitializedThis(selfType); |
|
1035 |
code.setDefined( |
|
1036 |
code.newLocal( |
|
1037 |
new VarSymbol(FINAL, names._this, selfType, meth.owner))); |
|
1038 |
} |
|
1039 |
||
1040 |
// Mark all parameters as defined from the beginning of |
|
1041 |
// the method. |
|
1042 |
for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { |
|
1043 |
checkDimension(l.head.pos(), l.head.sym.type); |
|
1044 |
code.setDefined(code.newLocal(l.head.sym)); |
|
1045 |
} |
|
1046 |
||
1047 |
// 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
|
1048 |
int startpcCrt = genCrt ? code.curCP() : 0; |
10 | 1049 |
code.entryPoint(); |
1050 |
||
1051 |
// Suppress initial stackmap |
|
1052 |
code.pendingStackMap = false; |
|
1053 |
||
1054 |
return startpcCrt; |
|
1055 |
} |
|
1056 |
||
1057 |
public void visitVarDef(JCVariableDecl tree) { |
|
1058 |
VarSymbol v = tree.sym; |
|
1059 |
if (tree.init != null) { |
|
1060 |
checkStringConstant(tree.init.pos(), v.getConstValue()); |
|
1061 |
if (v.getConstValue() == null || varDebugInfo) { |
|
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1062 |
Assert.check(code.isStatementStart()); |
51658
805807f15830
8210435: don't add local variable spots if they are DCE'ed by the compiler
vromero
parents:
51563
diff
changeset
|
1063 |
code.newLocal(v); |
10 | 1064 |
genExpr(tree.init, v.erasure(types)).load(); |
1065 |
items.makeLocalItem(v).store(); |
|
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1066 |
Assert.check(code.isStatementStart()); |
10 | 1067 |
} |
51658
805807f15830
8210435: don't add local variable spots if they are DCE'ed by the compiler
vromero
parents:
51563
diff
changeset
|
1068 |
} else { |
805807f15830
8210435: don't add local variable spots if they are DCE'ed by the compiler
vromero
parents:
51563
diff
changeset
|
1069 |
code.newLocal(v); |
10 | 1070 |
} |
1071 |
checkDimension(tree.pos(), v.type); |
|
1072 |
} |
|
1073 |
||
1074 |
public void visitSkip(JCSkip tree) { |
|
1075 |
} |
|
1076 |
||
1077 |
public void visitBlock(JCBlock tree) { |
|
1078 |
int limit = code.nextreg; |
|
1079 |
Env<GenContext> localEnv = env.dup(tree, new GenContext()); |
|
1080 |
genStats(tree.stats, localEnv); |
|
1081 |
// End the scope of all block-local variables in variable info. |
|
10950 | 1082 |
if (!env.tree.hasTag(METHODDEF)) { |
10 | 1083 |
code.statBegin(tree.endpos); |
1084 |
code.endScopes(limit); |
|
1085 |
code.pendingStatPos = Position.NOPOS; |
|
1086 |
} |
|
1087 |
} |
|
1088 |
||
1089 |
public void visitDoLoop(JCDoWhileLoop tree) { |
|
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41029
diff
changeset
|
1090 |
genLoop(tree, tree.body, tree.cond, List.nil(), false); |
10 | 1091 |
} |
1092 |
||
1093 |
public void visitWhileLoop(JCWhileLoop tree) { |
|
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41029
diff
changeset
|
1094 |
genLoop(tree, tree.body, tree.cond, List.nil(), true); |
10 | 1095 |
} |
1096 |
||
1097 |
public void visitForLoop(JCForLoop tree) { |
|
1098 |
int limit = code.nextreg; |
|
1099 |
genStats(tree.init, env); |
|
1100 |
genLoop(tree, tree.body, tree.cond, tree.step, true); |
|
1101 |
code.endScopes(limit); |
|
1102 |
} |
|
1103 |
//where |
|
1104 |
/** Generate code for a loop. |
|
1105 |
* @param loop The tree representing the loop. |
|
1106 |
* @param body The loop's body. |
|
1107 |
* @param cond The loop's controling condition. |
|
1108 |
* @param step "Step" statements to be inserted at end of |
|
1109 |
* each iteration. |
|
1110 |
* @param testFirst True if the loop test belongs before the body. |
|
1111 |
*/ |
|
1112 |
private void genLoop(JCStatement loop, |
|
1113 |
JCStatement body, |
|
1114 |
JCExpression cond, |
|
1115 |
List<JCExpressionStatement> step, |
|
1116 |
boolean testFirst) { |
|
1117 |
Env<GenContext> loopEnv = env.dup(loop, new GenContext()); |
|
1118 |
int startpc = code.entryPoint(); |
|
25607 | 1119 |
if (testFirst) { //while or for loop |
10 | 1120 |
CondItem c; |
1121 |
if (cond != null) { |
|
1122 |
code.statBegin(cond.pos); |
|
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1123 |
Assert.check(code.isStatementStart()); |
10 | 1124 |
c = genCond(TreeInfo.skipParens(cond), CRT_FLOW_CONTROLLER); |
1125 |
} else { |
|
1126 |
c = items.makeCondItem(goto_); |
|
1127 |
} |
|
1128 |
Chain loopDone = c.jumpFalse(); |
|
1129 |
code.resolve(c.trueJumps); |
|
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1130 |
Assert.check(code.isStatementStart()); |
10 | 1131 |
genStat(body, loopEnv, CRT_STATEMENT | CRT_FLOW_TARGET); |
1132 |
code.resolve(loopEnv.info.cont); |
|
1133 |
genStats(step, loopEnv); |
|
1134 |
code.resolve(code.branch(goto_), startpc); |
|
1135 |
code.resolve(loopDone); |
|
1136 |
} else { |
|
1137 |
genStat(body, loopEnv, CRT_STATEMENT | CRT_FLOW_TARGET); |
|
1138 |
code.resolve(loopEnv.info.cont); |
|
1139 |
genStats(step, loopEnv); |
|
37753
dbc87c966861
8155028: javac crashes in silly do-while loop
sadayapalam
parents:
37635
diff
changeset
|
1140 |
if (code.isAlive()) { |
dbc87c966861
8155028: javac crashes in silly do-while loop
sadayapalam
parents:
37635
diff
changeset
|
1141 |
CondItem c; |
dbc87c966861
8155028: javac crashes in silly do-while loop
sadayapalam
parents:
37635
diff
changeset
|
1142 |
if (cond != null) { |
dbc87c966861
8155028: javac crashes in silly do-while loop
sadayapalam
parents:
37635
diff
changeset
|
1143 |
code.statBegin(cond.pos); |
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1144 |
Assert.check(code.isStatementStart()); |
37753
dbc87c966861
8155028: javac crashes in silly do-while loop
sadayapalam
parents:
37635
diff
changeset
|
1145 |
c = genCond(TreeInfo.skipParens(cond), CRT_FLOW_CONTROLLER); |
dbc87c966861
8155028: javac crashes in silly do-while loop
sadayapalam
parents:
37635
diff
changeset
|
1146 |
} else { |
dbc87c966861
8155028: javac crashes in silly do-while loop
sadayapalam
parents:
37635
diff
changeset
|
1147 |
c = items.makeCondItem(goto_); |
dbc87c966861
8155028: javac crashes in silly do-while loop
sadayapalam
parents:
37635
diff
changeset
|
1148 |
} |
dbc87c966861
8155028: javac crashes in silly do-while loop
sadayapalam
parents:
37635
diff
changeset
|
1149 |
code.resolve(c.jumpTrue(), startpc); |
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1150 |
Assert.check(code.isStatementStart()); |
37753
dbc87c966861
8155028: javac crashes in silly do-while loop
sadayapalam
parents:
37635
diff
changeset
|
1151 |
code.resolve(c.falseJumps); |
10 | 1152 |
} |
1153 |
} |
|
28338
53f6dcec62d1
8067429: java.lang.VerifyError: Inconsistent stackmap frames at branch target
mcimadamore
parents:
28330
diff
changeset
|
1154 |
Chain exit = loopEnv.info.exit; |
53f6dcec62d1
8067429: java.lang.VerifyError: Inconsistent stackmap frames at branch target
mcimadamore
parents:
28330
diff
changeset
|
1155 |
if (exit != null) { |
53f6dcec62d1
8067429: java.lang.VerifyError: Inconsistent stackmap frames at branch target
mcimadamore
parents:
28330
diff
changeset
|
1156 |
code.resolve(exit); |
53f6dcec62d1
8067429: java.lang.VerifyError: Inconsistent stackmap frames at branch target
mcimadamore
parents:
28330
diff
changeset
|
1157 |
exit.state.defined.excludeFrom(code.nextreg); |
25607 | 1158 |
} |
10 | 1159 |
} |
1160 |
||
1161 |
public void visitForeachLoop(JCEnhancedForLoop tree) { |
|
1162 |
throw new AssertionError(); // should have been removed by Lower. |
|
1163 |
} |
|
1164 |
||
1165 |
public void visitLabelled(JCLabeledStatement tree) { |
|
1166 |
Env<GenContext> localEnv = env.dup(tree, new GenContext()); |
|
1167 |
genStat(tree.body, localEnv, CRT_STATEMENT); |
|
28338
53f6dcec62d1
8067429: java.lang.VerifyError: Inconsistent stackmap frames at branch target
mcimadamore
parents:
28330
diff
changeset
|
1168 |
Chain exit = localEnv.info.exit; |
53f6dcec62d1
8067429: java.lang.VerifyError: Inconsistent stackmap frames at branch target
mcimadamore
parents:
28330
diff
changeset
|
1169 |
if (exit != null) { |
53f6dcec62d1
8067429: java.lang.VerifyError: Inconsistent stackmap frames at branch target
mcimadamore
parents:
28330
diff
changeset
|
1170 |
code.resolve(exit); |
53f6dcec62d1
8067429: java.lang.VerifyError: Inconsistent stackmap frames at branch target
mcimadamore
parents:
28330
diff
changeset
|
1171 |
exit.state.defined.excludeFrom(code.nextreg); |
53f6dcec62d1
8067429: java.lang.VerifyError: Inconsistent stackmap frames at branch target
mcimadamore
parents:
28330
diff
changeset
|
1172 |
} |
10 | 1173 |
} |
1174 |
||
1175 |
public void visitSwitch(JCSwitch tree) { |
|
52794
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1176 |
handleSwitch(tree, tree.selector, tree.cases); |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1177 |
} |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1178 |
|
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1179 |
@Override |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1180 |
public void visitSwitchExpression(JCSwitchExpression tree) { |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1181 |
code.resolvePending(); |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1182 |
boolean prevInCondSwitchExpression = inCondSwitchExpression; |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1183 |
try { |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1184 |
inCondSwitchExpression = false; |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1185 |
doHandleSwitchExpression(tree); |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1186 |
} finally { |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1187 |
inCondSwitchExpression = prevInCondSwitchExpression; |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1188 |
} |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1189 |
result = items.makeStackItem(pt); |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1190 |
} |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1191 |
|
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1192 |
private void doHandleSwitchExpression(JCSwitchExpression tree) { |
52936
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1193 |
List<LocalItem> prevStackBeforeSwitchExpression = stackBeforeSwitchExpression; |
58678 | 1194 |
LocalItem prevSwitchResult = switchResult; |
52936
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1195 |
int limit = code.nextreg; |
52794
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1196 |
try { |
52936
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1197 |
stackBeforeSwitchExpression = List.nil(); |
58678 | 1198 |
switchResult = null; |
52936
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1199 |
if (hasTry(tree)) { |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1200 |
//if the switch expression contains try-catch, the catch handlers need to have |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1201 |
//an empty stack. So stash whole stack to local variables, and restore it before |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1202 |
//breaks: |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1203 |
while (code.state.stacksize > 0) { |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1204 |
Type type = code.state.peek(); |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1205 |
Name varName = names.fromString(target.syntheticNameChar() + |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1206 |
"stack" + |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1207 |
target.syntheticNameChar() + |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1208 |
tree.pos + |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1209 |
target.syntheticNameChar() + |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1210 |
code.state.stacksize); |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1211 |
VarSymbol var = new VarSymbol(Flags.SYNTHETIC, varName, type, |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1212 |
this.env.enclMethod.sym); |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1213 |
LocalItem item = items.new LocalItem(type, code.newLocal(var)); |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1214 |
stackBeforeSwitchExpression = stackBeforeSwitchExpression.prepend(item); |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1215 |
item.store(); |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1216 |
} |
58678 | 1217 |
switchResult = makeTemp(tree.type); |
52936
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1218 |
} |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1219 |
int prevLetExprStart = code.setLetExprStackPos(code.state.stacksize); |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1220 |
try { |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1221 |
handleSwitch(tree, tree.selector, tree.cases); |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1222 |
} finally { |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1223 |
code.setLetExprStackPos(prevLetExprStart); |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1224 |
} |
52794
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1225 |
} finally { |
52936
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1226 |
stackBeforeSwitchExpression = prevStackBeforeSwitchExpression; |
58678 | 1227 |
switchResult = prevSwitchResult; |
52936
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1228 |
code.endScopes(limit); |
52794
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1229 |
} |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1230 |
} |
52936
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1231 |
//where: |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1232 |
private boolean hasTry(JCSwitchExpression tree) { |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1233 |
boolean[] hasTry = new boolean[1]; |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1234 |
new TreeScanner() { |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1235 |
@Override |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1236 |
public void visitTry(JCTry tree) { |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1237 |
hasTry[0] = true; |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1238 |
} |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1239 |
|
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1240 |
@Override |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1241 |
public void visitClassDef(JCClassDecl tree) { |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1242 |
} |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1243 |
|
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1244 |
@Override |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1245 |
public void visitLambda(JCLambda tree) { |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1246 |
} |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1247 |
}.scan(tree); |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1248 |
return hasTry[0]; |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1249 |
} |
52794
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1250 |
|
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1251 |
private void handleSwitch(JCTree swtch, JCExpression selector, List<JCCase> cases) { |
10 | 1252 |
int limit = code.nextreg; |
52794
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1253 |
Assert.check(!selector.type.hasTag(CLASS)); |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
1254 |
int startpcCrt = genCrt ? code.curCP() : 0; |
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1255 |
Assert.check(code.isStatementStart()); |
52794
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1256 |
Item sel = genExpr(selector, syms.intType); |
10 | 1257 |
if (cases.isEmpty()) { |
1258 |
// We are seeing: switch <sel> {} |
|
1259 |
sel.load().drop(); |
|
1260 |
if (genCrt) |
|
52794
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1261 |
code.crt.put(TreeInfo.skipParens(selector), |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
1262 |
CRT_FLOW_CONTROLLER, startpcCrt, code.curCP()); |
10 | 1263 |
} else { |
1264 |
// We are seeing a nonempty switch. |
|
1265 |
sel.load(); |
|
1266 |
if (genCrt) |
|
52794
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1267 |
code.crt.put(TreeInfo.skipParens(selector), |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
1268 |
CRT_FLOW_CONTROLLER, startpcCrt, code.curCP()); |
52794
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1269 |
Env<GenContext> switchEnv = env.dup(swtch, new GenContext()); |
10 | 1270 |
switchEnv.info.isSwitch = true; |
1271 |
||
1272 |
// Compute number of labels and minimum and maximum label values. |
|
1273 |
// For each case, store its label in an array. |
|
1274 |
int lo = Integer.MAX_VALUE; // minimum label. |
|
1275 |
int hi = Integer.MIN_VALUE; // maximum label. |
|
1276 |
int nlabels = 0; // number of labels. |
|
1277 |
||
1278 |
int[] labels = new int[cases.length()]; // the label array. |
|
1279 |
int defaultIndex = -1; // the index of the default clause. |
|
1280 |
||
1281 |
List<JCCase> l = cases; |
|
1282 |
for (int i = 0; i < labels.length; i++) { |
|
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1283 |
if (l.head.pats.nonEmpty()) { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1284 |
Assert.check(l.head.pats.size() == 1); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1285 |
int val = ((Number)l.head.pats.head.type.constValue()).intValue(); |
10 | 1286 |
labels[i] = val; |
1287 |
if (val < lo) lo = val; |
|
1288 |
if (hi < val) hi = val; |
|
1289 |
nlabels++; |
|
1290 |
} else { |
|
8032 | 1291 |
Assert.check(defaultIndex == -1); |
10 | 1292 |
defaultIndex = i; |
1293 |
} |
|
1294 |
l = l.tail; |
|
1295 |
} |
|
1296 |
||
1297 |
// Determine whether to issue a tableswitch or a lookupswitch |
|
27123 | 1298 |
// instruction. |
1299 |
long table_space_cost = 4 + ((long) hi - lo + 1); // words |
|
1300 |
long table_time_cost = 3; // comparisons |
|
1301 |
long lookup_space_cost = 3 + 2 * (long) nlabels; |
|
1302 |
long lookup_time_cost = nlabels; |
|
1303 |
int opcode = |
|
1304 |
nlabels > 0 && |
|
1305 |
table_space_cost + 3 * table_time_cost <= |
|
1306 |
lookup_space_cost + 3 * lookup_time_cost |
|
1307 |
? |
|
1308 |
tableswitch : lookupswitch; |
|
10 | 1309 |
|
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
1310 |
int startpc = code.curCP(); // the position of the selector operation |
10 | 1311 |
code.emitop0(opcode); |
1312 |
code.align(4); |
|
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
1313 |
int tableBase = code.curCP(); // the start of the jump table |
10 | 1314 |
int[] offsets = null; // a table of offsets for a lookupswitch |
1315 |
code.emit4(-1); // leave space for default offset |
|
1316 |
if (opcode == tableswitch) { |
|
1317 |
code.emit4(lo); // minimum label |
|
1318 |
code.emit4(hi); // maximum label |
|
1319 |
for (long i = lo; i <= hi; i++) { // leave space for jump table |
|
1320 |
code.emit4(-1); |
|
1321 |
} |
|
1322 |
} else { |
|
1323 |
code.emit4(nlabels); // number of labels |
|
1324 |
for (int i = 0; i < nlabels; i++) { |
|
1325 |
code.emit4(-1); code.emit4(-1); // leave space for lookup table |
|
1326 |
} |
|
1327 |
offsets = new int[labels.length]; |
|
1328 |
} |
|
1329 |
Code.State stateSwitch = code.state.dup(); |
|
1330 |
code.markDead(); |
|
1331 |
||
1332 |
// For each case do: |
|
1333 |
l = cases; |
|
1334 |
for (int i = 0; i < labels.length; i++) { |
|
1335 |
JCCase c = l.head; |
|
1336 |
l = l.tail; |
|
1337 |
||
1338 |
int pc = code.entryPoint(stateSwitch); |
|
1339 |
// Insert offset directly into code or else into the |
|
1340 |
// offsets table. |
|
1341 |
if (i != defaultIndex) { |
|
1342 |
if (opcode == tableswitch) { |
|
1343 |
code.put4( |
|
1344 |
tableBase + 4 * (labels[i] - lo + 3), |
|
1345 |
pc - startpc); |
|
1346 |
} else { |
|
1347 |
offsets[i] = pc - startpc; |
|
1348 |
} |
|
1349 |
} else { |
|
1350 |
code.put4(tableBase, pc - startpc); |
|
1351 |
} |
|
1352 |
||
1353 |
// Generate code for the statements in this case. |
|
1354 |
genStats(c.stats, switchEnv, CRT_FLOW_TARGET); |
|
1355 |
} |
|
1356 |
||
1357 |
// Resolve all breaks. |
|
28338
53f6dcec62d1
8067429: java.lang.VerifyError: Inconsistent stackmap frames at branch target
mcimadamore
parents:
28330
diff
changeset
|
1358 |
Chain exit = switchEnv.info.exit; |
53f6dcec62d1
8067429: java.lang.VerifyError: Inconsistent stackmap frames at branch target
mcimadamore
parents:
28330
diff
changeset
|
1359 |
if (exit != null) { |
53f6dcec62d1
8067429: java.lang.VerifyError: Inconsistent stackmap frames at branch target
mcimadamore
parents:
28330
diff
changeset
|
1360 |
code.resolve(exit); |
41029
869e95ade880
8160699: java.lang.VerifyError: Inconsistent stackmap frames at branch target
sadayapalam
parents:
39920
diff
changeset
|
1361 |
exit.state.defined.excludeFrom(limit); |
28338
53f6dcec62d1
8067429: java.lang.VerifyError: Inconsistent stackmap frames at branch target
mcimadamore
parents:
28330
diff
changeset
|
1362 |
} |
10 | 1363 |
|
1364 |
// If we have not set the default offset, we do so now. |
|
1365 |
if (code.get4(tableBase) == -1) { |
|
1366 |
code.put4(tableBase, code.entryPoint(stateSwitch) - startpc); |
|
1367 |
} |
|
1368 |
||
1369 |
if (opcode == tableswitch) { |
|
1370 |
// Let any unfilled slots point to the default case. |
|
1371 |
int defaultOffset = code.get4(tableBase); |
|
1372 |
for (long i = lo; i <= hi; i++) { |
|
1373 |
int t = (int)(tableBase + 4 * (i - lo + 3)); |
|
1374 |
if (code.get4(t) == -1) |
|
1375 |
code.put4(t, defaultOffset); |
|
1376 |
} |
|
1377 |
} else { |
|
1378 |
// Sort non-default offsets and copy into lookup table. |
|
1379 |
if (defaultIndex >= 0) |
|
1380 |
for (int i = defaultIndex; i < labels.length - 1; i++) { |
|
1381 |
labels[i] = labels[i+1]; |
|
1382 |
offsets[i] = offsets[i+1]; |
|
1383 |
} |
|
1384 |
if (nlabels > 0) |
|
1385 |
qsort2(labels, offsets, 0, nlabels - 1); |
|
1386 |
for (int i = 0; i < nlabels; i++) { |
|
1387 |
int caseidx = tableBase + 8 * (i + 1); |
|
1388 |
code.put4(caseidx, labels[i]); |
|
1389 |
code.put4(caseidx + 4, offsets[i]); |
|
1390 |
} |
|
1391 |
} |
|
1392 |
} |
|
1393 |
code.endScopes(limit); |
|
1394 |
} |
|
1395 |
//where |
|
1396 |
/** Sort (int) arrays of keys and values |
|
1397 |
*/ |
|
1398 |
static void qsort2(int[] keys, int[] values, int lo, int hi) { |
|
1399 |
int i = lo; |
|
1400 |
int j = hi; |
|
1401 |
int pivot = keys[(i+j)/2]; |
|
1402 |
do { |
|
1403 |
while (keys[i] < pivot) i++; |
|
1404 |
while (pivot < keys[j]) j--; |
|
1405 |
if (i <= j) { |
|
1406 |
int temp1 = keys[i]; |
|
1407 |
keys[i] = keys[j]; |
|
1408 |
keys[j] = temp1; |
|
1409 |
int temp2 = values[i]; |
|
1410 |
values[i] = values[j]; |
|
1411 |
values[j] = temp2; |
|
1412 |
i++; |
|
1413 |
j--; |
|
1414 |
} |
|
1415 |
} while (i <= j); |
|
1416 |
if (lo < j) qsort2(keys, values, lo, j); |
|
1417 |
if (i < hi) qsort2(keys, values, i, hi); |
|
1418 |
} |
|
1419 |
||
1420 |
public void visitSynchronized(JCSynchronized tree) { |
|
1421 |
int limit = code.nextreg; |
|
1422 |
// Generate code to evaluate lock and save in temporary variable. |
|
1423 |
final LocalItem lockVar = makeTemp(syms.objectType); |
|
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1424 |
Assert.check(code.isStatementStart()); |
10 | 1425 |
genExpr(tree.lock, tree.lock.type).load().duplicate(); |
1426 |
lockVar.store(); |
|
1427 |
||
1428 |
// Generate code to enter monitor. |
|
1429 |
code.emitop0(monitorenter); |
|
1430 |
code.state.lock(lockVar.reg); |
|
1431 |
||
1432 |
// Generate code for a try statement with given body, no catch clauses |
|
1433 |
// in a new environment with the "exit-monitor" operation as finalizer. |
|
1434 |
final Env<GenContext> syncEnv = env.dup(tree, new GenContext()); |
|
1435 |
syncEnv.info.finalize = new GenFinalizer() { |
|
1436 |
void gen() { |
|
1437 |
genLast(); |
|
8032 | 1438 |
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
|
1439 |
syncEnv.info.gaps.append(code.curCP()); |
10 | 1440 |
} |
1441 |
void genLast() { |
|
1442 |
if (code.isAlive()) { |
|
1443 |
lockVar.load(); |
|
1444 |
code.emitop0(monitorexit); |
|
1445 |
code.state.unlock(lockVar.reg); |
|
1446 |
} |
|
1447 |
} |
|
1448 |
}; |
|
22163 | 1449 |
syncEnv.info.gaps = new ListBuffer<>(); |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41029
diff
changeset
|
1450 |
genTry(tree.body, List.nil(), syncEnv); |
10 | 1451 |
code.endScopes(limit); |
1452 |
} |
|
1453 |
||
1454 |
public void visitTry(final JCTry tree) { |
|
1455 |
// Generate code for a try statement with given body and catch clauses, |
|
1456 |
// in a new environment which calls the finally block if there is one. |
|
1457 |
final Env<GenContext> tryEnv = env.dup(tree, new GenContext()); |
|
1458 |
final Env<GenContext> oldEnv = env; |
|
1459 |
tryEnv.info.finalize = new GenFinalizer() { |
|
1460 |
void gen() { |
|
36153 | 1461 |
Assert.check(tryEnv.info.gaps.length() % 2 == 0); |
1462 |
tryEnv.info.gaps.append(code.curCP()); |
|
1463 |
genLast(); |
|
10 | 1464 |
} |
1465 |
void genLast() { |
|
1466 |
if (tree.finalizer != null) |
|
1467 |
genStat(tree.finalizer, oldEnv, CRT_BLOCK); |
|
1468 |
} |
|
1469 |
boolean hasFinalizer() { |
|
1470 |
return tree.finalizer != null; |
|
1471 |
} |
|
49280
c2a3a2aa2475
8194978: Javac produces dead code for try-with-resource
jlahoda
parents:
47216
diff
changeset
|
1472 |
|
c2a3a2aa2475
8194978: Javac produces dead code for try-with-resource
jlahoda
parents:
47216
diff
changeset
|
1473 |
@Override |
c2a3a2aa2475
8194978: Javac produces dead code for try-with-resource
jlahoda
parents:
47216
diff
changeset
|
1474 |
void afterBody() { |
c2a3a2aa2475
8194978: Javac produces dead code for try-with-resource
jlahoda
parents:
47216
diff
changeset
|
1475 |
if (tree.finalizer != null && (tree.finalizer.flags & BODY_ONLY_FINALIZE) != 0) { |
c2a3a2aa2475
8194978: Javac produces dead code for try-with-resource
jlahoda
parents:
47216
diff
changeset
|
1476 |
//for body-only finally, remove the GenFinalizer after try body |
c2a3a2aa2475
8194978: Javac produces dead code for try-with-resource
jlahoda
parents:
47216
diff
changeset
|
1477 |
//so that the finally is not generated to catch bodies: |
c2a3a2aa2475
8194978: Javac produces dead code for try-with-resource
jlahoda
parents:
47216
diff
changeset
|
1478 |
tryEnv.info.finalize = null; |
c2a3a2aa2475
8194978: Javac produces dead code for try-with-resource
jlahoda
parents:
47216
diff
changeset
|
1479 |
} |
c2a3a2aa2475
8194978: Javac produces dead code for try-with-resource
jlahoda
parents:
47216
diff
changeset
|
1480 |
} |
c2a3a2aa2475
8194978: Javac produces dead code for try-with-resource
jlahoda
parents:
47216
diff
changeset
|
1481 |
|
10 | 1482 |
}; |
22163 | 1483 |
tryEnv.info.gaps = new ListBuffer<>(); |
10 | 1484 |
genTry(tree.body, tree.catchers, tryEnv); |
1485 |
} |
|
1486 |
//where |
|
1487 |
/** Generate code for a try or synchronized statement |
|
1488 |
* @param body The body of the try or synchronized statement. |
|
1489 |
* @param catchers The lis of catch clauses. |
|
1490 |
* @param env the environment current for the body. |
|
1491 |
*/ |
|
1492 |
void genTry(JCTree body, List<JCCatch> catchers, Env<GenContext> env) { |
|
1493 |
int limit = code.nextreg; |
|
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
1494 |
int startpc = code.curCP(); |
10 | 1495 |
Code.State stateTry = code.state.dup(); |
1496 |
genStat(body, env, CRT_BLOCK); |
|
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
1497 |
int endpc = code.curCP(); |
10 | 1498 |
List<Integer> gaps = env.info.gaps.toList(); |
1499 |
code.statBegin(TreeInfo.endPos(body)); |
|
1500 |
genFinalizer(env); |
|
1501 |
code.statBegin(TreeInfo.endPos(env.tree)); |
|
19923
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1502 |
Chain exitChain = code.branch(goto_); |
10 | 1503 |
endFinalizerGap(env); |
49280
c2a3a2aa2475
8194978: Javac produces dead code for try-with-resource
jlahoda
parents:
47216
diff
changeset
|
1504 |
env.info.finalize.afterBody(); |
c2a3a2aa2475
8194978: Javac produces dead code for try-with-resource
jlahoda
parents:
47216
diff
changeset
|
1505 |
boolean hasFinalizer = |
c2a3a2aa2475
8194978: Javac produces dead code for try-with-resource
jlahoda
parents:
47216
diff
changeset
|
1506 |
env.info.finalize != null && |
c2a3a2aa2475
8194978: Javac produces dead code for try-with-resource
jlahoda
parents:
47216
diff
changeset
|
1507 |
env.info.finalize.hasFinalizer(); |
19923
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1508 |
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
|
1509 |
// start off with exception on stack |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1510 |
code.entryPoint(stateTry, l.head.param.sym.type); |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1511 |
genCatch(l.head, env, startpc, endpc, gaps); |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1512 |
genFinalizer(env); |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1513 |
if (hasFinalizer || l.tail.nonEmpty()) { |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1514 |
code.statBegin(TreeInfo.endPos(env.tree)); |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1515 |
exitChain = Code.mergeChains(exitChain, |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1516 |
code.branch(goto_)); |
10 | 1517 |
} |
19923
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1518 |
endFinalizerGap(env); |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1519 |
} |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1520 |
if (hasFinalizer) { |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1521 |
// Create a new register segement to avoid allocating |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1522 |
// the same variables in finalizers and other statements. |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1523 |
code.newRegSegment(); |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1524 |
|
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1525 |
// Add a catch-all clause. |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1526 |
|
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1527 |
// start off with exception on stack |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1528 |
int catchallpc = code.entryPoint(stateTry, syms.throwableType); |
10 | 1529 |
|
19923
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1530 |
// Register all exception ranges for catch all clause. |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1531 |
// 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
|
1532 |
// of the try or synchronized block until the present |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1533 |
// code pointer excluding all gaps in the current |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1534 |
// environment's GenContext. |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1535 |
int startseg = startpc; |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1536 |
while (env.info.gaps.nonEmpty()) { |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1537 |
int endseg = env.info.gaps.next().intValue(); |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1538 |
registerCatch(body.pos(), startseg, endseg, |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1539 |
catchallpc, 0); |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1540 |
startseg = env.info.gaps.next().intValue(); |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1541 |
} |
45220 | 1542 |
code.statBegin(TreeInfo.finalizerPos(env.tree, PosKind.FIRST_STAT_POS)); |
19923
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1543 |
code.markStatBegin(); |
10 | 1544 |
|
19923
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1545 |
Item excVar = makeTemp(syms.throwableType); |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1546 |
excVar.store(); |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1547 |
genFinalizer(env); |
45220 | 1548 |
code.resolvePending(); |
1549 |
code.statBegin(TreeInfo.finalizerPos(env.tree, PosKind.END_POS)); |
|
1550 |
code.markStatBegin(); |
|
1551 |
||
19923
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1552 |
excVar.load(); |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1553 |
registerCatch(body.pos(), startseg, |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1554 |
env.info.gaps.next().intValue(), |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1555 |
catchallpc, 0); |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1556 |
code.emitop0(athrow); |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1557 |
code.markDead(); |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1558 |
|
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1559 |
// If there are jsr's to this finalizer, ... |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1560 |
if (env.info.cont != null) { |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1561 |
// Resolve all jsr's. |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1562 |
code.resolve(env.info.cont); |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1563 |
|
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1564 |
// Mark statement line number |
45220 | 1565 |
code.statBegin(TreeInfo.finalizerPos(env.tree, PosKind.FIRST_STAT_POS)); |
10 | 1566 |
code.markStatBegin(); |
1567 |
||
19923
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1568 |
// Save return address. |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1569 |
LocalItem retVar = makeTemp(syms.throwableType); |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1570 |
retVar.store(); |
10 | 1571 |
|
19923
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1572 |
// Generate finalizer code. |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1573 |
env.info.finalize.genLast(); |
10 | 1574 |
|
19923
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1575 |
// Return. |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1576 |
code.emitop1w(ret, retVar.reg); |
4895f15b3845
8024039: javac, previous solution for JDK-8022186 was incorrect
vromero
parents:
19247
diff
changeset
|
1577 |
code.markDead(); |
10 | 1578 |
} |
1579 |
} |
|
1580 |
// Resolve all breaks. |
|
1581 |
code.resolve(exitChain); |
|
1582 |
||
1583 |
code.endScopes(limit); |
|
1584 |
} |
|
1585 |
||
1586 |
/** Generate code for a catch clause. |
|
1587 |
* @param tree The catch clause. |
|
1588 |
* @param env The environment current in the enclosing try. |
|
1589 |
* @param startpc Start pc of try-block. |
|
1590 |
* @param endpc End pc of try-block. |
|
1591 |
*/ |
|
1592 |
void genCatch(JCCatch tree, |
|
1593 |
Env<GenContext> env, |
|
1594 |
int startpc, int endpc, |
|
1595 |
List<Integer> gaps) { |
|
1596 |
if (startpc != endpc) { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1597 |
List<Pair<List<Attribute.TypeCompound>, JCExpression>> catchTypeExprs |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1598 |
= catchTypesWithAnnotations(tree); |
6354
f50c012cd1f0
6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents:
5857
diff
changeset
|
1599 |
while (gaps.nonEmpty()) { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1600 |
for (Pair<List<Attribute.TypeCompound>, JCExpression> subCatch1 : catchTypeExprs) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1601 |
JCExpression subCatch = subCatch1.snd; |
6354
f50c012cd1f0
6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents:
5857
diff
changeset
|
1602 |
int catchType = makeRef(tree.pos(), subCatch.type); |
f50c012cd1f0
6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents:
5857
diff
changeset
|
1603 |
int end = gaps.head.intValue(); |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5004
diff
changeset
|
1604 |
registerCatch(tree.pos(), |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
1605 |
startpc, end, code.curCP(), |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5004
diff
changeset
|
1606 |
catchType); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1607 |
for (Attribute.TypeCompound tc : subCatch1.fst) { |
24396 | 1608 |
tc.position.setCatchInfo(catchType, startpc); |
17578 | 1609 |
} |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5004
diff
changeset
|
1610 |
} |
6354
f50c012cd1f0
6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents:
5857
diff
changeset
|
1611 |
gaps = gaps.tail; |
f50c012cd1f0
6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents:
5857
diff
changeset
|
1612 |
startpc = gaps.head.intValue(); |
f50c012cd1f0
6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents:
5857
diff
changeset
|
1613 |
gaps = gaps.tail; |
f50c012cd1f0
6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents:
5857
diff
changeset
|
1614 |
} |
f50c012cd1f0
6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents:
5857
diff
changeset
|
1615 |
if (startpc < endpc) { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1616 |
for (Pair<List<Attribute.TypeCompound>, JCExpression> subCatch1 : catchTypeExprs) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1617 |
JCExpression subCatch = subCatch1.snd; |
6354
f50c012cd1f0
6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents:
5857
diff
changeset
|
1618 |
int catchType = makeRef(tree.pos(), subCatch.type); |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5004
diff
changeset
|
1619 |
registerCatch(tree.pos(), |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
1620 |
startpc, endpc, code.curCP(), |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5004
diff
changeset
|
1621 |
catchType); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1622 |
for (Attribute.TypeCompound tc : subCatch1.fst) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1623 |
tc.position.setCatchInfo(catchType, startpc); |
17578 | 1624 |
} |
6354
f50c012cd1f0
6978574: return statement in try block with multi-catch causes ClassFormatError
mcimadamore
parents:
5857
diff
changeset
|
1625 |
} |
10 | 1626 |
} |
1627 |
VarSymbol exparam = tree.param.sym; |
|
1628 |
code.statBegin(tree.pos); |
|
1629 |
code.markStatBegin(); |
|
1630 |
int limit = code.nextreg; |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1631 |
code.newLocal(exparam); |
10 | 1632 |
items.makeLocalItem(exparam).store(); |
1633 |
code.statBegin(TreeInfo.firstStatPos(tree.body)); |
|
1634 |
genStat(tree.body, env, CRT_BLOCK); |
|
1635 |
code.endScopes(limit); |
|
1636 |
code.statBegin(TreeInfo.endPos(tree.body)); |
|
1637 |
} |
|
1638 |
} |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1639 |
// where |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1640 |
List<Pair<List<Attribute.TypeCompound>, JCExpression>> catchTypesWithAnnotations(JCCatch tree) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1641 |
return TreeInfo.isMultiCatch(tree) ? |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1642 |
catchTypesWithAnnotationsFromMulticatch((JCTypeUnion)tree.param.vartype, tree.param.sym.getRawTypeAttributes()) : |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1643 |
List.of(new Pair<>(tree.param.sym.getRawTypeAttributes(), tree.param.vartype)); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1644 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1645 |
// where |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1646 |
List<Pair<List<Attribute.TypeCompound>, JCExpression>> catchTypesWithAnnotationsFromMulticatch(JCTypeUnion tree, List<TypeCompound> first) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1647 |
List<JCExpression> alts = tree.alternatives; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1648 |
List<Pair<List<TypeCompound>, JCExpression>> res = List.of(new Pair<>(first, alts.head)); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1649 |
alts = alts.tail; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1650 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1651 |
while(alts != null && alts.head != null) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1652 |
JCExpression alt = alts.head; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1653 |
if (alt instanceof JCAnnotatedType) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1654 |
JCAnnotatedType a = (JCAnnotatedType)alt; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1655 |
res = res.prepend(new Pair<>(annotate.fromAnnotations(a.annotations), alt)); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1656 |
} else { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1657 |
res = res.prepend(new Pair<>(List.nil(), alt)); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1658 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1659 |
alts = alts.tail; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1660 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1661 |
return res.reverse(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29777
diff
changeset
|
1662 |
} |
10 | 1663 |
|
1664 |
/** Register a catch clause in the "Exceptions" code-attribute. |
|
1665 |
*/ |
|
1666 |
void registerCatch(DiagnosticPosition pos, |
|
1667 |
int startpc, int endpc, |
|
1668 |
int handler_pc, int catch_type) { |
|
10811
4d4ed480210e
7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
10457
diff
changeset
|
1669 |
char startpc1 = (char)startpc; |
4d4ed480210e
7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
10457
diff
changeset
|
1670 |
char endpc1 = (char)endpc; |
4d4ed480210e
7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
10457
diff
changeset
|
1671 |
char handler_pc1 = (char)handler_pc; |
4d4ed480210e
7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
10457
diff
changeset
|
1672 |
if (startpc1 == startpc && |
4d4ed480210e
7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
10457
diff
changeset
|
1673 |
endpc1 == endpc && |
4d4ed480210e
7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
10457
diff
changeset
|
1674 |
handler_pc1 == handler_pc) { |
4d4ed480210e
7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
10457
diff
changeset
|
1675 |
code.addCatch(startpc1, endpc1, handler_pc1, |
4d4ed480210e
7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
10457
diff
changeset
|
1676 |
(char)catch_type); |
4d4ed480210e
7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
10457
diff
changeset
|
1677 |
} else { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45316
diff
changeset
|
1678 |
log.error(pos, Errors.LimitCodeTooLargeForTryStmt); |
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
1679 |
nerrs++; |
10 | 1680 |
} |
1681 |
} |
|
1682 |
||
1683 |
public void visitIf(JCIf tree) { |
|
1684 |
int limit = code.nextreg; |
|
1685 |
Chain thenExit = null; |
|
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1686 |
Assert.check(code.isStatementStart()); |
10 | 1687 |
CondItem c = genCond(TreeInfo.skipParens(tree.cond), |
1688 |
CRT_FLOW_CONTROLLER); |
|
1689 |
Chain elseChain = c.jumpFalse(); |
|
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1690 |
Assert.check(code.isStatementStart()); |
10 | 1691 |
if (!c.isFalse()) { |
1692 |
code.resolve(c.trueJumps); |
|
1693 |
genStat(tree.thenpart, env, CRT_STATEMENT | CRT_FLOW_TARGET); |
|
1694 |
thenExit = code.branch(goto_); |
|
1695 |
} |
|
1696 |
if (elseChain != null) { |
|
1697 |
code.resolve(elseChain); |
|
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
1698 |
if (tree.elsepart != null) { |
10 | 1699 |
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
|
1700 |
} |
10 | 1701 |
} |
1702 |
code.resolve(thenExit); |
|
1703 |
code.endScopes(limit); |
|
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1704 |
Assert.check(code.isStatementStart()); |
10 | 1705 |
} |
1706 |
||
1707 |
public void visitExec(JCExpressionStatement tree) { |
|
1708 |
// Optimize x++ to ++x and x-- to --x. |
|
1709 |
JCExpression e = tree.expr; |
|
1710 |
switch (e.getTag()) { |
|
10950 | 1711 |
case POSTINC: |
1712 |
((JCUnary) e).setTag(PREINC); |
|
10 | 1713 |
break; |
10950 | 1714 |
case POSTDEC: |
1715 |
((JCUnary) e).setTag(PREDEC); |
|
10 | 1716 |
break; |
1717 |
} |
|
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1718 |
Assert.check(code.isStatementStart()); |
10 | 1719 |
genExpr(tree.expr, tree.expr.type).drop(); |
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1720 |
Assert.check(code.isStatementStart()); |
10 | 1721 |
} |
1722 |
||
1723 |
public void visitBreak(JCBreak tree) { |
|
52794
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1724 |
Assert.check(code.isStatementStart()); |
58678 | 1725 |
final Env<GenContext> targetEnv = unwindBreak(tree.target); |
1726 |
targetEnv.info.addExit(code.branch(goto_)); |
|
1727 |
endFinalizerGaps(env, targetEnv); |
|
1728 |
} |
|
1729 |
||
1730 |
public void visitYield(JCYield tree) { |
|
1731 |
Assert.check(code.isStatementStart()); |
|
52936
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1732 |
final Env<GenContext> targetEnv; |
58678 | 1733 |
if (inCondSwitchExpression) { |
1734 |
CondItem value = genCond(tree.value, CRT_FLOW_TARGET); |
|
1735 |
Chain falseJumps = value.jumpFalse(); |
|
1736 |
||
1737 |
code.resolve(value.trueJumps); |
|
1738 |
Env<GenContext> localEnv = unwindBreak(tree.target); |
|
1739 |
reloadStackBeforeSwitchExpr(); |
|
1740 |
Chain trueJumps = code.branch(goto_); |
|
1741 |
||
1742 |
endFinalizerGaps(env, localEnv); |
|
1743 |
||
1744 |
code.resolve(falseJumps); |
|
1745 |
targetEnv = unwindBreak(tree.target); |
|
1746 |
reloadStackBeforeSwitchExpr(); |
|
1747 |
falseJumps = code.branch(goto_); |
|
1748 |
||
1749 |
if (switchExpressionTrueChain == null) { |
|
1750 |
switchExpressionTrueChain = trueJumps; |
|
1751 |
} else { |
|
1752 |
switchExpressionTrueChain = |
|
1753 |
Code.mergeChains(switchExpressionTrueChain, trueJumps); |
|
52936
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1754 |
} |
58678 | 1755 |
if (switchExpressionFalseChain == null) { |
1756 |
switchExpressionFalseChain = falseJumps; |
|
52794
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1757 |
} else { |
58678 | 1758 |
switchExpressionFalseChain = |
1759 |
Code.mergeChains(switchExpressionFalseChain, falseJumps); |
|
52794
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1760 |
} |
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1761 |
} else { |
58678 | 1762 |
genExpr(tree.value, pt).load(); |
1763 |
if (switchResult != null) |
|
1764 |
switchResult.store(); |
|
1765 |
||
1766 |
targetEnv = unwindBreak(tree.target); |
|
1767 |
||
1768 |
if (code.isAlive()) { |
|
1769 |
reloadStackBeforeSwitchExpr(); |
|
1770 |
if (switchResult != null) |
|
1771 |
switchResult.load(); |
|
1772 |
||
1773 |
code.state.forceStackTop(tree.target.type); |
|
1774 |
targetEnv.info.addExit(code.branch(goto_)); |
|
1775 |
code.markDead(); |
|
1776 |
} |
|
52794
e4ba5414c8b4
8214031: Assertion error in value break statement with conditional operator in switch expression
jlahoda
parents:
51658
diff
changeset
|
1777 |
} |
10 | 1778 |
endFinalizerGaps(env, targetEnv); |
1779 |
} |
|
52936
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1780 |
//where: |
58678 | 1781 |
/** As side-effect, might mark code as dead disabling any further emission. |
1782 |
*/ |
|
1783 |
private Env<GenContext> unwindBreak(JCTree target) { |
|
52936
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1784 |
int tmpPos = code.pendingStatPos; |
58678 | 1785 |
Env<GenContext> targetEnv = unwind(target, env); |
52936
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1786 |
code.pendingStatPos = tmpPos; |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1787 |
return targetEnv; |
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
1788 |
} |
10 | 1789 |
|
58678 | 1790 |
private void reloadStackBeforeSwitchExpr() { |
1791 |
for (LocalItem li : stackBeforeSwitchExpression) |
|
1792 |
li.load(); |
|
1793 |
} |
|
1794 |
||
10 | 1795 |
public void visitContinue(JCContinue tree) { |
45088
b85080f2f0cc
8180141: Missing entry in LineNumberTable for break statement that jumps out of try-finally
vromero
parents:
43765
diff
changeset
|
1796 |
int tmpPos = code.pendingStatPos; |
10 | 1797 |
Env<GenContext> targetEnv = unwind(tree.target, env); |
45088
b85080f2f0cc
8180141: Missing entry in LineNumberTable for break statement that jumps out of try-finally
vromero
parents:
43765
diff
changeset
|
1798 |
code.pendingStatPos = tmpPos; |
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1799 |
Assert.check(code.isStatementStart()); |
10 | 1800 |
targetEnv.info.addCont(code.branch(goto_)); |
1801 |
endFinalizerGaps(env, targetEnv); |
|
1802 |
} |
|
1803 |
||
1804 |
public void visitReturn(JCReturn tree) { |
|
1805 |
int limit = code.nextreg; |
|
1806 |
final Env<GenContext> targetEnv; |
|
33371
b6f6281b4c07
8134759: jdb: Incorrect stepping inside finally block
aeriksso
parents:
31000
diff
changeset
|
1807 |
|
b6f6281b4c07
8134759: jdb: Incorrect stepping inside finally block
aeriksso
parents:
31000
diff
changeset
|
1808 |
/* Save and then restore the location of the return in case a finally |
b6f6281b4c07
8134759: jdb: Incorrect stepping inside finally block
aeriksso
parents:
31000
diff
changeset
|
1809 |
* is expanded (with unwind()) in the middle of our bytecodes. |
b6f6281b4c07
8134759: jdb: Incorrect stepping inside finally block
aeriksso
parents:
31000
diff
changeset
|
1810 |
*/ |
b6f6281b4c07
8134759: jdb: Incorrect stepping inside finally block
aeriksso
parents:
31000
diff
changeset
|
1811 |
int tmpPos = code.pendingStatPos; |
10 | 1812 |
if (tree.expr != null) { |
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1813 |
Assert.check(code.isStatementStart()); |
10 | 1814 |
Item r = genExpr(tree.expr, pt).load(); |
1815 |
if (hasFinally(env.enclMethod, env)) { |
|
1816 |
r = makeTemp(pt); |
|
1817 |
r.store(); |
|
1818 |
} |
|
1819 |
targetEnv = unwind(env.enclMethod, env); |
|
33371
b6f6281b4c07
8134759: jdb: Incorrect stepping inside finally block
aeriksso
parents:
31000
diff
changeset
|
1820 |
code.pendingStatPos = tmpPos; |
10 | 1821 |
r.load(); |
1822 |
code.emitop0(ireturn + Code.truncate(Code.typecode(pt))); |
|
1823 |
} else { |
|
1824 |
targetEnv = unwind(env.enclMethod, env); |
|
18658
55e4c45e091c
7008643: inlined finally clauses confuse debuggers
vromero
parents:
18653
diff
changeset
|
1825 |
code.pendingStatPos = tmpPos; |
10 | 1826 |
code.emitop0(return_); |
1827 |
} |
|
1828 |
endFinalizerGaps(env, targetEnv); |
|
1829 |
code.endScopes(limit); |
|
1830 |
} |
|
1831 |
||
1832 |
public void visitThrow(JCThrow tree) { |
|
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1833 |
Assert.check(code.isStatementStart()); |
10 | 1834 |
genExpr(tree.expr, tree.expr.type).load(); |
1835 |
code.emitop0(athrow); |
|
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
1836 |
Assert.check(code.isStatementStart()); |
10 | 1837 |
} |
1838 |
||
1839 |
/* ************************************************************************ |
|
1840 |
* Visitor methods for expressions |
|
1841 |
*************************************************************************/ |
|
1842 |
||
1843 |
public void visitApply(JCMethodInvocation tree) { |
|
15385 | 1844 |
setTypeAnnotationPositions(tree.pos); |
10 | 1845 |
// Generate code for method. |
1846 |
Item m = genExpr(tree.meth, methodType); |
|
1847 |
// Generate code for all arguments, where the expected types are |
|
1848 |
// the parameters of the method's external type (that is, any implicit |
|
1849 |
// 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
|
1850 |
MethodSymbol msym = (MethodSymbol)TreeInfo.symbol(tree.meth); |
10 | 1851 |
genArgs(tree.args, |
16807
b442b47d3ae9
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents:
16801
diff
changeset
|
1852 |
msym.externalType(types).getParameterTypes()); |
b442b47d3ae9
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents:
16801
diff
changeset
|
1853 |
if (!msym.isDynamic()) { |
b442b47d3ae9
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents:
16801
diff
changeset
|
1854 |
code.statBegin(tree.pos); |
b442b47d3ae9
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents:
16801
diff
changeset
|
1855 |
} |
10 | 1856 |
result = m.invoke(); |
1857 |
} |
|
1858 |
||
1859 |
public void visitConditional(JCConditional tree) { |
|
1860 |
Chain thenExit = null; |
|
37754
7b4f67ce5cb5
8050993: There is no record for condition in ternary operator in LineNumberTable.
jlahoda
parents:
37753
diff
changeset
|
1861 |
code.statBegin(tree.cond.pos); |
10 | 1862 |
CondItem c = genCond(tree.cond, CRT_FLOW_CONTROLLER); |
1863 |
Chain elseChain = c.jumpFalse(); |
|
1864 |
if (!c.isFalse()) { |
|
1865 |
code.resolve(c.trueJumps); |
|
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
1866 |
int startpc = genCrt ? code.curCP() : 0; |
23391
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
22697
diff
changeset
|
1867 |
code.statBegin(tree.truepart.pos); |
10 | 1868 |
genExpr(tree.truepart, pt).load(); |
1869 |
code.state.forceStackTop(tree.type); |
|
1870 |
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
|
1871 |
startpc, code.curCP()); |
10 | 1872 |
thenExit = code.branch(goto_); |
1873 |
} |
|
1874 |
if (elseChain != null) { |
|
1875 |
code.resolve(elseChain); |
|
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
1876 |
int startpc = genCrt ? code.curCP() : 0; |
23391
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
22697
diff
changeset
|
1877 |
code.statBegin(tree.falsepart.pos); |
10 | 1878 |
genExpr(tree.falsepart, pt).load(); |
1879 |
code.state.forceStackTop(tree.type); |
|
1880 |
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
|
1881 |
startpc, code.curCP()); |
10 | 1882 |
} |
1883 |
code.resolve(thenExit); |
|
1884 |
result = items.makeStackItem(pt); |
|
1885 |
} |
|
1886 |
||
17578 | 1887 |
private void setTypeAnnotationPositions(int treePos) { |
1888 |
MethodSymbol meth = code.meth; |
|
1889 |
boolean initOrClinit = code.meth.getKind() == javax.lang.model.element.ElementKind.CONSTRUCTOR |
|
1890 |
|| code.meth.getKind() == javax.lang.model.element.ElementKind.STATIC_INIT; |
|
15385 | 1891 |
|
17578 | 1892 |
for (Attribute.TypeCompound ta : meth.getRawTypeAttributes()) { |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
1893 |
if (ta.hasUnknownPosition()) |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
1894 |
ta.tryFixPosition(); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
1895 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
1896 |
if (ta.position.matchesPos(treePos)) |
17578 | 1897 |
ta.position.updatePosOffset(code.cp); |
1898 |
} |
|
1899 |
||
1900 |
if (!initOrClinit) |
|
1901 |
return; |
|
15385 | 1902 |
|
17578 | 1903 |
for (Attribute.TypeCompound ta : meth.owner.getRawTypeAttributes()) { |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
1904 |
if (ta.hasUnknownPosition()) |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
1905 |
ta.tryFixPosition(); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
1906 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
1907 |
if (ta.position.matchesPos(treePos)) |
17578 | 1908 |
ta.position.updatePosOffset(code.cp); |
1909 |
} |
|
15385 | 1910 |
|
17578 | 1911 |
ClassSymbol clazz = meth.enclClass(); |
1912 |
for (Symbol s : new com.sun.tools.javac.model.FilteredMemberList(clazz.members())) { |
|
1913 |
if (!s.getKind().isField()) |
|
1914 |
continue; |
|
1915 |
||
1916 |
for (Attribute.TypeCompound ta : s.getRawTypeAttributes()) { |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
1917 |
if (ta.hasUnknownPosition()) |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
1918 |
ta.tryFixPosition(); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
1919 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
1920 |
if (ta.position.matchesPos(treePos)) |
17578 | 1921 |
ta.position.updatePosOffset(code.cp); |
1922 |
} |
|
1923 |
} |
|
1924 |
} |
|
15385 | 1925 |
|
10 | 1926 |
public void visitNewClass(JCNewClass tree) { |
1927 |
// Enclosing instances or anonymous classes should have been eliminated |
|
1928 |
// by now. |
|
8032 | 1929 |
Assert.check(tree.encl == null && tree.def == null); |
15385 | 1930 |
setTypeAnnotationPositions(tree.pos); |
10 | 1931 |
|
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
1932 |
code.emitop2(new_, checkDimension(tree.pos(), tree.type), PoolWriter::putClass); |
10 | 1933 |
code.emitop0(dup); |
1934 |
||
1935 |
// Generate code for all arguments, where the expected types are |
|
1936 |
// the parameters of the constructor's external type (that is, |
|
1937 |
// any implicit outer instance appears as first parameter). |
|
1938 |
genArgs(tree.args, tree.constructor.externalType(types).getParameterTypes()); |
|
1939 |
||
1940 |
items.makeMemberItem(tree.constructor, true).invoke(); |
|
1941 |
result = items.makeStackItem(tree.type); |
|
1942 |
} |
|
1943 |
||
1944 |
public void visitNewArray(JCNewArray tree) { |
|
15385 | 1945 |
setTypeAnnotationPositions(tree.pos); |
3149 | 1946 |
|
10 | 1947 |
if (tree.elems != null) { |
1948 |
Type elemtype = types.elemtype(tree.type); |
|
1949 |
loadIntConst(tree.elems.length()); |
|
1950 |
Item arr = makeNewArray(tree.pos(), tree.type, 1); |
|
1951 |
int i = 0; |
|
1952 |
for (List<JCExpression> l = tree.elems; l.nonEmpty(); l = l.tail) { |
|
1953 |
arr.duplicate(); |
|
1954 |
loadIntConst(i); |
|
1955 |
i++; |
|
1956 |
genExpr(l.head, elemtype).load(); |
|
1957 |
items.makeIndexedItem(elemtype).store(); |
|
1958 |
} |
|
1959 |
result = arr; |
|
1960 |
} else { |
|
1961 |
for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) { |
|
1962 |
genExpr(l.head, syms.intType).load(); |
|
1963 |
} |
|
1964 |
result = makeNewArray(tree.pos(), tree.type, tree.dims.length()); |
|
1965 |
} |
|
1966 |
} |
|
1967 |
//where |
|
1968 |
/** Generate code to create an array with given element type and number |
|
1969 |
* of dimensions. |
|
1970 |
*/ |
|
1971 |
Item makeNewArray(DiagnosticPosition pos, Type type, int ndims) { |
|
1972 |
Type elemtype = types.elemtype(type); |
|
7630 | 1973 |
if (types.dimensions(type) > ClassFile.MAX_DIMENSIONS) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45316
diff
changeset
|
1974 |
log.error(pos, Errors.LimitDimensions); |
10 | 1975 |
nerrs++; |
1976 |
} |
|
1977 |
int elemcode = Code.arraycode(elemtype); |
|
1978 |
if (elemcode == 0 || (elemcode == 1 && ndims == 1)) { |
|
1979 |
code.emitAnewarray(makeRef(pos, elemtype), type); |
|
1980 |
} else if (elemcode == 1) { |
|
1981 |
code.emitMultianewarray(ndims, makeRef(pos, type), type); |
|
1982 |
} else { |
|
1983 |
code.emitNewarray(elemcode, type); |
|
1984 |
} |
|
1985 |
return items.makeStackItem(type); |
|
1986 |
} |
|
1987 |
||
1988 |
public void visitParens(JCParens tree) { |
|
1989 |
result = genExpr(tree.expr, tree.expr.type); |
|
1990 |
} |
|
1991 |
||
1992 |
public void visitAssign(JCAssign tree) { |
|
1993 |
Item l = genExpr(tree.lhs, tree.lhs.type); |
|
1994 |
genExpr(tree.rhs, tree.lhs.type).load(); |
|
29777
95a89a2efd89
7040592: Gen.java: fix code for handling 'null' literal when expected type is array
sadayapalam
parents:
29295
diff
changeset
|
1995 |
if (tree.rhs.type.hasTag(BOT)) { |
95a89a2efd89
7040592: Gen.java: fix code for handling 'null' literal when expected type is array
sadayapalam
parents:
29295
diff
changeset
|
1996 |
/* This is just a case of widening reference conversion that per 5.1.5 simply calls |
95a89a2efd89
7040592: Gen.java: fix code for handling 'null' literal when expected type is array
sadayapalam
parents:
29295
diff
changeset
|
1997 |
for "regarding a reference as having some other type in a manner that can be proved |
95a89a2efd89
7040592: Gen.java: fix code for handling 'null' literal when expected type is array
sadayapalam
parents:
29295
diff
changeset
|
1998 |
correct at compile time." |
95a89a2efd89
7040592: Gen.java: fix code for handling 'null' literal when expected type is array
sadayapalam
parents:
29295
diff
changeset
|
1999 |
*/ |
95a89a2efd89
7040592: Gen.java: fix code for handling 'null' literal when expected type is array
sadayapalam
parents:
29295
diff
changeset
|
2000 |
code.state.forceStackTop(tree.lhs.type); |
95a89a2efd89
7040592: Gen.java: fix code for handling 'null' literal when expected type is array
sadayapalam
parents:
29295
diff
changeset
|
2001 |
} |
10 | 2002 |
result = items.makeAssignItem(l); |
2003 |
} |
|
2004 |
||
2005 |
public void visitAssignop(JCAssignOp tree) { |
|
39920
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39599
diff
changeset
|
2006 |
OperatorSymbol operator = tree.operator; |
10 | 2007 |
Item l; |
2008 |
if (operator.opcode == string_add) { |
|
35424 | 2009 |
l = concat.makeConcat(tree); |
10 | 2010 |
} else { |
2011 |
// Generate code for first expression |
|
2012 |
l = genExpr(tree.lhs, tree.lhs.type); |
|
2013 |
||
2014 |
// If we have an increment of -32768 to +32767 of a local |
|
2015 |
// int variable we can use an incr instruction instead of |
|
2016 |
// proceeding further. |
|
10950 | 2017 |
if ((tree.hasTag(PLUS_ASG) || tree.hasTag(MINUS_ASG)) && |
10 | 2018 |
l instanceof LocalItem && |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
2019 |
tree.lhs.type.getTag().isSubRangeOf(INT) && |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
2020 |
tree.rhs.type.getTag().isSubRangeOf(INT) && |
10 | 2021 |
tree.rhs.type.constValue() != null) { |
2022 |
int ival = ((Number) tree.rhs.type.constValue()).intValue(); |
|
10950 | 2023 |
if (tree.hasTag(MINUS_ASG)) ival = -ival; |
10 | 2024 |
((LocalItem)l).incr(ival); |
2025 |
result = l; |
|
2026 |
return; |
|
2027 |
} |
|
2028 |
// Otherwise, duplicate expression, load one copy |
|
2029 |
// and complete binary operation. |
|
2030 |
l.duplicate(); |
|
2031 |
l.coerce(operator.type.getParameterTypes().head).load(); |
|
2032 |
completeBinop(tree.lhs, tree.rhs, operator).coerce(tree.lhs.type); |
|
2033 |
} |
|
2034 |
result = items.makeAssignItem(l); |
|
2035 |
} |
|
2036 |
||
2037 |
public void visitUnary(JCUnary tree) { |
|
39920
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39599
diff
changeset
|
2038 |
OperatorSymbol operator = tree.operator; |
10950 | 2039 |
if (tree.hasTag(NOT)) { |
10 | 2040 |
CondItem od = genCond(tree.arg, false); |
2041 |
result = od.negate(); |
|
2042 |
} else { |
|
2043 |
Item od = genExpr(tree.arg, operator.type.getParameterTypes().head); |
|
2044 |
switch (tree.getTag()) { |
|
10950 | 2045 |
case POS: |
10 | 2046 |
result = od.load(); |
2047 |
break; |
|
10950 | 2048 |
case NEG: |
10 | 2049 |
result = od.load(); |
2050 |
code.emitop0(operator.opcode); |
|
2051 |
break; |
|
10950 | 2052 |
case COMPL: |
10 | 2053 |
result = od.load(); |
2054 |
emitMinusOne(od.typecode); |
|
2055 |
code.emitop0(operator.opcode); |
|
2056 |
break; |
|
10950 | 2057 |
case PREINC: case PREDEC: |
10 | 2058 |
od.duplicate(); |
2059 |
if (od instanceof LocalItem && |
|
2060 |
(operator.opcode == iadd || operator.opcode == isub)) { |
|
10950 | 2061 |
((LocalItem)od).incr(tree.hasTag(PREINC) ? 1 : -1); |
10 | 2062 |
result = od; |
2063 |
} else { |
|
2064 |
od.load(); |
|
2065 |
code.emitop0(one(od.typecode)); |
|
2066 |
code.emitop0(operator.opcode); |
|
2067 |
// Perform narrowing primitive conversion if byte, |
|
2068 |
// char, or short. Fix for 4304655. |
|
2069 |
if (od.typecode != INTcode && |
|
2070 |
Code.truncate(od.typecode) == INTcode) |
|
2071 |
code.emitop0(int2byte + od.typecode - BYTEcode); |
|
2072 |
result = items.makeAssignItem(od); |
|
2073 |
} |
|
2074 |
break; |
|
10950 | 2075 |
case POSTINC: case POSTDEC: |
10 | 2076 |
od.duplicate(); |
2077 |
if (od instanceof LocalItem && |
|
2078 |
(operator.opcode == iadd || operator.opcode == isub)) { |
|
2079 |
Item res = od.load(); |
|
10950 | 2080 |
((LocalItem)od).incr(tree.hasTag(POSTINC) ? 1 : -1); |
10 | 2081 |
result = res; |
2082 |
} else { |
|
2083 |
Item res = od.load(); |
|
2084 |
od.stash(od.typecode); |
|
2085 |
code.emitop0(one(od.typecode)); |
|
2086 |
code.emitop0(operator.opcode); |
|
2087 |
// Perform narrowing primitive conversion if byte, |
|
2088 |
// char, or short. Fix for 4304655. |
|
2089 |
if (od.typecode != INTcode && |
|
2090 |
Code.truncate(od.typecode) == INTcode) |
|
2091 |
code.emitop0(int2byte + od.typecode - BYTEcode); |
|
2092 |
od.store(); |
|
2093 |
result = res; |
|
2094 |
} |
|
2095 |
break; |
|
10950 | 2096 |
case NULLCHK: |
10 | 2097 |
result = od.load(); |
2098 |
code.emitop0(dup); |
|
45316
170696ddb377
8172880: Incorrect line number for NPE generated by instance-bound method reference
jlahoda
parents:
45220
diff
changeset
|
2099 |
genNullCheck(tree); |
10 | 2100 |
break; |
2101 |
default: |
|
8032 | 2102 |
Assert.error(); |
10 | 2103 |
} |
2104 |
} |
|
2105 |
} |
|
2106 |
||
2107 |
/** Generate a null check from the object value at stack top. */ |
|
45316
170696ddb377
8172880: Incorrect line number for NPE generated by instance-bound method reference
jlahoda
parents:
45220
diff
changeset
|
2108 |
private void genNullCheck(JCTree tree) { |
170696ddb377
8172880: Incorrect line number for NPE generated by instance-bound method reference
jlahoda
parents:
45220
diff
changeset
|
2109 |
code.statBegin(tree.pos); |
51047
860a3648c494
8028563: Remove javac support for 6/1.6 source and target values
darcy
parents:
50735
diff
changeset
|
2110 |
callMethod(tree.pos(), syms.objectsType, names.requireNonNull, |
860a3648c494
8028563: Remove javac support for 6/1.6 source and target values
darcy
parents:
50735
diff
changeset
|
2111 |
List.of(syms.objectType), true); |
10 | 2112 |
code.emitop0(pop); |
2113 |
} |
|
2114 |
||
2115 |
public void visitBinary(JCBinary tree) { |
|
39920
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39599
diff
changeset
|
2116 |
OperatorSymbol operator = tree.operator; |
10 | 2117 |
if (operator.opcode == string_add) { |
35424 | 2118 |
result = concat.makeConcat(tree); |
10950 | 2119 |
} else if (tree.hasTag(AND)) { |
10 | 2120 |
CondItem lcond = genCond(tree.lhs, CRT_FLOW_CONTROLLER); |
2121 |
if (!lcond.isFalse()) { |
|
2122 |
Chain falseJumps = lcond.jumpFalse(); |
|
2123 |
code.resolve(lcond.trueJumps); |
|
2124 |
CondItem rcond = genCond(tree.rhs, CRT_FLOW_TARGET); |
|
2125 |
result = items. |
|
2126 |
makeCondItem(rcond.opcode, |
|
2127 |
rcond.trueJumps, |
|
5004
6c2694dc2da0
6929544: langtools source code uses statics qualified by instance variables
jjg
parents:
4875
diff
changeset
|
2128 |
Code.mergeChains(falseJumps, |
10 | 2129 |
rcond.falseJumps)); |
2130 |
} else { |
|
2131 |
result = lcond; |
|
2132 |
} |
|
10950 | 2133 |
} else if (tree.hasTag(OR)) { |
10 | 2134 |
CondItem lcond = genCond(tree.lhs, CRT_FLOW_CONTROLLER); |
2135 |
if (!lcond.isTrue()) { |
|
2136 |
Chain trueJumps = lcond.jumpTrue(); |
|
2137 |
code.resolve(lcond.falseJumps); |
|
2138 |
CondItem rcond = genCond(tree.rhs, CRT_FLOW_TARGET); |
|
2139 |
result = items. |
|
2140 |
makeCondItem(rcond.opcode, |
|
5004
6c2694dc2da0
6929544: langtools source code uses statics qualified by instance variables
jjg
parents:
4875
diff
changeset
|
2141 |
Code.mergeChains(trueJumps, rcond.trueJumps), |
10 | 2142 |
rcond.falseJumps); |
2143 |
} else { |
|
2144 |
result = lcond; |
|
2145 |
} |
|
2146 |
} else { |
|
2147 |
Item od = genExpr(tree.lhs, operator.type.getParameterTypes().head); |
|
2148 |
od.load(); |
|
2149 |
result = completeBinop(tree.lhs, tree.rhs, operator); |
|
2150 |
} |
|
2151 |
} |
|
2152 |
||
2153 |
||
2154 |
/** Complete generating code for operation, with left operand |
|
2155 |
* already on stack. |
|
2156 |
* @param lhs The tree representing the left operand. |
|
2157 |
* @param rhs The tree representing the right operand. |
|
2158 |
* @param operator The operator symbol. |
|
2159 |
*/ |
|
2160 |
Item completeBinop(JCTree lhs, JCTree rhs, OperatorSymbol operator) { |
|
2161 |
MethodType optype = (MethodType)operator.type; |
|
2162 |
int opcode = operator.opcode; |
|
2163 |
if (opcode >= if_icmpeq && opcode <= if_icmple && |
|
2164 |
rhs.type.constValue() instanceof Number && |
|
2165 |
((Number) rhs.type.constValue()).intValue() == 0) { |
|
2166 |
opcode = opcode + (ifeq - if_icmpeq); |
|
2167 |
} else if (opcode >= if_acmpeq && opcode <= if_acmpne && |
|
2168 |
TreeInfo.isNull(rhs)) { |
|
2169 |
opcode = opcode + (if_acmp_null - if_acmpeq); |
|
2170 |
} else { |
|
2171 |
// The expected type of the right operand is |
|
2172 |
// the second parameter type of the operator, except for |
|
2173 |
// shifts with long shiftcount, where we convert the opcode |
|
2174 |
// to a short shift and the expected type to int. |
|
2175 |
Type rtype = operator.erasure(types).getParameterTypes().tail.head; |
|
2176 |
if (opcode >= ishll && opcode <= lushrl) { |
|
2177 |
opcode = opcode + (ishl - ishll); |
|
2178 |
rtype = syms.intType; |
|
2179 |
} |
|
2180 |
// Generate code for right operand and load. |
|
2181 |
genExpr(rhs, rtype).load(); |
|
2182 |
// If there are two consecutive opcode instructions, |
|
2183 |
// emit the first now. |
|
2184 |
if (opcode >= (1 << preShift)) { |
|
2185 |
code.emitop0(opcode >> preShift); |
|
2186 |
opcode = opcode & 0xFF; |
|
2187 |
} |
|
2188 |
} |
|
2189 |
if (opcode >= ifeq && opcode <= if_acmpne || |
|
2190 |
opcode == if_acmp_null || opcode == if_acmp_nonnull) { |
|
2191 |
return items.makeCondItem(opcode); |
|
2192 |
} else { |
|
2193 |
code.emitop0(opcode); |
|
2194 |
return items.makeStackItem(optype.restype); |
|
2195 |
} |
|
2196 |
} |
|
2197 |
||
2198 |
public void visitTypeCast(JCTypeCast tree) { |
|
35418
8681d57fc3f8
8144168: No type annotations generated for nested lambdas
sadayapalam
parents:
33371
diff
changeset
|
2199 |
result = genExpr(tree.expr, tree.clazz.type).load(); |
15385 | 2200 |
setTypeAnnotationPositions(tree.pos); |
10 | 2201 |
// Additional code is only needed if we cast to a reference type |
2202 |
// which is not statically a supertype of the expression's type. |
|
2203 |
// For basic types, the coerce(...) in genExpr(...) will do |
|
2204 |
// the conversion. |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
2205 |
if (!tree.clazz.type.isPrimitive() && |
28800
35f9042d53b3
8069265: ClassCastException when compiled with JDK 9b08+, JDK8 compiles OK.
jlahoda
parents:
28338
diff
changeset
|
2206 |
!types.isSameType(tree.expr.type, tree.clazz.type) && |
35f9042d53b3
8069265: ClassCastException when compiled with JDK 9b08+, JDK8 compiles OK.
jlahoda
parents:
28338
diff
changeset
|
2207 |
types.asSuper(tree.expr.type, tree.clazz.type.tsym) == null) { |
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
2208 |
code.emitop2(checkcast, checkDimension(tree.pos(), tree.clazz.type), PoolWriter::putClass); |
10 | 2209 |
} |
2210 |
} |
|
2211 |
||
2212 |
public void visitWildcard(JCWildcard tree) { |
|
2213 |
throw new AssertionError(this.getClass().getName()); |
|
2214 |
} |
|
2215 |
||
2216 |
public void visitTypeTest(JCInstanceOf tree) { |
|
35418
8681d57fc3f8
8144168: No type annotations generated for nested lambdas
sadayapalam
parents:
33371
diff
changeset
|
2217 |
genExpr(tree.expr, tree.expr.type).load(); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
2218 |
setTypeAnnotationPositions(tree.pos); |
10 | 2219 |
code.emitop2(instanceof_, makeRef(tree.pos(), tree.clazz.type)); |
2220 |
result = items.makeStackItem(syms.booleanType); |
|
2221 |
} |
|
2222 |
||
2223 |
public void visitIndexed(JCArrayAccess tree) { |
|
2224 |
genExpr(tree.indexed, tree.indexed.type).load(); |
|
2225 |
genExpr(tree.index, syms.intType).load(); |
|
2226 |
result = items.makeIndexedItem(tree.type); |
|
2227 |
} |
|
2228 |
||
2229 |
public void visitIdent(JCIdent tree) { |
|
2230 |
Symbol sym = tree.sym; |
|
2231 |
if (tree.name == names._this || tree.name == names._super) { |
|
2232 |
Item res = tree.name == names._this |
|
2233 |
? items.makeThisItem() |
|
2234 |
: items.makeSuperItem(); |
|
2235 |
if (sym.kind == MTH) { |
|
2236 |
// Generate code to address the constructor. |
|
2237 |
res.load(); |
|
2238 |
res = items.makeMemberItem(sym, true); |
|
2239 |
} |
|
2240 |
result = res; |
|
54762 | 2241 |
} else if (isInvokeDynamic(sym) || isConstantDynamic(sym)) { |
2242 |
if (isConstantDynamic(sym)) { |
|
2243 |
setTypeAnnotationPositions(tree.pos); |
|
2244 |
} |
|
2245 |
result = items.makeDynamicItem(sym); |
|
52936
9745e4e36dd1
8214114: Switch expressions with try-catch statements
jlahoda
parents:
52794
diff
changeset
|
2246 |
} else if (sym.kind == VAR && (sym.owner.kind == MTH || sym.owner.kind == VAR)) { |
10 | 2247 |
result = items.makeLocalItem((VarSymbol)sym); |
2248 |
} else if ((sym.flags() & STATIC) != 0) { |
|
2249 |
if (!isAccessSuper(env.enclMethod)) |
|
2250 |
sym = binaryQualifier(sym, env.enclClass.type); |
|
2251 |
result = items.makeStaticItem(sym); |
|
2252 |
} else { |
|
2253 |
items.makeThisItem().load(); |
|
2254 |
sym = binaryQualifier(sym, env.enclClass.type); |
|
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49280
diff
changeset
|
2255 |
result = items.makeMemberItem(sym, nonVirtualForPrivateAccess(sym)); |
10 | 2256 |
} |
2257 |
} |
|
2258 |
||
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49280
diff
changeset
|
2259 |
//where |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49280
diff
changeset
|
2260 |
private boolean nonVirtualForPrivateAccess(Symbol sym) { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49280
diff
changeset
|
2261 |
boolean useVirtual = target.hasVirtualPrivateInvoke() && |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49280
diff
changeset
|
2262 |
!disableVirtualizedPrivateInvoke; |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49280
diff
changeset
|
2263 |
return !useVirtual && ((sym.flags() & PRIVATE) != 0); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49280
diff
changeset
|
2264 |
} |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49280
diff
changeset
|
2265 |
|
10 | 2266 |
public void visitSelect(JCFieldAccess tree) { |
2267 |
Symbol sym = tree.sym; |
|
2268 |
||
2269 |
if (tree.name == names._class) { |
|
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
2270 |
code.emitLdc((LoadableConstant)checkDimension(tree.pos(), tree.selected.type)); |
10 | 2271 |
result = items.makeStackItem(pt); |
2272 |
return; |
|
15385 | 2273 |
} |
10 | 2274 |
|
2275 |
Symbol ssym = TreeInfo.symbol(tree.selected); |
|
2276 |
||
2277 |
// Are we selecting via super? |
|
2278 |
boolean selectSuper = |
|
2279 |
ssym != null && (ssym.kind == TYP || ssym.name == names._super); |
|
2280 |
||
2281 |
// Are we accessing a member of the superclass in an access method |
|
2282 |
// resulting from a qualified super? |
|
2283 |
boolean accessSuper = isAccessSuper(env.enclMethod); |
|
2284 |
||
2285 |
Item base = (selectSuper) |
|
2286 |
? items.makeSuperItem() |
|
2287 |
: genExpr(tree.selected, tree.selected.type); |
|
2288 |
||
2289 |
if (sym.kind == VAR && ((VarSymbol) sym).getConstValue() != null) { |
|
2290 |
// We are seeing a variable that is constant but its selecting |
|
2291 |
// expression is not. |
|
2292 |
if ((sym.flags() & STATIC) != 0) { |
|
2293 |
if (!selectSuper && (ssym == null || ssym.kind != TYP)) |
|
2294 |
base = base.load(); |
|
2295 |
base.drop(); |
|
2296 |
} else { |
|
2297 |
base.load(); |
|
45316
170696ddb377
8172880: Incorrect line number for NPE generated by instance-bound method reference
jlahoda
parents:
45220
diff
changeset
|
2298 |
genNullCheck(tree.selected); |
10 | 2299 |
} |
2300 |
result = items. |
|
2301 |
makeImmediateItem(sym.type, ((VarSymbol) sym).getConstValue()); |
|
2302 |
} else { |
|
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13844
diff
changeset
|
2303 |
if (isInvokeDynamic(sym)) { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13844
diff
changeset
|
2304 |
result = items.makeDynamicItem(sym); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13844
diff
changeset
|
2305 |
return; |
21897
ba025087b9f9
8027789: Access method for Outer.super.m() references indirect superclass
jlahoda
parents:
21498
diff
changeset
|
2306 |
} else { |
10 | 2307 |
sym = binaryQualifier(sym, tree.selected.type); |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13844
diff
changeset
|
2308 |
} |
10 | 2309 |
if ((sym.flags() & STATIC) != 0) { |
2310 |
if (!selectSuper && (ssym == null || ssym.kind != TYP)) |
|
2311 |
base = base.load(); |
|
2312 |
base.drop(); |
|
2313 |
result = items.makeStaticItem(sym); |
|
2314 |
} else { |
|
2315 |
base.load(); |
|
2316 |
if (sym == syms.lengthVar) { |
|
2317 |
code.emitop0(arraylength); |
|
2318 |
result = items.makeStackItem(syms.intType); |
|
2319 |
} else { |
|
2320 |
result = items. |
|
2321 |
makeMemberItem(sym, |
|
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49280
diff
changeset
|
2322 |
nonVirtualForPrivateAccess(sym) || |
10 | 2323 |
selectSuper || accessSuper); |
2324 |
} |
|
2325 |
} |
|
2326 |
} |
|
2327 |
} |
|
2328 |
||
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13844
diff
changeset
|
2329 |
public boolean isInvokeDynamic(Symbol sym) { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13844
diff
changeset
|
2330 |
return sym.kind == MTH && ((MethodSymbol)sym).isDynamic(); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13844
diff
changeset
|
2331 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13844
diff
changeset
|
2332 |
|
10 | 2333 |
public void visitLiteral(JCLiteral tree) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
2334 |
if (tree.type.hasTag(BOT)) { |
10 | 2335 |
code.emitop0(aconst_null); |
29777
95a89a2efd89
7040592: Gen.java: fix code for handling 'null' literal when expected type is array
sadayapalam
parents:
29295
diff
changeset
|
2336 |
result = items.makeStackItem(tree.type); |
10 | 2337 |
} |
2338 |
else |
|
2339 |
result = items.makeImmediateItem(tree.type, tree.value); |
|
2340 |
} |
|
2341 |
||
2342 |
public void visitLetExpr(LetExpr tree) { |
|
54894
382101e97784
8222169: java.lang.AssertionError switch expression in ternary operator - ?
jlahoda
parents:
54762
diff
changeset
|
2343 |
code.resolvePending(); |
382101e97784
8222169: java.lang.AssertionError switch expression in ternary operator - ?
jlahoda
parents:
54762
diff
changeset
|
2344 |
|
10 | 2345 |
int limit = code.nextreg; |
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
2346 |
int prevLetExprStart = code.setLetExprStackPos(code.state.stacksize); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
2347 |
try { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
2348 |
genStats(tree.defs, env); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
2349 |
} finally { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
2350 |
code.setLetExprStackPos(prevLetExprStart); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
51047
diff
changeset
|
2351 |
} |
10 | 2352 |
result = genExpr(tree.expr, tree.expr.type).load(); |
2353 |
code.endScopes(limit); |
|
2354 |
} |
|
2355 |
||
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
2356 |
private void generateReferencesToPrunedTree(ClassSymbol classSymbol) { |
14721
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
2357 |
List<JCTree> prunedInfo = lower.prunedTree.get(classSymbol); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
2358 |
if (prunedInfo != null) { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
2359 |
for (JCTree prunedTree: prunedInfo) { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
2360 |
prunedTree.accept(classReferenceVisitor); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
2361 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
2362 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
2363 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
14359
diff
changeset
|
2364 |
|
10 | 2365 |
/* ************************************************************************ |
2366 |
* main method |
|
2367 |
*************************************************************************/ |
|
2368 |
||
2369 |
/** Generate code for a class definition. |
|
2370 |
* @param env The attribution environment that belongs to the |
|
2371 |
* outermost class containing this class definition. |
|
2372 |
* We need this for resolving some additional symbols. |
|
2373 |
* @param cdef The tree representing the class definition. |
|
2374 |
* @return True if code is generated with no errors. |
|
2375 |
*/ |
|
2376 |
public boolean genClass(Env<AttrContext> env, JCClassDecl cdef) { |
|
2377 |
try { |
|
2378 |
attrEnv = env; |
|
2379 |
ClassSymbol c = cdef.sym; |
|
2380 |
this.toplevel = env.toplevel; |
|
11055 | 2381 |
this.endPosTable = toplevel.endPositions; |
31000
18bc6fadeb4e
8073372: Redundant CONSTANT_Class entry not generated for inlined constant
vromero
parents:
30406
diff
changeset
|
2382 |
/* method normalizeDefs() can add references to external classes into the constant pool |
18bc6fadeb4e
8073372: Redundant CONSTANT_Class entry not generated for inlined constant
vromero
parents:
30406
diff
changeset
|
2383 |
*/ |
18bc6fadeb4e
8073372: Redundant CONSTANT_Class entry not generated for inlined constant
vromero
parents:
30406
diff
changeset
|
2384 |
cdef.defs = normalizeDefs(cdef.defs, c); |
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
2385 |
generateReferencesToPrunedTree(c); |
22163 | 2386 |
Env<GenContext> localEnv = new Env<>(cdef, new GenContext()); |
10 | 2387 |
localEnv.toplevel = env.toplevel; |
2388 |
localEnv.enclClass = cdef; |
|
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
2389 |
|
10 | 2390 |
for (List<JCTree> l = cdef.defs; l.nonEmpty(); l = l.tail) { |
2391 |
genDef(l.head, localEnv); |
|
2392 |
} |
|
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
52936
diff
changeset
|
2393 |
if (poolWriter.size() > PoolWriter.MAX_ENTRIES) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45316
diff
changeset
|
2394 |
log.error(cdef.pos(), Errors.LimitPool); |
10 | 2395 |
nerrs++; |
2396 |
} |
|
2397 |
if (nerrs != 0) { |
|
2398 |
// if errors, discard code |
|
2399 |
for (List<JCTree> l = cdef.defs; l.nonEmpty(); l = l.tail) { |
|
10950 | 2400 |
if (l.head.hasTag(METHODDEF)) |
10 | 2401 |
((JCMethodDecl) l.head).sym.code = null; |
2402 |
} |
|
2403 |
} |
|
2404 |
cdef.defs = List.nil(); // discard trees |
|
2405 |
return nerrs == 0; |
|
2406 |
} finally { |
|
2407 |
// note: this method does NOT support recursion. |
|
2408 |
attrEnv = null; |
|
2409 |
this.env = null; |
|
2410 |
toplevel = null; |
|
11055 | 2411 |
endPosTable = null; |
10 | 2412 |
nerrs = 0; |
2413 |
} |
|
2414 |
} |
|
2415 |
||
2416 |
/* ************************************************************************ |
|
2417 |
* Auxiliary classes |
|
2418 |
*************************************************************************/ |
|
2419 |
||
2420 |
/** An abstract class for finalizer generation. |
|
2421 |
*/ |
|
2422 |
abstract class GenFinalizer { |
|
2423 |
/** Generate code to clean up when unwinding. */ |
|
2424 |
abstract void gen(); |
|
2425 |
||
2426 |
/** Generate code to clean up at last. */ |
|
2427 |
abstract void genLast(); |
|
2428 |
||
2429 |
/** Does this finalizer have some nontrivial cleanup to perform? */ |
|
2430 |
boolean hasFinalizer() { return true; } |
|
49280
c2a3a2aa2475
8194978: Javac produces dead code for try-with-resource
jlahoda
parents:
47216
diff
changeset
|
2431 |
|
c2a3a2aa2475
8194978: Javac produces dead code for try-with-resource
jlahoda
parents:
47216
diff
changeset
|
2432 |
/** Should be invoked after the try's body has been visited. */ |
c2a3a2aa2475
8194978: Javac produces dead code for try-with-resource
jlahoda
parents:
47216
diff
changeset
|
2433 |
void afterBody() {} |
10 | 2434 |
} |
2435 |
||
2436 |
/** code generation contexts, |
|
2437 |
* to be used as type parameter for environments. |
|
2438 |
*/ |
|
2439 |
static class GenContext { |
|
2440 |
||
2441 |
/** A chain for all unresolved jumps that exit the current environment. |
|
2442 |
*/ |
|
2443 |
Chain exit = null; |
|
2444 |
||
2445 |
/** A chain for all unresolved jumps that continue in the |
|
2446 |
* current environment. |
|
2447 |
*/ |
|
2448 |
Chain cont = null; |
|
2449 |
||
2450 |
/** A closure that generates the finalizer of the current environment. |
|
2451 |
* Only set for Synchronized and Try contexts. |
|
2452 |
*/ |
|
2453 |
GenFinalizer finalize = null; |
|
2454 |
||
2455 |
/** Is this a switch statement? If so, allocate registers |
|
2456 |
* even when the variable declaration is unreachable. |
|
2457 |
*/ |
|
2458 |
boolean isSwitch = false; |
|
2459 |
||
2460 |
/** A list buffer containing all gaps in the finalizer range, |
|
2461 |
* where a catch all exception should not apply. |
|
2462 |
*/ |
|
2463 |
ListBuffer<Integer> gaps = null; |
|
2464 |
||
2465 |
/** Add given chain to exit chain. |
|
2466 |
*/ |
|
2467 |
void addExit(Chain c) { |
|
2468 |
exit = Code.mergeChains(c, exit); |
|
2469 |
} |
|
2470 |
||
2471 |
/** Add given chain to cont chain. |
|
2472 |
*/ |
|
2473 |
void addCont(Chain c) { |
|
2474 |
cont = Code.mergeChains(c, cont); |
|
2475 |
} |
|
2476 |
} |
|
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19923
diff
changeset
|
2477 |
|
10 | 2478 |
} |