Initializing all Java classes at Start-Up
Jean-Marie Dautelle writes "Java classes are initialized at first-use only which can introduce significant runtime delays detrimental to real-time or games applications (for which accurate scheduling is often required).
To solve this problem, the latest open-source Javolution library supports initialization of all Java classes at start-up (e.g.
javolution.lang.ClassInitializer.initializeAll(); // Initialize runtime classes (rt.jar) and all classes in classpath).
Note: Runtime class initialization (rt.jar) takes typically a few seconds and about 3 Mbytes of memory."
How long would it take someone to write this themselves if they needed it? 10 minutes?
On a serious note, This is interesting. I program in java, some games in fact, and I think I'll be checking this one out, just to see if/what an impact it makes.
Want to find other gamers to play board and role playing game
system.tumbleWeed.initialise() ?
"A few seconds" and 3MB of memory for rt.jar sound nice but I wonder how timings and memory consumption would look like with a couple of more libraries in the CLASSPATH, how about a full Eclipse environment?
The problem with Java startup times is that every Java app loads it's own complete runtime environment. This is not easy to fix, since many apps depend on the fact that they get their own.
db4o - open source object database for Java and
Making a function that calls System.XYZ.Init() for each xyz is newsworthy?
Egad... Time to submit my hello world-programs...
After e.g. and before ). There's a bunch of text that Firefox isn't rendering properly on my PC. Any ideas what I can do about it? I've seen it elsewhere, and fiddling with my fonts in the menu options didn't help.
How long would it take someone to write this themselves if they needed it? 10 minutes?
.class files to the list of class names .zip, .war ... ) and find all class names in there.
Maybe a day ?
(1) Identify all files and directories that can be found in the CLASSPATH.
(2) Look at the directories and add all contained files to the list of files.
(3) Differentiate beween types of files:
(4) Add
(5) Look through all zip format files (.jar,
(6) Call ClassLoader#loadClass with all classnames.
(5) will take longest to write yourself, but there should certainly already be code out there tht gets that done
(6) Which ClassLoader to use? Surely the ClassLoader needs to be supplyable as a parameter.
db4o - open source object database for Java and
I haven't touched Java with a 10-foot pole in over 5 years, but wouldn't this be something you do with the Reflection functions to get the list of defined classes and have yourself some Foreach fun.
-Billco, Fnarg.com
The advantage of doing eager initialization is predictability, and in the case where almost all classes get initialized sooner or later (which would be very rare considering the size of the Java API) a slight performance increase.
Maybe some kinds of games would benefit from this, but almost all other applications would benefit from more lazy initialization, not less.
Try out fish, the friendly interactive shell.
Let's see. Submitter of story: Jean-Marie Dautelle. Javolution project owner: Jean-Marie Dautelle.
Windows is like decaf - it tastes like the real thing, but it won't get you through the day.
Java classes are initialized at first-use only which can introduce significant runtime delays detrimental to real-time or games applications
At least in terms of unused code. I ran PMD's unused code rules on it and found no problems. Good stuff!
The Army reading list
No, reflection won't work to load all classes in the CLASSPATH. For reflection you would need a starting point from where all other classes are referenced. There is no common root. Any line of code can decide to create an instance of a class that has not been used or referenced yet.
db4o - open source object database for Java and
If you want to dictate how the JVM starts up at a fundamental level, go hack on Apache Harmony, the open source Java implementation. They're just getting started so your contribution could go a long way.
I speed up my java load times by using this tecnique that I like to call C++.
.NET is somewhat different, the design part is still the same. It gets worse in VB.NET (please don't start flaming) where people can have project level imports. It even bothered me in C++ when someone would lets say remove functionality but leave all the imports/#define behind. Today I came accross this problem in ASP.NET an webpage:
On a more serious note, one of the problems with load times I have noticed in a lot of Java is that people unnecessarily include namespaces where they don't need/use them. Sometimes there's no reason to go into another library when there's an equivalent function in one you're already using and there's certainly no need to reference things you don't use. That also creates a design problem in addition to the performance issue IMO because although it's not hurting too bad, it's a violation of least privilege.
This post reminds me of some other related problems that occur in other languages both design and performance related. Although the issue with
imports System.Web.UI (only namespace used)
imports System.Text (not used!)
imports System.XML.Serialization (not used!)
imports System.Threading (not used!)
Yes, "import" is a problem. It's such a PITA to identify the actual bits you need, that most code just imports huge chunks of the API.
Furthermore, "import" has no dependency handling. For instance, org.xml.sax.XMLReader is no use without org.xml.sax.helpers.XMLReaderFactory. Rather than have to manually hunt down the dependencies in the few functions they use, most programmers import org.xml.sax.*.
In C/C++/Objective-C, at least include files tend to include their dependencies.
GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
[...] supports initialization of [...] all classes in classpath
"He who packs his entire wardrobe for a row across the lake becomes the best-dressed fish around." (Source unknown)
"javad" would boot from /etc/init.d and be running by the time KDE got finished loading the kitchen sink. At which point, Java processes would have as low startup overhead as regular ones.
Unfortunately there just isn't a good way to determine what classes are available. Reflection doesn't have a way to determine all available subclasses of a given class, which would be really useful.
There's a library class for accessing ZIP/JAR files. All in all it sounds rather simple.
I guess Java really is a ghost town these days. Everyone rode the rails on out of town.
September 2011: Looking for Cocoa/iOS work in Boston area Cocoa Programmer Quincy, MA