Change an already loaded class using a Java agent?

I'm currently trying to modify the bodies of methods that are in classes already loaded by the JVM . I know that the JVM does not actually allow you to change the definition of classes already loaded. But my research led me to implementations like the JRebel API or the Java Instrumentation API, both using the agent approach. I know how to do this right before the class boots on behalf of Javassist. But given, for example, JRebel in an EJB environment where class definitions are loaded when the application starts, should the bytecode be modified on JVM-loaded classes?

+4
source share
2 answers

Well, you find out that the Instrumentation API exists, and it offers class overrides as an operation. So, it's time to rethink the original premise "The JVM does not really allow you to change the definition of classes already loaded."

You should notice that

  • as the links show, the Instrumentation API is part of the standard API
  • support for class overrides, however, is optional. You may ask if the current JVM supports this feature.
  • it may be limited so as not to support each class; you may ask if this is possible for a particular class
  • Even if supported, changes may be limited to include documentation :

    , . , , . .

  • , ; ,

, Instrumentation ..

, EJB, , ClassLoader, , .

Java <ClassLoader, Qualified Name>, ...

+5

, API- (. @Holger). , , . , javadoc :

" , .

- ... Java.

+2

Source: https://habr.com/ru/post/1584856/


All Articles