This post originated from an RSS feed registered with Java Buzz
by Weiqi Gao.
Original Post: Class Data Sharing in JDK 1.5.0
Feed Title: Weiqi Gao's Weblog
Feed URL: http://www.weiqigao.com/blog/rss.xml
Feed Description: Sharing My Experience...
Just noticed a new feature in the JDK 1.5.0 Beta2 called Class Data Sharing.
Certain system classes from the rt.jar are loaded and then memory dumped into a shared archive file /opt/jdk1.5.0/jre/lib/i386/client/classes.jsa, either during installation or by running java -Xshare:dump.
On my system, this file is 12591104 bytes long.
Subsequent invocations of Java programs will merely map this file into memory, saving the time to load the classes. Moreover, between five to six megabytes of the shared archive (metadata for the classes in the shared archive) will be mapped read-only and shared by all JVM instances.
The net result is faster startup time for small Java programs such as BeanShell scripts. Here's some benchmarks while running a trivial class with an empty CLASSPATH:
[weiqi@gao] $ cat Foo.java
public class Foo {
public static void main(String[] args) throws Exception {
Thread.sleep(1000);
}
}
[weiqi@gao] $ . switch-to-1.5.0
[weiqi@gao] $ time java Foo
real 0m1.101s
user 0m0.051s
sys 0m0.017s
[weiqi@gao] $ time java -Xshare:off Foo
real 0m1.144s
user 0m0.103s
sys 0m0.023s
[weiqi@gao] $ . switch-to-1.4.2
[weiqi@gao] $ time java Foo
real 0m1.131s
user 0m0.082s
sys 0m0.017s
Discounting the 1 second sleep, startup time in 1.5.0 Beta2 is 23% faster than in 1.4.2_04, and 30% faster than in 1.5.0 Beta2 with class data sharing turned off.
Ever since I started using Java, I have expressed the opinion that it is foolish to load and jit Java classes like java.lang.Object and java.lang.String on every invocation of any Java program, day after day, month after month, year after year.
I'm glad to see class data sharing coming to the JDK.