| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 base + (object_size >> kPointerSizeLog2) - kMinObjectSizeInWords); | 134 base + (object_size >> kPointerSizeLog2) - kMinObjectSizeInWords); |
| 135 | 135 |
| 136 return Min(specialization, generic); | 136 return Min(specialization, generic); |
| 137 } | 137 } |
| 138 }; | 138 }; |
| 139 | 139 |
| 140 | 140 |
| 141 template<typename Callback> | 141 template<typename Callback> |
| 142 class VisitorDispatchTable { | 142 class VisitorDispatchTable { |
| 143 public: | 143 public: |
| 144 void CopyFrom(VisitorDispatchTable* other) { |
| 145 // We are not using memcpy to guarantee that during update |
| 146 // every element of callbacks_ array will remain correct |
| 147 // pointer (memcpy might be implemented as a byte copying loop). |
| 148 for (int i = 0; i < StaticVisitorBase::kVisitorIdCount; i++) { |
| 149 NoBarrier_Store(&callbacks_[i], other->callbacks_[i]); |
| 150 } |
| 151 } |
| 152 |
| 144 inline Callback GetVisitor(Map* map) { | 153 inline Callback GetVisitor(Map* map) { |
| 145 return callbacks_[map->visitor_id()]; | 154 return reinterpret_cast<Callback>(callbacks_[map->visitor_id()]); |
| 146 } | 155 } |
| 147 | 156 |
| 148 void Register(StaticVisitorBase::VisitorId id, Callback callback) { | 157 void Register(StaticVisitorBase::VisitorId id, Callback callback) { |
| 149 ASSERT(id < StaticVisitorBase::kVisitorIdCount); // id is unsigned. | 158 ASSERT(id < StaticVisitorBase::kVisitorIdCount); // id is unsigned. |
| 150 callbacks_[id] = callback; | 159 callbacks_[id] = reinterpret_cast<AtomicWord>(callback); |
| 151 } | 160 } |
| 152 | 161 |
| 153 template<typename Visitor, | 162 template<typename Visitor, |
| 154 StaticVisitorBase::VisitorId base, | 163 StaticVisitorBase::VisitorId base, |
| 155 StaticVisitorBase::VisitorId generic, | 164 StaticVisitorBase::VisitorId generic, |
| 156 int object_size_in_words> | 165 int object_size_in_words> |
| 157 void RegisterSpecialization() { | 166 void RegisterSpecialization() { |
| 158 static const int size = object_size_in_words * kPointerSize; | 167 static const int size = object_size_in_words * kPointerSize; |
| 159 Register(StaticVisitorBase::GetVisitorIdForSize(base, generic, size), | 168 Register(StaticVisitorBase::GetVisitorIdForSize(base, generic, size), |
| 160 &Visitor::template VisitSpecialized<size>); | 169 &Visitor::template VisitSpecialized<size>); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 172 RegisterSpecialization<Visitor, base, generic, 4>(); | 181 RegisterSpecialization<Visitor, base, generic, 4>(); |
| 173 RegisterSpecialization<Visitor, base, generic, 5>(); | 182 RegisterSpecialization<Visitor, base, generic, 5>(); |
| 174 RegisterSpecialization<Visitor, base, generic, 6>(); | 183 RegisterSpecialization<Visitor, base, generic, 6>(); |
| 175 RegisterSpecialization<Visitor, base, generic, 7>(); | 184 RegisterSpecialization<Visitor, base, generic, 7>(); |
| 176 RegisterSpecialization<Visitor, base, generic, 8>(); | 185 RegisterSpecialization<Visitor, base, generic, 8>(); |
| 177 RegisterSpecialization<Visitor, base, generic, 9>(); | 186 RegisterSpecialization<Visitor, base, generic, 9>(); |
| 178 Register(generic, &Visitor::Visit); | 187 Register(generic, &Visitor::Visit); |
| 179 } | 188 } |
| 180 | 189 |
| 181 private: | 190 private: |
| 182 Callback callbacks_[StaticVisitorBase::kVisitorIdCount]; | 191 AtomicWord callbacks_[StaticVisitorBase::kVisitorIdCount]; |
| 183 }; | 192 }; |
| 184 | 193 |
| 185 | 194 |
| 186 template<typename StaticVisitor> | 195 template<typename StaticVisitor> |
| 187 class BodyVisitorBase : public AllStatic { | 196 class BodyVisitorBase : public AllStatic { |
| 188 public: | 197 public: |
| 189 INLINE(static void IteratePointers(Heap* heap, | 198 INLINE(static void IteratePointers(Heap* heap, |
| 190 HeapObject* object, | 199 HeapObject* object, |
| 191 int start_offset, | 200 int start_offset, |
| 192 int end_offset)) { | 201 int end_offset)) { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 | 413 |
| 405 for (; !it.done(); it.next()) { | 414 for (; !it.done(); it.next()) { |
| 406 it.rinfo()->template Visit<StaticVisitor>(heap); | 415 it.rinfo()->template Visit<StaticVisitor>(heap); |
| 407 } | 416 } |
| 408 } | 417 } |
| 409 | 418 |
| 410 | 419 |
| 411 } } // namespace v8::internal | 420 } } // namespace v8::internal |
| 412 | 421 |
| 413 #endif // V8_OBJECTS_VISITING_H_ | 422 #endif // V8_OBJECTS_VISITING_H_ |
| OLD | NEW |