Do not call _exit() for PGO instrumentation
Bug: http://b/63768402
For PGO instrumentation, the profiles are written by an atexit callback.
Exit normally and do not call _exit() when PGO instrumentation is
hinted with the ANDROID_PGO_INSTRUMENTATION build flag.
Test: Build and verify that the atexit() callbcak is invoked during PGO
instrumentation.
Change-Id: I5024d965627392aee5a04e106946bb47ca48b5d6
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 06cc71b..83a8656 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -3061,9 +3061,9 @@
int main(int argc, char** argv) {
int result = static_cast<int>(art::Dex2oat(argc, argv));
// Everything was done, do an explicit exit here to avoid running Runtime destructors that take
- // time (bug 10645725) unless we're a debug build or running on valgrind. Note: The Dex2Oat class
- // should not destruct the runtime in this case.
- if (!art::kIsDebugBuild && (RUNNING_ON_MEMORY_TOOL == 0)) {
+ // time (bug 10645725) unless we're a debug or instrumented build or running on valgrind. Note:
+ // The Dex2Oat class should not destruct the runtime in this case.
+ if (!art::kIsDebugBuild && !art::kIsPGOInstrumentation && (RUNNING_ON_MEMORY_TOOL == 0)) {
_exit(result);
}
return result;
diff --git a/runtime/globals.h b/runtime/globals.h
index f14d6e9..ca4040d 100644
--- a/runtime/globals.h
+++ b/runtime/globals.h
@@ -62,6 +62,12 @@
static constexpr bool kIsDebugBuild = GlobalsReturnSelf(true);
#endif
+#if defined(ART_PGO_INSTRUMENTATION)
+static constexpr bool kIsPGOInstrumentation = true;
+#else
+static constexpr bool kIsPGOInstrumentation = false;
+#endif
+
// ART_TARGET - Defined for target builds of ART.
// ART_TARGET_LINUX - Defined for target Linux builds of ART.
// ART_TARGET_ANDROID - Defined for target Android builds of ART.