src/share/classes/com/sun/tools/javac/jvm/Gen.java

Tue, 26 Nov 2013 15:33:12 +0100

author
jlahoda
date
Tue, 26 Nov 2013 15:33:12 +0100
changeset 2207
756ae3791c45
parent 2167
d2fa3f7e964e
child 2376
12f99d1f23d9
permissions
-rw-r--r--

8027789: Access method for Outer.super.m() references indirect superclass
Summary: Internally convert the qualified super access to an equivalent of an unqualified super access inside the access method.
Reviewed-by: vromero, jjg

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

mercurial