[jboss-user] [Javassist] - Re: Matching and replacing a sequence of bytecodes/instructions

susanin do-not-reply at jboss.com
Tue Jul 3 17:07:35 EDT 2012


susanin [https://community.jboss.org/people/susanin] created the discussion

"Re: Matching and replacing a sequence of bytecodes/instructions"

To view the discussion, visit: https://community.jboss.org/message/745894#745894

--------------------------------------------------------------
Update:

I've ported BCEL's instruction matching feature (InstructionFinder class) to Javassist in the meantime. The matching part works perfectly and is really nice. You can build regular expressions over bytecodes, i.e. it is like usual regex for String, but your letters are bytecode instructions. 
For example you can say "NOP+(ILOAD|ALOAD)*" or "GETFIELD PUTFIELD". There are also short-cuts for common groups of instructions

At the moment I'm working on the replacement part. I'm trying to follow the ExprEditor approach and provide a similar API for instruction matching and replacement. It is sort of working already for simple use-cases, but still needs more work. Some of the problems that I face are:
1.  A match can span multiple bytecode instructions. Should each instruction be accessible via a special $... syntax? If so, which one. May be $#i, which would refer to the i-th instruction in the matched fragment.
2. Should it be possible to replace all of the instructions or just some of them by e.g. using a special syntax like $#i = replacement_expression
3. In ExprEditor and related classes, the replacement expression is using a Java syntax, which is very nice. But since we want to replace bytecode instructions here, we may need to be able to use bytecode instructions in the replacement expression string, because Java expressions are too high-level to express some aspects at bytecode level (e.g. pushing/poping values from stack). I can see scenarios, where one would only want to use bytecode instructions in the replecement, where one would want to use a mix of java code and bytecode instructions and where only Java code is used. Among other things, these questions are interesting here : * which easy to use syntax should be used for bytecode expressions? 
* If and how it can be mixed with Java?


Any comments and opinions regarding mentioned problems is very welcome!

And please let me know if there is any interest in this functionality. If so, I could create a JIRA issue and attach my current patches there as a start.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/745894#745894]

Start a new discussion in Javassist at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2062]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120703/173bbd37/attachment-0001.html 


More information about the jboss-user mailing list