OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/source-position-table.h" | 5 #include "src/source-position-table.h" |
6 | 6 |
7 #include "src/log.h" | 7 #include "src/log.h" |
8 #include "src/objects-inl.h" | 8 #include "src/objects-inl.h" |
9 #include "src/objects.h" | 9 #include "src/objects.h" |
10 | 10 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } else { | 98 } else { |
99 entry->is_statement = false; | 99 entry->is_statement = false; |
100 entry->code_offset = -(tmp + 1); | 100 entry->code_offset = -(tmp + 1); |
101 } | 101 } |
102 DecodeInt(bytes, index, &entry->source_position); | 102 DecodeInt(bytes, index, &entry->source_position); |
103 } | 103 } |
104 | 104 |
105 } // namespace | 105 } // namespace |
106 | 106 |
107 SourcePositionTableBuilder::SourcePositionTableBuilder( | 107 SourcePositionTableBuilder::SourcePositionTableBuilder( |
108 Isolate* isolate, Zone* zone, | 108 Zone* zone, SourcePositionTableBuilder::RecordingMode mode) |
109 SourcePositionTableBuilder::RecordingMode mode) | 109 : mode_(mode), |
110 : isolate_(isolate), | |
111 mode_(mode), | |
112 bytes_(zone), | 110 bytes_(zone), |
113 #ifdef ENABLE_SLOW_DCHECKS | 111 #ifdef ENABLE_SLOW_DCHECKS |
114 raw_entries_(zone), | 112 raw_entries_(zone), |
115 #endif | 113 #endif |
116 previous_(), | 114 previous_() { |
117 jit_handler_data_(nullptr) { | |
118 if (Omit()) return; | |
119 LOG_CODE_EVENT(isolate_, CodeStartLinePosInfoRecordEvent(&jit_handler_data_)); | |
120 } | |
121 | |
122 void SourcePositionTableBuilder::EndJitLogging(AbstractCode* code) { | |
123 if (Omit()) return; | |
124 LOG_CODE_EVENT(isolate_, | |
125 CodeEndLinePosInfoRecordEvent(code, jit_handler_data_)); | |
126 } | 115 } |
127 | 116 |
128 void SourcePositionTableBuilder::AddPosition(size_t code_offset, | 117 void SourcePositionTableBuilder::AddPosition(size_t code_offset, |
129 int source_position, | 118 int source_position, |
130 bool is_statement) { | 119 bool is_statement) { |
131 if (Omit()) return; | 120 if (Omit()) return; |
132 int offset = static_cast<int>(code_offset); | 121 int offset = static_cast<int>(code_offset); |
133 AddEntry({offset, source_position, is_statement}); | 122 AddEntry({offset, source_position, is_statement}); |
134 } | 123 } |
135 | 124 |
136 void SourcePositionTableBuilder::AddEntry(const PositionTableEntry& entry) { | 125 void SourcePositionTableBuilder::AddEntry(const PositionTableEntry& entry) { |
137 PositionTableEntry tmp(entry); | 126 PositionTableEntry tmp(entry); |
138 SubtractFromEntry(tmp, previous_); | 127 SubtractFromEntry(tmp, previous_); |
139 EncodeEntry(bytes_, tmp); | 128 EncodeEntry(bytes_, tmp); |
140 previous_ = entry; | 129 previous_ = entry; |
141 | |
142 if (entry.is_statement) { | |
143 LOG_CODE_EVENT(isolate_, CodeLinePosInfoAddStatementPositionEvent( | |
144 jit_handler_data_, entry.code_offset, | |
145 entry.source_position)); | |
146 } | |
147 LOG_CODE_EVENT(isolate_, CodeLinePosInfoAddPositionEvent( | |
148 jit_handler_data_, entry.code_offset, | |
149 entry.source_position)); | |
150 | |
151 #ifdef ENABLE_SLOW_DCHECKS | 130 #ifdef ENABLE_SLOW_DCHECKS |
152 raw_entries_.push_back(entry); | 131 raw_entries_.push_back(entry); |
153 #endif | 132 #endif |
154 } | 133 } |
155 | 134 |
156 Handle<ByteArray> SourcePositionTableBuilder::ToSourcePositionTable() { | 135 Handle<ByteArray> SourcePositionTableBuilder::ToSourcePositionTable( |
157 if (bytes_.empty()) return isolate_->factory()->empty_byte_array(); | 136 Isolate* isolate, Handle<AbstractCode> code) { |
| 137 if (bytes_.empty()) return isolate->factory()->empty_byte_array(); |
158 DCHECK(!Omit()); | 138 DCHECK(!Omit()); |
159 | 139 |
160 Handle<ByteArray> table = isolate_->factory()->NewByteArray( | 140 Handle<ByteArray> table = isolate->factory()->NewByteArray( |
161 static_cast<int>(bytes_.size()), TENURED); | 141 static_cast<int>(bytes_.size()), TENURED); |
162 | 142 |
163 MemCopy(table->GetDataStartAddress(), &*bytes_.begin(), bytes_.size()); | 143 MemCopy(table->GetDataStartAddress(), &*bytes_.begin(), bytes_.size()); |
164 | 144 |
| 145 LOG_CODE_EVENT(isolate, CodeLinePosInfoRecordEvent(*code, *table)); |
| 146 |
165 #ifdef ENABLE_SLOW_DCHECKS | 147 #ifdef ENABLE_SLOW_DCHECKS |
166 // Brute force testing: Record all positions and decode | 148 // Brute force testing: Record all positions and decode |
167 // the entire table to verify they are identical. | 149 // the entire table to verify they are identical. |
168 auto raw = raw_entries_.begin(); | 150 auto raw = raw_entries_.begin(); |
169 for (SourcePositionTableIterator encoded(*table); !encoded.done(); | 151 for (SourcePositionTableIterator encoded(*table); !encoded.done(); |
170 encoded.Advance(), raw++) { | 152 encoded.Advance(), raw++) { |
171 DCHECK(raw != raw_entries_.end()); | 153 DCHECK(raw != raw_entries_.end()); |
172 DCHECK_EQ(encoded.code_offset(), raw->code_offset); | 154 DCHECK_EQ(encoded.code_offset(), raw->code_offset); |
173 DCHECK_EQ(encoded.source_position(), raw->source_position); | 155 DCHECK_EQ(encoded.source_position(), raw->source_position); |
174 DCHECK_EQ(encoded.is_statement(), raw->is_statement); | 156 DCHECK_EQ(encoded.is_statement(), raw->is_statement); |
(...skipping 17 matching lines...) Expand all Loading... |
192 index_ = kDone; | 174 index_ = kDone; |
193 } else { | 175 } else { |
194 PositionTableEntry tmp; | 176 PositionTableEntry tmp; |
195 DecodeEntry(table_, &index_, &tmp); | 177 DecodeEntry(table_, &index_, &tmp); |
196 AddAndSetEntry(current_, tmp); | 178 AddAndSetEntry(current_, tmp); |
197 } | 179 } |
198 } | 180 } |
199 | 181 |
200 } // namespace internal | 182 } // namespace internal |
201 } // namespace v8 | 183 } // namespace v8 |
OLD | NEW |