upd JavaMethod

This commit is contained in:
wangxiang
2023-10-25 15:21:04 +08:00
parent c91945c791
commit 82348cee01
4 changed files with 16 additions and 5 deletions

View File

@@ -210,6 +210,11 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
staticJavaFieldMap.put(field.getName(), field); staticJavaFieldMap.put(field.getName(), field);
} }
} }
JavaMethod[] javaMethods = getMethods();
for (JavaMethod javaMethod : javaMethods) {
javaMethod.setJavaClass(this);
}
} }
/* /*

View File

@@ -18,6 +18,8 @@ package haidnor.jvm.bcel.classfile;
import haidnor.jvm.bcel.generic.Type; import haidnor.jvm.bcel.generic.Type;
import haidnor.jvm.bcel.util.BCELComparator; import haidnor.jvm.bcel.util.BCELComparator;
import lombok.Getter;
import lombok.Setter;
import java.io.DataInput; import java.io.DataInput;
import java.io.IOException; import java.io.IOException;
@@ -57,6 +59,10 @@ public class JavaMethod extends FieldOrMethod {
// annotations defined on the parameters of a method // annotations defined on the parameters of a method
private ParameterAnnotationEntry[] parameterAnnotationEntries; private ParameterAnnotationEntry[] parameterAnnotationEntries;
@Getter
@Setter
private JavaClass javaClass;
/** /**
* Empty constructor, all attributes have to be defined via 'setXXX' methods. Use at your own risk. * Empty constructor, all attributes have to be defined via 'setXXX' methods. Use at your own risk.
*/ */

View File

@@ -28,7 +28,7 @@ public class JavaExecutionEngine {
*/ */
public static void callMainMethod(JavaClass javaClass) { public static void callMainMethod(JavaClass javaClass) {
JavaMethod mainMethod = javaClass.getMainMethod(); JavaMethod mainMethod = javaClass.getMainMethod();
callMethod(null, javaClass, mainMethod); callMethod(null, mainMethod);
} }
/** /**
@@ -37,10 +37,10 @@ public class JavaExecutionEngine {
* @param lastFrame 方法调用者的栈帧 * @param lastFrame 方法调用者的栈帧
* @param javaMethod 方法元信息 * @param javaMethod 方法元信息
*/ */
public static void callMethod(Frame lastFrame, JavaClass javaClass, JavaMethod javaMethod) { public static void callMethod(Frame lastFrame, JavaMethod javaMethod) {
JVMThread jvmThread = JVMThreadHolder.get(); JVMThread jvmThread = JVMThreadHolder.get();
// 调用方法时会创建新的栈帧 // 调用方法时会创建新的栈帧
Frame newFrame = new Frame(jvmThread, javaClass, javaMethod); Frame newFrame = new Frame(jvmThread, javaMethod);
// 如果线程栈内存在栈帧, 代表可能需要方法调用传参 // 如果线程栈内存在栈帧, 代表可能需要方法调用传参
if (lastFrame != null) { if (lastFrame != null) {

View File

@@ -51,9 +51,9 @@ public class Frame {
*/ */
private final Slot[] slots; private final Slot[] slots;
public Frame(JVMThread thread, JavaClass javaClass, JavaMethod javaMethod) { public Frame(JVMThread thread, JavaMethod javaMethod) {
this.jvmThread = thread; this.jvmThread = thread;
this.javaClass = javaClass; this.javaClass = javaMethod.getJavaClass();
this.javaMethod = javaMethod; this.javaMethod = javaMethod;
this.code = javaMethod.getCode(); this.code = javaMethod.getCode();
this.codeStream = new CodeStream(javaMethod.getCode()); this.codeStream = new CodeStream(javaMethod.getCode());