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"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
|
|
|
inline FieldIndex FieldIndex::ForInObjectOffset(int offset, Map* map) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK((offset % kPointerSize) == 0);
|
2014-06-10 14:01:08 +00:00
|
|
|
int index = offset / kPointerSize;
|
2015-02-06 09:43:41 +00:00
|
|
|
DCHECK(map == NULL ||
|
|
|
|
index < (map->GetInObjectPropertyOffset(0) / kPointerSize +
|
2015-08-11 19:36:04 +00:00
|
|
|
map->GetInObjectProperties()));
|
2015-02-06 09:43:41 +00:00
|
|
|
return FieldIndex(true, index, false, 0, 0, true);
|
2014-06-10 14:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline FieldIndex FieldIndex::ForPropertyIndex(Map* map,
|
|
|
|
int property_index,
|
|
|
|
bool is_double) {
|
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;
|
|
|
|
if (is_inobject) {
|
|
|
|
first_inobject_offset = map->GetInObjectPropertyOffset(0);
|
|
|
|
} else {
|
|
|
|
first_inobject_offset = FixedArray::kHeaderSize;
|
|
|
|
property_index -= inobject_properties;
|
|
|
|
}
|
|
|
|
return FieldIndex(is_inobject,
|
|
|
|
property_index + first_inobject_offset / kPointerSize,
|
|
|
|
is_double, inobject_properties, first_inobject_offset);
|
|
|
|
}
|
|
|
|
|
2016-07-15 17:41:14 +00:00
|
|
|
// Takes an index as computed by GetLoadByFieldIndex and reconstructs a
|
2014-07-07 11:35:17 +00:00
|
|
|
// FieldIndex object from it.
|
2014-06-10 14:01:08 +00:00
|
|
|
inline FieldIndex FieldIndex::ForLoadByFieldIndex(Map* map, int orig_index) {
|
|
|
|
int field_index = orig_index;
|
2017-03-17 15:18:18 +00:00
|
|
|
bool is_inobject = true;
|
2014-06-10 14:01:08 +00:00
|
|
|
bool is_double = field_index & 1;
|
|
|
|
int first_inobject_offset = 0;
|
|
|
|
field_index >>= 1;
|
|
|
|
if (field_index < 0) {
|
|
|
|
field_index = -(field_index + 1);
|
|
|
|
is_inobject = false;
|
|
|
|
first_inobject_offset = FixedArray::kHeaderSize;
|
|
|
|
field_index += FixedArray::kHeaderSize / kPointerSize;
|
|
|
|
} else {
|
|
|
|
first_inobject_offset = map->GetInObjectPropertyOffset(0);
|
|
|
|
field_index += JSObject::kHeaderSize / kPointerSize;
|
|
|
|
}
|
2014-07-07 11:35:17 +00:00
|
|
|
FieldIndex result(is_inobject, field_index, is_double,
|
2015-08-11 19:36:04 +00:00
|
|
|
map->GetInObjectProperties(), first_inobject_offset);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(result.GetLoadByFieldIndex() == orig_index);
|
2014-07-07 11:35:17 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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.)
|
|
|
|
inline int FieldIndex::GetLoadByFieldIndex() const {
|
|
|
|
// 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()) {
|
|
|
|
result -= JSObject::kHeaderSize / kPointerSize;
|
|
|
|
} else {
|
|
|
|
result -= FixedArray::kHeaderSize / kPointerSize;
|
|
|
|
result = -result - 1;
|
|
|
|
}
|
|
|
|
result <<= 1;
|
|
|
|
return is_double() ? (result | 1) : result;
|
2014-06-10 14:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline FieldIndex FieldIndex::ForDescriptor(Map* map, int descriptor_index) {
|
|
|
|
PropertyDetails details =
|
|
|
|
map->instance_descriptors()->GetDetails(descriptor_index);
|
2015-09-30 12:49:07 +00:00
|
|
|
int field_index = details.field_index();
|
2014-06-10 14:01:08 +00:00
|
|
|
return ForPropertyIndex(map, field_index,
|
|
|
|
details.representation().IsDouble());
|
|
|
|
}
|
|
|
|
|
2014-09-01 13:55:39 +00:00
|
|
|
inline FieldIndex FieldIndex::FromFieldAccessStubKey(int key) {
|
|
|
|
return FieldIndex(key);
|
|
|
|
}
|
|
|
|
|
2015-09-30 13:46:56 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2014-06-10 14:01:08 +00:00
|
|
|
|
|
|
|
#endif
|