Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 762 v->VisitPointer(node->location()); | 762 v->VisitPointer(node->location()); |
| 763 } | 763 } |
| 764 } | 764 } |
| 765 } | 765 } |
| 766 } | 766 } |
| 767 | 767 |
| 768 | 768 |
| 769 bool GlobalHandles::IterateObjectGroups(ObjectVisitor* v, | 769 bool GlobalHandles::IterateObjectGroups(ObjectVisitor* v, |
| 770 WeakSlotCallbackWithHeap can_skip) { | 770 WeakSlotCallbackWithHeap can_skip) { |
| 771 ComputeObjectGroupsAndImplicitReferences(); | 771 ComputeObjectGroupsAndImplicitReferences(); |
| 772 if (FLAG_trace_object_groups) { | |
| 773 ObjectGroupsTracer(isolate_).CollectTraces(); | |
|
ulan
2016/03/08 20:23:32
Not needed anymore.
Marcel Hlopko
2016/03/09 09:30:30
Done.
| |
| 774 } | |
| 775 | |
| 772 int last = 0; | 776 int last = 0; |
| 773 bool any_group_was_visited = false; | 777 bool any_group_was_visited = false; |
| 774 for (int i = 0; i < object_groups_.length(); i++) { | 778 for (int i = 0; i < object_groups_.length(); i++) { |
| 775 ObjectGroup* entry = object_groups_.at(i); | 779 ObjectGroup* entry = object_groups_.at(i); |
| 776 DCHECK(entry != NULL); | 780 DCHECK(entry != NULL); |
| 777 | 781 |
| 778 Object*** objects = entry->objects; | 782 Object*** objects = entry->objects; |
| 779 bool group_should_be_visited = false; | 783 bool group_should_be_visited = false; |
| 780 for (size_t j = 0; j < entry->length; j++) { | 784 for (size_t j = 0; j < entry->length; j++) { |
| 781 Object* object = *objects[j]; | 785 Object* object = *objects[j]; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 804 | 808 |
| 805 // Once the entire group has been iterated over, set the object | 809 // Once the entire group has been iterated over, set the object |
| 806 // group to NULL so it won't be processed again. | 810 // group to NULL so it won't be processed again. |
| 807 delete entry; | 811 delete entry; |
| 808 object_groups_.at(i) = NULL; | 812 object_groups_.at(i) = NULL; |
| 809 } | 813 } |
| 810 object_groups_.Rewind(last); | 814 object_groups_.Rewind(last); |
| 811 return any_group_was_visited; | 815 return any_group_was_visited; |
| 812 } | 816 } |
| 813 | 817 |
| 818 namespace { | |
| 819 // Traces the information about object groups and implicit ref groups given by | |
| 820 // the embedder to the V8 during each gc prologue. | |
| 821 class ObjectGroupsTracer { | |
| 822 public: | |
| 823 class HasDumpObject { | |
| 824 public: | |
| 825 void DumpObject(Object* object); | |
| 826 | |
| 827 private: | |
| 828 void DumpConstructor(JSObject* js_object); | |
| 829 void DumpInternalFields(JSObject* js_object); | |
| 830 }; | |
| 831 | |
| 832 class ObjectGroupVisitor : public HasDumpObject { | |
| 833 public: | |
| 834 explicit ObjectGroupVisitor(Isolate* isolate); | |
| 835 void Apply(ObjectGroup** group); | |
| 836 | |
| 837 private: | |
| 838 Isolate* isolate_; | |
| 839 }; | |
| 840 | |
| 841 class ImplicitRefGroupVisitor : public HasDumpObject { | |
| 842 public: | |
| 843 explicit ImplicitRefGroupVisitor(Isolate* isolate); | |
| 844 void Apply(ImplicitRefGroup** group); | |
| 845 | |
| 846 private: | |
| 847 Isolate* isolate_; | |
| 848 }; | |
| 849 | |
| 850 explicit ObjectGroupsTracer(Isolate* isolate); | |
| 851 void CollectTraces(); | |
| 852 | |
| 853 private: | |
| 854 Isolate* isolate_; | |
| 855 DISALLOW_COPY_AND_ASSIGN(ObjectGroupsTracer); | |
| 856 }; | |
| 857 | |
| 858 ObjectGroupsTracer::ObjectGroupsTracer(Isolate* isolate) : isolate_(isolate) {} | |
| 859 | |
| 860 void ObjectGroupsTracer::CollectTraces() { | |
| 861 GlobalHandles* global_handles = isolate_->global_handles(); | |
| 862 ObjectGroupVisitor object_groups_visitor(isolate_); | |
| 863 ImplicitRefGroupVisitor implicit_ref_groups_visitor(isolate_); | |
| 864 | |
| 865 PrintIsolate(isolate_, "### Tracing object groups:\n"); | |
| 866 | |
| 867 global_handles->object_groups()->Iterate(&object_groups_visitor); | |
| 868 global_handles->implicit_ref_groups()->Iterate(&implicit_ref_groups_visitor); | |
| 869 | |
| 870 PrintIsolate(isolate_, "### Tracing object groups finished.\n"); | |
| 871 } | |
| 872 | |
| 873 void ObjectGroupsTracer::HasDumpObject::DumpObject(Object* o) { | |
| 874 JSObject* js_object = reinterpret_cast<JSObject*>(o); | |
| 875 | |
| 876 PrintF("{ constructor_name: "); | |
| 877 DumpConstructor(js_object); | |
| 878 PrintF(", hidden_fields: [ "); | |
| 879 DumpInternalFields(js_object); | |
| 880 PrintF(" ] }\n"); | |
| 881 } | |
| 882 | |
| 883 void ObjectGroupsTracer::HasDumpObject::DumpConstructor(JSObject* js_object) { | |
| 884 Object* maybe_constructor = js_object->map()->GetConstructor(); | |
| 885 if (maybe_constructor->IsJSFunction()) { | |
| 886 JSFunction* constructor = JSFunction::cast(maybe_constructor); | |
| 887 String* name = String::cast(constructor->shared()->name()); | |
| 888 if (name->length() == 0) name = constructor->shared()->inferred_name(); | |
| 889 | |
| 890 PrintF("%s", name->ToCString().get()); | |
| 891 } else if (maybe_constructor->IsNull()) { | |
| 892 if (js_object->IsOddball()) { | |
| 893 PrintF("<oddball>"); | |
| 894 } else { | |
| 895 PrintF("<null>"); | |
| 896 } | |
| 897 } else { | |
| 898 PrintF("boo will crash\n"); | |
| 899 maybe_constructor->Print(); | |
| 900 UNREACHABLE(); | |
| 901 } | |
| 902 } | |
| 903 | |
| 904 void ObjectGroupsTracer::HasDumpObject::DumpInternalFields( | |
| 905 JSObject* js_object) { | |
| 906 if (js_object->IsOddball()) { | |
| 907 return; | |
| 908 } | |
| 909 | |
| 910 for (int i = 0; i < js_object->GetInternalFieldCount(); ++i) { | |
| 911 if (i != 0) { | |
| 912 PrintF(", "); | |
| 913 } | |
| 914 PrintF("%p", js_object->GetInternalField(i)); | |
| 915 } | |
| 916 } | |
| 917 | |
| 918 ObjectGroupsTracer::ObjectGroupVisitor::ObjectGroupVisitor(Isolate* isolate) | |
| 919 : isolate_(isolate) {} | |
| 920 | |
| 921 ObjectGroupsTracer::ImplicitRefGroupVisitor::ImplicitRefGroupVisitor( | |
| 922 Isolate* isolate) | |
| 923 : isolate_(isolate) {} | |
| 924 | |
| 925 void ObjectGroupsTracer::ObjectGroupVisitor::Apply(ObjectGroup** p) { | |
| 926 ObjectGroup* group = *p; | |
| 927 PrintIsolate(isolate_, "ObjectGroup (size: %lu)\n", group->length); | |
| 928 Object*** objects = group->objects; | |
| 929 | |
| 930 for (size_t i = 0; i < group->length; ++i) { | |
| 931 PrintIsolate(isolate_, " - Member: "); | |
| 932 DumpObject(*objects[i]); | |
| 933 } | |
| 934 } | |
| 935 | |
| 936 void ObjectGroupsTracer::ImplicitRefGroupVisitor::Apply(ImplicitRefGroup** p) { | |
| 937 ImplicitRefGroup* group = *p; | |
| 938 PrintIsolate(isolate_, "ImplicitRefGroup (children count: %lu)\n", | |
| 939 group->length); | |
| 940 PrintIsolate(isolate_, " - Parent: "); | |
| 941 DumpObject(*(group->parent)); | |
| 942 | |
| 943 Object*** children = group->children; | |
| 944 for (size_t i = 0; i < group->length; ++i) { | |
| 945 PrintIsolate(isolate_, " - Child: "); | |
| 946 DumpObject(*children[i]); | |
| 947 } | |
| 948 } | |
| 949 | |
| 950 } // namespace | |
| 951 | |
| 952 void GlobalHandles::PrintObjectGroups() { | |
| 953 ObjectGroupsTracer(isolate_).CollectTraces(); | |
| 954 } | |
| 814 | 955 |
| 815 void GlobalHandles::InvokeSecondPassPhantomCallbacks( | 956 void GlobalHandles::InvokeSecondPassPhantomCallbacks( |
| 816 List<PendingPhantomCallback>* callbacks, Isolate* isolate) { | 957 List<PendingPhantomCallback>* callbacks, Isolate* isolate) { |
| 817 while (callbacks->length() != 0) { | 958 while (callbacks->length() != 0) { |
| 818 auto callback = callbacks->RemoveLast(); | 959 auto callback = callbacks->RemoveLast(); |
| 819 DCHECK(callback.node() == nullptr); | 960 DCHECK(callback.node() == nullptr); |
| 820 // Fire second pass callback | 961 // Fire second pass callback |
| 821 callback.Invoke(isolate); | 962 callback.Invoke(isolate); |
| 822 } | 963 } |
| 823 } | 964 } |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1377 blocks_[block][offset] = object; | 1518 blocks_[block][offset] = object; |
| 1378 if (isolate->heap()->InNewSpace(object)) { | 1519 if (isolate->heap()->InNewSpace(object)) { |
| 1379 new_space_indices_.Add(size_); | 1520 new_space_indices_.Add(size_); |
| 1380 } | 1521 } |
| 1381 *index = size_++; | 1522 *index = size_++; |
| 1382 } | 1523 } |
| 1383 | 1524 |
| 1384 | 1525 |
| 1385 } // namespace internal | 1526 } // namespace internal |
| 1386 } // namespace v8 | 1527 } // namespace v8 |
| OLD | NEW |