1

I am wondering whether it is possible to combine multiple java method bytecode sequences into one method. Assume we have a method A, which invokes another two method B1, and B2.

A bytecode sequences: 

.....
invokevirtual B1 
iload ..
....
invokevirtual B2 
.... 

At runtime, B1 and B2 may be close correlated and we want to combine B1 bytecodes and B2 bytecodes, together with bytecodes between "invokevirtul B1" and "invokevirtual B2", into one method.

I am not sure whether it is possible to implement, I would appreciate if some clue can be provided. THanks.

2
  • 1
    FYI: This is called "inline expansion", or just "inlining". en.wikipedia.org/wiki/Inline_expansion Commented May 10, 2014 at 17:11
  • It is somewhat like adverse of "inline" Commented May 11, 2014 at 0:24

2 Answers 2

1

Yes, it is possible, with a few minor restrictions. The main restriction is that a single method's bytecode is limited to 65535 bytes, but you're unlikely to run into this restriction in practice. The number of exception handlers, local variable slots, and operand stack size in a single method are also limited, though these are even less likely to be reached.

Sign up to request clarification or add additional context in comments.

1 Comment

Do you have idea of what opensource projects or documents related to this topic.. Though i can merge two functions into one method with ASM, i still have little knowledge how to invoke this new method.. Also, what potential issues with combined method?
1

See ASM bytecode manipylation framework code example from my paper "Using ASM framework to implement common bytecode transformation patterns" [1].

[1] http://asm.ow2.org/current/asm-transformations.pdf

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.