Reviewers: Søren Gjesse,

Description:
Add an ability to initiate GC through V8 API.

I'm planning to use it in DevTools heap profiler. It is a common
scenario in debugging memory leaks to enforce GC, then perform an
operation, then enforce GC again to check for non-collected (that is,
leaked) objects. Using the existing GC extension isn't possible because
it doesn't exposed in the normal operation mode of Chromium.

Please review this at http://codereview.chromium.org/159787

Affected files:
   M include/v8.h
   M src/api.cc


Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index  
5e3dbffb68ce68058298308d5e72b280dda9d0d7..24e5d97164d95d086e6d0a19690b848f019086ac
  
100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -2080,6 +2080,11 @@ class V8EXPORT V8 {
    static void SetGlobalGCEpilogueCallback(GCCallback);

    /**
+   * Explicitly initiates garbage collection.
+   */
+  static void LaunchGC();
+
+  /**
     * Allows the host application to group objects together. If one
     * object in the group is alive, all objects in the group are alive.
     * After each garbage collection, object groups are removed. It is
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index  
08281012bdb05a012884b6375fa59f5357f85790..932cab90901a2dd3235853b41b42d28e376635d6
  
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -3212,6 +3212,12 @@ void V8::SetGlobalGCEpilogueCallback(GCCallback  
callback) {
  }


+void V8::LaunchGC() {
+  if (IsDeadCheck("v8::V8::LaunchGC()")) return;
+  i::Heap::CollectAllGarbage();
+}
+
+
  void V8::PauseProfiler() {
  #ifdef ENABLE_LOGGING_AND_PROFILING
    i::Logger::PauseProfiler();



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

Reply via email to