annotate src/os/windows/vm/os_windows.hpp @ 3465:d2a62e0f25eb

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