| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/api.h" | 8 #include "src/api.h" |
| 9 #include "src/base/once.h" | 9 #include "src/base/once.h" |
| 10 #include "src/base/utils/random-number-generator.h" | 10 #include "src/base/utils/random-number-generator.h" |
| (...skipping 3531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3542 result->set_map_no_write_barrier(map); | 3542 result->set_map_no_write_barrier(map); |
| 3543 if (allocation_site != NULL) { | 3543 if (allocation_site != NULL) { |
| 3544 AllocationMemento* alloc_memento = reinterpret_cast<AllocationMemento*>( | 3544 AllocationMemento* alloc_memento = reinterpret_cast<AllocationMemento*>( |
| 3545 reinterpret_cast<Address>(result) + map->instance_size()); | 3545 reinterpret_cast<Address>(result) + map->instance_size()); |
| 3546 InitializeAllocationMemento(alloc_memento, allocation_site); | 3546 InitializeAllocationMemento(alloc_memento, allocation_site); |
| 3547 } | 3547 } |
| 3548 return result; | 3548 return result; |
| 3549 } | 3549 } |
| 3550 | 3550 |
| 3551 | 3551 |
| 3552 AllocationResult Heap::AllocateArgumentsObject(Object* callee, int length) { | |
| 3553 // To get fast allocation and map sharing for arguments objects we | |
| 3554 // allocate them based on an arguments boilerplate. | |
| 3555 | |
| 3556 JSObject* boilerplate; | |
| 3557 int arguments_object_size; | |
| 3558 bool strict_mode_callee = callee->IsJSFunction() && | |
| 3559 JSFunction::cast(callee)->shared()->strict_mode() == STRICT; | |
| 3560 if (strict_mode_callee) { | |
| 3561 boilerplate = | |
| 3562 isolate()->context()->native_context()->strict_arguments_boilerplate(); | |
| 3563 arguments_object_size = kStrictArgumentsObjectSize; | |
| 3564 } else { | |
| 3565 boilerplate = | |
| 3566 isolate()->context()->native_context()->sloppy_arguments_boilerplate(); | |
| 3567 arguments_object_size = kSloppyArgumentsObjectSize; | |
| 3568 } | |
| 3569 | |
| 3570 // Check that the size of the boilerplate matches our | |
| 3571 // expectations. The ArgumentsAccessStub::GenerateNewObject relies | |
| 3572 // on the size being a known constant. | |
| 3573 ASSERT(arguments_object_size == boilerplate->map()->instance_size()); | |
| 3574 | |
| 3575 // Do the allocation. | |
| 3576 HeapObject* result; | |
| 3577 { AllocationResult allocation = | |
| 3578 AllocateRaw(arguments_object_size, NEW_SPACE, OLD_POINTER_SPACE); | |
| 3579 if (!allocation.To(&result)) return allocation; | |
| 3580 } | |
| 3581 | |
| 3582 // Copy the content. The arguments boilerplate doesn't have any | |
| 3583 // fields that point to new space so it's safe to skip the write | |
| 3584 // barrier here. | |
| 3585 CopyBlock(result->address(), boilerplate->address(), JSObject::kHeaderSize); | |
| 3586 | |
| 3587 // Set the length property. | |
| 3588 JSObject* js_obj = JSObject::cast(result); | |
| 3589 js_obj->InObjectPropertyAtPut( | |
| 3590 kArgumentsLengthIndex, Smi::FromInt(length), SKIP_WRITE_BARRIER); | |
| 3591 // Set the callee property for sloppy mode arguments object only. | |
| 3592 if (!strict_mode_callee) { | |
| 3593 js_obj->InObjectPropertyAtPut(kArgumentsCalleeIndex, callee); | |
| 3594 } | |
| 3595 | |
| 3596 // Check the state of the object | |
| 3597 ASSERT(js_obj->HasFastProperties()); | |
| 3598 ASSERT(js_obj->HasFastObjectElements()); | |
| 3599 | |
| 3600 return js_obj; | |
| 3601 } | |
| 3602 | |
| 3603 | |
| 3604 void Heap::InitializeJSObjectFromMap(JSObject* obj, | 3552 void Heap::InitializeJSObjectFromMap(JSObject* obj, |
| 3605 FixedArray* properties, | 3553 FixedArray* properties, |
| 3606 Map* map) { | 3554 Map* map) { |
| 3607 obj->set_properties(properties); | 3555 obj->set_properties(properties); |
| 3608 obj->initialize_elements(); | 3556 obj->initialize_elements(); |
| 3609 // TODO(1240798): Initialize the object's body using valid initial values | 3557 // TODO(1240798): Initialize the object's body using valid initial values |
| 3610 // according to the object's initial map. For example, if the map's | 3558 // according to the object's initial map. For example, if the map's |
| 3611 // instance type is JS_ARRAY_TYPE, the length field should be initialized | 3559 // instance type is JS_ARRAY_TYPE, the length field should be initialized |
| 3612 // to a number (e.g. Smi::FromInt(0)) and the elements initialized to a | 3560 // to a number (e.g. Smi::FromInt(0)) and the elements initialized to a |
| 3613 // fixed array (e.g. Heap::empty_fixed_array()). Currently, the object | 3561 // fixed array (e.g. Heap::empty_fixed_array()). Currently, the object |
| (...skipping 2829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6443 static_cast<int>(object_sizes_last_time_[index])); | 6391 static_cast<int>(object_sizes_last_time_[index])); |
| 6444 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 6392 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 6445 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 6393 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 6446 | 6394 |
| 6447 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 6395 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
| 6448 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 6396 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
| 6449 ClearObjectStats(); | 6397 ClearObjectStats(); |
| 6450 } | 6398 } |
| 6451 | 6399 |
| 6452 } } // namespace v8::internal | 6400 } } // namespace v8::internal |
| OLD | NEW |