comparison src/os/windows/vm/os_windows.cpp @ 20804:7848fc12602b

Merge with jdk8u40-b25
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Tue, 07 Apr 2015 14:58:49 +0200
parents 52b4284cb496 09259e52a610
children be896a1983c0
comparison
equal deleted inserted replaced
20184:84105dcdb05b 20804:7848fc12602b
49 #include "runtime/interfaceSupport.hpp" 49 #include "runtime/interfaceSupport.hpp"
50 #include "runtime/java.hpp" 50 #include "runtime/java.hpp"
51 #include "runtime/javaCalls.hpp" 51 #include "runtime/javaCalls.hpp"
52 #include "runtime/mutexLocker.hpp" 52 #include "runtime/mutexLocker.hpp"
53 #include "runtime/objectMonitor.hpp" 53 #include "runtime/objectMonitor.hpp"
54 #include "runtime/orderAccess.inline.hpp"
54 #include "runtime/osThread.hpp" 55 #include "runtime/osThread.hpp"
55 #include "runtime/perfMemory.hpp" 56 #include "runtime/perfMemory.hpp"
56 #include "runtime/sharedRuntime.hpp" 57 #include "runtime/sharedRuntime.hpp"
57 #include "runtime/statSampler.hpp" 58 #include "runtime/statSampler.hpp"
58 #include "runtime/stubRoutines.hpp" 59 #include "runtime/stubRoutines.hpp"
128 timeBeginPeriod(1L); 129 timeBeginPeriod(1L);
129 break; 130 break;
130 case DLL_PROCESS_DETACH: 131 case DLL_PROCESS_DETACH:
131 if(ForceTimeHighResolution) 132 if(ForceTimeHighResolution)
132 timeEndPeriod(1L); 133 timeEndPeriod(1L);
134
133 break; 135 break;
134 default: 136 default:
135 break; 137 break;
136 } 138 }
137 return true; 139 return true;
150 bool os::getenv(const char* name, char* buffer, int len) { 152 bool os::getenv(const char* name, char* buffer, int len) {
151 int result = GetEnvironmentVariable(name, buffer, len); 153 int result = GetEnvironmentVariable(name, buffer, len);
152 return result > 0 && result < len; 154 return result > 0 && result < len;
153 } 155 }
154 156
157 bool os::unsetenv(const char* name) {
158 assert(name != NULL, "Null pointer");
159 return (SetEnvironmentVariable(name, NULL) == TRUE);
160 }
155 161
156 // No setuid programs under Windows. 162 // No setuid programs under Windows.
157 bool os::have_special_privileges() { 163 bool os::have_special_privileges() {
158 return false; 164 return false;
159 } 165 }
308 /* 314 /*
309 * RtlCaptureStackBackTrace Windows API may not exist prior to Windows XP. 315 * RtlCaptureStackBackTrace Windows API may not exist prior to Windows XP.
310 * So far, this method is only used by Native Memory Tracking, which is 316 * So far, this method is only used by Native Memory Tracking, which is
311 * only supported on Windows XP or later. 317 * only supported on Windows XP or later.
312 */ 318 */
313 address os::get_caller_pc(int n) { 319
320 int os::get_native_stack(address* stack, int frames, int toSkip) {
314 #ifdef _NMT_NOINLINE_ 321 #ifdef _NMT_NOINLINE_
315 n ++; 322 toSkip ++;
316 #endif 323 #endif
317 address pc; 324 int captured = Kernel32Dll::RtlCaptureStackBackTrace(toSkip + 1, frames,
318 if (os::Kernel32Dll::RtlCaptureStackBackTrace(n + 1, 1, (PVOID*)&pc, NULL) == 1) { 325 (PVOID*)stack, NULL);
319 return pc; 326 for (int index = captured; index < frames; index ++) {
320 } 327 stack[index] = NULL;
321 return NULL; 328 }
329 return captured;
322 } 330 }
323 331
324 332
325 // os::current_stack_base() 333 // os::current_stack_base()
326 // 334 //
1640 os::win32::print_windows_version(st); 1648 os::win32::print_windows_version(st);
1641 } 1649 }
1642 1650
1643 void os::win32::print_windows_version(outputStream* st) { 1651 void os::win32::print_windows_version(outputStream* st) {
1644 OSVERSIONINFOEX osvi; 1652 OSVERSIONINFOEX osvi;
1645 SYSTEM_INFO si; 1653 VS_FIXEDFILEINFO *file_info;
1646 1654 TCHAR kernel32_path[MAX_PATH];
1655 UINT len, ret;
1656
1657 // Use the GetVersionEx information to see if we're on a server or
1658 // workstation edition of Windows. Starting with Windows 8.1 we can't
1659 // trust the OS version information returned by this API.
1647 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); 1660 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
1648 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); 1661 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
1649
1650 if (!GetVersionEx((OSVERSIONINFO *)&osvi)) { 1662 if (!GetVersionEx((OSVERSIONINFO *)&osvi)) {
1651 st->print_cr("N/A"); 1663 st->print_cr("Call to GetVersionEx failed");
1652 return; 1664 return;
1653 } 1665 }
1654 1666 bool is_workstation = (osvi.wProductType == VER_NT_WORKSTATION);
1655 int os_vers = osvi.dwMajorVersion * 1000 + osvi.dwMinorVersion; 1667
1656 1668 // Get the full path to \Windows\System32\kernel32.dll and use that for
1669 // determining what version of Windows we're running on.
1670 len = MAX_PATH - (UINT)strlen("\\kernel32.dll") - 1;
1671 ret = GetSystemDirectory(kernel32_path, len);
1672 if (ret == 0 || ret > len) {
1673 st->print_cr("Call to GetSystemDirectory failed");
1674 return;
1675 }
1676 strncat(kernel32_path, "\\kernel32.dll", MAX_PATH - ret);
1677
1678 DWORD version_size = GetFileVersionInfoSize(kernel32_path, NULL);
1679 if (version_size == 0) {
1680 st->print_cr("Call to GetFileVersionInfoSize failed");
1681 return;
1682 }
1683
1684 LPTSTR version_info = (LPTSTR)os::malloc(version_size, mtInternal);
1685 if (version_info == NULL) {
1686 st->print_cr("Failed to allocate version_info");
1687 return;
1688 }
1689
1690 if (!GetFileVersionInfo(kernel32_path, NULL, version_size, version_info)) {
1691 os::free(version_info);
1692 st->print_cr("Call to GetFileVersionInfo failed");
1693 return;
1694 }
1695
1696 if (!VerQueryValue(version_info, TEXT("\\"), (LPVOID*)&file_info, &len)) {
1697 os::free(version_info);
1698 st->print_cr("Call to VerQueryValue failed");
1699 return;
1700 }
1701
1702 int major_version = HIWORD(file_info->dwProductVersionMS);
1703 int minor_version = LOWORD(file_info->dwProductVersionMS);
1704 int build_number = HIWORD(file_info->dwProductVersionLS);
1705 int build_minor = LOWORD(file_info->dwProductVersionLS);
1706 int os_vers = major_version * 1000 + minor_version;
1707 os::free(version_info);
1708
1709 st->print(" Windows ");
1710 switch (os_vers) {
1711
1712 case 6000:
1713 if (is_workstation) {
1714 st->print("Vista");
1715 } else {
1716 st->print("Server 2008");
1717 }
1718 break;
1719
1720 case 6001:
1721 if (is_workstation) {
1722 st->print("7");
1723 } else {
1724 st->print("Server 2008 R2");
1725 }
1726 break;
1727
1728 case 6002:
1729 if (is_workstation) {
1730 st->print("8");
1731 } else {
1732 st->print("Server 2012");
1733 }
1734 break;
1735
1736 case 6003:
1737 if (is_workstation) {
1738 st->print("8.1");
1739 } else {
1740 st->print("Server 2012 R2");
1741 }
1742 break;
1743
1744 case 6004:
1745 if (is_workstation) {
1746 st->print("10");
1747 } else {
1748 // The server version name of Windows 10 is not known at this time
1749 st->print("%d.%d", major_version, minor_version);
1750 }
1751 break;
1752
1753 default:
1754 // Unrecognized windows, print out its major and minor versions
1755 st->print("%d.%d", major_version, minor_version);
1756 break;
1757 }
1758
1759 // Retrieve SYSTEM_INFO from GetNativeSystemInfo call so that we could
1760 // find out whether we are running on 64 bit processor or not
1761 SYSTEM_INFO si;
1657 ZeroMemory(&si, sizeof(SYSTEM_INFO)); 1762 ZeroMemory(&si, sizeof(SYSTEM_INFO));
1658 if (os_vers >= 5002) { 1763 os::Kernel32Dll::GetNativeSystemInfo(&si);
1659 // Retrieve SYSTEM_INFO from GetNativeSystemInfo call so that we could 1764 if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) {
1660 // find out whether we are running on 64 bit processor or not.
1661 if (os::Kernel32Dll::GetNativeSystemInfoAvailable()) {
1662 os::Kernel32Dll::GetNativeSystemInfo(&si);
1663 } else {
1664 GetSystemInfo(&si);
1665 }
1666 }
1667
1668 if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
1669 switch (os_vers) {
1670 case 3051: st->print(" Windows NT 3.51"); break;
1671 case 4000: st->print(" Windows NT 4.0"); break;
1672 case 5000: st->print(" Windows 2000"); break;
1673 case 5001: st->print(" Windows XP"); break;
1674 case 5002:
1675 if (osvi.wProductType == VER_NT_WORKSTATION &&
1676 si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) {
1677 st->print(" Windows XP x64 Edition");
1678 } else {
1679 st->print(" Windows Server 2003 family");
1680 }
1681 break;
1682
1683 case 6000:
1684 if (osvi.wProductType == VER_NT_WORKSTATION) {
1685 st->print(" Windows Vista");
1686 } else {
1687 st->print(" Windows Server 2008");
1688 }
1689 break;
1690
1691 case 6001:
1692 if (osvi.wProductType == VER_NT_WORKSTATION) {
1693 st->print(" Windows 7");
1694 } else {
1695 st->print(" Windows Server 2008 R2");
1696 }
1697 break;
1698
1699 case 6002:
1700 if (osvi.wProductType == VER_NT_WORKSTATION) {
1701 st->print(" Windows 8");
1702 } else {
1703 st->print(" Windows Server 2012");
1704 }
1705 break;
1706
1707 case 6003:
1708 if (osvi.wProductType == VER_NT_WORKSTATION) {
1709 st->print(" Windows 8.1");
1710 } else {
1711 st->print(" Windows Server 2012 R2");
1712 }
1713 break;
1714
1715 default: // future os
1716 // Unrecognized windows, print out its major and minor versions
1717 st->print(" Windows NT %d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion);
1718 }
1719 } else {
1720 switch (os_vers) {
1721 case 4000: st->print(" Windows 95"); break;
1722 case 4010: st->print(" Windows 98"); break;
1723 case 4090: st->print(" Windows Me"); break;
1724 default: // future windows, print out its major and minor versions
1725 st->print(" Windows %d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion);
1726 }
1727 }
1728
1729 if (os_vers >= 6000 && si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) {
1730 st->print(" , 64 bit"); 1765 st->print(" , 64 bit");
1731 } 1766 }
1732 1767
1733 st->print(" Build %d", osvi.dwBuildNumber); 1768 st->print(" Build %d", build_number);
1734 st->print(" %s", osvi.szCSDVersion); // service pack 1769 st->print(" (%d.%d.%d.%d)", major_version, minor_version, build_number, build_minor);
1735 st->cr(); 1770 st->cr();
1736 } 1771 }
1737 1772
1738 void os::pd_print_cpu_info(outputStream* st) { 1773 void os::pd_print_cpu_info(outputStream* st) {
1739 // Nothing to do for now. 1774 // Nothing to do for now.
2914 size_of_reserve, // size of Reserve 2949 size_of_reserve, // size of Reserve
2915 MEM_RESERVE, 2950 MEM_RESERVE,
2916 PAGE_READWRITE); 2951 PAGE_READWRITE);
2917 // If reservation failed, return NULL 2952 // If reservation failed, return NULL
2918 if (p_buf == NULL) return NULL; 2953 if (p_buf == NULL) return NULL;
2919 MemTracker::record_virtual_memory_reserve((address)p_buf, size_of_reserve, mtNone, CALLER_PC); 2954 MemTracker::record_virtual_memory_reserve((address)p_buf, size_of_reserve, CALLER_PC);
2920 os::release_memory(p_buf, bytes + chunk_size); 2955 os::release_memory(p_buf, bytes + chunk_size);
2921 2956
2922 // we still need to round up to a page boundary (in case we are using large pages) 2957 // we still need to round up to a page boundary (in case we are using large pages)
2923 // but not to a chunk boundary (in case InterleavingGranularity doesn't align with page size) 2958 // but not to a chunk boundary (in case InterleavingGranularity doesn't align with page size)
2924 // instead we handle this in the bytes_to_rq computation below 2959 // instead we handle this in the bytes_to_rq computation below
2980 size_t bytes_to_release = bytes - bytes_remaining; 3015 size_t bytes_to_release = bytes - bytes_remaining;
2981 // NMT has yet to record any individual blocks, so it 3016 // NMT has yet to record any individual blocks, so it
2982 // need to create a dummy 'reserve' record to match 3017 // need to create a dummy 'reserve' record to match
2983 // the release. 3018 // the release.
2984 MemTracker::record_virtual_memory_reserve((address)p_buf, 3019 MemTracker::record_virtual_memory_reserve((address)p_buf,
2985 bytes_to_release, mtNone, CALLER_PC); 3020 bytes_to_release, CALLER_PC);
2986 os::release_memory(p_buf, bytes_to_release); 3021 os::release_memory(p_buf, bytes_to_release);
2987 } 3022 }
2988 #ifdef ASSERT 3023 #ifdef ASSERT
2989 if (should_inject_error) { 3024 if (should_inject_error) {
2990 if (TracePageSizes && Verbose) { 3025 if (TracePageSizes && Verbose) {
2999 next_alloc_addr += bytes_to_rq; 3034 next_alloc_addr += bytes_to_rq;
3000 count++; 3035 count++;
3001 } 3036 }
3002 // Although the memory is allocated individually, it is returned as one. 3037 // Although the memory is allocated individually, it is returned as one.
3003 // NMT records it as one block. 3038 // NMT records it as one block.
3004 address pc = CALLER_PC;
3005 if ((flags & MEM_COMMIT) != 0) { 3039 if ((flags & MEM_COMMIT) != 0) {
3006 MemTracker::record_virtual_memory_reserve_and_commit((address)p_buf, bytes, mtNone, pc); 3040 MemTracker::record_virtual_memory_reserve_and_commit((address)p_buf, bytes, CALLER_PC);
3007 } else { 3041 } else {
3008 MemTracker::record_virtual_memory_reserve((address)p_buf, bytes, mtNone, pc); 3042 MemTracker::record_virtual_memory_reserve((address)p_buf, bytes, CALLER_PC);
3009 } 3043 }
3010 3044
3011 // made it this far, success 3045 // made it this far, success
3012 return p_buf; 3046 return p_buf;
3013 } 3047 }
3201 } 3235 }
3202 // normal policy just allocate it all at once 3236 // normal policy just allocate it all at once
3203 DWORD flag = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES; 3237 DWORD flag = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES;
3204 char * res = (char *)VirtualAlloc(addr, bytes, flag, prot); 3238 char * res = (char *)VirtualAlloc(addr, bytes, flag, prot);
3205 if (res != NULL) { 3239 if (res != NULL) {
3206 address pc = CALLER_PC; 3240 MemTracker::record_virtual_memory_reserve_and_commit((address)res, bytes, CALLER_PC);
3207 MemTracker::record_virtual_memory_reserve_and_commit((address)res, bytes, mtNone, pc);
3208 } 3241 }
3209 3242
3210 return res; 3243 return res;
3211 } 3244 }
3212 } 3245 }
5365 5398
5366 inline BOOL os::Kernel32Dll::Module32Next(HANDLE hSnapshot,LPMODULEENTRY32 lpme) { 5399 inline BOOL os::Kernel32Dll::Module32Next(HANDLE hSnapshot,LPMODULEENTRY32 lpme) {
5367 return ::Module32Next(hSnapshot, lpme); 5400 return ::Module32Next(hSnapshot, lpme);
5368 } 5401 }
5369 5402
5370
5371 inline BOOL os::Kernel32Dll::GetNativeSystemInfoAvailable() {
5372 return true;
5373 }
5374
5375 inline void os::Kernel32Dll::GetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo) { 5403 inline void os::Kernel32Dll::GetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo) {
5376 ::GetNativeSystemInfo(lpSystemInfo); 5404 ::GetNativeSystemInfo(lpSystemInfo);
5377 } 5405 }
5378 5406
5379 // PSAPI API 5407 // PSAPI API