From a264088bf94b962ae8a622919638183e857a7d82 Mon Sep 17 00:00:00 2001 From: Rick Lavoie Date: Tue, 7 Jul 2015 07:26:26 -0700 Subject: [PATCH] Make ResourceData ref-count start at 1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Summary: Similar to how StringData/ObjectData/ArrayData now works, initialize the ResourceData ref-count to 1 instead of 0, and save pointless inc-refs. Unlike other patches of this nature, this change is quite trivial, as there's very few bare manipulations of ResourceData reference counts. Also mark that the AllocObj and NewInstance IR opcodes produce a ref-count (since the ObjectData ref-count diff). Reviewed By: @​bnell Differential Revision: D2218061 --- hphp/doc/ir.specification | 4 ++-- hphp/runtime/base/resource-data.cpp | 3 ++- hphp/runtime/base/resource-data.h | 5 +++-- hphp/runtime/base/tv-helpers.cpp | 1 - hphp/runtime/ext_zend_compat/php-src/Zend/zend_list.cpp | 1 - hphp/runtime/ext_zend_compat/php-src/main/streams/plain_wrapper.cpp | 1 - 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/hphp/doc/ir.specification b/hphp/doc/ir.specification index 2cfb7160697..549f4bb345e 100644 --- a/hphp/doc/ir.specification +++ b/hphp/doc/ir.specification @@ -1108,7 +1108,7 @@ To string conversions: 8. Allocation -| AllocObj, DAllocObj, S(Cls), Er +| AllocObj, DAllocObj, S(Cls), PRc|Er Allocates a new object of class S1. @@ -1135,7 +1135,7 @@ To string conversions: Calls the static property initializer function (86sinit) for class. May throw. -| NewInstanceRaw, DAllocObj, NA, NF +| NewInstanceRaw, DAllocObj, NA, PRc Allocates an instance of class. diff --git a/hphp/runtime/base/resource-data.cpp b/hphp/runtime/base/resource-data.cpp index 5331ca1d6b9..53fb29b6ee2 100644 --- a/hphp/runtime/base/resource-data.cpp +++ b/hphp/runtime/base/resource-data.cpp @@ -30,11 +30,12 @@ namespace HPHP { __thread int ResourceData::os_max_resource_id; ResourceData::ResourceData() { - m_hdr.init(0, HeaderKind::Resource, 0); + m_hdr.init(0, HeaderKind::Resource, 1); int& pmax = os_max_resource_id; if (pmax < 3) pmax = 3; // reserving 1, 2, 3 for STDIN, STDOUT, STDERR o_id = ++pmax; assert(MM().checkContains(this)); + assert(hasExactlyOneRef()); } void ResourceData::o_setId(int id) { diff --git a/hphp/runtime/base/resource-data.h b/hphp/runtime/base/resource-data.h index 7c907b96318..1bc80a407e7 100644 --- a/hphp/runtime/base/resource-data.h +++ b/hphp/runtime/base/resource-data.h @@ -210,6 +210,7 @@ template T* newres(Args&&... args) { try { auto r = new (mem) T(std::forward(args)...); r->m_hdr.aux = sizeof(T); + assert(r->hasExactlyOneRef()); return r; } catch (...) { MM().smartFreeSize(mem, sizeof(T)); @@ -244,9 +245,9 @@ typename std::enable_if< std::is_convertible::value, req::ptr >::type make(Args&&... args) { - using UnownedAndNonNull = typename req::ptr::UnownedAndNonNull; + using NoIncRef = typename req::ptr::NoIncRef; return req::ptr(newres(std::forward(args)...), - UnownedAndNonNull{}); + NoIncRef{}); } } // namespace req diff --git a/hphp/runtime/base/tv-helpers.cpp b/hphp/runtime/base/tv-helpers.cpp index 7e6f1ee65ea..e8a9741cade 100644 --- a/hphp/runtime/base/tv-helpers.cpp +++ b/hphp/runtime/base/tv-helpers.cpp @@ -565,7 +565,6 @@ void tvCastToResourceInPlace(TypedValue* tv) { tv->m_type = KindOfResource; tv->m_data.pres = newres(); - tv->m_data.pres->incRefCount(); } bool tvCoerceParamToBooleanInPlace(TypedValue* tv) { diff --git a/hphp/runtime/ext_zend_compat/php-src/Zend/zend_list.cpp b/hphp/runtime/ext_zend_compat/php-src/Zend/zend_list.cpp index 0c35ca896c5..c2cc13b63a5 100644 --- a/hphp/runtime/ext_zend_compat/php-src/Zend/zend_list.cpp +++ b/hphp/runtime/ext_zend_compat/php-src/Zend/zend_list.cpp @@ -76,7 +76,6 @@ static zend_rsrc_list_entry *zend_list_id_to_entry(int id TSRMLS_DC) { ZEND_API int zend_list_insert(void *ptr, int type TSRMLS_DC) { auto le = HPHP::newres(ptr, type); - le->incRefCount(); RL().push_back(le); int id = RL().size() - 1; le->id = id; diff --git a/hphp/runtime/ext_zend_compat/php-src/main/streams/plain_wrapper.cpp b/hphp/runtime/ext_zend_compat/php-src/main/streams/plain_wrapper.cpp index f752f7500fb..44571d928b3 100644 --- a/hphp/runtime/ext_zend_compat/php-src/main/streams/plain_wrapper.cpp +++ b/hphp/runtime/ext_zend_compat/php-src/main/streams/plain_wrapper.cpp @@ -27,7 +27,6 @@ PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC TSRMLS_DC) { if (f) { auto* file = HPHP::newres(f); auto* stream = HPHP::req::make_raw(file); - stream->hphp_file->incRefCount(); return stream; } return nullptr; -- 2.11.4.GIT