4 Replies Latest reply on May 24, 2005 2:35 AM by oberon777

    Instrumenting JDK classes

    oberon777

      I am using JBOSS AOP in a standalone mode using the org.jboss.aop.standalone.SystemClassLoader approach.

      However, I am having trouble instrumenting system classes such as java.lang.Class, etc. Is there a way around that? What I really want is a way to add pointcuts to dump parameters of calls to java.lang.Class.forName(String).

      Thanks,
      -Ben

        • 1. Re: Instrumenting JDK classes
          kabirkhan

          We do not allow for bytecode modification of java system classes. If you use execution/field/get/set they all modify the target class.

          You can use caller pointcuts, which do not modify the target class only the caller class. So you would need to use something like the following for your pointcut expression:

          call(java.lang.Class java.lang.Class->forName(java.lang.String))
          


          More info about this here:
          http://docs.jboss.org/aop/1.1/aspect-framework/examples/caller/caller.html



          • 2. Re: Instrumenting JDK classes
            oberon777

            Thank you very much for this link -- in fact it does almost everything I need!

            The only thing missing is the ability to examine parameters and return values of calls at runtime. I.e. suppose I am interested in a call to Class.forName. I'd like to print the parameter string as well as the return value object. Calls to invocation.getArguments() only give me the argument *types*, it seems.

            Thanks much,
            -Ben

            • 3. Re: Instrumenting JDK classes
              kabirkhan

              Invocation.getArguments() should get you the actual parameters? Please check again and let me know if there is a problem.

              The value of a return value can be done by examining the return of invocation.invokeNext() in you advice before returning it.

              • 4. Re: Instrumenting JDK classes
                oberon777

                It's working now. Thanks a bunch.