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
This commit is contained in:
ager@chromium.org 2010-07-02 11:27:57 +00:00
parent f9eb21f950
commit 47b5b3f951
3 changed files with 23 additions and 9 deletions

View File

@ -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) {
Object* value = Heap::undefined_value();
for (int offset = kHeaderSize; offset < object_size; offset += kPointerSize) {
@ -1343,11 +1358,6 @@ void Struct::InitializeBody(int object_size) {
}
bool JSObject::HasFastProperties() {
return !properties()->IsDictionary();
}
bool Object::ToArrayIndex(uint32_t* index) {
if (IsSmi()) {
int value = Smi::cast(this)->value();

View File

@ -1276,7 +1276,7 @@ Object* JSObject::AddFastProperty(String* name,
}
if (map()->unused_property_fields() == 0) {
if (properties()->length() > kMaxFastProperties) {
if (properties()->length() > MaxFastProperties()) {
Object* obj = NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0);
if (obj->IsFailure()) return obj;
return AddSlowProperty(name, value, attributes);
@ -1474,7 +1474,7 @@ Object* JSObject::ConvertDescriptorToField(String* name,
Object* new_value,
PropertyAttributes attributes) {
if (map()->unused_property_fields() == 0 &&
properties()->length() > kMaxFastProperties) {
properties()->length() > MaxFastProperties()) {
Object* obj = NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0);
if (obj->IsFailure()) return obj;
return ReplaceSlowProperty(name, new_value, attributes);

View File

@ -1367,6 +1367,7 @@ class JSObject: public HeapObject {
// Returns the index'th element.
// The undefined object if index is out of bounds.
Object* GetElementWithReceiver(JSObject* receiver, uint32_t index);
Object* GetElementWithInterceptor(JSObject* receiver, uint32_t index);
Object* SetFastElementsCapacityAndLength(int capacity, int length);
Object* SetSlowElements(Object* length);
@ -1547,6 +1548,11 @@ class JSObject: public HeapObject {
#endif
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).
// Also maximal value of JSArray's length property.
static const uint32_t kMaxElementCount = 0xffffffffu;
@ -1568,8 +1574,6 @@ class JSObject: public HeapObject {
STATIC_CHECK(kHeaderSize == Internals::kJSObjectHeaderSize);
Object* GetElementWithInterceptor(JSObject* receiver, uint32_t index);
private:
Object* GetElementWithCallback(Object* receiver,
Object* structure,