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