OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/become.h" | 8 #include "vm/become.h" |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
11 #include "vm/heap.h" | 11 #include "vm/heap.h" |
12 #include "vm/unit_test.h" | 12 #include "vm/unit_test.h" |
13 | 13 |
14 namespace dart { | 14 namespace dart { |
15 | 15 |
16 TEST_CASE(OldGC) { | 16 TEST_CASE(OldGC) { |
17 const char* kScriptChars = | 17 const char* kScriptChars = |
18 "main() {\n" | 18 "main() {\n" |
19 " return [1, 2, 3];\n" | 19 " return [1, 2, 3];\n" |
20 "}\n"; | 20 "}\n"; |
21 NOT_IN_PRODUCT(FLAG_verbose_gc = true); | 21 FLAG_verbose_gc = true; |
22 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 22 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
23 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 23 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
24 | 24 |
25 EXPECT_VALID(result); | 25 EXPECT_VALID(result); |
26 EXPECT(!Dart_IsNull(result)); | 26 EXPECT(!Dart_IsNull(result)); |
27 EXPECT(Dart_IsList(result)); | 27 EXPECT(Dart_IsList(result)); |
28 TransitionNativeToVM transition(thread); | 28 TransitionNativeToVM transition(thread); |
29 Isolate* isolate = Isolate::Current(); | 29 Isolate* isolate = Isolate::Current(); |
30 Heap* heap = isolate->heap(); | 30 Heap* heap = isolate->heap(); |
31 heap->CollectGarbage(Heap::kOld); | 31 heap->CollectGarbage(Heap::kOld); |
(...skipping 11 matching lines...) Expand all Loading... |
43 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 43 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
44 | 44 |
45 EXPECT_VALID(result); | 45 EXPECT_VALID(result); |
46 EXPECT(!Dart_IsNull(result)); | 46 EXPECT(!Dart_IsNull(result)); |
47 EXPECT(Dart_IsList(result)); | 47 EXPECT(Dart_IsList(result)); |
48 TransitionNativeToVM transition(thread); | 48 TransitionNativeToVM transition(thread); |
49 Isolate* isolate = Isolate::Current(); | 49 Isolate* isolate = Isolate::Current(); |
50 Heap* heap = isolate->heap(); | 50 Heap* heap = isolate->heap(); |
51 heap->CollectGarbage(Heap::kOld); | 51 heap->CollectGarbage(Heap::kOld); |
52 } | 52 } |
53 #endif // !defined(PRODUCT) | 53 #endif |
54 | 54 |
55 TEST_CASE(LargeSweep) { | 55 TEST_CASE(LargeSweep) { |
56 const char* kScriptChars = | 56 const char* kScriptChars = |
57 "main() {\n" | 57 "main() {\n" |
58 " return new List(8 * 1024 * 1024);\n" | 58 " return new List(8 * 1024 * 1024);\n" |
59 "}\n"; | 59 "}\n"; |
60 NOT_IN_PRODUCT(FLAG_verbose_gc = true); | 60 FLAG_verbose_gc = true; |
61 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 61 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
62 Dart_EnterScope(); | 62 Dart_EnterScope(); |
63 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 63 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
64 | 64 |
65 EXPECT_VALID(result); | 65 EXPECT_VALID(result); |
66 EXPECT(!Dart_IsNull(result)); | 66 EXPECT(!Dart_IsNull(result)); |
67 EXPECT(Dart_IsList(result)); | 67 EXPECT(Dart_IsList(result)); |
68 TransitionNativeToVM transition(thread); | 68 TransitionNativeToVM transition(thread); |
69 Isolate* isolate = Isolate::Current(); | 69 Isolate* isolate = Isolate::Current(); |
70 Heap* heap = isolate->heap(); | 70 Heap* heap = isolate->heap(); |
(...skipping 29 matching lines...) Expand all Loading... |
100 const char* kScriptChars = | 100 const char* kScriptChars = |
101 "class A {\n" | 101 "class A {\n" |
102 " var a;\n" | 102 " var a;\n" |
103 " var b;\n" | 103 " var b;\n" |
104 "}\n" | 104 "}\n" |
105 "" | 105 "" |
106 "main() {\n" | 106 "main() {\n" |
107 " var x = new A();\n" | 107 " var x = new A();\n" |
108 " return new A();\n" | 108 " return new A();\n" |
109 "}\n"; | 109 "}\n"; |
110 bool saved_concurrent_sweep_mode = FLAG_concurrent_sweep; | |
111 FLAG_concurrent_sweep = false; | |
112 Dart_Handle h_lib = TestCase::LoadTestScript(kScriptChars, NULL); | 110 Dart_Handle h_lib = TestCase::LoadTestScript(kScriptChars, NULL); |
113 Isolate* isolate = Isolate::Current(); | 111 Isolate* isolate = Isolate::Current(); |
114 ClassTable* class_table = isolate->class_table(); | 112 ClassTable* class_table = isolate->class_table(); |
115 Heap* heap = isolate->heap(); | 113 Heap* heap = isolate->heap(); |
116 Dart_EnterScope(); | 114 Dart_EnterScope(); |
117 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); | 115 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); |
118 EXPECT_VALID(result); | 116 EXPECT_VALID(result); |
119 EXPECT(!Dart_IsNull(result)); | 117 EXPECT(!Dart_IsNull(result)); |
120 TransitionNativeToVM transition(thread); | 118 TransitionNativeToVM transition(thread); |
121 Library& lib = Library::Handle(); | 119 Library& lib = Library::Handle(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 heap->CollectGarbage(Heap::kOld); | 180 heap->CollectGarbage(Heap::kOld); |
183 // Verify postconditions: | 181 // Verify postconditions: |
184 EXPECT_EQ(1, class_stats->pre_gc.old_count); | 182 EXPECT_EQ(1, class_stats->pre_gc.old_count); |
185 EXPECT_EQ(0, class_stats->post_gc.old_count); | 183 EXPECT_EQ(0, class_stats->post_gc.old_count); |
186 EXPECT_EQ(0, class_stats->recent.old_count); | 184 EXPECT_EQ(0, class_stats->recent.old_count); |
187 // Perform GC. | 185 // Perform GC. |
188 heap->CollectGarbage(Heap::kOld); | 186 heap->CollectGarbage(Heap::kOld); |
189 EXPECT_EQ(0, class_stats->pre_gc.old_count); | 187 EXPECT_EQ(0, class_stats->pre_gc.old_count); |
190 EXPECT_EQ(0, class_stats->post_gc.old_count); | 188 EXPECT_EQ(0, class_stats->post_gc.old_count); |
191 EXPECT_EQ(0, class_stats->recent.old_count); | 189 EXPECT_EQ(0, class_stats->recent.old_count); |
192 FLAG_concurrent_sweep = saved_concurrent_sweep_mode; | |
193 } | 190 } |
194 | 191 |
195 TEST_CASE(ArrayHeapStats) { | 192 TEST_CASE(ArrayHeapStats) { |
196 const char* kScriptChars = | 193 const char* kScriptChars = |
197 "List f(int len) {\n" | 194 "List f(int len) {\n" |
198 " return new List(len);\n" | 195 " return new List(len);\n" |
199 "}\n" | 196 "}\n" |
200 "" | 197 "" |
201 "main() {\n" | 198 "main() {\n" |
202 " return f(1234);\n" | 199 " return f(1234);\n" |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 | 542 |
546 heap->CollectAllGarbage(); | 543 heap->CollectAllGarbage(); |
547 | 544 |
548 intptr_t size_after = | 545 intptr_t size_after = |
549 heap->new_space()->UsedInWords() + heap->old_space()->UsedInWords(); | 546 heap->new_space()->UsedInWords() + heap->old_space()->UsedInWords(); |
550 | 547 |
551 EXPECT(size_before < size_after); | 548 EXPECT(size_before < size_after); |
552 } | 549 } |
553 | 550 |
554 } // namespace dart | 551 } // namespace dart |
OLD | NEW |