| 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 4079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4090 HeapObject::cast(result)->set_map_no_write_barrier(map); | 4090 HeapObject::cast(result)->set_map_no_write_barrier(map); |
| 4091 if (allocation_site != NULL) { | 4091 if (allocation_site != NULL) { |
| 4092 AllocationMemento* alloc_memento = reinterpret_cast<AllocationMemento*>( | 4092 AllocationMemento* alloc_memento = reinterpret_cast<AllocationMemento*>( |
| 4093 reinterpret_cast<Address>(result) + map->instance_size()); | 4093 reinterpret_cast<Address>(result) + map->instance_size()); |
| 4094 InitializeAllocationMemento(alloc_memento, allocation_site); | 4094 InitializeAllocationMemento(alloc_memento, allocation_site); |
| 4095 } | 4095 } |
| 4096 return result; | 4096 return result; |
| 4097 } | 4097 } |
| 4098 | 4098 |
| 4099 | 4099 |
| 4100 void Heap::InitializeFunction(JSFunction* function, | |
| 4101 SharedFunctionInfo* shared, | |
| 4102 Object* prototype) { | |
| 4103 ASSERT(!prototype->IsMap()); | |
| 4104 function->initialize_properties(); | |
| 4105 function->initialize_elements(); | |
| 4106 function->set_shared(shared); | |
| 4107 function->set_code(shared->code()); | |
| 4108 function->set_prototype_or_initial_map(prototype); | |
| 4109 function->set_context(undefined_value()); | |
| 4110 function->set_literals_or_bindings(empty_fixed_array()); | |
| 4111 function->set_next_function_link(undefined_value()); | |
| 4112 } | |
| 4113 | |
| 4114 | |
| 4115 MaybeObject* Heap::AllocateFunction(Map* function_map, | |
| 4116 SharedFunctionInfo* shared, | |
| 4117 Object* prototype, | |
| 4118 PretenureFlag pretenure) { | |
| 4119 AllocationSpace space = | |
| 4120 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; | |
| 4121 Object* result; | |
| 4122 { MaybeObject* maybe_result = Allocate(function_map, space); | |
| 4123 if (!maybe_result->ToObject(&result)) return maybe_result; | |
| 4124 } | |
| 4125 InitializeFunction(JSFunction::cast(result), shared, prototype); | |
| 4126 return result; | |
| 4127 } | |
| 4128 | |
| 4129 | |
| 4130 MaybeObject* Heap::AllocateArgumentsObject(Object* callee, int length) { | 4100 MaybeObject* Heap::AllocateArgumentsObject(Object* callee, int length) { |
| 4131 // To get fast allocation and map sharing for arguments objects we | 4101 // To get fast allocation and map sharing for arguments objects we |
| 4132 // allocate them based on an arguments boilerplate. | 4102 // allocate them based on an arguments boilerplate. |
| 4133 | 4103 |
| 4134 JSObject* boilerplate; | 4104 JSObject* boilerplate; |
| 4135 int arguments_object_size; | 4105 int arguments_object_size; |
| 4136 bool strict_mode_callee = callee->IsJSFunction() && | 4106 bool strict_mode_callee = callee->IsJSFunction() && |
| 4137 JSFunction::cast(callee)->shared()->strict_mode() == STRICT; | 4107 JSFunction::cast(callee)->shared()->strict_mode() == STRICT; |
| 4138 if (strict_mode_callee) { | 4108 if (strict_mode_callee) { |
| 4139 boilerplate = | 4109 boilerplate = |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4399 { MaybeObject* maybe_prop = CopyFixedArray(properties); | 4369 { MaybeObject* maybe_prop = CopyFixedArray(properties); |
| 4400 if (!maybe_prop->ToObject(&prop)) return maybe_prop; | 4370 if (!maybe_prop->ToObject(&prop)) return maybe_prop; |
| 4401 } | 4371 } |
| 4402 JSObject::cast(clone)->set_properties(FixedArray::cast(prop), wb_mode); | 4372 JSObject::cast(clone)->set_properties(FixedArray::cast(prop), wb_mode); |
| 4403 } | 4373 } |
| 4404 // Return the new clone. | 4374 // Return the new clone. |
| 4405 return clone; | 4375 return clone; |
| 4406 } | 4376 } |
| 4407 | 4377 |
| 4408 | 4378 |
| 4409 MaybeObject* Heap::ReinitializeJSReceiver( | |
| 4410 JSReceiver* object, InstanceType type, int size) { | |
| 4411 ASSERT(type >= FIRST_JS_OBJECT_TYPE); | |
| 4412 | |
| 4413 // Allocate fresh map. | |
| 4414 // TODO(rossberg): Once we optimize proxies, cache these maps. | |
| 4415 Map* map; | |
| 4416 MaybeObject* maybe = AllocateMap(type, size); | |
| 4417 if (!maybe->To<Map>(&map)) return maybe; | |
| 4418 | |
| 4419 // Check that the receiver has at least the size of the fresh object. | |
| 4420 int size_difference = object->map()->instance_size() - map->instance_size(); | |
| 4421 ASSERT(size_difference >= 0); | |
| 4422 | |
| 4423 map->set_prototype(object->map()->prototype()); | |
| 4424 | |
| 4425 // Allocate the backing storage for the properties. | |
| 4426 int prop_size = map->unused_property_fields() - map->inobject_properties(); | |
| 4427 Object* properties; | |
| 4428 maybe = AllocateFixedArray(prop_size, TENURED); | |
| 4429 if (!maybe->ToObject(&properties)) return maybe; | |
| 4430 | |
| 4431 // Functions require some allocation, which might fail here. | |
| 4432 SharedFunctionInfo* shared = NULL; | |
| 4433 if (type == JS_FUNCTION_TYPE) { | |
| 4434 String* name; | |
| 4435 OneByteStringKey key(STATIC_ASCII_VECTOR("<freezing call trap>"), | |
| 4436 HashSeed()); | |
| 4437 maybe = InternalizeStringWithKey(&key); | |
| 4438 if (!maybe->To<String>(&name)) return maybe; | |
| 4439 maybe = AllocateSharedFunctionInfo(name); | |
| 4440 if (!maybe->To<SharedFunctionInfo>(&shared)) return maybe; | |
| 4441 } | |
| 4442 | |
| 4443 // Because of possible retries of this function after failure, | |
| 4444 // we must NOT fail after this point, where we have changed the type! | |
| 4445 | |
| 4446 // Reset the map for the object. | |
| 4447 object->set_map(map); | |
| 4448 JSObject* jsobj = JSObject::cast(object); | |
| 4449 | |
| 4450 // Reinitialize the object from the constructor map. | |
| 4451 InitializeJSObjectFromMap(jsobj, FixedArray::cast(properties), map); | |
| 4452 | |
| 4453 // Functions require some minimal initialization. | |
| 4454 if (type == JS_FUNCTION_TYPE) { | |
| 4455 map->set_function_with_prototype(true); | |
| 4456 InitializeFunction(JSFunction::cast(object), shared, the_hole_value()); | |
| 4457 JSFunction::cast(object)->set_context( | |
| 4458 isolate()->context()->native_context()); | |
| 4459 } | |
| 4460 | |
| 4461 // Put in filler if the new object is smaller than the old. | |
| 4462 if (size_difference > 0) { | |
| 4463 CreateFillerObjectAt( | |
| 4464 object->address() + map->instance_size(), size_difference); | |
| 4465 } | |
| 4466 | |
| 4467 return object; | |
| 4468 } | |
| 4469 | |
| 4470 | |
| 4471 MaybeObject* Heap::ReinitializeJSGlobalProxy(JSFunction* constructor, | |
| 4472 JSGlobalProxy* object) { | |
| 4473 ASSERT(constructor->has_initial_map()); | |
| 4474 Map* map = constructor->initial_map(); | |
| 4475 | |
| 4476 // Check that the already allocated object has the same size and type as | |
| 4477 // objects allocated using the constructor. | |
| 4478 ASSERT(map->instance_size() == object->map()->instance_size()); | |
| 4479 ASSERT(map->instance_type() == object->map()->instance_type()); | |
| 4480 | |
| 4481 // Allocate the backing storage for the properties. | |
| 4482 int prop_size = map->unused_property_fields() - map->inobject_properties(); | |
| 4483 Object* properties; | |
| 4484 { MaybeObject* maybe_properties = AllocateFixedArray(prop_size, TENURED); | |
| 4485 if (!maybe_properties->ToObject(&properties)) return maybe_properties; | |
| 4486 } | |
| 4487 | |
| 4488 // Reset the map for the object. | |
| 4489 object->set_map(constructor->initial_map()); | |
| 4490 | |
| 4491 // Reinitialize the object from the constructor map. | |
| 4492 InitializeJSObjectFromMap(object, FixedArray::cast(properties), map); | |
| 4493 return object; | |
| 4494 } | |
| 4495 | |
| 4496 | |
| 4497 MaybeObject* Heap::AllocateStringFromOneByte(Vector<const uint8_t> string, | 4379 MaybeObject* Heap::AllocateStringFromOneByte(Vector<const uint8_t> string, |
| 4498 PretenureFlag pretenure) { | 4380 PretenureFlag pretenure) { |
| 4499 int length = string.length(); | 4381 int length = string.length(); |
| 4500 if (length == 1) { | 4382 if (length == 1) { |
| 4501 return Heap::LookupSingleCharacterStringFromCode(string[0]); | 4383 return Heap::LookupSingleCharacterStringFromCode(string[0]); |
| 4502 } | 4384 } |
| 4503 Object* result; | 4385 Object* result; |
| 4504 { MaybeObject* maybe_result = | 4386 { MaybeObject* maybe_result = |
| 4505 AllocateRawOneByteString(string.length(), pretenure); | 4387 AllocateRawOneByteString(string.length(), pretenure); |
| 4506 if (!maybe_result->ToObject(&result)) return maybe_result; | 4388 if (!maybe_result->ToObject(&result)) return maybe_result; |
| (...skipping 2782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7289 static_cast<int>(object_sizes_last_time_[index])); | 7171 static_cast<int>(object_sizes_last_time_[index])); |
| 7290 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 7172 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 7291 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 7173 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 7292 | 7174 |
| 7293 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 7175 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
| 7294 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 7176 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
| 7295 ClearObjectStats(); | 7177 ClearObjectStats(); |
| 7296 } | 7178 } |
| 7297 | 7179 |
| 7298 } } // namespace v8::internal | 7180 } } // namespace v8::internal |
| OLD | NEW |