changeset 8985:4f3ddb6a2b70

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
author jiangli
date Mon, 14 Sep 2015 14:55:01 -0400
parents 7b8eb3b6361a
children ea4f98bd8dd5 2acd6706667f
files src/os/windows/vm/os_windows.cpp
diffstat 1 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/os/windows/vm/os_windows.cpp	Mon Sep 14 14:26:29 2015 +0300
+++ b/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) {