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

Side by Side Diff: src/source-position.h

Issue 2451853002: Uniform and precise source positions for inlining (Closed)
Patch Set: fixed PodArray::copy_out Created 4 years, 1 month 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 #ifndef V8_SOURCE_POSITION_H_ 5 #ifndef V8_SOURCE_POSITION_H_
6 #define V8_SOURCE_POSITION_H_ 6 #define V8_SOURCE_POSITION_H_
7 7
8 #include <ostream> 8 #include <ostream>
9 9
10 #include "src/flags.h" 10 #include "src/flags.h"
11 #include "src/globals.h" 11 #include "src/globals.h"
12 #include "src/handles.h"
12 #include "src/utils.h" 13 #include "src/utils.h"
13 14
14 namespace v8 { 15 namespace v8 {
15 namespace internal { 16 namespace internal {
16 17
17 // This class encapsulates encoding and decoding of sources positions from 18 class SharedFunctionInfo;
vogelheim 2016/11/04 10:57:41 nitpick: Code < Comp... < Script < SharedFunc...
18 // which hydrogen values originated. 19 class Code;
19 // When FLAG_track_hydrogen_positions is set this object encodes the 20 class CompilationInfo;
20 // identifier of the inlining and absolute offset from the start of the 21 class Script;
21 // inlined function. 22
22 // When the flag is not set we simply track absolute offset from the 23 struct SourcePositionInfo;
23 // script start. 24
24 class SourcePosition { 25 class SourcePosition final {
vogelheim 2016/11/04 10:57:41 Please add a one-line comment on what this class d
Tobias Tebbi 2016/11/07 15:10:34 It has a proper interpretation (unknown position i
25 public: 26 public:
26 static SourcePosition Unknown() { 27 explicit SourcePosition(int script_offset = kNoSourcePosition,
27 return SourcePosition::FromRaw(kNoPosition); 28 int inlining_id = kNotInlined)
29 : value_(0) {
30 SetScriptOffset(script_offset);
31 SetInliningId(inlining_id);
28 } 32 }
29 33
30 bool IsUnknown() const { return value_ == kNoPosition; } 34 static SourcePosition Unknown() { return SourcePosition(); }
35 bool IsUnknown() const { return !IsKnown(); }
36 bool IsKnown() const { return ScriptOffset() != kNoSourcePosition; }
vogelheim 2016/11/04 10:57:41 I'm confused.... The CL comment says, "If SourcePo
vogelheim 2016/11/04 10:57:42 Naming (likely connected to my confusion above):
31 37
32 uint32_t position() const { return PositionField::decode(value_); } 38 SourcePositionInfo Info(Handle<SharedFunctionInfo> script) const;
33 void set_position(uint32_t position) { 39 std::vector<SourcePositionInfo> Info(Handle<Code> code) const;
34 if (FLAG_hydrogen_track_positions) { 40 std::vector<SourcePositionInfo> Info(CompilationInfo* code) const;
35 value_ = static_cast<uint32_t>(PositionField::update(value_, position)); 41
42 void Print(std::ostream& out, Code* function) const;
43
44 int ScriptOffset() const { return ScriptOffsetField::decode(value_) - 1; }
45 int InliningId() const { return InliningIdField::decode(value_) - 1; }
46
47 void SetScriptOffset(int script_offset) {
48 if (script_offset >= ScriptOffsetField::kMax)
49 script_offset = kNoSourcePosition;
vogelheim 2016/11/04 10:57:41 What does this if statement guard against? Should
50 DCHECK(script_offset >= kNoSourcePosition);
51 value_ = ScriptOffsetField::update(value_, script_offset + 1);
52 }
53 void SetInliningId(int inlining_id) {
54 if (inlining_id >= InliningIdField::kMax) inlining_id = kNotInlined;
vogelheim 2016/11/04 10:57:41 ... as above. Also, if kNotInlined has a specific
55 DCHECK(inlining_id >= kNotInlined);
56 value_ = InliningIdField::update(value_, inlining_id + 1);
57 }
58
59 // This encodes a SourcePosition in two non-overlapping 32bit integer ranges.
60 // The encoding is used for the RelocInfo.
vogelheim 2016/11/04 10:57:42 Why the requirement of "non-overlapping" ints? Fro
vogelheim 2016/11/04 10:57:42 If this is specifically about 32bit integers, why
Yang 2016/11/04 14:32:59 I would also suggest using uint32_t
Tobias Tebbi 2016/11/07 15:10:34 I don't have a very good reason to do this indeed,
61 int EncodeScriptOffset() { return ScriptOffset() + 2; }
vogelheim 2016/11/04 10:57:41 const function? (also below)
vogelheim 2016/11/04 10:57:41 Super nitpick, but you're technically constraining
62 int EncodeInliningId() { return -(InliningId() + 2); }
63 void Decode(int enc) {
64 if (enc > 0) {
65 SetScriptOffset(enc - 2);
36 } else { 66 } else {
37 value_ = position; 67 DCHECK(enc < 0);
68 SetInliningId(-enc - 2);
38 } 69 }
39 } 70 }
40 71
41 uint32_t inlining_id() const { return InliningIdField::decode(value_); } 72 static const int kNotInlined = -1;
42 void set_inlining_id(uint32_t inlining_id) { 73 STATIC_ASSERT(kNoSourcePosition == -1);
43 if (FLAG_hydrogen_track_positions) {
44 value_ =
45 static_cast<uint32_t>(InliningIdField::update(value_, inlining_id));
46 }
47 }
48 74
49 uint32_t raw() const { return value_; } 75 uint64_t raw() const { return value_; }
50 76 static SourcePosition FromRaw(uint64_t raw) {
51 private:
52 static const uint32_t kNoPosition = static_cast<uint32_t>(kNoSourcePosition);
53 typedef BitField<uint32_t, 0, 9> InliningIdField;
54
55 // Offset from the start of the inlined function.
56 typedef BitField<uint32_t, 9, 23> PositionField;
57
58 friend class HPositionInfo;
59 friend class Deoptimizer;
60
61 static SourcePosition FromRaw(uint32_t raw_position) {
62 SourcePosition position; 77 SourcePosition position;
63 position.value_ = raw_position; 78 position.value_ = raw;
64 return position; 79 return position;
65 } 80 }
66 81
67 // If FLAG_hydrogen_track_positions is set contains bitfields InliningIdField 82 private:
68 // and PositionField. 83 void Print(std::ostream& out) const;
69 // Otherwise contains absolute offset from the script start. 84 void Print(std::ostream& out, SharedFunctionInfo* function) const;
70 uint32_t value_; 85
86 // InliningId is in the high bits for better compression in
87 // SourcePositionTable.
88 typedef BitField64<int, 0, 31> ScriptOffsetField;
89 typedef BitField64<int, 31, 16> InliningIdField;
90 // Leaving the highest bit untouched to allow for signed conversion.
91 uint64_t value_;
71 }; 92 };
72 93
73 inline std::ostream& operator<<(std::ostream& os, const SourcePosition& p) { 94 inline bool operator==(const SourcePosition& lhs, const SourcePosition& rhs) {
74 if (p.IsUnknown()) { 95 return lhs.raw() == rhs.raw();
75 return os << "<?>";
76 } else if (FLAG_hydrogen_track_positions) {
77 return os << "<" << p.inlining_id() << ":" << p.position() << ">";
78 } else {
79 return os << "<0:" << p.raw() << ">";
80 }
81 } 96 }
82 97
98 inline bool operator!=(const SourcePosition& lhs, const SourcePosition& rhs) {
99 return !(lhs == rhs);
100 }
101
102 struct InliningPosition {
103 // position of the inlined call
104 SourcePosition position;
105
106 // references position in DeoptimizationInputData::literals()
107 int inlined_function_id;
vogelheim 2016/11/04 10:57:42 What's the difference/relationship between inlined
Yang 2016/11/04 14:32:59 I'm also surprised that this needs to be an additi
Tobias Tebbi 2016/11/07 15:10:34 DeoptimizationInputData::literals() can have diffe
108 };
109
110 struct SourcePositionInfo {
111 explicit SourcePositionInfo(SourcePosition position) : position(position) {}
vogelheim 2016/11/04 10:57:41 Ah.... honestly unsure about the C++ subtleties he
Yang 2016/11/04 14:32:59 Yeah. Let's rename the parameter here for readabil
112
113 SourcePosition position;
114 MaybeHandle<SharedFunctionInfo> function;
115 int line = -1;
116 int column = -1;
117 };
118
119 std::ostream& operator<<(std::ostream& out, const SourcePosition& pos);
120
121 std::ostream& operator<<(std::ostream& out, const SourcePositionInfo& pos);
122 std::ostream& operator<<(std::ostream& out,
123 const std::vector<SourcePositionInfo>& stack);
124
83 } // namespace internal 125 } // namespace internal
84 } // namespace v8 126 } // namespace v8
85 127
86 #endif // V8_SOURCE_POSITION_H_ 128 #endif // V8_SOURCE_POSITION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698