| 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 "test/cctest/interpreter/source-position-matcher.h" | 5 #include "test/cctest/interpreter/source-position-matcher.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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 return false; | 80 return false; |
| 81 } | 81 } |
| 82 | 82 |
| 83 if (HasNewExpressionPositionsInOptimized(&original_expression_entries, | 83 if (HasNewExpressionPositionsInOptimized(&original_expression_entries, |
| 84 &optimized_expression_entries)) { | 84 &optimized_expression_entries)) { |
| 85 return false; | 85 return false; |
| 86 } | 86 } |
| 87 | 87 |
| 88 StripUnneededExpressionPositions(original_bytecode, | 88 StripUnneededExpressionPositions(original_bytecode, |
| 89 &original_expression_entries, | 89 &original_expression_entries, |
| 90 original.bytecode_offset()); | 90 original.code_offset()); |
| 91 StripUnneededExpressionPositions(optimized_bytecode, | 91 StripUnneededExpressionPositions(optimized_bytecode, |
| 92 &optimized_expression_entries, | 92 &optimized_expression_entries, |
| 93 optimized.bytecode_offset()); | 93 optimized.code_offset()); |
| 94 | 94 |
| 95 if (!CompareExpressionPositions(&original_expression_entries, | 95 if (!CompareExpressionPositions(&original_expression_entries, |
| 96 &optimized_expression_entries)) { | 96 &optimized_expression_entries)) { |
| 97 // Message logged in CompareExpressionPositions(). | 97 // Message logged in CompareExpressionPositions(). |
| 98 return false; | 98 return false; |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Check original and optimized have matching source positions. | 101 // Check original and optimized have matching source positions. |
| 102 if (original.source_position() != optimized.source_position()) { | 102 if (original.source_position() != optimized.source_position()) { |
| 103 return false; | 103 return false; |
| 104 } | 104 } |
| 105 | 105 |
| 106 if (original.bytecode_offset() < last_original_bytecode_offset) { | 106 if (original.code_offset() < last_original_bytecode_offset) { |
| 107 return false; | 107 return false; |
| 108 } | 108 } |
| 109 last_original_bytecode_offset = original.bytecode_offset(); | 109 last_original_bytecode_offset = original.code_offset(); |
| 110 | 110 |
| 111 if (optimized.bytecode_offset() < last_optimized_bytecode_offset) { | 111 if (optimized.code_offset() < last_optimized_bytecode_offset) { |
| 112 return false; | 112 return false; |
| 113 } | 113 } |
| 114 last_optimized_bytecode_offset = optimized.bytecode_offset(); | 114 last_optimized_bytecode_offset = optimized.code_offset(); |
| 115 | 115 |
| 116 // TODO(oth): Can we compare statement positions are semantically | 116 // TODO(oth): Can we compare statement positions are semantically |
| 117 // equivalent? e.g. before a bytecode that has debugger observable | 117 // equivalent? e.g. before a bytecode that has debugger observable |
| 118 // effects. This is likely non-trivial. | 118 // effects. This is likely non-trivial. |
| 119 } | 119 } |
| 120 | 120 |
| 121 return true; | 121 return true; |
| 122 } | 122 } |
| 123 | 123 |
| 124 bool SourcePositionMatcher::HasNewExpressionPositionsInOptimized( | 124 bool SourcePositionMatcher::HasNewExpressionPositionsInOptimized( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 void SourcePositionMatcher::StripUnneededExpressionPositions( | 163 void SourcePositionMatcher::StripUnneededExpressionPositions( |
| 164 Handle<BytecodeArray> bytecode_array, | 164 Handle<BytecodeArray> bytecode_array, |
| 165 std::vector<PositionTableEntry>* expression_positions, | 165 std::vector<PositionTableEntry>* expression_positions, |
| 166 int next_statement_bytecode_offset) { | 166 int next_statement_bytecode_offset) { |
| 167 size_t j = 0; | 167 size_t j = 0; |
| 168 for (size_t i = 0; i < expression_positions->size(); ++i) { | 168 for (size_t i = 0; i < expression_positions->size(); ++i) { |
| 169 CHECK(expression_positions->at(i).source_position > 0 && | 169 CHECK(expression_positions->at(i).source_position > 0 && |
| 170 !expression_positions->at(i).is_statement); | 170 !expression_positions->at(i).is_statement); |
| 171 int bytecode_end = (i == expression_positions->size() - 1) | 171 int bytecode_end = (i == expression_positions->size() - 1) |
| 172 ? next_statement_bytecode_offset | 172 ? next_statement_bytecode_offset |
| 173 : expression_positions->at(i + 1).bytecode_offset; | 173 : expression_positions->at(i + 1).code_offset; |
| 174 if (ExpressionPositionIsNeeded(bytecode_array, | 174 if (ExpressionPositionIsNeeded(bytecode_array, |
| 175 expression_positions->at(i).bytecode_offset, | 175 expression_positions->at(i).code_offset, |
| 176 bytecode_end)) { | 176 bytecode_end)) { |
| 177 expression_positions->at(j++) = expression_positions->at(i); | 177 expression_positions->at(j++) = expression_positions->at(i); |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 expression_positions->resize(j); | 180 expression_positions->resize(j); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void SourcePositionMatcher::AdvanceBytecodeIterator( | 183 void SourcePositionMatcher::AdvanceBytecodeIterator( |
| 184 BytecodeArrayIterator* iterator, int bytecode_offset) { | 184 BytecodeArrayIterator* iterator, int bytecode_offset) { |
| 185 while (iterator->current_offset() != bytecode_offset) { | 185 while (iterator->current_offset() != bytecode_offset) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 206 | 206 |
| 207 void SourcePositionMatcher::MoveToNextStatement( | 207 void SourcePositionMatcher::MoveToNextStatement( |
| 208 SourcePositionTableIterator* iterator, | 208 SourcePositionTableIterator* iterator, |
| 209 std::vector<PositionTableEntry>* positions) { | 209 std::vector<PositionTableEntry>* positions) { |
| 210 iterator->Advance(); | 210 iterator->Advance(); |
| 211 positions->clear(); | 211 positions->clear(); |
| 212 while (!iterator->done()) { | 212 while (!iterator->done()) { |
| 213 if (iterator->is_statement()) { | 213 if (iterator->is_statement()) { |
| 214 break; | 214 break; |
| 215 } | 215 } |
| 216 positions->push_back({iterator->bytecode_offset(), | 216 positions->push_back({iterator->code_offset(), iterator->source_position(), |
| 217 iterator->source_position(), | |
| 218 iterator->is_statement()}); | 217 iterator->is_statement()}); |
| 219 iterator->Advance(); | 218 iterator->Advance(); |
| 220 } | 219 } |
| 221 } | 220 } |
| 222 | 221 |
| 223 } // namespace interpreter | 222 } // namespace interpreter |
| 224 } // namespace internal | 223 } // namespace internal |
| 225 } // namespace v8 | 224 } // namespace v8 |
| OLD | NEW |