Commit 47b5b3f9 authored by ager@chromium.org's avatar ager@chromium.org

Use the number of in-object properties when deciding how many fast

properties to allow on an object. If there are many in-object
properties it is unlikely that the object is used as a dictionary and
we allow more map transitions to keep such objects in fast case.

Review URL: http://codereview.chromium.org/2818041

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5008 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent f9eb21f9
...@@ -1335,6 +1335,21 @@ void JSObject::InitializeBody(int object_size) { ...@@ -1335,6 +1335,21 @@ void JSObject::InitializeBody(int object_size) {
} }
bool JSObject::HasFastProperties() {
return !properties()->IsDictionary();
}
int JSObject::MaxFastProperties() {
// Allow extra fast properties if the object has more than
// kMaxFastProperties in-object properties. When this is the case,
// it is very unlikely that the object is being used as a dictionary
// and there is a good chance that allowing more map transitions
// will be worth it.
return Max(map()->inobject_properties(), kMaxFastProperties);
}
void Struct::InitializeBody(int object_size) { void Struct::InitializeBody(int object_size) {
Object* value = Heap::undefined_value(); Object* value = Heap::undefined_value();
for (int offset = kHeaderSize; offset < object_size; offset += kPointerSize) { for (int offset = kHeaderSize; offset < object_size; offset += kPointerSize) {
...@@ -1343,11 +1358,6 @@ void Struct::InitializeBody(int object_size) { ...@@ -1343,11 +1358,6 @@ void Struct::InitializeBody(int object_size) {
} }
bool JSObject::HasFastProperties() {
return !properties()->IsDictionary();
}
bool Object::ToArrayIndex(uint32_t* index) { bool Object::ToArrayIndex(uint32_t* index) {
if (IsSmi()) { if (IsSmi()) {
int value = Smi::cast(this)->value(); int value = Smi::cast(this)->value();
......
...@@ -1276,7 +1276,7 @@ Object* JSObject::AddFastProperty(String* name, ...@@ -1276,7 +1276,7 @@ Object* JSObject::AddFastProperty(String* name,
} }
if (map()->unused_property_fields() == 0) { if (map()->unused_property_fields() == 0) {
if (properties()->length() > kMaxFastProperties) { if (properties()->length() > MaxFastProperties()) {
Object* obj = NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0); Object* obj = NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0);
if (obj->IsFailure()) return obj; if (obj->IsFailure()) return obj;
return AddSlowProperty(name, value, attributes); return AddSlowProperty(name, value, attributes);
...@@ -1474,7 +1474,7 @@ Object* JSObject::ConvertDescriptorToField(String* name, ...@@ -1474,7 +1474,7 @@ Object* JSObject::ConvertDescriptorToField(String* name,
Object* new_value, Object* new_value,
PropertyAttributes attributes) { PropertyAttributes attributes) {
if (map()->unused_property_fields() == 0 && if (map()->unused_property_fields() == 0 &&
properties()->length() > kMaxFastProperties) { properties()->length() > MaxFastProperties()) {
Object* obj = NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0); Object* obj = NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0);
if (obj->IsFailure()) return obj; if (obj->IsFailure()) return obj;
return ReplaceSlowProperty(name, new_value, attributes); return ReplaceSlowProperty(name, new_value, attributes);
......
...@@ -1367,6 +1367,7 @@ class JSObject: public HeapObject { ...@@ -1367,6 +1367,7 @@ class JSObject: public HeapObject {
// Returns the index'th element. // Returns the index'th element.
// The undefined object if index is out of bounds. // The undefined object if index is out of bounds.
Object* GetElementWithReceiver(JSObject* receiver, uint32_t index); Object* GetElementWithReceiver(JSObject* receiver, uint32_t index);
Object* GetElementWithInterceptor(JSObject* receiver, uint32_t index);
Object* SetFastElementsCapacityAndLength(int capacity, int length); Object* SetFastElementsCapacityAndLength(int capacity, int length);
Object* SetSlowElements(Object* length); Object* SetSlowElements(Object* length);
...@@ -1547,6 +1548,11 @@ class JSObject: public HeapObject { ...@@ -1547,6 +1548,11 @@ class JSObject: public HeapObject {
#endif #endif
Object* SlowReverseLookup(Object* value); Object* SlowReverseLookup(Object* value);
// Maximal number of fast properties for the JSObject. Used to
// restrict the number of map transitions to avoid an explosion in
// the number of maps for objects used as dictionaries.
inline int MaxFastProperties();
// Maximal number of elements (numbered 0 .. kMaxElementCount - 1). // Maximal number of elements (numbered 0 .. kMaxElementCount - 1).
// Also maximal value of JSArray's length property. // Also maximal value of JSArray's length property.
static const uint32_t kMaxElementCount = 0xffffffffu; static const uint32_t kMaxElementCount = 0xffffffffu;
...@@ -1568,8 +1574,6 @@ class JSObject: public HeapObject { ...@@ -1568,8 +1574,6 @@ class JSObject: public HeapObject {
STATIC_CHECK(kHeaderSize == Internals::kJSObjectHeaderSize); STATIC_CHECK(kHeaderSize == Internals::kJSObjectHeaderSize);
Object* GetElementWithInterceptor(JSObject* receiver, uint32_t index);
private: private:
Object* GetElementWithCallback(Object* receiver, Object* GetElementWithCallback(Object* receiver,
Object* structure, Object* structure,
......
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