Skip to content

Commit

Permalink
Quick fix for inline caching profiler
Browse files Browse the repository at this point in the history
Summary: A fix to make inline caching profiler work after the recent changes in internal bytecode.

Reviewed By: dulinriley

Differential Revision: D17529650

fbshipit-source-id: 82239cc225c61bcc8412e7d810f19444f6e112ca
  • Loading branch information
JacksonGL authored and facebook-github-bot committed Sep 26, 2019
1 parent 29fddeb commit bd2d76d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion include/hermes/VM/Profiler/InlineCacheProfiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class InlineCacheProfiler {

/// Get a JS array containing all hidden classes that shouldn't be
/// garbage collected.
JSArray *getHiddenClassArray();
JSArray *&getHiddenClassArray();

/// Set a JS array containing all hidden classes that shouldn't be
/// garbage collected.
Expand Down
32 changes: 22 additions & 10 deletions lib/VM/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2161,11 +2161,17 @@ CallResult<HermesValue> Interpreter::interpretFunction(
auto *cacheEntry = curCodeBlock->getReadCacheEntry(cacheIdx);

#ifdef HERMESVM_PROFILER_BB
HERMES_SLOW_ASSERT(
gcScope.getHandleCountDbg() == KEEP_HANDLES &&
"unaccounted handles were created");
runtime->recordHiddenClass(
curCodeBlock, ip, ID(idVal), clazz, cacheEntry->clazz);
{
HERMES_SLOW_ASSERT(
gcScope.getHandleCountDbg() == KEEP_HANDLES &&
"unaccounted handles were created");
auto objHandle = runtime->makeHandle(obj);
runtime->recordHiddenClass(
curCodeBlock, ip, ID(idVal), clazz, cacheEntry->clazz);
// obj may be moved by GC due to recordHiddenClass
obj = objHandle.get();
clazz = obj->getClass(runtime);
}
gcScope.flushToSmallCount(KEEP_HANDLES);
#endif
// If we have a cache hit, reuse the cached offset and immediately
Expand Down Expand Up @@ -2303,11 +2309,17 @@ CallResult<HermesValue> Interpreter::interpretFunction(
auto *cacheEntry = curCodeBlock->getWriteCacheEntry(cacheIdx);

#ifdef HERMESVM_PROFILER_BB
HERMES_SLOW_ASSERT(
gcScope.getHandleCountDbg() == KEEP_HANDLES &&
"unaccounted handles were created");
runtime->recordHiddenClass(
curCodeBlock, ip, ID(idVal), clazz, cacheEntry->clazz);
{
HERMES_SLOW_ASSERT(
gcScope.getHandleCountDbg() == KEEP_HANDLES &&
"unaccounted handles were created");
auto objHandle = runtime->makeHandle(obj);
runtime->recordHiddenClass(
curCodeBlock, ip, ID(idVal), clazz, cacheEntry->clazz);
// obj may be moved by GC due to recordHiddenClass
obj = objHandle.get();
clazz = obj->getClass(runtime);
}
gcScope.flushToSmallCount(KEEP_HANDLES);
#endif
// If we have a cache hit, reuse the cached offset and immediately
Expand Down
2 changes: 1 addition & 1 deletion lib/VM/Profiler/InlineCacheProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool InlineCacheProfiler::insertICHit(
return true;
}

JSArray *InlineCacheProfiler::getHiddenClassArray() {
JSArray *&InlineCacheProfiler::getHiddenClassArray() {
return cachedHiddenClassesRawPtr_;
}

Expand Down
4 changes: 1 addition & 3 deletions lib/VM/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,7 @@ void Runtime::markRoots(RootAcceptor &acceptor, bool markLongLived) {
samplingProfiler_->markRoots(acceptor);
}
#ifdef HERMESVM_PROFILER_BB
auto *hiddenCalssArray = inlineCacheProfiler_.getHiddenClassArray();
acceptor.acceptPtr(hiddenCalssArray, "");
inlineCacheProfiler_.setHiddenClassArray(hiddenCalssArray);
acceptor.acceptPtr(inlineCacheProfiler_.getHiddenClassArray());
#endif
acceptor.endRootSection();
}
Expand Down

0 comments on commit bd2d76d

Please sign in to comment.