Improve caching for debug contexts.
Bug: 7343201
We now skip caching on debug contexts and destroy the cached script copy
when we are finished with it. This is a temporary fix until we can refactor
libbcc caching.
Change-Id: I356b67419dc246209c7b5e077264b0cf2e42578c
diff --git a/include/bcc/Renderscript/RSCompilerDriver.h b/include/bcc/Renderscript/RSCompilerDriver.h
index 14e8856..7b54a13 100644
--- a/include/bcc/Renderscript/RSCompilerDriver.h
+++ b/include/bcc/Renderscript/RSCompilerDriver.h
@@ -39,6 +39,9 @@
LookupFunctionSymbolResolver<void*> mRSRuntime;
SymbolResolverProxy mResolver;
+ // Are we compiling under an RS debug context with additional checks?
+ bool mDebugContext;
+
RSExecutable *loadScriptCache(const char *pOutputPath,
const RSInfo::DependencyTableTy &pDeps);
@@ -71,6 +74,10 @@
mConfig = config;
}
+ void setDebugContext(bool v) {
+ mDebugContext = v;
+ }
+
// FIXME: This method accompany with loadScriptCache and compileScript should
// all be const-methods. They're not now because the getAddress() in
// SymbolResolverInterface is not a const-method.
diff --git a/lib/Renderscript/RSCompilerDriver.cpp b/lib/Renderscript/RSCompilerDriver.cpp
index 474b884..3438246 100644
--- a/lib/Renderscript/RSCompilerDriver.cpp
+++ b/lib/Renderscript/RSCompilerDriver.cpp
@@ -61,7 +61,7 @@
} // end anonymous namespace
RSCompilerDriver::RSCompilerDriver(bool pUseCompilerRT) :
- mConfig(NULL), mCompiler(), mCompilerRuntime(NULL) {
+ mConfig(NULL), mCompiler(), mCompilerRuntime(NULL), mDebugContext(false) {
init::Initialize();
// Chain the symbol resolvers for compiler_rt and RS runtimes.
if (pUseCompilerRT) {
@@ -235,8 +235,12 @@
//===--------------------------------------------------------------------===//
// Open the output file for write.
//===--------------------------------------------------------------------===//
- OutputFile *output_file =
- new (std::nothrow) OutputFile(pOutputPath, FileBase::kTruncate);
+ unsigned flags = FileBase::kTruncate;
+ if (mDebugContext) {
+ // Delete the cache file when we finish up under a debug context.
+ flags |= FileBase::kDeleteOnClose;
+ }
+ OutputFile *output_file = new (std::nothrow) OutputFile(pOutputPath, flags);
if ((output_file == NULL) || output_file->hasError()) {
ALOGE("Unable to open the %s for write! (%s)", pOutputPath,
@@ -375,11 +379,16 @@
//===--------------------------------------------------------------------===//
// Load cache.
//===--------------------------------------------------------------------===//
- RSExecutable *result = loadScriptCache(output_path.c_str(), dep_info);
+ RSExecutable *result = NULL;
- if (result != NULL) {
- // Cache hit
- return result;
+ // Skip loading from the cache if we are using a debug context.
+ if (!mDebugContext) {
+ result = loadScriptCache(output_path.c_str(), dep_info);
+
+ if (result != NULL) {
+ // Cache hit
+ return result;
+ }
}
//===--------------------------------------------------------------------===//