mirror of
https://gitee.com/arthas/arthas.git
synced 2024-11-30 11:17:39 +08:00
update redefine doc
This commit is contained in:
parent
7218eb6d17
commit
9cf0ceef7e
@ -17,7 +17,38 @@ Reference: [Instrumentation#redefineClasses](https://docs.oracle.com/javase/8/do
|
||||
|
||||
### Usage
|
||||
|
||||
```
|
||||
```bash
|
||||
redefine -p /tmp/Test.class
|
||||
redefine -c 327a647b -p /tmp/Test.class /tmp/Test$Inner.class
|
||||
```
|
||||
|
||||
### Restrictions of the redefine command
|
||||
|
||||
* New field/method is not allowed
|
||||
* The function that is running, no exit can not take effect, such as the new `System.out.println` added below, only the `run()` function will take effect.
|
||||
|
||||
```java
|
||||
public class MathGame {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
MathGame game = new MathGame();
|
||||
while (true) {
|
||||
game.run();
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
// This doesn't work because the code keeps running in while
|
||||
System.out.println("in loop");
|
||||
}
|
||||
}
|
||||
|
||||
public void run() throws InterruptedException {
|
||||
// This works because the run() function ends completely every time
|
||||
System.out.println("call run()");
|
||||
try {
|
||||
int number = random.nextInt();
|
||||
List<Integer> primeFactors = primeFactors(number);
|
||||
print(number, primeFactors);
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println(String.format("illegalArgumentCount:%3d, ", illegalArgumentCount) + e.getMessage());
|
||||
}
|
||||
}
|
||||
```
|
@ -18,7 +18,38 @@ redefine
|
||||
|
||||
### 使用参考
|
||||
|
||||
```
|
||||
```bash
|
||||
redefine -p /tmp/Test.class
|
||||
redefine -c 327a647b -p /tmp/Test.class /tmp/Test\$Inner.class
|
||||
```
|
||||
|
||||
### redefine的限制
|
||||
|
||||
* 不允许新增加field/method
|
||||
* 正在跑的函数,没有退出不能生效,比如下面新增加的`System.out.println`,只有`run()`函数里的会生效
|
||||
|
||||
```java
|
||||
public class MathGame {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
MathGame game = new MathGame();
|
||||
while (true) {
|
||||
game.run();
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
// 这个不生效,因为代码一直跑在 while里
|
||||
System.out.println("in loop");
|
||||
}
|
||||
}
|
||||
|
||||
public void run() throws InterruptedException {
|
||||
// 这个生效,因为run()函数每次都可以完整结束
|
||||
System.out.println("call run()");
|
||||
try {
|
||||
int number = random.nextInt();
|
||||
List<Integer> primeFactors = primeFactors(number);
|
||||
print(number, primeFactors);
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println(String.format("illegalArgumentCount:%3d, ", illegalArgumentCount) + e.getMessage());
|
||||
}
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue
Block a user