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