From 9d52c4093266a88c49e7813cdd2423f211b914aa Mon Sep 17 00:00:00 2001 From: "jkummerow@chromium.org" Date: Mon, 7 Jul 2014 11:35:17 +0000 Subject: [PATCH] Hydrogenized KeyedLoadGeneric stub: Fix FieldIndex::GetLoadByFieldIndex() R=danno@chromium.org Review URL: https://codereview.chromium.org/370573003 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22238 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/field-index-inl.h | 28 +++++++++++++++++++++++++++- src/field-index.h | 23 ++++++++--------------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/field-index-inl.h b/src/field-index-inl.h index d3bf94a..f1591af 100644 --- a/src/field-index-inl.h +++ b/src/field-index-inl.h @@ -45,6 +45,8 @@ inline FieldIndex FieldIndex::ForPropertyIndex(Map* map, } +// Takes an index as computed by GetLoadFieldByIndex and reconstructs a +// FieldIndex object from it. inline FieldIndex FieldIndex::ForLoadByFieldIndex(Map* map, int orig_index) { int field_index = orig_index; int is_inobject = true; @@ -60,8 +62,32 @@ inline FieldIndex FieldIndex::ForLoadByFieldIndex(Map* map, int orig_index) { first_inobject_offset = map->GetInObjectPropertyOffset(0); field_index += JSObject::kHeaderSize / kPointerSize; } - return FieldIndex(is_inobject, field_index, is_double, + FieldIndex result(is_inobject, field_index, is_double, map->inobject_properties(), first_inobject_offset); + ASSERT(result.GetLoadByFieldIndex() == orig_index); + 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; } diff --git a/src/field-index.h b/src/field-index.h index b25e624..096b335 100644 --- a/src/field-index.h +++ b/src/field-index.h @@ -28,6 +28,8 @@ class FieldIndex V8_FINAL { static FieldIndex ForLoadByFieldIndex(Map* map, int index); static FieldIndex ForKeyedLookupCacheIndex(Map* map, int index); + int GetLoadByFieldIndex() const; + bool is_inobject() const { return IsInObjectBits::decode(bit_field_); } @@ -40,6 +42,7 @@ class FieldIndex V8_FINAL { return index() * kPointerSize; } + // Zero-indexed from beginning of the object. int index() const { return IndexBits::decode(bit_field_); } @@ -49,6 +52,8 @@ class FieldIndex V8_FINAL { return index() - first_inobject_property_offset() / kPointerSize; } + // Zero-based from the first inobject property. Overflows to out-of-object + // properties. int property_index() const { ASSERT(!IsHiddenField::decode(bit_field_)); int result = index() - first_inobject_property_offset() / kPointerSize; @@ -58,21 +63,6 @@ class FieldIndex V8_FINAL { return result; } - int 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() - first_inobject_property_offset() / kPointerSize; - if (!is_inobject()) { - result = -result - 1; - } - result <<= 1; - return is_double() ? (result | 1) : result; - } - int GetKeyedLookupCacheIndex() const; int GetLoadFieldStubKey() const { @@ -100,11 +90,14 @@ class FieldIndex V8_FINAL { static const int kIndexBitsSize = kDescriptorIndexBitCount + 1; + // Index from beginning of object. class IndexBits: public BitField {}; class IsInObjectBits: public BitField {}; class IsDoubleBits: public BitField {}; + // Number of inobject properties. class InObjectPropertyBits: public BitField {}; + // Offset of first inobject property from beginning of object. class FirstInobjectPropertyOffsetBits: public BitField {}; class IsHiddenField: -- 2.7.4