Author: [email protected]
Date: Thu Apr 16 14:01:05 2009
New Revision: 1729

Modified:
    branches/bleeding_edge/src/platform-freebsd.cc
    branches/bleeding_edge/src/platform-linux.cc
    branches/bleeding_edge/src/platform-macos.cc
    branches/bleeding_edge/src/platform-nullos.cc
    branches/bleeding_edge/src/platform-win32.cc
    branches/bleeding_edge/src/platform.h
    branches/bleeding_edge/src/runtime.cc
    branches/bleeding_edge/src/string-stream.cc
    branches/bleeding_edge/src/string-stream.h
    branches/bleeding_edge/src/top.cc
    branches/bleeding_edge/src/utils.h

Log:
Start addressing massive arrays on the stack. There is hardly ever
a reason to stack allocate large chunks of stack space.
- Runtime_GetCFrames used to allocate a frame size of 52040 bytes.
- PreallocatedMemoryThread::Run used to allocate 32784 bytes.
- Fixed StringStream overflow conditions.

Review URL: http://codereview.chromium.org/67197

Modified: branches/bleeding_edge/src/platform-freebsd.cc
==============================================================================
--- branches/bleeding_edge/src/platform-freebsd.cc      (original)
+++ branches/bleeding_edge/src/platform-freebsd.cc      Thu Apr 16 14:01:05 2009
@@ -262,7 +262,8 @@
  }


-int OS::StackWalk(OS::StackFrame* frames, int frames_size) {
+int OS::StackWalk(Vector<OS::StackFrame> frames) {
+  int frames_size = frames.length();
    void** addresses = NewArray<void*>(frames_size);

    int frames_count = backtrace(addresses, frames_size);

Modified: branches/bleeding_edge/src/platform-linux.cc
==============================================================================
--- branches/bleeding_edge/src/platform-linux.cc        (original)
+++ branches/bleeding_edge/src/platform-linux.cc        Thu Apr 16 14:01:05 2009
@@ -262,9 +262,10 @@
  }


-int OS::StackWalk(OS::StackFrame* frames, int frames_size) {
+int OS::StackWalk(Vector<OS::StackFrame> frames) {
    // backtrace is a glibc extension.
  #ifdef __GLIBC__
+  int frames_size = frames.length();
    void** addresses = NewArray<void*>(frames_size);

    int frames_count = backtrace(addresses, frames_size);

Modified: branches/bleeding_edge/src/platform-macos.cc
==============================================================================
--- branches/bleeding_edge/src/platform-macos.cc        (original)
+++ branches/bleeding_edge/src/platform-macos.cc        Thu Apr 16 14:01:05 2009
@@ -212,10 +212,11 @@
  }


-int OS::StackWalk(StackFrame* frames, int frames_size) {
+int OS::StackWalk(Vector<StackFrame> frames) {
  #ifndef MAC_OS_X_VERSION_10_5
    return 0;
  #else
+  int frames_size = frames.length();
    void** addresses = NewArray<void*>(frames_size);
    int frames_count = backtrace(addresses, frames_size);


Modified: branches/bleeding_edge/src/platform-nullos.cc
==============================================================================
--- branches/bleeding_edge/src/platform-nullos.cc       (original)
+++ branches/bleeding_edge/src/platform-nullos.cc       Thu Apr 16 14:01:05 2009
@@ -215,7 +215,7 @@
  }


-int OS::StackWalk(OS::StackFrame* frames, int frames_size) {
+int OS::StackWalk(Vector<OS::StackFrame> frames) {
    UNIMPLEMENTED();
    return 0;
  }

Modified: branches/bleeding_edge/src/platform-win32.cc
==============================================================================
--- branches/bleeding_edge/src/platform-win32.cc        (original)
+++ branches/bleeding_edge/src/platform-win32.cc        Thu Apr 16 14:01:05 2009
@@ -1161,7 +1161,7 @@
  // it is triggered by the use of inline assembler.
  #pragma warning(push)
  #pragma warning(disable : 4748)
-int OS::StackWalk(OS::StackFrame* frames, int frames_size) {
+int OS::StackWalk(Vector<OS::StackFrame> frames) {
    BOOL ok;

    // Load the required functions from DLL's.
@@ -1201,6 +1201,7 @@
    int frames_count = 0;

    // Collect stack frames.
+  int frames_size = frames.length();
    while (frames_count < frames_size) {
      ok = _StackWalk64(
          IMAGE_FILE_MACHINE_I386,    // MachineType
@@ -1284,7 +1285,7 @@

  #else  // __MINGW32__
  void OS::LogSharedLibraryAddresses() { }
-int OS::StackWalk(OS::StackFrame* frames, int frames_size) { return 0; }
+int OS::StackWalk(Vector<OS::StackFrame> frames) { return 0; }
  #endif  // __MINGW32__



Modified: branches/bleeding_edge/src/platform.h
==============================================================================
--- branches/bleeding_edge/src/platform.h       (original)
+++ branches/bleeding_edge/src/platform.h       Thu Apr 16 14:01:05 2009
@@ -207,7 +207,7 @@
      char text[kStackWalkMaxTextLen];
    };

-  static int StackWalk(StackFrame* frames, int frames_size);
+  static int StackWalk(Vector<StackFrame> frames);

    // Factory method for creating platform dependent Mutex.
    // Please use delete to reclaim the storage for the returned Mutex.

Modified: branches/bleeding_edge/src/runtime.cc
==============================================================================
--- branches/bleeding_edge/src/runtime.cc       (original)
+++ branches/bleeding_edge/src/runtime.cc       Thu Apr 16 14:01:05 2009
@@ -5929,8 +5929,8 @@
    if (result->IsFailure()) return result;

    static const int kMaxCFramesSize = 200;
-  OS::StackFrame frames[kMaxCFramesSize];
-  int frames_count = OS::StackWalk(frames, kMaxCFramesSize);
+  ScopedVector<OS::StackFrame> frames(kMaxCFramesSize);
+  int frames_count = OS::StackWalk(frames);
    if (frames_count == OS::kStackWalkError) {
      return Heap::undefined_value();
    }

Modified: branches/bleeding_edge/src/string-stream.cc
==============================================================================
--- branches/bleeding_edge/src/string-stream.cc (original)
+++ branches/bleeding_edge/src/string-stream.cc Thu Apr 16 14:01:05 2009
@@ -57,19 +57,26 @@


  bool StringStream::Put(char c) {
-  if (space() == 0) return false;
-  if (length_ >= capacity_ - 1) {
+  if (full()) return false;
+  ASSERT(length_ < capacity_);
+  // Since the trailing '\0' is not accounted for in length_ fullness is
+  // indicated by a difference of 1 between length_ and capacity_. Thus  
when
+  // reaching a difference of 2 we need to grow the buffer.
+  if (length_ == capacity_ - 2) {
      unsigned new_capacity = capacity_;
      char* new_buffer = allocator_->grow(&new_capacity);
      if (new_capacity > capacity_) {
        capacity_ = new_capacity;
        buffer_ = new_buffer;
      } else {
-      // Indicate truncation with dots.
-      memset(cursor(), '.', space());
-      length_ = capacity_;
-      buffer_[length_ - 2] = '\n';
-      buffer_[length_ - 1] = '\0';
+      // Reached the end of the available buffer.
+      ASSERT(capacity_ >= 5);
+      length_ = capacity_ - 1;  // Indicate fullness of the stream.
+      buffer_[length_ - 4] = '.';
+      buffer_[length_ - 3] = '.';
+      buffer_[length_ - 2] = '.';
+      buffer_[length_ - 1] = '\n';
+      buffer_[length_] = '\0';
        return false;
      }
    }
@@ -95,8 +102,7 @@

  void StringStream::Add(Vector<const char> format, Vector<FmtElm> elms) {
    // If we already ran out of space then return immediately.
-  if (space() == 0)
-    return;
+  if (full()) return;
    int offset = 0;
    int elm = 0;
    while (offset < format.length()) {
@@ -564,12 +570,10 @@
  }


+// Only grow once to the maximum allowable size.
  char* NoAllocationStringAllocator::grow(unsigned* bytes) {
-  unsigned new_bytes = *bytes * 2;
-  if (new_bytes > size_) {
-    new_bytes = size_;
-  }
-  *bytes = new_bytes;
+  ASSERT(size_ >= *bytes);
+  *bytes = size_;
    return space_;
  }


Modified: branches/bleeding_edge/src/string-stream.h
==============================================================================
--- branches/bleeding_edge/src/string-stream.h  (original)
+++ branches/bleeding_edge/src/string-stream.h  Thu Apr 16 14:01:05 2009
@@ -162,8 +162,8 @@
    unsigned length_;  // does not include terminating 0-character
    char* buffer_;

+  bool full() const { return (capacity_ - length_) == 1; }
    int space() const { return capacity_ - length_; }
-  char* cursor() const { return buffer_ + length_; }

    DISALLOW_IMPLICIT_CONSTRUCTORS(StringStream);
  };

Modified: branches/bleeding_edge/src/top.cc
==============================================================================
--- branches/bleeding_edge/src/top.cc   (original)
+++ branches/bleeding_edge/src/top.cc   Thu Apr 16 14:01:05 2009
@@ -116,7 +116,7 @@
    // When the thread starts running it will allocate a fixed number of  
bytes
    // on the stack and publish the location of this memory for others to  
use.
    void Run() {
-    EmbeddedVector<char, 32 * 1024> local_buffer;
+    EmbeddedVector<char, 15 * 1024> local_buffer;

      // Initialize the buffer with a known good value.
      OS::StrNCpy(local_buffer, "Trace data was not generated.\n",

Modified: branches/bleeding_edge/src/utils.h
==============================================================================
--- branches/bleeding_edge/src/utils.h  (original)
+++ branches/bleeding_edge/src/utils.h  Thu Apr 16 14:01:05 2009
@@ -406,6 +406,16 @@
  };


+template <typename T>
+class ScopedVector : public Vector<T> {
+ public:
+  explicit ScopedVector(int length) : Vector<T>(NewArray<T>(length),  
length) { }
+  ~ScopedVector() {
+    DeleteArray(this->start());
+  }
+};
+
+
  inline Vector<const char> CStrVector(const char* data) {
    return Vector<const char>(data, strlen(data));
  }

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to