6

While debugging Spring-driven AspectJ LTW (using -verbose:class), I have noticed that one of the classes to be advised is being loaded by the class loader before Spring establishes the connection to the AspectJ weaver.

Considering that Java postpones the loading of a class until it's not possible to delay it more, there must be a reason why that specific class is being loaded so soon.

Is it possible to obtain the "references stack" that provokes the loading of a class to the JVM in a specific moment (so I can try to postpone its usage)? If so, how can I do it?

1
  • Could be a good idea to you check your classpath which might contain the class and is loaded before actually spring gets the oppurtunity to advise.
    – Shailendra
    Jul 11, 2013 at 10:37

1 Answer 1

2

As you already noted, Java (or actually the VM, that runs your code) loads and resolves classes at the time, they are needed. This normally also leads to a knock-on effect for several classes. There is obviously a high chance, that the classes that do not contain the woven code, are loaded prior to the Spring classes.

However, the Java HotSpot VM (the typical VM, when Oracle's Java is installed) can be configured in many ways when being started. One of those options is "-XX:+TraceClassLoading" (note the plus sign; the above mentioned link unfortunately documents a minus sign for this option). There is also another option, that traces the loaded classes in reference order.

With that, you should be able to narrow the problem down. If not, some example code might help. Although I fear, that that would be a bit too large.

7
  • 1
    The - means to disable the option, the + to enable it, it's shown there because it's the default value.
    – Jacopofar
    Jul 11, 2013 at 12:34
  • You are right, but how many times you just copy/paste the option and wonder, why it does not show any effect? This happens to me regularly. :-) Jul 11, 2013 at 12:46
  • Thanks for your suggestion, but that modifier just gives me the same output as -verbose:class, i.e. printing when a class is loaded. This is useful to identify linear and simple class dependencies (by looking at the previous loaded classes), but not so much for complex ones.
    – andresp
    Jul 11, 2013 at 13:35
  • Hmmm ... I fear, then it's nearly impossible to narrow down your problem. Are you able to make a minimal example showing your problem? Or is the project so big, that you are not able to extract the classes of interest? Maybe you can show us the class, which does not get "aspected", and maybe another class, which gets "aspected". Jul 12, 2013 at 12:06
  • It's effectively too big a project to be able to extract the relevant classes (that's what I am trying to do, by finding the origin of the class load). I think giving you the class that is not being weaved wouldn't make any difference as it's not a problem with the class itself. It is correctly weaved when I use pure AspectJ LTW with aspectjweaver.jar as the java agent, so the AOP configuration is right. Anyway, what I'm trying to weave is Jetty's HttpClient class in order to log HTTP requests.
    – andresp
    Jul 13, 2013 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.