| 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/interpreter/source-position-table.h" | 5 #include "src/interpreter/source-position-table.h" |
| 6 | 6 |
| 7 #include "src/objects-inl.h" | 7 #include "src/objects-inl.h" |
| 8 #include "src/objects.h" | 8 #include "src/objects.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // numbers properly. | 110 // numbers properly. |
| 111 entry->bytecode_offset = (tmp >> 1); | 111 entry->bytecode_offset = (tmp >> 1); |
| 112 | 112 |
| 113 DecodeInt(bytes, index, &entry->source_position); | 113 DecodeInt(bytes, index, &entry->source_position); |
| 114 } | 114 } |
| 115 | 115 |
| 116 } // namespace | 116 } // namespace |
| 117 | 117 |
| 118 void SourcePositionTableBuilder::AddStatementPosition(size_t bytecode_offset, | 118 void SourcePositionTableBuilder::AddStatementPosition(size_t bytecode_offset, |
| 119 int source_position) { | 119 int source_position) { |
| 120 int offset = static_cast<int>(bytecode_offset); | 120 AddPosition(bytecode_offset, source_position, true); |
| 121 AddEntry({offset, source_position, true}); | |
| 122 } | 121 } |
| 123 | 122 |
| 124 void SourcePositionTableBuilder::AddExpressionPosition(size_t bytecode_offset, | 123 void SourcePositionTableBuilder::AddExpressionPosition(size_t bytecode_offset, |
| 125 int source_position) { | 124 int source_position) { |
| 125 AddPosition(bytecode_offset, source_position, false); |
| 126 } |
| 127 |
| 128 void SourcePositionTableBuilder::AddPosition(size_t bytecode_offset, |
| 129 int source_position, |
| 130 bool is_statement) { |
| 126 int offset = static_cast<int>(bytecode_offset); | 131 int offset = static_cast<int>(bytecode_offset); |
| 127 AddEntry({offset, source_position, false}); | 132 AddEntry({offset, source_position, is_statement}); |
| 128 } | 133 } |
| 129 | 134 |
| 130 void SourcePositionTableBuilder::AddEntry(const PositionTableEntry& entry) { | 135 void SourcePositionTableBuilder::AddEntry(const PositionTableEntry& entry) { |
| 131 // Don't encode a new entry if this bytecode already has a source position | 136 PositionTableEntry tmp(entry); |
| 132 // assigned. | |
| 133 if (candidate_.bytecode_offset == entry.bytecode_offset) { | |
| 134 if (entry.is_statement) candidate_ = entry; | |
| 135 return; | |
| 136 } | |
| 137 | |
| 138 CommitEntry(); | |
| 139 candidate_ = entry; | |
| 140 } | |
| 141 | |
| 142 void SourcePositionTableBuilder::CommitEntry() { | |
| 143 if (candidate_.bytecode_offset == kUninitializedCandidateOffset) return; | |
| 144 PositionTableEntry tmp(candidate_); | |
| 145 SubtractFromEntry(tmp, previous_); | 137 SubtractFromEntry(tmp, previous_); |
| 146 EncodeEntry(bytes_, tmp); | 138 EncodeEntry(bytes_, tmp); |
| 147 previous_ = candidate_; | 139 previous_ = entry; |
| 148 | 140 |
| 149 if (candidate_.is_statement) { | 141 if (entry.is_statement) { |
| 150 LOG_CODE_EVENT(isolate_, CodeLinePosInfoAddStatementPositionEvent( | 142 LOG_CODE_EVENT(isolate_, CodeLinePosInfoAddStatementPositionEvent( |
| 151 jit_handler_data_, candidate_.bytecode_offset, | 143 jit_handler_data_, entry.bytecode_offset, |
| 152 candidate_.source_position)); | 144 entry.source_position)); |
| 153 } | 145 } |
| 154 LOG_CODE_EVENT(isolate_, CodeLinePosInfoAddPositionEvent( | 146 LOG_CODE_EVENT(isolate_, CodeLinePosInfoAddPositionEvent( |
| 155 jit_handler_data_, candidate_.bytecode_offset, | 147 jit_handler_data_, entry.bytecode_offset, |
| 156 candidate_.source_position)); | 148 entry.source_position)); |
| 157 | 149 |
| 158 #ifdef ENABLE_SLOW_DCHECKS | 150 #ifdef ENABLE_SLOW_DCHECKS |
| 159 raw_entries_.push_back(candidate_); | 151 raw_entries_.push_back(entry); |
| 160 #endif | 152 #endif |
| 161 } | 153 } |
| 162 | 154 |
| 163 Handle<ByteArray> SourcePositionTableBuilder::ToSourcePositionTable() { | 155 Handle<ByteArray> SourcePositionTableBuilder::ToSourcePositionTable() { |
| 164 CommitEntry(); | |
| 165 if (bytes_.empty()) return isolate_->factory()->empty_byte_array(); | 156 if (bytes_.empty()) return isolate_->factory()->empty_byte_array(); |
| 166 | 157 |
| 167 Handle<ByteArray> table = isolate_->factory()->NewByteArray( | 158 Handle<ByteArray> table = isolate_->factory()->NewByteArray( |
| 168 static_cast<int>(bytes_.size()), TENURED); | 159 static_cast<int>(bytes_.size()), TENURED); |
| 169 | 160 |
| 170 MemCopy(table->GetDataStartAddress(), &*bytes_.begin(), bytes_.size()); | 161 MemCopy(table->GetDataStartAddress(), &*bytes_.begin(), bytes_.size()); |
| 171 | 162 |
| 172 #ifdef ENABLE_SLOW_DCHECKS | 163 #ifdef ENABLE_SLOW_DCHECKS |
| 173 // Brute force testing: Record all positions and decode | 164 // Brute force testing: Record all positions and decode |
| 174 // the entire table to verify they are identical. | 165 // the entire table to verify they are identical. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 199 } else { | 190 } else { |
| 200 PositionTableEntry tmp; | 191 PositionTableEntry tmp; |
| 201 DecodeEntry(table_, &index_, &tmp); | 192 DecodeEntry(table_, &index_, &tmp); |
| 202 AddAndSetEntry(current_, tmp); | 193 AddAndSetEntry(current_, tmp); |
| 203 } | 194 } |
| 204 } | 195 } |
| 205 | 196 |
| 206 } // namespace interpreter | 197 } // namespace interpreter |
| 207 } // namespace internal | 198 } // namespace internal |
| 208 } // namespace v8 | 199 } // namespace v8 |
| OLD | NEW |