Skip to main content
gamedev.net
🔒 Locked

[java] Java Class Usage

Started by Wyrframe Jan 22, 2008 at 12:34 PM 2 replies 1.2k views
Original Post
Wyrframe
Wyrframe
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?
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
Antheus
Antheus
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.
Wyrframe
Wyrframe
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.
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
Antheus
Antheus
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.