Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: src/interpreter/source-position-table.cc

Issue 1668863002: [interpreter] source positions should not be emitted for dead code. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/assembler.h" 7 #include "src/assembler.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
11 namespace v8 { 11 namespace v8 {
12 namespace internal { 12 namespace internal {
13 namespace interpreter { 13 namespace interpreter {
14 14
15 class IsStatementField : public BitField<bool, 0, 1> {}; 15 class IsStatementField : public BitField<bool, 0, 1> {};
16 class SourcePositionField : public BitField<int, 1, 30> {}; 16 class SourcePositionField : public BitField<int, 1, 30> {};
17 17
18 void SourcePositionTableBuilder::AddStatementPosition(int bytecode_offset, 18 void SourcePositionTableBuilder::AddStatementPosition(size_t bytecode_offset,
19 int source_position) { 19 int source_position) {
20 AssertMonotonic(bytecode_offset); 20 int offset = static_cast<int>(bytecode_offset);
21 AssertMonotonic(offset);
21 uint32_t encoded = IsStatementField::encode(true) | 22 uint32_t encoded = IsStatementField::encode(true) |
22 SourcePositionField::encode(source_position); 23 SourcePositionField::encode(source_position);
23 entries_.push_back({bytecode_offset, encoded}); 24 entries_.push_back({offset, encoded});
24 } 25 }
25 26
26 void SourcePositionTableBuilder::AddExpressionPosition(int bytecode_offset, 27 void SourcePositionTableBuilder::AddExpressionPosition(size_t bytecode_offset,
27 int source_position) { 28 int source_position) {
28 AssertMonotonic(bytecode_offset); 29 int offset = static_cast<int>(bytecode_offset);
30 AssertMonotonic(offset);
29 uint32_t encoded = IsStatementField::encode(false) | 31 uint32_t encoded = IsStatementField::encode(false) |
30 SourcePositionField::encode(source_position); 32 SourcePositionField::encode(source_position);
31 entries_.push_back({bytecode_offset, encoded}); 33 entries_.push_back({offset, encoded});
34 }
35
36 void SourcePositionTableBuilder::RevertPosition(size_t bytecode_offset) {
37 int offset = static_cast<int>(bytecode_offset);
38 // If we already added a source position table entry, but the bytecode array
39 // builder ended up not outputting a bytecode for the corresponding bytecode
40 // offset, we have to remove that entry.
41 if (entries_.size() > 0 && entries_.back().bytecode_offset == offset) {
42 entries_.pop_back();
43 }
32 } 44 }
33 45
34 Handle<FixedArray> SourcePositionTableBuilder::ToFixedArray() { 46 Handle<FixedArray> SourcePositionTableBuilder::ToFixedArray() {
35 int length = static_cast<int>(entries_.size()); 47 int length = static_cast<int>(entries_.size());
36 Handle<FixedArray> table = 48 Handle<FixedArray> table =
37 isolate_->factory()->NewFixedArray(length * 2, TENURED); 49 isolate_->factory()->NewFixedArray(length * 2, TENURED);
38 for (int i = 0; i < length; i++) { 50 for (int i = 0; i < length; i++) {
39 table->set(i * 2, Smi::FromInt(entries_[i].bytecode_offset)); 51 table->set(i * 2, Smi::FromInt(entries_[i].bytecode_offset));
40 table->set(i * 2 + 1, Smi::FromInt(entries_[i].source_position_and_type)); 52 table->set(i * 2 + 1, Smi::FromInt(entries_[i].source_position_and_type));
41 } 53 }
(...skipping 30 matching lines...) Expand all
72 !iterator.done() && iterator.bytecode_offset() <= bytecode_offset; 84 !iterator.done() && iterator.bytecode_offset() <= bytecode_offset;
73 iterator.Advance()) { 85 iterator.Advance()) {
74 last_position = iterator.source_position(); 86 last_position = iterator.source_position();
75 } 87 }
76 return last_position; 88 return last_position;
77 } 89 }
78 90
79 } // namespace interpreter 91 } // namespace interpreter
80 } // namespace internal 92 } // namespace internal
81 } // namespace v8 93 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/source-position-table.h ('k') | test/mjsunit/ignition/dead-code-source-position.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698