[PATCH] Remove Internal{Alloc,Free} calls from StopTheWorld.

Sergey Matveev earthdok at google.com
Thu Apr 4 12:35:55 PDT 2013


Hi kcc, glider, samsonov,

Android flakiness should be fixed thusly.

http://llvm-reviews.chandlerc.com/D626

Files:
  lib/sanitizer_common/sanitizer_linux.cc
  lib/sanitizer_common/sanitizer_linux.h
  lib/sanitizer_common/sanitizer_stoptheworld_linux.cc

Index: lib/sanitizer_common/sanitizer_linux.cc
===================================================================
--- lib/sanitizer_common/sanitizer_linux.cc
+++ lib/sanitizer_common/sanitizer_linux.cc
@@ -651,9 +651,10 @@
 ThreadLister::ThreadLister(int pid)
   : pid_(pid),
     descriptor_(-1),
+    buffer_(4096),
     error_(true),
-    entry_((linux_dirent *)buffer_),
     bytes_read_(0) {
+  entry_ = (linux_dirent *)buffer_.data();
   char task_directory_path[80];
   internal_snprintf(task_directory_path, sizeof(task_directory_path),
                     "/proc/%d/task/", pid);
@@ -700,16 +701,16 @@
   CHECK_GE(descriptor_, 0);
   CHECK_NE(error_, true);
   bytes_read_ = internal_getdents(descriptor_,
-                                  (struct linux_dirent *)buffer_,
-                                  sizeof(buffer_));
+                                  (struct linux_dirent *)buffer_.data(),
+                                  buffer_.size());
   if (bytes_read_ < 0) {
     Report("Can't read directory entries from /proc/%d/task.\n", pid_);
     error_ = true;
     return false;
   } else if (bytes_read_ == 0) {
     return false;
   }
-  entry_ = (struct linux_dirent *)buffer_;
+  entry_ = (struct linux_dirent *)buffer_.data();
   return true;
 }
 
Index: lib/sanitizer_common/sanitizer_linux.h
===================================================================
--- lib/sanitizer_common/sanitizer_linux.h
+++ lib/sanitizer_common/sanitizer_linux.h
@@ -13,6 +13,7 @@
 #ifndef SANITIZER_LINUX_H
 #define SANITIZER_LINUX_H
 
+#include "sanitizer_common.h"
 #include "sanitizer_internal_defs.h"
 
 struct sigaltstack;
@@ -43,7 +44,7 @@
 
   int pid_;
   int descriptor_;
-  char buffer_[4096];
+  InternalScopedBuffer<char> buffer_;
   bool error_;
   struct linux_dirent* entry_;
   int bytes_read_;
Index: lib/sanitizer_common/sanitizer_stoptheworld_linux.cc
===================================================================
--- lib/sanitizer_common/sanitizer_stoptheworld_linux.cc
+++ lib/sanitizer_common/sanitizer_stoptheworld_linux.cc
@@ -148,27 +148,24 @@
 }
 
 bool ThreadSuspender::SuspendAllThreads() {
-  void *mem = InternalAlloc(sizeof(ThreadLister));
-  ThreadLister *thread_lister = new(mem) ThreadLister(pid_);
+  ThreadLister thread_lister(pid_);
   bool added_threads;
   do {
     // Run through the directory entries once.
     added_threads = false;
-    pid_t tid = thread_lister->GetNextTID();
+    pid_t tid = thread_lister.GetNextTID();
     while (tid >= 0) {
       if (SuspendThread(tid))
         added_threads = true;
-      tid = thread_lister->GetNextTID();
+      tid = thread_lister.GetNextTID();
     }
-    if (thread_lister->error()) {
+    if (thread_lister.error()) {
       // Detach threads and fail.
       ResumeAllThreads();
-      InternalFree(mem);
       return false;
     }
-    thread_lister->Reset();
+    thread_lister.Reset();
   } while (added_threads);
-  InternalFree(mem);
   return true;
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D626.1.patch
Type: text/x-patch
Size: 2976 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130404/8c709c83/attachment.bin>


More information about the llvm-commits mailing list