<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Re: Matching and replacing a sequence of bytecodes/instructions
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/susanin">susanin</a> in <i>Javassist</i> - <a href="https://community.jboss.org/message/745894#745894">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Update:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>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. </p><p>For example you can say <span style="color: #000000;"><span class="str">"NOP+(ILOAD|ALOAD)*" or "GETFIELD PUTFIELD". There are also short-cuts for common groups of instructions</span></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>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:</p><ol><li style="text-align: start;"> 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.</li><li style="text-align: start;">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</li><li style="text-align: start;">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 : <ul><li style="text-align: start;">which easy to use syntax should be used for bytecode expressions? </li><li style="text-align: start;">If and how it can be mixed with Java?</li></ul></li></ol><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="text-align: start;">Any comments and opinions regarding mentioned problems is very welcome!</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="text-align: start;">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. </p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/745894#745894">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in Javassist at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2062">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>