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?
Note: The ClassLoader Delegation Hierarchy Model always functions in the order Application ClassLoader->Extension ClassLoader->Bootstrap ClassLoader. The Bootstrap ClassLoader is always given the higher priority, next is Extension ClassLoader and then Application ClassLoader.
Java Classloaders are hierarchical in nature. Whenever JVM requests to load a class, each classloader first delegates the request to its parent. If the parent fails to find the class to be loaded, then classloader itself tries to load the class using the java.
Class loaders are responsible for loading Java classes dynamically to the JVM (Java Virtual Machine) during runtime. They're also part of the JRE (Java Runtime Environment). Therefore, the JVM doesn't need to know about the underlying files or file systems in order to run Java programs thanks to class loaders.
Java ClassLoader is used to load the classes at run time. In other words, JVM performs the linking process at runtime. Classes are loaded into the JVM according to need. If a loaded class depends on another class, that class is loaded as well. When we request to load a class, it delegates the class to its parent.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With