Revision: 12210
Author:   [email protected]
Date:     Fri Jul 27 02:54:56 2012
Log:      Avoid GC when printing shared function info.

[email protected]
BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com/10828048
http://code.google.com/p/v8/source/detail?r=12210

Modified:
 /branches/bleeding_edge/src/objects-printer.cc
 /branches/bleeding_edge/test/cctest/test-heap.cc

=======================================
--- /branches/bleeding_edge/src/objects-printer.cc      Mon Jul  9 01:59:03 2012
+++ /branches/bleeding_edge/src/objects-printer.cc      Fri Jul 27 02:54:56 2012
@@ -794,7 +794,14 @@
   code()->ShortPrint(out);
   if (HasSourceCode()) {
     PrintF(out, "\n - source code = ");
-    GetSourceCode()->ShortPrint(out);
+    String* source = String::cast(Script::cast(script())->source());
+    int start = start_position();
+    int length = end_position() - start;
+    SmartArrayPointer<char> source_string =
+        source->ToCString(DISALLOW_NULLS,
+                          FAST_STRING_TRAVERSAL,
+                          start, length, NULL);
+    PrintF(out, "%s", *source_string);
   }
   // Script files are often large, hard to read.
   // PrintF(out, "\n - script =");
=======================================
--- /branches/bleeding_edge/test/cctest/test-heap.cc Wed Jul 18 06:39:53 2012 +++ /branches/bleeding_edge/test/cctest/test-heap.cc Fri Jul 27 02:54:56 2012
@@ -1966,3 +1966,21 @@
   HEAP->CollectAllGarbage(Heap::kNoGCFlags);
   CHECK(SlicedString::cast(*slice)->parent()->IsSeqAsciiString());
 }
+
+
+#ifdef OBJECT_PRINT
+TEST(PrintSharedFunctionInfo) {
+  InitializeVM();
+  v8::HandleScope scope;
+  const char* source = "f = function() { return 987654321; }\n"
+                       "g = function() { return 123456789; }\n";
+  CompileRun(source);
+  Handle<JSFunction> g =
+      v8::Utils::OpenHandle(
+          *v8::Handle<v8::Function>::Cast(
+              v8::Context::GetCurrent()->Global()->Get(v8_str("g"))));
+
+  AssertNoAllocation no_alloc;
+  g->shared()->PrintLn();
+}
+#endif  // OBJECT_PRINT

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

Reply via email to