Fix multithreaded dex2oat on Mac OS.
Also ensure that we error out rather than writing an empty .oat file if we can't
open one or more .dex files.
Change-Id: I776482054bb098737ac17aef230256aaaf2c6ba0
diff --git a/src/compiler.cc b/src/compiler.cc
index e9cd99b..578c0af 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -957,7 +957,12 @@
WorkerThread(Context* context, size_t begin, size_t end, Callback callback, size_t stripe, bool spawn)
: spawn_(spawn), context_(context), begin_(begin), end_(end), callback_(callback), stripe_(stripe) {
if (spawn_) {
- CHECK_PTHREAD_CALL(pthread_create, (&pthread_, NULL, &Go, this), "compiler worker thread");
+ // Mac OS stacks are only 512KiB. Make sure we have the same stack size on all platforms.
+ pthread_attr_t attr;
+ CHECK_PTHREAD_CALL(pthread_attr_init, (&attr), "new compiler worker thread");
+ CHECK_PTHREAD_CALL(pthread_attr_setstacksize, (&attr, 1*MB), "new compiler worker thread");
+ CHECK_PTHREAD_CALL(pthread_create, (&pthread_, &attr, &Go, this), "new compiler worker thread");
+ CHECK_PTHREAD_CALL(pthread_attr_destroy, (&attr), "new compiler worker thread");
}
}
diff --git a/src/dex2oat.cc b/src/dex2oat.cc
index e792311..7008f3b 100644
--- a/src/dex2oat.cc
+++ b/src/dex2oat.cc
@@ -38,10 +38,6 @@
#include "timing_logger.h"
#include "zip_archive.h"
-#if defined(__APPLE__)
-#include "AvailabilityMacros.h" // For MAC_OS_X_VERSION_MAX_ALLOWED
-#endif
-
namespace art {
static void UsageErrorV(const char* fmt, va_list ap) {
@@ -433,19 +429,22 @@
return true;
}
-static void OpenDexFiles(const std::vector<const char*>& dex_filenames,
- const std::vector<const char*>& dex_locations,
- std::vector<const DexFile*>& dex_files) {
+static size_t OpenDexFiles(const std::vector<const char*>& dex_filenames,
+ const std::vector<const char*>& dex_locations,
+ std::vector<const DexFile*>& dex_files) {
+ size_t failure_count = 0;
for (size_t i = 0; i < dex_filenames.size(); i++) {
const char* dex_filename = dex_filenames[i];
const char* dex_location = dex_locations[i];
const DexFile* dex_file = DexFile::Open(dex_filename, dex_location);
if (dex_file == NULL) {
LOG(WARNING) << "could not open .dex from file " << dex_filename;
+ ++failure_count;
} else {
dex_files.push_back(dex_file);
}
}
+ return failure_count;
}
static int dex2oat(int argc, char** argv) {
@@ -555,12 +554,6 @@
}
}
-#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED < 1060
- // Something is broken on Mac OS 10.5, and we don't have direct access to any machines running it.
- // Restricting dex2oat to a single thread on Mac OS 10.5 appears to be a workaround.
- thread_count = 1;
-#endif
-
if (oat_filename.empty() && oat_fd == -1) {
Usage("Output must be supplied with either --oat-file or --oat-fd");
}
@@ -664,7 +657,11 @@
options.push_back(std::make_pair("compiler", reinterpret_cast<void*>(NULL)));
std::vector<const DexFile*> boot_class_path;
if (boot_image_option.empty()) {
- OpenDexFiles(dex_filenames, dex_locations, boot_class_path);
+ size_t failure_count = OpenDexFiles(dex_filenames, dex_locations, boot_class_path);
+ if (failure_count > 0) {
+ LOG(ERROR) << "Failed to open some dex files: " << failure_count;
+ return EXIT_FAILURE;
+ }
options.push_back(std::make_pair("bootclasspath", &boot_class_path));
} else {
options.push_back(std::make_pair(boot_image_option.c_str(), reinterpret_cast<void*>(NULL)));
@@ -706,7 +703,11 @@
}
dex_files.push_back(dex_file);
} else {
- OpenDexFiles(dex_filenames, dex_locations, dex_files);
+ size_t failure_count = OpenDexFiles(dex_filenames, dex_locations, dex_files);
+ if (failure_count > 0) {
+ LOG(ERROR) << "Failed to open some dex files: " << failure_count;
+ return EXIT_FAILURE;
+ }
}
}