8043770: File leak in MemNotifyThread::start() in hotspot.src.os.linux.vm.os_linux.cpp

Thu, 12 Mar 2015 22:03:16 -0400

author
cjplummer
date
Thu, 12 Mar 2015 22:03:16 -0400
changeset 7633
8461d0b03127
parent 7632
ffae627760ca
child 7634
ceaf8db28d68

8043770: File leak in MemNotifyThread::start() in hotspot.src.os.linux.vm.os_linux.cpp
Summary: Fixed by removing all code related to LowMemoryProtection, which removed offending code.
Reviewed-by: dholmes, minqi

src/os/aix/vm/os_aix.cpp file | annotate | diff | comparison | revisions
src/os/bsd/vm/os_bsd.cpp file | annotate | diff | comparison | revisions
src/os/linux/vm/os_linux.cpp file | annotate | diff | comparison | revisions
src/os/solaris/vm/os_solaris.cpp file | annotate | diff | comparison | revisions
src/os/windows/vm/os_windows.cpp file | annotate | diff | comparison | revisions
src/share/vm/runtime/globals.hpp file | annotate | diff | comparison | revisions
src/share/vm/runtime/os.hpp file | annotate | diff | comparison | revisions
src/share/vm/runtime/thread.cpp file | annotate | diff | comparison | revisions
     1.1 --- a/src/os/aix/vm/os_aix.cpp	Wed Jan 08 20:23:16 2014 -0500
     1.2 +++ b/src/os/aix/vm/os_aix.cpp	Thu Mar 12 22:03:16 2015 -0400
     1.3 @@ -3987,11 +3987,6 @@
     1.4    return JNI_OK;
     1.5  }
     1.6  
     1.7 -// this is called at the end of vm_initialization
     1.8 -void os::init_3(void) {
     1.9 -  return;
    1.10 -}
    1.11 -
    1.12  // Mark the polling page as unreadable
    1.13  void os::make_polling_page_unreadable(void) {
    1.14    if (!guard_memory((char*)_polling_page, Aix::page_size())) {
     2.1 --- a/src/os/bsd/vm/os_bsd.cpp	Wed Jan 08 20:23:16 2014 -0500
     2.2 +++ b/src/os/bsd/vm/os_bsd.cpp	Thu Mar 12 22:03:16 2015 -0400
     2.3 @@ -3745,9 +3745,6 @@
     2.4    return JNI_OK;
     2.5  }
     2.6  
     2.7 -// this is called at the end of vm_initialization
     2.8 -void os::init_3(void) { }
     2.9 -
    2.10  // Mark the polling page as unreadable
    2.11  void os::make_polling_page_unreadable(void) {
    2.12    if( !guard_memory((char*)_polling_page, Bsd::page_size()) )
     3.1 --- a/src/os/linux/vm/os_linux.cpp	Wed Jan 08 20:23:16 2014 -0500
     3.2 +++ b/src/os/linux/vm/os_linux.cpp	Thu Mar 12 22:03:16 2015 -0400
     3.3 @@ -160,35 +160,6 @@
     3.4  // Declarations
     3.5  static void unpackTime(timespec* absTime, bool isAbsolute, jlong time);
     3.6  
     3.7 -#ifdef JAVASE_EMBEDDED
     3.8 -class MemNotifyThread: public Thread {
     3.9 -  friend class VMStructs;
    3.10 - public:
    3.11 -  virtual void run();
    3.12 -
    3.13 - private:
    3.14 -  static MemNotifyThread* _memnotify_thread;
    3.15 -  int _fd;
    3.16 -
    3.17 - public:
    3.18 -
    3.19 -  // Constructor
    3.20 -  MemNotifyThread(int fd);
    3.21 -
    3.22 -  // Tester
    3.23 -  bool is_memnotify_thread() const { return true; }
    3.24 -
    3.25 -  // Printing
    3.26 -  char* name() const { return (char*)"Linux MemNotify Thread"; }
    3.27 -
    3.28 -  // Returns the single instance of the MemNotifyThread
    3.29 -  static MemNotifyThread* memnotify_thread() { return _memnotify_thread; }
    3.30 -
    3.31 -  // Create and start the single instance of MemNotifyThread
    3.32 -  static void start();
    3.33 -};
    3.34 -#endif // JAVASE_EMBEDDED
    3.35 -
    3.36  // utility functions
    3.37  
    3.38  static int SR_initialize();
    3.39 @@ -4913,17 +4884,6 @@
    3.40    return JNI_OK;
    3.41  }
    3.42  
    3.43 -// this is called at the end of vm_initialization
    3.44 -void os::init_3(void) {
    3.45 -#ifdef JAVASE_EMBEDDED
    3.46 -  // Start the MemNotifyThread
    3.47 -  if (LowMemoryProtection) {
    3.48 -    MemNotifyThread::start();
    3.49 -  }
    3.50 -  return;
    3.51 -#endif
    3.52 -}
    3.53 -
    3.54  // Mark the polling page as unreadable
    3.55  void os::make_polling_page_unreadable(void) {
    3.56    if( !guard_memory((char*)_polling_page, Linux::page_size()) )
    3.57 @@ -6100,83 +6060,6 @@
    3.58    return strlen(buffer);
    3.59  }
    3.60  
    3.61 -#ifdef JAVASE_EMBEDDED
    3.62 -//
    3.63 -// A thread to watch the '/dev/mem_notify' device, which will tell us when the OS is running low on memory.
    3.64 -//
    3.65 -MemNotifyThread* MemNotifyThread::_memnotify_thread = NULL;
    3.66 -
    3.67 -// ctor
    3.68 -//
    3.69 -MemNotifyThread::MemNotifyThread(int fd): Thread() {
    3.70 -  assert(memnotify_thread() == NULL, "we can only allocate one MemNotifyThread");
    3.71 -  _fd = fd;
    3.72 -
    3.73 -  if (os::create_thread(this, os::os_thread)) {
    3.74 -    _memnotify_thread = this;
    3.75 -    os::set_priority(this, NearMaxPriority);
    3.76 -    os::start_thread(this);
    3.77 -  }
    3.78 -}
    3.79 -
    3.80 -// Where all the work gets done
    3.81 -//
    3.82 -void MemNotifyThread::run() {
    3.83 -  assert(this == memnotify_thread(), "expected the singleton MemNotifyThread");
    3.84 -
    3.85 -  // Set up the select arguments
    3.86 -  fd_set rfds;
    3.87 -  if (_fd != -1) {
    3.88 -    FD_ZERO(&rfds);
    3.89 -    FD_SET(_fd, &rfds);
    3.90 -  }
    3.91 -
    3.92 -  // Now wait for the mem_notify device to wake up
    3.93 -  while (1) {
    3.94 -    // Wait for the mem_notify device to signal us..
    3.95 -    int rc = select(_fd+1, _fd != -1 ? &rfds : NULL, NULL, NULL, NULL);
    3.96 -    if (rc == -1) {
    3.97 -      perror("select!\n");
    3.98 -      break;
    3.99 -    } else if (rc) {
   3.100 -      //ssize_t free_before = os::available_memory();
   3.101 -      //tty->print ("Notified: Free: %dK \n",os::available_memory()/1024);
   3.102 -
   3.103 -      // The kernel is telling us there is not much memory left...
   3.104 -      // try to do something about that
   3.105 -
   3.106 -      // If we are not already in a GC, try one.
   3.107 -      if (!Universe::heap()->is_gc_active()) {
   3.108 -        Universe::heap()->collect(GCCause::_allocation_failure);
   3.109 -
   3.110 -        //ssize_t free_after = os::available_memory();
   3.111 -        //tty->print ("Post-Notify: Free: %dK\n",free_after/1024);
   3.112 -        //tty->print ("GC freed: %dK\n", (free_after - free_before)/1024);
   3.113 -      }
   3.114 -      // We might want to do something like the following if we find the GC's are not helping...
   3.115 -      // Universe::heap()->size_policy()->set_gc_time_limit_exceeded(true);
   3.116 -    }
   3.117 -  }
   3.118 -}
   3.119 -
   3.120 -//
   3.121 -// See if the /dev/mem_notify device exists, and if so, start a thread to monitor it.
   3.122 -//
   3.123 -void MemNotifyThread::start() {
   3.124 -  int    fd;
   3.125 -  fd = open ("/dev/mem_notify", O_RDONLY, 0);
   3.126 -  if (fd < 0) {
   3.127 -      return;
   3.128 -  }
   3.129 -
   3.130 -  if (memnotify_thread() == NULL) {
   3.131 -    new MemNotifyThread(fd);
   3.132 -  }
   3.133 -}
   3.134 -
   3.135 -#endif // JAVASE_EMBEDDED
   3.136 -
   3.137 -
   3.138  /////////////// Unit tests ///////////////
   3.139  
   3.140  #ifndef PRODUCT
     4.1 --- a/src/os/solaris/vm/os_solaris.cpp	Wed Jan 08 20:23:16 2014 -0500
     4.2 +++ b/src/os/solaris/vm/os_solaris.cpp	Thu Mar 12 22:03:16 2015 -0400
     4.3 @@ -5194,10 +5194,6 @@
     4.4    return JNI_OK;
     4.5  }
     4.6  
     4.7 -void os::init_3(void) {
     4.8 -  return;
     4.9 -}
    4.10 -
    4.11  // Mark the polling page as unreadable
    4.12  void os::make_polling_page_unreadable(void) {
    4.13    if( mprotect((char *)_polling_page, page_size, PROT_NONE) != 0 )
     5.1 --- a/src/os/windows/vm/os_windows.cpp	Wed Jan 08 20:23:16 2014 -0500
     5.2 +++ b/src/os/windows/vm/os_windows.cpp	Thu Mar 12 22:03:16 2015 -0400
     5.3 @@ -4062,10 +4062,6 @@
     5.4    return JNI_OK;
     5.5  }
     5.6  
     5.7 -void os::init_3(void) {
     5.8 -  return;
     5.9 -}
    5.10 -
    5.11  // Mark the polling page as unreadable
    5.12  void os::make_polling_page_unreadable(void) {
    5.13    DWORD old_status;
     6.1 --- a/src/share/vm/runtime/globals.hpp	Wed Jan 08 20:23:16 2014 -0500
     6.2 +++ b/src/share/vm/runtime/globals.hpp	Thu Mar 12 22:03:16 2015 -0400
     6.3 @@ -2048,9 +2048,6 @@
     6.4            "Provide more detailed and expensive TLAB statistics "            \
     6.5            "(with PrintTLAB)")                                               \
     6.6                                                                              \
     6.7 -  EMBEDDED_ONLY(product(bool, LowMemoryProtection, true,                    \
     6.8 -          "Enable LowMemoryProtection"))                                    \
     6.9 -                                                                            \
    6.10    product_pd(bool, NeverActAsServerClassMachine,                            \
    6.11            "Never act like a server-class machine")                          \
    6.12                                                                              \
     7.1 --- a/src/share/vm/runtime/os.hpp	Wed Jan 08 20:23:16 2014 -0500
     7.2 +++ b/src/share/vm/runtime/os.hpp	Thu Mar 12 22:03:16 2015 -0400
     7.3 @@ -159,7 +159,6 @@
     7.4    static void init_globals(void) {             // Called from init_globals() in init.cpp
     7.5      init_globals_ext();
     7.6    }
     7.7 -  static void init_3(void);                    // Called at the end of vm init
     7.8  
     7.9    // File names are case-insensitive on windows only
    7.10    // Override me as needed
     8.1 --- a/src/share/vm/runtime/thread.cpp	Wed Jan 08 20:23:16 2014 -0500
     8.2 +++ b/src/share/vm/runtime/thread.cpp	Thu Mar 12 22:03:16 2015 -0400
     8.3 @@ -3690,9 +3690,6 @@
     8.4        }
     8.5    }
     8.6  
     8.7 -  // Give os specific code one last chance to start
     8.8 -  os::init_3();
     8.9 -
    8.10    create_vm_timer.end();
    8.11  #ifdef ASSERT
    8.12    _vm_complete = true;

mercurial