Move vmfp, vmsp, and vmpc into RDS
[hiphop-php.git] / hphp / runtime / ext_zend_compat / hhvm / zend-object-store.cpp
blob7c4d59f09f47c0660c56712f7f3d5095e3024b66
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 Facebook, Inc. (http://www.facebook.com) |
6 | Copyright (c) 1997-2010 The PHP Group |
7 +----------------------------------------------------------------------+
8 | This source file is subject to version 3.01 of the PHP license, |
9 | that is bundled with this package in the file LICENSE, and is |
10 | available through the world-wide-web at the following url: |
11 | http://www.php.net/license/3_01.txt |
12 | If you did not receive a copy of the PHP license and are unable to |
13 | obtain it through the world-wide-web, please send a note to |
14 | license@php.net so we can mail you a copy immediately. |
15 +----------------------------------------------------------------------+
18 #include "hphp/runtime/ext_zend_compat/hhvm/zend-object-store.h"
19 #include "hphp/runtime/vm/jit/translator-inline.h"
21 namespace HPHP {
23 __thread RequestLocal<ZendObjectStore> ZendObjectStore::tl_instance;
25 void ZendObjectStore::requestShutdown() {
26 m_store.clear();
27 m_free_list_head = 0;
30 zend_object_handle ZendObjectStore::insertObject(void *object,
31 zend_objects_store_dtor_t dtor,
32 zend_objects_free_object_storage_t free_storage,
33 zend_objects_store_clone_t clone)
35 zend_object_handle index;
36 if (m_free_list_head) {
37 index = m_free_list_head;
38 m_free_list_head = m_store.at(index).bucket.free_list.next;
39 } else {
40 index = m_store.size();
41 // Don't use handle zero
42 if (index == 0) {
43 index++;
45 m_store.resize(index + 1);
48 zend_object_store_bucket & bucket = m_store.at(index);
49 bucket.destructor_called = 0;
50 bucket.valid = 1;
51 bucket.apply_count = 0;
53 auto & obj = bucket.bucket.obj;
54 obj.refcount = 1; // unused
55 obj.object = object;
56 obj.dtor = dtor; // unused
57 obj.free_storage = free_storage;
58 obj.clone = clone;
59 obj.handlers = nullptr; // unused
60 return index;
64 void * ZendObjectStore::getObject(zend_object_handle handle) {
65 return m_store.at(handle).bucket.obj.object;
68 void ZendObjectStore::freeObject(zend_object_handle handle) {
69 zend_object_store_bucket & bucket = m_store.at(handle);
70 assert(bucket.valid);
71 auto & obj = bucket.bucket.obj;
73 if (obj.free_storage) {
74 TSRMLS_FETCH();
75 HPHP::VMRegAnchor _;
76 obj.free_storage(obj.object TSRMLS_CC);
79 bucket.bucket.free_list.next = m_free_list_head;
80 m_free_list_head = handle;
81 bucket.valid = 0;
84 zend_object_handle ZendObjectStore::cloneObject(zend_object_handle handle) {
85 TSRMLS_FETCH();
86 zend_object_store_bucket & bucket = m_store.at(handle);
87 assert(bucket.valid);
88 auto & obj = bucket.bucket.obj;
89 if (obj.clone == nullptr) {
90 return 0;
92 void * new_object = nullptr;
93 obj.clone(obj.object, &new_object TSRMLS_CC);
94 assert(bucket.valid);
95 return insertObject(new_object, obj.dtor, obj.free_storage, obj.clone);