summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
author Jean Christophe Beyler <jean.christophe.beyler@intel.com> 2014-09-12 12:03:25 -0700
committer Andreas Gampe <agampe@google.com> 2015-02-23 15:43:46 -0800
commit24e04aa68c575d349eac0d9d09aab9bd3106ef94 (patch)
treee6a14642cc4a4b409fe98a696b17968c6d0a65f4 /runtime
parent38fee8ef4bc0f4dbe2c6d1f5585895f0c4d16984 (diff)
ART: Allow the execution to stop if the compilation fails via an option
The current implementation continues the execution of the application if dex2oat fails by relying on the interpreter. This patch adds a -Xno-dex-file-fallback option to stop the default behavior. This can be used two-fold. First, one can enforce that a runtime only starts with a boot image. A follow-up patch will ensure that dex2oat (for apps) and patchoat in general request that mode and close gracefully otherwise. Second, this can be used for testing and debugging purposes, as it ensures that compiler failures & aborts are not silently ignored. Add testing. Bug: 19100590 Change-Id: Iaf07b5ccf00942ca8a8ec8687599320a3ddbc089 Signed-off-by: Jean Christophe Beyler <jean.christophe.beyler@intel.com>
Diffstat (limited to 'runtime')
-rw-r--r--runtime/class_linker.cc11
-rw-r--r--runtime/parsed_options.cc4
-rw-r--r--runtime/runtime.cc11
-rw-r--r--runtime/runtime.h8
-rw-r--r--runtime/runtime_options.def2
5 files changed, 31 insertions, 5 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index ee66b49e7d..327875195d 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -1008,10 +1008,15 @@ bool ClassLinker::OpenDexFilesFromOat(const char* dex_location, const char* oat_
// Failed, bail.
if (open_oat_file.get() == nullptr) {
- std::string error_msg;
// dex2oat was disabled or crashed. Add the dex file in the list of dex_files to make progress.
- DexFile::Open(dex_location, dex_location, &error_msg, dex_files);
- error_msgs->push_back(error_msg);
+ if (Runtime::Current()->IsDexFileFallbackEnabled()) {
+ std::string error_msg;
+ if (!DexFile::Open(dex_location, dex_location, &error_msg, dex_files)) {
+ error_msgs->push_back(error_msg);
+ }
+ } else {
+ error_msgs->push_back("Fallback mode disabled, skipping dex files.");
+ }
return false;
}
diff --git a/runtime/parsed_options.cc b/runtime/parsed_options.cc
index 99369ca35d..c0c7baaae1 100644
--- a/runtime/parsed_options.cc
+++ b/runtime/parsed_options.cc
@@ -241,6 +241,8 @@ std::unique_ptr<RuntimeParser> ParsedOptions::MakeParser(bool ignore_unrecognize
.Define("-Xzygote-max-failed-boots=_")
.WithType<unsigned int>()
.IntoKey(M::ZygoteMaxFailedBoots)
+ .Define("-Xno-dex-file-fallback")
+ .IntoKey(M::NoDexFileFallback)
.Ignore({
"-ea", "-da", "-enableassertions", "-disableassertions", "--runtime-arg", "-esa",
"-dsa", "-enablesystemassertions", "-disablesystemassertions", "-Xrs", "-Xint:_",
@@ -631,6 +633,8 @@ void ParsedOptions::Usage(const char* fmt, ...) {
UsageMessage(stream, " -X[no]relocate\n");
UsageMessage(stream, " -X[no]dex2oat (Whether to invoke dex2oat on the application)\n");
UsageMessage(stream, " -X[no]image-dex2oat (Whether to create and use a boot image)\n");
+ UsageMessage(stream, " -Xno-dex-file-fallback "
+ "(Don't fall back to dex files without oat files)\n");
UsageMessage(stream, "\n");
UsageMessage(stream, "The following previously supported Dalvik options are ignored:\n");
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index f38f65e2ad..1af08c113b 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -169,6 +169,7 @@ Runtime::Runtime()
dump_gc_performance_on_shutdown_(false),
preinitialization_transaction_(nullptr),
verify_(false),
+ allow_dex_file_fallback_(true),
target_sdk_version_(0),
implicit_null_checks_(false),
implicit_so_checks_(false),
@@ -380,7 +381,9 @@ bool Runtime::Create(const RuntimeOptions& options, bool ignore_unrecognized) {
InitLogging(NULL); // Calls Locks::Init() as a side effect.
instance_ = new Runtime;
if (!instance_->Init(options, ignore_unrecognized)) {
- delete instance_;
+ // TODO: Currently deleting the instance will abort the runtime on destruction. Now This will
+ // leak memory, instead. Fix the destructor. b/19100793.
+ // delete instance_;
instance_ = NULL;
return false;
}
@@ -762,6 +765,7 @@ bool Runtime::Init(const RuntimeOptions& raw_options, bool ignore_unrecognized)
intern_table_ = new InternTable;
verify_ = runtime_options.GetOrDefault(Opt::Verify);
+ allow_dex_file_fallback_ = !runtime_options.Exists(Opt::NoDexFileFallback);
if (runtime_options.GetOrDefault(Opt::Interpret)) {
GetInstrumentation()->ForceInterpretOnly();
@@ -800,6 +804,11 @@ bool Runtime::Init(const RuntimeOptions& raw_options, bool ignore_unrecognized)
runtime_options.GetOrDefault(Opt::EnableHSpaceCompactForOOM),
runtime_options.GetOrDefault(Opt::HSpaceCompactForOOMMinIntervalsMs));
+ if (heap_->GetImageSpace() == nullptr && !allow_dex_file_fallback_) {
+ LOG(ERROR) << "Dex file fallback disabled, cannot continue without image.";
+ return false;
+ }
+
dump_gc_performance_on_shutdown_ = runtime_options.Exists(Opt::DumpGCPerformanceOnShutdown);
if (runtime_options.Exists(Opt::JdwpOptions)) {
diff --git a/runtime/runtime.h b/runtime/runtime.h
index fb9ca401ac..944c8bd0dd 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -505,6 +505,10 @@ class Runtime {
return verify_;
}
+ bool IsDexFileFallbackEnabled() const {
+ return allow_dex_file_fallback_;
+ }
+
bool RunningOnValgrind() const {
return running_on_valgrind_;
}
@@ -668,6 +672,10 @@ class Runtime {
// If false, verification is disabled. True by default.
bool verify_;
+ // If true, the runtime may use dex files directly with the interpreter if an oat file is not
+ // available/usable.
+ bool allow_dex_file_fallback_;
+
// Specifies target SDK version to allow workarounds for certain API levels.
int32_t target_sdk_version_;
diff --git a/runtime/runtime_options.def b/runtime/runtime_options.def
index 71a0152956..d9cc4d43e7 100644
--- a/runtime/runtime_options.def
+++ b/runtime/runtime_options.def
@@ -115,6 +115,6 @@ RUNTIME_OPTIONS_KEY (void (*)(int32_t status), \
// Runtime::Abort.
RUNTIME_OPTIONS_KEY (void (*)(), HookAbort, nullptr)
RUNTIME_OPTIONS_KEY (unsigned int, ZygoteMaxFailedBoots, 1)
-
+RUNTIME_OPTIONS_KEY (Unit, NoDexFileFallback)
#undef RUNTIME_OPTIONS_KEY