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 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_REF_DATA_H
18 #define incl_HPHP_REF_DATA_H
20 #include "hphp/runtime/base/countable.h"
21 #include "hphp/runtime/base/memory-manager.h"
22 #include "hphp/runtime/base/typed-value.h"
29 * We heap allocate a RefData when we make a reference to something.
30 * A Variant or TypedValue can be KindOfRef and point to a RefData,
31 * but the value held here must not be KindOfRef.
33 * Note that a RefData should never contain KindOfUninit.
35 struct RefData final
: Countable
, type_scan::MarkScannableCollectable
<RefData
> {
37 * Create a RefData, allocated in the request local heap.
39 static RefData
* Make(Cell v
) {
40 assertx(cellIsPlausible(v
));
41 return new (tl_heap
->objMalloc(sizeof(RefData
)))
42 RefData(v
.m_type
, v
.m_data
.num
);
48 * Deallocate a RefData.
50 void release() noexcept
{
51 assertx(kindIsValid());
53 tl_heap
->objFree(this, sizeof(RefData
));
54 AARCH64_WALKABLE_FRAME();
57 ALWAYS_INLINE
void decRefAndRelease() {
58 assertx(kindIsValid());
59 if (decReleaseCheck()) release();
61 bool kindIsValid() const { return m_kind
== HeaderKind::Ref
; }
64 * This can never return a non-Cell.
66 const Cell
* cell() const {
67 assertx(kindIsValid());
68 assertx(cellIsPlausible(m_cell
));
73 assertx(kindIsValid());
77 const Variant
* var() const {
78 return reinterpret_cast<const Variant
*>(cell());
81 return reinterpret_cast<Variant
*>(cell());
84 static constexpr int cellOffset() { return offsetof(RefData
, m_cell
); }
86 void assertValid() const { assertx(kindIsValid()); }
88 bool isReferenced() const {
89 assertx(kindIsValid());
90 return hasMultipleRefs();
94 RefData(DataType t
, int64_t datum
) {
95 // Initialize this value by laundering uninitNull -> Null.
97 initHeader_16(HeaderKind::Ref
, OneReference
, 0);
100 m_cell
.m_data
.num
= datum
;
102 m_cell
.m_type
= KindOfNull
;
110 ALWAYS_INLINE
void decRefRef(RefData
* ref
) {
111 ref
->decRefAndRelease();
116 #endif //incl_HPHP_REF_DATA_H