开发者

Can we push a Custom Type Object on Stack Operand in BCEL?

In BCEL we can push primitive types on Operand Stack. BUT now I want to know if it is possible to push a Custom Type Object on Stack in BCEL?

I am giving some code so that it can explain the Problem Context

    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-if i use createNew() method and generate new object then how i am going to fill its fields 开发者_运维问答value? 2-or if i firstly push all fields values of Engine type Obj on Stack using PUSH then i can some how construct object on memory & then push it on Stack. these are some solution i can think of.

But i don't know the right solution So Still need help ...


NEW creates a new object and places a reference to it on stack. It needs an index to the class reference in the constant pool which can be obtained with ConstantPoolGen.addClass. For example:

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

This is taken from ASTProgram.java which is a part of BCEL examples.

There are other ways to get an object reference on stack as well. For example, ACONST_NULL pushes a null reference on stack, ALOAD loads a reference from local variable or GETSTATIC fetches static field from class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜