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_HHBBC_MISC_H_
17 #define incl_HHBBC_MISC_H_
22 #include <boost/variant.hpp>
25 #include "hphp/util/trace.h"
26 #include "hphp/util/match.h"
27 #include "hphp/util/low-ptr.h"
34 namespace HPHP
{ namespace HHBBC
{
36 //////////////////////////////////////////////////////////////////////
39 * Self-documenting type alias for pointers that aren't owned.
41 * This type is intended to imply that someone else has an owning
42 * pointer on this value which is guaranteed to live longer than this
45 template<class T
> using borrowed_ptr
= T
*;
48 borrowed_ptr
<T
> borrow(const std::unique_ptr
<T
>& p
) {
53 * String that must be a static string, and Array that must be a
56 using SString
= const StringData
*;
57 using LSString
= LowPtr
<const StringData
>;
58 using SArray
= const ArrayData
*;
61 * HHBC evaluation stack flavors.
63 enum class Flavor
{ C
, V
, R
, F
, U
, CR
, CU
, CVU
};
66 * Types of parameter preparation (or unknown).
68 enum class PrepKind
{ Ref
, Val
, Unknown
};
70 using LocalId
= uint32_t;
71 constexpr const LocalId NoLocalId
= -1;
73 * Special value used by StackElem::equivLoc to indicate that
74 * this element is a dup of the one below.
76 constexpr const LocalId StackDupId
= -2;
77 constexpr const LocalId MaxLocalId
= StackDupId
- 1;
79 using IterId
= uint32_t;
80 using ClsRefSlotId
= uint32_t;
81 constexpr const ClsRefSlotId NoClsRefSlotId
= -1;
82 using BlockId
= uint32_t;
83 constexpr const BlockId NoBlockId
= -1;
85 //////////////////////////////////////////////////////////////////////
88 * Many places in the code want to bump tracing levels by some amount
89 * for systemlib-related processing. This is the amount they all bump
92 constexpr int kSystemLibBump
= 10;
95 * Functions listed in the --trace functions list get trace level bumped by
98 constexpr int kTraceFuncBump
= -10;
101 * We may run the interpreter collecting stats and when trace is on
102 * the amount of noise is unbearable. This is to keep tracing out
103 * of stats collection.
105 constexpr int kStatsBump
= 50;
107 //////////////////////////////////////////////////////////////////////
110 using clock
= std::chrono::high_resolution_clock
;
111 using time_point
= clock::time_point
;
113 explicit trace_time(const char* what
,
114 const std::string
& extra
= std::string
{})
116 , start(clock::now())
118 if (Trace::moduleEnabledRelease(Trace::hhbbc_time
, 1)) {
121 folly::format("{}: start{}\n",
123 !extra
.empty() ? folly::format(" ({})", extra
).str() : extra
130 namespace C
= std::chrono
;
131 DEBUG_ONLY
auto const elapsed
= C::duration_cast
<C::milliseconds
>(
134 if (Trace::moduleEnabledRelease(Trace::hhbbc_time
, 1)) {
137 folly::format("{}: {}ms elapsed\n", what
, elapsed
.count())
143 trace_time(const trace_time
&) = delete;
144 trace_time
& operator=(const trace_time
&) = delete;
151 //////////////////////////////////////////////////////////////////////