4195 // + Shutdown native memory tracking if it is on
4196 // + Wait until we are the last non-daemon thread to execute
4197 // <-- every thing is still working at this moment -->
4198 // + Call java.lang.Shutdown.shutdown(), which will invoke Java level
4199 // shutdown hooks
4200 // + Call before_exit(), prepare for VM exit
4201 // > run VM level shutdown hooks (they are registered through JVM_OnExit(),
4202 // currently the only user of this mechanism is File.deleteOnExit())
4203 // > stop StatSampler, watcher thread, CMS threads,
4204 // post thread end and vm death events to JVMTI,
4205 // stop signal thread
4206 // + Call JavaThread::exit(), it will:
4207 // > release JNI handle blocks, remove stack guard pages
4208 // > remove this thread from Threads list
4209 // <-- no more Java code from this thread after this point -->
4210 // + Stop VM thread, it will bring the remaining VM to a safepoint and stop
4211 // the compiler threads at safepoint
4212 // <-- do not use anything that could get blocked by Safepoint -->
4213 // + Disable tracing at JNI/JVM barriers
4214 // + Set _vm_exited flag for threads that are still running native code
4215 // + Delete this thread
4216 // + Call exit_globals()
4217 // > deletes tty
4218 // > deletes PerfMemory resources
4219 // + Return to caller
4220
4221 bool Threads::destroy_vm() {
4222 JavaThread* thread = JavaThread::current();
4223
4224 #ifdef ASSERT
4225 _vm_complete = false;
4226 #endif
4227 // Wait until we are the last non-daemon thread to execute
4228 { MutexLocker nu(Threads_lock);
4229 while (Threads::number_of_non_daemon_threads() > 1)
4230 // This wait should make safepoint checks, wait without a timeout,
4231 // and wait as a suspend-equivalent condition.
4232 Threads_lock->wait(!Mutex::_no_safepoint_check_flag, 0,
4233 Mutex::_as_suspend_equivalent_flag);
4234 }
4235
4236 EventShutdown e;
4237 if (e.should_commit()) {
4238 e.set_reason("No remaining non-daemon Java threads");
4274 // Now, all Java threads are gone except daemon threads. Daemon threads
4275 // running Java code or in VM are stopped by the Safepoint. However,
4276 // daemon threads executing native code are still running. But they
4277 // will be stopped at native=>Java/VM barriers. Note that we can't
4278 // simply kill or suspend them, as it is inherently deadlock-prone.
4279
4280 VM_Exit::set_vm_exited();
4281
4282 // Clean up ideal graph printers after the VMThread has started
4283 // the final safepoint which will block all the Compiler threads.
4284 // Note that this Thread has already logically exited so the
4285 // clean_up() function's use of a JavaThreadIteratorWithHandle
4286 // would be a problem except set_vm_exited() has remembered the
4287 // shutdown thread which is granted a policy exception.
4288 #if defined(COMPILER2) && !defined(PRODUCT)
4289 IdealGraphPrinter::clean_up();
4290 #endif
4291
4292 notify_vm_shutdown();
4293
4294 // We are after VM_Exit::set_vm_exited() so we can't call
4295 // thread->smr_delete() or we will block on the Threads_lock.
4296 // Deleting the shutdown thread here is safe because another
4297 // JavaThread cannot have an active ThreadsListHandle for
4298 // this JavaThread.
4299 delete thread;
4300
4301 #if INCLUDE_JVMCI
4302 if (JVMCICounterSize > 0) {
4303 FREE_C_HEAP_ARRAY(jlong, JavaThread::_jvmci_old_thread_counters);
4304 }
4305 #endif
4306
4307 // exit_globals() will delete tty
4308 exit_globals();
4309
4310 LogConfiguration::finalize();
4311
4312 return true;
4313 }
4314
4315
4316 jboolean Threads::is_supported_jni_version_including_1_1(jint version) {
4317 if (version == JNI_VERSION_1_1) return JNI_TRUE;
4318 return is_supported_jni_version(version);
4319 }
4320
4321
4322 jboolean Threads::is_supported_jni_version(jint version) {
4323 if (version == JNI_VERSION_1_2) return JNI_TRUE;
4324 if (version == JNI_VERSION_1_4) return JNI_TRUE;
4325 if (version == JNI_VERSION_1_6) return JNI_TRUE;
4326 if (version == JNI_VERSION_1_8) return JNI_TRUE;
4327 if (version == JNI_VERSION_9) return JNI_TRUE;
4328 if (version == JNI_VERSION_10) return JNI_TRUE;
|
4195 // + Shutdown native memory tracking if it is on
4196 // + Wait until we are the last non-daemon thread to execute
4197 // <-- every thing is still working at this moment -->
4198 // + Call java.lang.Shutdown.shutdown(), which will invoke Java level
4199 // shutdown hooks
4200 // + Call before_exit(), prepare for VM exit
4201 // > run VM level shutdown hooks (they are registered through JVM_OnExit(),
4202 // currently the only user of this mechanism is File.deleteOnExit())
4203 // > stop StatSampler, watcher thread, CMS threads,
4204 // post thread end and vm death events to JVMTI,
4205 // stop signal thread
4206 // + Call JavaThread::exit(), it will:
4207 // > release JNI handle blocks, remove stack guard pages
4208 // > remove this thread from Threads list
4209 // <-- no more Java code from this thread after this point -->
4210 // + Stop VM thread, it will bring the remaining VM to a safepoint and stop
4211 // the compiler threads at safepoint
4212 // <-- do not use anything that could get blocked by Safepoint -->
4213 // + Disable tracing at JNI/JVM barriers
4214 // + Set _vm_exited flag for threads that are still running native code
4215 // + Call exit_globals()
4216 // > deletes tty
4217 // > deletes PerfMemory resources
4218 // + Delete this thread
4219 // + Return to caller
4220
4221 bool Threads::destroy_vm() {
4222 JavaThread* thread = JavaThread::current();
4223
4224 #ifdef ASSERT
4225 _vm_complete = false;
4226 #endif
4227 // Wait until we are the last non-daemon thread to execute
4228 { MutexLocker nu(Threads_lock);
4229 while (Threads::number_of_non_daemon_threads() > 1)
4230 // This wait should make safepoint checks, wait without a timeout,
4231 // and wait as a suspend-equivalent condition.
4232 Threads_lock->wait(!Mutex::_no_safepoint_check_flag, 0,
4233 Mutex::_as_suspend_equivalent_flag);
4234 }
4235
4236 EventShutdown e;
4237 if (e.should_commit()) {
4238 e.set_reason("No remaining non-daemon Java threads");
4274 // Now, all Java threads are gone except daemon threads. Daemon threads
4275 // running Java code or in VM are stopped by the Safepoint. However,
4276 // daemon threads executing native code are still running. But they
4277 // will be stopped at native=>Java/VM barriers. Note that we can't
4278 // simply kill or suspend them, as it is inherently deadlock-prone.
4279
4280 VM_Exit::set_vm_exited();
4281
4282 // Clean up ideal graph printers after the VMThread has started
4283 // the final safepoint which will block all the Compiler threads.
4284 // Note that this Thread has already logically exited so the
4285 // clean_up() function's use of a JavaThreadIteratorWithHandle
4286 // would be a problem except set_vm_exited() has remembered the
4287 // shutdown thread which is granted a policy exception.
4288 #if defined(COMPILER2) && !defined(PRODUCT)
4289 IdealGraphPrinter::clean_up();
4290 #endif
4291
4292 notify_vm_shutdown();
4293
4294 // exit_globals() will delete tty
4295 exit_globals();
4296
4297 // We are after VM_Exit::set_vm_exited() so we can't call
4298 // thread->smr_delete() or we will block on the Threads_lock.
4299 // Deleting the shutdown thread here is safe because another
4300 // JavaThread cannot have an active ThreadsListHandle for
4301 // this JavaThread.
4302 delete thread;
4303
4304 #if INCLUDE_JVMCI
4305 if (JVMCICounterSize > 0) {
4306 FREE_C_HEAP_ARRAY(jlong, JavaThread::_jvmci_old_thread_counters);
4307 }
4308 #endif
4309
4310 LogConfiguration::finalize();
4311
4312 return true;
4313 }
4314
4315
4316 jboolean Threads::is_supported_jni_version_including_1_1(jint version) {
4317 if (version == JNI_VERSION_1_1) return JNI_TRUE;
4318 return is_supported_jni_version(version);
4319 }
4320
4321
4322 jboolean Threads::is_supported_jni_version(jint version) {
4323 if (version == JNI_VERSION_1_2) return JNI_TRUE;
4324 if (version == JNI_VERSION_1_4) return JNI_TRUE;
4325 if (version == JNI_VERSION_1_6) return JNI_TRUE;
4326 if (version == JNI_VERSION_1_8) return JNI_TRUE;
4327 if (version == JNI_VERSION_9) return JNI_TRUE;
4328 if (version == JNI_VERSION_10) return JNI_TRUE;
|