gpt4 book ai didi

java - 我们可以在 BCEL 中将自定义类型对象推送到堆栈操作数吗?

转载 作者:行者123 更新时间:2023-11-30 11:53:29 27 4
gpt4 key购买 nike

在 BCEL 中,我们可以将原始类型压入操作数栈。但是现在我想知道是否可以在 BCEL 中将自定义类型对象推送到堆栈上

我正在提供一些代码,以便它可以解释问题上下文

    class Automobile {

public void getEngine(int carNo,EngineClass engineClassObj){

System.out.println("EngineNo="+engineClassObj.sisNo);
}
}

Now when i load "Automobile" class in memory.

ilist = new InstructionList();
ilist.append(InstructionConstants.ALOAD_0);
ilist.append(new PUSH(pgen,345));

////Hear Now i have to also push the Object on Stack

ilist.append(ifact.createInvoke(_invoking_ClassName,_invoking_MethodName, Type.INT,*
new Type[] { Type.INT,Type.OBJECT }, Constants.INVOKEVIRTUAL));

ilist.append(InstructionConstants.IRETURN);

1-如果我使用 createNew() 方法并生成新对象,那么我将如何填写其字段值?2-或者如果我首先使用 PUSH 将引擎类型 Obj 的所有字段值推送到堆栈上然后我可以了解如何在内存中构建对象,然后将其推送到堆栈上。这些是我能想到的一些解决方案。

但我不知道正确的解决方案所以仍然需要帮助......

最佳答案

NEW创建一个新对象并将对它的引用放在堆栈上。它需要一个指向常量池中类引用的索引,可以通过 ConstantPoolGen.addClass 获得。 .例如:

il = new InstructionList();
il.append(new NEW(cp.addClass("java.lang.StringBuffer")));

这取自ASTProgram.java这是 BCEL 示例的一部分。

还有其他方法可以在堆栈上获取对象引用。例如,ACONST_NULL将空引用压入堆栈,ALOAD从局部变量或 GETSTATIC 加载引用从类中获取静态字段。

关于java - 我们可以在 BCEL 中将自定义类型对象推送到堆栈操作数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6249394/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com