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