add return 系列字节码指令的抽象类

This commit is contained in:
wangxiang
2023-07-30 13:16:37 +08:00
parent 368e9e60b7
commit 0c2290c3e3
8 changed files with 23 additions and 14 deletions

View File

@@ -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;
}
// 程序计数器值增加. 指向下一次执行的字节码行号

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);
}
}