1 // Copyright 2011 the V8 project authors. All rights reserved. 2 // Redistribution and use in source and binary forms, with or without 3 // modification, are permitted provided that the following conditions are 4 // met: 5 // 6 // * Redistributions of source code must retain the above copyright 7 // notice, this list of conditions and the following disclaimer. 8 // * Redistributions in binary form must reproduce the above 9 // copyright notice, this list of conditions and the following 10 // disclaimer in the documentation and/or other materials provided 11 // with the distribution. 12 // * Neither the name of Google Inc. nor the names of its 13 // contributors may be used to endorse or promote products derived 14 // from this software without specific prior written permission. 15 // 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28 #ifndef V8_OBJECTS_VISITING_INL_H_ 29 #define V8_OBJECTS_VISITING_INL_H_ 30 31 32 namespace v8 { 33 namespace internal { 34 35 template<typename StaticVisitor> 36 void StaticNewSpaceVisitor<StaticVisitor>::Initialize() { 37 table_.Register(kVisitShortcutCandidate, 38 &FixedBodyVisitor<StaticVisitor, 39 ConsString::BodyDescriptor, 40 int>::Visit); 41 42 table_.Register(kVisitConsString, 43 &FixedBodyVisitor<StaticVisitor, 44 ConsString::BodyDescriptor, 45 int>::Visit); 46 47 table_.Register(kVisitSlicedString, 48 &FixedBodyVisitor<StaticVisitor, 49 SlicedString::BodyDescriptor, 50 int>::Visit); 51 52 table_.Register(kVisitFixedArray, 53 &FlexibleBodyVisitor<StaticVisitor, 54 FixedArray::BodyDescriptor, 55 int>::Visit); 56 57 table_.Register(kVisitFixedDoubleArray, &VisitFixedDoubleArray); 58 59 table_.Register(kVisitGlobalContext, 60 &FixedBodyVisitor<StaticVisitor, 61 Context::ScavengeBodyDescriptor, 62 int>::Visit); 63 64 table_.Register(kVisitByteArray, &VisitByteArray); 65 66 table_.Register(kVisitSharedFunctionInfo, 67 &FixedBodyVisitor<StaticVisitor, 68 SharedFunctionInfo::BodyDescriptor, 69 int>::Visit); 70 71 table_.Register(kVisitSeqAsciiString, &VisitSeqAsciiString); 72 73 table_.Register(kVisitSeqTwoByteString, &VisitSeqTwoByteString); 74 75 table_.Register(kVisitJSFunction, 76 &JSObjectVisitor:: 77 template VisitSpecialized<JSFunction::kSize>); 78 79 table_.Register(kVisitFreeSpace, &VisitFreeSpace); 80 81 table_.Register(kVisitJSWeakMap, &JSObjectVisitor::Visit); 82 83 table_.Register(kVisitJSRegExp, &JSObjectVisitor::Visit); 84 85 table_.template RegisterSpecializations<DataObjectVisitor, 86 kVisitDataObject, 87 kVisitDataObjectGeneric>(); 88 89 table_.template RegisterSpecializations<JSObjectVisitor, 90 kVisitJSObject, 91 kVisitJSObjectGeneric>(); 92 table_.template RegisterSpecializations<StructVisitor, 93 kVisitStruct, 94 kVisitStructGeneric>(); 95 } 96 97 98 void Code::CodeIterateBody(ObjectVisitor* v) { 99 int mode_mask = RelocInfo::kCodeTargetMask | 100 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) | 101 RelocInfo::ModeMask(RelocInfo::GLOBAL_PROPERTY_CELL) | 102 RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) | 103 RelocInfo::ModeMask(RelocInfo::JS_RETURN) | 104 RelocInfo::ModeMask(RelocInfo::DEBUG_BREAK_SLOT) | 105 RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY); 106 107 // There are two places where we iterate code bodies: here and the 108 // templated CodeIterateBody (below). They should be kept in sync. 109 IteratePointer(v, kRelocationInfoOffset); 110 IteratePointer(v, kHandlerTableOffset); 111 IteratePointer(v, kDeoptimizationDataOffset); 112 IteratePointer(v, kTypeFeedbackInfoOffset); 113 114 RelocIterator it(this, mode_mask); 115 for (; !it.done(); it.next()) { 116 it.rinfo()->Visit(v); 117 } 118 } 119 120 121 template<typename StaticVisitor> 122 void Code::CodeIterateBody(Heap* heap) { 123 int mode_mask = RelocInfo::kCodeTargetMask | 124 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) | 125 RelocInfo::ModeMask(RelocInfo::GLOBAL_PROPERTY_CELL) | 126 RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) | 127 RelocInfo::ModeMask(RelocInfo::JS_RETURN) | 128 RelocInfo::ModeMask(RelocInfo::DEBUG_BREAK_SLOT) | 129 RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY); 130 131 // There are two places where we iterate code bodies: here and the 132 // non-templated CodeIterateBody (above). They should be kept in sync. 133 StaticVisitor::VisitPointer( 134 heap, 135 reinterpret_cast<Object**>(this->address() + kRelocationInfoOffset)); 136 StaticVisitor::VisitPointer( 137 heap, 138 reinterpret_cast<Object**>(this->address() + kHandlerTableOffset)); 139 StaticVisitor::VisitPointer( 140 heap, 141 reinterpret_cast<Object**>(this->address() + kDeoptimizationDataOffset)); 142 StaticVisitor::VisitPointer( 143 heap, 144 reinterpret_cast<Object**>(this->address() + kTypeFeedbackInfoOffset)); 145 146 RelocIterator it(this, mode_mask); 147 for (; !it.done(); it.next()) { 148 it.rinfo()->template Visit<StaticVisitor>(heap); 149 } 150 } 151 152 153 } } // namespace v8::internal 154 155 #endif // V8_OBJECTS_VISITING_INL_H_ 156