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