20 * or visit www.oracle.com if you need additional information or have any |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 * |
22 * |
23 */ |
23 */ |
24 |
24 |
25 // Must be at least Windows 2000 or XP to use IsDebuggerPresent |
25 // Must be at least Windows Vista or Server 2008 to use InitOnceExecuteOnce |
26 #define _WIN32_WINNT 0x500 |
26 #define _WIN32_WINNT 0x0600 |
27 |
27 |
28 // no precompiled headers |
28 // no precompiled headers |
29 #include "classfile/classLoader.hpp" |
29 #include "classfile/classLoader.hpp" |
30 #include "classfile/systemDictionary.hpp" |
30 #include "classfile/systemDictionary.hpp" |
31 #include "classfile/vmSymbols.hpp" |
31 #include "classfile/vmSymbols.hpp" |
407 return NULL; |
407 return NULL; |
408 } |
408 } |
409 |
409 |
410 LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo); |
410 LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo); |
411 |
411 |
412 extern jint volatile vm_getting_terminated; |
|
413 |
|
414 // Thread start routine for all new Java threads |
412 // Thread start routine for all new Java threads |
415 static unsigned __stdcall java_start(Thread* thread) { |
413 static unsigned __stdcall java_start(Thread* thread) { |
416 // Try to randomize the cache line index of hot stack frames. |
414 // Try to randomize the cache line index of hot stack frames. |
417 // This helps when threads of the same stack traces evict each other's |
415 // This helps when threads of the same stack traces evict each other's |
418 // cache lines. The threads can be either from the same JVM instance, or |
416 // cache lines. The threads can be either from the same JVM instance, or |
430 if (lgrp_id != -1) { |
428 if (lgrp_id != -1) { |
431 thread->set_lgrp_id(lgrp_id); |
429 thread->set_lgrp_id(lgrp_id); |
432 } |
430 } |
433 } |
431 } |
434 |
432 |
435 // Diagnostic code to investigate JDK-6573254 (Part I) |
433 // Diagnostic code to investigate JDK-6573254 |
436 unsigned res = 90115; // non-java thread |
434 int res = 90115; // non-java thread |
437 if (thread->is_Java_thread()) { |
435 if (thread->is_Java_thread()) { |
438 JavaThread* java_thread = (JavaThread*)thread; |
436 res = 60115; // java thread |
439 res = java_lang_Thread::is_daemon(java_thread->threadObj()) |
|
440 ? 70115 // java daemon thread |
|
441 : 80115; // java non-daemon thread |
|
442 } |
437 } |
443 |
438 |
444 // Install a win32 structured exception handler around every thread created |
439 // Install a win32 structured exception handler around every thread created |
445 // by VM, so VM can generate error dump when an exception occurred in non- |
440 // by VM, so VM can generate error dump when an exception occurred in non- |
446 // Java thread (e.g. VM thread). |
441 // Java thread (e.g. VM thread). |
456 // which frees the CodeHeap containing the Atomic::add code |
451 // which frees the CodeHeap containing the Atomic::add code |
457 if (thread != VMThread::vm_thread() && VMThread::vm_thread() != NULL) { |
452 if (thread != VMThread::vm_thread() && VMThread::vm_thread() != NULL) { |
458 Atomic::dec_ptr((intptr_t*)&os::win32::_os_thread_count); |
453 Atomic::dec_ptr((intptr_t*)&os::win32::_os_thread_count); |
459 } |
454 } |
460 |
455 |
461 // Diagnostic code to investigate JDK-6573254 (Part II) |
456 // Thread must not return from exit_process_or_thread(), but if it does, |
462 if (OrderAccess::load_acquire(&vm_getting_terminated)) { |
457 // let it proceed to exit normally |
463 return res; |
458 return (unsigned)os::win32::exit_process_or_thread(os::win32::EPT_THREAD, res); |
464 } |
|
465 |
|
466 return 0; |
|
467 } |
459 } |
468 |
460 |
469 static OSThread* create_os_thread(Thread* thread, HANDLE thread_handle, int thread_id) { |
461 static OSThread* create_os_thread(Thread* thread, HANDLE thread_handle, int thread_id) { |
470 // Allocate the OSThread object |
462 // Allocate the OSThread object |
471 OSThread* osthread = new OSThread(NULL, NULL); |
463 OSThread* osthread = new OSThread(NULL, NULL); |
1060 |
1052 |
1061 CloseHandle(dumpFile); |
1053 CloseHandle(dumpFile); |
1062 } |
1054 } |
1063 |
1055 |
1064 |
1056 |
1065 |
1057 void os::abort(bool dump_core) { |
1066 void os::abort(bool dump_core) |
|
1067 { |
|
1068 os::shutdown(); |
1058 os::shutdown(); |
1069 // no core dump on Windows |
1059 // no core dump on Windows |
1070 ::exit(1); |
1060 win32::exit_process_or_thread(win32::EPT_PROCESS, 1); |
1071 } |
1061 } |
1072 |
1062 |
1073 // Die immediately, no exit hook, no abort hook, no cleanup. |
1063 // Die immediately, no exit hook, no abort hook, no cleanup. |
1074 void os::die() { |
1064 void os::die() { |
1075 _exit(-1); |
1065 win32::exit_process_or_thread(win32::EPT_PROCESS_DIE, -1); |
1076 } |
1066 } |
1077 |
1067 |
1078 // Directory routines copied from src/win32/native/java/io/dirent_md.c |
1068 // Directory routines copied from src/win32/native/java/io/dirent_md.c |
1079 // * dirent_md.c 1.15 00/02/02 |
1069 // * dirent_md.c 1.15 00/02/02 |
1080 // |
1070 // |
3630 |
3620 |
3631 bool os::win32::_is_nt = false; |
3621 bool os::win32::_is_nt = false; |
3632 bool os::win32::_is_windows_2003 = false; |
3622 bool os::win32::_is_windows_2003 = false; |
3633 bool os::win32::_is_windows_server = false; |
3623 bool os::win32::_is_windows_server = false; |
3634 |
3624 |
|
3625 // 6573254 |
|
3626 // Currently, the bug is observed across all the supported Windows releases, |
|
3627 // including the latest one (as of this writing - Windows Server 2012 R2) |
|
3628 bool os::win32::_has_exit_bug = true; |
3635 bool os::win32::_has_performance_count = 0; |
3629 bool os::win32::_has_performance_count = 0; |
3636 |
3630 |
3637 void os::win32::initialize_system_info() { |
3631 void os::win32::initialize_system_info() { |
3638 SYSTEM_INFO si; |
3632 SYSTEM_INFO si; |
3639 GetSystemInfo(&si); |
3633 GetSystemInfo(&si); |
3725 |
3719 |
3726 jio_snprintf(ebuf, ebuflen, |
3720 jio_snprintf(ebuf, ebuflen, |
3727 "os::win32::load_windows_dll() cannot load %s from system directories.", name); |
3721 "os::win32::load_windows_dll() cannot load %s from system directories.", name); |
3728 return NULL; |
3722 return NULL; |
3729 } |
3723 } |
|
3724 |
|
3725 #define MIN_EXIT_MUTEXES 1 |
|
3726 #define MAX_EXIT_MUTEXES 16 |
|
3727 |
|
3728 struct ExitMutexes { |
|
3729 DWORD count; |
|
3730 HANDLE handles[MAX_EXIT_MUTEXES]; |
|
3731 }; |
|
3732 |
|
3733 static BOOL CALLBACK init_muts_call(PINIT_ONCE, PVOID ppmuts, PVOID*) { |
|
3734 static ExitMutexes muts; |
|
3735 |
|
3736 muts.count = os::processor_count(); |
|
3737 if (muts.count < MIN_EXIT_MUTEXES) { |
|
3738 muts.count = MIN_EXIT_MUTEXES; |
|
3739 } else if (muts.count > MAX_EXIT_MUTEXES) { |
|
3740 muts.count = MAX_EXIT_MUTEXES; |
|
3741 } |
|
3742 |
|
3743 for (DWORD i = 0; i < muts.count; ++i) { |
|
3744 muts.handles[i] = CreateMutex(NULL, FALSE, NULL); |
|
3745 if (muts.handles[i] == NULL) { |
|
3746 return FALSE; |
|
3747 } |
|
3748 } |
|
3749 *((ExitMutexes**)ppmuts) = &muts; |
|
3750 return TRUE; |
|
3751 } |
|
3752 |
|
3753 int os::win32::exit_process_or_thread(Ept what, int exit_code) { |
|
3754 if (os::win32::has_exit_bug()) { |
|
3755 static INIT_ONCE init_once_muts = INIT_ONCE_STATIC_INIT; |
|
3756 static ExitMutexes* pmuts; |
|
3757 |
|
3758 if (!InitOnceExecuteOnce(&init_once_muts, init_muts_call, &pmuts, NULL)) { |
|
3759 warning("ExitMutex initialization failed in %s: %d\n", __FILE__, __LINE__); |
|
3760 } else if (WaitForMultipleObjects(pmuts->count, pmuts->handles, |
|
3761 (what != EPT_THREAD), // exiting process waits for all mutexes |
|
3762 INFINITE) == WAIT_FAILED) { |
|
3763 warning("ExitMutex acquisition failed in %s: %d\n", __FILE__, __LINE__); |
|
3764 } |
|
3765 } |
|
3766 |
|
3767 switch (what) { |
|
3768 case EPT_THREAD: |
|
3769 _endthreadex((unsigned)exit_code); |
|
3770 break; |
|
3771 |
|
3772 case EPT_PROCESS: |
|
3773 ::exit(exit_code); |
|
3774 break; |
|
3775 |
|
3776 case EPT_PROCESS_DIE: |
|
3777 _exit(exit_code); |
|
3778 break; |
|
3779 } |
|
3780 |
|
3781 // should not reach here |
|
3782 return exit_code; |
|
3783 } |
|
3784 |
|
3785 #undef MIN_EXIT_MUTEXES |
|
3786 #undef MAX_EXIT_MUTEXES |
3730 |
3787 |
3731 void os::win32::setmode_streams() { |
3788 void os::win32::setmode_streams() { |
3732 _setmode(_fileno(stdin), _O_BINARY); |
3789 _setmode(_fileno(stdin), _O_BINARY); |
3733 _setmode(_fileno(stdout), _O_BINARY); |
3790 _setmode(_fileno(stdout), _O_BINARY); |
3734 _setmode(_fileno(stderr), _O_BINARY); |
3791 _setmode(_fileno(stderr), _O_BINARY); |