Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/os/windows/vm/os_windows.hpp
32284 views
/*1* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef OS_WINDOWS_VM_OS_WINDOWS_HPP25#define OS_WINDOWS_VM_OS_WINDOWS_HPP26// Win32_OS defines the interface to windows operating systems2728// Information about the protection of the page at address '0' on this os.29static bool zero_page_read_protected() { return true; }3031class win32 {32friend class os;3334protected:35static int _vm_page_size;36static int _vm_allocation_granularity;37static int _processor_type;38static int _processor_level;39static julong _physical_memory;40static size_t _default_stack_size;41static bool _is_nt;42static bool _is_windows_2003;43static bool _is_windows_server;4445static void print_windows_version(outputStream* st);4647public:48// Windows-specific interface:49static void initialize_system_info();50static void setmode_streams();5152// Processor info as provided by NT53static int processor_type() { return _processor_type; }54// Processor level may not be accurate on non-NT systems55static int processor_level() {56assert(is_nt(), "use vm_version instead");57return _processor_level;58}59static julong available_memory();60static julong physical_memory() { return _physical_memory; }6162// load dll from Windows system directory or Windows directory63static HINSTANCE load_Windows_dll(const char* name, char *ebuf, int ebuflen);6465public:66// Generic interface:6768// Trace number of created threads69static intx _os_thread_limit;70static volatile intx _os_thread_count;7172// Tells whether the platform is NT or Windown9573static bool is_nt() { return _is_nt; }7475// Tells whether this is a server version of Windows76static bool is_windows_server() { return _is_windows_server; }7778// Tells whether the platform is Windows 200379static bool is_windows_2003() { return _is_windows_2003; }8081// Returns the byte size of a virtual memory page82static int vm_page_size() { return _vm_page_size; }8384// Returns the size in bytes of memory blocks which can be allocated.85static int vm_allocation_granularity() { return _vm_allocation_granularity; }8687// Read the headers for the executable that started the current process into88// the structure passed in (see winnt.h).89static void read_executable_headers(PIMAGE_NT_HEADERS);9091// Default stack size for the current process.92static size_t default_stack_size() { return _default_stack_size; }9394#ifndef _WIN6495// A wrapper to install a structured exception handler for fast JNI accesors.96static address fast_jni_accessor_wrapper(BasicType);97#endif9899static void call_test_func_with_wrapper(void (*funcPtr)(void));100101// filter function to ignore faults on serializations page102static LONG WINAPI serialize_fault_filter(struct _EXCEPTION_POINTERS* e);103};104105/*106* Crash protection for the watcher thread. Wrap the callback107* with a __try { call() }108* To be able to use this - don't take locks, don't rely on destructors,109* don't make OS library calls, don't allocate memory, don't print,110* don't call code that could leave the heap / memory in an inconsistent state,111* or anything else where we are not in control if we suddenly jump out.112*/113class ThreadCrashProtection : public StackObj {114public:115static bool is_crash_protected(Thread* thr) {116return _crash_protection != NULL && _protected_thread == thr;117}118119ThreadCrashProtection();120bool call(os::CrashProtectionCallback& cb);121private:122static Thread* _protected_thread;123static ThreadCrashProtection* _crash_protection;124static volatile intptr_t _crash_mux;125};126127class PlatformEvent : public CHeapObj<mtInternal> {128private:129double CachePad [4] ; // increase odds that _Event is sole occupant of cache line130volatile int _Event ;131HANDLE _ParkHandle ;132133public: // TODO-FIXME: make dtor private134~PlatformEvent() { guarantee (0, "invariant") ; }135136public:137PlatformEvent() {138_Event = 0 ;139_ParkHandle = CreateEvent (NULL, false, false, NULL) ;140guarantee (_ParkHandle != NULL, "invariant") ;141}142143// Exercise caution using reset() and fired() - they may require MEMBARs144void reset() { _Event = 0 ; }145int fired() { return _Event; }146void park () ;147void unpark () ;148int park (jlong millis) ;149} ;150151152153class PlatformParker : public CHeapObj<mtInternal> {154protected:155HANDLE _ParkEvent ;156157public:158~PlatformParker () { guarantee (0, "invariant") ; }159PlatformParker () {160_ParkEvent = CreateEvent (NULL, true, false, NULL) ;161guarantee (_ParkEvent != NULL, "invariant") ;162}163164} ;165166// JDK7 requires VS2010167#if _MSC_VER < 1600168#define JDK6_OR_EARLIER 1169#endif170171172173class WinSock2Dll: AllStatic {174public:175static BOOL WSAStartup(WORD, LPWSADATA);176static struct hostent* gethostbyname(const char *name);177static BOOL WinSock2Available();178#ifdef JDK6_OR_EARLIER179private:180static int (PASCAL FAR* _WSAStartup)(WORD, LPWSADATA);181static struct hostent *(PASCAL FAR *_gethostbyname)(...);182static BOOL initialized;183184static void initialize();185#endif186};187188class Kernel32Dll: AllStatic {189public:190static BOOL SwitchToThread();191static SIZE_T GetLargePageMinimum();192193static BOOL SwitchToThreadAvailable();194static BOOL GetLargePageMinimumAvailable();195196// Help tools197static BOOL HelpToolsAvailable();198static HANDLE CreateToolhelp32Snapshot(DWORD,DWORD);199static BOOL Module32First(HANDLE,LPMODULEENTRY32);200static BOOL Module32Next(HANDLE,LPMODULEENTRY32);201202static void GetNativeSystemInfo(LPSYSTEM_INFO);203204// NUMA calls205static BOOL NumaCallsAvailable();206static LPVOID VirtualAllocExNuma(HANDLE, LPVOID, SIZE_T, DWORD, DWORD, DWORD);207static BOOL GetNumaHighestNodeNumber(PULONG);208static BOOL GetNumaNodeProcessorMask(UCHAR, PULONGLONG);209210// Stack walking211static USHORT RtlCaptureStackBackTrace(ULONG, ULONG, PVOID*, PULONG);212213private:214// GetLargePageMinimum available on Windows Vista/Windows Server 2003215// and later216// NUMA calls available Windows Vista/WS2008 and later217218static SIZE_T (WINAPI *_GetLargePageMinimum)(void);219static LPVOID (WINAPI *_VirtualAllocExNuma) (HANDLE, LPVOID, SIZE_T, DWORD, DWORD, DWORD);220static BOOL (WINAPI *_GetNumaHighestNodeNumber) (PULONG);221static BOOL (WINAPI *_GetNumaNodeProcessorMask) (UCHAR, PULONGLONG);222static USHORT (WINAPI *_RtlCaptureStackBackTrace)(ULONG, ULONG, PVOID*, PULONG);223static BOOL initialized;224225static void initialize();226static void initializeCommon();227228#ifdef JDK6_OR_EARLIER229private:230static BOOL (WINAPI *_SwitchToThread)(void);231static HANDLE (WINAPI* _CreateToolhelp32Snapshot)(DWORD,DWORD);232static BOOL (WINAPI* _Module32First)(HANDLE,LPMODULEENTRY32);233static BOOL (WINAPI* _Module32Next)(HANDLE,LPMODULEENTRY32);234static void (WINAPI *_GetNativeSystemInfo)(LPSYSTEM_INFO);235#endif236237};238239class Advapi32Dll: AllStatic {240public:241static BOOL AdjustTokenPrivileges(HANDLE, BOOL, PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD);242static BOOL OpenProcessToken(HANDLE, DWORD, PHANDLE);243static BOOL LookupPrivilegeValue(LPCTSTR, LPCTSTR, PLUID);244245static BOOL AdvapiAvailable();246247#ifdef JDK6_OR_EARLIER248private:249static BOOL (WINAPI *_AdjustTokenPrivileges)(HANDLE, BOOL, PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD);250static BOOL (WINAPI *_OpenProcessToken)(HANDLE, DWORD, PHANDLE);251static BOOL (WINAPI *_LookupPrivilegeValue)(LPCTSTR, LPCTSTR, PLUID);252static BOOL initialized;253254static void initialize();255#endif256};257258class PSApiDll: AllStatic {259public:260static BOOL EnumProcessModules(HANDLE, HMODULE *, DWORD, LPDWORD);261static DWORD GetModuleFileNameEx(HANDLE, HMODULE, LPTSTR, DWORD);262static BOOL GetModuleInformation(HANDLE, HMODULE, LPMODULEINFO, DWORD);263264static BOOL PSApiAvailable();265266#ifdef JDK6_OR_EARLIER267private:268static BOOL (WINAPI *_EnumProcessModules)(HANDLE, HMODULE *, DWORD, LPDWORD);269static BOOL (WINAPI *_GetModuleFileNameEx)(HANDLE, HMODULE, LPTSTR, DWORD);;270static BOOL (WINAPI *_GetModuleInformation)(HANDLE, HMODULE, LPMODULEINFO, DWORD);271static BOOL initialized;272273static void initialize();274#endif275};276277#endif // OS_WINDOWS_VM_OS_WINDOWS_HPP278279280