<!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="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">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;">
    JVM advice needed
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/swd847">Stuart Douglas</a> in <i>Javassist</i> - <a href="http://community.jboss.org/message/539410#539410">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>I am using javassist on an open source project that aims to bring run time class reloading to java, without discarding the classloader.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>It aims to expand on the hotswap capabilities of the JVM, by recompiling the classes as they are loaded to allow the schema to be changed.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>For instance an Object[] field is added to all classes as they are loaded, if the user then adds a field all gets/puts to this field are re-written to be array access to this array. The reflection API is also instrumented so it appears the new field behaves as expected with regard to reflection, and the fields/methods added at load time do not show up. This instrumentation also allows for annotations to be modified.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I similar approach is taken with static methods, a general purpose method is added at compile time:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>static public Object FAKEREPALCE_ADDED_METHOD(int mno, Object[] args)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>and the bytecode from the added method is placed in the method body of this method inside a conditional based on the method number. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>This approach works quite well, mostly because you know that no existing code references the new field or method. However with virtual methods this is not the case as the user can add a new method that overrides a superclass method, so existing code will not be aware of the added method and the superclass method will continue to be called. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The only way i can see to get around this is to add overriden methods to all classes as they are loaded that call the corresponding superclass method, e.g.:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>public String toString()</p><p>{</p><p>&#160;&#160;&#160;&#160; return super.toString();</p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Obviously this will result in a lot of extra methods being generated, and may result in quite a significant performance degradation.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I was wondering if anyone can think of a better / less invasive way to accomplish this? </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span>If anyone is interested the project is here: </span><a class="jive-link-external-small" href="http://code.google.com/p/fakereplace/" target="_blank">http://code.google.com/p/fakereplace/</a></p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/539410#539410">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in Javassist at <a href="http://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>