OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 | 621 |
622 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotGenerator); | 622 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotGenerator); |
623 }; | 623 }; |
624 | 624 |
625 class OutputStreamWriter; | 625 class OutputStreamWriter; |
626 | 626 |
627 class HeapSnapshotJSONSerializer { | 627 class HeapSnapshotJSONSerializer { |
628 public: | 628 public: |
629 explicit HeapSnapshotJSONSerializer(HeapSnapshot* snapshot) | 629 explicit HeapSnapshotJSONSerializer(HeapSnapshot* snapshot) |
630 : snapshot_(snapshot), | 630 : snapshot_(snapshot), |
631 strings_(StringsMatch), | 631 strings_(ObjectsMatch), |
632 next_node_id_(1), | 632 next_node_id_(1), |
633 next_string_id_(1), | 633 next_string_id_(1), |
634 writer_(NULL) { | 634 writer_(NULL) { |
635 } | 635 } |
636 void Serialize(v8::OutputStream* stream); | 636 void Serialize(v8::OutputStream* stream); |
637 | 637 |
638 private: | 638 private: |
639 INLINE(static bool StringsMatch(void* key1, void* key2)) { | 639 INLINE(static bool ObjectsMatch(void* key1, void* key2)) { |
640 return strcmp(reinterpret_cast<char*>(key1), | 640 return key1 == key2; |
641 reinterpret_cast<char*>(key2)) == 0; | |
642 } | 641 } |
643 | 642 |
644 INLINE(static uint32_t StringHash(const void* string)) { | 643 INLINE(static uint32_t ObjectHash(const void* key)) { |
645 const char* s = reinterpret_cast<const char*>(string); | 644 return ComputeIntegerHash( |
646 int len = static_cast<int>(strlen(s)); | 645 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(key)), |
647 return StringHasher::HashSequentialString( | 646 v8::internal::kZeroHashSeed); |
648 s, len, v8::internal::kZeroHashSeed); | |
649 } | 647 } |
650 | 648 |
651 int GetStringId(const char* s); | 649 int GetStringId(const char* s); |
652 int entry_index(HeapEntry* e) { return e->index() * kNodeFieldsCount; } | 650 int entry_index(HeapEntry* e) { return e->index() * kNodeFieldsCount; } |
653 void SerializeEdge(HeapGraphEdge* edge, bool first_edge); | 651 void SerializeEdge(HeapGraphEdge* edge, bool first_edge); |
654 void SerializeEdges(); | 652 void SerializeEdges(); |
655 void SerializeImpl(); | 653 void SerializeImpl(); |
656 void SerializeNode(HeapEntry* entry); | 654 void SerializeNode(HeapEntry* entry); |
657 void SerializeNodes(); | 655 void SerializeNodes(); |
658 void SerializeSnapshot(); | 656 void SerializeSnapshot(); |
659 void SerializeString(const unsigned char* s); | 657 void SerializeString(const unsigned char* s); |
660 void SerializeStrings(); | 658 void SerializeStrings(); |
| 659 void SortHashMap(HashMap* map, List<HashMap::Entry*>* sorted_entries); |
661 | 660 |
662 static const int kEdgeFieldsCount; | 661 static const int kEdgeFieldsCount; |
663 static const int kNodeFieldsCount; | 662 static const int kNodeFieldsCount; |
664 | 663 |
665 HeapSnapshot* snapshot_; | 664 HeapSnapshot* snapshot_; |
666 HashMap strings_; | 665 HashMap strings_; |
667 int next_node_id_; | 666 int next_node_id_; |
668 int next_string_id_; | 667 int next_string_id_; |
669 OutputStreamWriter* writer_; | 668 OutputStreamWriter* writer_; |
670 | 669 |
671 friend class HeapSnapshotJSONSerializerEnumerator; | 670 friend class HeapSnapshotJSONSerializerEnumerator; |
672 friend class HeapSnapshotJSONSerializerIterator; | 671 friend class HeapSnapshotJSONSerializerIterator; |
673 | 672 |
674 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotJSONSerializer); | 673 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotJSONSerializer); |
675 }; | 674 }; |
676 | 675 |
677 | 676 |
678 } } // namespace v8::internal | 677 } } // namespace v8::internal |
679 | 678 |
680 #endif // V8_HEAP_SNAPSHOT_GENERATOR_H_ | 679 #endif // V8_HEAP_SNAPSHOT_GENERATOR_H_ |
681 | 680 |
OLD | NEW |