Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // Dart test program testing code GC. | 5 // Dart test program testing code GC. |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import "dart:async"; | 8 import "dart:async"; |
| 9 import "dart:io"; | 9 import "dart:io"; |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 var ms = const Duration(milliseconds: 100); | 29 var ms = const Duration(milliseconds: 100); |
| 30 var t = new Timer.periodic(ms, (timer) { | 30 var t = new Timer.periodic(ms, (timer) { |
| 31 i++; | 31 i++; |
| 32 // Calling bar will trigger GC without foo being on the stack. This way | 32 // Calling bar will trigger GC without foo being on the stack. This way |
| 33 // the method can be collected. | 33 // the method can be collected. |
| 34 bar(); | 34 bar(); |
| 35 if (i > 1) { | 35 if (i > 1) { |
| 36 timer.cancel(); | 36 timer.cancel(); |
| 37 // foo is called again to make sure we can still run it even after | 37 // foo is called again to make sure we can still run it even after |
| 38 // its code has been detached. | 38 // its code has been detached. |
| 39 var ret = foo(2); | 39 var ret = foo(2); |
|
rmacnak
2017/08/04 00:44:21
GC after returning here may collect the second com
zra
2017/08/04 05:19:43
Maybe add this as a comment.
rmacnak
2017/08/04 17:33:44
Done.
| |
| 40 } | 40 } |
| 41 }); | 41 }); |
| 42 } | 42 } |
| 43 | 43 |
| 44 List<String> packageOptions() { | 44 List<String> packageOptions() { |
| 45 if (Platform.packageRoot != null) { | 45 if (Platform.packageRoot != null) { |
| 46 return <String>['--package-root=${Platform.packageRoot}']; | 46 return <String>['--package-root=${Platform.packageRoot}']; |
| 47 } else if (Platform.packageConfig != null) { | 47 } else if (Platform.packageConfig != null) { |
| 48 return <String>['--packages=${Platform.packageConfig}']; | 48 return <String>['--packages=${Platform.packageConfig}']; |
| 49 } else { | 49 } else { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 67 Platform.script.toFilePath(), | 67 Platform.script.toFilePath(), |
| 68 "--run" | 68 "--run" |
| 69 ]); | 69 ]); |
| 70 var pr = Process.runSync(Platform.executable, args); | 70 var pr = Process.runSync(Platform.executable, args); |
| 71 | 71 |
| 72 Expect.equals(0, pr.exitCode); | 72 Expect.equals(0, pr.exitCode); |
| 73 | 73 |
| 74 // Code drops are logged with --log-code-drop. Look through stdout for the | 74 // Code drops are logged with --log-code-drop. Look through stdout for the |
| 75 // message that foo's code was dropped. | 75 // message that foo's code was dropped. |
| 76 print(pr.stdout); | 76 print(pr.stdout); |
| 77 var count = 0; | 77 bool saw_foo2 = false; |
| 78 bool saw_detaching_foo = false; | |
| 79 bool saw_foo3 = false; | |
| 78 pr.stdout.split("\n").forEach((line) { | 80 pr.stdout.split("\n").forEach((line) { |
| 79 if (line.contains("foo=2")) { | 81 if (line.contains("foo=2")) { |
| 80 Expect.equals(0, count); | 82 Expect.isFalse(saw_foo2, "foo=2 ran twice"); |
| 81 count++; | 83 saw_foo2 = true; |
| 82 } | 84 } |
| 83 if (line.contains("Detaching code") && line.contains("foo")) { | 85 if (line.contains("Detaching code") && line.contains("foo")) { |
| 84 Expect.equals(1, count); | 86 Expect.isTrue(saw_foo2, "foo detached before running"); |
| 85 count++; | 87 // May detach twice. |
| 88 saw_detaching_foo = true; | |
| 86 } | 89 } |
| 87 if (line.contains("foo=3")) { | 90 if (line.contains("foo=3")) { |
| 88 Expect.equals(2, count); | 91 Expect.isFalse(saw_foo3, "foo=3 ran twice"); |
| 89 count++; | 92 Expect.isTrue(saw_detaching_foo, "foo should have been collected"); |
| 93 saw_foo3 = true; | |
| 90 } | 94 } |
| 91 }); | 95 }); |
| 92 Expect.equals(3, count); | 96 |
| 97 Expect.isTrue(saw_foo2, "Missing foo=2"); | |
| 98 Expect.isTrue(saw_detaching_foo, "Missing code collection for foo"); | |
| 99 Expect.isTrue(saw_foo3, "Missing foo=3"); | |
| 93 } | 100 } |
| 94 } | 101 } |
| OLD | NEW |