   [java] Java Class Usage
  I'm working with a massive Java project (18+ MB of source code), in which about 40% of the classes are deprecated or legacy, and not used at any time during runtime. Problem is, they're mixed all up in the rest of the classes.Is there any way to get the Java VM to dump a list, preferably just newline-delimited, of all classes instantiated, and maybe what classpath root element that class was selected from? If I can get a list of used classes, then I can create the list of unused ones.Any suggestions?   
  Due to nature of Java, this isn't a good idea. Classes get loaded on demand. For example, if some class throws an exception, the exception class will not get loaded until the first time exception is thrown.You could do this if you have 100% code coverage via unit tests (literally 100%).I'm assuming this is some fancy AOP IOC container framework, where classes are dynamically discovered and loaded during run-time?If not - just delete the files, and compiler will show you what you break.   ;  The project itself defines no new exception types, so that is not a problem, and all the classes used in normal operation are loaded within the first 30 seconds after startup. It's just that a huge chunk of the codebase is legacy, and hasn't been used in years. I want to prune out all that old code that never gets loaded at runtime. Knowing the full path of each class will tell me whether it came from the project or from our support JARs, like the Jakarta log4j or Digester libraries we use.And no, it's a process simulation framework, but it uses XML configuration and a java-independant configuration model that allows multiple-inheritance-like behaviour. I could write a tool that would iterate over the configuration and over the Startup class and do a mark&sweep jumping through class references like that, but the most time-effective route  would take some deep digging into the Eclipse plugin framework, which I don't have time for.   ;  Up to you, just keep in mind that removing classes may go unnoticed, despite rigorous testing.Start the JVM with one of these options:-XX:+TraceClassLoading Trace loading of classes.-XX:+TraceClassLoadingPreorder Trace all classes loaded in order referenced (not loaded). (Introduced in 1.4.2.)-XX:+TraceClassResolution Trace constant pool resolutions. (Introduced in 1.4.2.)-XX:+TraceClassUnloading Trace unloading of classes.-XX:+TraceLoaderConstraints Trace recording of loader constraints. (Introduced in 6.)More fun hard-core stuff here.   