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