8135097: Unmap failure for executable memory on windows
authorjiangli
Mon, 14 Sep 2015 14:55:01 -0400
changeset 32748 6cb8b6ab9081
parent 32747 51960ef64fa4
child 32749 96b8d735bbac
child 32816 dc3aa11c6da7
8135097: Unmap failure for executable memory on windows Summary: Use 'pd_release_memory' for executable memory in os::pd_unmap_memory(). Reviewed-by: iklam, coleenp
hotspot/src/os/windows/vm/os_windows.cpp
--- a/hotspot/src/os/windows/vm/os_windows.cpp	Mon Sep 14 14:26:29 2015 +0300
+++ b/hotspot/src/os/windows/vm/os_windows.cpp	Mon Sep 14 14:55:01 2015 -0400
@@ -4877,6 +4877,26 @@
 // Returns true=success, otherwise false.
 
 bool os::pd_unmap_memory(char* addr, size_t bytes) {
+  MEMORY_BASIC_INFORMATION mem_info;
+  if (VirtualQuery(addr, &mem_info, sizeof(mem_info)) == 0) {
+    if (PrintMiscellaneous && Verbose) {
+      DWORD err = GetLastError();
+      tty->print_cr("VirtualQuery() failed: GetLastError->%ld.", err);
+    }
+    return false;
+  }
+
+  // Executable memory was not mapped using CreateFileMapping/MapViewOfFileEx.
+  // Instead, executable region was allocated using VirtualAlloc(). See
+  // pd_map_memory() above.
+  //
+  // The following flags should match the 'exec_access' flages used for
+  // VirtualProtect() in pd_map_memory().
+  if (mem_info.Protect == PAGE_EXECUTE_READ ||
+      mem_info.Protect == PAGE_EXECUTE_READWRITE) {
+    return pd_release_memory(addr, bytes);
+  }
+
   BOOL result = UnmapViewOfFile(addr);
   if (result == 0) {
     if (PrintMiscellaneous && Verbose) {