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

Side by Side Diff: src/objects.cc

Issue 10915260: Reduce space usage of simple transitions and descriptors holders. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments Created 8 years, 3 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') | src/objects-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 4982 matching lines...) Expand 10 before | Expand all | Expand 10 after
4993 // descriptors in the descriptor array. 4993 // descriptors in the descriptor array.
4994 ASSERT(NumberOfOwnDescriptors() == 4994 ASSERT(NumberOfOwnDescriptors() ==
4995 instance_descriptors()->number_of_descriptors()); 4995 instance_descriptors()->number_of_descriptors());
4996 Map* result; 4996 Map* result;
4997 MaybeObject* maybe_result = CopyDropDescriptors(); 4997 MaybeObject* maybe_result = CopyDropDescriptors();
4998 if (!maybe_result->To(&result)) return maybe_result; 4998 if (!maybe_result->To(&result)) return maybe_result;
4999 4999
5000 String* name = descriptor->GetKey(); 5000 String* name = descriptor->GetKey();
5001 5001
5002 TransitionArray* transitions; 5002 TransitionArray* transitions;
5003 MaybeObject* maybe_transitions = AddTransition(name, result); 5003 MaybeObject* maybe_transitions =
5004 AddTransition(name, result, SIMPLE_TRANSITION);
5004 if (!maybe_transitions->To(&transitions)) return maybe_transitions; 5005 if (!maybe_transitions->To(&transitions)) return maybe_transitions;
5005 5006
5006 DescriptorArray* descriptors = instance_descriptors(); 5007 DescriptorArray* descriptors = instance_descriptors();
5007 int old_size = descriptors->number_of_descriptors(); 5008 int old_size = descriptors->number_of_descriptors();
5008 5009
5009 DescriptorArray* new_descriptors; 5010 DescriptorArray* new_descriptors;
5010 5011
5011 if (descriptors->NumberOfSlackDescriptors() > 0) { 5012 if (descriptors->NumberOfSlackDescriptors() > 0) {
5012 new_descriptors = descriptors; 5013 new_descriptors = descriptors;
5013 new_descriptors->Append(descriptor); 5014 new_descriptors->Append(descriptor);
(...skipping 30 matching lines...) Expand all
5044 5045
5045 result->SetNumberOfOwnDescriptors(new_descriptors->number_of_descriptors()); 5046 result->SetNumberOfOwnDescriptors(new_descriptors->number_of_descriptors());
5046 ASSERT(result->NumberOfOwnDescriptors() == NumberOfOwnDescriptors() + 1); 5047 ASSERT(result->NumberOfOwnDescriptors() == NumberOfOwnDescriptors() + 1);
5047 5048
5048 return result; 5049 return result;
5049 } 5050 }
5050 5051
5051 5052
5052 MaybeObject* Map::CopyReplaceDescriptors(DescriptorArray* descriptors, 5053 MaybeObject* Map::CopyReplaceDescriptors(DescriptorArray* descriptors,
5053 String* name, 5054 String* name,
5054 TransitionFlag flag) { 5055 TransitionFlag flag,
5056 int descriptor_index) {
5055 ASSERT(descriptors->IsSortedNoDuplicates()); 5057 ASSERT(descriptors->IsSortedNoDuplicates());
5056 5058
5057 Map* result; 5059 Map* result;
5058 MaybeObject* maybe_result = CopyDropDescriptors(); 5060 MaybeObject* maybe_result = CopyDropDescriptors();
5059 if (!maybe_result->To(&result)) return maybe_result; 5061 if (!maybe_result->To(&result)) return maybe_result;
5060 5062
5061 // Unless we are creating a map with no descriptors and no back pointer, we 5063 // Unless we are creating a map with no descriptors and no back pointer, we
5062 // insert the descriptor array locally. 5064 // insert the descriptor array locally.
5063 if (!descriptors->IsEmpty()) { 5065 if (!descriptors->IsEmpty()) {
5064 MaybeObject* maybe_failure = result->SetDescriptors(descriptors); 5066 MaybeObject* maybe_failure = result->SetDescriptors(descriptors);
5065 if (maybe_failure->IsFailure()) return maybe_failure; 5067 if (maybe_failure->IsFailure()) return maybe_failure;
5066 result->SetNumberOfOwnDescriptors(descriptors->number_of_descriptors()); 5068 result->SetNumberOfOwnDescriptors(descriptors->number_of_descriptors());
5067 } 5069 }
5068 5070
5069 if (flag == INSERT_TRANSITION && CanHaveMoreTransitions()) { 5071 if (flag == INSERT_TRANSITION && CanHaveMoreTransitions()) {
5070 TransitionArray* transitions; 5072 TransitionArray* transitions;
5071 MaybeObject* maybe_transitions = AddTransition(name, result); 5073 SimpleTransitionFlag simple_flag =
5074 (descriptor_index == descriptors->number_of_descriptors() - 1)
5075 ? SIMPLE_TRANSITION
5076 : FULL_TRANSITION;
5077 MaybeObject* maybe_transitions = AddTransition(name, result, simple_flag);
5072 if (!maybe_transitions->To(&transitions)) return maybe_transitions; 5078 if (!maybe_transitions->To(&transitions)) return maybe_transitions;
5073 5079
5074 if (descriptors->IsEmpty()) { 5080 if (descriptors->IsEmpty()) {
5075 if (owns_descriptors()) { 5081 if (owns_descriptors()) {
5076 // If the copied map has no added fields, and the parent map owns its 5082 // If the copied map has no added fields, and the parent map owns its
5077 // descriptors, those descriptors have to be empty. In that case, 5083 // descriptors, those descriptors have to be empty. In that case,
5078 // transfer ownership of the descriptors to the new child. 5084 // transfer ownership of the descriptors to the new child.
5079 ASSERT(instance_descriptors()->IsEmpty()); 5085 ASSERT(instance_descriptors()->IsEmpty());
5080 set_owns_descriptors(false); 5086 set_owns_descriptors(false);
5081 } else { 5087 } else {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
5166 JSFunction* ctor = JSFunction::cast(constructor()); 5172 JSFunction* ctor = JSFunction::cast(constructor());
5167 Map* map = ctor->initial_map(); 5173 Map* map = ctor->initial_map();
5168 DescriptorArray* descriptors = map->instance_descriptors(); 5174 DescriptorArray* descriptors = map->instance_descriptors();
5169 5175
5170 int number_of_own_descriptors = map->NumberOfOwnDescriptors(); 5176 int number_of_own_descriptors = map->NumberOfOwnDescriptors();
5171 DescriptorArray* new_descriptors; 5177 DescriptorArray* new_descriptors;
5172 MaybeObject* maybe_descriptors = 5178 MaybeObject* maybe_descriptors =
5173 descriptors->CopyUpTo(number_of_own_descriptors); 5179 descriptors->CopyUpTo(number_of_own_descriptors);
5174 if (!maybe_descriptors->To(&new_descriptors)) return maybe_descriptors; 5180 if (!maybe_descriptors->To(&new_descriptors)) return maybe_descriptors;
5175 5181
5176 return CopyReplaceDescriptors(new_descriptors, NULL, OMIT_TRANSITION); 5182 return CopyReplaceDescriptors(new_descriptors, NULL, OMIT_TRANSITION, 0);
5177 } 5183 }
5178 5184
5179 5185
5180 MaybeObject* Map::Copy() { 5186 MaybeObject* Map::Copy() {
5181 DescriptorArray* descriptors = instance_descriptors(); 5187 DescriptorArray* descriptors = instance_descriptors();
5182 DescriptorArray* new_descriptors; 5188 DescriptorArray* new_descriptors;
5183 int number_of_own_descriptors = NumberOfOwnDescriptors(); 5189 int number_of_own_descriptors = NumberOfOwnDescriptors();
5184 MaybeObject* maybe_descriptors = 5190 MaybeObject* maybe_descriptors =
5185 descriptors->CopyUpTo(number_of_own_descriptors); 5191 descriptors->CopyUpTo(number_of_own_descriptors);
5186 if (!maybe_descriptors->To(&new_descriptors)) return maybe_descriptors; 5192 if (!maybe_descriptors->To(&new_descriptors)) return maybe_descriptors;
5187 5193
5188 return CopyReplaceDescriptors(new_descriptors, NULL, OMIT_TRANSITION); 5194 return CopyReplaceDescriptors(new_descriptors, NULL, OMIT_TRANSITION, 0);
5189 } 5195 }
5190 5196
5191 5197
5192 MaybeObject* Map::CopyAddDescriptor(Descriptor* descriptor, 5198 MaybeObject* Map::CopyAddDescriptor(Descriptor* descriptor,
5193 TransitionFlag flag) { 5199 TransitionFlag flag) {
5194 DescriptorArray* descriptors = instance_descriptors(); 5200 DescriptorArray* descriptors = instance_descriptors();
5195 5201
5196 // Ensure the key is a symbol. 5202 // Ensure the key is a symbol.
5197 MaybeObject* maybe_failure = descriptor->KeyToSymbol(); 5203 MaybeObject* maybe_failure = descriptor->KeyToSymbol();
5198 if (maybe_failure->IsFailure()) return maybe_failure; 5204 if (maybe_failure->IsFailure()) return maybe_failure;
(...skipping 21 matching lines...) Expand all
5220 5226
5221 if (old_size != descriptors->number_of_descriptors()) { 5227 if (old_size != descriptors->number_of_descriptors()) {
5222 new_descriptors->SetNumberOfDescriptors(new_size); 5228 new_descriptors->SetNumberOfDescriptors(new_size);
5223 new_descriptors->Set(old_size, descriptor, witness); 5229 new_descriptors->Set(old_size, descriptor, witness);
5224 new_descriptors->Sort(); 5230 new_descriptors->Sort();
5225 } else { 5231 } else {
5226 new_descriptors->Append(descriptor, witness); 5232 new_descriptors->Append(descriptor, witness);
5227 } 5233 }
5228 5234
5229 String* key = descriptor->GetKey(); 5235 String* key = descriptor->GetKey();
5236 int insertion_index = new_descriptors->number_of_descriptors() - 1;
5230 5237
5231 return CopyReplaceDescriptors(new_descriptors, key, flag); 5238 return CopyReplaceDescriptors(new_descriptors, key, flag, insertion_index);
5232 } 5239 }
5233 5240
5234 5241
5235 MaybeObject* Map::CopyInsertDescriptor(Descriptor* descriptor, 5242 MaybeObject* Map::CopyInsertDescriptor(Descriptor* descriptor,
5236 TransitionFlag flag) { 5243 TransitionFlag flag) {
5237 DescriptorArray* old_descriptors = instance_descriptors(); 5244 DescriptorArray* old_descriptors = instance_descriptors();
5238 5245
5239 // Ensure the key is a symbol. 5246 // Ensure the key is a symbol.
5240 MaybeObject* maybe_result = descriptor->KeyToSymbol(); 5247 MaybeObject* maybe_result = descriptor->KeyToSymbol();
5241 if (maybe_result->IsFailure()) return maybe_result; 5248 if (maybe_result->IsFailure()) return maybe_result;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
5297 if (i == insertion_index) { 5304 if (i == insertion_index) {
5298 new_descriptors->Set(i, descriptor, witness); 5305 new_descriptors->Set(i, descriptor, witness);
5299 } else { 5306 } else {
5300 new_descriptors->CopyFrom(i, descriptors, i, witness); 5307 new_descriptors->CopyFrom(i, descriptors, i, witness);
5301 } 5308 }
5302 } 5309 }
5303 5310
5304 // Re-sort if descriptors were removed. 5311 // Re-sort if descriptors were removed.
5305 if (new_size != descriptors->length()) new_descriptors->Sort(); 5312 if (new_size != descriptors->length()) new_descriptors->Sort();
5306 5313
5307 return CopyReplaceDescriptors(new_descriptors, key, flag); 5314 return CopyReplaceDescriptors(new_descriptors, key, flag, insertion_index);
5308 } 5315 }
5309 5316
5310 5317
5311 void Map::UpdateCodeCache(Handle<Map> map, 5318 void Map::UpdateCodeCache(Handle<Map> map,
5312 Handle<String> name, 5319 Handle<String> name,
5313 Handle<Code> code) { 5320 Handle<Code> code) {
5314 Isolate* isolate = map->GetIsolate(); 5321 Isolate* isolate = map->GetIsolate();
5315 CALL_HEAP_FUNCTION_VOID(isolate, 5322 CALL_HEAP_FUNCTION_VOID(isolate,
5316 map->UpdateCodeCache(*name, *code)); 5323 map->UpdateCodeCache(*name, *code));
5317 } 5324 }
(...skipping 2229 matching lines...) Expand 10 before | Expand all | Expand 10 after
7547 if (transition_index == 0 && 7554 if (transition_index == 0 &&
7548 !t->HasElementsTransition() && 7555 !t->HasElementsTransition() &&
7549 !t->HasPrototypeTransitions() && 7556 !t->HasPrototypeTransitions() &&
7550 number_of_own_descriptors == 0) { 7557 number_of_own_descriptors == 0) {
7551 ASSERT(owns_descriptors()); 7558 ASSERT(owns_descriptors());
7552 return ClearTransitions(heap); 7559 return ClearTransitions(heap);
7553 } 7560 }
7554 7561
7555 int trim = t->number_of_transitions() - transition_index; 7562 int trim = t->number_of_transitions() - transition_index;
7556 if (trim > 0) { 7563 if (trim > 0) {
7557 RightTrimFixedArray<FROM_GC>( 7564 RightTrimFixedArray<FROM_GC>(heap, t, t->IsSimpleTransition()
7558 heap, t, trim * TransitionArray::kTransitionSize); 7565 ? trim : trim * TransitionArray::kTransitionSize);
7559 } 7566 }
7560 } 7567 }
7561 7568
7562 7569
7563 int Map::Hash() { 7570 int Map::Hash() {
7564 // For performance reasons we only hash the 3 most variable fields of a map: 7571 // For performance reasons we only hash the 3 most variable fields of a map:
7565 // constructor, prototype and bit_field2. 7572 // constructor, prototype and bit_field2.
7566 7573
7567 // Shift away the tag. 7574 // Shift away the tag.
7568 int hash = (static_cast<uint32_t>( 7575 int hash = (static_cast<uint32_t>(
(...skipping 5952 matching lines...) Expand 10 before | Expand all | Expand 10 after
13521 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 13528 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
13522 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 13529 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
13523 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 13530 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
13524 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 13531 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
13525 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 13532 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
13526 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 13533 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
13527 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 13534 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
13528 } 13535 }
13529 13536
13530 } } // namespace v8::internal 13537 } } // namespace v8::internal
OLDNEW
« 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