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