Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1434)

Unified Diff: src/objects.cc

Issue 10824042: Use linear backing store for hidden properties to save memory. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index fe94a42c4ad9fcb709c9c2af86b0a15fb34cf32f..c798343a1f32a7a2c448e237b53f79a2b3a8cd62 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -3559,16 +3559,14 @@ Object* JSObject::GetHiddenProperty(String* key) {
return JSObject::cast(proxy_parent)->GetHiddenProperty(key);
}
ASSERT(!IsJSGlobalProxy());
- MaybeObject* hidden_lookup = GetHiddenPropertiesDictionary(false);
+ MaybeObject* hidden_lookup = GetHiddenPropertiesArray(false);
ASSERT(!hidden_lookup->IsFailure()); // No failure when passing false as arg.
if (hidden_lookup->ToObjectUnchecked()->IsUndefined()) {
return GetHeap()->undefined_value();
}
- StringDictionary* dictionary =
- StringDictionary::cast(hidden_lookup->ToObjectUnchecked());
- int entry = dictionary->FindEntry(key);
- if (entry == StringDictionary::kNotFound) return GetHeap()->undefined_value();
- return dictionary->ValueAt(entry);
+ HiddenPropertiesArray* hidden_properties =
+ HiddenPropertiesArray::cast(hidden_lookup->ToObjectUnchecked());
+ return hidden_properties->Get(key);
}
@@ -3591,28 +3589,25 @@ MaybeObject* JSObject::SetHiddenProperty(String* key, Object* value) {
return JSObject::cast(proxy_parent)->SetHiddenProperty(key, value);
}
ASSERT(!IsJSGlobalProxy());
- MaybeObject* hidden_lookup = GetHiddenPropertiesDictionary(true);
- StringDictionary* dictionary;
- if (!hidden_lookup->To<StringDictionary>(&dictionary)) return hidden_lookup;
- // If it was found, check if the key is already in the dictionary.
- int entry = dictionary->FindEntry(key);
- if (entry != StringDictionary::kNotFound) {
- // If key was found, just update the value.
- dictionary->ValueAtPut(entry, value);
- return this;
+ HiddenPropertiesArray* hidden_properties;
+ { MaybeObject* maybe_obj = GetHiddenPropertiesArray(true);
+ if (!maybe_obj->To<HiddenPropertiesArray>(&hidden_properties)) {
+ return maybe_obj;
+ }
}
- // Key was not already in the dictionary, so add the entry.
- MaybeObject* insert_result = dictionary->Add(key,
- value,
- PropertyDetails(NONE, NORMAL));
- StringDictionary* new_dict;
- if (!insert_result->To<StringDictionary>(&new_dict)) return insert_result;
- if (new_dict != dictionary) {
- // If adding the key expanded the dictionary (i.e., Add returned a new
- // dictionary), store it back to the object.
- MaybeObject* store_result = SetHiddenPropertiesDictionary(new_dict);
- if (store_result->IsFailure()) return store_result;
+
+ HiddenPropertiesArray* new_hidden_properties;
+ MaybeObject* store_result = hidden_properties->Set(key, value);
+ if (!store_result->To<HiddenPropertiesArray>(&new_hidden_properties)) {
+ return store_result;
+ }
+
+ if (new_hidden_properties != hidden_properties) {
+ // Update the object if the backing store has been re-allocated.
+ MaybeObject* maybe_obj = SetHiddenPropertiesArray(
+ new_hidden_properties);
+ if (maybe_obj->IsFailure()) return maybe_obj;
}
// Return this to mark success.
return this;
@@ -3629,18 +3624,12 @@ void JSObject::DeleteHiddenProperty(String* key) {
JSObject::cast(proxy_parent)->DeleteHiddenProperty(key);
return;
}
- MaybeObject* hidden_lookup = GetHiddenPropertiesDictionary(false);
- ASSERT(!hidden_lookup->IsFailure()); // No failure when passing false as arg.
+ MaybeObject* hidden_lookup = GetHiddenPropertiesArray(false);
+ ASSERT(!hidden_lookup->IsFailure());
if (hidden_lookup->ToObjectUnchecked()->IsUndefined()) return;
- StringDictionary* dictionary =
- StringDictionary::cast(hidden_lookup->ToObjectUnchecked());
- int entry = dictionary->FindEntry(key);
- if (entry == StringDictionary::kNotFound) {
- // Key wasn't in dictionary. Deletion is a success.
- return;
- }
- // Key was in the dictionary. Remove it.
- dictionary->DeleteProperty(entry, JSReceiver::FORCE_DELETION);
+ HiddenPropertiesArray* hidden_properties =
+ HiddenPropertiesArray::cast(hidden_lookup->ToObjectUnchecked());
+ hidden_properties->Delete(key);
}
@@ -3651,7 +3640,7 @@ bool JSObject::HasHiddenProperties() {
}
-MaybeObject* JSObject::GetHiddenPropertiesDictionary(bool create_if_absent) {
+MaybeObject* JSObject::GetHiddenPropertiesArray(bool create_if_absent) {
ASSERT(!IsJSGlobalProxy());
if (HasFastProperties()) {
// If the object has fast properties, check whether the first slot
@@ -3662,9 +3651,9 @@ MaybeObject* JSObject::GetHiddenPropertiesDictionary(bool create_if_absent) {
if ((descriptors->number_of_descriptors() > 0) &&
(descriptors->GetKey(0) == GetHeap()->hidden_symbol())) {
ASSERT(descriptors->GetType(0) == FIELD);
- Object* hidden_store =
+ Object* hidden_properties =
this->FastPropertyAt(descriptors->GetFieldIndex(0));
- return StringDictionary::cast(hidden_store);
+ return HiddenPropertiesArray::cast(hidden_properties);
}
} else {
PropertyAttributes attributes;
@@ -3676,27 +3665,31 @@ MaybeObject* JSObject::GetHiddenPropertiesDictionary(bool create_if_absent) {
GetHeap()->hidden_symbol(),
&attributes)->ToObjectUnchecked();
if (!lookup->IsUndefined()) {
- return StringDictionary::cast(lookup);
+ return HiddenPropertiesArray::cast(lookup);
}
}
if (!create_if_absent) return GetHeap()->undefined_value();
- const int kInitialSize = 5;
- MaybeObject* dict_alloc = StringDictionary::Allocate(kInitialSize);
- StringDictionary* dictionary;
- if (!dict_alloc->To<StringDictionary>(&dictionary)) return dict_alloc;
+
+ HiddenPropertiesArray* hidden_properties;
+ { MaybeObject* maybe_obj = HiddenPropertiesArray::Allocate();
+ if (!maybe_obj->To<HiddenPropertiesArray>(&hidden_properties)) {
+ return maybe_obj;
+ }
+ }
+
MaybeObject* store_result =
SetPropertyPostInterceptor(GetHeap()->hidden_symbol(),
- dictionary,
+ hidden_properties,
DONT_ENUM,
kNonStrictMode,
OMIT_EXTENSIBILITY_CHECK);
if (store_result->IsFailure()) return store_result;
- return dictionary;
+ return hidden_properties;
}
-MaybeObject* JSObject::SetHiddenPropertiesDictionary(
- StringDictionary* dictionary) {
+MaybeObject* JSObject::SetHiddenPropertiesArray(
+ HiddenPropertiesArray* hidden_properties) {
ASSERT(!IsJSGlobalProxy());
ASSERT(HasHiddenProperties());
if (HasFastProperties()) {
@@ -3708,13 +3701,13 @@ MaybeObject* JSObject::SetHiddenPropertiesDictionary(
if ((descriptors->number_of_descriptors() > 0) &&
(descriptors->GetKey(0) == GetHeap()->hidden_symbol())) {
ASSERT(descriptors->GetType(0) == FIELD);
- this->FastPropertyAtPut(descriptors->GetFieldIndex(0), dictionary);
+ this->FastPropertyAtPut(descriptors->GetFieldIndex(0), hidden_properties);
return this;
}
}
MaybeObject* store_result =
SetPropertyPostInterceptor(GetHeap()->hidden_symbol(),
- dictionary,
+ hidden_properties,
DONT_ENUM,
kNonStrictMode,
OMIT_EXTENSIBILITY_CHECK);
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698