Chromium Code Reviews| 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/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
| 10 #include "vm/heap.h" | 10 #include "vm/heap.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 EXPECT_EQ(0, class_stats->post_gc.old_count); | 162 EXPECT_EQ(0, class_stats->post_gc.old_count); |
| 163 EXPECT_EQ(0, class_stats->recent.old_count); | 163 EXPECT_EQ(0, class_stats->recent.old_count); |
| 164 // Perform GC. | 164 // Perform GC. |
| 165 heap->CollectGarbage(Heap::kOld); | 165 heap->CollectGarbage(Heap::kOld); |
| 166 EXPECT_EQ(0, class_stats->pre_gc.old_count); | 166 EXPECT_EQ(0, class_stats->pre_gc.old_count); |
| 167 EXPECT_EQ(0, class_stats->post_gc.old_count); | 167 EXPECT_EQ(0, class_stats->post_gc.old_count); |
| 168 EXPECT_EQ(0, class_stats->recent.old_count); | 168 EXPECT_EQ(0, class_stats->recent.old_count); |
| 169 } | 169 } |
| 170 | 170 |
| 171 | 171 |
| 172 TEST_CASE(ArrayHeapStats) { | |
| 173 const char* kScriptChars = | |
| 174 "List f(int len) {\n" | |
| 175 " return new List(len);\n" | |
| 176 "}\n" | |
| 177 "" | |
| 178 "main() {\n" | |
| 179 " return f(1234);\n" | |
| 180 "}\n"; | |
| 181 Dart_Handle h_lib = TestCase::LoadTestScript(kScriptChars, NULL); | |
| 182 Isolate* isolate = Isolate::Current(); | |
| 183 ClassTable* class_table = isolate->class_table(); | |
| 184 intptr_t cid = kArrayCid; | |
| 185 ClassHeapStats* class_stats = | |
| 186 ClassHeapStatsTestHelper::GetHeapStatsForCid(class_table, | |
| 187 cid); | |
| 188 Dart_EnterScope(); | |
| 189 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); | |
| 190 EXPECT_VALID(result); | |
| 191 EXPECT(!Dart_IsNull(result)); | |
| 192 Library& lib = Library::Handle(); | |
| 193 lib ^= Api::UnwrapHandle(h_lib); | |
| 194 EXPECT(!lib.IsNull()); | |
| 195 intptr_t before = class_stats->recent.new_size; | |
| 196 Dart_Handle result2 = Dart_Invoke(h_lib, NewString("main"), 0, NULL); | |
|
zra
2014/11/20 19:05:18
Add comment about invoking twice.
koda
2014/11/20 19:19:53
Done.
| |
| 197 EXPECT_VALID(result2); | |
| 198 EXPECT(!Dart_IsNull(result2)); | |
| 199 intptr_t after = class_stats->recent.new_size; | |
| 200 const intptr_t expected_size = Array::InstanceSize(1234); | |
| 201 // Invoking the method might involve some additional tiny array allocations, | |
| 202 // so we allow slightly more than expected. | |
| 203 static const intptr_t kTolerance = 10 * kWordSize; | |
| 204 EXPECT_LE(expected_size, after - before); | |
| 205 EXPECT_GT(expected_size + kTolerance, after - before); | |
| 206 Dart_ExitScope(); | |
| 207 } | |
| 208 | |
| 209 | |
| 172 class FindOnly : public FindObjectVisitor { | 210 class FindOnly : public FindObjectVisitor { |
| 173 public: | 211 public: |
| 174 FindOnly(Isolate* isolate, RawObject* target) | 212 FindOnly(Isolate* isolate, RawObject* target) |
| 175 : FindObjectVisitor(isolate), target_(target) { | 213 : FindObjectVisitor(isolate), target_(target) { |
| 176 ASSERT(isolate->no_gc_scope_depth() != 0); | 214 ASSERT(isolate->no_gc_scope_depth() != 0); |
| 177 } | 215 } |
| 178 virtual ~FindOnly() { } | 216 virtual ~FindOnly() { } |
| 179 | 217 |
| 180 virtual bool FindObject(RawObject* obj) const { | 218 virtual bool FindObject(RawObject* obj) const { |
| 181 return obj == target_; | 219 return obj == target_; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 206 } | 244 } |
| 207 } | 245 } |
| 208 { | 246 { |
| 209 NoGCScope no_gc; | 247 NoGCScope no_gc; |
| 210 FindNothing find_nothing; | 248 FindNothing find_nothing; |
| 211 EXPECT(Object::null() == heap->FindObject(&find_nothing)); | 249 EXPECT(Object::null() == heap->FindObject(&find_nothing)); |
| 212 } | 250 } |
| 213 } | 251 } |
| 214 | 252 |
| 215 } // namespace dart. | 253 } // namespace dart. |
| OLD | NEW |