[Bug 150] New: finalizers are not run

[email protected] Sat, 16 Jul 2005 14:37:26 -0400
Newsgroups gmane.comp.java.vm.sablevm.bugs
Message-ID <[email protected]>
http://sablevm.org/bugs/show_bug.cgi?id=150

           Summary: finalizers are not run
           Product: SableVM
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: default
        AssignedTo: [email protected]
        ReportedBy: [email protected]
         QAContact: [email protected]


The VM Spec says finalizers must be run for objects that are reclaimed (Section
2.17.7 Finalization of Class Instances).  Sun's VM prints Hello then Done here,
SableVM just hangs.

Note that unreclaimed storage on VM exit does not need to have its finalizers
run (Section 2.17.9 Virtual Machine Exit).

One solution is to have GC run finalizers during collection.  This is probably
safest from a concurrency standpoint (in general, finalizers are dangerous
things and should be avoided in good Java programming practice).  Another
solution is to have GC be the producer of objects that need finalization, and
have another thread be the consumer of these objects.

public class Foo {
    public volatile static int x;

    public static void main(String[] args) {

        new Foo();
        while(x==0) {
            System.gc();
        }
        System.out.println("Done");
    }

    public void finalize() {
        System.out.println("Hello");
        x=1;
    }
}



------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
You are the QA contact for the bug, or are watching the QA contact.