jdk/src/java.base/share/classes/java/lang/ref/Finalizer.java
changeset 27337 89b967c599ce
parent 25859 3317bb8137f4
child 29919 be906afc335b
equal deleted inserted replaced
27325:948cceef81ba 27337:89b967c599ce
   120      */
   120      */
   121     private static void forkSecondaryFinalizer(final Runnable proc) {
   121     private static void forkSecondaryFinalizer(final Runnable proc) {
   122         AccessController.doPrivileged(
   122         AccessController.doPrivileged(
   123             new PrivilegedAction<Void>() {
   123             new PrivilegedAction<Void>() {
   124                 public Void run() {
   124                 public Void run() {
   125                 ThreadGroup tg = Thread.currentThread().getThreadGroup();
   125                     ThreadGroup tg = Thread.currentThread().getThreadGroup();
   126                 for (ThreadGroup tgn = tg;
   126                     for (ThreadGroup tgn = tg;
   127                      tgn != null;
   127                          tgn != null;
   128                      tg = tgn, tgn = tg.getParent());
   128                          tg = tgn, tgn = tg.getParent());
   129                 Thread sft = new Thread(tg, proc, "Secondary finalizer");
   129                     Thread sft = new Thread(tg, proc, "Secondary finalizer");
   130                 sft.start();
   130                     sft.start();
   131                 try {
   131                     try {
   132                     sft.join();
   132                         sft.join();
   133                 } catch (InterruptedException x) {
   133                     } catch (InterruptedException x) {
   134                     /* Ignore */
   134                         Thread.currentThread().interrupt();
   135                 }
   135                     }
   136                 return null;
   136                     return null;
   137                 }});
   137                 }});
   138     }
   138     }
   139 
   139 
   140     /* Called by Runtime.runFinalization() */
   140     /* Called by Runtime.runFinalization() */
   141     static void runFinalization() {
   141     static void runFinalization() {
   144         }
   144         }
   145 
   145 
   146         forkSecondaryFinalizer(new Runnable() {
   146         forkSecondaryFinalizer(new Runnable() {
   147             private volatile boolean running;
   147             private volatile boolean running;
   148             public void run() {
   148             public void run() {
       
   149                 // in case of recursive call to run()
   149                 if (running)
   150                 if (running)
   150                     return;
   151                     return;
   151                 final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
   152                 final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
   152                 running = true;
   153                 running = true;
   153                 for (;;) {
   154                 for (;;) {
   166         }
   167         }
   167 
   168 
   168         forkSecondaryFinalizer(new Runnable() {
   169         forkSecondaryFinalizer(new Runnable() {
   169             private volatile boolean running;
   170             private volatile boolean running;
   170             public void run() {
   171             public void run() {
       
   172                 // in case of recursive call to run()
   171                 if (running)
   173                 if (running)
   172                     return;
   174                     return;
   173                 final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
   175                 final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
   174                 running = true;
   176                 running = true;
   175                 for (;;) {
   177                 for (;;) {
   187         private volatile boolean running;
   189         private volatile boolean running;
   188         FinalizerThread(ThreadGroup g) {
   190         FinalizerThread(ThreadGroup g) {
   189             super(g, "Finalizer");
   191             super(g, "Finalizer");
   190         }
   192         }
   191         public void run() {
   193         public void run() {
       
   194             // in case of recursive call to run()
   192             if (running)
   195             if (running)
   193                 return;
   196                 return;
   194 
   197 
   195             // Finalizer thread starts before System.initializeSystemClass
   198             // Finalizer thread starts before System.initializeSystemClass
   196             // is called.  Wait until JavaLangAccess is available
   199             // is called.  Wait until JavaLangAccess is available