OLD | NEW |
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 4030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4041 function->set_context(undefined_value()); | 4041 function->set_context(undefined_value()); |
4042 function->set_literals_or_bindings(empty_fixed_array()); | 4042 function->set_literals_or_bindings(empty_fixed_array()); |
4043 function->set_next_function_link(undefined_value()); | 4043 function->set_next_function_link(undefined_value()); |
4044 } | 4044 } |
4045 | 4045 |
4046 | 4046 |
4047 MaybeObject* Heap::AllocateFunctionPrototype(JSFunction* function) { | 4047 MaybeObject* Heap::AllocateFunctionPrototype(JSFunction* function) { |
4048 // Make sure to use globals from the function's context, since the function | 4048 // Make sure to use globals from the function's context, since the function |
4049 // can be from a different context. | 4049 // can be from a different context. |
4050 Context* native_context = function->context()->native_context(); | 4050 Context* native_context = function->context()->native_context(); |
4051 bool needs_constructor_property; | |
4052 Map* new_map; | 4051 Map* new_map; |
4053 if (function->shared()->is_generator()) { | 4052 if (function->shared()->is_generator()) { |
4054 // Generator prototypes can share maps since they don't have "constructor" | 4053 // Generator prototypes can share maps since they don't have "constructor" |
4055 // properties. | 4054 // properties. |
4056 new_map = native_context->generator_object_prototype_map(); | 4055 new_map = native_context->generator_object_prototype_map(); |
4057 needs_constructor_property = false; | |
4058 } else { | 4056 } else { |
4059 // Each function prototype gets a fresh map to avoid unwanted sharing of | 4057 // Each function prototype gets a fresh map to avoid unwanted sharing of |
4060 // maps between prototypes of different constructors. | 4058 // maps between prototypes of different constructors. |
4061 JSFunction* object_function = native_context->object_function(); | 4059 JSFunction* object_function = native_context->object_function(); |
4062 ASSERT(object_function->has_initial_map()); | 4060 ASSERT(object_function->has_initial_map()); |
4063 MaybeObject* maybe_map = object_function->initial_map()->Copy(); | 4061 MaybeObject* maybe_map = object_function->initial_map()->Copy(); |
4064 if (!maybe_map->To(&new_map)) return maybe_map; | 4062 if (!maybe_map->To(&new_map)) return maybe_map; |
4065 needs_constructor_property = true; | |
4066 } | 4063 } |
4067 | 4064 |
4068 Object* prototype; | 4065 Object* prototype; |
4069 MaybeObject* maybe_prototype = AllocateJSObjectFromMap(new_map); | 4066 MaybeObject* maybe_prototype = AllocateJSObjectFromMap(new_map); |
4070 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype; | 4067 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype; |
4071 | 4068 |
4072 if (needs_constructor_property) { | 4069 if (!function->shared()->is_generator()) { |
4073 MaybeObject* maybe_failure = | 4070 MaybeObject* maybe_failure = |
4074 JSObject::cast(prototype)->SetLocalPropertyIgnoreAttributes( | 4071 JSObject::cast(prototype)->SetLocalPropertyIgnoreAttributes( |
4075 constructor_string(), function, DONT_ENUM); | 4072 constructor_string(), function, DONT_ENUM); |
4076 if (maybe_failure->IsFailure()) return maybe_failure; | 4073 if (maybe_failure->IsFailure()) return maybe_failure; |
4077 } | 4074 } |
4078 | 4075 |
4079 return prototype; | 4076 return prototype; |
4080 } | 4077 } |
4081 | 4078 |
4082 | 4079 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4202 map->set_unused_property_fields(in_object_properties); | 4199 map->set_unused_property_fields(in_object_properties); |
4203 map->set_prototype(prototype); | 4200 map->set_prototype(prototype); |
4204 ASSERT(map->has_fast_object_elements()); | 4201 ASSERT(map->has_fast_object_elements()); |
4205 | 4202 |
4206 // If the function has only simple this property assignments add | 4203 // If the function has only simple this property assignments add |
4207 // field descriptors for these to the initial map as the object | 4204 // field descriptors for these to the initial map as the object |
4208 // cannot be constructed without having these properties. Guard by | 4205 // cannot be constructed without having these properties. Guard by |
4209 // the inline_new flag so we only change the map if we generate a | 4206 // the inline_new flag so we only change the map if we generate a |
4210 // specialized construct stub. | 4207 // specialized construct stub. |
4211 ASSERT(in_object_properties <= Map::kMaxPreAllocatedPropertyFields); | 4208 ASSERT(in_object_properties <= Map::kMaxPreAllocatedPropertyFields); |
4212 if (instance_type == JS_OBJECT_TYPE && | 4209 if (!fun->shared()->is_generator() && |
4213 fun->shared()->CanGenerateInlineConstructor(prototype)) { | 4210 fun->shared()->CanGenerateInlineConstructor(prototype)) { |
4214 int count = fun->shared()->this_property_assignments_count(); | 4211 int count = fun->shared()->this_property_assignments_count(); |
4215 if (count > in_object_properties) { | 4212 if (count > in_object_properties) { |
4216 // Inline constructor can only handle inobject properties. | 4213 // Inline constructor can only handle inobject properties. |
4217 fun->shared()->ForbidInlineConstructor(); | 4214 fun->shared()->ForbidInlineConstructor(); |
4218 } else { | 4215 } else { |
4219 DescriptorArray* descriptors; | 4216 DescriptorArray* descriptors; |
4220 MaybeObject* maybe_descriptors = DescriptorArray::Allocate(count); | 4217 MaybeObject* maybe_descriptors = DescriptorArray::Allocate(count); |
4221 if (!maybe_descriptors->To(&descriptors)) return maybe_descriptors; | 4218 if (!maybe_descriptors->To(&descriptors)) return maybe_descriptors; |
4222 | 4219 |
(...skipping 15 matching lines...) Expand all Loading... |
4238 if (HasDuplicates(descriptors)) { | 4235 if (HasDuplicates(descriptors)) { |
4239 fun->shared()->ForbidInlineConstructor(); | 4236 fun->shared()->ForbidInlineConstructor(); |
4240 } else { | 4237 } else { |
4241 map->InitializeDescriptors(descriptors); | 4238 map->InitializeDescriptors(descriptors); |
4242 map->set_pre_allocated_property_fields(count); | 4239 map->set_pre_allocated_property_fields(count); |
4243 map->set_unused_property_fields(in_object_properties - count); | 4240 map->set_unused_property_fields(in_object_properties - count); |
4244 } | 4241 } |
4245 } | 4242 } |
4246 } | 4243 } |
4247 | 4244 |
4248 if (instance_type == JS_OBJECT_TYPE) { | 4245 if (!fun->shared()->is_generator()) { |
4249 fun->shared()->StartInobjectSlackTracking(map); | 4246 fun->shared()->StartInobjectSlackTracking(map); |
4250 } | 4247 } |
4251 | 4248 |
4252 return map; | 4249 return map; |
4253 } | 4250 } |
4254 | 4251 |
4255 | 4252 |
4256 void Heap::InitializeJSObjectFromMap(JSObject* obj, | 4253 void Heap::InitializeJSObjectFromMap(JSObject* obj, |
4257 FixedArray* properties, | 4254 FixedArray* properties, |
4258 Map* map) { | 4255 Map* map) { |
(...skipping 3687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7946 if (FLAG_parallel_recompilation) { | 7943 if (FLAG_parallel_recompilation) { |
7947 heap_->relocation_mutex_->Lock(); | 7944 heap_->relocation_mutex_->Lock(); |
7948 #ifdef DEBUG | 7945 #ifdef DEBUG |
7949 heap_->relocation_mutex_locked_by_optimizer_thread_ = | 7946 heap_->relocation_mutex_locked_by_optimizer_thread_ = |
7950 heap_->isolate()->optimizing_compiler_thread()->IsOptimizerThread(); | 7947 heap_->isolate()->optimizing_compiler_thread()->IsOptimizerThread(); |
7951 #endif // DEBUG | 7948 #endif // DEBUG |
7952 } | 7949 } |
7953 } | 7950 } |
7954 | 7951 |
7955 } } // namespace v8::internal | 7952 } } // namespace v8::internal |
OLD | NEW |