add DUP2_X1 DUP2_X2

This commit is contained in:
wangxiang
2023-07-22 22:32:28 +08:00
parent 1edd2e8509
commit da05322ccb
3 changed files with 108 additions and 2 deletions

View File

@@ -301,10 +301,10 @@ public abstract class InstructionFactory {
return new DUP2(codeStream); return new DUP2(codeStream);
} }
case Const.DUP2_X1 -> { case Const.DUP2_X1 -> {
throw new Error("Not support JavaVM opcode DUP2_X1"); return new DUP2_X1(codeStream);
} }
case Const.DUP2_X2 -> { case Const.DUP2_X2 -> {
throw new Error("Not support JavaVM opcode DUP2_X2"); return new DUP2_X2(codeStream);
} }
case Const.SWAP -> { case Const.SWAP -> {
return new SWAP(codeStream); return new SWAP(codeStream);

View File

@@ -0,0 +1,36 @@
package haidnor.jvm.instruction.stack;
import haidnor.jvm.instruction.Instruction;
import haidnor.jvm.runtime.Frame;
import haidnor.jvm.runtime.StackValue;
import haidnor.jvm.util.CodeStream;
import lombok.SneakyThrows;
import org.apache.bcel.Const;
public class DUP2_X1 extends Instruction {
public DUP2_X1(CodeStream codeStream) {
super(codeStream);
}
@Override
@SneakyThrows
public void execute(Frame frame) {
StackValue stackValue1 = frame.pop();
StackValue stackValue2 = frame.pop();
if (stackValue1.getType() == Const.T_DOUBLE || stackValue1.getType() == Const.T_LONG) {
frame.push(stackValue1);
frame.push(stackValue2);
frame.push(stackValue1);
} else {
StackValue stackValue3 = frame.pop();
frame.push(stackValue1);
frame.push(stackValue2);
frame.push(stackValue3);
frame.push(stackValue1);
frame.push(stackValue2);
}
}
}

View File

@@ -0,0 +1,70 @@
package haidnor.jvm.instruction.stack;
import haidnor.jvm.instruction.Instruction;
import haidnor.jvm.runtime.Frame;
import haidnor.jvm.runtime.StackValue;
import haidnor.jvm.util.CodeStream;
import lombok.SneakyThrows;
import org.apache.bcel.Const;
/**
* @author wang xiang
*/
public class DUP2_X2 extends Instruction {
public DUP2_X2(CodeStream codeStream) {
super(codeStream);
}
@Override
@SneakyThrows
public void execute(Frame frame) {
StackValue stackValue1 = frame.pop();
// v1(64)
if (stackValue1.getType() == Const.T_DOUBLE || stackValue1.getType() == Const.T_LONG) {
StackValue stackValue2 = frame.pop();
// v1(64) v2(64)
if (stackValue2.getType() == Const.T_DOUBLE || stackValue2.getType() == Const.T_LONG) {
frame.push(stackValue1);
frame.push(stackValue2);
frame.push(stackValue1);
}
// v1(64) v2(32)
else {
StackValue stackValue3 = frame.pop();
frame.push(stackValue1);
frame.push(stackValue2);
frame.push(stackValue3);
frame.push(stackValue1);
}
}
// v1(32)
else {
StackValue stackValue2 = frame.pop();
StackValue stackValue3 = frame.pop();
// v1(32) v2(32) v3(64)
if (stackValue3.getType() == Const.T_DOUBLE || stackValue3.getType() == Const.T_LONG) {
frame.push(stackValue1);
frame.push(stackValue2);
frame.push(stackValue3);
frame.push(stackValue1);
frame.push(stackValue2);
}
// v1(32) v2(32) v3(32) v4(32)
else {
StackValue stackValue4 = frame.pop();
frame.push(stackValue1);
frame.push(stackValue2);
frame.push(stackValue3);
frame.push(stackValue4);
frame.push(stackValue1);
frame.push(stackValue2);
}
}
}
}