summaryrefslogtreecommitdiffstats
path: root/core/jni/AndroidRuntime.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/jni/AndroidRuntime.cpp')
-rw-r--r--core/jni/AndroidRuntime.cpp91
1 files changed, 73 insertions, 18 deletions
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index 97ea5e6..649968e 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -131,7 +131,6 @@ extern int register_android_database_CursorWindow(JNIEnv* env);
extern int register_android_database_SQLiteConnection(JNIEnv* env);
extern int register_android_database_SQLiteGlobal(JNIEnv* env);
extern int register_android_database_SQLiteDebug(JNIEnv* env);
-extern int register_android_debug_JNITest(JNIEnv* env);
extern int register_android_nio_utils(JNIEnv* env);
extern int register_android_text_format_Time(JNIEnv* env);
extern int register_android_os_Debug(JNIEnv* env);
@@ -396,16 +395,16 @@ static void readLocale(char* language, char* region)
*
* This will cut up "extraOptsBuf" as we chop it into individual options.
*
+ * If "quotingArg" is non-null, it is passed before each extra option in mOptions.
+ *
* Adds the strings, if any, to mOptions.
*/
-void AndroidRuntime::parseExtraOpts(char* extraOptsBuf)
+void AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg)
{
JavaVMOption opt;
- char* start;
- char* end;
-
memset(&opt, 0, sizeof(opt));
- start = extraOptsBuf;
+ char* start = extraOptsBuf;
+ char* end = NULL;
while (*start != '\0') {
while (*start == ' ') /* skip leading whitespace */
start++;
@@ -419,6 +418,11 @@ void AndroidRuntime::parseExtraOpts(char* extraOptsBuf)
*end++ = '\0'; /* mark end, advance to indicate more */
opt.optionString = start;
+ if (quotingArg != NULL) {
+ JavaVMOption quotingOpt;
+ quotingOpt.optionString = quotingArg;
+ mOptions.add(quotingOpt);
+ }
mOptions.add(opt);
start = end;
}
@@ -430,6 +434,14 @@ void AndroidRuntime::parseExtraOpts(char* extraOptsBuf)
* Various arguments, most determined by system properties, are passed in.
* The "mOptions" vector is updated.
*
+ * CAUTION: when adding options in here, be careful not to put the
+ * char buffer inside a nested scope. Adding the buffer to the
+ * options using mOptions.add() does not copy the buffer, so if the
+ * buffer goes out of scope the option may be overwritten. It's best
+ * to put the buffer at the top of the function so that it is more
+ * unlikely that someone will surround it in a scope at a later time
+ * and thus introduce a bug.
+ *
* Returns 0 on success.
*/
int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
@@ -450,6 +462,9 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
char jitcodecachesizeOptsBuf[sizeof("-Xjitcodecachesize:")-1 + PROPERTY_VALUE_MAX];
+ char dalvikVmLibBuf[PROPERTY_VALUE_MAX];
+ char dex2oatFlagsBuf[PROPERTY_VALUE_MAX];
+ char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX];
char extraOptsBuf[PROPERTY_VALUE_MAX];
char* stackTraceFile = NULL;
bool checkJni = false;
@@ -461,7 +476,15 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
kEMIntFast,
kEMJitCompiler,
} executionMode = kEMDefault;
-
+ char profile_period[sizeof("-Xprofile-period:") + PROPERTY_VALUE_MAX];
+ char profile_duration[sizeof("-Xprofile-duration:") + PROPERTY_VALUE_MAX];
+ char profile_interval[sizeof("-Xprofile-interval:") + PROPERTY_VALUE_MAX];
+ char profile_backoff[sizeof("-Xprofile-backoff:") + PROPERTY_VALUE_MAX];
+ char langOption[sizeof("-Duser.language=") + 3];
+ char regionOption[sizeof("-Duser.region=") + 3];
+ char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:") + sizeof(propBuf)];
+ char jitOpBuf[sizeof("-Xjitop:") + PROPERTY_VALUE_MAX];
+ char jitMethodBuf[sizeof("-Xjitmethod:") + PROPERTY_VALUE_MAX];
property_get("dalvik.vm.checkjni", propBuf, "");
if (strcmp(propBuf, "true") == 0) {
@@ -662,7 +685,6 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
//mOptions.add(opt);
}
- char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:") + sizeof(propBuf)];
property_get("dalvik.vm.lockprof.threshold", propBuf, "");
if (strlen(propBuf) > 0) {
strcpy(lockProfThresholdBuf, "-Xlockprofthreshold:");
@@ -672,7 +694,6 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
}
/* Force interpreter-only mode for selected opcodes. Eg "1-0a,3c,f1-ff" */
- char jitOpBuf[sizeof("-Xjitop:") + PROPERTY_VALUE_MAX];
property_get("dalvik.vm.jit.op", propBuf, "");
if (strlen(propBuf) > 0) {
strcpy(jitOpBuf, "-Xjitop:");
@@ -682,7 +703,6 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
}
/* Force interpreter-only mode for selected methods */
- char jitMethodBuf[sizeof("-Xjitmethod:") + PROPERTY_VALUE_MAX];
property_get("dalvik.vm.jit.method", propBuf, "");
if (strlen(propBuf) > 0) {
strcpy(jitMethodBuf, "-Xjitmethod:");
@@ -742,14 +762,26 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
mOptions.add(opt);
}
+ // libart tolerates libdvm flags, but not vice versa, so only pass some options if libart.
+ property_get("persist.sys.dalvik.vm.lib.1", dalvikVmLibBuf, "libdvm.so");
+ bool libart = (strncmp(dalvikVmLibBuf, "libart", 6) == 0);
+
+ if (libart) {
+ // Extra options for DexClassLoader.
+ property_get("dalvik.vm.dex2oat-flags", dex2oatFlagsBuf, "");
+ parseExtraOpts(dex2oatFlagsBuf, "-Xcompiler-option");
+
+ // Extra options for boot.art/boot.oat image generation.
+ property_get("dalvik.vm.image-dex2oat-flags", dex2oatImageFlagsBuf, "");
+ parseExtraOpts(dex2oatImageFlagsBuf, "-Ximage-compiler-option");
+ }
+
/* extra options; parse this late so it overrides others */
property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
- parseExtraOpts(extraOptsBuf);
+ parseExtraOpts(extraOptsBuf, NULL);
/* Set the properties for locale */
{
- char langOption[sizeof("-Duser.language=") + 3];
- char regionOption[sizeof("-Duser.region=") + 3];
strcpy(langOption, "-Duser.language=");
strcpy(regionOption, "-Duser.region=");
readLocale(langOption, regionOption);
@@ -761,11 +793,35 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
}
/*
- * We don't have /tmp on the device, but we often have an SD card. Apps
- * shouldn't use this, but some test suites might want to exercise it.
+ * Set profiler options
*/
- opt.optionString = "-Djava.io.tmpdir=/sdcard";
- mOptions.add(opt);
+ if (libart) {
+ // Number of seconds during profile runs.
+ strcpy(profile_period, "-Xprofile-period:");
+ property_get("dalvik.vm.profile.period_secs", profile_period+17, "10");
+ opt.optionString = profile_period;
+ mOptions.add(opt);
+
+ // Length of each profile run (seconds).
+ strcpy(profile_duration, "-Xprofile-duration:");
+ property_get("dalvik.vm.profile.duration_secs", profile_duration+19, "30");
+ opt.optionString = profile_duration;
+ mOptions.add(opt);
+
+
+ // Polling interval during profile run (microseconds).
+ strcpy(profile_interval, "-Xprofile-interval:");
+ property_get("dalvik.vm.profile.interval_us", profile_interval+19, "10000");
+ opt.optionString = profile_interval;
+ mOptions.add(opt);
+
+ // Coefficient for period backoff. The the period is multiplied
+ // by this value after each profile run.
+ strcpy(profile_backoff, "-Xprofile-backoff:");
+ property_get("dalvik.vm.profile.backoff_coeff", profile_backoff+18, "2.0");
+ opt.optionString = profile_backoff;
+ mOptions.add(opt);
+ }
initArgs.version = JNI_VERSION_1_4;
initArgs.options = mOptions.editArray();
@@ -1100,7 +1156,6 @@ static void register_jam_procs(const RegJAMProc array[], size_t count)
}
static const RegJNIRec gRegJNI[] = {
- REG_JNI(register_android_debug_JNITest),
REG_JNI(register_com_android_internal_os_RuntimeInit),
REG_JNI(register_android_os_SystemClock),
REG_JNI(register_android_util_EventLog),