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 4037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4048 if (map->instance_size() > Page::kMaxNonCodeHeapObjectSize) space = LO_SPACE; | 4048 if (map->instance_size() > Page::kMaxNonCodeHeapObjectSize) space = LO_SPACE; |
4049 Object* obj; | 4049 Object* obj; |
4050 { MaybeObject* maybe_obj = Allocate(map, space); | 4050 { MaybeObject* maybe_obj = Allocate(map, space); |
4051 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 4051 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
4052 } | 4052 } |
4053 | 4053 |
4054 // Initialize the JSObject. | 4054 // Initialize the JSObject. |
4055 InitializeJSObjectFromMap(JSObject::cast(obj), | 4055 InitializeJSObjectFromMap(JSObject::cast(obj), |
4056 FixedArray::cast(properties), | 4056 FixedArray::cast(properties), |
4057 map); | 4057 map); |
4058 ASSERT(JSObject::cast(obj)->HasFastSmiOrObjectElements()); | |
4059 return obj; | 4058 return obj; |
4060 } | 4059 } |
4061 | 4060 |
4062 | 4061 |
4063 MaybeObject* Heap::AllocateJSObject(JSFunction* constructor, | 4062 MaybeObject* Heap::AllocateJSObject(JSFunction* constructor, |
4064 PretenureFlag pretenure) { | 4063 PretenureFlag pretenure) { |
4065 // Allocate the initial map if absent. | 4064 // Allocate the initial map if absent. |
4066 if (!constructor->has_initial_map()) { | 4065 if (!constructor->has_initial_map()) { |
4067 Object* initial_map; | 4066 Object* initial_map; |
4068 { MaybeObject* maybe_initial_map = AllocateInitialMap(constructor); | 4067 { MaybeObject* maybe_initial_map = AllocateInitialMap(constructor); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4113 if (!maybe_array->To(&array)) return maybe_array; | 4112 if (!maybe_array->To(&array)) return maybe_array; |
4114 | 4113 |
4115 if (capacity == 0) { | 4114 if (capacity == 0) { |
4116 array->set_length(Smi::FromInt(0)); | 4115 array->set_length(Smi::FromInt(0)); |
4117 array->set_elements(empty_fixed_array()); | 4116 array->set_elements(empty_fixed_array()); |
4118 return array; | 4117 return array; |
4119 } | 4118 } |
4120 | 4119 |
4121 FixedArrayBase* elms; | 4120 FixedArrayBase* elms; |
4122 MaybeObject* maybe_elms = NULL; | 4121 MaybeObject* maybe_elms = NULL; |
4123 if (elements_kind == FAST_DOUBLE_ELEMENTS) { | 4122 if (IsFastDoubleElementsKind(elements_kind)) { |
4124 if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) { | 4123 if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) { |
4125 maybe_elms = AllocateUninitializedFixedDoubleArray(capacity); | 4124 maybe_elms = AllocateUninitializedFixedDoubleArray(capacity); |
4126 } else { | 4125 } else { |
4127 ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); | 4126 ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); |
4128 maybe_elms = AllocateFixedDoubleArrayWithHoles(capacity); | 4127 maybe_elms = AllocateFixedDoubleArrayWithHoles(capacity); |
4129 } | 4128 } |
4130 } else { | 4129 } else { |
4131 ASSERT(IsFastSmiOrObjectElementsKind(elements_kind)); | 4130 ASSERT(IsFastSmiOrObjectElementsKind(elements_kind)); |
4132 if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) { | 4131 if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) { |
4133 maybe_elms = AllocateUninitializedFixedArray(capacity); | 4132 maybe_elms = AllocateUninitializedFixedArray(capacity); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4266 global->set_map(new_map); | 4265 global->set_map(new_map); |
4267 global->set_properties(dictionary); | 4266 global->set_properties(dictionary); |
4268 | 4267 |
4269 // Make sure result is a global object with properties in dictionary. | 4268 // Make sure result is a global object with properties in dictionary. |
4270 ASSERT(global->IsGlobalObject()); | 4269 ASSERT(global->IsGlobalObject()); |
4271 ASSERT(!global->HasFastProperties()); | 4270 ASSERT(!global->HasFastProperties()); |
4272 return global; | 4271 return global; |
4273 } | 4272 } |
4274 | 4273 |
4275 | 4274 |
4276 MaybeObject* Heap::CopyJSObject(JSObject* source) { | 4275 MaybeObject* Heap::CopyJSObject(JSObject* source, |
| 4276 AllocationOriginTrackMode mode) { |
4277 // Never used to copy functions. If functions need to be copied we | 4277 // Never used to copy functions. If functions need to be copied we |
4278 // have to be careful to clear the literals array. | 4278 // have to be careful to clear the literals array. |
4279 SLOW_ASSERT(!source->IsJSFunction()); | 4279 SLOW_ASSERT(!source->IsJSFunction()); |
4280 | 4280 |
4281 // Make the clone. | 4281 // Make the clone. |
4282 Map* map = source->map(); | 4282 Map* map = source->map(); |
4283 int object_size = map->instance_size(); | 4283 int object_size = map->instance_size(); |
4284 Object* clone; | 4284 Object* clone; |
4285 | 4285 |
4286 WriteBarrierMode wb_mode = UPDATE_WRITE_BARRIER; | 4286 WriteBarrierMode wb_mode = UPDATE_WRITE_BARRIER; |
4287 | 4287 |
4288 // If we're forced to always allocate, we use the general allocation | 4288 // If we're forced to always allocate, we use the general allocation |
4289 // functions which may leave us with an object in old space. | 4289 // functions which may leave us with an object in old space. |
4290 if (always_allocate()) { | 4290 if (always_allocate()) { |
4291 { MaybeObject* maybe_clone = | 4291 { MaybeObject* maybe_clone = |
4292 AllocateRaw(object_size, NEW_SPACE, OLD_POINTER_SPACE); | 4292 AllocateRaw(object_size, NEW_SPACE, OLD_POINTER_SPACE); |
4293 if (!maybe_clone->ToObject(&clone)) return maybe_clone; | 4293 if (!maybe_clone->ToObject(&clone)) return maybe_clone; |
4294 } | 4294 } |
| 4295 |
4295 Address clone_address = HeapObject::cast(clone)->address(); | 4296 Address clone_address = HeapObject::cast(clone)->address(); |
4296 CopyBlock(clone_address, | 4297 CopyBlock(clone_address, |
4297 source->address(), | 4298 source->address(), |
4298 object_size); | 4299 object_size); |
4299 // Update write barrier for all fields that lie beyond the header. | 4300 // Update write barrier for all fields that lie beyond the header. |
4300 RecordWrites(clone_address, | 4301 RecordWrites(clone_address, |
4301 JSObject::kHeaderSize, | 4302 JSObject::kHeaderSize, |
4302 (object_size - JSObject::kHeaderSize) / kPointerSize); | 4303 (object_size - JSObject::kHeaderSize) / kPointerSize); |
| 4304 |
| 4305 // Track allocation site information. |
| 4306 if (mode == TRACK_ALLOCATION_ORIGIN && InNewSpace(clone) && false) { |
| 4307 MaybeObject* maybe_alloc_info = |
| 4308 AllocateStruct(ALLOCATION_SITE_INFO_TYPE); |
| 4309 AllocationSiteInfo* alloc_info; |
| 4310 // If the tracking info allocation fails, just don't track the block. |
| 4311 if (maybe_alloc_info->To(&alloc_info)) { |
| 4312 alloc_info->set_map(allocation_site_info_map()); |
| 4313 alloc_info->set_payload(source); |
| 4314 } |
| 4315 } |
4303 } else { | 4316 } else { |
4304 wb_mode = SKIP_WRITE_BARRIER; | 4317 wb_mode = SKIP_WRITE_BARRIER; |
4305 { MaybeObject* maybe_clone = new_space_.AllocateRaw(object_size); | 4318 |
| 4319 int adjusted_object_size = object_size; |
| 4320 if (mode == TRACK_ALLOCATION_ORIGIN && false) { |
| 4321 adjusted_object_size += AllocationSiteInfo::kSize; |
| 4322 } |
| 4323 |
| 4324 { MaybeObject* maybe_clone = new_space_.AllocateRaw(adjusted_object_size); |
4306 if (!maybe_clone->ToObject(&clone)) return maybe_clone; | 4325 if (!maybe_clone->ToObject(&clone)) return maybe_clone; |
4307 } | 4326 } |
4308 SLOW_ASSERT(InNewSpace(clone)); | 4327 SLOW_ASSERT(InNewSpace(clone)); |
4309 // Since we know the clone is allocated in new space, we can copy | 4328 // Since we know the clone is allocated in new space, we can copy |
4310 // the contents without worrying about updating the write barrier. | 4329 // the contents without worrying about updating the write barrier. |
4311 CopyBlock(HeapObject::cast(clone)->address(), | 4330 CopyBlock(HeapObject::cast(clone)->address(), |
4312 source->address(), | 4331 source->address(), |
4313 object_size); | 4332 object_size); |
4314 } | 4333 |
| 4334 if (mode == TRACK_ALLOCATION_ORIGIN && false) { |
| 4335 AllocationSiteInfo* alloc_info = |
| 4336 reinterpret_cast<AllocationSiteInfo*>( |
| 4337 reinterpret_cast<Address>(clone) + object_size); |
| 4338 alloc_info->set_map(allocation_site_info_map()); |
| 4339 alloc_info->set_payload(source); |
| 4340 } |
| 4341 } |
4315 | 4342 |
4316 SLOW_ASSERT( | 4343 SLOW_ASSERT( |
4317 JSObject::cast(clone)->GetElementsKind() == source->GetElementsKind()); | 4344 JSObject::cast(clone)->GetElementsKind() == source->GetElementsKind()); |
4318 FixedArrayBase* elements = FixedArrayBase::cast(source->elements()); | 4345 FixedArrayBase* elements = FixedArrayBase::cast(source->elements()); |
4319 FixedArray* properties = FixedArray::cast(source->properties()); | 4346 FixedArray* properties = FixedArray::cast(source->properties()); |
4320 // Update elements if necessary. | 4347 // Update elements if necessary. |
4321 if (elements->length() > 0) { | 4348 if (elements->length() > 0) { |
4322 Object* elem; | 4349 Object* elem; |
4323 { MaybeObject* maybe_elem; | 4350 { MaybeObject* maybe_elem; |
4324 if (elements->map() == fixed_cow_array_map()) { | 4351 if (elements->map() == fixed_cow_array_map()) { |
(...skipping 3035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7360 static_cast<int>(object_sizes_last_time_[index])); | 7387 static_cast<int>(object_sizes_last_time_[index])); |
7361 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) | 7388 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) |
7362 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 7389 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
7363 | 7390 |
7364 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 7391 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
7365 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 7392 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
7366 ClearObjectStats(); | 7393 ClearObjectStats(); |
7367 } | 7394 } |
7368 | 7395 |
7369 } } // namespace v8::internal | 7396 } } // namespace v8::internal |
OLD | NEW |