| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 15 matching lines...) Expand all Loading... |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "accessors.h" | 30 #include "accessors.h" |
| 31 #include "api.h" | 31 #include "api.h" |
| 32 #include "bootstrapper.h" | 32 #include "bootstrapper.h" |
| 33 #include "codegen-inl.h" | 33 #include "codegen-inl.h" |
| 34 #include "compilation-cache.h" | 34 #include "compilation-cache.h" |
| 35 #include "debug.h" | 35 #include "debug.h" |
| 36 #include "heap-profiler.h" |
| 36 #include "global-handles.h" | 37 #include "global-handles.h" |
| 37 #include "mark-compact.h" | 38 #include "mark-compact.h" |
| 38 #include "natives.h" | 39 #include "natives.h" |
| 39 #include "scanner.h" | 40 #include "scanner.h" |
| 40 #include "scopeinfo.h" | 41 #include "scopeinfo.h" |
| 41 #include "v8threads.h" | 42 #include "v8threads.h" |
| 42 #if V8_TARGET_ARCH_ARM && V8_NATIVE_REGEXP | 43 #if V8_TARGET_ARCH_ARM && V8_NATIVE_REGEXP |
| 43 #include "regexp-macro-assembler.h" | 44 #include "regexp-macro-assembler.h" |
| 44 #endif | 45 #endif |
| 45 | 46 |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 }; | 630 }; |
| 630 | 631 |
| 631 | 632 |
| 632 static void VerifyNonPointerSpacePointers() { | 633 static void VerifyNonPointerSpacePointers() { |
| 633 // Verify that there are no pointers to new space in spaces where we | 634 // Verify that there are no pointers to new space in spaces where we |
| 634 // do not expect them. | 635 // do not expect them. |
| 635 VerifyNonPointerSpacePointersVisitor v; | 636 VerifyNonPointerSpacePointersVisitor v; |
| 636 HeapObjectIterator code_it(Heap::code_space()); | 637 HeapObjectIterator code_it(Heap::code_space()); |
| 637 while (code_it.has_next()) { | 638 while (code_it.has_next()) { |
| 638 HeapObject* object = code_it.next(); | 639 HeapObject* object = code_it.next(); |
| 639 if (object->IsCode()) { | 640 object->Iterate(&v); |
| 640 Code::cast(object)->ConvertICTargetsFromAddressToObject(); | |
| 641 object->Iterate(&v); | |
| 642 Code::cast(object)->ConvertICTargetsFromObjectToAddress(); | |
| 643 } else { | |
| 644 // If we find non-code objects in code space (e.g., free list | |
| 645 // nodes) we want to verify them as well. | |
| 646 object->Iterate(&v); | |
| 647 } | |
| 648 } | 641 } |
| 649 | 642 |
| 650 HeapObjectIterator data_it(Heap::old_data_space()); | 643 HeapObjectIterator data_it(Heap::old_data_space()); |
| 651 while (data_it.has_next()) data_it.next()->Iterate(&v); | 644 while (data_it.has_next()) data_it.next()->Iterate(&v); |
| 652 } | 645 } |
| 653 #endif | 646 #endif |
| 654 | 647 |
| 655 | 648 |
| 656 void Heap::Scavenge() { | 649 void Heap::Scavenge() { |
| 657 #ifdef DEBUG | 650 #ifdef DEBUG |
| (...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1927 | 1920 |
| 1928 if (result->IsFailure()) return result; | 1921 if (result->IsFailure()) return result; |
| 1929 | 1922 |
| 1930 // Initialize the object | 1923 // Initialize the object |
| 1931 HeapObject::cast(result)->set_map(code_map()); | 1924 HeapObject::cast(result)->set_map(code_map()); |
| 1932 Code* code = Code::cast(result); | 1925 Code* code = Code::cast(result); |
| 1933 code->set_instruction_size(desc.instr_size); | 1926 code->set_instruction_size(desc.instr_size); |
| 1934 code->set_relocation_size(desc.reloc_size); | 1927 code->set_relocation_size(desc.reloc_size); |
| 1935 code->set_sinfo_size(sinfo_size); | 1928 code->set_sinfo_size(sinfo_size); |
| 1936 code->set_flags(flags); | 1929 code->set_flags(flags); |
| 1937 code->set_ic_flag(Code::IC_TARGET_IS_ADDRESS); | |
| 1938 // Allow self references to created code object by patching the handle to | 1930 // Allow self references to created code object by patching the handle to |
| 1939 // point to the newly allocated Code object. | 1931 // point to the newly allocated Code object. |
| 1940 if (!self_reference.is_null()) { | 1932 if (!self_reference.is_null()) { |
| 1941 *(self_reference.location()) = code; | 1933 *(self_reference.location()) = code; |
| 1942 } | 1934 } |
| 1943 // Migrate generated code. | 1935 // Migrate generated code. |
| 1944 // The generated code can contain Object** values (typically from handles) | 1936 // The generated code can contain Object** values (typically from handles) |
| 1945 // that are dereferenced during the copy to point directly to the actual heap | 1937 // that are dereferenced during the copy to point directly to the actual heap |
| 1946 // objects. These pointers can include references to the code object itself, | 1938 // objects. These pointers can include references to the code object itself, |
| 1947 // through the self_reference parameter. | 1939 // through the self_reference parameter. |
| (...skipping 1589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3537 } | 3529 } |
| 3538 | 3530 |
| 3539 | 3531 |
| 3540 void HeapIterator::reset() { | 3532 void HeapIterator::reset() { |
| 3541 // Restart the iterator. | 3533 // Restart the iterator. |
| 3542 Shutdown(); | 3534 Shutdown(); |
| 3543 Init(); | 3535 Init(); |
| 3544 } | 3536 } |
| 3545 | 3537 |
| 3546 | 3538 |
| 3547 #ifdef ENABLE_LOGGING_AND_PROFILING | |
| 3548 namespace { | |
| 3549 | |
| 3550 // JSConstructorProfile is responsible for gathering and logging | |
| 3551 // "constructor profile" of JS object allocated on heap. | |
| 3552 // It is run during garbage collection cycle, thus it doesn't need | |
| 3553 // to use handles. | |
| 3554 class JSConstructorProfile BASE_EMBEDDED { | |
| 3555 public: | |
| 3556 JSConstructorProfile() : zscope_(DELETE_ON_EXIT) {} | |
| 3557 void CollectStats(HeapObject* obj); | |
| 3558 void PrintStats(); | |
| 3559 // Used by ZoneSplayTree::ForEach. | |
| 3560 void Call(String* name, const NumberAndSizeInfo& number_and_size); | |
| 3561 private: | |
| 3562 struct TreeConfig { | |
| 3563 typedef String* Key; | |
| 3564 typedef NumberAndSizeInfo Value; | |
| 3565 static const Key kNoKey; | |
| 3566 static const Value kNoValue; | |
| 3567 // Strings are unique, so it is sufficient to compare their pointers. | |
| 3568 static int Compare(const Key& a, const Key& b) { | |
| 3569 return a == b ? 0 : (a < b ? -1 : 1); | |
| 3570 } | |
| 3571 }; | |
| 3572 | |
| 3573 typedef ZoneSplayTree<TreeConfig> JSObjectsInfoTree; | |
| 3574 static int CalculateJSObjectNetworkSize(JSObject* obj); | |
| 3575 | |
| 3576 ZoneScope zscope_; | |
| 3577 JSObjectsInfoTree js_objects_info_tree_; | |
| 3578 }; | |
| 3579 | |
| 3580 const JSConstructorProfile::TreeConfig::Key | |
| 3581 JSConstructorProfile::TreeConfig::kNoKey = NULL; | |
| 3582 const JSConstructorProfile::TreeConfig::Value | |
| 3583 JSConstructorProfile::TreeConfig::kNoValue; | |
| 3584 | |
| 3585 | |
| 3586 int JSConstructorProfile::CalculateJSObjectNetworkSize(JSObject* obj) { | |
| 3587 int size = obj->Size(); | |
| 3588 // If 'properties' and 'elements' are non-empty (thus, non-shared), | |
| 3589 // take their size into account. | |
| 3590 if (FixedArray::cast(obj->properties())->length() != 0) { | |
| 3591 size += obj->properties()->Size(); | |
| 3592 } | |
| 3593 if (FixedArray::cast(obj->elements())->length() != 0) { | |
| 3594 size += obj->elements()->Size(); | |
| 3595 } | |
| 3596 return size; | |
| 3597 } | |
| 3598 | |
| 3599 | |
| 3600 void JSConstructorProfile::Call(String* name, | |
| 3601 const NumberAndSizeInfo& number_and_size) { | |
| 3602 ASSERT(name != NULL); | |
| 3603 SmartPointer<char> s_name( | |
| 3604 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL)); | |
| 3605 LOG(HeapSampleJSConstructorEvent(*s_name, | |
| 3606 number_and_size.number(), | |
| 3607 number_and_size.bytes())); | |
| 3608 } | |
| 3609 | |
| 3610 | |
| 3611 void JSConstructorProfile::CollectStats(HeapObject* obj) { | |
| 3612 String* constructor = NULL; | |
| 3613 int size; | |
| 3614 if (obj->IsString()) { | |
| 3615 constructor = Heap::String_symbol(); | |
| 3616 size = obj->Size(); | |
| 3617 } else if (obj->IsJSObject()) { | |
| 3618 JSObject* js_obj = JSObject::cast(obj); | |
| 3619 constructor = js_obj->constructor_name(); | |
| 3620 size = CalculateJSObjectNetworkSize(js_obj); | |
| 3621 } else { | |
| 3622 return; | |
| 3623 } | |
| 3624 | |
| 3625 JSObjectsInfoTree::Locator loc; | |
| 3626 if (!js_objects_info_tree_.Find(constructor, &loc)) { | |
| 3627 js_objects_info_tree_.Insert(constructor, &loc); | |
| 3628 } | |
| 3629 NumberAndSizeInfo number_and_size = loc.value(); | |
| 3630 number_and_size.increment_number(1); | |
| 3631 number_and_size.increment_bytes(size); | |
| 3632 loc.set_value(number_and_size); | |
| 3633 } | |
| 3634 | |
| 3635 | |
| 3636 void JSConstructorProfile::PrintStats() { | |
| 3637 js_objects_info_tree_.ForEach(this); | |
| 3638 } | |
| 3639 | |
| 3640 } // namespace | |
| 3641 #endif | |
| 3642 | |
| 3643 | |
| 3644 // | |
| 3645 // HeapProfiler class implementation. | |
| 3646 // | |
| 3647 #ifdef ENABLE_LOGGING_AND_PROFILING | |
| 3648 void HeapProfiler::CollectStats(HeapObject* obj, HistogramInfo* info) { | |
| 3649 InstanceType type = obj->map()->instance_type(); | |
| 3650 ASSERT(0 <= type && type <= LAST_TYPE); | |
| 3651 info[type].increment_number(1); | |
| 3652 info[type].increment_bytes(obj->Size()); | |
| 3653 } | |
| 3654 #endif | |
| 3655 | |
| 3656 | |
| 3657 #ifdef ENABLE_LOGGING_AND_PROFILING | |
| 3658 void HeapProfiler::WriteSample() { | |
| 3659 LOG(HeapSampleBeginEvent("Heap", "allocated")); | |
| 3660 LOG(HeapSampleStats( | |
| 3661 "Heap", "allocated", Heap::Capacity(), Heap::SizeOfObjects())); | |
| 3662 | |
| 3663 HistogramInfo info[LAST_TYPE+1]; | |
| 3664 #define DEF_TYPE_NAME(name) info[name].set_name(#name); | |
| 3665 INSTANCE_TYPE_LIST(DEF_TYPE_NAME) | |
| 3666 #undef DEF_TYPE_NAME | |
| 3667 | |
| 3668 JSConstructorProfile js_cons_profile; | |
| 3669 HeapIterator iterator; | |
| 3670 while (iterator.has_next()) { | |
| 3671 HeapObject* obj = iterator.next(); | |
| 3672 CollectStats(obj, info); | |
| 3673 js_cons_profile.CollectStats(obj); | |
| 3674 } | |
| 3675 | |
| 3676 // Lump all the string types together. | |
| 3677 int string_number = 0; | |
| 3678 int string_bytes = 0; | |
| 3679 #define INCREMENT_SIZE(type, size, name, camel_name) \ | |
| 3680 string_number += info[type].number(); \ | |
| 3681 string_bytes += info[type].bytes(); | |
| 3682 STRING_TYPE_LIST(INCREMENT_SIZE) | |
| 3683 #undef INCREMENT_SIZE | |
| 3684 if (string_bytes > 0) { | |
| 3685 LOG(HeapSampleItemEvent("STRING_TYPE", string_number, string_bytes)); | |
| 3686 } | |
| 3687 | |
| 3688 for (int i = FIRST_NONSTRING_TYPE; i <= LAST_TYPE; ++i) { | |
| 3689 if (info[i].bytes() > 0) { | |
| 3690 LOG(HeapSampleItemEvent(info[i].name(), info[i].number(), | |
| 3691 info[i].bytes())); | |
| 3692 } | |
| 3693 } | |
| 3694 | |
| 3695 js_cons_profile.PrintStats(); | |
| 3696 | |
| 3697 LOG(HeapSampleEndEvent("Heap", "allocated")); | |
| 3698 } | |
| 3699 | |
| 3700 | |
| 3701 #endif | |
| 3702 | |
| 3703 | |
| 3704 | |
| 3705 #ifdef DEBUG | 3539 #ifdef DEBUG |
| 3706 | 3540 |
| 3707 static bool search_for_any_global; | 3541 static bool search_for_any_global; |
| 3708 static Object* search_target; | 3542 static Object* search_target; |
| 3709 static bool found_target; | 3543 static bool found_target; |
| 3710 static List<Object*> object_stack(20); | 3544 static List<Object*> object_stack(20); |
| 3711 | 3545 |
| 3712 | 3546 |
| 3713 // Tags 0, 1, and 3 are used. Use 2 for marking visited HeapObject. | 3547 // Tags 0, 1, and 3 are used. Use 2 for marking visited HeapObject. |
| 3714 static const int kMarkTag = 2; | 3548 static const int kMarkTag = 2; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3737 if (!map->IsHeapObject()) return; // visited before | 3571 if (!map->IsHeapObject()) return; // visited before |
| 3738 | 3572 |
| 3739 if (found_target) return; // stop if target found | 3573 if (found_target) return; // stop if target found |
| 3740 object_stack.Add(obj); | 3574 object_stack.Add(obj); |
| 3741 if ((search_for_any_global && obj->IsJSGlobalObject()) || | 3575 if ((search_for_any_global && obj->IsJSGlobalObject()) || |
| 3742 (!search_for_any_global && (obj == search_target))) { | 3576 (!search_for_any_global && (obj == search_target))) { |
| 3743 found_target = true; | 3577 found_target = true; |
| 3744 return; | 3578 return; |
| 3745 } | 3579 } |
| 3746 | 3580 |
| 3747 if (obj->IsCode()) { | |
| 3748 Code::cast(obj)->ConvertICTargetsFromAddressToObject(); | |
| 3749 } | |
| 3750 | |
| 3751 // not visited yet | 3581 // not visited yet |
| 3752 Map* map_p = reinterpret_cast<Map*>(HeapObject::cast(map)); | 3582 Map* map_p = reinterpret_cast<Map*>(HeapObject::cast(map)); |
| 3753 | 3583 |
| 3754 Address map_addr = map_p->address(); | 3584 Address map_addr = map_p->address(); |
| 3755 | 3585 |
| 3756 obj->set_map(reinterpret_cast<Map*>(map_addr + kMarkTag)); | 3586 obj->set_map(reinterpret_cast<Map*>(map_addr + kMarkTag)); |
| 3757 | 3587 |
| 3758 MarkObjectRecursively(&map); | 3588 MarkObjectRecursively(&map); |
| 3759 | 3589 |
| 3760 obj->IterateBody(map_p->instance_type(), obj->SizeFromMap(map_p), | 3590 obj->IterateBody(map_p->instance_type(), obj->SizeFromMap(map_p), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3796 | 3626 |
| 3797 HeapObject* map_p = HeapObject::FromAddress(map_addr); | 3627 HeapObject* map_p = HeapObject::FromAddress(map_addr); |
| 3798 | 3628 |
| 3799 obj->set_map(reinterpret_cast<Map*>(map_p)); | 3629 obj->set_map(reinterpret_cast<Map*>(map_p)); |
| 3800 | 3630 |
| 3801 UnmarkObjectRecursively(reinterpret_cast<Object**>(&map_p)); | 3631 UnmarkObjectRecursively(reinterpret_cast<Object**>(&map_p)); |
| 3802 | 3632 |
| 3803 obj->IterateBody(Map::cast(map_p)->instance_type(), | 3633 obj->IterateBody(Map::cast(map_p)->instance_type(), |
| 3804 obj->SizeFromMap(Map::cast(map_p)), | 3634 obj->SizeFromMap(Map::cast(map_p)), |
| 3805 &unmark_visitor); | 3635 &unmark_visitor); |
| 3806 | |
| 3807 if (obj->IsCode()) { | |
| 3808 Code::cast(obj)->ConvertICTargetsFromObjectToAddress(); | |
| 3809 } | |
| 3810 } | 3636 } |
| 3811 | 3637 |
| 3812 | 3638 |
| 3813 static void MarkRootObjectRecursively(Object** root) { | 3639 static void MarkRootObjectRecursively(Object** root) { |
| 3814 if (search_for_any_global) { | 3640 if (search_for_any_global) { |
| 3815 ASSERT(search_target == NULL); | 3641 ASSERT(search_target == NULL); |
| 3816 } else { | 3642 } else { |
| 3817 ASSERT(search_target->IsHeapObject()); | 3643 ASSERT(search_target->IsHeapObject()); |
| 3818 } | 3644 } |
| 3819 found_target = false; | 3645 found_target = false; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3999 for (int i = 0; i < kNumberOfCaches; i++) { | 3825 for (int i = 0; i < kNumberOfCaches; i++) { |
| 4000 if (caches_[i] != NULL) { | 3826 if (caches_[i] != NULL) { |
| 4001 delete caches_[i]; | 3827 delete caches_[i]; |
| 4002 caches_[i] = NULL; | 3828 caches_[i] = NULL; |
| 4003 } | 3829 } |
| 4004 } | 3830 } |
| 4005 } | 3831 } |
| 4006 | 3832 |
| 4007 | 3833 |
| 4008 } } // namespace v8::internal | 3834 } } // namespace v8::internal |
| OLD | NEW |