Add sub-controls for Hack array compat runtime checks
[hiphop-php.git] / hphp / runtime / base / apc-object.h
blob8d1e80b7a6f1c63d326b37ea71dff1af72edbd26
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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_
20 #include <cinttypes>
22 #include "hphp/util/either.h"
23 #include "hphp/runtime/base/apc-string.h"
24 #include "hphp/runtime/base/type-string.h"
26 namespace HPHP {
28 //////////////////////////////////////////////////////////////////////
30 struct ObjectData;
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.
42 struct APCObject {
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 assert(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 assert(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; }
78 private:
79 struct Prop {
80 StringData* name;
81 APCHandle* val;
82 Either<const Class*,const StringData*> ctx;
85 private:
86 explicit APCObject(ClassOrName cls, uint32_t propCount);
87 ~APCObject();
88 APCObject(const APCObject&) = delete;
89 APCObject& operator=(const APCObject&) = delete;
91 private:
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();
110 private:
111 APCHandle m_handle;
112 ClassOrName m_cls;
113 uint32_t m_propCount;
114 uint8_t m_persistent:1;
115 uint8_t m_no_wakeup:1;
116 uint8_t m_fast_init:1;
119 //////////////////////////////////////////////////////////////////////
123 #endif