OSDN Git Service

ART: Check whether an oat file exists before opening
authorAndreas Gampe <agampe@google.com>
Thu, 19 May 2016 04:10:42 +0000 (21:10 -0700)
committerAndreas Gampe <agampe@google.com>
Thu, 19 May 2016 22:39:35 +0000 (15:39 -0700)
The two-stage process of dlopen and our own loader is expensive.
Considering that the OatFileAssistant needs to check two locations,
one of which is unlikely to have a file for the common case of apps
installed in data, do a file existence check before attempting to
load the file.

Remove an unused variable.

Saves about 0.25ms on a N6P.

Bug: 28801010

(cherry picked from commit d9a720bcb5df2c135f161c7c6da2d25db4400dca)

Change-Id: I0aff9c276c0f539723f8a92663f14ce72160c44d

runtime/oat_file.cc

index c33a9cd..ec28685 100644 (file)
@@ -954,7 +954,12 @@ OatFile* OatFile::Open(const std::string& filename,
   ScopedTrace trace("Open oat file " + location);
   CHECK(!filename.empty()) << location;
   CheckLocation(location);
-  std::unique_ptr<OatFile> ret;
+
+  // Check that the file even exists, fast-fail.
+  if (!OS::FileExists(filename.c_str())) {
+    *error_msg = StringPrintf("File %s does not exist.", filename.c_str());
+    return nullptr;
+  }
 
   // Try dlopen first, as it is required for native debuggability. This will fail fast if dlopen is
   // disabled.