Another take on Finalization

Peter Levart peter.levart at gmail.com
Sun Jun 7 08:46:33 UTC 2015


Hi,

On 06/05/2015 11:11 PM, Jonathan Payne wrote:
> My problem was that finalization was not being run at all with the G1 collector. Not at all. That would have been fine with me because none of the existing objects in the Finalizer queue actually needed the service anymore: the files, sockets, streams, etc. had all been properly closed by my application, otherwise the server would have long since failed completely. However, those objects started to accumulate in the VM and eventually (8 hours later) brought the server down.

I made a quick test comparing default (PS MarkSweep / PS Scavenge) and 
G1 collectors with -Xmx512m option. When finalizable objects are 
released immediately after construction with a sustained rate of ~90 
objects/ms, the results for default collector are:

Finalization, PATCHED, PS MarkSweep, PS Scavenge
Heap: init = 260046848(253952K) used = 9175232(8960K) committed = 
249561088(243712K) max = 477626368(466432K)

   construction threads: 1
   instances per thread: 10000000
   cons. per 1 ms sleep: 100
                                            ~5s interval cumulative   
active  pool     queued
    t[ms] construct.  destruct.  in-flight con./ms des./ms con./ms 
des./ms  thr.  size      tasks
  ------- ---------- ---------- ---------- ------- ------- ------- 
------- ----- ----- ----------
     5000     439500          0     439500      87 0      87       0     
0     0          0
    10002     877703          0     877703      87 0      87       0     
0     0          0
    15004    1308200     238692    1069508      86 47      87      
15     0     0          0
    20006    1747600     238692    1508908      87 0      87      11     
0     0          0
    25008    2177600     478173    1699427      85 47      87      
19     0     1          0
    30010    2620800     478173    2142627      88 0      87      15     
0     0          0
    35012    3067800     478173    2589627      89 0      87      13     
0     0          0
    40014    3463600    3302385     161215      79 564      86      
82     0     1          0
    45016    3903200    3302385     600815      87 0      86      73     
0     0          0
    50018    4342800    3302385    1040415      87 0      86      66     
0     0          0
    55020    4772809    3564145    1208664      85 52      86      
64     0     0          0
    60021    5212000    3564145    1647855      87 0      86      59     
0     0          0
    65023    5611300    4096555    1514745      79 106      86      
63     1     1         47
    70024    6051400    5609375     442025      88 302      86      
80     0     0          0
    75025    6477000    6424132      52868      85 162      86      
85     0     1          0
    80026    6916000    6424132     491868      87 0      86      80     
0     0          0
    85027    7355600    6424132     931468      87 0      86      75     
0     0          0
    90028    7780400    7490435     289965      84 213      86      
83     0     0          0
    95029    8220800    7490435     730365      88 0      86      78     
0     0          0
   100029    8644500    8550627      93873      84 211      86      
85     0     1          0
   105031    9084400    8550627     533773      87 0      86      81     
0     0          0
   110032    9524100    8550627     973473      87 0      86      77     
0     0          0
   115033    9948900    9618391     330509      84 213      86      
83     0     0          0
   120033   10000000    9618391     381609      10 0      83      80     
0     0          0
   125205   10000000   10000000          0       0 73      79      
79     0     0          0


And for G1:

Finalization, PATCHED, G1 Young Generation, G1 Old Generation
Heap: init = 260046848(253952K) used = 3145728(3072K) committed = 
260046848(253952K) max = 536870912(524288K)

   construction threads: 1
   instances per thread: 10000000
   cons. per 1 ms sleep: 100
                                            ~5s interval cumulative   
active  pool     queued
    t[ms] construct.  destruct.  in-flight con./ms des./ms con./ms 
des./ms  thr.  size      tasks
  ------- ---------- ---------- ---------- ------- ------- ------- 
------- ----- ----- ----------
     5000     437600     337879      99721      87 67      87      
67     0     1          0
    10002     876200     592612     283588      87 50      87      
59     0     0          0
    15004    1309600    1032801     276799      86 87      87      
68     0     0          0
    20006    1742200    1545349     196851      86 102      87      
77     0     0          0
    25008    2172300    2152632      19668      85 121      86      
86     0     1          0
    30010    2617800    2152632     465168      89 0      87      71     
0     0          0
    35012    3047400    2783284     264116      85 126      87      
79     0     0          0
    40139    3487900    2783284     704616      85 0      86      69     
0     0          0
    45140    3929800    3597818     331982      88 162      87      
79     0     0          0
    50142    4374400    3597818     776582      88 0      87      71     
0     0          0
    55144    4797700    4641649     156051      84 208      87      
84     0     1          0
    60145    5242800    4641649     601151      88 0      87      77     
0     0          0
    65147    5670900    5458835     212065      85 163      87      
83     0     0          0
    70148    6101400    6071013      30387      86 122      86      
86     0     1          0
    75150    6546100    6071013     475087      88 0      87      80     
0     0          0
    80151    6990100    6071013     919087      88 0      87      75     
0     0          0
    85153    7432600    6071013    1361587      88 0      87      71     
0     0          0
    90154    7850400    7506935     343465      83 287      87      
83     0     0          0
    95154    8280100    8175574     104526      85 133      87      
85     0     1          0
   100155    8713200    8675215      37985      86 99      86      
86     0     1          0
   105156    9158500    8675215     483285      89 0      87      82     
0     0          0
   110157    9603800    8675215     928585      89 0      87      78     
0     0          0
   115158   10000000    8675215    1324785      79 0      86      75     
0     0          0
   120761   10000000   10000000          0       0 236      82      
82     0     0          0


...which suggests that G1 is no less eager to process finalizable 
objects that are young garbage (see "in-flight" column). At least it 
doesn't seem that they accumulate. So your problem might have been with 
finalizable objects escaping to old-gen. Tuning the young-gen size and 
survivor ratio might help in your case.

Regards, Peter




More information about the core-libs-dev mailing list