Mercurial > hg > graal-jvmci-8
comparison src/os/linux/vm/os_linux.cpp @ 22883:8461d0b03127
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
author | cjplummer |
---|---|
date | Thu, 12 Mar 2015 22:03:16 -0400 |
parents | ddce0b7cee93 |
children | 915ca3e9d15e |
comparison
equal
deleted
inserted
replaced
22882:ffae627760ca | 22883:8461d0b03127 |
---|---|
157 /* Used to protect dlsym() calls */ | 157 /* Used to protect dlsym() calls */ |
158 static pthread_mutex_t dl_mutex; | 158 static pthread_mutex_t dl_mutex; |
159 | 159 |
160 // Declarations | 160 // Declarations |
161 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time); | 161 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time); |
162 | |
163 #ifdef JAVASE_EMBEDDED | |
164 class MemNotifyThread: public Thread { | |
165 friend class VMStructs; | |
166 public: | |
167 virtual void run(); | |
168 | |
169 private: | |
170 static MemNotifyThread* _memnotify_thread; | |
171 int _fd; | |
172 | |
173 public: | |
174 | |
175 // Constructor | |
176 MemNotifyThread(int fd); | |
177 | |
178 // Tester | |
179 bool is_memnotify_thread() const { return true; } | |
180 | |
181 // Printing | |
182 char* name() const { return (char*)"Linux MemNotify Thread"; } | |
183 | |
184 // Returns the single instance of the MemNotifyThread | |
185 static MemNotifyThread* memnotify_thread() { return _memnotify_thread; } | |
186 | |
187 // Create and start the single instance of MemNotifyThread | |
188 static void start(); | |
189 }; | |
190 #endif // JAVASE_EMBEDDED | |
191 | 162 |
192 // utility functions | 163 // utility functions |
193 | 164 |
194 static int SR_initialize(); | 165 static int SR_initialize(); |
195 | 166 |
4909 | 4880 |
4910 // initialize thread priority policy | 4881 // initialize thread priority policy |
4911 prio_init(); | 4882 prio_init(); |
4912 | 4883 |
4913 return JNI_OK; | 4884 return JNI_OK; |
4914 } | |
4915 | |
4916 // this is called at the end of vm_initialization | |
4917 void os::init_3(void) { | |
4918 #ifdef JAVASE_EMBEDDED | |
4919 // Start the MemNotifyThread | |
4920 if (LowMemoryProtection) { | |
4921 MemNotifyThread::start(); | |
4922 } | |
4923 return; | |
4924 #endif | |
4925 } | 4885 } |
4926 | 4886 |
4927 // Mark the polling page as unreadable | 4887 // Mark the polling page as unreadable |
4928 void os::make_polling_page_unreadable(void) { | 4888 void os::make_polling_page_unreadable(void) { |
4929 if( !guard_memory((char*)_polling_page, Linux::page_size()) ) | 4889 if( !guard_memory((char*)_polling_page, Linux::page_size()) ) |
6098 } | 6058 } |
6099 | 6059 |
6100 return strlen(buffer); | 6060 return strlen(buffer); |
6101 } | 6061 } |
6102 | 6062 |
6103 #ifdef JAVASE_EMBEDDED | |
6104 // | |
6105 // A thread to watch the '/dev/mem_notify' device, which will tell us when the OS is running low on memory. | |
6106 // | |
6107 MemNotifyThread* MemNotifyThread::_memnotify_thread = NULL; | |
6108 | |
6109 // ctor | |
6110 // | |
6111 MemNotifyThread::MemNotifyThread(int fd): Thread() { | |
6112 assert(memnotify_thread() == NULL, "we can only allocate one MemNotifyThread"); | |
6113 _fd = fd; | |
6114 | |
6115 if (os::create_thread(this, os::os_thread)) { | |
6116 _memnotify_thread = this; | |
6117 os::set_priority(this, NearMaxPriority); | |
6118 os::start_thread(this); | |
6119 } | |
6120 } | |
6121 | |
6122 // Where all the work gets done | |
6123 // | |
6124 void MemNotifyThread::run() { | |
6125 assert(this == memnotify_thread(), "expected the singleton MemNotifyThread"); | |
6126 | |
6127 // Set up the select arguments | |
6128 fd_set rfds; | |
6129 if (_fd != -1) { | |
6130 FD_ZERO(&rfds); | |
6131 FD_SET(_fd, &rfds); | |
6132 } | |
6133 | |
6134 // Now wait for the mem_notify device to wake up | |
6135 while (1) { | |
6136 // Wait for the mem_notify device to signal us.. | |
6137 int rc = select(_fd+1, _fd != -1 ? &rfds : NULL, NULL, NULL, NULL); | |
6138 if (rc == -1) { | |
6139 perror("select!\n"); | |
6140 break; | |
6141 } else if (rc) { | |
6142 //ssize_t free_before = os::available_memory(); | |
6143 //tty->print ("Notified: Free: %dK \n",os::available_memory()/1024); | |
6144 | |
6145 // The kernel is telling us there is not much memory left... | |
6146 // try to do something about that | |
6147 | |
6148 // If we are not already in a GC, try one. | |
6149 if (!Universe::heap()->is_gc_active()) { | |
6150 Universe::heap()->collect(GCCause::_allocation_failure); | |
6151 | |
6152 //ssize_t free_after = os::available_memory(); | |
6153 //tty->print ("Post-Notify: Free: %dK\n",free_after/1024); | |
6154 //tty->print ("GC freed: %dK\n", (free_after - free_before)/1024); | |
6155 } | |
6156 // We might want to do something like the following if we find the GC's are not helping... | |
6157 // Universe::heap()->size_policy()->set_gc_time_limit_exceeded(true); | |
6158 } | |
6159 } | |
6160 } | |
6161 | |
6162 // | |
6163 // See if the /dev/mem_notify device exists, and if so, start a thread to monitor it. | |
6164 // | |
6165 void MemNotifyThread::start() { | |
6166 int fd; | |
6167 fd = open ("/dev/mem_notify", O_RDONLY, 0); | |
6168 if (fd < 0) { | |
6169 return; | |
6170 } | |
6171 | |
6172 if (memnotify_thread() == NULL) { | |
6173 new MemNotifyThread(fd); | |
6174 } | |
6175 } | |
6176 | |
6177 #endif // JAVASE_EMBEDDED | |
6178 | |
6179 | |
6180 /////////////// Unit tests /////////////// | 6063 /////////////// Unit tests /////////////// |
6181 | 6064 |
6182 #ifndef PRODUCT | 6065 #ifndef PRODUCT |
6183 | 6066 |
6184 #define test_log(...) \ | 6067 #define test_log(...) \ |