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

📄 method.java

📁 这是有关Java虚拟机的实现代码,是学习和使用Java虚拟机的朋友们不可或缺的代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        int locVarPos = ((int) code[pc + 1]) & 0xff;        float f = sf.popFloat();        sf.setLocalFloat(locVarPos, f);        ++pc;    }    private void executeFSTORE_N(int locVarPos) {        float f = sf.popFloat();        sf.setLocalFloat(locVarPos, f);        ++pc;    }    private void executeFSUB() {        float value2 = sf.popFloat();        float value1 = sf.popFloat();        float result = value1 - value2;        sf.pushFloat(result);        ++pc;    }    private void executeGETSTATIC() {			// This is hard-coded for the Play Ball! simulation.			// This simulation code doesn't simulate the constant			// pool, because it was only used once or twice in all			// the bytecode sequences. In Play Ball!'s bytecode			// sequence, getstatic refers to constant pool entry			// six, which refers to a class variable named ball that			// is of type Ball.			sf.pushObject(constantPool[6].getStaticField());			pc += 3;	}    private void executeGOTO() {        branch();    }    private void executeI2B() {        int value = sf.popInt();        int result = (byte) value;        sf.pushInt(result);        ++pc;    }    private void executeI2C() {        int value = sf.popInt();        int result = (char) value;        sf.pushInt(result);        ++pc;    }    private void executeI2D() {        int value = sf.popInt();        double result = (double) value;        sf.pushDouble(result);        ++pc;    }    private void executeI2F() {        int value = sf.popInt();        float result = (float) value;        sf.pushFloat(result);        ++pc;    }    private void executeI2L() {        int value = sf.popInt();        long result = (long) value;        sf.pushLong(result);        ++pc;    }    private void executeI2S() {        int value = sf.popInt();        int result = (short) value;        sf.pushInt(result);        ++pc;    }    private void executeIADD() {        int value2 = sf.popInt();        int value1 = sf.popInt();        int result = value1 + value2;        sf.pushInt(result);        ++pc;    }    private void executeIAND() {        int value2 = sf.popInt();        int value1 = sf.popInt();        int result = value1 & value2;        sf.pushInt(result);        ++pc;    }    private void executeIASTORE() {        // Pop int value.        int value = sf.popInt();        // Pop index.        int index = sf.popInt();        // Pop reference to an array of integers. Must cast the generic object        // reference to a reference to an array of integers, then use that        // to assign arrayRef[index] = value.        int[] theArray = (int[]) sf.popObject();        theArray[index] = value;        ++pc;    }    private void executeICONST_N(int i) {        sf.pushInt(i);        ++pc;    }    private void executeIDIV() {        int value2 = sf.popInt();        int value1 = sf.popInt();        int result = value1 / value2;        sf.pushInt(result);        ++pc;    }    private void executeIF_ICMPCOND(int condition) {        int value2 = sf.popInt();        int value1 = sf.popInt();        boolean branch = compare(condition, value1, value2);        if (branch) {            branch();        }        else {            pc += 3;        }    }    private void executeIFCOND(int condition) {        int value = sf.popInt();        boolean branch = compare(condition, value, 0);        if (branch) {            branch();        }        else {            pc += 3;        }    }    private void executeIINC() {        int index = code[pc + 1];        index &= 0xff; // index is an unsigned byte        int constant = code[pc + 2]; // constant is a signed byte        int locVar = sf.getLocalInt(index);        locVar += constant;        sf.setLocalInt(index, locVar);        pc += 3;    }    private void executeILOAD() {        int locVarPos = ((int) code[pc + 1]) & 0xff;        int val = sf.getLocalInt(locVarPos);        sf.pushInt(val);        ++pc;    }    private void executeILOAD_N(int locVarPos) {        int val = sf.getLocalInt(locVarPos);        sf.pushInt(val);        ++pc;    }    private void executeIMUL() {        int value2 = sf.popInt();        int value1 = sf.popInt();        int result = value1 * value2;        sf.pushInt(result);        ++pc;    }    private void executeINEG() {        int value = sf.popInt();        int result = -value;        sf.pushInt(result);        ++pc;    }    private void executeINVOKESTATIC() {        // Hardcoded to invoke Math.random() for Slice of Pi        double value = sf.popDouble();        double result = Math.sqrt(value);        sf.pushDouble(result);        pc += 3;    }    private void executeIOR() {        int value2 = sf.popInt();        int value1 = sf.popInt();        int result = value1 | value2;        sf.pushInt(result);        ++pc;    }    private void executeIREM() {        int value2 = sf.popInt();        int value1 = sf.popInt();        int result = value1 % value2;        sf.pushInt(result);        ++pc;    }    private void executeISHL() {        int value2 = sf.popInt();        int value1 = sf.popInt();        int result = value1 << (value2 & 0x1f);        sf.pushInt(result);        ++pc;    }    private void executeISHR() {        int value2 = sf.popInt();        int value1 = sf.popInt();        int result = value1 >> (value2 & 0x1f);        sf.pushInt(result);        ++pc;    }    private void executeISTORE() {        int locVarPos = ((int) code[pc + 1]) & 0xff;        int val = sf.popInt();        sf.setLocalInt(locVarPos, val);        pc += 2;    }    private void executeISTORE_N(int locVarPos) {        int val = sf.popInt();        sf.setLocalInt(locVarPos, val);        ++pc;    }    private void executeISUB() {        int value2 = sf.popInt();        int value1 = sf.popInt();        int result = value1 - value2;        sf.pushInt(result);        ++pc;    }    private void executeIUSHR() {        int value2 = sf.popInt();        int value1 = sf.popInt();        int result = value1 >>> (value2 & 0x1f);        sf.pushInt(result);        ++pc;    }    private void executeIXOR() {        int value2 = sf.popInt();        int value1 = sf.popInt();        int result = value1 ^ value2;        sf.pushInt(result);        ++pc;    }    private void executeJSR() {        int offset = getShortOperand(pc + 1);        sf.pushReturnAddress(new ReturnAddress(pc + 3));        pc += offset;    }    private void executeL2D() {        long value = sf.popLong();        double result = (double) value;        sf.pushDouble(result);        ++pc;    }    private void executeL2F() {        long value = sf.popLong();        float result = (float) value;        sf.pushFloat(result);        ++pc;    }    private void executeL2I() {        long value = sf.popLong();        int result = (int) value;        sf.pushInt(result);        ++pc;    }    private void executeLADD() {        long value2 = sf.popLong();        long value1 = sf.popLong();        long result = value1 + value2;        sf.pushLong(result);        ++pc;    }    private void executeLAND() {        long value2 = sf.popLong();        long value1 = sf.popLong();        long result = value1 & value2;        sf.pushLong(result);        ++pc;    }    private void executeLCONST_N(long theLong) {        sf.pushLong(theLong);        ++pc;    }    private void executeLDC2_W() {        short cpIndex = getShortOperand(pc + 1);        // Hardcoded for Slices of Pi        if (cpIndex == 6) {            sf.pushDouble(0.5);        }        else if (cpIndex == 8) {            sf.pushDouble(2.0);        }        else if (cpIndex == 10) {            sf.pushDouble(4.0);        }        pc += 3;    }    private void executeLDIV() {        long value2 = sf.popLong();        long value1 = sf.popLong();        long result = value1 / value2;        sf.pushLong(result);        ++pc;    }    private void executeLLOAD() {        int locVarPos = ((int) code[pc + 1]) & 0xff;        long theLong = sf.getLocalLong(locVarPos);        sf.pushLong(theLong);        pc += 2;    }    private void executeLLOAD_N(int locVarPos) {        long theLong = sf.getLocalLong(locVarPos);        sf.pushLong(theLong);        ++pc;    }    private void executeLMUL() {        long value2 = sf.popLong();        long value1 = sf.popLong();        long result = value1 * value2;        sf.pushLong(result);        ++pc;    }    private void executeLNEG() {        long value = sf.popLong();        long result = -value;        sf.pushLong(result);        ++pc;    }    private void executeLOR() {        long value2 = sf.popLong();        long value1 = sf.popLong();        long result = value1 | value2;        sf.pushLong(result);        ++pc;    }    private void executeLREM() {        long value2 = sf.popLong();        long value1 = sf.popLong();        long result = value1 % value2;        sf.pushLong(result);        ++pc;    }    private void executeLSHL() {        int value2 = sf.popInt();        long value1 = sf.popLong();        long result = value1 << (value2 & 0x3f);        sf.pushLong(result);        ++pc;    }    private void executeLSHR() {        int value2 = sf.popInt();        long value1 = sf.popLong();        long result = value1 >> (value2 & 0x3f);        sf.pushLong(result);        ++pc;    }    private void executeLSTORE() {        int locVarPos = ((int) code[pc + 1]) & 0xff;        long theLong = sf.popLong();        sf.setLocalLong(locVarPos, theLong);        pc += 2;    }    private void executeLSTORE_N(int locVarPos) {        long theLong = sf.popLong();        sf.setLocalLong(locVarPos, theLong);        ++pc;    }    private void executeLSUB() {        long value2 = sf.popLong();        long value1 = sf.popLong();        long result = value1 - value2;        sf.pushLong(result);        ++pc;    }    private void executeLUSHR() {        int value2 = sf.popInt();        long value1 = sf.popLong();        long result = value1 >>> (value2 & 0x3f);        sf.pushLong(result);        ++pc;    }    private void executeLXOR() {        long value2 = sf.popLong();        long value1 = sf.popLong();        long result = value1 ^ value2;        sf.pushLong(result);        ++pc;    }    private void executeMULTIANEWARRAY() {        int index = getShortOperand(pc + 1);        int dim = code[pc + 3];        if (dim < 1) {            throw new JVMSimError();        }        // Fill an array with the sizes of the various arrays. The sizes go into the        // array in the order in which they appear in the declaration, left to right.        // This was the same order in which they were pushed onto the stack. Therefore,        // the first element is assigned the value most buried (furthest down) in the        // stack.        int[] size = new int[dim];        for (int i = dim - 1; i >= 0; --i) {            size[i] = sf.popInt();        }        // This time around, I'll just assume it's an array of ints. In the future, I'll        // need to check the constant pool and pass down the type.        Object result = createMultiDimArray(size);        sf.pushObject(result);        pc += 4;    }	private void executePOP() {		sf.pop();		++pc;	}    private void executeRET() {        int index = ((int) code[pc + 1]) & 0xff;        ReturnAddress returnAddress = (ReturnAddress) sf.getLocalObject(index);        pc = returnAddress.getReturnAddress();    }    private void executeSIPUSH() {        short theShort = getShortOperand(pc + 1);        sf.pushInt(theShort);        pc += 3;    }    private void executeTABLESWITCH() {        // Skip zero to three places so the addresses are 32-bit aligned assuming        // that the first instruction in the method is at address zero.        int padding = (pc + 1) % 4;        int pcPlusPadding = pc + padding;        // Get the default branch offset        int offset = getIntOperand(pcPlusPadding + 1);        // Get the low value        int low = getIntOperand(pcPlusPadding + 5);        // Get the high value        int high = getIntOperand(pcPlusPadding + 9);        // Pop the index (the value of the switch expression) off        // of the stack        int index = sf.popInt();        // If the index is within the low-high range, grab an offset        // from the table. Else, use the default offset.        if ((index >= low) || (index <= high)) {            int result = index - low;            result *= 4;            result += pcPlusPadding + 12;            // Get the branch offset            offset = getIntOperand(result + 1);        }        pc += offset;    }}

⌨️ 快捷键说明

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