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