📄 method.java
字号:
break; case OpCode.ISTORE_2: executeISTORE_N(2); break; case OpCode.ISTORE_3: executeISTORE_N(3); break; case OpCode.ISUB: executeISUB(); break; case OpCode.IUSHR: executeIUSHR(); break; case OpCode.IXOR: executeIXOR(); break; case OpCode.JSR: executeJSR(); break; case OpCode.L2D: executeL2D(); break; case OpCode.L2F: executeL2F(); break; case OpCode.L2I: executeL2I(); break; case OpCode.LADD: executeLADD(); break; case OpCode.LAND: executeLAND(); break; case OpCode.LCONST_0: executeLCONST_N(0L); break; case OpCode.LCONST_1: executeLCONST_N(1L); break; case OpCode.LDC2_W: executeLDC2_W(); break; case OpCode.LDIV: executeLDIV(); break; case OpCode.LLOAD: executeLLOAD(); break; case OpCode.LLOAD_0: executeLLOAD_N(0); break; case OpCode.LLOAD_1: executeLLOAD_N(1); break; case OpCode.LLOAD_2: executeLLOAD_N(2); break; case OpCode.LLOAD_3: executeLLOAD_N(3); break; case OpCode.LMUL: executeLMUL(); break; case OpCode.LNEG: executeLNEG(); break; case OpCode.LOR: executeLOR(); break; case OpCode.LREM: executeLREM(); break; case OpCode.LSHL: executeLSHL(); break; case OpCode.LSHR: executeLSHR(); break; case OpCode.LSTORE: executeLSTORE(); break; case OpCode.LSTORE_0: executeLSTORE_N(0); break; case OpCode.LSTORE_1: executeLSTORE_N(1); break; case OpCode.LSTORE_2: executeLSTORE_N(2); break; case OpCode.LSTORE_3: executeLSTORE_N(3); break; case OpCode.LSUB: executeLSUB(); break; case OpCode.LUSHR: executeLUSHR(); break; case OpCode.LXOR: executeLXOR(); break; case OpCode.MULTIANEWARRAY: executeMULTIANEWARRAY(); break; case OpCode.POP: executePOP(); break; case OpCode.RET: executeRET(); break; case OpCode.SIPUSH: executeSIPUSH(); break; case OpCode.TABLESWITCH: executeTABLESWITCH(); break; default: throw new JVMSimError(); } return pc; } // Branch interprets the first two opcodes following the // instruction (pointed to by the current pc) as branchbyte1 and // branchbyte2. It uses them to form a 16 bit signed offset, which // it adds to the pc register. This is used to execute several // opcodes, such as GOTO and IF_ICMPLT. private void branch() { byte branchByte1 = code[pc + 1]; byte branchByte2 = code[pc + 2]; short branchOffset = branchByte1; branchOffset <<= 8; branchOffset += ((short) branchByte2) & 0xff; pc += branchOffset; } private short getShortOperand(int codeIndex) { byte shortByte1 = code[codeIndex]; byte shortByte2 = code[codeIndex + 1]; short theShort = shortByte1; theShort <<= 8; theShort += ((short) shortByte2) & 0xff; return theShort; } private int getIntOperand(int codeIndex) { byte intByte1 = code[codeIndex]; byte intByte2 = code[codeIndex + 1]; byte intByte3 = code[codeIndex + 2]; byte intByte4 = code[codeIndex + 3]; int theInt = (intByte1 << 24) | ((intByte2 & 0xff) << 16) | ((intByte3 & 0xff) << 8) | (intByte4 & 0xff); return theInt; } private boolean compare(int condition, int value1, int value2) { switch (condition) { case EQ: return (value1 == value2); case NE: return (value1 != value2); case LT: return (value1 < value2); case LE: return (value1 <= value2); case GT: return (value1 > value2); case GE: return (value1 >= value2); default: throw new JVMSimError(); } } // This is used by executeMULTIANEWARRAY(). It calls itself recursively // as many times as the multi-dimensional array is deep. private Object createMultiDimArray(int[] size) { Object result; if (size.length == 1) { result = new int[size[0]]; } else { // Create and initialize an array of arrays Object[] arrayOfArrays = new Object[size[0]]; result = arrayOfArrays; // As soon as a size of zero is hit for the next array, we are done. This // will be the case if some of the square brackets were left empty in // the declaration, as in "new int[5][4][][]," in which the third and fourth // sizes will be zero. if (size[1] != 0) { // Create and initialize an array of sizes to be passed to a recursive call // to createMultiDimArray(). This array is identical to the array passed // to this function with the first element clipped off. int[] nextSize = new int[size.length - 1]; for (int i = 1; i < size.length; ++i) { nextSize[i - 1] = size[i]; } // Call this function recursively to create initialize this array // of array with the sub-arrays. for (int i = 0; i < size[0]; ++i) { arrayOfArrays[i] = createMultiDimArray(nextSize); } } } return result; } private void executeAALOAD() { // Pop array index. int index = sf.popInt(); // Pop reference to array of object references. // Cast generic object reference to a reference to an array of objects. This // will cause the JVM to do a checkcast instruction to make sure this is a // valid operation. An exception will be thrown if I've got any other kind // of array or object reference. Once this succeeds, I can use the arrayRef // as an array to get the index'th object reference and push it. Object[] theArray = (Object[]) sf.popObject(); // Push the object reference at theArray[index]. sf.pushObject(theArray[index]); ++pc; } private void executeACONST_NULL() { sf.pushObject(null); ++pc; } private void executeALOAD() { int locVarPos = ((int) code[pc + 1]) & 0xff; Object theObject = sf.getLocalObject(locVarPos); sf.pushObject(theObject); ++pc; } private void executeALOAD_N(int locVarPos) { Object theObject = sf.getLocalObject(locVarPos); sf.pushObject(theObject); ++pc; } private void executeASTORE() { int locVar = ((int) code[pc +1]) & 0xff; Object theObject = sf.popObject(); sf.setLocalObject(locVar, theObject); pc += 2; } private void executeASTORE_N(int locVar) { Object theObject = sf.popObject(); sf.setLocalObject(locVar, theObject); ++pc; } private void executeATHROW() { // This is hard-coded for the Play Ball! simulation. It assumes // the exception is caught by the first entry in the exception // table. pc = exceptionTable[0].getTarget(); } private void executeBIPUSH() { byte theByte = code[pc + 1]; sf.pushInt(theByte); pc += 2; } private void executeDADD() { double value2 = sf.popDouble(); double value1 = sf.popDouble(); double result = value1 + value2; sf.pushDouble(result); ++pc; } private void executeD2F() { double value = sf.popDouble(); float result = (float) value; sf.pushFloat(result); ++pc; } private void executeD2I() { double value = sf.popDouble(); int result = (int) value; sf.pushInt(result); ++pc; } private void executeD2L() { double value = sf.popDouble(); long result = (long) value; sf.pushLong(result); ++pc; } private void executeDCMPG() { double value2 = sf.popDouble(); double value1 = sf.popDouble(); if (Double.isNaN(value1) || Double.isNaN(value2)) { sf.pushInt(1); } else if (value1 > value2) { sf.pushInt(1); } else if (value1 < value2) { sf.pushInt(-1); } else { sf.pushInt(0); } ++pc; } private void executeDCONST_N(double theDouble) { sf.pushDouble(theDouble); ++pc; } private void executeDDIV() { double value2 = sf.popDouble(); double value1 = sf.popDouble(); double result = value1 / value2; sf.pushDouble(result); ++pc; } private void executeDLOAD() { int locVarPos = ((int) code[pc + 1]) & 0xff; double theDouble = sf.getLocalDouble(locVarPos); sf.pushDouble(theDouble); pc += 2; } private void executeDLOAD_N(int locVarPos) { double theDouble = sf.getLocalDouble(locVarPos); sf.pushDouble(theDouble); ++pc; } private void executeDMUL() { double value2 = sf.popDouble(); double value1 = sf.popDouble(); double result = value1 * value2; sf.pushDouble(result); ++pc; } private void executeDNEG() { double value = sf.popDouble(); double result = -value; sf.pushDouble(result); ++pc; } private void executeDREM() { double value2 = sf.popDouble(); double value1 = sf.popDouble(); double result = value1 % value2; sf.pushDouble(result); ++pc; } private void executeDSTORE() { int locVarPos = ((int) code[pc + 1]) & 0xff; double theDouble = sf.popDouble(); sf.setLocalDouble(locVarPos, theDouble); pc += 2; } private void executeDSTORE_N(int locVarPos) { double theDouble = sf.popDouble(); sf.setLocalDouble(locVarPos, theDouble); ++pc; } private void executeDSUB() { double value2 = sf.popDouble(); double value1 = sf.popDouble(); double result = value1 - value2; sf.pushDouble(result); ++pc; } private void executeF2D() { float value = sf.popFloat(); double result = (double) value; sf.pushDouble(result); ++pc; } private void executeF2I() { float value = sf.popFloat(); int result = (int) value; sf.pushInt(result); ++pc; } private void executeF2L() { float value = sf.popFloat(); long result = (long) value; sf.pushLong(result); ++pc; } private void executeFADD() { float value2 = sf.popFloat(); float value1 = sf.popFloat(); float result = value1 + value2; sf.pushFloat(result); ++pc; } private void executeFCONST_N(float value) { sf.pushFloat(value); ++pc; } private void executeFDIV() { float value2 = sf.popFloat(); float value1 = sf.popFloat(); float result = value1 / value2; sf.pushFloat(result); ++pc; } private void executeFLOAD() { int locVarPos = ((int) code[pc + 1]) & 0xff; float f = sf.getLocalFloat(locVarPos); sf.pushFloat(f); ++pc; } private void executeFLOAD_N(int locVarPos) { float f = sf.getLocalFloat(locVarPos); sf.pushFloat(f); ++pc; } private void executeFMUL() { float value2 = sf.popFloat(); float value1 = sf.popFloat(); float result = value1 * value2; sf.pushFloat(result); ++pc; } private void executeFNEG() { float value = sf.popFloat(); float result = -value; sf.pushFloat(result); ++pc; } private void executeFREM() { float value2 = sf.popFloat(); float value1 = sf.popFloat(); float result = value1 % value2; sf.pushFloat(result); ++pc; } private void executeFSTORE() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -