2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
16 #ifndef incl_HPHP_SRCKEY_H_
17 #define incl_HPHP_SRCKEY_H_
19 #include "hphp/runtime/vm/hhbc.h"
20 #include "hphp/runtime/vm/resumable.h"
22 #include <boost/operators.hpp>
26 ///////////////////////////////////////////////////////////////////////////////
28 namespace arrprov
{ struct Tag
; }
33 ///////////////////////////////////////////////////////////////////////////////
36 * A SrcKey is a logical source instruction---it's enough to identify
37 * these using a (Func id, hhbc instruction) pair.
39 struct SrcKey
: private boost::totally_ordered
<SrcKey
> {
40 static_assert(sizeof(FuncId
) == sizeof(uint32_t), "");
41 static_assert(sizeof(Offset
) == sizeof(uint32_t), "");
43 /////////////////////////////////////////////////////////////////////////////
46 using AtomicInt
= uint64_t;
49 struct TbbHashCompare
;
52 * Used for SrcKeys corresponding to the prologue which precedes a function
53 * entry source location.
55 * Used disjointly from the `resumeMode'.
57 enum class PrologueTag
{};
59 /////////////////////////////////////////////////////////////////////////////
62 * Invalid SrcKey constructor.
66 SrcKey(const Func
* f
, Offset off
, ResumeMode resumeMode
);
67 SrcKey(const Func
* f
, PC pc
, ResumeMode resumeMode
);
68 SrcKey(FuncId funcId
, Offset off
, ResumeMode resumeMode
);
70 SrcKey(const Func
* f
, Offset off
, PrologueTag
);
71 SrcKey(const Func
* f
, PC pc
, PrologueTag
);
72 SrcKey(FuncId funcId
, Offset off
, PrologueTag
);
74 SrcKey(SrcKey other
, Offset off
);
76 explicit SrcKey(AtomicInt in
);
77 static SrcKey
fromAtomicInt(AtomicInt in
);
79 /////////////////////////////////////////////////////////////////////////////
82 * Whether the SrcKey has a valid FuncId.
84 * Does not check for validity of any other fields.
89 * Packed representation of SrcKeys for use in contexts (e.g. the SrcDB)
90 * where we want atomicity.
92 AtomicInt
toAtomicInt() const;
97 FuncId
funcID() const;
99 bool prologue() const;
100 ResumeMode
resumeMode() const;
101 bool hasThis() const;
106 const Func
* func() const;
107 const Unit
* unit() const;
111 /////////////////////////////////////////////////////////////////////////////
114 * Set this SrcKey's offset.
116 * Does not perform any bounds or consistency checks.
118 void setOffset(Offset o
);
121 * Get all possible Offsets for the next bytecode.
123 OffsetSet
succOffsets() const;
126 * Advance the SrcKey to the next instruction.
128 * If the SrcKey points to the last instruction in a function, this will
129 * advance past the end of the function, and potentially contain an invalid
132 void advance(const Unit
* u
= nullptr);
135 * Return a SrcKey representing the next instruction, without mutating this
138 SrcKey
advanced(const Unit
* u
= nullptr) const;
140 /////////////////////////////////////////////////////////////////////////////
145 * SrcKeys are ordered by their AtomicInt values.
147 bool operator==(const SrcKey
& r
) const;
148 bool operator<(const SrcKey
& r
) const;
153 std::string
showInst() const;
154 std::string
getSymbol() const;
156 /////////////////////////////////////////////////////////////////////////////
159 uint32_t encodeResumeMode(ResumeMode resumeMode
);
160 uint32_t encodePrologue();
162 /////////////////////////////////////////////////////////////////////////////
165 AtomicInt m_atomicInt
;
168 uint32_t m_offset
: 30;
169 uint32_t m_resumeModeAndPrologue
: 2;
174 ///////////////////////////////////////////////////////////////////////////////
176 struct SrcKey::Hasher
{
177 size_t operator()(SrcKey sk
) const {
178 return hash_int64(sk
.toAtomicInt());
182 using SrcKeySet
= hphp_hash_set
<SrcKey
,SrcKey::Hasher
>;
184 ///////////////////////////////////////////////////////////////////////////////
186 struct SrcKey::TbbHashCompare
{
187 static size_t hash(const SrcKey
& sk
) { return hash_int64(sk
.toAtomicInt()); }
188 static bool equal(const SrcKey
& a
, const SrcKey
& b
) { return a
== b
; }
191 ///////////////////////////////////////////////////////////////////////////////
193 std::string
show(SrcKey sk
);
194 std::string
showShort(SrcKey sk
);
196 void sktrace(SrcKey sk
, ATTRIBUTE_PRINTF_STRING
const char *fmt
, ...)
197 ATTRIBUTE_PRINTF(2,3);
198 #define SKTRACE(level, sk, ...) \
199 ONTRACE(level, sktrace(sk, __VA_ARGS__))
201 ///////////////////////////////////////////////////////////////////////////////
205 #include "hphp/runtime/vm/srckey-inl.h"