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...)

Note that

  • An inner class MyObject is used to represent a generic object. It has a fixed size of 128KB plus some overhead.
  • Another inner class MyList is used to as a manager to register and release objects. It uses a linked list data structure to do the job.
  • A third inner class Monitor is used to sample memory usage and object counts data.
  • The main test, myTest(), is divided two sections: the initialization section, where a number of objects are added to the list; the loop section, where objects are added to the list, then removed from the list.
  • Two paramters are supported. The first one, initSteps, is used to control how many objects we want to put into the list initially. The second one, testSteps, is used to control the number objects to be added to the list before removing the same number of objects from the list.
  • Two types of data are collected by the program: memory usage data, including total memory, free memory, and the percentage of the free memory over total memory; and counts of my objects, including number of total object, number of active objects, and number of dead objects. The object counts have been converted into memory sizes to make it easier to compare them with memory usages.
  • Memory related data has been normalized into kilo bytes (BK).
  • The over head memory represents the memory that are used by the program, but not by the allocated objects.

GCTest Program Output - Constant Memory Requirement

I compiled GCTest.java with J2SDK 1.4.0_02, and executed it with:

java -Xms2m -Xmx8m GCTest 16 1 > tail_16_01.out

I got the following output:

Time   Total   Free   Free   Total   Act.   Dead   Over
sec.   Mem.    Mem.   Per.   Obj.    Obj.   Obj.   Head
   0    1984   1727    87%       0      0      0    257 
   0    1984   1593    80%     128    128      0    263 
   1    1984   1592    80%     128    128      0    264 
   1    1984   1462    73%     256    256      0    266 
   2    1984   1332    67%     384    384      0    268 
   2    1984   1202    60%     512    512      0    270 
....                                                  
   8    3124   1062    33%    1920   1920      0    142 
   8    3124    932    29%    2048   2048      0    144 
   9    3124    803    25%    2176   2176      0    145 
   9    3124    801    25%    2176   2048    128    147 
  10    3124    671    21%    2304   2176    128    149 
  10    3124    669    21%    2304   2048    256    151 
  11    3124    540    17%    2432   2176    256    152 
  11    3124    538    17%    2432   2048    384    154 
  12    3124    408    13%    2560   2176    384    156 
  12    3124    406    12%    2560   2048    512    158 
  13    3124    277     8%    2688   2176    512    159 
  13    3124    275     8%    2688   2048    640    161 
  14    5256   2303    43%    2176   2176      0    777 
  14    5256   2301    43%    2176   2048    128    779 
  15    5256   2171    41%    2304   2176    128    781 
  15    5256   2170    41%    2304   2048    256    782 
  16    5256   2040    38%    2432   2176    256    784 
  16    5256   2038    38%    2432   2048    384    786 
....                                                
  29    5256    330     6%    4096   2176   1920    830 
  29    5256    329     6%    4096   2048   2048    831 
  30    5256    199     3%    4224   2176   2048    833 
  30    5256    197     3%    4224   2048   2176    835 
  31    7848   3358    42%    2176   2176      0   2314
  31    7848   3357    42%    2176   2048    128   2315
  32    7848   3227    41%    2304   2176    128   2317
  32    7848   3225    41%    2304   2048    256   2319
  33    7848   3095    39%    2432   2176    256   2321
  33    7848   3094    39%    2432   2048    384   2322
....                                                  
  54    7848    334     4%    5120   2176   2944   2394
  55    7848    332     4%    5120   2048   3072   2396
  55    7848    203     2%    5248   2176   3072   2397
  56    7848    201     2%    5248   2048   3200   2399
  56    8128   2614    32%    2176   2176      0   3338
  57    8128   2612    32%    2176   2048    128   3340
  57    8128   2482    30%    2304   2176    128   3342
  58    8128   2481    30%    2304   2048    256   3343
  58    8128   2351    28%    2432   2176    256   3345
  59    8128   2349    28%    2432   2048    384   3347
....                                                  
  73    8128    378     4%    4352   2176   2176   3398
  74    8128    377     4%    4352   2048   2304   3399
  74    8128    247     3%    4480   2176   2304   3401
  75    8128    245     3%    4480   2048   2432   3403
  75    8128   3382    41%    2176   2176      0   2570
  76    8128   3381    41%    2176   2048    128   2571
  76    8128   3251    39%    2304   2176    128   2573
  77    8128   3249    39%    2304   2048    256   2575
  77    8128   3119    38%    2432   2176    256   2577
  78    8128   3118    38%    2432   2048    384   2578
....                                                  
  98    8128    358     4%    5120   2176   2944   2650
  99    8128    356     4%    5120   2048   3072   2652
  99    8128    226     2%    5248   2176   3072   2654
 100    8128    225     2%    5248   2048   3200   2655
 100    8128   2614    32%    2176   2176      0   3338
 101    8128   2612    32%    2176   2048    128   3340
 101    8128   2482    30%    2304   2176    128   3342
 102    8128   2481    30%    2304   2048    256   3343
 102    8128   2351    28%    2432   2176    256   3345
 103    8128   2349    28%    2432   2048    384   3347
....                                                  
 117    8128    378     4%    4352   2176   2176   3398
 118    8128    376     4%    4352   2048   2304   3400
 118    8128    247     3%    4480   2176   2304   3401
 119    8128    245     3%    4480   2048   2432   3403
 119    8128   3382    41%    2176   2176      0   2570
 120    8128   3380    41%    2176   2048    128   2572
 120    8128   3251    39%    2304   2176    128   2573
 121    8128   3249    39%    2304   2048    256   2575
 121    8128   3119    38%    2432   2176    256   2577
 122    8128   3117    38%    2432   2048    384   2579

(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