AndroidRuntime.cpp revision d195e5ab401432ddac659791640a2927fc668699
1/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
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
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17#define LOG_TAG "AndroidRuntime"
18//#define LOG_NDEBUG 0
19
20#include <android_runtime/AndroidRuntime.h>
21#include <binder/IBinder.h>
22#include <binder/IPCThreadState.h>
23#include <binder/IServiceManager.h>
24#include <utils/Log.h>
25#include <utils/misc.h>
26#include <binder/Parcel.h>
27#include <utils/StringArray.h>
28#include <utils/threads.h>
29#include <cutils/properties.h>
30
31#include <SkGraphics.h>
32#include <SkImageDecoder.h>
33#include <SkImageRef_GlobalPool.h>
34
35#include "jni.h"
36#include "JNIHelp.h"
37#include "android_util_Binder.h"
38
39#include <stdio.h>
40#include <signal.h>
41#include <sys/stat.h>
42#include <sys/types.h>
43#include <signal.h>
44#include <dirent.h>
45#include <assert.h>
46
47
48using namespace android;
49
50extern void register_BindTest();
51
52extern int register_android_os_Binder(JNIEnv* env);
53extern int register_android_os_Process(JNIEnv* env);
54extern int register_android_graphics_Bitmap(JNIEnv*);
55extern int register_android_graphics_BitmapFactory(JNIEnv*);
56extern int register_android_graphics_BitmapRegionDecoder(JNIEnv*);
57extern int register_android_graphics_Camera(JNIEnv* env);
58extern int register_android_graphics_Graphics(JNIEnv* env);
59extern int register_android_graphics_Interpolator(JNIEnv* env);
60extern int register_android_graphics_LayerRasterizer(JNIEnv*);
61extern int register_android_graphics_MaskFilter(JNIEnv* env);
62extern int register_android_graphics_Movie(JNIEnv* env);
63extern int register_android_graphics_NinePatch(JNIEnv*);
64extern int register_android_graphics_PathEffect(JNIEnv* env);
65extern int register_android_graphics_Shader(JNIEnv* env);
66extern int register_android_graphics_Typeface(JNIEnv* env);
67extern int register_android_graphics_YuvImage(JNIEnv* env);
68
69extern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env);
70extern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env);
71extern int register_android_opengl_jni_GLES10(JNIEnv* env);
72extern int register_android_opengl_jni_GLES10Ext(JNIEnv* env);
73extern int register_android_opengl_jni_GLES11(JNIEnv* env);
74extern int register_android_opengl_jni_GLES11Ext(JNIEnv* env);
75extern int register_android_opengl_jni_GLES20(JNIEnv* env);
76
77extern int register_android_hardware_Camera(JNIEnv *env);
78extern int register_android_hardware_SensorManager(JNIEnv *env);
79extern int register_android_hardware_UsbDevice(JNIEnv *env);
80extern int register_android_hardware_UsbDeviceConnection(JNIEnv *env);
81extern int register_android_hardware_UsbRequest(JNIEnv *env);
82
83extern int register_android_media_AudioRecord(JNIEnv *env);
84extern int register_android_media_AudioSystem(JNIEnv *env);
85extern int register_android_media_AudioTrack(JNIEnv *env);
86extern int register_android_media_JetPlayer(JNIEnv *env);
87extern int register_android_media_ToneGenerator(JNIEnv *env);
88
89extern int register_android_util_FloatMath(JNIEnv* env);
90
91namespace android {
92
93/*
94 * JNI-based registration functions.  Note these are properly contained in
95 * namespace android.
96 */
97extern int register_android_content_AssetManager(JNIEnv* env);
98extern int register_android_util_EventLog(JNIEnv* env);
99extern int register_android_util_Log(JNIEnv* env);
100extern int register_android_content_StringBlock(JNIEnv* env);
101extern int register_android_content_XmlBlock(JNIEnv* env);
102extern int register_android_emoji_EmojiFactory(JNIEnv* env);
103extern int register_android_graphics_Canvas(JNIEnv* env);
104extern int register_android_graphics_ColorFilter(JNIEnv* env);
105extern int register_android_graphics_DrawFilter(JNIEnv* env);
106extern int register_android_graphics_Matrix(JNIEnv* env);
107extern int register_android_graphics_Paint(JNIEnv* env);
108extern int register_android_graphics_Path(JNIEnv* env);
109extern int register_android_graphics_PathMeasure(JNIEnv* env);
110extern int register_android_graphics_Picture(JNIEnv*);
111extern int register_android_graphics_PorterDuff(JNIEnv* env);
112extern int register_android_graphics_Rasterizer(JNIEnv* env);
113extern int register_android_graphics_Region(JNIEnv* env);
114extern int register_android_graphics_SurfaceTexture(JNIEnv* env);
115extern int register_android_graphics_Xfermode(JNIEnv* env);
116extern int register_android_graphics_PixelFormat(JNIEnv* env);
117extern int register_com_android_internal_graphics_NativeUtils(JNIEnv *env);
118extern int register_android_view_Display(JNIEnv* env);
119extern int register_android_view_GLES20Canvas(JNIEnv* env);
120extern int register_android_view_Surface(JNIEnv* env);
121extern int register_android_view_ViewRoot(JNIEnv* env);
122extern int register_android_database_CursorWindow(JNIEnv* env);
123extern int register_android_database_SQLiteCompiledSql(JNIEnv* env);
124extern int register_android_database_SQLiteDatabase(JNIEnv* env);
125extern int register_android_database_SQLiteDebug(JNIEnv* env);
126extern int register_android_database_SQLiteProgram(JNIEnv* env);
127extern int register_android_database_SQLiteQuery(JNIEnv* env);
128extern int register_android_database_SQLiteStatement(JNIEnv* env);
129extern int register_android_debug_JNITest(JNIEnv* env);
130extern int register_android_nio_utils(JNIEnv* env);
131extern int register_android_nfc_NdefMessage(JNIEnv *env);
132extern int register_android_nfc_NdefRecord(JNIEnv *env);
133extern int register_android_pim_EventRecurrence(JNIEnv* env);
134extern int register_android_text_format_Time(JNIEnv* env);
135extern int register_android_os_Debug(JNIEnv* env);
136extern int register_android_os_MessageQueue(JNIEnv* env);
137extern int register_android_os_ParcelFileDescriptor(JNIEnv *env);
138extern int register_android_os_Power(JNIEnv *env);
139extern int register_android_os_StatFs(JNIEnv *env);
140extern int register_android_os_SystemProperties(JNIEnv *env);
141extern int register_android_os_SystemClock(JNIEnv* env);
142extern int register_android_os_FileObserver(JNIEnv *env);
143extern int register_android_os_FileUtils(JNIEnv *env);
144extern int register_android_os_UEventObserver(JNIEnv* env);
145extern int register_android_os_MemoryFile(JNIEnv* env);
146extern int register_android_net_LocalSocketImpl(JNIEnv* env);
147extern int register_android_net_NetworkUtils(JNIEnv* env);
148extern int register_android_net_TrafficStats(JNIEnv* env);
149extern int register_android_net_wifi_WifiManager(JNIEnv* env);
150extern int register_android_text_AndroidCharacter(JNIEnv *env);
151extern int register_android_text_AndroidBidi(JNIEnv *env);
152extern int register_android_text_KeyCharacterMap(JNIEnv *env);
153extern int register_android_opengl_classes(JNIEnv *env);
154extern int register_android_bluetooth_HeadsetBase(JNIEnv* env);
155extern int register_android_bluetooth_BluetoothAudioGateway(JNIEnv* env);
156extern int register_android_bluetooth_BluetoothSocket(JNIEnv *env);
157extern int register_android_server_BluetoothService(JNIEnv* env);
158extern int register_android_server_BluetoothEventLoop(JNIEnv *env);
159extern int register_android_server_BluetoothA2dpService(JNIEnv* env);
160extern int register_android_server_Watchdog(JNIEnv* env);
161extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
162extern int register_com_android_internal_os_ZygoteInit(JNIEnv* env);
163extern int register_android_backup_BackupDataInput(JNIEnv *env);
164extern int register_android_backup_BackupDataOutput(JNIEnv *env);
165extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
166extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
167extern int register_android_app_ActivityThread(JNIEnv *env);
168extern int register_android_app_NativeActivity(JNIEnv *env);
169extern int register_android_view_InputChannel(JNIEnv* env);
170extern int register_android_view_InputQueue(JNIEnv* env);
171extern int register_android_view_KeyEvent(JNIEnv* env);
172extern int register_android_view_MotionEvent(JNIEnv* env);
173extern int register_android_view_VelocityTracker(JNIEnv* env);
174extern int register_android_content_res_ObbScanner(JNIEnv* env);
175extern int register_android_content_res_Configuration(JNIEnv* env);
176extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
177
178static AndroidRuntime* gCurRuntime = NULL;
179
180static void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL)
181{
182    if (jniThrowException(env, exc, msg) != 0)
183        assert(false);
184}
185
186/*
187 * Code written in the Java Programming Language calls here from main().
188 */
189static void com_android_internal_os_RuntimeInit_finishInit(JNIEnv* env, jobject clazz)
190{
191    gCurRuntime->onStarted();
192}
193
194static void com_android_internal_os_RuntimeInit_zygoteInit(JNIEnv* env, jobject clazz)
195{
196    gCurRuntime->onZygoteInit();
197}
198
199static jint com_android_internal_os_RuntimeInit_isComputerOn(JNIEnv* env, jobject clazz)
200{
201    return 1;
202}
203
204static void com_android_internal_os_RuntimeInit_turnComputerOn(JNIEnv* env, jobject clazz)
205{
206}
207
208static jint com_android_internal_os_RuntimeInit_getQwertyKeyboard(JNIEnv* env, jobject clazz)
209{
210    char* value = getenv("qwerty");
211    if (value != NULL && strcmp(value, "true") == 0) {
212        return 1;
213    }
214
215    return 0;
216}
217
218/*
219 * JNI registration.
220 */
221static JNINativeMethod gMethods[] = {
222    { "finishInit", "()V",
223        (void*) com_android_internal_os_RuntimeInit_finishInit },
224    { "zygoteInitNative", "()V",
225        (void*) com_android_internal_os_RuntimeInit_zygoteInit },
226    { "isComputerOn", "()I",
227        (void*) com_android_internal_os_RuntimeInit_isComputerOn },
228    { "turnComputerOn", "()V",
229        (void*) com_android_internal_os_RuntimeInit_turnComputerOn },
230    { "getQwertyKeyboard", "()I",
231        (void*) com_android_internal_os_RuntimeInit_getQwertyKeyboard },
232};
233
234int register_com_android_internal_os_RuntimeInit(JNIEnv* env)
235{
236    return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
237        gMethods, NELEM(gMethods));
238}
239
240// ----------------------------------------------------------------------
241
242/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
243
244
245AndroidRuntime::AndroidRuntime()
246{
247    SkGraphics::Init();
248    // this sets our preference for 16bit images during decode
249    // in case the src is opaque and 24bit
250    SkImageDecoder::SetDeviceConfig(SkBitmap::kRGB_565_Config);
251    // This cache is shared between browser native images, and java "purgeable"
252    // bitmaps. This globalpool is for images that do not either use the java
253    // heap, or are not backed by ashmem. See BitmapFactory.cpp for the key
254    // java call site.
255    SkImageRef_GlobalPool::SetRAMBudget(512 * 1024);
256    // There is also a global font cache, but its budget is specified in code
257    // see SkFontHost_android.cpp
258
259    // Pre-allocate enough space to hold a fair number of options.
260    mOptions.setCapacity(20);
261
262    assert(gCurRuntime == NULL);        // one per process
263    gCurRuntime = this;
264}
265
266AndroidRuntime::~AndroidRuntime()
267{
268    SkGraphics::Term();
269}
270
271/*
272 * Register native methods using JNI.
273 */
274/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
275    const char* className, const JNINativeMethod* gMethods, int numMethods)
276{
277    return jniRegisterNativeMethods(env, className, gMethods, numMethods);
278}
279
280status_t AndroidRuntime::callMain(const char* className,
281    jclass clazz, int argc, const char* const argv[])
282{
283    JNIEnv* env;
284    jmethodID methodId;
285
286    LOGD("Calling main entry %s", className);
287
288    env = getJNIEnv();
289    if (clazz == NULL || env == NULL) {
290        return UNKNOWN_ERROR;
291    }
292
293    methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
294    if (methodId == NULL) {
295        LOGE("ERROR: could not find method %s.main(String[])\n", className);
296        return UNKNOWN_ERROR;
297    }
298
299    /*
300     * We want to call main() with a String array with our arguments in it.
301     * Create an array and populate it.
302     */
303    jclass stringClass;
304    jobjectArray strArray;
305
306    stringClass = env->FindClass("java/lang/String");
307    strArray = env->NewObjectArray(argc, stringClass, NULL);
308
309    for (int i = 0; i < argc; i++) {
310        jstring argStr = env->NewStringUTF(argv[i]);
311        env->SetObjectArrayElement(strArray, i, argStr);
312    }
313
314    env->CallStaticVoidMethod(clazz, methodId, strArray);
315    return NO_ERROR;
316}
317
318/*
319 * The VM calls this through the "exit" hook.
320 */
321static void runtime_exit(int code)
322{
323    gCurRuntime->onExit(code);
324    exit(code);
325}
326
327/*
328 * The VM calls this through the "vfprintf" hook.
329 *
330 * We ignore "fp" and just write the results to the log file.
331 */
332static void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
333{
334    LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
335}
336
337/**
338 * The VM calls this when mutex contention debugging is enabled to
339 * determine whether or not the blocked thread was a "sensitive thread"
340 * for user responsiveness/smoothess.
341 *
342 * Our policy for this is whether or not we're tracing any StrictMode
343 * events on this thread (which we might've inherited via Binder calls
344 * into us)
345 */
346static bool runtime_isSensitiveThread() {
347    IPCThreadState* state = IPCThreadState::selfOrNull();
348    return state && state->getStrictModePolicy() != 0;
349}
350
351
352/**
353 * Add VM arguments to the to-be-executed VM
354 * Stops at first non '-' argument (also stops at an argument of '--')
355 * Returns the number of args consumed
356 */
357int AndroidRuntime::addVmArguments(int argc, const char* const argv[])
358{
359    int i;
360
361    for (i = 0; i<argc; i++) {
362        if (argv[i][0] != '-') {
363            return i;
364        }
365        if (argv[i][1] == '-' && argv[i][2] == 0) {
366            return i+1;
367        }
368
369        JavaVMOption opt;
370        memset(&opt, 0, sizeof(opt));
371        opt.optionString = (char*)argv[i];
372        mOptions.add(opt);
373    }
374    return i;
375}
376
377static int hasDir(const char* dir)
378{
379    struct stat s;
380    int res = stat(dir, &s);
381    if (res == 0) {
382        return S_ISDIR(s.st_mode);
383    }
384    return 0;
385}
386
387/*
388 * We just want failed write() calls to just return with an error.
389 */
390static void blockSigpipe()
391{
392    sigset_t mask;
393
394    sigemptyset(&mask);
395    sigaddset(&mask, SIGPIPE);
396    if (sigprocmask(SIG_BLOCK, &mask, NULL) != 0)
397        LOGW("WARNING: SIGPIPE not blocked\n");
398}
399
400/*
401 * Read the persistent locale.
402 */
403static void readLocale(char* language, char* region)
404{
405    char propLang[PROPERTY_VALUE_MAX], propRegn[PROPERTY_VALUE_MAX];
406
407    property_get("persist.sys.language", propLang, "");
408    property_get("persist.sys.country", propRegn, "");
409    if (*propLang == 0 && *propRegn == 0) {
410        /* Set to ro properties, default is en_US */
411        property_get("ro.product.locale.language", propLang, "en");
412        property_get("ro.product.locale.region", propRegn, "US");
413    }
414    strncat(language, propLang, 2);
415    strncat(region, propRegn, 2);
416    //LOGD("language=%s region=%s\n", language, region);
417}
418
419/*
420 * Parse a property containing space-separated options that should be
421 * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
422 *
423 * This will cut up "extraOptsBuf" as we chop it into individual options.
424 *
425 * Adds the strings, if any, to mOptions.
426 */
427void AndroidRuntime::parseExtraOpts(char* extraOptsBuf)
428{
429    JavaVMOption opt;
430    char* start;
431    char* end;
432
433    memset(&opt, 0, sizeof(opt));
434    start = extraOptsBuf;
435    while (*start != '\0') {
436        while (*start == ' ')                   /* skip leading whitespace */
437            start++;
438        if (*start == '\0')                     /* was trailing ws, bail */
439            break;
440
441        end = start+1;
442        while (*end != ' ' && *end != '\0')     /* find end of token */
443            end++;
444        if (*end == ' ')
445            *end++ = '\0';          /* mark end, advance to indicate more */
446
447        opt.optionString = start;
448        mOptions.add(opt);
449        start = end;
450    }
451}
452
453/*
454 * Start the Dalvik Virtual Machine.
455 *
456 * Various arguments, most determined by system properties, are passed in.
457 * The "mOptions" vector is updated.
458 *
459 * Returns 0 on success.
460 */
461int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
462{
463    int result = -1;
464    JavaVMInitArgs initArgs;
465    JavaVMOption opt;
466    char propBuf[PROPERTY_VALUE_MAX];
467    char stackTraceFileBuf[PROPERTY_VALUE_MAX];
468    char dexoptFlagsBuf[PROPERTY_VALUE_MAX];
469    char enableAssertBuf[sizeof("-ea:")-1 + PROPERTY_VALUE_MAX];
470    char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
471    char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
472    char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
473    char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
474    char extraOptsBuf[PROPERTY_VALUE_MAX];
475    char* stackTraceFile = NULL;
476    bool checkJni = false;
477    bool checkDexSum = false;
478    bool logStdio = false;
479    enum {
480      kEMDefault,
481      kEMIntPortable,
482      kEMIntFast,
483#if defined(WITH_JIT)
484      kEMJitCompiler,
485#endif
486    } executionMode = kEMDefault;
487
488
489    property_get("dalvik.vm.checkjni", propBuf, "");
490    if (strcmp(propBuf, "true") == 0) {
491        checkJni = true;
492    } else if (strcmp(propBuf, "false") != 0) {
493        /* property is neither true nor false; fall back on kernel parameter */
494        property_get("ro.kernel.android.checkjni", propBuf, "");
495        if (propBuf[0] == '1') {
496            checkJni = true;
497        }
498    }
499
500    property_get("dalvik.vm.execution-mode", propBuf, "");
501    if (strcmp(propBuf, "int:portable") == 0) {
502        executionMode = kEMIntPortable;
503    } else if (strcmp(propBuf, "int:fast") == 0) {
504        executionMode = kEMIntFast;
505#if defined(WITH_JIT)
506    } else if (strcmp(propBuf, "int:jit") == 0) {
507        executionMode = kEMJitCompiler;
508#endif
509    }
510
511    property_get("dalvik.vm.stack-trace-file", stackTraceFileBuf, "");
512
513    property_get("dalvik.vm.check-dex-sum", propBuf, "");
514    if (strcmp(propBuf, "true") == 0) {
515        checkDexSum = true;
516    }
517
518    property_get("log.redirect-stdio", propBuf, "");
519    if (strcmp(propBuf, "true") == 0) {
520        logStdio = true;
521    }
522
523    strcpy(enableAssertBuf, "-ea:");
524    property_get("dalvik.vm.enableassertions", enableAssertBuf+4, "");
525
526    strcpy(jniOptsBuf, "-Xjniopts:");
527    property_get("dalvik.vm.jniopts", jniOptsBuf+10, "");
528
529    /* route exit() to our handler */
530    opt.extraInfo = (void*) runtime_exit;
531    opt.optionString = "exit";
532    mOptions.add(opt);
533
534    /* route fprintf() to our handler */
535    opt.extraInfo = (void*) runtime_vfprintf;
536    opt.optionString = "vfprintf";
537    mOptions.add(opt);
538
539    /* register the framework-specific "is sensitive thread" hook */
540    opt.extraInfo = (void*) runtime_isSensitiveThread;
541    opt.optionString = "sensitiveThread";
542    mOptions.add(opt);
543
544    opt.extraInfo = NULL;
545
546    /* enable verbose; standard options are { jni, gc, class } */
547    //options[curOpt++].optionString = "-verbose:jni";
548    opt.optionString = "-verbose:gc";
549    mOptions.add(opt);
550    //options[curOpt++].optionString = "-verbose:class";
551
552    /*
553     * The default starting and maximum size of the heap.  Larger
554     * values should be specified in a product property override.
555     */
556    strcpy(heapstartsizeOptsBuf, "-Xms");
557    property_get("dalvik.vm.heapstartsize", heapstartsizeOptsBuf+4, "4m");
558    opt.optionString = heapstartsizeOptsBuf;
559    mOptions.add(opt);
560    strcpy(heapsizeOptsBuf, "-Xmx");
561    property_get("dalvik.vm.heapsize", heapsizeOptsBuf+4, "16m");
562    opt.optionString = heapsizeOptsBuf;
563    mOptions.add(opt);
564
565    strcpy(heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
566    property_get("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf+20, "");
567    if (heapgrowthlimitOptsBuf[20] != '\0') {
568        opt.optionString = heapgrowthlimitOptsBuf;
569        mOptions.add(opt);
570    }
571
572    /*
573     * Enable or disable dexopt features, such as bytecode verification and
574     * calculation of register maps for precise GC.
575     */
576    property_get("dalvik.vm.dexopt-flags", dexoptFlagsBuf, "");
577    if (dexoptFlagsBuf[0] != '\0') {
578        const char* opc;
579        const char* val;
580
581        opc = strstr(dexoptFlagsBuf, "v=");     /* verification */
582        if (opc != NULL) {
583            switch (*(opc+2)) {
584            case 'n':   val = "-Xverify:none";      break;
585            case 'r':   val = "-Xverify:remote";    break;
586            case 'a':   val = "-Xverify:all";       break;
587            default:    val = NULL;                 break;
588            }
589
590            if (val != NULL) {
591                opt.optionString = val;
592                mOptions.add(opt);
593            }
594        }
595
596        opc = strstr(dexoptFlagsBuf, "o=");     /* optimization */
597        if (opc != NULL) {
598            switch (*(opc+2)) {
599            case 'n':   val = "-Xdexopt:none";      break;
600            case 'v':   val = "-Xdexopt:verified";  break;
601            case 'a':   val = "-Xdexopt:all";       break;
602            case 'f':   val = "-Xdexopt:full";      break;
603            default:    val = NULL;                 break;
604            }
605
606            if (val != NULL) {
607                opt.optionString = val;
608                mOptions.add(opt);
609            }
610        }
611
612        opc = strstr(dexoptFlagsBuf, "m=y");    /* register map */
613        if (opc != NULL) {
614            opt.optionString = "-Xgenregmap";
615            mOptions.add(opt);
616
617            /* turn on precise GC while we're at it */
618            opt.optionString = "-Xgc:precise";
619            mOptions.add(opt);
620        }
621    }
622
623    /* enable debugging; set suspend=y to pause during VM init */
624#ifdef HAVE_ANDROID_OS
625    /* use android ADB transport */
626    opt.optionString =
627        "-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y";
628#else
629    /* use TCP socket; address=0 means start at port 8000 and probe up */
630    LOGI("Using TCP socket for JDWP\n");
631    opt.optionString =
632        "-agentlib:jdwp=transport=dt_socket,suspend=n,server=y,address=0";
633#endif
634    mOptions.add(opt);
635
636    char enableDPBuf[sizeof("-Xdeadlockpredict:") + PROPERTY_VALUE_MAX];
637    property_get("dalvik.vm.deadlock-predict", propBuf, "");
638    if (strlen(propBuf) > 0) {
639        strcpy(enableDPBuf, "-Xdeadlockpredict:");
640        strcat(enableDPBuf, propBuf);
641        opt.optionString = enableDPBuf;
642        mOptions.add(opt);
643    }
644
645    LOGD("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
646    if (checkJni) {
647        /* extended JNI checking */
648        opt.optionString = "-Xcheck:jni";
649        mOptions.add(opt);
650
651        /* set a cap on JNI global references */
652        opt.optionString = "-Xjnigreflimit:2000";
653        mOptions.add(opt);
654
655        /* with -Xcheck:jni, this provides a JNI function call trace */
656        //opt.optionString = "-verbose:jni";
657        //mOptions.add(opt);
658    }
659
660    char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:") + sizeof(propBuf)];
661    property_get("dalvik.vm.lockprof.threshold", propBuf, "");
662    if (strlen(propBuf) > 0) {
663      strcpy(lockProfThresholdBuf, "-Xlockprofthreshold:");
664      strcat(lockProfThresholdBuf, propBuf);
665      opt.optionString = lockProfThresholdBuf;
666      mOptions.add(opt);
667    }
668
669#if defined(WITH_JIT)
670    /* Force interpreter-only mode for selected opcodes. Eg "1-0a,3c,f1-ff" */
671    char jitOpBuf[sizeof("-Xjitop:") + PROPERTY_VALUE_MAX];
672    property_get("dalvik.vm.jit.op", propBuf, "");
673    if (strlen(propBuf) > 0) {
674        strcpy(jitOpBuf, "-Xjitop:");
675        strcat(jitOpBuf, propBuf);
676        opt.optionString = jitOpBuf;
677        mOptions.add(opt);
678    }
679
680    /* Force interpreter-only mode for selected methods */
681    char jitMethodBuf[sizeof("-Xjitmethod:") + PROPERTY_VALUE_MAX];
682    property_get("dalvik.vm.jit.method", propBuf, "");
683    if (strlen(propBuf) > 0) {
684        strcpy(jitMethodBuf, "-Xjitmethod:");
685        strcat(jitMethodBuf, propBuf);
686        opt.optionString = jitMethodBuf;
687        mOptions.add(opt);
688    }
689#endif
690
691    if (executionMode == kEMIntPortable) {
692        opt.optionString = "-Xint:portable";
693        mOptions.add(opt);
694    } else if (executionMode == kEMIntFast) {
695        opt.optionString = "-Xint:fast";
696        mOptions.add(opt);
697#if defined(WITH_JIT)
698    } else if (executionMode == kEMJitCompiler) {
699        opt.optionString = "-Xint:jit";
700        mOptions.add(opt);
701#endif
702    }
703
704    if (checkDexSum) {
705        /* perform additional DEX checksum tests */
706        opt.optionString = "-Xcheckdexsum";
707        mOptions.add(opt);
708    }
709
710    if (logStdio) {
711        /* convert stdout/stderr to log messages */
712        opt.optionString = "-Xlog-stdio";
713        mOptions.add(opt);
714    }
715
716    if (enableAssertBuf[4] != '\0') {
717        /* accept "all" to mean "all classes and packages" */
718        if (strcmp(enableAssertBuf+4, "all") == 0)
719            enableAssertBuf[3] = '\0';
720        LOGI("Assertions enabled: '%s'\n", enableAssertBuf);
721        opt.optionString = enableAssertBuf;
722        mOptions.add(opt);
723    } else {
724        LOGV("Assertions disabled\n");
725    }
726
727    if (jniOptsBuf[10] != '\0') {
728        LOGI("JNI options: '%s'\n", jniOptsBuf);
729        opt.optionString = jniOptsBuf;
730        mOptions.add(opt);
731    }
732
733    if (stackTraceFileBuf[0] != '\0') {
734        static const char* stfOptName = "-Xstacktracefile:";
735
736        stackTraceFile = (char*) malloc(strlen(stfOptName) +
737            strlen(stackTraceFileBuf) +1);
738        strcpy(stackTraceFile, stfOptName);
739        strcat(stackTraceFile, stackTraceFileBuf);
740        opt.optionString = stackTraceFile;
741        mOptions.add(opt);
742    }
743
744    /* extra options; parse this late so it overrides others */
745    property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
746    parseExtraOpts(extraOptsBuf);
747
748    /* Set the properties for locale */
749    {
750        char langOption[sizeof("-Duser.language=") + 3];
751        char regionOption[sizeof("-Duser.region=") + 3];
752        strcpy(langOption, "-Duser.language=");
753        strcpy(regionOption, "-Duser.region=");
754        readLocale(langOption, regionOption);
755        opt.extraInfo = NULL;
756        opt.optionString = langOption;
757        mOptions.add(opt);
758        opt.optionString = regionOption;
759        mOptions.add(opt);
760    }
761
762    /*
763     * We don't have /tmp on the device, but we often have an SD card.  Apps
764     * shouldn't use this, but some test suites might want to exercise it.
765     */
766    opt.optionString = "-Djava.io.tmpdir=/sdcard";
767    mOptions.add(opt);
768
769    initArgs.version = JNI_VERSION_1_4;
770    initArgs.options = mOptions.editArray();
771    initArgs.nOptions = mOptions.size();
772    initArgs.ignoreUnrecognized = JNI_FALSE;
773
774    /*
775     * Initialize the VM.
776     *
777     * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread.
778     * If this call succeeds, the VM is ready, and we can start issuing
779     * JNI calls.
780     */
781    if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) {
782        LOGE("JNI_CreateJavaVM failed\n");
783        goto bail;
784    }
785
786    result = 0;
787
788bail:
789    free(stackTraceFile);
790    return result;
791}
792
793char* AndroidRuntime::toSlashClassName(const char* className)
794{
795    char* result = strdup(className);
796    for (char* cp = result; *cp != '\0'; cp++) {
797        if (*cp == '.') {
798            *cp = '/';
799        }
800    }
801    return result;
802}
803
804/*
805 * Start the Android runtime.  This involves starting the virtual machine
806 * and calling the "static void main(String[] args)" method in the class
807 * named by "className".
808 */
809void AndroidRuntime::start(const char* className, const bool startSystemServer)
810{
811    LOGD("\n>>>>>> AndroidRuntime START %s <<<<<<\n",
812            className != NULL ? className : "(unknown)");
813
814    blockSigpipe();
815
816    /*
817     * 'startSystemServer == true' means runtime is obsolete and not run from
818     * init.rc anymore, so we print out the boot start event here.
819     */
820    if (startSystemServer) {
821        /* track our progress through the boot sequence */
822        const int LOG_BOOT_PROGRESS_START = 3000;
823        LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START,
824                       ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));
825    }
826
827    const char* rootDir = getenv("ANDROID_ROOT");
828    if (rootDir == NULL) {
829        rootDir = "/system";
830        if (!hasDir("/system")) {
831            LOG_FATAL("No root directory specified, and /android does not exist.");
832            return;
833        }
834        setenv("ANDROID_ROOT", rootDir, 1);
835    }
836
837    //const char* kernelHack = getenv("LD_ASSUME_KERNEL");
838    //LOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack);
839
840    /* start the virtual machine */
841    JNIEnv* env;
842    if (startVm(&mJavaVM, &env) != 0) {
843        return;
844    }
845    onVmCreated(env);
846
847    /*
848     * Register android functions.
849     */
850    if (startReg(env) < 0) {
851        LOGE("Unable to register all android natives\n");
852        return;
853    }
854
855    /*
856     * We want to call main() with a String array with arguments in it.
857     * At present we only have one argument, the class name.  Create an
858     * array to hold it.
859     */
860    jclass stringClass;
861    jobjectArray strArray;
862    jstring classNameStr;
863    jstring startSystemServerStr;
864
865    stringClass = env->FindClass("java/lang/String");
866    assert(stringClass != NULL);
867    strArray = env->NewObjectArray(2, stringClass, NULL);
868    assert(strArray != NULL);
869    classNameStr = env->NewStringUTF(className);
870    assert(classNameStr != NULL);
871    env->SetObjectArrayElement(strArray, 0, classNameStr);
872    startSystemServerStr = env->NewStringUTF(startSystemServer ?
873                                                 "true" : "false");
874    env->SetObjectArrayElement(strArray, 1, startSystemServerStr);
875
876    /*
877     * Start VM.  This thread becomes the main thread of the VM, and will
878     * not return until the VM exits.
879     */
880    char* slashClassName = toSlashClassName(className);
881    jclass startClass = env->FindClass(slashClassName);
882    if (startClass == NULL) {
883        LOGE("JavaVM unable to locate class '%s'\n", slashClassName);
884        /* keep going */
885    } else {
886        jmethodID startMeth = env->GetStaticMethodID(startClass, "main",
887            "([Ljava/lang/String;)V");
888        if (startMeth == NULL) {
889            LOGE("JavaVM unable to find main() in '%s'\n", className);
890            /* keep going */
891        } else {
892            env->CallStaticVoidMethod(startClass, startMeth, strArray);
893
894#if 0
895            if (env->ExceptionCheck())
896                threadExitUncaughtException(env);
897#endif
898        }
899    }
900    free(slashClassName);
901
902    LOGD("Shutting down VM\n");
903    if (mJavaVM->DetachCurrentThread() != JNI_OK)
904        LOGW("Warning: unable to detach main thread\n");
905    if (mJavaVM->DestroyJavaVM() != 0)
906        LOGW("Warning: VM did not shut down cleanly\n");
907}
908
909void AndroidRuntime::start()
910{
911    start("com.android.internal.os.RuntimeInit",
912        false /* Don't start the system server */);
913}
914
915void AndroidRuntime::onExit(int code)
916{
917    LOGV("AndroidRuntime onExit calling exit(%d)", code);
918    exit(code);
919}
920
921void AndroidRuntime::onVmCreated(JNIEnv* env)
922{
923    // If AndroidRuntime had anything to do here, we'd have done it in 'start'.
924}
925
926/*
927 * Get the JNIEnv pointer for this thread.
928 *
929 * Returns NULL if the slot wasn't allocated or populated.
930 */
931/*static*/ JNIEnv* AndroidRuntime::getJNIEnv()
932{
933    JNIEnv* env;
934    JavaVM* vm = AndroidRuntime::getJavaVM();
935    assert(vm != NULL);
936
937    if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
938        return NULL;
939    return env;
940}
941
942/*
943 * Makes the current thread visible to the VM.
944 *
945 * The JNIEnv pointer returned is only valid for the current thread, and
946 * thus must be tucked into thread-local storage.
947 */
948static int javaAttachThread(const char* threadName, JNIEnv** pEnv)
949{
950    JavaVMAttachArgs args;
951    JavaVM* vm;
952    jint result;
953
954    vm = AndroidRuntime::getJavaVM();
955    assert(vm != NULL);
956
957    args.version = JNI_VERSION_1_4;
958    args.name = (char*) threadName;
959    args.group = NULL;
960
961    result = vm->AttachCurrentThread(pEnv, (void*) &args);
962    if (result != JNI_OK)
963        LOGI("NOTE: attach of thread '%s' failed\n", threadName);
964
965    return result;
966}
967
968/*
969 * Detach the current thread from the set visible to the VM.
970 */
971static int javaDetachThread(void)
972{
973    JavaVM* vm;
974    jint result;
975
976    vm = AndroidRuntime::getJavaVM();
977    assert(vm != NULL);
978
979    result = vm->DetachCurrentThread();
980    if (result != JNI_OK)
981        LOGE("ERROR: thread detach failed\n");
982    return result;
983}
984
985/*
986 * When starting a native thread that will be visible from the VM, we
987 * bounce through this to get the right attach/detach action.
988 * Note that this function calls free(args)
989 */
990/*static*/ int AndroidRuntime::javaThreadShell(void* args) {
991    void* start = ((void**)args)[0];
992    void* userData = ((void **)args)[1];
993    char* name = (char*) ((void **)args)[2];        // we own this storage
994    free(args);
995    JNIEnv* env;
996    int result;
997
998    /* hook us into the VM */
999    if (javaAttachThread(name, &env) != JNI_OK)
1000        return -1;
1001
1002    /* start the thread running */
1003    result = (*(android_thread_func_t)start)(userData);
1004
1005    /* unhook us */
1006    javaDetachThread();
1007    free(name);
1008
1009    return result;
1010}
1011
1012/*
1013 * This is invoked from androidCreateThreadEtc() via the callback
1014 * set with androidSetCreateThreadFunc().
1015 *
1016 * We need to create the new thread in such a way that it gets hooked
1017 * into the VM before it really starts executing.
1018 */
1019/*static*/ int AndroidRuntime::javaCreateThreadEtc(
1020                                android_thread_func_t entryFunction,
1021                                void* userData,
1022                                const char* threadName,
1023                                int32_t threadPriority,
1024                                size_t threadStackSize,
1025                                android_thread_id_t* threadId)
1026{
1027    void** args = (void**) malloc(3 * sizeof(void*));   // javaThreadShell must free
1028    int result;
1029
1030    assert(threadName != NULL);
1031
1032    args[0] = (void*) entryFunction;
1033    args[1] = userData;
1034    args[2] = (void*) strdup(threadName);   // javaThreadShell must free
1035
1036    result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args,
1037        threadName, threadPriority, threadStackSize, threadId);
1038    return result;
1039}
1040
1041/*
1042 * Create a thread that is visible from the VM.
1043 *
1044 * This is called from elsewhere in the library.
1045 */
1046/*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name,
1047    void (*start)(void *), void* arg)
1048{
1049    android_thread_id_t threadId = 0;
1050    javaCreateThreadEtc((android_thread_func_t) start, arg, name,
1051        ANDROID_PRIORITY_DEFAULT, 0, &threadId);
1052    return threadId;
1053}
1054
1055#if 0
1056static void quickTest(void* arg)
1057{
1058    const char* str = (const char*) arg;
1059
1060    printf("In quickTest: %s\n", str);
1061}
1062#endif
1063
1064#ifdef NDEBUG
1065    #define REG_JNI(name)      { name }
1066    struct RegJNIRec {
1067        int (*mProc)(JNIEnv*);
1068    };
1069#else
1070    #define REG_JNI(name)      { name, #name }
1071    struct RegJNIRec {
1072        int (*mProc)(JNIEnv*);
1073        const char* mName;
1074    };
1075#endif
1076
1077typedef void (*RegJAMProc)();
1078
1079static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env)
1080{
1081    for (size_t i = 0; i < count; i++) {
1082        if (array[i].mProc(env) < 0) {
1083#ifndef NDEBUG
1084            LOGD("----------!!! %s failed to load\n", array[i].mName);
1085#endif
1086            return -1;
1087        }
1088    }
1089    return 0;
1090}
1091
1092static void register_jam_procs(const RegJAMProc array[], size_t count)
1093{
1094    for (size_t i = 0; i < count; i++) {
1095        array[i]();
1096    }
1097}
1098
1099static const RegJNIRec gRegJNI[] = {
1100    REG_JNI(register_android_debug_JNITest),
1101    REG_JNI(register_com_android_internal_os_RuntimeInit),
1102    REG_JNI(register_android_os_SystemClock),
1103    REG_JNI(register_android_util_EventLog),
1104    REG_JNI(register_android_util_Log),
1105    REG_JNI(register_android_util_FloatMath),
1106    REG_JNI(register_android_text_format_Time),
1107    REG_JNI(register_android_pim_EventRecurrence),
1108    REG_JNI(register_android_content_AssetManager),
1109    REG_JNI(register_android_content_StringBlock),
1110    REG_JNI(register_android_content_XmlBlock),
1111    REG_JNI(register_android_emoji_EmojiFactory),
1112    REG_JNI(register_android_text_AndroidCharacter),
1113    REG_JNI(register_android_text_AndroidBidi),
1114    REG_JNI(register_android_text_KeyCharacterMap),
1115    REG_JNI(register_android_os_Process),
1116    REG_JNI(register_android_os_SystemProperties),
1117    REG_JNI(register_android_os_Binder),
1118    REG_JNI(register_android_view_Display),
1119    REG_JNI(register_android_nio_utils),
1120    REG_JNI(register_android_graphics_PixelFormat),
1121    REG_JNI(register_android_graphics_Graphics),
1122    REG_JNI(register_android_view_GLES20Canvas),
1123    REG_JNI(register_android_view_Surface),
1124    REG_JNI(register_android_view_ViewRoot),
1125    REG_JNI(register_com_google_android_gles_jni_EGLImpl),
1126    REG_JNI(register_com_google_android_gles_jni_GLImpl),
1127    REG_JNI(register_android_opengl_jni_GLES10),
1128    REG_JNI(register_android_opengl_jni_GLES10Ext),
1129    REG_JNI(register_android_opengl_jni_GLES11),
1130    REG_JNI(register_android_opengl_jni_GLES11Ext),
1131    REG_JNI(register_android_opengl_jni_GLES20),
1132
1133    REG_JNI(register_android_graphics_Bitmap),
1134    REG_JNI(register_android_graphics_BitmapFactory),
1135    REG_JNI(register_android_graphics_BitmapRegionDecoder),
1136    REG_JNI(register_android_graphics_Camera),
1137    REG_JNI(register_android_graphics_Canvas),
1138    REG_JNI(register_android_graphics_ColorFilter),
1139    REG_JNI(register_android_graphics_DrawFilter),
1140    REG_JNI(register_android_graphics_Interpolator),
1141    REG_JNI(register_android_graphics_LayerRasterizer),
1142    REG_JNI(register_android_graphics_MaskFilter),
1143    REG_JNI(register_android_graphics_Matrix),
1144    REG_JNI(register_android_graphics_Movie),
1145    REG_JNI(register_android_graphics_NinePatch),
1146    REG_JNI(register_android_graphics_Paint),
1147    REG_JNI(register_android_graphics_Path),
1148    REG_JNI(register_android_graphics_PathMeasure),
1149    REG_JNI(register_android_graphics_PathEffect),
1150    REG_JNI(register_android_graphics_Picture),
1151    REG_JNI(register_android_graphics_PorterDuff),
1152    REG_JNI(register_android_graphics_Rasterizer),
1153    REG_JNI(register_android_graphics_Region),
1154    REG_JNI(register_android_graphics_Shader),
1155    REG_JNI(register_android_graphics_SurfaceTexture),
1156    REG_JNI(register_android_graphics_Typeface),
1157    REG_JNI(register_android_graphics_Xfermode),
1158    REG_JNI(register_android_graphics_YuvImage),
1159    REG_JNI(register_com_android_internal_graphics_NativeUtils),
1160
1161    REG_JNI(register_android_database_CursorWindow),
1162    REG_JNI(register_android_database_SQLiteCompiledSql),
1163    REG_JNI(register_android_database_SQLiteDatabase),
1164    REG_JNI(register_android_database_SQLiteDebug),
1165    REG_JNI(register_android_database_SQLiteProgram),
1166    REG_JNI(register_android_database_SQLiteQuery),
1167    REG_JNI(register_android_database_SQLiteStatement),
1168    REG_JNI(register_android_os_Debug),
1169    REG_JNI(register_android_os_FileObserver),
1170    REG_JNI(register_android_os_FileUtils),
1171    REG_JNI(register_android_os_MessageQueue),
1172    REG_JNI(register_android_os_ParcelFileDescriptor),
1173    REG_JNI(register_android_os_Power),
1174    REG_JNI(register_android_os_StatFs),
1175    REG_JNI(register_android_os_UEventObserver),
1176    REG_JNI(register_android_net_LocalSocketImpl),
1177    REG_JNI(register_android_net_NetworkUtils),
1178    REG_JNI(register_android_net_TrafficStats),
1179    REG_JNI(register_android_net_wifi_WifiManager),
1180    REG_JNI(register_android_nfc_NdefMessage),
1181    REG_JNI(register_android_nfc_NdefRecord),
1182    REG_JNI(register_android_os_MemoryFile),
1183    REG_JNI(register_com_android_internal_os_ZygoteInit),
1184    REG_JNI(register_android_hardware_Camera),
1185    REG_JNI(register_android_hardware_SensorManager),
1186    REG_JNI(register_android_hardware_UsbDevice),
1187    REG_JNI(register_android_hardware_UsbDeviceConnection),
1188    REG_JNI(register_android_hardware_UsbRequest),
1189    REG_JNI(register_android_media_AudioRecord),
1190    REG_JNI(register_android_media_AudioSystem),
1191    REG_JNI(register_android_media_AudioTrack),
1192    REG_JNI(register_android_media_JetPlayer),
1193    REG_JNI(register_android_media_ToneGenerator),
1194
1195    REG_JNI(register_android_opengl_classes),
1196    REG_JNI(register_android_bluetooth_HeadsetBase),
1197    REG_JNI(register_android_bluetooth_BluetoothAudioGateway),
1198    REG_JNI(register_android_bluetooth_BluetoothSocket),
1199    REG_JNI(register_android_server_BluetoothService),
1200    REG_JNI(register_android_server_BluetoothEventLoop),
1201    REG_JNI(register_android_server_BluetoothA2dpService),
1202    REG_JNI(register_android_server_Watchdog),
1203    REG_JNI(register_android_ddm_DdmHandleNativeHeap),
1204    REG_JNI(register_android_backup_BackupDataInput),
1205    REG_JNI(register_android_backup_BackupDataOutput),
1206    REG_JNI(register_android_backup_FileBackupHelperBase),
1207    REG_JNI(register_android_backup_BackupHelperDispatcher),
1208
1209    REG_JNI(register_android_app_ActivityThread),
1210    REG_JNI(register_android_app_NativeActivity),
1211    REG_JNI(register_android_view_InputChannel),
1212    REG_JNI(register_android_view_InputQueue),
1213    REG_JNI(register_android_view_KeyEvent),
1214    REG_JNI(register_android_view_MotionEvent),
1215    REG_JNI(register_android_view_VelocityTracker),
1216
1217    REG_JNI(register_android_content_res_ObbScanner),
1218    REG_JNI(register_android_content_res_Configuration),
1219
1220    REG_JNI(register_android_animation_PropertyValuesHolder),
1221};
1222
1223/*
1224 * Register android native functions with the VM.
1225 */
1226/*static*/ int AndroidRuntime::startReg(JNIEnv* env)
1227{
1228    /*
1229     * This hook causes all future threads created in this process to be
1230     * attached to the JavaVM.  (This needs to go away in favor of JNI
1231     * Attach calls.)
1232     */
1233    androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc);
1234
1235    LOGV("--- registering native functions ---\n");
1236
1237    /*
1238     * Every "register" function calls one or more things that return
1239     * a local reference (e.g. FindClass).  Because we haven't really
1240     * started the VM yet, they're all getting stored in the base frame
1241     * and never released.  Use Push/Pop to manage the storage.
1242     */
1243    env->PushLocalFrame(200);
1244
1245    if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) {
1246        env->PopLocalFrame(NULL);
1247        return -1;
1248    }
1249    env->PopLocalFrame(NULL);
1250
1251    //createJavaThread("fubar", quickTest, (void*) "hello");
1252
1253    return 0;
1254}
1255
1256AndroidRuntime* AndroidRuntime::getRuntime()
1257{
1258    return gCurRuntime;
1259}
1260
1261/**
1262 * Used by WithFramework to register native functions.
1263 */
1264extern "C"
1265jint Java_com_android_internal_util_WithFramework_registerNatives(
1266        JNIEnv* env, jclass clazz) {
1267    return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1268}
1269
1270/**
1271 * Used by LoadClass to register native functions.
1272 */
1273extern "C"
1274jint Java_LoadClass_registerNatives(JNIEnv* env, jclass clazz) {
1275    return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1276}
1277
1278}   // namespace android
1279