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

Side by Side Diff: src/objects.cc

Issue 72333004: Match max property descriptor length to corresponding bit fields (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review feedback Created 7 years, 1 month 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/property-details.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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 2119 matching lines...) Expand 10 before | Expand all | Expand 10 after
2130 Handle<Object> args[1] = { name }; 2130 Handle<Object> args[1] = { name };
2131 Handle<Object> error = isolate->factory()->NewTypeError( 2131 Handle<Object> error = isolate->factory()->NewTypeError(
2132 "object_not_extensible", HandleVector(args, ARRAY_SIZE(args))); 2132 "object_not_extensible", HandleVector(args, ARRAY_SIZE(args)));
2133 isolate->Throw(*error); 2133 isolate->Throw(*error);
2134 return Handle<Object>(); 2134 return Handle<Object>();
2135 } 2135 }
2136 } 2136 }
2137 2137
2138 if (object->HasFastProperties()) { 2138 if (object->HasFastProperties()) {
2139 // Ensure the descriptor array does not get too big. 2139 // Ensure the descriptor array does not get too big.
2140 if (object->map()->NumberOfOwnDescriptors() < 2140 if (object->map()->NumberOfOwnDescriptors() <= kMaxNumberOfDescriptors) {
2141 DescriptorArray::kMaxNumberOfDescriptors) {
2142 // TODO(verwaest): Support other constants. 2141 // TODO(verwaest): Support other constants.
2143 // if (mode == ALLOW_AS_CONSTANT && 2142 // if (mode == ALLOW_AS_CONSTANT &&
2144 // !value->IsTheHole() && 2143 // !value->IsTheHole() &&
2145 // !value->IsConsString()) { 2144 // !value->IsConsString()) {
2146 if (value->IsJSFunction()) { 2145 if (value->IsJSFunction()) {
2147 AddConstantProperty(object, name, value, attributes, transition_flag); 2146 AddConstantProperty(object, name, value, attributes, transition_flag);
2148 } else { 2147 } else {
2149 AddFastProperty(object, name, value, attributes, store_mode, 2148 AddFastProperty(object, name, value, attributes, store_mode,
2150 value_type, transition_flag); 2149 value_type, transition_flag);
2151 } 2150 }
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
2553 transitions->GetTarget(transition)->DeprecateTransitionTree(); 2552 transitions->GetTarget(transition)->DeprecateTransitionTree();
2554 } 2553 }
2555 } 2554 }
2556 2555
2557 // Don't overwrite the empty descriptor array. 2556 // Don't overwrite the empty descriptor array.
2558 if (NumberOfOwnDescriptors() == 0) return; 2557 if (NumberOfOwnDescriptors() == 0) return;
2559 2558
2560 DescriptorArray* to_replace = instance_descriptors(); 2559 DescriptorArray* to_replace = instance_descriptors();
2561 Map* current = this; 2560 Map* current = this;
2562 while (current->instance_descriptors() == to_replace) { 2561 while (current->instance_descriptors() == to_replace) {
2563 current->SetEnumLength(Map::kInvalidEnumCache); 2562 current->SetEnumLength(kInvalidEnumCacheSentinel);
2564 current->set_instance_descriptors(new_descriptors); 2563 current->set_instance_descriptors(new_descriptors);
2565 Object* next = current->GetBackPointer(); 2564 Object* next = current->GetBackPointer();
2566 if (next->IsUndefined()) break; 2565 if (next->IsUndefined()) break;
2567 current = Map::cast(next); 2566 current = Map::cast(next);
2568 } 2567 }
2569 2568
2570 set_owns_descriptors(false); 2569 set_owns_descriptors(false);
2571 } 2570 }
2572 2571
2573 2572
(...skipping 3334 matching lines...) Expand 10 before | Expand all | Expand 10 after
5908 // - This object has no elements. 5907 // - This object has no elements.
5909 // - No prototype has enumerable properties/elements. 5908 // - No prototype has enumerable properties/elements.
5910 bool JSReceiver::IsSimpleEnum() { 5909 bool JSReceiver::IsSimpleEnum() {
5911 Heap* heap = GetHeap(); 5910 Heap* heap = GetHeap();
5912 for (Object* o = this; 5911 for (Object* o = this;
5913 o != heap->null_value(); 5912 o != heap->null_value();
5914 o = JSObject::cast(o)->GetPrototype()) { 5913 o = JSObject::cast(o)->GetPrototype()) {
5915 if (!o->IsJSObject()) return false; 5914 if (!o->IsJSObject()) return false;
5916 JSObject* curr = JSObject::cast(o); 5915 JSObject* curr = JSObject::cast(o);
5917 int enum_length = curr->map()->EnumLength(); 5916 int enum_length = curr->map()->EnumLength();
5918 if (enum_length == Map::kInvalidEnumCache) return false; 5917 if (enum_length == kInvalidEnumCacheSentinel) return false;
5919 ASSERT(!curr->HasNamedInterceptor()); 5918 ASSERT(!curr->HasNamedInterceptor());
5920 ASSERT(!curr->HasIndexedInterceptor()); 5919 ASSERT(!curr->HasIndexedInterceptor());
5921 ASSERT(!curr->IsAccessCheckNeeded()); 5920 ASSERT(!curr->IsAccessCheckNeeded());
5922 if (curr->NumberOfEnumElements() > 0) return false; 5921 if (curr->NumberOfEnumElements() > 0) return false;
5923 if (curr != this && enum_length != 0) return false; 5922 if (curr != this && enum_length != 0) return false;
5924 } 5923 }
5925 return true; 5924 return true;
5926 } 5925 }
5927 5926
5928 5927
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
6162 Handle<Name> name, 6161 Handle<Name> name,
6163 Handle<Object> getter, 6162 Handle<Object> getter,
6164 Handle<Object> setter, 6163 Handle<Object> setter,
6165 PropertyAttributes attributes, 6164 PropertyAttributes attributes,
6166 v8::AccessControl access_control) { 6165 v8::AccessControl access_control) {
6167 // We could assert that the property is configurable here, but we would need 6166 // We could assert that the property is configurable here, but we would need
6168 // to do a lookup, which seems to be a bit of overkill. 6167 // to do a lookup, which seems to be a bit of overkill.
6169 bool only_attribute_changes = getter->IsNull() && setter->IsNull(); 6168 bool only_attribute_changes = getter->IsNull() && setter->IsNull();
6170 if (object->HasFastProperties() && !only_attribute_changes && 6169 if (object->HasFastProperties() && !only_attribute_changes &&
6171 access_control == v8::DEFAULT && 6170 access_control == v8::DEFAULT &&
6172 (object->map()->NumberOfOwnDescriptors() < 6171 (object->map()->NumberOfOwnDescriptors() <= kMaxNumberOfDescriptors)) {
6173 DescriptorArray::kMaxNumberOfDescriptors)) {
6174 bool getterOk = getter->IsNull() || 6172 bool getterOk = getter->IsNull() ||
6175 DefineFastAccessor(object, name, ACCESSOR_GETTER, getter, attributes); 6173 DefineFastAccessor(object, name, ACCESSOR_GETTER, getter, attributes);
6176 bool setterOk = !getterOk || setter->IsNull() || 6174 bool setterOk = !getterOk || setter->IsNull() ||
6177 DefineFastAccessor(object, name, ACCESSOR_SETTER, setter, attributes); 6175 DefineFastAccessor(object, name, ACCESSOR_SETTER, setter, attributes);
6178 if (getterOk && setterOk) return; 6176 if (getterOk && setterOk) return;
6179 } 6177 }
6180 6178
6181 Handle<AccessorPair> accessors = CreateAccessorPairFor(object, name); 6179 Handle<AccessorPair> accessors = CreateAccessorPairFor(object, name);
6182 accessors->SetComponents(*getter, *setter); 6180 accessors->SetComponents(*getter, *setter);
6183 accessors->set_access_flags(access_control); 6181 accessors->set_access_flags(access_control);
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
6680 GetHeap()->AllocateMap(instance_type(), instance_size); 6678 GetHeap()->AllocateMap(instance_type(), instance_size);
6681 if (!maybe_result->To(&result)) return maybe_result; 6679 if (!maybe_result->To(&result)) return maybe_result;
6682 6680
6683 result->set_prototype(prototype()); 6681 result->set_prototype(prototype());
6684 result->set_constructor(constructor()); 6682 result->set_constructor(constructor());
6685 result->set_bit_field(bit_field()); 6683 result->set_bit_field(bit_field());
6686 result->set_bit_field2(bit_field2()); 6684 result->set_bit_field2(bit_field2());
6687 int new_bit_field3 = bit_field3(); 6685 int new_bit_field3 = bit_field3();
6688 new_bit_field3 = OwnsDescriptors::update(new_bit_field3, true); 6686 new_bit_field3 = OwnsDescriptors::update(new_bit_field3, true);
6689 new_bit_field3 = NumberOfOwnDescriptorsBits::update(new_bit_field3, 0); 6687 new_bit_field3 = NumberOfOwnDescriptorsBits::update(new_bit_field3, 0);
6690 new_bit_field3 = EnumLengthBits::update(new_bit_field3, kInvalidEnumCache); 6688 new_bit_field3 = EnumLengthBits::update(new_bit_field3,
6689 kInvalidEnumCacheSentinel);
6691 new_bit_field3 = Deprecated::update(new_bit_field3, false); 6690 new_bit_field3 = Deprecated::update(new_bit_field3, false);
6692 new_bit_field3 = IsUnstable::update(new_bit_field3, false); 6691 new_bit_field3 = IsUnstable::update(new_bit_field3, false);
6693 result->set_bit_field3(new_bit_field3); 6692 result->set_bit_field3(new_bit_field3);
6694 return result; 6693 return result;
6695 } 6694 }
6696 6695
6697 6696
6698 Handle<Map> Map::CopyNormalized(Handle<Map> map, 6697 Handle<Map> Map::CopyNormalized(Handle<Map> map,
6699 PropertyNormalizationMode mode, 6698 PropertyNormalizationMode mode,
6700 NormalizedMapSharingMode sharing) { 6699 NormalizedMapSharingMode sharing) {
(...skipping 2607 matching lines...) Expand 10 before | Expand all | Expand 10 after
9308 void String::PrintOn(FILE* file) { 9307 void String::PrintOn(FILE* file) {
9309 int length = this->length(); 9308 int length = this->length();
9310 for (int i = 0; i < length; i++) { 9309 for (int i = 0; i < length; i++) {
9311 PrintF(file, "%c", Get(i)); 9310 PrintF(file, "%c", Get(i));
9312 } 9311 }
9313 } 9312 }
9314 9313
9315 9314
9316 static void TrimEnumCache(Heap* heap, Map* map, DescriptorArray* descriptors) { 9315 static void TrimEnumCache(Heap* heap, Map* map, DescriptorArray* descriptors) {
9317 int live_enum = map->EnumLength(); 9316 int live_enum = map->EnumLength();
9318 if (live_enum == Map::kInvalidEnumCache) { 9317 if (live_enum == kInvalidEnumCacheSentinel) {
9319 live_enum = map->NumberOfDescribedProperties(OWN_DESCRIPTORS, DONT_ENUM); 9318 live_enum = map->NumberOfDescribedProperties(OWN_DESCRIPTORS, DONT_ENUM);
9320 } 9319 }
9321 if (live_enum == 0) return descriptors->ClearEnumCache(); 9320 if (live_enum == 0) return descriptors->ClearEnumCache();
9322 9321
9323 FixedArray* enum_cache = descriptors->GetEnumCache(); 9322 FixedArray* enum_cache = descriptors->GetEnumCache();
9324 9323
9325 int to_trim = enum_cache->length() - live_enum; 9324 int to_trim = enum_cache->length() - live_enum;
9326 if (to_trim <= 0) return; 9325 if (to_trim <= 0) return;
9327 RightTrimFixedArray<FROM_GC>(heap, descriptors->GetEnumCache(), to_trim); 9326 RightTrimFixedArray<FROM_GC>(heap, descriptors->GetEnumCache(), to_trim);
9328 9327
(...skipping 4065 matching lines...) Expand 10 before | Expand all | Expand 10 after
13394 return result.IsPropertyCallbacks(); 13393 return result.IsPropertyCallbacks();
13395 } 13394 }
13396 13395
13397 13396
13398 int JSObject::NumberOfLocalProperties(PropertyAttributes filter) { 13397 int JSObject::NumberOfLocalProperties(PropertyAttributes filter) {
13399 if (HasFastProperties()) { 13398 if (HasFastProperties()) {
13400 Map* map = this->map(); 13399 Map* map = this->map();
13401 if (filter == NONE) return map->NumberOfOwnDescriptors(); 13400 if (filter == NONE) return map->NumberOfOwnDescriptors();
13402 if (filter & DONT_ENUM) { 13401 if (filter & DONT_ENUM) {
13403 int result = map->EnumLength(); 13402 int result = map->EnumLength();
13404 if (result != Map::kInvalidEnumCache) return result; 13403 if (result != kInvalidEnumCacheSentinel) return result;
13405 } 13404 }
13406 return map->NumberOfDescribedProperties(OWN_DESCRIPTORS, filter); 13405 return map->NumberOfDescribedProperties(OWN_DESCRIPTORS, filter);
13407 } 13406 }
13408 return property_dictionary()->NumberOfElementsFilterAttributes(filter); 13407 return property_dictionary()->NumberOfElementsFilterAttributes(filter);
13409 } 13408 }
13410 13409
13411 13410
13412 void FixedArray::SwapPairs(FixedArray* numbers, int i, int j) { 13411 void FixedArray::SwapPairs(FixedArray* numbers, int i, int j) {
13413 Object* temp = get(i); 13412 Object* temp = get(i);
13414 set(i, get(j)); 13413 set(i, get(j));
(...skipping 2346 matching lines...) Expand 10 before | Expand all | Expand 10 after
15761 Heap* heap = Dictionary<Shape, Key>::GetHeap(); 15760 Heap* heap = Dictionary<Shape, Key>::GetHeap();
15762 return heap->undefined_value(); 15761 return heap->undefined_value();
15763 } 15762 }
15764 15763
15765 15764
15766 MaybeObject* NameDictionary::TransformPropertiesToFastFor( 15765 MaybeObject* NameDictionary::TransformPropertiesToFastFor(
15767 JSObject* obj, int unused_property_fields) { 15766 JSObject* obj, int unused_property_fields) {
15768 // Make sure we preserve dictionary representation if there are too many 15767 // Make sure we preserve dictionary representation if there are too many
15769 // descriptors. 15768 // descriptors.
15770 int number_of_elements = NumberOfElements(); 15769 int number_of_elements = NumberOfElements();
15771 if (number_of_elements > DescriptorArray::kMaxNumberOfDescriptors) return obj; 15770 if (number_of_elements > kMaxNumberOfDescriptors) return obj;
15772 15771
15773 if (number_of_elements != NextEnumerationIndex()) { 15772 if (number_of_elements != NextEnumerationIndex()) {
15774 MaybeObject* maybe_result = GenerateNewEnumerationIndices(); 15773 MaybeObject* maybe_result = GenerateNewEnumerationIndices();
15775 if (maybe_result->IsFailure()) return maybe_result; 15774 if (maybe_result->IsFailure()) return maybe_result;
15776 } 15775 }
15777 15776
15778 int instance_descriptor_length = 0; 15777 int instance_descriptor_length = 0;
15779 int number_of_fields = 0; 15778 int number_of_fields = 0;
15780 15779
15781 Heap* heap = GetHeap(); 15780 Heap* heap = GetHeap();
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
16633 #define ERROR_MESSAGES_TEXTS(C, T) T, 16632 #define ERROR_MESSAGES_TEXTS(C, T) T,
16634 static const char* error_messages_[] = { 16633 static const char* error_messages_[] = {
16635 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16634 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16636 }; 16635 };
16637 #undef ERROR_MESSAGES_TEXTS 16636 #undef ERROR_MESSAGES_TEXTS
16638 return error_messages_[reason]; 16637 return error_messages_[reason];
16639 } 16638 }
16640 16639
16641 16640
16642 } } // namespace v8::internal 16641 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/property-details.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698