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

Unified Diff: src/objects.cc

Issue 3028019: Cache maps when normalizing properties.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 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/contexts.h ('k') | src/v8-counters.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
===================================================================
--- src/objects.cc (revision 5120)
+++ src/objects.cc (working copy)
@@ -2114,6 +2114,84 @@
}
+class NormalizedMapCache {
Mads Ager (chromium) 2010/07/23 09:07:32 : public AllStatic ? Also, please have public: se
+ static bool IsMatchFor(Map* slow, Map* fast, PropertyNormalizationMode mode);
+
+ public:
+ static int Hash(Map* fast, PropertyNormalizationMode mode);
+
+ static Object* Get(Map* fast, int hash, PropertyNormalizationMode mode);
+
+ static void Set(int hash, Map* slow);
+};
+
+
+int NormalizedMapCache::Hash(Map* fast, PropertyNormalizationMode mode) {
+ // XOR bytes in every fields that will be copied to the normalized fast_map.
+ // Ignoring:
+ // instance_size (determined by instance_type and inobject_properties)
+ // scavenger (determined by instance_type and instance_size)
+ // pre_allocated_property_fields (always 0)
+ // unused_property_fields (always 0)
+ // code_cache (always empty)
+ // instance_descriptors (always empty)
+
+ int index =
+ (static_cast<uint32_t>(
+ reinterpret_cast<uintptr_t>(fast->constructor())) >> 2) ^
+ (static_cast<uint32_t>(
+ reinterpret_cast<uintptr_t>(fast->prototype())) >> 2);
+
+ index ^= (index >> 16);
+ index ^= (index >> 8);
+
+ index ^=
+ ((mode == CLEAR_INOBJECT_PROPERTIES) ? 0 : fast->inobject_properties());
+ index ^= fast->instance_type();
+ index ^= fast->bit_field();
+ index ^= fast->bit_field2();
+
+ return index & 0xFF;
Mads Ager (chromium) 2010/07/23 09:07:32 Why do you return only 8 bits?
+}
+
+
+bool NormalizedMapCache::IsMatchFor(Map* slow,
+ Map* fast,
+ PropertyNormalizationMode mode) {
+ ASSERT(slow->pre_allocated_property_fields() == 0);
+ ASSERT(slow->unused_property_fields() == 0);
+
+ return
+ slow->constructor() == fast->constructor() &&
+ slow->prototype() == fast->prototype() &&
+ slow->inobject_properties() == ((mode == CLEAR_INOBJECT_PROPERTIES) ?
+ 0 :
+ fast->inobject_properties()) &&
+ slow->instance_type() == fast->instance_type() &&
+ slow->bit_field() == fast->bit_field() &&
+ slow->bit_field2() == fast->bit_field2();
+}
+
+
+Object* NormalizedMapCache::Get(Map* fast,
+ int hash,
+ PropertyNormalizationMode mode) {
+ Object* cached = Top::slow_map_cache()->get(hash);
+ if (!cached->IsMap()) return cached; // Cache miss.
+
+ Map* slow = Map::cast(cached);
+ if (IsMatchFor(slow, fast, mode)) return cached; // Found the right map.
+
+ // Hash collision. Pretend there was a miss, the entry will be overwritten.
+ return Heap::undefined_value();
+}
+
+
+void NormalizedMapCache::Set(int hash, Map* map) {
+ Top::slow_map_cache()->set(hash, map);
+}
+
+
Object* JSObject::NormalizeProperties(PropertyNormalizationMode mode,
int expected_additional_properties) {
if (!HasFastProperties()) return this;
@@ -2178,30 +2256,46 @@
int index = map()->instance_descriptors()->NextEnumerationIndex();
dictionary->SetNextEnumerationIndex(index);
- // Allocate new map.
- obj = map()->CopyDropDescriptors();
- if (obj->IsFailure()) return obj;
- Map* new_map = Map::cast(obj);
+ int hash = NormalizedMapCache::Hash(map(), mode);
+ obj = NormalizedMapCache::Get(map(), hash, mode);
+ if (obj->IsMap()) {
+ Map* new_map = Map::cast(obj);
+ int new_instance_size = new_map->instance_size();
+ int instance_size_delta = map()->instance_size() - new_instance_size;
+ if (instance_size_delta != 0) {
+ Heap::CreateFillerObjectAt(this->address() + new_instance_size,
+ instance_size_delta);
+ }
+ set_map(new_map);
+ } else {
+ // Allocate new map.
+ obj = map()->CopyDropDescriptors();
+ if (obj->IsFailure()) return obj;
+ Map* new_map = Map::cast(obj);
- // Clear inobject properties if needed by adjusting the instance size and
- // putting in a filler object instead of the inobject properties.
- if (mode == CLEAR_INOBJECT_PROPERTIES && map()->inobject_properties() > 0) {
- int instance_size_delta = map()->inobject_properties() * kPointerSize;
- int new_instance_size = map()->instance_size() - instance_size_delta;
- new_map->set_inobject_properties(0);
- new_map->set_instance_size(new_instance_size);
- new_map->set_scavenger(Heap::GetScavenger(new_map->instance_type(),
- new_map->instance_size()));
- Heap::CreateFillerObjectAt(this->address() + new_instance_size,
- instance_size_delta);
+ // Clear inobject properties if needed by adjusting the instance size and
+ // putting in a filler object instead of the inobject properties.
+ if (mode == CLEAR_INOBJECT_PROPERTIES && map()->inobject_properties() > 0) {
+ int instance_size_delta = map()->inobject_properties() * kPointerSize;
+ int new_instance_size = map()->instance_size() - instance_size_delta;
+ new_map->set_inobject_properties(0);
+ new_map->set_instance_size(new_instance_size);
+ new_map->set_scavenger(Heap::GetScavenger(new_map->instance_type(),
+ new_map->instance_size()));
+ Heap::CreateFillerObjectAt(this->address() + new_instance_size,
+ instance_size_delta);
+ }
+ new_map->set_unused_property_fields(0);
+ new_map->set_pre_allocated_property_fields(0);
+
+ // We have now successfully allocated all the necessary objects.
+ // Changes can now be made with the guarantee that all of them take effect.
+ set_map(new_map);
+ map()->set_instance_descriptors(Heap::empty_descriptor_array());
+ NormalizedMapCache::Set(hash, new_map);
+ Counters::normalized_maps.Increment();
}
- new_map->set_unused_property_fields(0);
- // We have now successfully allocated all the necessary objects.
- // Changes can now be made with the guarantee that all of them take effect.
- set_map(new_map);
- map()->set_instance_descriptors(Heap::empty_descriptor_array());
-
set_properties(dictionary);
Counters::props_to_dictionary.Increment();
« no previous file with comments | « src/contexts.h ('k') | src/v8-counters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698