Revision: 17270
Author:   [email protected]
Date:     Fri Oct 18 11:25:43 2013 UTC
Log:      HeapProfiler: integrate FindUntrackedObjects into js code.

In some cases we would like to check untracked objects right from the js code.
Otherwise the objects might be collected rigth before check.

BUG=none
[email protected], [email protected]

Review URL: https://codereview.chromium.org/27717003
http://code.google.com/p/v8/source/detail?r=17270

Modified:
 /branches/bleeding_edge/src/builtins.cc
 /branches/bleeding_edge/test/cctest/test-heap-profiler.cc

=======================================
--- /branches/bleeding_edge/src/builtins.cc     Fri Oct 18 10:59:55 2013 UTC
+++ /branches/bleeding_edge/src/builtins.cc     Fri Oct 18 11:25:43 2013 UTC
@@ -280,6 +280,11 @@
     profiler->ObjectMoveEvent(elms->address(),
                               new_elms->address(),
                               new_elms->Size());
+    if (profiler->is_tracking_allocations()) {
+      // Report filler object as a new allocation.
+      // Otherwise it will become an untracked object.
+      profiler->NewObjectEvent(elms->address(), elms->Size());
+    }
   }
   return new_elms;
 }
=======================================
--- /branches/bleeding_edge/test/cctest/test-heap-profiler.cc Mon Oct 14 12:41:28 2013 UTC +++ /branches/bleeding_edge/test/cctest/test-heap-profiler.cc Fri Oct 18 11:25:43 2013 UTC
@@ -2005,19 +2005,70 @@
       GetProperty(foo_func, v8::HeapGraphEdge::kInternal, "code");
   CHECK_NE(NULL, code);
 }
+
+
+
+class HeapProfilerExtension : public v8::Extension {
+ public:
+  static const char* kName;
+  HeapProfilerExtension() : v8::Extension(kName, kSource) { }
+  virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
+      v8::Handle<v8::String> name);
+  static void FindUntrackedObjects(
+      const v8::FunctionCallbackInfo<v8::Value>& args);
+ private:
+  static const char* kSource;
+};
+
+const char* HeapProfilerExtension::kName = "v8/heap-profiler";
+
+
+const char* HeapProfilerExtension::kSource =
+    "native function findUntrackedObjects();";
+
+
+v8::Handle<v8::FunctionTemplate> HeapProfilerExtension::GetNativeFunction(
+    v8::Handle<v8::String> name) {
+  if (name->Equals(v8::String::New("findUntrackedObjects"))) {
+    return v8::FunctionTemplate::New(
+        HeapProfilerExtension::FindUntrackedObjects);
+  } else {
+    CHECK(false);
+    return v8::Handle<v8::FunctionTemplate>();
+  }
+}
+
+
+void HeapProfilerExtension::FindUntrackedObjects(
+    const v8::FunctionCallbackInfo<v8::Value>& args) {
+  i::HeapProfiler* heap_profiler =
+ reinterpret_cast<i::HeapProfiler*>(args.GetIsolate()->GetHeapProfiler());
+  int untracked_objects = heap_profiler->FindUntrackedObjects();
+  args.GetReturnValue().Set(untracked_objects);
+  CHECK_EQ(0, untracked_objects);
+}
+
+
+static HeapProfilerExtension kHeapProfilerExtension;
+v8::DeclareExtension kHeapProfilerExtensionDeclaration(
+    &kHeapProfilerExtension);


// This is an example of using checking of JS allocations tracking in a test.
 TEST(HeapObjectsTracker) {
-  LocalContext env;
+  const char* extensions[] = { HeapProfilerExtension::kName };
+  v8::ExtensionConfiguration config(1, extensions);
+  LocalContext env(&config);
   v8::HandleScope scope(env->GetIsolate());
   HeapObjectsTracker tracker;
   CompileRun("var a = 1.2");
   CompileRun("var a = 1.2; var b = 1.0; var c = 1.0;");
   CompileRun(
-    "var a = [];"
-    "for (var i = 0; i < 5; ++i)"
+    "var a = [];\n"
+    "for (var i = 0; i < 5; ++i)\n"
     "    a[i] = i;\n"
-    "for (var i = 0; i < 3; ++i)"
-    "    a.shift();\n");
+    "findUntrackedObjects();\n"
+    "for (var i = 0; i < 3; ++i)\n"
+    "    a.shift();\n"
+    "findUntrackedObjects();\n");
 }

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to