summaryrefslogtreecommitdiff
path: root/runtime/utils.cc
diff options
context:
space:
mode:
author Brian Carlstrom <bdc@google.com> 2014-02-10 23:48:36 -0800
committer Brian Carlstrom <bdc@google.com> 2014-02-24 14:24:12 -0800
commit6449c62e40ef3a9bb75f664f922555affb532ee4 (patch)
tree2f1b2120bd648c95dea32b68c8e168e42c8e24fd /runtime/utils.cc
parent3fcf18e25241253f23efbeebe77b2a4c4a7c54d3 (diff)
Create CompilerOptions
Package up most compiler related options in CompilerOptions. Details include: - Includes compiler filter, method thresholds, SEA IR mode. - Excludes those needed during Runtime::Init such as CompilerCallbacks and VerificationResults. - Pass CompilerOptions to CompilerDriver. - Remove CompilerOptions from Runtime. - Add ability to pass options for app and image dex2oat to runtime via -Xcompiler-option and -Ximage-compiler-option respectively. Other - Replace 2x CompilerCallbacks implementations with one. - Factor out execv code for use by both image and oat generation. - More OatFile error_msg reporting. - DCHECK for SuspendAll found trying to run valgrind. Change-Id: Iecb57da907be0c856d00c3cd634b5042a229e620
Diffstat (limited to 'runtime/utils.cc')
-rw-r--r--runtime/utils.cc53
1 files changed, 53 insertions, 0 deletions
diff --git a/runtime/utils.cc b/runtime/utils.cc
index aad21bca85..8e6ddaf0c9 100644
--- a/runtime/utils.cc
+++ b/runtime/utils.cc
@@ -24,6 +24,7 @@
#include <unistd.h>
#include "UniquePtr.h"
+#include "base/stl_util.h"
#include "base/unix_file/fd_file.h"
#include "dex_file-inl.h"
#include "mirror/art_field-inl.h"
@@ -1203,4 +1204,56 @@ bool IsOatMagic(uint32_t magic) {
sizeof(OatHeader::kOatMagic)) == 0);
}
+bool Exec(std::vector<std::string>& arg_vector, std::string* error_msg) {
+ const std::string command_line(Join(arg_vector, ' '));
+
+ CHECK_GE(arg_vector.size(), 1U) << command_line;
+
+ // Convert the args to char pointers.
+ const char* program = arg_vector[0].c_str();
+ std::vector<char*> args;
+ for (std::vector<std::string>::const_iterator it = arg_vector.begin(); it != arg_vector.end();
+ ++it) {
+ CHECK(*it != nullptr);
+ args.push_back(const_cast<char*>(it->c_str()));
+ }
+ args.push_back(NULL);
+
+ // fork and exec
+ pid_t pid = fork();
+ if (pid == 0) {
+ // no allocation allowed between fork and exec
+
+ // change process groups, so we don't get reaped by ProcessManager
+ setpgid(0, 0);
+
+ execv(program, &args[0]);
+
+ *error_msg = StringPrintf("Failed to execv(%s): %s", command_line.c_str(), strerror(errno));
+ return false;
+ } else {
+ if (pid == -1) {
+ *error_msg = StringPrintf("Failed to execv(%s) because fork failed: %s",
+ command_line.c_str(), strerror(errno));
+ return false;
+ }
+
+ // wait for subprocess to finish
+ int status;
+ pid_t got_pid = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0));
+ if (got_pid != pid) {
+ *error_msg = StringPrintf("Failed after fork for execv(%s) because waitpid failed: "
+ "wanted %d, got %d: %s",
+ command_line.c_str(), pid, got_pid, strerror(errno));
+ return false;
+ }
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
+ *error_msg = StringPrintf("Failed execv(%s) because non-0 exit status",
+ command_line.c_str());
+ return false;
+ }
+ }
+ return true;
+}
+
} // namespace art