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