| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 class StackTrace; | 108 class StackTrace; |
| 109 class StackFrame; | 109 class StackFrame; |
| 110 | 110 |
| 111 namespace internal { | 111 namespace internal { |
| 112 | 112 |
| 113 class Arguments; | 113 class Arguments; |
| 114 class Object; | 114 class Object; |
| 115 class Heap; | 115 class Heap; |
| 116 class HeapObject; | 116 class HeapObject; |
| 117 class Isolate; | 117 class Isolate; |
| 118 class HeapVisualizerImplementation; |
| 118 } | 119 } |
| 119 | 120 |
| 120 | 121 |
| 121 // --- Weak Handles --- | 122 // --- Weak Handles --- |
| 122 | 123 |
| 123 | 124 |
| 124 /** | 125 /** |
| 125 * A weak reference callback function. | 126 * A weak reference callback function. |
| 126 * | 127 * |
| 127 * This callback should either explicitly invoke Dispose on |object| if | 128 * This callback should either explicitly invoke Dispose on |object| if |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 /** | 676 /** |
| 676 * Associate an additional data object with the script. This is mainly used | 677 * Associate an additional data object with the script. This is mainly used |
| 677 * with the debugger as this data object is only available through the | 678 * with the debugger as this data object is only available through the |
| 678 * debugger API. | 679 * debugger API. |
| 679 */ | 680 */ |
| 680 void SetData(Handle<String> data); | 681 void SetData(Handle<String> data); |
| 681 }; | 682 }; |
| 682 | 683 |
| 683 | 684 |
| 684 /** | 685 /** |
| 686 * A heap visualization listener. |
| 687 */ |
| 688 // The linter thinks V8EXPORT is the class name. |
| 689 class V8EXPORT HeapVisualizer { // NOLINT |
| 690 public: |
| 691 HeapVisualizer() |
| 692 : next_(NULL), |
| 693 pixel_size_log_2_(8), |
| 694 buffer_fullness_(0), |
| 695 secs_zero_(0) { } |
| 696 virtual ~HeapVisualizer() { } |
| 697 virtual void Write(const char* buf, int count) = 0; |
| 698 virtual void Flush() { |
| 699 Write(buffer_, buffer_fullness_); |
| 700 buffer_fullness_ = 0; |
| 701 } |
| 702 |
| 703 static const int kHeapOverheadPseudoSpaceIdentity = 10; |
| 704 static const int kSurvivingNewSpacePseudoSpaceIdentity = 11; |
| 705 |
| 706 typedef enum { |
| 707 kAllocated, // start_w len_w transparency-byte transparency-byte ... |
| 708 kConstantAllocation, // start_w len_w transparency-byte |
| 709 kChangeAllocation, // start_w, change-byte |
| 710 kNameArea, // space-code-byte start_w len_w |
| 711 kFreeArea, // start_w len_w |
| 712 kWritten, // " " |
| 713 kRead, // " " |
| 714 kSwept, // " " |
| 715 kMarked, // " " |
| 716 kTimeStamp // s_w us_w |
| 717 } MessageId; |
| 718 |
| 719 typedef enum { |
| 720 kRunning, |
| 721 kCrankshafting, |
| 722 kScavenging, |
| 723 kMarking, |
| 724 kCompacting, |
| 725 kSweeping |
| 726 } ProfileState; |
| 727 |
| 728 intptr_t pixel_size_log_2() { return pixel_size_log_2_; } |
| 729 virtual void set_pixel_size_log_2(uintptr_t pixel_size_log_2) { |
| 730 pixel_size_log_2_ = pixel_size_log_2; |
| 731 } |
| 732 |
| 733 uint32_t secs_zero() { return secs_zero_; } |
| 734 uint32_t usecs_zero() { return usecs_zero_; } |
| 735 void set_time_zero(uint32_t secs, uint32_t usecs) { |
| 736 secs_zero_ = secs; |
| 737 usecs_zero_ = usecs; |
| 738 } |
| 739 |
| 740 // These methods don't necessarily have to be here, but they server |
| 741 // as a sort of documentation of the protocol. |
| 742 |
| 743 // The protocol describes the state of the heap at a (currently implicit) |
| 744 // granularity of 'pixels'. A pixel is some power-of-2 number of bytes. |
| 745 |
| 746 // A graymap that indicates how full a set of |size| consecutive pixels of |
| 747 // memory are. 0 indicates that all bytes in a pixel are allocated. 255 |
| 748 // indicates that all bytes in a pixel are free. |
| 749 void Allocate(uintptr_t address, uintptr_t size, unsigned char* freeness) { |
| 750 Write8(kAllocated); |
| 751 Write32(address >> pixel_size_log_2_); |
| 752 Write32(size); |
| 753 WriteX(freeness, size); |
| 754 } |
| 755 |
| 756 // A way to quickly set the allocatedness of a set of pixels to the same |
| 757 // value. Normally the freeness will be 0 (all bytes allocated) or 255 (all |
| 758 // bytes free). |
| 759 void ConstantAllocation( |
| 760 uintptr_t address, uintptr_t size, unsigned char freeness) { |
| 761 Write8(kConstantAllocation); |
| 762 Write32(address >> pixel_size_log_2_); |
| 763 Write32(size >> pixel_size_log_2_); |
| 764 Write8(freeness); |
| 765 } |
| 766 |
| 767 // A way to indicate that a number of bytes have been allocated within a |
| 768 // pixel. The resolution is limited unless a pixel is smaller than 256 |
| 769 // bytes, since there are only 8 bits of precision in the final byte which |
| 770 // indicates how many bytes have been allocated from 0 to 255 (representing |
| 771 // all the bytes in the pixel). |
| 772 void ChangeAllocation(uintptr_t address, uintptr_t change) { |
| 773 Write8(kChangeAllocation); |
| 774 Write32(address >> pixel_size_log_2_); |
| 775 uintptr_t change_byte = change >> pixel_size_log_2_; |
| 776 Write8(change_byte == 256 ? 255 : change_byte); |
| 777 } |
| 778 |
| 779 // Indicates for a range of memory that it has been allocated from the OS and |
| 780 // dedicated to a particular use in the heap. The |space| argument is a |
| 781 // space id from spaces.h or one of the pseudo-space-identities defined in |
| 782 // this class. |
| 783 void Name(int space, uintptr_t address, uintptr_t size) { |
| 784 Write8(kNameArea); |
| 785 Write8(space); |
| 786 Write32(address >> pixel_size_log_2_); |
| 787 Write32(size >> pixel_size_log_2_); |
| 788 } |
| 789 |
| 790 // Currently unused way of indicating that something has happened in a region |
| 791 // of memory. |
| 792 void Event(MessageId id, uintptr_t address, uintptr_t size) { |
| 793 Write8(id); |
| 794 Write32(address >> pixel_size_log_2_); |
| 795 Write32(size >> pixel_size_log_2_); |
| 796 } |
| 797 |
| 798 // Transmit the time since the VM started in seconds and microseconds. Also |
| 799 // transmits a VM state. The VM is assumed to transition into the given |
| 800 // state at the time indicated, so the time up to the indicated time is |
| 801 // assumed to have been spent in the previous state. |
| 802 void TimeStamp(int state, uintptr_t s, uintptr_t us) { |
| 803 Write8(kTimeStamp); |
| 804 Write8(state); |
| 805 Write32(s); |
| 806 Write32(us); |
| 807 } |
| 808 |
| 809 HeapVisualizer* next() { return next_; } |
| 810 |
| 811 private: |
| 812 static const int kBufferSize = 4096; |
| 813 |
| 814 HeapVisualizer* next_; |
| 815 uintptr_t pixel_size_log_2_; |
| 816 int buffer_fullness_; |
| 817 uint32_t secs_zero_; |
| 818 uint32_t usecs_zero_; |
| 819 char buffer_[kBufferSize]; |
| 820 |
| 821 void set_next(HeapVisualizer* next) { next_ = next; } |
| 822 |
| 823 // Little endian 32 bit value. |
| 824 inline void Write32(intptr_t x) { |
| 825 if (kBufferSize - buffer_fullness_ < 4) { |
| 826 Flush(); |
| 827 } |
| 828 buffer_[buffer_fullness_] = x >> 24; |
| 829 buffer_[buffer_fullness_ + 1] = x >> 16; |
| 830 buffer_[buffer_fullness_ + 2] = x >> 8; |
| 831 buffer_[buffer_fullness_ + 3] = x; |
| 832 buffer_fullness_ += 4; |
| 833 } |
| 834 |
| 835 inline void Write8(int x) { |
| 836 if (kBufferSize == buffer_fullness_) Flush(); |
| 837 buffer_[buffer_fullness_++] = x; |
| 838 } |
| 839 |
| 840 void WriteX(unsigned char* bytes, int len); |
| 841 |
| 842 friend class v8::internal::HeapVisualizerImplementation; |
| 843 }; |
| 844 |
| 845 |
| 846 void V8EXPORT RegisterHeapVisualizer(HeapVisualizer* visualizer); |
| 847 |
| 848 |
| 849 /** |
| 685 * An error message. | 850 * An error message. |
| 686 */ | 851 */ |
| 687 class V8EXPORT Message { | 852 class V8EXPORT Message { |
| 688 public: | 853 public: |
| 689 Local<String> Get() const; | 854 Local<String> Get() const; |
| 690 Local<String> GetSourceLine() const; | 855 Local<String> GetSourceLine() const; |
| 691 | 856 |
| 692 /** | 857 /** |
| 693 * Returns the resource name for the script from where the function causing | 858 * Returns the resource name for the script from where the function causing |
| 694 * the error originates. | 859 * the error originates. |
| (...skipping 3526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4221 | 4386 |
| 4222 | 4387 |
| 4223 } // namespace v8 | 4388 } // namespace v8 |
| 4224 | 4389 |
| 4225 | 4390 |
| 4226 #undef V8EXPORT | 4391 #undef V8EXPORT |
| 4227 #undef TYPE_CHECK | 4392 #undef TYPE_CHECK |
| 4228 | 4393 |
| 4229 | 4394 |
| 4230 #endif // V8_H_ | 4395 #endif // V8_H_ |
| OLD | NEW |