rev 47452 : imported patch jdk-new-asmv6.patch

   1 /*
   2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.  Oracle designates this
   7  * particular file as subject to the "Classpath" exception as provided
   8  * by Oracle in the LICENSE file that accompanied this code.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /*
  26  * This file is available under and governed by the GNU General Public
  27  * License version 2 only, as published by the Free Software Foundation.
  28  * However, the following notice accompanied the original version of this
  29  * file:
  30  *
  31  * ASM: a very small and fast Java bytecode manipulation framework
  32  * Copyright (c) 2000-2011 INRIA, France Telecom
  33  * All rights reserved.
  34  *
  35  * Redistribution and use in source and binary forms, with or without
  36  * modification, are permitted provided that the following conditions
  37  * are met:
  38  * 1. Redistributions of source code must retain the above copyright
  39  *    notice, this list of conditions and the following disclaimer.
  40  * 2. Redistributions in binary form must reproduce the above copyright
  41  *    notice, this list of conditions and the following disclaimer in the
  42  *    documentation and/or other materials provided with the distribution.
  43  * 3. Neither the name of the copyright holders nor the names of its
  44  *    contributors may be used to endorse or promote products derived from
  45  *    this software without specific prior written permission.
  46  *
  47  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  48  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  49  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  50  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  51  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  52  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  53  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  54  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  55  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  56  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  57  * THE POSSIBILITY OF SUCH DAMAGE.
  58  */
  59 package jdk.internal.org.objectweb.asm;
  60 
  61 /**
  62  * Information about the input and output stack map frames of a basic block.
  63  *
  64  * @author Eric Bruneton
  65  */
  66 final class Frame {
  67 
  68     /*
  69      * Frames are computed in a two steps process: during the visit of each
  70      * instruction, the state of the frame at the end of current basic block is
  71      * updated by simulating the action of the instruction on the previous state
  72      * of this so called "output frame". In visitMaxs, a fix point algorithm is
  73      * used to compute the "input frame" of each basic block, i.e. the stack map
  74      * frame at the beginning of the basic block, starting from the input frame
  75      * of the first basic block (which is computed from the method descriptor),
  76      * and by using the previously computed output frames to compute the input
  77      * state of the other blocks.
  78      *
  79      * All output and input frames are stored as arrays of integers. Reference
  80      * and array types are represented by an index into a type table (which is
  81      * not the same as the constant pool of the class, in order to avoid adding
  82      * unnecessary constants in the pool - not all computed frames will end up
  83      * being stored in the stack map table). This allows very fast type
  84      * comparisons.
  85      *
  86      * Output stack map frames are computed relatively to the input frame of the
  87      * basic block, which is not yet known when output frames are computed. It
  88      * is therefore necessary to be able to represent abstract types such as
  89      * "the type at position x in the input frame locals" or "the type at
  90      * position x from the top of the input frame stack" or even "the type at
  91      * position x in the input frame, with y more (or less) array dimensions".
  92      * This explains the rather complicated type format used in output frames.
  93      *
  94      * This format is the following: DIM KIND VALUE (4, 4 and 24 bits). DIM is a
  95      * signed number of array dimensions (from -8 to 7). KIND is either BASE,
  96      * LOCAL or STACK. BASE is used for types that are not relative to the input
  97      * frame. LOCAL is used for types that are relative to the input local
  98      * variable types. STACK is used for types that are relative to the input
  99      * stack types. VALUE depends on KIND. For LOCAL types, it is an index in
 100      * the input local variable types. For STACK types, it is a position
 101      * relatively to the top of input frame stack. For BASE types, it is either
 102      * one of the constants defined below, or for OBJECT and UNINITIALIZED
 103      * types, a tag and an index in the type table.
 104      *
 105      * Output frames can contain types of any kind and with a positive or
 106      * negative dimension (and even unassigned types, represented by 0 - which
 107      * does not correspond to any valid type value). Input frames can only
 108      * contain BASE types of positive or null dimension. In all cases the type
 109      * table contains only internal type names (array type descriptors are
 110      * forbidden - dimensions must be represented through the DIM field).
 111      *
 112      * The LONG and DOUBLE types are always represented by using two slots (LONG
 113      * + TOP or DOUBLE + TOP), for local variable types as well as in the
 114      * operand stack. This is necessary to be able to simulate DUPx_y
 115      * instructions, whose effect would be dependent on the actual type values
 116      * if types were always represented by a single slot in the stack (and this
 117      * is not possible, since actual type values are not always known - cf LOCAL
 118      * and STACK type kinds).
 119      */
 120 
 121     /**
 122      * Mask to get the dimension of a frame type. This dimension is a signed
 123      * integer between -8 and 7.
 124      */
 125     static final int DIM = 0xF0000000;
 126 
 127     /**
 128      * Constant to be added to a type to get a type with one more dimension.
 129      */
 130     static final int ARRAY_OF = 0x10000000;
 131 
 132     /**
 133      * Constant to be added to a type to get a type with one less dimension.
 134      */
 135     static final int ELEMENT_OF = 0xF0000000;
 136 
 137     /**
 138      * Mask to get the kind of a frame type.
 139      *
 140      * @see #BASE
 141      * @see #LOCAL
 142      * @see #STACK
 143      */
 144     static final int KIND = 0xF000000;
 145 
 146     /**
 147      * Flag used for LOCAL and STACK types. Indicates that if this type happens
 148      * to be a long or double type (during the computations of input frames),
 149      * then it must be set to TOP because the second word of this value has been
 150      * reused to store other data in the basic block. Hence the first word no
 151      * longer stores a valid long or double value.
 152      */
 153     static final int TOP_IF_LONG_OR_DOUBLE = 0x800000;
 154 
 155     /**
 156      * Mask to get the value of a frame type.
 157      */
 158     static final int VALUE = 0x7FFFFF;
 159 
 160     /**
 161      * Mask to get the kind of base types.
 162      */
 163     static final int BASE_KIND = 0xFF00000;
 164 
 165     /**
 166      * Mask to get the value of base types.
 167      */
 168     static final int BASE_VALUE = 0xFFFFF;
 169 
 170     /**
 171      * Kind of the types that are not relative to an input stack map frame.
 172      */
 173     static final int BASE = 0x1000000;
 174 
 175     /**
 176      * Base kind of the base reference types. The BASE_VALUE of such types is an
 177      * index into the type table.
 178      */
 179     static final int OBJECT = BASE | 0x700000;
 180 
 181     /**
 182      * Base kind of the uninitialized base types. The BASE_VALUE of such types
 183      * in an index into the type table (the Item at that index contains both an
 184      * instruction offset and an internal class name).
 185      */
 186     static final int UNINITIALIZED = BASE | 0x800000;
 187 
 188     /**
 189      * Kind of the types that are relative to the local variable types of an
 190      * input stack map frame. The value of such types is a local variable index.
 191      */
 192     private static final int LOCAL = 0x2000000;
 193 
 194     /**
 195      * Kind of the the types that are relative to the stack of an input stack
 196      * map frame. The value of such types is a position relatively to the top of
 197      * this stack.
 198      */
 199     private static final int STACK = 0x3000000;
 200 
 201     /**
 202      * The TOP type. This is a BASE type.
 203      */
 204     static final int TOP = BASE | 0;
 205 
 206     /**
 207      * The BOOLEAN type. This is a BASE type mainly used for array types.
 208      */
 209     static final int BOOLEAN = BASE | 9;
 210 
 211     /**
 212      * The BYTE type. This is a BASE type mainly used for array types.
 213      */
 214     static final int BYTE = BASE | 10;
 215 
 216     /**
 217      * The CHAR type. This is a BASE type mainly used for array types.
 218      */
 219     static final int CHAR = BASE | 11;
 220 
 221     /**
 222      * The SHORT type. This is a BASE type mainly used for array types.
 223      */
 224     static final int SHORT = BASE | 12;
 225 
 226     /**
 227      * The INTEGER type. This is a BASE type.
 228      */
 229     static final int INTEGER = BASE | 1;
 230 
 231     /**
 232      * The FLOAT type. This is a BASE type.
 233      */
 234     static final int FLOAT = BASE | 2;
 235 
 236     /**
 237      * The DOUBLE type. This is a BASE type.
 238      */
 239     static final int DOUBLE = BASE | 3;
 240 
 241     /**
 242      * The LONG type. This is a BASE type.
 243      */
 244     static final int LONG = BASE | 4;
 245 
 246     /**
 247      * The NULL type. This is a BASE type.
 248      */
 249     static final int NULL = BASE | 5;
 250 
 251     /**
 252      * The UNINITIALIZED_THIS type. This is a BASE type.
 253      */
 254     static final int UNINITIALIZED_THIS = BASE | 6;
 255 
 256     /**
 257      * The stack size variation corresponding to each JVM instruction. This
 258      * stack variation is equal to the size of the values produced by an
 259      * instruction, minus the size of the values consumed by this instruction.
 260      */
 261     static final int[] SIZE;
 262 
 263     /**
 264      * Computes the stack size variation corresponding to each JVM instruction.
 265      */
 266     static {
 267         int i;
 268         int[] b = new int[202];
 269         String s = "EFFFFFFFFGGFFFGGFFFEEFGFGFEEEEEEEEEEEEEEEEEEEEDEDEDDDDD"
 270                 + "CDCDEEEEEEEEEEEEEEEEEEEEBABABBBBDCFFFGGGEDCDCDCDCDCDCDCDCD"
 271                 + "CDCEEEEDDDDDDDCDCDCEFEFDDEEFFDEDEEEBDDBBDDDDDDCCCCCCCCEFED"
 272                 + "DDCDCDEEEEEEEEEEFEEEEEEDDEEDDEE";
 273         for (i = 0; i < b.length; ++i) {
 274             b[i] = s.charAt(i) - 'E';
 275         }
 276         SIZE = b;
 277 
 278         // code to generate the above string
 279         //
 280         // int NA = 0; // not applicable (unused opcode or variable size opcode)
 281         //
 282         // b = new int[] {
 283         // 0, //NOP, // visitInsn
 284         // 1, //ACONST_NULL, // -
 285         // 1, //ICONST_M1, // -
 286         // 1, //ICONST_0, // -
 287         // 1, //ICONST_1, // -
 288         // 1, //ICONST_2, // -
 289         // 1, //ICONST_3, // -
 290         // 1, //ICONST_4, // -
 291         // 1, //ICONST_5, // -
 292         // 2, //LCONST_0, // -
 293         // 2, //LCONST_1, // -
 294         // 1, //FCONST_0, // -
 295         // 1, //FCONST_1, // -
 296         // 1, //FCONST_2, // -
 297         // 2, //DCONST_0, // -
 298         // 2, //DCONST_1, // -
 299         // 1, //BIPUSH, // visitIntInsn
 300         // 1, //SIPUSH, // -
 301         // 1, //LDC, // visitLdcInsn
 302         // NA, //LDC_W, // -
 303         // NA, //LDC2_W, // -
 304         // 1, //ILOAD, // visitVarInsn
 305         // 2, //LLOAD, // -
 306         // 1, //FLOAD, // -
 307         // 2, //DLOAD, // -
 308         // 1, //ALOAD, // -
 309         // NA, //ILOAD_0, // -
 310         // NA, //ILOAD_1, // -
 311         // NA, //ILOAD_2, // -
 312         // NA, //ILOAD_3, // -
 313         // NA, //LLOAD_0, // -
 314         // NA, //LLOAD_1, // -
 315         // NA, //LLOAD_2, // -
 316         // NA, //LLOAD_3, // -
 317         // NA, //FLOAD_0, // -
 318         // NA, //FLOAD_1, // -
 319         // NA, //FLOAD_2, // -
 320         // NA, //FLOAD_3, // -
 321         // NA, //DLOAD_0, // -
 322         // NA, //DLOAD_1, // -
 323         // NA, //DLOAD_2, // -
 324         // NA, //DLOAD_3, // -
 325         // NA, //ALOAD_0, // -
 326         // NA, //ALOAD_1, // -
 327         // NA, //ALOAD_2, // -
 328         // NA, //ALOAD_3, // -
 329         // -1, //IALOAD, // visitInsn
 330         // 0, //LALOAD, // -
 331         // -1, //FALOAD, // -
 332         // 0, //DALOAD, // -
 333         // -1, //AALOAD, // -
 334         // -1, //BALOAD, // -
 335         // -1, //CALOAD, // -
 336         // -1, //SALOAD, // -
 337         // -1, //ISTORE, // visitVarInsn
 338         // -2, //LSTORE, // -
 339         // -1, //FSTORE, // -
 340         // -2, //DSTORE, // -
 341         // -1, //ASTORE, // -
 342         // NA, //ISTORE_0, // -
 343         // NA, //ISTORE_1, // -
 344         // NA, //ISTORE_2, // -
 345         // NA, //ISTORE_3, // -
 346         // NA, //LSTORE_0, // -
 347         // NA, //LSTORE_1, // -
 348         // NA, //LSTORE_2, // -
 349         // NA, //LSTORE_3, // -
 350         // NA, //FSTORE_0, // -
 351         // NA, //FSTORE_1, // -
 352         // NA, //FSTORE_2, // -
 353         // NA, //FSTORE_3, // -
 354         // NA, //DSTORE_0, // -
 355         // NA, //DSTORE_1, // -
 356         // NA, //DSTORE_2, // -
 357         // NA, //DSTORE_3, // -
 358         // NA, //ASTORE_0, // -
 359         // NA, //ASTORE_1, // -
 360         // NA, //ASTORE_2, // -
 361         // NA, //ASTORE_3, // -
 362         // -3, //IASTORE, // visitInsn
 363         // -4, //LASTORE, // -
 364         // -3, //FASTORE, // -
 365         // -4, //DASTORE, // -
 366         // -3, //AASTORE, // -
 367         // -3, //BASTORE, // -
 368         // -3, //CASTORE, // -
 369         // -3, //SASTORE, // -
 370         // -1, //POP, // -
 371         // -2, //POP2, // -
 372         // 1, //DUP, // -
 373         // 1, //DUP_X1, // -
 374         // 1, //DUP_X2, // -
 375         // 2, //DUP2, // -
 376         // 2, //DUP2_X1, // -
 377         // 2, //DUP2_X2, // -
 378         // 0, //SWAP, // -
 379         // -1, //IADD, // -
 380         // -2, //LADD, // -
 381         // -1, //FADD, // -
 382         // -2, //DADD, // -
 383         // -1, //ISUB, // -
 384         // -2, //LSUB, // -
 385         // -1, //FSUB, // -
 386         // -2, //DSUB, // -
 387         // -1, //IMUL, // -
 388         // -2, //LMUL, // -
 389         // -1, //FMUL, // -
 390         // -2, //DMUL, // -
 391         // -1, //IDIV, // -
 392         // -2, //LDIV, // -
 393         // -1, //FDIV, // -
 394         // -2, //DDIV, // -
 395         // -1, //IREM, // -
 396         // -2, //LREM, // -
 397         // -1, //FREM, // -
 398         // -2, //DREM, // -
 399         // 0, //INEG, // -
 400         // 0, //LNEG, // -
 401         // 0, //FNEG, // -
 402         // 0, //DNEG, // -
 403         // -1, //ISHL, // -
 404         // -1, //LSHL, // -
 405         // -1, //ISHR, // -
 406         // -1, //LSHR, // -
 407         // -1, //IUSHR, // -
 408         // -1, //LUSHR, // -
 409         // -1, //IAND, // -
 410         // -2, //LAND, // -
 411         // -1, //IOR, // -
 412         // -2, //LOR, // -
 413         // -1, //IXOR, // -
 414         // -2, //LXOR, // -
 415         // 0, //IINC, // visitIincInsn
 416         // 1, //I2L, // visitInsn
 417         // 0, //I2F, // -
 418         // 1, //I2D, // -
 419         // -1, //L2I, // -
 420         // -1, //L2F, // -
 421         // 0, //L2D, // -
 422         // 0, //F2I, // -
 423         // 1, //F2L, // -
 424         // 1, //F2D, // -
 425         // -1, //D2I, // -
 426         // 0, //D2L, // -
 427         // -1, //D2F, // -
 428         // 0, //I2B, // -
 429         // 0, //I2C, // -
 430         // 0, //I2S, // -
 431         // -3, //LCMP, // -
 432         // -1, //FCMPL, // -
 433         // -1, //FCMPG, // -
 434         // -3, //DCMPL, // -
 435         // -3, //DCMPG, // -
 436         // -1, //IFEQ, // visitJumpInsn
 437         // -1, //IFNE, // -
 438         // -1, //IFLT, // -
 439         // -1, //IFGE, // -
 440         // -1, //IFGT, // -
 441         // -1, //IFLE, // -
 442         // -2, //IF_ICMPEQ, // -
 443         // -2, //IF_ICMPNE, // -
 444         // -2, //IF_ICMPLT, // -
 445         // -2, //IF_ICMPGE, // -
 446         // -2, //IF_ICMPGT, // -
 447         // -2, //IF_ICMPLE, // -
 448         // -2, //IF_ACMPEQ, // -
 449         // -2, //IF_ACMPNE, // -
 450         // 0, //GOTO, // -
 451         // 1, //JSR, // -
 452         // 0, //RET, // visitVarInsn
 453         // -1, //TABLESWITCH, // visiTableSwitchInsn
 454         // -1, //LOOKUPSWITCH, // visitLookupSwitch
 455         // -1, //IRETURN, // visitInsn
 456         // -2, //LRETURN, // -
 457         // -1, //FRETURN, // -
 458         // -2, //DRETURN, // -
 459         // -1, //ARETURN, // -
 460         // 0, //RETURN, // -
 461         // NA, //GETSTATIC, // visitFieldInsn
 462         // NA, //PUTSTATIC, // -
 463         // NA, //GETFIELD, // -
 464         // NA, //PUTFIELD, // -
 465         // NA, //INVOKEVIRTUAL, // visitMethodInsn
 466         // NA, //INVOKESPECIAL, // -
 467         // NA, //INVOKESTATIC, // -
 468         // NA, //INVOKEINTERFACE, // -
 469         // NA, //INVOKEDYNAMIC, // visitInvokeDynamicInsn
 470         // 1, //NEW, // visitTypeInsn
 471         // 0, //NEWARRAY, // visitIntInsn
 472         // 0, //ANEWARRAY, // visitTypeInsn
 473         // 0, //ARRAYLENGTH, // visitInsn
 474         // NA, //ATHROW, // -
 475         // 0, //CHECKCAST, // visitTypeInsn
 476         // 0, //INSTANCEOF, // -
 477         // -1, //MONITORENTER, // visitInsn
 478         // -1, //MONITOREXIT, // -
 479         // NA, //WIDE, // NOT VISITED
 480         // NA, //MULTIANEWARRAY, // visitMultiANewArrayInsn
 481         // -1, //IFNULL, // visitJumpInsn
 482         // -1, //IFNONNULL, // -
 483         // NA, //GOTO_W, // -
 484         // NA, //JSR_W, // -
 485         // };
 486         // for (i = 0; i < b.length; ++i) {
 487         // System.err.print((char)('E' + b[i]));
 488         // }
 489         // System.err.println();
 490     }
 491 
 492     /**
 493      * The label (i.e. basic block) to which these input and output stack map
 494      * frames correspond.
 495      */
 496     Label owner;
 497 
 498     /**
 499      * The input stack map frame locals.
 500      */
 501     int[] inputLocals;
 502 
 503     /**
 504      * The input stack map frame stack.
 505      */
 506     int[] inputStack;
 507 
 508     /**
 509      * The output stack map frame locals.
 510      */
 511     private int[] outputLocals;
 512 
 513     /**
 514      * The output stack map frame stack.
 515      */
 516     private int[] outputStack;
 517 
 518     /**
 519      * Relative size of the output stack. The exact semantics of this field
 520      * depends on the algorithm that is used.
 521      *
 522      * When only the maximum stack size is computed, this field is the size of
 523      * the output stack relatively to the top of the input stack.
 524      *
 525      * When the stack map frames are completely computed, this field is the
 526      * actual number of types in {@link #outputStack}.
 527      */
 528     private int outputStackTop;
 529 
 530     /**
 531      * Number of types that are initialized in the basic block.
 532      *
 533      * @see #initializations
 534      */
 535     private int initializationCount;
 536 
 537     /**
 538      * The types that are initialized in the basic block. A constructor
 539      * invocation on an UNINITIALIZED or UNINITIALIZED_THIS type must replace
 540      * <i>every occurence</i> of this type in the local variables and in the
 541      * operand stack. This cannot be done during the first phase of the
 542      * algorithm since, during this phase, the local variables and the operand
 543      * stack are not completely computed. It is therefore necessary to store the
 544      * types on which constructors are invoked in the basic block, in order to
 545      * do this replacement during the second phase of the algorithm, where the
 546      * frames are fully computed. Note that this array can contain types that
 547      * are relative to input locals or to the input stack (see below for the
 548      * description of the algorithm).
 549      */
 550     private int[] initializations;
 551 
 552     /**








































































































 553      * Returns the output frame local variable type at the given index.
 554      *
 555      * @param local
 556      *            the index of the local that must be returned.
 557      * @return the output frame local variable type at the given index.
 558      */
 559     private int get(final int local) {
 560         if (outputLocals == null || local >= outputLocals.length) {
 561             // this local has never been assigned in this basic block,
 562             // so it is still equal to its value in the input frame
 563             return LOCAL | local;
 564         } else {
 565             int type = outputLocals[local];
 566             if (type == 0) {
 567                 // this local has never been assigned in this basic block,
 568                 // so it is still equal to its value in the input frame
 569                 type = outputLocals[local] = LOCAL | local;
 570             }
 571             return type;
 572         }
 573     }
 574 
 575     /**
 576      * Sets the output frame local variable type at the given index.
 577      *
 578      * @param local
 579      *            the index of the local that must be set.
 580      * @param type
 581      *            the value of the local that must be set.
 582      */
 583     private void set(final int local, final int type) {
 584         // creates and/or resizes the output local variables array if necessary
 585         if (outputLocals == null) {
 586             outputLocals = new int[10];
 587         }
 588         int n = outputLocals.length;
 589         if (local >= n) {
 590             int[] t = new int[Math.max(local + 1, 2 * n)];
 591             System.arraycopy(outputLocals, 0, t, 0, n);
 592             outputLocals = t;
 593         }
 594         // sets the local variable
 595         outputLocals[local] = type;
 596     }
 597 
 598     /**
 599      * Pushes a new type onto the output frame stack.
 600      *
 601      * @param type
 602      *            the type that must be pushed.
 603      */
 604     private void push(final int type) {
 605         // creates and/or resizes the output stack array if necessary
 606         if (outputStack == null) {
 607             outputStack = new int[10];
 608         }
 609         int n = outputStack.length;
 610         if (outputStackTop >= n) {
 611             int[] t = new int[Math.max(outputStackTop + 1, 2 * n)];
 612             System.arraycopy(outputStack, 0, t, 0, n);
 613             outputStack = t;
 614         }
 615         // pushes the type on the output stack
 616         outputStack[outputStackTop++] = type;
 617         // updates the maximun height reached by the output stack, if needed
 618         int top = owner.inputStackTop + outputStackTop;
 619         if (top > owner.outputStackMax) {
 620             owner.outputStackMax = top;
 621         }
 622     }
 623 
 624     /**
 625      * Pushes a new type onto the output frame stack.
 626      *
 627      * @param cw
 628      *            the ClassWriter to which this label belongs.
 629      * @param desc
 630      *            the descriptor of the type to be pushed. Can also be a method
 631      *            descriptor (in this case this method pushes its return type
 632      *            onto the output frame stack).
 633      */
 634     private void push(final ClassWriter cw, final String desc) {
 635         int type = type(cw, desc);
 636         if (type != 0) {
 637             push(type);
 638             if (type == LONG || type == DOUBLE) {
 639                 push(TOP);
 640             }
 641         }
 642     }
 643 
 644     /**
 645      * Returns the int encoding of the given type.
 646      *
 647      * @param cw
 648      *            the ClassWriter to which this label belongs.
 649      * @param desc
 650      *            a type descriptor.
 651      * @return the int encoding of the given type.
 652      */
 653     private static int type(final ClassWriter cw, final String desc) {
 654         String t;
 655         int index = desc.charAt(0) == '(' ? desc.indexOf(')') + 1 : 0;
 656         switch (desc.charAt(index)) {
 657         case 'V':
 658             return 0;
 659         case 'Z':
 660         case 'C':
 661         case 'B':
 662         case 'S':
 663         case 'I':
 664             return INTEGER;
 665         case 'F':
 666             return FLOAT;
 667         case 'J':
 668             return LONG;
 669         case 'D':
 670             return DOUBLE;
 671         case 'L':
 672             // stores the internal name, not the descriptor!
 673             t = desc.substring(index + 1, desc.length() - 1);
 674             return OBJECT | cw.addType(t);
 675             // case '[':
 676         default:
 677             // extracts the dimensions and the element type
 678             int data;
 679             int dims = index + 1;
 680             while (desc.charAt(dims) == '[') {
 681                 ++dims;
 682             }
 683             switch (desc.charAt(dims)) {
 684             case 'Z':
 685                 data = BOOLEAN;
 686                 break;
 687             case 'C':
 688                 data = CHAR;
 689                 break;
 690             case 'B':
 691                 data = BYTE;
 692                 break;
 693             case 'S':
 694                 data = SHORT;
 695                 break;
 696             case 'I':
 697                 data = INTEGER;
 698                 break;
 699             case 'F':
 700                 data = FLOAT;
 701                 break;
 702             case 'J':
 703                 data = LONG;
 704                 break;
 705             case 'D':
 706                 data = DOUBLE;
 707                 break;
 708             // case 'L':
 709             default:
 710                 // stores the internal name, not the descriptor
 711                 t = desc.substring(dims + 1, desc.length() - 1);
 712                 data = OBJECT | cw.addType(t);
 713             }
 714             return (dims - index) << 28 | data;
 715         }
 716     }
 717 
 718     /**
 719      * Pops a type from the output frame stack and returns its value.
 720      *
 721      * @return the type that has been popped from the output frame stack.
 722      */
 723     private int pop() {
 724         if (outputStackTop > 0) {
 725             return outputStack[--outputStackTop];
 726         } else {
 727             // if the output frame stack is empty, pops from the input stack
 728             return STACK | -(--owner.inputStackTop);
 729         }
 730     }
 731 
 732     /**
 733      * Pops the given number of types from the output frame stack.
 734      *
 735      * @param elements
 736      *            the number of types that must be popped.
 737      */
 738     private void pop(final int elements) {
 739         if (outputStackTop >= elements) {
 740             outputStackTop -= elements;
 741         } else {
 742             // if the number of elements to be popped is greater than the number
 743             // of elements in the output stack, clear it, and pops the remaining
 744             // elements from the input stack.
 745             owner.inputStackTop -= elements - outputStackTop;
 746             outputStackTop = 0;
 747         }
 748     }
 749 
 750     /**
 751      * Pops a type from the output frame stack.
 752      *
 753      * @param desc
 754      *            the descriptor of the type to be popped. Can also be a method
 755      *            descriptor (in this case this method pops the types
 756      *            corresponding to the method arguments).
 757      */
 758     private void pop(final String desc) {
 759         char c = desc.charAt(0);
 760         if (c == '(') {
 761             pop((Type.getArgumentsAndReturnSizes(desc) >> 2) - 1);
 762         } else if (c == 'J' || c == 'D') {
 763             pop(2);
 764         } else {
 765             pop(1);
 766         }
 767     }
 768 
 769     /**
 770      * Adds a new type to the list of types on which a constructor is invoked in
 771      * the basic block.
 772      *
 773      * @param var
 774      *            a type on a which a constructor is invoked.
 775      */
 776     private void init(final int var) {
 777         // creates and/or resizes the initializations array if necessary
 778         if (initializations == null) {
 779             initializations = new int[2];
 780         }
 781         int n = initializations.length;
 782         if (initializationCount >= n) {
 783             int[] t = new int[Math.max(initializationCount + 1, 2 * n)];
 784             System.arraycopy(initializations, 0, t, 0, n);
 785             initializations = t;
 786         }
 787         // stores the type to be initialized
 788         initializations[initializationCount++] = var;
 789     }
 790 
 791     /**
 792      * Replaces the given type with the appropriate type if it is one of the
 793      * types on which a constructor is invoked in the basic block.
 794      *
 795      * @param cw
 796      *            the ClassWriter to which this label belongs.
 797      * @param t
 798      *            a type
 799      * @return t or, if t is one of the types on which a constructor is invoked
 800      *         in the basic block, the type corresponding to this constructor.
 801      */
 802     private int init(final ClassWriter cw, final int t) {
 803         int s;
 804         if (t == UNINITIALIZED_THIS) {
 805             s = OBJECT | cw.addType(cw.thisName);
 806         } else if ((t & (DIM | BASE_KIND)) == UNINITIALIZED) {
 807             String type = cw.typeTable[t & BASE_VALUE].strVal1;
 808             s = OBJECT | cw.addType(type);
 809         } else {
 810             return t;
 811         }
 812         for (int j = 0; j < initializationCount; ++j) {
 813             int u = initializations[j];
 814             int dim = u & DIM;
 815             int kind = u & KIND;
 816             if (kind == LOCAL) {
 817                 u = dim + inputLocals[u & VALUE];
 818             } else if (kind == STACK) {
 819                 u = dim + inputStack[inputStack.length - (u & VALUE)];
 820             }
 821             if (t == u) {
 822                 return s;
 823             }
 824         }
 825         return t;
 826     }
 827 
 828     /**
 829      * Initializes the input frame of the first basic block from the method
 830      * descriptor.
 831      *
 832      * @param cw
 833      *            the ClassWriter to which this label belongs.
 834      * @param access
 835      *            the access flags of the method to which this label belongs.
 836      * @param args
 837      *            the formal parameter types of this method.
 838      * @param maxLocals
 839      *            the maximum number of local variables of this method.
 840      */
 841     void initInputFrame(final ClassWriter cw, final int access,
 842             final Type[] args, final int maxLocals) {
 843         inputLocals = new int[maxLocals];
 844         inputStack = new int[0];
 845         int i = 0;
 846         if ((access & Opcodes.ACC_STATIC) == 0) {
 847             if ((access & MethodWriter.ACC_CONSTRUCTOR) == 0) {
 848                 inputLocals[i++] = OBJECT | cw.addType(cw.thisName);
 849             } else {
 850                 inputLocals[i++] = UNINITIALIZED_THIS;
 851             }
 852         }
 853         for (int j = 0; j < args.length; ++j) {
 854             int t = type(cw, args[j].getDescriptor());
 855             inputLocals[i++] = t;
 856             if (t == LONG || t == DOUBLE) {
 857                 inputLocals[i++] = TOP;
 858             }
 859         }
 860         while (i < maxLocals) {
 861             inputLocals[i++] = TOP;
 862         }
 863     }
 864 
 865     /**
 866      * Simulates the action of the given instruction on the output stack frame.
 867      *
 868      * @param opcode
 869      *            the opcode of the instruction.
 870      * @param arg
 871      *            the operand of the instruction, if any.
 872      * @param cw
 873      *            the class writer to which this label belongs.
 874      * @param item
 875      *            the operand of the instructions, if any.
 876      */
 877     void execute(final int opcode, final int arg, final ClassWriter cw,
 878             final Item item) {
 879         int t1, t2, t3, t4;
 880         switch (opcode) {
 881         case Opcodes.NOP:
 882         case Opcodes.INEG:
 883         case Opcodes.LNEG:
 884         case Opcodes.FNEG:
 885         case Opcodes.DNEG:
 886         case Opcodes.I2B:
 887         case Opcodes.I2C:
 888         case Opcodes.I2S:
 889         case Opcodes.GOTO:
 890         case Opcodes.RETURN:
 891             break;
 892         case Opcodes.ACONST_NULL:
 893             push(NULL);
 894             break;
 895         case Opcodes.ICONST_M1:
 896         case Opcodes.ICONST_0:
 897         case Opcodes.ICONST_1:
 898         case Opcodes.ICONST_2:
 899         case Opcodes.ICONST_3:
 900         case Opcodes.ICONST_4:
 901         case Opcodes.ICONST_5:
 902         case Opcodes.BIPUSH:
 903         case Opcodes.SIPUSH:
 904         case Opcodes.ILOAD:
 905             push(INTEGER);
 906             break;
 907         case Opcodes.LCONST_0:
 908         case Opcodes.LCONST_1:
 909         case Opcodes.LLOAD:
 910             push(LONG);
 911             push(TOP);
 912             break;
 913         case Opcodes.FCONST_0:
 914         case Opcodes.FCONST_1:
 915         case Opcodes.FCONST_2:
 916         case Opcodes.FLOAD:
 917             push(FLOAT);
 918             break;
 919         case Opcodes.DCONST_0:
 920         case Opcodes.DCONST_1:
 921         case Opcodes.DLOAD:
 922             push(DOUBLE);
 923             push(TOP);
 924             break;
 925         case Opcodes.LDC:
 926             switch (item.type) {
 927             case ClassWriter.INT:
 928                 push(INTEGER);
 929                 break;
 930             case ClassWriter.LONG:
 931                 push(LONG);
 932                 push(TOP);
 933                 break;
 934             case ClassWriter.FLOAT:
 935                 push(FLOAT);
 936                 break;
 937             case ClassWriter.DOUBLE:
 938                 push(DOUBLE);
 939                 push(TOP);
 940                 break;
 941             case ClassWriter.CLASS:
 942                 push(OBJECT | cw.addType("java/lang/Class"));
 943                 break;
 944             case ClassWriter.STR:
 945                 push(OBJECT | cw.addType("java/lang/String"));
 946                 break;
 947             case ClassWriter.MTYPE:
 948                 push(OBJECT | cw.addType("java/lang/invoke/MethodType"));
 949                 break;
 950             // case ClassWriter.HANDLE_BASE + [1..9]:
 951             default:
 952                 push(OBJECT | cw.addType("java/lang/invoke/MethodHandle"));
 953             }
 954             break;
 955         case Opcodes.ALOAD:
 956             push(get(arg));
 957             break;
 958         case Opcodes.IALOAD:
 959         case Opcodes.BALOAD:
 960         case Opcodes.CALOAD:
 961         case Opcodes.SALOAD:
 962             pop(2);
 963             push(INTEGER);
 964             break;
 965         case Opcodes.LALOAD:
 966         case Opcodes.D2L:
 967             pop(2);
 968             push(LONG);
 969             push(TOP);
 970             break;
 971         case Opcodes.FALOAD:
 972             pop(2);
 973             push(FLOAT);
 974             break;
 975         case Opcodes.DALOAD:
 976         case Opcodes.L2D:
 977             pop(2);
 978             push(DOUBLE);
 979             push(TOP);
 980             break;
 981         case Opcodes.AALOAD:
 982             pop(1);
 983             t1 = pop();
 984             push(ELEMENT_OF + t1);
 985             break;
 986         case Opcodes.ISTORE:
 987         case Opcodes.FSTORE:
 988         case Opcodes.ASTORE:
 989             t1 = pop();
 990             set(arg, t1);
 991             if (arg > 0) {
 992                 t2 = get(arg - 1);
 993                 // if t2 is of kind STACK or LOCAL we cannot know its size!
 994                 if (t2 == LONG || t2 == DOUBLE) {
 995                     set(arg - 1, TOP);
 996                 } else if ((t2 & KIND) != BASE) {
 997                     set(arg - 1, t2 | TOP_IF_LONG_OR_DOUBLE);
 998                 }
 999             }
1000             break;
1001         case Opcodes.LSTORE:
1002         case Opcodes.DSTORE:
1003             pop(1);
1004             t1 = pop();
1005             set(arg, t1);
1006             set(arg + 1, TOP);
1007             if (arg > 0) {
1008                 t2 = get(arg - 1);
1009                 // if t2 is of kind STACK or LOCAL we cannot know its size!
1010                 if (t2 == LONG || t2 == DOUBLE) {
1011                     set(arg - 1, TOP);
1012                 } else if ((t2 & KIND) != BASE) {
1013                     set(arg - 1, t2 | TOP_IF_LONG_OR_DOUBLE);
1014                 }
1015             }
1016             break;
1017         case Opcodes.IASTORE:
1018         case Opcodes.BASTORE:
1019         case Opcodes.CASTORE:
1020         case Opcodes.SASTORE:
1021         case Opcodes.FASTORE:
1022         case Opcodes.AASTORE:
1023             pop(3);
1024             break;
1025         case Opcodes.LASTORE:
1026         case Opcodes.DASTORE:
1027             pop(4);
1028             break;
1029         case Opcodes.POP:
1030         case Opcodes.IFEQ:
1031         case Opcodes.IFNE:
1032         case Opcodes.IFLT:
1033         case Opcodes.IFGE:
1034         case Opcodes.IFGT:
1035         case Opcodes.IFLE:
1036         case Opcodes.IRETURN:
1037         case Opcodes.FRETURN:
1038         case Opcodes.ARETURN:
1039         case Opcodes.TABLESWITCH:
1040         case Opcodes.LOOKUPSWITCH:
1041         case Opcodes.ATHROW:
1042         case Opcodes.MONITORENTER:
1043         case Opcodes.MONITOREXIT:
1044         case Opcodes.IFNULL:
1045         case Opcodes.IFNONNULL:
1046             pop(1);
1047             break;
1048         case Opcodes.POP2:
1049         case Opcodes.IF_ICMPEQ:
1050         case Opcodes.IF_ICMPNE:
1051         case Opcodes.IF_ICMPLT:
1052         case Opcodes.IF_ICMPGE:
1053         case Opcodes.IF_ICMPGT:
1054         case Opcodes.IF_ICMPLE:
1055         case Opcodes.IF_ACMPEQ:
1056         case Opcodes.IF_ACMPNE:
1057         case Opcodes.LRETURN:
1058         case Opcodes.DRETURN:
1059             pop(2);
1060             break;
1061         case Opcodes.DUP:
1062             t1 = pop();
1063             push(t1);
1064             push(t1);
1065             break;
1066         case Opcodes.DUP_X1:
1067             t1 = pop();
1068             t2 = pop();
1069             push(t1);
1070             push(t2);
1071             push(t1);
1072             break;
1073         case Opcodes.DUP_X2:
1074             t1 = pop();
1075             t2 = pop();
1076             t3 = pop();
1077             push(t1);
1078             push(t3);
1079             push(t2);
1080             push(t1);
1081             break;
1082         case Opcodes.DUP2:
1083             t1 = pop();
1084             t2 = pop();
1085             push(t2);
1086             push(t1);
1087             push(t2);
1088             push(t1);
1089             break;
1090         case Opcodes.DUP2_X1:
1091             t1 = pop();
1092             t2 = pop();
1093             t3 = pop();
1094             push(t2);
1095             push(t1);
1096             push(t3);
1097             push(t2);
1098             push(t1);
1099             break;
1100         case Opcodes.DUP2_X2:
1101             t1 = pop();
1102             t2 = pop();
1103             t3 = pop();
1104             t4 = pop();
1105             push(t2);
1106             push(t1);
1107             push(t4);
1108             push(t3);
1109             push(t2);
1110             push(t1);
1111             break;
1112         case Opcodes.SWAP:
1113             t1 = pop();
1114             t2 = pop();
1115             push(t1);
1116             push(t2);
1117             break;
1118         case Opcodes.IADD:
1119         case Opcodes.ISUB:
1120         case Opcodes.IMUL:
1121         case Opcodes.IDIV:
1122         case Opcodes.IREM:
1123         case Opcodes.IAND:
1124         case Opcodes.IOR:
1125         case Opcodes.IXOR:
1126         case Opcodes.ISHL:
1127         case Opcodes.ISHR:
1128         case Opcodes.IUSHR:
1129         case Opcodes.L2I:
1130         case Opcodes.D2I:
1131         case Opcodes.FCMPL:
1132         case Opcodes.FCMPG:
1133             pop(2);
1134             push(INTEGER);
1135             break;
1136         case Opcodes.LADD:
1137         case Opcodes.LSUB:
1138         case Opcodes.LMUL:
1139         case Opcodes.LDIV:
1140         case Opcodes.LREM:
1141         case Opcodes.LAND:
1142         case Opcodes.LOR:
1143         case Opcodes.LXOR:
1144             pop(4);
1145             push(LONG);
1146             push(TOP);
1147             break;
1148         case Opcodes.FADD:
1149         case Opcodes.FSUB:
1150         case Opcodes.FMUL:
1151         case Opcodes.FDIV:
1152         case Opcodes.FREM:
1153         case Opcodes.L2F:
1154         case Opcodes.D2F:
1155             pop(2);
1156             push(FLOAT);
1157             break;
1158         case Opcodes.DADD:
1159         case Opcodes.DSUB:
1160         case Opcodes.DMUL:
1161         case Opcodes.DDIV:
1162         case Opcodes.DREM:
1163             pop(4);
1164             push(DOUBLE);
1165             push(TOP);
1166             break;
1167         case Opcodes.LSHL:
1168         case Opcodes.LSHR:
1169         case Opcodes.LUSHR:
1170             pop(3);
1171             push(LONG);
1172             push(TOP);
1173             break;
1174         case Opcodes.IINC:
1175             set(arg, INTEGER);
1176             break;
1177         case Opcodes.I2L:
1178         case Opcodes.F2L:
1179             pop(1);
1180             push(LONG);
1181             push(TOP);
1182             break;
1183         case Opcodes.I2F:
1184             pop(1);
1185             push(FLOAT);
1186             break;
1187         case Opcodes.I2D:
1188         case Opcodes.F2D:
1189             pop(1);
1190             push(DOUBLE);
1191             push(TOP);
1192             break;
1193         case Opcodes.F2I:
1194         case Opcodes.ARRAYLENGTH:
1195         case Opcodes.INSTANCEOF:
1196             pop(1);
1197             push(INTEGER);
1198             break;
1199         case Opcodes.LCMP:
1200         case Opcodes.DCMPL:
1201         case Opcodes.DCMPG:
1202             pop(4);
1203             push(INTEGER);
1204             break;
1205         case Opcodes.JSR:
1206         case Opcodes.RET:
1207             throw new RuntimeException(
1208                     "JSR/RET are not supported with computeFrames option");
1209         case Opcodes.GETSTATIC:
1210             push(cw, item.strVal3);
1211             break;
1212         case Opcodes.PUTSTATIC:
1213             pop(item.strVal3);
1214             break;
1215         case Opcodes.GETFIELD:
1216             pop(1);
1217             push(cw, item.strVal3);
1218             break;
1219         case Opcodes.PUTFIELD:
1220             pop(item.strVal3);
1221             pop();
1222             break;
1223         case Opcodes.INVOKEVIRTUAL:
1224         case Opcodes.INVOKESPECIAL:
1225         case Opcodes.INVOKESTATIC:
1226         case Opcodes.INVOKEINTERFACE:
1227             pop(item.strVal3);
1228             if (opcode != Opcodes.INVOKESTATIC) {
1229                 t1 = pop();
1230                 if (opcode == Opcodes.INVOKESPECIAL
1231                         && item.strVal2.charAt(0) == '<') {
1232                     init(t1);
1233                 }
1234             }
1235             push(cw, item.strVal3);
1236             break;
1237         case Opcodes.INVOKEDYNAMIC:
1238             pop(item.strVal2);
1239             push(cw, item.strVal2);
1240             break;
1241         case Opcodes.NEW:
1242             push(UNINITIALIZED | cw.addUninitializedType(item.strVal1, arg));
1243             break;
1244         case Opcodes.NEWARRAY:
1245             pop();
1246             switch (arg) {
1247             case Opcodes.T_BOOLEAN:
1248                 push(ARRAY_OF | BOOLEAN);
1249                 break;
1250             case Opcodes.T_CHAR:
1251                 push(ARRAY_OF | CHAR);
1252                 break;
1253             case Opcodes.T_BYTE:
1254                 push(ARRAY_OF | BYTE);
1255                 break;
1256             case Opcodes.T_SHORT:
1257                 push(ARRAY_OF | SHORT);
1258                 break;
1259             case Opcodes.T_INT:
1260                 push(ARRAY_OF | INTEGER);
1261                 break;
1262             case Opcodes.T_FLOAT:
1263                 push(ARRAY_OF | FLOAT);
1264                 break;
1265             case Opcodes.T_DOUBLE:
1266                 push(ARRAY_OF | DOUBLE);
1267                 break;
1268             // case Opcodes.T_LONG:
1269             default:
1270                 push(ARRAY_OF | LONG);
1271                 break;
1272             }
1273             break;
1274         case Opcodes.ANEWARRAY:
1275             String s = item.strVal1;
1276             pop();
1277             if (s.charAt(0) == '[') {
1278                 push(cw, '[' + s);
1279             } else {
1280                 push(ARRAY_OF | OBJECT | cw.addType(s));
1281             }
1282             break;
1283         case Opcodes.CHECKCAST:
1284             s = item.strVal1;
1285             pop();
1286             if (s.charAt(0) == '[') {
1287                 push(cw, s);
1288             } else {
1289                 push(OBJECT | cw.addType(s));
1290             }
1291             break;
1292         // case Opcodes.MULTIANEWARRAY:
1293         default:
1294             pop(arg);
1295             push(cw, item.strVal1);
1296             break;
1297         }
1298     }
1299 
1300     /**
1301      * Merges the input frame of the given basic block with the input and output
1302      * frames of this basic block. Returns <tt>true</tt> if the input frame of
1303      * the given label has been changed by this operation.
1304      *
1305      * @param cw
1306      *            the ClassWriter to which this label belongs.
1307      * @param frame
1308      *            the basic block whose input frame must be updated.
1309      * @param edge
1310      *            the kind of the {@link Edge} between this label and 'label'.
1311      *            See {@link Edge#info}.
1312      * @return <tt>true</tt> if the input frame of the given label has been
1313      *         changed by this operation.
1314      */
1315     boolean merge(final ClassWriter cw, final Frame frame, final int edge) {
1316         boolean changed = false;
1317         int i, s, dim, kind, t;
1318 
1319         int nLocal = inputLocals.length;
1320         int nStack = inputStack.length;
1321         if (frame.inputLocals == null) {
1322             frame.inputLocals = new int[nLocal];
1323             changed = true;
1324         }
1325 
1326         for (i = 0; i < nLocal; ++i) {
1327             if (outputLocals != null && i < outputLocals.length) {
1328                 s = outputLocals[i];
1329                 if (s == 0) {
1330                     t = inputLocals[i];
1331                 } else {
1332                     dim = s & DIM;
1333                     kind = s & KIND;
1334                     if (kind == BASE) {
1335                         t = s;
1336                     } else {
1337                         if (kind == LOCAL) {
1338                             t = dim + inputLocals[s & VALUE];
1339                         } else {
1340                             t = dim + inputStack[nStack - (s & VALUE)];
1341                         }
1342                         if ((s & TOP_IF_LONG_OR_DOUBLE) != 0
1343                                 && (t == LONG || t == DOUBLE)) {
1344                             t = TOP;
1345                         }
1346                     }
1347                 }
1348             } else {
1349                 t = inputLocals[i];
1350             }
1351             if (initializations != null) {
1352                 t = init(cw, t);
1353             }
1354             changed |= merge(cw, t, frame.inputLocals, i);
1355         }
1356 
1357         if (edge > 0) {
1358             for (i = 0; i < nLocal; ++i) {
1359                 t = inputLocals[i];
1360                 changed |= merge(cw, t, frame.inputLocals, i);
1361             }
1362             if (frame.inputStack == null) {
1363                 frame.inputStack = new int[1];
1364                 changed = true;
1365             }
1366             changed |= merge(cw, edge, frame.inputStack, 0);
1367             return changed;
1368         }
1369 
1370         int nInputStack = inputStack.length + owner.inputStackTop;
1371         if (frame.inputStack == null) {
1372             frame.inputStack = new int[nInputStack + outputStackTop];
1373             changed = true;
1374         }
1375 
1376         for (i = 0; i < nInputStack; ++i) {
1377             t = inputStack[i];
1378             if (initializations != null) {
1379                 t = init(cw, t);
1380             }
1381             changed |= merge(cw, t, frame.inputStack, i);
1382         }
1383         for (i = 0; i < outputStackTop; ++i) {
1384             s = outputStack[i];
1385             dim = s & DIM;
1386             kind = s & KIND;
1387             if (kind == BASE) {
1388                 t = s;
1389             } else {
1390                 if (kind == LOCAL) {
1391                     t = dim + inputLocals[s & VALUE];
1392                 } else {
1393                     t = dim + inputStack[nStack - (s & VALUE)];
1394                 }
1395                 if ((s & TOP_IF_LONG_OR_DOUBLE) != 0
1396                         && (t == LONG || t == DOUBLE)) {
1397                     t = TOP;
1398                 }
1399             }
1400             if (initializations != null) {
1401                 t = init(cw, t);
1402             }
1403             changed |= merge(cw, t, frame.inputStack, nInputStack + i);
1404         }
1405         return changed;
1406     }
1407 
1408     /**
1409      * Merges the type at the given index in the given type array with the given
1410      * type. Returns <tt>true</tt> if the type array has been modified by this
1411      * operation.
1412      *
1413      * @param cw
1414      *            the ClassWriter to which this label belongs.
1415      * @param t
1416      *            the type with which the type array element must be merged.
1417      * @param types
1418      *            an array of types.
1419      * @param index
1420      *            the index of the type that must be merged in 'types'.
1421      * @return <tt>true</tt> if the type array has been modified by this
1422      *         operation.
1423      */
1424     private static boolean merge(final ClassWriter cw, int t,
1425             final int[] types, final int index) {
1426         int u = types[index];
1427         if (u == t) {
1428             // if the types are equal, merge(u,t)=u, so there is no change
1429             return false;
1430         }
1431         if ((t & ~DIM) == NULL) {
1432             if (u == NULL) {
1433                 return false;
1434             }
1435             t = NULL;
1436         }
1437         if (u == 0) {
1438             // if types[index] has never been assigned, merge(u,t)=t
1439             types[index] = t;
1440             return true;
1441         }
1442         int v;
1443         if ((u & BASE_KIND) == OBJECT || (u & DIM) != 0) {
1444             // if u is a reference type of any dimension
1445             if (t == NULL) {
1446                 // if t is the NULL type, merge(u,t)=u, so there is no change
1447                 return false;
1448             } else if ((t & (DIM | BASE_KIND)) == (u & (DIM | BASE_KIND))) {
1449                 // if t and u have the same dimension and same base kind
1450                 if ((u & BASE_KIND) == OBJECT) {
1451                     // if t is also a reference type, and if u and t have the
1452                     // same dimension merge(u,t) = dim(t) | common parent of the
1453                     // element types of u and t
1454                     v = (t & DIM) | OBJECT
1455                             | cw.getMergedType(t & BASE_VALUE, u & BASE_VALUE);
1456                 } else {
1457                     // if u and t are array types, but not with the same element
1458                     // type, merge(u,t) = dim(u) - 1 | java/lang/Object
1459                     int vdim = ELEMENT_OF + (u & DIM);
1460                     v = vdim | OBJECT | cw.addType("java/lang/Object");
1461                 }
1462             } else if ((t & BASE_KIND) == OBJECT || (t & DIM) != 0) {
1463                 // if t is any other reference or array type, the merged type
1464                 // is min(udim, tdim) | java/lang/Object, where udim is the
1465                 // array dimension of u, minus 1 if u is an array type with a
1466                 // primitive element type (and similarly for tdim).
1467                 int tdim = (((t & DIM) == 0 || (t & BASE_KIND) == OBJECT) ? 0
1468                         : ELEMENT_OF) + (t & DIM);
1469                 int udim = (((u & DIM) == 0 || (u & BASE_KIND) == OBJECT) ? 0
1470                         : ELEMENT_OF) + (u & DIM);
1471                 v = Math.min(tdim, udim) | OBJECT
1472                         | cw.addType("java/lang/Object");
1473             } else {
1474                 // if t is any other type, merge(u,t)=TOP
1475                 v = TOP;
1476             }
1477         } else if (u == NULL) {
1478             // if u is the NULL type, merge(u,t)=t,
1479             // or TOP if t is not a reference type
1480             v = (t & BASE_KIND) == OBJECT || (t & DIM) != 0 ? t : TOP;
1481         } else {
1482             // if u is any other type, merge(u,t)=TOP whatever t
1483             v = TOP;
1484         }
1485         if (u != v) {
1486             types[index] = v;
1487             return true;
1488         }
1489         return false;
1490     }
1491 }
--- EOF ---