changeset 56405:d3afe760b392

8224221: add memprotect calls to event log Reviewed-by: dholmes, mdoerr
author mbaesken
date Thu, 23 May 2019 15:15:01 +0200
parents d871ce8ab96b
children 3a8433d967ea
files src/hotspot/os/aix/os_aix.cpp src/hotspot/os/bsd/os_bsd.cpp src/hotspot/os/linux/os_linux.cpp src/hotspot/os/solaris/os_solaris.cpp src/hotspot/share/runtime/globals.hpp src/hotspot/share/utilities/events.hpp
diffstat 6 files changed, 16 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/os/aix/os_aix.cpp	Sat May 25 20:55:33 2019 +0900
+++ b/src/hotspot/os/aix/os_aix.cpp	Thu May 23 15:15:01 2019 +0200
@@ -2442,6 +2442,7 @@
   //
   // See http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf1/mprotect.htm
 
+  Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(addr), p2i(addr+size), prot);
   bool rc = ::mprotect(addr, size, prot) == 0 ? true : false;
 
   if (!rc) {
@@ -2482,6 +2483,7 @@
           // A valid strategy is just to try again. This usually works. :-/
 
           ::usleep(1000);
+          Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(addr), p2i(addr+size), prot);
           if (::mprotect(addr, size, prot) == 0) {
             const bool read_protected_2 =
               (SafeFetch32((int*)addr, 0x12345678) == 0x12345678 &&
--- a/src/hotspot/os/bsd/os_bsd.cpp	Sat May 25 20:55:33 2019 +0900
+++ b/src/hotspot/os/bsd/os_bsd.cpp	Thu May 23 15:15:01 2019 +0200
@@ -1933,6 +1933,7 @@
   int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
 #ifdef __OpenBSD__
   // XXX: Work-around mmap/MAP_FIXED bug temporarily on OpenBSD
+  Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(addr), p2i(addr+size), prot);
   if (::mprotect(addr, size, prot) == 0) {
     return true;
   }
@@ -2017,6 +2018,7 @@
 bool os::pd_uncommit_memory(char* addr, size_t size) {
 #ifdef __OpenBSD__
   // XXX: Work-around mmap/MAP_FIXED bug temporarily on OpenBSD
+  Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with PROT_NONE", p2i(addr), p2i(addr+size));
   return ::mprotect(addr, size, PROT_NONE) == 0;
 #else
   uintptr_t res = (uintptr_t) ::mmap(addr, size, PROT_NONE,
@@ -2085,6 +2087,7 @@
   assert(addr == bottom, "sanity check");
 
   size = align_up(pointer_delta(addr, bottom, 1) + size, os::Bsd::page_size());
+  Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(bottom), p2i(bottom+size), prot);
   return ::mprotect(bottom, size, prot) == 0;
 }
 
--- a/src/hotspot/os/linux/os_linux.cpp	Sat May 25 20:55:33 2019 +0900
+++ b/src/hotspot/os/linux/os_linux.cpp	Thu May 23 15:15:01 2019 +0200
@@ -3450,6 +3450,7 @@
   assert(addr == bottom, "sanity check");
 
   size = align_up(pointer_delta(addr, bottom, 1) + size, os::Linux::page_size());
+  Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(bottom), p2i(bottom+size), prot);
   return ::mprotect(bottom, size, prot) == 0;
 }
 
--- a/src/hotspot/os/solaris/os_solaris.cpp	Sat May 25 20:55:33 2019 +0900
+++ b/src/hotspot/os/solaris/os_solaris.cpp	Thu May 23 15:15:01 2019 +0200
@@ -2666,6 +2666,7 @@
 static bool solaris_mprotect(char* addr, size_t bytes, int prot) {
   assert(addr == (char*)align_down((uintptr_t)addr, os::vm_page_size()),
          "addr must be page aligned");
+  Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(addr), p2i(addr+bytes), prot);
   int retVal = mprotect(addr, bytes, prot);
   return retVal == 0;
 }
@@ -4229,6 +4230,7 @@
 
 // Mark the polling page as unreadable
 void os::make_polling_page_unreadable(void) {
+  Events::log(NULL, "Protecting polling page " INTPTR_FORMAT " with PROT_NONE", p2i(_polling_page));
   if (mprotect((char *)_polling_page, page_size, PROT_NONE) != 0) {
     fatal("Could not disable polling page");
   }
@@ -4236,6 +4238,7 @@
 
 // Mark the polling page as readable
 void os::make_polling_page_readable(void) {
+  Events::log(NULL, "Protecting polling page " INTPTR_FORMAT " with PROT_READ", p2i(_polling_page));
   if (mprotect((char *)_polling_page, page_size, PROT_READ) != 0) {
     fatal("Could not enable polling page");
   }
--- a/src/hotspot/share/runtime/globals.hpp	Sat May 25 20:55:33 2019 +0900
+++ b/src/hotspot/share/runtime/globals.hpp	Thu May 23 15:15:01 2019 +0200
@@ -444,7 +444,7 @@
   diagnostic(bool, LogEvents, true,                                         \
           "Enable the various ring buffer event logs")                      \
                                                                             \
-  diagnostic(uintx, LogEventsBufferEntries, 10,                             \
+  diagnostic(uintx, LogEventsBufferEntries, 20,                             \
           "Number of ring buffer event logs")                               \
           range(1, NOT_LP64(1*K) LP64_ONLY(1*M))                            \
                                                                             \
--- a/src/hotspot/share/utilities/events.hpp	Sat May 25 20:55:33 2019 +0900
+++ b/src/hotspot/share/utilities/events.hpp	Thu May 23 15:15:01 2019 +0200
@@ -232,7 +232,7 @@
 };
 
 inline void Events::log(Thread* thread, const char* format, ...) {
-  if (LogEvents) {
+  if (LogEvents && _messages != NULL) {
     va_list ap;
     va_start(ap, format);
     _messages->logv(thread, format, ap);
@@ -241,7 +241,7 @@
 }
 
 inline void Events::log_exception(Thread* thread, const char* format, ...) {
-  if (LogEvents) {
+  if (LogEvents && _exceptions != NULL) {
     va_list ap;
     va_start(ap, format);
     _exceptions->logv(thread, format, ap);
@@ -250,13 +250,13 @@
 }
 
 inline void Events::log_exception(Thread* thread, Handle h_exception, const char* message, const char* file, int line) {
-  if (LogEvents) {
+  if (LogEvents && _exceptions != NULL) {
     _exceptions->log(thread, h_exception, message, file, line);
   }
 }
 
 inline void Events::log_redefinition(Thread* thread, const char* format, ...) {
-  if (LogEvents) {
+  if (LogEvents && _redefinitions != NULL) {
     va_list ap;
     va_start(ap, format);
     _redefinitions->logv(thread, format, ap);
@@ -265,13 +265,13 @@
 }
 
 inline void Events::log_class_unloading(Thread* thread, InstanceKlass* ik) {
-  if (LogEvents) {
+  if (LogEvents && _class_unloading != NULL) {
     _class_unloading->log(thread, ik);
   }
 }
 
 inline void Events::log_deopt_message(Thread* thread, const char* format, ...) {
-  if (LogEvents) {
+  if (LogEvents && _deopt_messages != NULL) {
     va_list ap;
     va_start(ap, format);
     _deopt_messages->logv(thread, format, ap);