2014-06-10 14:01:08 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef V8_FIELD_INDEX_INL_H_
|
|
|
|
#define V8_FIELD_INDEX_INL_H_
|
|
|
|
|
|
|
|
#include "src/field-index.h"
|
2017-07-28 07:01:59 +00:00
|
|
|
#include "src/objects-inl.h"
|
2019-02-01 09:14:54 +00:00
|
|
|
#include "src/objects/descriptor-array-inl.h"
|
2014-06-10 14:01:08 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2019-02-07 20:27:25 +00:00
|
|
|
FieldIndex FieldIndex::ForInObjectOffset(int offset, Encoding encoding) {
|
2019-01-17 18:02:38 +00:00
|
|
|
DCHECK_IMPLIES(encoding == kWord32, IsAligned(offset, kInt32Size));
|
|
|
|
DCHECK_IMPLIES(encoding == kTagged, IsAligned(offset, kTaggedSize));
|
|
|
|
DCHECK_IMPLIES(encoding == kDouble, IsAligned(offset, kDoubleSize));
|
2017-11-14 14:15:00 +00:00
|
|
|
return FieldIndex(true, offset, encoding, 0, 0);
|
2014-06-10 14:01:08 +00:00
|
|
|
}
|
|
|
|
|
2019-02-07 20:27:25 +00:00
|
|
|
FieldIndex FieldIndex::ForPropertyIndex(const Map map, int property_index,
|
|
|
|
Representation representation) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(map->instance_type() >= FIRST_NONSTRING_TYPE);
|
2015-08-11 19:36:04 +00:00
|
|
|
int inobject_properties = map->GetInObjectProperties();
|
2014-06-10 14:01:08 +00:00
|
|
|
bool is_inobject = property_index < inobject_properties;
|
|
|
|
int first_inobject_offset;
|
2017-11-14 14:15:00 +00:00
|
|
|
int offset;
|
2014-06-10 14:01:08 +00:00
|
|
|
if (is_inobject) {
|
|
|
|
first_inobject_offset = map->GetInObjectPropertyOffset(0);
|
2017-11-14 14:15:00 +00:00
|
|
|
offset = map->GetInObjectPropertyOffset(property_index);
|
2014-06-10 14:01:08 +00:00
|
|
|
} else {
|
|
|
|
first_inobject_offset = FixedArray::kHeaderSize;
|
|
|
|
property_index -= inobject_properties;
|
2019-01-17 18:02:38 +00:00
|
|
|
offset = PropertyArray::OffsetOfElementAt(property_index);
|
2014-06-10 14:01:08 +00:00
|
|
|
}
|
2017-11-14 14:15:00 +00:00
|
|
|
Encoding encoding = FieldEncoding(representation);
|
|
|
|
return FieldIndex(is_inobject, offset, encoding, inobject_properties,
|
|
|
|
first_inobject_offset);
|
2014-06-10 14:01:08 +00:00
|
|
|
}
|
|
|
|
|
2014-07-07 11:35:17 +00:00
|
|
|
// Returns the index format accepted by the HLoadFieldByIndex instruction.
|
|
|
|
// (In-object: zero-based from (object start + JSObject::kHeaderSize),
|
|
|
|
// out-of-object: zero-based from FixedArray::kHeaderSize.)
|
2019-02-07 20:27:25 +00:00
|
|
|
int FieldIndex::GetLoadByFieldIndex() const {
|
2014-07-07 11:35:17 +00:00
|
|
|
// For efficiency, the LoadByFieldIndex instruction takes an index that is
|
|
|
|
// optimized for quick access. If the property is inline, the index is
|
|
|
|
// positive. If it's out-of-line, the encoded index is -raw_index - 1 to
|
|
|
|
// disambiguate the zero out-of-line index from the zero inobject case.
|
|
|
|
// The index itself is shifted up by one bit, the lower-most bit
|
|
|
|
// signifying if the field is a mutable double box (1) or not (0).
|
|
|
|
int result = index();
|
|
|
|
if (is_inobject()) {
|
2019-01-17 18:02:38 +00:00
|
|
|
result -= JSObject::kHeaderSize / kTaggedSize;
|
2014-07-07 11:35:17 +00:00
|
|
|
} else {
|
2019-01-17 18:02:38 +00:00
|
|
|
result -= FixedArray::kHeaderSize / kTaggedSize;
|
2014-07-07 11:35:17 +00:00
|
|
|
result = -result - 1;
|
|
|
|
}
|
2019-01-25 00:33:28 +00:00
|
|
|
result = static_cast<uint32_t>(result) << 1;
|
2014-07-07 11:35:17 +00:00
|
|
|
return is_double() ? (result | 1) : result;
|
2014-06-10 14:01:08 +00:00
|
|
|
}
|
|
|
|
|
2019-02-07 20:27:25 +00:00
|
|
|
FieldIndex FieldIndex::ForDescriptor(const Map map, int descriptor_index) {
|
2014-06-10 14:01:08 +00:00
|
|
|
PropertyDetails details =
|
|
|
|
map->instance_descriptors()->GetDetails(descriptor_index);
|
2015-09-30 12:49:07 +00:00
|
|
|
int field_index = details.field_index();
|
2017-11-14 14:15:00 +00:00
|
|
|
return ForPropertyIndex(map, field_index, details.representation());
|
2014-09-01 13:55:39 +00:00
|
|
|
}
|
|
|
|
|
2015-09-30 13:46:56 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2014-06-10 14:01:08 +00:00
|
|
|
|
2018-02-02 12:05:19 +00:00
|
|
|
#endif // V8_FIELD_INDEX_INL_H_
|