mirror of
https://github.com/FranzHaidnor/haidnorJVM.git
synced 2026-03-14 06:03:50 +08:00
fix:方法调用传参无效
编译器将编译后,class文件不存在 LocalVariableTable。 从而导致调用传参步骤错误。
This commit is contained in:
@@ -32,8 +32,8 @@ public class JavaExecutionEngine {
|
|||||||
/**
|
/**
|
||||||
* 执行普通方法
|
* 执行普通方法
|
||||||
*
|
*
|
||||||
* @param lastFrame 方法调用者的栈帧
|
* @param lastFrame 方法调用者的栈帧
|
||||||
* @param method 方法元信息
|
* @param method 方法元信息
|
||||||
*/
|
*/
|
||||||
public static void callMethod(Frame lastFrame, JavaMethod method) {
|
public static void callMethod(Frame lastFrame, JavaMethod method) {
|
||||||
JVMThread thread = JVMThreadHolder.get();
|
JVMThread thread = JVMThreadHolder.get();
|
||||||
@@ -47,19 +47,14 @@ public class JavaExecutionEngine {
|
|||||||
|
|
||||||
int argumentSlotSize = argumentTypes.length;
|
int argumentSlotSize = argumentTypes.length;
|
||||||
if (!method.isStatic()) {
|
if (!method.isStatic()) {
|
||||||
|
// 非静态方法 argumentSlotSize++ 的原因是第一个 slot 需要存放对象本身的引用
|
||||||
argumentSlotSize++;
|
argumentSlotSize++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 方法调用传参 (原理: 将顶部栈帧的操作数栈中的数据弹出, 存入新栈帧的局部变量表中)
|
// 方法调用传参 (原理: 将顶部栈帧的操作数栈中的数据弹出, 存入新栈帧的局部变量表中)
|
||||||
LocalVariableTable localVariableTable = method.getLocalVariableTable();
|
for (int i = argumentSlotSize - 1; i >= 0; i--) {
|
||||||
if (localVariableTable != null) {
|
StackValue stackValue = lastFrame.pop();
|
||||||
for (int i = argumentSlotSize - 1; i >= 0; i--) {
|
newFrame.slotSet(i, stackValue);
|
||||||
LocalVariable[] localVariableArr = localVariableTable.getLocalVariableTable();
|
|
||||||
LocalVariable localVariable = localVariableArr[i];
|
|
||||||
int slotIndex = localVariable.getIndex();
|
|
||||||
StackValue stackValue = lastFrame.pop();
|
|
||||||
newFrame.slotSet(slotIndex, stackValue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user