support finally

This commit is contained in:
wangxiang
2023-07-25 14:15:54 +08:00
parent dc16862bb1
commit 86c3689b1d
5 changed files with 48 additions and 3 deletions

View File

@@ -3,7 +3,7 @@ package haidnor.jvm.core;
import haidnor.jvm.instruction.Instruction; import haidnor.jvm.instruction.Instruction;
import haidnor.jvm.instruction.InstructionFactory; import haidnor.jvm.instruction.InstructionFactory;
import haidnor.jvm.instruction.control.RETURN; import haidnor.jvm.instruction.control.*;
import haidnor.jvm.rtda.KlassMethod; import haidnor.jvm.rtda.KlassMethod;
import haidnor.jvm.runtime.Frame; import haidnor.jvm.runtime.Frame;
import haidnor.jvm.runtime.JVMThread; import haidnor.jvm.runtime.JVMThread;
@@ -95,7 +95,7 @@ public class JavaExecutionEngine {
Instruction instruction = instructionMap.get(i); Instruction instruction = instructionMap.get(i);
log.debug("{}│ {}", blank, instruction); log.debug("{}│ {}", blank, instruction);
instruction.execute(frame); instruction.execute(frame);
if (instruction instanceof RETURN) { if (instruction instanceof RETURN || instruction instanceof ARETURN || instruction instanceof DRETURN || instruction instanceof FRETURN || instruction instanceof IRETURN) {
break; break;
} }
i += instruction.offSet(); i += instruction.offSet();

View File

@@ -595,7 +595,7 @@ public abstract class InstructionFactory {
return new ARRAYLENGTH(codeStream); return new ARRAYLENGTH(codeStream);
} }
case Const.ATHROW -> { case Const.ATHROW -> {
throw new Error("Not support JavaVM opcode ATHROW"); return new ATHROW(codeStream);
} }
case Const.CHECKCAST -> { case Const.CHECKCAST -> {
return new CHECKCAST(codeStream); return new CHECKCAST(codeStream);

View File

@@ -0,0 +1,20 @@
package haidnor.jvm.instruction.references;
import haidnor.jvm.instruction.Instruction;
import haidnor.jvm.runtime.Frame;
import haidnor.jvm.util.CodeStream;
import lombok.SneakyThrows;
public class ATHROW extends Instruction {
public ATHROW(CodeStream codeStream) {
super(codeStream);
}
@Override
@SneakyThrows
public void execute(Frame frame) {
}
}

View File

@@ -70,6 +70,11 @@ public class TestJVM {
runMainClass(Demo6.class); runMainClass(Demo6.class);
} }
@Test
public void test_7() throws Exception {
runMainClass(Demo7.class);
}
@Test @Test
public void test_NEW() throws Exception { public void test_NEW() throws Exception {
runMainClass(NEW.class); runMainClass(NEW.class);

View File

@@ -0,0 +1,20 @@
package haidnor.jvm.test.demo;
public class Demo7 {
public static void main(String[] args) {
String fun = fun();
System.out.println(fun);
}
public static String fun() {
String str = "hello";
try {
return str;
} finally {
System.out.println("zhangsan");
}
}
}