OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/disasm.h" | 7 #include "src/disasm.h" |
8 #include "src/disassembler.h" | 8 #include "src/disassembler.h" |
9 #include "src/heap/objects-visiting.h" | 9 #include "src/heap/objects-visiting.h" |
10 #include "src/jsregexp.h" | 10 #include "src/jsregexp.h" |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 os << " " << (i - 2) << ":" << Brief(p->get(i)); | 339 os << " " << (i - 2) << ":" << Brief(p->get(i)); |
340 } | 340 } |
341 os << "\n context: " << Brief(p->get(0)) | 341 os << "\n context: " << Brief(p->get(0)) |
342 << "\n arguments: " << Brief(p->get(1)) << "\n"; | 342 << "\n arguments: " << Brief(p->get(1)) << "\n"; |
343 break; | 343 break; |
344 } | 344 } |
345 } | 345 } |
346 } | 346 } |
347 | 347 |
348 | 348 |
349 void JSObject::PrintTransitions(std::ostream& os) { // NOLINT | |
350 if (!map()->HasTransitionArray()) return; | |
351 map()->transitions()->PrintTransitions(os, false); | |
352 } | |
353 | |
354 | |
355 void JSObject::JSObjectPrint(std::ostream& os) { // NOLINT | 349 void JSObject::JSObjectPrint(std::ostream& os) { // NOLINT |
356 HeapObject::PrintHeader(os, "JSObject"); | 350 HeapObject::PrintHeader(os, "JSObject"); |
357 // Don't call GetElementsKind, its validation code can cause the printer to | 351 // Don't call GetElementsKind, its validation code can cause the printer to |
358 // fail when debugging. | 352 // fail when debugging. |
359 PrototypeIterator iter(GetIsolate(), this); | 353 PrototypeIterator iter(GetIsolate(), this); |
360 os << " - map = " << reinterpret_cast<void*>(map()) << " [" | 354 os << " - map = " << reinterpret_cast<void*>(map()) << " [" |
361 << ElementsKindToString(this->map()->elements_kind()) | 355 << ElementsKindToString(this->map()->elements_kind()) |
362 << "]\n - prototype = " << reinterpret_cast<void*>(iter.GetCurrent()) | 356 << "]\n - prototype = " << reinterpret_cast<void*>(iter.GetCurrent()) |
363 << "\n {\n"; | 357 << "\n {\n"; |
364 PrintProperties(os); | 358 PrintProperties(os); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 if (IsString()) { | 579 if (IsString()) { |
586 String::cast(this)->StringPrint(os); | 580 String::cast(this)->StringPrint(os); |
587 } else if (IsSymbol()) { | 581 } else if (IsSymbol()) { |
588 Symbol::cast(this)->name()->Print(os); | 582 Symbol::cast(this)->name()->Print(os); |
589 } else { | 583 } else { |
590 os << Brief(this); | 584 os << Brief(this); |
591 } | 585 } |
592 } | 586 } |
593 | 587 |
594 | 588 |
595 // This method is only meant to be called from gdb for debugging purposes. | |
596 // Since the string can also be in two-byte encoding, non-Latin1 characters | |
597 // will be ignored in the output. | |
598 char* String::ToAsciiArray() { | |
599 // Static so that subsequent calls frees previously allocated space. | |
600 // This also means that previous results will be overwritten. | |
601 static char* buffer = NULL; | |
602 if (buffer != NULL) delete[] buffer; | |
603 buffer = new char[length()+1]; | |
604 WriteToFlat(this, reinterpret_cast<uint8_t*>(buffer), 0, length()); | |
605 buffer[length()] = 0; | |
606 return buffer; | |
607 } | |
608 | |
609 | |
610 static const char* const weekdays[] = { | 589 static const char* const weekdays[] = { |
611 "???", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" | 590 "???", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" |
612 }; | 591 }; |
613 | 592 |
614 | 593 |
615 void JSDate::JSDatePrint(std::ostream& os) { // NOLINT | 594 void JSDate::JSDatePrint(std::ostream& os) { // NOLINT |
616 HeapObject::PrintHeader(os, "JSDate"); | 595 HeapObject::PrintHeader(os, "JSDate"); |
617 os << " - map = " << reinterpret_cast<void*>(map()) << "\n"; | 596 os << " - map = " << reinterpret_cast<void*>(map()) << "\n"; |
618 os << " - value = "; | 597 os << " - value = "; |
619 value()->Print(os); | 598 value()->Print(os); |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 void BreakPointInfo::BreakPointInfoPrint(std::ostream& os) { // NOLINT | 1039 void BreakPointInfo::BreakPointInfoPrint(std::ostream& os) { // NOLINT |
1061 HeapObject::PrintHeader(os, "BreakPointInfo"); | 1040 HeapObject::PrintHeader(os, "BreakPointInfo"); |
1062 os << "\n - code_position: " << code_position()->value(); | 1041 os << "\n - code_position: " << code_position()->value(); |
1063 os << "\n - source_position: " << source_position()->value(); | 1042 os << "\n - source_position: " << source_position()->value(); |
1064 os << "\n - statement_position: " << statement_position()->value(); | 1043 os << "\n - statement_position: " << statement_position()->value(); |
1065 os << "\n - break_point_objects: " << Brief(break_point_objects()); | 1044 os << "\n - break_point_objects: " << Brief(break_point_objects()); |
1066 os << "\n"; | 1045 os << "\n"; |
1067 } | 1046 } |
1068 | 1047 |
1069 | 1048 |
1070 void DescriptorArray::Print() { | |
1071 OFStream os(stdout); | |
1072 this->PrintDescriptors(os); | |
1073 os << std::flush; | |
1074 } | |
1075 | |
1076 | |
1077 void DescriptorArray::PrintDescriptors(std::ostream& os) { // NOLINT | |
1078 HandleScope scope(GetIsolate()); | |
1079 os << "Descriptor array " << number_of_descriptors() << "\n"; | |
1080 for (int i = 0; i < number_of_descriptors(); i++) { | |
1081 Descriptor desc; | |
1082 Get(i, &desc); | |
1083 os << " " << i << ": " << desc << "\n"; | |
1084 } | |
1085 os << "\n"; | |
1086 } | |
1087 | |
1088 | |
1089 static void PrintBitMask(std::ostream& os, uint32_t value) { // NOLINT | 1049 static void PrintBitMask(std::ostream& os, uint32_t value) { // NOLINT |
1090 for (int i = 0; i < 32; i++) { | 1050 for (int i = 0; i < 32; i++) { |
1091 if ((i & 7) == 0) os << " "; | 1051 if ((i & 7) == 0) os << " "; |
1092 os << (((value & 1) == 0) ? "_" : "x"); | 1052 os << (((value & 1) == 0) ? "_" : "x"); |
1093 value >>= 1; | 1053 value >>= 1; |
1094 } | 1054 } |
1095 } | 1055 } |
1096 | 1056 |
1097 | 1057 |
1098 void LayoutDescriptor::Print() { | 1058 void LayoutDescriptor::Print() { |
(...skipping 17 matching lines...) Expand all Loading... |
1116 int len = length(); | 1076 int len = length(); |
1117 for (int i = 0; i < len; i++) { | 1077 for (int i = 0; i < len; i++) { |
1118 if (i > 0) os << " |"; | 1078 if (i > 0) os << " |"; |
1119 PrintBitMask(os, get_scalar(i)); | 1079 PrintBitMask(os, get_scalar(i)); |
1120 } | 1080 } |
1121 } | 1081 } |
1122 os << "\n"; | 1082 os << "\n"; |
1123 } | 1083 } |
1124 | 1084 |
1125 | 1085 |
| 1086 #endif // OBJECT_PRINT |
| 1087 |
| 1088 |
| 1089 #if TRACE_MAPS |
| 1090 |
| 1091 |
| 1092 void Name::NameShortPrint() { |
| 1093 if (this->IsString()) { |
| 1094 PrintF("%s", String::cast(this)->ToCString().get()); |
| 1095 } else { |
| 1096 DCHECK(this->IsSymbol()); |
| 1097 Symbol* s = Symbol::cast(this); |
| 1098 if (s->name()->IsUndefined()) { |
| 1099 PrintF("#<%s>", s->PrivateSymbolToName()); |
| 1100 } else { |
| 1101 PrintF("<%s>", String::cast(s->name())->ToCString().get()); |
| 1102 } |
| 1103 } |
| 1104 } |
| 1105 |
| 1106 |
| 1107 int Name::NameShortPrint(Vector<char> str) { |
| 1108 if (this->IsString()) { |
| 1109 return SNPrintF(str, "%s", String::cast(this)->ToCString().get()); |
| 1110 } else { |
| 1111 DCHECK(this->IsSymbol()); |
| 1112 Symbol* s = Symbol::cast(this); |
| 1113 if (s->name()->IsUndefined()) { |
| 1114 return SNPrintF(str, "#<%s>", s->PrivateSymbolToName()); |
| 1115 } else { |
| 1116 return SNPrintF(str, "<%s>", String::cast(s->name())->ToCString().get()); |
| 1117 } |
| 1118 } |
| 1119 } |
| 1120 |
| 1121 |
| 1122 #endif // TRACE_MAPS |
| 1123 |
| 1124 |
| 1125 #ifdef DEBUG |
| 1126 // This method is only meant to be called from gdb for debugging purposes. |
| 1127 // Since the string can also be in two-byte encoding, non-Latin1 characters |
| 1128 // will be ignored in the output. |
| 1129 char* String::ToAsciiArray() { |
| 1130 // Static so that subsequent calls frees previously allocated space. |
| 1131 // This also means that previous results will be overwritten. |
| 1132 static char* buffer = NULL; |
| 1133 if (buffer != NULL) delete[] buffer; |
| 1134 buffer = new char[length() + 1]; |
| 1135 WriteToFlat(this, reinterpret_cast<uint8_t*>(buffer), 0, length()); |
| 1136 buffer[length()] = 0; |
| 1137 return buffer; |
| 1138 } |
| 1139 |
| 1140 |
| 1141 void DescriptorArray::Print() { |
| 1142 OFStream os(stdout); |
| 1143 this->PrintDescriptors(os); |
| 1144 os << std::flush; |
| 1145 } |
| 1146 |
| 1147 |
| 1148 void DescriptorArray::PrintDescriptors(std::ostream& os) { // NOLINT |
| 1149 HandleScope scope(GetIsolate()); |
| 1150 os << "Descriptor array " << number_of_descriptors() << "\n"; |
| 1151 for (int i = 0; i < number_of_descriptors(); i++) { |
| 1152 Descriptor desc; |
| 1153 Get(i, &desc); |
| 1154 os << " " << i << ": " << desc << "\n"; |
| 1155 } |
| 1156 os << "\n"; |
| 1157 } |
| 1158 |
| 1159 |
1126 void TransitionArray::Print() { | 1160 void TransitionArray::Print() { |
1127 OFStream os(stdout); | 1161 OFStream os(stdout); |
1128 this->PrintTransitions(os); | 1162 this->PrintTransitions(os); |
1129 os << std::flush; | 1163 os << std::flush; |
1130 } | 1164 } |
1131 | 1165 |
1132 | 1166 |
1133 void TransitionArray::PrintTransitions(std::ostream& os, | 1167 void TransitionArray::PrintTransitions(std::ostream& os, |
1134 bool print_header) { // NOLINT | 1168 bool print_header) { // NOLINT |
1135 if (print_header) { | 1169 if (print_header) { |
1136 os << "Transition array " << number_of_transitions() << "\n"; | 1170 os << "Transition array " << number_of_transitions() << "\n"; |
1137 } | 1171 } |
1138 for (int i = 0; i < number_of_transitions(); i++) { | 1172 for (int i = 0; i < number_of_transitions(); i++) { |
1139 Name* key = GetKey(i); | 1173 Name* key = GetKey(i); |
1140 os << " "; | 1174 os << " "; |
| 1175 #ifdef OBJECT_PRINT |
1141 key->NamePrint(os); | 1176 key->NamePrint(os); |
| 1177 #else |
| 1178 key->ShortPrint(os); |
| 1179 #endif |
1142 os << ": "; | 1180 os << ": "; |
1143 if (key == GetHeap()->frozen_symbol()) { | 1181 if (key == GetHeap()->frozen_symbol()) { |
1144 os << " (transition to frozen)"; | 1182 os << " (transition to frozen)"; |
1145 } else if (key == GetHeap()->elements_transition_symbol()) { | 1183 } else if (key == GetHeap()->elements_transition_symbol()) { |
1146 os << " (transition to " | 1184 os << " (transition to " |
1147 << ElementsKindToString(GetTarget(i)->elements_kind()) << ")"; | 1185 << ElementsKindToString(GetTarget(i)->elements_kind()) << ")"; |
1148 } else if (key == GetHeap()->observed_symbol()) { | 1186 } else if (key == GetHeap()->observed_symbol()) { |
1149 os << " (transition to Object.observe)"; | 1187 os << " (transition to Object.observe)"; |
1150 } else { | 1188 } else { |
1151 PropertyDetails details = GetTargetDetails(i); | 1189 PropertyDetails details = GetTargetDetails(i); |
1152 switch (details.type()) { | 1190 switch (details.type()) { |
1153 case FIELD: { | 1191 case FIELD: { |
1154 os << " (transition to field)"; | 1192 os << " (transition to field)"; |
1155 break; | 1193 break; |
1156 } | 1194 } |
1157 case CONSTANT: | 1195 case CONSTANT: |
1158 os << " (transition to constant " << Brief(GetTargetValue(i)) << ")"; | 1196 os << " (transition to constant " << Brief(GetTargetValue(i)) << ")"; |
1159 break; | 1197 break; |
1160 case CALLBACKS: | 1198 case CALLBACKS: |
1161 os << " (transition to callback " << Brief(GetTargetValue(i)) << ")"; | 1199 os << " (transition to callback " << Brief(GetTargetValue(i)) << ")"; |
1162 break; | 1200 break; |
1163 } | 1201 } |
1164 os << ", attrs: " << details.attributes(); | 1202 os << ", attrs: " << details.attributes(); |
1165 } | 1203 } |
1166 os << " -> " << Brief(GetTarget(i)) << "\n"; | 1204 os << " -> " << Brief(GetTarget(i)) << "\n"; |
1167 } | 1205 } |
1168 } | 1206 } |
1169 | 1207 |
1170 | 1208 |
1171 #endif // OBJECT_PRINT | 1209 void JSObject::PrintTransitions(std::ostream& os) { // NOLINT |
1172 | 1210 if (!map()->HasTransitionArray()) return; |
1173 | 1211 map()->transitions()->PrintTransitions(os, false); |
1174 #if TRACE_MAPS | |
1175 | |
1176 | |
1177 void Name::NameShortPrint() { | |
1178 if (this->IsString()) { | |
1179 PrintF("%s", String::cast(this)->ToCString().get()); | |
1180 } else { | |
1181 DCHECK(this->IsSymbol()); | |
1182 Symbol* s = Symbol::cast(this); | |
1183 if (s->name()->IsUndefined()) { | |
1184 PrintF("#<%s>", s->PrivateSymbolToName()); | |
1185 } else { | |
1186 PrintF("<%s>", String::cast(s->name())->ToCString().get()); | |
1187 } | |
1188 } | |
1189 } | 1212 } |
1190 | 1213 #endif // DEBUG |
1191 | |
1192 int Name::NameShortPrint(Vector<char> str) { | |
1193 if (this->IsString()) { | |
1194 return SNPrintF(str, "%s", String::cast(this)->ToCString().get()); | |
1195 } else { | |
1196 DCHECK(this->IsSymbol()); | |
1197 Symbol* s = Symbol::cast(this); | |
1198 if (s->name()->IsUndefined()) { | |
1199 return SNPrintF(str, "#<%s>", s->PrivateSymbolToName()); | |
1200 } else { | |
1201 return SNPrintF(str, "<%s>", String::cast(s->name())->ToCString().get()); | |
1202 } | |
1203 } | |
1204 } | |
1205 | |
1206 | |
1207 #endif // TRACE_MAPS | |
1208 } } // namespace v8::internal | 1214 } } // namespace v8::internal |
OLD | NEW |