Add a flag to d8 to invoke weak callbacks
authorjochen@chromium.org <jochen@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 27 May 2014 13:57:48 +0000 (13:57 +0000)
committerjochen@chromium.org <jochen@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 27 May 2014 13:57:48 +0000 (13:57 +0000)
This will send an idle notification and a low memory notification after
each test.

For some reason it's not enough to send a low memory notification alone.

BUG=none
R=yangguo@chromium.org
LOG=n

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

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

src/d8.cc
src/d8.h
tools/run-tests.py

index 73bde94..b1d996a 100644 (file)
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -1190,6 +1190,21 @@ i::Thread::Options SourceGroup::GetThreadOptions() {
 }
 
 
+void SuggestivelyAskForAggressiveGC() {
+  if (Shell::options.send_idle_notification) {
+    const int kLongIdlePauseInMs = 1000;
+    V8::ContextDisposedNotification();
+    V8::IdleNotification(kLongIdlePauseInMs);
+  }
+  if (Shell::options.invoke_weak_callbacks) {
+    // By sending a low memory notifications, we will try hard to collect
+    // all garbage and will therefore also invoke all weak callbacks of
+    // actually unreachable persistent handles.
+    V8::LowMemoryNotification();
+  }
+}
+
+
 void SourceGroup::ExecuteInThread() {
   Isolate* isolate = Isolate::New();
   do {
@@ -1206,14 +1221,11 @@ void SourceGroup::ExecuteInThread() {
           Execute(isolate);
         }
       }
-      if (Shell::options.send_idle_notification) {
-        const int kLongIdlePauseInMs = 1000;
-        V8::ContextDisposedNotification();
-        V8::IdleNotification(kLongIdlePauseInMs);
-      }
+      SuggestivelyAskForAggressiveGC();
     }
     done_semaphore_.Signal();
   } while (!Shell::options.last_run);
+
   isolate->Dispose();
 }
 
@@ -1274,6 +1286,11 @@ bool Shell::SetOptions(int argc, char* argv[]) {
     } else if (strcmp(argv[i], "--send-idle-notification") == 0) {
       options.send_idle_notification = true;
       argv[i] = NULL;
+    } else if (strcmp(argv[i], "--invoke-weak-callbacks") == 0) {
+      options.invoke_weak_callbacks = true;
+      // TODO(jochen) See issue 3351
+      options.send_idle_notification = true;
+      argv[i] = NULL;
     } else if (strcmp(argv[i], "-f") == 0) {
       // Ignore any -f flags for compatibility with other stand-alone
       // JavaScript engines.
@@ -1362,11 +1379,7 @@ int Shell::RunMain(Isolate* isolate, int argc, char* argv[]) {
       options.isolate_sources[0].Execute(isolate);
     }
   }
-  if (options.send_idle_notification) {
-    const int kLongIdlePauseInMs = 1000;
-    V8::ContextDisposedNotification();
-    V8::IdleNotification(kLongIdlePauseInMs);
-  }
+  SuggestivelyAskForAggressiveGC();
 
 #ifndef V8_SHARED
   for (int i = 1; i < options.num_isolates; ++i) {
index 2c7513f..1f7f5d1 100644 (file)
--- a/src/d8.h
+++ b/src/d8.h
@@ -198,6 +198,7 @@ class ShellOptions {
      script_executed(false),
      last_run(true),
      send_idle_notification(false),
+     invoke_weak_callbacks(false),
      stress_opt(false),
      stress_deopt(false),
      interactive_shell(false),
@@ -220,6 +221,7 @@ class ShellOptions {
   bool script_executed;
   bool last_run;
   bool send_idle_notification;
+  bool invoke_weak_callbacks;
   bool stress_opt;
   bool stress_deopt;
   bool interactive_shell;
index b02fcfa..5824f25 100755 (executable)
@@ -257,7 +257,7 @@ def ProcessOptions(options):
     options.extra_flags += GC_STRESS_FLAGS
 
   if options.asan:
-    options.extra_flags.append("--send-idle-notification")
+    options.extra_flags.append("--invoke-weak-callbacks")
 
   if options.j == 0:
     options.j = multiprocessing.cpu_count()