Chromium Code Reviews| Index: src/log.h |
| diff --git a/src/log.h b/src/log.h |
| index 51597ddda93a902d3c7ffd73b2974d47ec0706fd..0be085395ed1fa3225ac9e7ec10f505f0d450b93 100644 |
| --- a/src/log.h |
| +++ b/src/log.h |
| @@ -149,6 +149,76 @@ class LowLevelLogger; |
| class PerfJitLogger; |
| class Sampler; |
| +// Mapping from the offset within generated code to source line number. |
| +class JITLineInfoTable : public Malloced { |
| + public: |
| + JITLineInfoTable() : pc_offset_infos_(20) {} |
| + |
| + void SetPosition(unsigned int pc_offset, unsigned int src_line) { |
| + AddPcOffsetInfo(PcOffsetInfo(pc_offset, src_line)); |
| + } |
| + |
| + int GetSourceLineNumber(unsigned int pc_offset) const { |
| + int length = pc_offset_infos_.length(); |
|
danno
2014/07/29 09:24:51
Why not use binary_search/lower_bound here?
|
| + if (0 == length) return 0; |
|
alph
2014/07/29 12:55:56
nit style: the v8 code doesn't seem to use const a
|
| + |
| + int low = 0; |
| + int high = length - 1; |
| + |
| + if (pc_offset > pc_offset_infos_[high].pc_offset_) { |
| + return 0; // out of range |
| + } |
| + |
| + while (low < high) { |
| + int mid = (low + high) / 2; |
| + const JITLineInfoTable::PcOffsetInfo& elem = pc_offset_infos_[mid]; |
| + if (elem.pc_offset_ > pc_offset) { |
| + high = mid; |
| + continue; |
| + } |
| + if (elem.pc_offset_ < pc_offset) { |
| + low = mid + 1; |
| + continue; |
| + } |
| + return elem.line_; // found the element |
| + } |
| + |
| + int line = pc_offset_infos_[high].line_; |
| + return line; |
| + } |
| + |
| + struct PcOffsetInfo { |
| + PcOffsetInfo(unsigned int pc_offset, unsigned int src_line) |
| + : pc_offset_(pc_offset), line_(src_line) { } |
| + |
| + unsigned int pc_offset_; |
| + unsigned int line_; |
| + }; |
| + |
| + List<PcOffsetInfo>* entries() { return &pc_offset_infos_; } |
| + const List<PcOffsetInfo>* entries() const { return &pc_offset_infos_; } |
| + |
| + JITLineInfoTable& operator=(const JITLineInfoTable& other) { |
| + if (this != &other) { |
| + const List<PcOffsetInfo>* entries = other.entries(); |
| + if (entries) { |
| + pc_offset_infos_.Clear(); |
| + pc_offset_infos_.AddAll(*entries); |
| + } |
| + } |
| + return *this; |
| + } |
| + |
| + private: |
| + void AddPcOffsetInfo(const PcOffsetInfo& pc_offset_info) { |
| + pc_offset_infos_.Add(pc_offset_info); |
|
alph
2014/07/29 12:55:56
As long as the algo expects the entries are sorted
|
| + } |
| + |
| + // The data reported by code generator. |
| + List<PcOffsetInfo> pc_offset_infos_; |
| +}; |
| + |
| + |
| class Logger { |
| public: |
| enum StartEnd { START = 0, END = 1 }; |