Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 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 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16 | |
| 17 | #define LOG_TAG "AndroidRuntime" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
| 20 | #include <android_runtime/AndroidRuntime.h> |
Mathias Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 21 | #include <binder/IBinder.h> |
Brad Fitzpatrick | 0bd5243 | 2010-12-13 16:52:35 -0800 | [diff] [blame] | 22 | #include <binder/IPCThreadState.h> |
Mathias Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 23 | #include <binder/IServiceManager.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | #include <utils/Log.h> |
| 25 | #include <utils/misc.h> |
Mathias Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 26 | #include <binder/Parcel.h> |
Mathias Agopian | 8ed6beb | 2009-06-05 01:26:23 -0700 | [diff] [blame] | 27 | #include <utils/StringArray.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | #include <utils/threads.h> |
| 29 | #include <cutils/properties.h> |
| 30 | |
| 31 | #include <SkGraphics.h> |
| 32 | #include <SkImageDecoder.h> |
Mike Reed | fc8db53 | 2009-04-27 11:43:30 -0400 | [diff] [blame] | 33 | #include <SkImageRef_GlobalPool.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | |
| 35 | #include "jni.h" |
| 36 | #include "JNIHelp.h" |
| 37 | #include "android_util_Binder.h" |
| 38 | |
| 39 | #include <stdio.h> |
| 40 | #include <signal.h> |
| 41 | #include <sys/stat.h> |
| 42 | #include <sys/types.h> |
| 43 | #include <signal.h> |
| 44 | #include <dirent.h> |
| 45 | #include <assert.h> |
| 46 | |
| 47 | |
| 48 | using namespace android; |
| 49 | |
| 50 | extern void register_BindTest(); |
| 51 | |
| 52 | extern int register_android_os_Binder(JNIEnv* env); |
| 53 | extern int register_android_os_Process(JNIEnv* env); |
| 54 | extern int register_android_graphics_Bitmap(JNIEnv*); |
| 55 | extern int register_android_graphics_BitmapFactory(JNIEnv*); |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 56 | extern int register_android_graphics_BitmapRegionDecoder(JNIEnv*); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | extern int register_android_graphics_Camera(JNIEnv* env); |
| 58 | extern int register_android_graphics_Graphics(JNIEnv* env); |
| 59 | extern int register_android_graphics_Interpolator(JNIEnv* env); |
| 60 | extern int register_android_graphics_LayerRasterizer(JNIEnv*); |
| 61 | extern int register_android_graphics_MaskFilter(JNIEnv* env); |
| 62 | extern int register_android_graphics_Movie(JNIEnv* env); |
| 63 | extern int register_android_graphics_NinePatch(JNIEnv*); |
| 64 | extern int register_android_graphics_PathEffect(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | extern int register_android_graphics_Shader(JNIEnv* env); |
| 66 | extern int register_android_graphics_Typeface(JNIEnv* env); |
Wei-Ta Chen | bca2d61 | 2009-11-30 17:52:05 +0800 | [diff] [blame] | 67 | extern int register_android_graphics_YuvImage(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | |
| 69 | extern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env); |
| 70 | extern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env); |
Jack Palevich | 1c4907e | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 71 | extern int register_android_opengl_jni_GLES10(JNIEnv* env); |
| 72 | extern int register_android_opengl_jni_GLES10Ext(JNIEnv* env); |
| 73 | extern int register_android_opengl_jni_GLES11(JNIEnv* env); |
| 74 | extern int register_android_opengl_jni_GLES11Ext(JNIEnv* env); |
Jack Palevich | 560814f | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 75 | extern int register_android_opengl_jni_GLES20(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | |
| 77 | extern int register_android_hardware_Camera(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | extern int register_android_hardware_SensorManager(JNIEnv *env); |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 79 | extern int register_android_hardware_UsbDevice(JNIEnv *env); |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 80 | extern int register_android_hardware_UsbDeviceConnection(JNIEnv *env); |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 81 | extern int register_android_hardware_UsbRequest(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | |
| 83 | extern int register_android_media_AudioRecord(JNIEnv *env); |
| 84 | extern int register_android_media_AudioSystem(JNIEnv *env); |
| 85 | extern int register_android_media_AudioTrack(JNIEnv *env); |
| 86 | extern int register_android_media_JetPlayer(JNIEnv *env); |
| 87 | extern int register_android_media_ToneGenerator(JNIEnv *env); |
| 88 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | extern int register_android_util_FloatMath(JNIEnv* env); |
| 90 | |
| 91 | namespace android { |
| 92 | |
| 93 | /* |
| 94 | * JNI-based registration functions. Note these are properly contained in |
| 95 | * namespace android. |
| 96 | */ |
| 97 | extern int register_android_content_AssetManager(JNIEnv* env); |
| 98 | extern int register_android_util_EventLog(JNIEnv* env); |
| 99 | extern int register_android_util_Log(JNIEnv* env); |
| 100 | extern int register_android_content_StringBlock(JNIEnv* env); |
| 101 | extern int register_android_content_XmlBlock(JNIEnv* env); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 102 | extern int register_android_emoji_EmojiFactory(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | extern int register_android_graphics_Canvas(JNIEnv* env); |
| 104 | extern int register_android_graphics_ColorFilter(JNIEnv* env); |
| 105 | extern int register_android_graphics_DrawFilter(JNIEnv* env); |
| 106 | extern int register_android_graphics_Matrix(JNIEnv* env); |
| 107 | extern int register_android_graphics_Paint(JNIEnv* env); |
| 108 | extern int register_android_graphics_Path(JNIEnv* env); |
| 109 | extern int register_android_graphics_PathMeasure(JNIEnv* env); |
| 110 | extern int register_android_graphics_Picture(JNIEnv*); |
| 111 | extern int register_android_graphics_PorterDuff(JNIEnv* env); |
| 112 | extern int register_android_graphics_Rasterizer(JNIEnv* env); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 113 | extern int register_android_graphics_Region(JNIEnv* env); |
Jamie Gennis | aa0ce33 | 2011-01-06 17:04:26 -0800 | [diff] [blame] | 114 | extern int register_android_graphics_SurfaceTexture(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | extern int register_android_graphics_Xfermode(JNIEnv* env); |
| 116 | extern int register_android_graphics_PixelFormat(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | extern int register_android_view_Display(JNIEnv* env); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 118 | extern int register_android_view_GLES20Canvas(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | extern int register_android_view_Surface(JNIEnv* env); |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 120 | extern int register_android_view_TextureView(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | extern int register_android_database_CursorWindow(JNIEnv* env); |
Vasu Nori | 5a03f36 | 2009-10-20 15:16:35 -0700 | [diff] [blame] | 122 | extern int register_android_database_SQLiteCompiledSql(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | extern int register_android_database_SQLiteDatabase(JNIEnv* env); |
| 124 | extern int register_android_database_SQLiteDebug(JNIEnv* env); |
| 125 | extern int register_android_database_SQLiteProgram(JNIEnv* env); |
| 126 | extern int register_android_database_SQLiteQuery(JNIEnv* env); |
| 127 | extern int register_android_database_SQLiteStatement(JNIEnv* env); |
| 128 | extern int register_android_debug_JNITest(JNIEnv* env); |
| 129 | extern int register_android_nio_utils(JNIEnv* env); |
Nick Pelly | cd0e839 | 2010-10-13 17:25:24 -0700 | [diff] [blame] | 130 | extern int register_android_nfc_NdefMessage(JNIEnv *env); |
| 131 | extern int register_android_nfc_NdefRecord(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | extern int register_android_text_format_Time(JNIEnv* env); |
| 133 | extern int register_android_os_Debug(JNIEnv* env); |
Christopher Tate | fa9e7c0 | 2010-05-06 12:07:10 -0700 | [diff] [blame] | 134 | extern int register_android_os_MessageQueue(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | extern int register_android_os_ParcelFileDescriptor(JNIEnv *env); |
| 136 | extern int register_android_os_Power(JNIEnv *env); |
| 137 | extern int register_android_os_StatFs(JNIEnv *env); |
| 138 | extern int register_android_os_SystemProperties(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | extern int register_android_os_SystemClock(JNIEnv* env); |
| 140 | extern int register_android_os_FileObserver(JNIEnv *env); |
| 141 | extern int register_android_os_FileUtils(JNIEnv *env); |
| 142 | extern int register_android_os_UEventObserver(JNIEnv* env); |
| 143 | extern int register_android_os_MemoryFile(JNIEnv* env); |
| 144 | extern int register_android_net_LocalSocketImpl(JNIEnv* env); |
| 145 | extern int register_android_net_NetworkUtils(JNIEnv* env); |
Dan Egnor | 2b4abcd | 2010-04-07 17:30:50 -0700 | [diff] [blame] | 146 | extern int register_android_net_TrafficStats(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | extern int register_android_net_wifi_WifiManager(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | extern int register_android_text_AndroidCharacter(JNIEnv *env); |
Doug Felt | dae8e94 | 2010-02-24 14:33:15 -0800 | [diff] [blame] | 149 | extern int register_android_text_AndroidBidi(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | extern int register_android_text_KeyCharacterMap(JNIEnv *env); |
| 151 | extern int register_android_opengl_classes(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | extern int register_android_bluetooth_HeadsetBase(JNIEnv* env); |
| 153 | extern int register_android_bluetooth_BluetoothAudioGateway(JNIEnv* env); |
Nick Pelly | 0b6955a | 2009-05-26 19:13:43 -0700 | [diff] [blame] | 154 | extern int register_android_bluetooth_BluetoothSocket(JNIEnv *env); |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 155 | extern int register_android_server_BluetoothService(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | extern int register_android_server_BluetoothEventLoop(JNIEnv *env); |
| 157 | extern int register_android_server_BluetoothA2dpService(JNIEnv* env); |
Christopher Tate | ecaa7b4 | 2010-06-04 14:55:02 -0700 | [diff] [blame] | 158 | extern int register_android_server_Watchdog(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env); |
| 160 | extern int register_com_android_internal_os_ZygoteInit(JNIEnv* env); |
Joe Onorato | 1cf5874 | 2009-06-12 11:06:24 -0700 | [diff] [blame] | 161 | extern int register_android_backup_BackupDataInput(JNIEnv *env); |
Joe Onorato | d2110db | 2009-05-19 13:41:21 -0700 | [diff] [blame] | 162 | extern int register_android_backup_BackupDataOutput(JNIEnv *env); |
Joe Onorato | 06290a4 | 2009-06-18 20:10:37 -0700 | [diff] [blame] | 163 | extern int register_android_backup_FileBackupHelperBase(JNIEnv *env); |
Joe Onorato | 4ababd9 | 2009-06-25 18:29:18 -0400 | [diff] [blame] | 164 | extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env); |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 165 | extern int register_android_app_backup_FullBackup(JNIEnv *env); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 166 | extern int register_android_app_ActivityThread(JNIEnv *env); |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 167 | extern int register_android_app_NativeActivity(JNIEnv *env); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 168 | extern int register_android_view_InputChannel(JNIEnv* env); |
| 169 | extern int register_android_view_InputQueue(JNIEnv* env); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 170 | extern int register_android_view_KeyEvent(JNIEnv* env); |
| 171 | extern int register_android_view_MotionEvent(JNIEnv* env); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 172 | extern int register_android_view_PointerIcon(JNIEnv* env); |
Jeff Brown | 2ed2462 | 2011-03-14 19:39:54 -0700 | [diff] [blame] | 173 | extern int register_android_view_VelocityTracker(JNIEnv* env); |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 174 | extern int register_android_content_res_ObbScanner(JNIEnv* env); |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 175 | extern int register_android_content_res_Configuration(JNIEnv* env); |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 176 | extern int register_android_animation_PropertyValuesHolder(JNIEnv *env); |
Kenny Root | 66269ea | 2011-07-12 14:14:01 -0700 | [diff] [blame] | 177 | extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | |
| 179 | static AndroidRuntime* gCurRuntime = NULL; |
| 180 | |
| 181 | static 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 | */ |
| 190 | static void com_android_internal_os_RuntimeInit_finishInit(JNIEnv* env, jobject clazz) |
| 191 | { |
| 192 | gCurRuntime->onStarted(); |
| 193 | } |
| 194 | |
| 195 | static void com_android_internal_os_RuntimeInit_zygoteInit(JNIEnv* env, jobject clazz) |
| 196 | { |
| 197 | gCurRuntime->onZygoteInit(); |
| 198 | } |
| 199 | |
| 200 | static jint com_android_internal_os_RuntimeInit_isComputerOn(JNIEnv* env, jobject clazz) |
| 201 | { |
| 202 | return 1; |
| 203 | } |
| 204 | |
| 205 | static void com_android_internal_os_RuntimeInit_turnComputerOn(JNIEnv* env, jobject clazz) |
| 206 | { |
| 207 | } |
| 208 | |
| 209 | static 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 | } |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 215 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | /* |
| 220 | * JNI registration. |
| 221 | */ |
| 222 | static 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", |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 230 | (void*) com_android_internal_os_RuntimeInit_turnComputerOn }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | { "getQwertyKeyboard", "()I", |
| 232 | (void*) com_android_internal_os_RuntimeInit_getQwertyKeyboard }, |
| 233 | }; |
| 234 | |
| 235 | int 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 | |
| 246 | AndroidRuntime::AndroidRuntime() |
| 247 | { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 248 | SkGraphics::Init(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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); |
Mike Reed | fc8db53 | 2009-04-27 11:43:30 -0400 | [diff] [blame] | 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 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
| 267 | AndroidRuntime::~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 | |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 281 | status_t AndroidRuntime::callMain(const char* className, |
| 282 | jclass clazz, int argc, const char* const argv[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | { |
| 284 | JNIEnv* env; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | jmethodID methodId; |
| 286 | |
Dianne Hackborn | 08e60f2 | 2010-09-01 18:17:17 -0700 | [diff] [blame] | 287 | LOGD("Calling main entry %s", className); |
| 288 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | env = getJNIEnv(); |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 290 | if (clazz == NULL || env == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | /* |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 320 | * The VM calls this through the "exit" hook. |
| 321 | */ |
| 322 | static 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 | */ |
| 333 | static 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 | |
Brad Fitzpatrick | 0bd5243 | 2010-12-13 16:52:35 -0800 | [diff] [blame] | 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 | */ |
| 347 | static bool runtime_isSensitiveThread() { |
| 348 | IPCThreadState* state = IPCThreadState::selfOrNull(); |
| 349 | return state && state->getStrictModePolicy() != 0; |
| 350 | } |
| 351 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | */ |
| 358 | int AndroidRuntime::addVmArguments(int argc, const char* const argv[]) |
| 359 | { |
| 360 | int i; |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
| 378 | static 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 | */ |
| 391 | static 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 | */ |
| 404 | static void readLocale(char* language, char* region) |
| 405 | { |
| 406 | char propLang[PROPERTY_VALUE_MAX], propRegn[PROPERTY_VALUE_MAX]; |
Brian Carlstrom | 171ea89 | 2010-08-24 21:27:52 -0700 | [diff] [blame] | 407 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 420 | /* |
Andy McFadden | e4d81f2 | 2010-07-14 16:02:20 -0700 | [diff] [blame] | 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 | */ |
| 428 | void 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 | /* |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 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 | */ |
| 462 | int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | { |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 464 | int result = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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]; |
Carl Shapiro | 38cfa8c | 2010-12-07 16:48:29 -0800 | [diff] [blame] | 472 | char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX]; |
Dianne Hackborn | bdcef70 | 2009-08-18 19:15:36 -0700 | [diff] [blame] | 473 | char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX]; |
Carl Shapiro | 8cdf27c | 2011-01-19 12:33:12 -0800 | [diff] [blame] | 474 | char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX]; |
Andy McFadden | e4d81f2 | 2010-07-14 16:02:20 -0700 | [diff] [blame] | 475 | char extraOptsBuf[PROPERTY_VALUE_MAX]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | char* stackTraceFile = NULL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | bool checkJni = false; |
Andy McFadden | e2b23e1 | 2009-04-03 11:09:46 -0700 | [diff] [blame] | 478 | bool checkDexSum = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 479 | bool logStdio = false; |
Ben Cheng | 52b0e73 | 2009-06-19 13:31:12 -0700 | [diff] [blame] | 480 | enum { |
| 481 | kEMDefault, |
| 482 | kEMIntPortable, |
| 483 | kEMIntFast, |
| 484 | #if defined(WITH_JIT) |
| 485 | kEMJitCompiler, |
| 486 | #endif |
| 487 | } executionMode = kEMDefault; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
Ben Cheng | 52b0e73 | 2009-06-19 13:31:12 -0700 | [diff] [blame] | 506 | #if defined(WITH_JIT) |
| 507 | } else if (strcmp(propBuf, "int:jit") == 0) { |
| 508 | executionMode = kEMJitCompiler; |
| 509 | #endif |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | property_get("dalvik.vm.stack-trace-file", stackTraceFileBuf, ""); |
| 513 | |
Andy McFadden | e2b23e1 | 2009-04-03 11:09:46 -0700 | [diff] [blame] | 514 | property_get("dalvik.vm.check-dex-sum", propBuf, ""); |
| 515 | if (strcmp(propBuf, "true") == 0) { |
| 516 | checkDexSum = true; |
| 517 | } |
| 518 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Brad Fitzpatrick | 0bd5243 | 2010-12-13 16:52:35 -0800 | [diff] [blame] | 540 | /* register the framework-specific "is sensitive thread" hook */ |
| 541 | opt.extraInfo = (void*) runtime_isSensitiveThread; |
| 542 | opt.optionString = "sensitiveThread"; |
| 543 | mOptions.add(opt); |
| 544 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Carl Shapiro | 9e4c884 | 2010-12-08 12:14:46 -0800 | [diff] [blame] | 553 | /* |
| 554 | * The default starting and maximum size of the heap. Larger |
| 555 | * values should be specified in a product property override. |
| 556 | */ |
Carl Shapiro | 38cfa8c | 2010-12-07 16:48:29 -0800 | [diff] [blame] | 557 | strcpy(heapstartsizeOptsBuf, "-Xms"); |
Carl Shapiro | 9e4c884 | 2010-12-08 12:14:46 -0800 | [diff] [blame] | 558 | property_get("dalvik.vm.heapstartsize", heapstartsizeOptsBuf+4, "4m"); |
Carl Shapiro | 38cfa8c | 2010-12-07 16:48:29 -0800 | [diff] [blame] | 559 | opt.optionString = heapstartsizeOptsBuf; |
| 560 | mOptions.add(opt); |
Dianne Hackborn | bdcef70 | 2009-08-18 19:15:36 -0700 | [diff] [blame] | 561 | strcpy(heapsizeOptsBuf, "-Xmx"); |
| 562 | property_get("dalvik.vm.heapsize", heapsizeOptsBuf+4, "16m"); |
Dianne Hackborn | bdcef70 | 2009-08-18 19:15:36 -0700 | [diff] [blame] | 563 | opt.optionString = heapsizeOptsBuf; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | mOptions.add(opt); |
| 565 | |
Carl Shapiro | 8cdf27c | 2011-01-19 12:33:12 -0800 | [diff] [blame] | 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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
Brian Carlstrom | 08065b9 | 2011-04-01 15:49:41 -0700 | [diff] [blame] | 603 | case 'f': val = "-Xdexopt:full"; break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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); |
The Android Open Source Project | 7b0b1ed | 2009-03-18 22:20:26 -0700 | [diff] [blame] | 617 | |
| 618 | /* turn on precise GC while we're at it */ |
| 619 | opt.optionString = "-Xgc:precise"; |
| 620 | mOptions.add(opt); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | |
| 624 | /* enable debugging; set suspend=y to pause during VM init */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 625 | /* use android ADB transport */ |
| 626 | opt.optionString = |
| 627 | "-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 628 | mOptions.add(opt); |
| 629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | LOGD("CheckJNI is %s\n", checkJni ? "ON" : "OFF"); |
| 631 | if (checkJni) { |
| 632 | /* extended JNI checking */ |
| 633 | opt.optionString = "-Xcheck:jni"; |
| 634 | mOptions.add(opt); |
| 635 | |
| 636 | /* set a cap on JNI global references */ |
| 637 | opt.optionString = "-Xjnigreflimit:2000"; |
| 638 | mOptions.add(opt); |
| 639 | |
| 640 | /* with -Xcheck:jni, this provides a JNI function call trace */ |
| 641 | //opt.optionString = "-verbose:jni"; |
| 642 | //mOptions.add(opt); |
| 643 | } |
Ben Cheng | 52b0e73 | 2009-06-19 13:31:12 -0700 | [diff] [blame] | 644 | |
Carl Shapiro | d8f3ec6 | 2010-04-12 16:31:59 -0700 | [diff] [blame] | 645 | char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:") + sizeof(propBuf)]; |
| 646 | property_get("dalvik.vm.lockprof.threshold", propBuf, ""); |
| 647 | if (strlen(propBuf) > 0) { |
| 648 | strcpy(lockProfThresholdBuf, "-Xlockprofthreshold:"); |
| 649 | strcat(lockProfThresholdBuf, propBuf); |
| 650 | opt.optionString = lockProfThresholdBuf; |
| 651 | mOptions.add(opt); |
| 652 | } |
| 653 | |
Ben Cheng | 52b0e73 | 2009-06-19 13:31:12 -0700 | [diff] [blame] | 654 | #if defined(WITH_JIT) |
Ben Cheng | 52b0e73 | 2009-06-19 13:31:12 -0700 | [diff] [blame] | 655 | /* Force interpreter-only mode for selected opcodes. Eg "1-0a,3c,f1-ff" */ |
| 656 | char jitOpBuf[sizeof("-Xjitop:") + PROPERTY_VALUE_MAX]; |
| 657 | property_get("dalvik.vm.jit.op", propBuf, ""); |
| 658 | if (strlen(propBuf) > 0) { |
| 659 | strcpy(jitOpBuf, "-Xjitop:"); |
| 660 | strcat(jitOpBuf, propBuf); |
| 661 | opt.optionString = jitOpBuf; |
| 662 | mOptions.add(opt); |
| 663 | } |
| 664 | |
Ben Cheng | 52b0e73 | 2009-06-19 13:31:12 -0700 | [diff] [blame] | 665 | /* Force interpreter-only mode for selected methods */ |
| 666 | char jitMethodBuf[sizeof("-Xjitmethod:") + PROPERTY_VALUE_MAX]; |
| 667 | property_get("dalvik.vm.jit.method", propBuf, ""); |
| 668 | if (strlen(propBuf) > 0) { |
| 669 | strcpy(jitMethodBuf, "-Xjitmethod:"); |
| 670 | strcat(jitMethodBuf, propBuf); |
| 671 | opt.optionString = jitMethodBuf; |
| 672 | mOptions.add(opt); |
| 673 | } |
Ben Cheng | 52b0e73 | 2009-06-19 13:31:12 -0700 | [diff] [blame] | 674 | #endif |
| 675 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 676 | if (executionMode == kEMIntPortable) { |
| 677 | opt.optionString = "-Xint:portable"; |
| 678 | mOptions.add(opt); |
| 679 | } else if (executionMode == kEMIntFast) { |
| 680 | opt.optionString = "-Xint:fast"; |
| 681 | mOptions.add(opt); |
Ben Cheng | 52b0e73 | 2009-06-19 13:31:12 -0700 | [diff] [blame] | 682 | #if defined(WITH_JIT) |
| 683 | } else if (executionMode == kEMJitCompiler) { |
| 684 | opt.optionString = "-Xint:jit"; |
| 685 | mOptions.add(opt); |
| 686 | #endif |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 687 | } |
Andy McFadden | e2b23e1 | 2009-04-03 11:09:46 -0700 | [diff] [blame] | 688 | |
| 689 | if (checkDexSum) { |
| 690 | /* perform additional DEX checksum tests */ |
| 691 | opt.optionString = "-Xcheckdexsum"; |
| 692 | mOptions.add(opt); |
| 693 | } |
| 694 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 695 | if (logStdio) { |
| 696 | /* convert stdout/stderr to log messages */ |
| 697 | opt.optionString = "-Xlog-stdio"; |
| 698 | mOptions.add(opt); |
| 699 | } |
| 700 | |
| 701 | if (enableAssertBuf[4] != '\0') { |
| 702 | /* accept "all" to mean "all classes and packages" */ |
| 703 | if (strcmp(enableAssertBuf+4, "all") == 0) |
| 704 | enableAssertBuf[3] = '\0'; |
| 705 | LOGI("Assertions enabled: '%s'\n", enableAssertBuf); |
| 706 | opt.optionString = enableAssertBuf; |
| 707 | mOptions.add(opt); |
| 708 | } else { |
| 709 | LOGV("Assertions disabled\n"); |
| 710 | } |
| 711 | |
| 712 | if (jniOptsBuf[10] != '\0') { |
| 713 | LOGI("JNI options: '%s'\n", jniOptsBuf); |
| 714 | opt.optionString = jniOptsBuf; |
| 715 | mOptions.add(opt); |
| 716 | } |
| 717 | |
| 718 | if (stackTraceFileBuf[0] != '\0') { |
| 719 | static const char* stfOptName = "-Xstacktracefile:"; |
| 720 | |
| 721 | stackTraceFile = (char*) malloc(strlen(stfOptName) + |
| 722 | strlen(stackTraceFileBuf) +1); |
| 723 | strcpy(stackTraceFile, stfOptName); |
| 724 | strcat(stackTraceFile, stackTraceFileBuf); |
| 725 | opt.optionString = stackTraceFile; |
| 726 | mOptions.add(opt); |
| 727 | } |
Andy McFadden | e4d81f2 | 2010-07-14 16:02:20 -0700 | [diff] [blame] | 728 | |
| 729 | /* extra options; parse this late so it overrides others */ |
| 730 | property_get("dalvik.vm.extra-opts", extraOptsBuf, ""); |
| 731 | parseExtraOpts(extraOptsBuf); |
| 732 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 733 | /* Set the properties for locale */ |
| 734 | { |
| 735 | char langOption[sizeof("-Duser.language=") + 3]; |
| 736 | char regionOption[sizeof("-Duser.region=") + 3]; |
| 737 | strcpy(langOption, "-Duser.language="); |
| 738 | strcpy(regionOption, "-Duser.region="); |
| 739 | readLocale(langOption, regionOption); |
| 740 | opt.extraInfo = NULL; |
| 741 | opt.optionString = langOption; |
| 742 | mOptions.add(opt); |
| 743 | opt.optionString = regionOption; |
| 744 | mOptions.add(opt); |
| 745 | } |
| 746 | |
| 747 | /* |
| 748 | * We don't have /tmp on the device, but we often have an SD card. Apps |
| 749 | * shouldn't use this, but some test suites might want to exercise it. |
| 750 | */ |
| 751 | opt.optionString = "-Djava.io.tmpdir=/sdcard"; |
| 752 | mOptions.add(opt); |
| 753 | |
| 754 | initArgs.version = JNI_VERSION_1_4; |
| 755 | initArgs.options = mOptions.editArray(); |
| 756 | initArgs.nOptions = mOptions.size(); |
| 757 | initArgs.ignoreUnrecognized = JNI_FALSE; |
| 758 | |
| 759 | /* |
| 760 | * Initialize the VM. |
| 761 | * |
| 762 | * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread. |
| 763 | * If this call succeeds, the VM is ready, and we can start issuing |
| 764 | * JNI calls. |
| 765 | */ |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 766 | if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 767 | LOGE("JNI_CreateJavaVM failed\n"); |
| 768 | goto bail; |
| 769 | } |
| 770 | |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 771 | result = 0; |
| 772 | |
| 773 | bail: |
| 774 | free(stackTraceFile); |
| 775 | return result; |
| 776 | } |
| 777 | |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 778 | char* AndroidRuntime::toSlashClassName(const char* className) |
| 779 | { |
| 780 | char* result = strdup(className); |
| 781 | for (char* cp = result; *cp != '\0'; cp++) { |
| 782 | if (*cp == '.') { |
| 783 | *cp = '/'; |
| 784 | } |
| 785 | } |
| 786 | return result; |
| 787 | } |
| 788 | |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 789 | /* |
| 790 | * Start the Android runtime. This involves starting the virtual machine |
| 791 | * and calling the "static void main(String[] args)" method in the class |
| 792 | * named by "className". |
Jeff Brown | ebed7d6 | 2011-05-16 17:08:42 -0700 | [diff] [blame] | 793 | * |
| 794 | * Passes the main function two arguments, the class name and the specified |
| 795 | * options string. |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 796 | */ |
Jeff Brown | ebed7d6 | 2011-05-16 17:08:42 -0700 | [diff] [blame] | 797 | void AndroidRuntime::start(const char* className, const char* options) |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 798 | { |
Dianne Hackborn | 08e60f2 | 2010-09-01 18:17:17 -0700 | [diff] [blame] | 799 | LOGD("\n>>>>>> AndroidRuntime START %s <<<<<<\n", |
| 800 | className != NULL ? className : "(unknown)"); |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 801 | |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 802 | blockSigpipe(); |
| 803 | |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 804 | /* |
| 805 | * 'startSystemServer == true' means runtime is obsolete and not run from |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 806 | * init.rc anymore, so we print out the boot start event here. |
| 807 | */ |
Jeff Brown | ebed7d6 | 2011-05-16 17:08:42 -0700 | [diff] [blame] | 808 | if (strcmp(options, "start-system-server") == 0) { |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 809 | /* track our progress through the boot sequence */ |
| 810 | const int LOG_BOOT_PROGRESS_START = 3000; |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 811 | LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 812 | ns2ms(systemTime(SYSTEM_TIME_MONOTONIC))); |
| 813 | } |
| 814 | |
| 815 | const char* rootDir = getenv("ANDROID_ROOT"); |
| 816 | if (rootDir == NULL) { |
| 817 | rootDir = "/system"; |
| 818 | if (!hasDir("/system")) { |
| 819 | LOG_FATAL("No root directory specified, and /android does not exist."); |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 820 | return; |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 821 | } |
| 822 | setenv("ANDROID_ROOT", rootDir, 1); |
| 823 | } |
| 824 | |
| 825 | //const char* kernelHack = getenv("LD_ASSUME_KERNEL"); |
| 826 | //LOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack); |
| 827 | |
| 828 | /* start the virtual machine */ |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 829 | JNIEnv* env; |
| 830 | if (startVm(&mJavaVM, &env) != 0) { |
| 831 | return; |
| 832 | } |
| 833 | onVmCreated(env); |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 834 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 835 | /* |
| 836 | * Register android functions. |
| 837 | */ |
| 838 | if (startReg(env) < 0) { |
| 839 | LOGE("Unable to register all android natives\n"); |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 840 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | /* |
| 844 | * We want to call main() with a String array with arguments in it. |
Jeff Brown | ebed7d6 | 2011-05-16 17:08:42 -0700 | [diff] [blame] | 845 | * At present we have two arguments, the class name and an option string. |
| 846 | * Create an array to hold them. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 847 | */ |
| 848 | jclass stringClass; |
| 849 | jobjectArray strArray; |
| 850 | jstring classNameStr; |
Jeff Brown | ebed7d6 | 2011-05-16 17:08:42 -0700 | [diff] [blame] | 851 | jstring optionsStr; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | |
| 853 | stringClass = env->FindClass("java/lang/String"); |
| 854 | assert(stringClass != NULL); |
| 855 | strArray = env->NewObjectArray(2, stringClass, NULL); |
| 856 | assert(strArray != NULL); |
| 857 | classNameStr = env->NewStringUTF(className); |
| 858 | assert(classNameStr != NULL); |
| 859 | env->SetObjectArrayElement(strArray, 0, classNameStr); |
Jeff Brown | ebed7d6 | 2011-05-16 17:08:42 -0700 | [diff] [blame] | 860 | optionsStr = env->NewStringUTF(options); |
| 861 | env->SetObjectArrayElement(strArray, 1, optionsStr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 862 | |
| 863 | /* |
| 864 | * Start VM. This thread becomes the main thread of the VM, and will |
| 865 | * not return until the VM exits. |
| 866 | */ |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 867 | char* slashClassName = toSlashClassName(className); |
| 868 | jclass startClass = env->FindClass(slashClassName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 869 | if (startClass == NULL) { |
| 870 | LOGE("JavaVM unable to locate class '%s'\n", slashClassName); |
| 871 | /* keep going */ |
| 872 | } else { |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 873 | jmethodID startMeth = env->GetStaticMethodID(startClass, "main", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 874 | "([Ljava/lang/String;)V"); |
| 875 | if (startMeth == NULL) { |
| 876 | LOGE("JavaVM unable to find main() in '%s'\n", className); |
| 877 | /* keep going */ |
| 878 | } else { |
| 879 | env->CallStaticVoidMethod(startClass, startMeth, strArray); |
| 880 | |
| 881 | #if 0 |
| 882 | if (env->ExceptionCheck()) |
| 883 | threadExitUncaughtException(env); |
| 884 | #endif |
| 885 | } |
| 886 | } |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 887 | free(slashClassName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 888 | |
| 889 | LOGD("Shutting down VM\n"); |
| 890 | if (mJavaVM->DetachCurrentThread() != JNI_OK) |
| 891 | LOGW("Warning: unable to detach main thread\n"); |
| 892 | if (mJavaVM->DestroyJavaVM() != 0) |
| 893 | LOGW("Warning: VM did not shut down cleanly\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 894 | } |
| 895 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 896 | void AndroidRuntime::onExit(int code) |
| 897 | { |
Dianne Hackborn | 08e60f2 | 2010-09-01 18:17:17 -0700 | [diff] [blame] | 898 | LOGV("AndroidRuntime onExit calling exit(%d)", code); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 899 | exit(code); |
| 900 | } |
| 901 | |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 902 | void AndroidRuntime::onVmCreated(JNIEnv* env) |
| 903 | { |
| 904 | // If AndroidRuntime had anything to do here, we'd have done it in 'start'. |
| 905 | } |
| 906 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 907 | /* |
| 908 | * Get the JNIEnv pointer for this thread. |
| 909 | * |
| 910 | * Returns NULL if the slot wasn't allocated or populated. |
| 911 | */ |
| 912 | /*static*/ JNIEnv* AndroidRuntime::getJNIEnv() |
| 913 | { |
| 914 | JNIEnv* env; |
| 915 | JavaVM* vm = AndroidRuntime::getJavaVM(); |
| 916 | assert(vm != NULL); |
| 917 | |
| 918 | if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) |
| 919 | return NULL; |
| 920 | return env; |
| 921 | } |
| 922 | |
| 923 | /* |
| 924 | * Makes the current thread visible to the VM. |
| 925 | * |
| 926 | * The JNIEnv pointer returned is only valid for the current thread, and |
| 927 | * thus must be tucked into thread-local storage. |
| 928 | */ |
| 929 | static int javaAttachThread(const char* threadName, JNIEnv** pEnv) |
| 930 | { |
| 931 | JavaVMAttachArgs args; |
| 932 | JavaVM* vm; |
| 933 | jint result; |
| 934 | |
| 935 | vm = AndroidRuntime::getJavaVM(); |
| 936 | assert(vm != NULL); |
| 937 | |
| 938 | args.version = JNI_VERSION_1_4; |
| 939 | args.name = (char*) threadName; |
| 940 | args.group = NULL; |
| 941 | |
| 942 | result = vm->AttachCurrentThread(pEnv, (void*) &args); |
| 943 | if (result != JNI_OK) |
Andy McFadden | 701d916 | 2010-03-01 14:03:13 -0800 | [diff] [blame] | 944 | LOGI("NOTE: attach of thread '%s' failed\n", threadName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 945 | |
| 946 | return result; |
| 947 | } |
| 948 | |
| 949 | /* |
| 950 | * Detach the current thread from the set visible to the VM. |
| 951 | */ |
| 952 | static int javaDetachThread(void) |
| 953 | { |
| 954 | JavaVM* vm; |
| 955 | jint result; |
| 956 | |
| 957 | vm = AndroidRuntime::getJavaVM(); |
| 958 | assert(vm != NULL); |
| 959 | |
| 960 | result = vm->DetachCurrentThread(); |
| 961 | if (result != JNI_OK) |
| 962 | LOGE("ERROR: thread detach failed\n"); |
| 963 | return result; |
| 964 | } |
| 965 | |
| 966 | /* |
| 967 | * When starting a native thread that will be visible from the VM, we |
| 968 | * bounce through this to get the right attach/detach action. |
| 969 | * Note that this function calls free(args) |
| 970 | */ |
| 971 | /*static*/ int AndroidRuntime::javaThreadShell(void* args) { |
| 972 | void* start = ((void**)args)[0]; |
| 973 | void* userData = ((void **)args)[1]; |
| 974 | char* name = (char*) ((void **)args)[2]; // we own this storage |
| 975 | free(args); |
| 976 | JNIEnv* env; |
| 977 | int result; |
| 978 | |
| 979 | /* hook us into the VM */ |
| 980 | if (javaAttachThread(name, &env) != JNI_OK) |
| 981 | return -1; |
| 982 | |
| 983 | /* start the thread running */ |
| 984 | result = (*(android_thread_func_t)start)(userData); |
| 985 | |
| 986 | /* unhook us */ |
| 987 | javaDetachThread(); |
| 988 | free(name); |
| 989 | |
| 990 | return result; |
| 991 | } |
| 992 | |
| 993 | /* |
| 994 | * This is invoked from androidCreateThreadEtc() via the callback |
| 995 | * set with androidSetCreateThreadFunc(). |
| 996 | * |
| 997 | * We need to create the new thread in such a way that it gets hooked |
| 998 | * into the VM before it really starts executing. |
| 999 | */ |
| 1000 | /*static*/ int AndroidRuntime::javaCreateThreadEtc( |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 1001 | android_thread_func_t entryFunction, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1002 | void* userData, |
| 1003 | const char* threadName, |
| 1004 | int32_t threadPriority, |
| 1005 | size_t threadStackSize, |
| 1006 | android_thread_id_t* threadId) |
| 1007 | { |
| 1008 | void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free |
| 1009 | int result; |
| 1010 | |
| 1011 | assert(threadName != NULL); |
| 1012 | |
| 1013 | args[0] = (void*) entryFunction; |
| 1014 | args[1] = userData; |
| 1015 | args[2] = (void*) strdup(threadName); // javaThreadShell must free |
| 1016 | |
| 1017 | result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args, |
| 1018 | threadName, threadPriority, threadStackSize, threadId); |
| 1019 | return result; |
| 1020 | } |
| 1021 | |
| 1022 | /* |
| 1023 | * Create a thread that is visible from the VM. |
| 1024 | * |
| 1025 | * This is called from elsewhere in the library. |
| 1026 | */ |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 1027 | /*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1028 | void (*start)(void *), void* arg) |
| 1029 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 1030 | android_thread_id_t threadId = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | javaCreateThreadEtc((android_thread_func_t) start, arg, name, |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 1032 | ANDROID_PRIORITY_DEFAULT, 0, &threadId); |
| 1033 | return threadId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | #if 0 |
| 1037 | static void quickTest(void* arg) |
| 1038 | { |
| 1039 | const char* str = (const char*) arg; |
| 1040 | |
| 1041 | printf("In quickTest: %s\n", str); |
| 1042 | } |
| 1043 | #endif |
| 1044 | |
| 1045 | #ifdef NDEBUG |
| 1046 | #define REG_JNI(name) { name } |
| 1047 | struct RegJNIRec { |
| 1048 | int (*mProc)(JNIEnv*); |
| 1049 | }; |
| 1050 | #else |
| 1051 | #define REG_JNI(name) { name, #name } |
| 1052 | struct RegJNIRec { |
| 1053 | int (*mProc)(JNIEnv*); |
| 1054 | const char* mName; |
| 1055 | }; |
| 1056 | #endif |
| 1057 | |
| 1058 | typedef void (*RegJAMProc)(); |
| 1059 | |
| 1060 | static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env) |
| 1061 | { |
| 1062 | for (size_t i = 0; i < count; i++) { |
| 1063 | if (array[i].mProc(env) < 0) { |
| 1064 | #ifndef NDEBUG |
| 1065 | LOGD("----------!!! %s failed to load\n", array[i].mName); |
| 1066 | #endif |
| 1067 | return -1; |
| 1068 | } |
| 1069 | } |
| 1070 | return 0; |
| 1071 | } |
| 1072 | |
| 1073 | static void register_jam_procs(const RegJAMProc array[], size_t count) |
| 1074 | { |
| 1075 | for (size_t i = 0; i < count; i++) { |
| 1076 | array[i](); |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | static const RegJNIRec gRegJNI[] = { |
| 1081 | REG_JNI(register_android_debug_JNITest), |
| 1082 | REG_JNI(register_com_android_internal_os_RuntimeInit), |
| 1083 | REG_JNI(register_android_os_SystemClock), |
| 1084 | REG_JNI(register_android_util_EventLog), |
| 1085 | REG_JNI(register_android_util_Log), |
| 1086 | REG_JNI(register_android_util_FloatMath), |
| 1087 | REG_JNI(register_android_text_format_Time), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1088 | REG_JNI(register_android_content_AssetManager), |
| 1089 | REG_JNI(register_android_content_StringBlock), |
| 1090 | REG_JNI(register_android_content_XmlBlock), |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1091 | REG_JNI(register_android_emoji_EmojiFactory), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1092 | REG_JNI(register_android_text_AndroidCharacter), |
Doug Felt | dae8e94 | 2010-02-24 14:33:15 -0800 | [diff] [blame] | 1093 | REG_JNI(register_android_text_AndroidBidi), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1094 | REG_JNI(register_android_text_KeyCharacterMap), |
| 1095 | REG_JNI(register_android_os_Process), |
Andreas Huber | a8079bf | 2010-11-16 14:40:31 -0800 | [diff] [blame] | 1096 | REG_JNI(register_android_os_SystemProperties), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1097 | REG_JNI(register_android_os_Binder), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1098 | REG_JNI(register_android_view_Display), |
| 1099 | REG_JNI(register_android_nio_utils), |
| 1100 | REG_JNI(register_android_graphics_PixelFormat), |
| 1101 | REG_JNI(register_android_graphics_Graphics), |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1102 | REG_JNI(register_android_view_GLES20Canvas), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | REG_JNI(register_android_view_Surface), |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 1104 | REG_JNI(register_android_view_TextureView), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1105 | REG_JNI(register_com_google_android_gles_jni_EGLImpl), |
| 1106 | REG_JNI(register_com_google_android_gles_jni_GLImpl), |
Jack Palevich | 1c4907e | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 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), |
Jack Palevich | 560814f | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 1111 | REG_JNI(register_android_opengl_jni_GLES20), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1112 | |
| 1113 | REG_JNI(register_android_graphics_Bitmap), |
| 1114 | REG_JNI(register_android_graphics_BitmapFactory), |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 1115 | REG_JNI(register_android_graphics_BitmapRegionDecoder), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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), |
Jamie Gennis | aa0ce33 | 2011-01-06 17:04:26 -0800 | [diff] [blame] | 1135 | REG_JNI(register_android_graphics_SurfaceTexture), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1136 | REG_JNI(register_android_graphics_Typeface), |
| 1137 | REG_JNI(register_android_graphics_Xfermode), |
Wei-Ta Chen | bca2d61 | 2009-11-30 17:52:05 +0800 | [diff] [blame] | 1138 | REG_JNI(register_android_graphics_YuvImage), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1139 | |
| 1140 | REG_JNI(register_android_database_CursorWindow), |
Vasu Nori | 5a03f36 | 2009-10-20 15:16:35 -0700 | [diff] [blame] | 1141 | REG_JNI(register_android_database_SQLiteCompiledSql), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1142 | REG_JNI(register_android_database_SQLiteDatabase), |
| 1143 | REG_JNI(register_android_database_SQLiteDebug), |
| 1144 | REG_JNI(register_android_database_SQLiteProgram), |
| 1145 | REG_JNI(register_android_database_SQLiteQuery), |
| 1146 | REG_JNI(register_android_database_SQLiteStatement), |
| 1147 | REG_JNI(register_android_os_Debug), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1148 | REG_JNI(register_android_os_FileObserver), |
| 1149 | REG_JNI(register_android_os_FileUtils), |
Christopher Tate | fa9e7c0 | 2010-05-06 12:07:10 -0700 | [diff] [blame] | 1150 | REG_JNI(register_android_os_MessageQueue), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | REG_JNI(register_android_os_ParcelFileDescriptor), |
| 1152 | REG_JNI(register_android_os_Power), |
| 1153 | REG_JNI(register_android_os_StatFs), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1154 | REG_JNI(register_android_os_UEventObserver), |
| 1155 | REG_JNI(register_android_net_LocalSocketImpl), |
| 1156 | REG_JNI(register_android_net_NetworkUtils), |
Dan Egnor | 2b4abcd | 2010-04-07 17:30:50 -0700 | [diff] [blame] | 1157 | REG_JNI(register_android_net_TrafficStats), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1158 | REG_JNI(register_android_net_wifi_WifiManager), |
Nick Pelly | cd0e839 | 2010-10-13 17:25:24 -0700 | [diff] [blame] | 1159 | REG_JNI(register_android_nfc_NdefMessage), |
| 1160 | REG_JNI(register_android_nfc_NdefRecord), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1161 | REG_JNI(register_android_os_MemoryFile), |
| 1162 | REG_JNI(register_com_android_internal_os_ZygoteInit), |
| 1163 | REG_JNI(register_android_hardware_Camera), |
| 1164 | REG_JNI(register_android_hardware_SensorManager), |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 1165 | REG_JNI(register_android_hardware_UsbDevice), |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 1166 | REG_JNI(register_android_hardware_UsbDeviceConnection), |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 1167 | REG_JNI(register_android_hardware_UsbRequest), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1168 | REG_JNI(register_android_media_AudioRecord), |
| 1169 | REG_JNI(register_android_media_AudioSystem), |
| 1170 | REG_JNI(register_android_media_AudioTrack), |
| 1171 | REG_JNI(register_android_media_JetPlayer), |
| 1172 | REG_JNI(register_android_media_ToneGenerator), |
| 1173 | |
| 1174 | REG_JNI(register_android_opengl_classes), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1175 | REG_JNI(register_android_bluetooth_HeadsetBase), |
| 1176 | REG_JNI(register_android_bluetooth_BluetoothAudioGateway), |
Nick Pelly | 0b6955a | 2009-05-26 19:13:43 -0700 | [diff] [blame] | 1177 | REG_JNI(register_android_bluetooth_BluetoothSocket), |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 1178 | REG_JNI(register_android_server_BluetoothService), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1179 | REG_JNI(register_android_server_BluetoothEventLoop), |
| 1180 | REG_JNI(register_android_server_BluetoothA2dpService), |
Christopher Tate | ecaa7b4 | 2010-06-04 14:55:02 -0700 | [diff] [blame] | 1181 | REG_JNI(register_android_server_Watchdog), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1182 | REG_JNI(register_android_ddm_DdmHandleNativeHeap), |
Joe Onorato | 1cf5874 | 2009-06-12 11:06:24 -0700 | [diff] [blame] | 1183 | REG_JNI(register_android_backup_BackupDataInput), |
Joe Onorato | d2110db | 2009-05-19 13:41:21 -0700 | [diff] [blame] | 1184 | REG_JNI(register_android_backup_BackupDataOutput), |
Joe Onorato | 06290a4 | 2009-06-18 20:10:37 -0700 | [diff] [blame] | 1185 | REG_JNI(register_android_backup_FileBackupHelperBase), |
Joe Onorato | 4ababd9 | 2009-06-25 18:29:18 -0400 | [diff] [blame] | 1186 | REG_JNI(register_android_backup_BackupHelperDispatcher), |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 1187 | REG_JNI(register_android_app_backup_FullBackup), |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1188 | REG_JNI(register_android_app_ActivityThread), |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 1189 | REG_JNI(register_android_app_NativeActivity), |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1190 | REG_JNI(register_android_view_InputChannel), |
| 1191 | REG_JNI(register_android_view_InputQueue), |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1192 | REG_JNI(register_android_view_KeyEvent), |
| 1193 | REG_JNI(register_android_view_MotionEvent), |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 1194 | REG_JNI(register_android_view_PointerIcon), |
Jeff Brown | 2ed2462 | 2011-03-14 19:39:54 -0700 | [diff] [blame] | 1195 | REG_JNI(register_android_view_VelocityTracker), |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 1196 | |
| 1197 | REG_JNI(register_android_content_res_ObbScanner), |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 1198 | REG_JNI(register_android_content_res_Configuration), |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 1199 | |
| 1200 | REG_JNI(register_android_animation_PropertyValuesHolder), |
Kenny Root | 66269ea | 2011-07-12 14:14:01 -0700 | [diff] [blame] | 1201 | REG_JNI(register_com_android_internal_content_NativeLibraryHelper), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1202 | }; |
| 1203 | |
| 1204 | /* |
| 1205 | * Register android native functions with the VM. |
| 1206 | */ |
| 1207 | /*static*/ int AndroidRuntime::startReg(JNIEnv* env) |
| 1208 | { |
| 1209 | /* |
| 1210 | * This hook causes all future threads created in this process to be |
| 1211 | * attached to the JavaVM. (This needs to go away in favor of JNI |
| 1212 | * Attach calls.) |
| 1213 | */ |
| 1214 | androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc); |
| 1215 | |
Dianne Hackborn | 08e60f2 | 2010-09-01 18:17:17 -0700 | [diff] [blame] | 1216 | LOGV("--- registering native functions ---\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1217 | |
| 1218 | /* |
| 1219 | * Every "register" function calls one or more things that return |
| 1220 | * a local reference (e.g. FindClass). Because we haven't really |
| 1221 | * started the VM yet, they're all getting stored in the base frame |
| 1222 | * and never released. Use Push/Pop to manage the storage. |
| 1223 | */ |
| 1224 | env->PushLocalFrame(200); |
| 1225 | |
| 1226 | if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) { |
| 1227 | env->PopLocalFrame(NULL); |
| 1228 | return -1; |
| 1229 | } |
| 1230 | env->PopLocalFrame(NULL); |
| 1231 | |
| 1232 | //createJavaThread("fubar", quickTest, (void*) "hello"); |
| 1233 | |
| 1234 | return 0; |
| 1235 | } |
| 1236 | |
| 1237 | AndroidRuntime* AndroidRuntime::getRuntime() |
| 1238 | { |
| 1239 | return gCurRuntime; |
| 1240 | } |
| 1241 | |
| 1242 | /** |
| 1243 | * Used by WithFramework to register native functions. |
| 1244 | */ |
| 1245 | extern "C" |
| 1246 | jint Java_com_android_internal_util_WithFramework_registerNatives( |
| 1247 | JNIEnv* env, jclass clazz) { |
| 1248 | return register_jni_procs(gRegJNI, NELEM(gRegJNI), env); |
| 1249 | } |
| 1250 | |
| 1251 | /** |
| 1252 | * Used by LoadClass to register native functions. |
| 1253 | */ |
| 1254 | extern "C" |
| 1255 | jint Java_LoadClass_registerNatives(JNIEnv* env, jclass clazz) { |
| 1256 | return register_jni_procs(gRegJNI, NELEM(gRegJNI), env); |
| 1257 | } |
| 1258 | |
| 1259 | } // namespace android |