8191212: AIX: Build and polling page allocation broken after 8189941
authormdoerr
Tue, 14 Nov 2017 16:45:27 +0100
changeset 47889 839a3b403a5e
parent 47888 99f13d4afe85
child 47890 2219a502fd45
8191212: AIX: Build and polling page allocation broken after 8189941 Reviewed-by: stuefe
src/hotspot/os/aix/safepointMechanism_aix.cpp
--- a/src/hotspot/os/aix/safepointMechanism_aix.cpp	Tue Nov 14 10:10:05 2017 -0500
+++ b/src/hotspot/os/aix/safepointMechanism_aix.cpp	Tue Nov 14 16:45:27 2017 +0100
@@ -27,10 +27,11 @@
 #include "runtime/globals.hpp"
 #include "runtime/os.hpp"
 #include "runtime/safepointMechanism.hpp"
+#include <sys/mman.h>
 
 void SafepointMechanism::pd_initialize() {
-  char* map_address = MAP_FAILED;
-  size_t page_size = os::vm_page_size();
+  char* map_address = (char*)MAP_FAILED;
+  const size_t page_size = os::vm_page_size();
   // Use optimized addresses for the polling page,
   // e.g. map it to a special 32-bit address.
   if (OptimizePollingPageLocation) {
@@ -40,43 +41,45 @@
         // PPC64: all address wishes are non-negative 32 bit values where
         // the lower 16 bits are all zero. we can load these addresses
         // with a single ppc_lis instruction.
-        (address) 0x30000000, (address) 0x31000000,
-        (address) 0x32000000, (address) 0x33000000,
-        (address) 0x40000000, (address) 0x41000000,
-        (address) 0x42000000, (address) 0x43000000,
-        (address) 0x50000000, (address) 0x51000000,
-        (address) 0x52000000, (address) 0x53000000,
-        (address) 0x60000000, (address) 0x61000000,
-        (address) 0x62000000, (address) 0x63000000
+        (char*) 0x30000000, (char*) 0x31000000,
+        (char*) 0x32000000, (char*) 0x33000000,
+        (char*) 0x40000000, (char*) 0x41000000,
+        (char*) 0x42000000, (char*) 0x43000000,
+        (char*) 0x50000000, (char*) 0x51000000,
+        (char*) 0x52000000, (char*) 0x53000000,
+        (char*) 0x60000000, (char*) 0x61000000,
+        (char*) 0x62000000, (char*) 0x63000000
     };
-    int address_wishes_length = sizeof(address_wishes)/sizeof(address);
+    int address_wishes_length = sizeof(address_wishes)/sizeof(char*);
 
     // iterate over the list of address wishes:
-    for (int i=0; i<address_wishes_length; i++) {
+    for (int i = 0; i < address_wishes_length; i++) {
       // Try to map with current address wish.
       // AIX: AIX needs MAP_FIXED if we provide an address and mmap will
       // fail if the address is already mapped.
-      map_address = os::attempt_reserve_memory_at(page_size, address_wishes[i] - page_size);
+      map_address = (char*) ::mmap(address_wishes[i] - (ssize_t)page_size,
+                                   page_size, PROT_READ,
+                                   MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
+                                   -1, 0);
       log_debug(os)("SafePoint Polling  Page address: %p (wish) => %p",
-          address_wishes[i], map_address + (ssize_t)page_size);
+                    address_wishes[i], map_address + (ssize_t)page_size);
 
       if (map_address + (ssize_t)page_size == address_wishes[i]) {
         // Map succeeded and map_address is at wished address, exit loop.
         break;
       }
 
-      if (map_address != (address) MAP_FAILED) {
+      if (map_address != (char*)MAP_FAILED) {
         // Map succeeded, but polling_page is not at wished address, unmap and continue.
-        os::release_memory(map_address, page_size);
-        map_address = (address) MAP_FAILED;
+        ::munmap(map_address, page_size);
+        map_address = (char*)MAP_FAILED;
       }
       // Map failed, continue loop.
     }
   }
-  if (map_address == (address) MAP_FAILED) {
+  if (map_address == (char*)MAP_FAILED) {
     map_address = os::reserve_memory(page_size, NULL, page_size);
   }
-  guarantee(map_address != MAP_FAILED, "SafepointMechanism::pd_initialize: failed to allocate polling page");
-  os::commit_memory_or_exit(map_address, page_size, false, "Unable to commit memory for polling page");
+  guarantee(map_address != (char*)MAP_FAILED, "SafepointMechanism::pd_initialize: failed to allocate polling page");
   os::set_polling_page((address)(map_address));
 }