3

I used java.lang.instrument.Instrumentation#redefineClasses() to redefine existing classes. Sometimes, I need to redefine several classes.

If I redefine classes one by one, I will know which ones were successful and which ones failed.

But is it better to put classes redefined in an array together to get more correctness?

Bilesh Ganguly
  • 3,792
  • 3
  • 36
  • 58
wang ming
  • 199
  • 2
  • 9
  • Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. – abarisone Aug 30 '16 at 14:10

2 Answers2

1

If I redefine class one by one, I will know which is success, which is failed.

True.

But is it better to put classes redefined in an array together to get more correctness?

I didn't get what you meant by more correctness! But, anyways from my understanding, using a set(array) of classes can be particularly helpful in the case where there is an interdependence of one class on other class. So, in this case you can re-define both classes by passing them in this method.


Also, Java Documentation of Interface Instrumentation says :

This method is used to replace the definition of a class without reference to the existing class file bytes, as one might do when recompiling from source for fix-and-continue debugging.

...

This method operates on a set in order to allow interdependent changes to more than one class at the same time (a redefinition of class A can require a redefinition of class B).

But, do keep remember :

If this method throws an exception, no classes have been redefined.

Am_I_Helpful
  • 18,735
  • 7
  • 49
  • 73
1

It is much more performant to instrument classes in a batch compared to passing each class individually.

The JVM needs to halt the application for applying the redefinition which is a rather costly operation so it is worth grouping up.

Also, grouping allows for interdependent changes of classes.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192