blob: 329cb93fe523baa2f5dd404623d93a8d6269b2ae [file] [log] [blame]
Ben Murdoch014dc512016-03-22 12:00:34 +00001// 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
3// found in the LICENSE file.
4
5#include <ostream>
6
7#include "src/accessors.h"
8#include "src/compilation-dependencies.h"
9#include "src/compiler/access-info.h"
Ben Murdochf3b273f2017-01-17 12:11:28 +000010#include "src/compiler/type-cache.h"
Ben Murdoch014dc512016-03-22 12:00:34 +000011#include "src/field-index-inl.h"
Ben Murdoch109988c2016-05-18 11:27:45 +010012#include "src/field-type.h"
Ben Murdoch13e2dad2016-09-16 13:49:30 +010013#include "src/objects-inl.h"
Ben Murdoch014dc512016-03-22 12:00:34 +000014
15namespace v8 {
16namespace internal {
17namespace compiler {
18
19namespace {
20
21bool CanInlineElementAccess(Handle<Map> map) {
22 if (!map->IsJSObjectMap()) return false;
23 if (map->is_access_check_needed()) return false;
24 if (map->has_indexed_interceptor()) return false;
25 ElementsKind const elements_kind = map->elements_kind();
26 if (IsFastElementsKind(elements_kind)) return true;
27 // TODO(bmeurer): Add support for other elements kind.
Ben Murdochf91f0612016-11-29 16:50:11 +000028 if (elements_kind == UINT8_CLAMPED_ELEMENTS) return false;
29 if (IsFixedTypedArrayElementsKind(elements_kind)) return true;
Ben Murdoch014dc512016-03-22 12:00:34 +000030 return false;
31}
32
33
34bool CanInlinePropertyAccess(Handle<Map> map) {
35 // We can inline property access to prototypes of all primitives, except
36 // the special Oddball ones that have no wrapper counterparts (i.e. Null,
37 // Undefined and TheHole).
38 STATIC_ASSERT(ODDBALL_TYPE == LAST_PRIMITIVE_TYPE);
39 if (map->IsBooleanMap()) return true;
40 if (map->instance_type() < LAST_PRIMITIVE_TYPE) return true;
41 return map->IsJSObjectMap() && !map->is_dictionary_map() &&
42 !map->has_named_interceptor() &&
43 // TODO(verwaest): Whitelist contexts to which we have access.
44 !map->is_access_check_needed();
45}
46
47} // namespace
48
49
50std::ostream& operator<<(std::ostream& os, AccessMode access_mode) {
51 switch (access_mode) {
52 case AccessMode::kLoad:
53 return os << "Load";
54 case AccessMode::kStore:
55 return os << "Store";
56 }
57 UNREACHABLE();
58 return os;
59}
60
Ben Murdochf91f0612016-11-29 16:50:11 +000061ElementAccessInfo::ElementAccessInfo() {}
62
63ElementAccessInfo::ElementAccessInfo(MapList const& receiver_maps,
64 ElementsKind elements_kind)
65 : elements_kind_(elements_kind), receiver_maps_(receiver_maps) {}
Ben Murdoch014dc512016-03-22 12:00:34 +000066
67// static
Ben Murdochf91f0612016-11-29 16:50:11 +000068PropertyAccessInfo PropertyAccessInfo::NotFound(MapList const& receiver_maps,
Ben Murdoch014dc512016-03-22 12:00:34 +000069 MaybeHandle<JSObject> holder) {
Ben Murdochf91f0612016-11-29 16:50:11 +000070 return PropertyAccessInfo(holder, receiver_maps);
Ben Murdoch014dc512016-03-22 12:00:34 +000071}
72
Ben Murdoch014dc512016-03-22 12:00:34 +000073// static
74PropertyAccessInfo PropertyAccessInfo::DataConstant(
Ben Murdochf91f0612016-11-29 16:50:11 +000075 MapList const& receiver_maps, Handle<Object> constant,
Ben Murdoch014dc512016-03-22 12:00:34 +000076 MaybeHandle<JSObject> holder) {
Ben Murdochf91f0612016-11-29 16:50:11 +000077 return PropertyAccessInfo(kDataConstant, holder, constant, receiver_maps);
Ben Murdoch014dc512016-03-22 12:00:34 +000078}
79
Ben Murdoch014dc512016-03-22 12:00:34 +000080// static
81PropertyAccessInfo PropertyAccessInfo::DataField(
Ben Murdochf3b273f2017-01-17 12:11:28 +000082 MapList const& receiver_maps, FieldIndex field_index,
83 MachineRepresentation field_representation, Type* field_type,
84 MaybeHandle<Map> field_map, MaybeHandle<JSObject> holder,
85 MaybeHandle<Map> transition_map) {
86 return PropertyAccessInfo(holder, transition_map, field_index,
87 field_representation, field_type, field_map,
Ben Murdochf91f0612016-11-29 16:50:11 +000088 receiver_maps);
Ben Murdoch014dc512016-03-22 12:00:34 +000089}
90
Ben Murdochf91f0612016-11-29 16:50:11 +000091// static
92PropertyAccessInfo PropertyAccessInfo::AccessorConstant(
93 MapList const& receiver_maps, Handle<Object> constant,
94 MaybeHandle<JSObject> holder) {
95 return PropertyAccessInfo(kAccessorConstant, holder, constant, receiver_maps);
96}
Ben Murdoch014dc512016-03-22 12:00:34 +000097
98PropertyAccessInfo::PropertyAccessInfo()
Ben Murdochf3b273f2017-01-17 12:11:28 +000099 : kind_(kInvalid),
100 field_representation_(MachineRepresentation::kNone),
101 field_type_(Type::None()) {}
Ben Murdoch014dc512016-03-22 12:00:34 +0000102
103PropertyAccessInfo::PropertyAccessInfo(MaybeHandle<JSObject> holder,
Ben Murdochf91f0612016-11-29 16:50:11 +0000104 MapList const& receiver_maps)
Ben Murdoch014dc512016-03-22 12:00:34 +0000105 : kind_(kNotFound),
Ben Murdochf91f0612016-11-29 16:50:11 +0000106 receiver_maps_(receiver_maps),
Ben Murdoch014dc512016-03-22 12:00:34 +0000107 holder_(holder),
Ben Murdochf3b273f2017-01-17 12:11:28 +0000108 field_representation_(MachineRepresentation::kNone),
Ben Murdochf91f0612016-11-29 16:50:11 +0000109 field_type_(Type::None()) {}
Ben Murdoch014dc512016-03-22 12:00:34 +0000110
Ben Murdochf91f0612016-11-29 16:50:11 +0000111PropertyAccessInfo::PropertyAccessInfo(Kind kind, MaybeHandle<JSObject> holder,
Ben Murdoch014dc512016-03-22 12:00:34 +0000112 Handle<Object> constant,
Ben Murdochf91f0612016-11-29 16:50:11 +0000113 MapList const& receiver_maps)
114 : kind_(kind),
115 receiver_maps_(receiver_maps),
Ben Murdoch014dc512016-03-22 12:00:34 +0000116 constant_(constant),
117 holder_(holder),
Ben Murdochf3b273f2017-01-17 12:11:28 +0000118 field_representation_(MachineRepresentation::kNone),
Ben Murdoch014dc512016-03-22 12:00:34 +0000119 field_type_(Type::Any()) {}
120
Ben Murdochf3b273f2017-01-17 12:11:28 +0000121PropertyAccessInfo::PropertyAccessInfo(
122 MaybeHandle<JSObject> holder, MaybeHandle<Map> transition_map,
123 FieldIndex field_index, MachineRepresentation field_representation,
124 Type* field_type, MaybeHandle<Map> field_map, MapList const& receiver_maps)
Ben Murdoch014dc512016-03-22 12:00:34 +0000125 : kind_(kDataField),
Ben Murdochf91f0612016-11-29 16:50:11 +0000126 receiver_maps_(receiver_maps),
Ben Murdoch014dc512016-03-22 12:00:34 +0000127 transition_map_(transition_map),
128 holder_(holder),
129 field_index_(field_index),
Ben Murdochf3b273f2017-01-17 12:11:28 +0000130 field_representation_(field_representation),
131 field_type_(field_type),
132 field_map_(field_map) {}
Ben Murdoch014dc512016-03-22 12:00:34 +0000133
Ben Murdochf91f0612016-11-29 16:50:11 +0000134bool PropertyAccessInfo::Merge(PropertyAccessInfo const* that) {
135 if (this->kind_ != that->kind_) return false;
136 if (this->holder_.address() != that->holder_.address()) return false;
137
138 switch (this->kind_) {
139 case kInvalid:
140 break;
141
142 case kNotFound:
143 return true;
144
145 case kDataField: {
146 // Check if we actually access the same field.
147 if (this->transition_map_.address() == that->transition_map_.address() &&
148 this->field_index_ == that->field_index_ &&
149 this->field_type_->Is(that->field_type_) &&
Ben Murdochf3b273f2017-01-17 12:11:28 +0000150 that->field_type_->Is(this->field_type_) &&
151 this->field_representation_ == that->field_representation_) {
Ben Murdochf91f0612016-11-29 16:50:11 +0000152 this->receiver_maps_.insert(this->receiver_maps_.end(),
153 that->receiver_maps_.begin(),
154 that->receiver_maps_.end());
155 return true;
156 }
157 return false;
158 }
159
160 case kDataConstant:
161 case kAccessorConstant: {
162 // Check if we actually access the same constant.
163 if (this->constant_.address() == that->constant_.address()) {
164 this->receiver_maps_.insert(this->receiver_maps_.end(),
165 that->receiver_maps_.begin(),
166 that->receiver_maps_.end());
167 return true;
168 }
169 return false;
170 }
171 }
172
173 UNREACHABLE();
174 return false;
175}
176
Ben Murdoch014dc512016-03-22 12:00:34 +0000177AccessInfoFactory::AccessInfoFactory(CompilationDependencies* dependencies,
178 Handle<Context> native_context, Zone* zone)
179 : dependencies_(dependencies),
180 native_context_(native_context),
181 isolate_(native_context->GetIsolate()),
182 type_cache_(TypeCache::Get()),
183 zone_(zone) {
184 DCHECK(native_context->IsNativeContext());
185}
186
187
188bool AccessInfoFactory::ComputeElementAccessInfo(
189 Handle<Map> map, AccessMode access_mode, ElementAccessInfo* access_info) {
190 // Check if it is safe to inline element access for the {map}.
191 if (!CanInlineElementAccess(map)) return false;
Ben Murdoch014dc512016-03-22 12:00:34 +0000192 ElementsKind const elements_kind = map->elements_kind();
Ben Murdochf91f0612016-11-29 16:50:11 +0000193 *access_info = ElementAccessInfo(MapList{map}, elements_kind);
Ben Murdoch014dc512016-03-22 12:00:34 +0000194 return true;
195}
196
197
198bool AccessInfoFactory::ComputeElementAccessInfos(
199 MapHandleList const& maps, AccessMode access_mode,
200 ZoneVector<ElementAccessInfo>* access_infos) {
201 // Collect possible transition targets.
202 MapHandleList possible_transition_targets(maps.length());
203 for (Handle<Map> map : maps) {
204 if (Map::TryUpdate(map).ToHandle(&map)) {
205 if (CanInlineElementAccess(map) &&
206 IsFastElementsKind(map->elements_kind()) &&
207 GetInitialFastElementsKind() != map->elements_kind()) {
208 possible_transition_targets.Add(map);
209 }
210 }
211 }
212
213 // Separate the actual receiver maps and the possible transition sources.
214 MapHandleList receiver_maps(maps.length());
215 MapTransitionList transitions(maps.length());
216 for (Handle<Map> map : maps) {
217 if (Map::TryUpdate(map).ToHandle(&map)) {
Ben Murdochbcf72ee2016-08-08 18:44:38 +0100218 Map* transition_target =
219 map->FindElementsKindTransitionedMap(&possible_transition_targets);
220 if (transition_target == nullptr) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000221 receiver_maps.Add(map);
222 } else {
Ben Murdochbcf72ee2016-08-08 18:44:38 +0100223 transitions.push_back(std::make_pair(map, handle(transition_target)));
Ben Murdoch014dc512016-03-22 12:00:34 +0000224 }
225 }
226 }
227
228 for (Handle<Map> receiver_map : receiver_maps) {
229 // Compute the element access information.
230 ElementAccessInfo access_info;
231 if (!ComputeElementAccessInfo(receiver_map, access_mode, &access_info)) {
232 return false;
233 }
234
235 // Collect the possible transitions for the {receiver_map}.
236 for (auto transition : transitions) {
237 if (transition.second.is_identical_to(receiver_map)) {
238 access_info.transitions().push_back(transition);
239 }
240 }
241
242 // Schedule the access information.
243 access_infos->push_back(access_info);
244 }
245 return true;
246}
247
248
249bool AccessInfoFactory::ComputePropertyAccessInfo(
250 Handle<Map> map, Handle<Name> name, AccessMode access_mode,
251 PropertyAccessInfo* access_info) {
252 // Check if it is safe to inline property access for the {map}.
253 if (!CanInlinePropertyAccess(map)) return false;
254
255 // Compute the receiver type.
256 Handle<Map> receiver_map = map;
257
Ben Murdoch109988c2016-05-18 11:27:45 +0100258 // Property lookups require the name to be internalized.
259 name = isolate()->factory()->InternalizeName(name);
260
Ben Murdoch014dc512016-03-22 12:00:34 +0000261 // We support fast inline cases for certain JSObject getters.
262 if (access_mode == AccessMode::kLoad &&
263 LookupSpecialFieldAccessor(map, name, access_info)) {
264 return true;
265 }
266
267 MaybeHandle<JSObject> holder;
268 do {
269 // Lookup the named property on the {map}.
270 Handle<DescriptorArray> descriptors(map->instance_descriptors(), isolate());
Ben Murdoch109988c2016-05-18 11:27:45 +0100271 int const number = descriptors->SearchWithCache(isolate(), *name, *map);
Ben Murdoch014dc512016-03-22 12:00:34 +0000272 if (number != DescriptorArray::kNotFound) {
273 PropertyDetails const details = descriptors->GetDetails(number);
274 if (access_mode == AccessMode::kStore) {
275 // Don't bother optimizing stores to read-only properties.
276 if (details.IsReadOnly()) {
277 return false;
278 }
279 // Check for store to data property on a prototype.
280 if (details.kind() == kData && !holder.is_null()) {
281 // Store to property not found on the receiver but on a prototype, we
282 // need to transition to a new data property.
283 // Implemented according to ES6 section 9.1.9 [[Set]] (P, V, Receiver)
284 return LookupTransition(receiver_map, name, holder, access_info);
285 }
286 }
Ben Murdochf91f0612016-11-29 16:50:11 +0000287 switch (details.type()) {
288 case DATA_CONSTANT: {
289 *access_info = PropertyAccessInfo::DataConstant(
290 MapList{receiver_map},
291 handle(descriptors->GetValue(number), isolate()), holder);
292 return true;
Ben Murdoch014dc512016-03-22 12:00:34 +0000293 }
Ben Murdochf91f0612016-11-29 16:50:11 +0000294 case DATA: {
295 int index = descriptors->GetFieldIndex(number);
Ben Murdochf3b273f2017-01-17 12:11:28 +0000296 Representation details_representation = details.representation();
Ben Murdochf91f0612016-11-29 16:50:11 +0000297 FieldIndex field_index = FieldIndex::ForPropertyIndex(
Ben Murdochf3b273f2017-01-17 12:11:28 +0000298 *map, index, details_representation.IsDouble());
299 Type* field_type = Type::NonInternal();
300 MachineRepresentation field_representation =
301 MachineRepresentation::kTagged;
302 MaybeHandle<Map> field_map;
303 if (details_representation.IsSmi()) {
Ben Murdochf91f0612016-11-29 16:50:11 +0000304 field_type = type_cache_.kSmi;
Ben Murdochf3b273f2017-01-17 12:11:28 +0000305 field_representation = MachineRepresentation::kTaggedSigned;
306 } else if (details_representation.IsDouble()) {
Ben Murdochf91f0612016-11-29 16:50:11 +0000307 field_type = type_cache_.kFloat64;
Ben Murdochf3b273f2017-01-17 12:11:28 +0000308 field_representation = MachineRepresentation::kFloat64;
309 } else if (details_representation.IsHeapObject()) {
Ben Murdochf91f0612016-11-29 16:50:11 +0000310 // Extract the field type from the property details (make sure its
311 // representation is TaggedPointer to reflect the heap object case).
Ben Murdochf3b273f2017-01-17 12:11:28 +0000312 field_representation = MachineRepresentation::kTaggedPointer;
313 Handle<FieldType> descriptors_field_type(
314 descriptors->GetFieldType(number), isolate());
315 if (descriptors_field_type->IsNone()) {
Ben Murdochf91f0612016-11-29 16:50:11 +0000316 // Store is not safe if the field type was cleared.
317 if (access_mode == AccessMode::kStore) return false;
318
319 // The field type was cleared by the GC, so we don't know anything
320 // about the contents now.
Ben Murdochf3b273f2017-01-17 12:11:28 +0000321 } else if (descriptors_field_type->IsClass()) {
Ben Murdochf91f0612016-11-29 16:50:11 +0000322 // Add proper code dependencies in case of stable field map(s).
323 Handle<Map> field_owner_map(map->FindFieldOwner(number),
324 isolate());
325 dependencies()->AssumeFieldType(field_owner_map);
Ben Murdochf3b273f2017-01-17 12:11:28 +0000326
327 // Remember the field map, and try to infer a useful type.
328 field_type = Type::For(descriptors_field_type->AsClass());
329 field_map = descriptors_field_type->AsClass();
Ben Murdochf91f0612016-11-29 16:50:11 +0000330 }
331 }
332 *access_info = PropertyAccessInfo::DataField(
Ben Murdochf3b273f2017-01-17 12:11:28 +0000333 MapList{receiver_map}, field_index, field_representation,
334 field_type, field_map, holder);
Ben Murdochf91f0612016-11-29 16:50:11 +0000335 return true;
336 }
337 case ACCESSOR_CONSTANT: {
338 Handle<Object> accessors(descriptors->GetValue(number), isolate());
339 if (!accessors->IsAccessorPair()) return false;
340 Handle<Object> accessor(
341 access_mode == AccessMode::kLoad
342 ? Handle<AccessorPair>::cast(accessors)->getter()
343 : Handle<AccessorPair>::cast(accessors)->setter(),
344 isolate());
345 if (!accessor->IsJSFunction()) {
346 // TODO(turbofan): Add support for API accessors.
347 return false;
348 }
349 *access_info = PropertyAccessInfo::AccessorConstant(
350 MapList{receiver_map}, accessor, holder);
351 return true;
352 }
353 case ACCESSOR: {
354 // TODO(turbofan): Add support for general accessors?
355 return false;
356 }
Ben Murdoch014dc512016-03-22 12:00:34 +0000357 }
Ben Murdochf91f0612016-11-29 16:50:11 +0000358 UNREACHABLE();
359 return false;
Ben Murdoch014dc512016-03-22 12:00:34 +0000360 }
361
362 // Don't search on the prototype chain for special indices in case of
363 // integer indexed exotic objects (see ES6 section 9.4.5).
364 if (map->IsJSTypedArrayMap() && name->IsString() &&
365 IsSpecialIndex(isolate()->unicode_cache(), String::cast(*name))) {
366 return false;
367 }
368
369 // Don't lookup private symbols on the prototype chain.
370 if (name->IsPrivate()) return false;
371
372 // Walk up the prototype chain.
373 if (!map->prototype()->IsJSObject()) {
374 // Perform the implicit ToObject for primitives here.
375 // Implemented according to ES6 section 7.3.2 GetV (V, P).
376 Handle<JSFunction> constructor;
377 if (Map::GetConstructorFunction(map, native_context())
378 .ToHandle(&constructor)) {
379 map = handle(constructor->initial_map(), isolate());
380 DCHECK(map->prototype()->IsJSObject());
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100381 } else if (map->prototype()->IsNull(isolate())) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000382 // Store to property not found on the receiver or any prototype, we need
383 // to transition to a new data property.
384 // Implemented according to ES6 section 9.1.9 [[Set]] (P, V, Receiver)
385 if (access_mode == AccessMode::kStore) {
386 return LookupTransition(receiver_map, name, holder, access_info);
387 }
388 // The property was not found, return undefined or throw depending
389 // on the language mode of the load operation.
390 // Implemented according to ES6 section 9.1.8 [[Get]] (P, Receiver)
Ben Murdochf91f0612016-11-29 16:50:11 +0000391 *access_info =
392 PropertyAccessInfo::NotFound(MapList{receiver_map}, holder);
Ben Murdoch014dc512016-03-22 12:00:34 +0000393 return true;
394 } else {
395 return false;
396 }
397 }
398 Handle<JSObject> map_prototype(JSObject::cast(map->prototype()), isolate());
399 if (map_prototype->map()->is_deprecated()) {
400 // Try to migrate the prototype object so we don't embed the deprecated
401 // map into the optimized code.
402 JSObject::TryMigrateInstance(map_prototype);
403 }
404 map = handle(map_prototype->map(), isolate());
405 holder = map_prototype;
406 } while (CanInlinePropertyAccess(map));
407 return false;
408}
409
Ben Murdoch014dc512016-03-22 12:00:34 +0000410bool AccessInfoFactory::ComputePropertyAccessInfos(
411 MapHandleList const& maps, Handle<Name> name, AccessMode access_mode,
412 ZoneVector<PropertyAccessInfo>* access_infos) {
413 for (Handle<Map> map : maps) {
414 if (Map::TryUpdate(map).ToHandle(&map)) {
415 PropertyAccessInfo access_info;
416 if (!ComputePropertyAccessInfo(map, name, access_mode, &access_info)) {
417 return false;
418 }
Ben Murdochf91f0612016-11-29 16:50:11 +0000419 // Try to merge the {access_info} with an existing one.
420 bool merged = false;
421 for (PropertyAccessInfo& other_info : *access_infos) {
422 if (other_info.Merge(&access_info)) {
423 merged = true;
424 break;
425 }
426 }
427 if (!merged) access_infos->push_back(access_info);
Ben Murdoch014dc512016-03-22 12:00:34 +0000428 }
429 }
430 return true;
431}
432
433
434bool AccessInfoFactory::LookupSpecialFieldAccessor(
435 Handle<Map> map, Handle<Name> name, PropertyAccessInfo* access_info) {
436 // Check for special JSObject field accessors.
437 int offset;
438 if (Accessors::IsJSObjectFieldAccessor(map, name, &offset)) {
439 FieldIndex field_index = FieldIndex::ForInObjectOffset(offset);
Ben Murdochf3b273f2017-01-17 12:11:28 +0000440 Type* field_type = Type::NonInternal();
441 MachineRepresentation field_representation = MachineRepresentation::kTagged;
Ben Murdoch014dc512016-03-22 12:00:34 +0000442 if (map->IsStringMap()) {
443 DCHECK(Name::Equals(factory()->length_string(), name));
444 // The String::length property is always a smi in the range
445 // [0, String::kMaxLength].
446 field_type = type_cache_.kStringLengthType;
Ben Murdochf3b273f2017-01-17 12:11:28 +0000447 field_representation = MachineRepresentation::kTaggedSigned;
Ben Murdoch014dc512016-03-22 12:00:34 +0000448 } else if (map->IsJSArrayMap()) {
449 DCHECK(Name::Equals(factory()->length_string(), name));
450 // The JSArray::length property is a smi in the range
451 // [0, FixedDoubleArray::kMaxLength] in case of fast double
452 // elements, a smi in the range [0, FixedArray::kMaxLength]
453 // in case of other fast elements, and [0, kMaxUInt32] in
454 // case of other arrays.
455 if (IsFastDoubleElementsKind(map->elements_kind())) {
456 field_type = type_cache_.kFixedDoubleArrayLengthType;
Ben Murdochf3b273f2017-01-17 12:11:28 +0000457 field_representation = MachineRepresentation::kTaggedSigned;
Ben Murdoch014dc512016-03-22 12:00:34 +0000458 } else if (IsFastElementsKind(map->elements_kind())) {
459 field_type = type_cache_.kFixedArrayLengthType;
Ben Murdochf3b273f2017-01-17 12:11:28 +0000460 field_representation = MachineRepresentation::kTaggedSigned;
Ben Murdoch014dc512016-03-22 12:00:34 +0000461 } else {
462 field_type = type_cache_.kJSArrayLengthType;
463 }
464 }
Ben Murdochf3b273f2017-01-17 12:11:28 +0000465 *access_info = PropertyAccessInfo::DataField(
466 MapList{map}, field_index, field_representation, field_type);
Ben Murdoch014dc512016-03-22 12:00:34 +0000467 return true;
468 }
Ben Murdoch014dc512016-03-22 12:00:34 +0000469 return false;
470}
471
472
473bool AccessInfoFactory::LookupTransition(Handle<Map> map, Handle<Name> name,
474 MaybeHandle<JSObject> holder,
475 PropertyAccessInfo* access_info) {
476 // Check if the {map} has a data transition with the given {name}.
477 if (map->unused_property_fields() == 0) return false;
478 Handle<Map> transition_map;
479 if (TransitionArray::SearchTransition(map, kData, name, NONE)
480 .ToHandle(&transition_map)) {
481 int const number = transition_map->LastAdded();
482 PropertyDetails const details =
483 transition_map->instance_descriptors()->GetDetails(number);
484 // Don't bother optimizing stores to read-only properties.
485 if (details.IsReadOnly()) return false;
486 // TODO(bmeurer): Handle transition to data constant?
487 if (details.type() != DATA) return false;
488 int const index = details.field_index();
Ben Murdochf3b273f2017-01-17 12:11:28 +0000489 Representation details_representation = details.representation();
Ben Murdoch014dc512016-03-22 12:00:34 +0000490 FieldIndex field_index = FieldIndex::ForPropertyIndex(
Ben Murdochf3b273f2017-01-17 12:11:28 +0000491 *transition_map, index, details_representation.IsDouble());
492 Type* field_type = Type::NonInternal();
493 MaybeHandle<Map> field_map;
494 MachineRepresentation field_representation = MachineRepresentation::kTagged;
495 if (details_representation.IsSmi()) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000496 field_type = type_cache_.kSmi;
Ben Murdochf3b273f2017-01-17 12:11:28 +0000497 field_representation = MachineRepresentation::kTaggedSigned;
498 } else if (details_representation.IsDouble()) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000499 field_type = type_cache_.kFloat64;
Ben Murdochf3b273f2017-01-17 12:11:28 +0000500 field_representation = MachineRepresentation::kFloat64;
501 } else if (details_representation.IsHeapObject()) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000502 // Extract the field type from the property details (make sure its
503 // representation is TaggedPointer to reflect the heap object case).
Ben Murdochf3b273f2017-01-17 12:11:28 +0000504 field_representation = MachineRepresentation::kTaggedPointer;
505 Handle<FieldType> descriptors_field_type(
506 transition_map->instance_descriptors()->GetFieldType(number),
507 isolate());
508 if (descriptors_field_type->IsNone()) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000509 // Store is not safe if the field type was cleared.
510 return false;
Ben Murdochf3b273f2017-01-17 12:11:28 +0000511 } else if (descriptors_field_type->IsClass()) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000512 // Add proper code dependencies in case of stable field map(s).
513 Handle<Map> field_owner_map(transition_map->FindFieldOwner(number),
514 isolate());
515 dependencies()->AssumeFieldType(field_owner_map);
Ben Murdochf3b273f2017-01-17 12:11:28 +0000516
517 // Remember the field map, and try to infer a useful type.
518 field_type = Type::For(descriptors_field_type->AsClass());
519 field_map = descriptors_field_type->AsClass();
Ben Murdoch014dc512016-03-22 12:00:34 +0000520 }
Ben Murdoch014dc512016-03-22 12:00:34 +0000521 }
522 dependencies()->AssumeMapNotDeprecated(transition_map);
Ben Murdochf91f0612016-11-29 16:50:11 +0000523 *access_info = PropertyAccessInfo::DataField(
Ben Murdochf3b273f2017-01-17 12:11:28 +0000524 MapList{map}, field_index, field_representation, field_type, field_map,
525 holder, transition_map);
Ben Murdoch014dc512016-03-22 12:00:34 +0000526 return true;
527 }
528 return false;
529}
530
531
532Factory* AccessInfoFactory::factory() const { return isolate()->factory(); }
533
534} // namespace compiler
535} // namespace internal
536} // namespace v8