Introduce an API mirroring the gc extension
authorjochen@chromium.org <jochen@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 13 Jan 2014 12:03:31 +0000 (12:03 +0000)
committerjochen@chromium.org <jochen@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 13 Jan 2014 12:03:31 +0000 (12:03 +0000)
BUG=none
R=mstarzinger@chromium.org, svenpanne@chromium.org
LOG=y

Review URL: https://codereview.chromium.org/131443008

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

include/v8.h
src/api.cc

index bcc4b3e7100d082d90f89a21dbd9eb61cc3e5178..d1867521f51e0ed395263c87efd98902dac36c3d 100644 (file)
@@ -3963,6 +3963,15 @@ class V8_EXPORT Isolate {
     Scope& operator=(const Scope&);
   };
 
+  /**
+   * Types of garbage collections that can be requested via
+   * RequestGarbageCollectionForTesting.
+   */
+  enum GarbageCollectionType {
+    kFullGarbageCollection,
+    kMinorGarbageCollection
+  };
+
   /**
    * Creates a new isolate.  Does not change the currently entered
    * isolate.
@@ -4175,6 +4184,17 @@ class V8_EXPORT Isolate {
    */
   void ClearInterrupt();
 
+  /**
+   * Request garbage collection in this Isolate. It is only valid to call this
+   * function if --expose_gc was specified.
+   *
+   * This should only be used for testing purposes and not to enforce a garbage
+   * collection schedule. It has strong negative impact on the garbage
+   * collection performance. Use IdleNotification() or LowMemoryNotification()
+   * instead to influence the garbage collection schedule.
+   */
+  void RequestGarbageCollectionForTesting(GarbageCollectionType type);
+
  private:
   Isolate();
   Isolate(const Isolate&);
index a1a192e45714c4d888062389b5fe8e2367746057..5ef6e5924998110c94bda8fe2ea35fb8c42ea24c 100644 (file)
@@ -6412,6 +6412,21 @@ void Isolate::ClearInterrupt() {
 }
 
 
+void Isolate::RequestGarbageCollectionForTesting(GarbageCollectionType type) {
+  CHECK(i::FLAG_expose_gc);
+  if (type == kMinorGarbageCollection) {
+    reinterpret_cast<i::Isolate*>(this)->heap()->CollectGarbage(
+        i::NEW_SPACE, "Isolate::RequestGarbageCollection",
+        kGCCallbackFlagForced);
+  } else {
+    ASSERT_EQ(kFullGarbageCollection, type);
+    reinterpret_cast<i::Isolate*>(this)->heap()->CollectAllGarbage(
+        i::Heap::kNoGCFlags, "Isolate::RequestGarbageCollection",
+        kGCCallbackFlagForced);
+  }
+}
+
+
 Isolate* Isolate::GetCurrent() {
   i::Isolate* isolate = i::Isolate::UncheckedCurrent();
   return reinterpret_cast<Isolate*>(isolate);