|
Garbage Collection
Part:
1
2
3
4
5
6
7
8
9
(Continued from previous part...)
Obviously, we had a problem here. My program crashed at second 42
with the "out of memory" exception.
At that time, the free memory decreased to 2%. But there were 3072KB of
dead objects that could be collected to gain more free memory.
Why the JVM did not collect the dead objects? Can anyone help to explain?
I believe the the answer is related my guessed rule that the JVM will reserve
the same amount of memory as the collected garbages.
At second 42 in our test, 8128 (total memory) - 4608 (active objects)
- 3072 (reserved memory) = 448 (free memory), not enough to work with.
Comparison - Releasing Old vs. New Objects
In the previous tests, objects were released from the tail of the list. So
old objects were released first. To see if there are any differences
between releasing old objects and new objects, I changed the code to use
the objList.removeHead() method. 4 tests were conducted to compare with
the previous tests:
java -Xms2m -Xmx8m GCTest 16 1 > head_16_01.out
java -Xms2m -Xmx8m GCTest 16 8 > head_16_08.out
java -Xms2m -Xmx8m GCTest 16 16 > head_16_16.out
java -Xms2m -Xmx8m GCTest 16 24 > head_16_24.out
The outputs were verys similar to those using objList.removeTail() method.
head_16_24.out also showed a memory crash at second 43.
Comparison - JDK 1.4.0 vs. JDK 1.3.1
The next group of tests were conducted under JDK 1.3.1_01:
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
Here was the output of tail_16_01.out:
Time Total Free Free Total Act. Dead Over
sec. Mem. Mem. Per. Obj. Obj. Obj. Head
0 1984 1816 91% 0 0 0 168
1 1984 1682 84% 128 128 0 174
1 1984 1553 78% 256 256 0 175
2 1984 1503 75% 384 384 0 97
2 1984 1373 69% 512 512 0 99
.....
6 1984 604 30% 1280 1280 0 100
6 1984 474 23% 1408 1408 0 102
7 2116 482 22% 1536 1536 0 98
7 2116 352 16% 1664 1664 0 100
8 2116 222 10% 1792 1792 0 102
8 3088 1070 34% 1920 1920 0 98
9 3088 942 30% 2048 2048 0 98
9 3088 812 26% 2176 2176 0 100
10 3088 810 26% 2176 2048 128 102
10 3088 680 22% 2304 2176 128 104
11 3088 678 21% 2304 2048 256 106
11 3088 558 18% 2432 2176 256 98
12 3088 556 18% 2432 2048 384 100
12 3088 426 13% 2560 2176 384 102
13 3088 424 13% 2560 2048 512 104
13 3088 294 9% 2688 2176 512 106
14 3088 292 9% 2688 2048 640 108
14 3484 569 16% 2816 2176 640 99
15 3484 567 16% 2816 2048 768 101
15 3484 438 12% 2944 2176 768 102
16 3484 436 12% 2944 2048 896 104
16 3484 306 8% 3072 2176 896 106
17 3484 304 8% 3072 2048 1024 108
17 5220 1921 36% 2176 2176 0 1123
18 5220 1919 36% 2176 2048 128 1125
18 5220 1793 34% 2304 2176 128 1123
19 5220 1791 34% 2304 2048 256 1125
....
31 5484 389 7% 3968 2176 1792 1127
32 5484 387 7% 3968 2048 1920 1129
32 5484 257 4% 4096 2176 1920 1131
33 5484 255 4% 4096 2048 2048 1133
33 7568 3245 42% 2176 2176 0 2147
34 7568 3243 42% 2176 2048 128 2149
34 7568 3113 41% 2304 2176 128 2151
35 7568 3111 41% 2304 2048 256 2153
....
58 7964 435 5% 5376 2176 3200 2153
59 7964 434 5% 5376 2048 3328 2154
59 7964 304 3% 5504 2176 3328 2156
60 7964 302 3% 5504 2048 3456 2158
61 8128 2396 29% 2176 2048 128 3556
61 8128 2266 27% 2304 2176 128 3558
62 8128 2264 27% 2304 2048 256 3560
....
77 8128 341 4% 4224 2176 2048 3563
77 8128 339 4% 4224 2048 2176 3565
78 8128 210 2% 4352 2176 2176 3566
78 8128 208 2% 4352 2048 2304 3568
79 8128 3549 43% 2176 2176 0 2403
79 8128 3547 43% 2176 2048 128 2405
80 8128 3417 42% 2304 2176 128 2407
80 8128 3415 42% 2304 2048 256 2409
81 8128 3285 40% 2432 2176 256 2411
81 8128 3283 40% 2432 2048 384 2413
(Continued on next part...)
Part:
1
2
3
4
5
6
7
8
9
|