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 3491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3537 } | 3538 } |
3538 | 3539 |
3539 | 3540 |
3540 void HeapIterator::reset() { | 3541 void HeapIterator::reset() { |
3541 // Restart the iterator. | 3542 // Restart the iterator. |
3542 Shutdown(); | 3543 Shutdown(); |
3543 Init(); | 3544 Init(); |
3544 } | 3545 } |
3545 | 3546 |
3546 | 3547 |
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 | 3548 #ifdef DEBUG |
3706 | 3549 |
3707 static bool search_for_any_global; | 3550 static bool search_for_any_global; |
3708 static Object* search_target; | 3551 static Object* search_target; |
3709 static bool found_target; | 3552 static bool found_target; |
3710 static List<Object*> object_stack(20); | 3553 static List<Object*> object_stack(20); |
3711 | 3554 |
3712 | 3555 |
3713 // Tags 0, 1, and 3 are used. Use 2 for marking visited HeapObject. | 3556 // Tags 0, 1, and 3 are used. Use 2 for marking visited HeapObject. |
3714 static const int kMarkTag = 2; | 3557 static const int kMarkTag = 2; |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3999 for (int i = 0; i < kNumberOfCaches; i++) { | 3842 for (int i = 0; i < kNumberOfCaches; i++) { |
4000 if (caches_[i] != NULL) { | 3843 if (caches_[i] != NULL) { |
4001 delete caches_[i]; | 3844 delete caches_[i]; |
4002 caches_[i] = NULL; | 3845 caches_[i] = NULL; |
4003 } | 3846 } |
4004 } | 3847 } |
4005 } | 3848 } |
4006 | 3849 |
4007 | 3850 |
4008 } } // namespace v8::internal | 3851 } } // namespace v8::internal |
OLD | NEW |