1 Reply Latest reply on Jan 11, 2010 10:52 PM by megalodon

    method instrumentation approaches - which is best?

      Hello All,

       

      I am sort of new to Javassist and have a design question which has probably been already discussed. I couldn't search and look for the discussion though due to no search facility as far as I could see. Anyway, to state my question,

       

      I don't know which instrumentation methods to choose for which situations when it comes to instrumenting many methods in an application during load time. I have 2 approaches in mind:

      1. Performing instrumentations directly in the methods using functions like insertBefore(), insertAfter(), addCatch() etc.
      2. Renaming name of original method (say, original name) to some unique name (possible conflict issues here), creating a dummy method with the original name, perfoming all insrumentation in dummy method and calling the original method from the dummy.

       

      Approach 1 seems to be easier to implement and would perhaps use less resources - no new to create new methods for every instrumented method, no need to make 2 method calls for each original method call and no need for the JVM to store additional method information for the dummy method. We need to create local variables to store any state between insertBefore() and insertAfter() since we cannot access existing local variables and it is not wise to use instance variables for load time instrumentation.

       

      Would love to hear your opinions. Thanks.

       

      -Arvind