 Chromium Code Reviews
 Chromium Code Reviews Issue 2451853002:
  Uniform and precise source positions for inlining  (Closed)
    
  
    Issue 2451853002:
  Uniform and precise source positions for inlining  (Closed) 
  | 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/v8.h" | 5 #include "src/v8.h" | 
| 6 | 6 | 
| 7 #include "src/objects.h" | 7 #include "src/objects.h" | 
| 8 #include "src/source-position-table.h" | 8 #include "src/source-position-table.h" | 
| 9 #include "test/unittests/test-utils.h" | 9 #include "test/unittests/test-utils.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 SourcePositionTableTest : public TestWithIsolateAndZone { | 15 class SourcePositionTableTest : public TestWithIsolateAndZone { | 
| 16 public: | 16 public: | 
| 17 SourcePositionTableTest() {} | 17 SourcePositionTableTest() {} | 
| 18 ~SourcePositionTableTest() override {} | 18 ~SourcePositionTableTest() override {} | 
| 19 | |
| 20 SourcePosition toPos(int offset) { | |
| 
vogelheim
2016/11/07 17:53:27
const
 | |
| 21 return SourcePosition(offset, offset % 10 - 1); | |
| 22 } | |
| 19 }; | 23 }; | 
| 20 | 24 | 
| 21 // Some random offsets, mostly at 'suspicious' bit boundaries. | 25 // Some random offsets, mostly at 'suspicious' bit boundaries. | 
| 22 static int offsets[] = {0, 1, 2, 3, 4, 30, 31, 32, | 26 static int offsets[] = {0, 1, 2, 3, 4, 30, 31, 32, | 
| 23 33, 62, 63, 64, 65, 126, 127, 128, | 27 33, 62, 63, 64, 65, 126, 127, 128, | 
| 24 129, 250, 1000, 9999, 12000, 31415926}; | 28 129, 250, 1000, 9999, 12000, 31415926}; | 
| 25 | 29 | 
| 26 TEST_F(SourcePositionTableTest, EncodeStatement) { | 30 TEST_F(SourcePositionTableTest, EncodeStatement) { | 
| 27 SourcePositionTableBuilder builder(zone()); | 31 SourcePositionTableBuilder builder(zone()); | 
| 28 for (int i = 0; i < arraysize(offsets); i++) { | 32 for (int i = 0; i < arraysize(offsets); i++) { | 
| 29 builder.AddPosition(offsets[i], offsets[i], true); | 33 builder.AddPosition(offsets[i], toPos(offsets[i]), true); | 
| 30 } | 34 } | 
| 31 | 35 | 
| 32 // To test correctness, we rely on the assertions in ToSourcePositionTable(). | 36 // To test correctness, we rely on the assertions in ToSourcePositionTable(). | 
| 33 // (Also below.) | 37 // (Also below.) | 
| 34 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>()) | 38 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>()) | 
| 35 .is_null()); | 39 .is_null()); | 
| 36 } | 40 } | 
| 37 | 41 | 
| 38 TEST_F(SourcePositionTableTest, EncodeStatementDuplicates) { | 42 TEST_F(SourcePositionTableTest, EncodeStatementDuplicates) { | 
| 39 SourcePositionTableBuilder builder(zone()); | 43 SourcePositionTableBuilder builder(zone()); | 
| 40 for (int i = 0; i < arraysize(offsets); i++) { | 44 for (int i = 0; i < arraysize(offsets); i++) { | 
| 41 builder.AddPosition(offsets[i], offsets[i], true); | 45 builder.AddPosition(offsets[i], toPos(offsets[i]), true); | 
| 42 builder.AddPosition(offsets[i], offsets[i] + 1, true); | 46 builder.AddPosition(offsets[i], toPos(offsets[i] + 1), true); | 
| 43 } | 47 } | 
| 44 | 48 | 
| 45 // To test correctness, we rely on the assertions in ToSourcePositionTable(). | 49 // To test correctness, we rely on the assertions in ToSourcePositionTable(). | 
| 46 // (Also below.) | 50 // (Also below.) | 
| 47 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>()) | 51 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>()) | 
| 48 .is_null()); | 52 .is_null()); | 
| 49 } | 53 } | 
| 50 | 54 | 
| 51 TEST_F(SourcePositionTableTest, EncodeExpression) { | 55 TEST_F(SourcePositionTableTest, EncodeExpression) { | 
| 52 SourcePositionTableBuilder builder(zone()); | 56 SourcePositionTableBuilder builder(zone()); | 
| 53 for (int i = 0; i < arraysize(offsets); i++) { | 57 for (int i = 0; i < arraysize(offsets); i++) { | 
| 54 builder.AddPosition(offsets[i], offsets[i], false); | 58 builder.AddPosition(offsets[i], toPos(offsets[i]), false); | 
| 55 } | 59 } | 
| 56 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>()) | 60 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>()) | 
| 57 .is_null()); | 61 .is_null()); | 
| 58 } | 62 } | 
| 59 | 63 | 
| 60 TEST_F(SourcePositionTableTest, EncodeAscending) { | 64 TEST_F(SourcePositionTableTest, EncodeAscending) { | 
| 61 SourcePositionTableBuilder builder(zone()); | 65 SourcePositionTableBuilder builder(zone()); | 
| 62 | 66 | 
| 63 int code_offset = 0; | 67 int code_offset = 0; | 
| 64 int source_position = 0; | 68 int source_position = 0; | 
| 65 for (int i = 0; i < arraysize(offsets); i++) { | 69 for (int i = 0; i < arraysize(offsets); i++) { | 
| 66 code_offset += offsets[i]; | 70 code_offset += offsets[i]; | 
| 67 source_position += offsets[i]; | 71 source_position += offsets[i]; | 
| 68 if (i % 2) { | 72 if (i % 2) { | 
| 69 builder.AddPosition(code_offset, source_position, true); | 73 builder.AddPosition(code_offset, toPos(source_position), true); | 
| 70 } else { | 74 } else { | 
| 71 builder.AddPosition(code_offset, source_position, false); | 75 builder.AddPosition(code_offset, toPos(source_position), false); | 
| 72 } | 76 } | 
| 73 } | 77 } | 
| 74 | 78 | 
| 75 // Also test negative offsets for source positions: | 79 // Also test negative offsets for source positions: | 
| 76 for (int i = 0; i < arraysize(offsets); i++) { | 80 for (int i = 0; i < arraysize(offsets); i++) { | 
| 77 code_offset += offsets[i]; | 81 code_offset += offsets[i]; | 
| 78 source_position -= offsets[i]; | 82 source_position -= offsets[i]; | 
| 79 if (i % 2) { | 83 if (i % 2) { | 
| 80 builder.AddPosition(code_offset, source_position, true); | 84 builder.AddPosition(code_offset, toPos(source_position), true); | 
| 81 } else { | 85 } else { | 
| 82 builder.AddPosition(code_offset, source_position, false); | 86 builder.AddPosition(code_offset, toPos(source_position), false); | 
| 83 } | 87 } | 
| 84 } | 88 } | 
| 85 | 89 | 
| 86 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>()) | 90 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>()) | 
| 87 .is_null()); | 91 .is_null()); | 
| 88 } | 92 } | 
| 89 | 93 | 
| 90 } // namespace interpreter | 94 } // namespace interpreter | 
| 91 } // namespace internal | 95 } // namespace internal | 
| 92 } // namespace v8 | 96 } // namespace v8 | 
| OLD | NEW |