Permalink
Browse files

Use getCached{Class,Func}() instead of get{Class,Func}Handle()

Summary:
Do not pessimize-bind the class handle as Normal if just checking if the class
was loaded by LookupClsRDS opcode, which is used only by $obj instanceof $str.

Move the get{Class,Func}Handle() helpers that are now used only by JIT and
debug mode to .cpp, allowing the next diff to bind them persistently if
possible.

Reviewed By: ottoni

Differential Revision: D12876716

fbshipit-source-id: 5e2e323ba8d4cabe0e4e982713b54ae71dbc3818
  • Loading branch information...
jano authored and hhvm-bot committed Nov 6, 2018
1 parent fd53e99 commit 1df79f130e3871bdb131545fa7c8960031ffc319
@@ -627,16 +627,10 @@ StaticMethodCache::lookup(rds::Handle handle, const NamedEntity *ne,
raise_error(Strings::UNKNOWN_CLASS, clsName->data());
}
if (debug) {
// After this call, it's a post-condition that the RDS entry for `cls' is
// initialized, so make sure it has been as a side-effect of
// Unit::loadClass().
auto const cls_ch = ne->getClassHandle();
assertx(rds::isHandleInit(cls_ch));
DEBUG_ONLY auto const p =
rds::handleToRef<LowPtr<Class>, rds::Mode::NonLocal>(cls_ch);
assertx(cls == p.get());
}
// After this call, it's a post-condition that the RDS entry for `cls' is
// initialized, so make sure it has been as a side-effect of
// Unit::loadClass().
assertx(cls == ne->getCachedClass());
LookupResult res = lookupClsMethod(f, cls, methName,
nullptr, // there may be an active
@@ -971,11 +971,7 @@ void raiseMissingArgument(const Func* func, int got) {
//////////////////////////////////////////////////////////////////////
Class* lookupClsRDS(const StringData* name) {
auto const handle = NamedEntity::get(name)->getClassHandle();
assertx(rds::isHandleBound(handle));
return rds::isHandleInit(handle)
? &*rds::handleToRef<LowPtr<Class>, rds::Mode::NonLocal>(handle)
: nullptr;
return NamedEntity::get(name)->getCachedClass();
}
void registerLiveObj(ObjectData* obj) {
@@ -29,14 +29,16 @@ inline NamedEntity::NamedEntity(NamedEntity&& ne) noexcept
m_clsList = ne.m_clsList;
}
inline rds::Handle NamedEntity::getFuncHandle() const {
m_cachedFunc.bind(rds::Mode::Normal);
return m_cachedFunc.handle();
inline Func* NamedEntity::getCachedFunc() const {
return LIKELY(m_cachedFunc.bound() && m_cachedFunc.isInit())
? *m_cachedFunc
: nullptr;
}
inline rds::Handle NamedEntity::getClassHandle() const {
m_cachedClass.bind(rds::Mode::Normal);
return m_cachedClass.handle();
inline Class* NamedEntity::getCachedClass() const {
return LIKELY(m_cachedClass.bound() && m_cachedClass.isInit())
? *m_cachedClass
: nullptr;
}
inline Class* NamedEntity::clsList() const {
@@ -35,17 +35,21 @@
namespace HPHP {
///////////////////////////////////////////////////////////////////////////////
rds::Handle NamedEntity::getFuncHandle() const {
m_cachedFunc.bind(rds::Mode::Normal);
return m_cachedFunc.handle();
}
void NamedEntity::setCachedFunc(Func* f) {
*m_cachedFunc = f;
if (m_cachedFunc.isNormal()) {
f ? m_cachedFunc.markInit() : m_cachedFunc.markUninit();
}
}
Func* NamedEntity::getCachedFunc() const {
return LIKELY(m_cachedFunc.bound() && m_cachedFunc.isInit())
? *m_cachedFunc
: nullptr;
rds::Handle NamedEntity::getClassHandle() const {
m_cachedClass.bind(rds::Mode::Normal);
return m_cachedClass.handle();
}
void NamedEntity::setCachedClass(Class* f) {
@@ -55,12 +59,6 @@ void NamedEntity::setCachedClass(Class* f) {
}
}
Class* NamedEntity::getCachedClass() const {
return LIKELY(m_cachedClass.bound() && m_cachedClass.isInit())
? *m_cachedClass
: nullptr;
}
bool NamedEntity::isPersistentTypeAlias() const {
return m_cachedTypeAlias.bound() && m_cachedTypeAlias.isPersistent();
}

0 comments on commit 1df79f1

Please sign in to comment.