diff --git a/src/main/java/haidnor/jvm/core/JavaExecutionEngine.java b/src/main/java/haidnor/jvm/core/JavaExecutionEngine.java index dad918f..80d4ded 100644 --- a/src/main/java/haidnor/jvm/core/JavaExecutionEngine.java +++ b/src/main/java/haidnor/jvm/core/JavaExecutionEngine.java @@ -102,8 +102,8 @@ public class JavaExecutionEngine { try { // 执行字节码指令 instruction.execute(frame); - // 若为 return 系列指令则结束当前栈帧 - if (instruction instanceof RETURN || instruction instanceof ARETURN || instruction instanceof DRETURN || instruction instanceof FRETURN || instruction instanceof IRETURN) { + // 若为 return 系列指令则结束当前栈帧 (RETURN,ARETURN,DRETURN,FRETURN,IRETURN) + if (instruction instanceof ReturnableInstruction) { break; } // 程序计数器值增加. 指向下一次执行的字节码行号 diff --git a/src/main/java/haidnor/jvm/instruction/control/ARETURN.java b/src/main/java/haidnor/jvm/instruction/control/ARETURN.java index 15533cb..1dc6f41 100644 --- a/src/main/java/haidnor/jvm/instruction/control/ARETURN.java +++ b/src/main/java/haidnor/jvm/instruction/control/ARETURN.java @@ -1,12 +1,11 @@ package haidnor.jvm.instruction.control; -import haidnor.jvm.instruction.Instruction; import haidnor.jvm.runtime.Frame; import haidnor.jvm.runtime.StackValue; import haidnor.jvm.util.CodeStream; import haidnor.jvm.util.JvmThreadHolder; -public class ARETURN extends Instruction { +public class ARETURN extends ReturnableInstruction { public ARETURN(CodeStream codeStream) { super(codeStream); diff --git a/src/main/java/haidnor/jvm/instruction/control/DRETURN.java b/src/main/java/haidnor/jvm/instruction/control/DRETURN.java index 16da89f..eaab65e 100644 --- a/src/main/java/haidnor/jvm/instruction/control/DRETURN.java +++ b/src/main/java/haidnor/jvm/instruction/control/DRETURN.java @@ -1,12 +1,11 @@ package haidnor.jvm.instruction.control; -import haidnor.jvm.instruction.Instruction; import haidnor.jvm.runtime.Frame; import haidnor.jvm.runtime.StackValue; import haidnor.jvm.util.CodeStream; import haidnor.jvm.util.JvmThreadHolder; -public class DRETURN extends Instruction { +public class DRETURN extends ReturnableInstruction { public DRETURN(CodeStream codeStream) { super(codeStream); diff --git a/src/main/java/haidnor/jvm/instruction/control/FRETURN.java b/src/main/java/haidnor/jvm/instruction/control/FRETURN.java index b0bc326..694df1c 100644 --- a/src/main/java/haidnor/jvm/instruction/control/FRETURN.java +++ b/src/main/java/haidnor/jvm/instruction/control/FRETURN.java @@ -1,12 +1,11 @@ package haidnor.jvm.instruction.control; -import haidnor.jvm.instruction.Instruction; import haidnor.jvm.runtime.Frame; import haidnor.jvm.runtime.StackValue; import haidnor.jvm.util.CodeStream; import haidnor.jvm.util.JvmThreadHolder; -public class FRETURN extends Instruction { +public class FRETURN extends ReturnableInstruction { public FRETURN(CodeStream codeStream) { super(codeStream); diff --git a/src/main/java/haidnor/jvm/instruction/control/IRETURN.java b/src/main/java/haidnor/jvm/instruction/control/IRETURN.java index f7781c0..294ba2e 100644 --- a/src/main/java/haidnor/jvm/instruction/control/IRETURN.java +++ b/src/main/java/haidnor/jvm/instruction/control/IRETURN.java @@ -1,12 +1,11 @@ package haidnor.jvm.instruction.control; -import haidnor.jvm.instruction.Instruction; import haidnor.jvm.runtime.Frame; import haidnor.jvm.runtime.StackValue; import haidnor.jvm.util.CodeStream; import haidnor.jvm.util.JvmThreadHolder; -public class IRETURN extends Instruction { +public class IRETURN extends ReturnableInstruction { public IRETURN(CodeStream codeStream) { super(codeStream); diff --git a/src/main/java/haidnor/jvm/instruction/control/LRETURN.java b/src/main/java/haidnor/jvm/instruction/control/LRETURN.java index 2fa2187..50de213 100644 --- a/src/main/java/haidnor/jvm/instruction/control/LRETURN.java +++ b/src/main/java/haidnor/jvm/instruction/control/LRETURN.java @@ -1,12 +1,11 @@ package haidnor.jvm.instruction.control; -import haidnor.jvm.instruction.Instruction; import haidnor.jvm.runtime.Frame; import haidnor.jvm.runtime.StackValue; import haidnor.jvm.util.CodeStream; import haidnor.jvm.util.JvmThreadHolder; -public class LRETURN extends Instruction { +public class LRETURN extends ReturnableInstruction { public LRETURN(CodeStream codeStream) { super(codeStream); diff --git a/src/main/java/haidnor/jvm/instruction/control/RETURN.java b/src/main/java/haidnor/jvm/instruction/control/RETURN.java index 56ff11a..596082f 100644 --- a/src/main/java/haidnor/jvm/instruction/control/RETURN.java +++ b/src/main/java/haidnor/jvm/instruction/control/RETURN.java @@ -1,11 +1,10 @@ package haidnor.jvm.instruction.control; -import haidnor.jvm.instruction.Instruction; import haidnor.jvm.runtime.Frame; import haidnor.jvm.util.CodeStream; import haidnor.jvm.util.JvmThreadHolder; -public class RETURN extends Instruction { +public class RETURN extends ReturnableInstruction { public RETURN(CodeStream codeStream) { super(codeStream); diff --git a/src/main/java/haidnor/jvm/instruction/control/ReturnableInstruction.java b/src/main/java/haidnor/jvm/instruction/control/ReturnableInstruction.java new file mode 100644 index 0000000..5e00204 --- /dev/null +++ b/src/main/java/haidnor/jvm/instruction/control/ReturnableInstruction.java @@ -0,0 +1,15 @@ +package haidnor.jvm.instruction.control; + +import haidnor.jvm.instruction.Instruction; +import haidnor.jvm.util.CodeStream; + +/** + * return 系列字节码指令的抽象类 + */ +public abstract class ReturnableInstruction extends Instruction { + + public ReturnableInstruction(CodeStream codeStream) { + super(codeStream); + } + +}