OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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/profiler/heap-snapshot-generator.h" | 5 #include "src/profiler/heap-snapshot-generator.h" |
6 | 6 |
7 #include "src/code-stubs.h" | 7 #include "src/code-stubs.h" |
8 #include "src/conversions.h" | 8 #include "src/conversions.h" |
9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
10 #include "src/objects-body-descriptors.h" | 10 #include "src/objects-body-descriptors.h" |
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 | 798 |
799 HeapEntry* V8HeapExplorer::AllocateEntry(HeapThing ptr) { | 799 HeapEntry* V8HeapExplorer::AllocateEntry(HeapThing ptr) { |
800 return AddEntry(reinterpret_cast<HeapObject*>(ptr)); | 800 return AddEntry(reinterpret_cast<HeapObject*>(ptr)); |
801 } | 801 } |
802 | 802 |
803 | 803 |
804 HeapEntry* V8HeapExplorer::AddEntry(HeapObject* object) { | 804 HeapEntry* V8HeapExplorer::AddEntry(HeapObject* object) { |
805 if (object->IsJSFunction()) { | 805 if (object->IsJSFunction()) { |
806 JSFunction* func = JSFunction::cast(object); | 806 JSFunction* func = JSFunction::cast(object); |
807 SharedFunctionInfo* shared = func->shared(); | 807 SharedFunctionInfo* shared = func->shared(); |
808 const char* name = shared->bound() ? "native_bind" : | 808 const char* name = names_->GetName(String::cast(shared->name())); |
809 names_->GetName(String::cast(shared->name())); | |
810 return AddEntry(object, HeapEntry::kClosure, name); | 809 return AddEntry(object, HeapEntry::kClosure, name); |
| 810 } else if (object->IsJSBoundFunction()) { |
| 811 return AddEntry(object, HeapEntry::kClosure, "native_bind"); |
811 } else if (object->IsJSRegExp()) { | 812 } else if (object->IsJSRegExp()) { |
812 JSRegExp* re = JSRegExp::cast(object); | 813 JSRegExp* re = JSRegExp::cast(object); |
813 return AddEntry(object, | 814 return AddEntry(object, |
814 HeapEntry::kRegExp, | 815 HeapEntry::kRegExp, |
815 names_->GetName(re->Pattern())); | 816 names_->GetName(re->Pattern())); |
816 } else if (object->IsJSObject()) { | 817 } else if (object->IsJSObject()) { |
817 const char* name = names_->GetName( | 818 const char* name = names_->GetName( |
818 GetConstructorName(JSObject::cast(object))); | 819 GetConstructorName(JSObject::cast(object))); |
819 if (object->IsJSGlobalObject()) { | 820 if (object->IsJSGlobalObject()) { |
820 const char* tag = objects_tags_.GetTag(object); | 821 const char* tag = objects_tags_.GetTag(object); |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1091 int entry, JSGlobalProxy* proxy) { | 1092 int entry, JSGlobalProxy* proxy) { |
1092 SetInternalReference(proxy, entry, | 1093 SetInternalReference(proxy, entry, |
1093 "native_context", proxy->native_context(), | 1094 "native_context", proxy->native_context(), |
1094 JSGlobalProxy::kNativeContextOffset); | 1095 JSGlobalProxy::kNativeContextOffset); |
1095 } | 1096 } |
1096 | 1097 |
1097 | 1098 |
1098 void V8HeapExplorer::ExtractJSObjectReferences( | 1099 void V8HeapExplorer::ExtractJSObjectReferences( |
1099 int entry, JSObject* js_obj) { | 1100 int entry, JSObject* js_obj) { |
1100 HeapObject* obj = js_obj; | 1101 HeapObject* obj = js_obj; |
1101 ExtractClosureReferences(js_obj, entry); | |
1102 ExtractPropertyReferences(js_obj, entry); | 1102 ExtractPropertyReferences(js_obj, entry); |
1103 ExtractElementReferences(js_obj, entry); | 1103 ExtractElementReferences(js_obj, entry); |
1104 ExtractInternalReferences(js_obj, entry); | 1104 ExtractInternalReferences(js_obj, entry); |
1105 PrototypeIterator iter(heap_->isolate(), js_obj); | 1105 PrototypeIterator iter(heap_->isolate(), js_obj); |
1106 SetPropertyReference(obj, entry, heap_->proto_string(), iter.GetCurrent()); | 1106 SetPropertyReference(obj, entry, heap_->proto_string(), iter.GetCurrent()); |
1107 if (obj->IsJSFunction()) { | 1107 if (obj->IsJSBoundFunction()) { |
| 1108 JSBoundFunction* js_fun = JSBoundFunction::cast(obj); |
| 1109 TagObject(js_fun->bound_arguments(), "(bound arguments)"); |
| 1110 SetInternalReference(js_fun, entry, "bindings", js_fun->bound_arguments(), |
| 1111 JSBoundFunction::kBoundArgumentsOffset); |
| 1112 SetNativeBindReference(js_obj, entry, "bound_this", js_fun->bound_this()); |
| 1113 SetNativeBindReference(js_obj, entry, "bound_function", |
| 1114 js_fun->bound_target_function()); |
| 1115 FixedArray* bindings = js_fun->bound_arguments(); |
| 1116 for (int i = 0; i < bindings->length(); i++) { |
| 1117 const char* reference_name = names_->GetFormatted("bound_argument_%d", i); |
| 1118 SetNativeBindReference(js_obj, entry, reference_name, bindings->get(i)); |
| 1119 } |
| 1120 } else if (obj->IsJSFunction()) { |
1108 JSFunction* js_fun = JSFunction::cast(js_obj); | 1121 JSFunction* js_fun = JSFunction::cast(js_obj); |
1109 Object* proto_or_map = js_fun->prototype_or_initial_map(); | 1122 Object* proto_or_map = js_fun->prototype_or_initial_map(); |
1110 if (!proto_or_map->IsTheHole()) { | 1123 if (!proto_or_map->IsTheHole()) { |
1111 if (!proto_or_map->IsMap()) { | 1124 if (!proto_or_map->IsMap()) { |
1112 SetPropertyReference( | 1125 SetPropertyReference( |
1113 obj, entry, | 1126 obj, entry, |
1114 heap_->prototype_string(), proto_or_map, | 1127 heap_->prototype_string(), proto_or_map, |
1115 NULL, | 1128 NULL, |
1116 JSFunction::kPrototypeOrInitialMapOffset); | 1129 JSFunction::kPrototypeOrInitialMapOffset); |
1117 } else { | 1130 } else { |
1118 SetPropertyReference( | 1131 SetPropertyReference( |
1119 obj, entry, | 1132 obj, entry, |
1120 heap_->prototype_string(), js_fun->prototype()); | 1133 heap_->prototype_string(), js_fun->prototype()); |
1121 SetInternalReference( | 1134 SetInternalReference( |
1122 obj, entry, "initial_map", proto_or_map, | 1135 obj, entry, "initial_map", proto_or_map, |
1123 JSFunction::kPrototypeOrInitialMapOffset); | 1136 JSFunction::kPrototypeOrInitialMapOffset); |
1124 } | 1137 } |
1125 } | 1138 } |
1126 SharedFunctionInfo* shared_info = js_fun->shared(); | 1139 SharedFunctionInfo* shared_info = js_fun->shared(); |
1127 // JSFunction has either bindings or literals and never both. | 1140 TagObject(js_fun->literals(), "(function literals)"); |
1128 bool bound = shared_info->bound(); | 1141 SetInternalReference(js_fun, entry, "literals", js_fun->literals(), |
1129 TagObject(js_fun->literals_or_bindings(), | |
1130 bound ? "(function bindings)" : "(function literals)"); | |
1131 SetInternalReference(js_fun, entry, | |
1132 bound ? "bindings" : "literals", | |
1133 js_fun->literals_or_bindings(), | |
1134 JSFunction::kLiteralsOffset); | 1142 JSFunction::kLiteralsOffset); |
1135 TagObject(shared_info, "(shared function info)"); | 1143 TagObject(shared_info, "(shared function info)"); |
1136 SetInternalReference(js_fun, entry, | 1144 SetInternalReference(js_fun, entry, |
1137 "shared", shared_info, | 1145 "shared", shared_info, |
1138 JSFunction::kSharedFunctionInfoOffset); | 1146 JSFunction::kSharedFunctionInfoOffset); |
1139 TagObject(js_fun->context(), "(context)"); | 1147 TagObject(js_fun->context(), "(context)"); |
1140 SetInternalReference(js_fun, entry, | 1148 SetInternalReference(js_fun, entry, |
1141 "context", js_fun->context(), | 1149 "context", js_fun->context(), |
1142 JSFunction::kContextOffset); | 1150 JSFunction::kContextOffset); |
1143 SetWeakReference(js_fun, entry, | 1151 SetWeakReference(js_fun, entry, |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1568 SetWeakReference(array, entry, | 1576 SetWeakReference(array, entry, |
1569 i, array->get(i), array->OffsetOfElementAt(i)); | 1577 i, array->get(i), array->OffsetOfElementAt(i)); |
1570 } else { | 1578 } else { |
1571 SetInternalReference(array, entry, | 1579 SetInternalReference(array, entry, |
1572 i, array->get(i), array->OffsetOfElementAt(i)); | 1580 i, array->get(i), array->OffsetOfElementAt(i)); |
1573 } | 1581 } |
1574 } | 1582 } |
1575 } | 1583 } |
1576 | 1584 |
1577 | 1585 |
1578 void V8HeapExplorer::ExtractClosureReferences(JSObject* js_obj, int entry) { | |
1579 if (!js_obj->IsJSFunction()) return; | |
1580 | |
1581 JSFunction* func = JSFunction::cast(js_obj); | |
1582 if (func->shared()->bound()) { | |
1583 BindingsArray* bindings = func->function_bindings(); | |
1584 SetNativeBindReference(js_obj, entry, "bound_this", bindings->bound_this()); | |
1585 SetNativeBindReference(js_obj, entry, "bound_function", | |
1586 bindings->bound_function()); | |
1587 for (int i = 0; i < bindings->bindings_count(); i++) { | |
1588 const char* reference_name = names_->GetFormatted("bound_argument_%d", i); | |
1589 SetNativeBindReference(js_obj, entry, reference_name, | |
1590 bindings->binding(i)); | |
1591 } | |
1592 } | |
1593 } | |
1594 | |
1595 | |
1596 void V8HeapExplorer::ExtractPropertyReferences(JSObject* js_obj, int entry) { | 1586 void V8HeapExplorer::ExtractPropertyReferences(JSObject* js_obj, int entry) { |
1597 if (js_obj->HasFastProperties()) { | 1587 if (js_obj->HasFastProperties()) { |
1598 DescriptorArray* descs = js_obj->map()->instance_descriptors(); | 1588 DescriptorArray* descs = js_obj->map()->instance_descriptors(); |
1599 int real_size = js_obj->map()->NumberOfOwnDescriptors(); | 1589 int real_size = js_obj->map()->NumberOfOwnDescriptors(); |
1600 for (int i = 0; i < real_size; i++) { | 1590 for (int i = 0; i < real_size; i++) { |
1601 PropertyDetails details = descs->GetDetails(i); | 1591 PropertyDetails details = descs->GetDetails(i); |
1602 switch (details.location()) { | 1592 switch (details.location()) { |
1603 case kField: { | 1593 case kField: { |
1604 Representation r = details.representation(); | 1594 Representation r = details.representation(); |
1605 if (r.IsSmi() || r.IsDouble()) break; | 1595 if (r.IsSmi() || r.IsDouble()) break; |
(...skipping 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3167 for (int i = 1; i < sorted_strings.length(); ++i) { | 3157 for (int i = 1; i < sorted_strings.length(); ++i) { |
3168 writer_->AddCharacter(','); | 3158 writer_->AddCharacter(','); |
3169 SerializeString(sorted_strings[i]); | 3159 SerializeString(sorted_strings[i]); |
3170 if (writer_->aborted()) return; | 3160 if (writer_->aborted()) return; |
3171 } | 3161 } |
3172 } | 3162 } |
3173 | 3163 |
3174 | 3164 |
3175 } // namespace internal | 3165 } // namespace internal |
3176 } // namespace v8 | 3166 } // namespace v8 |
OLD | NEW |