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

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

Issue 265773011: De-duplicate code by adding size-independent iteration. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 7 months 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/pages.h ('k') | no next file » | 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 "vm/pages.h" 5 #include "vm/pages.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/compiler_stats.h" 8 #include "vm/compiler_stats.h"
9 #include "vm/gc_marker.h" 9 #include "vm/gc_marker.h"
10 #include "vm/gc_sweeper.h" 10 #include "vm/gc_sweeper.h"
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 usage_.external_in_words -= size_in_words; 289 usage_.external_in_words -= size_in_words;
290 } 290 }
291 291
292 292
293 bool PageSpace::Contains(uword addr) const { 293 bool PageSpace::Contains(uword addr) const {
294 HeapPage* page = pages_; 294 HeapPage* page = pages_;
295 while (page != NULL) { 295 while (page != NULL) {
296 if (page->Contains(addr)) { 296 if (page->Contains(addr)) {
297 return true; 297 return true;
298 } 298 }
299 page = page->next(); 299 page = NextPageAnySize(page);
300 }
301
302 page = large_pages_;
303 while (page != NULL) {
304 if (page->Contains(addr)) {
305 return true;
306 }
307 page = page->next();
308 } 300 }
309 return false; 301 return false;
310 } 302 }
311 303
312 304
313 bool PageSpace::Contains(uword addr, HeapPage::PageType type) const { 305 bool PageSpace::Contains(uword addr, HeapPage::PageType type) const {
314 HeapPage* page = pages_; 306 HeapPage* page = pages_;
315 while (page != NULL) { 307 while (page != NULL) {
316 if ((page->type() == type) && page->Contains(addr)) { 308 if ((page->type() == type) && page->Contains(addr)) {
317 return true; 309 return true;
318 } 310 }
319 page = page->next(); 311 page = NextPageAnySize(page);
320 }
321
322 page = large_pages_;
323 while (page != NULL) {
324 if ((page->type() == type) && page->Contains(addr)) {
325 return true;
326 }
327 page = page->next();
328 } 312 }
329 return false; 313 return false;
330 } 314 }
331 315
332 316
333 void PageSpace::StartEndAddress(uword* start, uword* end) const { 317 void PageSpace::StartEndAddress(uword* start, uword* end) const {
334 ASSERT(pages_ != NULL || large_pages_ != NULL); 318 ASSERT(pages_ != NULL || large_pages_ != NULL);
335 *start = static_cast<uword>(~0); 319 *start = static_cast<uword>(~0);
336 *end = 0; 320 *end = 0;
337 for (HeapPage* page = pages_; page != NULL; page = page->next()) { 321 for (HeapPage* page = pages_; page != NULL; page = NextPageAnySize(page)) {
338 *start = Utils::Minimum(*start, page->object_start());
339 *end = Utils::Maximum(*end, page->object_end());
340 }
341 for (HeapPage* page = large_pages_; page != NULL; page = page->next()) {
342 *start = Utils::Minimum(*start, page->object_start()); 322 *start = Utils::Minimum(*start, page->object_start());
343 *end = Utils::Maximum(*end, page->object_end()); 323 *end = Utils::Maximum(*end, page->object_end());
344 } 324 }
345 ASSERT(*start != static_cast<uword>(~0)); 325 ASSERT(*start != static_cast<uword>(~0));
346 ASSERT(*end != 0); 326 ASSERT(*end != 0);
347 } 327 }
348 328
349 329
350 void PageSpace::VisitObjects(ObjectVisitor* visitor) const { 330 void PageSpace::VisitObjects(ObjectVisitor* visitor) const {
351 HeapPage* page = pages_; 331 HeapPage* page = pages_;
352 while (page != NULL) { 332 while (page != NULL) {
353 page->VisitObjects(visitor); 333 page->VisitObjects(visitor);
354 page = page->next(); 334 page = NextPageAnySize(page);
355 }
356
357 page = large_pages_;
358 while (page != NULL) {
359 page->VisitObjects(visitor);
360 page = page->next();
361 } 335 }
362 } 336 }
363 337
364 338
365 void PageSpace::VisitObjectPointers(ObjectPointerVisitor* visitor) const { 339 void PageSpace::VisitObjectPointers(ObjectPointerVisitor* visitor) const {
366 HeapPage* page = pages_; 340 HeapPage* page = pages_;
367 while (page != NULL) { 341 while (page != NULL) {
368 page->VisitObjectPointers(visitor); 342 page->VisitObjectPointers(visitor);
369 page = page->next(); 343 page = NextPageAnySize(page);
370 }
371
372 page = large_pages_;
373 while (page != NULL) {
374 page->VisitObjectPointers(visitor);
375 page = page->next();
376 } 344 }
377 } 345 }
378 346
379 347
380 RawObject* PageSpace::FindObject(FindObjectVisitor* visitor, 348 RawObject* PageSpace::FindObject(FindObjectVisitor* visitor,
381 HeapPage::PageType type) const { 349 HeapPage::PageType type) const {
382 ASSERT(Isolate::Current()->no_gc_scope_depth() != 0); 350 ASSERT(Isolate::Current()->no_gc_scope_depth() != 0);
383 HeapPage* page = pages_; 351 HeapPage* page = pages_;
384 while (page != NULL) { 352 while (page != NULL) {
385 if (page->type() == type) { 353 if (page->type() == type) {
386 RawObject* obj = page->FindObject(visitor); 354 RawObject* obj = page->FindObject(visitor);
387 if (obj != Object::null()) { 355 if (obj != Object::null()) {
388 return obj; 356 return obj;
389 } 357 }
390 } 358 }
391 page = page->next(); 359 page = NextPageAnySize(page);
392 }
393
394 page = large_pages_;
395 while (page != NULL) {
396 if (page->type() == type) {
397 RawObject* obj = page->FindObject(visitor);
398 if (obj != Object::null()) {
399 return obj;
400 }
401 }
402 page = page->next();
403 } 360 }
404 return Object::null(); 361 return Object::null();
405 } 362 }
406 363
407 364
408 void PageSpace::WriteProtect(bool read_only) { 365 void PageSpace::WriteProtect(bool read_only) {
409 HeapPage* page = pages_; 366 HeapPage* page = pages_;
410 while (page != NULL) { 367 while (page != NULL) {
411 page->WriteProtect(read_only); 368 page->WriteProtect(read_only);
412 page = page->next(); 369 page = NextPageAnySize(page);
413 }
414 page = large_pages_;
415 while (page != NULL) {
416 page->WriteProtect(read_only);
417 page = page->next();
418 } 370 }
419 } 371 }
420 372
421 373
422 void PageSpace::PrintToJSONObject(JSONObject* object) { 374 void PageSpace::PrintToJSONObject(JSONObject* object) {
423 JSONObject space(object, "old"); 375 JSONObject space(object, "old");
424 space.AddProperty("type", "PageSpace"); 376 space.AddProperty("type", "PageSpace");
425 space.AddProperty("id", "heaps/old"); 377 space.AddProperty("id", "heaps/old");
426 space.AddProperty("name", "PageSpace"); 378 space.AddProperty("name", "PageSpace");
427 space.AddProperty("user_name", "old"); 379 space.AddProperty("user_name", "old");
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 468
517 const int64_t start = OS::GetCurrentTimeMicros(); 469 const int64_t start = OS::GetCurrentTimeMicros();
518 470
519 if (FLAG_write_protect_code) { 471 if (FLAG_write_protect_code) {
520 // Make code pages writable. 472 // Make code pages writable.
521 HeapPage* current_page = pages_; 473 HeapPage* current_page = pages_;
522 while (current_page != NULL) { 474 while (current_page != NULL) {
523 if (current_page->type() == HeapPage::kExecutable) { 475 if (current_page->type() == HeapPage::kExecutable) {
524 current_page->WriteProtect(false); 476 current_page->WriteProtect(false);
525 } 477 }
526 current_page = current_page->next(); 478 current_page = NextPageAnySize(current_page);
527 }
528 current_page = large_pages_;
529 while (current_page != NULL) {
530 if (current_page->type() == HeapPage::kExecutable) {
531 current_page->WriteProtect(false);
532 }
533 current_page = current_page->next();
534 } 479 }
535 } 480 }
536 481
537 // Save old value before GCMarker visits the weak persistent handles. 482 // Save old value before GCMarker visits the weak persistent handles.
538 SpaceUsage usage_before = usage_; 483 SpaceUsage usage_before = usage_;
539 484
540 // Mark all reachable old-gen objects. 485 // Mark all reachable old-gen objects.
541 bool collect_code = FLAG_collect_code && ShouldCollectCode(); 486 bool collect_code = FLAG_collect_code && ShouldCollectCode();
542 GCMarker marker(heap_); 487 GCMarker marker(heap_);
543 marker.MarkObjects(isolate, this, invoke_api_callbacks, collect_code); 488 marker.MarkObjects(isolate, this, invoke_api_callbacks, collect_code);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 page = next_page; 529 page = next_page;
585 } 530 }
586 531
587 if (FLAG_write_protect_code) { 532 if (FLAG_write_protect_code) {
588 // Make code pages read-only. 533 // Make code pages read-only.
589 HeapPage* current_page = pages_; 534 HeapPage* current_page = pages_;
590 while (current_page != NULL) { 535 while (current_page != NULL) {
591 if (current_page->type() == HeapPage::kExecutable) { 536 if (current_page->type() == HeapPage::kExecutable) {
592 current_page->WriteProtect(true); 537 current_page->WriteProtect(true);
593 } 538 }
594 current_page = current_page->next(); 539 current_page = NextPageAnySize(current_page);
595 }
596 current_page = large_pages_;
597 while (current_page != NULL) {
598 if (current_page->type() == HeapPage::kExecutable) {
599 current_page->WriteProtect(true);
600 }
601 current_page = current_page->next();
602 } 540 }
603 } 541 }
604 542
605 int64_t end = OS::GetCurrentTimeMicros(); 543 int64_t end = OS::GetCurrentTimeMicros();
606 544
607 // Record signals for growth control. Include size of external allocations. 545 // Record signals for growth control. Include size of external allocations.
608 page_space_controller_.EvaluateGarbageCollection(usage_before, usage_, 546 page_space_controller_.EvaluateGarbageCollection(usage_before, usage_,
609 start, end); 547 start, end);
610 548
611 heap_->RecordTime(kMarkObjects, mid1 - start); 549 heap_->RecordTime(kMarkObjects, mid1 - start);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 return 0; 684 return 0;
747 } else { 685 } else {
748 ASSERT(total_time >= gc_time); 686 ASSERT(total_time >= gc_time);
749 int result= static_cast<int>((static_cast<double>(gc_time) / 687 int result= static_cast<int>((static_cast<double>(gc_time) /
750 static_cast<double>(total_time)) * 100); 688 static_cast<double>(total_time)) * 100);
751 return result; 689 return result;
752 } 690 }
753 } 691 }
754 692
755 } // namespace dart 693 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/pages.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698