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 2589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2600 | 2600 |
2601 // ------------------------------------------------------------------------- | 2601 // ------------------------------------------------------------------------- |
2602 // Phase 3: Update pointers | 2602 // Phase 3: Update pointers |
2603 | 2603 |
2604 // Helper class for updating pointers in HeapObjects. | 2604 // Helper class for updating pointers in HeapObjects. |
2605 class UpdatingVisitor: public ObjectVisitor { | 2605 class UpdatingVisitor: public ObjectVisitor { |
2606 public: | 2606 public: |
2607 explicit UpdatingVisitor(Heap* heap) : heap_(heap) {} | 2607 explicit UpdatingVisitor(Heap* heap) : heap_(heap) {} |
2608 | 2608 |
2609 void VisitPointer(Object** p) { | 2609 void VisitPointer(Object** p) { |
2610 UpdatePointer(p); | 2610 UpdatePointer(p, NULL); |
| 2611 } |
| 2612 |
| 2613 void VisitPointer(Object** p, RelocInfo* rinfo) { |
| 2614 // Variant of UpdatePointer, for arch's where RelocInfo is needed. |
| 2615 UpdatePointer(p, rinfo); |
2611 } | 2616 } |
2612 | 2617 |
2613 void VisitPointers(Object** start, Object** end) { | 2618 void VisitPointers(Object** start, Object** end) { |
2614 // Mark all HeapObject pointers in [start, end) | 2619 // Mark all HeapObject pointers in [start, end) |
2615 for (Object** p = start; p < end; p++) UpdatePointer(p); | 2620 for (Object** p = start; p < end; p++) UpdatePointer(p, NULL); |
2616 } | 2621 } |
2617 | 2622 |
2618 void VisitCodeTarget(RelocInfo* rinfo) { | 2623 void VisitCodeTarget(RelocInfo* rinfo) { |
2619 ASSERT(RelocInfo::IsCodeTarget(rinfo->rmode())); | 2624 ASSERT(RelocInfo::IsCodeTarget(rinfo->rmode())); |
2620 Object* target = Code::GetCodeFromTargetAddress(rinfo->target_address()); | 2625 Object* target = Code::GetCodeFromTargetAddress(rinfo->target_address()); |
2621 VisitPointer(&target); | 2626 VisitPointer(&target); |
2622 rinfo->set_target_address( | 2627 rinfo->set_target_address( |
2623 reinterpret_cast<Code*>(target)->instruction_start()); | 2628 reinterpret_cast<Code*>(target)->instruction_start()); |
2624 } | 2629 } |
2625 | 2630 |
2626 void VisitDebugTarget(RelocInfo* rinfo) { | 2631 void VisitDebugTarget(RelocInfo* rinfo) { |
2627 ASSERT((RelocInfo::IsJSReturn(rinfo->rmode()) && | 2632 ASSERT((RelocInfo::IsJSReturn(rinfo->rmode()) && |
2628 rinfo->IsPatchedReturnSequence()) || | 2633 rinfo->IsPatchedReturnSequence()) || |
2629 (RelocInfo::IsDebugBreakSlot(rinfo->rmode()) && | 2634 (RelocInfo::IsDebugBreakSlot(rinfo->rmode()) && |
2630 rinfo->IsPatchedDebugBreakSlotSequence())); | 2635 rinfo->IsPatchedDebugBreakSlotSequence())); |
2631 Object* target = Code::GetCodeFromTargetAddress(rinfo->call_address()); | 2636 Object* target = Code::GetCodeFromTargetAddress(rinfo->call_address()); |
2632 VisitPointer(&target); | 2637 VisitPointer(&target); |
2633 rinfo->set_call_address( | 2638 rinfo->set_call_address( |
2634 reinterpret_cast<Code*>(target)->instruction_start()); | 2639 reinterpret_cast<Code*>(target)->instruction_start()); |
2635 } | 2640 } |
2636 | 2641 |
2637 inline Heap* heap() const { return heap_; } | 2642 inline Heap* heap() const { return heap_; } |
2638 | 2643 |
2639 private: | 2644 private: |
2640 void UpdatePointer(Object** p) { | 2645 void UpdatePointer(Object** p, RelocInfo* rinfo) { |
2641 if (!(*p)->IsHeapObject()) return; | 2646 if (!(*p)->IsHeapObject()) return; |
2642 | 2647 |
2643 HeapObject* obj = HeapObject::cast(*p); | 2648 HeapObject* obj = HeapObject::cast(*p); |
2644 Address old_addr = obj->address(); | 2649 Address old_addr = obj->address(); |
2645 Address new_addr; | 2650 Address new_addr; |
2646 ASSERT(!heap()->InFromSpace(obj)); | 2651 ASSERT(!heap()->InFromSpace(obj)); |
2647 | 2652 |
2648 if (heap()->new_space()->Contains(obj)) { | 2653 if (heap()->new_space()->Contains(obj)) { |
2649 Address forwarding_pointer_addr = | 2654 Address forwarding_pointer_addr = |
2650 heap()->new_space()->FromSpaceLow() + | 2655 heap()->new_space()->FromSpaceLow() + |
(...skipping 25 matching lines...) Expand all Loading... |
2676 original_space = spaces.next(); | 2681 original_space = spaces.next(); |
2677 } | 2682 } |
2678 ASSERT(original_space != NULL); | 2683 ASSERT(original_space != NULL); |
2679 #endif | 2684 #endif |
2680 new_addr = MarkCompactCollector::GetForwardingAddressInOldSpace(obj); | 2685 new_addr = MarkCompactCollector::GetForwardingAddressInOldSpace(obj); |
2681 ASSERT(original_space->Contains(new_addr)); | 2686 ASSERT(original_space->Contains(new_addr)); |
2682 ASSERT(original_space->MCSpaceOffsetForAddress(new_addr) <= | 2687 ASSERT(original_space->MCSpaceOffsetForAddress(new_addr) <= |
2683 original_space->MCSpaceOffsetForAddress(old_addr)); | 2688 original_space->MCSpaceOffsetForAddress(old_addr)); |
2684 } | 2689 } |
2685 | 2690 |
2686 *p = HeapObject::FromAddress(new_addr); | 2691 if (rinfo) { |
| 2692 // For arch (like mips) without natural pointers in embedded code |
| 2693 // objects, rinfo->set_target_object() allows proper pointer update. |
| 2694 rinfo->set_target_object(HeapObject::FromAddress(new_addr)); |
| 2695 } else { |
| 2696 // Do normal indirect pointer update when there is no reloc info. |
| 2697 *p = HeapObject::FromAddress(new_addr); |
| 2698 } |
2687 | 2699 |
2688 #ifdef DEBUG | 2700 #ifdef DEBUG |
2689 if (FLAG_gc_verbose) { | 2701 if (FLAG_gc_verbose) { |
2690 PrintF("update %p : %p -> %p\n", | 2702 PrintF("update %p : %p -> %p\n", |
2691 reinterpret_cast<Address>(p), old_addr, new_addr); | 2703 reinterpret_cast<Address>(p), old_addr, new_addr); |
2692 } | 2704 } |
2693 #endif | 2705 #endif |
2694 } | 2706 } |
2695 | 2707 |
2696 Heap* heap_; | 2708 Heap* heap_; |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3129 } | 3141 } |
3130 | 3142 |
3131 | 3143 |
3132 void MarkCompactCollector::Initialize() { | 3144 void MarkCompactCollector::Initialize() { |
3133 StaticPointersToNewGenUpdatingVisitor::Initialize(); | 3145 StaticPointersToNewGenUpdatingVisitor::Initialize(); |
3134 StaticMarkingVisitor::Initialize(); | 3146 StaticMarkingVisitor::Initialize(); |
3135 } | 3147 } |
3136 | 3148 |
3137 | 3149 |
3138 } } // namespace v8::internal | 3150 } } // namespace v8::internal |
OLD | NEW |