src/share/vm/runtime/thread.cpp

Print this page
rev 6498 : 8044796: G1: Enable G1CollectedHeap::stop()
Reviewed-by:


3951   if (JDK_Version::is_jdk12x_version()) {
3952     // We are the last thread running, so check if finalizers should be run.
3953     // For 1.3 or later this is done in thread->invoke_shutdown_hooks()
3954     HandleMark rm(thread);
3955     Universe::run_finalizers_on_exit();
3956   } else {
3957     // run Java level shutdown hooks
3958     thread->invoke_shutdown_hooks();
3959   }
3960 
3961   before_exit(thread);
3962 
3963   thread->exit(true);
3964 
3965   // Stop VM thread.
3966   {
3967     // 4945125 The vm thread comes to a safepoint during exit.
3968     // GC vm_operations can get caught at the safepoint, and the
3969     // heap is unparseable if they are caught. Grab the Heap_lock
3970     // to prevent this. The GC vm_operations will not be able to
3971     // queue until after the vm thread is dead.
3972     // After this point, we'll never emerge out of the safepoint before
3973     // the VM exits, so concurrent GC threads do not need to be explicitly
3974     // stopped; they remain inactive until the process exits.
3975     // Note: some concurrent G1 threads may be running during a safepoint,
3976     // but these will not be accessing the heap, just some G1-specific side
3977     // data structures that are not accessed by any other threads but them
3978     // after this point in a terminal safepoint.
3979 
3980     MutexLocker ml(Heap_lock);
3981 
3982     VMThread::wait_for_vm_thread_exit();
3983     assert(SafepointSynchronize::is_at_safepoint(), "VM thread should exit at Safepoint");
3984     VMThread::destroy();
3985   }
3986 
3987   // clean up ideal graph printers
3988 #if defined(COMPILER2) && !defined(PRODUCT)
3989   IdealGraphPrinter::clean_up();
3990 #endif
3991 
3992   // Now, all Java threads are gone except daemon threads. Daemon threads
3993   // running Java code or in VM are stopped by the Safepoint. However,
3994   // daemon threads executing native code are still running.  But they
3995   // will be stopped at native=>Java/VM barriers. Note that we can't
3996   // simply kill or suspend them, as it is inherently deadlock-prone.
3997 
3998 #ifndef PRODUCT




3951   if (JDK_Version::is_jdk12x_version()) {
3952     // We are the last thread running, so check if finalizers should be run.
3953     // For 1.3 or later this is done in thread->invoke_shutdown_hooks()
3954     HandleMark rm(thread);
3955     Universe::run_finalizers_on_exit();
3956   } else {
3957     // run Java level shutdown hooks
3958     thread->invoke_shutdown_hooks();
3959   }
3960 
3961   before_exit(thread);
3962 
3963   thread->exit(true);
3964 
3965   // Stop VM thread.
3966   {
3967     // 4945125 The vm thread comes to a safepoint during exit.
3968     // GC vm_operations can get caught at the safepoint, and the
3969     // heap is unparseable if they are caught. Grab the Heap_lock
3970     // to prevent this. The GC vm_operations will not be able to
3971     // queue until after the vm thread is dead. After this point,
3972     // we'll never emerge out of the safepoint before the VM exits.






3973 
3974     MutexLocker ml(Heap_lock);
3975 
3976     VMThread::wait_for_vm_thread_exit();
3977     assert(SafepointSynchronize::is_at_safepoint(), "VM thread should exit at Safepoint");
3978     VMThread::destroy();
3979   }
3980 
3981   // clean up ideal graph printers
3982 #if defined(COMPILER2) && !defined(PRODUCT)
3983   IdealGraphPrinter::clean_up();
3984 #endif
3985 
3986   // Now, all Java threads are gone except daemon threads. Daemon threads
3987   // running Java code or in VM are stopped by the Safepoint. However,
3988   // daemon threads executing native code are still running.  But they
3989   // will be stopped at native=>Java/VM barriers. Note that we can't
3990   // simply kill or suspend them, as it is inherently deadlock-prone.
3991 
3992 #ifndef PRODUCT