Home | History | Annotate | Download | only in jni
      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 
     48 using namespace android;
     49 
     50 extern int register_android_os_Binder(JNIEnv* env);
     51 extern int register_android_os_Process(JNIEnv* env);
     52 extern int register_android_graphics_Bitmap(JNIEnv*);
     53 extern int register_android_graphics_BitmapFactory(JNIEnv*);
     54 extern int register_android_graphics_BitmapRegionDecoder(JNIEnv*);
     55 extern int register_android_graphics_Camera(JNIEnv* env);
     56 extern int register_android_graphics_Graphics(JNIEnv* env);
     57 extern int register_android_graphics_Interpolator(JNIEnv* env);
     58 extern int register_android_graphics_LayerRasterizer(JNIEnv*);
     59 extern int register_android_graphics_MaskFilter(JNIEnv* env);
     60 extern int register_android_graphics_Movie(JNIEnv* env);
     61 extern int register_android_graphics_NinePatch(JNIEnv*);
     62 extern int register_android_graphics_PathEffect(JNIEnv* env);
     63 extern int register_android_graphics_Shader(JNIEnv* env);
     64 extern int register_android_graphics_Typeface(JNIEnv* env);
     65 extern int register_android_graphics_YuvImage(JNIEnv* env);
     66 
     67 extern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env);
     68 extern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env);
     69 extern int register_android_opengl_jni_EGL14(JNIEnv* env);
     70 extern int register_android_opengl_jni_EGLExt(JNIEnv* env);
     71 extern int register_android_opengl_jni_GLES10(JNIEnv* env);
     72 extern int register_android_opengl_jni_GLES10Ext(JNIEnv* env);
     73 extern int register_android_opengl_jni_GLES11(JNIEnv* env);
     74 extern int register_android_opengl_jni_GLES11Ext(JNIEnv* env);
     75 extern int register_android_opengl_jni_GLES20(JNIEnv* env);
     76 extern int register_android_opengl_jni_GLES30(JNIEnv* env);
     77 
     78 extern int register_android_hardware_Camera(JNIEnv *env);
     79 extern int register_android_hardware_SensorManager(JNIEnv *env);
     80 extern int register_android_hardware_SerialPort(JNIEnv *env);
     81 extern int register_android_hardware_UsbDevice(JNIEnv *env);
     82 extern int register_android_hardware_UsbDeviceConnection(JNIEnv *env);
     83 extern int register_android_hardware_UsbRequest(JNIEnv *env);
     84 
     85 extern int register_android_media_AudioRecord(JNIEnv *env);
     86 extern int register_android_media_AudioSystem(JNIEnv *env);
     87 extern int register_android_media_AudioTrack(JNIEnv *env);
     88 extern int register_android_media_JetPlayer(JNIEnv *env);
     89 extern int register_android_media_ToneGenerator(JNIEnv *env);
     90 
     91 extern int register_android_util_FloatMath(JNIEnv* env);
     92 
     93 namespace android {
     94 
     95 /*
     96  * JNI-based registration functions.  Note these are properly contained in
     97  * namespace android.
     98  */
     99 extern int register_android_content_AssetManager(JNIEnv* env);
    100 extern int register_android_util_EventLog(JNIEnv* env);
    101 extern int register_android_util_Log(JNIEnv* env);
    102 extern int register_android_content_StringBlock(JNIEnv* env);
    103 extern int register_android_content_XmlBlock(JNIEnv* env);
    104 extern int register_android_emoji_EmojiFactory(JNIEnv* env);
    105 extern int register_android_graphics_Canvas(JNIEnv* env);
    106 extern int register_android_graphics_ColorFilter(JNIEnv* env);
    107 extern int register_android_graphics_DrawFilter(JNIEnv* env);
    108 extern int register_android_graphics_Matrix(JNIEnv* env);
    109 extern int register_android_graphics_Paint(JNIEnv* env);
    110 extern int register_android_graphics_Path(JNIEnv* env);
    111 extern int register_android_graphics_PathMeasure(JNIEnv* env);
    112 extern int register_android_graphics_Picture(JNIEnv*);
    113 extern int register_android_graphics_PorterDuff(JNIEnv* env);
    114 extern int register_android_graphics_Rasterizer(JNIEnv* env);
    115 extern int register_android_graphics_Region(JNIEnv* env);
    116 extern int register_android_graphics_SurfaceTexture(JNIEnv* env);
    117 extern int register_android_graphics_Xfermode(JNIEnv* env);
    118 extern int register_android_graphics_PixelFormat(JNIEnv* env);
    119 extern int register_android_view_DisplayEventReceiver(JNIEnv* env);
    120 extern int register_android_view_GLES20DisplayList(JNIEnv* env);
    121 extern int register_android_view_GLES20Canvas(JNIEnv* env);
    122 extern int register_android_view_HardwareRenderer(JNIEnv* env);
    123 extern int register_android_view_Surface(JNIEnv* env);
    124 extern int register_android_view_SurfaceControl(JNIEnv* env);
    125 extern int register_android_view_SurfaceSession(JNIEnv* env);
    126 extern int register_android_view_TextureView(JNIEnv* env);
    127 extern int register_android_database_CursorWindow(JNIEnv* env);
    128 extern int register_android_database_SQLiteConnection(JNIEnv* env);
    129 extern int register_android_database_SQLiteGlobal(JNIEnv* env);
    130 extern int register_android_database_SQLiteDebug(JNIEnv* env);
    131 extern int register_android_debug_JNITest(JNIEnv* env);
    132 extern int register_android_nio_utils(JNIEnv* env);
    133 extern int register_android_text_format_Time(JNIEnv* env);
    134 extern int register_android_os_Debug(JNIEnv* env);
    135 extern int register_android_os_MessageQueue(JNIEnv* env);
    136 extern int register_android_os_Parcel(JNIEnv* env);
    137 extern int register_android_os_ParcelFileDescriptor(JNIEnv *env);
    138 extern int register_android_os_SELinux(JNIEnv* env);
    139 extern int register_android_os_SystemProperties(JNIEnv *env);
    140 extern int register_android_os_SystemClock(JNIEnv* env);
    141 extern int register_android_os_Trace(JNIEnv* env);
    142 extern int register_android_os_FileObserver(JNIEnv *env);
    143 extern int register_android_os_FileUtils(JNIEnv *env);
    144 extern int register_android_os_UEventObserver(JNIEnv* env);
    145 extern int register_android_os_MemoryFile(JNIEnv* env);
    146 extern int register_android_net_LocalSocketImpl(JNIEnv* env);
    147 extern int register_android_net_NetworkUtils(JNIEnv* env);
    148 extern int register_android_net_TrafficStats(JNIEnv* env);
    149 extern int register_android_net_wifi_WifiManager(JNIEnv* env);
    150 extern int register_android_text_AndroidCharacter(JNIEnv *env);
    151 extern int register_android_text_AndroidBidi(JNIEnv *env);
    152 extern int register_android_opengl_classes(JNIEnv *env);
    153 extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env);
    154 extern int register_android_server_Watchdog(JNIEnv* env);
    155 extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
    156 extern int register_com_android_internal_os_ZygoteInit(JNIEnv* env);
    157 extern int register_android_backup_BackupDataInput(JNIEnv *env);
    158 extern int register_android_backup_BackupDataOutput(JNIEnv *env);
    159 extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
    160 extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
    161 extern int register_android_app_backup_FullBackup(JNIEnv *env);
    162 extern int register_android_app_ActivityThread(JNIEnv *env);
    163 extern int register_android_app_NativeActivity(JNIEnv *env);
    164 extern int register_android_media_RemoteDisplay(JNIEnv *env);
    165 extern int register_android_view_InputChannel(JNIEnv* env);
    166 extern int register_android_view_InputDevice(JNIEnv* env);
    167 extern int register_android_view_InputEventReceiver(JNIEnv* env);
    168 extern int register_android_view_InputEventSender(JNIEnv* env);
    169 extern int register_android_view_InputQueue(JNIEnv* env);
    170 extern int register_android_view_KeyCharacterMap(JNIEnv *env);
    171 extern int register_android_view_KeyEvent(JNIEnv* env);
    172 extern int register_android_view_MotionEvent(JNIEnv* env);
    173 extern int register_android_view_PointerIcon(JNIEnv* env);
    174 extern int register_android_view_VelocityTracker(JNIEnv* env);
    175 extern int register_android_content_res_ObbScanner(JNIEnv* env);
    176 extern int register_android_content_res_Configuration(JNIEnv* env);
    177 extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
    178 extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
    179 extern int register_com_android_internal_net_NetworkStatsFactory(JNIEnv *env);
    180 
    181 static AndroidRuntime* gCurRuntime = NULL;
    182 
    183 static 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  */
    192 static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz)
    193 {
    194     gCurRuntime->onStarted();
    195 }
    196 
    197 static void com_android_internal_os_RuntimeInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
    198 {
    199     gCurRuntime->onZygoteInit();
    200 }
    201 
    202 static 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  */
    211 static 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 
    220 int 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 
    231 AndroidRuntime::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 
    253 AndroidRuntime::~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 
    267 status_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  */
    308 static 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  */
    318 static 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  */
    332 static 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  */
    343 int 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 
    363 static 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  */
    376 static 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  */
    389 static 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  */
    413 void 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  */
    447 int 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 heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
    461     char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
    462     char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
    463     char extraOptsBuf[PROPERTY_VALUE_MAX];
    464     char* stackTraceFile = NULL;
    465     bool checkJni = false;
    466     bool checkDexSum = false;
    467     bool logStdio = false;
    468     enum {
    469       kEMDefault,
    470       kEMIntPortable,
    471       kEMIntFast,
    472       kEMJitCompiler,
    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     } else if (strcmp(propBuf, "int:jit") == 0) {
    493         executionMode = kEMJitCompiler;
    494     }
    495 
    496     property_get("dalvik.vm.stack-trace-file", stackTraceFileBuf, "");
    497 
    498     property_get("dalvik.vm.check-dex-sum", propBuf, "");
    499     if (strcmp(propBuf, "true") == 0) {
    500         checkDexSum = true;
    501     }
    502 
    503     property_get("log.redirect-stdio", propBuf, "");
    504     if (strcmp(propBuf, "true") == 0) {
    505         logStdio = true;
    506     }
    507 
    508     strcpy(enableAssertBuf, "-ea:");
    509     property_get("dalvik.vm.enableassertions", enableAssertBuf+4, "");
    510 
    511     strcpy(jniOptsBuf, "-Xjniopts:");
    512     property_get("dalvik.vm.jniopts", jniOptsBuf+10, "");
    513 
    514     /* route exit() to our handler */
    515     opt.extraInfo = (void*) runtime_exit;
    516     opt.optionString = "exit";
    517     mOptions.add(opt);
    518 
    519     /* route fprintf() to our handler */
    520     opt.extraInfo = (void*) runtime_vfprintf;
    521     opt.optionString = "vfprintf";
    522     mOptions.add(opt);
    523 
    524     /* register the framework-specific "is sensitive thread" hook */
    525     opt.extraInfo = (void*) runtime_isSensitiveThread;
    526     opt.optionString = "sensitiveThread";
    527     mOptions.add(opt);
    528 
    529     opt.extraInfo = NULL;
    530 
    531     /* enable verbose; standard options are { jni, gc, class } */
    532     //options[curOpt++].optionString = "-verbose:jni";
    533     opt.optionString = "-verbose:gc";
    534     mOptions.add(opt);
    535     //options[curOpt++].optionString = "-verbose:class";
    536 
    537     /*
    538      * The default starting and maximum size of the heap.  Larger
    539      * values should be specified in a product property override.
    540      */
    541     strcpy(heapstartsizeOptsBuf, "-Xms");
    542     property_get("dalvik.vm.heapstartsize", heapstartsizeOptsBuf+4, "4m");
    543     opt.optionString = heapstartsizeOptsBuf;
    544     mOptions.add(opt);
    545     strcpy(heapsizeOptsBuf, "-Xmx");
    546     property_get("dalvik.vm.heapsize", heapsizeOptsBuf+4, "16m");
    547     opt.optionString = heapsizeOptsBuf;
    548     mOptions.add(opt);
    549 
    550     // Increase the main thread's interpreter stack size for bug 6315322.
    551     opt.optionString = "-XX:mainThreadStackSize=24K";
    552     mOptions.add(opt);
    553 
    554     strcpy(heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
    555     property_get("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf+20, "");
    556     if (heapgrowthlimitOptsBuf[20] != '\0') {
    557         opt.optionString = heapgrowthlimitOptsBuf;
    558         mOptions.add(opt);
    559     }
    560 
    561     strcpy(heapminfreeOptsBuf, "-XX:HeapMinFree=");
    562     property_get("dalvik.vm.heapminfree", heapminfreeOptsBuf+16, "");
    563     if (heapminfreeOptsBuf[16] != '\0') {
    564         opt.optionString = heapminfreeOptsBuf;
    565         mOptions.add(opt);
    566     }
    567 
    568     strcpy(heapmaxfreeOptsBuf, "-XX:HeapMaxFree=");
    569     property_get("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf+16, "");
    570     if (heapmaxfreeOptsBuf[16] != '\0') {
    571         opt.optionString = heapmaxfreeOptsBuf;
    572         mOptions.add(opt);
    573     }
    574 
    575     strcpy(heaptargetutilizationOptsBuf, "-XX:HeapTargetUtilization=");
    576     property_get("dalvik.vm.heaptargetutilization", heaptargetutilizationOptsBuf+26, "");
    577     if (heaptargetutilizationOptsBuf[26] != '\0') {
    578         opt.optionString = heaptargetutilizationOptsBuf;
    579         mOptions.add(opt);
    580     }
    581 
    582     /*
    583      * Enable or disable dexopt features, such as bytecode verification and
    584      * calculation of register maps for precise GC.
    585      */
    586     property_get("dalvik.vm.dexopt-flags", dexoptFlagsBuf, "");
    587     if (dexoptFlagsBuf[0] != '\0') {
    588         const char* opc;
    589         const char* val;
    590 
    591         opc = strstr(dexoptFlagsBuf, "v=");     /* verification */
    592         if (opc != NULL) {
    593             switch (*(opc+2)) {
    594             case 'n':   val = "-Xverify:none";      break;
    595             case 'r':   val = "-Xverify:remote";    break;
    596             case 'a':   val = "-Xverify:all";       break;
    597             default:    val = NULL;                 break;
    598             }
    599 
    600             if (val != NULL) {
    601                 opt.optionString = val;
    602                 mOptions.add(opt);
    603             }
    604         }
    605 
    606         opc = strstr(dexoptFlagsBuf, "o=");     /* optimization */
    607         if (opc != NULL) {
    608             switch (*(opc+2)) {
    609             case 'n':   val = "-Xdexopt:none";      break;
    610             case 'v':   val = "-Xdexopt:verified";  break;
    611             case 'a':   val = "-Xdexopt:all";       break;
    612             case 'f':   val = "-Xdexopt:full";      break;
    613             default:    val = NULL;                 break;
    614             }
    615 
    616             if (val != NULL) {
    617                 opt.optionString = val;
    618                 mOptions.add(opt);
    619             }
    620         }
    621 
    622         opc = strstr(dexoptFlagsBuf, "m=y");    /* register map */
    623         if (opc != NULL) {
    624             opt.optionString = "-Xgenregmap";
    625             mOptions.add(opt);
    626 
    627             /* turn on precise GC while we're at it */
    628             opt.optionString = "-Xgc:precise";
    629             mOptions.add(opt);
    630         }
    631     }
    632 
    633     /* enable debugging; set suspend=y to pause during VM init */
    634     /* use android ADB transport */
    635     opt.optionString =
    636         "-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y";
    637     mOptions.add(opt);
    638 
    639     ALOGD("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
    640     if (checkJni) {
    641         /* extended JNI checking */
    642         opt.optionString = "-Xcheck:jni";
    643         mOptions.add(opt);
    644 
    645         /* set a cap on JNI global references */
    646         opt.optionString = "-Xjnigreflimit:2000";
    647         mOptions.add(opt);
    648 
    649         /* with -Xcheck:jni, this provides a JNI function call trace */
    650         //opt.optionString = "-verbose:jni";
    651         //mOptions.add(opt);
    652     }
    653 
    654     char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:") + sizeof(propBuf)];
    655     property_get("dalvik.vm.lockprof.threshold", propBuf, "");
    656     if (strlen(propBuf) > 0) {
    657       strcpy(lockProfThresholdBuf, "-Xlockprofthreshold:");
    658       strcat(lockProfThresholdBuf, propBuf);
    659       opt.optionString = lockProfThresholdBuf;
    660       mOptions.add(opt);
    661     }
    662 
    663     /* Force interpreter-only mode for selected opcodes. Eg "1-0a,3c,f1-ff" */
    664     char jitOpBuf[sizeof("-Xjitop:") + PROPERTY_VALUE_MAX];
    665     property_get("dalvik.vm.jit.op", propBuf, "");
    666     if (strlen(propBuf) > 0) {
    667         strcpy(jitOpBuf, "-Xjitop:");
    668         strcat(jitOpBuf, propBuf);
    669         opt.optionString = jitOpBuf;
    670         mOptions.add(opt);
    671     }
    672 
    673     /* Force interpreter-only mode for selected methods */
    674     char jitMethodBuf[sizeof("-Xjitmethod:") + PROPERTY_VALUE_MAX];
    675     property_get("dalvik.vm.jit.method", propBuf, "");
    676     if (strlen(propBuf) > 0) {
    677         strcpy(jitMethodBuf, "-Xjitmethod:");
    678         strcat(jitMethodBuf, propBuf);
    679         opt.optionString = jitMethodBuf;
    680         mOptions.add(opt);
    681     }
    682 
    683     if (executionMode == kEMIntPortable) {
    684         opt.optionString = "-Xint:portable";
    685         mOptions.add(opt);
    686     } else if (executionMode == kEMIntFast) {
    687         opt.optionString = "-Xint:fast";
    688         mOptions.add(opt);
    689     } else if (executionMode == kEMJitCompiler) {
    690         opt.optionString = "-Xint:jit";
    691         mOptions.add(opt);
    692     }
    693 
    694     if (checkDexSum) {
    695         /* perform additional DEX checksum tests */
    696         opt.optionString = "-Xcheckdexsum";
    697         mOptions.add(opt);
    698     }
    699 
    700     if (logStdio) {
    701         /* convert stdout/stderr to log messages */
    702         opt.optionString = "-Xlog-stdio";
    703         mOptions.add(opt);
    704     }
    705 
    706     if (enableAssertBuf[4] != '\0') {
    707         /* accept "all" to mean "all classes and packages" */
    708         if (strcmp(enableAssertBuf+4, "all") == 0)
    709             enableAssertBuf[3] = '\0';
    710         ALOGI("Assertions enabled: '%s'\n", enableAssertBuf);
    711         opt.optionString = enableAssertBuf;
    712         mOptions.add(opt);
    713     } else {
    714         ALOGV("Assertions disabled\n");
    715     }
    716 
    717     if (jniOptsBuf[10] != '\0') {
    718         ALOGI("JNI options: '%s'\n", jniOptsBuf);
    719         opt.optionString = jniOptsBuf;
    720         mOptions.add(opt);
    721     }
    722 
    723     if (stackTraceFileBuf[0] != '\0') {
    724         static const char* stfOptName = "-Xstacktracefile:";
    725 
    726         stackTraceFile = (char*) malloc(strlen(stfOptName) +
    727             strlen(stackTraceFileBuf) +1);
    728         strcpy(stackTraceFile, stfOptName);
    729         strcat(stackTraceFile, stackTraceFileBuf);
    730         opt.optionString = stackTraceFile;
    731         mOptions.add(opt);
    732     }
    733 
    734     /* extra options; parse this late so it overrides others */
    735     property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
    736     parseExtraOpts(extraOptsBuf);
    737 
    738     /* Set the properties for locale */
    739     {
    740         char langOption[sizeof("-Duser.language=") + 3];
    741         char regionOption[sizeof("-Duser.region=") + 3];
    742         strcpy(langOption, "-Duser.language=");
    743         strcpy(regionOption, "-Duser.region=");
    744         readLocale(langOption, regionOption);
    745         opt.extraInfo = NULL;
    746         opt.optionString = langOption;
    747         mOptions.add(opt);
    748         opt.optionString = regionOption;
    749         mOptions.add(opt);
    750     }
    751 
    752     /*
    753      * We don't have /tmp on the device, but we often have an SD card.  Apps
    754      * shouldn't use this, but some test suites might want to exercise it.
    755      */
    756     opt.optionString = "-Djava.io.tmpdir=/sdcard";
    757     mOptions.add(opt);
    758 
    759     initArgs.version = JNI_VERSION_1_4;
    760     initArgs.options = mOptions.editArray();
    761     initArgs.nOptions = mOptions.size();
    762     initArgs.ignoreUnrecognized = JNI_FALSE;
    763 
    764     /*
    765      * Initialize the VM.
    766      *
    767      * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread.
    768      * If this call succeeds, the VM is ready, and we can start issuing
    769      * JNI calls.
    770      */
    771     if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) {
    772         ALOGE("JNI_CreateJavaVM failed\n");
    773         goto bail;
    774     }
    775 
    776     result = 0;
    777 
    778 bail:
    779     free(stackTraceFile);
    780     return result;
    781 }
    782 
    783 char* AndroidRuntime::toSlashClassName(const char* className)
    784 {
    785     char* result = strdup(className);
    786     for (char* cp = result; *cp != '\0'; cp++) {
    787         if (*cp == '.') {
    788             *cp = '/';
    789         }
    790     }
    791     return result;
    792 }
    793 
    794 /*
    795  * Start the Android runtime.  This involves starting the virtual machine
    796  * and calling the "static void main(String[] args)" method in the class
    797  * named by "className".
    798  *
    799  * Passes the main function two arguments, the class name and the specified
    800  * options string.
    801  */
    802 void AndroidRuntime::start(const char* className, const char* options)
    803 {
    804     ALOGD("\n>>>>>> AndroidRuntime START %s <<<<<<\n",
    805             className != NULL ? className : "(unknown)");
    806 
    807     blockSigpipe();
    808 
    809     /*
    810      * 'startSystemServer == true' means runtime is obsolete and not run from
    811      * init.rc anymore, so we print out the boot start event here.
    812      */
    813     if (strcmp(options, "start-system-server") == 0) {
    814         /* track our progress through the boot sequence */
    815         const int LOG_BOOT_PROGRESS_START = 3000;
    816         LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START,
    817                        ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));
    818     }
    819 
    820     const char* rootDir = getenv("ANDROID_ROOT");
    821     if (rootDir == NULL) {
    822         rootDir = "/system";
    823         if (!hasDir("/system")) {
    824             LOG_FATAL("No root directory specified, and /android does not exist.");
    825             return;
    826         }
    827         setenv("ANDROID_ROOT", rootDir, 1);
    828     }
    829 
    830     //const char* kernelHack = getenv("LD_ASSUME_KERNEL");
    831     //ALOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack);
    832 
    833     /* start the virtual machine */
    834     JNIEnv* env;
    835     if (startVm(&mJavaVM, &env) != 0) {
    836         return;
    837     }
    838     onVmCreated(env);
    839 
    840     /*
    841      * Register android functions.
    842      */
    843     if (startReg(env) < 0) {
    844         ALOGE("Unable to register all android natives\n");
    845         return;
    846     }
    847 
    848     /*
    849      * We want to call main() with a String array with arguments in it.
    850      * At present we have two arguments, the class name and an option string.
    851      * Create an array to hold them.
    852      */
    853     jclass stringClass;
    854     jobjectArray strArray;
    855     jstring classNameStr;
    856     jstring optionsStr;
    857 
    858     stringClass = env->FindClass("java/lang/String");
    859     assert(stringClass != NULL);
    860     strArray = env->NewObjectArray(2, stringClass, NULL);
    861     assert(strArray != NULL);
    862     classNameStr = env->NewStringUTF(className);
    863     assert(classNameStr != NULL);
    864     env->SetObjectArrayElement(strArray, 0, classNameStr);
    865     optionsStr = env->NewStringUTF(options);
    866     env->SetObjectArrayElement(strArray, 1, optionsStr);
    867 
    868     /*
    869      * Start VM.  This thread becomes the main thread of the VM, and will
    870      * not return until the VM exits.
    871      */
    872     char* slashClassName = toSlashClassName(className);
    873     jclass startClass = env->FindClass(slashClassName);
    874     if (startClass == NULL) {
    875         ALOGE("JavaVM unable to locate class '%s'\n", slashClassName);
    876         /* keep going */
    877     } else {
    878         jmethodID startMeth = env->GetStaticMethodID(startClass, "main",
    879             "([Ljava/lang/String;)V");
    880         if (startMeth == NULL) {
    881             ALOGE("JavaVM unable to find main() in '%s'\n", className);
    882             /* keep going */
    883         } else {
    884             env->CallStaticVoidMethod(startClass, startMeth, strArray);
    885 
    886 #if 0
    887             if (env->ExceptionCheck())
    888                 threadExitUncaughtException(env);
    889 #endif
    890         }
    891     }
    892     free(slashClassName);
    893 
    894     ALOGD("Shutting down VM\n");
    895     if (mJavaVM->DetachCurrentThread() != JNI_OK)
    896         ALOGW("Warning: unable to detach main thread\n");
    897     if (mJavaVM->DestroyJavaVM() != 0)
    898         ALOGW("Warning: VM did not shut down cleanly\n");
    899 }
    900 
    901 void AndroidRuntime::exit(int code)
    902 {
    903     if (mExitWithoutCleanup) {
    904         ALOGI("VM exiting with result code %d, cleanup skipped.", code);
    905         ::_exit(code);
    906     } else {
    907         ALOGI("VM exiting with result code %d.", code);
    908         onExit(code);
    909         ::exit(code);
    910     }
    911 }
    912 
    913 void AndroidRuntime::onVmCreated(JNIEnv* env)
    914 {
    915     // If AndroidRuntime had anything to do here, we'd have done it in 'start'.
    916 }
    917 
    918 /*
    919  * Get the JNIEnv pointer for this thread.
    920  *
    921  * Returns NULL if the slot wasn't allocated or populated.
    922  */
    923 /*static*/ JNIEnv* AndroidRuntime::getJNIEnv()
    924 {
    925     JNIEnv* env;
    926     JavaVM* vm = AndroidRuntime::getJavaVM();
    927     assert(vm != NULL);
    928 
    929     if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
    930         return NULL;
    931     return env;
    932 }
    933 
    934 /*
    935  * Makes the current thread visible to the VM.
    936  *
    937  * The JNIEnv pointer returned is only valid for the current thread, and
    938  * thus must be tucked into thread-local storage.
    939  */
    940 static int javaAttachThread(const char* threadName, JNIEnv** pEnv)
    941 {
    942     JavaVMAttachArgs args;
    943     JavaVM* vm;
    944     jint result;
    945 
    946     vm = AndroidRuntime::getJavaVM();
    947     assert(vm != NULL);
    948 
    949     args.version = JNI_VERSION_1_4;
    950     args.name = (char*) threadName;
    951     args.group = NULL;
    952 
    953     result = vm->AttachCurrentThread(pEnv, (void*) &args);
    954     if (result != JNI_OK)
    955         ALOGI("NOTE: attach of thread '%s' failed\n", threadName);
    956 
    957     return result;
    958 }
    959 
    960 /*
    961  * Detach the current thread from the set visible to the VM.
    962  */
    963 static int javaDetachThread(void)
    964 {
    965     JavaVM* vm;
    966     jint result;
    967 
    968     vm = AndroidRuntime::getJavaVM();
    969     assert(vm != NULL);
    970 
    971     result = vm->DetachCurrentThread();
    972     if (result != JNI_OK)
    973         ALOGE("ERROR: thread detach failed\n");
    974     return result;
    975 }
    976 
    977 /*
    978  * When starting a native thread that will be visible from the VM, we
    979  * bounce through this to get the right attach/detach action.
    980  * Note that this function calls free(args)
    981  */
    982 /*static*/ int AndroidRuntime::javaThreadShell(void* args) {
    983     void* start = ((void**)args)[0];
    984     void* userData = ((void **)args)[1];
    985     char* name = (char*) ((void **)args)[2];        // we own this storage
    986     free(args);
    987     JNIEnv* env;
    988     int result;
    989 
    990     /* hook us into the VM */
    991     if (javaAttachThread(name, &env) != JNI_OK)
    992         return -1;
    993 
    994     /* start the thread running */
    995     result = (*(android_thread_func_t)start)(userData);
    996 
    997     /* unhook us */
    998     javaDetachThread();
    999     free(name);
   1000 
   1001     return result;
   1002 }
   1003 
   1004 /*
   1005  * This is invoked from androidCreateThreadEtc() via the callback
   1006  * set with androidSetCreateThreadFunc().
   1007  *
   1008  * We need to create the new thread in such a way that it gets hooked
   1009  * into the VM before it really starts executing.
   1010  */
   1011 /*static*/ int AndroidRuntime::javaCreateThreadEtc(
   1012                                 android_thread_func_t entryFunction,
   1013                                 void* userData,
   1014                                 const char* threadName,
   1015                                 int32_t threadPriority,
   1016                                 size_t threadStackSize,
   1017                                 android_thread_id_t* threadId)
   1018 {
   1019     void** args = (void**) malloc(3 * sizeof(void*));   // javaThreadShell must free
   1020     int result;
   1021 
   1022     assert(threadName != NULL);
   1023 
   1024     args[0] = (void*) entryFunction;
   1025     args[1] = userData;
   1026     args[2] = (void*) strdup(threadName);   // javaThreadShell must free
   1027 
   1028     result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args,
   1029         threadName, threadPriority, threadStackSize, threadId);
   1030     return result;
   1031 }
   1032 
   1033 /*
   1034  * Create a thread that is visible from the VM.
   1035  *
   1036  * This is called from elsewhere in the library.
   1037  */
   1038 /*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name,
   1039     void (*start)(void *), void* arg)
   1040 {
   1041     android_thread_id_t threadId = 0;
   1042     javaCreateThreadEtc((android_thread_func_t) start, arg, name,
   1043         ANDROID_PRIORITY_DEFAULT, 0, &threadId);
   1044     return threadId;
   1045 }
   1046 
   1047 #if 0
   1048 static void quickTest(void* arg)
   1049 {
   1050     const char* str = (const char*) arg;
   1051 
   1052     printf("In quickTest: %s\n", str);
   1053 }
   1054 #endif
   1055 
   1056 #ifdef NDEBUG
   1057     #define REG_JNI(name)      { name }
   1058     struct RegJNIRec {
   1059         int (*mProc)(JNIEnv*);
   1060     };
   1061 #else
   1062     #define REG_JNI(name)      { name, #name }
   1063     struct RegJNIRec {
   1064         int (*mProc)(JNIEnv*);
   1065         const char* mName;
   1066     };
   1067 #endif
   1068 
   1069 typedef void (*RegJAMProc)();
   1070 
   1071 static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env)
   1072 {
   1073     for (size_t i = 0; i < count; i++) {
   1074         if (array[i].mProc(env) < 0) {
   1075 #ifndef NDEBUG
   1076             ALOGD("----------!!! %s failed to load\n", array[i].mName);
   1077 #endif
   1078             return -1;
   1079         }
   1080     }
   1081     return 0;
   1082 }
   1083 
   1084 static void register_jam_procs(const RegJAMProc array[], size_t count)
   1085 {
   1086     for (size_t i = 0; i < count; i++) {
   1087         array[i]();
   1088     }
   1089 }
   1090 
   1091 static const RegJNIRec gRegJNI[] = {
   1092     REG_JNI(register_android_debug_JNITest),
   1093     REG_JNI(register_com_android_internal_os_RuntimeInit),
   1094     REG_JNI(register_android_os_SystemClock),
   1095     REG_JNI(register_android_util_EventLog),
   1096     REG_JNI(register_android_util_Log),
   1097     REG_JNI(register_android_util_FloatMath),
   1098     REG_JNI(register_android_text_format_Time),
   1099     REG_JNI(register_android_content_AssetManager),
   1100     REG_JNI(register_android_content_StringBlock),
   1101     REG_JNI(register_android_content_XmlBlock),
   1102     REG_JNI(register_android_emoji_EmojiFactory),
   1103     REG_JNI(register_android_text_AndroidCharacter),
   1104     REG_JNI(register_android_text_AndroidBidi),
   1105     REG_JNI(register_android_view_InputDevice),
   1106     REG_JNI(register_android_view_KeyCharacterMap),
   1107     REG_JNI(register_android_os_Process),
   1108     REG_JNI(register_android_os_SystemProperties),
   1109     REG_JNI(register_android_os_Binder),
   1110     REG_JNI(register_android_os_Parcel),
   1111     REG_JNI(register_android_view_DisplayEventReceiver),
   1112     REG_JNI(register_android_nio_utils),
   1113     REG_JNI(register_android_graphics_PixelFormat),
   1114     REG_JNI(register_android_graphics_Graphics),
   1115     REG_JNI(register_android_view_GLES20DisplayList),
   1116     REG_JNI(register_android_view_GLES20Canvas),
   1117     REG_JNI(register_android_view_HardwareRenderer),
   1118     REG_JNI(register_android_view_Surface),
   1119     REG_JNI(register_android_view_SurfaceControl),
   1120     REG_JNI(register_android_view_SurfaceSession),
   1121     REG_JNI(register_android_view_TextureView),
   1122     REG_JNI(register_com_google_android_gles_jni_EGLImpl),
   1123     REG_JNI(register_com_google_android_gles_jni_GLImpl),
   1124     REG_JNI(register_android_opengl_jni_EGL14),
   1125     REG_JNI(register_android_opengl_jni_EGLExt),
   1126     REG_JNI(register_android_opengl_jni_GLES10),
   1127     REG_JNI(register_android_opengl_jni_GLES10Ext),
   1128     REG_JNI(register_android_opengl_jni_GLES11),
   1129     REG_JNI(register_android_opengl_jni_GLES11Ext),
   1130     REG_JNI(register_android_opengl_jni_GLES20),
   1131     REG_JNI(register_android_opengl_jni_GLES30),
   1132 
   1133     REG_JNI(register_android_graphics_Bitmap),
   1134     REG_JNI(register_android_graphics_BitmapFactory),
   1135     REG_JNI(register_android_graphics_BitmapRegionDecoder),
   1136     REG_JNI(register_android_graphics_Camera),
   1137     REG_JNI(register_android_graphics_Canvas),
   1138     REG_JNI(register_android_graphics_ColorFilter),
   1139     REG_JNI(register_android_graphics_DrawFilter),
   1140     REG_JNI(register_android_graphics_Interpolator),
   1141     REG_JNI(register_android_graphics_LayerRasterizer),
   1142     REG_JNI(register_android_graphics_MaskFilter),
   1143     REG_JNI(register_android_graphics_Matrix),
   1144     REG_JNI(register_android_graphics_Movie),
   1145     REG_JNI(register_android_graphics_NinePatch),
   1146     REG_JNI(register_android_graphics_Paint),
   1147     REG_JNI(register_android_graphics_Path),
   1148     REG_JNI(register_android_graphics_PathMeasure),
   1149     REG_JNI(register_android_graphics_PathEffect),
   1150     REG_JNI(register_android_graphics_Picture),
   1151     REG_JNI(register_android_graphics_PorterDuff),
   1152     REG_JNI(register_android_graphics_Rasterizer),
   1153     REG_JNI(register_android_graphics_Region),
   1154     REG_JNI(register_android_graphics_Shader),
   1155     REG_JNI(register_android_graphics_SurfaceTexture),
   1156     REG_JNI(register_android_graphics_Typeface),
   1157     REG_JNI(register_android_graphics_Xfermode),
   1158     REG_JNI(register_android_graphics_YuvImage),
   1159 
   1160     REG_JNI(register_android_database_CursorWindow),
   1161     REG_JNI(register_android_database_SQLiteConnection),
   1162     REG_JNI(register_android_database_SQLiteGlobal),
   1163     REG_JNI(register_android_database_SQLiteDebug),
   1164     REG_JNI(register_android_os_Debug),
   1165     REG_JNI(register_android_os_FileObserver),
   1166     REG_JNI(register_android_os_FileUtils),
   1167     REG_JNI(register_android_os_MessageQueue),
   1168     REG_JNI(register_android_os_ParcelFileDescriptor),
   1169     REG_JNI(register_android_os_SELinux),
   1170     REG_JNI(register_android_os_Trace),
   1171     REG_JNI(register_android_os_UEventObserver),
   1172     REG_JNI(register_android_net_LocalSocketImpl),
   1173     REG_JNI(register_android_net_NetworkUtils),
   1174     REG_JNI(register_android_net_TrafficStats),
   1175     REG_JNI(register_android_net_wifi_WifiManager),
   1176     REG_JNI(register_android_os_MemoryFile),
   1177     REG_JNI(register_com_android_internal_os_ZygoteInit),
   1178     REG_JNI(register_android_hardware_Camera),
   1179     REG_JNI(register_android_hardware_SensorManager),
   1180     REG_JNI(register_android_hardware_SerialPort),
   1181     REG_JNI(register_android_hardware_UsbDevice),
   1182     REG_JNI(register_android_hardware_UsbDeviceConnection),
   1183     REG_JNI(register_android_hardware_UsbRequest),
   1184     REG_JNI(register_android_media_AudioRecord),
   1185     REG_JNI(register_android_media_AudioSystem),
   1186     REG_JNI(register_android_media_AudioTrack),
   1187     REG_JNI(register_android_media_JetPlayer),
   1188     REG_JNI(register_android_media_RemoteDisplay),
   1189     REG_JNI(register_android_media_ToneGenerator),
   1190 
   1191     REG_JNI(register_android_opengl_classes),
   1192     REG_JNI(register_android_server_NetworkManagementSocketTagger),
   1193     REG_JNI(register_android_server_Watchdog),
   1194     REG_JNI(register_android_ddm_DdmHandleNativeHeap),
   1195     REG_JNI(register_android_backup_BackupDataInput),
   1196     REG_JNI(register_android_backup_BackupDataOutput),
   1197     REG_JNI(register_android_backup_FileBackupHelperBase),
   1198     REG_JNI(register_android_backup_BackupHelperDispatcher),
   1199     REG_JNI(register_android_app_backup_FullBackup),
   1200     REG_JNI(register_android_app_ActivityThread),
   1201     REG_JNI(register_android_app_NativeActivity),
   1202     REG_JNI(register_android_view_InputChannel),
   1203     REG_JNI(register_android_view_InputEventReceiver),
   1204     REG_JNI(register_android_view_InputEventSender),
   1205     REG_JNI(register_android_view_InputQueue),
   1206     REG_JNI(register_android_view_KeyEvent),
   1207     REG_JNI(register_android_view_MotionEvent),
   1208     REG_JNI(register_android_view_PointerIcon),
   1209     REG_JNI(register_android_view_VelocityTracker),
   1210 
   1211     REG_JNI(register_android_content_res_ObbScanner),
   1212     REG_JNI(register_android_content_res_Configuration),
   1213 
   1214     REG_JNI(register_android_animation_PropertyValuesHolder),
   1215     REG_JNI(register_com_android_internal_content_NativeLibraryHelper),
   1216     REG_JNI(register_com_android_internal_net_NetworkStatsFactory),
   1217 };
   1218 
   1219 /*
   1220  * Register android native functions with the VM.
   1221  */
   1222 /*static*/ int AndroidRuntime::startReg(JNIEnv* env)
   1223 {
   1224     /*
   1225      * This hook causes all future threads created in this process to be
   1226      * attached to the JavaVM.  (This needs to go away in favor of JNI
   1227      * Attach calls.)
   1228      */
   1229     androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc);
   1230 
   1231     ALOGV("--- registering native functions ---\n");
   1232 
   1233     /*
   1234      * Every "register" function calls one or more things that return
   1235      * a local reference (e.g. FindClass).  Because we haven't really
   1236      * started the VM yet, they're all getting stored in the base frame
   1237      * and never released.  Use Push/Pop to manage the storage.
   1238      */
   1239     env->PushLocalFrame(200);
   1240 
   1241     if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) {
   1242         env->PopLocalFrame(NULL);
   1243         return -1;
   1244     }
   1245     env->PopLocalFrame(NULL);
   1246 
   1247     //createJavaThread("fubar", quickTest, (void*) "hello");
   1248 
   1249     return 0;
   1250 }
   1251 
   1252 AndroidRuntime* AndroidRuntime::getRuntime()
   1253 {
   1254     return gCurRuntime;
   1255 }
   1256 
   1257 /**
   1258  * Used by WithFramework to register native functions.
   1259  */
   1260 extern "C"
   1261 jint Java_com_android_internal_util_WithFramework_registerNatives(
   1262         JNIEnv* env, jclass clazz) {
   1263     return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
   1264 }
   1265 
   1266 /**
   1267  * Used by LoadClass to register native functions.
   1268  */
   1269 extern "C"
   1270 jint Java_LoadClass_registerNatives(JNIEnv* env, jclass clazz) {
   1271     return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
   1272 }
   1273 
   1274 }   // namespace android
   1275