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

Side by Side Diff: src/objects.cc

Issue 346743005: Making MigrateToMap() a single bottleneck for all migrations except slow-to-fast case. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/allocation-site-scopes.h" 8 #include "src/allocation-site-scopes.h"
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/arguments.h" 10 #include "src/arguments.h"
(...skipping 2101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2112 Handle<TransitionArray> transitions = TransitionArray::CopyInsert( 2112 Handle<TransitionArray> transitions = TransitionArray::CopyInsert(
2113 map, 2113 map,
2114 map->GetIsolate()->factory()->elements_transition_symbol(), 2114 map->GetIsolate()->factory()->elements_transition_symbol(),
2115 transitioned_map, 2115 transitioned_map,
2116 FULL_TRANSITION); 2116 FULL_TRANSITION);
2117 map->set_transitions(*transitions); 2117 map->set_transitions(*transitions);
2118 return transitions; 2118 return transitions;
2119 } 2119 }
2120 2120
2121 2121
2122 // To migrate an instance to a map: 2122 void JSObject::MigrateToMap(Handle<JSObject> object, Handle<Map> new_map) {
2123 if (object->map() == *new_map) return;
2124 if (object->HasFastProperties()) {
2125 if (!new_map->is_dictionary_map()) {
2126 MigrateFastToFast(object, new_map);
2127 } else {
2128 MigrateFastToSlow(object, new_map, 0);
2129 }
2130 } else {
2131 // For slow-to-fast migrations JSObject::TransformToFastProperties()
2132 // must be used instead.
2133 CHECK(new_map->is_dictionary_map());
2134
2135 // Slow-to-slow migration is trivial.
2136 object->set_map(*new_map);
2137 }
2138 }
2139
2140
2141 // To migrate an fast instance to a fast map:
Toon Verwaest 2014/06/24 13:17:33 a fast
2123 // - First check whether the instance needs to be rewritten. If not, simply 2142 // - First check whether the instance needs to be rewritten. If not, simply
2124 // change the map. 2143 // change the map.
2125 // - Otherwise, allocate a fixed array large enough to hold all fields, in 2144 // - Otherwise, allocate a fixed array large enough to hold all fields, in
2126 // addition to unused space. 2145 // addition to unused space.
2127 // - Copy all existing properties in, in the following order: backing store 2146 // - Copy all existing properties in, in the following order: backing store
2128 // properties, unused fields, inobject properties. 2147 // properties, unused fields, inobject properties.
2129 // - If all allocation succeeded, commit the state atomically: 2148 // - If all allocation succeeded, commit the state atomically:
2130 // * Copy inobject properties from the backing store back into the object. 2149 // * Copy inobject properties from the backing store back into the object.
2131 // * Trim the difference in instance size of the object. This also cleanly 2150 // * Trim the difference in instance size of the object. This also cleanly
2132 // frees inobject properties that moved to the backing store. 2151 // frees inobject properties that moved to the backing store.
2133 // * If there are properties left in the backing store, trim of the space used 2152 // * If there are properties left in the backing store, trim of the space used
2134 // to temporarily store the inobject properties. 2153 // to temporarily store the inobject properties.
2135 // * If there are properties left in the backing store, install the backing 2154 // * If there are properties left in the backing store, install the backing
2136 // store. 2155 // store.
2137 void JSObject::MigrateToMap(Handle<JSObject> object, Handle<Map> new_map) { 2156 void JSObject::MigrateFastToFast(Handle<JSObject> object, Handle<Map> new_map) {
2138 Isolate* isolate = object->GetIsolate(); 2157 Isolate* isolate = object->GetIsolate();
2139 Handle<Map> old_map(object->map()); 2158 Handle<Map> old_map(object->map());
2140 int number_of_fields = new_map->NumberOfFields(); 2159 int number_of_fields = new_map->NumberOfFields();
2141 int inobject = new_map->inobject_properties(); 2160 int inobject = new_map->inobject_properties();
2142 int unused = new_map->unused_property_fields(); 2161 int unused = new_map->unused_property_fields();
2143 2162
2144 // Nothing to do if no functions were converted to fields and no smis were 2163 // Nothing to do if no functions were converted to fields and no smis were
2145 // converted to doubles. 2164 // converted to doubles.
2146 if (!old_map->InstancesNeedRewriting( 2165 if (!old_map->InstancesNeedRewriting(
2147 *new_map, number_of_fields, inobject, unused)) { 2166 *new_map, number_of_fields, inobject, unused)) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
2269 2288
2270 2289
2271 void JSObject::GeneralizeFieldRepresentation(Handle<JSObject> object, 2290 void JSObject::GeneralizeFieldRepresentation(Handle<JSObject> object,
2272 int modify_index, 2291 int modify_index,
2273 Representation new_representation, 2292 Representation new_representation,
2274 Handle<HeapType> new_field_type, 2293 Handle<HeapType> new_field_type,
2275 StoreMode store_mode) { 2294 StoreMode store_mode) {
2276 Handle<Map> new_map = Map::GeneralizeRepresentation( 2295 Handle<Map> new_map = Map::GeneralizeRepresentation(
2277 handle(object->map()), modify_index, new_representation, 2296 handle(object->map()), modify_index, new_representation,
2278 new_field_type, store_mode); 2297 new_field_type, store_mode);
2279 if (object->map() == *new_map) return; 2298 MigrateToMap(object, new_map);
2280 return MigrateToMap(object, new_map);
2281 } 2299 }
2282 2300
2283 2301
2284 int Map::NumberOfFields() { 2302 int Map::NumberOfFields() {
2285 DescriptorArray* descriptors = instance_descriptors(); 2303 DescriptorArray* descriptors = instance_descriptors();
2286 int result = 0; 2304 int result = 0;
2287 for (int i = 0; i < NumberOfOwnDescriptors(); i++) { 2305 for (int i = 0; i < NumberOfOwnDescriptors(); i++) {
2288 if (descriptors->GetDetails(i).type() == FIELD) result++; 2306 if (descriptors->GetDetails(i).type() == FIELD) result++;
2289 } 2307 }
2290 return result; 2308 return result;
(...skipping 2272 matching lines...) Expand 10 before | Expand all | Expand 10 after
4563 Handle<Map> map(object->map()); 4581 Handle<Map> map(object->map());
4564 Map::UpdateCodeCache(map, name, code); 4582 Map::UpdateCodeCache(map, name, code);
4565 } 4583 }
4566 4584
4567 4585
4568 void JSObject::NormalizeProperties(Handle<JSObject> object, 4586 void JSObject::NormalizeProperties(Handle<JSObject> object,
4569 PropertyNormalizationMode mode, 4587 PropertyNormalizationMode mode,
4570 int expected_additional_properties) { 4588 int expected_additional_properties) {
4571 if (!object->HasFastProperties()) return; 4589 if (!object->HasFastProperties()) return;
4572 4590
4591 Handle<Map> map(object->map());
4592 Handle<Map> new_map = Map::Normalize(map, mode);
4593
4594 MigrateFastToSlow(object, new_map, expected_additional_properties);
4595 }
4596
4597
4598 void JSObject::MigrateFastToSlow(Handle<JSObject> object,
4599 Handle<Map> new_map,
4600 int expected_additional_properties) {
4573 // The global object is always normalized. 4601 // The global object is always normalized.
4574 ASSERT(!object->IsGlobalObject()); 4602 ASSERT(!object->IsGlobalObject());
4575 // JSGlobalProxy must never be normalized 4603 // JSGlobalProxy must never be normalized
4576 ASSERT(!object->IsJSGlobalProxy()); 4604 ASSERT(!object->IsJSGlobalProxy());
4577 4605
4578 Isolate* isolate = object->GetIsolate(); 4606 Isolate* isolate = object->GetIsolate();
4579 HandleScope scope(isolate); 4607 HandleScope scope(isolate);
4580 Handle<Map> map(object->map()); 4608 Handle<Map> map(object->map());
4581 Handle<Map> new_map = Map::Normalize(map, mode);
4582 4609
4583 // Allocate new content. 4610 // Allocate new content.
4584 int real_size = map->NumberOfOwnDescriptors(); 4611 int real_size = map->NumberOfOwnDescriptors();
4585 int property_count = real_size; 4612 int property_count = real_size;
4586 if (expected_additional_properties > 0) { 4613 if (expected_additional_properties > 0) {
4587 property_count += expected_additional_properties; 4614 property_count += expected_additional_properties;
4588 } else { 4615 } else {
4589 property_count += 2; // Make space for two more properties. 4616 property_count += 2; // Make space for two more properties.
4590 } 4617 }
4591 Handle<NameDictionary> dictionary = 4618 Handle<NameDictionary> dictionary =
(...skipping 12391 matching lines...) Expand 10 before | Expand all | Expand 10 after
16983 #define ERROR_MESSAGES_TEXTS(C, T) T, 17010 #define ERROR_MESSAGES_TEXTS(C, T) T,
16984 static const char* error_messages_[] = { 17011 static const char* error_messages_[] = {
16985 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 17012 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16986 }; 17013 };
16987 #undef ERROR_MESSAGES_TEXTS 17014 #undef ERROR_MESSAGES_TEXTS
16988 return error_messages_[reason]; 17015 return error_messages_[reason];
16989 } 17016 }
16990 17017
16991 17018
16992 } } // namespace v8::internal 17019 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698