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