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