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 793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 CollectTraces(); | |
|
ulan
2016/03/09 14:37:49
Let's rename the method to Print() since that is w
Marcel Hlopko
2016/03/09 17:20:23
Done.
| |
| 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::CollectTraces() { | |
| 835 GlobalHandles* global_handles = isolate_->global_handles(); | |
| 836 | |
| 837 PrintIsolate(isolate_, "### Tracing object groups:\n"); | |
| 838 | |
| 839 List<ObjectGroup*>* object_groups = global_handles->object_groups(); | |
| 840 for (int i = 0; i < object_groups->length(); ++i) { | |
|
ulan
2016/03/09 14:37:49
We can use:
for (auto group : *object_groups) {
..
Marcel Hlopko
2016/03/09 17:20:23
Done.
| |
| 841 PrintObjectGroup(object_groups->at(i)); | |
| 842 } | |
| 843 | |
| 844 List<ImplicitRefGroup*>* implicit_ref_groups = | |
| 845 global_handles->implicit_ref_groups(); | |
| 846 for (int i = 0; i < implicit_ref_groups->length(); ++i) { | |
| 847 PrintImplicitRefGroup(implicit_ref_groups->at(i)); | |
| 848 } | |
| 849 | |
| 850 PrintIsolate(isolate_, "### Tracing object groups finished.\n"); | |
| 851 } | |
| 852 | |
| 853 void ObjectGroupsTracer::PrintObject(Object* o) { | |
|
ulan
2016/03/09 14:37:49
Let's replace "o" with more descriptive "object".
Marcel Hlopko
2016/03/09 17:20:23
Done.
| |
| 854 JSObject* js_object = reinterpret_cast<JSObject*>(o); | |
|
ulan
2016/03/09 14:37:49
if (object->IsJSObject()) {
JSObject* js_object
Marcel Hlopko
2016/03/09 17:20:23
Done.
| |
| 855 | |
| 856 PrintF("{ constructor_name: "); | |
| 857 PrintConstructor(js_object); | |
| 858 PrintF(", hidden_fields: [ "); | |
| 859 PrintInternalFields(js_object); | |
| 860 PrintF(" ] }\n"); | |
| 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 if (js_object->IsOddball()) { | |
|
ulan
2016/03/09 14:37:49
Not needed.
Marcel Hlopko
2016/03/09 17:20:23
Done.
| |
| 884 return; | |
| 885 } | |
| 886 | |
| 887 for (int i = 0; i < js_object->GetInternalFieldCount(); ++i) { | |
| 888 if (i != 0) { | |
| 889 PrintF(", "); | |
| 890 } | |
| 891 PrintF("%p", js_object->GetInternalField(i)); | |
| 892 } | |
| 893 } | |
| 894 | |
| 895 void ObjectGroupsTracer::PrintObjectGroup(ObjectGroup* group) { | |
| 896 PrintIsolate(isolate_, "ObjectGroup (size: %lu)\n", group->length); | |
| 897 Object*** objects = group->objects; | |
| 898 | |
| 899 for (size_t i = 0; i < group->length; ++i) { | |
| 900 PrintIsolate(isolate_, " - Member: "); | |
| 901 PrintObject(*objects[i]); | |
| 902 } | |
| 903 } | |
| 904 | |
| 905 void ObjectGroupsTracer::PrintImplicitRefGroup(ImplicitRefGroup* group) { | |
| 906 PrintIsolate(isolate_, "ImplicitRefGroup (children count: %lu)\n", | |
| 907 group->length); | |
| 908 PrintIsolate(isolate_, " - Parent: "); | |
| 909 PrintObject(*(group->parent)); | |
| 910 | |
| 911 Object*** children = group->children; | |
| 912 for (size_t i = 0; i < group->length; ++i) { | |
| 913 PrintIsolate(isolate_, " - Child: "); | |
| 914 PrintObject(*children[i]); | |
| 915 } | |
| 916 } | |
| 917 | |
| 918 } // namespace | |
| 919 | |
| 920 void GlobalHandles::PrintObjectGroups() { | |
| 921 ObjectGroupsTracer(isolate_).CollectTraces(); | |
| 922 } | |
| 814 | 923 |
| 815 void GlobalHandles::InvokeSecondPassPhantomCallbacks( | 924 void GlobalHandles::InvokeSecondPassPhantomCallbacks( |
| 816 List<PendingPhantomCallback>* callbacks, Isolate* isolate) { | 925 List<PendingPhantomCallback>* callbacks, Isolate* isolate) { |
| 817 while (callbacks->length() != 0) { | 926 while (callbacks->length() != 0) { |
| 818 auto callback = callbacks->RemoveLast(); | 927 auto callback = callbacks->RemoveLast(); |
| 819 DCHECK(callback.node() == nullptr); | 928 DCHECK(callback.node() == nullptr); |
| 820 // Fire second pass callback | 929 // Fire second pass callback |
| 821 callback.Invoke(isolate); | 930 callback.Invoke(isolate); |
| 822 } | 931 } |
| 823 } | 932 } |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1377 blocks_[block][offset] = object; | 1486 blocks_[block][offset] = object; |
| 1378 if (isolate->heap()->InNewSpace(object)) { | 1487 if (isolate->heap()->InNewSpace(object)) { |
| 1379 new_space_indices_.Add(size_); | 1488 new_space_indices_.Add(size_); |
| 1380 } | 1489 } |
| 1381 *index = size_++; | 1490 *index = size_++; |
| 1382 } | 1491 } |
| 1383 | 1492 |
| 1384 | 1493 |
| 1385 } // namespace internal | 1494 } // namespace internal |
| 1386 } // namespace v8 | 1495 } // namespace v8 |
| OLD | NEW |