Commit 05270212 authored by ishell@chromium.org's avatar ishell@chromium.org

Remake of the load elimination fix made earlier (r18884).

R=titzer@chromium.org, verwaest@chromium.org

Review URL: https://codereview.chromium.org/149063010

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19057 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 8d1504b2
This diff is collapsed.
......@@ -3618,8 +3618,7 @@ void HAllocate::CreateFreeSpaceFiller(int32_t free_space_size) {
filler_map->FinalizeUniqueness(); // TODO(titzer): should be init'd a'ready
filler_map->InsertAfter(free_space_instr);
HInstruction* store_map = HStoreNamedField::New(zone, context(),
free_space_instr, HObjectAccess::ForMap(), filler_map,
INITIALIZING_STORE);
free_space_instr, HObjectAccess::ForMap(), filler_map);
store_map->SetFlag(HValue::kHasNoObservableSideEffects);
store_map->InsertAfter(filler_map);
......@@ -3630,10 +3629,11 @@ void HAllocate::CreateFreeSpaceFiller(int32_t free_space_size) {
zone, context(), free_space_size, Representation::Smi(), store_map);
// Must force Smi representation for x64 (see comment above).
HObjectAccess access =
HObjectAccess::ForJSObjectOffset(FreeSpace::kSizeOffset,
Representation::Smi());
HObjectAccess::ForMapAndOffset(isolate()->factory()->free_space_map(),
FreeSpace::kSizeOffset,
Representation::Smi());
HStoreNamedField* store_size = HStoreNamedField::New(zone, context(),
free_space_instr, access, filler_size, INITIALIZING_STORE);
free_space_instr, access, filler_size);
store_size->SetFlag(HValue::kHasNoObservableSideEffects);
store_size->InsertAfter(filler_size);
filler_free_space_size_ = store_size;
......@@ -3643,10 +3643,11 @@ void HAllocate::CreateFreeSpaceFiller(int32_t free_space_size) {
void HAllocate::ClearNextMapWord(int offset) {
if (MustClearNextMapWord()) {
Zone* zone = block()->zone();
HObjectAccess access = HObjectAccess::ForJSObjectOffset(offset);
HObjectAccess access =
HObjectAccess::ForObservableJSObjectOffset(offset);
HStoreNamedField* clear_next_map =
HStoreNamedField::New(zone, context(), this, access,
block()->graph()->GetConstant0(), INITIALIZING_STORE);
block()->graph()->GetConstant0());
clear_next_map->ClearAllSideEffects();
clear_next_map->InsertAfter(this);
}
......@@ -4270,7 +4271,7 @@ HObjectAccess HObjectAccess::ForFixedArrayHeader(int offset) {
}
HObjectAccess HObjectAccess::ForJSObjectOffset(int offset,
HObjectAccess HObjectAccess::ForMapAndOffset(Handle<Map> map, int offset,
Representation representation) {
ASSERT(offset >= 0);
Portion portion = kInobject;
......@@ -4280,7 +4281,13 @@ HObjectAccess HObjectAccess::ForJSObjectOffset(int offset,
} else if (offset == JSObject::kMapOffset) {
portion = kMaps;
}
return HObjectAccess(portion, offset, representation);
bool existing_inobject_property = true;
if (!map.is_null()) {
existing_inobject_property = (offset <
map->instance_size() - map->unused_property_fields() * kPointerSize);
}
return HObjectAccess(portion, offset, representation, Handle<String>::null(),
false, existing_inobject_property);
}
......@@ -4332,7 +4339,8 @@ HObjectAccess HObjectAccess::ForJSArrayOffset(int offset) {
HObjectAccess HObjectAccess::ForBackingStoreOffset(int offset,
Representation representation) {
ASSERT(offset >= 0);
return HObjectAccess(kBackingStore, offset, representation);
return HObjectAccess(kBackingStore, offset, representation,
Handle<String>::null(), false, false);
}
......@@ -4357,11 +4365,12 @@ HObjectAccess HObjectAccess::ForField(Handle<Map> map,
// Negative property indices are in-object properties, indexed
// from the end of the fixed part of the object.
int offset = (index * kPointerSize) + map->instance_size();
return HObjectAccess(kInobject, offset, representation, name);
return HObjectAccess(kInobject, offset, representation, name, false, true);
} else {
// Non-negative property indices are in the properties array.
int offset = (index * kPointerSize) + FixedArray::kHeaderSize;
return HObjectAccess(kBackingStore, offset, representation, name);
return HObjectAccess(kBackingStore, offset, representation, name,
false, false);
}
}
......
......@@ -5710,8 +5710,15 @@ class HObjectAccess V8_FINAL {
return ImmutableField::decode(value_);
}
// Returns true if access is being made to an in-object property that
// was already added to the object.
inline bool existing_inobject_property() const {
return ExistingInobjectPropertyField::decode(value_);
}
inline HObjectAccess WithRepresentation(Representation representation) {
return HObjectAccess(portion(), offset(), representation, name());
return HObjectAccess(portion(), offset(), representation, name(),
immutable(), existing_inobject_property());
}
static HObjectAccess ForHeapNumberValue() {
......@@ -5755,7 +5762,8 @@ class HObjectAccess V8_FINAL {
static HObjectAccess ForAllocationSiteOffset(int offset);
static HObjectAccess ForAllocationSiteList() {
return HObjectAccess(kExternalMemory, 0, Representation::Tagged());
return HObjectAccess(kExternalMemory, 0, Representation::Tagged(),
Handle<String>::null(), false, false);
}
static HObjectAccess ForFixedArrayLength() {
......@@ -5857,16 +5865,29 @@ class HObjectAccess V8_FINAL {
}
static HObjectAccess ForCounter() {
return HObjectAccess(kExternalMemory, 0, Representation::Integer32());
return HObjectAccess(kExternalMemory, 0, Representation::Integer32(),
Handle<String>::null(), false, false);
}
// Create an access to an offset in a fixed array header.
static HObjectAccess ForFixedArrayHeader(int offset);
// Create an access to an in-object property in a JSObject.
static HObjectAccess ForJSObjectOffset(int offset,
// This kind of access must be used when the object |map| is known and
// in-object properties are being accessed. Accesses of the in-object
// properties can have different semantics depending on whether corresponding
// property was added to the map or not.
static HObjectAccess ForMapAndOffset(Handle<Map> map, int offset,
Representation representation = Representation::Tagged());
// Create an access to an in-object property in a JSObject.
// This kind of access can be used for accessing object header fields or
// in-object properties if the map of the object is not known.
static HObjectAccess ForObservableJSObjectOffset(int offset,
Representation representation = Representation::Tagged()) {
return ForMapAndOffset(Handle<Map>::null(), offset, representation);
}
// Create an access to an in-object property in a JSArray.
static HObjectAccess ForJSArrayOffset(int offset);
......@@ -5884,39 +5905,42 @@ class HObjectAccess V8_FINAL {
static HObjectAccess ForCellPayload(Isolate* isolate);
static HObjectAccess ForJSTypedArrayLength() {
return HObjectAccess::ForJSObjectOffset(JSTypedArray::kLengthOffset);
return HObjectAccess::ForObservableJSObjectOffset(
JSTypedArray::kLengthOffset);
}
static HObjectAccess ForJSArrayBufferBackingStore() {
return HObjectAccess::ForJSObjectOffset(
return HObjectAccess::ForObservableJSObjectOffset(
JSArrayBuffer::kBackingStoreOffset, Representation::External());
}
static HObjectAccess ForExternalArrayExternalPointer() {
return HObjectAccess::ForJSObjectOffset(
return HObjectAccess::ForObservableJSObjectOffset(
ExternalArray::kExternalPointerOffset, Representation::External());
}
static HObjectAccess ForJSArrayBufferViewWeakNext() {
return HObjectAccess::ForJSObjectOffset(JSArrayBufferView::kWeakNextOffset);
return HObjectAccess::ForObservableJSObjectOffset(
JSArrayBufferView::kWeakNextOffset);
}
static HObjectAccess ForJSArrayBufferWeakFirstView() {
return HObjectAccess::ForJSObjectOffset(
return HObjectAccess::ForObservableJSObjectOffset(
JSArrayBuffer::kWeakFirstViewOffset);
}
static HObjectAccess ForJSArrayBufferViewBuffer() {
return HObjectAccess::ForJSObjectOffset(JSArrayBufferView::kBufferOffset);
return HObjectAccess::ForObservableJSObjectOffset(
JSArrayBufferView::kBufferOffset);
}
static HObjectAccess ForJSArrayBufferViewByteOffset() {
return HObjectAccess::ForJSObjectOffset(
return HObjectAccess::ForObservableJSObjectOffset(
JSArrayBufferView::kByteOffsetOffset);
}
static HObjectAccess ForJSArrayBufferViewByteLength() {
return HObjectAccess::ForJSObjectOffset(
return HObjectAccess::ForObservableJSObjectOffset(
JSArrayBufferView::kByteLengthOffset);
}
......@@ -5949,23 +5973,29 @@ class HObjectAccess V8_FINAL {
HObjectAccess(Portion portion, int offset,
Representation representation = Representation::Tagged(),
Handle<String> name = Handle<String>::null(),
bool immutable = false)
bool immutable = false,
bool existing_inobject_property = true)
: value_(PortionField::encode(portion) |
RepresentationField::encode(representation.kind()) |
ImmutableField::encode(immutable ? 1 : 0) |
ExistingInobjectPropertyField::encode(
existing_inobject_property ? 1 : 0) |
OffsetField::encode(offset)),
name_(name) {
// assert that the fields decode correctly
ASSERT(this->offset() == offset);
ASSERT(this->portion() == portion);
ASSERT(this->immutable() == immutable);
ASSERT(this->existing_inobject_property() == existing_inobject_property);
ASSERT(RepresentationField::decode(value_) == representation.kind());
ASSERT(!this->existing_inobject_property() || IsInobject());
}
class PortionField : public BitField<Portion, 0, 3> {};
class RepresentationField : public BitField<Representation::Kind, 3, 4> {};
class ImmutableField : public BitField<bool, 7, 1> {};
class OffsetField : public BitField<int, 8, 24> {};
class ExistingInobjectPropertyField : public BitField<bool, 8, 1> {};
class OffsetField : public BitField<int, 9, 23> {};
uint32_t value_; // encodes portion, representation, immutable, and offset
Handle<String> name_;
......@@ -6351,9 +6381,6 @@ class HLoadKeyedGeneric V8_FINAL : public HTemplateInstruction<3> {
// Indicates whether the store is a store to an entry that was previously
// initialized or not.
enum StoreFieldOrKeyedMode {
// This is a store of either an undefined value to a field or a hole/NaN to
// an entry of a newly allocated object.
PREINITIALIZING_STORE,
// The entry could be either previously initialized or not.
INITIALIZING_STORE,
// At the time of this store it is guaranteed that the entry is already
......@@ -6364,6 +6391,8 @@ enum StoreFieldOrKeyedMode {
class HStoreNamedField V8_FINAL : public HTemplateInstruction<3> {
public:
DECLARE_INSTRUCTION_FACTORY_P3(HStoreNamedField, HValue*,
HObjectAccess, HValue*);
DECLARE_INSTRUCTION_FACTORY_P4(HStoreNamedField, HValue*,
HObjectAccess, HValue*, StoreFieldOrKeyedMode);
......@@ -6470,16 +6499,15 @@ class HStoreNamedField V8_FINAL : public HTemplateInstruction<3> {
HStoreNamedField(HValue* obj,
HObjectAccess access,
HValue* val,
StoreFieldOrKeyedMode store_mode)
StoreFieldOrKeyedMode store_mode = INITIALIZING_STORE)
: access_(access),
new_space_dominator_(NULL),
write_barrier_mode_(UPDATE_WRITE_BARRIER),
has_transition_(false),
store_mode_(store_mode) {
// PREINITIALIZING_STORE is only used to mark stores that initialize a
// memory region resulting from HAllocate (possibly through an
// HInnerAllocatedObject).
ASSERT(store_mode != PREINITIALIZING_STORE ||
// Stores to a non existing in-object property are allowed only to the
// newly allocated objects (via HAllocate or HInnerAllocatedObject).
ASSERT(!access.IsInobject() || access.existing_inobject_property() ||
obj->IsAllocate() || obj->IsInnerAllocatedObject());
SetOperandAt(0, obj);
SetOperandAt(1, val);
......@@ -6491,7 +6519,7 @@ class HStoreNamedField V8_FINAL : public HTemplateInstruction<3> {
HValue* new_space_dominator_;
WriteBarrierMode write_barrier_mode_ : 1;
bool has_transition_ : 1;
StoreFieldOrKeyedMode store_mode_ : 2;
StoreFieldOrKeyedMode store_mode_ : 1;
};
......@@ -6536,6 +6564,8 @@ class HStoreNamedGeneric V8_FINAL : public HTemplateInstruction<3> {
class HStoreKeyed V8_FINAL
: public HTemplateInstruction<3>, public ArrayInstructionInterface {
public:
DECLARE_INSTRUCTION_FACTORY_P4(HStoreKeyed, HValue*, HValue*, HValue*,
ElementsKind);
DECLARE_INSTRUCTION_FACTORY_P5(HStoreKeyed, HValue*, HValue*, HValue*,
ElementsKind, StoreFieldOrKeyedMode);
......@@ -6655,7 +6685,7 @@ class HStoreKeyed V8_FINAL
private:
HStoreKeyed(HValue* obj, HValue* key, HValue* val,
ElementsKind elements_kind,
StoreFieldOrKeyedMode store_mode)
StoreFieldOrKeyedMode store_mode = INITIALIZING_STORE)
: elements_kind_(elements_kind),
index_offset_(0),
is_dehoisted_(false),
......@@ -6666,12 +6696,6 @@ class HStoreKeyed V8_FINAL
SetOperandAt(1, key);
SetOperandAt(2, val);
// PREINITIALIZING_STORE is only used to mark stores that initialize a
// memory region resulting from HAllocate (possibly through an
// HInnerAllocatedObject).
ASSERT(store_mode != PREINITIALIZING_STORE ||
obj->IsAllocate() || obj->IsInnerAllocatedObject());
ASSERT(store_mode != STORE_TO_INITIALIZED_ENTRY ||
elements_kind == FAST_SMI_ELEMENTS);
......@@ -6706,7 +6730,7 @@ class HStoreKeyed V8_FINAL
uint32_t index_offset_;
bool is_dehoisted_ : 1;
bool is_uninitialized_ : 1;
StoreFieldOrKeyedMode store_mode_: 2;
StoreFieldOrKeyedMode store_mode_: 1;
HValue* new_space_dominator_;
};
......
......@@ -193,6 +193,10 @@ class HLoadEliminationTable : public ZoneObject {
// load or store for this object and field exists, return the new value with
// which the load should be replaced. Otherwise, return {instr}.
HValue* load(HLoadNamedField* instr) {
// There must be no loads from non observable in-object properties.
ASSERT(!instr->access().IsInobject() ||
instr->access().existing_inobject_property());
int field = FieldOf(instr->access());
if (field < 0) return instr;
......@@ -217,8 +221,9 @@ class HLoadEliminationTable : public ZoneObject {
// the stored values are the same), return NULL indicating that this store
// instruction is redundant. Otherwise, return {instr}.
HValue* store(HStoreNamedField* instr) {
if (instr->store_mode() == PREINITIALIZING_STORE) {
TRACE((" skipping preinitializing store\n"));
if (instr->access().IsInobject() &&
!instr->access().existing_inobject_property()) {
TRACE((" skipping non existing property initialization store\n"));
return instr;
}
......
This diff is collapsed.
......@@ -1370,7 +1370,7 @@ class HGraphBuilder {
HInstruction* AddLoadStringLength(HValue* string);
HStoreNamedField* AddStoreMapNoWriteBarrier(HValue* object, HValue* map) {
HStoreNamedField* store_map = Add<HStoreNamedField>(
object, HObjectAccess::ForMap(), map, INITIALIZING_STORE);
object, HObjectAccess::ForMap(), map);
store_map->SkipWriteBarrier();
return store_map;
}
......@@ -2322,7 +2322,7 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor {
ASSERT(name_->Equals(isolate()->heap()->length_string()));
*access = HObjectAccess::ForStringLength();
} else {
*access = HObjectAccess::ForJSObjectOffset(offset);
*access = HObjectAccess::ForMapAndOffset(map(), offset);
}
return true;
}
......
......@@ -1968,18 +1968,12 @@ void JSObject::FastPropertyAtPut(int index, Object* value) {
int JSObject::GetInObjectPropertyOffset(int index) {
// Adjust for the number of properties stored in the object.
index -= map()->inobject_properties();
ASSERT(index < 0);
return map()->instance_size() + (index * kPointerSize);
return map()->GetInObjectPropertyOffset(index);
}
Object* JSObject::InObjectPropertyAt(int index) {
// Adjust for the number of properties stored in the object.
index -= map()->inobject_properties();
ASSERT(index < 0);
int offset = map()->instance_size() + (index * kPointerSize);
int offset = GetInObjectPropertyOffset(index);
return READ_FIELD(this, offset);
}
......@@ -1988,9 +1982,7 @@ Object* JSObject::InObjectPropertyAtPut(int index,
Object* value,
WriteBarrierMode mode) {
// Adjust for the number of properties stored in the object.
index -= map()->inobject_properties();
ASSERT(index < 0);
int offset = map()->instance_size() + (index * kPointerSize);
int offset = GetInObjectPropertyOffset(index);
WRITE_FIELD(this, offset, value);
CONDITIONAL_WRITE_BARRIER(GetHeap(), this, offset, value, mode);
return value;
......@@ -3808,6 +3800,14 @@ int Map::pre_allocated_property_fields() {
}
int Map::GetInObjectPropertyOffset(int index) {
// Adjust for the number of properties stored in the object.
index -= inobject_properties();
ASSERT(index < 0);
return instance_size() + (index * kPointerSize);
}
int HeapObject::SizeFromMap(Map* map) {
int instance_size = map->instance_size();
if (instance_size != kVariableSizeSentinel) return instance_size;
......
......@@ -5981,6 +5981,8 @@ class Map: public HeapObject {
Map* FindUpdatedMap(int verbatim, int length, DescriptorArray* descriptors);
Map* FindLastMatchMap(int verbatim, int length, DescriptorArray* descriptors);
inline int GetInObjectPropertyOffset(int index);
int NumberOfFields();
bool InstancesNeedRewriting(Map* target,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment