Reviewers: jochen,

Message:
PTAL

Description:
Fixed memory-leak in d8. It did not clean evaluation context used for executing
shell commands.

BUG=chromium:493284
LOG=N

Please review this at https://codereview.chromium.org/1147343004/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+26, -11 lines):
  M src/d8.h
  M src/d8.cc
  A + test/mjsunit/regress/regress-crbug-493284.js


Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index e43a7c54055b8bf3ee37cb6f10d354331d035a01..fc1288c45ba9afc54624e2c0f708fceb8cc9aae9 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -1076,6 +1076,13 @@ inline bool operator<(const CounterAndKey& lhs, const CounterAndKey& rhs) {


 void Shell::OnExit(v8::Isolate* isolate) {
+  // Shut down contexts and collect garbage.
+  evaluation_context_.Reset();
+#ifndef V8_SHARED
+  utility_context_.Reset();
+#endif  // !V8_SHARED
+  CollectGarbage(isolate);
+
   LineEditor* line_editor = LineEditor::Get();
   if (line_editor) line_editor->Close();
 #ifndef V8_SHARED
@@ -1413,6 +1420,10 @@ bool Shell::SetOptions(int argc, char* argv[]) {
     } else if (strcmp(argv[i], "--test") == 0) {
       options.test_shell = true;
       argv[i] = NULL;
+    } else if (strcmp(argv[i], "--notest") == 0 ||
+               strcmp(argv[i], "--no-test") == 0) {
+      options.test_shell = false;
+      argv[i] = NULL;
     } else if (strcmp(argv[i], "--send-idle-notification") == 0) {
       options.send_idle_notification = true;
       argv[i] = NULL;
@@ -1542,6 +1553,17 @@ int Shell::RunMain(Isolate* isolate, int argc, char* argv[]) {
       options.isolate_sources[0].Execute(isolate);
     }
   }
+  CollectGarbage(isolate);
+#ifndef V8_SHARED
+  for (int i = 1; i < options.num_isolates; ++i) {
+    options.isolate_sources[i].WaitForThread();
+  }
+#endif  // !V8_SHARED
+  return 0;
+}
+
+
+void Shell::CollectGarbage(Isolate* isolate) {
   if (options.send_idle_notification) {
     const double kLongIdlePauseInSeconds = 1.0;
     isolate->ContextDisposedNotification();
@@ -1554,13 +1576,6 @@ int Shell::RunMain(Isolate* isolate, int argc, char* argv[]) {
     // unreachable persistent handles.
     isolate->LowMemoryNotification();
   }
-
-#ifndef V8_SHARED
-  for (int i = 1; i < options.num_isolates; ++i) {
-    options.isolate_sources[i].WaitForThread();
-  }
-#endif  // !V8_SHARED
-  return 0;
 }


Index: src/d8.h
diff --git a/src/d8.h b/src/d8.h
index 1f4bee29ed9dec50847fe6ac499d0354fe344d21..aac622833194e5815bd3a0424705049a79cefea7 100644
--- a/src/d8.h
+++ b/src/d8.h
@@ -264,6 +264,7 @@ class Shell : public i::AllStatic {
   static int Main(int argc, char* argv[]);
   static void Exit(int exit_code);
   static void OnExit(Isolate* isolate);
+  static void CollectGarbage(Isolate* isolate);

 #ifndef V8_SHARED
   static Handle<Array> GetCompletions(Isolate* isolate,
Index: test/mjsunit/regress/regress-crbug-493284.js
diff --git a/test/message/destructuring-modify-const.js b/test/mjsunit/regress/regress-crbug-493284.js
similarity index 56%
copy from test/message/destructuring-modify-const.js
copy to test/mjsunit/regress/regress-crbug-493284.js
index cabd924b37ea9f178259f4c979c3b3268920c713..85f7d2af9132d867358943b2899fad7819a78f0b 100644
--- a/test/message/destructuring-modify-const.js
+++ b/test/mjsunit/regress/regress-crbug-493284.js
@@ -2,8 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.

-// Flags: --harmony-destructuring
-'use strict';
+// Flags: --invoke-weak-callbacks --omit-quit --no-test

-const { x : x, y : y } = { x : 1, y : 2 };
-x++;
+var coll = new Intl.Collator();
+assertEquals(-1, coll.compare('a', 'c'));


--
--
v8-dev mailing list
v8-dev@googlegroups.com
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 v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to