Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#866 closed defect (fixed)

gc goes crazy with faulty finalizers

Reported by: megane Owned by: felix winkelmann
Priority: major Milestone: 4.9.0
Component: core libraries Version: 4.7.x
Keywords: Cc:
Estimated difficulty:

Description

;; It seems like the gc stops working correctly after an exception
;; from a faulty finalizer gets caught (and not crash the whole
;; program).

(define n 2000000000)
(define vector-size 100)

(define (make-objects n gc-msg)
  (let loop [(i 0)]
    (let [(o (make-vector vector-size))]
      (print "making " i)
      (set-finalizer! o (lambda (ob) (print gc-msg " " i))) 
      (if (< i n)
	  (loop (+ 1 i))))))

(set-finalizer! (make-vector 100) (lambda (ob) (+ i 'a)))
(handle-exceptions
    exn
  (begin
    (print "Caught an exception" exn))
  (make-objects n "gc'ing"))

(print "done")

;; Result when compiled: 3 cases

;; Case 1: out of memory, tweak n, vector-size to avoid this
;; ...
;; [panic] out of memory - cannot allocate heap segment - execution terminated

;; Case 2:  100% cpu with no apparent progress

;; Output with -:g
;; ...
;; [GC] 2 finalized item(s) still pending
;; [GC] 2680 finalizer value(s) marked
;; [GC] level  1	gcs(minor)  379	gcs(major)  22
;; [GC] stack	0xbfef7880	0xbff36a00	0xbff37880
;; [GC]  from	0x773d9008	0xb731f744	0xb73d9000	0x3ff4673c
;; [GC]    to	0x09123008	0x09123008	0x49123000 
;; [GC] 0 locatives (from 32)
;; 681
;; [GC] 2 finalized item(s) still pending
;; [GC] 2681 finalizer value(s) marked
;; [GC] level  1	gcs(minor)  0	gcs(major)  23
;; [GC] stack	0xbfef7880	0xbff36a00	0xbff37880
;; [GC]  from	0x09123008	0x490cb1d8	0x49123000	0x3ffa81d0
;; [GC]    to	0x773d9008	0x773d9008	0xb73d9000 
;; [GC] 0 locatives (from 32)
;; <- stuck here with 100% cpu

;; Case 3: 100% at the end
;; making 1
;; making 2
;; ...
;; ...
;; gc'ing 103
;; gc'ing 102
;; gc'ing 101
;; Caught an exception#<condition: (exn type)>
;; done
;; <- stuck here with 100% cpu


Attachments (1)

0001-Catch-exceptions-in-finalizers-and-added-tests.patch (8.0 KB) - added by felix winkelmann 12 years ago.
better variant

Download all attachments as: .zip

Change History (8)

comment:1 Changed 12 years ago by felix winkelmann

Owner: set to felix winkelmann
Status: newassigned

comment:2 Changed 12 years ago by felix winkelmann

The attached patch adds catching any errors during finalizer execution, but there still seems to be a problem - running the test sometimes crashes (seems to depend on memory layout or something similar).

Changed 12 years ago by felix winkelmann

better variant

comment:3 Changed 12 years ago by felix winkelmann

Milestone: 4.9.04.8.0

comment:4 Changed 12 years ago by felix winkelmann

Component: unknowncore libraries

comment:5 Changed 12 years ago by sjamaan

Hopefully this is the final fix for this problem:

http://lists.nongnu.org/archive/html/chicken-hackers/2012-06/msg00100.html

comment:6 Changed 12 years ago by sjamaan

Resolution: fixed
Status: assignedclosed

This was applied, so I'm closing the ticket

comment:7 Changed 12 years ago by felix winkelmann

Milestone: 4.8.04.9.0

Milestone 4.8.0 deleted

Note: See TracTickets for help on using tickets.