blob: f964cd2e4816afdbfb3d2576b5427ebec77d36cc [file] [log] [blame]
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001/*
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 Project9066cfe2009-03-03 19:31:44 -080016
17#define LOG_TAG "AndroidRuntime"
18//#define LOG_NDEBUG 0
19
20#include <android_runtime/AndroidRuntime.h>
Mathias Agopian07952722009-05-19 19:08:10 -070021#include <binder/IBinder.h>
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -080022#include <binder/IPCThreadState.h>
Mathias Agopian07952722009-05-19 19:08:10 -070023#include <binder/IServiceManager.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024#include <utils/Log.h>
25#include <utils/misc.h>
Mathias Agopian07952722009-05-19 19:08:10 -070026#include <binder/Parcel.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027#include <utils/threads.h>
28#include <cutils/properties.h>
29
30#include <SkGraphics.h>
31#include <SkImageDecoder.h>
Mike Reedfc8db532009-04-27 11:43:30 -040032#include <SkImageRef_GlobalPool.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033
34#include "jni.h"
35#include "JNIHelp.h"
Brian Carlstrom9f8203a2013-06-19 13:49:36 -070036#include "JniInvocation.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037#include "android_util_Binder.h"
38
39#include <stdio.h>
40#include <signal.h>
41#include <sys/stat.h>
42#include <sys/types.h>
43#include <signal.h>
44#include <dirent.h>
45#include <assert.h>
46
47
48using namespace android;
49
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050extern int register_android_os_Binder(JNIEnv* env);
51extern int register_android_os_Process(JNIEnv* env);
52extern int register_android_graphics_Bitmap(JNIEnv*);
53extern int register_android_graphics_BitmapFactory(JNIEnv*);
Wei-Ta Chen6b849e22010-09-07 17:32:18 +080054extern int register_android_graphics_BitmapRegionDecoder(JNIEnv*);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055extern int register_android_graphics_Camera(JNIEnv* env);
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -040056extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057extern int register_android_graphics_Graphics(JNIEnv* env);
58extern int register_android_graphics_Interpolator(JNIEnv* env);
59extern int register_android_graphics_LayerRasterizer(JNIEnv*);
60extern int register_android_graphics_MaskFilter(JNIEnv* env);
61extern int register_android_graphics_Movie(JNIEnv* env);
62extern int register_android_graphics_NinePatch(JNIEnv*);
63extern int register_android_graphics_PathEffect(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064extern int register_android_graphics_Shader(JNIEnv* env);
65extern int register_android_graphics_Typeface(JNIEnv* env);
Wei-Ta Chenbca2d612009-11-30 17:52:05 +080066extern int register_android_graphics_YuvImage(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067
68extern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env);
69extern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070070extern int register_android_opengl_jni_EGL14(JNIEnv* env);
Jesse Hall237c2b82013-05-06 11:36:57 -070071extern int register_android_opengl_jni_EGLExt(JNIEnv* env);
Jack Palevich1c4907e2009-04-13 16:22:25 -070072extern int register_android_opengl_jni_GLES10(JNIEnv* env);
73extern int register_android_opengl_jni_GLES10Ext(JNIEnv* env);
74extern int register_android_opengl_jni_GLES11(JNIEnv* env);
75extern int register_android_opengl_jni_GLES11Ext(JNIEnv* env);
Jack Palevich560814f2009-11-19 16:34:55 +080076extern int register_android_opengl_jni_GLES20(JNIEnv* env);
Jesse Halld877efe2013-04-29 15:59:35 -070077extern int register_android_opengl_jni_GLES30(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078
79extern int register_android_hardware_Camera(JNIEnv *env);
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -070080extern int register_android_hardware_camera2_CameraMetadata(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081extern int register_android_hardware_SensorManager(JNIEnv *env);
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -040082extern int register_android_hardware_SerialPort(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -050083extern int register_android_hardware_UsbDevice(JNIEnv *env);
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050084extern int register_android_hardware_UsbDeviceConnection(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -050085extern int register_android_hardware_UsbRequest(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086
87extern int register_android_media_AudioRecord(JNIEnv *env);
88extern int register_android_media_AudioSystem(JNIEnv *env);
89extern int register_android_media_AudioTrack(JNIEnv *env);
90extern int register_android_media_JetPlayer(JNIEnv *env);
91extern int register_android_media_ToneGenerator(JNIEnv *env);
92
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093extern int register_android_util_FloatMath(JNIEnv* env);
94
95namespace android {
96
97/*
98 * JNI-based registration functions. Note these are properly contained in
99 * namespace android.
100 */
101extern int register_android_content_AssetManager(JNIEnv* env);
102extern int register_android_util_EventLog(JNIEnv* env);
103extern int register_android_util_Log(JNIEnv* env);
104extern int register_android_content_StringBlock(JNIEnv* env);
105extern int register_android_content_XmlBlock(JNIEnv* env);
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700106extern int register_android_emoji_EmojiFactory(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107extern int register_android_graphics_Canvas(JNIEnv* env);
108extern int register_android_graphics_ColorFilter(JNIEnv* env);
109extern int register_android_graphics_DrawFilter(JNIEnv* env);
110extern int register_android_graphics_Matrix(JNIEnv* env);
111extern int register_android_graphics_Paint(JNIEnv* env);
112extern int register_android_graphics_Path(JNIEnv* env);
113extern int register_android_graphics_PathMeasure(JNIEnv* env);
114extern int register_android_graphics_Picture(JNIEnv*);
115extern int register_android_graphics_PorterDuff(JNIEnv* env);
116extern int register_android_graphics_Rasterizer(JNIEnv* env);
Jeff Brownfbf09772011-01-16 14:06:57 -0800117extern int register_android_graphics_Region(JNIEnv* env);
Jamie Gennisaa0ce332011-01-06 17:04:26 -0800118extern int register_android_graphics_SurfaceTexture(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119extern int register_android_graphics_Xfermode(JNIEnv* env);
Svetoslav6811f4e2013-09-18 15:58:28 -0700120extern int register_android_graphics_pdf_PdfDocument(JNIEnv* env);
Jeff Brown0a0a1242011-12-02 02:25:22 -0800121extern int register_android_view_DisplayEventReceiver(JNIEnv* env);
John Reckf666ad72014-03-14 16:24:57 -0700122extern int register_android_view_RenderNode(JNIEnv* env);
John Recke45b1fd2014-04-15 09:50:16 -0700123extern int register_android_view_RenderNodeAnimator(JNIEnv* env);
Romain Guy3b748a42013-04-17 18:54:38 -0700124extern int register_android_view_GraphicBuffer(JNIEnv* env);
Romain Guye4d01122010-06-16 18:44:05 -0700125extern int register_android_view_GLES20Canvas(JNIEnv* env);
John Reck30835792013-11-07 14:21:24 -0800126extern int register_android_view_GLRenderer(JNIEnv* env);
John Reck04fc5832014-02-05 16:38:25 -0800127extern int register_android_view_HardwareLayer(JNIEnv* env);
John Reckcec24ae2013-11-05 13:27:50 -0800128extern int register_android_view_ThreadedRenderer(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129extern int register_android_view_Surface(JNIEnv* env);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800130extern int register_android_view_SurfaceControl(JNIEnv* env);
Jeff Brown64a55af2012-08-26 02:47:39 -0700131extern int register_android_view_SurfaceSession(JNIEnv* env);
Romain Guy8f0095c2011-05-02 17:24:22 -0700132extern int register_android_view_TextureView(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133extern int register_android_database_CursorWindow(JNIEnv* env);
Jeff Browne5360fb2011-10-31 17:48:13 -0700134extern int register_android_database_SQLiteConnection(JNIEnv* env);
135extern int register_android_database_SQLiteGlobal(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136extern int register_android_database_SQLiteDebug(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137extern int register_android_nio_utils(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138extern int register_android_text_format_Time(JNIEnv* env);
139extern int register_android_os_Debug(JNIEnv* env);
Christopher Tatefa9e7c02010-05-06 12:07:10 -0700140extern int register_android_os_MessageQueue(JNIEnv* env);
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -0800141extern int register_android_os_Parcel(JNIEnv* env);
Stephen Smalleyc07fca32012-01-13 08:31:39 -0500142extern int register_android_os_SELinux(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143extern int register_android_os_SystemProperties(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144extern int register_android_os_SystemClock(JNIEnv* env);
Jeff Brown481c1572012-03-09 14:41:15 -0800145extern int register_android_os_Trace(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146extern int register_android_os_FileObserver(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147extern int register_android_os_UEventObserver(JNIEnv* env);
148extern int register_android_os_MemoryFile(JNIEnv* env);
149extern int register_android_net_LocalSocketImpl(JNIEnv* env);
150extern int register_android_net_NetworkUtils(JNIEnv* env);
Dan Egnor2b4abcd2010-04-07 17:30:50 -0700151extern int register_android_net_TrafficStats(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152extern int register_android_text_AndroidCharacter(JNIEnv *env);
Doug Feltdae8e942010-02-24 14:33:15 -0800153extern int register_android_text_AndroidBidi(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154extern int register_android_opengl_classes(JNIEnv *env);
JP Abgrall98a4f7e2011-09-02 15:36:33 -0700155extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env);
Christopher Tateecaa7b42010-06-04 14:55:02 -0700156extern int register_android_server_Watchdog(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
158extern int register_com_android_internal_os_ZygoteInit(JNIEnv* env);
Joe Onorato1cf58742009-06-12 11:06:24 -0700159extern int register_android_backup_BackupDataInput(JNIEnv *env);
Joe Onoratod2110db2009-05-19 13:41:21 -0700160extern int register_android_backup_BackupDataOutput(JNIEnv *env);
Joe Onorato06290a42009-06-18 20:10:37 -0700161extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
Joe Onorato4ababd92009-06-25 18:29:18 -0400162extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
Christopher Tate4a627c72011-04-01 14:43:32 -0700163extern int register_android_app_backup_FullBackup(JNIEnv *env);
Chet Haase9c1e23b2011-03-24 10:51:31 -0700164extern int register_android_app_ActivityThread(JNIEnv *env);
Dianne Hackborn69969e42010-05-04 11:40:40 -0700165extern int register_android_app_NativeActivity(JNIEnv *env);
Jeff Browncbad9762012-09-04 21:57:59 -0700166extern int register_android_media_RemoteDisplay(JNIEnv *env);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700167extern int register_android_view_InputChannel(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700168extern int register_android_view_InputDevice(JNIEnv* env);
Jeff Brown32cbc38552011-12-01 14:01:49 -0800169extern int register_android_view_InputEventReceiver(JNIEnv* env);
Jeff Brownc28867a2013-03-26 15:42:39 -0700170extern int register_android_view_InputEventSender(JNIEnv* env);
Michael Wrighta44dd262013-04-10 21:12:00 -0700171extern int register_android_view_InputQueue(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700172extern int register_android_view_KeyCharacterMap(JNIEnv *env);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700173extern int register_android_view_KeyEvent(JNIEnv* env);
174extern int register_android_view_MotionEvent(JNIEnv* env);
Jeff Brown2352b972011-04-12 22:39:53 -0700175extern int register_android_view_PointerIcon(JNIEnv* env);
Jeff Brown2ed24622011-03-14 19:39:54 -0700176extern int register_android_view_VelocityTracker(JNIEnv* env);
Kenny Root02c87302010-07-01 08:10:18 -0700177extern int register_android_content_res_ObbScanner(JNIEnv* env);
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700178extern int register_android_content_res_Configuration(JNIEnv* env);
Chet Haase6e0ecb42010-11-03 19:41:18 -0700179extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
Kenny Root66269ea2011-07-12 14:14:01 -0700180extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -0800181extern int register_com_android_internal_net_NetworkStatsFactory(JNIEnv *env);
Narayan Kamath973b4662014-03-31 13:41:26 +0100182extern int register_com_android_internal_os_Zygote(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183
184static AndroidRuntime* gCurRuntime = NULL;
185
186static 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 Brown16f5f5c2012-03-15 16:53:55 -0700195static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196{
197 gCurRuntime->onStarted();
198}
199
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700200static void com_android_internal_os_RuntimeInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201{
202 gCurRuntime->onZygoteInit();
203}
204
Jeff Brown4280c4a2012-03-15 17:48:02 -0700205static 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 Project9066cfe2009-03-03 19:31:44 -0800211/*
212 * JNI registration.
213 */
214static JNINativeMethod gMethods[] = {
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700215 { "nativeFinishInit", "()V",
216 (void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
217 { "nativeZygoteInit", "()V",
218 (void*) com_android_internal_os_RuntimeInit_nativeZygoteInit },
Jeff Brown4280c4a2012-03-15 17:48:02 -0700219 { "nativeSetExitWithoutCleanup", "(Z)V",
220 (void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221};
222
223int 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
Andreas Huber9ae000c2014-02-13 17:22:33 +0000231/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
232
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000233AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) :
234 mExitWithoutCleanup(false),
235 mArgBlockStart(argBlockStart),
236 mArgBlockLength(argBlockLength)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700238 SkGraphics::Init();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 // this sets our preference for 16bit images during decode
240 // in case the src is opaque and 24bit
241 SkImageDecoder::SetDeviceConfig(SkBitmap::kRGB_565_Config);
Mike Reedfc8db532009-04-27 11:43:30 -0400242 // This cache is shared between browser native images, and java "purgeable"
243 // bitmaps. This globalpool is for images that do not either use the java
244 // heap, or are not backed by ashmem. See BitmapFactory.cpp for the key
245 // java call site.
246 SkImageRef_GlobalPool::SetRAMBudget(512 * 1024);
247 // There is also a global font cache, but its budget is specified in code
248 // see SkFontHost_android.cpp
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249
250 // Pre-allocate enough space to hold a fair number of options.
251 mOptions.setCapacity(20);
252
253 assert(gCurRuntime == NULL); // one per process
254 gCurRuntime = this;
255}
256
257AndroidRuntime::~AndroidRuntime()
258{
259 SkGraphics::Term();
260}
261
Andreas Huber9ae000c2014-02-13 17:22:33 +0000262/*
263 * Register native methods using JNI.
264 */
265/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
266 const char* className, const JNINativeMethod* gMethods, int numMethods)
267{
268 return jniRegisterNativeMethods(env, className, gMethods, numMethods);
269}
270
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000271void AndroidRuntime::setArgv0(const char* argv0) {
272 strlcpy(mArgBlockStart, argv0, mArgBlockLength);
273}
274
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100275status_t AndroidRuntime::callMain(const String8& className, jclass clazz,
276 const Vector<String8>& args)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277{
278 JNIEnv* env;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 jmethodID methodId;
280
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100281 ALOGD("Calling main entry %s", className.string());
Dianne Hackborn08e60f22010-09-01 18:17:17 -0700282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 env = getJNIEnv();
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700284 if (clazz == NULL || env == NULL) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 return UNKNOWN_ERROR;
286 }
287
288 methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
289 if (methodId == NULL) {
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100290 ALOGE("ERROR: could not find method %s.main(String[])\n", className.string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291 return UNKNOWN_ERROR;
292 }
293
294 /*
295 * We want to call main() with a String array with our arguments in it.
296 * Create an array and populate it.
297 */
298 jclass stringClass;
299 jobjectArray strArray;
300
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100301 const size_t numArgs = args.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 stringClass = env->FindClass("java/lang/String");
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100303 strArray = env->NewObjectArray(numArgs, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100305 for (size_t i = 0; i < numArgs; i++) {
306 jstring argStr = env->NewStringUTF(args[i].string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 env->SetObjectArrayElement(strArray, i, argStr);
308 }
309
310 env->CallStaticVoidMethod(clazz, methodId, strArray);
311 return NO_ERROR;
312}
313
314/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 * The VM calls this through the "exit" hook.
316 */
317static void runtime_exit(int code)
318{
Jeff Brown4280c4a2012-03-15 17:48:02 -0700319 gCurRuntime->exit(code);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320}
321
322/*
323 * The VM calls this through the "vfprintf" hook.
324 *
325 * We ignore "fp" and just write the results to the log file.
326 */
327static void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
328{
329 LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
330}
331
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800332/**
333 * The VM calls this when mutex contention debugging is enabled to
334 * determine whether or not the blocked thread was a "sensitive thread"
335 * for user responsiveness/smoothess.
336 *
337 * Our policy for this is whether or not we're tracing any StrictMode
338 * events on this thread (which we might've inherited via Binder calls
339 * into us)
340 */
341static bool runtime_isSensitiveThread() {
342 IPCThreadState* state = IPCThreadState::selfOrNull();
343 return state && state->getStrictModePolicy() != 0;
344}
345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346
347/**
348 * Add VM arguments to the to-be-executed VM
349 * Stops at first non '-' argument (also stops at an argument of '--')
350 * Returns the number of args consumed
351 */
352int AndroidRuntime::addVmArguments(int argc, const char* const argv[])
353{
354 int i;
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 for (i = 0; i<argc; i++) {
357 if (argv[i][0] != '-') {
358 return i;
359 }
360 if (argv[i][1] == '-' && argv[i][2] == 0) {
361 return i+1;
362 }
363
364 JavaVMOption opt;
365 memset(&opt, 0, sizeof(opt));
366 opt.optionString = (char*)argv[i];
367 mOptions.add(opt);
368 }
369 return i;
370}
371
372static int hasDir(const char* dir)
373{
374 struct stat s;
375 int res = stat(dir, &s);
376 if (res == 0) {
377 return S_ISDIR(s.st_mode);
378 }
379 return 0;
380}
381
382/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 * Read the persistent locale.
384 */
385static void readLocale(char* language, char* region)
386{
387 char propLang[PROPERTY_VALUE_MAX], propRegn[PROPERTY_VALUE_MAX];
Brian Carlstrom171ea892010-08-24 21:27:52 -0700388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 property_get("persist.sys.language", propLang, "");
390 property_get("persist.sys.country", propRegn, "");
391 if (*propLang == 0 && *propRegn == 0) {
392 /* Set to ro properties, default is en_US */
393 property_get("ro.product.locale.language", propLang, "en");
394 property_get("ro.product.locale.region", propRegn, "US");
395 }
396 strncat(language, propLang, 2);
397 strncat(region, propRegn, 2);
Steve Block5baa3a62011-12-20 16:23:08 +0000398 //ALOGD("language=%s region=%s\n", language, region);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399}
400
Andy McFaddenf70188a2009-03-31 15:52:13 -0700401/*
Andy McFaddene4d81f22010-07-14 16:02:20 -0700402 * Parse a property containing space-separated options that should be
403 * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
404 *
405 * This will cut up "extraOptsBuf" as we chop it into individual options.
406 *
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800407 * If "quotingArg" is non-null, it is passed before each extra option in mOptions.
408 *
Andy McFaddene4d81f22010-07-14 16:02:20 -0700409 * Adds the strings, if any, to mOptions.
410 */
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800411void AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg)
Andy McFaddene4d81f22010-07-14 16:02:20 -0700412{
413 JavaVMOption opt;
Andy McFaddene4d81f22010-07-14 16:02:20 -0700414 memset(&opt, 0, sizeof(opt));
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800415 char* start = extraOptsBuf;
416 char* end = NULL;
Andy McFaddene4d81f22010-07-14 16:02:20 -0700417 while (*start != '\0') {
418 while (*start == ' ') /* skip leading whitespace */
419 start++;
420 if (*start == '\0') /* was trailing ws, bail */
421 break;
422
423 end = start+1;
424 while (*end != ' ' && *end != '\0') /* find end of token */
425 end++;
426 if (*end == ' ')
427 *end++ = '\0'; /* mark end, advance to indicate more */
428
429 opt.optionString = start;
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800430 if (quotingArg != NULL) {
431 JavaVMOption quotingOpt;
432 quotingOpt.optionString = quotingArg;
433 mOptions.add(quotingOpt);
434 }
Andy McFaddene4d81f22010-07-14 16:02:20 -0700435 mOptions.add(opt);
436 start = end;
437 }
438}
439
440/*
Andy McFaddenf70188a2009-03-31 15:52:13 -0700441 * Start the Dalvik Virtual Machine.
442 *
443 * Various arguments, most determined by system properties, are passed in.
444 * The "mOptions" vector is updated.
445 *
Dave Allison07a1e232014-03-14 08:54:33 -0700446 * CAUTION: when adding options in here, be careful not to put the
447 * char buffer inside a nested scope. Adding the buffer to the
448 * options using mOptions.add() does not copy the buffer, so if the
449 * buffer goes out of scope the option may be overwritten. It's best
450 * to put the buffer at the top of the function so that it is more
451 * unlikely that someone will surround it in a scope at a later time
452 * and thus introduce a bug.
453 *
Andy McFaddenf70188a2009-03-31 15:52:13 -0700454 * Returns 0 on success.
455 */
456int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457{
Andy McFaddenf70188a2009-03-31 15:52:13 -0700458 int result = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 JavaVMInitArgs initArgs;
460 JavaVMOption opt;
461 char propBuf[PROPERTY_VALUE_MAX];
462 char stackTraceFileBuf[PROPERTY_VALUE_MAX];
463 char dexoptFlagsBuf[PROPERTY_VALUE_MAX];
464 char enableAssertBuf[sizeof("-ea:")-1 + PROPERTY_VALUE_MAX];
465 char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro38cfa8c2010-12-07 16:48:29 -0800466 char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700467 char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro8cdf27c2011-01-19 12:33:12 -0800468 char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700469 char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
470 char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier7e4fdec2013-12-02 15:46:51 -0800471 char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700472 char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
buzbeeb63de6d2013-05-24 13:14:08 -0700473 char jitcodecachesizeOptsBuf[sizeof("-Xjitcodecachesize:")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800474 char dalvikVmLibBuf[PROPERTY_VALUE_MAX];
475 char dex2oatFlagsBuf[PROPERTY_VALUE_MAX];
476 char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX];
Andy McFaddene4d81f22010-07-14 16:02:20 -0700477 char extraOptsBuf[PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478 char* stackTraceFile = NULL;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479 bool checkJni = false;
Andy McFaddene2b23e12009-04-03 11:09:46 -0700480 bool checkDexSum = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481 bool logStdio = false;
Ben Cheng52b0e732009-06-19 13:31:12 -0700482 enum {
483 kEMDefault,
484 kEMIntPortable,
485 kEMIntFast,
Ben Cheng52b0e732009-06-19 13:31:12 -0700486 kEMJitCompiler,
Ben Cheng52b0e732009-06-19 13:31:12 -0700487 } executionMode = kEMDefault;
Dave Allison07a1e232014-03-14 08:54:33 -0700488 char profile_period[sizeof("-Xprofile-period:") + PROPERTY_VALUE_MAX];
489 char profile_duration[sizeof("-Xprofile-duration:") + PROPERTY_VALUE_MAX];
490 char profile_interval[sizeof("-Xprofile-interval:") + PROPERTY_VALUE_MAX];
491 char profile_backoff[sizeof("-Xprofile-backoff:") + PROPERTY_VALUE_MAX];
492 char langOption[sizeof("-Duser.language=") + 3];
493 char regionOption[sizeof("-Duser.region=") + 3];
494 char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:") + sizeof(propBuf)];
495 char jitOpBuf[sizeof("-Xjitop:") + PROPERTY_VALUE_MAX];
496 char jitMethodBuf[sizeof("-Xjitmethod:") + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497
498 property_get("dalvik.vm.checkjni", propBuf, "");
499 if (strcmp(propBuf, "true") == 0) {
500 checkJni = true;
501 } else if (strcmp(propBuf, "false") != 0) {
502 /* property is neither true nor false; fall back on kernel parameter */
503 property_get("ro.kernel.android.checkjni", propBuf, "");
504 if (propBuf[0] == '1') {
505 checkJni = true;
506 }
507 }
508
509 property_get("dalvik.vm.execution-mode", propBuf, "");
510 if (strcmp(propBuf, "int:portable") == 0) {
511 executionMode = kEMIntPortable;
512 } else if (strcmp(propBuf, "int:fast") == 0) {
513 executionMode = kEMIntFast;
Ben Cheng52b0e732009-06-19 13:31:12 -0700514 } else if (strcmp(propBuf, "int:jit") == 0) {
515 executionMode = kEMJitCompiler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 }
517
518 property_get("dalvik.vm.stack-trace-file", stackTraceFileBuf, "");
519
Andy McFaddene2b23e12009-04-03 11:09:46 -0700520 property_get("dalvik.vm.check-dex-sum", propBuf, "");
521 if (strcmp(propBuf, "true") == 0) {
522 checkDexSum = true;
523 }
524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525 property_get("log.redirect-stdio", propBuf, "");
526 if (strcmp(propBuf, "true") == 0) {
527 logStdio = true;
528 }
529
530 strcpy(enableAssertBuf, "-ea:");
531 property_get("dalvik.vm.enableassertions", enableAssertBuf+4, "");
532
533 strcpy(jniOptsBuf, "-Xjniopts:");
534 property_get("dalvik.vm.jniopts", jniOptsBuf+10, "");
535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 /* route exit() to our handler */
537 opt.extraInfo = (void*) runtime_exit;
538 opt.optionString = "exit";
539 mOptions.add(opt);
540
541 /* route fprintf() to our handler */
542 opt.extraInfo = (void*) runtime_vfprintf;
543 opt.optionString = "vfprintf";
544 mOptions.add(opt);
545
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800546 /* register the framework-specific "is sensitive thread" hook */
547 opt.extraInfo = (void*) runtime_isSensitiveThread;
548 opt.optionString = "sensitiveThread";
549 mOptions.add(opt);
550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 opt.extraInfo = NULL;
552
553 /* enable verbose; standard options are { jni, gc, class } */
554 //options[curOpt++].optionString = "-verbose:jni";
555 opt.optionString = "-verbose:gc";
556 mOptions.add(opt);
557 //options[curOpt++].optionString = "-verbose:class";
558
Carl Shapiro9e4c8842010-12-08 12:14:46 -0800559 /*
560 * The default starting and maximum size of the heap. Larger
561 * values should be specified in a product property override.
562 */
Carl Shapiro38cfa8c2010-12-07 16:48:29 -0800563 strcpy(heapstartsizeOptsBuf, "-Xms");
Carl Shapiro9e4c8842010-12-08 12:14:46 -0800564 property_get("dalvik.vm.heapstartsize", heapstartsizeOptsBuf+4, "4m");
Carl Shapiro38cfa8c2010-12-07 16:48:29 -0800565 opt.optionString = heapstartsizeOptsBuf;
566 mOptions.add(opt);
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700567 strcpy(heapsizeOptsBuf, "-Xmx");
568 property_get("dalvik.vm.heapsize", heapsizeOptsBuf+4, "16m");
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700569 opt.optionString = heapsizeOptsBuf;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 mOptions.add(opt);
571
Elliott Hughes3f177d72012-04-12 16:02:56 -0700572 // Increase the main thread's interpreter stack size for bug 6315322.
573 opt.optionString = "-XX:mainThreadStackSize=24K";
574 mOptions.add(opt);
575
buzbeeb63de6d2013-05-24 13:14:08 -0700576 // Set the max jit code cache size. Note: size of 0 will disable the JIT.
577 strcpy(jitcodecachesizeOptsBuf, "-Xjitcodecachesize:");
578 property_get("dalvik.vm.jit.codecachesize", jitcodecachesizeOptsBuf+19, NULL);
579 if (jitcodecachesizeOptsBuf[19] != '\0') {
580 opt.optionString = jitcodecachesizeOptsBuf;
581 mOptions.add(opt);
582 }
583
Carl Shapiro8cdf27c2011-01-19 12:33:12 -0800584 strcpy(heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
585 property_get("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf+20, "");
586 if (heapgrowthlimitOptsBuf[20] != '\0') {
587 opt.optionString = heapgrowthlimitOptsBuf;
588 mOptions.add(opt);
589 }
590
Ian Rogers53250102012-09-23 16:38:03 -0700591 strcpy(heapminfreeOptsBuf, "-XX:HeapMinFree=");
592 property_get("dalvik.vm.heapminfree", heapminfreeOptsBuf+16, "");
593 if (heapminfreeOptsBuf[16] != '\0') {
594 opt.optionString = heapminfreeOptsBuf;
595 mOptions.add(opt);
596 }
597
598 strcpy(heapmaxfreeOptsBuf, "-XX:HeapMaxFree=");
599 property_get("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf+16, "");
600 if (heapmaxfreeOptsBuf[16] != '\0') {
601 opt.optionString = heapmaxfreeOptsBuf;
602 mOptions.add(opt);
603 }
604
605 strcpy(heaptargetutilizationOptsBuf, "-XX:HeapTargetUtilization=");
606 property_get("dalvik.vm.heaptargetutilization", heaptargetutilizationOptsBuf+26, "");
Ian Rogers7fef2b82012-10-01 14:54:24 -0700607 if (heaptargetutilizationOptsBuf[26] != '\0') {
Ian Rogers53250102012-09-23 16:38:03 -0700608 opt.optionString = heaptargetutilizationOptsBuf;
609 mOptions.add(opt);
610 }
611
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700612 property_get("ro.config.low_ram", propBuf, "");
613 if (strcmp(propBuf, "true") == 0) {
614 opt.optionString = "-XX:LowMemoryMode";
615 mOptions.add(opt);
616 }
617
Mathieu Chartier7e4fdec2013-12-02 15:46:51 -0800618 strcpy(gctypeOptsBuf, "-Xgc:");
619 property_get("dalvik.vm.gctype", gctypeOptsBuf+5, "");
620 if (gctypeOptsBuf[5] != '\0') {
621 opt.optionString = gctypeOptsBuf;
622 mOptions.add(opt);
623 }
624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 /*
626 * Enable or disable dexopt features, such as bytecode verification and
627 * calculation of register maps for precise GC.
628 */
629 property_get("dalvik.vm.dexopt-flags", dexoptFlagsBuf, "");
630 if (dexoptFlagsBuf[0] != '\0') {
631 const char* opc;
632 const char* val;
633
634 opc = strstr(dexoptFlagsBuf, "v="); /* verification */
635 if (opc != NULL) {
636 switch (*(opc+2)) {
637 case 'n': val = "-Xverify:none"; break;
638 case 'r': val = "-Xverify:remote"; break;
639 case 'a': val = "-Xverify:all"; break;
640 default: val = NULL; break;
641 }
642
643 if (val != NULL) {
644 opt.optionString = val;
645 mOptions.add(opt);
646 }
647 }
648
649 opc = strstr(dexoptFlagsBuf, "o="); /* optimization */
650 if (opc != NULL) {
651 switch (*(opc+2)) {
652 case 'n': val = "-Xdexopt:none"; break;
653 case 'v': val = "-Xdexopt:verified"; break;
654 case 'a': val = "-Xdexopt:all"; break;
Brian Carlstrom08065b92011-04-01 15:49:41 -0700655 case 'f': val = "-Xdexopt:full"; break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 default: val = NULL; break;
657 }
658
659 if (val != NULL) {
660 opt.optionString = val;
661 mOptions.add(opt);
662 }
663 }
664
665 opc = strstr(dexoptFlagsBuf, "m=y"); /* register map */
666 if (opc != NULL) {
667 opt.optionString = "-Xgenregmap";
668 mOptions.add(opt);
The Android Open Source Project7b0b1ed2009-03-18 22:20:26 -0700669
670 /* turn on precise GC while we're at it */
671 opt.optionString = "-Xgc:precise";
672 mOptions.add(opt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 }
674 }
675
676 /* enable debugging; set suspend=y to pause during VM init */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 /* use android ADB transport */
678 opt.optionString =
679 "-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800680 mOptions.add(opt);
681
Steve Block5baa3a62011-12-20 16:23:08 +0000682 ALOGD("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 if (checkJni) {
684 /* extended JNI checking */
685 opt.optionString = "-Xcheck:jni";
686 mOptions.add(opt);
687
688 /* set a cap on JNI global references */
689 opt.optionString = "-Xjnigreflimit:2000";
690 mOptions.add(opt);
691
692 /* with -Xcheck:jni, this provides a JNI function call trace */
693 //opt.optionString = "-verbose:jni";
694 //mOptions.add(opt);
695 }
Ben Cheng52b0e732009-06-19 13:31:12 -0700696
Carl Shapirod8f3ec62010-04-12 16:31:59 -0700697 property_get("dalvik.vm.lockprof.threshold", propBuf, "");
698 if (strlen(propBuf) > 0) {
699 strcpy(lockProfThresholdBuf, "-Xlockprofthreshold:");
700 strcat(lockProfThresholdBuf, propBuf);
701 opt.optionString = lockProfThresholdBuf;
702 mOptions.add(opt);
703 }
704
Ben Cheng52b0e732009-06-19 13:31:12 -0700705 /* Force interpreter-only mode for selected opcodes. Eg "1-0a,3c,f1-ff" */
Ben Cheng52b0e732009-06-19 13:31:12 -0700706 property_get("dalvik.vm.jit.op", propBuf, "");
707 if (strlen(propBuf) > 0) {
708 strcpy(jitOpBuf, "-Xjitop:");
709 strcat(jitOpBuf, propBuf);
710 opt.optionString = jitOpBuf;
711 mOptions.add(opt);
712 }
713
Ben Cheng52b0e732009-06-19 13:31:12 -0700714 /* Force interpreter-only mode for selected methods */
Ben Cheng52b0e732009-06-19 13:31:12 -0700715 property_get("dalvik.vm.jit.method", propBuf, "");
716 if (strlen(propBuf) > 0) {
717 strcpy(jitMethodBuf, "-Xjitmethod:");
718 strcat(jitMethodBuf, propBuf);
719 opt.optionString = jitMethodBuf;
720 mOptions.add(opt);
721 }
Ben Cheng52b0e732009-06-19 13:31:12 -0700722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800723 if (executionMode == kEMIntPortable) {
724 opt.optionString = "-Xint:portable";
725 mOptions.add(opt);
726 } else if (executionMode == kEMIntFast) {
727 opt.optionString = "-Xint:fast";
728 mOptions.add(opt);
Ben Cheng52b0e732009-06-19 13:31:12 -0700729 } else if (executionMode == kEMJitCompiler) {
730 opt.optionString = "-Xint:jit";
731 mOptions.add(opt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 }
Andy McFaddene2b23e12009-04-03 11:09:46 -0700733
734 if (checkDexSum) {
735 /* perform additional DEX checksum tests */
736 opt.optionString = "-Xcheckdexsum";
737 mOptions.add(opt);
738 }
739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800740 if (logStdio) {
741 /* convert stdout/stderr to log messages */
742 opt.optionString = "-Xlog-stdio";
743 mOptions.add(opt);
744 }
745
746 if (enableAssertBuf[4] != '\0') {
747 /* accept "all" to mean "all classes and packages" */
748 if (strcmp(enableAssertBuf+4, "all") == 0)
749 enableAssertBuf[3] = '\0';
Steve Block6215d3f2012-01-04 20:05:49 +0000750 ALOGI("Assertions enabled: '%s'\n", enableAssertBuf);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 opt.optionString = enableAssertBuf;
752 mOptions.add(opt);
753 } else {
Steve Block71f2cf12011-10-20 11:56:00 +0100754 ALOGV("Assertions disabled\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 }
756
757 if (jniOptsBuf[10] != '\0') {
Steve Block6215d3f2012-01-04 20:05:49 +0000758 ALOGI("JNI options: '%s'\n", jniOptsBuf);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 opt.optionString = jniOptsBuf;
760 mOptions.add(opt);
761 }
762
763 if (stackTraceFileBuf[0] != '\0') {
764 static const char* stfOptName = "-Xstacktracefile:";
765
766 stackTraceFile = (char*) malloc(strlen(stfOptName) +
767 strlen(stackTraceFileBuf) +1);
768 strcpy(stackTraceFile, stfOptName);
769 strcat(stackTraceFile, stackTraceFileBuf);
770 opt.optionString = stackTraceFile;
771 mOptions.add(opt);
772 }
Andy McFaddene4d81f22010-07-14 16:02:20 -0700773
Brian Carlstrom98ba7bd2014-03-10 10:20:01 -0700774 // libart tolerates libdvm flags, but not vice versa, so only pass some options if libart.
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800775 property_get("persist.sys.dalvik.vm.lib.1", dalvikVmLibBuf, "libdvm.so");
Brian Carlstrom98ba7bd2014-03-10 10:20:01 -0700776 bool libart = (strncmp(dalvikVmLibBuf, "libart", 6) == 0);
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800777
Brian Carlstrom98ba7bd2014-03-10 10:20:01 -0700778 if (libart) {
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800779 // Extra options for DexClassLoader.
780 property_get("dalvik.vm.dex2oat-flags", dex2oatFlagsBuf, "");
781 parseExtraOpts(dex2oatFlagsBuf, "-Xcompiler-option");
782
783 // Extra options for boot.art/boot.oat image generation.
784 property_get("dalvik.vm.image-dex2oat-flags", dex2oatImageFlagsBuf, "");
785 parseExtraOpts(dex2oatImageFlagsBuf, "-Ximage-compiler-option");
786 }
787
Andy McFaddene4d81f22010-07-14 16:02:20 -0700788 /* extra options; parse this late so it overrides others */
789 property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800790 parseExtraOpts(extraOptsBuf, NULL);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800792 /* Set the properties for locale */
793 {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 strcpy(langOption, "-Duser.language=");
795 strcpy(regionOption, "-Duser.region=");
796 readLocale(langOption, regionOption);
797 opt.extraInfo = NULL;
798 opt.optionString = langOption;
799 mOptions.add(opt);
800 opt.optionString = regionOption;
801 mOptions.add(opt);
802 }
803
Dave Allison0efbd9a2014-01-30 14:19:51 -0800804 /*
805 * Set profiler options
806 */
Brian Carlstrom98ba7bd2014-03-10 10:20:01 -0700807 if (libart) {
Dave Allison0efbd9a2014-01-30 14:19:51 -0800808 // Number of seconds during profile runs.
Dave Allison07a1e232014-03-14 08:54:33 -0700809 strcpy(profile_period, "-Xprofile-period:");
810 property_get("dalvik.vm.profile.period_secs", profile_period+17, "10");
811 opt.optionString = profile_period;
Dave Allison0efbd9a2014-01-30 14:19:51 -0800812 mOptions.add(opt);
813
814 // Length of each profile run (seconds).
Dave Allison07a1e232014-03-14 08:54:33 -0700815 strcpy(profile_duration, "-Xprofile-duration:");
816 property_get("dalvik.vm.profile.duration_secs", profile_duration+19, "30");
817 opt.optionString = profile_duration;
Dave Allison0efbd9a2014-01-30 14:19:51 -0800818 mOptions.add(opt);
819
820
821 // Polling interval during profile run (microseconds).
Dave Allison07a1e232014-03-14 08:54:33 -0700822 strcpy(profile_interval, "-Xprofile-interval:");
823 property_get("dalvik.vm.profile.interval_us", profile_interval+19, "10000");
824 opt.optionString = profile_interval;
Dave Allison0efbd9a2014-01-30 14:19:51 -0800825 mOptions.add(opt);
826
827 // Coefficient for period backoff. The the period is multiplied
828 // by this value after each profile run.
Dave Allison07a1e232014-03-14 08:54:33 -0700829 strcpy(profile_backoff, "-Xprofile-backoff:");
830 property_get("dalvik.vm.profile.backoff_coeff", profile_backoff+18, "2.0");
831 opt.optionString = profile_backoff;
Dave Allison0efbd9a2014-01-30 14:19:51 -0800832 mOptions.add(opt);
833 }
834
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800835 initArgs.version = JNI_VERSION_1_4;
836 initArgs.options = mOptions.editArray();
837 initArgs.nOptions = mOptions.size();
838 initArgs.ignoreUnrecognized = JNI_FALSE;
839
840 /*
841 * Initialize the VM.
842 *
843 * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread.
844 * If this call succeeds, the VM is ready, and we can start issuing
845 * JNI calls.
846 */
Andy McFaddenf70188a2009-03-31 15:52:13 -0700847 if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) {
Steve Block3762c312012-01-06 19:20:56 +0000848 ALOGE("JNI_CreateJavaVM failed\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 goto bail;
850 }
851
Andy McFaddenf70188a2009-03-31 15:52:13 -0700852 result = 0;
853
854bail:
855 free(stackTraceFile);
856 return result;
857}
858
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700859char* AndroidRuntime::toSlashClassName(const char* className)
860{
861 char* result = strdup(className);
862 for (char* cp = result; *cp != '\0'; cp++) {
863 if (*cp == '.') {
864 *cp = '/';
865 }
866 }
867 return result;
868}
869
Andy McFaddenf70188a2009-03-31 15:52:13 -0700870/*
871 * Start the Android runtime. This involves starting the virtual machine
872 * and calling the "static void main(String[] args)" method in the class
873 * named by "className".
Jeff Brownebed7d62011-05-16 17:08:42 -0700874 *
875 * Passes the main function two arguments, the class name and the specified
876 * options string.
Andy McFaddenf70188a2009-03-31 15:52:13 -0700877 */
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100878void AndroidRuntime::start(const char* className, const Vector<String8>& options)
Andy McFaddenf70188a2009-03-31 15:52:13 -0700879{
Steve Block5baa3a62011-12-20 16:23:08 +0000880 ALOGD("\n>>>>>> AndroidRuntime START %s <<<<<<\n",
Dianne Hackborn08e60f22010-09-01 18:17:17 -0700881 className != NULL ? className : "(unknown)");
Andy McFaddenf70188a2009-03-31 15:52:13 -0700882
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100883 static const String8 startSystemServer("start-system-server");
884
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700885 /*
886 * 'startSystemServer == true' means runtime is obsolete and not run from
Andy McFaddenf70188a2009-03-31 15:52:13 -0700887 * init.rc anymore, so we print out the boot start event here.
888 */
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100889 for (size_t i = 0; i < options.size(); ++i) {
890 if (options[i] == startSystemServer) {
891 /* track our progress through the boot sequence */
892 const int LOG_BOOT_PROGRESS_START = 3000;
893 LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));
894 }
Andy McFaddenf70188a2009-03-31 15:52:13 -0700895 }
896
897 const char* rootDir = getenv("ANDROID_ROOT");
898 if (rootDir == NULL) {
899 rootDir = "/system";
900 if (!hasDir("/system")) {
901 LOG_FATAL("No root directory specified, and /android does not exist.");
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700902 return;
Andy McFaddenf70188a2009-03-31 15:52:13 -0700903 }
904 setenv("ANDROID_ROOT", rootDir, 1);
905 }
906
907 //const char* kernelHack = getenv("LD_ASSUME_KERNEL");
Steve Block5baa3a62011-12-20 16:23:08 +0000908 //ALOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack);
Andy McFaddenf70188a2009-03-31 15:52:13 -0700909
910 /* start the virtual machine */
Brian Carlstrom9f8203a2013-06-19 13:49:36 -0700911 JniInvocation jni_invocation;
912 jni_invocation.Init(NULL);
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700913 JNIEnv* env;
914 if (startVm(&mJavaVM, &env) != 0) {
915 return;
916 }
917 onVmCreated(env);
Andy McFaddenf70188a2009-03-31 15:52:13 -0700918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 /*
920 * Register android functions.
921 */
922 if (startReg(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +0000923 ALOGE("Unable to register all android natives\n");
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700924 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 }
926
927 /*
928 * We want to call main() with a String array with arguments in it.
Jeff Brownebed7d62011-05-16 17:08:42 -0700929 * At present we have two arguments, the class name and an option string.
930 * Create an array to hold them.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 */
932 jclass stringClass;
933 jobjectArray strArray;
934 jstring classNameStr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935
936 stringClass = env->FindClass("java/lang/String");
937 assert(stringClass != NULL);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100938 strArray = env->NewObjectArray(options.size() + 1, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 assert(strArray != NULL);
940 classNameStr = env->NewStringUTF(className);
941 assert(classNameStr != NULL);
942 env->SetObjectArrayElement(strArray, 0, classNameStr);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100943
944 for (size_t i = 0; i < options.size(); ++i) {
945 jstring optionsStr = env->NewStringUTF(options.itemAt(i).string());
946 assert(optionsStr != NULL);
947 env->SetObjectArrayElement(strArray, i + 1, optionsStr);
948 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800949
950 /*
951 * Start VM. This thread becomes the main thread of the VM, and will
952 * not return until the VM exits.
953 */
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700954 char* slashClassName = toSlashClassName(className);
955 jclass startClass = env->FindClass(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 if (startClass == NULL) {
Steve Block3762c312012-01-06 19:20:56 +0000957 ALOGE("JavaVM unable to locate class '%s'\n", slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800958 /* keep going */
959 } else {
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700960 jmethodID startMeth = env->GetStaticMethodID(startClass, "main",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 "([Ljava/lang/String;)V");
962 if (startMeth == NULL) {
Steve Block3762c312012-01-06 19:20:56 +0000963 ALOGE("JavaVM unable to find main() in '%s'\n", className);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800964 /* keep going */
965 } else {
966 env->CallStaticVoidMethod(startClass, startMeth, strArray);
967
968#if 0
969 if (env->ExceptionCheck())
970 threadExitUncaughtException(env);
971#endif
972 }
973 }
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700974 free(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800975
Steve Block5baa3a62011-12-20 16:23:08 +0000976 ALOGD("Shutting down VM\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 if (mJavaVM->DetachCurrentThread() != JNI_OK)
Steve Block8564c8d2012-01-05 23:22:43 +0000978 ALOGW("Warning: unable to detach main thread\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 if (mJavaVM->DestroyJavaVM() != 0)
Steve Block8564c8d2012-01-05 23:22:43 +0000980 ALOGW("Warning: VM did not shut down cleanly\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981}
982
Jeff Brown4280c4a2012-03-15 17:48:02 -0700983void AndroidRuntime::exit(int code)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984{
Jeff Brown4280c4a2012-03-15 17:48:02 -0700985 if (mExitWithoutCleanup) {
986 ALOGI("VM exiting with result code %d, cleanup skipped.", code);
987 ::_exit(code);
988 } else {
989 ALOGI("VM exiting with result code %d.", code);
990 onExit(code);
991 ::exit(code);
992 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800993}
994
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700995void AndroidRuntime::onVmCreated(JNIEnv* env)
996{
997 // If AndroidRuntime had anything to do here, we'd have done it in 'start'.
998}
999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000/*
Andreas Huber9ae000c2014-02-13 17:22:33 +00001001 * Get the JNIEnv pointer for this thread.
1002 *
1003 * Returns NULL if the slot wasn't allocated or populated.
1004 */
1005/*static*/ JNIEnv* AndroidRuntime::getJNIEnv()
1006{
1007 JNIEnv* env;
1008 JavaVM* vm = AndroidRuntime::getJavaVM();
1009 assert(vm != NULL);
1010
1011 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
1012 return NULL;
1013 return env;
1014}
1015
1016/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017 * Makes the current thread visible to the VM.
1018 *
1019 * The JNIEnv pointer returned is only valid for the current thread, and
1020 * thus must be tucked into thread-local storage.
1021 */
1022static int javaAttachThread(const char* threadName, JNIEnv** pEnv)
1023{
1024 JavaVMAttachArgs args;
1025 JavaVM* vm;
1026 jint result;
1027
1028 vm = AndroidRuntime::getJavaVM();
1029 assert(vm != NULL);
1030
1031 args.version = JNI_VERSION_1_4;
1032 args.name = (char*) threadName;
1033 args.group = NULL;
1034
1035 result = vm->AttachCurrentThread(pEnv, (void*) &args);
1036 if (result != JNI_OK)
Steve Block6215d3f2012-01-04 20:05:49 +00001037 ALOGI("NOTE: attach of thread '%s' failed\n", threadName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001038
1039 return result;
1040}
1041
1042/*
1043 * Detach the current thread from the set visible to the VM.
1044 */
1045static int javaDetachThread(void)
1046{
1047 JavaVM* vm;
1048 jint result;
1049
1050 vm = AndroidRuntime::getJavaVM();
1051 assert(vm != NULL);
1052
1053 result = vm->DetachCurrentThread();
1054 if (result != JNI_OK)
Steve Block3762c312012-01-06 19:20:56 +00001055 ALOGE("ERROR: thread detach failed\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001056 return result;
1057}
1058
1059/*
1060 * When starting a native thread that will be visible from the VM, we
1061 * bounce through this to get the right attach/detach action.
1062 * Note that this function calls free(args)
1063 */
1064/*static*/ int AndroidRuntime::javaThreadShell(void* args) {
1065 void* start = ((void**)args)[0];
1066 void* userData = ((void **)args)[1];
1067 char* name = (char*) ((void **)args)[2]; // we own this storage
1068 free(args);
1069 JNIEnv* env;
1070 int result;
1071
1072 /* hook us into the VM */
1073 if (javaAttachThread(name, &env) != JNI_OK)
1074 return -1;
1075
1076 /* start the thread running */
1077 result = (*(android_thread_func_t)start)(userData);
1078
1079 /* unhook us */
1080 javaDetachThread();
1081 free(name);
1082
1083 return result;
1084}
1085
1086/*
1087 * This is invoked from androidCreateThreadEtc() via the callback
1088 * set with androidSetCreateThreadFunc().
1089 *
1090 * We need to create the new thread in such a way that it gets hooked
1091 * into the VM before it really starts executing.
1092 */
1093/*static*/ int AndroidRuntime::javaCreateThreadEtc(
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001094 android_thread_func_t entryFunction,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 void* userData,
1096 const char* threadName,
1097 int32_t threadPriority,
1098 size_t threadStackSize,
1099 android_thread_id_t* threadId)
1100{
1101 void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free
1102 int result;
1103
Mike Lockwood32f2e622013-10-10 10:11:27 -07001104 if (!threadName)
1105 threadName = "unnamed thread";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106
1107 args[0] = (void*) entryFunction;
1108 args[1] = userData;
1109 args[2] = (void*) strdup(threadName); // javaThreadShell must free
1110
1111 result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args,
1112 threadName, threadPriority, threadStackSize, threadId);
1113 return result;
1114}
1115
1116/*
1117 * Create a thread that is visible from the VM.
1118 *
1119 * This is called from elsewhere in the library.
1120 */
Mike Lockwoodf602d362010-06-20 14:28:16 -07001121/*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001122 void (*start)(void *), void* arg)
1123{
Mike Lockwoodf602d362010-06-20 14:28:16 -07001124 android_thread_id_t threadId = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125 javaCreateThreadEtc((android_thread_func_t) start, arg, name,
Mike Lockwoodf602d362010-06-20 14:28:16 -07001126 ANDROID_PRIORITY_DEFAULT, 0, &threadId);
1127 return threadId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128}
1129
1130#if 0
1131static void quickTest(void* arg)
1132{
1133 const char* str = (const char*) arg;
1134
1135 printf("In quickTest: %s\n", str);
1136}
1137#endif
1138
1139#ifdef NDEBUG
1140 #define REG_JNI(name) { name }
1141 struct RegJNIRec {
1142 int (*mProc)(JNIEnv*);
1143 };
1144#else
1145 #define REG_JNI(name) { name, #name }
1146 struct RegJNIRec {
1147 int (*mProc)(JNIEnv*);
1148 const char* mName;
1149 };
1150#endif
1151
1152typedef void (*RegJAMProc)();
1153
1154static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env)
1155{
1156 for (size_t i = 0; i < count; i++) {
1157 if (array[i].mProc(env) < 0) {
1158#ifndef NDEBUG
Steve Block5baa3a62011-12-20 16:23:08 +00001159 ALOGD("----------!!! %s failed to load\n", array[i].mName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160#endif
1161 return -1;
1162 }
1163 }
1164 return 0;
1165}
1166
1167static void register_jam_procs(const RegJAMProc array[], size_t count)
1168{
1169 for (size_t i = 0; i < count; i++) {
1170 array[i]();
1171 }
1172}
1173
1174static const RegJNIRec gRegJNI[] = {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 REG_JNI(register_com_android_internal_os_RuntimeInit),
1176 REG_JNI(register_android_os_SystemClock),
1177 REG_JNI(register_android_util_EventLog),
1178 REG_JNI(register_android_util_Log),
1179 REG_JNI(register_android_util_FloatMath),
1180 REG_JNI(register_android_text_format_Time),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001181 REG_JNI(register_android_content_AssetManager),
1182 REG_JNI(register_android_content_StringBlock),
1183 REG_JNI(register_android_content_XmlBlock),
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001184 REG_JNI(register_android_emoji_EmojiFactory),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001185 REG_JNI(register_android_text_AndroidCharacter),
Doug Feltdae8e942010-02-24 14:33:15 -08001186 REG_JNI(register_android_text_AndroidBidi),
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001187 REG_JNI(register_android_view_InputDevice),
1188 REG_JNI(register_android_view_KeyCharacterMap),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001189 REG_JNI(register_android_os_Process),
Andreas Hubera8079bf2010-11-16 14:40:31 -08001190 REG_JNI(register_android_os_SystemProperties),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001191 REG_JNI(register_android_os_Binder),
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -08001192 REG_JNI(register_android_os_Parcel),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193 REG_JNI(register_android_nio_utils),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001194 REG_JNI(register_android_graphics_Graphics),
Chris Craik54389792013-12-20 13:28:11 -08001195 REG_JNI(register_android_view_DisplayEventReceiver),
John Reckf666ad72014-03-14 16:24:57 -07001196 REG_JNI(register_android_view_RenderNode),
John Recke45b1fd2014-04-15 09:50:16 -07001197 REG_JNI(register_android_view_RenderNodeAnimator),
Romain Guy3b748a42013-04-17 18:54:38 -07001198 REG_JNI(register_android_view_GraphicBuffer),
Romain Guye4d01122010-06-16 18:44:05 -07001199 REG_JNI(register_android_view_GLES20Canvas),
John Reck30835792013-11-07 14:21:24 -08001200 REG_JNI(register_android_view_GLRenderer),
John Reck04fc5832014-02-05 16:38:25 -08001201 REG_JNI(register_android_view_HardwareLayer),
John Reckcec24ae2013-11-05 13:27:50 -08001202 REG_JNI(register_android_view_ThreadedRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 REG_JNI(register_android_view_Surface),
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001204 REG_JNI(register_android_view_SurfaceControl),
Jeff Brown64a55af2012-08-26 02:47:39 -07001205 REG_JNI(register_android_view_SurfaceSession),
Romain Guy8f0095c2011-05-02 17:24:22 -07001206 REG_JNI(register_android_view_TextureView),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001207 REG_JNI(register_com_google_android_gles_jni_EGLImpl),
1208 REG_JNI(register_com_google_android_gles_jni_GLImpl),
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001209 REG_JNI(register_android_opengl_jni_EGL14),
Jesse Hall237c2b82013-05-06 11:36:57 -07001210 REG_JNI(register_android_opengl_jni_EGLExt),
Jack Palevich1c4907e2009-04-13 16:22:25 -07001211 REG_JNI(register_android_opengl_jni_GLES10),
1212 REG_JNI(register_android_opengl_jni_GLES10Ext),
1213 REG_JNI(register_android_opengl_jni_GLES11),
1214 REG_JNI(register_android_opengl_jni_GLES11Ext),
Jack Palevich560814f2009-11-19 16:34:55 +08001215 REG_JNI(register_android_opengl_jni_GLES20),
Jesse Halld877efe2013-04-29 15:59:35 -07001216 REG_JNI(register_android_opengl_jni_GLES30),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217
1218 REG_JNI(register_android_graphics_Bitmap),
1219 REG_JNI(register_android_graphics_BitmapFactory),
Wei-Ta Chen6b849e22010-09-07 17:32:18 +08001220 REG_JNI(register_android_graphics_BitmapRegionDecoder),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221 REG_JNI(register_android_graphics_Camera),
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -04001222 REG_JNI(register_android_graphics_CreateJavaOutputStreamAdaptor),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 REG_JNI(register_android_graphics_Canvas),
1224 REG_JNI(register_android_graphics_ColorFilter),
1225 REG_JNI(register_android_graphics_DrawFilter),
1226 REG_JNI(register_android_graphics_Interpolator),
1227 REG_JNI(register_android_graphics_LayerRasterizer),
1228 REG_JNI(register_android_graphics_MaskFilter),
1229 REG_JNI(register_android_graphics_Matrix),
1230 REG_JNI(register_android_graphics_Movie),
1231 REG_JNI(register_android_graphics_NinePatch),
1232 REG_JNI(register_android_graphics_Paint),
1233 REG_JNI(register_android_graphics_Path),
1234 REG_JNI(register_android_graphics_PathMeasure),
1235 REG_JNI(register_android_graphics_PathEffect),
1236 REG_JNI(register_android_graphics_Picture),
1237 REG_JNI(register_android_graphics_PorterDuff),
1238 REG_JNI(register_android_graphics_Rasterizer),
1239 REG_JNI(register_android_graphics_Region),
1240 REG_JNI(register_android_graphics_Shader),
Jamie Gennisaa0ce332011-01-06 17:04:26 -08001241 REG_JNI(register_android_graphics_SurfaceTexture),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242 REG_JNI(register_android_graphics_Typeface),
1243 REG_JNI(register_android_graphics_Xfermode),
Wei-Ta Chenbca2d612009-11-30 17:52:05 +08001244 REG_JNI(register_android_graphics_YuvImage),
Svetoslav6811f4e2013-09-18 15:58:28 -07001245 REG_JNI(register_android_graphics_pdf_PdfDocument),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001246
1247 REG_JNI(register_android_database_CursorWindow),
Jeff Browne5360fb2011-10-31 17:48:13 -07001248 REG_JNI(register_android_database_SQLiteConnection),
1249 REG_JNI(register_android_database_SQLiteGlobal),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 REG_JNI(register_android_database_SQLiteDebug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251 REG_JNI(register_android_os_Debug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 REG_JNI(register_android_os_FileObserver),
Christopher Tatefa9e7c02010-05-06 12:07:10 -07001253 REG_JNI(register_android_os_MessageQueue),
Stephen Smalleyc07fca32012-01-13 08:31:39 -05001254 REG_JNI(register_android_os_SELinux),
Jeff Brown481c1572012-03-09 14:41:15 -08001255 REG_JNI(register_android_os_Trace),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 REG_JNI(register_android_os_UEventObserver),
1257 REG_JNI(register_android_net_LocalSocketImpl),
1258 REG_JNI(register_android_net_NetworkUtils),
Dan Egnor2b4abcd2010-04-07 17:30:50 -07001259 REG_JNI(register_android_net_TrafficStats),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001260 REG_JNI(register_android_os_MemoryFile),
1261 REG_JNI(register_com_android_internal_os_ZygoteInit),
Narayan Kamath973b4662014-03-31 13:41:26 +01001262 REG_JNI(register_com_android_internal_os_Zygote),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263 REG_JNI(register_android_hardware_Camera),
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07001264 REG_JNI(register_android_hardware_camera2_CameraMetadata),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 REG_JNI(register_android_hardware_SensorManager),
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04001266 REG_JNI(register_android_hardware_SerialPort),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001267 REG_JNI(register_android_hardware_UsbDevice),
Mike Lockwoodacc29cc2011-03-11 08:18:08 -05001268 REG_JNI(register_android_hardware_UsbDeviceConnection),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001269 REG_JNI(register_android_hardware_UsbRequest),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001270 REG_JNI(register_android_media_AudioRecord),
1271 REG_JNI(register_android_media_AudioSystem),
1272 REG_JNI(register_android_media_AudioTrack),
1273 REG_JNI(register_android_media_JetPlayer),
Jeff Browncbad9762012-09-04 21:57:59 -07001274 REG_JNI(register_android_media_RemoteDisplay),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 REG_JNI(register_android_media_ToneGenerator),
1276
1277 REG_JNI(register_android_opengl_classes),
JP Abgrall98a4f7e2011-09-02 15:36:33 -07001278 REG_JNI(register_android_server_NetworkManagementSocketTagger),
Christopher Tateecaa7b42010-06-04 14:55:02 -07001279 REG_JNI(register_android_server_Watchdog),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001280 REG_JNI(register_android_ddm_DdmHandleNativeHeap),
Joe Onorato1cf58742009-06-12 11:06:24 -07001281 REG_JNI(register_android_backup_BackupDataInput),
Joe Onoratod2110db2009-05-19 13:41:21 -07001282 REG_JNI(register_android_backup_BackupDataOutput),
Joe Onorato06290a42009-06-18 20:10:37 -07001283 REG_JNI(register_android_backup_FileBackupHelperBase),
Joe Onorato4ababd92009-06-25 18:29:18 -04001284 REG_JNI(register_android_backup_BackupHelperDispatcher),
Christopher Tate4a627c72011-04-01 14:43:32 -07001285 REG_JNI(register_android_app_backup_FullBackup),
Chet Haase9c1e23b2011-03-24 10:51:31 -07001286 REG_JNI(register_android_app_ActivityThread),
Dianne Hackborn69969e42010-05-04 11:40:40 -07001287 REG_JNI(register_android_app_NativeActivity),
Jeff Brown46b9ac02010-04-22 18:58:52 -07001288 REG_JNI(register_android_view_InputChannel),
Jeff Brown32cbc38552011-12-01 14:01:49 -08001289 REG_JNI(register_android_view_InputEventReceiver),
Jeff Brownc28867a2013-03-26 15:42:39 -07001290 REG_JNI(register_android_view_InputEventSender),
Michael Wrighta44dd262013-04-10 21:12:00 -07001291 REG_JNI(register_android_view_InputQueue),
Jeff Brown46b9ac02010-04-22 18:58:52 -07001292 REG_JNI(register_android_view_KeyEvent),
1293 REG_JNI(register_android_view_MotionEvent),
Jeff Brown2352b972011-04-12 22:39:53 -07001294 REG_JNI(register_android_view_PointerIcon),
Jeff Brown2ed24622011-03-14 19:39:54 -07001295 REG_JNI(register_android_view_VelocityTracker),
Kenny Root02c87302010-07-01 08:10:18 -07001296
1297 REG_JNI(register_android_content_res_ObbScanner),
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -07001298 REG_JNI(register_android_content_res_Configuration),
Chet Haase6e0ecb42010-11-03 19:41:18 -07001299
1300 REG_JNI(register_android_animation_PropertyValuesHolder),
Kenny Root66269ea2011-07-12 14:14:01 -07001301 REG_JNI(register_com_android_internal_content_NativeLibraryHelper),
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -08001302 REG_JNI(register_com_android_internal_net_NetworkStatsFactory),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001303};
1304
1305/*
1306 * Register android native functions with the VM.
1307 */
1308/*static*/ int AndroidRuntime::startReg(JNIEnv* env)
1309{
1310 /*
1311 * This hook causes all future threads created in this process to be
1312 * attached to the JavaVM. (This needs to go away in favor of JNI
1313 * Attach calls.)
1314 */
1315 androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc);
1316
Steve Block71f2cf12011-10-20 11:56:00 +01001317 ALOGV("--- registering native functions ---\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001318
1319 /*
1320 * Every "register" function calls one or more things that return
1321 * a local reference (e.g. FindClass). Because we haven't really
1322 * started the VM yet, they're all getting stored in the base frame
1323 * and never released. Use Push/Pop to manage the storage.
1324 */
1325 env->PushLocalFrame(200);
1326
1327 if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) {
1328 env->PopLocalFrame(NULL);
1329 return -1;
1330 }
1331 env->PopLocalFrame(NULL);
1332
1333 //createJavaThread("fubar", quickTest, (void*) "hello");
1334
1335 return 0;
1336}
1337
1338AndroidRuntime* AndroidRuntime::getRuntime()
1339{
1340 return gCurRuntime;
1341}
1342
1343/**
1344 * Used by WithFramework to register native functions.
1345 */
1346extern "C"
1347jint Java_com_android_internal_util_WithFramework_registerNatives(
1348 JNIEnv* env, jclass clazz) {
1349 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1350}
1351
1352/**
1353 * Used by LoadClass to register native functions.
1354 */
1355extern "C"
1356jint Java_LoadClass_registerNatives(JNIEnv* env, jclass clazz) {
1357 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1358}
1359
1360} // namespace android