Chromium Code Reviews| 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 #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; |
| 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 { |
| 25 public: | 26 public: |
| 26 static SourcePosition Unknown() { | 27 SourcePosition() = default; |
|
vogelheim
2016/10/31 17:34:40
Wouldn't this leave value_ uninitialized? That doe
| |
| 27 return SourcePosition::FromRaw(kNoPosition); | 28 |
| 29 explicit SourcePosition(int script_offset, int inlining_id = kUnknown) | |
| 30 : value_(0) { | |
| 31 SetScriptOffset(script_offset); | |
| 32 SetInliningId(inlining_id); | |
| 28 } | 33 } |
| 29 | 34 |
| 30 bool IsUnknown() const { return value_ == kNoPosition; } | 35 static SourcePosition Unknown() { return SourcePosition(); } |
| 36 bool IsUnknown() const { return !IsKnown(); } | |
| 37 bool IsKnown() const { return ScriptOffset() != kUnknown; } | |
| 31 | 38 |
| 32 uint32_t position() const { return PositionField::decode(value_); } | 39 SourcePositionInfo Info(Handle<SharedFunctionInfo> script) const; |
| 33 void set_position(uint32_t position) { | 40 std::vector<SourcePositionInfo> Info(Handle<Code> code) const; |
| 34 if (FLAG_hydrogen_track_positions) { | 41 std::vector<SourcePositionInfo> Info(CompilationInfo* code) const; |
| 35 value_ = static_cast<uint32_t>(PositionField::update(value_, position)); | 42 |
| 36 } else { | 43 void Print(std::ostream& out, Code* function) const; |
| 37 value_ = position; | 44 |
| 45 int ScriptOffset() const { return ScriptOffsetField::decode(value_) - 1; } | |
| 46 int InliningId() const { return InliningIdField::decode(value_) - 1; } | |
| 47 | |
| 48 void SetScriptOffset(int script_offset) { | |
|
vogelheim
2016/10/31 17:34:40
This claims to set the script offset, but for cert
| |
| 49 if (script_offset == kNoSourcePosition || | |
| 50 script_offset >= ScriptOffsetField::kMax) | |
| 51 script_offset = kUnknown; | |
| 52 if (script_offset != kUnknown) { | |
|
vogelheim
2016/10/31 17:34:40
Why not merge the ifs?
if (script_offset != kUnkn
| |
| 53 DCHECK(script_offset >= 0); | |
| 54 value_ = ScriptOffsetField::update(value_, script_offset + 1); | |
| 55 } | |
| 56 } | |
| 57 void SetInliningId(int inlining_id) { | |
| 58 if (inlining_id >= InliningIdField::kMax) inlining_id = kUnknown; | |
| 59 if (inlining_id != kUnknown) { | |
| 60 DCHECK(inlining_id >= 0); | |
| 61 value_ = InliningIdField::update(value_, inlining_id + 1); | |
| 38 } | 62 } |
| 39 } | 63 } |
| 40 | 64 |
| 41 uint32_t inlining_id() const { return InliningIdField::decode(value_); } | 65 int EncodeScriptOffset() { return ScriptOffset() + 2; } |
| 42 void set_inlining_id(uint32_t inlining_id) { | 66 int EncodeInliningId() { return -(InliningId() + 2); } |
|
vogelheim
2016/10/31 17:34:40
why?
| |
| 43 if (FLAG_hydrogen_track_positions) { | 67 void Decode(int enc) { |
| 44 value_ = | 68 if (enc > 0) { |
| 45 static_cast<uint32_t>(InliningIdField::update(value_, inlining_id)); | 69 SetScriptOffset(enc - 2); |
| 70 } else { | |
| 71 DCHECK(enc < 0); | |
| 72 SetInliningId(-enc - 2); | |
| 46 } | 73 } |
| 47 } | 74 } |
| 48 | 75 |
| 49 uint32_t raw() const { return value_; } | 76 static const int kUnknown = -1; |
| 77 STATIC_ASSERT(kUnknown == kNoSourcePosition); | |
| 50 | 78 |
| 51 private: | 79 uint64_t raw() const { return value_; } |
| 52 static const uint32_t kNoPosition = static_cast<uint32_t>(kNoSourcePosition); | 80 static SourcePosition FromRaw(uint64_t raw) { |
| 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; | 81 SourcePosition position; |
| 63 position.value_ = raw_position; | 82 position.value_ = raw; |
| 64 return position; | 83 return position; |
| 65 } | 84 } |
| 66 | 85 |
| 67 // If FLAG_hydrogen_track_positions is set contains bitfields InliningIdField | 86 private: |
| 68 // and PositionField. | 87 void Print(std::ostream& out) const; |
| 69 // Otherwise contains absolute offset from the script start. | 88 void Print(std::ostream& out, SharedFunctionInfo* function) const; |
| 70 uint32_t value_; | 89 |
| 90 // ids are in the hight bits for better compression in SourcePositionTable | |
|
vogelheim
2016/10/31 17:34:40
hight -> high
| |
| 91 typedef BitField64<int, 0, 31> ScriptOffsetField; | |
| 92 typedef BitField64<int, 31, 16> InliningIdField; | |
| 93 // leaving the highest bit untouched to allow for signed conversion | |
| 94 uint64_t value_; | |
| 71 }; | 95 }; |
| 72 | 96 |
| 73 inline std::ostream& operator<<(std::ostream& os, const SourcePosition& p) { | 97 inline bool operator==(const SourcePosition& lhs, const SourcePosition& rhs) { |
| 74 if (p.IsUnknown()) { | 98 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 } | 99 } |
| 82 | 100 |
| 101 inline bool operator!=(const SourcePosition& lhs, const SourcePosition& rhs) { | |
| 102 return !(lhs == rhs); | |
| 103 } | |
| 104 | |
| 105 struct InliningPosition { | |
| 106 // these two ints correspond to the fields in SourcePosition | |
|
vogelheim
2016/10/31 17:34:40
"these two ints"? I'm only seeing one int and a So
| |
| 107 SourcePosition position; | |
| 108 | |
| 109 // references position in DeoptimizationInputData::literals() | |
| 110 int inlined_function_id; | |
| 111 }; | |
| 112 | |
| 113 struct SourcePositionInfo { | |
| 114 explicit SourcePositionInfo(SourcePosition position) : position(position) {} | |
| 115 | |
| 116 SourcePosition position; | |
| 117 MaybeHandle<SharedFunctionInfo> function; | |
| 118 int line = -1; | |
| 119 int column = -1; | |
| 120 }; | |
| 121 | |
| 122 std::ostream& operator<<(std::ostream& out, const SourcePosition& pos); | |
| 123 | |
| 124 std::ostream& operator<<(std::ostream& out, const SourcePositionInfo& pos); | |
| 125 std::ostream& operator<<(std::ostream& out, | |
| 126 const std::vector<SourcePositionInfo>& stack); | |
| 127 | |
| 83 } // namespace internal | 128 } // namespace internal |
| 84 } // namespace v8 | 129 } // namespace v8 |
| 85 | 130 |
| 86 #endif // V8_SOURCE_POSITION_H_ | 131 #endif // V8_SOURCE_POSITION_H_ |
| OLD | NEW |