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