Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(668)

Side by Side Diff: src/heap.cc

Issue 202018: Heap profiler: account primitive string objects as being constructed using 'String'. (Closed)
Patch Set: Fixed comments Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/log.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 3531 matching lines...) Expand 10 before | Expand all | Expand 10 after
3542 #ifdef ENABLE_LOGGING_AND_PROFILING 3542 #ifdef ENABLE_LOGGING_AND_PROFILING
3543 namespace { 3543 namespace {
3544 3544
3545 // JSConstructorProfile is responsible for gathering and logging 3545 // JSConstructorProfile is responsible for gathering and logging
3546 // "constructor profile" of JS object allocated on heap. 3546 // "constructor profile" of JS object allocated on heap.
3547 // It is run during garbage collection cycle, thus it doesn't need 3547 // It is run during garbage collection cycle, thus it doesn't need
3548 // to use handles. 3548 // to use handles.
3549 class JSConstructorProfile BASE_EMBEDDED { 3549 class JSConstructorProfile BASE_EMBEDDED {
3550 public: 3550 public:
3551 JSConstructorProfile() : zscope_(DELETE_ON_EXIT) {} 3551 JSConstructorProfile() : zscope_(DELETE_ON_EXIT) {}
3552 void CollectStats(JSObject* obj); 3552 void CollectStats(HeapObject* obj);
3553 void PrintStats(); 3553 void PrintStats();
3554 // Used by ZoneSplayTree::ForEach. 3554 // Used by ZoneSplayTree::ForEach.
3555 void Call(String* name, const NumberAndSizeInfo& number_and_size); 3555 void Call(String* name, const NumberAndSizeInfo& number_and_size);
3556 private: 3556 private:
3557 struct TreeConfig { 3557 struct TreeConfig {
3558 typedef String* Key; 3558 typedef String* Key;
3559 typedef NumberAndSizeInfo Value; 3559 typedef NumberAndSizeInfo Value;
3560 static const Key kNoKey; 3560 static const Key kNoKey;
3561 static const Value kNoValue; 3561 static const Value kNoValue;
3562 // Strings are unique, so it is sufficient to compare their pointers. 3562 // Strings are unique, so it is sufficient to compare their pointers.
(...skipping 24 matching lines...) Expand all
3587 } 3587 }
3588 if (FixedArray::cast(obj->elements())->length() != 0) { 3588 if (FixedArray::cast(obj->elements())->length() != 0) {
3589 size += obj->elements()->Size(); 3589 size += obj->elements()->Size();
3590 } 3590 }
3591 return size; 3591 return size;
3592 } 3592 }
3593 3593
3594 3594
3595 void JSConstructorProfile::Call(String* name, 3595 void JSConstructorProfile::Call(String* name,
3596 const NumberAndSizeInfo& number_and_size) { 3596 const NumberAndSizeInfo& number_and_size) {
3597 SmartPointer<char> s_name; 3597 ASSERT(name != NULL);
3598 if (name != NULL) { 3598 SmartPointer<char> s_name(
3599 s_name = name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 3599 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL));
3600 }
3601 LOG(HeapSampleJSConstructorEvent(*s_name, 3600 LOG(HeapSampleJSConstructorEvent(*s_name,
3602 number_and_size.number(), 3601 number_and_size.number(),
3603 number_and_size.bytes())); 3602 number_and_size.bytes()));
3604 } 3603 }
3605 3604
3606 3605
3607 void JSConstructorProfile::CollectStats(JSObject* obj) { 3606 void JSConstructorProfile::CollectStats(HeapObject* obj) {
3608 String* constructor_func = NULL; 3607 String* constructor = NULL;
3609 if (obj->map()->constructor()->IsJSFunction()) { 3608 int size;
3610 JSFunction* constructor = JSFunction::cast(obj->map()->constructor()); 3609 if (obj->IsString()) {
3611 SharedFunctionInfo* sfi = constructor->shared(); 3610 constructor = Heap::String_symbol();
3612 String* name = String::cast(sfi->name()); 3611 size = obj->Size();
3613 constructor_func = name->length() > 0 ? name : sfi->inferred_name(); 3612 } else if (obj->IsJSObject()) {
3614 } else if (obj->IsJSFunction()) { 3613 JSObject* js_obj = JSObject::cast(obj);
3615 constructor_func = Heap::function_class_symbol(); 3614 constructor = js_obj->constructor_name();
3615 size = CalculateJSObjectNetworkSize(js_obj);
3616 } else {
3617 return;
3616 } 3618 }
3619
3617 JSObjectsInfoTree::Locator loc; 3620 JSObjectsInfoTree::Locator loc;
3618 if (!js_objects_info_tree_.Find(constructor_func, &loc)) { 3621 if (!js_objects_info_tree_.Find(constructor, &loc)) {
3619 js_objects_info_tree_.Insert(constructor_func, &loc); 3622 js_objects_info_tree_.Insert(constructor, &loc);
3620 } 3623 }
3621 NumberAndSizeInfo number_and_size = loc.value(); 3624 NumberAndSizeInfo number_and_size = loc.value();
3622 number_and_size.increment_number(1); 3625 number_and_size.increment_number(1);
3623 number_and_size.increment_bytes(CalculateJSObjectNetworkSize(obj)); 3626 number_and_size.increment_bytes(size);
3624 loc.set_value(number_and_size); 3627 loc.set_value(number_and_size);
3625 } 3628 }
3626 3629
3627 3630
3628 void JSConstructorProfile::PrintStats() { 3631 void JSConstructorProfile::PrintStats() {
3629 js_objects_info_tree_.ForEach(this); 3632 js_objects_info_tree_.ForEach(this);
3630 } 3633 }
3631 3634
3632 } // namespace 3635 } // namespace
3633 #endif 3636 #endif
(...skipping 21 matching lines...) Expand all
3655 HistogramInfo info[LAST_TYPE+1]; 3658 HistogramInfo info[LAST_TYPE+1];
3656 #define DEF_TYPE_NAME(name) info[name].set_name(#name); 3659 #define DEF_TYPE_NAME(name) info[name].set_name(#name);
3657 INSTANCE_TYPE_LIST(DEF_TYPE_NAME) 3660 INSTANCE_TYPE_LIST(DEF_TYPE_NAME)
3658 #undef DEF_TYPE_NAME 3661 #undef DEF_TYPE_NAME
3659 3662
3660 JSConstructorProfile js_cons_profile; 3663 JSConstructorProfile js_cons_profile;
3661 HeapIterator iterator; 3664 HeapIterator iterator;
3662 while (iterator.has_next()) { 3665 while (iterator.has_next()) {
3663 HeapObject* obj = iterator.next(); 3666 HeapObject* obj = iterator.next();
3664 CollectStats(obj, info); 3667 CollectStats(obj, info);
3665 if (obj->IsJSObject()) { 3668 js_cons_profile.CollectStats(obj);
3666 js_cons_profile.CollectStats(JSObject::cast(obj));
3667 }
3668 } 3669 }
3669 3670
3670 // Lump all the string types together. 3671 // Lump all the string types together.
3671 int string_number = 0; 3672 int string_number = 0;
3672 int string_bytes = 0; 3673 int string_bytes = 0;
3673 #define INCREMENT_SIZE(type, size, name, camel_name) \ 3674 #define INCREMENT_SIZE(type, size, name, camel_name) \
3674 string_number += info[type].number(); \ 3675 string_number += info[type].number(); \
3675 string_bytes += info[type].bytes(); 3676 string_bytes += info[type].bytes();
3676 STRING_TYPE_LIST(INCREMENT_SIZE) 3677 STRING_TYPE_LIST(INCREMENT_SIZE)
3677 #undef INCREMENT_SIZE 3678 #undef INCREMENT_SIZE
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
3993 for (int i = 0; i < kNumberOfCaches; i++) { 3994 for (int i = 0; i < kNumberOfCaches; i++) {
3994 if (caches_[i] != NULL) { 3995 if (caches_[i] != NULL) {
3995 delete caches_[i]; 3996 delete caches_[i];
3996 caches_[i] = NULL; 3997 caches_[i] = NULL;
3997 } 3998 }
3998 } 3999 }
3999 } 4000 }
4000 4001
4001 4002
4002 } } // namespace v8::internal 4003 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698