Get a hierarchy of Java class loading links

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

Given that Java defers loading the class until it can be delayed more, there must be a reason why this particular class loads so soon.

Is it possible to get a "link stack" that provokes the loading of the class in the JVM at a certain point (so that I can try to delay its use)? If so, how can I do this?

+6
source share
1 answer

As you already noted, Java (or actually the virtual machine that runs your code) loads and resolves classes at the time they are needed. This usually also results in a knock effect for several classes. Obviously, there is a high probability that classes that do not contain woven code are loaded before the Spring classes.

However, the HotSpot Java virtual machine (a typical virtual machine when Oracle Java is installed) can be configured in many ways at startup. One of these options is "- XX: + TraceClassLoading" (note the plus sign, the specified link, unfortunately, documents the minus sign for this option). There is another parameter that tracks loaded classes in referential order.

With this, you can narrow down the problem. Otherwise, sample code might be helpful. Although I'm afraid it will be too big.

+2
source

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


All Articles