Herong's Tutorial Notes on JVM
Dr. Herong Yang, Version 3.00, 2007

Garbage Collection

Part:   1  2  3  4  5  6  7  8  9 

(Continued from previous part...)

I also tried to reach 7.5 MB, but failed:

java -Xms2m -Xmx8m GCTest 16 44 > tail_16_44.out
Time   Total   Free   Free   Total   Act.   Dead   Over
sec.    Mem.   Mem.   Per.    Obj.   Obj.   Obj.   Head
   0    1984   1815    91%       0      0      0    169
   0    1984   1682    84%     128    128      0    174
   1    1984   1552    78%     256    256      0    176
....
  20    5484    390     7%    4992   4992      0    102
  20    5484    260     4%    5120   5120      0    104
  21    8128   2780    34%    5248   5248      0    100
  21    8128   2652    32%    5376   5376      0    100
....
  51    8128    272     3%    7680   2432   5248    176
  51    8128    270     3%    7680   2304   5376    178
  52    8128    268     3%    7680   2176   5504    180
  52    8128    266     3%    7680   2048   5632    182
  53    8128    136     1%    7808   2176   5632    184
Exception in thread "main" java.lang.OutOfMemoryError

It is very interesting to see that the JVM died out of memory, but there was 5632KB memory as garbage. Why did the JVM not collect the garbages at that time?

Comparing with JDK 1.4.0, JDK 1.3.1 did a good job in collecting garbages. JDK 1.3.1 allowed GCTest to use upto 88% of the total memory, while JDK 1.4.0 crashed when GCTest tring to get 63% of the total memory.

Comparison - Client vs. Server

I also made some tests to compare between the client version and the server version of JDK 1.4.0.

java -server -Xms2m -Xmx8m GCTest 16 24 > tail_16_24.out

But the program ran out of memory the same way as the client version:

Time   Total   Free   Free   Total   Act.   Dead   Over
sec.    Mem.   Mem.   Per.    Obj.   Obj.   Obj.   Head
   0    1984   1726    86%       0      0      0    258
   0    1984   1593    80%     128    128      0    263
   1    1984   1463    73%     256    256      0    265
....
  19    5260    357     6%    4736   4736      0    167
  19    5260    227     4%    4864   4864      0    169
  20    8128   2997    36%    4992   4992      0    139
  20    8128   2867    35%    5120   5120      0    141
  21    8128   2866    35%    5120   4992    128    142
  21    8128   2864    35%    5120   4864    256    144
....
  41    8128    482     5%    7424   4352   3072    222
  42    8128    352     4%    7552   4480   3072    224
  42    8128    223     2%    7680   4608   3072    225
Exception in thread "main" java.lang.OutOfMemoryError

Comparison - JDK 1.6.0 vs. 1.4.0

After installing JDK 6u2 on a Windows XP system, I repeated the same tests to see how JDK 1.6.0 behaves:

java -Xms2m -Xmx8m GCTest 16 1 > tail_16_01.out
java -Xms2m -Xmx8m GCTest 16 8 > tail_16_08.out
java -Xms2m -Xmx8m GCTest 16 16 > tail_16_16.out
java -Xms2m -Xmx8m GCTest 16 24 > tail_16_24.out

Test "java -Xms2m -Xmx8m GCTest 16 24" gave me an OutOfMemoryError similar to JDK 1.4.0 as shown below:

Time   Total   Free   Free   Total   Act.   Dead   Over
sec.   Mem.    Mem.   Per.   Obj.    Obj.   Obj.   Head
0       1984   1772    89%       0      0      0    212
0       1984   1643    82%     128    128      0    213
1       1984   1515    76%     256    256      0    213
1       1984   1387    69%     384    384      0    213
2       1984   1259    63%     512    512      0    213
2       1984   1131    57%     640    640      0    213
3       1984   1107    55%     768    640    128    109
3       1984   1098    55%     896    768    128    -10
4       1984    960    48%     896    896      0    128
4       1984    832    41%    1024   1024      0    128
5       1984    704    35%    1152   1152      0    128
5       1984    576    29%    1280   1280      0    128
6       1984    448    22%    1408   1408      0    128
6       3488   1837    52%    1536   1536      0    115

(Continued on next part...)

Part:   1  2  3  4  5  6  7  8  9 

Dr. Herong Yang, updated in 2007
Herong's Tutorial Notes on JVM - Garbage Collection