문제

I'm using ASM4 for some Java bytecode manipulation. I want to copy some code from one method to another one. The latter has some additional code and because of that every LabelNode from the first method must be remapped.

The problem arise when local variables needs to be inserted. I followed this pattern: get the local variables from first method, create a copy of it with index and start label and ending label nodes modified. The visitor used to get the local variable has this form:

public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index)

and the code that should insert a new local variable look like this:

localVariableList.add(new LocalVariableNode((String name, String desc, String signature, LabelNode start, LabelNode end, int index)))

Problem is, the info field from Label object is null, therefore I can't get a reference of the old LabelNode so that I could remap with my new label nodes.

I also tried to get the offset from the code with label.getOffset() and then remap the offset to a list of offsets associated with my new list of LabelNode but I get an exception:

java.lang.IllegalStateException: Label offset position has not been resolved yet
at org.objectweb.asm.Label.getOffset(Unknown Source)

If any of you has an idea of how could I get the corresponding LabelNode from a Label would be much appreciated. Or maybe there's a better approach on copying the code from one method to another one and resolving the issue with labels, lablenode's and localvariables.

Most of the time I use the tree API because of it's simplicity.

Thank for you help.

도움이 되었습니까?

해결책

There is an example of similar transformation in "Inline Method" section of my AOSD'07 paper.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top