OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_OBJECTS_VISITING_INL_H_ | 5 #ifndef V8_OBJECTS_VISITING_INL_H_ |
6 #define V8_OBJECTS_VISITING_INL_H_ | 6 #define V8_OBJECTS_VISITING_INL_H_ |
7 | 7 |
8 #include "src/heap/array-buffer-tracker.h" | 8 #include "src/heap/array-buffer-tracker.h" |
9 #include "src/heap/objects-visiting.h" | 9 #include "src/heap/objects-visiting.h" |
10 #include "src/ic/ic-state.h" | 10 #include "src/ic/ic-state.h" |
11 #include "src/macro-assembler.h" | 11 #include "src/macro-assembler.h" |
| 12 #include "src/objects-body-descriptors-inl.h" |
12 | 13 |
13 namespace v8 { | 14 namespace v8 { |
14 namespace internal { | 15 namespace internal { |
15 | 16 |
16 | 17 |
17 template <typename Callback> | 18 template <typename Callback> |
18 Callback VisitorDispatchTable<Callback>::GetVisitor(Map* map) { | 19 Callback VisitorDispatchTable<Callback>::GetVisitor(Map* map) { |
19 return reinterpret_cast<Callback>(callbacks_[map->visitor_id()]); | 20 return reinterpret_cast<Callback>(callbacks_[map->visitor_id()]); |
20 } | 21 } |
21 | 22 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 table_.template RegisterSpecializations<JSObjectVisitor, kVisitJSObject, | 88 table_.template RegisterSpecializations<JSObjectVisitor, kVisitJSObject, |
88 kVisitJSObjectGeneric>(); | 89 kVisitJSObjectGeneric>(); |
89 table_.template RegisterSpecializations<StructVisitor, kVisitStruct, | 90 table_.template RegisterSpecializations<StructVisitor, kVisitStruct, |
90 kVisitStructGeneric>(); | 91 kVisitStructGeneric>(); |
91 } | 92 } |
92 | 93 |
93 | 94 |
94 template <typename StaticVisitor> | 95 template <typename StaticVisitor> |
95 int StaticNewSpaceVisitor<StaticVisitor>::VisitJSArrayBuffer( | 96 int StaticNewSpaceVisitor<StaticVisitor>::VisitJSArrayBuffer( |
96 Map* map, HeapObject* object) { | 97 Map* map, HeapObject* object) { |
97 Heap* heap = map->GetHeap(); | 98 typedef FlexibleBodyVisitor<StaticVisitor, JSArrayBuffer::BodyDescriptor, int> |
| 99 JSArrayBufferBodyVisitor; |
98 | 100 |
99 JSArrayBuffer::JSArrayBufferIterateBody< | |
100 StaticNewSpaceVisitor<StaticVisitor> >(heap, object); | |
101 if (!JSArrayBuffer::cast(object)->is_external()) { | 101 if (!JSArrayBuffer::cast(object)->is_external()) { |
| 102 Heap* heap = map->GetHeap(); |
102 heap->array_buffer_tracker()->MarkLive(JSArrayBuffer::cast(object)); | 103 heap->array_buffer_tracker()->MarkLive(JSArrayBuffer::cast(object)); |
103 } | 104 } |
104 return JSArrayBuffer::kSizeWithInternalFields; | 105 return JSArrayBufferBodyVisitor::Visit(map, object); |
105 } | 106 } |
106 | 107 |
107 | 108 |
108 template <typename StaticVisitor> | 109 template <typename StaticVisitor> |
109 int StaticNewSpaceVisitor<StaticVisitor>::VisitJSTypedArray( | 110 int StaticNewSpaceVisitor<StaticVisitor>::VisitJSTypedArray( |
110 Map* map, HeapObject* object) { | 111 Map* map, HeapObject* object) { |
111 VisitPointers( | 112 VisitPointers( |
112 map->GetHeap(), object, | 113 map->GetHeap(), object, |
113 HeapObject::RawField(object, JSTypedArray::BodyDescriptor::kStartOffset), | 114 HeapObject::RawField(object, JSTypedArray::BodyDescriptor::kStartOffset), |
114 HeapObject::RawField(object, JSTypedArray::kSizeWithInternalFields)); | 115 HeapObject::RawField(object, JSTypedArray::kSizeWithInternalFields)); |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 Object** slot = HeapObject::RawField(object, JSWeakCollection::kTableOffset); | 421 Object** slot = HeapObject::RawField(object, JSWeakCollection::kTableOffset); |
421 HeapObject* obj = HeapObject::cast(*slot); | 422 HeapObject* obj = HeapObject::cast(*slot); |
422 heap->mark_compact_collector()->RecordSlot(object, slot, obj); | 423 heap->mark_compact_collector()->RecordSlot(object, slot, obj); |
423 StaticVisitor::MarkObjectWithoutPush(heap, obj); | 424 StaticVisitor::MarkObjectWithoutPush(heap, obj); |
424 } | 425 } |
425 | 426 |
426 | 427 |
427 template <typename StaticVisitor> | 428 template <typename StaticVisitor> |
428 void StaticMarkingVisitor<StaticVisitor>::VisitCode(Map* map, | 429 void StaticMarkingVisitor<StaticVisitor>::VisitCode(Map* map, |
429 HeapObject* object) { | 430 HeapObject* object) { |
| 431 typedef FlexibleBodyVisitor<StaticVisitor, Code::BodyDescriptor, void> |
| 432 CodeBodyVisitor; |
430 Heap* heap = map->GetHeap(); | 433 Heap* heap = map->GetHeap(); |
431 Code* code = Code::cast(object); | 434 Code* code = Code::cast(object); |
432 if (FLAG_age_code && !heap->isolate()->serializer_enabled()) { | 435 if (FLAG_age_code && !heap->isolate()->serializer_enabled()) { |
433 code->MakeOlder(heap->mark_compact_collector()->marking_parity()); | 436 code->MakeOlder(heap->mark_compact_collector()->marking_parity()); |
434 } | 437 } |
435 MarkCompactCollector* collector = heap->mark_compact_collector(); | 438 MarkCompactCollector* collector = heap->mark_compact_collector(); |
436 if (collector->is_code_flushing_enabled()) { | 439 if (collector->is_code_flushing_enabled()) { |
437 if (code->kind() == Code::OPTIMIZED_FUNCTION) { | 440 if (code->kind() == Code::OPTIMIZED_FUNCTION) { |
438 // Visit all unoptimized code objects to prevent flushing them. | 441 // Visit all unoptimized code objects to prevent flushing them. |
439 MarkInlinedFunctionsCode(heap, code); | 442 MarkInlinedFunctionsCode(heap, code); |
440 } | 443 } |
441 } | 444 } |
442 code->CodeIterateBody<StaticVisitor>(heap); | 445 CodeBodyVisitor::Visit(map, object); |
443 } | 446 } |
444 | 447 |
445 | 448 |
446 template <typename StaticVisitor> | 449 template <typename StaticVisitor> |
447 void StaticMarkingVisitor<StaticVisitor>::VisitSharedFunctionInfo( | 450 void StaticMarkingVisitor<StaticVisitor>::VisitSharedFunctionInfo( |
448 Map* map, HeapObject* object) { | 451 Map* map, HeapObject* object) { |
449 Heap* heap = map->GetHeap(); | 452 Heap* heap = map->GetHeap(); |
450 SharedFunctionInfo* shared = SharedFunctionInfo::cast(object); | 453 SharedFunctionInfo* shared = SharedFunctionInfo::cast(object); |
451 if (shared->ic_age() != heap->global_ic_age()) { | 454 if (shared->ic_age() != heap->global_ic_age()) { |
452 shared->ResetForNewContext(heap->global_ic_age()); | 455 shared->ResetForNewContext(heap->global_ic_age()); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 StaticVisitor::MarkObject(heap, function->shared()->code()); | 521 StaticVisitor::MarkObject(heap, function->shared()->code()); |
519 } | 522 } |
520 } | 523 } |
521 VisitJSFunctionStrongCode(map, object); | 524 VisitJSFunctionStrongCode(map, object); |
522 } | 525 } |
523 | 526 |
524 | 527 |
525 template <typename StaticVisitor> | 528 template <typename StaticVisitor> |
526 void StaticMarkingVisitor<StaticVisitor>::VisitJSRegExp(Map* map, | 529 void StaticMarkingVisitor<StaticVisitor>::VisitJSRegExp(Map* map, |
527 HeapObject* object) { | 530 HeapObject* object) { |
528 int last_property_offset = | 531 typedef FlexibleBodyVisitor<StaticVisitor, JSRegExp::BodyDescriptor, void> |
529 JSRegExp::kSize + kPointerSize * map->GetInObjectProperties(); | 532 JSRegExpBodyVisitor; |
530 StaticVisitor::VisitPointers( | 533 JSRegExpBodyVisitor::Visit(map, object); |
531 map->GetHeap(), object, | |
532 HeapObject::RawField(object, JSRegExp::kPropertiesOffset), | |
533 HeapObject::RawField(object, last_property_offset)); | |
534 } | 534 } |
535 | 535 |
536 | 536 |
537 template <typename StaticVisitor> | 537 template <typename StaticVisitor> |
538 void StaticMarkingVisitor<StaticVisitor>::VisitJSArrayBuffer( | 538 void StaticMarkingVisitor<StaticVisitor>::VisitJSArrayBuffer( |
539 Map* map, HeapObject* object) { | 539 Map* map, HeapObject* object) { |
540 Heap* heap = map->GetHeap(); | 540 Heap* heap = map->GetHeap(); |
541 | 541 |
542 JSArrayBuffer::JSArrayBufferIterateBody<StaticVisitor>(heap, object); | 542 typedef FlexibleBodyVisitor<StaticVisitor, JSArrayBuffer::BodyDescriptor, |
| 543 void> JSArrayBufferBodyVisitor; |
| 544 |
| 545 JSArrayBufferBodyVisitor::Visit(map, object); |
| 546 |
543 if (!JSArrayBuffer::cast(object)->is_external() && | 547 if (!JSArrayBuffer::cast(object)->is_external() && |
544 !heap->InNewSpace(object)) { | 548 !heap->InNewSpace(object)) { |
545 heap->array_buffer_tracker()->MarkLive(JSArrayBuffer::cast(object)); | 549 heap->array_buffer_tracker()->MarkLive(JSArrayBuffer::cast(object)); |
546 } | 550 } |
547 } | 551 } |
548 | 552 |
549 | 553 |
550 template <typename StaticVisitor> | 554 template <typename StaticVisitor> |
551 void StaticMarkingVisitor<StaticVisitor>::VisitJSTypedArray( | 555 void StaticMarkingVisitor<StaticVisitor>::VisitJSTypedArray( |
552 Map* map, HeapObject* object) { | 556 Map* map, HeapObject* object) { |
553 StaticVisitor::VisitPointers( | 557 typedef FlexibleBodyVisitor<StaticVisitor, JSTypedArray::BodyDescriptor, void> |
554 map->GetHeap(), object, | 558 JSTypedArrayBodyVisitor; |
555 HeapObject::RawField(object, JSTypedArray::BodyDescriptor::kStartOffset), | 559 JSTypedArrayBodyVisitor::Visit(map, object); |
556 HeapObject::RawField(object, JSTypedArray::kSizeWithInternalFields)); | |
557 } | 560 } |
558 | 561 |
559 | 562 |
560 template <typename StaticVisitor> | 563 template <typename StaticVisitor> |
561 void StaticMarkingVisitor<StaticVisitor>::VisitJSDataView(Map* map, | 564 void StaticMarkingVisitor<StaticVisitor>::VisitJSDataView(Map* map, |
562 HeapObject* object) { | 565 HeapObject* object) { |
563 StaticVisitor::VisitPointers( | 566 typedef FlexibleBodyVisitor<StaticVisitor, JSDataView::BodyDescriptor, void> |
564 map->GetHeap(), object, | 567 JSDataViewBodyVisitor; |
565 HeapObject::RawField(object, JSDataView::BodyDescriptor::kStartOffset), | 568 JSDataViewBodyVisitor::Visit(map, object); |
566 HeapObject::RawField(object, JSDataView::kSizeWithInternalFields)); | |
567 } | 569 } |
568 | 570 |
569 | 571 |
570 template <typename StaticVisitor> | 572 template <typename StaticVisitor> |
571 void StaticMarkingVisitor<StaticVisitor>::VisitBytecodeArray( | 573 void StaticMarkingVisitor<StaticVisitor>::VisitBytecodeArray( |
572 Map* map, HeapObject* object) { | 574 Map* map, HeapObject* object) { |
573 StaticVisitor::VisitPointers( | 575 StaticVisitor::VisitPointers( |
574 map->GetHeap(), object, | 576 map->GetHeap(), object, |
575 HeapObject::RawField(object, BytecodeArray::kConstantPoolOffset), | 577 HeapObject::RawField(object, BytecodeArray::kConstantPoolOffset), |
576 HeapObject::RawField(object, BytecodeArray::kHeaderSize)); | 578 HeapObject::RawField(object, BytecodeArray::kHeaderSize)); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 | 817 |
816 template <typename StaticVisitor> | 818 template <typename StaticVisitor> |
817 void StaticMarkingVisitor<StaticVisitor>::VisitJSFunctionWeakCode( | 819 void StaticMarkingVisitor<StaticVisitor>::VisitJSFunctionWeakCode( |
818 Map* map, HeapObject* object) { | 820 Map* map, HeapObject* object) { |
819 typedef FlexibleBodyVisitor<StaticVisitor, JSFunction::BodyDescriptorWeakCode, | 821 typedef FlexibleBodyVisitor<StaticVisitor, JSFunction::BodyDescriptorWeakCode, |
820 void> JSFunctionWeakCodeBodyVisitor; | 822 void> JSFunctionWeakCodeBodyVisitor; |
821 JSFunctionWeakCodeBodyVisitor::Visit(map, object); | 823 JSFunctionWeakCodeBodyVisitor::Visit(map, object); |
822 } | 824 } |
823 | 825 |
824 | 826 |
825 void Code::CodeIterateBody(ObjectVisitor* v) { | |
826 int mode_mask = RelocInfo::kCodeTargetMask | | |
827 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) | | |
828 RelocInfo::ModeMask(RelocInfo::CELL) | | |
829 RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) | | |
830 RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE) | | |
831 RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE_ENCODED) | | |
832 RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY) | | |
833 RelocInfo::kDebugBreakSlotMask; | |
834 | |
835 // There are two places where we iterate code bodies: here and the | |
836 // templated CodeIterateBody (below). They should be kept in sync. | |
837 IteratePointer(v, kRelocationInfoOffset); | |
838 IteratePointer(v, kHandlerTableOffset); | |
839 IteratePointer(v, kDeoptimizationDataOffset); | |
840 IteratePointer(v, kTypeFeedbackInfoOffset); | |
841 IterateNextCodeLink(v, kNextCodeLinkOffset); | |
842 | |
843 RelocIterator it(this, mode_mask); | |
844 Isolate* isolate = this->GetIsolate(); | |
845 for (; !it.done(); it.next()) { | |
846 it.rinfo()->Visit(isolate, v); | |
847 } | |
848 } | |
849 | |
850 | |
851 template <typename StaticVisitor> | |
852 void Code::CodeIterateBody(Heap* heap) { | |
853 int mode_mask = RelocInfo::kCodeTargetMask | | |
854 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) | | |
855 RelocInfo::ModeMask(RelocInfo::CELL) | | |
856 RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) | | |
857 RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE) | | |
858 RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE_ENCODED) | | |
859 RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY) | | |
860 RelocInfo::kDebugBreakSlotMask; | |
861 | |
862 // There are two places where we iterate code bodies: here and the non- | |
863 // templated CodeIterateBody (above). They should be kept in sync. | |
864 StaticVisitor::VisitPointer( | |
865 heap, this, | |
866 reinterpret_cast<Object**>(this->address() + kRelocationInfoOffset)); | |
867 StaticVisitor::VisitPointer( | |
868 heap, this, | |
869 reinterpret_cast<Object**>(this->address() + kHandlerTableOffset)); | |
870 StaticVisitor::VisitPointer( | |
871 heap, this, | |
872 reinterpret_cast<Object**>(this->address() + kDeoptimizationDataOffset)); | |
873 StaticVisitor::VisitPointer( | |
874 heap, this, | |
875 reinterpret_cast<Object**>(this->address() + kTypeFeedbackInfoOffset)); | |
876 StaticVisitor::VisitNextCodeLink( | |
877 heap, reinterpret_cast<Object**>(this->address() + kNextCodeLinkOffset)); | |
878 | |
879 | |
880 RelocIterator it(this, mode_mask); | |
881 for (; !it.done(); it.next()) { | |
882 it.rinfo()->template Visit<StaticVisitor>(heap); | |
883 } | |
884 } | |
885 } // namespace internal | 827 } // namespace internal |
886 } // namespace v8 | 828 } // namespace v8 |
887 | 829 |
888 #endif // V8_OBJECTS_VISITING_INL_H_ | 830 #endif // V8_OBJECTS_VISITING_INL_H_ |
OLD | NEW |