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