Created a factory method for allocating the debug info object. The new
authorsgjesse@gmail.com <sgjesse@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 1 Sep 2008 10:15:45 +0000 (10:15 +0000)
committersgjesse@gmail.com <sgjesse@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 1 Sep 2008 10:15:45 +0000 (10:15 +0000)
method ensures that there are no allocations during the setup.

This fixes test breakage on Linux in debug mode where allocation
happened while the debug info object was not fully set up making
verify heap unhappy.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@70 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/debug.cc
src/factory.cc
src/factory.h

index 89fc7d8e3ce6dae1d132096428745a413fa5500a..7487cdcb8217638a6686c0c297b71f3962dee056 100644 (file)
@@ -1154,24 +1154,7 @@ bool Debug::EnsureDebugInfo(Handle<SharedFunctionInfo> shared) {
   if (!EnsureCompiled(shared)) return false;
 
   // Create the debug info object.
-  Handle<DebugInfo> debug_info =
-      Handle<DebugInfo>::cast(Factory::NewStruct(DEBUG_INFO_TYPE));
-
-  // Get the function original code.
-  Handle<Code> code(shared->code());
-
-  // Debug info contains function, a copy of the original code and the executing
-  // code.
-  debug_info->set_shared(*shared);
-  debug_info->set_original_code(*Factory::CopyCode(code));
-  debug_info->set_code(*code);
-
-  // Link debug info to function.
-  shared->set_debug_info(*debug_info);
-
-  // Initially no active break points.
-  debug_info->set_break_points(
-      *Factory::NewFixedArray(Debug::kEstimatedNofBreakPointsInFunction));
+  Handle<DebugInfo> debug_info = Factory::NewDebugInfo(shared);
 
   // Add debug info to the list.
   DebugInfoListNode* node = new DebugInfoListNode(*debug_info);
index 8016965010083c7ce5b33b200d32664db9d61f85..39bc763ca6e42702f226880499babb76be6c137a 100644 (file)
@@ -28,6 +28,7 @@
 #include "v8.h"
 
 #include "api.h"
+#include "debug.h"
 #include "execution.h"
 #include "factory.h"
 #include "macro-assembler.h"
@@ -625,6 +626,37 @@ Handle<Object> Factory::ToObject(Handle<Object> object,
 }
 
 
+Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) {
+  // Get the original code of the function.
+  Handle<Code> code(shared->code());
+
+  // Create a copy of the code before allocating the debug info object to avoid
+  // allocation while setting up the debug info object.
+  Handle<Code> original_code(*Factory::CopyCode(code));
+
+  // Allocate initial fixed array for active break points before allocating the
+  // debug info object to avoid allocation while setting up the debug info
+  // object.
+  Handle<FixedArray> break_points(
+      Factory::NewFixedArray(Debug::kEstimatedNofBreakPointsInFunction));
+
+  // Create and set up the debug info object. Debug info contains function, a
+  // copy of the original code, the executing code and initial fixed array for
+  // active break points.
+  Handle<DebugInfo> debug_info =
+      Handle<DebugInfo>::cast(Factory::NewStruct(DEBUG_INFO_TYPE));
+  debug_info->set_shared(*shared);
+  debug_info->set_original_code(*original_code);
+  debug_info->set_code(*code);
+  debug_info->set_break_points(*break_points);
+
+  // Link debug info to function.
+  shared->set_debug_info(*debug_info);
+
+  return debug_info;
+}
+
+
 Handle<JSObject> Factory::NewArgumentsObject(Handle<Object> callee,
                                              int length) {
   CALL_HEAP_FUNCTION(Heap::AllocateArgumentsObject(*callee, length), JSObject);
index a0cd93660a91bd940574d5034a076625004bd792..40e13053dbc3b62f388f80a980e52b6a93384dd3 100644 (file)
@@ -289,6 +289,8 @@ class Factory : public AllStatic {
                                                   uint32_t key,
                                                   Handle<Object> value);
 
+  static Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
+
  private:
   static Handle<JSFunction> NewFunctionHelper(Handle<String> name,
                                               Handle<Object> prototype);