OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #include <ostream> | 5 #include <ostream> |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/compilation-dependencies.h" | 8 #include "src/compilation-dependencies.h" |
9 #include "src/compiler/access-info.h" | 9 #include "src/compiler/access-info.h" |
10 #include "src/field-index-inl.h" | 10 #include "src/field-index-inl.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 case AccessMode::kStore: | 54 case AccessMode::kStore: |
55 return os << "Store"; | 55 return os << "Store"; |
56 } | 56 } |
57 UNREACHABLE(); | 57 UNREACHABLE(); |
58 return os; | 58 return os; |
59 } | 59 } |
60 | 60 |
61 ElementAccessInfo::ElementAccessInfo() {} | 61 ElementAccessInfo::ElementAccessInfo() {} |
62 | 62 |
63 ElementAccessInfo::ElementAccessInfo(MapList const& receiver_maps, | 63 ElementAccessInfo::ElementAccessInfo(MapList const& receiver_maps, |
64 ElementsKind elements_kind, | 64 ElementsKind elements_kind) |
65 MaybeHandle<JSObject> holder) | 65 : elements_kind_(elements_kind), receiver_maps_(receiver_maps) {} |
66 : elements_kind_(elements_kind), | |
67 holder_(holder), | |
68 receiver_maps_(receiver_maps) {} | |
69 | 66 |
70 // static | 67 // static |
71 PropertyAccessInfo PropertyAccessInfo::NotFound(MapList const& receiver_maps, | 68 PropertyAccessInfo PropertyAccessInfo::NotFound(MapList const& receiver_maps, |
72 MaybeHandle<JSObject> holder) { | 69 MaybeHandle<JSObject> holder) { |
73 return PropertyAccessInfo(holder, receiver_maps); | 70 return PropertyAccessInfo(holder, receiver_maps); |
74 } | 71 } |
75 | 72 |
76 // static | 73 // static |
77 PropertyAccessInfo PropertyAccessInfo::DataConstant( | 74 PropertyAccessInfo PropertyAccessInfo::DataConstant( |
78 MapList const& receiver_maps, Handle<Object> constant, | 75 MapList const& receiver_maps, Handle<Object> constant, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 type_cache_(TypeCache::Get()), | 172 type_cache_(TypeCache::Get()), |
176 zone_(zone) { | 173 zone_(zone) { |
177 DCHECK(native_context->IsNativeContext()); | 174 DCHECK(native_context->IsNativeContext()); |
178 } | 175 } |
179 | 176 |
180 | 177 |
181 bool AccessInfoFactory::ComputeElementAccessInfo( | 178 bool AccessInfoFactory::ComputeElementAccessInfo( |
182 Handle<Map> map, AccessMode access_mode, ElementAccessInfo* access_info) { | 179 Handle<Map> map, AccessMode access_mode, ElementAccessInfo* access_info) { |
183 // Check if it is safe to inline element access for the {map}. | 180 // Check if it is safe to inline element access for the {map}. |
184 if (!CanInlineElementAccess(map)) return false; | 181 if (!CanInlineElementAccess(map)) return false; |
185 | |
186 ElementsKind const elements_kind = map->elements_kind(); | 182 ElementsKind const elements_kind = map->elements_kind(); |
187 | 183 *access_info = ElementAccessInfo(MapList{map}, elements_kind); |
188 // Certain (monomorphic) stores need a prototype chain check because shape | |
189 // changes could allow callbacks on elements in the chain that are not | |
190 // compatible with monomorphic keyed stores. | |
191 MaybeHandle<JSObject> holder; | |
192 if (access_mode == AccessMode::kStore && map->prototype()->IsJSObject()) { | |
193 for (PrototypeIterator i(map); !i.IsAtEnd(); i.Advance()) { | |
194 Handle<JSReceiver> prototype = | |
195 PrototypeIterator::GetCurrent<JSReceiver>(i); | |
196 if (!prototype->IsJSObject()) return false; | |
197 // TODO(bmeurer): We do not currently support unstable prototypes. | |
198 // We might want to revisit the way we handle certain keyed stores | |
199 // because this whole prototype chain check is essential a hack, | |
200 // and I'm not sure that it is correct at all with dictionaries in | |
201 // the prototype chain. | |
202 if (!prototype->map()->is_stable()) return false; | |
203 holder = Handle<JSObject>::cast(prototype); | |
204 } | |
205 } | |
206 | |
207 *access_info = ElementAccessInfo(MapList{map}, elements_kind, holder); | |
208 return true; | 184 return true; |
209 } | 185 } |
210 | 186 |
211 | 187 |
212 bool AccessInfoFactory::ComputeElementAccessInfos( | 188 bool AccessInfoFactory::ComputeElementAccessInfos( |
213 MapHandleList const& maps, AccessMode access_mode, | 189 MapHandleList const& maps, AccessMode access_mode, |
214 ZoneVector<ElementAccessInfo>* access_infos) { | 190 ZoneVector<ElementAccessInfo>* access_infos) { |
215 // Collect possible transition targets. | 191 // Collect possible transition targets. |
216 MapHandleList possible_transition_targets(maps.length()); | 192 MapHandleList possible_transition_targets(maps.length()); |
217 for (Handle<Map> map : maps) { | 193 for (Handle<Map> map : maps) { |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 } | 499 } |
524 return false; | 500 return false; |
525 } | 501 } |
526 | 502 |
527 | 503 |
528 Factory* AccessInfoFactory::factory() const { return isolate()->factory(); } | 504 Factory* AccessInfoFactory::factory() const { return isolate()->factory(); } |
529 | 505 |
530 } // namespace compiler | 506 } // namespace compiler |
531 } // namespace internal | 507 } // namespace internal |
532 } // namespace v8 | 508 } // namespace v8 |
OLD | NEW |