hotspot/src/os/windows/vm/os_windows.cpp
changeset 16623 89050b0a21e3
parent 15927 f256c20146f4
child 16631 c6860a0ebc99
equal deleted inserted replaced
16622:32565ca20073 16623:89050b0a21e3
  3766   static void perfMemory_exit_helper() {
  3766   static void perfMemory_exit_helper() {
  3767     perfMemory_exit();
  3767     perfMemory_exit();
  3768   }
  3768   }
  3769 }
  3769 }
  3770 
  3770 
       
  3771 static jint initSock();
       
  3772 
  3771 // this is called _after_ the global arguments have been parsed
  3773 // this is called _after_ the global arguments have been parsed
  3772 jint os::init_2(void) {
  3774 jint os::init_2(void) {
  3773   // Allocate a single page and mark it as readable for safepoint polling
  3775   // Allocate a single page and mark it as readable for safepoint polling
  3774   address polling_page = (address)VirtualAlloc(NULL, os::vm_page_size(), MEM_RESERVE, PAGE_READONLY);
  3776   address polling_page = (address)VirtualAlloc(NULL, os::vm_page_size(), MEM_RESERVE, PAGE_READONLY);
  3775   guarantee( polling_page != NULL, "Reserve Failed for polling page");
  3777   guarantee( polling_page != NULL, "Reserve Failed for polling page");
  3894 
  3896 
  3895   if (UseNUMAInterleaving) {
  3897   if (UseNUMAInterleaving) {
  3896     // first check whether this Windows OS supports VirtualAllocExNuma, if not ignore this flag
  3898     // first check whether this Windows OS supports VirtualAllocExNuma, if not ignore this flag
  3897     bool success = numa_interleaving_init();
  3899     bool success = numa_interleaving_init();
  3898     if (!success) UseNUMAInterleaving = false;
  3900     if (!success) UseNUMAInterleaving = false;
       
  3901   }
       
  3902 
       
  3903   if (initSock() != JNI_OK) {
       
  3904     return JNI_ERR;
  3899   }
  3905   }
  3900 
  3906 
  3901   return JNI_OK;
  3907   return JNI_OK;
  3902 }
  3908 }
  3903 
  3909 
  4892 }
  4898 }
  4893 
  4899 
  4894 // We don't build a headless jre for Windows
  4900 // We don't build a headless jre for Windows
  4895 bool os::is_headless_jre() { return false; }
  4901 bool os::is_headless_jre() { return false; }
  4896 
  4902 
  4897 
  4903 static jint initSock() {
  4898 typedef CRITICAL_SECTION mutex_t;
       
  4899 #define mutexInit(m)    InitializeCriticalSection(m)
       
  4900 #define mutexDestroy(m) DeleteCriticalSection(m)
       
  4901 #define mutexLock(m)    EnterCriticalSection(m)
       
  4902 #define mutexUnlock(m)  LeaveCriticalSection(m)
       
  4903 
       
  4904 static bool sock_initialized = FALSE;
       
  4905 static mutex_t sockFnTableMutex;
       
  4906 
       
  4907 static void initSock() {
       
  4908   WSADATA wsadata;
  4904   WSADATA wsadata;
  4909 
  4905 
  4910   if (!os::WinSock2Dll::WinSock2Available()) {
  4906   if (!os::WinSock2Dll::WinSock2Available()) {
  4911     jio_fprintf(stderr, "Could not load Winsock 2 (error: %d)\n",
  4907     jio_fprintf(stderr, "Could not load Winsock (error: %d)\n",
  4912       ::GetLastError());
  4908       ::GetLastError());
  4913     return;
  4909     return JNI_ERR;
  4914   }
  4910   }
  4915   if (sock_initialized == TRUE) return;
  4911 
  4916 
  4912   if (os::WinSock2Dll::WSAStartup(MAKEWORD(2,2), &wsadata) != 0) {
  4917   ::mutexInit(&sockFnTableMutex);
  4913     jio_fprintf(stderr, "Could not initialize Winsock (error: %d)\n",
  4918   ::mutexLock(&sockFnTableMutex);
  4914       ::GetLastError());
  4919   if (os::WinSock2Dll::WSAStartup(MAKEWORD(1,1), &wsadata) != 0) {
  4915     return JNI_ERR;
  4920       jio_fprintf(stderr, "Could not initialize Winsock\n");
  4916   }
  4921   }
  4917   return JNI_OK;
  4922   sock_initialized = TRUE;
       
  4923   ::mutexUnlock(&sockFnTableMutex);
       
  4924 }
  4918 }
  4925 
  4919 
  4926 struct hostent* os::get_host_by_name(char* name) {
  4920 struct hostent* os::get_host_by_name(char* name) {
  4927   if (!sock_initialized) {
       
  4928     initSock();
       
  4929   }
       
  4930   if (!os::WinSock2Dll::WinSock2Available()) {
       
  4931     return NULL;
       
  4932   }
       
  4933   return (struct hostent*)os::WinSock2Dll::gethostbyname(name);
  4921   return (struct hostent*)os::WinSock2Dll::gethostbyname(name);
  4934 }
  4922 }
  4935 
  4923 
  4936 int os::socket_close(int fd) {
  4924 int os::socket_close(int fd) {
  4937   return ::closesocket(fd);
  4925   return ::closesocket(fd);