Hi, Thanks for investing. I want to be clear about 2 things.
> Jvm can not change the class structure when a class has already been loaded. Yes, this rule always exists. So, the instrumentation target can't be used in the agent core booting stage. > If we just want to make a aspect for ThreadPoolExecutor#execute method, we don't need to add a field. If you don't add a field, this class isn't `EnhancedInstance`. All interceptors would not work. About what we can do, I still think unless this wouldn't be used in the core services, we don't have many options. In my mind, I still don't like the idea of `ThreadPoolExecutor` instrumentation, it is really widely used, and manipulating it is a high-risk operation. Sheng Wu 吴晟 Twitter, wusheng1108 Li BingLong(智能平台) <[email protected]> 于2021年1月23日周六 下午1:15写道: > After a few days learning byte buddy, I finally know why we can not > instrument ThreadPoolExecutor when we have used it in the agent. > > See the following code that byte buddy generates: > > public class ThreadPoolExecutor extends AbstractExecutorService implements > EnhancedInstance { > //... > private volatile Object _$EnhancedClassField_ws; > //... > } > > The agent add a field in the ThreadPoolExecutor class. > > When config is AgentBuilder.RedefinitionStrategy.RETRANSFORMATION and > disableClassFormatChanges, we will see the error: > > java.lang.IllegalStateException: Cannot define field for frozen type: > class java.util.concurrent.ThreadPoolExecutor > > Now the problem is clear. > Jvm can not change the class structure when a class has already been > loaded. > > If we just want to make a aspect for ThreadPoolExecutor#execute method, we > don't need to add a field. > So if we can do something here? > > > > >
