<liclass="toctree-l3"><aclass="reference internal"href="#tips-for-uploading-class-files-to-the-server">Tips for uploading .class files to the server</a></li>
<liclass="toctree-l1"><aclass="reference external"href="https://github.com/alibaba/arthas/issues?q=label%3Aquestion-answered">Questions and answers</a></li>
<liclass="toctree-l1"><aclass="reference external"href="https://github.com/alibaba/arthas">Fork me at GitHub</a></li>
<liclass="toctree-l1"><aclass="reference external"href="https://github.com/alibaba/arthas/blob/master/CONTRIBUTING.md#">Compile and debug/CONTRIBUTING</a></li>
<div><p>Load the external <codeclass="docutils literal notranslate"><spanclass="pre">*.class</span></code> files to re-define the loaded classes in JVM.</p>
<div><p>Notes: Re-defined classes cannot be restored. There are chances that redefining may fail due to some reasons, for example: there’s new field introduced in the new version of the class, pls. refer to JDK’s documentation for the limitations.</p>
<div><p>The <codeclass="docutils literal notranslate"><spanclass="pre">reset</span></code> command is not valid for classes that have been processed by <codeclass="docutils literal notranslate"><spanclass="pre">redefine</span></code>. If you want to reset, you need <codeclass="docutils literal notranslate"><spanclass="pre">redefine</span></code> the original bytecode.</p>
<div><p>The <codeclass="docutils literal notranslate"><spanclass="pre">redefine</span></code> command will conflict with the <codeclass="docutils literal notranslate"><spanclass="pre">jad</span></code>/<codeclass="docutils literal notranslate"><spanclass="pre">watch</span></code>/<codeclass="docutils literal notranslate"><spanclass="pre">trace</span></code>/<codeclass="docutils literal notranslate"><spanclass="pre">monitor</span></code>/<codeclass="docutils literal notranslate"><spanclass="pre">tt</span></code> commands. After executing <codeclass="docutils literal notranslate"><spanclass="pre">redefine</span></code>, if you execute the above mentioned command, the bytecode of the class will be reset.
The reason is that in the JDK <codeclass="docutils literal notranslate"><spanclass="pre">redefine</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">retransform</span></code> are different mechanisms. When two mechanisms are both used to update the bytecode, only the last modified will take effect.</p>
<li><p>Use <codeclass="docutils literal notranslate"><spanclass="pre">jad</span></code> command to decompile bytecode, and then you can use other editors, such as vim to modify the source code.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">mc</span></code> command to compile the modified code</p></li>
<li><p>Load new bytecode with <codeclass="docutils literal notranslate"><spanclass="pre">redefine</span></code> command</p></li>
<h2>Tips for uploading .class files to the server<aclass="headerlink"href="#tips-for-uploading-class-files-to-the-server"title="Permalink to this headline">¶</a></h2>
<p>The <codeclass="docutils literal notranslate"><spanclass="pre">mc</span></code> command may fail. You can modify the code locally, compile it, and upload it to the server. Some servers do not allow direct uploading files, you can use the <codeclass="docutils literal notranslate"><spanclass="pre">base64</span></code> command to bypass.</p>
<li><p>Convert the <codeclass="docutils literal notranslate"><spanclass="pre">.class</span></code> file to base64 first, then save it as result.txt</p>
<li><p>Login the server, create and edit <codeclass="docutils literal notranslate"><spanclass="pre">result.txt</span></code>, copy the local content, paste and save</p></li>
<li><p>Restore <codeclass="docutils literal notranslate"><spanclass="pre">result.txt</span></code> on the server to <codeclass="docutils literal notranslate"><spanclass="pre">.class</span></code></p>
<li><p>Use the md5 command to verify that the <codeclass="docutils literal notranslate"><spanclass="pre">.class</span></code> files are consistent.</p></li>
<li><p>The function that is running, no exit can not take effect, such as the new <codeclass="docutils literal notranslate"><spanclass="pre">System.out.println</span></code> added below, only the <codeclass="docutils literal notranslate"><spanclass="pre">run()</span></code> function will take effect.</p>
Built with <ahref="http://sphinx-doc.org/">Sphinx</a> using a <ahref="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <ahref="https://readthedocs.org">Read the Docs</a>.