You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
arthas/tutorials/katacoda/command-dump-en/dump.md

69 lines
2.5 KiB
Markdown

> Dump the bytecode for the particular classes to the specified directory.
### Options
|Name|Specification|
|---:|:---|
|*class-pattern*|class name pattern|
|`[c:]`|hashcode of the [class loader](classloader.md) that loaded the target class|
|`[classLoaderClass:]`| The class name of the ClassLoader that executes the expression. |
|`[d:]`|set the destination directory for class files|
|`[E]`|turn on regex match, the default behavior is wild card match|
### Usage
`dump java.lang.String`{{execute T2}}
```bash
$ dump java.lang.String
HASHCODE CLASSLOADER LOCATION
null /Users/admin/logs/arthas/classdump/java/lang/String.class
Affect(row-cnt:1) cost in 119 ms.
```
`dump demo.*`{{execute T2}}
```bash
$ dump demo.*
HASHCODE CLASSLOADER LOCATION
3d4eac69 +-sun.misc.Launcher$AppClassLoader@3d4eac69 /Users/admin/logs/arthas/classdump/sun.misc.Launcher$AppClassLoader-3d4eac69/demo/MathGame.class
+-sun.misc.Launcher$ExtClassLoader@66350f69
Affect(row-cnt:1) cost in 39 ms.
```
`dump -d /tmp/output java.lang.String`{{execute T2}}
```bash
$ dump
HASHCODE CLASSLOADER LOCATION
null /tmp/output/java/lang/String.class
Affect(row-cnt:1) cost in 138 ms.
```
* Specify classLoader
Note that the hashcode changes, you need to check the current ClassLoader information first, and extract the hashcode corresponding to the ClassLoader.
if you use`-c`, you have to manually type hashcode by `-c <hashcode>`.
```bash
$ dump -c 3d4eac69 demo.*
```
For classloader with only one instance, it can be specified by `--classLoaderClass` using class name, which is more convenient to use.
`dump --classLoaderClass sun.misc.Launcher$AppClassLoader demo.*`{{execute T2}}
```bash
$ dump --classLoaderClass sun.misc.Launcher$AppClassLoader demo.*
HASHCODE CLASSLOADER LOCATION
3d4eac69 +-sun.misc.Launcher$AppClassLoader@3d4eac69 /Users/admin/logs/arthas/classdump/sun.misc.Launcher$AppClassLoader-3d4eac69/demo/MathGame.class
+-sun.misc.Launcher$ExtClassLoader@66350f69
Affect(row-cnt:1) cost in 39 ms.
```
* PS: Here the classLoaderClass in java 8 is sun.misc.Launcher$AppClassLoader, while in java 11 it's jdk.internal.loader.ClassLoaders$AppClassLoader. Currently katacoda using java 8.
The value of `--classloaderclass` is the class name of classloader. It can only work when it matches a unique classloader instance. The purpose is to facilitate the input of general commands. However, `-c <hashcode>` is dynamic.