Avoid GC when printing shared function info.
authoryangguo@chromium.org <yangguo@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 27 Jul 2012 09:54:56 +0000 (09:54 +0000)
committeryangguo@chromium.org <yangguo@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 27 Jul 2012 09:54:56 +0000 (09:54 +0000)
R=mstarzinger@chromium.org
BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com/10828048

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

src/objects-printer.cc
test/cctest/test-heap.cc

index c35ed5e..9bd7a75 100644 (file)
@@ -794,7 +794,14 @@ void SharedFunctionInfo::SharedFunctionInfoPrint(FILE* out) {
   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 =");
index 9229a97..daf45ad 100644 (file)
@@ -1966,3 +1966,21 @@ TEST(Regress2237) {
   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