AndroidRuntime.cpp revision dafbf247ee4d0c14d501a23612115ab3a1306288
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_ParcelSurfaceTexture(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_GLES20Canvas(JNIEnv* env); 120extern int register_android_view_Surface(JNIEnv* env); 121extern int register_android_view_TextureView(JNIEnv* env); 122extern int register_android_database_CursorWindow(JNIEnv* env); 123extern int register_android_database_SQLiteCompiledSql(JNIEnv* env); 124extern int register_android_database_SQLiteDatabase(JNIEnv* env); 125extern int register_android_database_SQLiteDebug(JNIEnv* env); 126extern int register_android_database_SQLiteProgram(JNIEnv* env); 127extern int register_android_database_SQLiteQuery(JNIEnv* env); 128extern int register_android_database_SQLiteStatement(JNIEnv* env); 129extern int register_android_debug_JNITest(JNIEnv* env); 130extern int register_android_nio_utils(JNIEnv* env); 131extern int register_android_nfc_NdefMessage(JNIEnv *env); 132extern int register_android_nfc_NdefRecord(JNIEnv *env); 133extern int register_android_text_format_Time(JNIEnv* env); 134extern int register_android_os_Debug(JNIEnv* env); 135extern int register_android_os_MessageQueue(JNIEnv* env); 136extern int register_android_os_ParcelFileDescriptor(JNIEnv *env); 137extern int register_android_os_Power(JNIEnv *env); 138extern int register_android_os_StatFs(JNIEnv *env); 139extern int register_android_os_SystemProperties(JNIEnv *env); 140extern int register_android_os_SystemClock(JNIEnv* env); 141extern int register_android_os_FileObserver(JNIEnv *env); 142extern int register_android_os_FileUtils(JNIEnv *env); 143extern int register_android_os_UEventObserver(JNIEnv* env); 144extern int register_android_os_MemoryFile(JNIEnv* env); 145extern int register_android_net_LocalSocketImpl(JNIEnv* env); 146extern int register_android_net_NetworkUtils(JNIEnv* env); 147extern int register_android_net_TrafficStats(JNIEnv* env); 148extern int register_android_net_wifi_WifiManager(JNIEnv* env); 149extern int register_android_text_AndroidCharacter(JNIEnv *env); 150extern int register_android_text_AndroidBidi(JNIEnv *env); 151extern int register_android_text_KeyCharacterMap(JNIEnv *env); 152extern int register_android_opengl_classes(JNIEnv *env); 153extern int register_android_bluetooth_HeadsetBase(JNIEnv* env); 154extern int register_android_bluetooth_BluetoothAudioGateway(JNIEnv* env); 155extern int register_android_bluetooth_BluetoothSocket(JNIEnv *env); 156extern int register_android_server_BluetoothService(JNIEnv* env); 157extern int register_android_server_BluetoothEventLoop(JNIEnv *env); 158extern int register_android_server_BluetoothA2dpService(JNIEnv* env); 159extern int register_android_server_Watchdog(JNIEnv* env); 160extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env); 161extern int register_com_android_internal_os_ZygoteInit(JNIEnv* env); 162extern int register_android_backup_BackupDataInput(JNIEnv *env); 163extern int register_android_backup_BackupDataOutput(JNIEnv *env); 164extern int register_android_backup_FileBackupHelperBase(JNIEnv *env); 165extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env); 166extern int register_android_app_backup_FullBackup(JNIEnv *env); 167extern int register_android_app_ActivityThread(JNIEnv *env); 168extern int register_android_app_NativeActivity(JNIEnv *env); 169extern int register_android_view_InputChannel(JNIEnv* env); 170extern int register_android_view_InputQueue(JNIEnv* env); 171extern int register_android_view_KeyEvent(JNIEnv* env); 172extern int register_android_view_MotionEvent(JNIEnv* env); 173extern int register_android_view_PointerIcon(JNIEnv* env); 174extern int register_android_view_VelocityTracker(JNIEnv* env); 175extern int register_android_content_res_ObbScanner(JNIEnv* env); 176extern int register_android_content_res_Configuration(JNIEnv* env); 177extern int register_android_animation_PropertyValuesHolder(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 LOGD("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 LOGE("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 LOGW("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 //LOGD("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 char enableDPBuf[sizeof("-Xdeadlockpredict:") + PROPERTY_VALUE_MAX]; 631 property_get("dalvik.vm.deadlock-predict", propBuf, ""); 632 if (strlen(propBuf) > 0) { 633 strcpy(enableDPBuf, "-Xdeadlockpredict:"); 634 strcat(enableDPBuf, propBuf); 635 opt.optionString = enableDPBuf; 636 mOptions.add(opt); 637 } 638 639 LOGD("CheckJNI is %s\n", checkJni ? "ON" : "OFF"); 640 if (checkJni) { 641 /* extended JNI checking */ 642 opt.optionString = "-Xcheck:jni"; 643 mOptions.add(opt); 644 645 /* set a cap on JNI global references */ 646 opt.optionString = "-Xjnigreflimit:2000"; 647 mOptions.add(opt); 648 649 /* with -Xcheck:jni, this provides a JNI function call trace */ 650 //opt.optionString = "-verbose:jni"; 651 //mOptions.add(opt); 652 } 653 654 char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:") + sizeof(propBuf)]; 655 property_get("dalvik.vm.lockprof.threshold", propBuf, ""); 656 if (strlen(propBuf) > 0) { 657 strcpy(lockProfThresholdBuf, "-Xlockprofthreshold:"); 658 strcat(lockProfThresholdBuf, propBuf); 659 opt.optionString = lockProfThresholdBuf; 660 mOptions.add(opt); 661 } 662 663#if defined(WITH_JIT) 664 /* Force interpreter-only mode for selected opcodes. Eg "1-0a,3c,f1-ff" */ 665 char jitOpBuf[sizeof("-Xjitop:") + PROPERTY_VALUE_MAX]; 666 property_get("dalvik.vm.jit.op", propBuf, ""); 667 if (strlen(propBuf) > 0) { 668 strcpy(jitOpBuf, "-Xjitop:"); 669 strcat(jitOpBuf, propBuf); 670 opt.optionString = jitOpBuf; 671 mOptions.add(opt); 672 } 673 674 /* Force interpreter-only mode for selected methods */ 675 char jitMethodBuf[sizeof("-Xjitmethod:") + PROPERTY_VALUE_MAX]; 676 property_get("dalvik.vm.jit.method", propBuf, ""); 677 if (strlen(propBuf) > 0) { 678 strcpy(jitMethodBuf, "-Xjitmethod:"); 679 strcat(jitMethodBuf, propBuf); 680 opt.optionString = jitMethodBuf; 681 mOptions.add(opt); 682 } 683#endif 684 685 if (executionMode == kEMIntPortable) { 686 opt.optionString = "-Xint:portable"; 687 mOptions.add(opt); 688 } else if (executionMode == kEMIntFast) { 689 opt.optionString = "-Xint:fast"; 690 mOptions.add(opt); 691#if defined(WITH_JIT) 692 } else if (executionMode == kEMJitCompiler) { 693 opt.optionString = "-Xint:jit"; 694 mOptions.add(opt); 695#endif 696 } 697 698 if (checkDexSum) { 699 /* perform additional DEX checksum tests */ 700 opt.optionString = "-Xcheckdexsum"; 701 mOptions.add(opt); 702 } 703 704 if (logStdio) { 705 /* convert stdout/stderr to log messages */ 706 opt.optionString = "-Xlog-stdio"; 707 mOptions.add(opt); 708 } 709 710 if (enableAssertBuf[4] != '\0') { 711 /* accept "all" to mean "all classes and packages" */ 712 if (strcmp(enableAssertBuf+4, "all") == 0) 713 enableAssertBuf[3] = '\0'; 714 LOGI("Assertions enabled: '%s'\n", enableAssertBuf); 715 opt.optionString = enableAssertBuf; 716 mOptions.add(opt); 717 } else { 718 LOGV("Assertions disabled\n"); 719 } 720 721 if (jniOptsBuf[10] != '\0') { 722 LOGI("JNI options: '%s'\n", jniOptsBuf); 723 opt.optionString = jniOptsBuf; 724 mOptions.add(opt); 725 } 726 727 if (stackTraceFileBuf[0] != '\0') { 728 static const char* stfOptName = "-Xstacktracefile:"; 729 730 stackTraceFile = (char*) malloc(strlen(stfOptName) + 731 strlen(stackTraceFileBuf) +1); 732 strcpy(stackTraceFile, stfOptName); 733 strcat(stackTraceFile, stackTraceFileBuf); 734 opt.optionString = stackTraceFile; 735 mOptions.add(opt); 736 } 737 738 /* extra options; parse this late so it overrides others */ 739 property_get("dalvik.vm.extra-opts", extraOptsBuf, ""); 740 parseExtraOpts(extraOptsBuf); 741 742 /* Set the properties for locale */ 743 { 744 char langOption[sizeof("-Duser.language=") + 3]; 745 char regionOption[sizeof("-Duser.region=") + 3]; 746 strcpy(langOption, "-Duser.language="); 747 strcpy(regionOption, "-Duser.region="); 748 readLocale(langOption, regionOption); 749 opt.extraInfo = NULL; 750 opt.optionString = langOption; 751 mOptions.add(opt); 752 opt.optionString = regionOption; 753 mOptions.add(opt); 754 } 755 756 /* 757 * We don't have /tmp on the device, but we often have an SD card. Apps 758 * shouldn't use this, but some test suites might want to exercise it. 759 */ 760 opt.optionString = "-Djava.io.tmpdir=/sdcard"; 761 mOptions.add(opt); 762 763 initArgs.version = JNI_VERSION_1_4; 764 initArgs.options = mOptions.editArray(); 765 initArgs.nOptions = mOptions.size(); 766 initArgs.ignoreUnrecognized = JNI_FALSE; 767 768 /* 769 * Initialize the VM. 770 * 771 * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread. 772 * If this call succeeds, the VM is ready, and we can start issuing 773 * JNI calls. 774 */ 775 if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) { 776 LOGE("JNI_CreateJavaVM failed\n"); 777 goto bail; 778 } 779 780 result = 0; 781 782bail: 783 free(stackTraceFile); 784 return result; 785} 786 787char* AndroidRuntime::toSlashClassName(const char* className) 788{ 789 char* result = strdup(className); 790 for (char* cp = result; *cp != '\0'; cp++) { 791 if (*cp == '.') { 792 *cp = '/'; 793 } 794 } 795 return result; 796} 797 798/* 799 * Start the Android runtime. This involves starting the virtual machine 800 * and calling the "static void main(String[] args)" method in the class 801 * named by "className". 802 * 803 * Passes the main function two arguments, the class name and the specified 804 * options string. 805 */ 806void AndroidRuntime::start(const char* className, const char* options) 807{ 808 LOGD("\n>>>>>> AndroidRuntime START %s <<<<<<\n", 809 className != NULL ? className : "(unknown)"); 810 811 blockSigpipe(); 812 813 /* 814 * 'startSystemServer == true' means runtime is obsolete and not run from 815 * init.rc anymore, so we print out the boot start event here. 816 */ 817 if (strcmp(options, "start-system-server") == 0) { 818 /* track our progress through the boot sequence */ 819 const int LOG_BOOT_PROGRESS_START = 3000; 820 LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, 821 ns2ms(systemTime(SYSTEM_TIME_MONOTONIC))); 822 } 823 824 const char* rootDir = getenv("ANDROID_ROOT"); 825 if (rootDir == NULL) { 826 rootDir = "/system"; 827 if (!hasDir("/system")) { 828 LOG_FATAL("No root directory specified, and /android does not exist."); 829 return; 830 } 831 setenv("ANDROID_ROOT", rootDir, 1); 832 } 833 834 //const char* kernelHack = getenv("LD_ASSUME_KERNEL"); 835 //LOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack); 836 837 /* start the virtual machine */ 838 JNIEnv* env; 839 if (startVm(&mJavaVM, &env) != 0) { 840 return; 841 } 842 onVmCreated(env); 843 844 /* 845 * Register android functions. 846 */ 847 if (startReg(env) < 0) { 848 LOGE("Unable to register all android natives\n"); 849 return; 850 } 851 852 /* 853 * We want to call main() with a String array with arguments in it. 854 * At present we have two arguments, the class name and an option string. 855 * Create an array to hold them. 856 */ 857 jclass stringClass; 858 jobjectArray strArray; 859 jstring classNameStr; 860 jstring optionsStr; 861 862 stringClass = env->FindClass("java/lang/String"); 863 assert(stringClass != NULL); 864 strArray = env->NewObjectArray(2, stringClass, NULL); 865 assert(strArray != NULL); 866 classNameStr = env->NewStringUTF(className); 867 assert(classNameStr != NULL); 868 env->SetObjectArrayElement(strArray, 0, classNameStr); 869 optionsStr = env->NewStringUTF(options); 870 env->SetObjectArrayElement(strArray, 1, optionsStr); 871 872 /* 873 * Start VM. This thread becomes the main thread of the VM, and will 874 * not return until the VM exits. 875 */ 876 char* slashClassName = toSlashClassName(className); 877 jclass startClass = env->FindClass(slashClassName); 878 if (startClass == NULL) { 879 LOGE("JavaVM unable to locate class '%s'\n", slashClassName); 880 /* keep going */ 881 } else { 882 jmethodID startMeth = env->GetStaticMethodID(startClass, "main", 883 "([Ljava/lang/String;)V"); 884 if (startMeth == NULL) { 885 LOGE("JavaVM unable to find main() in '%s'\n", className); 886 /* keep going */ 887 } else { 888 env->CallStaticVoidMethod(startClass, startMeth, strArray); 889 890#if 0 891 if (env->ExceptionCheck()) 892 threadExitUncaughtException(env); 893#endif 894 } 895 } 896 free(slashClassName); 897 898 LOGD("Shutting down VM\n"); 899 if (mJavaVM->DetachCurrentThread() != JNI_OK) 900 LOGW("Warning: unable to detach main thread\n"); 901 if (mJavaVM->DestroyJavaVM() != 0) 902 LOGW("Warning: VM did not shut down cleanly\n"); 903} 904 905void AndroidRuntime::onExit(int code) 906{ 907 LOGV("AndroidRuntime onExit calling exit(%d)", code); 908 exit(code); 909} 910 911void AndroidRuntime::onVmCreated(JNIEnv* env) 912{ 913 // If AndroidRuntime had anything to do here, we'd have done it in 'start'. 914} 915 916/* 917 * Get the JNIEnv pointer for this thread. 918 * 919 * Returns NULL if the slot wasn't allocated or populated. 920 */ 921/*static*/ JNIEnv* AndroidRuntime::getJNIEnv() 922{ 923 JNIEnv* env; 924 JavaVM* vm = AndroidRuntime::getJavaVM(); 925 assert(vm != NULL); 926 927 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) 928 return NULL; 929 return env; 930} 931 932/* 933 * Makes the current thread visible to the VM. 934 * 935 * The JNIEnv pointer returned is only valid for the current thread, and 936 * thus must be tucked into thread-local storage. 937 */ 938static int javaAttachThread(const char* threadName, JNIEnv** pEnv) 939{ 940 JavaVMAttachArgs args; 941 JavaVM* vm; 942 jint result; 943 944 vm = AndroidRuntime::getJavaVM(); 945 assert(vm != NULL); 946 947 args.version = JNI_VERSION_1_4; 948 args.name = (char*) threadName; 949 args.group = NULL; 950 951 result = vm->AttachCurrentThread(pEnv, (void*) &args); 952 if (result != JNI_OK) 953 LOGI("NOTE: attach of thread '%s' failed\n", threadName); 954 955 return result; 956} 957 958/* 959 * Detach the current thread from the set visible to the VM. 960 */ 961static int javaDetachThread(void) 962{ 963 JavaVM* vm; 964 jint result; 965 966 vm = AndroidRuntime::getJavaVM(); 967 assert(vm != NULL); 968 969 result = vm->DetachCurrentThread(); 970 if (result != JNI_OK) 971 LOGE("ERROR: thread detach failed\n"); 972 return result; 973} 974 975/* 976 * When starting a native thread that will be visible from the VM, we 977 * bounce through this to get the right attach/detach action. 978 * Note that this function calls free(args) 979 */ 980/*static*/ int AndroidRuntime::javaThreadShell(void* args) { 981 void* start = ((void**)args)[0]; 982 void* userData = ((void **)args)[1]; 983 char* name = (char*) ((void **)args)[2]; // we own this storage 984 free(args); 985 JNIEnv* env; 986 int result; 987 988 /* hook us into the VM */ 989 if (javaAttachThread(name, &env) != JNI_OK) 990 return -1; 991 992 /* start the thread running */ 993 result = (*(android_thread_func_t)start)(userData); 994 995 /* unhook us */ 996 javaDetachThread(); 997 free(name); 998 999 return result; 1000} 1001 1002/* 1003 * This is invoked from androidCreateThreadEtc() via the callback 1004 * set with androidSetCreateThreadFunc(). 1005 * 1006 * We need to create the new thread in such a way that it gets hooked 1007 * into the VM before it really starts executing. 1008 */ 1009/*static*/ int AndroidRuntime::javaCreateThreadEtc( 1010 android_thread_func_t entryFunction, 1011 void* userData, 1012 const char* threadName, 1013 int32_t threadPriority, 1014 size_t threadStackSize, 1015 android_thread_id_t* threadId) 1016{ 1017 void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free 1018 int result; 1019 1020 assert(threadName != NULL); 1021 1022 args[0] = (void*) entryFunction; 1023 args[1] = userData; 1024 args[2] = (void*) strdup(threadName); // javaThreadShell must free 1025 1026 result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args, 1027 threadName, threadPriority, threadStackSize, threadId); 1028 return result; 1029} 1030 1031/* 1032 * Create a thread that is visible from the VM. 1033 * 1034 * This is called from elsewhere in the library. 1035 */ 1036/*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name, 1037 void (*start)(void *), void* arg) 1038{ 1039 android_thread_id_t threadId = 0; 1040 javaCreateThreadEtc((android_thread_func_t) start, arg, name, 1041 ANDROID_PRIORITY_DEFAULT, 0, &threadId); 1042 return threadId; 1043} 1044 1045#if 0 1046static void quickTest(void* arg) 1047{ 1048 const char* str = (const char*) arg; 1049 1050 printf("In quickTest: %s\n", str); 1051} 1052#endif 1053 1054#ifdef NDEBUG 1055 #define REG_JNI(name) { name } 1056 struct RegJNIRec { 1057 int (*mProc)(JNIEnv*); 1058 }; 1059#else 1060 #define REG_JNI(name) { name, #name } 1061 struct RegJNIRec { 1062 int (*mProc)(JNIEnv*); 1063 const char* mName; 1064 }; 1065#endif 1066 1067typedef void (*RegJAMProc)(); 1068 1069static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env) 1070{ 1071 for (size_t i = 0; i < count; i++) { 1072 if (array[i].mProc(env) < 0) { 1073#ifndef NDEBUG 1074 LOGD("----------!!! %s failed to load\n", array[i].mName); 1075#endif 1076 return -1; 1077 } 1078 } 1079 return 0; 1080} 1081 1082static void register_jam_procs(const RegJAMProc array[], size_t count) 1083{ 1084 for (size_t i = 0; i < count; i++) { 1085 array[i](); 1086 } 1087} 1088 1089static const RegJNIRec gRegJNI[] = { 1090 REG_JNI(register_android_debug_JNITest), 1091 REG_JNI(register_com_android_internal_os_RuntimeInit), 1092 REG_JNI(register_android_os_SystemClock), 1093 REG_JNI(register_android_util_EventLog), 1094 REG_JNI(register_android_util_Log), 1095 REG_JNI(register_android_util_FloatMath), 1096 REG_JNI(register_android_text_format_Time), 1097 REG_JNI(register_android_content_AssetManager), 1098 REG_JNI(register_android_content_StringBlock), 1099 REG_JNI(register_android_content_XmlBlock), 1100 REG_JNI(register_android_emoji_EmojiFactory), 1101 REG_JNI(register_android_text_AndroidCharacter), 1102 REG_JNI(register_android_text_AndroidBidi), 1103 REG_JNI(register_android_text_KeyCharacterMap), 1104 REG_JNI(register_android_os_Process), 1105 REG_JNI(register_android_os_SystemProperties), 1106 REG_JNI(register_android_os_Binder), 1107 REG_JNI(register_android_view_Display), 1108 REG_JNI(register_android_nio_utils), 1109 REG_JNI(register_android_graphics_PixelFormat), 1110 REG_JNI(register_android_graphics_Graphics), 1111 REG_JNI(register_android_view_GLES20Canvas), 1112 REG_JNI(register_android_view_Surface), 1113 REG_JNI(register_android_view_TextureView), 1114 REG_JNI(register_com_google_android_gles_jni_EGLImpl), 1115 REG_JNI(register_com_google_android_gles_jni_GLImpl), 1116 REG_JNI(register_android_opengl_jni_GLES10), 1117 REG_JNI(register_android_opengl_jni_GLES10Ext), 1118 REG_JNI(register_android_opengl_jni_GLES11), 1119 REG_JNI(register_android_opengl_jni_GLES11Ext), 1120 REG_JNI(register_android_opengl_jni_GLES20), 1121 1122 REG_JNI(register_android_graphics_Bitmap), 1123 REG_JNI(register_android_graphics_BitmapFactory), 1124 REG_JNI(register_android_graphics_BitmapRegionDecoder), 1125 REG_JNI(register_android_graphics_Camera), 1126 REG_JNI(register_android_graphics_Canvas), 1127 REG_JNI(register_android_graphics_ColorFilter), 1128 REG_JNI(register_android_graphics_DrawFilter), 1129 REG_JNI(register_android_graphics_Interpolator), 1130 REG_JNI(register_android_graphics_LayerRasterizer), 1131 REG_JNI(register_android_graphics_MaskFilter), 1132 REG_JNI(register_android_graphics_Matrix), 1133 REG_JNI(register_android_graphics_Movie), 1134 REG_JNI(register_android_graphics_NinePatch), 1135 REG_JNI(register_android_graphics_Paint), 1136 REG_JNI(register_android_graphics_ParcelSurfaceTexture), 1137 REG_JNI(register_android_graphics_Path), 1138 REG_JNI(register_android_graphics_PathMeasure), 1139 REG_JNI(register_android_graphics_PathEffect), 1140 REG_JNI(register_android_graphics_Picture), 1141 REG_JNI(register_android_graphics_PorterDuff), 1142 REG_JNI(register_android_graphics_Rasterizer), 1143 REG_JNI(register_android_graphics_Region), 1144 REG_JNI(register_android_graphics_Shader), 1145 REG_JNI(register_android_graphics_SurfaceTexture), 1146 REG_JNI(register_android_graphics_Typeface), 1147 REG_JNI(register_android_graphics_Xfermode), 1148 REG_JNI(register_android_graphics_YuvImage), 1149 REG_JNI(register_com_android_internal_graphics_NativeUtils), 1150 1151 REG_JNI(register_android_database_CursorWindow), 1152 REG_JNI(register_android_database_SQLiteCompiledSql), 1153 REG_JNI(register_android_database_SQLiteDatabase), 1154 REG_JNI(register_android_database_SQLiteDebug), 1155 REG_JNI(register_android_database_SQLiteProgram), 1156 REG_JNI(register_android_database_SQLiteQuery), 1157 REG_JNI(register_android_database_SQLiteStatement), 1158 REG_JNI(register_android_os_Debug), 1159 REG_JNI(register_android_os_FileObserver), 1160 REG_JNI(register_android_os_FileUtils), 1161 REG_JNI(register_android_os_MessageQueue), 1162 REG_JNI(register_android_os_ParcelFileDescriptor), 1163 REG_JNI(register_android_os_Power), 1164 REG_JNI(register_android_os_StatFs), 1165 REG_JNI(register_android_os_UEventObserver), 1166 REG_JNI(register_android_net_LocalSocketImpl), 1167 REG_JNI(register_android_net_NetworkUtils), 1168 REG_JNI(register_android_net_TrafficStats), 1169 REG_JNI(register_android_net_wifi_WifiManager), 1170 REG_JNI(register_android_nfc_NdefMessage), 1171 REG_JNI(register_android_nfc_NdefRecord), 1172 REG_JNI(register_android_os_MemoryFile), 1173 REG_JNI(register_com_android_internal_os_ZygoteInit), 1174 REG_JNI(register_android_hardware_Camera), 1175 REG_JNI(register_android_hardware_SensorManager), 1176 REG_JNI(register_android_hardware_UsbDevice), 1177 REG_JNI(register_android_hardware_UsbDeviceConnection), 1178 REG_JNI(register_android_hardware_UsbRequest), 1179 REG_JNI(register_android_media_AudioRecord), 1180 REG_JNI(register_android_media_AudioSystem), 1181 REG_JNI(register_android_media_AudioTrack), 1182 REG_JNI(register_android_media_JetPlayer), 1183 REG_JNI(register_android_media_ToneGenerator), 1184 1185 REG_JNI(register_android_opengl_classes), 1186 REG_JNI(register_android_bluetooth_HeadsetBase), 1187 REG_JNI(register_android_bluetooth_BluetoothAudioGateway), 1188 REG_JNI(register_android_bluetooth_BluetoothSocket), 1189 REG_JNI(register_android_server_BluetoothService), 1190 REG_JNI(register_android_server_BluetoothEventLoop), 1191 REG_JNI(register_android_server_BluetoothA2dpService), 1192 REG_JNI(register_android_server_Watchdog), 1193 REG_JNI(register_android_ddm_DdmHandleNativeHeap), 1194 REG_JNI(register_android_backup_BackupDataInput), 1195 REG_JNI(register_android_backup_BackupDataOutput), 1196 REG_JNI(register_android_backup_FileBackupHelperBase), 1197 REG_JNI(register_android_backup_BackupHelperDispatcher), 1198 REG_JNI(register_android_app_backup_FullBackup), 1199 REG_JNI(register_android_app_ActivityThread), 1200 REG_JNI(register_android_app_NativeActivity), 1201 REG_JNI(register_android_view_InputChannel), 1202 REG_JNI(register_android_view_InputQueue), 1203 REG_JNI(register_android_view_KeyEvent), 1204 REG_JNI(register_android_view_MotionEvent), 1205 REG_JNI(register_android_view_PointerIcon), 1206 REG_JNI(register_android_view_VelocityTracker), 1207 1208 REG_JNI(register_android_content_res_ObbScanner), 1209 REG_JNI(register_android_content_res_Configuration), 1210 1211 REG_JNI(register_android_animation_PropertyValuesHolder), 1212}; 1213 1214/* 1215 * Register android native functions with the VM. 1216 */ 1217/*static*/ int AndroidRuntime::startReg(JNIEnv* env) 1218{ 1219 /* 1220 * This hook causes all future threads created in this process to be 1221 * attached to the JavaVM. (This needs to go away in favor of JNI 1222 * Attach calls.) 1223 */ 1224 androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc); 1225 1226 LOGV("--- registering native functions ---\n"); 1227 1228 /* 1229 * Every "register" function calls one or more things that return 1230 * a local reference (e.g. FindClass). Because we haven't really 1231 * started the VM yet, they're all getting stored in the base frame 1232 * and never released. Use Push/Pop to manage the storage. 1233 */ 1234 env->PushLocalFrame(200); 1235 1236 if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) { 1237 env->PopLocalFrame(NULL); 1238 return -1; 1239 } 1240 env->PopLocalFrame(NULL); 1241 1242 //createJavaThread("fubar", quickTest, (void*) "hello"); 1243 1244 return 0; 1245} 1246 1247AndroidRuntime* AndroidRuntime::getRuntime() 1248{ 1249 return gCurRuntime; 1250} 1251 1252/** 1253 * Used by WithFramework to register native functions. 1254 */ 1255extern "C" 1256jint Java_com_android_internal_util_WithFramework_registerNatives( 1257 JNIEnv* env, jclass clazz) { 1258 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env); 1259} 1260 1261/** 1262 * Used by LoadClass to register native functions. 1263 */ 1264extern "C" 1265jint Java_LoadClass_registerNatives(JNIEnv* env, jclass clazz) { 1266 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env); 1267} 1268 1269} // namespace android 1270