forked from facebook/hhvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcls-cns-profile.cpp
More file actions
86 lines (69 loc) · 2.88 KB
/
Copy pathcls-cns-profile.cpp
File metadata and controls
86 lines (69 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#include "hphp/runtime/vm/jit/cls-cns-profile.h"
#include "hphp/runtime/base/type-variant.h"
#include "hphp/runtime/vm/class.h"
#include "hphp/util/assertions.h"
#include <folly/Format.h>
#include <string>
namespace HPHP::jit {
///////////////////////////////////////////////////////////////////////////////
namespace {
Slot updateSlot(Slot curSlot, Slot newSlot) {
if (newSlot == kInvalidSlot || curSlot == kInvalidSlot) return kInvalidSlot;
if (!curSlot) return newSlot + 1;
if (curSlot != newSlot + 1) return kInvalidSlot;
return curSlot;
}
}
TypedValue ClsCnsProfile::reportClsCns(const Class* cls,
const StringData* cnsName) {
Slot slot;
auto const tv = cls->cnsNameToTV(cnsName, slot);
if (slot == kInvalidSlot) return make_tv<KindOfUninit>();
m_curSlot = updateSlot(m_curSlot, slot);
if (!tv) return make_tv<KindOfUninit>();
return tv->m_type != KindOfUninit ? *tv : cls->clsCnsGet(cnsName);
}
void ClsCnsProfile::reduce(ClsCnsProfile& a, const ClsCnsProfile& b) {
if (a.m_curSlot == kInvalidSlot || !b.m_curSlot) return;
if (b.m_curSlot == kInvalidSlot) {
a.m_curSlot = kInvalidSlot;
return;
}
if (!a.m_curSlot) {
a.m_curSlot = b.m_curSlot;
return;
}
if (a.m_curSlot != b.m_curSlot) {
a.m_curSlot = kInvalidSlot;
return;
}
}
std::string ClsCnsProfile::toString() const {
if (!m_curSlot) return "empty";
if (m_curSlot == kInvalidSlot) return "InvalidSlot";
return folly::sformat("Slot {}", getSlot());
}
folly::dynamic ClsCnsProfile::toDynamic() const {
if (!m_curSlot) return folly::dynamic();
return folly::dynamic::object("slot", m_curSlot == kInvalidSlot ?
folly::dynamic() :
getSlot())
("profileType", "ClsCnsProfile");
}
///////////////////////////////////////////////////////////////////////////////
}