1 /*
   2  * Copyright (c) 1999, 2018, 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.code.*;
  29 import com.sun.tools.javac.code.Symbol.*;
  30 import com.sun.tools.javac.code.Types.UniqueType;
  31 import com.sun.tools.javac.resources.CompilerProperties.Errors;
  32 import com.sun.tools.javac.jvm.Pool.DynamicVariable;
  33 import com.sun.tools.javac.tree.JCTree;
  34 import com.sun.tools.javac.util.*;
  35 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
  36 
  37 import static com.sun.tools.javac.code.TypeTag.BOT;
  38 import static com.sun.tools.javac.code.TypeTag.INT;
  39 import static com.sun.tools.javac.jvm.ByteCodes.*;
  40 import static com.sun.tools.javac.jvm.UninitializedType.*;
  41 import static com.sun.tools.javac.jvm.ClassWriter.StackMapTableFrame;
  42 
  43 /** An internal structure that corresponds to the code attribute of
  44  *  methods in a classfile. The class also provides some utility operations to
  45  *  generate bytecode instructions.
  46  *
  47  *  <p><b>This is NOT part of any supported API.
  48  *  If you write code that depends on this, you do so at your own risk.
  49  *  This code and its internal interfaces are subject to change or
  50  *  deletion without notice.</b>
  51  */
  52 public class Code {
  53 
  54     public final boolean debugCode;
  55     public final boolean needStackMap;
  56 
  57     public enum StackMapFormat {
  58         NONE,
  59         CLDC {
  60             Name getAttributeName(Names names) {
  61                 return names.StackMap;
  62             }
  63         },
  64         JSR202 {
  65             Name getAttributeName(Names names) {
  66                 return names.StackMapTable;
  67             }
  68         };
  69         Name getAttributeName(Names names) {
  70             return names.empty;
  71         }
  72     }
  73 
  74     final Types types;
  75     final Symtab syms;
  76 
  77 /*---------- classfile fields: --------------- */
  78 
  79     /** The maximum stack size.
  80      */
  81     public int max_stack = 0;
  82 
  83     /** The maximum number of local variable slots.
  84      */
  85     public int max_locals = 0;
  86 
  87     /** The code buffer.
  88      */
  89     public byte[] code = new byte[64];
  90 
  91     /** the current code pointer.
  92      */
  93     public int cp = 0;
  94 
  95     /** Check the code against VM spec limits; if
  96      *  problems report them and return true.
  97      */
  98     public boolean checkLimits(DiagnosticPosition pos, Log log) {
  99         if (cp > ClassFile.MAX_CODE) {
 100             log.error(pos, Errors.LimitCode);
 101             return true;
 102         }
 103         if (max_locals > ClassFile.MAX_LOCALS) {
 104             log.error(pos, Errors.LimitLocals);
 105             return true;
 106         }
 107         if (max_stack > ClassFile.MAX_STACK) {
 108             log.error(pos, Errors.LimitStack);
 109             return true;
 110         }
 111         return false;
 112     }
 113 
 114     /** A buffer for expression catch data. Each enter is a vector
 115      *  of four unsigned shorts.
 116      */
 117     ListBuffer<char[]> catchInfo = new ListBuffer<>();
 118 
 119     /** A buffer for line number information. Each entry is a vector
 120      *  of two unsigned shorts.
 121      */
 122     List<char[]> lineInfo = List.nil(); // handled in stack fashion
 123 
 124     /** The CharacterRangeTable
 125      */
 126     public CRTable crt;
 127 
 128 /*---------- internal fields: --------------- */
 129 
 130     /** Are we generating code with jumps &ge; 32K?
 131      */
 132     public boolean fatcode;
 133 
 134     /** Code generation enabled?
 135      */
 136     private boolean alive = true;
 137 
 138     /** The current machine state (registers and stack).
 139      */
 140     State state;
 141 
 142     /** Is it forbidden to compactify code, because something is
 143      *  pointing to current location?
 144      */
 145     private boolean fixedPc = false;
 146 
 147     /** The next available register.
 148      */
 149     public int nextreg = 0;
 150 
 151     /** A chain for jumps to be resolved before the next opcode is emitted.
 152      *  We do this lazily to avoid jumps to jumps.
 153      */
 154     Chain pendingJumps = null;
 155 
 156     /** The position of the currently statement, if we are at the
 157      *  start of this statement, NOPOS otherwise.
 158      *  We need this to emit line numbers lazily, which we need to do
 159      *  because of jump-to-jump optimization.
 160      */
 161     int pendingStatPos = Position.NOPOS;
 162 
 163     /** Set true when a stackMap is needed at the current PC. */
 164     boolean pendingStackMap = false;
 165 
 166     /** The stack map format to be generated. */
 167     StackMapFormat stackMap;
 168 
 169     /** Switch: emit variable debug info.
 170      */
 171     boolean varDebugInfo;
 172 
 173     /** Switch: emit line number info.
 174      */
 175     boolean lineDebugInfo;
 176 
 177     /** Emit line number info if map supplied
 178      */
 179     Position.LineMap lineMap;
 180 
 181     /** The constant pool of the current class.
 182      */
 183     final Pool pool;
 184 
 185     final MethodSymbol meth;
 186 
 187     private int letExprStackPos = 0;
 188 
 189     /** Construct a code object, given the settings of the fatcode,
 190      *  debugging info switches and the CharacterRangeTable.
 191      */
 192     public Code(MethodSymbol meth,
 193                 boolean fatcode,
 194                 Position.LineMap lineMap,
 195                 boolean varDebugInfo,
 196                 StackMapFormat stackMap,
 197                 boolean debugCode,
 198                 CRTable crt,
 199                 Symtab syms,
 200                 Types types,
 201                 Pool pool) {
 202         this.meth = meth;
 203         this.fatcode = fatcode;
 204         this.lineMap = lineMap;
 205         this.lineDebugInfo = lineMap != null;
 206         this.varDebugInfo = varDebugInfo;
 207         this.crt = crt;
 208         this.syms = syms;
 209         this.types = types;
 210         this.debugCode = debugCode;
 211         this.stackMap = stackMap;
 212         switch (stackMap) {
 213         case CLDC:
 214         case JSR202:
 215             this.needStackMap = true;
 216             break;
 217         default:
 218             this.needStackMap = false;
 219         }
 220         state = new State();
 221         lvar = new LocalVar[20];
 222         this.pool = pool;
 223     }
 224 
 225 
 226 /* **************************************************************************
 227  * Typecodes & related stuff
 228  ****************************************************************************/
 229 
 230     /** Given a type, return its type code (used implicitly in the
 231      *  JVM architecture).
 232      */
 233     public static int typecode(Type type) {
 234         switch (type.getTag()) {
 235         case BYTE: return BYTEcode;
 236         case SHORT: return SHORTcode;
 237         case CHAR: return CHARcode;
 238         case INT: return INTcode;
 239         case LONG: return LONGcode;
 240         case FLOAT: return FLOATcode;
 241         case DOUBLE: return DOUBLEcode;
 242         case BOOLEAN: return BYTEcode;
 243         case VOID: return VOIDcode;
 244         case CLASS:
 245         case ARRAY:
 246         case METHOD:
 247         case BOT:
 248         case TYPEVAR:
 249         case UNINITIALIZED_THIS:
 250         case UNINITIALIZED_OBJECT:
 251             return OBJECTcode;
 252         default: throw new AssertionError("typecode " + type.getTag());
 253         }
 254     }
 255 
 256     /** Collapse type code for subtypes of int to INTcode.
 257      */
 258     public static int truncate(int tc) {
 259         switch (tc) {
 260         case BYTEcode: case SHORTcode: case CHARcode: return INTcode;
 261         default: return tc;
 262         }
 263     }
 264 
 265     /** The width in bytes of objects of the type.
 266      */
 267     public static int width(int typecode) {
 268         switch (typecode) {
 269         case LONGcode: case DOUBLEcode: return 2;
 270         case VOIDcode: return 0;
 271         default: return 1;
 272         }
 273     }
 274 
 275     public static int width(Type type) {
 276         return type == null ? 1 : width(typecode(type));
 277     }
 278 
 279     /** The total width taken up by a vector of objects.
 280      */
 281     public static int width(List<Type> types) {
 282         int w = 0;
 283         for (List<Type> l = types; l.nonEmpty(); l = l.tail)
 284             w = w + width(l.head);
 285         return w;
 286     }
 287 
 288     /** Given a type, return its code for allocating arrays of that type.
 289      */
 290     public static int arraycode(Type type) {
 291         switch (type.getTag()) {
 292         case BYTE: return 8;
 293         case BOOLEAN: return 4;
 294         case SHORT: return 9;
 295         case CHAR: return 5;
 296         case INT: return 10;
 297         case LONG: return 11;
 298         case FLOAT: return 6;
 299         case DOUBLE: return 7;
 300         case CLASS: return 0;
 301         case ARRAY: return 1;
 302         default: throw new AssertionError("arraycode " + type);
 303         }
 304     }
 305 
 306 
 307 /* **************************************************************************
 308  * Emit code
 309  ****************************************************************************/
 310 
 311     /** The current output code pointer.
 312      */
 313     public int curCP() {
 314         /*
 315          * This method has side-effects because calling it can indirectly provoke
 316          *  extra code generation, like goto instructions, depending on the context
 317          *  where it's called.
 318          *  Use with care or even better avoid using it.
 319          */
 320         if (pendingJumps != null) {
 321             resolvePending();
 322         }
 323         if (pendingStatPos != Position.NOPOS) {
 324             markStatBegin();
 325         }
 326         fixedPc = true;
 327         return cp;
 328     }
 329 
 330     /** Emit a byte of code.
 331      */
 332     private  void emit1(int od) {
 333         if (!alive) return;
 334         code = ArrayUtils.ensureCapacity(code, cp);
 335         code[cp++] = (byte)od;
 336     }
 337 
 338     /** Emit two bytes of code.
 339      */
 340     private void emit2(int od) {
 341         if (!alive) return;
 342         if (cp + 2 > code.length) {
 343             emit1(od >> 8);
 344             emit1(od);
 345         } else {
 346             code[cp++] = (byte)(od >> 8);
 347             code[cp++] = (byte)od;
 348         }
 349     }
 350 
 351     /** Emit four bytes of code.
 352      */
 353     public void emit4(int od) {
 354         if (!alive) return;
 355         if (cp + 4 > code.length) {
 356             emit1(od >> 24);
 357             emit1(od >> 16);
 358             emit1(od >> 8);
 359             emit1(od);
 360         } else {
 361             code[cp++] = (byte)(od >> 24);
 362             code[cp++] = (byte)(od >> 16);
 363             code[cp++] = (byte)(od >> 8);
 364             code[cp++] = (byte)od;
 365         }
 366     }
 367 
 368     /** Emit an opcode.
 369      */
 370     private void emitop(int op) {
 371         if (pendingJumps != null) resolvePending();
 372         if (alive) {
 373             if (pendingStatPos != Position.NOPOS)
 374                 markStatBegin();
 375             if (pendingStackMap) {
 376                 pendingStackMap = false;
 377                 emitStackMap();
 378             }
 379             if (debugCode)
 380                 System.err.println("emit@" + cp + " stack=" +
 381                                    state.stacksize + ": " +
 382                                    mnem(op));
 383             emit1(op);
 384         }
 385     }
 386 
 387     void postop() {
 388         Assert.check(alive || isStatementStart());
 389     }
 390 
 391     /** Emit a ldc (or ldc_w) instruction, taking into account operand size
 392     */
 393     public void emitLdc(int od) {
 394         if (od <= 255) {
 395             emitop1(ldc1, od);
 396         }
 397         else {
 398             emitop2(ldc2, od);
 399         }
 400     }
 401 
 402     /** Emit a multinewarray instruction.
 403      */
 404     public void emitMultianewarray(int ndims, int type, Type arrayType) {
 405         emitop(multianewarray);
 406         if (!alive) return;
 407         emit2(type);
 408         emit1(ndims);
 409         state.pop(ndims);
 410         state.push(arrayType);
 411     }
 412 
 413     /** Emit newarray.
 414      */
 415     public void emitNewarray(int elemcode, Type arrayType) {
 416         emitop(newarray);
 417         if (!alive) return;
 418         emit1(elemcode);
 419         state.pop(1); // count
 420         state.push(arrayType);
 421     }
 422 
 423     /** Emit anewarray.
 424      */
 425     public void emitAnewarray(int od, Type arrayType) {
 426         emitop(anewarray);
 427         if (!alive) return;
 428         emit2(od);
 429         state.pop(1);
 430         state.push(arrayType);
 431     }
 432 
 433     /** Emit an invokeinterface instruction.
 434      */
 435     public void emitInvokeinterface(int meth, Type mtype) {
 436         int argsize = width(mtype.getParameterTypes());
 437         emitop(invokeinterface);
 438         if (!alive) return;
 439         emit2(meth);
 440         emit1(argsize + 1);
 441         emit1(0);
 442         state.pop(argsize + 1);
 443         state.push(mtype.getReturnType());
 444     }
 445 
 446     /** Emit an invokespecial instruction.
 447      */
 448     public void emitInvokespecial(int meth, Type mtype) {
 449         int argsize = width(mtype.getParameterTypes());
 450         emitop(invokespecial);
 451         if (!alive) return;
 452         emit2(meth);
 453         Symbol sym = (Symbol)pool.pool[meth];
 454         state.pop(argsize);
 455         if (sym.isConstructor())
 456             state.markInitialized((UninitializedType)state.peek());
 457         state.pop(1);
 458         state.push(mtype.getReturnType());
 459     }
 460 
 461     /** Emit an invokestatic instruction.
 462      */
 463     public void emitInvokestatic(int meth, Type mtype) {
 464         int argsize = width(mtype.getParameterTypes());
 465         emitop(invokestatic);
 466         if (!alive) return;
 467         emit2(meth);
 468         state.pop(argsize);
 469         state.push(mtype.getReturnType());
 470     }
 471 
 472     /** Emit an invokevirtual instruction.
 473      */
 474     public void emitInvokevirtual(int meth, Type mtype) {
 475         int argsize = width(mtype.getParameterTypes());
 476         emitop(invokevirtual);
 477         if (!alive) return;
 478         emit2(meth);
 479         state.pop(argsize + 1);
 480         state.push(mtype.getReturnType());
 481     }
 482 
 483     /** Emit an invokedynamic instruction.
 484      */
 485     public void emitInvokedynamic(int desc, Type mtype) {
 486         int argsize = width(mtype.getParameterTypes());
 487         emitop(invokedynamic);
 488         if (!alive) return;
 489         emit2(desc);
 490         emit2(0);
 491         state.pop(argsize);
 492         state.push(mtype.getReturnType());
 493     }
 494 
 495     /** Emit an opcode with no operand field.
 496      */
 497     public void emitop0(int op) {
 498         emitop(op);
 499         if (!alive) return;
 500         switch (op) {
 501         case aaload: {
 502             state.pop(1);// index
 503             Type a = state.stack[state.stacksize-1];
 504             Assert.check(!a.hasTag(BOT)); // null type as is cannot be indexed.
 505             state.pop(1);
 506             state.push(types.erasure(types.elemtype(a))); }
 507             break;
 508         case goto_:
 509             markDead();
 510             break;
 511         case nop:
 512         case ineg:
 513         case lneg:
 514         case fneg:
 515         case dneg:
 516             break;
 517         case aconst_null:
 518             state.push(syms.botType);
 519             break;
 520         case iconst_m1:
 521         case iconst_0:
 522         case iconst_1:
 523         case iconst_2:
 524         case iconst_3:
 525         case iconst_4:
 526         case iconst_5:
 527         case iload_0:
 528         case iload_1:
 529         case iload_2:
 530         case iload_3:
 531             state.push(syms.intType);
 532             break;
 533         case lconst_0:
 534         case lconst_1:
 535         case lload_0:
 536         case lload_1:
 537         case lload_2:
 538         case lload_3:
 539             state.push(syms.longType);
 540             break;
 541         case fconst_0:
 542         case fconst_1:
 543         case fconst_2:
 544         case fload_0:
 545         case fload_1:
 546         case fload_2:
 547         case fload_3:
 548             state.push(syms.floatType);
 549             break;
 550         case dconst_0:
 551         case dconst_1:
 552         case dload_0:
 553         case dload_1:
 554         case dload_2:
 555         case dload_3:
 556             state.push(syms.doubleType);
 557             break;
 558         case aload_0:
 559             state.push(lvar[0].sym.type);
 560             break;
 561         case aload_1:
 562             state.push(lvar[1].sym.type);
 563             break;
 564         case aload_2:
 565             state.push(lvar[2].sym.type);
 566             break;
 567         case aload_3:
 568             state.push(lvar[3].sym.type);
 569             break;
 570         case iaload:
 571         case baload:
 572         case caload:
 573         case saload:
 574             state.pop(2);
 575             state.push(syms.intType);
 576             break;
 577         case laload:
 578             state.pop(2);
 579             state.push(syms.longType);
 580             break;
 581         case faload:
 582             state.pop(2);
 583             state.push(syms.floatType);
 584             break;
 585         case daload:
 586             state.pop(2);
 587             state.push(syms.doubleType);
 588             break;
 589         case istore_0:
 590         case istore_1:
 591         case istore_2:
 592         case istore_3:
 593         case fstore_0:
 594         case fstore_1:
 595         case fstore_2:
 596         case fstore_3:
 597         case astore_0:
 598         case astore_1:
 599         case astore_2:
 600         case astore_3:
 601         case pop:
 602         case lshr:
 603         case lshl:
 604         case lushr:
 605             state.pop(1);
 606             break;
 607         case areturn:
 608         case ireturn:
 609         case freturn:
 610             Assert.check(state.nlocks == 0);
 611             state.pop(1);
 612             markDead();
 613             break;
 614         case athrow:
 615             state.pop(1);
 616             markDead();
 617             break;
 618         case lstore_0:
 619         case lstore_1:
 620         case lstore_2:
 621         case lstore_3:
 622         case dstore_0:
 623         case dstore_1:
 624         case dstore_2:
 625         case dstore_3:
 626         case pop2:
 627             state.pop(2);
 628             break;
 629         case lreturn:
 630         case dreturn:
 631             Assert.check(state.nlocks == 0);
 632             state.pop(2);
 633             markDead();
 634             break;
 635         case dup:
 636             state.push(state.stack[state.stacksize-1]);
 637             break;
 638         case return_:
 639             Assert.check(state.nlocks == 0);
 640             markDead();
 641             break;
 642         case arraylength:
 643             state.pop(1);
 644             state.push(syms.intType);
 645             break;
 646         case isub:
 647         case iadd:
 648         case imul:
 649         case idiv:
 650         case imod:
 651         case ishl:
 652         case ishr:
 653         case iushr:
 654         case iand:
 655         case ior:
 656         case ixor:
 657             state.pop(1);
 658             // state.pop(1);
 659             // state.push(syms.intType);
 660             break;
 661         case aastore:
 662             state.pop(3);
 663             break;
 664         case land:
 665         case lor:
 666         case lxor:
 667         case lmod:
 668         case ldiv:
 669         case lmul:
 670         case lsub:
 671         case ladd:
 672             state.pop(2);
 673             break;
 674         case lcmp:
 675             state.pop(4);
 676             state.push(syms.intType);
 677             break;
 678         case l2i:
 679             state.pop(2);
 680             state.push(syms.intType);
 681             break;
 682         case i2l:
 683             state.pop(1);
 684             state.push(syms.longType);
 685             break;
 686         case i2f:
 687             state.pop(1);
 688             state.push(syms.floatType);
 689             break;
 690         case i2d:
 691             state.pop(1);
 692             state.push(syms.doubleType);
 693             break;
 694         case l2f:
 695             state.pop(2);
 696             state.push(syms.floatType);
 697             break;
 698         case l2d:
 699             state.pop(2);
 700             state.push(syms.doubleType);
 701             break;
 702         case f2i:
 703             state.pop(1);
 704             state.push(syms.intType);
 705             break;
 706         case f2l:
 707             state.pop(1);
 708             state.push(syms.longType);
 709             break;
 710         case f2d:
 711             state.pop(1);
 712             state.push(syms.doubleType);
 713             break;
 714         case d2i:
 715             state.pop(2);
 716             state.push(syms.intType);
 717             break;
 718         case d2l:
 719             state.pop(2);
 720             state.push(syms.longType);
 721             break;
 722         case d2f:
 723             state.pop(2);
 724             state.push(syms.floatType);
 725             break;
 726         case tableswitch:
 727         case lookupswitch:
 728             state.pop(1);
 729             // the caller is responsible for patching up the state
 730             break;
 731         case dup_x1: {
 732             Type val1 = state.pop1();
 733             Type val2 = state.pop1();
 734             state.push(val1);
 735             state.push(val2);
 736             state.push(val1);
 737             break;
 738         }
 739         case bastore:
 740             state.pop(3);
 741             break;
 742         case int2byte:
 743         case int2char:
 744         case int2short:
 745             break;
 746         case fmul:
 747         case fadd:
 748         case fsub:
 749         case fdiv:
 750         case fmod:
 751             state.pop(1);
 752             break;
 753         case castore:
 754         case iastore:
 755         case fastore:
 756         case sastore:
 757             state.pop(3);
 758             break;
 759         case lastore:
 760         case dastore:
 761             state.pop(4);
 762             break;
 763         case dup2:
 764             if (state.stack[state.stacksize-1] != null) {
 765                 Type value1 = state.pop1();
 766                 Type value2 = state.pop1();
 767                 state.push(value2);
 768                 state.push(value1);
 769                 state.push(value2);
 770                 state.push(value1);
 771             } else {
 772                 Type value = state.pop2();
 773                 state.push(value);
 774                 state.push(value);
 775             }
 776             break;
 777         case dup2_x1:
 778             if (state.stack[state.stacksize-1] != null) {
 779                 Type value1 = state.pop1();
 780                 Type value2 = state.pop1();
 781                 Type value3 = state.pop1();
 782                 state.push(value2);
 783                 state.push(value1);
 784                 state.push(value3);
 785                 state.push(value2);
 786                 state.push(value1);
 787             } else {
 788                 Type value1 = state.pop2();
 789                 Type value2 = state.pop1();
 790                 state.push(value1);
 791                 state.push(value2);
 792                 state.push(value1);
 793             }
 794             break;
 795         case dup2_x2:
 796             if (state.stack[state.stacksize-1] != null) {
 797                 Type value1 = state.pop1();
 798                 Type value2 = state.pop1();
 799                 if (state.stack[state.stacksize-1] != null) {
 800                     // form 1
 801                     Type value3 = state.pop1();
 802                     Type value4 = state.pop1();
 803                     state.push(value2);
 804                     state.push(value1);
 805                     state.push(value4);
 806                     state.push(value3);
 807                     state.push(value2);
 808                     state.push(value1);
 809                 } else {
 810                     // form 3
 811                     Type value3 = state.pop2();
 812                     state.push(value2);
 813                     state.push(value1);
 814                     state.push(value3);
 815                     state.push(value2);
 816                     state.push(value1);
 817                 }
 818             } else {
 819                 Type value1 = state.pop2();
 820                 if (state.stack[state.stacksize-1] != null) {
 821                     // form 2
 822                     Type value2 = state.pop1();
 823                     Type value3 = state.pop1();
 824                     state.push(value1);
 825                     state.push(value3);
 826                     state.push(value2);
 827                     state.push(value1);
 828                 } else {
 829                     // form 4
 830                     Type value2 = state.pop2();
 831                     state.push(value1);
 832                     state.push(value2);
 833                     state.push(value1);
 834                 }
 835             }
 836             break;
 837         case dup_x2: {
 838             Type value1 = state.pop1();
 839             if (state.stack[state.stacksize-1] != null) {
 840                 // form 1
 841                 Type value2 = state.pop1();
 842                 Type value3 = state.pop1();
 843                 state.push(value1);
 844                 state.push(value3);
 845                 state.push(value2);
 846                 state.push(value1);
 847             } else {
 848                 // form 2
 849                 Type value2 = state.pop2();
 850                 state.push(value1);
 851                 state.push(value2);
 852                 state.push(value1);
 853             }
 854         }
 855             break;
 856         case fcmpl:
 857         case fcmpg:
 858             state.pop(2);
 859             state.push(syms.intType);
 860             break;
 861         case dcmpl:
 862         case dcmpg:
 863             state.pop(4);
 864             state.push(syms.intType);
 865             break;
 866         case swap: {
 867             Type value1 = state.pop1();
 868             Type value2 = state.pop1();
 869             state.push(value1);
 870             state.push(value2);
 871             break;
 872         }
 873         case dadd:
 874         case dsub:
 875         case dmul:
 876         case ddiv:
 877         case dmod:
 878             state.pop(2);
 879             break;
 880         case ret:
 881             markDead();
 882             break;
 883         case wide:
 884             // must be handled by the caller.
 885             return;
 886         case monitorenter:
 887         case monitorexit:
 888             state.pop(1);
 889             break;
 890 
 891         default:
 892             throw new AssertionError(mnem(op));
 893         }
 894         postop();
 895     }
 896 
 897     /** Emit an opcode with a one-byte operand field.
 898      */
 899     public void emitop1(int op, int od) {
 900         emitop(op);
 901         if (!alive) return;
 902         emit1(od);
 903         switch (op) {
 904         case bipush:
 905             state.push(syms.intType);
 906             break;
 907         case ldc1:
 908             state.push(typeForPool(pool.pool[od]));
 909             break;
 910         default:
 911             throw new AssertionError(mnem(op));
 912         }
 913         postop();
 914     }
 915 
 916     /** The type of a constant pool entry. */
 917     private Type typeForPool(Object o) {
 918         if (o instanceof Integer) return syms.intType;
 919         if (o instanceof Float) return syms.floatType;
 920         if (o instanceof String) return syms.stringType;
 921         if (o instanceof Long) return syms.longType;
 922         if (o instanceof Double) return syms.doubleType;
 923         if (o instanceof ClassSymbol) return syms.classType;
 924         if (o instanceof Pool.MethodHandle) return syms.methodHandleType;
 925         if (o instanceof UniqueType) return typeForPool(((UniqueType)o).type);
 926         if (o instanceof Pool.DynamicVariable) return ((Pool.DynamicVariable)o).type;
 927         if (o instanceof Type) {
 928             Type ty = (Type) o;
 929 
 930             if (ty instanceof Type.ArrayType) return syms.classType;
 931             if (ty instanceof Type.MethodType) return syms.methodTypeType;
 932         }
 933         throw new AssertionError("Invalid type of constant pool entry: " + o.getClass());
 934     }
 935 
 936     /** Emit an opcode with a one-byte operand field;
 937      *  widen if field does not fit in a byte.
 938      */
 939     public void emitop1w(int op, int od) {
 940         if (od > 0xFF) {
 941             emitop(wide);
 942             emitop(op);
 943             emit2(od);
 944         } else {
 945             emitop(op);
 946             emit1(od);
 947         }
 948         if (!alive) return;
 949         switch (op) {
 950         case iload:
 951             state.push(syms.intType);
 952             break;
 953         case lload:
 954             state.push(syms.longType);
 955             break;
 956         case fload:
 957             state.push(syms.floatType);
 958             break;
 959         case dload:
 960             state.push(syms.doubleType);
 961             break;
 962         case aload:
 963             state.push(lvar[od].sym.type);
 964             break;
 965         case lstore:
 966         case dstore:
 967             state.pop(2);
 968             break;
 969         case istore:
 970         case fstore:
 971         case astore:
 972             state.pop(1);
 973             break;
 974         case ret:
 975             markDead();
 976             break;
 977         default:
 978             throw new AssertionError(mnem(op));
 979         }
 980         postop();
 981     }
 982 
 983     /** Emit an opcode with two one-byte operand fields;
 984      *  widen if either field does not fit in a byte.
 985      */
 986     public void emitop1w(int op, int od1, int od2) {
 987         if (od1 > 0xFF || od2 < -128 || od2 > 127) {
 988             emitop(wide);
 989             emitop(op);
 990             emit2(od1);
 991             emit2(od2);
 992         } else {
 993             emitop(op);
 994             emit1(od1);
 995             emit1(od2);
 996         }
 997         if (!alive) return;
 998         switch (op) {
 999         case iinc:
1000             break;
1001         default:
1002             throw new AssertionError(mnem(op));
1003         }
1004     }
1005 
1006     /** Emit an opcode with a two-byte operand field.
1007      */
1008     public void emitop2(int op, int od) {
1009         emitop(op);
1010         if (!alive) return;
1011         emit2(od);
1012         switch (op) {
1013         case getstatic:
1014             state.push(((Symbol)(pool.pool[od])).erasure(types));
1015             break;
1016         case putstatic:
1017             state.pop(((Symbol)(pool.pool[od])).erasure(types));
1018             break;
1019         case new_:
1020             Symbol sym;
1021             if (pool.pool[od] instanceof UniqueType) {
1022                 // Required by change in Gen.makeRef to allow
1023                 // annotated types.
1024                 // TODO: is this needed anywhere else?
1025                 sym = ((UniqueType)(pool.pool[od])).type.tsym;
1026             } else {
1027                 sym = (Symbol)(pool.pool[od]);
1028             }
1029             state.push(uninitializedObject(sym.erasure(types), cp-3));
1030             break;
1031         case sipush:
1032             state.push(syms.intType);
1033             break;
1034         case if_acmp_null:
1035         case if_acmp_nonnull:
1036         case ifeq:
1037         case ifne:
1038         case iflt:
1039         case ifge:
1040         case ifgt:
1041         case ifle:
1042             state.pop(1);
1043             break;
1044         case if_icmpeq:
1045         case if_icmpne:
1046         case if_icmplt:
1047         case if_icmpge:
1048         case if_icmpgt:
1049         case if_icmple:
1050         case if_acmpeq:
1051         case if_acmpne:
1052             state.pop(2);
1053             break;
1054         case goto_:
1055             markDead();
1056             break;
1057         case putfield:
1058             state.pop(((Symbol)(pool.pool[od])).erasure(types));
1059             state.pop(1); // object ref
1060             break;
1061         case getfield:
1062             state.pop(1); // object ref
1063             state.push(((Symbol)(pool.pool[od])).erasure(types));
1064             break;
1065         case checkcast: {
1066             state.pop(1); // object ref
1067             Object o = pool.pool[od];
1068             Type t = (o instanceof Symbol)
1069                 ? ((Symbol)o).erasure(types)
1070                 : types.erasure((((UniqueType)o).type));
1071             state.push(t);
1072             break; }
1073         case ldc2w:
1074             state.push(typeForPool(pool.pool[od]));
1075             break;
1076         case instanceof_:
1077             state.pop(1);
1078             state.push(syms.intType);
1079             break;
1080         case ldc2:
1081             state.push(typeForPool(pool.pool[od]));
1082             break;
1083         case jsr:
1084             break;
1085         default:
1086             throw new AssertionError(mnem(op));
1087         }
1088         // postop();
1089     }
1090 
1091     /** Emit an opcode with a four-byte operand field.
1092      */
1093     public void emitop4(int op, int od) {
1094         emitop(op);
1095         if (!alive) return;
1096         emit4(od);
1097         switch (op) {
1098         case goto_w:
1099             markDead();
1100             break;
1101         case jsr_w:
1102             break;
1103         default:
1104             throw new AssertionError(mnem(op));
1105         }
1106         // postop();
1107     }
1108 
1109     /** Align code pointer to next `incr' boundary.
1110      */
1111     public void align(int incr) {
1112         if (alive)
1113             while (cp % incr != 0) emitop0(nop);
1114     }
1115 
1116     /** Place a byte into code at address pc.
1117      *  Pre: {@literal pc + 1 <= cp }.
1118      */
1119     private void put1(int pc, int op) {
1120         code[pc] = (byte)op;
1121     }
1122 
1123     /** Place two bytes into code at address pc.
1124      *  Pre: {@literal pc + 2 <= cp }.
1125      */
1126     private void put2(int pc, int od) {
1127         // pre: pc + 2 <= cp
1128         put1(pc, od >> 8);
1129         put1(pc+1, od);
1130     }
1131 
1132     /** Place four  bytes into code at address pc.
1133      *  Pre: {@literal pc + 4 <= cp }.
1134      */
1135     public void put4(int pc, int od) {
1136         // pre: pc + 4 <= cp
1137         put1(pc  , od >> 24);
1138         put1(pc+1, od >> 16);
1139         put1(pc+2, od >> 8);
1140         put1(pc+3, od);
1141     }
1142 
1143     /** Return code byte at position pc as an unsigned int.
1144      */
1145     private int get1(int pc) {
1146         return code[pc] & 0xFF;
1147     }
1148 
1149     /** Return two code bytes at position pc as an unsigned int.
1150      */
1151     private int get2(int pc) {
1152         return (get1(pc) << 8) | get1(pc+1);
1153     }
1154 
1155     /** Return four code bytes at position pc as an int.
1156      */
1157     public int get4(int pc) {
1158         // pre: pc + 4 <= cp
1159         return
1160             (get1(pc) << 24) |
1161             (get1(pc+1) << 16) |
1162             (get1(pc+2) << 8) |
1163             (get1(pc+3));
1164     }
1165 
1166     /** Is code generation currently enabled?
1167      */
1168     public boolean isAlive() {
1169         return alive || pendingJumps != null;
1170     }
1171 
1172     /** Switch code generation on/off.
1173      */
1174     public void markDead() {
1175         alive = false;
1176     }
1177 
1178     /** Declare an entry point; return current code pointer
1179      */
1180     public int entryPoint() {
1181         int pc = curCP();
1182         alive = true;
1183         pendingStackMap = needStackMap;
1184         return pc;
1185     }
1186 
1187     /** Declare an entry point with initial state;
1188      *  return current code pointer
1189      */
1190     public int entryPoint(State state) {
1191         int pc = curCP();
1192         alive = true;
1193         State newState = state.dup();
1194         setDefined(newState.defined);
1195         this.state = newState;
1196         Assert.check(state.stacksize <= max_stack);
1197         if (debugCode) System.err.println("entry point " + state);
1198         pendingStackMap = needStackMap;
1199         return pc;
1200     }
1201 
1202     /** Declare an entry point with initial state plus a pushed value;
1203      *  return current code pointer
1204      */
1205     public int entryPoint(State state, Type pushed) {
1206         int pc = curCP();
1207         alive = true;
1208         State newState = state.dup();
1209         setDefined(newState.defined);
1210         this.state = newState;
1211         Assert.check(state.stacksize <= max_stack);
1212         this.state.push(pushed);
1213         if (debugCode) System.err.println("entry point " + state);
1214         pendingStackMap = needStackMap;
1215         return pc;
1216     }
1217 
1218     public int setLetExprStackPos(int pos) {
1219         int res = letExprStackPos;
1220         letExprStackPos = pos;
1221         return res;
1222     }
1223 
1224     public boolean isStatementStart() {
1225         return !alive || state.stacksize == letExprStackPos;
1226     }
1227 
1228 /**************************************************************************
1229  * Stack map generation
1230  *************************************************************************/
1231 
1232     /** An entry in the stack map. */
1233     static class StackMapFrame {
1234         int pc;
1235         Type[] locals;
1236         Type[] stack;
1237     }
1238 
1239     /** A buffer of cldc stack map entries. */
1240     StackMapFrame[] stackMapBuffer = null;
1241 
1242     /** A buffer of compressed StackMapTable entries. */
1243     StackMapTableFrame[] stackMapTableBuffer = null;
1244     int stackMapBufferSize = 0;
1245 
1246     /** The last PC at which we generated a stack map. */
1247     int lastStackMapPC = -1;
1248 
1249     /** The last stack map frame in StackMapTable. */
1250     StackMapFrame lastFrame = null;
1251 
1252     /** The stack map frame before the last one. */
1253     StackMapFrame frameBeforeLast = null;
1254 
1255     /** Emit a stack map entry.  */
1256     public void emitStackMap() {
1257         int pc = curCP();
1258         if (!needStackMap) return;
1259 
1260 
1261 
1262         switch (stackMap) {
1263             case CLDC:
1264                 emitCLDCStackMap(pc, getLocalsSize());
1265                 break;
1266             case JSR202:
1267                 emitStackMapFrame(pc, getLocalsSize());
1268                 break;
1269             default:
1270                 throw new AssertionError("Should have chosen a stackmap format");
1271         }
1272         // DEBUG code follows
1273         if (debugCode) state.dump(pc);
1274     }
1275 
1276     private int getLocalsSize() {
1277         int nextLocal = 0;
1278         for (int i=max_locals-1; i>=0; i--) {
1279             if (state.defined.isMember(i) && lvar[i] != null) {
1280                 nextLocal = i + width(lvar[i].sym.erasure(types));
1281                 break;
1282             }
1283         }
1284         return nextLocal;
1285     }
1286 
1287     /** Emit a CLDC stack map frame. */
1288     void emitCLDCStackMap(int pc, int localsSize) {
1289         if (lastStackMapPC == pc) {
1290             // drop existing stackmap at this offset
1291             stackMapBuffer[--stackMapBufferSize] = null;
1292         }
1293         lastStackMapPC = pc;
1294 
1295         if (stackMapBuffer == null) {
1296             stackMapBuffer = new StackMapFrame[20];
1297         } else {
1298             stackMapBuffer = ArrayUtils.ensureCapacity(stackMapBuffer, stackMapBufferSize);
1299         }
1300         StackMapFrame frame =
1301             stackMapBuffer[stackMapBufferSize++] = new StackMapFrame();
1302         frame.pc = pc;
1303 
1304         frame.locals = new Type[localsSize];
1305         for (int i=0; i<localsSize; i++) {
1306             if (state.defined.isMember(i) && lvar[i] != null) {
1307                 Type vtype = lvar[i].sym.type;
1308                 if (!(vtype instanceof UninitializedType))
1309                     vtype = types.erasure(vtype);
1310                 frame.locals[i] = vtype;
1311             }
1312         }
1313         frame.stack = new Type[state.stacksize];
1314         for (int i=0; i<state.stacksize; i++)
1315             frame.stack[i] = state.stack[i];
1316     }
1317 
1318     void emitStackMapFrame(int pc, int localsSize) {
1319         if (lastFrame == null) {
1320             // first frame
1321             lastFrame = getInitialFrame();
1322         } else if (lastFrame.pc == pc) {
1323             // drop existing stackmap at this offset
1324             stackMapTableBuffer[--stackMapBufferSize] = null;
1325             lastFrame = frameBeforeLast;
1326             frameBeforeLast = null;
1327         }
1328 
1329         StackMapFrame frame = new StackMapFrame();
1330         frame.pc = pc;
1331 
1332         int localCount = 0;
1333         Type[] locals = new Type[localsSize];
1334         for (int i=0; i<localsSize; i++, localCount++) {
1335             if (state.defined.isMember(i) && lvar[i] != null) {
1336                 Type vtype = lvar[i].sym.type;
1337                 if (!(vtype instanceof UninitializedType))
1338                     vtype = types.erasure(vtype);
1339                 locals[i] = vtype;
1340                 if (width(vtype) > 1) i++;
1341             }
1342         }
1343         frame.locals = new Type[localCount];
1344         for (int i=0, j=0; i<localsSize; i++, j++) {
1345             Assert.check(j < localCount);
1346             frame.locals[j] = locals[i];
1347             if (width(locals[i]) > 1) i++;
1348         }
1349 
1350         int stackCount = 0;
1351         for (int i=0; i<state.stacksize; i++) {
1352             if (state.stack[i] != null) {
1353                 stackCount++;
1354             }
1355         }
1356         frame.stack = new Type[stackCount];
1357         stackCount = 0;
1358         for (int i=0; i<state.stacksize; i++) {
1359             if (state.stack[i] != null) {
1360                 frame.stack[stackCount++] = types.erasure(state.stack[i]);
1361             }
1362         }
1363 
1364         if (stackMapTableBuffer == null) {
1365             stackMapTableBuffer = new StackMapTableFrame[20];
1366         } else {
1367             stackMapTableBuffer = ArrayUtils.ensureCapacity(
1368                                     stackMapTableBuffer,
1369                                     stackMapBufferSize);
1370         }
1371         stackMapTableBuffer[stackMapBufferSize++] =
1372                 StackMapTableFrame.getInstance(frame, lastFrame.pc, lastFrame.locals, types);
1373 
1374         frameBeforeLast = lastFrame;
1375         lastFrame = frame;
1376     }
1377 
1378     StackMapFrame getInitialFrame() {
1379         StackMapFrame frame = new StackMapFrame();
1380         List<Type> arg_types = ((MethodType)meth.externalType(types)).argtypes;
1381         int len = arg_types.length();
1382         int count = 0;
1383         if (!meth.isStatic()) {
1384             Type thisType = meth.owner.type;
1385             frame.locals = new Type[len+1];
1386             if (meth.isConstructor() && thisType != syms.objectType) {
1387                 frame.locals[count++] = UninitializedType.uninitializedThis(thisType);
1388             } else {
1389                 frame.locals[count++] = types.erasure(thisType);
1390             }
1391         } else {
1392             frame.locals = new Type[len];
1393         }
1394         for (Type arg_type : arg_types) {
1395             frame.locals[count++] = types.erasure(arg_type);
1396         }
1397         frame.pc = -1;
1398         frame.stack = null;
1399         return frame;
1400     }
1401 
1402 
1403 /**************************************************************************
1404  * Operations having to do with jumps
1405  *************************************************************************/
1406 
1407     /** A chain represents a list of unresolved jumps. Jump locations
1408      *  are sorted in decreasing order.
1409      */
1410     public static class Chain {
1411 
1412         /** The position of the jump instruction.
1413          */
1414         public final int pc;
1415 
1416         /** The machine state after the jump instruction.
1417          *  Invariant: all elements of a chain list have the same stacksize
1418          *  and compatible stack and register contents.
1419          */
1420         Code.State state;
1421 
1422         /** The next jump in the list.
1423          */
1424         public final Chain next;
1425 
1426         /** Construct a chain from its jump position, stacksize, previous
1427          *  chain, and machine state.
1428          */
1429         public Chain(int pc, Chain next, Code.State state) {
1430             this.pc = pc;
1431             this.next = next;
1432             this.state = state;
1433         }
1434     }
1435 
1436     /** Negate a branch opcode.
1437      */
1438     public static int negate(int opcode) {
1439         if (opcode == if_acmp_null) return if_acmp_nonnull;
1440         else if (opcode == if_acmp_nonnull) return if_acmp_null;
1441         else return ((opcode + 1) ^ 1) - 1;
1442     }
1443 
1444     /** Emit a jump instruction.
1445      *  Return code pointer of instruction to be patched.
1446      */
1447     public int emitJump(int opcode) {
1448         if (fatcode) {
1449             if (opcode == goto_ || opcode == jsr) {
1450                 emitop4(opcode + goto_w - goto_, 0);
1451             } else {
1452                 emitop2(negate(opcode), 8);
1453                 emitop4(goto_w, 0);
1454                 alive = true;
1455                 pendingStackMap = needStackMap;
1456             }
1457             return cp - 5;
1458         } else {
1459             emitop2(opcode, 0);
1460             return cp - 3;
1461         }
1462     }
1463 
1464     /** Emit a branch with given opcode; return its chain.
1465      *  branch differs from jump in that jsr is treated as no-op.
1466      */
1467     public Chain branch(int opcode) {
1468         Chain result = null;
1469         if (opcode == goto_) {
1470             result = pendingJumps;
1471             pendingJumps = null;
1472         }
1473         if (opcode != dontgoto && isAlive()) {
1474             result = new Chain(emitJump(opcode),
1475                                result,
1476                                state.dup());
1477             fixedPc = fatcode;
1478             if (opcode == goto_) alive = false;
1479         }
1480         return result;
1481     }
1482 
1483     /** Resolve chain to point to given target.
1484      */
1485     public void resolve(Chain chain, int target) {
1486         boolean changed = false;
1487         State newState = state;
1488         for (; chain != null; chain = chain.next) {
1489             Assert.check(state != chain.state
1490                     && (target > chain.pc || isStatementStart()));
1491             if (target >= cp) {
1492                 target = cp;
1493             } else if (get1(target) == goto_) {
1494                 if (fatcode) target = target + get4(target + 1);
1495                 else target = target + get2(target + 1);
1496             }
1497             if (get1(chain.pc) == goto_ &&
1498                 chain.pc + 3 == target && target == cp && !fixedPc) {
1499                 // If goto the next instruction, the jump is not needed:
1500                 // compact the code.
1501                 if (varDebugInfo) {
1502                     adjustAliveRanges(cp, -3);
1503                 }
1504                 cp = cp - 3;
1505                 target = target - 3;
1506                 if (chain.next == null) {
1507                     // This is the only jump to the target. Exit the loop
1508                     // without setting new state. The code is reachable
1509                     // from the instruction before goto_.
1510                     alive = true;
1511                     break;
1512                 }
1513             } else {
1514                 if (fatcode)
1515                     put4(chain.pc + 1, target - chain.pc);
1516                 else if (target - chain.pc < Short.MIN_VALUE ||
1517                          target - chain.pc > Short.MAX_VALUE)
1518                     fatcode = true;
1519                 else
1520                     put2(chain.pc + 1, target - chain.pc);
1521                 Assert.check(!alive ||
1522                     chain.state.stacksize == newState.stacksize &&
1523                     chain.state.nlocks == newState.nlocks);
1524             }
1525             fixedPc = true;
1526             if (cp == target) {
1527                 changed = true;
1528                 if (debugCode)
1529                     System.err.println("resolving chain state=" + chain.state);
1530                 if (alive) {
1531                     newState = chain.state.join(newState);
1532                 } else {
1533                     newState = chain.state;
1534                     alive = true;
1535                 }
1536             }
1537         }
1538         Assert.check(!changed || state != newState);
1539         if (state != newState) {
1540             setDefined(newState.defined);
1541             state = newState;
1542             pendingStackMap = needStackMap;
1543         }
1544     }
1545 
1546     /** Resolve chain to point to current code pointer.
1547      */
1548     public void resolve(Chain chain) {
1549         Assert.check(
1550             !alive ||
1551             chain==null ||
1552             state.stacksize == chain.state.stacksize &&
1553             state.nlocks == chain.state.nlocks);
1554         pendingJumps = mergeChains(chain, pendingJumps);
1555     }
1556 
1557     /** Resolve any pending jumps.
1558      */
1559     public void resolvePending() {
1560         Chain x = pendingJumps;
1561         pendingJumps = null;
1562         resolve(x, cp);
1563     }
1564 
1565     /** Merge the jumps in of two chains into one.
1566      */
1567     public static Chain mergeChains(Chain chain1, Chain chain2) {
1568         // recursive merge sort
1569         if (chain2 == null) return chain1;
1570         if (chain1 == null) return chain2;
1571         Assert.check(
1572             chain1.state.stacksize == chain2.state.stacksize &&
1573             chain1.state.nlocks == chain2.state.nlocks);
1574         if (chain1.pc < chain2.pc)
1575             return new Chain(
1576                 chain2.pc,
1577                 mergeChains(chain1, chain2.next),
1578                 chain2.state);
1579         return new Chain(
1580                 chain1.pc,
1581                 mergeChains(chain1.next, chain2),
1582                 chain1.state);
1583     }
1584 
1585 
1586 /* **************************************************************************
1587  * Catch clauses
1588  ****************************************************************************/
1589 
1590     /** Add a catch clause to code.
1591      */
1592     public void addCatch(char startPc, char endPc,
1593                          char handlerPc, char catchType) {
1594             catchInfo.append(new char[]{startPc, endPc, handlerPc, catchType});
1595         }
1596 
1597 
1598     public void compressCatchTable() {
1599         ListBuffer<char[]> compressedCatchInfo = new ListBuffer<>();
1600         List<Integer> handlerPcs = List.nil();
1601         for (char[] catchEntry : catchInfo) {
1602             handlerPcs = handlerPcs.prepend((int)catchEntry[2]);
1603         }
1604         for (char[] catchEntry : catchInfo) {
1605             int startpc = catchEntry[0];
1606             int endpc = catchEntry[1];
1607             if (startpc == endpc ||
1608                     (startpc == (endpc - 1) &&
1609                     handlerPcs.contains(startpc))) {
1610                 continue;
1611             } else {
1612                 compressedCatchInfo.append(catchEntry);
1613             }
1614         }
1615         catchInfo = compressedCatchInfo;
1616     }
1617 
1618 
1619 /* **************************************************************************
1620  * Line numbers
1621  ****************************************************************************/
1622 
1623     /** Add a line number entry.
1624      */
1625     public void addLineNumber(char startPc, char lineNumber) {
1626         if (lineDebugInfo) {
1627             if (lineInfo.nonEmpty() && lineInfo.head[0] == startPc)
1628                 lineInfo = lineInfo.tail;
1629             if (lineInfo.isEmpty() || lineInfo.head[1] != lineNumber)
1630                 lineInfo = lineInfo.prepend(new char[]{startPc, lineNumber});
1631         }
1632     }
1633 
1634     /** Mark beginning of statement.
1635      */
1636     public void statBegin(int pos) {
1637         if (pos != Position.NOPOS) {
1638             pendingStatPos = pos;
1639         }
1640     }
1641 
1642     /** Force stat begin eagerly
1643      */
1644     public void markStatBegin() {
1645         if (alive && lineDebugInfo) {
1646             int line = lineMap.getLineNumber(pendingStatPos);
1647             char cp1 = (char)cp;
1648             char line1 = (char)line;
1649             if (cp1 == cp && line1 == line)
1650                 addLineNumber(cp1, line1);
1651         }
1652         pendingStatPos = Position.NOPOS;
1653     }
1654 
1655 
1656 /* **************************************************************************
1657  * Simulated VM machine state
1658  ****************************************************************************/
1659 
1660     class State implements Cloneable {
1661         /** The set of registers containing values. */
1662         Bits defined;
1663 
1664         /** The (types of the) contents of the machine stack. */
1665         Type[] stack;
1666 
1667         /** The first stack position currently unused. */
1668         int stacksize;
1669 
1670         /** The numbers of registers containing locked monitors. */
1671         int[] locks;
1672         int nlocks;
1673 
1674         State() {
1675             defined = new Bits();
1676             stack = new Type[16];
1677         }
1678 
1679         State dup() {
1680             try {
1681                 State state = (State)super.clone();
1682                 state.defined = new Bits(defined);
1683                 state.stack = stack.clone();
1684                 if (locks != null) state.locks = locks.clone();
1685                 if (debugCode) {
1686                     System.err.println("duping state " + this);
1687                     dump();
1688                 }
1689                 return state;
1690             } catch (CloneNotSupportedException ex) {
1691                 throw new AssertionError(ex);
1692             }
1693         }
1694 
1695         void lock(int register) {
1696             if (locks == null) {
1697                 locks = new int[20];
1698             } else {
1699                 locks = ArrayUtils.ensureCapacity(locks, nlocks);
1700             }
1701             locks[nlocks] = register;
1702             nlocks++;
1703         }
1704 
1705         void unlock(int register) {
1706             nlocks--;
1707             Assert.check(locks[nlocks] == register);
1708             locks[nlocks] = -1;
1709         }
1710 
1711         void push(Type t) {
1712             if (debugCode) System.err.println("   pushing " + t);
1713             switch (t.getTag()) {
1714             case VOID:
1715                 return;
1716             case BYTE:
1717             case CHAR:
1718             case SHORT:
1719             case BOOLEAN:
1720                 t = syms.intType;
1721                 break;
1722             default:
1723                 break;
1724             }
1725             stack = ArrayUtils.ensureCapacity(stack, stacksize+2);
1726             stack[stacksize++] = t;
1727             switch (width(t)) {
1728             case 1:
1729                 break;
1730             case 2:
1731                 stack[stacksize++] = null;
1732                 break;
1733             default:
1734                 throw new AssertionError(t);
1735             }
1736             if (stacksize > max_stack)
1737                 max_stack = stacksize;
1738         }
1739 
1740         Type pop1() {
1741             if (debugCode) System.err.println("   popping " + 1);
1742             stacksize--;
1743             Type result = stack[stacksize];
1744             stack[stacksize] = null;
1745             Assert.check(result != null && width(result) == 1);
1746             return result;
1747         }
1748 
1749         Type peek() {
1750             return stack[stacksize-1];
1751         }
1752 
1753         Type pop2() {
1754             if (debugCode) System.err.println("   popping " + 2);
1755             stacksize -= 2;
1756             Type result = stack[stacksize];
1757             stack[stacksize] = null;
1758             Assert.check(stack[stacksize+1] == null
1759                     && result != null && width(result) == 2);
1760             return result;
1761         }
1762 
1763         void pop(int n) {
1764             if (debugCode) System.err.println("   popping " + n);
1765             while (n > 0) {
1766                 stack[--stacksize] = null;
1767                 n--;
1768             }
1769         }
1770 
1771         void pop(Type t) {
1772             pop(width(t));
1773         }
1774 
1775         /** Force the top of the stack to be treated as this supertype
1776          *  of its current type. */
1777         void forceStackTop(Type t) {
1778             if (!alive) return;
1779             switch (t.getTag()) {
1780             case CLASS:
1781             case ARRAY:
1782                 int width = width(t);
1783                 Type old = stack[stacksize-width];
1784                 Assert.check(types.isSubtype(types.erasure(old),
1785                                        types.erasure(t)));
1786                 stack[stacksize-width] = t;
1787                 break;
1788             default:
1789             }
1790         }
1791 
1792         void markInitialized(UninitializedType old) {
1793             Type newtype = old.initializedType();
1794             for (int i=0; i<stacksize; i++) {
1795                 if (stack[i] == old) stack[i] = newtype;
1796             }
1797             for (int i=0; i<lvar.length; i++) {
1798                 LocalVar lv = lvar[i];
1799                 if (lv != null && lv.sym.type == old) {
1800                     VarSymbol sym = lv.sym;
1801                     sym = sym.clone(sym.owner);
1802                     sym.type = newtype;
1803                     LocalVar newlv = lvar[i] = new LocalVar(sym);
1804                     newlv.aliveRanges = lv.aliveRanges;
1805                 }
1806             }
1807         }
1808 
1809         State join(State other) {
1810             defined.andSet(other.defined);
1811             Assert.check(stacksize == other.stacksize
1812                     && nlocks == other.nlocks);
1813             for (int i=0; i<stacksize; ) {
1814                 Type t = stack[i];
1815                 Type tother = other.stack[i];
1816                 Type result =
1817                     t==tother ? t :
1818                     types.isSubtype(t, tother) ? tother :
1819                     types.isSubtype(tother, t) ? t :
1820                     error();
1821                 int w = width(result);
1822                 stack[i] = result;
1823                 if (w == 2) Assert.checkNull(stack[i+1]);
1824                 i += w;
1825             }
1826             return this;
1827         }
1828 
1829         Type error() {
1830             throw new AssertionError("inconsistent stack types at join point");
1831         }
1832 
1833         void dump() {
1834             dump(-1);
1835         }
1836 
1837         void dump(int pc) {
1838             System.err.print("stackMap for " + meth.owner + "." + meth);
1839             if (pc == -1)
1840                 System.out.println();
1841             else
1842                 System.out.println(" at " + pc);
1843             System.err.println(" stack (from bottom):");
1844             for (int i=0; i<stacksize; i++)
1845                 System.err.println("  " + i + ": " + stack[i]);
1846 
1847             int lastLocal = 0;
1848             for (int i=max_locals-1; i>=0; i--) {
1849                 if (defined.isMember(i)) {
1850                     lastLocal = i;
1851                     break;
1852                 }
1853             }
1854             if (lastLocal >= 0)
1855                 System.err.println(" locals:");
1856             for (int i=0; i<=lastLocal; i++) {
1857                 System.err.print("  " + i + ": ");
1858                 if (defined.isMember(i)) {
1859                     LocalVar var = lvar[i];
1860                     if (var == null) {
1861                         System.err.println("(none)");
1862                     } else if (var.sym == null)
1863                         System.err.println("UNKNOWN!");
1864                     else
1865                         System.err.println("" + var.sym + " of type " +
1866                                            var.sym.erasure(types));
1867                 } else {
1868                     System.err.println("undefined");
1869                 }
1870             }
1871             if (nlocks != 0) {
1872                 System.err.print(" locks:");
1873                 for (int i=0; i<nlocks; i++) {
1874                     System.err.print(" " + locks[i]);
1875                 }
1876                 System.err.println();
1877             }
1878         }
1879     }
1880 
1881     static final Type jsrReturnValue = new JCPrimitiveType(INT, null);
1882 
1883 
1884 /* **************************************************************************
1885  * Local variables
1886  ****************************************************************************/
1887 
1888     /** A live range of a local variable. */
1889     static class LocalVar {
1890         final VarSymbol sym;
1891         final char reg;
1892 
1893         class Range {
1894             char start_pc = Character.MAX_VALUE;
1895             char length = Character.MAX_VALUE;
1896 
1897             Range() {}
1898 
1899             Range(char start) {
1900                 this.start_pc = start;
1901             }
1902 
1903             Range(char start, char length) {
1904                 this.start_pc = start;
1905                 this.length = length;
1906             }
1907 
1908             boolean closed() {
1909                 return start_pc != Character.MAX_VALUE && length != Character.MAX_VALUE;
1910             }
1911 
1912             @Override
1913             public String toString() {
1914                 int currentStartPC = start_pc;
1915                 int currentLength = length;
1916                 return "startpc = " + currentStartPC + " length " + currentLength;
1917             }
1918         }
1919 
1920         java.util.List<Range> aliveRanges = new java.util.ArrayList<>();
1921 
1922         LocalVar(VarSymbol v) {
1923             this.sym = v;
1924             this.reg = (char)v.adr;
1925         }
1926         public LocalVar dup() {
1927             return new LocalVar(sym);
1928         }
1929 
1930         Range firstRange() {
1931             return aliveRanges.isEmpty() ? null : aliveRanges.get(0);
1932         }
1933 
1934         Range lastRange() {
1935             return aliveRanges.isEmpty() ? null : aliveRanges.get(aliveRanges.size() - 1);
1936         }
1937 
1938         void removeLastRange() {
1939             Range lastRange = lastRange();
1940             if (lastRange != null) {
1941                 aliveRanges.remove(lastRange);
1942             }
1943         }
1944 
1945         @Override
1946         public String toString() {
1947             if (aliveRanges == null) {
1948                 return "empty local var";
1949             }
1950             StringBuilder sb = new StringBuilder().append(sym)
1951                     .append(" in register ").append((int)reg).append(" \n");
1952             for (Range r : aliveRanges) {
1953                 sb.append(" starts at pc=").append(Integer.toString(((int)r.start_pc)))
1954                     .append(" length=").append(Integer.toString(((int)r.length)))
1955                     .append("\n");
1956             }
1957             return sb.toString();
1958         }
1959 
1960         public void openRange(char start) {
1961             if (!hasOpenRange()) {
1962                 aliveRanges.add(new Range(start));
1963             }
1964         }
1965 
1966         public void closeRange(char length) {
1967             if (isLastRangeInitialized() && length > 0) {
1968                 Range range = lastRange();
1969                 if (range != null) {
1970                     if (range.length == Character.MAX_VALUE) {
1971                         range.length = length;
1972                     }
1973                 }
1974             } else {
1975                 removeLastRange();
1976             }
1977         }
1978 
1979         public boolean hasOpenRange() {
1980             if (aliveRanges.isEmpty()) {
1981                 return false;
1982             }
1983             return lastRange().length == Character.MAX_VALUE;
1984         }
1985 
1986         public boolean isLastRangeInitialized() {
1987             if (aliveRanges.isEmpty()) {
1988                 return false;
1989             }
1990             return lastRange().start_pc != Character.MAX_VALUE;
1991         }
1992 
1993         public Range getWidestRange() {
1994             if (aliveRanges.isEmpty()) {
1995                 return new Range();
1996             } else {
1997                 Range firstRange = firstRange();
1998                 Range lastRange = lastRange();
1999                 char length = (char)(lastRange.length + (lastRange.start_pc - firstRange.start_pc));
2000                 return new Range(firstRange.start_pc, length);
2001             }
2002          }
2003 
2004     }
2005 
2006     /** Local variables, indexed by register. */
2007     LocalVar[] lvar;
2008 
2009     /** Add a new local variable. */
2010     private void addLocalVar(VarSymbol v) {
2011         int adr = v.adr;
2012         lvar = ArrayUtils.ensureCapacity(lvar, adr+1);
2013         Assert.checkNull(lvar[adr]);
2014         if (pendingJumps != null) {
2015             resolvePending();
2016         }
2017         lvar[adr] = new LocalVar(v);
2018         state.defined.excl(adr);
2019     }
2020 
2021     void adjustAliveRanges(int oldCP, int delta) {
2022         for (LocalVar localVar: lvar) {
2023             if (localVar != null) {
2024                 for (LocalVar.Range range: localVar.aliveRanges) {
2025                     if (range.closed() && range.start_pc + range.length >= oldCP) {
2026                         range.length += delta;
2027                     }
2028                 }
2029             }
2030         }
2031     }
2032 
2033     /**
2034      * Calculates the size of the LocalVariableTable.
2035      */
2036     public int getLVTSize() {
2037         int result = varBufferSize;
2038         for (int i = 0; i < varBufferSize; i++) {
2039             LocalVar var = varBuffer[i];
2040             result += var.aliveRanges.size() - 1;
2041         }
2042         return result;
2043     }
2044 
2045     /** Set the current variable defined state. */
2046     public void setDefined(Bits newDefined) {
2047         if (alive && newDefined != state.defined) {
2048             Bits diff = new Bits(state.defined).xorSet(newDefined);
2049             for (int adr = diff.nextBit(0);
2050                  adr >= 0;
2051                  adr = diff.nextBit(adr+1)) {
2052                 if (adr >= nextreg)
2053                     state.defined.excl(adr);
2054                 else if (state.defined.isMember(adr))
2055                     setUndefined(adr);
2056                 else
2057                     setDefined(adr);
2058             }
2059         }
2060     }
2061 
2062     /** Mark a register as being (possibly) defined. */
2063     public void setDefined(int adr) {
2064         LocalVar v = lvar[adr];
2065         if (v == null) {
2066             state.defined.excl(adr);
2067         } else {
2068             state.defined.incl(adr);
2069             if (cp < Character.MAX_VALUE) {
2070                 v.openRange((char)cp);
2071             }
2072         }
2073     }
2074 
2075     /** Mark a register as being undefined. */
2076     public void setUndefined(int adr) {
2077         state.defined.excl(adr);
2078         if (adr < lvar.length &&
2079             lvar[adr] != null &&
2080             lvar[adr].isLastRangeInitialized()) {
2081             LocalVar v = lvar[adr];
2082             char length = (char)(curCP() - v.lastRange().start_pc);
2083             if (length < Character.MAX_VALUE) {
2084                 lvar[adr] = v.dup();
2085                 v.closeRange(length);
2086                 putVar(v);
2087             } else {
2088                 v.removeLastRange();
2089             }
2090         }
2091     }
2092 
2093     /** End the scope of a variable. */
2094     private void endScope(int adr) {
2095         LocalVar v = lvar[adr];
2096         if (v != null) {
2097             if (v.isLastRangeInitialized()) {
2098                 char length = (char)(curCP() - v.lastRange().start_pc);
2099                 if (length < Character.MAX_VALUE) {
2100                     v.closeRange(length);
2101                     putVar(v);
2102                     fillLocalVarPosition(v);
2103                 }
2104             }
2105             /** the call to curCP() can implicitly adjust the current cp, if so
2106              * the alive range of local variables may be modified. Thus we need
2107              * all of them. For this reason assigning null to the given address
2108              * should be the last action to do.
2109              */
2110             lvar[adr] = null;
2111         }
2112         state.defined.excl(adr);
2113     }
2114 
2115     private void fillLocalVarPosition(LocalVar lv) {
2116         if (lv == null || lv.sym == null || lv.sym.isExceptionParameter()|| !lv.sym.hasTypeAnnotations())
2117             return;
2118         LocalVar.Range widestRange = lv.getWidestRange();
2119         for (Attribute.TypeCompound ta : lv.sym.getRawTypeAttributes()) {
2120             TypeAnnotationPosition p = ta.position;
2121             if (widestRange.closed() && widestRange.length > 0) {
2122                 p.lvarOffset = new int[] { (int)widestRange.start_pc };
2123                 p.lvarLength = new int[] { (int)widestRange.length };
2124                 p.lvarIndex = new int[] { (int)lv.reg };
2125                 p.isValidOffset = true;
2126             } else {
2127                 p.isValidOffset = false;
2128             }
2129         }
2130     }
2131 
2132     // Method to be called after compressCatchTable to
2133     // fill in the exception table index for type
2134     // annotations on exception parameters.
2135     public void fillExceptionParameterPositions() {
2136         for (int i = 0; i < varBufferSize; ++i) {
2137             LocalVar lv = varBuffer[i];
2138             if (lv == null || lv.sym == null
2139                     || !lv.sym.hasTypeAnnotations()
2140                     || !lv.sym.isExceptionParameter())
2141                 continue;
2142 
2143             for (Attribute.TypeCompound ta : lv.sym.getRawTypeAttributes()) {
2144                 TypeAnnotationPosition p = ta.position;
2145                 if (p.hasCatchType()) {
2146                     final int idx = findExceptionIndex(p);
2147                     if (idx == -1)
2148                         Assert.error("Could not find exception index for type annotation " +
2149                                      ta + " on exception parameter");
2150                     p.setExceptionIndex(idx);
2151                 }
2152             }
2153         }
2154     }
2155 
2156     private int findExceptionIndex(TypeAnnotationPosition p) {
2157         final int catchType = p.getCatchType();
2158         final int startPos = p.getStartPos();
2159         final int len = catchInfo.length();
2160         List<char[]> iter = catchInfo.toList();
2161         for (int i = 0; i < len; ++i) {
2162             char[] catchEntry = iter.head;
2163             iter = iter.tail;
2164             int ct = catchEntry[3];
2165             int sp = catchEntry[0];
2166             if (catchType == ct && sp == startPos) {
2167                 return i;
2168             }
2169         }
2170         return -1;
2171     }
2172 
2173     /** Put a live variable range into the buffer to be output to the
2174      *  class file.
2175      */
2176     void putVar(LocalVar var) {
2177         // Keep local variables if
2178         // 1) we need them for debug information
2179         // 2) it is an exception type and it contains type annotations
2180         boolean keepLocalVariables = varDebugInfo ||
2181             (var.sym.isExceptionParameter() && var.sym.hasTypeAnnotations());
2182         if (!keepLocalVariables) return;
2183         //don't keep synthetic vars, unless they are lambda method parameters
2184         boolean ignoredSyntheticVar = (var.sym.flags() & Flags.SYNTHETIC) != 0 &&
2185                 ((var.sym.owner.flags() & Flags.LAMBDA_METHOD) == 0 ||
2186                  (var.sym.flags() & Flags.PARAMETER) == 0);
2187         if (ignoredSyntheticVar) return;
2188         if (varBuffer == null)
2189             varBuffer = new LocalVar[20];
2190         else
2191             varBuffer = ArrayUtils.ensureCapacity(varBuffer, varBufferSize);
2192         varBuffer[varBufferSize++] = var;
2193     }
2194 
2195     /** Previously live local variables, to be put into the variable table. */
2196     LocalVar[] varBuffer;
2197     int varBufferSize;
2198 
2199     /** Create a new local variable address and return it.
2200      */
2201     private int newLocal(int typecode) {
2202         int reg = nextreg;
2203         int w = width(typecode);
2204         nextreg = reg + w;
2205         if (nextreg > max_locals) max_locals = nextreg;
2206         return reg;
2207     }
2208 
2209     private int newLocal(Type type) {
2210         return newLocal(typecode(type));
2211     }
2212 
2213     public int newLocal(VarSymbol v) {
2214         int reg = v.adr = newLocal(v.erasure(types));
2215         addLocalVar(v);
2216         return reg;
2217     }
2218 
2219     /** Start a set of fresh registers.
2220      */
2221     public void newRegSegment() {
2222         nextreg = max_locals;
2223     }
2224 
2225     /** End scopes of all variables with registers &ge; first.
2226      */
2227     public void endScopes(int first) {
2228         int prevNextReg = nextreg;
2229         nextreg = first;
2230         for (int i = nextreg; i < prevNextReg; i++) endScope(i);
2231     }
2232 
2233 /**************************************************************************
2234  * static tables
2235  *************************************************************************/
2236 
2237     public static String mnem(int opcode) {
2238         return Mneumonics.mnem[opcode];
2239     }
2240 
2241     private static class Mneumonics {
2242         private final static String[] mnem = new String[ByteCodeCount];
2243         static {
2244             mnem[nop] = "nop";
2245             mnem[aconst_null] = "aconst_null";
2246             mnem[iconst_m1] = "iconst_m1";
2247             mnem[iconst_0] = "iconst_0";
2248             mnem[iconst_1] = "iconst_1";
2249             mnem[iconst_2] = "iconst_2";
2250             mnem[iconst_3] = "iconst_3";
2251             mnem[iconst_4] = "iconst_4";
2252             mnem[iconst_5] = "iconst_5";
2253             mnem[lconst_0] = "lconst_0";
2254             mnem[lconst_1] = "lconst_1";
2255             mnem[fconst_0] = "fconst_0";
2256             mnem[fconst_1] = "fconst_1";
2257             mnem[fconst_2] = "fconst_2";
2258             mnem[dconst_0] = "dconst_0";
2259             mnem[dconst_1] = "dconst_1";
2260             mnem[bipush] = "bipush";
2261             mnem[sipush] = "sipush";
2262             mnem[ldc1] = "ldc1";
2263             mnem[ldc2] = "ldc2";
2264             mnem[ldc2w] = "ldc2w";
2265             mnem[iload] = "iload";
2266             mnem[lload] = "lload";
2267             mnem[fload] = "fload";
2268             mnem[dload] = "dload";
2269             mnem[aload] = "aload";
2270             mnem[iload_0] = "iload_0";
2271             mnem[lload_0] = "lload_0";
2272             mnem[fload_0] = "fload_0";
2273             mnem[dload_0] = "dload_0";
2274             mnem[aload_0] = "aload_0";
2275             mnem[iload_1] = "iload_1";
2276             mnem[lload_1] = "lload_1";
2277             mnem[fload_1] = "fload_1";
2278             mnem[dload_1] = "dload_1";
2279             mnem[aload_1] = "aload_1";
2280             mnem[iload_2] = "iload_2";
2281             mnem[lload_2] = "lload_2";
2282             mnem[fload_2] = "fload_2";
2283             mnem[dload_2] = "dload_2";
2284             mnem[aload_2] = "aload_2";
2285             mnem[iload_3] = "iload_3";
2286             mnem[lload_3] = "lload_3";
2287             mnem[fload_3] = "fload_3";
2288             mnem[dload_3] = "dload_3";
2289             mnem[aload_3] = "aload_3";
2290             mnem[iaload] = "iaload";
2291             mnem[laload] = "laload";
2292             mnem[faload] = "faload";
2293             mnem[daload] = "daload";
2294             mnem[aaload] = "aaload";
2295             mnem[baload] = "baload";
2296             mnem[caload] = "caload";
2297             mnem[saload] = "saload";
2298             mnem[istore] = "istore";
2299             mnem[lstore] = "lstore";
2300             mnem[fstore] = "fstore";
2301             mnem[dstore] = "dstore";
2302             mnem[astore] = "astore";
2303             mnem[istore_0] = "istore_0";
2304             mnem[lstore_0] = "lstore_0";
2305             mnem[fstore_0] = "fstore_0";
2306             mnem[dstore_0] = "dstore_0";
2307             mnem[astore_0] = "astore_0";
2308             mnem[istore_1] = "istore_1";
2309             mnem[lstore_1] = "lstore_1";
2310             mnem[fstore_1] = "fstore_1";
2311             mnem[dstore_1] = "dstore_1";
2312             mnem[astore_1] = "astore_1";
2313             mnem[istore_2] = "istore_2";
2314             mnem[lstore_2] = "lstore_2";
2315             mnem[fstore_2] = "fstore_2";
2316             mnem[dstore_2] = "dstore_2";
2317             mnem[astore_2] = "astore_2";
2318             mnem[istore_3] = "istore_3";
2319             mnem[lstore_3] = "lstore_3";
2320             mnem[fstore_3] = "fstore_3";
2321             mnem[dstore_3] = "dstore_3";
2322             mnem[astore_3] = "astore_3";
2323             mnem[iastore] = "iastore";
2324             mnem[lastore] = "lastore";
2325             mnem[fastore] = "fastore";
2326             mnem[dastore] = "dastore";
2327             mnem[aastore] = "aastore";
2328             mnem[bastore] = "bastore";
2329             mnem[castore] = "castore";
2330             mnem[sastore] = "sastore";
2331             mnem[pop] = "pop";
2332             mnem[pop2] = "pop2";
2333             mnem[dup] = "dup";
2334             mnem[dup_x1] = "dup_x1";
2335             mnem[dup_x2] = "dup_x2";
2336             mnem[dup2] = "dup2";
2337             mnem[dup2_x1] = "dup2_x1";
2338             mnem[dup2_x2] = "dup2_x2";
2339             mnem[swap] = "swap";
2340             mnem[iadd] = "iadd";
2341             mnem[ladd] = "ladd";
2342             mnem[fadd] = "fadd";
2343             mnem[dadd] = "dadd";
2344             mnem[isub] = "isub";
2345             mnem[lsub] = "lsub";
2346             mnem[fsub] = "fsub";
2347             mnem[dsub] = "dsub";
2348             mnem[imul] = "imul";
2349             mnem[lmul] = "lmul";
2350             mnem[fmul] = "fmul";
2351             mnem[dmul] = "dmul";
2352             mnem[idiv] = "idiv";
2353             mnem[ldiv] = "ldiv";
2354             mnem[fdiv] = "fdiv";
2355             mnem[ddiv] = "ddiv";
2356             mnem[imod] = "imod";
2357             mnem[lmod] = "lmod";
2358             mnem[fmod] = "fmod";
2359             mnem[dmod] = "dmod";
2360             mnem[ineg] = "ineg";
2361             mnem[lneg] = "lneg";
2362             mnem[fneg] = "fneg";
2363             mnem[dneg] = "dneg";
2364             mnem[ishl] = "ishl";
2365             mnem[lshl] = "lshl";
2366             mnem[ishr] = "ishr";
2367             mnem[lshr] = "lshr";
2368             mnem[iushr] = "iushr";
2369             mnem[lushr] = "lushr";
2370             mnem[iand] = "iand";
2371             mnem[land] = "land";
2372             mnem[ior] = "ior";
2373             mnem[lor] = "lor";
2374             mnem[ixor] = "ixor";
2375             mnem[lxor] = "lxor";
2376             mnem[iinc] = "iinc";
2377             mnem[i2l] = "i2l";
2378             mnem[i2f] = "i2f";
2379             mnem[i2d] = "i2d";
2380             mnem[l2i] = "l2i";
2381             mnem[l2f] = "l2f";
2382             mnem[l2d] = "l2d";
2383             mnem[f2i] = "f2i";
2384             mnem[f2l] = "f2l";
2385             mnem[f2d] = "f2d";
2386             mnem[d2i] = "d2i";
2387             mnem[d2l] = "d2l";
2388             mnem[d2f] = "d2f";
2389             mnem[int2byte] = "int2byte";
2390             mnem[int2char] = "int2char";
2391             mnem[int2short] = "int2short";
2392             mnem[lcmp] = "lcmp";
2393             mnem[fcmpl] = "fcmpl";
2394             mnem[fcmpg] = "fcmpg";
2395             mnem[dcmpl] = "dcmpl";
2396             mnem[dcmpg] = "dcmpg";
2397             mnem[ifeq] = "ifeq";
2398             mnem[ifne] = "ifne";
2399             mnem[iflt] = "iflt";
2400             mnem[ifge] = "ifge";
2401             mnem[ifgt] = "ifgt";
2402             mnem[ifle] = "ifle";
2403             mnem[if_icmpeq] = "if_icmpeq";
2404             mnem[if_icmpne] = "if_icmpne";
2405             mnem[if_icmplt] = "if_icmplt";
2406             mnem[if_icmpge] = "if_icmpge";
2407             mnem[if_icmpgt] = "if_icmpgt";
2408             mnem[if_icmple] = "if_icmple";
2409             mnem[if_acmpeq] = "if_acmpeq";
2410             mnem[if_acmpne] = "if_acmpne";
2411             mnem[goto_] = "goto_";
2412             mnem[jsr] = "jsr";
2413             mnem[ret] = "ret";
2414             mnem[tableswitch] = "tableswitch";
2415             mnem[lookupswitch] = "lookupswitch";
2416             mnem[ireturn] = "ireturn";
2417             mnem[lreturn] = "lreturn";
2418             mnem[freturn] = "freturn";
2419             mnem[dreturn] = "dreturn";
2420             mnem[areturn] = "areturn";
2421             mnem[return_] = "return_";
2422             mnem[getstatic] = "getstatic";
2423             mnem[putstatic] = "putstatic";
2424             mnem[getfield] = "getfield";
2425             mnem[putfield] = "putfield";
2426             mnem[invokevirtual] = "invokevirtual";
2427             mnem[invokespecial] = "invokespecial";
2428             mnem[invokestatic] = "invokestatic";
2429             mnem[invokeinterface] = "invokeinterface";
2430             mnem[invokedynamic] = "invokedynamic";
2431             mnem[new_] = "new_";
2432             mnem[newarray] = "newarray";
2433             mnem[anewarray] = "anewarray";
2434             mnem[arraylength] = "arraylength";
2435             mnem[athrow] = "athrow";
2436             mnem[checkcast] = "checkcast";
2437             mnem[instanceof_] = "instanceof_";
2438             mnem[monitorenter] = "monitorenter";
2439             mnem[monitorexit] = "monitorexit";
2440             mnem[wide] = "wide";
2441             mnem[multianewarray] = "multianewarray";
2442             mnem[if_acmp_null] = "if_acmp_null";
2443             mnem[if_acmp_nonnull] = "if_acmp_nonnull";
2444             mnem[goto_w] = "goto_w";
2445             mnem[jsr_w] = "jsr_w";
2446             mnem[breakpoint] = "breakpoint";
2447         }
2448     }
2449 }