418 // data, and they will be stopped during state transition. In theory, we 419 // don't have to wait for user threads to be quiescent, but it's always 420 // better to terminate VM when current thread is the only active thread, so 421 // wait for user threads too. Numbers are in 10 milliseconds. 422 int max_wait_user_thread = 30; // at least 300 milliseconds 423 int max_wait_compiler_thread = 1000; // at least 10 seconds 424 425 int max_wait = max_wait_compiler_thread; 426 427 int attempts = 0; 428 JavaThreadIteratorWithHandle jtiwh; 429 while (true) { 430 int num_active = 0; 431 int num_active_compiler_thread = 0; 432 433 jtiwh.rewind(); 434 for (; JavaThread *thr = jtiwh.next(); ) { 435 if (thr!=thr_cur && thr->thread_state() == _thread_in_native) { 436 num_active++; 437 if (thr->is_Compiler_thread()) { 438 CompilerThread* ct = (CompilerThread*) thr; 439 if (ct->compiler() == NULL || !ct->compiler()->is_jvmci()) { 440 num_active_compiler_thread++; 441 } else { 442 // When using a Java based JVMCI compiler, it's possible 443 // for one compiler thread to grab a Java lock, enter 444 // HotSpot and go to sleep on the shutdown safepoint. 445 // Another JVMCI compiler thread can then attempt grab 446 // the lock and thus never make progress. 447 } 448 } 449 } 450 } 451 452 if (num_active == 0) { 453 return 0; 454 } else if (attempts > max_wait) { 455 return num_active; 456 } else if (num_active_compiler_thread == 0 && attempts > max_wait_user_thread) { 457 return num_active; 458 } 459 460 attempts++; 461 462 MutexLockerEx ml(&timer, Mutex::_no_safepoint_check_flag); 463 timer.wait(Mutex::_no_safepoint_check_flag, 10); 464 } 465 } 466 467 void VM_Exit::doit() { | 418 // data, and they will be stopped during state transition. In theory, we 419 // don't have to wait for user threads to be quiescent, but it's always 420 // better to terminate VM when current thread is the only active thread, so 421 // wait for user threads too. Numbers are in 10 milliseconds. 422 int max_wait_user_thread = 30; // at least 300 milliseconds 423 int max_wait_compiler_thread = 1000; // at least 10 seconds 424 425 int max_wait = max_wait_compiler_thread; 426 427 int attempts = 0; 428 JavaThreadIteratorWithHandle jtiwh; 429 while (true) { 430 int num_active = 0; 431 int num_active_compiler_thread = 0; 432 433 jtiwh.rewind(); 434 for (; JavaThread *thr = jtiwh.next(); ) { 435 if (thr!=thr_cur && thr->thread_state() == _thread_in_native) { 436 num_active++; 437 if (thr->is_Compiler_thread()) { 438 #if INCLUDE_JVMCI 439 CompilerThread* ct = (CompilerThread*) thr; 440 if (ct->compiler() == NULL || !ct->compiler()->is_jvmci() || !UseJVMCINativeLibrary) { 441 num_active_compiler_thread++; 442 } else { 443 // When using a compiler in a JVMCI shared library, it's possible 444 // for one compiler thread to grab a lock in the shared library, 445 // enter HotSpot and go to sleep on the shutdown safepoint. Another 446 // JVMCI shared library compiler thread can then attempt to grab the 447 // lock and thus never make progress. 448 } 449 #else 450 num_active_compiler_thread++; 451 #endif 452 } 453 } 454 } 455 456 if (num_active == 0) { 457 return 0; 458 } else if (attempts > max_wait) { 459 return num_active; 460 } else if (num_active_compiler_thread == 0 && attempts > max_wait_user_thread) { 461 return num_active; 462 } 463 464 attempts++; 465 466 MutexLockerEx ml(&timer, Mutex::_no_safepoint_check_flag); 467 timer.wait(Mutex::_no_safepoint_check_flag, 10); 468 } 469 } 470 471 void VM_Exit::doit() { |