mirror of
https://github.com/FranzHaidnor/haidnorJVM.git
synced 2026-03-14 06:03:50 +08:00
upd JavaExecutionEngine
This commit is contained in:
@@ -35,25 +35,25 @@ public class JavaExecutionEngine {
|
|||||||
* 执行普通方法
|
* 执行普通方法
|
||||||
*
|
*
|
||||||
* @param lastFrame 方法调用者的栈帧
|
* @param lastFrame 方法调用者的栈帧
|
||||||
* @param javaMethod 方法元信息
|
* @param method 方法元信息
|
||||||
*/
|
*/
|
||||||
public static void callMethod(Frame lastFrame, JavaMethod javaMethod) {
|
public static void callMethod(Frame lastFrame, JavaMethod method) {
|
||||||
JVMThread jvmThread = JVMThreadHolder.get();
|
JVMThread thread = JVMThreadHolder.get();
|
||||||
// 调用方法时会创建新的栈帧
|
// 调用方法时会创建新的栈帧
|
||||||
Frame newFrame = new Frame(jvmThread, javaMethod);
|
Frame newFrame = new Frame(thread, method);
|
||||||
|
|
||||||
// 如果线程栈内存在栈帧, 代表可能需要方法调用传参
|
// 如果线程栈内存在栈帧, 代表可能需要方法调用传参
|
||||||
if (lastFrame != null) {
|
if (lastFrame != null) {
|
||||||
String signature = javaMethod.getSignature();
|
String signature = method.getSignature();
|
||||||
String[] argumentTypes = Utility.methodSignatureArgumentTypes(signature);
|
String[] argumentTypes = Utility.methodSignatureArgumentTypes(signature);
|
||||||
|
|
||||||
int argumentSlotSize = argumentTypes.length;
|
int argumentSlotSize = argumentTypes.length;
|
||||||
if (!javaMethod.isStatic()) {
|
if (!method.isStatic()) {
|
||||||
argumentSlotSize++;
|
argumentSlotSize++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 方法调用传参 (原理: 将顶部栈帧的操作数栈中的数据弹出, 存入新栈帧的局部变量表中)
|
// 方法调用传参 (原理: 将顶部栈帧的操作数栈中的数据弹出, 存入新栈帧的局部变量表中)
|
||||||
LocalVariableTable localVariableTable = javaMethod.getLocalVariableTable();
|
LocalVariableTable localVariableTable = method.getLocalVariableTable();
|
||||||
if (localVariableTable != null) {
|
if (localVariableTable != null) {
|
||||||
for (int i = argumentSlotSize - 1; i >= 0; i--) {
|
for (int i = argumentSlotSize - 1; i >= 0; i--) {
|
||||||
LocalVariable[] localVariableArr = localVariableTable.getLocalVariableTable();
|
LocalVariable[] localVariableArr = localVariableTable.getLocalVariableTable();
|
||||||
@@ -66,7 +66,7 @@ public class JavaExecutionEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 将新栈帧压入线程栈顶部, 并执行新栈帧中的代码
|
// 将新栈帧压入线程栈顶部, 并执行新栈帧中的代码
|
||||||
jvmThread.push(newFrame);
|
thread.push(newFrame);
|
||||||
executeFrame(newFrame);
|
executeFrame(newFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,12 +51,12 @@ public class Frame {
|
|||||||
*/
|
*/
|
||||||
private final Slot[] slots;
|
private final Slot[] slots;
|
||||||
|
|
||||||
public Frame(JVMThread thread, JavaMethod javaMethod) {
|
public Frame(JVMThread thread, JavaMethod method) {
|
||||||
this.jvmThread = thread;
|
this.jvmThread = thread;
|
||||||
this.javaClass = javaMethod.getJavaClass();
|
this.javaClass = method.getJavaClass();
|
||||||
this.javaMethod = javaMethod;
|
this.javaMethod = method;
|
||||||
this.code = javaMethod.getCode();
|
this.code = method.getCode();
|
||||||
this.codeStream = new CodeStream(javaMethod.getCode());
|
this.codeStream = new CodeStream(method.getCode());
|
||||||
this.slots = new Slot[code.getMaxLocals()];
|
this.slots = new Slot[code.getMaxLocals()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user