Path: blob/master/src/hotspot/os/windows/os_windows.hpp
40930 views
/*1* Copyright (c) 1997, 2021, 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_OS_WINDOWS_HPP25#define OS_WINDOWS_OS_WINDOWS_HPP26// Win32_OS defines the interface to windows operating systems2728// strtok_s is the Windows thread-safe equivalent of POSIX strtok_r29#define strtok_r strtok_s3031#define S_ISCHR(mode) (((mode) & _S_IFCHR) == _S_IFCHR)32#define S_ISFIFO(mode) (((mode) & _S_IFIFO) == _S_IFIFO)3334// Information about the protection of the page at address '0' on this os.35static bool zero_page_read_protected() { return true; }3637// File conventions38static const char* file_separator() { return "\\"; }39static const char* line_separator() { return "\r\n"; }40static const char* path_separator() { return ";"; }4142class win32 {43friend class os;44friend unsigned __stdcall thread_native_entry(class Thread*);4546protected:47static int _vm_page_size;48static int _vm_allocation_granularity;49static int _processor_type;50static int _processor_level;51static julong _physical_memory;52static size_t _default_stack_size;53static bool _is_windows_server;54static bool _has_exit_bug;5556static void print_windows_version(outputStream* st);57static void print_uptime_info(outputStream* st);5859public:60// Windows-specific interface:61static void initialize_system_info();62static void setmode_streams();6364// Processor info as provided by NT65static int processor_type() { return _processor_type; }66static int processor_level() {67return _processor_level;68}69static julong available_memory();70static julong physical_memory() { return _physical_memory; }7172// load dll from Windows system directory or Windows directory73static HINSTANCE load_Windows_dll(const char* name, char *ebuf, int ebuflen);7475private:76enum Ept { EPT_THREAD, EPT_PROCESS, EPT_PROCESS_DIE };77// Wrapper around _endthreadex(), exit() and _exit()78static int exit_process_or_thread(Ept what, int exit_code);7980static void initialize_performance_counter();8182public:83// Generic interface:8485// Trace number of created threads86static intx _os_thread_limit;87static volatile intx _os_thread_count;8889// Tells whether this is a server version of Windows90static bool is_windows_server() { return _is_windows_server; }9192// Tells whether there can be the race bug during process exit on this platform93static bool has_exit_bug() { return _has_exit_bug; }9495// Returns the byte size of a virtual memory page96static int vm_page_size() { return _vm_page_size; }9798// Returns the size in bytes of memory blocks which can be allocated.99static int vm_allocation_granularity() { return _vm_allocation_granularity; }100101// Read the headers for the executable that started the current process into102// the structure passed in (see winnt.h).103static void read_executable_headers(PIMAGE_NT_HEADERS);104105// Default stack size for the current process.106static size_t default_stack_size() { return _default_stack_size; }107108static bool get_frame_at_stack_banging_point(JavaThread* thread,109struct _EXCEPTION_POINTERS* exceptionInfo,110address pc, frame* fr);111112struct mapping_info_t {113// Start of allocation (AllocationBase)114address base;115// Total size of allocation over all regions116size_t size;117// Total committed size118size_t committed_size;119// Number of regions120int regions;121};122// Given an address p which points into an area allocated with VirtualAlloc(),123// return information about that area.124static bool find_mapping(address p, mapping_info_t* mapping_info);125126#ifndef _WIN64127// A wrapper to install a structured exception handler for fast JNI accesors.128static address fast_jni_accessor_wrapper(BasicType);129#endif130131// Fast access to current thread132protected:133static int _thread_ptr_offset;134private:135static void initialize_thread_ptr_offset();136public:137static inline void set_thread_ptr_offset(int offset) {138_thread_ptr_offset = offset;139}140static inline int get_thread_ptr_offset() { return _thread_ptr_offset; }141};142143/*144* Crash protection for the JfrSampler thread. Wrap the callback145* with a __try { call() }146* To be able to use this - don't take locks, don't rely on destructors,147* don't make OS library calls, don't allocate memory, don't print,148* don't call code that could leave the heap / memory in an inconsistent state,149* or anything else where we are not in control if we suddenly jump out.150*/151class ThreadCrashProtection : public StackObj {152public:153static bool is_crash_protected(Thread* thr) {154return _crash_protection != NULL && _protected_thread == thr;155}156157ThreadCrashProtection();158bool call(os::CrashProtectionCallback& cb);159private:160static Thread* _protected_thread;161static ThreadCrashProtection* _crash_protection;162};163164class PlatformEvent : public CHeapObj<mtSynchronizer> {165private:166double CachePad [4] ; // increase odds that _Event is sole occupant of cache line167volatile int _Event ;168HANDLE _ParkHandle ;169170public: // TODO-FIXME: make dtor private171~PlatformEvent() { guarantee (0, "invariant") ; }172173public:174PlatformEvent() {175_Event = 0 ;176_ParkHandle = CreateEvent (NULL, false, false, NULL) ;177guarantee (_ParkHandle != NULL, "invariant") ;178}179180// Exercise caution using reset() and fired() - they may require MEMBARs181void reset() { _Event = 0 ; }182int fired() { return _Event; }183void park () ;184void unpark () ;185int park (jlong millis) ;186} ;187188189190class PlatformParker {191NONCOPYABLE(PlatformParker);192193protected:194HANDLE _ParkHandle;195196public:197PlatformParker() {198_ParkHandle = CreateEvent (NULL, true, false, NULL) ;199guarantee(_ParkHandle != NULL, "invariant") ;200}201~PlatformParker() {202CloseHandle(_ParkHandle);203}204};205206// Platform specific implementations that underpin VM Mutex/Monitor classes.207// Note that CRITICAL_SECTION supports recursive locking, while the semantics208// of the VM Mutex class does not. It is up to the Mutex class to hide this209// difference in behaviour.210211class PlatformMutex : public CHeapObj<mtSynchronizer> {212NONCOPYABLE(PlatformMutex);213214protected:215CRITICAL_SECTION _mutex; // Native mutex for locking216217public:218PlatformMutex();219~PlatformMutex();220void lock();221void unlock();222bool try_lock();223};224225class PlatformMonitor : public PlatformMutex {226private:227CONDITION_VARIABLE _cond; // Native condition variable for blocking228NONCOPYABLE(PlatformMonitor);229230public:231PlatformMonitor();232~PlatformMonitor();233int wait(jlong millis);234void notify();235void notify_all();236};237238#endif // OS_WINDOWS_OS_WINDOWS_HPP239240241