2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * Dalvik initialization, shutdown, and command-line argument processing.
21 #include "test/Test.h"
22 #include "mterp/Mterp.h"
33 #define kMinHeapStartSize (1*1024*1024)
34 #define kMinHeapSize (2*1024*1024)
35 #define kMaxHeapSize (1*1024*1024*1024)
38 * Register VM-agnostic native methods for system classes.
40 * Currently defined in ../include/nativehelper/AndroidSystemNatives.h
42 extern int jniRegisterSystemMethods(JNIEnv* env);
45 static bool registerSystemNatives(JNIEnv* pEnv);
46 static bool dvmInitJDWP(void);
47 static bool dvmInitZygote(void);
51 struct DvmGlobals gDvm;
53 /* JIT-specific global state */
55 struct DvmJitGlobals gDvmJit;
61 * We follow the tradition of unhyphenated compound words.
63 static void dvmUsage(const char* progName)
65 dvmFprintf(stderr, "%s: [options] class [argument ...]\n", progName);
66 dvmFprintf(stderr, "%s: [options] -jar file.jar [argument ...]\n",progName);
67 dvmFprintf(stderr, "\n");
68 dvmFprintf(stderr, "The following standard options are recognized:\n");
69 dvmFprintf(stderr, " -classpath classpath\n");
70 dvmFprintf(stderr, " -Dproperty=value\n");
71 dvmFprintf(stderr, " -verbose:tag ('gc', 'jni', or 'class')\n");
72 dvmFprintf(stderr, " -ea[:<package name>... |:<class name>]\n");
73 dvmFprintf(stderr, " -da[:<package name>... |:<class name>]\n");
74 dvmFprintf(stderr, " (-enableassertions, -disableassertions)\n");
75 dvmFprintf(stderr, " -esa\n");
76 dvmFprintf(stderr, " -dsa\n");
78 " (-enablesystemassertions, -disablesystemassertions)\n");
79 dvmFprintf(stderr, " -showversion\n");
80 dvmFprintf(stderr, " -help\n");
81 dvmFprintf(stderr, "\n");
82 dvmFprintf(stderr, "The following extended options are recognized:\n");
83 dvmFprintf(stderr, " -Xrunjdwp:<options>\n");
84 dvmFprintf(stderr, " -Xbootclasspath:bootclasspath\n");
85 dvmFprintf(stderr, " -Xcheck:tag (e.g. 'jni')\n");
86 dvmFprintf(stderr, " -XmsN (min heap, must be multiple of 1K, >= 1MB)\n");
87 dvmFprintf(stderr, " -XmxN (max heap, must be multiple of 1K, >= 2MB)\n");
88 dvmFprintf(stderr, " -XssN (stack size, >= %dKB, <= %dKB)\n",
89 kMinStackSize / 1024, kMaxStackSize / 1024);
90 dvmFprintf(stderr, " -Xverify:{none,remote,all}\n");
91 dvmFprintf(stderr, " -Xrs\n");
94 " -Xint (extended to accept ':portable', ':fast' and ':jit')\n");
97 " -Xint (extended to accept ':portable' and ':fast')\n");
99 dvmFprintf(stderr, "\n");
100 dvmFprintf(stderr, "These are unique to Dalvik:\n");
101 dvmFprintf(stderr, " -Xzygote\n");
102 dvmFprintf(stderr, " -Xdexopt:{none,verified,all}\n");
103 dvmFprintf(stderr, " -Xnoquithandler\n");
105 " -Xjnigreflimit:N (must be multiple of 100, >= 200)\n");
106 dvmFprintf(stderr, " -Xjniopts:{warnonly,forcecopy}\n");
107 dvmFprintf(stderr, " -Xdeadlockpredict:{off,warn,err,abort}\n");
108 dvmFprintf(stderr, " -Xstacktracefile:<filename>\n");
109 dvmFprintf(stderr, " -Xgc:[no]precise\n");
110 dvmFprintf(stderr, " -Xgc:[no]overwritefree\n");
111 dvmFprintf(stderr, " -Xgenregmap\n");
112 dvmFprintf(stderr, " -Xcheckdexsum\n");
113 #if defined(WITH_JIT)
114 dvmFprintf(stderr, " -Xincludeselectedop\n");
115 dvmFprintf(stderr, " -Xjitop:hexopvalue[-endvalue]"
116 "[,hexopvalue[-endvalue]]*\n");
117 dvmFprintf(stderr, " -Xincludeselectedmethod\n");
118 dvmFprintf(stderr, " -Xjitthreshold:decimalvalue\n");
119 dvmFprintf(stderr, " -Xjitblocking\n");
120 dvmFprintf(stderr, " -Xjitmethod:signature[,signature]* "
121 "(eg Ljava/lang/String\\;replace)\n");
122 dvmFprintf(stderr, " -Xjitcheckcg\n");
123 dvmFprintf(stderr, " -Xjitverbose\n");
124 dvmFprintf(stderr, " -Xjitprofile\n");
125 dvmFprintf(stderr, " -Xjitdisableopt\n");
127 dvmFprintf(stderr, "\n");
128 dvmFprintf(stderr, "Configured with:"
135 #ifdef WITH_MONITOR_TRACKING
138 #ifdef WITH_DEADLOCK_PREDICTION
139 " deadlock_prediction"
144 #ifdef WITH_HPROF_STACK
147 #ifdef WITH_ALLOC_LIMITS
150 #ifdef WITH_TRACKREF_CHECKS
153 #ifdef WITH_INSTR_CHECKS
156 #ifdef WITH_EXTRA_OBJECT_VALIDATION
157 " extra_object_validation"
159 #ifdef WITH_EXTRA_GC_CHECKS
162 #ifdef WITH_DALVIK_ASSERT
165 #ifdef WITH_JNI_STACK_CHECK
174 #ifdef PROFILE_FIELD_ACCESS
175 " profile_field_access"
177 #ifdef DVM_TRACK_HEAP_MARKING
178 " track_heap_marking"
180 #if DVM_RESOLVER_CACHE == DVM_RC_REDUCING
181 " resolver_cache_reducing"
182 #elif DVM_RESOLVER_CACHE == DVM_RC_EXPANDING
183 " resolver_cache_expanding"
184 #elif DVM_RESOLVER_CACHE == DVM_RC_NO_CACHE
185 " resolver_cache_disabled"
187 #if defined(WITH_JIT)
190 #if defined(WITH_SELF_VERIFICATION)
194 #ifdef DVM_SHOW_EXCEPTION
195 dvmFprintf(stderr, " show_exception=%d", DVM_SHOW_EXCEPTION);
197 dvmFprintf(stderr, "\n\n");
201 * Show helpful information on JDWP options.
203 static void showJdwpHelp(void)
206 "Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n");
208 "Example: -Xrunjdwp:transport=dt_socket,address=localhost:6500,server=n\n");
212 * Show version and copyright info.
214 static void showVersion(void)
216 dvmFprintf(stdout, "DalvikVM version %d.%d.%d\n",
217 DALVIK_MAJOR_VERSION, DALVIK_MINOR_VERSION, DALVIK_BUG_VERSION);
219 "Copyright (C) 2007 The Android Open Source Project\n\n"
220 "This software is built from source code licensed under the "
222 "Version 2.0 (the \"License\"). You may obtain a copy of the "
224 " http://www.apache.org/licenses/LICENSE-2.0\n\n"
225 "See the associated NOTICE file for this software for further "
230 * Parse a string of the form /[0-9]+[kKmMgG]?/, which is used to specify
231 * memory sizes. [kK] indicates kilobytes, [mM] megabytes, and
234 * "s" should point just past the "-Xm?" part of the string.
235 * "min" specifies the lowest acceptable value described by "s".
236 * "div" specifies a divisor, e.g. 1024 if the value must be a multiple
239 * The spec says the -Xmx and -Xms options must be multiples of 1024. It
240 * doesn't say anything about -Xss.
242 * Returns 0 (a useless size) if "s" is malformed or specifies a low or
243 * non-evenly-divisible value.
245 static unsigned int dvmParseMemOption(const char *s, unsigned int div)
247 /* strtoul accepts a leading [+-], which we don't want,
248 * so make sure our string starts with a decimal digit.
254 val = (unsigned int)strtoul(s, (char **)&s2, 10);
256 /* s2 should be pointing just after the number.
257 * If this is the end of the string, the user
258 * has specified a number of bytes. Otherwise,
259 * there should be exactly one more character
260 * that specifies a multiplier.
265 /* The remainder of the string is either a single multiplier
266 * character, or nothing to indicate that the value is in
275 } else if (c == 'k' || c == 'K') {
277 } else if (c == 'm' || c == 'M') {
279 } else if (c == 'g' || c == 'G') {
280 mul = 1024 * 1024 * 1024;
282 /* Unknown multiplier character.
287 if (val <= UINT_MAX / mul) {
290 /* Clamp to a multiple of 1024.
292 val = UINT_MAX & ~(1024-1);
295 /* There's more than one character after the
302 /* The man page says that a -Xm value must be
303 * a multiple of 1024.
305 if (val % div == 0) {
315 * Handle one of the JDWP name/value pairs.
318 * help: if specified, show help message and bail
319 * transport: may be dt_socket or dt_shmem
320 * address: for dt_socket, "host:port", or just "port" when listening
321 * server: if "y", wait for debugger to attach; if "n", attach to debugger
322 * timeout: how long to wait for debugger to connect / listen
324 * Useful with server=n (these aren't supported yet):
325 * onthrow=<exception-name>: connect to debugger when exception thrown
326 * onuncaught=y|n: connect to debugger when uncaught exception thrown
327 * launch=<command-line>: launch the debugger itself
329 * The "transport" option is required, as is "address" if server=n.
331 static bool handleJdwpOption(const char* name, const char* value)
333 if (strcmp(name, "transport") == 0) {
334 if (strcmp(value, "dt_socket") == 0) {
335 gDvm.jdwpTransport = kJdwpTransportSocket;
336 } else if (strcmp(value, "dt_android_adb") == 0) {
337 gDvm.jdwpTransport = kJdwpTransportAndroidAdb;
339 LOGE("JDWP transport '%s' not supported\n", value);
342 } else if (strcmp(name, "server") == 0) {
344 gDvm.jdwpServer = false;
345 else if (*value == 'y')
346 gDvm.jdwpServer = true;
348 LOGE("JDWP option 'server' must be 'y' or 'n'\n");
351 } else if (strcmp(name, "suspend") == 0) {
353 gDvm.jdwpSuspend = false;
354 else if (*value == 'y')
355 gDvm.jdwpSuspend = true;
357 LOGE("JDWP option 'suspend' must be 'y' or 'n'\n");
360 } else if (strcmp(name, "address") == 0) {
361 /* this is either <port> or <host>:<port> */
362 const char* colon = strchr(value, ':');
368 gDvm.jdwpHost = (char*) malloc(colon - value +1);
369 strncpy(gDvm.jdwpHost, value, colon - value +1);
370 gDvm.jdwpHost[colon-value] = '\0';
373 if (*value == '\0') {
374 LOGE("JDWP address missing port\n");
377 port = strtol(value, &end, 10);
379 LOGE("JDWP address has junk in port field '%s'\n", value);
382 gDvm.jdwpPort = port;
383 } else if (strcmp(name, "launch") == 0 ||
384 strcmp(name, "onthrow") == 0 ||
385 strcmp(name, "oncaught") == 0 ||
386 strcmp(name, "timeout") == 0)
388 /* valid but unsupported */
389 LOGI("Ignoring JDWP option '%s'='%s'\n", name, value);
391 LOGI("Ignoring unrecognized JDWP option '%s'='%s'\n", name, value);
398 * Parse the latter half of a -Xrunjdwp/-agentlib:jdwp= string, e.g.:
399 * "transport=dt_socket,address=8000,server=y,suspend=n"
401 static bool parseJdwpOptions(const char* str)
403 char* mangle = strdup(str);
408 * Process all of the name=value pairs.
414 value = strchr(name, '=');
416 LOGE("JDWP opts: garbage at '%s'\n", name);
420 comma = strchr(name, ','); // use name, not value, for safety
423 LOGE("JDWP opts: found comma before '=' in '%s'\n", mangle);
429 *value++ = '\0'; // stomp the '='
431 if (!handleJdwpOption(name, value))
442 * Make sure the combination of arguments makes sense.
444 if (gDvm.jdwpTransport == kJdwpTransportUnknown) {
445 LOGE("JDWP opts: must specify transport\n");
448 if (!gDvm.jdwpServer && (gDvm.jdwpHost == NULL || gDvm.jdwpPort == 0)) {
449 LOGE("JDWP opts: when server=n, must specify host and port\n");
452 // transport mandatory
453 // outbound server address
455 gDvm.jdwpConfigured = true;
464 * Handle one of the four kinds of assertion arguments.
466 * "pkgOrClass" is the last part of an enable/disable line. For a package
467 * the arg looks like "-ea:com.google.fubar...", for a class it looks
468 * like "-ea:com.google.fubar.Wahoo". The string we get starts at the ':'.
470 * For system assertions (-esa/-dsa), "pkgOrClass" is NULL.
472 * Multiple instances of these arguments can be specified, e.g. you can
473 * enable assertions for a package and then disable them for one class in
476 static bool enableAssertions(const char* pkgOrClass, bool enable)
478 AssertionControl* pCtrl = &gDvm.assertionCtrl[gDvm.assertionCtrlCount++];
479 pCtrl->enable = enable;
481 if (pkgOrClass == NULL) {
482 /* enable or disable for all system classes */
483 pCtrl->isPackage = false;
484 pCtrl->pkgOrClass = NULL;
485 pCtrl->pkgOrClassLen = 0;
487 if (*pkgOrClass == '\0') {
488 /* global enable/disable for all but system */
489 pCtrl->isPackage = false;
490 pCtrl->pkgOrClass = strdup("");
491 pCtrl->pkgOrClassLen = 0;
493 pCtrl->pkgOrClass = dvmDotToSlash(pkgOrClass+1); // skip ':'
494 if (pCtrl->pkgOrClass == NULL) {
495 /* can happen if class name includes an illegal '/' */
496 LOGW("Unable to process assertion arg '%s'\n", pkgOrClass);
500 int len = strlen(pCtrl->pkgOrClass);
501 if (len >= 3 && strcmp(pCtrl->pkgOrClass + len-3, "///") == 0) {
502 /* mark as package, truncate two of the three slashes */
503 pCtrl->isPackage = true;
504 *(pCtrl->pkgOrClass + len-2) = '\0';
505 pCtrl->pkgOrClassLen = len - 2;
508 pCtrl->isPackage = false;
509 pCtrl->pkgOrClassLen = len;
518 * Turn assertions on when requested to do so by the Zygote.
520 * This is a bit sketchy. We can't (easily) go back and fiddle with all
521 * of the classes that have already been initialized, so this only
522 * affects classes that have yet to be loaded. If some or all assertions
523 * have been enabled through some other means, we don't want to mess with
524 * it here, so we do nothing. Finally, we assume that there's room in
525 * "assertionCtrl" to hold at least one entry; this is guaranteed by the
528 * This must only be called from the main thread during zygote init.
530 void dvmLateEnableAssertions(void)
532 if (gDvm.assertionCtrl == NULL) {
533 LOGD("Not late-enabling assertions: no assertionCtrl array\n");
535 } else if (gDvm.assertionCtrlCount != 0) {
536 LOGD("Not late-enabling assertions: some asserts already configured\n");
539 LOGD("Late-enabling assertions\n");
541 /* global enable for all but system */
542 AssertionControl* pCtrl = gDvm.assertionCtrl;
543 pCtrl->pkgOrClass = strdup("");
544 pCtrl->pkgOrClassLen = 0;
545 pCtrl->isPackage = false;
546 pCtrl->enable = true;
547 gDvm.assertionCtrlCount = 1;
552 * Release memory associated with the AssertionCtrl array.
554 static void freeAssertionCtrl(void)
558 for (i = 0; i < gDvm.assertionCtrlCount; i++)
559 free(gDvm.assertionCtrl[i].pkgOrClass);
560 free(gDvm.assertionCtrl);
563 #if defined(WITH_JIT)
564 /* Parse -Xjitop to selectively turn on/off certain opcodes for JIT */
565 static void processXjitop(const char *opt)
568 const char *startPtr = &opt[8];
572 long startValue, endValue;
574 startValue = strtol(startPtr, &endPtr, 16);
575 if (startPtr != endPtr) {
576 /* Just in case value is out of range */
579 if (*endPtr == '-') {
580 endValue = strtol(endPtr+1, &endPtr, 16);
583 endValue = startValue;
586 for (; startValue <= endValue; startValue++) {
587 LOGW("Dalvik opcode %x is selected for debugging",
588 (unsigned int) startValue);
589 /* Mark the corresponding bit to 1 */
590 gDvmJit.opList[startValue >> 3] |=
591 1 << (startValue & 0x7);
598 startPtr = endPtr + 1;
604 "Warning: Unrecognized opcode value substring "
612 for (i = 0; i < 32; i++) {
613 gDvmJit.opList[i] = 0xff;
615 dvmFprintf(stderr, "Warning: select all opcodes\n");
619 /* Parse -Xjitmethod to selectively turn on/off certain methods for JIT */
620 static void processXjitmethod(const char *opt)
622 char *buf = strdup(&opt[12]);
625 gDvmJit.methodTable = dvmHashTableCreate(8, NULL);
629 * Break comma-separated method signatures and enter them into the hash
630 * table individually.
635 end = strchr(start, ',');
640 hashValue = dvmComputeUtf8Hash(start);
642 dvmHashTableLookup(gDvmJit.methodTable, hashValue,
644 (HashCompareFunc) strcmp, true);
656 * Process an argument vector full of options. Unlike standard C programs,
657 * argv[0] does not contain the name of the program.
659 * If "ignoreUnrecognized" is set, we ignore options starting with "-X" or "_"
660 * that we don't recognize. Otherwise, we return with an error as soon as
661 * we see anything we can't identify.
663 * Returns 0 on success, -1 on failure, and 1 for the special case of
664 * "-version" where we want to stop without showing an error message.
666 static int dvmProcessOptions(int argc, const char* const argv[],
667 bool ignoreUnrecognized)
671 LOGV("VM options (%d):\n", argc);
672 for (i = 0; i < argc; i++)
673 LOGV(" %d: '%s'\n", i, argv[i]);
676 * Over-allocate AssertionControl array for convenience. If allocated,
677 * the array must be able to hold at least one entry, so that the
678 * zygote-time activation can do its business.
680 assert(gDvm.assertionCtrl == NULL);
683 (AssertionControl*) malloc(sizeof(AssertionControl) * argc);
684 if (gDvm.assertionCtrl == NULL)
686 assert(gDvm.assertionCtrlCount == 0);
689 for (i = 0; i < argc; i++) {
690 if (strcmp(argv[i], "-help") == 0) {
691 /* show usage and stop */
694 } else if (strcmp(argv[i], "-version") == 0) {
695 /* show version and stop */
698 } else if (strcmp(argv[i], "-showversion") == 0) {
699 /* show version and continue */
702 } else if (strcmp(argv[i], "-classpath") == 0 ||
703 strcmp(argv[i], "-cp") == 0)
707 dvmFprintf(stderr, "Missing classpath path list\n");
710 free(gDvm.classPathStr); /* in case we have compiled-in default */
711 gDvm.classPathStr = strdup(argv[++i]);
713 } else if (strncmp(argv[i], "-Xbootclasspath:",
714 sizeof("-Xbootclasspath:")-1) == 0)
716 /* set bootclasspath */
717 const char* path = argv[i] + sizeof("-Xbootclasspath:")-1;
720 dvmFprintf(stderr, "Missing bootclasspath path list\n");
723 free(gDvm.bootClassPathStr);
724 gDvm.bootClassPathStr = strdup(path);
727 * TODO: support -Xbootclasspath/a and /p, which append or
728 * prepend to the default bootclasspath. We set the default
732 } else if (strncmp(argv[i], "-D", 2) == 0) {
734 dvmAddCommandLineProperty(argv[i] + 2);
736 } else if (strcmp(argv[i], "-jar") == 0) {
737 // TODO: handle this; name of jar should be in argv[i+1]
738 dvmFprintf(stderr, "-jar not yet handled\n");
741 } else if (strncmp(argv[i], "-Xms", 4) == 0) {
742 unsigned int val = dvmParseMemOption(argv[i]+4, 1024);
744 if (val >= kMinHeapStartSize && val <= kMaxHeapSize) {
745 gDvm.heapSizeStart = val;
748 "Invalid -Xms '%s', range is %dKB to %dKB\n",
749 argv[i], kMinHeapStartSize/1024, kMaxHeapSize/1024);
753 dvmFprintf(stderr, "Invalid -Xms option '%s'\n", argv[i]);
756 } else if (strncmp(argv[i], "-Xmx", 4) == 0) {
757 unsigned int val = dvmParseMemOption(argv[i]+4, 1024);
759 if (val >= kMinHeapSize && val <= kMaxHeapSize) {
760 gDvm.heapSizeMax = val;
763 "Invalid -Xmx '%s', range is %dKB to %dKB\n",
764 argv[i], kMinHeapSize/1024, kMaxHeapSize/1024);
768 dvmFprintf(stderr, "Invalid -Xmx option '%s'\n", argv[i]);
771 } else if (strncmp(argv[i], "-Xss", 4) == 0) {
772 unsigned int val = dvmParseMemOption(argv[i]+4, 1);
774 if (val >= kMinStackSize && val <= kMaxStackSize) {
775 gDvm.stackSize = val;
777 dvmFprintf(stderr, "Invalid -Xss '%s', range is %d to %d\n",
778 argv[i], kMinStackSize, kMaxStackSize);
782 dvmFprintf(stderr, "Invalid -Xss option '%s'\n", argv[i]);
786 } else if (strcmp(argv[i], "-verbose") == 0 ||
787 strcmp(argv[i], "-verbose:class") == 0)
789 // JNI spec says "-verbose:gc,class" is valid, but cmd line
790 // doesn't work that way; may want to support.
791 gDvm.verboseClass = true;
792 } else if (strcmp(argv[i], "-verbose:jni") == 0) {
793 gDvm.verboseJni = true;
794 } else if (strcmp(argv[i], "-verbose:gc") == 0) {
795 gDvm.verboseGc = true;
796 } else if (strcmp(argv[i], "-verbose:shutdown") == 0) {
797 gDvm.verboseShutdown = true;
799 } else if (strncmp(argv[i], "-enableassertions", 17) == 0) {
800 enableAssertions(argv[i] + 17, true);
801 } else if (strncmp(argv[i], "-ea", 3) == 0) {
802 enableAssertions(argv[i] + 3, true);
803 } else if (strncmp(argv[i], "-disableassertions", 18) == 0) {
804 enableAssertions(argv[i] + 18, false);
805 } else if (strncmp(argv[i], "-da", 3) == 0) {
806 enableAssertions(argv[i] + 3, false);
807 } else if (strcmp(argv[i], "-enablesystemassertions") == 0 ||
808 strcmp(argv[i], "-esa") == 0)
810 enableAssertions(NULL, true);
811 } else if (strcmp(argv[i], "-disablesystemassertions") == 0 ||
812 strcmp(argv[i], "-dsa") == 0)
814 enableAssertions(NULL, false);
816 } else if (strncmp(argv[i], "-Xcheck:jni", 11) == 0) {
817 /* nothing to do now -- was handled during JNI init */
819 } else if (strcmp(argv[i], "-Xdebug") == 0) {
820 /* accept but ignore */
822 } else if (strncmp(argv[i], "-Xrunjdwp:", 10) == 0 ||
823 strncmp(argv[i], "-agentlib:jdwp=", 15) == 0)
828 if (argv[i][1] == 'X')
833 if (strncmp(tail, "help", 4) == 0 || !parseJdwpOptions(tail)) {
837 } else if (strcmp(argv[i], "-Xrs") == 0) {
838 gDvm.reduceSignals = true;
839 } else if (strcmp(argv[i], "-Xnoquithandler") == 0) {
840 /* disables SIGQUIT handler thread while still blocking SIGQUIT */
841 /* (useful if we don't want thread but system still signals us) */
842 gDvm.noQuitHandler = true;
843 } else if (strcmp(argv[i], "-Xzygote") == 0) {
845 #if defined(WITH_JIT)
846 gDvmJit.runningInAndroidFramework = true;
848 } else if (strncmp(argv[i], "-Xdexopt:", 9) == 0) {
849 if (strcmp(argv[i] + 9, "none") == 0)
850 gDvm.dexOptMode = OPTIMIZE_MODE_NONE;
851 else if (strcmp(argv[i] + 9, "verified") == 0)
852 gDvm.dexOptMode = OPTIMIZE_MODE_VERIFIED;
853 else if (strcmp(argv[i] + 9, "all") == 0)
854 gDvm.dexOptMode = OPTIMIZE_MODE_ALL;
856 dvmFprintf(stderr, "Unrecognized dexopt option '%s'\n",argv[i]);
859 } else if (strncmp(argv[i], "-Xverify:", 9) == 0) {
860 if (strcmp(argv[i] + 9, "none") == 0)
861 gDvm.classVerifyMode = VERIFY_MODE_NONE;
862 else if (strcmp(argv[i] + 9, "remote") == 0)
863 gDvm.classVerifyMode = VERIFY_MODE_REMOTE;
864 else if (strcmp(argv[i] + 9, "all") == 0)
865 gDvm.classVerifyMode = VERIFY_MODE_ALL;
867 dvmFprintf(stderr, "Unrecognized verify option '%s'\n",argv[i]);
870 } else if (strncmp(argv[i], "-Xjnigreflimit:", 15) == 0) {
871 int lim = atoi(argv[i] + 15);
872 if (lim < 200 || (lim % 100) != 0) {
873 dvmFprintf(stderr, "Bad value for -Xjnigreflimit: '%s'\n",
877 gDvm.jniGrefLimit = lim;
879 } else if (strcmp(argv[i], "-Xlog-stdio") == 0) {
880 gDvm.logStdio = true;
882 } else if (strncmp(argv[i], "-Xint", 5) == 0) {
883 if (argv[i][5] == ':') {
884 if (strcmp(argv[i] + 6, "portable") == 0)
885 gDvm.executionMode = kExecutionModeInterpPortable;
886 else if (strcmp(argv[i] + 6, "fast") == 0)
887 gDvm.executionMode = kExecutionModeInterpFast;
889 else if (strcmp(argv[i] + 6, "jit") == 0)
890 gDvm.executionMode = kExecutionModeJit;
894 "Warning: Unrecognized interpreter mode %s\n",argv[i]);
898 /* disable JIT -- nothing to do here for now */
902 } else if (strncmp(argv[i], "-Xjitop", 7) == 0) {
903 processXjitop(argv[i]);
904 } else if (strncmp(argv[i], "-Xjitmethod", 11) == 0) {
905 processXjitmethod(argv[i]);
906 } else if (strncmp(argv[i], "-Xjitblocking", 13) == 0) {
907 gDvmJit.blockingMode = true;
908 } else if (strncmp(argv[i], "-Xjitthreshold:", 15) == 0) {
909 gDvmJit.threshold = atoi(argv[i] + 15);
910 } else if (strncmp(argv[i], "-Xincludeselectedop", 19) == 0) {
911 gDvmJit.includeSelectedOp = true;
912 } else if (strncmp(argv[i], "-Xincludeselectedmethod", 23) == 0) {
913 gDvmJit.includeSelectedMethod = true;
914 } else if (strncmp(argv[i], "-Xjitcheckcg", 12) == 0) {
915 gDvmJit.checkCallGraph = true;
916 /* Need to enable blocking mode due to stack crawling */
917 gDvmJit.blockingMode = true;
918 } else if (strncmp(argv[i], "-Xjitverbose", 12) == 0) {
919 gDvmJit.printMe = true;
920 } else if (strncmp(argv[i], "-Xjitprofile", 12) == 0) {
921 gDvmJit.profile = true;
922 } else if (strncmp(argv[i], "-Xjitdisableopt:", 16) == 0) {
923 sscanf(argv[i] + 16, "%x", &gDvmJit.disableOpt);
926 } else if (strncmp(argv[i], "-Xdeadlockpredict:", 18) == 0) {
927 #ifdef WITH_DEADLOCK_PREDICTION
928 if (strcmp(argv[i] + 18, "off") == 0)
929 gDvm.deadlockPredictMode = kDPOff;
930 else if (strcmp(argv[i] + 18, "warn") == 0)
931 gDvm.deadlockPredictMode = kDPWarn;
932 else if (strcmp(argv[i] + 18, "err") == 0)
933 gDvm.deadlockPredictMode = kDPErr;
934 else if (strcmp(argv[i] + 18, "abort") == 0)
935 gDvm.deadlockPredictMode = kDPAbort;
937 dvmFprintf(stderr, "Bad value for -Xdeadlockpredict");
940 if (gDvm.deadlockPredictMode != kDPOff)
941 LOGD("Deadlock prediction enabled (%s)\n", argv[i]+18);
944 } else if (strncmp(argv[i], "-Xstacktracefile:", 17) == 0) {
945 gDvm.stackTraceFile = strdup(argv[i]+17);
947 } else if (strcmp(argv[i], "-Xgenregmap") == 0) {
948 gDvm.generateRegisterMaps = true;
949 LOGV("Register maps will be generated during verification\n");
951 } else if (strncmp(argv[i], "-Xgc:", 5) == 0) {
952 if (strcmp(argv[i] + 5, "precise") == 0)
953 gDvm.preciseGc = true;
954 else if (strcmp(argv[i] + 5, "noprecise") == 0)
955 gDvm.preciseGc = false;
956 else if (strcmp(argv[i] + 5, "overwritefree") == 0)
957 gDvm.overwriteFree = true;
958 else if (strcmp(argv[i] + 5, "nooverwritefree") == 0)
959 gDvm.overwriteFree = false;
961 dvmFprintf(stderr, "Bad value for -Xgc");
964 LOGV("Precise GC configured %s\n", gDvm.preciseGc ? "ON" : "OFF");
966 } else if (strcmp(argv[i], "-Xcheckdexsum") == 0) {
967 gDvm.verifyDexChecksum = true;
970 if (!ignoreUnrecognized) {
971 dvmFprintf(stderr, "Unrecognized option '%s'\n", argv[i]);
977 if (gDvm.heapSizeStart > gDvm.heapSizeMax) {
978 dvmFprintf(stderr, "Heap start size must be <= heap max size\n");
986 * Set defaults for fields altered or modified by arguments.
988 * Globals are initialized to 0 (a/k/a NULL or false).
990 static void setCommandLineDefaults()
994 envStr = getenv("CLASSPATH");
996 gDvm.classPathStr = strdup(envStr);
998 gDvm.classPathStr = strdup(".");
999 envStr = getenv("BOOTCLASSPATH");
1001 gDvm.bootClassPathStr = strdup(envStr);
1003 gDvm.bootClassPathStr = strdup(".");
1005 /* Defaults overridden by -Xms and -Xmx.
1006 * TODO: base these on a system or application-specific default
1008 gDvm.heapSizeStart = 2 * 1024 * 1024; // Spec says 16MB; too big for us.
1009 gDvm.heapSizeMax = 16 * 1024 * 1024; // Spec says 75% physical mem
1010 gDvm.stackSize = kDefaultStackSize;
1012 /* gDvm.jdwpSuspend = true; */
1014 /* allowed unless zygote config doesn't allow it */
1015 gDvm.jdwpAllowed = true;
1017 /* default verification and optimization modes */
1018 gDvm.classVerifyMode = VERIFY_MODE_ALL;
1019 gDvm.dexOptMode = OPTIMIZE_MODE_VERIFIED;
1022 * Default execution mode.
1024 * This should probably interact with the mterp code somehow, e.g. if
1025 * we know we're using the "desktop" build we should probably be
1026 * using "portable" rather than "fast".
1028 #if defined(WITH_JIT)
1029 gDvm.executionMode = kExecutionModeJit;
1031 gDvm.executionMode = kExecutionModeInterpFast;
1037 * Handle a SIGBUS, which frequently occurs because somebody replaced an
1038 * optimized DEX file out from under us.
1040 static void busCatcher(int signum, siginfo_t* info, void* context)
1042 void* addr = info->si_addr;
1044 LOGE("Caught a SIGBUS (%d), addr=%p\n", signum, addr);
1047 * If we return at this point the SIGBUS just keeps happening, so we
1048 * remove the signal handler and allow it to kill us. TODO: restore
1049 * the original, which points to a debuggerd stub; if we don't then
1050 * debuggerd won't be notified.
1052 signal(SIGBUS, SIG_DFL);
1056 * Configure signals. We need to block SIGQUIT so that the signal only
1057 * reaches the dump-stack-trace thread.
1059 * This can be disabled with the "-Xrs" flag.
1061 static void blockSignals()
1067 sigaddset(&mask, SIGQUIT);
1068 sigaddset(&mask, SIGUSR1); // used to initiate heap dump
1069 #if defined(WITH_JIT) && defined(WITH_JIT_TUNING)
1070 sigaddset(&mask, SIGUSR2); // used to investigate JIT internals
1072 //sigaddset(&mask, SIGPIPE);
1073 cc = sigprocmask(SIG_BLOCK, &mask, NULL);
1077 /* TODO: save the old sigaction in a global */
1078 struct sigaction sa;
1079 memset(&sa, 0, sizeof(sa));
1080 sa.sa_sigaction = busCatcher;
1081 sa.sa_flags = SA_SIGINFO;
1082 cc = sigaction(SIGBUS, &sa, NULL);
1088 * VM initialization. Pass in any options provided on the command line.
1089 * Do not pass in the class name or the options for the class.
1091 * Returns 0 on success.
1093 int dvmStartup(int argc, const char* const argv[], bool ignoreUnrecognized,
1098 assert(gDvm.initializing);
1100 LOGV("VM init args (%d):\n", argc);
1101 for (i = 0; i < argc; i++)
1102 LOGV(" %d: '%s'\n", i, argv[i]);
1104 setCommandLineDefaults();
1106 /* prep properties storage */
1107 if (!dvmPropertiesStartup(argc))
1111 * Process the option flags (if any).
1113 cc = dvmProcessOptions(argc, argv, ignoreUnrecognized);
1116 dvmFprintf(stderr, "\n");
1117 dvmUsage("dalvikvm");
1122 #if WITH_EXTRA_GC_CHECKS > 1
1123 /* only "portable" interp has the extra goodies */
1124 if (gDvm.executionMode != kExecutionModeInterpPortable) {
1125 LOGI("Switching to 'portable' interpreter for GC checks\n");
1126 gDvm.executionMode = kExecutionModeInterpPortable;
1130 /* Configure group scheduling capabilities */
1131 if (!access("/dev/cpuctl/tasks", F_OK)) {
1132 LOGV("Using kernel group scheduling");
1133 gDvm.kernelGroupScheduling = 1;
1135 LOGV("Using kernel scheduler policies");
1138 /* configure signal handling */
1139 if (!gDvm.reduceSignals)
1142 /* verify system page size */
1143 if (sysconf(_SC_PAGESIZE) != SYSTEM_PAGE_SIZE) {
1144 LOGE("ERROR: expected page size %d, got %d\n",
1145 SYSTEM_PAGE_SIZE, (int) sysconf(_SC_PAGESIZE));
1150 LOGV("Using executionMode %d\n", gDvm.executionMode);
1151 dvmCheckAsmConstants();
1154 * Initialize components.
1156 if (!dvmAllocTrackerStartup())
1158 if (!dvmGcStartup())
1160 if (!dvmThreadStartup())
1162 if (!dvmInlineNativeStartup())
1164 if (!dvmVerificationStartup())
1166 if (!dvmRegisterMapStartup())
1168 if (!dvmInstanceofStartup())
1170 if (!dvmClassStartup())
1172 if (!dvmThreadObjStartup())
1174 if (!dvmExceptionStartup())
1176 if (!dvmStringInternStartup())
1178 if (!dvmNativeStartup())
1180 if (!dvmInternalNativeStartup())
1182 if (!dvmJniStartup())
1184 if (!dvmReflectStartup())
1186 #ifdef WITH_PROFILER
1187 if (!dvmProfilingStartup())
1191 /* make sure we got these [can this go away?] */
1192 assert(gDvm.classJavaLangClass != NULL);
1193 assert(gDvm.classJavaLangObject != NULL);
1194 //assert(gDvm.classJavaLangString != NULL);
1195 assert(gDvm.classJavaLangThread != NULL);
1196 assert(gDvm.classJavaLangVMThread != NULL);
1197 assert(gDvm.classJavaLangThreadGroup != NULL);
1200 * Make sure these exist. If they don't, we can return a failure out
1201 * of main and nip the whole thing in the bud.
1203 static const char* earlyClasses[] = {
1204 "Ljava/lang/InternalError;",
1205 "Ljava/lang/StackOverflowError;",
1206 "Ljava/lang/UnsatisfiedLinkError;",
1207 "Ljava/lang/NoClassDefFoundError;",
1210 const char** pClassName;
1211 for (pClassName = earlyClasses; *pClassName != NULL; pClassName++) {
1212 if (dvmFindSystemClassNoInit(*pClassName) == NULL)
1217 * Miscellaneous class library validation.
1219 if (!dvmValidateBoxClasses())
1223 * Do the last bits of Thread struct initialization we need to allow
1224 * JNI calls to work.
1226 if (!dvmPrepMainForJni(pEnv))
1230 * Register the system native methods, which are registered through JNI.
1232 if (!registerSystemNatives(pEnv))
1236 * Do some "late" initialization for the memory allocator. This may
1237 * allocate storage and initialize classes.
1239 if (!dvmCreateStockExceptions())
1243 * At this point, the VM is in a pretty good state. Finish prep on
1244 * the main thread (specifically, create a java.lang.Thread object to go
1245 * along with our Thread struct). Note we will probably be executing
1246 * some interpreted class initializer code in here.
1248 if (!dvmPrepMainThread())
1252 * Make sure we haven't accumulated any tracked references. The main
1253 * thread should be starting with a clean slate.
1255 if (dvmReferenceTableEntries(&dvmThreadSelf()->internalLocalRefTable) != 0)
1257 LOGW("Warning: tracked references remain post-initialization\n");
1258 dvmDumpReferenceTable(&dvmThreadSelf()->internalLocalRefTable, "MAIN");
1261 /* general debugging setup */
1262 if (!dvmDebuggerStartup())
1266 * Init for either zygote mode or non-zygote mode. The key difference
1267 * is that we don't start any additional threads in Zygote mode.
1270 if (!dvmInitZygote())
1273 if (!dvmInitAfterZygote())
1280 LOGE("dmvTestHash FAILED\n");
1281 if (false /*noisy!*/ && !dvmTestIndirectRefTable())
1282 LOGE("dvmTestIndirectRefTable FAILED\n");
1285 assert(!dvmCheckException(dvmThreadSelf()));
1286 gDvm.initExceptionCount = 0;
1296 * Register java.* natives from our class libraries. We need to do
1297 * this after we're ready for JNI registration calls, but before we
1298 * do any class initialization.
1300 * If we get this wrong, we will blow up in the ThreadGroup class init if
1301 * interpreted code makes any reference to System. It will likely do this
1302 * since it wants to do some java.io.File setup (e.g. for static in/out/err).
1304 * We need to have gDvm.initializing raised here so that JNI FindClass
1305 * won't try to use the system/application class loader.
1307 static bool registerSystemNatives(JNIEnv* pEnv)
1311 /* main thread is always first in list */
1312 self = gDvm.threadList;
1314 /* must set this before allowing JNI-based method registration */
1315 self->status = THREAD_NATIVE;
1317 if (jniRegisterSystemMethods(pEnv) < 0) {
1318 LOGW("jniRegisterSystemMethods failed\n");
1322 /* back to run mode */
1323 self->status = THREAD_RUNNING;
1330 * Do zygote-mode-only initialization.
1332 static bool dvmInitZygote(void)
1334 /* zygote goes into its own process group */
1341 * Do non-zygote-mode initialization. This is done during VM init for
1342 * standard startup, or after a "zygote fork" when creating a new process.
1344 bool dvmInitAfterZygote(void)
1346 u8 startHeap, startQuit, startJdwp;
1347 u8 endHeap, endQuit, endJdwp;
1349 startHeap = dvmGetRelativeTimeUsec();
1352 * Post-zygote heap initialization, including starting
1353 * the HeapWorker thread.
1355 if (!dvmGcStartupAfterZygote())
1358 endHeap = dvmGetRelativeTimeUsec();
1359 startQuit = dvmGetRelativeTimeUsec();
1361 /* start signal catcher thread that dumps stacks on SIGQUIT */
1362 if (!gDvm.reduceSignals && !gDvm.noQuitHandler) {
1363 if (!dvmSignalCatcherStartup())
1367 /* start stdout/stderr copier, if requested */
1368 if (gDvm.logStdio) {
1369 if (!dvmStdioConverterStartup())
1373 endQuit = dvmGetRelativeTimeUsec();
1374 startJdwp = dvmGetRelativeTimeUsec();
1377 * Start JDWP thread. If the command-line debugger flags specified
1378 * "suspend=y", this will pause the VM. We probably want this to
1381 if (!dvmInitJDWP()) {
1382 LOGD("JDWP init failed; continuing anyway\n");
1385 endJdwp = dvmGetRelativeTimeUsec();
1387 LOGV("thread-start heap=%d quit=%d jdwp=%d total=%d usec\n",
1388 (int)(endHeap-startHeap), (int)(endQuit-startQuit),
1389 (int)(endJdwp-startJdwp), (int)(endJdwp-startHeap));
1392 if (gDvm.executionMode == kExecutionModeJit) {
1393 if (!dvmCompilerStartup())
1402 * Prepare for a connection to a JDWP-compliant debugger.
1404 * Note this needs to happen fairly late in the startup process, because
1405 * we need to have all of the java.* native methods registered (which in
1406 * turn requires JNI to be fully prepped).
1408 * There are several ways to initialize:
1410 * We immediately try to connect to host:port. Bail on failure. On
1411 * success, send VM_START (suspending the VM if "suspend=y").
1412 * server=y suspend=n
1413 * Passively listen for a debugger to connect. Return immediately.
1414 * server=y suspend=y
1415 * Wait until debugger connects. Send VM_START ASAP, suspending the
1416 * VM after the message is sent.
1418 * This gets more complicated with a nonzero value for "timeout".
1420 static bool dvmInitJDWP(void)
1422 assert(!gDvm.zygote);
1424 #ifndef WITH_DEBUGGER
1425 LOGI("Debugger support not compiled into VM\n");
1430 * Init JDWP if the debugger is enabled. This may connect out to a
1431 * debugger, passively listen for a debugger, or block waiting for a
1434 if (gDvm.jdwpAllowed && gDvm.jdwpConfigured) {
1435 JdwpStartupParams params;
1437 if (gDvm.jdwpHost != NULL) {
1438 if (strlen(gDvm.jdwpHost) >= sizeof(params.host)-1) {
1439 LOGE("ERROR: hostname too long: '%s'\n", gDvm.jdwpHost);
1442 strcpy(params.host, gDvm.jdwpHost);
1444 params.host[0] = '\0';
1446 params.transport = gDvm.jdwpTransport;
1447 params.server = gDvm.jdwpServer;
1448 params.suspend = gDvm.jdwpSuspend;
1449 params.port = gDvm.jdwpPort;
1451 gDvm.jdwpState = dvmJdwpStartup(¶ms);
1452 if (gDvm.jdwpState == NULL) {
1453 LOGW("WARNING: debugger thread failed to initialize\n");
1454 /* TODO: ignore? fail? need to mimic "expected" behavior */
1459 * If a debugger has already attached, send the "welcome" message. This
1460 * may cause us to suspend all threads.
1462 if (dvmJdwpIsActive(gDvm.jdwpState)) {
1463 //dvmChangeStatus(NULL, THREAD_RUNNING);
1464 if (!dvmJdwpPostVMStart(gDvm.jdwpState, gDvm.jdwpSuspend)) {
1465 LOGW("WARNING: failed to post 'start' message to debugger\n");
1468 //dvmChangeStatus(NULL, THREAD_NATIVE);
1475 * An alternative to JNI_CreateJavaVM/dvmStartup that does the first bit
1476 * of initialization and then returns with "initializing" still set. (Used
1477 * by DexOpt command-line utility.)
1479 * Attempting to use JNI or internal natives will fail. It's best if
1480 * no bytecode gets executed, which means no <clinit>, which means no
1481 * exception-throwing. We check the "initializing" flag anyway when
1482 * throwing an exception, so we can insert some code that avoids chucking
1483 * an exception when we're optimizing stuff.
1485 * Returns 0 on success.
1487 int dvmPrepForDexOpt(const char* bootClassPath, DexOptimizerMode dexOptMode,
1488 DexClassVerifyMode verifyMode, int dexoptFlags)
1490 gDvm.initializing = true;
1491 gDvm.optimizing = true;
1493 /* configure signal handling */
1496 /* set some defaults */
1497 setCommandLineDefaults();
1498 free(gDvm.bootClassPathStr);
1499 gDvm.bootClassPathStr = strdup(bootClassPath);
1501 /* set opt/verify modes */
1502 gDvm.dexOptMode = dexOptMode;
1503 gDvm.classVerifyMode = verifyMode;
1504 gDvm.generateRegisterMaps = (dexoptFlags & DEXOPT_GEN_REGISTER_MAPS) != 0;
1507 * Initialize the heap, some basic thread control mutexes, and
1508 * get the bootclasspath prepped.
1510 * We can't load any classes yet because we may not yet have a source
1511 * for things like java.lang.Object and java.lang.Class.
1513 if (!dvmGcStartup())
1515 if (!dvmThreadStartup())
1517 if (!dvmInlineNativeStartup())
1519 if (!dvmVerificationStartup())
1521 if (!dvmRegisterMapStartup())
1523 if (!dvmInstanceofStartup())
1525 if (!dvmClassStartup())
1529 * We leave gDvm.initializing set to "true" so that, if we're not
1530 * able to process the "core" classes, we don't go into a death-spin
1531 * trying to throw a "class not found" exception.
1543 * All threads have stopped. Finish the shutdown procedure.
1545 * We can also be called if startup fails partway through, so be prepared
1546 * to deal with partially initialized data.
1548 * Free any storage allocated in gGlobals.
1550 * We can't dlclose() shared libs we've loaded, because it's possible a
1551 * thread not associated with the VM is running code in one.
1553 * This is called from the JNI DestroyJavaVM function, which can be
1554 * called from any thread. (In practice, this will usually run in the
1555 * same thread that started the VM, a/k/a the main thread, but we don't
1556 * want to assume that.)
1558 void dvmShutdown(void)
1560 LOGV("VM shutting down\n");
1562 if (CALC_CACHE_STATS)
1563 dvmDumpAtomicCacheStats(gDvm.instanceofCache);
1566 * Stop our internal threads.
1568 dvmHeapWorkerShutdown();
1570 if (gDvm.jdwpState != NULL)
1571 dvmJdwpShutdown(gDvm.jdwpState);
1572 free(gDvm.jdwpHost);
1573 gDvm.jdwpHost = NULL;
1574 free(gDvm.stackTraceFile);
1575 gDvm.stackTraceFile = NULL;
1577 /* tell signal catcher to shut down if it was started */
1578 dvmSignalCatcherShutdown();
1580 /* shut down stdout/stderr conversion */
1581 dvmStdioConverterShutdown();
1584 if (gDvm.executionMode == kExecutionModeJit) {
1585 /* shut down the compiler thread */
1586 dvmCompilerShutdown();
1591 * Kill any daemon threads that still exist. Actively-running threads
1592 * are likely to crash the process if they continue to execute while
1593 * the VM shuts down.
1597 if (gDvm.verboseShutdown)
1598 LOGD("VM cleaning up\n");
1600 dvmDebuggerShutdown();
1601 dvmReflectShutdown();
1602 #ifdef WITH_PROFILER
1603 dvmProfilingShutdown();
1606 dvmStringInternShutdown();
1607 dvmExceptionShutdown();
1608 dvmThreadShutdown();
1610 dvmVerificationShutdown();
1611 dvmRegisterMapShutdown();
1612 dvmInstanceofShutdown();
1613 dvmInlineNativeShutdown();
1615 dvmAllocTrackerShutdown();
1616 dvmPropertiesShutdown();
1618 /* these must happen AFTER dvmClassShutdown has walked through class data */
1619 dvmNativeShutdown();
1620 dvmInternalNativeShutdown();
1622 free(gDvm.bootClassPathStr);
1623 free(gDvm.classPathStr);
1625 freeAssertionCtrl();
1628 * We want valgrind to report anything we forget to free as "definitely
1629 * lost". If there's a pointer in the global chunk, it would be reported
1630 * as "still reachable". Erasing the memory fixes this.
1632 * This must be erased to zero if we want to restart the VM within this
1635 memset(&gDvm, 0xcd, sizeof(gDvm));
1640 * fprintf() wrapper that calls through the JNI-specified vfprintf hook if
1641 * one was specified.
1643 int dvmFprintf(FILE* fp, const char* format, ...)
1648 va_start(args, format);
1649 if (gDvm.vfprintfHook != NULL)
1650 result = (*gDvm.vfprintfHook)(fp, format, args);
1652 result = vfprintf(fp, format, args);
1659 * Abort the VM. We get here on fatal errors. Try very hard not to use
1660 * this; whenever possible, return an error to somebody responsible.
1664 LOGE("VM aborting\n");
1666 fflush(NULL); // flush all open file buffers
1668 /* JNI-supplied abort hook gets right of first refusal */
1669 if (gDvm.abortHook != NULL)
1670 (*gDvm.abortHook)();
1673 * If we call abort(), all threads in the process receives a SIBABRT.
1674 * debuggerd dumps the stack trace of the main thread, whether or not
1675 * that was the thread that failed.
1677 * By stuffing a value into a bogus address, we cause a segmentation
1678 * fault in the current thread, and get a useful log from debuggerd.
1679 * We can also trivially tell the difference between a VM crash and
1680 * a deliberate abort by looking at the fault address.
1682 *((char*)0xdeadd00d) = 38;