diff src/share/vm/runtime/os.cpp @ 11151:5e3b6f79d280

8020701: Avoid crashes in WatcherThread Reviewed-by: acorn, dcubed, dsimms
author rbackman
date Wed, 17 Jul 2013 13:48:15 +0200
parents 1f4355cee9a2
children 6b0fd0964b87 f92b82d454fa d8e99408faad 94c202aa2646 7ccce1a6fa4d
line wrap: on
line diff
--- a/src/share/vm/runtime/os.cpp	Thu Jul 18 06:47:15 2013 -0400
+++ b/src/share/vm/runtime/os.cpp	Wed Jul 17 13:48:15 2013 +0200
@@ -595,6 +595,22 @@
   NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1));
   NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size));
 
+#ifdef ASSERT
+  // checking for the WatcherThread and crash_protection first
+  // since os::malloc can be called when the libjvm.{dll,so} is
+  // first loaded and we don't have a thread yet.
+  // try to find the thread after we see that the watcher thread
+  // exists and has crash protection.
+  WatcherThread *wt = WatcherThread::watcher_thread();
+  if (wt != NULL && wt->has_crash_protection()) {
+    Thread* thread = ThreadLocalStorage::get_thread_slow();
+    if (thread == wt) {
+      assert(!wt->has_crash_protection(),
+          "Can't malloc with crash protection from WatcherThread");
+    }
+  }
+#endif
+
   if (size == 0) {
     // return a valid pointer if size is zero
     // if NULL is returned the calling functions assume out of memory.