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

object finalizer is not invoked when System.exit() is called

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5

      Description



      Name: szC45993 Date: 07/10/97



      The Java Virtual Machine, chapter 2 Java Concepts,
      section 2.16.9 Virtual Machine Exit, claims:
      "A Java Virtual Machine terminates all its activity and exits when one of two things happens:
      - All the threads that are not daemon threads ($2.17) terminate.
      - Some thread invokes the exit method of class Runtime or class System and the exit operation is permitted by the security manager.

      A Java program can specify that the finalizers of all objects that have finalizers that have not been automatically invoked are to be run before the virtual machine exits. This is done by invoking the method runFinalizersOnExit of the class System with the argument true.
      ..."

      Meanwhile, test shows that the object finalizer is not invoked under System.runFinalizersOnExit(true) in the case when jvm exits when some thread invokes the exit method of class System (compare LOG1 with LOG2). The identical results are on jdk1.1.3F, jdk1.1.4, jdk1.2.

      LOG1 (System.exit() is used in the test):

      ----------------------------------------------------------------------------
      novo7% /export/ld14/java/dest/jdk1.1.3F/solaris/bin/java -verify javasoft.sqe.tests.vm.execution.execution075.execution07502.execution07502
      novo7% echo $status
      5
      ----------------------------------------------------------------------------

      LOG2 (System.exit() is not used in the test. Comment, please, all
      lines with System.exit() invoking for this.):

      ----------------------------------------------------------------------------
      novo7% /export/ld14/java/dest/jdk1.1.3F/solaris/bin/java -verify javasoft.sqe.tests.vm.execution.execution075.execution07502.execution07502
      execution07502a FINALIZE INVOCATION
      novo7% echo $status
      0
       ----------------------------------------------------------------------------

      SOURCES:

      --------------------- execution07502.java
      //File: @(#)execution07502.java 1.2 97/07/08
      //Copyright 07/08/97 Sun Microsystems, Inc. All Rights Reserved

      package javasoft.sqe.tests.vm.execution.execution075.execution07502;

      import java.io.PrintStream;

      public class execution07502 {

        static execution07502a exca1 = new execution07502a();

        public static void main(String argv[]) {
      System.runFinalizersOnExit(true);
      try{
      exca1.num = 1;
      Thread thr1 = new Thread(exca1);
      thr1.start();
      thr1.join();
      } catch (Throwable e) {
      System.out.println("TRACE: Error/Exception in execution07502b: "+ e);
      };
      ///////////////////////////////////////////////////////////////////////////////
      System.exit(7);
      ///////////////////////////////////////////////////////////////////////////////
        }

        public void finalize() {

      System.out.println("execution07502 FINALIZE INVOCATION");

        }
      }
      --------------------- execution07502a.java
      //File: @(#)execution07502a.java 1.1 97/07/08
      //Copyright 07/08/97 Sun Microsystems, Inc. All Rights Reserved

      package javasoft.sqe.tests.vm.execution.execution075.execution07502;

      class execution07502a implements Runnable {

        public int num;

        public void run() {

      while (num >= 0) {
      try{
      java.lang.Thread.sleep(1000);
      } catch (java.lang.InterruptedException e) {};
      num -= 1;
      }
      ///////////////////////////////////////////////////////////////////////////////
      System.exit(5);
      ///////////////////////////////////////////////////////////////////////////////
        }

        public void finalize() {

      System.out.println("execution07502a FINALIZE INVOCATION");

        }
      }
      ---------------------

      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mr Mark Reinhold
                Reporter:
                zsssunw Zss Zss (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: