[jboss-jira] [JBoss JIRA] (JASSIST-172) Support for matching and replacing sequences of bytecode instructions
susanin (JIRA)
jira-events at lists.jboss.org
Fri Jul 6 08:25:12 EDT 2012
susanin created JASSIST-172:
-------------------------------
Summary: Support for matching and replacing sequences of bytecode instructions
Key: JASSIST-172
URL: https://issues.jboss.org/browse/JASSIST-172
Project: Javassist
Issue Type: Feature Request
Affects Versions: 3.16.1-GA
Reporter: susanin
Assignee: Shigeru Chiba
Priority: Optional
I've ported BCEL's instruction matching feature (InstructionFinder class, see http://commons.apache.org/bcel/manual.html, section 3.3.7) to Javassist. The matching part works perfectly and is really nice. You can build regular expressions over bytecode instructions, i.e. it is like a usual regex for String, but your alphabet is bytecode instructions instead of letters.
For example you can say "NOP+(ILOAD|ALOAD)*" or "GETFIELD PUTFIELD". There are also short-cuts for often used or 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:
- 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.
- 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
- 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 attach my current patches.
The original discussion thread can be found here:
https://community.jboss.org/thread/201922?tstart=0
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list