⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kvmstackmap.java

📁 已经移植好的java虚拟机
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                index = (token - opc_astore_0);                locals[index] = true;                stackSize--;                break;                /* These leave any pointers on the stack as pointers, and                 * any nonpointers on the stack as nonpointers */            case opc_iinc: case opc_checkcast:                 thisIP += 2;            case opc_nop:            case opc_ineg: case opc_lneg: case opc_fneg: case opc_dneg:            case opc_i2f:  case opc_l2d:  case opc_f2i:  case opc_d2l:            case opc_i2b:  case opc_i2c:  case opc_i2s:                break;                /* These push a non-pointer onto the stack */            case opc_sipush:                thisIP++;            case opc_iload:  case opc_fload:  case opc_bipush:                thisIP++;            case opc_aconst_null:            case opc_iconst_m1: case opc_iconst_0: case opc_iconst_1:            case opc_iconst_2:  case opc_iconst_3: case opc_iconst_4:            case opc_iconst_5:            case opc_fconst_0:  case opc_fconst_1: case opc_fconst_2:            case opc_iload_0:   case opc_iload_1:              case opc_iload_2:   case opc_iload_3:            case opc_fload_0:   case opc_fload_1:              case opc_fload_2:   case opc_fload_3:            case opc_i2l: case opc_i2d: case opc_f2l: case opc_f2d:                stack[stackSize++] = false;                break;                /* These push two non-pointers onto the stack */            case opc_ldc2_w:                thisIP++;            case opc_lload:    case opc_dload:                thisIP++;            case opc_lconst_0: case opc_lconst_1:             case opc_dconst_0: case opc_dconst_1:            case opc_lload_0:  case opc_lload_1:              case opc_lload_2:  case opc_lload_3:            case opc_dload_0:  case opc_dload_1:             case opc_dload_2:  case opc_dload_3:                stack[stackSize++] = false;                stack[stackSize++] = false;                break;                /* These push a pointer onto the stack */            case opc_new:                 thisIP++;            case opc_aload:                thisIP++;            case opc_aload_0:  case opc_aload_1:              case opc_aload_2: case opc_aload_3:                stack[stackSize++] = true;                break;                /* These pop an item off the stack */            case opc_ifeq: case opc_ifne: case opc_iflt: case opc_ifge:            case opc_ifgt: case opc_ifle: case opc_ifnull: case opc_ifnonnull:                thisIP += 2;            case opc_pop:   case opc_iadd: case opc_fadd: case opc_isub:             case opc_fsub:  case opc_imul: case opc_fmul: case opc_idiv:             case opc_fdiv:  case opc_irem: case opc_frem: case opc_ishl:             case opc_lshl:  case opc_ishr: case opc_lshr: case opc_iushr:             case opc_lushr: case opc_iand: case opc_ior:  case opc_ixor:            case opc_l2i:   case opc_l2f:  case opc_d2i:  case opc_d2f:            case opc_fcmpl: case opc_fcmpg:            case opc_monitorenter: case opc_monitorexit:            case opc_aaload:        /* Ptr Int => Ptr */                stackSize--;                break;                /* These pop an item off the stack, and then push a pointer */            case opc_anewarray:                thisIP++;            case opc_newarray:                thisIP++;                stack[stackSize - 1] = true;                break;                /* These pop an item off the stack, and then push an int */            case opc_instanceof:                thisIP += 2;            case opc_arraylength:                stack[stackSize - 1] = false;                break;                /* These pop two items off the stack */            case opc_if_icmpeq: case opc_if_icmpne: case opc_if_icmplt:             case opc_if_icmpge: case opc_if_icmpgt: case opc_if_icmple:             case opc_if_acmpeq: case opc_if_acmpne:                 thisIP += 2;            case opc_pop2:            case opc_ladd: case opc_dadd: case opc_lsub:             case opc_dsub: case opc_lmul: case opc_dmul:            case opc_ldiv: case opc_ddiv: case opc_lrem: case opc_drem:            case opc_land: case opc_lor: case opc_lxor:                stackSize -= 2;                break;                /* These pop two items off, and then push non-pointer */            case opc_iaload: case opc_faload: case opc_baload:             case opc_caload: case opc_saload:                stackSize -= 2;                stack[stackSize++] = false;                break;                /* These pop two items off, and then push two non pointers */            case opc_daload: case opc_laload:                stack[stackSize - 1] = false;                stack[stackSize - 2] = false;                break;                /* These pop three items off the stack. */            case opc_iastore: case opc_fastore: case opc_aastore:             case opc_bastore: case opc_castore: case opc_sastore:            case opc_lcmp:    case opc_dcmpl:   case opc_dcmpg:                stackSize -= 3;                break;                /* These pop four items off the stack. */            case opc_lastore: case opc_dastore:                stackSize -= 4;                break;                /* These either load a pointer or an integer */            case opc_ldc:            case opc_ldc_w:                if (token == opc_ldc) {                     index = code[thisIP++] & 0xFF;                } else {                     index = mi.getUnsignedShort(thisIP);                    thisIP += 2;                }                stack[stackSize++] =                     (cpool[index] instanceof StringConstant);                break;                                /* These involve doing bit twiddling */            case opc_dup:                stackSize++;                stack[stackSize - 1] = stack[stackSize - 2];                break;            case opc_dup_x1:                stackSize++;                stack[stackSize - 1] = stack[stackSize - 2];                stack[stackSize - 2] = stack[stackSize - 3];                stack[stackSize - 3] = stack[stackSize - 1];                break;            case opc_dup_x2:                stackSize++;                stack[stackSize - 1] = stack[stackSize - 2];                stack[stackSize - 2] = stack[stackSize - 3];                stack[stackSize - 3] = stack[stackSize - 4];                stack[stackSize - 4] = stack[stackSize - 1];                break;            case opc_dup2:                stackSize += 2;                stack[stackSize - 1] = stack[stackSize - 3];                stack[stackSize - 2] = stack[stackSize - 4];                break;            case opc_dup2_x1:                stackSize += 2;                stack[stackSize - 1] = stack[stackSize - 3];                stack[stackSize - 2] = stack[stackSize - 4];                stack[stackSize - 3] = stack[stackSize - 5];                stack[stackSize - 4] = stack[stackSize - 1];                stack[stackSize - 5] = stack[stackSize - 2];                break;            case opc_dup2_x2:                stackSize += 2;                stack[stackSize - 1] = stack[stackSize - 3];                stack[stackSize - 2] = stack[stackSize - 4];                stack[stackSize - 3] = stack[stackSize - 5];                stack[stackSize - 4] = stack[stackSize - 6];                stack[stackSize - 5] = stack[stackSize - 1];                stack[stackSize - 6] = stack[stackSize - 2];                break;            case opc_swap: {                 boolean temp = stack[stackSize - 1];                stack[stackSize - 1] = stack[stackSize - 2];                stack[stackSize - 2] = temp;                break;            }            case opc_getfield:                /* Remove the pointer to the object */                stackSize -= 1;            case opc_getstatic: {                index = mi.getUnsignedShort(thisIP);                thisIP += 2;                FieldInfo field = ((FieldConstant)cpool[index]).find();                if (removeVerbose) {                     System.out.print(" " + writer.prettyName(field));                }                String type = field.type.string;                switch(field.type.string.charAt(0)) {                     case SIGC_CLASS: case SIGC_ARRAY:                        stack[stackSize++] = true;                        break;                    case SIGC_LONG: case SIGC_DOUBLE:                        stack[stackSize++] = false;                    default:                        stack[stackSize++] = false;                        break;                }                break;            }                /* Set a field value from the stack */            case opc_putfield:                /* Remove the pointer to the object */                stackSize -= 1;            case opc_putstatic: {                 index = mi.getUnsignedShort(thisIP);                thisIP += 2;                FieldInfo field = ((FieldConstant)cpool[index]).find();                if (removeVerbose) {                     System.out.print(" " + writer.prettyName(field));                }                String type = field.type.string;                switch(field.type.string.charAt(0)) {                     case SIGC_LONG: case SIGC_DOUBLE:                         stackSize -= 2;                        break;                    default:                        stackSize -= 1;                        break;                }                break;            }            case opc_multianewarray:                stackSize -= (code[thisIP + 2] & 0xFF);                thisIP += 3;                stack[stackSize++] = true;                break;            case opc_wide:                token = code[thisIP++] & 0xFF;                index = mi.getUnsignedShort(thisIP); thisIP += 2;                switch(token) {                    case opc_lload: case opc_dload:                        stack[stackSize++] = false;                    case opc_iload: case opc_fload: case opc_aload:                        stack[stackSize++] = (token == opc_aload);                        break;                    case opc_lstore: case opc_dstore:                        locals[index + 1] = false;                        stackSize--;                    case opc_istore: case opc_fstore: case opc_astore:                        locals[index] = (token == opc_astore);                        stackSize--;                        break;                    case opc_iinc:                        thisIP += 2;                        break;                    case opc_ret:                    default:                         throw new RuntimeException("Unexpected byte code");                }                break;                            case opc_invokevirtual:            case opc_invokespecial:            case opc_invokestatic:            case opc_invokeinterface: {                index = mi.getUnsignedShort(thisIP);                MethodInfo method = ((MethodConstant)cpool[index]).find();                if (removeVerbose) {                     System.out.print(" " + writer.prettyName(method));                }                String type = method.type.string;                thisIP += (token == opc_invokeinterface) ? 4 : 2;                stackSize -= method.argsSize;                int paren = type.indexOf(')');                switch (type.charAt(paren + 1)) {                     case SIGC_CLASS: case SIGC_ARRAY:                        stack[stackSize++] = true;                        break;                    case SIGC_LONG: case SIGC_DOUBLE:                        stack[stackSize++] = false;                     default:                        stack[stackSize++] = false;                    case SIGC_VOID:                        break;                }                break;            }                        case opc_lookupswitch:            case opc_tableswitch:                 thisIP = (thisIP + 3) & ~3; // round up to multiple of 4                if (token == opc_tableswitch) {                     int low = mi.getInt(thisIP + 4);                    int high = mi.getInt(thisIP + 8);                    thisIP += (high - low + 1) * 4 + 12;                } else {                     int pairs = mi.getInt(thisIP + 4);                    thisIP += pairs * 8 + 8;                }                stackSize--;    // pop int off the stack                needStackmap = true;                break;            case opc_goto:                thisIP += 2;                needStackmap = true;                break;	    case opc_goto_w:                thisIP += 4;                needStackmap = true;                break;            case opc_lreturn: case opc_dreturn:                stackSize--;            case opc_athrow:             case opc_ireturn: case opc_freturn: case opc_areturn:                stackSize--;            case opc_return:                needStackmap = true;                break;                /* The KVM doesn't allow these.  But if it did, they should                 * be treated the same as goto, since that's almost always                 * what's there for the next instruction.                 */	    case opc_jsr: 	    case opc_jsr_w:            case opc_ret:            default:                throw new RuntimeException("Unexpected byte code at " + thisIP);            }            if (removeVerbose) {                 System.out.println();            }        } // end of for loop;        if (discardCount > 0) {             StackMapFrame newFrames[] =                 new StackMapFrame[frames.length - discardCount];            int i, j;            for (i = j = 0; i < frames.length; i++) {                 if (!discardList[i]) {                     newFrames[j++] = frames[i];                }            }            if (j != newFrames.length) {                 throw new RuntimeException("I cannot code");            }            mi.stackMapTable = newFrames;        }    }    private void    initializeLocals(MethodInfo mi, boolean locals[]) {         int argsSize = 0;        String sig = mi.type.string;        if (!mi.isStaticMember()) {             locals[argsSize++] = true;        }	for (int pos = 1; sig.charAt(pos) !=SIGC_ENDMETHOD; pos++) {	    switch (sig.charAt(pos)) {	      case SIGC_BOOLEAN: case SIGC_BYTE:   case SIGC_CHAR:                  case SIGC_SHORT:  case SIGC_INT:     case SIGC_FLOAT:		  argsSize++;		  break;	      case SIGC_LONG: case SIGC_DOUBLE:		  argsSize += 2;		  break;                  	      case SIGC_CLASS:                    locals[argsSize++] = true;                  while (sig.charAt(pos) != SIGC_ENDCLASS) {                      pos++;                  }                  break;              case SIGC_ARRAY:                  locals[argsSize++] = true;                  while (sig.charAt(pos) == SIGC_ARRAY) {                      pos++;                  }                  if (sig.charAt(pos) == SIGC_CLASS) {                      while (sig.charAt(pos) != SIGC_ENDCLASS) {                          pos++;                      }                  }                  break;             default:                 System.err.println("Error: unparseable signature: " + sig);                 System.exit(3);	    }	}    }    private boolean     sameStackMaps(boolean[] locals, boolean[] stack, int stackSize,                   boolean[] newLocals, boolean [] newStack)    {         if (stackSize != newStack.length) {             return false;        }         if (!java.util.Arrays.equals(locals, newLocals)) {             return false;        }        for (int i = 0; i < stackSize; i++) {             if (stack[i] != newStack[i]) {                 return false;            }        }        return true;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -