Space optimisations: OpenJDK runtime .jar

Louis Simard louis.simard at
Sat Nov 6 23:24:05 UTC 2010


In a posting from 'More LiveCD space optimizations' [1], you asked if
the Java VM would open recompressed .jar files as quickly as the
originals. I wrote a benchmark to assess this, by using the largest
.jar there is: the Java library itself! :)

I've split off this benchmark result to its own e-mail thread because
Java is not on the LiveCD, and it has more of a special interest to
folks running servers. But it's still a space optimisation.

Attached is a benchmark program; please download it if you want to
reproduce this benchmark on your machine.


In the OpenJDK package, most of the Java class library is implemented
as a single file, rt.jar, and that file is uncompressed. Compressing
it with 'advzip -z4 rt.jar' saves 32,184 KiB out of 60,064 KiB

The speed regressed by 32 milliseconds (16%) to load 894 classes from
the Java library. I believe this number to be representative of the
number of classes loaded by an application server such as JBoss or


-- Preparing for the benchmark --

sudo apt-get install openjdk-6-jre advancecomp
cp /usr/lib/jvm/java-6-openjdk/jre/lib/rt.jar rt.jar; sync
cp rt.jar rt-recompressed.jar
advzip -z4 rt-recompressed.jar

# [At this stage, rt.jar is 60064 KiB and rt-recompressed.jar is 27880 KiB]
# Make sure you've downloaded the attachment and saved it to
# before running the rest.

gunzip && javac -g:none -source 1.6 -target 1.6
for i in `seq 1 10`; do java ClassLoadTest; done
sudo cp rt-recompressed.jar /usr/lib/jvm/java-6-openjdk/jre/
for i in `seq 1 10`; do java ClassLoadTest; done

# Cleanup
sudo cp rt.jar /usr/lib/jvm/java-6-openjdk/jre/lib/rt.jar
rm ClassLoadTest.class rt.jar rt-recompressed.jar; sync

-- Methodology --

I ran this test on a computer that has 4 GB of RAM and a dual-core 2.6
GHz AMD processor set to 2.6 GHz with the Performance frequency
selector. This test does not use threads, so it would be run at 2600

The Java program outputs the number of nanoseconds it takes the Java
VM to load all of the classes named in the 'loads' variable and all of
their dependencies (to see the number of classes loaded, use 'java
-XX:+TraceClassLoading ClassLoadTest | grep Loaded | wc -l'). For the
results below, I have removed the fastest and the slowest run before
calculating the average time.

-- Results --

Original rt.jar, nanoseconds: 192534058, 197527724, 194842272,
196013535, 188327043 [fastest], 191867030, 200329576, 202827722
[slowest], 195906590, 199961018

Recompressed rt.jar, nanoseconds: 208085265 [fastest], 230182021,
218891572, 221611904, 231577539, 232149021, 228110533, 230476584,
232480308 [slowest], 229873766

Original rt.jar: 196 milliseconds
Recompressed rt.jar: 228 milliseconds

Speed regressed by 32 milliseconds (16%) to load 894 classes.

Louis Simard
<Conspicuous absence of digital signature here>
-------------- next part --------------
A non-text attachment was scrubbed...
Type: application/x-gzip
Size: 2460 bytes
Desc: not available
URL: <>

More information about the Ubuntu-devel-discuss mailing list