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