Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4120342

Immediate finalization

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.2.0
    • specification
    • generic
    • generic



      Name: rm29839 Date: 03/17/98

      =20
      The current specification of when the finalize
      methods are run is insufficient for handling
      other resources than memory. I belive this is
      important and has to be fixed.

      The following illustrates how it can be done
      independent of the current garbage collection
      mechanism and without changing the VM.

      The compiler can recognize that a class has a
      finalize method. Each reference to such a class
      is specially handled. The compiler simply places
      code for handling a reference count hidden in
      objects of classes that has a finalize method.
      Assignment and the reference going out of scope
      is handled especially, and the object's finalize
      method is run when the reference count becomes
      zero.

      We may assume that the finalize method is
      sparingly used, and the inefficiency of the extra
      code for each assignment of these references are
      well worth taking.=20

      The garbage collecting can be largly left unchanged
      and may be implemented with unimpared efficiency.
      One change though. we don't want the finalize
      methods to be run more than once. The garbage
      collection should therefore not run them,
      except for when the reference count is different
      from zero.

      I don't belive this scheme would require any change
      to the virtual machine. The compiler does all the
      work by laying out extra code for the finalize
      references. The extra reference count field in
      these objects should not be visible to the VM.

      I don't want to tag the special references in any
      way such as "finalize" or "runFinalization")
      because this would be percieved as a complication
      of the language.
      The only reason for such a tag would be if we
      belive that the finalize method is commonly used
      when the finalization can be delayed to when
      garbage collection is made.=20

      I don't belive these ideas are very original, but
      perhaps worth pointing out anyway. I myself didn't
      realize at once how simple it would be to get this
      replacement for the C++ destructor.
      (Review ID: 26297)
      ======================================================================

            gbrachasunw Gilad Bracha (Inactive)
            rmandelsunw Ronan Mandel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: