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
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.
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.
28 #ifndef V8_OBJECTS_VISITING_INL_H_
29 #define V8_OBJECTS_VISITING_INL_H_
35 template<typename StaticVisitor>
36 void StaticNewSpaceVisitor<StaticVisitor>::Initialize() {
37 table_.Register(kVisitShortcutCandidate,
38 &FixedBodyVisitor<StaticVisitor,
39 ConsString::BodyDescriptor,
42 table_.Register(kVisitConsString,
43 &FixedBodyVisitor<StaticVisitor,
44 ConsString::BodyDescriptor,
47 table_.Register(kVisitSlicedString,
48 &FixedBodyVisitor<StaticVisitor,
49 SlicedString::BodyDescriptor,
52 table_.Register(kVisitFixedArray,
53 &FlexibleBodyVisitor<StaticVisitor,
54 FixedArray::BodyDescriptor,
57 table_.Register(kVisitFixedDoubleArray, &VisitFixedDoubleArray);
59 table_.Register(kVisitGlobalContext,
60 &FixedBodyVisitor<StaticVisitor,
61 Context::ScavengeBodyDescriptor,
64 table_.Register(kVisitByteArray, &VisitByteArray);
66 table_.Register(kVisitSharedFunctionInfo,
67 &FixedBodyVisitor<StaticVisitor,
68 SharedFunctionInfo::BodyDescriptor,
71 table_.Register(kVisitSeqAsciiString, &VisitSeqAsciiString);
73 table_.Register(kVisitSeqTwoByteString, &VisitSeqTwoByteString);
75 table_.Register(kVisitJSFunction, &VisitJSFunction);
77 table_.Register(kVisitFreeSpace, &VisitFreeSpace);
79 table_.Register(kVisitJSWeakMap, &JSObjectVisitor::Visit);
81 table_.Register(kVisitJSRegExp, &JSObjectVisitor::Visit);
83 table_.template RegisterSpecializations<DataObjectVisitor,
85 kVisitDataObjectGeneric>();
87 table_.template RegisterSpecializations<JSObjectVisitor,
89 kVisitJSObjectGeneric>();
90 table_.template RegisterSpecializations<StructVisitor,
92 kVisitStructGeneric>();
96 void Code::CodeIterateBody(ObjectVisitor* v) {
97 int mode_mask = RelocInfo::kCodeTargetMask |
98 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
99 RelocInfo::ModeMask(RelocInfo::GLOBAL_PROPERTY_CELL) |
100 RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) |
101 RelocInfo::ModeMask(RelocInfo::JS_RETURN) |
102 RelocInfo::ModeMask(RelocInfo::DEBUG_BREAK_SLOT) |
103 RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY);
105 // There are two places where we iterate code bodies: here and the
106 // templated CodeIterateBody (below). They should be kept in sync.
107 IteratePointer(v, kRelocationInfoOffset);
108 IteratePointer(v, kHandlerTableOffset);
109 IteratePointer(v, kDeoptimizationDataOffset);
110 IteratePointer(v, kTypeFeedbackInfoOffset);
112 RelocIterator it(this, mode_mask);
113 for (; !it.done(); it.next()) {
114 it.rinfo()->Visit(v);
119 template<typename StaticVisitor>
120 void Code::CodeIterateBody(Heap* heap) {
121 int mode_mask = RelocInfo::kCodeTargetMask |
122 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
123 RelocInfo::ModeMask(RelocInfo::GLOBAL_PROPERTY_CELL) |
124 RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) |
125 RelocInfo::ModeMask(RelocInfo::JS_RETURN) |
126 RelocInfo::ModeMask(RelocInfo::DEBUG_BREAK_SLOT) |
127 RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY);
129 // There are two places where we iterate code bodies: here and the
130 // non-templated CodeIterateBody (above). They should be kept in sync.
131 StaticVisitor::VisitPointer(
133 reinterpret_cast<Object**>(this->address() + kRelocationInfoOffset));
134 StaticVisitor::VisitPointer(
136 reinterpret_cast<Object**>(this->address() + kHandlerTableOffset));
137 StaticVisitor::VisitPointer(
139 reinterpret_cast<Object**>(this->address() + kDeoptimizationDataOffset));
140 StaticVisitor::VisitPointer(
142 reinterpret_cast<Object**>(this->address() + kTypeFeedbackInfoOffset));
144 RelocIterator it(this, mode_mask);
145 for (; !it.done(); it.next()) {
146 it.rinfo()->template Visit<StaticVisitor>(heap);
151 } } // namespace v8::internal
153 #endif // V8_OBJECTS_VISITING_INL_H_