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