* [echo](echo.md) - write arguments to the standard output
* [grep](grep.md) - Pattern searcher
* [base64](base64.md) - Encode and decode using Base64 representation.
* [tee](tee.md) - Copies standard input to standard output, making a copy in zero or more files.
* [pwd](pwd.md) - Return working directory name
* session - display current session information
@ -39,6 +40,7 @@ Advanced Usage
* [sm](sm.md) - check methods info for the loaded classes
* [jad](jad.md) - decompile the specified loaded classes
* [mc](mc.md) - Memory compiler, compiles `.java` files into `.class` files in memory
* [retransform](retransform.md) - load external `*.class` files and retransform it into JVM
* [redefine](redefine.md) - load external `*.class` files and re-define it into JVM
* [dump](dump.md) - dump the loaded classes in byte code to the specified location
* [classloader](classloader.md) - check the inheritance structure, urls, class loading info for the specified class; using classloader to get the url of the resource e.g. `java/lang/String.class`
##### Can commands such as trace/watch enhance the classes in jdk?
By default, classes beginning with `java.` are filtered out, but they can be turned on:
```bash
options unsafe true
```
See more at [options](options.md)
##### How to view the result in `json` format
```bash
@ -24,3 +35,29 @@ No.
##### Can arthas view the value of a variable in memory?
No. But you can use some tricks to intercept the object with the `tt` command, or fetch it from a static method.
##### How to filter method with the same name?
You can used all variables in [fundamental fields in expressions](advice-class.md) for the condition express to filter method with the same name, you can use the number of parameters `params.length ==1`,parameter type `params[0] instanceof java.lang.Integer`,return value type `returnObj instanceof java.util.List` and so on in one or more combinations as condition express.
You can use `-v` to view the condition express result [https://github.com/alibaba/arthas/issues/1348](https://github.com/alibaba/arthas/issues/1348)
##### java.lang.ClassFormatError: null, skywalking arthas compatible use
When error log appear `java.lang.ClassFormatError: null`, it is usually modified by other bytecode tools that are not compatible with arthas modified bytecode.
For example: use skywalking V8.1.0 below [cannot trace, watch classes enhanced by skywalking agent](https://github.com/alibaba/arthas/issues/1141), V8.1.0 or above is compatible, refer to skywalking configuration for more details. [skywalking compatible with other javaagent bytecode processing](https://github.com/apache/skywalking/blob/v8.1.0/docs/en/FAQ/Compatible-with-other-javaagent-bytecode-processing.md).
By default, the decompile result will have the `ClassLoader` information. With the `--source-only` option, you can print only the source code. Conveniently used with the [mc](mc.md)/[redefine](redefine.md) commands.
By default, the decompile result will have the `ClassLoader` information. With the `--source-only` option, you can print only the source code. Conveniently used with the [mc](mc.md)/[retransform](retransform.md) commands.
@ -30,6 +30,6 @@ The output directory can be specified with the `-d` option:
mc -d /tmp/output /tmp/ClassA.java /tmp/ClassB.java
```
After compiling the `.class` file, you can use the [redefine](redefine.md) command to re-define the loaded classes in JVM.
After compiling the `.class` file, you can use the [retransform](retransform.md) command to re-define the loaded classes in JVM.
> Note that the mc command may fail. If the compilation fails, the `.class` file can be compiled locally and uploaded to the server. Refer to the [redefine](redefine.md) command description for details.
> Note that the mc command may fail. If the compilation fails, the `.class` file can be compiled locally and uploaded to the server. Refer to the [retransform](retransform.md) command description for details.
> Recommend to use the [retransform](retransform.md) command.
* The class of `redefine` cannot modify, add or delete the field and method of the class, including method parameters, method names and return values.
* If `mc` fails, you can compile the class file in the local development environment, upload it to the target system, and use `redefine` to hot load the class.
Since Arthas stores the context of the call, you can even *replay* the method calling afterwards with extra option `-p` to replay the issue for advanced troubleshooting, option `--replay-times`
define the replay execution times, option `--replay-interval` define the interval(unit in ms,with default value 1000) of replays
@ -152,13 +152,50 @@ Time fragment[1004] successfully replayed.
Affect(row-cnt:1) cost in 14 ms.
```
#### Watch express
`-w, --watch-express` watch the time fragment by ognl express.
* You can used all variables in [fundamental fields in expressions](advice-class.md) for the watch express。
<li><p><aclass="reference internal"href="base64.html"><spanclass="doc">base64</span></a> - Encode and decode using Base64 representation.</p></li>
<li><p><aclass="reference internal"href="tee.html"><spanclass="doc">tee</span></a> - Copies standard input to standard output, making a copy in zero or more files.</p></li>
<li><p><aclass="reference internal"href="pwd.html"><spanclass="doc">pwd</span></a> - Return working directory name</p></li>
<li><p>session - display current session information</p></li>
@ -259,6 +260,7 @@
<li><p><aclass="reference internal"href="sm.html"><spanclass="doc">sm</span></a> - check methods info for the loaded classes</p></li>
<li><p><aclass="reference internal"href="jad.html"><spanclass="doc">jad</span></a> - decompile the specified loaded classes</p></li>
<li><p><aclass="reference internal"href="mc.html"><spanclass="doc">mc</span></a> - Memory compiler, compiles <codeclass="docutils literal notranslate"><spanclass="pre">.java</span></code> files into <codeclass="docutils literal notranslate"><spanclass="pre">.class</span></code> files in memory</p></li>
<li><p><aclass="reference internal"href="retransform.html"><spanclass="doc">retransform</span></a> - load external <codeclass="docutils literal notranslate"><spanclass="pre">*.class</span></code> files and retransform it into JVM</p></li>
<li><p><aclass="reference internal"href="redefine.html"><spanclass="doc">redefine</span></a> - load external <codeclass="docutils literal notranslate"><spanclass="pre">*.class</span></code> files and re-define it into JVM</p></li>
<li><p><aclass="reference internal"href="dump.html"><spanclass="doc">dump</span></a> - dump the loaded classes in byte code to the specified location</p></li>
<li><p><aclass="reference internal"href="classloader.html"><spanclass="doc">classloader</span></a> - check the inheritance structure, urls, class loading info for the specified class; using classloader to get the url of the resource e.g. <codeclass="docutils literal notranslate"><spanclass="pre">java/lang/String.class</span></code></p></li>
<liclass="toctree-l2"><aclass="reference internal"href="#how-much-impact-does-arthas-attach-have-on-the-performance-of-the-original-process">How much impact does Arthas attach have on the performance of the original process?</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="#can-commands-such-as-trace-watch-enhance-the-classes-in-jdk">Can commands such as trace/watch enhance the classes in jdk?</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="#how-to-view-the-result-in-json-format">How to view the result in <codeclass="docutils literal notranslate"><spanclass="pre">json</span></code> format</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="#can-arthas-view-the-value-of-a-variable-in-memory">Can arthas view the value of a variable in memory?</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="#how-to-filter-method-with-the-same-name">How to filter method with the same name?</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="#how-to-watch-or-trace-constructor">How to watch or trace constructor?</a></li>
<liclass="toctree-l1"><aclass="reference external"href="https://github.com/alibaba/arthas">Star me at GitHub</a></li>
@ -198,6 +202,13 @@
<h2>How much impact does Arthas attach have on the performance of the original process?<aclass="headerlink"href="#how-much-impact-does-arthas-attach-have-on-the-performance-of-the-original-process"title="Permalink to this headline">¶</a></h2>
<h2>Can commands such as trace/watch enhance the classes in jdk?<aclass="headerlink"href="#can-commands-such-as-trace-watch-enhance-the-classes-in-jdk"title="Permalink to this headline">¶</a></h2>
<p>By default, classes beginning with <codeclass="docutils literal notranslate"><spanclass="pre">java.</span></code> are filtered out, but they can be turned on:</p>
<h2>How to view the result in <codeclass="docutils literal notranslate"><spanclass="pre">json</span></code> format<aclass="headerlink"href="#how-to-view-the-result-in-json-format"title="Permalink to this headline">¶</a></h2>
<h2>Can arthas view the value of a variable in memory?<aclass="headerlink"href="#can-arthas-view-the-value-of-a-variable-in-memory"title="Permalink to this headline">¶</a></h2>
<p>No. But you can use some tricks to intercept the object with the <codeclass="docutils literal notranslate"><spanclass="pre">tt</span></code> command, or fetch it from a static method.</p>
<h2>How to filter method with the same name?<aclass="headerlink"href="#how-to-filter-method-with-the-same-name"title="Permalink to this headline">¶</a></h2>
<p>You can used all variables in <aclass="reference internal"href="advice-class.html"><spanclass="doc">fundamental fields in expressions</span></a> for the condition express to filter method with the same name, you can use the number of parameters <codeclass="docutils literal notranslate"><spanclass="pre">params.length</span><spanclass="pre">==1</span></code>,parameter type <codeclass="docutils literal notranslate"><spanclass="pre">params[0]</span><spanclass="pre">instanceof</span><spanclass="pre">java.lang.Integer</span></code>,return value type <codeclass="docutils literal notranslate"><spanclass="pre">returnObj</span><spanclass="pre">instanceof</span><spanclass="pre">java.util.List</span></code> and so on in one or more combinations as condition express.</p>
<p>You can use <codeclass="docutils literal notranslate"><spanclass="pre">-v</span></code> to view the condition express result <aclass="reference external"href="https://github.com/alibaba/arthas/issues/1348">https://github.com/alibaba/arthas/issues/1348</a></p>
<h2>java.lang.ClassFormatError: null, skywalking arthas compatible use<aclass="headerlink"href="#java-lang-classformaterror-null-skywalking-arthas-compatible-use"title="Permalink to this headline">¶</a></h2>
<p>When error log appear <codeclass="docutils literal notranslate"><spanclass="pre">java.lang.ClassFormatError:</span><spanclass="pre">null</span></code>, it is usually modified by other bytecode tools that are not compatible with arthas modified bytecode.</p>
<p>For example: use skywalking V8.1.0 below <aclass="reference external"href="https://github.com/alibaba/arthas/issues/1141">cannot trace, watch classes enhanced by skywalking agent</a>, V8.1.0 or above is compatible, refer to skywalking configuration for more details. <aclass="reference external"href="https://github.com/apache/skywalking/blob/v8.1.0/docs/en/FAQ/Compatible-with-other-javaagent-bytecode-processing">skywalking compatible with other javaagent bytecode processing</a>.</p>
<h3>Print source only<aclass="headerlink"href="#print-source-only"title="Permalink to this headline">¶</a></h3>
<p>By default, the decompile result will have the <codeclass="docutils literal notranslate"><spanclass="pre">ClassLoader</span></code> information. With the <codeclass="docutils literal notranslate"><spanclass="pre">--source-only</span></code> option, you can print only the source code. Conveniently used with the <aclass="reference internal"href="mc.html"><spanclass="doc">mc</span></a>/<aclass="reference internal"href="redefine.html"><spanclass="doc">redefine</span></a> commands.</p>
<p>By default, the decompile result will have the <codeclass="docutils literal notranslate"><spanclass="pre">ClassLoader</span></code> information. With the <codeclass="docutils literal notranslate"><spanclass="pre">--source-only</span></code> option, you can print only the source code. Conveniently used with the <aclass="reference internal"href="mc.html"><spanclass="doc">mc</span></a>/<aclass="reference internal"href="retransform.html"><spanclass="doc">retransform</span></a> commands.</p>
<p>After compiling the <codeclass="docutils literal notranslate"><spanclass="pre">.class</span></code> file, you can use the <aclass="reference internal"href="redefine.html"><spanclass="doc">redefine</span></a> command to re-define the loaded classes in JVM.</p>
<p>After compiling the <codeclass="docutils literal notranslate"><spanclass="pre">.class</span></code> file, you can use the <aclass="reference internal"href="retransform.html"><spanclass="doc">retransform</span></a> command to re-define the loaded classes in JVM.</p>
<blockquote>
<div><p>Note that the mc command may fail. If the compilation fails, the <codeclass="docutils literal notranslate"><spanclass="pre">.class</span></code> file can be compiled locally and uploaded to the server. Refer to the <aclass="reference internal"href="redefine.html"><spanclass="doc">redefine</span></a> command description for details.</p>
<div><p>Note that the mc command may fail. If the compilation fails, the <codeclass="docutils literal notranslate"><spanclass="pre">.class</span></code> file can be compiled locally and uploaded to the server. Refer to the <aclass="reference internal"href="retransform.html"><spanclass="doc">retransform</span></a> command description for details.</p>
</div></blockquote>
</div>
@ -253,7 +255,7 @@ Affect(row-cnt:1) cost in 346 ms</pre></div>
<div><p>Load the external <codeclass="docutils literal notranslate"><spanclass="pre">*.class</span></code> files to re-define the loaded classes in JVM.</p>
<h2>Frequently asked questions<aclass="headerlink"href="#frequently-asked-questions"title="Permalink to this headline">¶</a></h2>
<blockquote>
<div><p>Recommend to use the <aclass="reference internal"href="retransform.html"><spanclass="doc">retransform</span></a> command.</p>
</div></blockquote>
<ulclass="simple">
<li><p>The class of <codeclass="docutils literal notranslate"><spanclass="pre">redefine</span></code> cannot modify, add or delete the field and method of the class, including method parameters, method names and return values.</p></li>
<li><p>If <codeclass="docutils literal notranslate"><spanclass="pre">mc</span></code> fails, you can compile the class file in the local development environment, upload it to the target system, and use <codeclass="docutils literal notranslate"><spanclass="pre">redefine</span></code> to hot load the class.</p></li>
@ -270,10 +278,6 @@ The reason is that in the JDK <code class="docutils literal notranslate"><span c
@ -381,9 +384,8 @@ Affect(row-cnt:6) cost in 607 ms.</pre></div>
Affect(row-cnt:1) cost in 11 ms.</pre></div>
</div>
</div>
</div>
<divclass="section"id="replay-record">
<h2>Replay record<aclass="headerlink"href="#replay-record"title="Permalink to this headline">¶</a></h2>
<h3>Replay record<aclass="headerlink"href="#replay-record"title="Permalink to this headline">¶</a></h3>
<p>Since Arthas stores the context of the call, you can even <em>replay</em> the method calling afterwards with extra option <codeclass="docutils literal notranslate"><spanclass="pre">-p</span></code> to replay the issue for advanced troubleshooting, option <codeclass="docutils literal notranslate"><spanclass="pre">--replay-times</span></code>
define the replay execution times, option <codeclass="docutils literal notranslate"><spanclass="pre">--replay-interval</span></code> define the interval(unit in ms,with default value 1000) of replays</p>
<h3>Watch express<aclass="headerlink"href="#watch-express"title="Permalink to this headline">¶</a></h3>
<p><codeclass="docutils literal notranslate"><spanclass="pre">-w,</span><spanclass="pre">--watch-express</span></code> watch the time fragment by ognl express.</p>
<ulclass="simple">
<li><p>You can used all variables in <aclass="reference internal"href="advice-class.html"><spanclass="doc">fundamental fields in expressions</span></a> for the watch express。</p></li>
</ul>
<divclass="highlight-bash notranslate"><divclass="highlight hljs"><preclass="bash">[arthas@10718]$ tt -t demo.MathGame run -n 5
<p>Note that <codeclass="docutils literal notranslate"><spanclass="pre">com.taobao.arthas.core.advisor.Advice#getLoader</span></code> is used here, and that it is better to use the exact <codeclass="docutils literal notranslate"><spanclass="pre">classloader</span></code><aclass="reference internal"href="ognl.html"><spanclass="doc">ognl</span></a>.</p>
<p>Advanced usage <aclass="reference external"href="https://github.com/alibaba/arthas/issues/482">get spring context to call the bean method</a></p>
<p>F.Y.I</p>
<ol>
<li><p><strong>Loss</strong> of the <codeclass="docutils literal notranslate"><spanclass="pre">ThreadLocal</span></code></p>
@ -414,6 +447,7 @@ Affect(row-cnt:1) cost in 14 ms.</pre></div>
<liclass="toctree-l4"><aclass="reference internal"href="#filter-by-time-cost">Filter by time cost</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#check-the-field-of-the-target-object">Check the field of the target object</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#get-a-static-field-and-calling-a-static-method">Get a static field and calling a static method</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#exclude-the-specified-class">Exclude the specified class</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#does-not-match-subclass">Does not match subclass</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#use-the-v-parameter-to-print-more-information">Use the -v parameter to print more information</a></li>
<h3>Get a static field and calling a static method<aclass="headerlink"href="#get-a-static-field-and-calling-a-static-method"title="Permalink to this headline">¶</a></h3>
<li><p>Note that here you use <codeclass="docutils literal notranslate"><spanclass="pre">Thread.currentThread().getContextClassLoader()</span></code> to load, and it is better to use the exact <codeclass="docutils literal notranslate"><spanclass="pre">classloader</span></code><aclass="reference internal"href="ognl.html"><spanclass="doc">ognl</span></a>.</p></li>