Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: runtime/vm/heap_test.cc

Issue 747463002: Fix allocation stats bug on ARM; add unit test. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/class_table.cc ('k') | runtime/vm/stub_code_arm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // Invoke 'main' twice, since initial compilation might trigger extra array
190 // allocations.
191 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL);
192 EXPECT_VALID(result);
193 EXPECT(!Dart_IsNull(result));
194 Library& lib = Library::Handle();
195 lib ^= Api::UnwrapHandle(h_lib);
196 EXPECT(!lib.IsNull());
197 intptr_t before = class_stats->recent.new_size;
198 Dart_Handle result2 = Dart_Invoke(h_lib, NewString("main"), 0, NULL);
199 EXPECT_VALID(result2);
200 EXPECT(!Dart_IsNull(result2));
201 intptr_t after = class_stats->recent.new_size;
202 const intptr_t expected_size = Array::InstanceSize(1234);
203 // Invoking the method might involve some additional tiny array allocations,
204 // so we allow slightly more than expected.
205 static const intptr_t kTolerance = 10 * kWordSize;
206 EXPECT_LE(expected_size, after - before);
207 EXPECT_GT(expected_size + kTolerance, after - before);
208 Dart_ExitScope();
209 }
210
211
172 class FindOnly : public FindObjectVisitor { 212 class FindOnly : public FindObjectVisitor {
173 public: 213 public:
174 FindOnly(Isolate* isolate, RawObject* target) 214 FindOnly(Isolate* isolate, RawObject* target)
175 : FindObjectVisitor(isolate), target_(target) { 215 : FindObjectVisitor(isolate), target_(target) {
176 ASSERT(isolate->no_gc_scope_depth() != 0); 216 ASSERT(isolate->no_gc_scope_depth() != 0);
177 } 217 }
178 virtual ~FindOnly() { } 218 virtual ~FindOnly() { }
179 219
180 virtual bool FindObject(RawObject* obj) const { 220 virtual bool FindObject(RawObject* obj) const {
181 return obj == target_; 221 return obj == target_;
(...skipping 24 matching lines...) Expand all
206 } 246 }
207 } 247 }
208 { 248 {
209 NoGCScope no_gc; 249 NoGCScope no_gc;
210 FindNothing find_nothing; 250 FindNothing find_nothing;
211 EXPECT(Object::null() == heap->FindObject(&find_nothing)); 251 EXPECT(Object::null() == heap->FindObject(&find_nothing));
212 } 252 }
213 } 253 }
214 254
215 } // namespace dart. 255 } // namespace dart.
OLDNEW
« no previous file with comments | « runtime/vm/class_table.cc ('k') | runtime/vm/stub_code_arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698