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