Mercurial > hg > truffle
comparison src/os/windows/vm/os_windows.cpp @ 2204:63d374c54045
7014918: Improve core/minidump handling in Hotspot
Summary: Added Minidump support on Windows, enabled large page core dumps when coredump_filter is present and writing out path/rlimit for core dumps.
Reviewed-by: poonam, dsamersoff, sla, coleenp
author | ctornqvi |
---|---|
date | Wed, 09 Feb 2011 11:08:10 +0100 |
parents | 34d64ad817f4 |
children | b83527d0482d |
comparison
equal
deleted
inserted
replaced
2203:5197f3d713a1 | 2204:63d374c54045 |
---|---|
1 /* | 1 /* |
2 * CopyrighT (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
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 |
3272 intx os::win32::_os_thread_limit = 0; | 3346 intx os::win32::_os_thread_limit = 0; |
3273 volatile intx os::win32::_os_thread_count = 0; | 3347 volatile intx os::win32::_os_thread_count = 0; |
3274 | 3348 |
3275 bool os::win32::_is_nt = false; | 3349 bool os::win32::_is_nt = false; |
3276 bool os::win32::_is_windows_2003 = false; | 3350 bool os::win32::_is_windows_2003 = false; |
3277 | 3351 bool os::win32::_is_windows_server = false; |
3278 | 3352 |
3279 void os::win32::initialize_system_info() { | 3353 void os::win32::initialize_system_info() { |
3280 SYSTEM_INFO si; | 3354 SYSTEM_INFO si; |
3281 GetSystemInfo(&si); | 3355 GetSystemInfo(&si); |
3282 _vm_page_size = si.dwPageSize; | 3356 _vm_page_size = si.dwPageSize; |
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 } |