831 lines · 30.1 KB · Java
RawDownload
            return ((MemberDefinition)value).getType().getReturnType().stackSize() -                   (((MemberDefinition)value).getType().stackSize());        }        throw new CompilerError("invalid opcode: " + toString());    }     /**     * Return the size of the instruction     */    int size(ConstantPool tab) {        switch (opc) {          case opc_try:         case opc_label:         case opc_dead:            return 0;           case opc_bipush:      case opc_newarray:            return 2;           case opc_sipush:      case opc_goto:          case opc_jsr:          case opc_ifeq:        case opc_ifne:          case opc_ifgt:          case opc_ifge:        case opc_iflt:          case opc_ifle:          case opc_ifnull:      case opc_ifnonnull:     case opc_if_acmpeq:          case opc_if_acmpne:   case opc_if_icmpeq:     case opc_if_icmpne:          case opc_if_icmpgt:   case opc_if_icmpge:     case opc_if_icmplt:          case opc_if_icmple:            return 3;           case opc_ldc:          case opc_ldc_w:            if (tab.index(value) < 256) {                opc = opc_ldc;                return 2;            } else {                opc = opc_ldc_w;                return 3;            }           case opc_iload:       case opc_lload:         case opc_fload:          case opc_dload:       case opc_aload: {            int v = ((Number)value).intValue();            if (v < 4) {                if (v < 0) {                    throw new CompilerError("invalid slot: " + toString()                        + "\nThis error possibly resulted from poorly constructed class paths.");                }                opc = opc_iload_0 + (opc - opc_iload) * 4 + v;                return 1;            } else if (v <= 255) {                return 2;            } else {                opc += 256;     // indicate wide variant                return 4;            }          }            case opc_iinc: {               int register = ((int[])value)[0];               int increment = ((int[])value)[1];               if (register < 0) {                   throw new CompilerError("invalid slot: " + toString());               }               if (register <= 255 && (((byte)increment) == increment)) {                   return 3;               } else {                   opc += 256;          // indicate wide variant                   return 6;               }           }           case opc_istore:      case opc_lstore:        case opc_fstore:          case opc_dstore:      case opc_astore: {            int v = (value instanceof Number) ?                ((Number)value).intValue() : ((LocalVariable)value).slot;            if (v < 4) {                if (v < 0) {                    throw new CompilerError("invalid slot: " + toString());                }                opc = opc_istore_0 + (opc - opc_istore) * 4 + v;                return 1;            } else if (v <= 255) {                return 2;            } else {                opc += 256;     // indicate wide variant                return 4;            }          }           case opc_ret: {              int v = ((Number)value).intValue();              if (v <= 255) {                  if (v < 0) {                      throw new CompilerError("invalid slot: " + toString());                  }                  return 2;              } else {                  opc += 256;   // indicate wide variant                  return 4;              }          }           case opc_ldc2_w:              case opc_new:          case opc_putstatic:           case opc_getstatic:          case opc_putfield:            case opc_getfield:          case opc_invokevirtual:       case opc_invokespecial:          case opc_invokestatic:        case opc_instanceof:          case opc_checkcast:           case opc_anewarray:            return 3;           case opc_multianewarray:            return 4;           case opc_invokeinterface:          case opc_goto_w:          case opc_jsr_w:            return 5;           case opc_tableswitch: {            SwitchData sw = (SwitchData)value;            int n = 1;            for(; ((pc + n) % 4) != 0 ; n++);            return n + 16 + (sw.maxValue - sw.minValue) * 4;          }           case opc_lookupswitch: {            SwitchData sw = (SwitchData)value;            int n = 1;            for(; ((pc + n) % 4) != 0 ; n++);            return n + 8 + sw.tab.size() * 8;          }           case opc_nop:            if ((value != null) && !(value instanceof Integer))                return 2;            else                return 1;        }         // most opcodes are only 1 byte long        return 1;    }     /**     * Generate code     */    void write(DataOutputStream out, ConstantPool tab) throws IOException {        switch (opc) {          case opc_try:         case opc_label:         case opc_dead:            break;           case opc_bipush:      case opc_newarray:          case opc_iload:       case opc_lload:         case opc_fload:          case opc_dload:       case opc_aload:         case opc_ret:            out.writeByte(opc);            out.writeByte(((Number)value).intValue());            break;           case opc_iload + 256:         case opc_lload + 256:          case opc_fload + 256:         case opc_dload + 256:          case opc_aload + 256:         case opc_ret   + 256:            out.writeByte(opc_wide);            out.writeByte(opc - 256);            out.writeShort(((Number)value).intValue());            break;           case opc_istore:      case opc_lstore:        case opc_fstore:          case opc_dstore:      case opc_astore:            out.writeByte(opc);            out.writeByte((value instanceof Number) ?                          ((Number)value).intValue() : ((LocalVariable)value).slot);            break;           case opc_istore + 256:        case opc_lstore + 256:          case opc_fstore + 256:        case opc_dstore + 256:          case opc_astore + 256:            out.writeByte(opc_wide);            out.writeByte(opc - 256);            out.writeShort((value instanceof Number) ?                      ((Number)value).intValue() : ((LocalVariable)value).slot);            break;           case opc_sipush:            out.writeByte(opc);            out.writeShort(((Number)value).intValue());            break;           case opc_ldc:            out.writeByte(opc);            out.writeByte(tab.index(value));            break;           case opc_ldc_w:               case opc_ldc2_w:          case opc_new:                 case opc_putstatic:          case opc_getstatic:           case opc_putfield:          case opc_getfield:            case opc_invokevirtual:          case opc_invokespecial:       case opc_invokestatic:          case opc_instanceof:          case opc_checkcast:            out.writeByte(opc);            out.writeShort(tab.index(value));            break;           case opc_iinc:            out.writeByte(opc);            out.writeByte(((int[])value)[0]); // register            out.writeByte(((int[])value)[1]); // increment            break;           case opc_iinc + 256:            out.writeByte(opc_wide);            out.writeByte(opc - 256);            out.writeShort(((int[])value)[0]); // register            out.writeShort(((int[])value)[1]); // increment            break;           case opc_anewarray:            out.writeByte(opc);            out.writeShort(tab.index(value));            break;           case opc_multianewarray:            out.writeByte(opc);            out.writeShort(tab.index(((ArrayData)value).type));            out.writeByte(((ArrayData)value).nargs);            break;           case opc_invokeinterface:            out.writeByte(opc);            out.writeShort(tab.index(value));            out.writeByte(((MemberDefinition)value).getType().stackSize() + 1);            out.writeByte(0);            break;           case opc_goto:        case opc_jsr:           case opc_ifeq:          case opc_ifne:        case opc_ifgt:          case opc_ifge:          case opc_iflt:        case opc_ifle:          case opc_ifnull:          case opc_ifnonnull:   case opc_if_acmpeq:     case opc_if_acmpne:          case opc_if_icmpeq:   case opc_if_icmpne:     case opc_if_icmpgt:          case opc_if_icmpge:   case opc_if_icmplt:     case opc_if_icmple:            out.writeByte(opc);            out.writeShort(((Instruction)value).pc - pc);            break;           case opc_goto_w:          case opc_jsr_w:            out.writeByte(opc);            out.writeLong(((Instruction)value).pc - pc);            break;           case opc_tableswitch: {            SwitchData sw = (SwitchData)value;            out.writeByte(opc);            for(int n = 1 ; ((pc + n) % 4) != 0 ; n++) {                out.writeByte(0);            }            out.writeInt(sw.defaultLabel.pc - pc);            out.writeInt(sw.minValue);            out.writeInt(sw.maxValue);            for (int n = sw.minValue ; n <= sw.maxValue ; n++) {                Label lbl = sw.get(n);                int target_pc = (lbl != null) ? lbl.pc : sw.defaultLabel.pc;                out.writeInt(target_pc - pc);            }            break;          }           case opc_lookupswitch: {            SwitchData sw = (SwitchData)value;            out.writeByte(opc);            int n = pc + 1;            for(; (n % 4) != 0 ; n++) {                out.writeByte(0);            }            out.writeInt(sw.defaultLabel.pc - pc);            out.writeInt(sw.tab.size());            for (Enumeration e = sw.sortedKeys(); e.hasMoreElements() ; ) {                Integer v = (Integer)e.nextElement();                out.writeInt(v.intValue());                out.writeInt(sw.get(v).pc - pc);            }            break;          }           case opc_nop:            if (value != null) {                if (value instanceof Integer)                    out.writeByte(((Integer)value).intValue());                else                    out.writeShort(tab.index(value));                return;            }            // fall through           default:            out.writeByte(opc);            break;        }    }     /**     * toString     */    public String toString() {        String prefix = (where >> WHEREOFFSETBITS) + ":\t";        switch (opc) {          case opc_try:            return prefix + "try " + ((TryData)value).getEndLabel().hashCode();           case opc_dead:            return prefix + "dead";           case opc_iinc: {            int register = ((int[])value)[0];            int increment = ((int[])value)[1];            return prefix + opcNames[opc] + " " + register + ", " + increment;          }           default:            if (value != null) {                if (value instanceof Label) {                    return prefix + opcNames[opc] + " " + value.toString();                } else if (value instanceof Instruction) {                    return prefix + opcNames[opc] + " " + value.hashCode();                } else if (value instanceof String) {                    return prefix + opcNames[opc] + " \"" + value + "\"";                } else {                    return prefix + opcNames[opc] + " " + value;                }            } else {              return prefix + opcNames[opc];            }        }    }}

Lines 501–831 of 831. Previous lines