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