OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 3335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3346 while (s < s_end) { | 3346 while (s < s_end) { |
3347 int s_chunk_size = Min( | 3347 int s_chunk_size = Min( |
3348 chunk_size_ - chunk_pos_, static_cast<int>(s_end - s)); | 3348 chunk_size_ - chunk_pos_, static_cast<int>(s_end - s)); |
3349 ASSERT(s_chunk_size > 0); | 3349 ASSERT(s_chunk_size > 0); |
3350 memcpy(chunk_.start() + chunk_pos_, s, s_chunk_size); | 3350 memcpy(chunk_.start() + chunk_pos_, s, s_chunk_size); |
3351 s += s_chunk_size; | 3351 s += s_chunk_size; |
3352 chunk_pos_ += s_chunk_size; | 3352 chunk_pos_ += s_chunk_size; |
3353 MaybeWriteChunk(); | 3353 MaybeWriteChunk(); |
3354 } | 3354 } |
3355 } | 3355 } |
3356 void AddNumber(int n) { AddNumberImpl<int>(n, "%d"); } | |
3357 void AddNumber(unsigned n) { AddNumberImpl<unsigned>(n, "%u"); } | 3356 void AddNumber(unsigned n) { AddNumberImpl<unsigned>(n, "%u"); } |
3358 void AddNumber(uint64_t n) { AddNumberImpl<uint64_t>(n, "%llu"); } | |
3359 void Finalize() { | 3357 void Finalize() { |
3360 if (aborted_) return; | 3358 if (aborted_) return; |
3361 ASSERT(chunk_pos_ < chunk_size_); | 3359 ASSERT(chunk_pos_ < chunk_size_); |
3362 if (chunk_pos_ != 0) { | 3360 if (chunk_pos_ != 0) { |
3363 WriteChunk(); | 3361 WriteChunk(); |
3364 } | 3362 } |
3365 stream_->EndOfStream(); | 3363 stream_->EndOfStream(); |
3366 } | 3364 } |
3367 | 3365 |
3368 private: | 3366 private: |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3503 int HeapSnapshotJSONSerializer::GetStringId(const char* s) { | 3501 int HeapSnapshotJSONSerializer::GetStringId(const char* s) { |
3504 HashMap::Entry* cache_entry = strings_.Lookup( | 3502 HashMap::Entry* cache_entry = strings_.Lookup( |
3505 const_cast<char*>(s), ObjectHash(s), true); | 3503 const_cast<char*>(s), ObjectHash(s), true); |
3506 if (cache_entry->value == NULL) { | 3504 if (cache_entry->value == NULL) { |
3507 cache_entry->value = reinterpret_cast<void*>(next_string_id_++); | 3505 cache_entry->value = reinterpret_cast<void*>(next_string_id_++); |
3508 } | 3506 } |
3509 return static_cast<int>(reinterpret_cast<intptr_t>(cache_entry->value)); | 3507 return static_cast<int>(reinterpret_cast<intptr_t>(cache_entry->value)); |
3510 } | 3508 } |
3511 | 3509 |
3512 | 3510 |
3511 static char* itoa(int value, char* buffer) { | |
mnaganov (inactive)
2012/04/04 10:03:31
Have you tried IntToCString? It uses Vector, which
alexeif
2012/04/04 11:20:49
I have more concerns regarding the checks in relea
yurys
2012/04/04 12:32:16
IntToCString will place the number into the end of
| |
3512 if (value < 0) { | |
3513 *buffer = '-'; | |
3514 ++buffer; | |
3515 value = -value; | |
3516 } | |
3517 | |
3518 int number_of_digits = 0; | |
3519 int t = value; | |
3520 do { | |
3521 ++number_of_digits; | |
3522 } while (t /= 10); | |
3523 | |
3524 buffer += number_of_digits; | |
3525 char* result = buffer; | |
3526 do { | |
3527 int last_digit = value % 10; | |
3528 value /= 10; | |
3529 *--buffer = '0' + last_digit; | |
3530 } while (value); | |
3531 return result; | |
3532 } | |
3533 | |
3534 | |
3513 void HeapSnapshotJSONSerializer::SerializeEdge(HeapGraphEdge* edge) { | 3535 void HeapSnapshotJSONSerializer::SerializeEdge(HeapGraphEdge* edge) { |
3514 // The buffer needs space for 3 ints, 3 commas and \0 | 3536 // The buffer needs space for 3 ints, 3 commas and \0 |
3515 static const int kBufferSize = | 3537 static const int kBufferSize = |
3516 MaxDecimalDigitsIn<sizeof(int)>::kSigned * 3 + 3 + 1; // NOLINT | 3538 MaxDecimalDigitsIn<sizeof(int)>::kSigned * 3 + 3 + 1; // NOLINT |
3517 EmbeddedVector<char, kBufferSize> buffer; | 3539 EmbeddedVector<char, kBufferSize> buffer; |
3518 int edge_name_or_index = edge->type() == HeapGraphEdge::kElement | 3540 int edge_name_or_index = edge->type() == HeapGraphEdge::kElement |
3519 || edge->type() == HeapGraphEdge::kHidden | 3541 || edge->type() == HeapGraphEdge::kHidden |
3520 || edge->type() == HeapGraphEdge::kWeak | 3542 || edge->type() == HeapGraphEdge::kWeak |
3521 ? edge->index() : GetStringId(edge->name()); | 3543 ? edge->index() : GetStringId(edge->name()); |
3522 STATIC_CHECK(sizeof(int) == sizeof(edge->type())); // NOLINT | 3544 STATIC_CHECK(sizeof(int) == sizeof(edge->type())); // NOLINT |
3523 STATIC_CHECK(sizeof(int) == sizeof(edge_name_or_index)); // NOLINT | 3545 STATIC_CHECK(sizeof(int) == sizeof(edge_name_or_index)); // NOLINT |
3524 STATIC_CHECK(sizeof(int) == sizeof(GetNodeId(edge->to()))); // NOLINT | 3546 STATIC_CHECK(sizeof(int) == sizeof(GetNodeId(edge->to()))); // NOLINT |
3525 int result = OS::SNPrintF(buffer, ",%d,%d,%d", | 3547 char* buffer_pos = buffer.start(); |
3526 edge->type(), edge_name_or_index, GetNodeId(edge->to())); | 3548 *buffer_pos++ = ','; |
3527 USE(result); | 3549 buffer_pos = itoa(edge->type(), buffer_pos); |
3528 ASSERT(result != -1); | 3550 *buffer_pos++ = ','; |
3551 buffer_pos = itoa(edge_name_or_index, buffer_pos); | |
3552 *buffer_pos++ = ','; | |
3553 buffer_pos = itoa(GetNodeId(edge->to()), buffer_pos); | |
3554 *buffer_pos++ = '\0'; | |
3555 ASSERT(buffer_pos <= (buffer.start() + buffer.length())); | |
3529 writer_->AddString(buffer.start()); | 3556 writer_->AddString(buffer.start()); |
3530 } | 3557 } |
3531 | 3558 |
3532 | 3559 |
3533 void HeapSnapshotJSONSerializer::SerializeNode(HeapEntry* entry) { | 3560 void HeapSnapshotJSONSerializer::SerializeNode(HeapEntry* entry) { |
3534 // The buffer needs space for 6 ints, 1 uint32_t, 7 commas, \n and \0 | 3561 // The buffer needs space for 6 ints, 1 uint32_t, 7 commas, \n and \0 |
3535 static const int kBufferSize = | 3562 static const int kBufferSize = |
3536 6 * MaxDecimalDigitsIn<sizeof(int)>::kSigned // NOLINT | 3563 6 * MaxDecimalDigitsIn<sizeof(int)>::kSigned // NOLINT |
3537 + MaxDecimalDigitsIn<sizeof(uint32_t)>::kUnsigned // NOLINT | 3564 + MaxDecimalDigitsIn<sizeof(uint32_t)>::kUnsigned // NOLINT |
3538 + 7 + 1 + 1; | 3565 + 7 + 1 + 1; |
3539 EmbeddedVector<char, kBufferSize> buffer; | 3566 EmbeddedVector<char, kBufferSize> buffer; |
3540 Vector<HeapGraphEdge> children = entry->children(); | 3567 Vector<HeapGraphEdge> children = entry->children(); |
3541 STATIC_CHECK(sizeof(int) == sizeof(entry->type())); // NOLINT | 3568 STATIC_CHECK(sizeof(int) == sizeof(entry->type())); // NOLINT |
alexeif
2012/04/04 11:20:49
If you remove printf these checks are unnecessary.
yurys
2012/04/04 12:32:16
Done. Removed.
| |
3542 STATIC_CHECK(sizeof(int) == sizeof(GetStringId(entry->name()))); // NOLINT | 3569 STATIC_CHECK(sizeof(int) == sizeof(GetStringId(entry->name()))); // NOLINT |
3543 STATIC_CHECK(sizeof(unsigned) == sizeof(entry->id())); // NOLINT | 3570 STATIC_CHECK(sizeof(unsigned) == sizeof(entry->id())); // NOLINT |
3544 STATIC_CHECK(sizeof(int) == sizeof(entry->self_size())); // NOLINT | 3571 STATIC_CHECK(sizeof(int) == sizeof(entry->self_size())); // NOLINT |
3545 STATIC_CHECK(sizeof(int) == sizeof(entry->retained_size())); // NOLINT | 3572 STATIC_CHECK(sizeof(int) == sizeof(entry->retained_size())); // NOLINT |
3546 STATIC_CHECK(sizeof(int) == sizeof(GetNodeId(entry->dominator()))); // NOLINT | 3573 STATIC_CHECK(sizeof(int) == sizeof(GetNodeId(entry->dominator()))); // NOLINT |
3547 STATIC_CHECK(sizeof(int) == sizeof(children.length())); // NOLINT | 3574 STATIC_CHECK(sizeof(int) == sizeof(children.length())); // NOLINT |
3548 int result = OS::SNPrintF(buffer, "\n,%d,%d,%u,%d,%d,%d,%d", | 3575 char* buffer_pos = buffer.start(); |
3549 entry->type(), | 3576 *buffer_pos++ = '\n'; |
3550 GetStringId(entry->name()), | 3577 *buffer_pos++ = ','; |
3551 entry->id(), | 3578 buffer_pos = itoa(entry->type(), buffer_pos); |
3552 entry->self_size(), | 3579 *buffer_pos++ = ','; |
3553 entry->retained_size(), | 3580 buffer_pos = itoa(GetStringId(entry->name()), buffer_pos); |
3554 GetNodeId(entry->dominator()), | 3581 *buffer_pos++ = ','; |
3555 children.length()); | 3582 buffer_pos = itoa(entry->id(), buffer_pos); |
3556 USE(result); | 3583 *buffer_pos++ = ','; |
3557 ASSERT(result != -1); | 3584 buffer_pos = itoa(entry->self_size(), buffer_pos); |
3585 *buffer_pos++ = ','; | |
3586 buffer_pos = itoa(entry->retained_size(), buffer_pos); | |
3587 *buffer_pos++ = ','; | |
3588 buffer_pos = itoa(GetNodeId(entry->dominator()), buffer_pos); | |
3589 *buffer_pos++ = ','; | |
3590 buffer_pos = itoa(children.length(), buffer_pos); | |
3591 *buffer_pos++ = '\0'; | |
3592 ASSERT(buffer_pos <= (buffer.start() + buffer.length())); | |
3558 writer_->AddString(buffer.start()); | 3593 writer_->AddString(buffer.start()); |
3559 for (int i = 0; i < children.length(); ++i) { | 3594 for (int i = 0; i < children.length(); ++i) { |
3560 SerializeEdge(&children[i]); | 3595 SerializeEdge(&children[i]); |
3561 if (writer_->aborted()) return; | 3596 if (writer_->aborted()) return; |
3562 } | 3597 } |
3563 } | 3598 } |
3564 | 3599 |
3565 | 3600 |
3566 void HeapSnapshotJSONSerializer::SerializeNodes() { | 3601 void HeapSnapshotJSONSerializer::SerializeNodes() { |
3567 // The first (zero) item of nodes array is an object describing node | 3602 // The first (zero) item of nodes array is an object describing node |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3739 | 3774 |
3740 | 3775 |
3741 void HeapSnapshotJSONSerializer::SortHashMap( | 3776 void HeapSnapshotJSONSerializer::SortHashMap( |
3742 HashMap* map, List<HashMap::Entry*>* sorted_entries) { | 3777 HashMap* map, List<HashMap::Entry*>* sorted_entries) { |
3743 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) | 3778 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) |
3744 sorted_entries->Add(p); | 3779 sorted_entries->Add(p); |
3745 sorted_entries->Sort(SortUsingEntryValue); | 3780 sorted_entries->Sort(SortUsingEntryValue); |
3746 } | 3781 } |
3747 | 3782 |
3748 } } // namespace v8::internal | 3783 } } // namespace v8::internal |
OLD | NEW |