| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   97     entry->code_offset = tmp; |   97     entry->code_offset = tmp; | 
|   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(Isolate* isolate, |  107 SourcePositionTableBuilder::SourcePositionTableBuilder( | 
|  108                                                        Zone* zone) |  108     Isolate* isolate, Zone* zone, | 
 |  109     SourcePositionTableBuilder::RecordingMode mode) | 
|  109     : isolate_(isolate), |  110     : isolate_(isolate), | 
 |  111       mode_(mode), | 
|  110       bytes_(zone), |  112       bytes_(zone), | 
|  111 #ifdef ENABLE_SLOW_DCHECKS |  113 #ifdef ENABLE_SLOW_DCHECKS | 
|  112       raw_entries_(zone), |  114       raw_entries_(zone), | 
|  113 #endif |  115 #endif | 
|  114       previous_(), |  116       previous_(), | 
|  115       jit_handler_data_(nullptr) { |  117       jit_handler_data_(nullptr) { | 
 |  118   if (Omit()) return; | 
|  116   LOG_CODE_EVENT(isolate_, CodeStartLinePosInfoRecordEvent(&jit_handler_data_)); |  119   LOG_CODE_EVENT(isolate_, CodeStartLinePosInfoRecordEvent(&jit_handler_data_)); | 
|  117 } |  120 } | 
|  118  |  121  | 
|  119 void SourcePositionTableBuilder::EndJitLogging(AbstractCode* code) { |  122 void SourcePositionTableBuilder::EndJitLogging(AbstractCode* code) { | 
 |  123   if (Omit()) return; | 
|  120   LOG_CODE_EVENT(isolate_, |  124   LOG_CODE_EVENT(isolate_, | 
|  121                  CodeEndLinePosInfoRecordEvent(code, jit_handler_data_)); |  125                  CodeEndLinePosInfoRecordEvent(code, jit_handler_data_)); | 
|  122 } |  126 } | 
|  123  |  127  | 
|  124 void SourcePositionTableBuilder::AddPosition(size_t code_offset, |  128 void SourcePositionTableBuilder::AddPosition(size_t code_offset, | 
|  125                                              int source_position, |  129                                              int source_position, | 
|  126                                              bool is_statement) { |  130                                              bool is_statement) { | 
 |  131   if (Omit()) return; | 
|  127   int offset = static_cast<int>(code_offset); |  132   int offset = static_cast<int>(code_offset); | 
|  128   AddEntry({offset, source_position, is_statement}); |  133   AddEntry({offset, source_position, is_statement}); | 
|  129 } |  134 } | 
|  130  |  135  | 
|  131 void SourcePositionTableBuilder::AddEntry(const PositionTableEntry& entry) { |  136 void SourcePositionTableBuilder::AddEntry(const PositionTableEntry& entry) { | 
|  132   PositionTableEntry tmp(entry); |  137   PositionTableEntry tmp(entry); | 
|  133   SubtractFromEntry(tmp, previous_); |  138   SubtractFromEntry(tmp, previous_); | 
|  134   EncodeEntry(bytes_, tmp); |  139   EncodeEntry(bytes_, tmp); | 
|  135   previous_ = entry; |  140   previous_ = entry; | 
|  136  |  141  | 
|  137   if (entry.is_statement) { |  142   if (entry.is_statement) { | 
|  138     LOG_CODE_EVENT(isolate_, CodeLinePosInfoAddStatementPositionEvent( |  143     LOG_CODE_EVENT(isolate_, CodeLinePosInfoAddStatementPositionEvent( | 
|  139                                  jit_handler_data_, entry.code_offset, |  144                                  jit_handler_data_, entry.code_offset, | 
|  140                                  entry.source_position)); |  145                                  entry.source_position)); | 
|  141   } |  146   } | 
|  142   LOG_CODE_EVENT(isolate_, CodeLinePosInfoAddPositionEvent( |  147   LOG_CODE_EVENT(isolate_, CodeLinePosInfoAddPositionEvent( | 
|  143                                jit_handler_data_, entry.code_offset, |  148                                jit_handler_data_, entry.code_offset, | 
|  144                                entry.source_position)); |  149                                entry.source_position)); | 
|  145  |  150  | 
|  146 #ifdef ENABLE_SLOW_DCHECKS |  151 #ifdef ENABLE_SLOW_DCHECKS | 
|  147   raw_entries_.push_back(entry); |  152   raw_entries_.push_back(entry); | 
|  148 #endif |  153 #endif | 
|  149 } |  154 } | 
|  150  |  155  | 
|  151 Handle<ByteArray> SourcePositionTableBuilder::ToSourcePositionTable() { |  156 Handle<ByteArray> SourcePositionTableBuilder::ToSourcePositionTable() { | 
|  152   if (bytes_.empty()) return isolate_->factory()->empty_byte_array(); |  157   if (bytes_.empty()) return isolate_->factory()->empty_byte_array(); | 
 |  158   DCHECK(!Omit()); | 
|  153  |  159  | 
|  154   Handle<ByteArray> table = isolate_->factory()->NewByteArray( |  160   Handle<ByteArray> table = isolate_->factory()->NewByteArray( | 
|  155       static_cast<int>(bytes_.size()), TENURED); |  161       static_cast<int>(bytes_.size()), TENURED); | 
|  156  |  162  | 
|  157   MemCopy(table->GetDataStartAddress(), &*bytes_.begin(), bytes_.size()); |  163   MemCopy(table->GetDataStartAddress(), &*bytes_.begin(), bytes_.size()); | 
|  158  |  164  | 
|  159 #ifdef ENABLE_SLOW_DCHECKS |  165 #ifdef ENABLE_SLOW_DCHECKS | 
|  160   // Brute force testing: Record all positions and decode |  166   // Brute force testing: Record all positions and decode | 
|  161   // the entire table to verify they are identical. |  167   // the entire table to verify they are identical. | 
|  162   auto raw = raw_entries_.begin(); |  168   auto raw = raw_entries_.begin(); | 
|  163   for (SourcePositionTableIterator encoded(*table); !encoded.done(); |  169   for (SourcePositionTableIterator encoded(*table); !encoded.done(); | 
|  164        encoded.Advance(), raw++) { |  170        encoded.Advance(), raw++) { | 
|  165     DCHECK(raw != raw_entries_.end()); |  171     DCHECK(raw != raw_entries_.end()); | 
|  166     DCHECK_EQ(encoded.code_offset(), raw->code_offset); |  172     DCHECK_EQ(encoded.code_offset(), raw->code_offset); | 
|  167     DCHECK_EQ(encoded.source_position(), raw->source_position); |  173     DCHECK_EQ(encoded.source_position(), raw->source_position); | 
|  168     DCHECK_EQ(encoded.is_statement(), raw->is_statement); |  174     DCHECK_EQ(encoded.is_statement(), raw->is_statement); | 
|  169   } |  175   } | 
|  170   DCHECK(raw == raw_entries_.end()); |  176   DCHECK(raw == raw_entries_.end()); | 
 |  177   // No additional source positions after creating the table. | 
 |  178   mode_ = OMIT_SOURCE_POSITIONS; | 
|  171 #endif |  179 #endif | 
|  172  |  | 
|  173   return table; |  180   return table; | 
|  174 } |  181 } | 
|  175  |  182  | 
|  176 SourcePositionTableIterator::SourcePositionTableIterator(ByteArray* byte_array) |  183 SourcePositionTableIterator::SourcePositionTableIterator(ByteArray* byte_array) | 
|  177     : table_(byte_array), index_(0), current_() { |  184     : table_(byte_array), index_(0), current_() { | 
|  178   Advance(); |  185   Advance(); | 
|  179 } |  186 } | 
|  180  |  187  | 
|  181 void SourcePositionTableIterator::Advance() { |  188 void SourcePositionTableIterator::Advance() { | 
|  182   DCHECK(!done()); |  189   DCHECK(!done()); | 
|  183   DCHECK(index_ >= 0 && index_ <= table_->length()); |  190   DCHECK(index_ >= 0 && index_ <= table_->length()); | 
|  184   if (index_ == table_->length()) { |  191   if (index_ == table_->length()) { | 
|  185     index_ = kDone; |  192     index_ = kDone; | 
|  186   } else { |  193   } else { | 
|  187     PositionTableEntry tmp; |  194     PositionTableEntry tmp; | 
|  188     DecodeEntry(table_, &index_, &tmp); |  195     DecodeEntry(table_, &index_, &tmp); | 
|  189     AddAndSetEntry(current_, tmp); |  196     AddAndSetEntry(current_, tmp); | 
|  190   } |  197   } | 
|  191 } |  198 } | 
|  192  |  199  | 
|  193 }  // namespace internal |  200 }  // namespace internal | 
|  194 }  // namespace v8 |  201 }  // namespace v8 | 
| OLD | NEW |