Commit 267aba8
authored
Improve bytebuddy class enhance for retransform classes (#561)
* SWAuxiliaryTypeNamingStrategy
Auxiliary type name pattern: <origin_class_name>$<name_trait>$auxiliary$<auxiliary_type_instance_hash>
* DelegateNamingResolver
Interceptor delegate field name pattern: <name_trait>$delegate$<class_name_hash>$<plugin_define_hash>$<intercept_point_hash>
* SWMethodNameTransformer
Renamed origin method pattern: <name_trait>$original$<method_name>$<method_description_hash>
* SWImplementationContextFactory
Method cache value field pattern: cachedValue$<name_trait>$<origin_class_name_hash>$<field_value_hash>
Accessor method name pattern: <renamed_origin_method>$accessor$<name_trait>$<origin_class_name_hash>
Here is an example of manipulated enhanced class with new naming policies of auxiliary classes, fields, and methods
```java
import sample.mybatis.controller.HotelController$sw$auxiliary$19cja42;
import sample.mybatis.controller.HotelController$sw$auxiliary$p257su0;
import sample.mybatis.domain.Hotel;
import sample.mybatis.service.HotelService;
@RequestMapping(value={"/hotel"})
@RestController
public class HotelController
implements EnhancedInstance {
@Autowired
@lazy
private HotelService hotelService;
private volatile Object _$EnhancedClassField_ws;
// Interceptor delegate fields
public static volatile /* synthetic */ InstMethodsInter sw$delegate$td03673$ain2do0$8im5jm1;
public static volatile /* synthetic */ InstMethodsInter sw$delegate$td03673$ain2do0$edkmf61;
public static volatile /* synthetic */ ConstructorInter sw$delegate$td03673$ain2do0$qs9unv1;
public static volatile /* synthetic */ InstMethodsInter sw$delegate$td03673$fl4lnk1$m3ia3a2;
public static volatile /* synthetic */ InstMethodsInter sw$delegate$td03673$fl4lnk1$sufrvp1;
public static volatile /* synthetic */ ConstructorInter sw$delegate$td03673$fl4lnk1$cteu7s1;
// Origin method cache value field
private static final /* synthetic */ Method cachedValue$sw$td03673$g5sobj1;
public HotelController() {
this(null);
sw$delegate$td03673$ain2do0$qs9unv1.intercept(this, new Object[0]);
}
private /* synthetic */ HotelController(sw.auxiliary.p257su0 p257su02) {
}
@GetMapping(value={"city/{cityId}"})
public Hotel selectByCityId(@PathVariable(value="cityId") int n) {
// call interceptor with auxiliary type and parameters and origin method object
return (Hotel)sw$delegate$td03673$ain2do0$8im5jm1.intercept(this, new Object[]{n}, new HotelController$sw$auxiliary$19cja42(this, n), cachedValue$sw$td03673$g5sobj1);
}
// Renamed origin method
private /* synthetic */ Hotel sw$origin$selectByCityId$a8458p3(int cityId) {
/*22*/ return this.hotelService.selectByCityId(cityId);
}
// Accessor of renamed origin method, calling from auxiliary type
final /* synthetic */ Hotel sw$origin$selectByCityId$a8458p3$accessor$sw$td03673(int n) {
// Calling renamed origin method
return this.sw$origin$selectByCityId$a8458p3(n);
}
@OverRide
public Object getSkyWalkingDynamicField() {
return this._$EnhancedClassField_ws;
}
@OverRide
public void setSkyWalkingDynamicField(Object object) {
this._$EnhancedClassField_ws = object;
}
static {
ClassLoader.getSystemClassLoader().loadClass("org.apache.skywalking.apm.dependencies.net.bytebuddy.dynamic.Nexus").getMethod("initialize", Class.class, Integer.TYPE).invoke(null, HotelController.class, -1072476370);
// Method object
cachedValue$sw$td03673$g5sobj1 = HotelController.class.getMethod("selectByCityId", Integer.TYPE);
}
}
```
Auxiliary type of Constructor :
```java
class HotelController$sw$auxiliary$p257su0 {
}
```
Auxiliary type of `selectByCityId` method:
```java
class HotelController$sw$auxiliary$19cja42
implements Runnable,
Callable {
private HotelController argument0;
private int argument1;
public Object call() throws Exception {
return this.argument0.sw$origin$selectByCityId$a8458p3$accessor$sw$td03673(this.argument1);
}
@OverRide
public void run() {
this.argument0.sw$origin$selectByCityId$a8458p3$accessor$sw$td03673(this.argument1);
}
HotelController$sw$auxiliary$19cja42(HotelController hotelController, int n) {
this.argument0 = hotelController;
this.argument1 = n;
}
}
```1 parent b72e984 commit 267aba8
57 files changed
Lines changed: 2313 additions & 258 deletions
File tree
- apm-sniffer
- apm-agent-core/src
- main/java/org/apache/skywalking/apm/agent/core
- conf
- plugin
- bytebuddy
- interceptor
- enhance
- v2
- v2
- match
- test/java/org/apache/skywalking/apm/agent/core/bytebuddy
- apm-agent
- src/main/java/org/apache/skywalking/apm/agent
- apm-sdk-plugin/finagle-6.25.x-plugin
- bytebuddy-patch
- src
- main/java
- net/bytebuddy
- agent/builder
- implementation
- org/apache/skywalking/apm/agent/bytebuddy
- test/java/org/apache/skywalking/apm/agent/bytebuddy
- biz
- cases
- config
- docs/en/setup/service-agent/java-agent
- test/plugin/scenarios
- retransform-class-scenario
- bin
- retransform-class-tomcat-scenario
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
Lines changed: 0 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
| |||
110 | 109 | | |
111 | 110 | | |
112 | 111 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | 112 | | |
127 | 113 | | |
128 | 114 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
35 | 41 | | |
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
58 | 69 | | |
59 | 70 | | |
60 | 71 | | |
| |||
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
71 | 83 | | |
72 | 84 | | |
73 | 85 | | |
| |||
Lines changed: 0 additions & 195 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
56 | 67 | | |
57 | 68 | | |
58 | 69 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
44 | 55 | | |
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
45 | 56 | | |
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
45 | 56 | | |
0 commit comments