Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef V8_SOURCE_POSITION_H_ | |
| 6 #define V8_SOURCE_POSITION_H_ | |
|
Benedikt Meurer
2016/01/15 11:38:49
Can you include the necessary headers here?
Michael Starzinger
2016/01/15 11:46:03
Done. Ooops, oversight.
| |
| 7 | |
| 8 namespace v8 { | |
| 9 namespace internal { | |
| 10 | |
| 11 // This class encapsulates encoding and decoding of sources positions from | |
| 12 // which hydrogen values originated. | |
| 13 // When FLAG_track_hydrogen_positions is set this object encodes the | |
| 14 // identifier of the inlining and absolute offset from the start of the | |
| 15 // inlined function. | |
| 16 // When the flag is not set we simply track absolute offset from the | |
| 17 // script start. | |
| 18 class SourcePosition { | |
| 19 public: | |
| 20 static SourcePosition Unknown() { | |
| 21 return SourcePosition::FromRaw(kNoPosition); | |
| 22 } | |
| 23 | |
| 24 bool IsUnknown() const { return value_ == kNoPosition; } | |
| 25 | |
| 26 uint32_t position() const { return PositionField::decode(value_); } | |
| 27 void set_position(uint32_t position) { | |
| 28 if (FLAG_hydrogen_track_positions) { | |
| 29 value_ = static_cast<uint32_t>(PositionField::update(value_, position)); | |
| 30 } else { | |
| 31 value_ = position; | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 uint32_t inlining_id() const { return InliningIdField::decode(value_); } | |
| 36 void set_inlining_id(uint32_t inlining_id) { | |
| 37 if (FLAG_hydrogen_track_positions) { | |
| 38 value_ = | |
| 39 static_cast<uint32_t>(InliningIdField::update(value_, inlining_id)); | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 uint32_t raw() const { return value_; } | |
| 44 | |
| 45 private: | |
| 46 static const uint32_t kNoPosition = | |
| 47 static_cast<uint32_t>(RelocInfo::kNoPosition); | |
| 48 typedef BitField<uint32_t, 0, 9> InliningIdField; | |
| 49 | |
| 50 // Offset from the start of the inlined function. | |
| 51 typedef BitField<uint32_t, 9, 23> PositionField; | |
| 52 | |
| 53 friend class HPositionInfo; | |
| 54 friend class Deoptimizer; | |
| 55 | |
| 56 static SourcePosition FromRaw(uint32_t raw_position) { | |
| 57 SourcePosition position; | |
| 58 position.value_ = raw_position; | |
| 59 return position; | |
| 60 } | |
| 61 | |
| 62 // If FLAG_hydrogen_track_positions is set contains bitfields InliningIdField | |
| 63 // and PositionField. | |
| 64 // Otherwise contains absolute offset from the script start. | |
| 65 uint32_t value_; | |
| 66 }; | |
| 67 | |
| 68 inline std::ostream& operator<<(std::ostream& os, const SourcePosition& p) { | |
| 69 if (p.IsUnknown()) { | |
| 70 return os << "<?>"; | |
| 71 } else if (FLAG_hydrogen_track_positions) { | |
| 72 return os << "<" << p.inlining_id() << ":" << p.position() << ">"; | |
| 73 } else { | |
| 74 return os << "<0:" << p.raw() << ">"; | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 } // namespace internal | |
| 79 } // namespace v8 | |
| 80 | |
| 81 #endif // V8_SOURCE_POSITION_H_ | |
| OLD | NEW |