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

Side by Side Diff: src/global-handles.cc

Issue 1773273002: Add flag to trace object groups (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Incorporated more Ulan's wonderful suggestions Created 4 years, 9 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 | « src/global-handles.h ('k') | src/heap/heap.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 // 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/global-handles.h" 5 #include "src/global-handles.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/v8.h" 8 #include "src/v8.h"
9 #include "src/vm-state-inl.h" 9 #include "src/vm-state-inl.h"
10 10
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 804
805 // Once the entire group has been iterated over, set the object 805 // Once the entire group has been iterated over, set the object
806 // group to NULL so it won't be processed again. 806 // group to NULL so it won't be processed again.
807 delete entry; 807 delete entry;
808 object_groups_.at(i) = NULL; 808 object_groups_.at(i) = NULL;
809 } 809 }
810 object_groups_.Rewind(last); 810 object_groups_.Rewind(last);
811 return any_group_was_visited; 811 return any_group_was_visited;
812 } 812 }
813 813
814 namespace {
815 // Traces the information about object groups and implicit ref groups given by
816 // the embedder to the V8 during each gc prologue.
817 class ObjectGroupsTracer {
818 public:
819 explicit ObjectGroupsTracer(Isolate* isolate);
820 void Print();
821
822 private:
823 void PrintObjectGroup(ObjectGroup* group);
824 void PrintImplicitRefGroup(ImplicitRefGroup* group);
825 void PrintObject(Object* object);
826 void PrintConstructor(JSObject* js_object);
827 void PrintInternalFields(JSObject* js_object);
828 Isolate* isolate_;
829 DISALLOW_COPY_AND_ASSIGN(ObjectGroupsTracer);
830 };
831
832 ObjectGroupsTracer::ObjectGroupsTracer(Isolate* isolate) : isolate_(isolate) {}
833
834 void ObjectGroupsTracer::Print() {
835 GlobalHandles* global_handles = isolate_->global_handles();
836
837 PrintIsolate(isolate_, "### Tracing object groups:\n");
838
839 for (auto group : *(global_handles->object_groups())) {
840 PrintObjectGroup(group);
841 }
842 for (auto group : *(global_handles->implicit_ref_groups())) {
843 PrintImplicitRefGroup(group);
844 }
845
846 PrintIsolate(isolate_, "### Tracing object groups finished.\n");
847 }
848
849 void ObjectGroupsTracer::PrintObject(Object* object) {
850 if (object->IsJSObject()) {
851 JSObject* js_object = JSObject::cast(object);
852
853 PrintF("{ constructor_name: ");
854 PrintConstructor(js_object);
855 PrintF(", hidden_fields: [ ");
856 PrintInternalFields(js_object);
857 PrintF(" ] }\n");
858 } else {
859 PrintF("object of unexpected type: %p\n", object);
860 }
861 }
862
863 void ObjectGroupsTracer::PrintConstructor(JSObject* js_object) {
864 Object* maybe_constructor = js_object->map()->GetConstructor();
865 if (maybe_constructor->IsJSFunction()) {
866 JSFunction* constructor = JSFunction::cast(maybe_constructor);
867 String* name = String::cast(constructor->shared()->name());
868 if (name->length() == 0) name = constructor->shared()->inferred_name();
869
870 PrintF("%s", name->ToCString().get());
871 } else if (maybe_constructor->IsNull()) {
872 if (js_object->IsOddball()) {
873 PrintF("<oddball>");
874 } else {
875 PrintF("<null>");
876 }
877 } else {
878 UNREACHABLE();
879 }
880 }
881
882 void ObjectGroupsTracer::PrintInternalFields(JSObject* js_object) {
883 for (int i = 0; i < js_object->GetInternalFieldCount(); ++i) {
884 if (i != 0) {
885 PrintF(", ");
886 }
887 PrintF("%p", js_object->GetInternalField(i));
888 }
889 }
890
891 void ObjectGroupsTracer::PrintObjectGroup(ObjectGroup* group) {
892 PrintIsolate(isolate_, "ObjectGroup (size: %lu)\n", group->length);
893 Object*** objects = group->objects;
894
895 for (size_t i = 0; i < group->length; ++i) {
896 PrintIsolate(isolate_, " - Member: ");
897 PrintObject(*objects[i]);
898 }
899 }
900
901 void ObjectGroupsTracer::PrintImplicitRefGroup(ImplicitRefGroup* group) {
902 PrintIsolate(isolate_, "ImplicitRefGroup (children count: %lu)\n",
903 group->length);
904 PrintIsolate(isolate_, " - Parent: ");
905 PrintObject(*(group->parent));
906
907 Object*** children = group->children;
908 for (size_t i = 0; i < group->length; ++i) {
909 PrintIsolate(isolate_, " - Child: ");
910 PrintObject(*children[i]);
911 }
912 }
913
914 } // namespace
915
916 void GlobalHandles::PrintObjectGroups() {
917 ObjectGroupsTracer(isolate_).Print();
918 }
814 919
815 void GlobalHandles::InvokeSecondPassPhantomCallbacks( 920 void GlobalHandles::InvokeSecondPassPhantomCallbacks(
816 List<PendingPhantomCallback>* callbacks, Isolate* isolate) { 921 List<PendingPhantomCallback>* callbacks, Isolate* isolate) {
817 while (callbacks->length() != 0) { 922 while (callbacks->length() != 0) {
818 auto callback = callbacks->RemoveLast(); 923 auto callback = callbacks->RemoveLast();
819 DCHECK(callback.node() == nullptr); 924 DCHECK(callback.node() == nullptr);
820 // Fire second pass callback 925 // Fire second pass callback
821 callback.Invoke(isolate); 926 callback.Invoke(isolate);
822 } 927 }
823 } 928 }
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 blocks_[block][offset] = object; 1482 blocks_[block][offset] = object;
1378 if (isolate->heap()->InNewSpace(object)) { 1483 if (isolate->heap()->InNewSpace(object)) {
1379 new_space_indices_.Add(size_); 1484 new_space_indices_.Add(size_);
1380 } 1485 }
1381 *index = size_++; 1486 *index = size_++;
1382 } 1487 }
1383 1488
1384 1489
1385 } // namespace internal 1490 } // namespace internal
1386 } // namespace v8 1491 } // namespace v8
OLDNEW
« no previous file with comments | « src/global-handles.h ('k') | src/heap/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698