hotspot/src/os/windows/vm/os_windows.cpp
changeset 37430 fd743dadef12
parent 37113 5a33bf5089ac
child 37462 58bb9394a98b
equal deleted inserted replaced
37428:6e724f3d488b 37430:fd743dadef12
  2434           address page_start =
  2434           address page_start =
  2435             (address) align_size_down((intptr_t) addr, (intptr_t) page_size);
  2435             (address) align_size_down((intptr_t) addr, (intptr_t) page_size);
  2436           bool res = os::protect_memory((char*) page_start, page_size,
  2436           bool res = os::protect_memory((char*) page_start, page_size,
  2437                                         os::MEM_PROT_RWX);
  2437                                         os::MEM_PROT_RWX);
  2438 
  2438 
  2439           if (PrintMiscellaneous && Verbose) {
  2439           log_debug(os)("Execution protection violation "
  2440             char buf[256];
  2440                         "at " INTPTR_FORMAT
  2441             jio_snprintf(buf, sizeof(buf), "Execution protection violation "
  2441                         ", unguarding " INTPTR_FORMAT ": %s", p2i(addr),
  2442                          "at " INTPTR_FORMAT
  2442                         p2i(page_start), (res ? "success" : os::strerror(errno)));
  2443                          ", unguarding " INTPTR_FORMAT ": %s", addr,
       
  2444                          page_start, (res ? "success" : os::strerror(errno)));
       
  2445             tty->print_raw_cr(buf);
       
  2446           }
       
  2447 
  2443 
  2448           // Set last_addr so if we fault again at the same address, we don't
  2444           // Set last_addr so if we fault again at the same address, we don't
  2449           // end up in an endless loop.
  2445           // end up in an endless loop.
  2450           //
  2446           //
  2451           // There are two potential complications here.  Two threads trapping
  2447           // There are two potential complications here.  Two threads trapping
  2894   // NUMAInterleaveGranularity cannot be less than vm_allocation_granularity (or _large_page_size if using large pages)
  2890   // NUMAInterleaveGranularity cannot be less than vm_allocation_granularity (or _large_page_size if using large pages)
  2895   size_t min_interleave_granularity = UseLargePages ? _large_page_size : os::vm_allocation_granularity();
  2891   size_t min_interleave_granularity = UseLargePages ? _large_page_size : os::vm_allocation_granularity();
  2896   NUMAInterleaveGranularity = align_size_up(NUMAInterleaveGranularity, min_interleave_granularity);
  2892   NUMAInterleaveGranularity = align_size_up(NUMAInterleaveGranularity, min_interleave_granularity);
  2897 
  2893 
  2898   if (numa_node_list_holder.build()) {
  2894   if (numa_node_list_holder.build()) {
  2899     if (PrintMiscellaneous && Verbose) {
  2895     if (log_is_enabled(Debug, os, cpu)) {
  2900       tty->print("NUMA UsedNodeCount=%d, namely ", numa_node_list_holder.get_count());
  2896       Log(os, cpu) log;
       
  2897       log.debug("NUMA UsedNodeCount=%d, namely ", numa_node_list_holder.get_count());
  2901       for (int i = 0; i < numa_node_list_holder.get_count(); i++) {
  2898       for (int i = 0; i < numa_node_list_holder.get_count(); i++) {
  2902         tty->print("%d ", numa_node_list_holder.get_node_list_entry(i));
  2899         log.debug("  %d ", numa_node_list_holder.get_node_list_entry(i));
  2903       }
  2900       }
  2904       tty->print("\n");
       
  2905     }
  2901     }
  2906     success = true;
  2902     success = true;
  2907   } else {
  2903   } else {
  2908     WARN("Process does not cover multiple NUMA nodes.");
  2904     WARN("Process does not cover multiple NUMA nodes.");
  2909   }
  2905   }
  4117 
  4113 
  4118   address return_page  = (address)VirtualAlloc(polling_page, os::vm_page_size(), MEM_COMMIT, PAGE_READONLY);
  4114   address return_page  = (address)VirtualAlloc(polling_page, os::vm_page_size(), MEM_COMMIT, PAGE_READONLY);
  4119   guarantee(return_page != NULL, "Commit Failed for polling page");
  4115   guarantee(return_page != NULL, "Commit Failed for polling page");
  4120 
  4116 
  4121   os::set_polling_page(polling_page);
  4117   os::set_polling_page(polling_page);
  4122 
  4118   log_info(os)("SafePoint Polling address: " INTPTR_FORMAT, p2i(polling_page));
  4123 #ifndef PRODUCT
       
  4124   if (Verbose && PrintMiscellaneous) {
       
  4125     tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n",
       
  4126                (intptr_t)polling_page);
       
  4127   }
       
  4128 #endif
       
  4129 
  4119 
  4130   if (!UseMembar) {
  4120   if (!UseMembar) {
  4131     address mem_serialize_page = (address)VirtualAlloc(NULL, os::vm_page_size(), MEM_RESERVE, PAGE_READWRITE);
  4121     address mem_serialize_page = (address)VirtualAlloc(NULL, os::vm_page_size(), MEM_RESERVE, PAGE_READWRITE);
  4132     guarantee(mem_serialize_page != NULL, "Reserve Failed for memory serialize page");
  4122     guarantee(mem_serialize_page != NULL, "Reserve Failed for memory serialize page");
  4133 
  4123 
  4134     return_page  = (address)VirtualAlloc(mem_serialize_page, os::vm_page_size(), MEM_COMMIT, PAGE_READWRITE);
  4124     return_page  = (address)VirtualAlloc(mem_serialize_page, os::vm_page_size(), MEM_COMMIT, PAGE_READWRITE);
  4135     guarantee(return_page != NULL, "Commit Failed for memory serialize page");
  4125     guarantee(return_page != NULL, "Commit Failed for memory serialize page");
  4136 
  4126 
  4137     os::set_memory_serialize_page(mem_serialize_page);
  4127     os::set_memory_serialize_page(mem_serialize_page);
  4138 
  4128     log_info(os)("Memory Serialize Page address: " INTPTR_FORMAT, p2i(mem_serialize_page));
  4139 #ifndef PRODUCT
       
  4140     if (Verbose && PrintMiscellaneous) {
       
  4141       tty->print("[Memory Serialize  Page address: " INTPTR_FORMAT "]\n",
       
  4142                  (intptr_t)mem_serialize_page);
       
  4143     }
       
  4144 #endif
       
  4145   }
  4129   }
  4146 
  4130 
  4147   // Setup Windows Exceptions
  4131   // Setup Windows Exceptions
  4148 
  4132 
  4149   // for debugging float code generation bugs
  4133   // for debugging float code generation bugs
  4767   char* base;
  4751   char* base;
  4768 
  4752 
  4769   hFile = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ, NULL,
  4753   hFile = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ, NULL,
  4770                      OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  4754                      OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  4771   if (hFile == NULL) {
  4755   if (hFile == NULL) {
  4772     if (PrintMiscellaneous && Verbose) {
  4756     log_info(os)("CreateFile() failed: GetLastError->%ld.", GetLastError());
  4773       DWORD err = GetLastError();
       
  4774       tty->print_cr("CreateFile() failed: GetLastError->%ld.", err);
       
  4775     }
       
  4776     return NULL;
  4757     return NULL;
  4777   }
  4758   }
  4778 
  4759 
  4779   if (allow_exec) {
  4760   if (allow_exec) {
  4780     // CreateFileMapping/MapViewOfFileEx can't map executable memory
  4761     // CreateFileMapping/MapViewOfFileEx can't map executable memory
  4788     // header so that mapping executable + sharing is possible.
  4769     // header so that mapping executable + sharing is possible.
  4789 
  4770 
  4790     base = (char*) VirtualAlloc(addr, bytes, MEM_COMMIT | MEM_RESERVE,
  4771     base = (char*) VirtualAlloc(addr, bytes, MEM_COMMIT | MEM_RESERVE,
  4791                                 PAGE_READWRITE);
  4772                                 PAGE_READWRITE);
  4792     if (base == NULL) {
  4773     if (base == NULL) {
  4793       if (PrintMiscellaneous && Verbose) {
  4774       log_info(os)("VirtualAlloc() failed: GetLastError->%ld.", GetLastError());
  4794         DWORD err = GetLastError();
       
  4795         tty->print_cr("VirtualAlloc() failed: GetLastError->%ld.", err);
       
  4796       }
       
  4797       CloseHandle(hFile);
  4775       CloseHandle(hFile);
  4798       return NULL;
  4776       return NULL;
  4799     }
  4777     }
  4800 
  4778 
  4801     DWORD bytes_read;
  4779     DWORD bytes_read;
  4805     overlapped.hEvent = NULL;
  4783     overlapped.hEvent = NULL;
  4806     // ReadFile guarantees that if the return value is true, the requested
  4784     // ReadFile guarantees that if the return value is true, the requested
  4807     // number of bytes were read before returning.
  4785     // number of bytes were read before returning.
  4808     bool res = ReadFile(hFile, base, (DWORD)bytes, &bytes_read, &overlapped) != 0;
  4786     bool res = ReadFile(hFile, base, (DWORD)bytes, &bytes_read, &overlapped) != 0;
  4809     if (!res) {
  4787     if (!res) {
  4810       if (PrintMiscellaneous && Verbose) {
  4788       log_info(os)("ReadFile() failed: GetLastError->%ld.", GetLastError());
  4811         DWORD err = GetLastError();
       
  4812         tty->print_cr("ReadFile() failed: GetLastError->%ld.", err);
       
  4813       }
       
  4814       release_memory(base, bytes);
  4789       release_memory(base, bytes);
  4815       CloseHandle(hFile);
  4790       CloseHandle(hFile);
  4816       return NULL;
  4791       return NULL;
  4817     }
  4792     }
  4818   } else {
  4793   } else {
  4819     HANDLE hMap = CreateFileMapping(hFile, NULL, PAGE_WRITECOPY, 0, 0,
  4794     HANDLE hMap = CreateFileMapping(hFile, NULL, PAGE_WRITECOPY, 0, 0,
  4820                                     NULL /* file_name */);
  4795                                     NULL /* file_name */);
  4821     if (hMap == NULL) {
  4796     if (hMap == NULL) {
  4822       if (PrintMiscellaneous && Verbose) {
  4797       log_info(os)("CreateFileMapping() failed: GetLastError->%ld.", GetLastError());
  4823         DWORD err = GetLastError();
       
  4824         tty->print_cr("CreateFileMapping() failed: GetLastError->%ld.", err);
       
  4825       }
       
  4826       CloseHandle(hFile);
  4798       CloseHandle(hFile);
  4827       return NULL;
  4799       return NULL;
  4828     }
  4800     }
  4829 
  4801 
  4830     DWORD access = read_only ? FILE_MAP_READ : FILE_MAP_COPY;
  4802     DWORD access = read_only ? FILE_MAP_READ : FILE_MAP_COPY;
  4831     base = (char*)MapViewOfFileEx(hMap, access, 0, (DWORD)file_offset,
  4803     base = (char*)MapViewOfFileEx(hMap, access, 0, (DWORD)file_offset,
  4832                                   (DWORD)bytes, addr);
  4804                                   (DWORD)bytes, addr);
  4833     if (base == NULL) {
  4805     if (base == NULL) {
  4834       if (PrintMiscellaneous && Verbose) {
  4806       log_info(os)("MapViewOfFileEx() failed: GetLastError->%ld.", GetLastError());
  4835         DWORD err = GetLastError();
       
  4836         tty->print_cr("MapViewOfFileEx() failed: GetLastError->%ld.", err);
       
  4837       }
       
  4838       CloseHandle(hMap);
  4807       CloseHandle(hMap);
  4839       CloseHandle(hFile);
  4808       CloseHandle(hFile);
  4840       return NULL;
  4809       return NULL;
  4841     }
  4810     }
  4842 
  4811 
  4843     if (CloseHandle(hMap) == 0) {
  4812     if (CloseHandle(hMap) == 0) {
  4844       if (PrintMiscellaneous && Verbose) {
  4813       log_info(os)("CloseHandle(hMap) failed: GetLastError->%ld.", GetLastError());
  4845         DWORD err = GetLastError();
       
  4846         tty->print_cr("CloseHandle(hMap) failed: GetLastError->%ld.", err);
       
  4847       }
       
  4848       CloseHandle(hFile);
  4814       CloseHandle(hFile);
  4849       return base;
  4815       return base;
  4850     }
  4816     }
  4851   }
  4817   }
  4852 
  4818 
  4854     DWORD old_protect;
  4820     DWORD old_protect;
  4855     DWORD exec_access = read_only ? PAGE_EXECUTE_READ : PAGE_EXECUTE_READWRITE;
  4821     DWORD exec_access = read_only ? PAGE_EXECUTE_READ : PAGE_EXECUTE_READWRITE;
  4856     bool res = VirtualProtect(base, bytes, exec_access, &old_protect) != 0;
  4822     bool res = VirtualProtect(base, bytes, exec_access, &old_protect) != 0;
  4857 
  4823 
  4858     if (!res) {
  4824     if (!res) {
  4859       if (PrintMiscellaneous && Verbose) {
  4825       log_info(os)("VirtualProtect() failed: GetLastError->%ld.", GetLastError());
  4860         DWORD err = GetLastError();
       
  4861         tty->print_cr("VirtualProtect() failed: GetLastError->%ld.", err);
       
  4862       }
       
  4863       // Don't consider this a hard error, on IA32 even if the
  4826       // Don't consider this a hard error, on IA32 even if the
  4864       // VirtualProtect fails, we should still be able to execute
  4827       // VirtualProtect fails, we should still be able to execute
  4865       CloseHandle(hFile);
  4828       CloseHandle(hFile);
  4866       return base;
  4829       return base;
  4867     }
  4830     }
  4868   }
  4831   }
  4869 
  4832 
  4870   if (CloseHandle(hFile) == 0) {
  4833   if (CloseHandle(hFile) == 0) {
  4871     if (PrintMiscellaneous && Verbose) {
  4834     log_info(os)("CloseHandle(hFile) failed: GetLastError->%ld.", GetLastError());
  4872       DWORD err = GetLastError();
       
  4873       tty->print_cr("CloseHandle(hFile) failed: GetLastError->%ld.", err);
       
  4874     }
       
  4875     return base;
  4835     return base;
  4876   }
  4836   }
  4877 
  4837 
  4878   return base;
  4838   return base;
  4879 }
  4839 }
  4902 // Returns true=success, otherwise false.
  4862 // Returns true=success, otherwise false.
  4903 
  4863 
  4904 bool os::pd_unmap_memory(char* addr, size_t bytes) {
  4864 bool os::pd_unmap_memory(char* addr, size_t bytes) {
  4905   MEMORY_BASIC_INFORMATION mem_info;
  4865   MEMORY_BASIC_INFORMATION mem_info;
  4906   if (VirtualQuery(addr, &mem_info, sizeof(mem_info)) == 0) {
  4866   if (VirtualQuery(addr, &mem_info, sizeof(mem_info)) == 0) {
  4907     if (PrintMiscellaneous && Verbose) {
  4867     log_info(os)("VirtualQuery() failed: GetLastError->%ld.", GetLastError());
  4908       DWORD err = GetLastError();
       
  4909       tty->print_cr("VirtualQuery() failed: GetLastError->%ld.", err);
       
  4910     }
       
  4911     return false;
  4868     return false;
  4912   }
  4869   }
  4913 
  4870 
  4914   // Executable memory was not mapped using CreateFileMapping/MapViewOfFileEx.
  4871   // Executable memory was not mapped using CreateFileMapping/MapViewOfFileEx.
  4915   // Instead, executable region was allocated using VirtualAlloc(). See
  4872   // Instead, executable region was allocated using VirtualAlloc(). See
  4922     return pd_release_memory(addr, bytes);
  4879     return pd_release_memory(addr, bytes);
  4923   }
  4880   }
  4924 
  4881 
  4925   BOOL result = UnmapViewOfFile(addr);
  4882   BOOL result = UnmapViewOfFile(addr);
  4926   if (result == 0) {
  4883   if (result == 0) {
  4927     if (PrintMiscellaneous && Verbose) {
  4884     log_info(os)("UnmapViewOfFile() failed: GetLastError->%ld.", GetLastError());
  4928       DWORD err = GetLastError();
       
  4929       tty->print_cr("UnmapViewOfFile() failed: GetLastError->%ld.", err);
       
  4930     }
       
  4931     return false;
  4885     return false;
  4932   }
  4886   }
  4933   return true;
  4887   return true;
  4934 }
  4888 }
  4935 
  4889