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_H_
|
|
|
|
#define V8_FIELD_INDEX_H_
|
|
|
|
|
|
|
|
#include "src/property-details.h"
|
2014-06-20 08:40:11 +00:00
|
|
|
#include "src/utils.h"
|
2014-06-10 14:01:08 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
class Map;
|
|
|
|
|
|
|
|
// Wrapper class to hold a field index, usually but not necessarily generated
|
|
|
|
// from a property index. When available, the wrapper class captures additional
|
|
|
|
// information to allow the field index to be translated back into the property
|
|
|
|
// index it was originally generated from.
|
|
|
|
class FieldIndex V8_FINAL {
|
|
|
|
public:
|
|
|
|
static FieldIndex ForPropertyIndex(Map* map,
|
|
|
|
int index,
|
|
|
|
bool is_double = false);
|
|
|
|
static FieldIndex ForInObjectOffset(int offset, Map* map = NULL);
|
|
|
|
static FieldIndex ForLookupResult(const LookupResult* result);
|
|
|
|
static FieldIndex ForDescriptor(Map* map, int descriptor_index);
|
|
|
|
static FieldIndex ForLoadByFieldIndex(Map* map, int index);
|
2014-06-12 09:58:10 +00:00
|
|
|
static FieldIndex ForKeyedLookupCacheIndex(Map* map, int index);
|
2014-06-10 14:01:08 +00:00
|
|
|
|
2014-07-07 11:35:17 +00:00
|
|
|
int GetLoadByFieldIndex() const;
|
|
|
|
|
2014-06-10 14:01:08 +00:00
|
|
|
bool is_inobject() const {
|
|
|
|
return IsInObjectBits::decode(bit_field_);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_double() const {
|
|
|
|
return IsDoubleBits::decode(bit_field_);
|
|
|
|
}
|
|
|
|
|
|
|
|
int offset() const {
|
|
|
|
return index() * kPointerSize;
|
|
|
|
}
|
|
|
|
|
2014-07-07 11:35:17 +00:00
|
|
|
// Zero-indexed from beginning of the object.
|
2014-06-10 14:01:08 +00:00
|
|
|
int index() const {
|
|
|
|
return IndexBits::decode(bit_field_);
|
|
|
|
}
|
|
|
|
|
|
|
|
int outobject_array_index() const {
|
|
|
|
ASSERT(!is_inobject());
|
|
|
|
return index() - first_inobject_property_offset() / kPointerSize;
|
|
|
|
}
|
|
|
|
|
2014-07-07 11:35:17 +00:00
|
|
|
// Zero-based from the first inobject property. Overflows to out-of-object
|
|
|
|
// properties.
|
2014-06-10 14:01:08 +00:00
|
|
|
int property_index() const {
|
|
|
|
ASSERT(!IsHiddenField::decode(bit_field_));
|
|
|
|
int result = index() - first_inobject_property_offset() / kPointerSize;
|
|
|
|
if (!is_inobject()) {
|
|
|
|
result += InObjectPropertyBits::decode(bit_field_);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-06-12 09:58:10 +00:00
|
|
|
int GetKeyedLookupCacheIndex() const;
|
2014-06-10 14:01:08 +00:00
|
|
|
|
|
|
|
int GetLoadFieldStubKey() const {
|
|
|
|
return bit_field_ &
|
|
|
|
(IsInObjectBits::kMask | IsDoubleBits::kMask | IndexBits::kMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
FieldIndex(bool is_inobject, int local_index, bool is_double,
|
|
|
|
int inobject_properties, int first_inobject_property_offset,
|
|
|
|
bool is_hidden = false) {
|
|
|
|
ASSERT((first_inobject_property_offset & (kPointerSize - 1)) == 0);
|
|
|
|
bit_field_ = IsInObjectBits::encode(is_inobject) |
|
|
|
|
IsDoubleBits::encode(is_double) |
|
|
|
|
FirstInobjectPropertyOffsetBits::encode(first_inobject_property_offset) |
|
|
|
|
IsHiddenField::encode(is_hidden) |
|
|
|
|
IndexBits::encode(local_index) |
|
|
|
|
InObjectPropertyBits::encode(inobject_properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
int first_inobject_property_offset() const {
|
|
|
|
ASSERT(!IsHiddenField::decode(bit_field_));
|
|
|
|
return FirstInobjectPropertyOffsetBits::decode(bit_field_);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const int kIndexBitsSize = kDescriptorIndexBitCount + 1;
|
|
|
|
|
2014-07-07 11:35:17 +00:00
|
|
|
// Index from beginning of object.
|
2014-06-10 14:01:08 +00:00
|
|
|
class IndexBits: public BitField<int, 0, kIndexBitsSize> {};
|
|
|
|
class IsInObjectBits: public BitField<bool, IndexBits::kNext, 1> {};
|
|
|
|
class IsDoubleBits: public BitField<bool, IsInObjectBits::kNext, 1> {};
|
2014-07-07 11:35:17 +00:00
|
|
|
// Number of inobject properties.
|
2014-06-10 14:01:08 +00:00
|
|
|
class InObjectPropertyBits: public BitField<int, IsDoubleBits::kNext,
|
|
|
|
kDescriptorIndexBitCount> {};
|
2014-07-07 11:35:17 +00:00
|
|
|
// Offset of first inobject property from beginning of object.
|
2014-06-10 14:01:08 +00:00
|
|
|
class FirstInobjectPropertyOffsetBits:
|
|
|
|
public BitField<int, InObjectPropertyBits::kNext, 7> {};
|
|
|
|
class IsHiddenField:
|
|
|
|
public BitField<bool, FirstInobjectPropertyOffsetBits::kNext, 1> {};
|
|
|
|
STATIC_ASSERT(IsHiddenField::kNext <= 32);
|
|
|
|
|
|
|
|
int bit_field_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif
|