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_APC_OBJECT_H_
18 #define incl_HPHP_APC_OBJECT_H_
22 #include "hphp/util/either.h"
23 #include "hphp/runtime/base/apc-string.h"
24 #include "hphp/runtime/base/type-string.h"
28 //////////////////////////////////////////////////////////////////////
32 //////////////////////////////////////////////////////////////////////
35 * Representation of an object stored in APC.
37 * It may also have a serialized form in which case it will be represented by
38 * an APCString instance with type KindOfObject.
40 * MakeObject and Delete take care of isolating callers from that detail.
43 using ClassOrName
= Either
<const Class
*,const StringData
*>;
46 * Create an APCObject from an ObjectData*; returns its APCHandle.
48 static APCHandle::Pair
Construct(ObjectData
* data
);
50 // Return an APCObject instance from a serialized version of the
51 // object. May return null.
52 static APCHandle::Pair
MakeAPCObject(APCHandle
* obj
, const Variant
& value
);
54 // Return an instance of a PHP object from the given object handle
55 static Variant
MakeLocalObject(const APCHandle
* handle
);
57 static void Delete(APCHandle
* handle
);
59 static APCObject
* fromHandle(APCHandle
* handle
) {
60 assertx(handle
->checkInvariants() &&
61 handle
->kind() == APCKind::SharedObject
);
62 static_assert(offsetof(APCObject
, m_handle
) == 0, "");
63 return reinterpret_cast<APCObject
*>(handle
);
66 static const APCObject
* fromHandle(const APCHandle
* handle
) {
67 assertx(handle
->checkInvariants() &&
68 handle
->kind() == APCKind::SharedObject
);
69 static_assert(offsetof(APCObject
, m_handle
) == 0, "");
70 return reinterpret_cast<const APCObject
*>(handle
);
73 APCHandle
* getHandle() { return &m_handle
; }
74 const APCHandle
* getHandle() const { return &m_handle
; }
76 bool isPersistent() const { return m_persistent
; }
82 Either
<const Class
*,const StringData
*> ctx
;
86 explicit APCObject(ClassOrName cls
, uint32_t propCount
);
88 APCObject(const APCObject
&) = delete;
89 APCObject
& operator=(const APCObject
&) = delete;
92 static APCHandle::Pair
ConstructSlow(ObjectData
* data
, ClassOrName name
);
94 friend size_t getMemSize(const APCObject
*);
95 Object
createObject() const;
96 Object
createObjectSlow() const;
98 Prop
* props() { return reinterpret_cast<Prop
*>(this + 1); }
99 const Prop
* props() const {
100 return const_cast<APCObject
*>(this)->props();
103 APCHandle
** persistentProps() {
104 return reinterpret_cast<APCHandle
**>(this + 1);
106 const APCHandle
* const * persistentProps() const {
107 return const_cast<APCObject
*>(this)->persistentProps();
113 uint32_t m_propCount
;
114 uint8_t m_persistent
:1;
115 uint8_t m_no_wakeup
:1;
116 uint8_t m_no_verify_prop_types
:1;
119 //////////////////////////////////////////////////////////////////////