summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorBrian Carlstrom <bdc@google.com>2014-03-02 18:24:38 -0800
committerBrian Carlstrom <bdc@google.com>2014-03-03 13:31:40 -0800
commit491ca9e75fad381468dd7f5fdbff56d1a9738dd7 (patch)
tree4a88d05188aebbcbe868a27b58fc1a932f914ce2 /runtime
parent82e3a8ef9cd776d7026b45fe7fb6c72bcfd61394 (diff)
downloadart-491ca9e75fad381468dd7f5fdbff56d1a9738dd7.zip
art-491ca9e75fad381468dd7f5fdbff56d1a9738dd7.tar.gz
art-491ca9e75fad381468dd7f5fdbff56d1a9738dd7.tar.bz2
Add ART -help and -showversion
Bug: https://code.google.com/p/android/issues/detail?id=62149 Change-Id: I5c21c0433f5f341f94e7d977e8d2d69cc46d6fe3
Diffstat (limited to 'runtime')
-rw-r--r--runtime/Android.mk1
-rw-r--r--runtime/jni_internal.cc31
-rw-r--r--runtime/jni_internal.h3
-rw-r--r--runtime/native/dalvik_system_VMRuntime.cc2
-rw-r--r--runtime/parsed_options.cc739
-rw-r--r--runtime/parsed_options.h105
-rw-r--r--runtime/parsed_options_test.cc (renamed from runtime/runtime_test.cc)8
-rw-r--r--runtime/runtime.cc518
-rw-r--r--runtime/runtime.h69
-rw-r--r--runtime/trace.cc6
-rw-r--r--runtime/trace.h6
11 files changed, 905 insertions, 583 deletions
diff --git a/runtime/Android.mk b/runtime/Android.mk
index 10ef64b..7a2fab9 100644
--- a/runtime/Android.mk
+++ b/runtime/Android.mk
@@ -124,6 +124,7 @@ LIBART_COMMON_SRC_FILES := \
oat_file.cc \
offsets.cc \
os_linux.cc \
+ parsed_options.cc \
primitive.cc \
reference_table.cc \
reflection.cc \
diff --git a/runtime/jni_internal.cc b/runtime/jni_internal.cc
index 2db0f5f..1bcb8dd 100644
--- a/runtime/jni_internal.cc
+++ b/runtime/jni_internal.cc
@@ -40,6 +40,7 @@
#include "mirror/object_array-inl.h"
#include "mirror/throwable.h"
#include "object_utils.h"
+#include "parsed_options.h"
#include "runtime.h"
#include "safe_map.h"
#include "scoped_thread_state_change.h"
@@ -104,7 +105,8 @@ static void CheckMethodArguments(mirror::ArtMethod* m, uint32_t* args)
mirror::Object* argument = reinterpret_cast<mirror::Object*>(args[i + offset]);
if (argument != nullptr && !argument->InstanceOf(param_type)) {
LOG(ERROR) << "JNI ERROR (app bug): attempt to pass an instance of "
- << PrettyTypeOf(argument) << " as argument " << (i + 1) << " to " << PrettyMethod(m);
+ << PrettyTypeOf(argument) << " as argument " << (i + 1)
+ << " to " << PrettyMethod(m);
++error_count;
}
} else if (param_type->IsPrimitiveLong() || param_type->IsPrimitiveDouble()) {
@@ -114,7 +116,8 @@ static void CheckMethodArguments(mirror::ArtMethod* m, uint32_t* args)
if (error_count > 0) {
// TODO: pass the JNI function name (such as "CallVoidMethodV") through so we can call JniAbort
// with an argument.
- JniAbortF(nullptr, "bad arguments passed to %s (see above for details)", PrettyMethod(m).c_str());
+ JniAbortF(nullptr, "bad arguments passed to %s (see above for details)",
+ PrettyMethod(m).c_str());
}
}
@@ -294,8 +297,8 @@ static jfieldID FindFieldID(const ScopedObjectAccess& soa, jclass jni_class, con
SirtRef<mirror::Throwable> cause(soa.Self(), soa.Self()->GetException(&throw_location));
soa.Self()->ClearException();
soa.Self()->ThrowNewExceptionF(throw_location, "Ljava/lang/NoSuchFieldError;",
- "no type \"%s\" found and so no field \"%s\" could be found in class "
- "\"%s\" or its superclasses", sig, name,
+ "no type \"%s\" found and so no field \"%s\" "
+ "could be found in class \"%s\" or its superclasses", sig, name,
ClassHelper(c.get()).GetDescriptor());
soa.Self()->GetException(nullptr)->SetCause(cause.get());
return nullptr;
@@ -782,7 +785,8 @@ class JNI {
old_throw_dex_pc = old_throw_location.GetDexPc();
soa.Self()->ClearException();
}
- ScopedLocalRef<jthrowable> exception(env, soa.AddLocalReference<jthrowable>(old_exception.get()));
+ ScopedLocalRef<jthrowable> exception(env,
+ soa.AddLocalReference<jthrowable>(old_exception.get()));
ScopedLocalRef<jclass> exception_class(env, env->GetObjectClass(exception.get()));
jmethodID mid = env->GetMethodID(exception_class.get(), "printStackTrace", "()V");
if (mid == nullptr) {
@@ -905,7 +909,8 @@ class JNI {
return JNI_TRUE;
} else {
ScopedObjectAccess soa(env);
- return (soa.Decode<mirror::Object*>(obj1) == soa.Decode<mirror::Object*>(obj2)) ? JNI_TRUE : JNI_FALSE;
+ return (soa.Decode<mirror::Object*>(obj1) == soa.Decode<mirror::Object*>(obj2))
+ ? JNI_TRUE : JNI_FALSE;
}
}
@@ -2334,7 +2339,8 @@ class JNI {
static void SetBooleanArrayRegion(JNIEnv* env, jbooleanArray array, jsize start, jsize length,
const jboolean* buf) {
ScopedObjectAccess soa(env);
- SetPrimitiveArrayRegion<jbooleanArray, jboolean, mirror::BooleanArray>(soa, array, start, length, buf);
+ SetPrimitiveArrayRegion<jbooleanArray, jboolean, mirror::BooleanArray>(soa, array, start,
+ length, buf);
}
static void SetByteArrayRegion(JNIEnv* env, jbyteArray array, jsize start, jsize length,
@@ -2352,13 +2358,15 @@ class JNI {
static void SetDoubleArrayRegion(JNIEnv* env, jdoubleArray array, jsize start, jsize length,
const jdouble* buf) {
ScopedObjectAccess soa(env);
- SetPrimitiveArrayRegion<jdoubleArray, jdouble, mirror::DoubleArray>(soa, array, start, length, buf);
+ SetPrimitiveArrayRegion<jdoubleArray, jdouble, mirror::DoubleArray>(soa, array, start, length,
+ buf);
}
static void SetFloatArrayRegion(JNIEnv* env, jfloatArray array, jsize start, jsize length,
const jfloat* buf) {
ScopedObjectAccess soa(env);
- SetPrimitiveArrayRegion<jfloatArray, jfloat, mirror::FloatArray>(soa, array, start, length, buf);
+ SetPrimitiveArrayRegion<jfloatArray, jfloat, mirror::FloatArray>(soa, array, start, length,
+ buf);
}
static void SetIntArrayRegion(JNIEnv* env, jintArray array, jsize start, jsize length,
@@ -2556,7 +2564,8 @@ class JNI {
ScopedObjectAccess soa(env);
if (soa.Decode<mirror::Object*>(java_object) ==
reinterpret_cast<mirror::Object*>(java_object)) {
- if (soa.Env()->locals.ContainsDirectPointer(reinterpret_cast<mirror::Object*>(java_object))) {
+ mirror::Object* object = reinterpret_cast<mirror::Object*>(java_object);
+ if (soa.Env()->locals.ContainsDirectPointer(object)) {
return JNILocalRefType;
}
}
@@ -3086,7 +3095,7 @@ const JNIInvokeInterface gJniInvokeInterface = {
JII::AttachCurrentThreadAsDaemon
};
-JavaVMExt::JavaVMExt(Runtime* runtime, Runtime::ParsedOptions* options)
+JavaVMExt::JavaVMExt(Runtime* runtime, ParsedOptions* options)
: runtime(runtime),
check_jni_abort_hook(nullptr),
check_jni_abort_hook_data(nullptr),
diff --git a/runtime/jni_internal.h b/runtime/jni_internal.h
index 9e10987..606d5d1 100644
--- a/runtime/jni_internal.h
+++ b/runtime/jni_internal.h
@@ -46,6 +46,7 @@ namespace mirror {
class ArgArray;
union JValue;
class Libraries;
+class ParsedOptions;
class ScopedObjectAccess;
class Thread;
@@ -64,7 +65,7 @@ int ThrowNewException(JNIEnv* env, jclass exception_class, const char* msg, jobj
class JavaVMExt : public JavaVM {
public:
- JavaVMExt(Runtime* runtime, Runtime::ParsedOptions* options);
+ JavaVMExt(Runtime* runtime, ParsedOptions* options);
~JavaVMExt();
/**
diff --git a/runtime/native/dalvik_system_VMRuntime.cc b/runtime/native/dalvik_system_VMRuntime.cc
index decbc66..d9bb121 100644
--- a/runtime/native/dalvik_system_VMRuntime.cc
+++ b/runtime/native/dalvik_system_VMRuntime.cc
@@ -155,7 +155,7 @@ static jstring VMRuntime_classPath(JNIEnv* env, jobject) {
}
static jstring VMRuntime_vmVersion(JNIEnv* env, jobject) {
- return env->NewStringUTF(Runtime::Current()->GetVersion());
+ return env->NewStringUTF(Runtime::GetVersion());
}
static jstring VMRuntime_vmLibrary(JNIEnv* env, jobject) {
diff --git a/runtime/parsed_options.cc b/runtime/parsed_options.cc
new file mode 100644
index 0000000..c5b1c4b
--- /dev/null
+++ b/runtime/parsed_options.cc
@@ -0,0 +1,739 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "parsed_options.h"
+
+#include "debugger.h"
+#include "monitor.h"
+
+namespace art {
+
+ParsedOptions* ParsedOptions::Create(const Runtime::Options& options, bool ignore_unrecognized) {
+ UniquePtr<ParsedOptions> parsed(new ParsedOptions());
+ if (parsed->Parse(options, ignore_unrecognized)) {
+ return parsed.release();
+ }
+ return nullptr;
+}
+
+// Parse a string of the form /[0-9]+[kKmMgG]?/, which is used to specify
+// memory sizes. [kK] indicates kilobytes, [mM] megabytes, and
+// [gG] gigabytes.
+//
+// "s" should point just past the "-Xm?" part of the string.
+// "div" specifies a divisor, e.g. 1024 if the value must be a multiple
+// of 1024.
+//
+// The spec says the -Xmx and -Xms options must be multiples of 1024. It
+// doesn't say anything about -Xss.
+//
+// Returns 0 (a useless size) if "s" is malformed or specifies a low or
+// non-evenly-divisible value.
+//
+size_t ParseMemoryOption(const char* s, size_t div) {
+ // strtoul accepts a leading [+-], which we don't want,
+ // so make sure our string starts with a decimal digit.
+ if (isdigit(*s)) {
+ char* s2;
+ size_t val = strtoul(s, &s2, 10);
+ if (s2 != s) {
+ // s2 should be pointing just after the number.
+ // If this is the end of the string, the user
+ // has specified a number of bytes. Otherwise,
+ // there should be exactly one more character
+ // that specifies a multiplier.
+ if (*s2 != '\0') {
+ // The remainder of the string is either a single multiplier
+ // character, or nothing to indicate that the value is in
+ // bytes.
+ char c = *s2++;
+ if (*s2 == '\0') {
+ size_t mul;
+ if (c == '\0') {
+ mul = 1;
+ } else if (c == 'k' || c == 'K') {
+ mul = KB;
+ } else if (c == 'm' || c == 'M') {
+ mul = MB;
+ } else if (c == 'g' || c == 'G') {
+ mul = GB;
+ } else {
+ // Unknown multiplier character.
+ return 0;
+ }
+
+ if (val <= std::numeric_limits<size_t>::max() / mul) {
+ val *= mul;
+ } else {
+ // Clamp to a multiple of 1024.
+ val = std::numeric_limits<size_t>::max() & ~(1024-1);
+ }
+ } else {
+ // There's more than one character after the numeric part.
+ return 0;
+ }
+ }
+ // The man page says that a -Xm value must be a multiple of 1024.
+ if (val % div == 0) {
+ return val;
+ }
+ }
+ }
+ return 0;
+}
+
+static gc::CollectorType ParseCollectorType(const std::string& option) {
+ if (option == "MS" || option == "nonconcurrent") {
+ return gc::kCollectorTypeMS;
+ } else if (option == "CMS" || option == "concurrent") {
+ return gc::kCollectorTypeCMS;
+ } else if (option == "SS") {
+ return gc::kCollectorTypeSS;
+ } else if (option == "GSS") {
+ return gc::kCollectorTypeGSS;
+ } else {
+ return gc::kCollectorTypeNone;
+ }
+}
+
+bool ParsedOptions::Parse(const Runtime::Options& options, bool ignore_unrecognized) {
+ const char* boot_class_path_string = getenv("BOOTCLASSPATH");
+ if (boot_class_path_string != NULL) {
+ boot_class_path_string_ = boot_class_path_string;
+ }
+ const char* class_path_string = getenv("CLASSPATH");
+ if (class_path_string != NULL) {
+ class_path_string_ = class_path_string;
+ }
+ // -Xcheck:jni is off by default for regular builds but on by default in debug builds.
+ check_jni_ = kIsDebugBuild;
+
+ heap_initial_size_ = gc::Heap::kDefaultInitialSize;
+ heap_maximum_size_ = gc::Heap::kDefaultMaximumSize;
+ heap_min_free_ = gc::Heap::kDefaultMinFree;
+ heap_max_free_ = gc::Heap::kDefaultMaxFree;
+ heap_target_utilization_ = gc::Heap::kDefaultTargetUtilization;
+ heap_growth_limit_ = 0; // 0 means no growth limit .
+ // Default to number of processors minus one since the main GC thread also does work.
+ parallel_gc_threads_ = sysconf(_SC_NPROCESSORS_CONF) - 1;
+ // Only the main GC thread, no workers.
+ conc_gc_threads_ = 0;
+ // Default is CMS which is Sticky + Partial + Full CMS GC.
+ collector_type_ = gc::kCollectorTypeCMS;
+ // If background_collector_type_ is kCollectorTypeNone, it defaults to the collector_type_ after
+ // parsing options.
+ background_collector_type_ = gc::kCollectorTypeNone;
+ stack_size_ = 0; // 0 means default.
+ max_spins_before_thin_lock_inflation_ = Monitor::kDefaultMaxSpinsBeforeThinLockInflation;
+ low_memory_mode_ = false;
+ use_tlab_ = false;
+ verify_pre_gc_heap_ = false;
+ verify_post_gc_heap_ = kIsDebugBuild;
+ verify_pre_gc_rosalloc_ = kIsDebugBuild;
+ verify_post_gc_rosalloc_ = false;
+
+ compiler_callbacks_ = nullptr;
+ is_zygote_ = false;
+ interpreter_only_ = false;
+ is_explicit_gc_disabled_ = false;
+
+ long_pause_log_threshold_ = gc::Heap::kDefaultLongPauseLogThreshold;
+ long_gc_log_threshold_ = gc::Heap::kDefaultLongGCLogThreshold;
+ dump_gc_performance_on_shutdown_ = false;
+ ignore_max_footprint_ = false;
+
+ lock_profiling_threshold_ = 0;
+ hook_is_sensitive_thread_ = NULL;
+
+ hook_vfprintf_ = vfprintf;
+ hook_exit_ = exit;
+ hook_abort_ = NULL; // We don't call abort(3) by default; see Runtime::Abort.
+
+// gLogVerbosity.class_linker = true; // TODO: don't check this in!
+// gLogVerbosity.compiler = true; // TODO: don't check this in!
+// gLogVerbosity.verifier = true; // TODO: don't check this in!
+// gLogVerbosity.heap = true; // TODO: don't check this in!
+// gLogVerbosity.gc = true; // TODO: don't check this in!
+// gLogVerbosity.jdwp = true; // TODO: don't check this in!
+// gLogVerbosity.jni = true; // TODO: don't check this in!
+// gLogVerbosity.monitor = true; // TODO: don't check this in!
+// gLogVerbosity.startup = true; // TODO: don't check this in!
+// gLogVerbosity.third_party_jni = true; // TODO: don't check this in!
+// gLogVerbosity.threads = true; // TODO: don't check this in!
+
+ method_trace_ = false;
+ method_trace_file_ = "/data/method-trace-file.bin";
+ method_trace_file_size_ = 10 * MB;
+
+ profile_ = false;
+ profile_period_s_ = 10; // Seconds.
+ profile_duration_s_ = 20; // Seconds.
+ profile_interval_us_ = 500; // Microseconds.
+ profile_backoff_coefficient_ = 2.0;
+ profile_clock_source_ = kDefaultProfilerClockSource;
+
+ for (size_t i = 0; i < options.size(); ++i) {
+ const std::string option(options[i].first);
+ if (true && options[0].first == "-Xzygote") {
+ LOG(INFO) << "option[" << i << "]=" << option;
+ }
+ if (StartsWith(option, "-help")) {
+ Usage(nullptr);
+ return false;
+ } else if (StartsWith(option, "-showversion")) {
+ UsageMessage(stdout, "ART version %s\n", Runtime::GetVersion());
+ Exit(0);
+ } else if (StartsWith(option, "-Xbootclasspath:")) {
+ boot_class_path_string_ = option.substr(strlen("-Xbootclasspath:")).data();
+ } else if (option == "-classpath" || option == "-cp") {
+ // TODO: support -Djava.class.path
+ i++;
+ if (i == options.size()) {
+ Usage("Missing required class path value for %s", option.c_str());
+ return false;
+ }
+ const StringPiece& value = options[i].first;
+ class_path_string_ = value.data();
+ } else if (option == "bootclasspath") {
+ boot_class_path_
+ = reinterpret_cast<const std::vector<const DexFile*>*>(options[i].second);
+ } else if (StartsWith(option, "-Ximage:")) {
+ if (!ParseStringAfterChar(option, ':', &image_)) {
+ return false;
+ }
+ } else if (StartsWith(option, "-Xcheck:jni")) {
+ check_jni_ = true;
+ } else if (StartsWith(option, "-Xrunjdwp:") || StartsWith(option, "-agentlib:jdwp=")) {
+ std::string tail(option.substr(option[1] == 'X' ? 10 : 15));
+ // TODO: move parsing logic out of Dbg
+ if (tail == "help" || !Dbg::ParseJdwpOptions(tail)) {
+ if (tail != "help") {
+ UsageMessage(stderr, "Failed to parse JDWP option %s\n", tail.c_str());
+ }
+ Usage("Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n"
+ "Example: -Xrunjdwp:transport=dt_socket,address=localhost:6500,server=n\n");
+ return false;
+ }
+ } else if (StartsWith(option, "-Xms")) {
+ size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).c_str(), 1024);
+ if (size == 0) {
+ Usage("Failed to parse memory option %s", option.c_str());
+ return false;
+ }
+ heap_initial_size_ = size;
+ } else if (StartsWith(option, "-Xmx")) {
+ size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).c_str(), 1024);
+ if (size == 0) {
+ Usage("Failed to parse memory option %s", option.c_str());
+ return false;
+ }
+ heap_maximum_size_ = size;
+ } else if (StartsWith(option, "-XX:HeapGrowthLimit=")) {
+ size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapGrowthLimit=")).c_str(), 1024);
+ if (size == 0) {
+ Usage("Failed to parse memory option %s", option.c_str());
+ return false;
+ }
+ heap_growth_limit_ = size;
+ } else if (StartsWith(option, "-XX:HeapMinFree=")) {
+ size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMinFree=")).c_str(), 1024);
+ if (size == 0) {
+ Usage("Failed to parse memory option %s", option.c_str());
+ return false;
+ }
+ heap_min_free_ = size;
+ } else if (StartsWith(option, "-XX:HeapMaxFree=")) {
+ size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMaxFree=")).c_str(), 1024);
+ if (size == 0) {
+ Usage("Failed to parse memory option %s", option.c_str());
+ return false;
+ }
+ heap_max_free_ = size;
+ } else if (StartsWith(option, "-XX:HeapTargetUtilization=")) {
+ if (!ParseDouble(option, '=', 0.1, 0.9, &heap_target_utilization_)) {
+ return false;
+ }
+ } else if (StartsWith(option, "-XX:ParallelGCThreads=")) {
+ if (!ParseUnsignedInteger(option, '=', &parallel_gc_threads_)) {
+ return false;
+ }
+ } else if (StartsWith(option, "-XX:ConcGCThreads=")) {
+ if (!ParseUnsignedInteger(option, '=', &conc_gc_threads_)) {
+ return false;
+ }
+ } else if (StartsWith(option, "-Xss")) {
+ size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).c_str(), 1);
+ if (size == 0) {
+ Usage("Failed to parse memory option %s", option.c_str());
+ return false;
+ }
+ stack_size_ = size;
+ } else if (StartsWith(option, "-XX:MaxSpinsBeforeThinLockInflation=")) {
+ if (!ParseUnsignedInteger(option, '=', &max_spins_before_thin_lock_inflation_)) {
+ return false;
+ }
+ } else if (StartsWith(option, "-XX:LongPauseLogThreshold=")) {
+ size_t value;
+ if (!ParseUnsignedInteger(option, '=', &value)) {
+ return false;
+ }
+ long_pause_log_threshold_ = MsToNs(value);
+ } else if (StartsWith(option, "-XX:LongGCLogThreshold=")) {
+ size_t value;
+ if (!ParseUnsignedInteger(option, '=', &value)) {
+ return false;
+ }
+ long_gc_log_threshold_ = MsToNs(value);
+ } else if (option == "-XX:DumpGCPerformanceOnShutdown") {
+ dump_gc_performance_on_shutdown_ = true;
+ } else if (option == "-XX:IgnoreMaxFootprint") {
+ ignore_max_footprint_ = true;
+ } else if (option == "-XX:LowMemoryMode") {
+ low_memory_mode_ = true;
+ } else if (option == "-XX:UseTLAB") {
+ use_tlab_ = true;
+ } else if (StartsWith(option, "-D")) {
+ properties_.push_back(option.substr(strlen("-D")));
+ } else if (StartsWith(option, "-Xjnitrace:")) {
+ jni_trace_ = option.substr(strlen("-Xjnitrace:"));
+ } else if (option == "compilercallbacks") {
+ compiler_callbacks_ =
+ reinterpret_cast<CompilerCallbacks*>(const_cast<void*>(options[i].second));
+ } else if (option == "-Xzygote") {
+ is_zygote_ = true;
+ } else if (option == "-Xint") {
+ interpreter_only_ = true;
+ } else if (StartsWith(option, "-Xgc:")) {
+ std::vector<std::string> gc_options;
+ Split(option.substr(strlen("-Xgc:")), ',', gc_options);
+ for (const std::string& gc_option : gc_options) {
+ gc::CollectorType collector_type = ParseCollectorType(gc_option);
+ if (collector_type != gc::kCollectorTypeNone) {
+ collector_type_ = collector_type;
+ } else if (gc_option == "preverify") {
+ verify_pre_gc_heap_ = true;
+ } else if (gc_option == "nopreverify") {
+ verify_pre_gc_heap_ = false;
+ } else if (gc_option == "postverify") {
+ verify_post_gc_heap_ = true;
+ } else if (gc_option == "nopostverify") {
+ verify_post_gc_heap_ = false;
+ } else if (gc_option == "preverify_rosalloc") {
+ verify_pre_gc_rosalloc_ = true;
+ } else if (gc_option == "nopreverify_rosalloc") {
+ verify_pre_gc_rosalloc_ = false;
+ } else if (gc_option == "postverify_rosalloc") {
+ verify_post_gc_rosalloc_ = true;
+ } else if (gc_option == "nopostverify_rosalloc") {
+ verify_post_gc_rosalloc_ = false;
+ } else if ((gc_option == "precise") ||
+ (gc_option == "noprecise") ||
+ (gc_option == "verifycardtable") ||
+ (gc_option == "noverifycardtable")) {
+ // Ignored for backwards compatibility.
+ } else {
+ Usage("Unknown -Xgc option %s", gc_option.c_str());
+ return false;
+ }
+ }
+ } else if (StartsWith(option, "-XX:BackgroundGC=")) {
+ std::string substring;
+ if (!ParseStringAfterChar(option, '=', &substring)) {
+ return false;
+ }
+ gc::CollectorType collector_type = ParseCollectorType(substring);
+ if (collector_type != gc::kCollectorTypeNone) {
+ background_collector_type_ = collector_type;
+ } else {
+ Usage("Unknown -XX:BackgroundGC option %s", substring.c_str());
+ return false;
+ }
+ } else if (option == "-XX:+DisableExplicitGC") {
+ is_explicit_gc_disabled_ = true;
+ } else if (StartsWith(option, "-verbose:")) {
+ std::vector<std::string> verbose_options;
+ Split(option.substr(strlen("-verbose:")), ',', verbose_options);
+ for (size_t i = 0; i < verbose_options.size(); ++i) {
+ if (verbose_options[i] == "class") {
+ gLogVerbosity.class_linker = true;
+ } else if (verbose_options[i] == "verifier") {
+ gLogVerbosity.verifier = true;
+ } else if (verbose_options[i] == "compiler") {
+ gLogVerbosity.compiler = true;
+ } else if (verbose_options[i] == "heap") {
+ gLogVerbosity.heap = true;
+ } else if (verbose_options[i] == "gc") {
+ gLogVerbosity.gc = true;
+ } else if (verbose_options[i] == "jdwp") {
+ gLogVerbosity.jdwp = true;
+ } else if (verbose_options[i] == "jni") {
+ gLogVerbosity.jni = true;
+ } else if (verbose_options[i] == "monitor") {
+ gLogVerbosity.monitor = true;
+ } else if (verbose_options[i] == "startup") {
+ gLogVerbosity.startup = true;
+ } else if (verbose_options[i] == "third-party-jni") {
+ gLogVerbosity.third_party_jni = true;
+ } else if (verbose_options[i] == "threads") {
+ gLogVerbosity.threads = true;
+ } else {
+ Usage("Unknown -verbose option %s", verbose_options[i].c_str());
+ return false;
+ }
+ }
+ } else if (StartsWith(option, "-Xlockprofthreshold:")) {
+ if (!ParseUnsignedInteger(option, ':', &lock_profiling_threshold_)) {
+ return false;
+ }
+ } else if (StartsWith(option, "-Xstacktracefile:")) {
+ if (!ParseStringAfterChar(option, ':', &stack_trace_file_)) {
+ return false;
+ }
+ } else if (option == "sensitiveThread") {
+ const void* hook = options[i].second;
+ hook_is_sensitive_thread_ = reinterpret_cast<bool (*)()>(const_cast<void*>(hook));
+ } else if (option == "vfprintf") {
+ const void* hook = options[i].second;
+ if (hook == nullptr) {
+ Usage("vfprintf argument was NULL");
+ return false;
+ }
+ hook_vfprintf_ =
+ reinterpret_cast<int (*)(FILE *, const char*, va_list)>(const_cast<void*>(hook));
+ } else if (option == "exit") {
+ const void* hook = options[i].second;
+ if (hook == nullptr) {
+ Usage("exit argument was NULL");
+ return false;
+ }
+ hook_exit_ = reinterpret_cast<void(*)(jint)>(const_cast<void*>(hook));
+ } else if (option == "abort") {
+ const void* hook = options[i].second;
+ if (hook == nullptr) {
+ Usage("abort was NULL");
+ return false;
+ }
+ hook_abort_ = reinterpret_cast<void(*)()>(const_cast<void*>(hook));
+ } else if (option == "host-prefix") {
+ host_prefix_ = reinterpret_cast<const char*>(options[i].second);
+ } else if (option == "-Xmethod-trace") {
+ method_trace_ = true;
+ } else if (StartsWith(option, "-Xmethod-trace-file:")) {
+ method_trace_file_ = option.substr(strlen("-Xmethod-trace-file:"));
+ } else if (StartsWith(option, "-Xmethod-trace-file-size:")) {
+ if (!ParseUnsignedInteger(option, ':', &method_trace_file_size_)) {
+ return false;
+ }
+ } else if (option == "-Xprofile:threadcpuclock") {
+ Trace::SetDefaultClockSource(kProfilerClockSourceThreadCpu);
+ } else if (option == "-Xprofile:wallclock") {
+ Trace::SetDefaultClockSource(kProfilerClockSourceWall);
+ } else if (option == "-Xprofile:dualclock") {
+ Trace::SetDefaultClockSource(kProfilerClockSourceDual);
+ } else if (StartsWith(option, "-Xprofile:")) {
+ if (!ParseStringAfterChar(option, ';', &profile_output_filename_)) {
+ return false;
+ }
+ profile_ = true;
+ } else if (StartsWith(option, "-Xprofile-period:")) {
+ if (!ParseUnsignedInteger(option, ':', &profile_period_s_)) {
+ return false;
+ }
+ } else if (StartsWith(option, "-Xprofile-duration:")) {
+ if (!ParseUnsignedInteger(option, ':', &profile_duration_s_)) {
+ return false;
+ }
+ } else if (StartsWith(option, "-Xprofile-interval:")) {
+ if (!ParseUnsignedInteger(option, ':', &profile_interval_us_)) {
+ return false;
+ }
+ } else if (StartsWith(option, "-Xprofile-backoff:")) {
+ if (!ParseDouble(option, ':', 1.0, 10.0, &profile_backoff_coefficient_)) {
+ return false;
+ }
+ } else if (option == "-Xcompiler-option") {
+ i++;
+ if (i == options.size()) {
+ Usage("Missing required compiler option for %s", option.c_str());
+ return false;
+ }
+ compiler_options_.push_back(options[i].first);
+ } else if (option == "-Ximage-compiler-option") {
+ i++;
+ if (i == options.size()) {
+ Usage("Missing required compiler option for %s", option.c_str());
+ return false;
+ }
+ image_compiler_options_.push_back(options[i].first);
+ } else if (StartsWith(option, "-ea:") ||
+ StartsWith(option, "-da:") ||
+ StartsWith(option, "-enableassertions:") ||
+ StartsWith(option, "-disableassertions:") ||
+ (option == "-esa") ||
+ (option == "-dsa") ||
+ (option == "-enablesystemassertions") ||
+ (option == "-disablesystemassertions") ||
+ StartsWith(option, "-Xverify:") ||
+ (option == "-Xrs") ||
+ StartsWith(option, "-Xint:") ||
+ StartsWith(option, "-Xdexopt:") ||
+ (option == "-Xnoquithandler") ||
+ StartsWith(option, "-Xjniopts:") ||
+ StartsWith(option, "-Xjnigreflimit:") ||
+ (option == "-Xgenregmap") ||
+ (option == "-Xnogenregmap") ||
+ StartsWith(option, "-Xverifyopt:") ||
+ (option == "-Xcheckdexsum") ||
+ (option == "-Xincludeselectedop") ||
+ StartsWith(option, "-Xjitop:") ||
+ (option == "-Xincludeselectedmethod") ||
+ StartsWith(option, "-Xjitthreshold:") ||
+ StartsWith(option, "-Xjitcodecachesize:") ||
+ (option == "-Xjitblocking") ||
+ StartsWith(option, "-Xjitmethod:") ||
+ StartsWith(option, "-Xjitclass:") ||
+ StartsWith(option, "-Xjitoffset:") ||
+ StartsWith(option, "-Xjitconfig:") ||
+ (option == "-Xjitcheckcg") ||
+ (option == "-Xjitverbose") ||
+ (option == "-Xjitprofile") ||
+ (option == "-Xjitdisableopt") ||
+ (option == "-Xjitsuspendpoll") ||
+ StartsWith(option, "-XX:mainThreadStackSize=")) {
+ // Ignored for backwards compatibility.
+ } else if (!ignore_unrecognized) {
+ Usage("Unrecognized option %s", option.c_str());
+ return false;
+ }
+ }
+
+ // If a reference to the dalvik core.jar snuck in, replace it with
+ // the art specific version. This can happen with on device
+ // boot.art/boot.oat generation by GenerateImage which relies on the
+ // value of BOOTCLASSPATH.
+ std::string core_jar("/core.jar");
+ size_t core_jar_pos = boot_class_path_string_.find(core_jar);
+ if (core_jar_pos != std::string::npos) {
+ boot_class_path_string_.replace(core_jar_pos, core_jar.size(), "/core-libart.jar");
+ }
+
+ if (compiler_callbacks_ == nullptr && image_.empty()) {
+ image_ += GetAndroidRoot();
+ image_ += "/framework/boot.art";
+ }
+ if (heap_growth_limit_ == 0) {
+ heap_growth_limit_ = heap_maximum_size_;
+ }
+ if (background_collector_type_ == gc::kCollectorTypeNone) {
+ background_collector_type_ = collector_type_;
+ }
+ return true;
+}
+
+void ParsedOptions::Exit(int status) {
+ hook_exit_(status);
+}
+
+void ParsedOptions::Abort() {
+ hook_abort_();
+}
+
+void ParsedOptions::UsageMessageV(FILE* stream, const char* fmt, va_list ap) {
+ hook_vfprintf_(stderr, fmt, ap);
+}
+
+void ParsedOptions::UsageMessage(FILE* stream, const char* fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ UsageMessageV(stream, fmt, ap);
+ va_end(ap);
+}
+
+void ParsedOptions::Usage(const char* fmt, ...) {
+ bool error = (fmt != nullptr);
+ FILE* stream = error ? stderr : stdout;
+
+ if (fmt != nullptr) {
+ va_list ap;
+ va_start(ap, fmt);
+ UsageMessageV(stream, fmt, ap);
+ va_end(ap);
+ }
+
+ const char* program = "dalvikvm";
+ UsageMessage(stream, "%s: [options] class [argument ...]\n", program);
+ UsageMessage(stream, "\n");
+ UsageMessage(stream, "The following standard options are supported:\n");
+ UsageMessage(stream, " -classpath classpath (-cp classpath)\n");
+ UsageMessage(stream, " -Dproperty=value\n");
+ UsageMessage(stream, " -verbose:tag ('gc', 'jni', or 'class')\n");
+ UsageMessage(stream, " -showversion\n");
+ UsageMessage(stream, " -help\n");
+ UsageMessage(stream, " -agentlib:jdwp=options\n");
+ UsageMessage(stream, "\n");
+
+ UsageMessage(stream, "The following extended options are supported:\n");
+ UsageMessage(stream, " -Xrunjdwp:<options>\n");
+ UsageMessage(stream, " -Xbootclasspath:bootclasspath\n");
+ UsageMessage(stream, " -Xcheck:tag (e.g. 'jni')\n");
+ UsageMessage(stream, " -XmsN (min heap, must be multiple of 1K, >= 1MB)\n");
+ UsageMessage(stream, " -XmxN (max heap, must be multiple of 1K, >= 2MB)\n");
+ UsageMessage(stream, " -XssN (stack size)\n");
+ UsageMessage(stream, " -Xint\n");
+ UsageMessage(stream, "\n");
+
+ UsageMessage(stream, "The following Dalvik options are supported:\n");
+ UsageMessage(stream, " -Xzygote\n");
+ UsageMessage(stream, " -Xjnitrace:substring (eg NativeClass or nativeMethod)\n");
+ UsageMessage(stream, " -Xstacktracefile:<filename>\n");
+ UsageMessage(stream, " -Xgc:[no]preverify\n");
+ UsageMessage(stream, " -Xgc:[no]postverify\n");
+ UsageMessage(stream, " -XX:+DisableExplicitGC\n");
+ UsageMessage(stream, " -XX:HeapGrowthLimit=N\n");
+ UsageMessage(stream, " -XX:HeapMinFree=N\n");
+ UsageMessage(stream, " -XX:HeapMaxFree=N\n");
+ UsageMessage(stream, " -XX:HeapTargetUtilization=doublevalue\n");
+ UsageMessage(stream, " -XX:LowMemoryMode\n");
+ UsageMessage(stream, " -Xprofile:{threadcpuclock,wallclock,dualclock}\n");
+ UsageMessage(stream, "\n");
+
+ UsageMessage(stream, "The following unique to ART options are supported:\n");
+ UsageMessage(stream, " -Xgc:[no]preverify_rosalloc\n");
+ UsageMessage(stream, " -Xgc:[no]postverify_rosalloc\n");
+ UsageMessage(stream, " -Ximage:filename\n");
+ UsageMessage(stream, " -XX:ParallelGCThreads=integervalue\n");
+ UsageMessage(stream, " -XX:ConcGCThreads=integervalue\n");
+ UsageMessage(stream, " -XX:MaxSpinsBeforeThinLockInflation=integervalue\n");
+ UsageMessage(stream, " -XX:LongPauseLogThreshold=integervalue\n");
+ UsageMessage(stream, " -XX:LongGCLogThreshold=integervalue\n");
+ UsageMessage(stream, " -XX:DumpGCPerformanceOnShutdown\n");
+ UsageMessage(stream, " -XX:IgnoreMaxFootprint\n");
+ UsageMessage(stream, " -XX:UseTLAB\n");
+ UsageMessage(stream, " -XX:BackgroundGC=none\n");
+ UsageMessage(stream, " -Xmethod-trace\n");
+ UsageMessage(stream, " -Xmethod-trace-file:filename");
+ UsageMessage(stream, " -Xmethod-trace-file-size:integervalue\n");
+ UsageMessage(stream, " -Xprofile=filename\n");
+ UsageMessage(stream, " -Xprofile-period:integervalue\n");
+ UsageMessage(stream, " -Xprofile-duration:integervalue\n");
+ UsageMessage(stream, " -Xprofile-interval:integervalue\n");
+ UsageMessage(stream, " -Xprofile-backoff:integervalue\n");
+ UsageMessage(stream, " -Xcompiler-option dex2oat-option\n");
+ UsageMessage(stream, " -Ximage-compiler-option dex2oat-option\n");
+ UsageMessage(stream, "\n");
+
+ UsageMessage(stream, "The following previously supported Dalvik options are ignored:\n");
+ UsageMessage(stream, " -ea[:<package name>... |:<class name>]\n");
+ UsageMessage(stream, " -da[:<package name>... |:<class name>]\n");
+ UsageMessage(stream, " (-enableassertions, -disableassertions)\n");
+ UsageMessage(stream, " -esa\n");
+ UsageMessage(stream, " -dsa\n");
+ UsageMessage(stream, " (-enablesystemassertions, -disablesystemassertions)\n");
+ UsageMessage(stream, " -Xverify:{none,remote,all}\n");
+ UsageMessage(stream, " -Xrs\n");
+ UsageMessage(stream, " -Xint:portable, -Xint:fast, -Xint:jit\n");
+ UsageMessage(stream, " -Xdexopt:{none,verified,all,full}\n");
+ UsageMessage(stream, " -Xnoquithandler\n");
+ UsageMessage(stream, " -Xjniopts:{warnonly,forcecopy}\n");
+ UsageMessage(stream, " -Xjnigreflimit:integervalue\n");
+ UsageMessage(stream, " -Xgc:[no]precise\n");
+ UsageMessage(stream, " -Xgc:[no]verifycardtable\n");
+ UsageMessage(stream, " -X[no]genregmap\n");
+ UsageMessage(stream, " -Xverifyopt:[no]checkmon\n");
+ UsageMessage(stream, " -Xcheckdexsum\n");
+ UsageMessage(stream, " -Xincludeselectedop\n");
+ UsageMessage(stream, " -Xjitop:hexopvalue[-endvalue][,hexopvalue[-endvalue]]*\n");
+ UsageMessage(stream, " -Xincludeselectedmethod\n");
+ UsageMessage(stream, " -Xjitthreshold:integervalue\n");
+ UsageMessage(stream, " -Xjitcodecachesize:decimalvalueofkbytes\n");
+ UsageMessage(stream, " -Xjitblocking\n");
+ UsageMessage(stream, " -Xjitmethod:signature[,signature]* (eg Ljava/lang/String\\;replace)\n");
+ UsageMessage(stream, " -Xjitclass:classname[,classname]*\n");
+ UsageMessage(stream, " -Xjitoffset:offset[,offset]\n");
+ UsageMessage(stream, " -Xjitconfig:filename\n");
+ UsageMessage(stream, " -Xjitcheckcg\n");
+ UsageMessage(stream, " -Xjitverbose\n");
+ UsageMessage(stream, " -Xjitprofile\n");
+ UsageMessage(stream, " -Xjitdisableopt\n");
+ UsageMessage(stream, " -Xjitsuspendpoll\n");
+ UsageMessage(stream, " -XX:mainThreadStackSize=N\n");
+ UsageMessage(stream, "\n");
+
+ Exit((error) ? 1 : 0);
+}
+
+bool ParsedOptions::ParseStringAfterChar(const std::string& s, char c, std::string* parsed_value) {
+ std::string::size_type colon = s.find(c);
+ if (colon == std::string::npos) {
+ Usage("Missing char %c in option %s", c, s.c_str());
+ return false;
+ }
+ // Add one to remove the char we were trimming until.
+ *parsed_value = s.substr(colon + 1);
+ return true;
+}
+
+bool ParsedOptions::ParseInteger(const std::string& s, char after_char, int* parsed_value) {
+ std::string::size_type colon = s.find(after_char);
+ if (colon == std::string::npos) {
+ Usage("Missing char %c in option %s", after_char, s.c_str());
+ return false;
+ }
+ const char* begin = &s[colon + 1];
+ char* end;
+ size_t result = strtoul(begin, &end, 10);
+ if (begin == end || *end != '\0') {
+ Usage("Failed to parse integer from %s ", s.c_str());
+ return false;
+ }
+ *parsed_value = result;
+ return true;
+}
+
+bool ParsedOptions::ParseUnsignedInteger(const std::string& s, char after_char,
+ unsigned int* parsed_value) {
+ int i;
+ if (!ParseInteger(s, after_char, &i)) {
+ return false;
+ }
+ if (i < 0) {
+ Usage("Negative value %d passed for unsigned option %s", i, s.c_str());
+ return false;
+ }
+ *parsed_value = i;
+ return true;
+}
+
+bool ParsedOptions::ParseDouble(const std::string& option, char after_char,
+ double min, double max, double* parsed_value) {
+ std::string substring;
+ if (!ParseStringAfterChar(option, after_char, &substring)) {
+ return false;
+ }
+ std::istringstream iss(substring);
+ double value;
+ iss >> value;
+ // Ensure that we have a value, there was no cruft after it and it satisfies a sensible range.
+ const bool sane_val = iss.eof() && (value >= min) && (value <= max);
+ if (!sane_val) {
+ Usage("Invalid double value %s for option %s", option.c_str());
+ return false;
+ }
+ *parsed_value = value;
+ return true;
+}
+
+} // namespace art
diff --git a/runtime/parsed_options.h b/runtime/parsed_options.h
new file mode 100644
index 0000000..b94956e
--- /dev/null
+++ b/runtime/parsed_options.h
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_RUNTIME_PARSED_OPTIONS_H_
+#define ART_RUNTIME_PARSED_OPTIONS_H_
+
+#include <string>
+
+#include "runtime.h"
+#include "trace.h"
+
+namespace art {
+
+class ParsedOptions {
+ public:
+ // returns null if problem parsing and ignore_unrecognized is false
+ static ParsedOptions* Create(const Runtime::Options& options, bool ignore_unrecognized);
+
+ const std::vector<const DexFile*>* boot_class_path_;
+ std::string boot_class_path_string_;
+ std::string class_path_string_;
+ std::string host_prefix_;
+ std::string image_;
+ bool check_jni_;
+ std::string jni_trace_;
+ CompilerCallbacks* compiler_callbacks_;
+ bool is_zygote_;
+ bool interpreter_only_;
+ bool is_explicit_gc_disabled_;
+ bool use_tlab_;
+ bool verify_pre_gc_heap_;
+ bool verify_post_gc_heap_;
+ bool verify_pre_gc_rosalloc_;
+ bool verify_post_gc_rosalloc_;
+ size_t long_pause_log_threshold_;
+ size_t long_gc_log_threshold_;
+ bool dump_gc_performance_on_shutdown_;
+ bool ignore_max_footprint_;
+ size_t heap_initial_size_;
+ size_t heap_maximum_size_;
+ size_t heap_growth_limit_;
+ size_t heap_min_free_;
+ size_t heap_max_free_;
+ double heap_target_utilization_;
+ size_t parallel_gc_threads_;
+ size_t conc_gc_threads_;
+ gc::CollectorType collector_type_;
+ gc::CollectorType background_collector_type_;
+ size_t stack_size_;
+ size_t max_spins_before_thin_lock_inflation_;
+ bool low_memory_mode_;
+ size_t lock_profiling_threshold_;
+ std::string stack_trace_file_;
+ bool method_trace_;
+ std::string method_trace_file_;
+ size_t method_trace_file_size_;
+ bool (*hook_is_sensitive_thread_)();
+ jint (*hook_vfprintf_)(FILE* stream, const char* format, va_list ap);
+ void (*hook_exit_)(jint status);
+ void (*hook_abort_)();
+ std::vector<std::string> properties_;
+ std::vector<std::string> compiler_options_;
+ std::vector<std::string> image_compiler_options_;
+ bool profile_;
+ std::string profile_output_filename_;
+ uint32_t profile_period_s_;
+ uint32_t profile_duration_s_;
+ uint32_t profile_interval_us_;
+ double profile_backoff_coefficient_;
+ ProfilerClockSource profile_clock_source_;
+
+ private:
+ ParsedOptions() {}
+
+ void Usage(const char* fmt, ...);
+ void UsageMessage(FILE* stream, const char* fmt, ...);
+ void UsageMessageV(FILE* stream, const char* fmt, va_list ap);
+
+ void Exit(int status);
+ void Abort();
+
+ bool Parse(const Runtime::Options& options, bool ignore_unrecognized);
+ bool ParseStringAfterChar(const std::string& option, char after_char, std::string* parsed_value);
+ bool ParseInteger(const std::string& option, char after_char, int* parsed_value);
+ bool ParseUnsignedInteger(const std::string& option, char after_char, unsigned int* parsed_value);
+ bool ParseDouble(const std::string& option, char after_char, double min, double max,
+ double* parsed_value);
+};
+
+} // namespace art
+
+#endif // ART_RUNTIME_PARSED_OPTIONS_H_
diff --git a/runtime/runtime_test.cc b/runtime/parsed_options_test.cc
index 5b881e5..58353b1 100644
--- a/runtime/runtime_test.cc
+++ b/runtime/parsed_options_test.cc
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-#include "runtime.h"
+#include "parsed_options.h"
#include "UniquePtr.h"
#include "common_runtime_test.h"
namespace art {
-class RuntimeTest : public CommonRuntimeTest {};
+class ParsedOptionsTest : public CommonRuntimeTest {};
-TEST_F(RuntimeTest, ParsedOptions) {
+TEST_F(ParsedOptionsTest, ParsedOptions) {
void* test_vfprintf = reinterpret_cast<void*>(0xa);
void* test_abort = reinterpret_cast<void*>(0xb);
void* test_exit = reinterpret_cast<void*>(0xc);
@@ -54,7 +54,7 @@ TEST_F(RuntimeTest, ParsedOptions) {
options.push_back(std::make_pair("vfprintf", test_vfprintf));
options.push_back(std::make_pair("abort", test_abort));
options.push_back(std::make_pair("exit", test_exit));
- UniquePtr<Runtime::ParsedOptions> parsed(Runtime::ParsedOptions::Create(options, false));
+ UniquePtr<ParsedOptions> parsed(ParsedOptions::Create(options, false));
ASSERT_TRUE(parsed.get() != NULL);
EXPECT_EQ(lib_core, parsed->boot_class_path_string_);
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 90ba7d3..ae9c983 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -51,6 +51,7 @@
#include "mirror/stack_trace_element.h"
#include "mirror/throwable.h"
#include "monitor.h"
+#include "parsed_options.h"
#include "oat_file.h"
#include "ScopedLocalRef.h"
#include "scoped_thread_state_change.h"
@@ -265,113 +266,6 @@ void Runtime::CallExitHook(jint status) {
}
}
-// Parse a string of the form /[0-9]+[kKmMgG]?/, which is used to specify
-// memory sizes. [kK] indicates kilobytes, [mM] megabytes, and
-// [gG] gigabytes.
-//
-// "s" should point just past the "-Xm?" part of the string.
-// "div" specifies a divisor, e.g. 1024 if the value must be a multiple
-// of 1024.
-//
-// The spec says the -Xmx and -Xms options must be multiples of 1024. It
-// doesn't say anything about -Xss.
-//
-// Returns 0 (a useless size) if "s" is malformed or specifies a low or
-// non-evenly-divisible value.
-//
-size_t ParseMemoryOption(const char* s, size_t div) {
- // strtoul accepts a leading [+-], which we don't want,
- // so make sure our string starts with a decimal digit.
- if (isdigit(*s)) {
- char* s2;
- size_t val = strtoul(s, &s2, 10);
- if (s2 != s) {
- // s2 should be pointing just after the number.
- // If this is the end of the string, the user
- // has specified a number of bytes. Otherwise,
- // there should be exactly one more character
- // that specifies a multiplier.
- if (*s2 != '\0') {
- // The remainder of the string is either a single multiplier
- // character, or nothing to indicate that the value is in
- // bytes.
- char c = *s2++;
- if (*s2 == '\0') {
- size_t mul;
- if (c == '\0') {
- mul = 1;
- } else if (c == 'k' || c == 'K') {
- mul = KB;
- } else if (c == 'm' || c == 'M') {
- mul = MB;
- } else if (c == 'g' || c == 'G') {
- mul = GB;
- } else {
- // Unknown multiplier character.
- return 0;
- }
-
- if (val <= std::numeric_limits<size_t>::max() / mul) {
- val *= mul;
- } else {
- // Clamp to a multiple of 1024.
- val = std::numeric_limits<size_t>::max() & ~(1024-1);
- }
- } else {
- // There's more than one character after the numeric part.
- return 0;
- }
- }
- // The man page says that a -Xm value must be a multiple of 1024.
- if (val % div == 0) {
- return val;
- }
- }
- }
- return 0;
-}
-
-static const std::string StringAfterChar(const std::string& s, char c) {
- std::string::size_type colon = s.find(c);
- if (colon == std::string::npos) {
- LOG(FATAL) << "Missing char " << c << " in string " << s;
- }
- // Add one to remove the char we were trimming until.
- return s.substr(colon + 1);
-}
-
-static size_t ParseIntegerOrDie(const std::string& s, char after_char) {
- std::string::size_type colon = s.find(after_char);
- if (colon == std::string::npos) {
- LOG(FATAL) << "Missing char " << after_char << " in string " << s;
- }
- const char* begin = &s[colon + 1];
- char* end;
- size_t result = strtoul(begin, &end, 10);
- if (begin == end || *end != '\0') {
- LOG(FATAL) << "Failed to parse integer in: " << s;
- }
- return result;
-}
-
-
-static double ParseDoubleOrDie(const std::string& option, char after_char, double min, double max,
- bool ignore_unrecognized, double defval) {
- std::istringstream iss(StringAfterChar(option, after_char));
- double value;
- iss >> value;
- // Ensure that we have a value, there was no cruft after it and it satisfies a sensible range.
- const bool sane_val = iss.eof() && (value >= min) && (value <= max);
- if (!sane_val) {
- if (ignore_unrecognized) {
- return defval;
- }
- LOG(FATAL)<< "Invalid option '" << option << "'";
- return defval;
- }
- return value;
-}
-
void Runtime::SweepSystemWeaks(IsMarkedCallback* visitor, void* arg) {
GetInternTable()->SweepInternTableWeaks(visitor, arg);
GetMonitorList()->SweepMonitorList(visitor, arg);
@@ -379,384 +273,6 @@ void Runtime::SweepSystemWeaks(IsMarkedCallback* visitor, void* arg) {
Dbg::UpdateObjectPointers(visitor, arg);
}
-static gc::CollectorType ParseCollectorType(const std::string& option) {
- if (option == "MS" || option == "nonconcurrent") {
- return gc::kCollectorTypeMS;
- } else if (option == "CMS" || option == "concurrent") {
- return gc::kCollectorTypeCMS;
- } else if (option == "SS") {
- return gc::kCollectorTypeSS;
- } else if (option == "GSS") {
- return gc::kCollectorTypeGSS;
- } else {
- return gc::kCollectorTypeNone;
- }
-}
-
-Runtime::ParsedOptions* Runtime::ParsedOptions::Create(const Options& options, bool ignore_unrecognized) {
- UniquePtr<ParsedOptions> parsed(new ParsedOptions());
- const char* boot_class_path_string = getenv("BOOTCLASSPATH");
- if (boot_class_path_string != NULL) {
- parsed->boot_class_path_string_ = boot_class_path_string;
- }
- const char* class_path_string = getenv("CLASSPATH");
- if (class_path_string != NULL) {
- parsed->class_path_string_ = class_path_string;
- }
- // -Xcheck:jni is off by default for regular builds but on by default in debug builds.
- parsed->check_jni_ = kIsDebugBuild;
-
- parsed->heap_initial_size_ = gc::Heap::kDefaultInitialSize;
- parsed->heap_maximum_size_ = gc::Heap::kDefaultMaximumSize;
- parsed->heap_min_free_ = gc::Heap::kDefaultMinFree;
- parsed->heap_max_free_ = gc::Heap::kDefaultMaxFree;
- parsed->heap_target_utilization_ = gc::Heap::kDefaultTargetUtilization;
- parsed->heap_growth_limit_ = 0; // 0 means no growth limit .
- // Default to number of processors minus one since the main GC thread also does work.
- parsed->parallel_gc_threads_ = sysconf(_SC_NPROCESSORS_CONF) - 1;
- // Only the main GC thread, no workers.
- parsed->conc_gc_threads_ = 0;
- // Default is CMS which is Sticky + Partial + Full CMS GC.
- parsed->collector_type_ = gc::kCollectorTypeCMS;
- // If background_collector_type_ is kCollectorTypeNone, it defaults to the collector_type_ after
- // parsing options.
- parsed->background_collector_type_ = gc::kCollectorTypeNone;
- parsed->stack_size_ = 0; // 0 means default.
- parsed->max_spins_before_thin_lock_inflation_ = Monitor::kDefaultMaxSpinsBeforeThinLockInflation;
- parsed->low_memory_mode_ = false;
- parsed->use_tlab_ = false;
- parsed->verify_pre_gc_heap_ = false;
- parsed->verify_post_gc_heap_ = kIsDebugBuild;
- parsed->verify_pre_gc_rosalloc_ = kIsDebugBuild;
- parsed->verify_post_gc_rosalloc_ = false;
-
- parsed->compiler_callbacks_ = nullptr;
- parsed->is_zygote_ = false;
- parsed->interpreter_only_ = false;
- parsed->is_explicit_gc_disabled_ = false;
-
- parsed->long_pause_log_threshold_ = gc::Heap::kDefaultLongPauseLogThreshold;
- parsed->long_gc_log_threshold_ = gc::Heap::kDefaultLongGCLogThreshold;
- parsed->dump_gc_performance_on_shutdown_ = false;
- parsed->ignore_max_footprint_ = false;
-
- parsed->lock_profiling_threshold_ = 0;
- parsed->hook_is_sensitive_thread_ = NULL;
-
- parsed->hook_vfprintf_ = vfprintf;
- parsed->hook_exit_ = exit;
- parsed->hook_abort_ = NULL; // We don't call abort(3) by default; see Runtime::Abort.
-
-// gLogVerbosity.class_linker = true; // TODO: don't check this in!
-// gLogVerbosity.compiler = true; // TODO: don't check this in!
-// gLogVerbosity.verifier = true; // TODO: don't check this in!
-// gLogVerbosity.heap = true; // TODO: don't check this in!
-// gLogVerbosity.gc = true; // TODO: don't check this in!
-// gLogVerbosity.jdwp = true; // TODO: don't check this in!
-// gLogVerbosity.jni = true; // TODO: don't check this in!
-// gLogVerbosity.monitor = true; // TODO: don't check this in!
-// gLogVerbosity.startup = true; // TODO: don't check this in!
-// gLogVerbosity.third_party_jni = true; // TODO: don't check this in!
-// gLogVerbosity.threads = true; // TODO: don't check this in!
-
- parsed->method_trace_ = false;
- parsed->method_trace_file_ = "/data/method-trace-file.bin";
- parsed->method_trace_file_size_ = 10 * MB;
-
- parsed->profile_ = false;
- parsed->profile_period_s_ = 10; // Seconds.
- parsed->profile_duration_s_ = 20; // Seconds.
- parsed->profile_interval_us_ = 500; // Microseconds.
- parsed->profile_backoff_coefficient_ = 2.0;
-
- for (size_t i = 0; i < options.size(); ++i) {
- const std::string option(options[i].first);
- if (true && options[0].first == "-Xzygote") {
- LOG(INFO) << "option[" << i << "]=" << option;
- }
- if (StartsWith(option, "-Xbootclasspath:")) {
- parsed->boot_class_path_string_ = option.substr(strlen("-Xbootclasspath:")).data();
- } else if (option == "-classpath" || option == "-cp") {
- // TODO: support -Djava.class.path
- i++;
- if (i == options.size()) {
- // TODO: usage
- LOG(FATAL) << "Missing required class path value for " << option;
- return NULL;
- }
- const StringPiece& value = options[i].first;
- parsed->class_path_string_ = value.data();
- } else if (option == "bootclasspath") {
- parsed->boot_class_path_
- = reinterpret_cast<const std::vector<const DexFile*>*>(options[i].second);
- } else if (StartsWith(option, "-Ximage:")) {
- parsed->image_ = StringAfterChar(option, ':');
- } else if (StartsWith(option, "-Xcheck:jni")) {
- parsed->check_jni_ = true;
- } else if (StartsWith(option, "-Xrunjdwp:") || StartsWith(option, "-agentlib:jdwp=")) {
- std::string tail(option.substr(option[1] == 'X' ? 10 : 15));
- if (tail == "help" || !Dbg::ParseJdwpOptions(tail)) {
- LOG(FATAL) << "Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n"
- << "Example: -Xrunjdwp:transport=dt_socket,address=localhost:6500,server=n";
- return NULL;
- }
- } else if (StartsWith(option, "-Xms")) {
- size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).c_str(), 1024);
- if (size == 0) {
- if (ignore_unrecognized) {
- continue;
- }
- // TODO: usage
- LOG(FATAL) << "Failed to parse " << option;
- return NULL;
- }
- parsed->heap_initial_size_ = size;
- } else if (StartsWith(option, "-Xmx")) {
- size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).c_str(), 1024);
- if (size == 0) {
- if (ignore_unrecognized) {
- continue;
- }
- // TODO: usage
- LOG(FATAL) << "Failed to parse " << option;
- return NULL;
- }
- parsed->heap_maximum_size_ = size;
- } else if (StartsWith(option, "-XX:HeapGrowthLimit=")) {
- size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapGrowthLimit=")).c_str(), 1024);
- if (size == 0) {
- if (ignore_unrecognized) {
- continue;
- }
- // TODO: usage
- LOG(FATAL) << "Failed to parse " << option;
- return NULL;
- }
- parsed->heap_growth_limit_ = size;
- } else if (StartsWith(option, "-XX:HeapMinFree=")) {
- size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMinFree=")).c_str(), 1024);
- if (size == 0) {
- if (ignore_unrecognized) {
- continue;
- }
- // TODO: usage
- LOG(FATAL) << "Failed to parse " << option;
- return NULL;
- }
- parsed->heap_min_free_ = size;
- } else if (StartsWith(option, "-XX:HeapMaxFree=")) {
- size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMaxFree=")).c_str(), 1024);
- if (size == 0) {
- if (ignore_unrecognized) {
- continue;
- }
- // TODO: usage
- LOG(FATAL) << "Failed to parse " << option;
- return NULL;
- }
- parsed->heap_max_free_ = size;
- } else if (StartsWith(option, "-XX:HeapTargetUtilization=")) {
- parsed->heap_target_utilization_ = ParseDoubleOrDie(
- option, '=', 0.1, 0.9, ignore_unrecognized, parsed->heap_target_utilization_);
- } else if (StartsWith(option, "-XX:ParallelGCThreads=")) {
- parsed->parallel_gc_threads_ = ParseIntegerOrDie(option, '=');
- } else if (StartsWith(option, "-XX:ConcGCThreads=")) {
- parsed->conc_gc_threads_ = ParseIntegerOrDie(option, '=');
- } else if (StartsWith(option, "-Xss")) {
- size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).c_str(), 1);
- if (size == 0) {
- if (ignore_unrecognized) {
- continue;
- }
- // TODO: usage
- LOG(FATAL) << "Failed to parse " << option;
- return NULL;
- }
- parsed->stack_size_ = size;
- } else if (StartsWith(option, "-XX:MaxSpinsBeforeThinLockInflation=")) {
- parsed->max_spins_before_thin_lock_inflation_ = ParseIntegerOrDie(option, '=');
- } else if (StartsWith(option, "-XX:LongPauseLogThreshold=")) {
- parsed->long_pause_log_threshold_ = MsToNs(ParseIntegerOrDie(option, '='));
- } else if (StartsWith(option, "-XX:LongGCLogThreshold=")) {
- parsed->long_gc_log_threshold_ = MsToNs(ParseIntegerOrDie(option, '='));
- } else if (option == "-XX:DumpGCPerformanceOnShutdown") {
- parsed->dump_gc_performance_on_shutdown_ = true;
- } else if (option == "-XX:IgnoreMaxFootprint") {
- parsed->ignore_max_footprint_ = true;
- } else if (option == "-XX:LowMemoryMode") {
- parsed->low_memory_mode_ = true;
- } else if (option == "-XX:UseTLAB") {
- parsed->use_tlab_ = true;
- } else if (StartsWith(option, "-D")) {
- parsed->properties_.push_back(option.substr(strlen("-D")));
- } else if (StartsWith(option, "-Xjnitrace:")) {
- parsed->jni_trace_ = option.substr(strlen("-Xjnitrace:"));
- } else if (option == "compilercallbacks") {
- parsed->compiler_callbacks_ =
- reinterpret_cast<CompilerCallbacks*>(const_cast<void*>(options[i].second));
- } else if (option == "-Xzygote") {
- parsed->is_zygote_ = true;
- } else if (option == "-Xint") {
- parsed->interpreter_only_ = true;
- } else if (StartsWith(option, "-Xgc:")) {
- std::vector<std::string> gc_options;
- Split(option.substr(strlen("-Xgc:")), ',', gc_options);
- for (const std::string& gc_option : gc_options) {
- gc::CollectorType collector_type = ParseCollectorType(gc_option);
- if (collector_type != gc::kCollectorTypeNone) {
- parsed->collector_type_ = collector_type;
- } else if (gc_option == "preverify") {
- parsed->verify_pre_gc_heap_ = true;
- } else if (gc_option == "nopreverify") {
- parsed->verify_pre_gc_heap_ = false;
- } else if (gc_option == "postverify") {
- parsed->verify_post_gc_heap_ = true;
- } else if (gc_option == "nopostverify") {
- parsed->verify_post_gc_heap_ = false;
- } else if (gc_option == "preverify_rosalloc") {
- parsed->verify_pre_gc_rosalloc_ = true;
- } else if (gc_option == "nopreverify_rosalloc") {
- parsed->verify_pre_gc_rosalloc_ = false;
- } else if (gc_option == "postverify_rosalloc") {
- parsed->verify_post_gc_rosalloc_ = true;
- } else if (gc_option == "nopostverify_rosalloc") {
- parsed->verify_post_gc_rosalloc_ = false;
- } else {
- LOG(WARNING) << "Ignoring unknown -Xgc option: " << gc_option;
- }
- }
- } else if (StartsWith(option, "-XX:BackgroundGC=")) {
- const std::string substring = StringAfterChar(option, '=');
- gc::CollectorType collector_type = ParseCollectorType(substring);
- if (collector_type != gc::kCollectorTypeNone) {
- parsed->background_collector_type_ = collector_type;
- } else {
- LOG(WARNING) << "Ignoring unknown -XX:BackgroundGC option: " << substring;
- }
- } else if (option == "-XX:+DisableExplicitGC") {
- parsed->is_explicit_gc_disabled_ = true;
- } else if (StartsWith(option, "-verbose:")) {
- std::vector<std::string> verbose_options;
- Split(option.substr(strlen("-verbose:")), ',', verbose_options);
- for (size_t i = 0; i < verbose_options.size(); ++i) {
- if (verbose_options[i] == "class") {
- gLogVerbosity.class_linker = true;
- } else if (verbose_options[i] == "verifier") {
- gLogVerbosity.verifier = true;
- } else if (verbose_options[i] == "compiler") {
- gLogVerbosity.compiler = true;
- } else if (verbose_options[i] == "heap") {
- gLogVerbosity.heap = true;
- } else if (verbose_options[i] == "gc") {
- gLogVerbosity.gc = true;
- } else if (verbose_options[i] == "jdwp") {
- gLogVerbosity.jdwp = true;
- } else if (verbose_options[i] == "jni") {
- gLogVerbosity.jni = true;
- } else if (verbose_options[i] == "monitor") {
- gLogVerbosity.monitor = true;
- } else if (verbose_options[i] == "startup") {
- gLogVerbosity.startup = true;
- } else if (verbose_options[i] == "third-party-jni") {
- gLogVerbosity.third_party_jni = true;
- } else if (verbose_options[i] == "threads") {
- gLogVerbosity.threads = true;
- } else {
- LOG(WARNING) << "Ignoring unknown -verbose option: " << verbose_options[i];
- }
- }
- } else if (StartsWith(option, "-Xjnigreflimit:")) {
- // Silently ignored for backwards compatibility.
- } else if (StartsWith(option, "-Xlockprofthreshold:")) {
- parsed->lock_profiling_threshold_ = ParseIntegerOrDie(option, ':');
- } else if (StartsWith(option, "-Xstacktracefile:")) {
- parsed->stack_trace_file_ = StringAfterChar(option, ':');
- } else if (option == "sensitiveThread") {
- parsed->hook_is_sensitive_thread_ = reinterpret_cast<bool (*)()>(const_cast<void*>(options[i].second));
- } else if (option == "vfprintf") {
- parsed->hook_vfprintf_ =
- reinterpret_cast<int (*)(FILE *, const char*, va_list)>(const_cast<void*>(options[i].second));
- } else if (option == "exit") {
- parsed->hook_exit_ = reinterpret_cast<void(*)(jint)>(const_cast<void*>(options[i].second));
- } else if (option == "abort") {
- parsed->hook_abort_ = reinterpret_cast<void(*)()>(const_cast<void*>(options[i].second));
- } else if (option == "host-prefix") {
- parsed->host_prefix_ = reinterpret_cast<const char*>(options[i].second);
- } else if (option == "-Xgenregmap" || option == "-Xgc:precise") {
- // We silently ignore these for backwards compatibility.
- } else if (option == "-Xmethod-trace") {
- parsed->method_trace_ = true;
- } else if (StartsWith(option, "-Xmethod-trace-file:")) {
- parsed->method_trace_file_ = option.substr(strlen("-Xmethod-trace-file:"));
- } else if (StartsWith(option, "-Xmethod-trace-file-size:")) {
- parsed->method_trace_file_size_ = ParseIntegerOrDie(option, ':');
- } else if (option == "-Xprofile:threadcpuclock") {
- Trace::SetDefaultClockSource(kProfilerClockSourceThreadCpu);
- } else if (option == "-Xprofile:wallclock") {
- Trace::SetDefaultClockSource(kProfilerClockSourceWall);
- } else if (option == "-Xprofile:dualclock") {
- Trace::SetDefaultClockSource(kProfilerClockSourceDual);
- } else if (StartsWith(option, "-Xprofile:")) {
- parsed->profile_output_filename_ = StringAfterChar(option, ';');
- parsed->profile_ = true;
- } else if (StartsWith(option, "-Xprofile-period:")) {
- parsed->profile_period_s_ = ParseIntegerOrDie(option, ':');
- } else if (StartsWith(option, "-Xprofile-duration:")) {
- parsed->profile_duration_s_ = ParseIntegerOrDie(option, ':');
- } else if (StartsWith(option, "-Xprofile-interval:")) {
- parsed->profile_interval_us_ = ParseIntegerOrDie(option, ':');
- } else if (StartsWith(option, "-Xprofile-backoff:")) {
- parsed->profile_backoff_coefficient_ = ParseDoubleOrDie(
- option, ':', 1.0, 10.0, ignore_unrecognized, parsed->profile_backoff_coefficient_);
- } else if (option == "-Xcompiler-option") {
- i++;
- if (i == options.size()) {
- // TODO: usage
- LOG(FATAL) << "Missing required compiler option for " << option;
- return NULL;
- }
- parsed->compiler_options_.push_back(options[i].first);
- } else if (option == "-Ximage-compiler-option") {
- i++;
- if (i == options.size()) {
- // TODO: usage
- LOG(FATAL) << "Missing required compiler option for " << option;
- return NULL;
- }
- parsed->image_compiler_options_.push_back(options[i].first);
- } else {
- if (!ignore_unrecognized) {
- // TODO: print usage via vfprintf
- LOG(ERROR) << "Unrecognized option " << option;
- // TODO: this should exit, but for now tolerate unknown options
- // return NULL;
- }
- }
- }
-
- // If a reference to the dalvik core.jar snuck in, replace it with
- // the art specific version. This can happen with on device
- // boot.art/boot.oat generation by GenerateImage which relies on the
- // value of BOOTCLASSPATH.
- std::string core_jar("/core.jar");
- size_t core_jar_pos = parsed->boot_class_path_string_.find(core_jar);
- if (core_jar_pos != std::string::npos) {
- parsed->boot_class_path_string_.replace(core_jar_pos, core_jar.size(), "/core-libart.jar");
- }
-
- if (parsed->compiler_callbacks_ == nullptr && parsed->image_.empty()) {
- parsed->image_ += GetAndroidRoot();
- parsed->image_ += "/framework/boot.art";
- }
- if (parsed->heap_growth_limit_ == 0) {
- parsed->heap_growth_limit_ = parsed->heap_maximum_size_;
- }
- if (parsed->background_collector_type_ == gc::kCollectorTypeNone) {
- parsed->background_collector_type_ = parsed->collector_type_;
- }
- return parsed.release();
-}
-
bool Runtime::Create(const Options& options, bool ignore_unrecognized) {
// TODO: acquire a static mutex on Runtime to avoid racing.
if (Runtime::instance_ != NULL) {
@@ -801,8 +317,9 @@ jobject CreateSystemClassLoader() {
soa.Self()->SetClassLoaderOverride(class_loader.get());
- SirtRef<mirror::Class> thread_class(soa.Self(),
- soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_Thread));
+ SirtRef<mirror::Class> thread_class(
+ soa.Self(),
+ soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_Thread));
CHECK(cl->EnsureInitialized(thread_class, true, true));
mirror::ArtField* contextClassLoader =
@@ -1048,12 +565,15 @@ bool Runtime::Init(const Options& raw_options, bool ignore_unrecognized) {
method_trace_file_size_ = options->method_trace_file_size_;
// Extract the profile options.
+ // TODO: move into a Trace options struct?
profile_period_s_ = options->profile_period_s_;
profile_duration_s_ = options->profile_duration_s_;
profile_interval_us_ = options->profile_interval_us_;
profile_backoff_coefficient_ = options->profile_backoff_coefficient_;
profile_ = options->profile_;
profile_output_filename_ = options->profile_output_filename_;
+ // TODO: move this to just be an Trace::Start argument
+ Trace::SetDefaultClockSource(options->profile_clock_source_);
if (options->method_trace_) {
Trace::Start(options->method_trace_file_.c_str(), -1, options->method_trace_file_size_, 0,
@@ -1062,7 +582,8 @@ bool Runtime::Init(const Options& raw_options, bool ignore_unrecognized) {
// Pre-allocate an OutOfMemoryError for the double-OOME case.
self->ThrowNewException(ThrowLocation(), "Ljava/lang/OutOfMemoryError;",
- "OutOfMemoryError thrown while trying to throw OutOfMemoryError; no stack available");
+ "OutOfMemoryError thrown while trying to throw OutOfMemoryError; "
+ "no stack available");
pre_allocated_OutOfMemoryError_ = self->GetException(NULL);
self->ClearException();
@@ -1110,12 +631,14 @@ void Runtime::InitThreadGroups(Thread* self) {
JNIEnvExt* env = self->GetJniEnv();
ScopedJniEnvLocalRefState env_state(env);
main_thread_group_ =
- env->NewGlobalRef(env->GetStaticObjectField(WellKnownClasses::java_lang_ThreadGroup,
- WellKnownClasses::java_lang_ThreadGroup_mainThreadGroup));
+ env->NewGlobalRef(env->GetStaticObjectField(
+ WellKnownClasses::java_lang_ThreadGroup,
+ WellKnownClasses::java_lang_ThreadGroup_mainThreadGroup));
CHECK(main_thread_group_ != NULL || IsCompiler());
system_thread_group_ =
- env->NewGlobalRef(env->GetStaticObjectField(WellKnownClasses::java_lang_ThreadGroup,
- WellKnownClasses::java_lang_ThreadGroup_systemThreadGroup));
+ env->NewGlobalRef(env->GetStaticObjectField(
+ WellKnownClasses::java_lang_ThreadGroup,
+ WellKnownClasses::java_lang_ThreadGroup_systemThreadGroup));
CHECK(system_thread_group_ != NULL || IsCompiler());
}
@@ -1459,7 +982,7 @@ mirror::ArtMethod* Runtime::CreateCalleeSaveMethod(InstructionSet instruction_se
(1 << art::x86_64::RSI) | (1 << art::x86_64::RDX) | (1 << art::x86_64::RCX) |
(1 << art::x86_64::R8) | (1 << art::x86_64::R9);
uint32_t core_spills = ref_spills | (type == kRefsAndArgs ? arg_spills : 0) |
- (1 << art::x86_64::kNumberOfCpuRegisters); // fake return address callee save
+ (1 << art::x86_64::kNumberOfCpuRegisters); // fake return address callee save
uint32_t fp_arg_spills =
(1 << art::x86_64::XMM0) | (1 << art::x86_64::XMM1) | (1 << art::x86_64::XMM2) |
(1 << art::x86_64::XMM3) | (1 << art::x86_64::XMM4) | (1 << art::x86_64::XMM5) |
@@ -1506,7 +1029,8 @@ const std::vector<const DexFile*>& Runtime::GetCompileTimeClassPath(jobject clas
return it->second;
}
-void Runtime::SetCompileTimeClassPath(jobject class_loader, std::vector<const DexFile*>& class_path) {
+void Runtime::SetCompileTimeClassPath(jobject class_loader,
+ std::vector<const DexFile*>& class_path) {
CHECK(!IsStarted());
use_compile_time_class_path_ = true;
compile_time_class_paths_.Put(class_loader, class_path);
@@ -1527,8 +1051,9 @@ void Runtime::RemoveMethodVerifier(verifier::MethodVerifier* verifier) {
}
void Runtime::StartProfiler(const char *appDir, bool startImmediately) {
- BackgroundMethodSamplingProfiler::Start(profile_period_s_, profile_duration_s_, appDir, profile_interval_us_,
- profile_backoff_coefficient_, startImmediately);
+ BackgroundMethodSamplingProfiler::Start(profile_period_s_, profile_duration_s_, appDir,
+ profile_interval_us_, profile_backoff_coefficient_,
+ startImmediately);
}
// Transaction support.
@@ -1605,4 +1130,5 @@ void Runtime::SetFaultMessage(const std::string& message) {
MutexLock mu(Thread::Current(), fault_message_lock_);
fault_message_ = message;
}
+
} // namespace art
diff --git a/runtime/runtime.h b/runtime/runtime.h
index 7f8e915..5ff334f 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -72,67 +72,6 @@ class Runtime {
public:
typedef std::vector<std::pair<std::string, const void*> > Options;
- class ParsedOptions {
- public:
- // returns null if problem parsing and ignore_unrecognized is false
- static ParsedOptions* Create(const Options& options, bool ignore_unrecognized);
-
- const std::vector<const DexFile*>* boot_class_path_;
- std::string boot_class_path_string_;
- std::string class_path_string_;
- std::string host_prefix_;
- std::string image_;
- bool check_jni_;
- std::string jni_trace_;
- CompilerCallbacks* compiler_callbacks_;
- bool is_zygote_;
- bool interpreter_only_;
- bool is_explicit_gc_disabled_;
- bool use_tlab_;
- bool verify_pre_gc_heap_;
- bool verify_post_gc_heap_;
- bool verify_pre_gc_rosalloc_;
- bool verify_post_gc_rosalloc_;
- size_t long_pause_log_threshold_;
- size_t long_gc_log_threshold_;
- bool dump_gc_performance_on_shutdown_;
- bool ignore_max_footprint_;
- size_t heap_initial_size_;
- size_t heap_maximum_size_;
- size_t heap_growth_limit_;
- size_t heap_min_free_;
- size_t heap_max_free_;
- double heap_target_utilization_;
- size_t parallel_gc_threads_;
- size_t conc_gc_threads_;
- gc::CollectorType collector_type_;
- gc::CollectorType background_collector_type_;
- size_t stack_size_;
- size_t max_spins_before_thin_lock_inflation_;
- bool low_memory_mode_;
- size_t lock_profiling_threshold_;
- std::string stack_trace_file_;
- bool method_trace_;
- std::string method_trace_file_;
- size_t method_trace_file_size_;
- bool (*hook_is_sensitive_thread_)();
- jint (*hook_vfprintf_)(FILE* stream, const char* format, va_list ap);
- void (*hook_exit_)(jint status);
- void (*hook_abort_)();
- std::vector<std::string> properties_;
- std::vector<std::string> compiler_options_;
- std::vector<std::string> image_compiler_options_;
- bool profile_;
- std::string profile_output_filename_;
- int profile_period_s_;
- int profile_duration_s_;
- int profile_interval_us_;
- double profile_backoff_coefficient_;
-
- private:
- ParsedOptions() {}
- };
-
// Creates and initializes a new runtime.
static bool Create(const Options& options, bool ignore_unrecognized)
SHARED_TRYLOCK_FUNCTION(true, Locks::mutator_lock_);
@@ -279,7 +218,7 @@ class Runtime {
return thread_list_;
}
- const char* GetVersion() const {
+ static const char* GetVersion() {
return "2.0.0";
}
@@ -566,9 +505,9 @@ class Runtime {
// Runtime profile support.
bool profile_;
std::string profile_output_filename_;
- uint32_t profile_period_s_; // Generate profile every n seconds.
- uint32_t profile_duration_s_; // Run profile for n seconds.
- uint32_t profile_interval_us_; // Microseconds between samples.
+ uint32_t profile_period_s_; // Generate profile every n seconds.
+ uint32_t profile_duration_s_; // Run profile for n seconds.
+ uint32_t profile_interval_us_; // Microseconds between samples.
double profile_backoff_coefficient_; // Coefficient to exponential backoff.
bool method_trace_;
diff --git a/runtime/trace.cc b/runtime/trace.cc
index 18185d4..1f24478 100644
--- a/runtime/trace.cc
+++ b/runtime/trace.cc
@@ -115,11 +115,7 @@ static const uint16_t kTraceVersionDualClock = 3;
static const uint16_t kTraceRecordSizeSingleClock = 10; // using v2
static const uint16_t kTraceRecordSizeDualClock = 14; // using v3 with two timestamps
-#if defined(HAVE_POSIX_CLOCKS)
-ProfilerClockSource Trace::default_clock_source_ = kProfilerClockSourceDual;
-#else
-ProfilerClockSource Trace::default_clock_source_ = kProfilerClockSourceWall;
-#endif
+ProfilerClockSource Trace::default_clock_source_ = kDefaultProfilerClockSource;
Trace* volatile Trace::the_trace_ = NULL;
pthread_t Trace::sampling_pthread_ = 0U;
diff --git a/runtime/trace.h b/runtime/trace.h
index d810df0..1af1283 100644
--- a/runtime/trace.h
+++ b/runtime/trace.h
@@ -42,6 +42,12 @@ enum ProfilerClockSource {
kProfilerClockSourceDual, // Both wall and thread CPU clocks.
};
+#if defined(HAVE_POSIX_CLOCKS)
+const ProfilerClockSource kDefaultProfilerClockSource = kProfilerClockSourceDual;
+#else
+const ProfilerClockSource kDefaultProfilerClockSource = kProfilerClockSourceWall;
+#endif
+
enum TracingMode {
kTracingInactive,
kMethodTracingActive,