os_windows.hpp revision 3465:d2a62e0f25eb
1/* 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. 4 * 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 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25#ifndef OS_WINDOWS_VM_OS_WINDOWS_HPP 26#define OS_WINDOWS_VM_OS_WINDOWS_HPP 27// Win32_OS defines the interface to windows operating systems 28 29class win32 { 30 friend class os; 31 32 protected: 33 static int _vm_page_size; 34 static int _vm_allocation_granularity; 35 static int _processor_type; 36 static int _processor_level; 37 static julong _physical_memory; 38 static size_t _default_stack_size; 39 static bool _is_nt; 40 static bool _is_windows_2003; 41 static bool _is_windows_server; 42 43 static void print_windows_version(outputStream* st); 44 45 public: 46 // Windows-specific interface: 47 static void initialize_system_info(); 48 static void setmode_streams(); 49 50 // Processor info as provided by NT 51 static int processor_type() { return _processor_type; } 52 // Processor level may not be accurate on non-NT systems 53 static int processor_level() { 54 assert(is_nt(), "use vm_version instead"); 55 return _processor_level; 56 } 57 static julong available_memory(); 58 static julong physical_memory() { return _physical_memory; } 59 60 // load dll from Windows system directory or Windows directory 61 static HINSTANCE load_Windows_dll(const char* name, char *ebuf, int ebuflen); 62 63 public: 64 // Generic interface: 65 66 // Trace number of created threads 67 static intx _os_thread_limit; 68 static volatile intx _os_thread_count; 69 70 // Tells whether the platform is NT or Windown95 71 static bool is_nt() { return _is_nt; } 72 73 // Tells whether this is a server version of Windows 74 static bool is_windows_server() { return _is_windows_server; } 75 76 // Tells whether the platform is Windows 2003 77 static bool is_windows_2003() { return _is_windows_2003; } 78 79 // Returns the byte size of a virtual memory page 80 static int vm_page_size() { return _vm_page_size; } 81 82 // Returns the size in bytes of memory blocks which can be allocated. 83 static int vm_allocation_granularity() { return _vm_allocation_granularity; } 84 85 // Read the headers for the executable that started the current process into 86 // the structure passed in (see winnt.h). 87 static void read_executable_headers(PIMAGE_NT_HEADERS); 88 89 // Default stack size for the current process. 90 static size_t default_stack_size() { return _default_stack_size; } 91 92#ifndef _WIN64 93 // A wrapper to install a structured exception handler for fast JNI accesors. 94 static address fast_jni_accessor_wrapper(BasicType); 95#endif 96 97 // filter function to ignore faults on serializations page 98 static LONG WINAPI serialize_fault_filter(struct _EXCEPTION_POINTERS* e); 99}; 100 101class PlatformEvent : public CHeapObj<mtInternal> { 102 private: 103 double CachePad [4] ; // increase odds that _Event is sole occupant of cache line 104 volatile int _Event ; 105 HANDLE _ParkHandle ; 106 107 public: // TODO-FIXME: make dtor private 108 ~PlatformEvent() { guarantee (0, "invariant") ; } 109 110 public: 111 PlatformEvent() { 112 _Event = 0 ; 113 _ParkHandle = CreateEvent (NULL, false, false, NULL) ; 114 guarantee (_ParkHandle != NULL, "invariant") ; 115 } 116 117 // Exercise caution using reset() and fired() - they may require MEMBARs 118 void reset() { _Event = 0 ; } 119 int fired() { return _Event; } 120 void park () ; 121 void unpark () ; 122 int park (jlong millis) ; 123} ; 124 125 126 127class PlatformParker : public CHeapObj<mtInternal> { 128 protected: 129 HANDLE _ParkEvent ; 130 131 public: 132 ~PlatformParker () { guarantee (0, "invariant") ; } 133 PlatformParker () { 134 _ParkEvent = CreateEvent (NULL, true, false, NULL) ; 135 guarantee (_ParkEvent != NULL, "invariant") ; 136 } 137 138} ; 139 140// JDK7 requires VS2010 141#if _MSC_VER < 1600 142#define JDK6_OR_EARLIER 1 143#endif 144 145 146 147class WinSock2Dll: AllStatic { 148public: 149 static BOOL WSAStartup(WORD, LPWSADATA); 150 static struct hostent* gethostbyname(const char *name); 151 static BOOL WinSock2Available(); 152#ifdef JDK6_OR_EARLIER 153private: 154 static int (PASCAL FAR* _WSAStartup)(WORD, LPWSADATA); 155 static struct hostent *(PASCAL FAR *_gethostbyname)(...); 156 static BOOL initialized; 157 158 static void initialize(); 159#endif 160}; 161 162class Kernel32Dll: AllStatic { 163public: 164 static BOOL SwitchToThread(); 165 static SIZE_T GetLargePageMinimum(); 166 167 static BOOL SwitchToThreadAvailable(); 168 static BOOL GetLargePageMinimumAvailable(); 169 170 // Help tools 171 static BOOL HelpToolsAvailable(); 172 static HANDLE CreateToolhelp32Snapshot(DWORD,DWORD); 173 static BOOL Module32First(HANDLE,LPMODULEENTRY32); 174 static BOOL Module32Next(HANDLE,LPMODULEENTRY32); 175 176 static BOOL GetNativeSystemInfoAvailable(); 177 static void GetNativeSystemInfo(LPSYSTEM_INFO); 178 179 // NUMA calls 180 static BOOL NumaCallsAvailable(); 181 static LPVOID VirtualAllocExNuma(HANDLE, LPVOID, SIZE_T, DWORD, DWORD, DWORD); 182 static BOOL GetNumaHighestNodeNumber(PULONG); 183 static BOOL GetNumaNodeProcessorMask(UCHAR, PULONGLONG); 184 185 // Stack walking 186 static USHORT RtlCaptureStackBackTrace(ULONG, ULONG, PVOID*, PULONG); 187 188private: 189 // GetLargePageMinimum available on Windows Vista/Windows Server 2003 190 // and later 191 // NUMA calls available Windows Vista/WS2008 and later 192 193 static SIZE_T (WINAPI *_GetLargePageMinimum)(void); 194 static LPVOID (WINAPI *_VirtualAllocExNuma) (HANDLE, LPVOID, SIZE_T, DWORD, DWORD, DWORD); 195 static BOOL (WINAPI *_GetNumaHighestNodeNumber) (PULONG); 196 static BOOL (WINAPI *_GetNumaNodeProcessorMask) (UCHAR, PULONGLONG); 197 static USHORT (WINAPI *_RtlCaptureStackBackTrace)(ULONG, ULONG, PVOID*, PULONG); 198 static BOOL initialized; 199 200 static void initialize(); 201 static void initializeCommon(); 202 203#ifdef JDK6_OR_EARLIER 204private: 205 static BOOL (WINAPI *_SwitchToThread)(void); 206 static HANDLE (WINAPI* _CreateToolhelp32Snapshot)(DWORD,DWORD); 207 static BOOL (WINAPI* _Module32First)(HANDLE,LPMODULEENTRY32); 208 static BOOL (WINAPI* _Module32Next)(HANDLE,LPMODULEENTRY32); 209 static void (WINAPI *_GetNativeSystemInfo)(LPSYSTEM_INFO); 210#endif 211 212}; 213 214class Advapi32Dll: AllStatic { 215public: 216 static BOOL AdjustTokenPrivileges(HANDLE, BOOL, PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD); 217 static BOOL OpenProcessToken(HANDLE, DWORD, PHANDLE); 218 static BOOL LookupPrivilegeValue(LPCTSTR, LPCTSTR, PLUID); 219 220 static BOOL AdvapiAvailable(); 221 222#ifdef JDK6_OR_EARLIER 223private: 224 static BOOL (WINAPI *_AdjustTokenPrivileges)(HANDLE, BOOL, PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD); 225 static BOOL (WINAPI *_OpenProcessToken)(HANDLE, DWORD, PHANDLE); 226 static BOOL (WINAPI *_LookupPrivilegeValue)(LPCTSTR, LPCTSTR, PLUID); 227 static BOOL initialized; 228 229 static void initialize(); 230#endif 231}; 232 233class PSApiDll: AllStatic { 234public: 235 static BOOL EnumProcessModules(HANDLE, HMODULE *, DWORD, LPDWORD); 236 static DWORD GetModuleFileNameEx(HANDLE, HMODULE, LPTSTR, DWORD); 237 static BOOL GetModuleInformation(HANDLE, HMODULE, LPMODULEINFO, DWORD); 238 239 static BOOL PSApiAvailable(); 240 241#ifdef JDK6_OR_EARLIER 242private: 243 static BOOL (WINAPI *_EnumProcessModules)(HANDLE, HMODULE *, DWORD, LPDWORD); 244 static BOOL (WINAPI *_GetModuleFileNameEx)(HANDLE, HMODULE, LPTSTR, DWORD);; 245 static BOOL (WINAPI *_GetModuleInformation)(HANDLE, HMODULE, LPMODULEINFO, DWORD); 246 static BOOL initialized; 247 248 static void initialize(); 249#endif 250}; 251 252#endif // OS_WINDOWS_VM_OS_WINDOWS_HPP 253