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