OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 2502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2513 if (current_ == NULL) return NULL; | 2513 if (current_ == NULL) return NULL; |
2514 | 2514 |
2515 HeapObject* object = current_->GetObject(); | 2515 HeapObject* object = current_->GetObject(); |
2516 current_ = current_->next_page(); | 2516 current_ = current_->next_page(); |
2517 return object; | 2517 return object; |
2518 } | 2518 } |
2519 | 2519 |
2520 | 2520 |
2521 // ----------------------------------------------------------------------------- | 2521 // ----------------------------------------------------------------------------- |
2522 // LargeObjectSpace | 2522 // LargeObjectSpace |
2523 static bool ComparePointers(void* key1, void* key2) { | |
2524 return key1 == key2; | |
2525 } | |
2526 | |
2523 | 2527 |
2524 LargeObjectSpace::LargeObjectSpace(Heap* heap, | 2528 LargeObjectSpace::LargeObjectSpace(Heap* heap, |
2525 intptr_t max_capacity, | 2529 intptr_t max_capacity, |
2526 AllocationSpace id) | 2530 AllocationSpace id) |
2527 : Space(heap, id, NOT_EXECUTABLE), // Managed on a per-allocation basis | 2531 : Space(heap, id, NOT_EXECUTABLE), // Managed on a per-allocation basis |
2528 max_capacity_(max_capacity), | 2532 max_capacity_(max_capacity), |
2529 first_page_(NULL), | 2533 first_page_(NULL), |
2530 size_(0), | 2534 size_(0), |
2531 page_count_(0), | 2535 page_count_(0), |
2532 objects_size_(0) {} | 2536 objects_size_(0), |
2537 chunk_map_(ComparePointers, 1024) {} | |
2533 | 2538 |
2534 | 2539 |
2535 bool LargeObjectSpace::SetUp() { | 2540 bool LargeObjectSpace::SetUp() { |
2536 first_page_ = NULL; | 2541 first_page_ = NULL; |
2537 size_ = 0; | 2542 size_ = 0; |
2538 page_count_ = 0; | 2543 page_count_ = 0; |
2539 objects_size_ = 0; | 2544 objects_size_ = 0; |
2545 chunk_map_.Clear(); | |
2540 return true; | 2546 return true; |
2541 } | 2547 } |
2542 | 2548 |
2543 | 2549 |
2544 void LargeObjectSpace::TearDown() { | 2550 void LargeObjectSpace::TearDown() { |
2545 while (first_page_ != NULL) { | 2551 while (first_page_ != NULL) { |
2546 LargePage* page = first_page_; | 2552 LargePage* page = first_page_; |
2547 first_page_ = first_page_->next_page(); | 2553 first_page_ = first_page_->next_page(); |
2548 LOG(heap()->isolate(), DeleteEvent("LargeObjectChunk", page->address())); | 2554 LOG(heap()->isolate(), DeleteEvent("LargeObjectChunk", page->address())); |
2549 | 2555 |
(...skipping 23 matching lines...) Expand all Loading... | |
2573 AllocateLargePage(object_size, executable, this); | 2579 AllocateLargePage(object_size, executable, this); |
2574 if (page == NULL) return Failure::RetryAfterGC(identity()); | 2580 if (page == NULL) return Failure::RetryAfterGC(identity()); |
2575 ASSERT(page->area_size() >= object_size); | 2581 ASSERT(page->area_size() >= object_size); |
2576 | 2582 |
2577 size_ += static_cast<int>(page->size()); | 2583 size_ += static_cast<int>(page->size()); |
2578 objects_size_ += object_size; | 2584 objects_size_ += object_size; |
2579 page_count_++; | 2585 page_count_++; |
2580 page->set_next_page(first_page_); | 2586 page->set_next_page(first_page_); |
2581 first_page_ = page; | 2587 first_page_ = page; |
2582 | 2588 |
2589 // Register all MemoryChunk::kAlignment-aligned chunks covered by | |
2590 // this large page in the chunk map. | |
2591 uint32_t base = reinterpret_cast<uint32_t>(page)/MemoryChunk::kAlignment; | |
Vyacheslav Egorov (Chromium)
2012/03/09 12:15:37
casting page to uint32_t is not suitable for 64-bi
kewpie.w.zp
2012/03/12 02:00:40
Done.
| |
2592 uint32_t limit = base + (page->size()-1)/MemoryChunk::kAlignment; | |
2593 for (uint32_t key = base; key <= limit; key++) { | |
2594 HashMap::Entry* entry = chunk_map_.Lookup(reinterpret_cast<void*>(key), | |
2595 key, true); | |
2596 ASSERT(entry != NULL); | |
2597 entry->value = page; | |
2598 } | |
2599 | |
2583 HeapObject* object = page->GetObject(); | 2600 HeapObject* object = page->GetObject(); |
2584 | 2601 |
2585 #ifdef DEBUG | 2602 #ifdef DEBUG |
2586 // Make the object consistent so the heap can be vefified in OldSpaceStep. | 2603 // Make the object consistent so the heap can be vefified in OldSpaceStep. |
2587 reinterpret_cast<Object**>(object->address())[0] = | 2604 reinterpret_cast<Object**>(object->address())[0] = |
2588 heap()->fixed_array_map(); | 2605 heap()->fixed_array_map(); |
2589 reinterpret_cast<Object**>(object->address())[1] = Smi::FromInt(0); | 2606 reinterpret_cast<Object**>(object->address())[1] = Smi::FromInt(0); |
2590 #endif | 2607 #endif |
2591 | 2608 |
2592 heap()->incremental_marking()->OldSpaceStep(object_size); | 2609 heap()->incremental_marking()->OldSpaceStep(object_size); |
2593 return object; | 2610 return object; |
2594 } | 2611 } |
2595 | 2612 |
2596 | 2613 |
2597 // GC support | 2614 // GC support |
2598 MaybeObject* LargeObjectSpace::FindObject(Address a) { | 2615 MaybeObject* LargeObjectSpace::FindObject(Address a) { |
2599 for (LargePage* page = first_page_; | 2616 LargePage* page = FindPageContainingPc(a); |
Vyacheslav Egorov (Chromium)
2012/03/09 12:15:37
I would suggest retaining FindPageContainingPc bec
kewpie.w.zp
2012/03/12 02:00:40
Not very sure if I catch your point. Please allow
Vyacheslav Egorov (Chromium)
2012/03/12 12:04:12
My original comment should read: "I would suggest
kewpie.w.zp
2012/03/13 01:44:35
I see. Maybe it's named so because called by Inner
Vyacheslav Egorov (Chromium)
2012/03/13 11:39:11
FindPage sounds good to me
| |
2600 page != NULL; | 2617 if (page != NULL) { |
2601 page = page->next_page()) { | 2618 return page->GetObject(); |
2602 Address page_address = page->address(); | |
2603 if (page_address <= a && a < page_address + page->size()) { | |
2604 return page->GetObject(); | |
2605 } | |
2606 } | 2619 } |
2607 return Failure::Exception(); | 2620 return Failure::Exception(); |
2608 } | 2621 } |
2609 | 2622 |
2610 | 2623 |
2611 LargePage* LargeObjectSpace::FindPageContainingPc(Address pc) { | 2624 LargePage* LargeObjectSpace::FindPageContainingPc(Address pc) { |
2612 // TODO(853): Change this implementation to only find executable | 2625 uint32_t key = reinterpret_cast<uint32_t>(pc) / MemoryChunk::kAlignment; |
2613 // chunks and use some kind of hash-based approach to speed it up. | 2626 HashMap::Entry* e = chunk_map_.Lookup(reinterpret_cast<void*>(key), |
2614 for (LargePage* chunk = first_page_; | 2627 key, false); |
2615 chunk != NULL; | 2628 if (e != NULL) { |
2616 chunk = chunk->next_page()) { | 2629 ASSERT(e->value != NULL); |
2617 Address chunk_address = chunk->address(); | 2630 LargePage* page = reinterpret_cast<LargePage*>(e->value); |
2618 if (chunk_address <= pc && pc < chunk_address + chunk->size()) { | 2631 ASSERT(page->is_valid()); |
2619 return chunk; | 2632 Address page_address = page->address(); |
2633 if (page_address <= pc && pc < page_address + page->size()) { | |
Vyacheslav Egorov (Chromium)
2012/03/09 12:15:37
Consider using page->Contains(pc) here.
kewpie.w.zp
2012/03/12 02:00:40
The check range of page->Contains(pc) falls into (
Vyacheslav Egorov (Chromium)
2012/03/12 12:04:12
I don't think anybody should pass addresses that f
kewpie.w.zp
2012/03/13 01:44:35
Done.
| |
2634 return page; | |
2620 } | 2635 } |
2621 } | 2636 } |
2622 return NULL; | 2637 return NULL; |
2623 } | 2638 } |
2624 | 2639 |
2625 | 2640 |
2626 void LargeObjectSpace::FreeUnmarkedObjects() { | 2641 void LargeObjectSpace::FreeUnmarkedObjects() { |
2627 LargePage* previous = NULL; | 2642 LargePage* previous = NULL; |
2628 LargePage* current = first_page_; | 2643 LargePage* current = first_page_; |
2629 while (current != NULL) { | 2644 while (current != NULL) { |
(...skipping 17 matching lines...) Expand all Loading... | |
2647 previous->set_next_page(current); | 2662 previous->set_next_page(current); |
2648 } | 2663 } |
2649 | 2664 |
2650 // Free the chunk. | 2665 // Free the chunk. |
2651 heap()->mark_compact_collector()->ReportDeleteIfNeeded( | 2666 heap()->mark_compact_collector()->ReportDeleteIfNeeded( |
2652 object, heap()->isolate()); | 2667 object, heap()->isolate()); |
2653 size_ -= static_cast<int>(page->size()); | 2668 size_ -= static_cast<int>(page->size()); |
2654 objects_size_ -= object->Size(); | 2669 objects_size_ -= object->Size(); |
2655 page_count_--; | 2670 page_count_--; |
2656 | 2671 |
2672 // Remove entries belonging to this page. | |
2673 uint32_t base = reinterpret_cast<uint32_t>(page)/MemoryChunk::kAlignment; | |
Vyacheslav Egorov (Chromium)
2012/03/09 12:15:37
casting page to uint32_t is not suitable for 64-bi
kewpie.w.zp
2012/03/12 02:00:40
Done.
| |
2674 uint32_t limit = base + (page->size()-1)/MemoryChunk::kAlignment; | |
2675 for (uint32_t key = base; key <= limit; key++) { | |
2676 chunk_map_.Remove(reinterpret_cast<void*>(key), key); | |
2677 } | |
2678 | |
2657 if (is_pointer_object) { | 2679 if (is_pointer_object) { |
2658 heap()->QueueMemoryChunkForFree(page); | 2680 heap()->QueueMemoryChunkForFree(page); |
2659 } else { | 2681 } else { |
2660 heap()->isolate()->memory_allocator()->Free(page); | 2682 heap()->isolate()->memory_allocator()->Free(page); |
2661 } | 2683 } |
2662 } | 2684 } |
2663 } | 2685 } |
2664 heap()->FreeQueuedChunks(); | 2686 heap()->FreeQueuedChunks(); |
2665 } | 2687 } |
2666 | 2688 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2782 object->ShortPrint(); | 2804 object->ShortPrint(); |
2783 PrintF("\n"); | 2805 PrintF("\n"); |
2784 } | 2806 } |
2785 printf(" --------------------------------------\n"); | 2807 printf(" --------------------------------------\n"); |
2786 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 2808 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
2787 } | 2809 } |
2788 | 2810 |
2789 #endif // DEBUG | 2811 #endif // DEBUG |
2790 | 2812 |
2791 } } // namespace v8::internal | 2813 } } // namespace v8::internal |
OLD | NEW |