OLD | NEW |
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 6642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6653 Handle<Map> Map::Copy(Handle<Map> map) { | 6653 Handle<Map> Map::Copy(Handle<Map> map) { |
6654 Handle<DescriptorArray> descriptors(map->instance_descriptors()); | 6654 Handle<DescriptorArray> descriptors(map->instance_descriptors()); |
6655 int number_of_own_descriptors = map->NumberOfOwnDescriptors(); | 6655 int number_of_own_descriptors = map->NumberOfOwnDescriptors(); |
6656 Handle<DescriptorArray> new_descriptors = | 6656 Handle<DescriptorArray> new_descriptors = |
6657 DescriptorArray::CopyUpTo(descriptors, number_of_own_descriptors); | 6657 DescriptorArray::CopyUpTo(descriptors, number_of_own_descriptors); |
6658 return CopyReplaceDescriptors( | 6658 return CopyReplaceDescriptors( |
6659 map, new_descriptors, OMIT_TRANSITION, MaybeHandle<Name>()); | 6659 map, new_descriptors, OMIT_TRANSITION, MaybeHandle<Name>()); |
6660 } | 6660 } |
6661 | 6661 |
6662 | 6662 |
6663 Handle<Map> Map::Create(Handle<JSFunction> constructor, | 6663 Handle<Map> Map::Create(Isolate* isolate, int inobject_properties) { |
6664 int extra_inobject_properties) { | 6664 Handle<Map> copy = Copy(handle(isolate->object_function()->initial_map())); |
6665 Handle<Map> copy = Copy(handle(constructor->initial_map())); | |
6666 | 6665 |
6667 // Check that we do not overflow the instance size when adding the | 6666 // Check that we do not overflow the instance size when adding the extra |
6668 // extra inobject properties. | 6667 // inobject properties. If the instance size overflows, we allocate as many |
6669 int instance_size_delta = extra_inobject_properties * kPointerSize; | 6668 // properties as we can as inobject properties. |
6670 int max_instance_size_delta = | 6669 int max_extra_properties = |
6671 JSObject::kMaxInstanceSize - copy->instance_size(); | 6670 (JSObject::kMaxInstanceSize - JSObject::kHeaderSize) >> kPointerSizeLog2; |
6672 int max_extra_properties = max_instance_size_delta >> kPointerSizeLog2; | |
6673 | 6671 |
6674 // If the instance size overflows, we allocate as many properties as we can as | 6672 if (inobject_properties > max_extra_properties) { |
6675 // inobject properties. | 6673 inobject_properties = max_extra_properties; |
6676 if (extra_inobject_properties > max_extra_properties) { | |
6677 instance_size_delta = max_instance_size_delta; | |
6678 extra_inobject_properties = max_extra_properties; | |
6679 } | 6674 } |
6680 | 6675 |
| 6676 int new_instance_size = |
| 6677 JSObject::kHeaderSize + kPointerSize * inobject_properties; |
| 6678 |
6681 // Adjust the map with the extra inobject properties. | 6679 // Adjust the map with the extra inobject properties. |
6682 int inobject_properties = | |
6683 copy->inobject_properties() + extra_inobject_properties; | |
6684 copy->set_inobject_properties(inobject_properties); | 6680 copy->set_inobject_properties(inobject_properties); |
6685 copy->set_unused_property_fields(inobject_properties); | 6681 copy->set_unused_property_fields(inobject_properties); |
6686 copy->set_instance_size(copy->instance_size() + instance_size_delta); | 6682 copy->set_instance_size(new_instance_size); |
6687 copy->set_visitor_id(StaticVisitorBase::GetVisitorId(*copy)); | 6683 copy->set_visitor_id(StaticVisitorBase::GetVisitorId(*copy)); |
6688 return copy; | 6684 return copy; |
6689 } | 6685 } |
6690 | 6686 |
6691 | 6687 |
6692 Handle<Map> Map::CopyForFreeze(Handle<Map> map) { | 6688 Handle<Map> Map::CopyForFreeze(Handle<Map> map) { |
6693 int num_descriptors = map->NumberOfOwnDescriptors(); | 6689 int num_descriptors = map->NumberOfOwnDescriptors(); |
6694 Isolate* isolate = map->GetIsolate(); | 6690 Isolate* isolate = map->GetIsolate(); |
6695 Handle<DescriptorArray> new_desc = DescriptorArray::CopyUpToAddAttributes( | 6691 Handle<DescriptorArray> new_desc = DescriptorArray::CopyUpToAddAttributes( |
6696 handle(map->instance_descriptors(), isolate), num_descriptors, FROZEN); | 6692 handle(map->instance_descriptors(), isolate), num_descriptors, FROZEN); |
(...skipping 9673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16370 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16366 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16371 static const char* error_messages_[] = { | 16367 static const char* error_messages_[] = { |
16372 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16368 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16373 }; | 16369 }; |
16374 #undef ERROR_MESSAGES_TEXTS | 16370 #undef ERROR_MESSAGES_TEXTS |
16375 return error_messages_[reason]; | 16371 return error_messages_[reason]; |
16376 } | 16372 } |
16377 | 16373 |
16378 | 16374 |
16379 } } // namespace v8::internal | 16375 } } // namespace v8::internal |
OLD | NEW |