912 abort_hook_t abort_hook = Arguments::abort_hook(); |
912 abort_hook_t abort_hook = Arguments::abort_hook(); |
913 if (abort_hook != NULL) { |
913 if (abort_hook != NULL) { |
914 abort_hook(); |
914 abort_hook(); |
915 } |
915 } |
916 } |
916 } |
|
917 |
|
918 |
|
919 static BOOL (WINAPI *_MiniDumpWriteDump) ( HANDLE, DWORD, HANDLE, MINIDUMP_TYPE, PMINIDUMP_EXCEPTION_INFORMATION, |
|
920 PMINIDUMP_USER_STREAM_INFORMATION, PMINIDUMP_CALLBACK_INFORMATION); |
|
921 |
|
922 void os::check_or_create_dump(void* exceptionRecord, void* contextRecord, char* buffer, size_t bufferSize) { |
|
923 HINSTANCE dbghelp; |
|
924 EXCEPTION_POINTERS ep; |
|
925 MINIDUMP_EXCEPTION_INFORMATION mei; |
|
926 HANDLE hProcess = GetCurrentProcess(); |
|
927 DWORD processId = GetCurrentProcessId(); |
|
928 HANDLE dumpFile; |
|
929 MINIDUMP_TYPE dumpType; |
|
930 static const char* cwd; |
|
931 |
|
932 // If running on a client version of Windows and user has not explicitly enabled dumping |
|
933 if (!os::win32::is_windows_server() && !CreateMinidumpOnCrash) { |
|
934 VMError::report_coredump_status("Minidumps are not enabled by default on client versions of Windows", false); |
|
935 return; |
|
936 // If running on a server version of Windows and user has explictly disabled dumping |
|
937 } else if (os::win32::is_windows_server() && !FLAG_IS_DEFAULT(CreateMinidumpOnCrash) && !CreateMinidumpOnCrash) { |
|
938 VMError::report_coredump_status("Minidump has been disabled from the command line", false); |
|
939 return; |
|
940 } |
|
941 |
|
942 dbghelp = LoadLibrary("DBGHELP.DLL"); |
|
943 |
|
944 if (dbghelp == NULL) { |
|
945 VMError::report_coredump_status("Failed to load dbghelp.dll", false); |
|
946 return; |
|
947 } |
|
948 |
|
949 _MiniDumpWriteDump = CAST_TO_FN_PTR( |
|
950 BOOL(WINAPI *)( HANDLE, DWORD, HANDLE, MINIDUMP_TYPE, PMINIDUMP_EXCEPTION_INFORMATION, |
|
951 PMINIDUMP_USER_STREAM_INFORMATION, PMINIDUMP_CALLBACK_INFORMATION), |
|
952 GetProcAddress(dbghelp, "MiniDumpWriteDump")); |
|
953 |
|
954 if (_MiniDumpWriteDump == NULL) { |
|
955 VMError::report_coredump_status("Failed to find MiniDumpWriteDump() in module dbghelp.dll", false); |
|
956 return; |
|
957 } |
|
958 |
|
959 dumpType = (MINIDUMP_TYPE)(MiniDumpWithFullMemory | MiniDumpWithFullMemoryInfo | |
|
960 MiniDumpWithHandleData | MiniDumpWithThreadInfo | MiniDumpWithUnloadedModules); |
|
961 |
|
962 |
|
963 cwd = get_current_directory(NULL, 0); |
|
964 jio_snprintf(buffer, bufferSize, "%s\\hs_err_pid%u.mdmp",cwd, current_process_id()); |
|
965 dumpFile = CreateFile(buffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
|
966 |
|
967 if (dumpFile == INVALID_HANDLE_VALUE) { |
|
968 VMError::report_coredump_status("Failed to create file for dumping", false); |
|
969 return; |
|
970 } |
|
971 |
|
972 ep.ContextRecord = (PCONTEXT) contextRecord; |
|
973 ep.ExceptionRecord = (PEXCEPTION_RECORD) exceptionRecord; |
|
974 |
|
975 mei.ThreadId = GetCurrentThreadId(); |
|
976 mei.ExceptionPointers = &ep; |
|
977 |
|
978 // Older versions of dbghelp.dll (the one shipped with Win2003 for example) may not support all |
|
979 // the dump types we really want. If first call fails, lets fall back to just use MiniDumpWithFullMemory then. |
|
980 if (_MiniDumpWriteDump(hProcess, processId, dumpFile, dumpType, &mei, NULL, NULL) == false && |
|
981 _MiniDumpWriteDump(hProcess, processId, dumpFile, (MINIDUMP_TYPE)MiniDumpWithFullMemory, &mei, NULL, NULL) == false) { |
|
982 VMError::report_coredump_status("Call to MiniDumpWriteDump() failed", false); |
|
983 } else { |
|
984 VMError::report_coredump_status(buffer, true); |
|
985 } |
|
986 |
|
987 CloseHandle(dumpFile); |
|
988 } |
|
989 |
|
990 |
917 |
991 |
918 void os::abort(bool dump_core) |
992 void os::abort(bool dump_core) |
919 { |
993 { |
920 os::shutdown(); |
994 os::shutdown(); |
921 // no core dump on Windows |
995 // no core dump on Windows |
3291 // also returns dwAvailPhys (free physical memory bytes), dwTotalVirtual, dwAvailVirtual, |
3365 // also returns dwAvailPhys (free physical memory bytes), dwTotalVirtual, dwAvailVirtual, |
3292 // dwMemoryLoad (% of memory in use) |
3366 // dwMemoryLoad (% of memory in use) |
3293 GlobalMemoryStatusEx(&ms); |
3367 GlobalMemoryStatusEx(&ms); |
3294 _physical_memory = ms.ullTotalPhys; |
3368 _physical_memory = ms.ullTotalPhys; |
3295 |
3369 |
3296 OSVERSIONINFO oi; |
3370 OSVERSIONINFOEX oi; |
3297 oi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); |
3371 oi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
3298 GetVersionEx(&oi); |
3372 GetVersionEx((OSVERSIONINFO*)&oi); |
3299 switch(oi.dwPlatformId) { |
3373 switch(oi.dwPlatformId) { |
3300 case VER_PLATFORM_WIN32_WINDOWS: _is_nt = false; break; |
3374 case VER_PLATFORM_WIN32_WINDOWS: _is_nt = false; break; |
3301 case VER_PLATFORM_WIN32_NT: |
3375 case VER_PLATFORM_WIN32_NT: |
3302 _is_nt = true; |
3376 _is_nt = true; |
3303 { |
3377 { |
3304 int os_vers = oi.dwMajorVersion * 1000 + oi.dwMinorVersion; |
3378 int os_vers = oi.dwMajorVersion * 1000 + oi.dwMinorVersion; |
3305 if (os_vers == 5002) { |
3379 if (os_vers == 5002) { |
3306 _is_windows_2003 = true; |
3380 _is_windows_2003 = true; |
|
3381 } |
|
3382 if (oi.wProductType == VER_NT_DOMAIN_CONTROLLER || |
|
3383 oi.wProductType == VER_NT_SERVER) { |
|
3384 _is_windows_server = true; |
3307 } |
3385 } |
3308 } |
3386 } |
3309 break; |
3387 break; |
3310 default: fatal("Unknown platform"); |
3388 default: fatal("Unknown platform"); |
3311 } |
3389 } |