| 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 #if !defined(PRODUCT) |
| 21 FLAG_verbose_gc = true; | 22 FLAG_verbose_gc = true; |
| 23 #endif |
| 22 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 24 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 23 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 25 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 24 | 26 |
| 25 EXPECT_VALID(result); | 27 EXPECT_VALID(result); |
| 26 EXPECT(!Dart_IsNull(result)); | 28 EXPECT(!Dart_IsNull(result)); |
| 27 EXPECT(Dart_IsList(result)); | 29 EXPECT(Dart_IsList(result)); |
| 28 TransitionNativeToVM transition(thread); | 30 TransitionNativeToVM transition(thread); |
| 29 Isolate* isolate = Isolate::Current(); | 31 Isolate* isolate = Isolate::Current(); |
| 30 Heap* heap = isolate->heap(); | 32 Heap* heap = isolate->heap(); |
| 31 heap->CollectGarbage(Heap::kOld); | 33 heap->CollectGarbage(Heap::kOld); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 50 Heap* heap = isolate->heap(); | 52 Heap* heap = isolate->heap(); |
| 51 heap->CollectGarbage(Heap::kOld); | 53 heap->CollectGarbage(Heap::kOld); |
| 52 } | 54 } |
| 53 #endif | 55 #endif |
| 54 | 56 |
| 55 TEST_CASE(LargeSweep) { | 57 TEST_CASE(LargeSweep) { |
| 56 const char* kScriptChars = | 58 const char* kScriptChars = |
| 57 "main() {\n" | 59 "main() {\n" |
| 58 " return new List(8 * 1024 * 1024);\n" | 60 " return new List(8 * 1024 * 1024);\n" |
| 59 "}\n"; | 61 "}\n"; |
| 62 #if !defined(PRODUCT) |
| 60 FLAG_verbose_gc = true; | 63 FLAG_verbose_gc = true; |
| 64 #endif |
| 61 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 65 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 62 Dart_EnterScope(); | 66 Dart_EnterScope(); |
| 63 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 67 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 64 | 68 |
| 65 EXPECT_VALID(result); | 69 EXPECT_VALID(result); |
| 66 EXPECT(!Dart_IsNull(result)); | 70 EXPECT(!Dart_IsNull(result)); |
| 67 EXPECT(Dart_IsList(result)); | 71 EXPECT(Dart_IsList(result)); |
| 68 TransitionNativeToVM transition(thread); | 72 TransitionNativeToVM transition(thread); |
| 69 Isolate* isolate = Isolate::Current(); | 73 Isolate* isolate = Isolate::Current(); |
| 70 Heap* heap = isolate->heap(); | 74 Heap* heap = isolate->heap(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 100 const char* kScriptChars = | 104 const char* kScriptChars = |
| 101 "class A {\n" | 105 "class A {\n" |
| 102 " var a;\n" | 106 " var a;\n" |
| 103 " var b;\n" | 107 " var b;\n" |
| 104 "}\n" | 108 "}\n" |
| 105 "" | 109 "" |
| 106 "main() {\n" | 110 "main() {\n" |
| 107 " var x = new A();\n" | 111 " var x = new A();\n" |
| 108 " return new A();\n" | 112 " return new A();\n" |
| 109 "}\n"; | 113 "}\n"; |
| 114 bool saved_concurrent_sweep_mode = FLAG_concurrent_sweep; |
| 115 FLAG_concurrent_sweep = false; |
| 110 Dart_Handle h_lib = TestCase::LoadTestScript(kScriptChars, NULL); | 116 Dart_Handle h_lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 111 Isolate* isolate = Isolate::Current(); | 117 Isolate* isolate = Isolate::Current(); |
| 112 ClassTable* class_table = isolate->class_table(); | 118 ClassTable* class_table = isolate->class_table(); |
| 113 Heap* heap = isolate->heap(); | 119 Heap* heap = isolate->heap(); |
| 114 Dart_EnterScope(); | 120 Dart_EnterScope(); |
| 115 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); | 121 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); |
| 116 EXPECT_VALID(result); | 122 EXPECT_VALID(result); |
| 117 EXPECT(!Dart_IsNull(result)); | 123 EXPECT(!Dart_IsNull(result)); |
| 118 TransitionNativeToVM transition(thread); | 124 TransitionNativeToVM transition(thread); |
| 119 Library& lib = Library::Handle(); | 125 Library& lib = Library::Handle(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 heap->CollectGarbage(Heap::kOld); | 186 heap->CollectGarbage(Heap::kOld); |
| 181 // Verify postconditions: | 187 // Verify postconditions: |
| 182 EXPECT_EQ(1, class_stats->pre_gc.old_count); | 188 EXPECT_EQ(1, class_stats->pre_gc.old_count); |
| 183 EXPECT_EQ(0, class_stats->post_gc.old_count); | 189 EXPECT_EQ(0, class_stats->post_gc.old_count); |
| 184 EXPECT_EQ(0, class_stats->recent.old_count); | 190 EXPECT_EQ(0, class_stats->recent.old_count); |
| 185 // Perform GC. | 191 // Perform GC. |
| 186 heap->CollectGarbage(Heap::kOld); | 192 heap->CollectGarbage(Heap::kOld); |
| 187 EXPECT_EQ(0, class_stats->pre_gc.old_count); | 193 EXPECT_EQ(0, class_stats->pre_gc.old_count); |
| 188 EXPECT_EQ(0, class_stats->post_gc.old_count); | 194 EXPECT_EQ(0, class_stats->post_gc.old_count); |
| 189 EXPECT_EQ(0, class_stats->recent.old_count); | 195 EXPECT_EQ(0, class_stats->recent.old_count); |
| 196 FLAG_concurrent_sweep = saved_concurrent_sweep_mode; |
| 190 } | 197 } |
| 191 | 198 |
| 192 TEST_CASE(ArrayHeapStats) { | 199 TEST_CASE(ArrayHeapStats) { |
| 193 const char* kScriptChars = | 200 const char* kScriptChars = |
| 194 "List f(int len) {\n" | 201 "List f(int len) {\n" |
| 195 " return new List(len);\n" | 202 " return new List(len);\n" |
| 196 "}\n" | 203 "}\n" |
| 197 "" | 204 "" |
| 198 "main() {\n" | 205 "main() {\n" |
| 199 " return f(1234);\n" | 206 " return f(1234);\n" |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 | 549 |
| 543 heap->CollectAllGarbage(); | 550 heap->CollectAllGarbage(); |
| 544 | 551 |
| 545 intptr_t size_after = | 552 intptr_t size_after = |
| 546 heap->new_space()->UsedInWords() + heap->old_space()->UsedInWords(); | 553 heap->new_space()->UsedInWords() + heap->old_space()->UsedInWords(); |
| 547 | 554 |
| 548 EXPECT(size_before < size_after); | 555 EXPECT(size_before < size_after); |
| 549 } | 556 } |
| 550 | 557 |
| 551 } // namespace dart | 558 } // namespace dart |
| OLD | NEW |