os_windows.hpp 7.8 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24
 *
 */

25 26
#ifndef OS_WINDOWS_VM_OS_WINDOWS_HPP
#define OS_WINDOWS_VM_OS_WINDOWS_HPP
D
duke 已提交
27 28 29
// Win32_OS defines the interface to windows operating systems

class win32 {
30
  friend class os;
D
duke 已提交
31 32 33 34 35 36 37 38 39

 protected:
  static int    _vm_page_size;
  static int    _vm_allocation_granularity;
  static int    _processor_type;
  static int    _processor_level;
  static julong _physical_memory;
  static size_t _default_stack_size;
  static bool   _is_nt;
40
  static bool   _is_windows_2003;
41
  static bool   _is_windows_server;
D
duke 已提交
42

43 44
  static void print_windows_version(outputStream* st);

D
duke 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
 public:
  // Windows-specific interface:
  static void   initialize_system_info();
  static void   setmode_streams();

  // Processor info as provided by NT
  static int processor_type()  { return _processor_type;  }
  // Processor level may not be accurate on non-NT systems
  static int processor_level() {
    assert(is_nt(), "use vm_version instead");
    return _processor_level;
  }
  static julong available_memory();
  static julong physical_memory() { return _physical_memory; }

60 61 62
  // load dll from Windows system directory or Windows directory
  static HINSTANCE load_Windows_dll(const char* name, char *ebuf, int ebuflen);

D
duke 已提交
63 64 65 66 67 68 69 70 71 72
 public:
  // Generic interface:

  // Trace number of created threads
  static          intx  _os_thread_limit;
  static volatile intx  _os_thread_count;

  // Tells whether the platform is NT or Windown95
  static bool is_nt() { return _is_nt; }

73 74 75
  // Tells whether this is a server version of Windows
  static bool is_windows_server() { return _is_windows_server; }

76 77 78
  // Tells whether the platform is Windows 2003
  static bool is_windows_2003() { return _is_windows_2003; }

D
duke 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
  // Returns the byte size of a virtual memory page
  static int vm_page_size() { return _vm_page_size; }

  // Returns the size in bytes of memory blocks which can be allocated.
  static int vm_allocation_granularity() { return _vm_allocation_granularity; }

  // Read the headers for the executable that started the current process into
  // the structure passed in (see winnt.h).
  static void read_executable_headers(PIMAGE_NT_HEADERS);

  // Default stack size for the current process.
  static size_t default_stack_size() { return _default_stack_size; }

#ifndef _WIN64
  // A wrapper to install a structured exception handler for fast JNI accesors.
  static address fast_jni_accessor_wrapper(BasicType);
#endif

  // filter function to ignore faults on serializations page
  static LONG WINAPI serialize_fault_filter(struct _EXCEPTION_POINTERS* e);
};

class PlatformEvent : public CHeapObj {
  private:
    double CachePad [4] ;   // increase odds that _Event is sole occupant of cache line
    volatile int _Event ;
    HANDLE _ParkHandle ;

  public:       // TODO-FIXME: make dtor private
    ~PlatformEvent() { guarantee (0, "invariant") ; }

  public:
    PlatformEvent() {
      _Event   = 0 ;
      _ParkHandle = CreateEvent (NULL, false, false, NULL) ;
      guarantee (_ParkHandle != NULL, "invariant") ;
    }

    // Exercise caution using reset() and fired() - they may require MEMBARs
    void reset() { _Event = 0 ; }
    int  fired() { return _Event; }
    void park () ;
    void unpark () ;
    int  park (jlong millis) ;
} ;



class PlatformParker : public CHeapObj {
  protected:
    HANDLE _ParkEvent ;

  public:
    ~PlatformParker () { guarantee (0, "invariant") ; }
    PlatformParker  () {
      _ParkEvent = CreateEvent (NULL, true, false, NULL) ;
      guarantee (_ParkEvent != NULL, "invariant") ;
    }

} ;
139

140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
// JDK7 requires VS2010
#if _MSC_VER < 1600
#define JDK6_OR_EARLIER 1
#endif



class WinSock2Dll: AllStatic {
public:
  static BOOL WSAStartup(WORD, LPWSADATA);
  static struct hostent* gethostbyname(const char *name);
  static BOOL WinSock2Available();
#ifdef JDK6_OR_EARLIER
private:
  static int (PASCAL FAR* _WSAStartup)(WORD, LPWSADATA);
  static struct hostent *(PASCAL FAR *_gethostbyname)(...);
  static BOOL initialized;

  static void initialize();
#endif
};

class Kernel32Dll: AllStatic {
public:
  static BOOL SwitchToThread();
  static SIZE_T GetLargePageMinimum();

  static BOOL SwitchToThreadAvailable();
  static BOOL GetLargePageMinimumAvailable();

  // Help tools
  static BOOL HelpToolsAvailable();
  static HANDLE CreateToolhelp32Snapshot(DWORD,DWORD);
  static BOOL Module32First(HANDLE,LPMODULEENTRY32);
  static BOOL Module32Next(HANDLE,LPMODULEENTRY32);

  static BOOL GetNativeSystemInfoAvailable();
  static void GetNativeSystemInfo(LPSYSTEM_INFO);

I
iveresov 已提交
179 180 181 182 183 184
  // NUMA calls
  static BOOL NumaCallsAvailable();
  static LPVOID VirtualAllocExNuma(HANDLE, LPVOID, SIZE_T, DWORD, DWORD, DWORD);
  static BOOL GetNumaHighestNodeNumber(PULONG);
  static BOOL GetNumaNodeProcessorMask(UCHAR, PULONGLONG);

185 186 187
private:
  // GetLargePageMinimum available on Windows Vista/Windows Server 2003
  // and later
I
iveresov 已提交
188 189
  // NUMA calls available Windows Vista/WS2008 and later

190
  static SIZE_T (WINAPI *_GetLargePageMinimum)(void);
I
iveresov 已提交
191 192 193
  static LPVOID (WINAPI *_VirtualAllocExNuma) (HANDLE, LPVOID, SIZE_T, DWORD, DWORD, DWORD);
  static BOOL (WINAPI *_GetNumaHighestNodeNumber) (PULONG);
  static BOOL (WINAPI *_GetNumaNodeProcessorMask) (UCHAR, PULONGLONG);
194 195 196
  static BOOL initialized;

  static void initialize();
I
iveresov 已提交
197
  static void initializeCommon();
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247

#ifdef JDK6_OR_EARLIER
private:
  static BOOL (WINAPI *_SwitchToThread)(void);
  static HANDLE (WINAPI* _CreateToolhelp32Snapshot)(DWORD,DWORD);
  static BOOL (WINAPI* _Module32First)(HANDLE,LPMODULEENTRY32);
  static BOOL (WINAPI* _Module32Next)(HANDLE,LPMODULEENTRY32);
  static void (WINAPI *_GetNativeSystemInfo)(LPSYSTEM_INFO);
#endif

};

class Advapi32Dll: AllStatic {
public:
  static BOOL AdjustTokenPrivileges(HANDLE, BOOL, PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD);
  static BOOL OpenProcessToken(HANDLE, DWORD, PHANDLE);
  static BOOL LookupPrivilegeValue(LPCTSTR, LPCTSTR, PLUID);

  static BOOL AdvapiAvailable();

#ifdef JDK6_OR_EARLIER
private:
  static BOOL (WINAPI *_AdjustTokenPrivileges)(HANDLE, BOOL, PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD);
  static BOOL (WINAPI *_OpenProcessToken)(HANDLE, DWORD, PHANDLE);
  static BOOL (WINAPI *_LookupPrivilegeValue)(LPCTSTR, LPCTSTR, PLUID);
  static BOOL initialized;

  static void initialize();
#endif
};

class PSApiDll: AllStatic {
public:
  static BOOL EnumProcessModules(HANDLE, HMODULE *, DWORD, LPDWORD);
  static DWORD GetModuleFileNameEx(HANDLE, HMODULE, LPTSTR, DWORD);
  static BOOL GetModuleInformation(HANDLE, HMODULE, LPMODULEINFO, DWORD);

  static BOOL PSApiAvailable();

#ifdef JDK6_OR_EARLIER
private:
  static BOOL (WINAPI *_EnumProcessModules)(HANDLE, HMODULE *, DWORD, LPDWORD);
  static BOOL (WINAPI *_GetModuleFileNameEx)(HANDLE, HMODULE, LPTSTR, DWORD);;
  static BOOL (WINAPI *_GetModuleInformation)(HANDLE, HMODULE, LPMODULEINFO, DWORD);
  static BOOL initialized;

  static void initialize();
#endif
};

248
#endif // OS_WINDOWS_VM_OS_WINDOWS_HPP