blob: fa1ccdb127ba9da0362d4d00317d12065379df14 [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
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +090017#define ATRACE_TAG ATRACE_TAG_DALVIK
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018#define LOG_TAG "AndroidRuntime"
19//#define LOG_NDEBUG 0
20
21#include <android_runtime/AndroidRuntime.h>
Mathias Agopian07952722009-05-19 19:08:10 -070022#include <binder/IBinder.h>
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -080023#include <binder/IPCThreadState.h>
Mathias Agopian07952722009-05-19 19:08:10 -070024#include <binder/IServiceManager.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025#include <utils/Log.h>
26#include <utils/misc.h>
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +090027#include <utils/Trace.h>
Mathias Agopian07952722009-05-19 19:08:10 -070028#include <binder/Parcel.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029#include <utils/threads.h>
30#include <cutils/properties.h>
31
32#include <SkGraphics.h>
33#include <SkImageDecoder.h>
34
35#include "jni.h"
36#include "JNIHelp.h"
Brian Carlstrom9f8203a2013-06-19 13:49:36 -070037#include "JniInvocation.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038#include "android_util_Binder.h"
39
40#include <stdio.h>
41#include <signal.h>
42#include <sys/stat.h>
43#include <sys/types.h>
44#include <signal.h>
45#include <dirent.h>
46#include <assert.h>
47
Narayan Kamathbf882052015-08-11 15:40:34 +010048#include <string>
49#include <vector>
50
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051
52using namespace android;
53
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054extern int register_android_os_Binder(JNIEnv* env);
55extern int register_android_os_Process(JNIEnv* env);
56extern int register_android_graphics_Bitmap(JNIEnv*);
57extern int register_android_graphics_BitmapFactory(JNIEnv*);
Wei-Ta Chen6b849e22010-09-07 17:32:18 +080058extern int register_android_graphics_BitmapRegionDecoder(JNIEnv*);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059extern int register_android_graphics_Camera(JNIEnv* env);
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -040060extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061extern int register_android_graphics_Graphics(JNIEnv* env);
62extern int register_android_graphics_Interpolator(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063extern int register_android_graphics_MaskFilter(JNIEnv* env);
64extern int register_android_graphics_Movie(JNIEnv* env);
65extern int register_android_graphics_NinePatch(JNIEnv*);
66extern int register_android_graphics_PathEffect(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067extern int register_android_graphics_Shader(JNIEnv* env);
68extern int register_android_graphics_Typeface(JNIEnv* env);
Wei-Ta Chenbca2d612009-11-30 17:52:05 +080069extern int register_android_graphics_YuvImage(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070
71extern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env);
72extern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070073extern int register_android_opengl_jni_EGL14(JNIEnv* env);
Jesse Hall237c2b82013-05-06 11:36:57 -070074extern int register_android_opengl_jni_EGLExt(JNIEnv* env);
Jack Palevich1c4907e2009-04-13 16:22:25 -070075extern int register_android_opengl_jni_GLES10(JNIEnv* env);
76extern int register_android_opengl_jni_GLES10Ext(JNIEnv* env);
77extern int register_android_opengl_jni_GLES11(JNIEnv* env);
78extern int register_android_opengl_jni_GLES11Ext(JNIEnv* env);
Jack Palevich560814f2009-11-19 16:34:55 +080079extern int register_android_opengl_jni_GLES20(JNIEnv* env);
Jesse Halld877efe2013-04-29 15:59:35 -070080extern int register_android_opengl_jni_GLES30(JNIEnv* env);
Jesse Hall7ab63ac2014-05-19 15:13:41 -070081extern int register_android_opengl_jni_GLES31(JNIEnv* env);
82extern int register_android_opengl_jni_GLES31Ext(JNIEnv* env);
Pablo Ceballos38c1a7e2015-10-30 10:34:30 -070083extern int register_android_opengl_jni_GLES32(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084
85extern int register_android_hardware_Camera(JNIEnv *env);
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -070086extern int register_android_hardware_camera2_CameraMetadata(JNIEnv *env);
Ruben Brunkfeb50af2014-05-09 19:58:49 -070087extern int register_android_hardware_camera2_legacy_LegacyCameraDevice(JNIEnv *env);
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -070088extern int register_android_hardware_camera2_legacy_PerfMeasurement(JNIEnv *env);
Ruben Brunkb6079002014-05-22 12:33:54 -070089extern int register_android_hardware_camera2_DngCreator(JNIEnv *env);
Eric Laurent633cb562015-03-05 15:17:20 -080090extern int register_android_hardware_Radio(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091extern int register_android_hardware_SensorManager(JNIEnv *env);
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -040092extern int register_android_hardware_SerialPort(JNIEnv *env);
Eric Laurent60b62bc2014-04-18 17:50:49 -070093extern int register_android_hardware_SoundTrigger(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -050094extern int register_android_hardware_UsbDevice(JNIEnv *env);
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050095extern int register_android_hardware_UsbDeviceConnection(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -050096extern int register_android_hardware_UsbRequest(JNIEnv *env);
destradaaa4fa3b52014-07-09 10:46:39 -070097extern int register_android_hardware_location_ActivityRecognitionHardware(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098
99extern int register_android_media_AudioRecord(JNIEnv *env);
100extern int register_android_media_AudioSystem(JNIEnv *env);
101extern int register_android_media_AudioTrack(JNIEnv *env);
102extern int register_android_media_JetPlayer(JNIEnv *env);
103extern int register_android_media_ToneGenerator(JNIEnv *env);
104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105namespace android {
106
107/*
108 * JNI-based registration functions. Note these are properly contained in
109 * namespace android.
110 */
111extern int register_android_content_AssetManager(JNIEnv* env);
112extern int register_android_util_EventLog(JNIEnv* env);
113extern int register_android_util_Log(JNIEnv* env);
Doris Liucdd23f92015-11-11 14:31:13 -0800114extern int register_android_util_PathParser(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115extern int register_android_content_StringBlock(JNIEnv* env);
116extern int register_android_content_XmlBlock(JNIEnv* env);
117extern int register_android_graphics_Canvas(JNIEnv* env);
John Reck52244ff2014-05-01 21:27:37 -0700118extern int register_android_graphics_CanvasProperty(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119extern int register_android_graphics_ColorFilter(JNIEnv* env);
120extern int register_android_graphics_DrawFilter(JNIEnv* env);
Raph Levien1a73f7322014-01-30 16:06:28 -0800121extern int register_android_graphics_FontFamily(JNIEnv* env);
Mike Reed4c9355c2014-05-07 11:48:37 -0400122extern int register_android_graphics_LayerRasterizer(JNIEnv*);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123extern int register_android_graphics_Matrix(JNIEnv* env);
124extern int register_android_graphics_Paint(JNIEnv* env);
125extern int register_android_graphics_Path(JNIEnv* env);
126extern int register_android_graphics_PathMeasure(JNIEnv* env);
127extern int register_android_graphics_Picture(JNIEnv*);
128extern int register_android_graphics_PorterDuff(JNIEnv* env);
129extern int register_android_graphics_Rasterizer(JNIEnv* env);
Jeff Brownfbf09772011-01-16 14:06:57 -0800130extern int register_android_graphics_Region(JNIEnv* env);
Jamie Gennisaa0ce332011-01-06 17:04:26 -0800131extern int register_android_graphics_SurfaceTexture(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132extern int register_android_graphics_Xfermode(JNIEnv* env);
Doris Liu4bbc2932015-12-01 17:59:40 -0800133extern int register_android_graphics_drawable_VectorDrawable(JNIEnv* env);
Svetoslav6811f4e2013-09-18 15:58:28 -0700134extern int register_android_graphics_pdf_PdfDocument(JNIEnv* env);
Svetoslav62ce3322014-09-04 21:17:17 -0700135extern int register_android_graphics_pdf_PdfEditor(JNIEnv* env);
Svetoslav29617692014-04-24 18:40:42 -0700136extern int register_android_graphics_pdf_PdfRenderer(JNIEnv* env);
Jeff Brown0a0a1242011-12-02 02:25:22 -0800137extern int register_android_view_DisplayEventReceiver(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700138extern int register_android_view_DisplayListCanvas(JNIEnv* env);
139extern int register_android_view_GraphicBuffer(JNIEnv* env);
140extern int register_android_view_HardwareLayer(JNIEnv* env);
John Reckf666ad72014-03-14 16:24:57 -0700141extern int register_android_view_RenderNode(JNIEnv* env);
John Recke45b1fd2014-04-15 09:50:16 -0700142extern int register_android_view_RenderNodeAnimator(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143extern int register_android_view_Surface(JNIEnv* env);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800144extern int register_android_view_SurfaceControl(JNIEnv* env);
Jeff Brown64a55af2012-08-26 02:47:39 -0700145extern int register_android_view_SurfaceSession(JNIEnv* env);
Romain Guy8f0095c2011-05-02 17:24:22 -0700146extern int register_android_view_TextureView(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700147extern int register_android_view_ThreadedRenderer(JNIEnv* env);
John Reck315c3292014-05-09 19:21:04 -0700148extern int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149extern int register_android_database_CursorWindow(JNIEnv* env);
Jeff Browne5360fb2011-10-31 17:48:13 -0700150extern int register_android_database_SQLiteConnection(JNIEnv* env);
151extern int register_android_database_SQLiteGlobal(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152extern int register_android_database_SQLiteDebug(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153extern int register_android_nio_utils(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154extern int register_android_os_Debug(JNIEnv* env);
Christopher Tatefa9e7c02010-05-06 12:07:10 -0700155extern int register_android_os_MessageQueue(JNIEnv* env);
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -0800156extern int register_android_os_Parcel(JNIEnv* env);
Stephen Smalleyc07fca32012-01-13 08:31:39 -0500157extern int register_android_os_SELinux(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158extern int register_android_os_SystemProperties(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159extern int register_android_os_SystemClock(JNIEnv* env);
Jeff Brown481c1572012-03-09 14:41:15 -0800160extern int register_android_os_Trace(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161extern int register_android_os_FileObserver(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162extern int register_android_os_UEventObserver(JNIEnv* env);
163extern int register_android_os_MemoryFile(JNIEnv* env);
164extern int register_android_net_LocalSocketImpl(JNIEnv* env);
165extern int register_android_net_NetworkUtils(JNIEnv* env);
Dan Egnor2b4abcd2010-04-07 17:30:50 -0700166extern int register_android_net_TrafficStats(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167extern int register_android_text_AndroidCharacter(JNIEnv *env);
Anish Athalye88b5b0b2014-06-24 14:39:43 -0700168extern int register_android_text_StaticLayout(JNIEnv *env);
Doug Feltdae8e942010-02-24 14:33:15 -0800169extern int register_android_text_AndroidBidi(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170extern int register_android_opengl_classes(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
Narayan Kamath29564cd2014-08-07 10:57:40 +0100172extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env);
Joe Onorato1cf58742009-06-12 11:06:24 -0700173extern int register_android_backup_BackupDataInput(JNIEnv *env);
Joe Onoratod2110db2009-05-19 13:41:21 -0700174extern int register_android_backup_BackupDataOutput(JNIEnv *env);
Joe Onorato06290a42009-06-18 20:10:37 -0700175extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
Joe Onorato4ababd92009-06-25 18:29:18 -0400176extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
Christopher Tate4a627c72011-04-01 14:43:32 -0700177extern int register_android_app_backup_FullBackup(JNIEnv *env);
Chet Haase9c1e23b2011-03-24 10:51:31 -0700178extern int register_android_app_ActivityThread(JNIEnv *env);
Dianne Hackborn69969e42010-05-04 11:40:40 -0700179extern int register_android_app_NativeActivity(JNIEnv *env);
Jeff Browncbad9762012-09-04 21:57:59 -0700180extern int register_android_media_RemoteDisplay(JNIEnv *env);
Przemyslaw Szczepaniak8a7c1602015-11-03 09:47:56 +0000181extern int register_android_util_jar_StrictJarFile(JNIEnv* env);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700182extern int register_android_view_InputChannel(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700183extern int register_android_view_InputDevice(JNIEnv* env);
Jeff Brown32cbc38552011-12-01 14:01:49 -0800184extern int register_android_view_InputEventReceiver(JNIEnv* env);
Jeff Brownc28867a2013-03-26 15:42:39 -0700185extern int register_android_view_InputEventSender(JNIEnv* env);
Michael Wrighta44dd262013-04-10 21:12:00 -0700186extern int register_android_view_InputQueue(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700187extern int register_android_view_KeyCharacterMap(JNIEnv *env);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700188extern int register_android_view_KeyEvent(JNIEnv* env);
189extern int register_android_view_MotionEvent(JNIEnv* env);
Jeff Brown2352b972011-04-12 22:39:53 -0700190extern int register_android_view_PointerIcon(JNIEnv* env);
Jeff Brown2ed24622011-03-14 19:39:54 -0700191extern int register_android_view_VelocityTracker(JNIEnv* env);
Kenny Root02c87302010-07-01 08:10:18 -0700192extern int register_android_content_res_ObbScanner(JNIEnv* env);
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700193extern int register_android_content_res_Configuration(JNIEnv* env);
Chet Haase6e0ecb42010-11-03 19:41:18 -0700194extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
Kenny Root66269ea2011-07-12 14:14:01 -0700195extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -0800196extern int register_com_android_internal_net_NetworkStatsFactory(JNIEnv *env);
Narayan Kamath973b4662014-03-31 13:41:26 +0100197extern int register_com_android_internal_os_Zygote(JNIEnv *env);
John Reck9fa40712014-05-09 15:26:59 -0700198extern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env);
Polina Bondarenko965ecbb2015-11-13 15:34:28 +0100199extern int register_android_os_HardwarePropertiesManager(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200
201static AndroidRuntime* gCurRuntime = NULL;
202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203/*
204 * Code written in the Java Programming Language calls here from main().
205 */
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700206static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207{
208 gCurRuntime->onStarted();
209}
210
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700211static void com_android_internal_os_RuntimeInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212{
213 gCurRuntime->onZygoteInit();
214}
215
Jeff Brown4280c4a2012-03-15 17:48:02 -0700216static void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIEnv* env,
217 jobject clazz, jboolean exitWithoutCleanup)
218{
219 gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup);
220}
221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222/*
223 * JNI registration.
224 */
Daniel Micay76f6a862015-09-19 17:31:01 -0400225static const JNINativeMethod gMethods[] = {
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700226 { "nativeFinishInit", "()V",
227 (void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
228 { "nativeZygoteInit", "()V",
229 (void*) com_android_internal_os_RuntimeInit_nativeZygoteInit },
Jeff Brown4280c4a2012-03-15 17:48:02 -0700230 { "nativeSetExitWithoutCleanup", "(Z)V",
231 (void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232};
233
234int register_com_android_internal_os_RuntimeInit(JNIEnv* env)
235{
236 return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
237 gMethods, NELEM(gMethods));
238}
239
240// ----------------------------------------------------------------------
241
Andreas Huber9ae000c2014-02-13 17:22:33 +0000242/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
243
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000244AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) :
245 mExitWithoutCleanup(false),
246 mArgBlockStart(argBlockStart),
247 mArgBlockLength(argBlockLength)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700249 SkGraphics::Init();
Ben Wagner177612332015-01-15 14:16:46 -0500250 // There is also a global font cache, but its budget is specified by
251 // SK_DEFAULT_FONT_CACHE_COUNT_LIMIT and SK_DEFAULT_FONT_CACHE_LIMIT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252
253 // Pre-allocate enough space to hold a fair number of options.
254 mOptions.setCapacity(20);
255
256 assert(gCurRuntime == NULL); // one per process
257 gCurRuntime = this;
258}
259
260AndroidRuntime::~AndroidRuntime()
261{
262 SkGraphics::Term();
263}
264
Andreas Huber9ae000c2014-02-13 17:22:33 +0000265/*
266 * Register native methods using JNI.
267 */
268/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
269 const char* className, const JNINativeMethod* gMethods, int numMethods)
270{
271 return jniRegisterNativeMethods(env, className, gMethods, numMethods);
272}
273
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000274void AndroidRuntime::setArgv0(const char* argv0) {
Jeff Brown00c0cd42014-09-10 16:48:46 -0700275 memset(mArgBlockStart, 0, mArgBlockLength);
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000276 strlcpy(mArgBlockStart, argv0, mArgBlockLength);
277}
278
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100279status_t AndroidRuntime::callMain(const String8& className, jclass clazz,
280 const Vector<String8>& args)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281{
282 JNIEnv* env;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 jmethodID methodId;
284
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100285 ALOGD("Calling main entry %s", className.string());
Dianne Hackborn08e60f22010-09-01 18:17:17 -0700286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 env = getJNIEnv();
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700288 if (clazz == NULL || env == NULL) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289 return UNKNOWN_ERROR;
290 }
291
292 methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
293 if (methodId == NULL) {
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100294 ALOGE("ERROR: could not find method %s.main(String[])\n", className.string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 return UNKNOWN_ERROR;
296 }
297
298 /*
299 * We want to call main() with a String array with our arguments in it.
300 * Create an array and populate it.
301 */
302 jclass stringClass;
303 jobjectArray strArray;
304
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100305 const size_t numArgs = args.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800306 stringClass = env->FindClass("java/lang/String");
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100307 strArray = env->NewObjectArray(numArgs, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100309 for (size_t i = 0; i < numArgs; i++) {
310 jstring argStr = env->NewStringUTF(args[i].string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 env->SetObjectArrayElement(strArray, i, argStr);
312 }
313
314 env->CallStaticVoidMethod(clazz, methodId, strArray);
315 return NO_ERROR;
316}
317
318/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 * The VM calls this through the "exit" hook.
320 */
321static void runtime_exit(int code)
322{
Jeff Brown4280c4a2012-03-15 17:48:02 -0700323 gCurRuntime->exit(code);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324}
325
326/*
327 * The VM calls this through the "vfprintf" hook.
328 *
329 * We ignore "fp" and just write the results to the log file.
330 */
331static void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
332{
333 LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
334}
335
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800336/**
337 * The VM calls this when mutex contention debugging is enabled to
338 * determine whether or not the blocked thread was a "sensitive thread"
339 * for user responsiveness/smoothess.
340 *
341 * Our policy for this is whether or not we're tracing any StrictMode
342 * events on this thread (which we might've inherited via Binder calls
343 * into us)
344 */
345static bool runtime_isSensitiveThread() {
346 IPCThreadState* state = IPCThreadState::selfOrNull();
347 return state && state->getStrictModePolicy() != 0;
348}
349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350static int hasDir(const char* dir)
351{
352 struct stat s;
353 int res = stat(dir, &s);
354 if (res == 0) {
355 return S_ISDIR(s.st_mode);
356 }
357 return 0;
358}
359
Andreas Gampe995c62d2014-11-14 16:15:17 -0800360static bool hasFile(const char* file) {
361 struct stat s;
362 int res = stat(file, &s);
363 if (res == 0) {
364 return S_ISREG(s.st_mode);
365 }
366 return false;
367}
368
Narayan Kamathbf882052015-08-11 15:40:34 +0100369// Convenience wrapper over the property API that returns an
370// std::string.
371std::string getProperty(const char* key, const char* defaultValue) {
372 std::vector<char> temp(PROPERTY_VALUE_MAX);
373 const int len = property_get(key, &temp[0], defaultValue);
374 if (len < 0) {
375 return "";
376 }
377 return std::string(&temp[0], len);
378}
379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380/*
Narayan Kamathbf882052015-08-11 15:40:34 +0100381 * Read the persistent locale. Inspects the following system properties
382 * (in order) and returns the first non-empty property in the list :
383 *
384 * (1) persist.sys.locale
385 * (2) persist.sys.language/country/localevar (country and localevar are
386 * inspected iff. language is non-empty.
387 * (3) ro.product.locale
388 * (4) ro.product.locale.language/region
389 *
390 * Note that we need to inspect persist.sys.language/country/localevar to
391 * preserve language settings for devices that are upgrading from Lollipop
392 * to M. The same goes for ro.product.locale.language/region as well.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 */
Narayan Kamathbf882052015-08-11 15:40:34 +0100394const std::string readLocale()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395{
Narayan Kamathbf882052015-08-11 15:40:34 +0100396 const std::string locale = getProperty("persist.sys.locale", "");
397 if (!locale.empty()) {
398 return locale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 }
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000400
Narayan Kamathbf882052015-08-11 15:40:34 +0100401 const std::string language = getProperty("persist.sys.language", "");
402 if (!language.empty()) {
403 const std::string country = getProperty("persist.sys.country", "");
404 const std::string variant = getProperty("persist.sys.localevar", "");
405
406 std::string out = language;
407 if (!country.empty()) {
408 out = out + "-" + country;
409 }
410
411 if (!variant.empty()) {
412 out = out + "-" + variant;
413 }
414
415 return out;
416 }
417
418 const std::string productLocale = getProperty("ro.product.locale", "");
419 if (!productLocale.empty()) {
420 return productLocale;
421 }
422
423 // If persist.sys.locale and ro.product.locale are missing,
424 // construct a locale value from the individual locale components.
425 const std::string productLanguage = getProperty("ro.product.locale.language", "en");
426 const std::string productRegion = getProperty("ro.product.locale.region", "US");
427
428 return productLanguage + "-" + productRegion;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429}
430
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700431void AndroidRuntime::addOption(const char* optionString, void* extraInfo)
432{
433 JavaVMOption opt;
434 opt.optionString = optionString;
435 opt.extraInfo = extraInfo;
436 mOptions.add(opt);
437}
438
Andy McFaddenf70188a2009-03-31 15:52:13 -0700439/*
Andy McFaddene4d81f22010-07-14 16:02:20 -0700440 * Parse a property containing space-separated options that should be
441 * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
442 *
443 * This will cut up "extraOptsBuf" as we chop it into individual options.
444 *
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800445 * If "quotingArg" is non-null, it is passed before each extra option in mOptions.
446 *
Andy McFaddene4d81f22010-07-14 16:02:20 -0700447 * Adds the strings, if any, to mOptions.
448 */
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800449void AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg)
Andy McFaddene4d81f22010-07-14 16:02:20 -0700450{
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800451 char* start = extraOptsBuf;
452 char* end = NULL;
Andy McFaddene4d81f22010-07-14 16:02:20 -0700453 while (*start != '\0') {
454 while (*start == ' ') /* skip leading whitespace */
455 start++;
456 if (*start == '\0') /* was trailing ws, bail */
457 break;
458
459 end = start+1;
460 while (*end != ' ' && *end != '\0') /* find end of token */
461 end++;
462 if (*end == ' ')
463 *end++ = '\0'; /* mark end, advance to indicate more */
464
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800465 if (quotingArg != NULL) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700466 addOption(quotingArg);
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800467 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700468 addOption(start);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700469 start = end;
470 }
471}
472
473/*
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700474 * Reads a "property" into "buffer" with a default of "defaultArg". If
475 * the property is non-empty, it is treated as a runtime option such
476 * as "-Xmx32m".
477 *
478 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
479 *
480 * If an argument is found, it is added to mOptions.
481 *
482 * If an option is found, it is added to mOptions and true is
483 * returned. Otherwise false is returned.
484 */
485bool AndroidRuntime::parseRuntimeOption(const char* property,
486 char* buffer,
487 const char* runtimeArg,
488 const char* defaultArg)
489{
490 strcpy(buffer, runtimeArg);
491 size_t runtimeArgLen = strlen(runtimeArg);
492 property_get(property, buffer+runtimeArgLen, defaultArg);
493 if (buffer[runtimeArgLen] == '\0') {
494 return false;
495 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700496 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700497 return true;
498}
499
500/*
501 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700502 * is treated as a dex2oat compiler option that should be
503 * passed as a quoted option, e.g. "-Ximage-compiler-option --compiler-filter=verify-none".
504 *
505 * The "compilerArg" is a prefix for the option such as "--compiler-filter=".
506 *
507 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
508 *
509 * If an option is found, it is added to mOptions and true is
510 * returned. Otherwise false is returned.
511 */
512bool AndroidRuntime::parseCompilerOption(const char* property,
513 char* buffer,
514 const char* compilerArg,
515 const char* quotingArg)
516{
517 strcpy(buffer, compilerArg);
518 size_t compilerArgLen = strlen(compilerArg);
519 property_get(property, buffer+compilerArgLen, "");
520 if (buffer[compilerArgLen] == '\0') {
521 return false;
522 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700523 addOption(quotingArg);
524 addOption(buffer);
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700525 return true;
526}
527
528/*
529 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700530 * is treated as a dex2oat compiler runtime option that should be
531 * passed as a quoted option, e.g. "-Ximage-compiler-option
532 * --runtime-arg -Ximage-compiler-option -Xmx32m".
533 *
534 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
535 *
536 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
537 *
538 * If an option is found, it is added to mOptions and true is
539 * returned. Otherwise false is returned.
540 */
541bool AndroidRuntime::parseCompilerRuntimeOption(const char* property,
542 char* buffer,
543 const char* runtimeArg,
544 const char* quotingArg)
545{
546 strcpy(buffer, runtimeArg);
547 size_t runtimeArgLen = strlen(runtimeArg);
548 property_get(property, buffer+runtimeArgLen, "");
549 if (buffer[runtimeArgLen] == '\0') {
550 return false;
551 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700552 addOption(quotingArg);
553 addOption("--runtime-arg");
554 addOption(quotingArg);
555 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700556 return true;
557}
558
559/*
Andy McFaddenf70188a2009-03-31 15:52:13 -0700560 * Start the Dalvik Virtual Machine.
561 *
562 * Various arguments, most determined by system properties, are passed in.
563 * The "mOptions" vector is updated.
564 *
Dave Allison07a1e232014-03-14 08:54:33 -0700565 * CAUTION: when adding options in here, be careful not to put the
566 * char buffer inside a nested scope. Adding the buffer to the
567 * options using mOptions.add() does not copy the buffer, so if the
568 * buffer goes out of scope the option may be overwritten. It's best
569 * to put the buffer at the top of the function so that it is more
570 * unlikely that someone will surround it in a scope at a later time
571 * and thus introduce a bug.
572 *
Andy McFaddenf70188a2009-03-31 15:52:13 -0700573 * Returns 0 on success.
574 */
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200575int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 JavaVMInitArgs initArgs;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 char propBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700579 char stackTraceFileBuf[sizeof("-Xstacktracefile:")-1 + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro38cfa8c2010-12-07 16:48:29 -0800581 char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700582 char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro8cdf27c2011-01-19 12:33:12 -0800583 char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700584 char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
585 char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800586 char usejitOptsBuf[sizeof("-Xusejit:")-1 + PROPERTY_VALUE_MAX];
Nicolas Geoffraycdf1dff2015-11-19 13:48:35 +0000587 char jitmaxsizeOptsBuf[sizeof("-Xjitmaxsize:")-1 + PROPERTY_VALUE_MAX];
588 char jitinitialsizeOptsBuf[sizeof("-Xjitinitialsize:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800589 char jitthresholdOptsBuf[sizeof("-Xjitthreshold:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier7e4fdec2013-12-02 15:46:51 -0800590 char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700591 char backgroundgcOptsBuf[sizeof("-XX:BackgroundGC=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700592 char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee324ba02015-03-31 16:15:17 -0700593 char cachePruneBuf[sizeof("-Xzygote-max-boot-retry=")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700594 char dex2oatXmsImageFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
595 char dex2oatXmxImageFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
596 char dex2oatXmsFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
597 char dex2oatXmxFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700598 char dex2oatCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
599 char dex2oatImageCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee0352382015-03-30 18:43:39 -0700600 char dex2oatThreadsBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
601 char dex2oatThreadsImageBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
Andreas Gampe605cca12015-04-02 23:12:56 -0700602 char dex2oat_isa_variant_key[PROPERTY_KEY_MAX];
603 char dex2oat_isa_variant[sizeof("--instruction-set-variant=") -1 + PROPERTY_VALUE_MAX];
604 char dex2oat_isa_features_key[PROPERTY_KEY_MAX];
605 char dex2oat_isa_features[sizeof("--instruction-set-features=") -1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800606 char dex2oatFlagsBuf[PROPERTY_VALUE_MAX];
607 char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX];
Andy McFaddene4d81f22010-07-14 16:02:20 -0700608 char extraOptsBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700609 char voldDecryptBuf[PROPERTY_VALUE_MAX];
Ben Cheng52b0e732009-06-19 13:31:12 -0700610 enum {
611 kEMDefault,
612 kEMIntPortable,
613 kEMIntFast,
Ben Cheng52b0e732009-06-19 13:31:12 -0700614 kEMJitCompiler,
Ben Cheng52b0e732009-06-19 13:31:12 -0700615 } executionMode = kEMDefault;
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000616 char localeOption[sizeof("-Duser.locale=") + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700617 char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle01db9162014-08-07 14:45:53 +0100618 char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX];
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700619 char cpuAbiListBuf[sizeof("--cpu-abilist=") + PROPERTY_VALUE_MAX];
Andreas Gampe98f406f2015-06-22 21:09:36 -0700620 char methodTraceFileBuf[sizeof("-Xmethod-trace-file:") + PROPERTY_VALUE_MAX];
621 char methodTraceFileSizeBuf[sizeof("-Xmethod-trace-file-size:") + PROPERTY_VALUE_MAX];
Andreas Gampee6082502015-07-24 14:19:44 -0700622 char fingerprintBuf[sizeof("-Xfingerprint:") + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700624 bool checkJni = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 property_get("dalvik.vm.checkjni", propBuf, "");
626 if (strcmp(propBuf, "true") == 0) {
627 checkJni = true;
628 } else if (strcmp(propBuf, "false") != 0) {
629 /* property is neither true nor false; fall back on kernel parameter */
630 property_get("ro.kernel.android.checkjni", propBuf, "");
631 if (propBuf[0] == '1') {
632 checkJni = true;
633 }
634 }
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700635 ALOGD("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
636 if (checkJni) {
637 /* extended JNI checking */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700638 addOption("-Xcheck:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700639
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700640 /* with -Xcheck:jni, this provides a JNI function call trace */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700641 //addOption("-verbose:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700642 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643
644 property_get("dalvik.vm.execution-mode", propBuf, "");
645 if (strcmp(propBuf, "int:portable") == 0) {
646 executionMode = kEMIntPortable;
647 } else if (strcmp(propBuf, "int:fast") == 0) {
648 executionMode = kEMIntFast;
Ben Cheng52b0e732009-06-19 13:31:12 -0700649 } else if (strcmp(propBuf, "int:jit") == 0) {
650 executionMode = kEMJitCompiler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 }
652
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700653 parseRuntimeOption("dalvik.vm.stack-trace-file", stackTraceFileBuf, "-Xstacktracefile:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655 strcpy(jniOptsBuf, "-Xjniopts:");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700656 if (parseRuntimeOption("dalvik.vm.jniopts", jniOptsBuf, "-Xjniopts:")) {
657 ALOGI("JNI options: '%s'\n", jniOptsBuf);
658 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800660 /* route exit() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700661 addOption("exit", (void*) runtime_exit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662
663 /* route fprintf() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700664 addOption("vfprintf", (void*) runtime_vfprintf);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800666 /* register the framework-specific "is sensitive thread" hook */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700667 addOption("sensitiveThread", (void*) runtime_isSensitiveThread);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668
669 /* enable verbose; standard options are { jni, gc, class } */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700670 //addOption("-verbose:jni");
671 addOption("-verbose:gc");
672 //addOption("-verbose:class");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673
Carl Shapiro9e4c8842010-12-08 12:14:46 -0800674 /*
675 * The default starting and maximum size of the heap. Larger
676 * values should be specified in a product property override.
677 */
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700678 parseRuntimeOption("dalvik.vm.heapstartsize", heapstartsizeOptsBuf, "-Xms", "4m");
679 parseRuntimeOption("dalvik.vm.heapsize", heapsizeOptsBuf, "-Xmx", "16m");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800680
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700681 parseRuntimeOption("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
682 parseRuntimeOption("dalvik.vm.heapminfree", heapminfreeOptsBuf, "-XX:HeapMinFree=");
683 parseRuntimeOption("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf, "-XX:HeapMaxFree=");
684 parseRuntimeOption("dalvik.vm.heaptargetutilization",
685 heaptargetutilizationOptsBuf,
686 "-XX:HeapTargetUtilization=");
Ian Rogers53250102012-09-23 16:38:03 -0700687
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800688 /*
689 * JIT related options.
690 */
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700691 parseRuntimeOption("dalvik.vm.usejit", usejitOptsBuf, "-Xusejit:");
Nicolas Geoffraycdf1dff2015-11-19 13:48:35 +0000692 parseRuntimeOption("dalvik.vm.jitmaxsize", jitmaxsizeOptsBuf, "-Xjitmaxsize:");
693 parseRuntimeOption("dalvik.vm.jitinitialsize", jitinitialsizeOptsBuf, "-Xjitinitialsize:");
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700694 parseRuntimeOption("dalvik.vm.jitthreshold", jitthresholdOptsBuf, "-Xjitthreshold:");
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800695
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700696 property_get("ro.config.low_ram", propBuf, "");
697 if (strcmp(propBuf, "true") == 0) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700698 addOption("-XX:LowMemoryMode");
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700699 }
700
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700701 parseRuntimeOption("dalvik.vm.gctype", gctypeOptsBuf, "-Xgc:");
702 parseRuntimeOption("dalvik.vm.backgroundgctype", backgroundgcOptsBuf, "-XX:BackgroundGC=");
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700703
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200704 /*
705 * Enable debugging only for apps forked from zygote.
706 * Set suspend=y to pause during VM init and use android ADB transport.
707 */
708 if (zygote) {
709 addOption("-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y");
710 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800711
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700712 parseRuntimeOption("dalvik.vm.lockprof.threshold",
713 lockProfThresholdBuf,
714 "-Xlockprofthreshold:");
Carl Shapirod8f3ec62010-04-12 16:31:59 -0700715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800716 if (executionMode == kEMIntPortable) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700717 addOption("-Xint:portable");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800718 } else if (executionMode == kEMIntFast) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700719 addOption("-Xint:fast");
Ben Cheng52b0e732009-06-19 13:31:12 -0700720 } else if (executionMode == kEMJitCompiler) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700721 addOption("-Xint:jit");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 }
Andy McFaddene2b23e12009-04-03 11:09:46 -0700723
Andreas Gampe08b2d582014-12-18 14:39:22 -0800724 // If we are booting without the real /data, don't spend time compiling.
725 property_get("vold.decrypt", voldDecryptBuf, "");
726 bool skip_compilation = ((strcmp(voldDecryptBuf, "trigger_restart_min_framework") == 0) ||
727 (strcmp(voldDecryptBuf, "1") == 0));
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800728
Andreas Gampe08b2d582014-12-18 14:39:22 -0800729 // Extra options for boot.art/boot.oat image generation.
730 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xms", dex2oatXmsImageFlagsBuf,
731 "-Xms", "-Ximage-compiler-option");
732 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xmx", dex2oatXmxImageFlagsBuf,
733 "-Xmx", "-Ximage-compiler-option");
734 if (skip_compilation) {
Brian Carlstromce5bbbe2014-07-30 15:13:17 -0700735 addOption("-Ximage-compiler-option");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800736 addOption("--compiler-filter=verify-none");
737 } else {
738 parseCompilerOption("dalvik.vm.image-dex2oat-filter", dex2oatImageCompilerFilterBuf,
739 "--compiler-filter=", "-Ximage-compiler-option");
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800740 }
741
Andreas Gampe08b2d582014-12-18 14:39:22 -0800742 // Make sure there is a preloaded-classes file.
743 if (!hasFile("/system/etc/preloaded-classes")) {
744 ALOGE("Missing preloaded-classes file, /system/etc/preloaded-classes not found: %s\n",
745 strerror(errno));
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700746 return -1;
Andreas Gampe08b2d582014-12-18 14:39:22 -0800747 }
748 addOption("-Ximage-compiler-option");
749 addOption("--image-classes=/system/etc/preloaded-classes");
750
751 // If there is a compiled-classes file, push it.
752 if (hasFile("/system/etc/compiled-classes")) {
753 addOption("-Ximage-compiler-option");
754 addOption("--compiled-classes=/system/etc/compiled-classes");
755 }
756
757 property_get("dalvik.vm.image-dex2oat-flags", dex2oatImageFlagsBuf, "");
758 parseExtraOpts(dex2oatImageFlagsBuf, "-Ximage-compiler-option");
759
760 // Extra options for DexClassLoader.
761 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xms", dex2oatXmsFlagsBuf,
762 "-Xms", "-Xcompiler-option");
763 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xmx", dex2oatXmxFlagsBuf,
764 "-Xmx", "-Xcompiler-option");
765 if (skip_compilation) {
766 addOption("-Xcompiler-option");
767 addOption("--compiler-filter=verify-none");
neo.chae155118f2015-01-07 15:32:15 +0900768
769 // We skip compilation when a minimal runtime is brought up for decryption. In that case
770 // /data is temporarily backed by a tmpfs, which is usually small.
771 // If the system image contains prebuilts, they will be relocated into the tmpfs. In this
772 // specific situation it is acceptable to *not* relocate and run out of the prebuilts
773 // directly instead.
774 addOption("--runtime-arg");
775 addOption("-Xnorelocate");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800776 } else {
777 parseCompilerOption("dalvik.vm.dex2oat-filter", dex2oatCompilerFilterBuf,
778 "--compiler-filter=", "-Xcompiler-option");
779 }
Andreas Gampee0352382015-03-30 18:43:39 -0700780 parseCompilerOption("dalvik.vm.dex2oat-threads", dex2oatThreadsBuf, "-j", "-Xcompiler-option");
781 parseCompilerOption("dalvik.vm.image-dex2oat-threads", dex2oatThreadsImageBuf, "-j",
782 "-Ximage-compiler-option");
Andreas Gampe605cca12015-04-02 23:12:56 -0700783
784 // The runtime will compile a boot image, when necessary, not using installd. Thus, we need to
785 // pass the instruction-set-features/variant as an image-compiler-option.
786 // TODO: Find a better way for the instruction-set.
787#if defined(__arm__)
788 constexpr const char* instruction_set = "arm";
789#elif defined(__aarch64__)
790 constexpr const char* instruction_set = "arm64";
791#elif defined(__mips__) && !defined(__LP64__)
792 constexpr const char* instruction_set = "mips";
793#elif defined(__mips__) && defined(__LP64__)
794 constexpr const char* instruction_set = "mips64";
795#elif defined(__i386__)
796 constexpr const char* instruction_set = "x86";
797#elif defined(__x86_64__)
798 constexpr const char* instruction_set = "x86_64";
799#else
800 constexpr const char* instruction_set = "unknown";
801#endif
802 // Note: it is OK to reuse the buffer, as the values are exactly the same between
803 // * compiler-option, used for runtime compilation (DexClassLoader)
804 // * image-compiler-option, used for boot-image compilation on device
805
806 // Copy the variant.
807 sprintf(dex2oat_isa_variant_key, "dalvik.vm.isa.%s.variant", instruction_set);
808 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
809 "--instruction-set-variant=", "-Ximage-compiler-option");
810 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
811 "--instruction-set-variant=", "-Xcompiler-option");
812 // Copy the features.
813 sprintf(dex2oat_isa_features_key, "dalvik.vm.isa.%s.features", instruction_set);
814 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
815 "--instruction-set-features=", "-Ximage-compiler-option");
816 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
817 "--instruction-set-features=", "-Xcompiler-option");
818
819
Andreas Gampe08b2d582014-12-18 14:39:22 -0800820 property_get("dalvik.vm.dex2oat-flags", dex2oatFlagsBuf, "");
821 parseExtraOpts(dex2oatFlagsBuf, "-Xcompiler-option");
822
Andy McFaddene4d81f22010-07-14 16:02:20 -0700823 /* extra options; parse this late so it overrides others */
824 property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800825 parseExtraOpts(extraOptsBuf, NULL);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827 /* Set the properties for locale */
828 {
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000829 strcpy(localeOption, "-Duser.locale=");
Narayan Kamathbf882052015-08-11 15:40:34 +0100830 const std::string locale = readLocale();
831 strncat(localeOption, locale.c_str(), PROPERTY_VALUE_MAX);
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000832 addOption(localeOption);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833 }
834
Calin Juravle92290b82015-11-10 19:30:45 +0000835 // Trace files are stored in /data/misc/trace which is writable only in debug mode.
836 property_get("ro.debuggable", propBuf, "0");
837 if (strcmp(propBuf, "1") == 0) {
838 property_get("dalvik.vm.method-trace", propBuf, "false");
Andreas Gampe98f406f2015-06-22 21:09:36 -0700839 if (strcmp(propBuf, "true") == 0) {
Calin Juravle92290b82015-11-10 19:30:45 +0000840 addOption("-Xmethod-trace");
841 parseRuntimeOption("dalvik.vm.method-trace-file",
842 methodTraceFileBuf,
843 "-Xmethod-trace-file:");
844 parseRuntimeOption("dalvik.vm.method-trace-file-siz",
845 methodTraceFileSizeBuf,
846 "-Xmethod-trace-file-size:");
847 property_get("dalvik.vm.method-trace-stream", propBuf, "false");
848 if (strcmp(propBuf, "true") == 0) {
849 addOption("-Xmethod-trace-stream");
850 }
Andreas Gampe98f406f2015-06-22 21:09:36 -0700851 }
852 }
853
Andreas Gampe08b2d582014-12-18 14:39:22 -0800854 // Native bridge library. "0" means that native bridge is disabled.
855 property_get("ro.dalvik.vm.native.bridge", propBuf, "");
856 if (propBuf[0] == '\0') {
857 ALOGW("ro.dalvik.vm.native.bridge is not expected to be empty");
858 } else if (strcmp(propBuf, "0") != 0) {
859 snprintf(nativeBridgeLibrary, sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX,
860 "-XX:NativeBridge=%s", propBuf);
861 addOption(nativeBridgeLibrary);
Calin Juravlebe20ed42014-08-26 23:00:11 +0100862 }
Calin Juravle01db9162014-08-07 14:45:53 +0100863
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700864#if defined(__LP64__)
865 const char* cpu_abilist_property_name = "ro.product.cpu.abilist64";
866#else
867 const char* cpu_abilist_property_name = "ro.product.cpu.abilist32";
868#endif // defined(__LP64__)
869 property_get(cpu_abilist_property_name, propBuf, "");
870 if (propBuf[0] == '\0') {
871 ALOGE("%s is not expected to be empty", cpu_abilist_property_name);
872 return -1;
873 }
874 snprintf(cpuAbiListBuf, sizeof(cpuAbiListBuf), "--cpu-abilist=%s", propBuf);
875 addOption(cpuAbiListBuf);
876
Andreas Gampee324ba02015-03-31 16:15:17 -0700877 // Dalvik-cache pruning counter.
878 parseRuntimeOption("dalvik.vm.zygote.max-boot-retry", cachePruneBuf,
879 "-Xzygote-max-boot-retry=");
880
Andreas Gampe27c39f12015-04-27 18:28:18 +0000881 /*
David Srbecky065075e2015-05-28 17:16:09 +0100882 * When running with debug.generate-debug-info, add --generate-debug-info to
883 * the compiler options so that the boot image, if it is compiled on device,
884 * will include native debugging information.
Andreas Gampe27c39f12015-04-27 18:28:18 +0000885 */
David Srbecky065075e2015-05-28 17:16:09 +0100886 property_get("debug.generate-debug-info", propBuf, "");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000887 if (strcmp(propBuf, "true") == 0) {
888 addOption("-Xcompiler-option");
David Srbecky065075e2015-05-28 17:16:09 +0100889 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000890 addOption("-Ximage-compiler-option");
David Srbecky065075e2015-05-28 17:16:09 +0100891 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000892 }
893
Andreas Gampee6082502015-07-24 14:19:44 -0700894 /*
895 * Retrieve the build fingerprint and provide it to the runtime. That way, ANR dumps will
896 * contain the fingerprint and can be parsed.
897 */
898 parseRuntimeOption("ro.build.fingerprint", fingerprintBuf, "-Xfingerprint:");
899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 initArgs.version = JNI_VERSION_1_4;
901 initArgs.options = mOptions.editArray();
902 initArgs.nOptions = mOptions.size();
903 initArgs.ignoreUnrecognized = JNI_FALSE;
904
905 /*
906 * Initialize the VM.
907 *
908 * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread.
909 * If this call succeeds, the VM is ready, and we can start issuing
910 * JNI calls.
911 */
Andy McFaddenf70188a2009-03-31 15:52:13 -0700912 if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) {
Steve Block3762c312012-01-06 19:20:56 +0000913 ALOGE("JNI_CreateJavaVM failed\n");
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700914 return -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 }
916
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700917 return 0;
Andy McFaddenf70188a2009-03-31 15:52:13 -0700918}
919
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700920char* AndroidRuntime::toSlashClassName(const char* className)
921{
922 char* result = strdup(className);
923 for (char* cp = result; *cp != '\0'; cp++) {
924 if (*cp == '.') {
925 *cp = '/';
926 }
927 }
928 return result;
929}
930
Mike Lockwood9ee5e7e2014-09-08 16:15:21 -0700931/** Create a Java string from an ASCII or Latin-1 string */
932jstring AndroidRuntime::NewStringLatin1(JNIEnv* env, const char* bytes) {
933 if (!bytes) return NULL;
934 int length = strlen(bytes);
935 jchar* buffer = (jchar *)alloca(length * sizeof(jchar));
936 if (!buffer) return NULL;
937 jchar* chp = buffer;
938 for (int i = 0; i < length; i++) {
939 *chp++ = *bytes++;
940 }
941 return env->NewString(buffer, length);
942}
943
944
Andy McFaddenf70188a2009-03-31 15:52:13 -0700945/*
946 * Start the Android runtime. This involves starting the virtual machine
947 * and calling the "static void main(String[] args)" method in the class
948 * named by "className".
Jeff Brownebed7d62011-05-16 17:08:42 -0700949 *
950 * Passes the main function two arguments, the class name and the specified
951 * options string.
Andy McFaddenf70188a2009-03-31 15:52:13 -0700952 */
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200953void AndroidRuntime::start(const char* className, const Vector<String8>& options, bool zygote)
Andy McFaddenf70188a2009-03-31 15:52:13 -0700954{
Dianne Hackborn8e5aafe2014-10-27 18:04:10 -0700955 ALOGD(">>>>>> START %s uid %d <<<<<<\n",
956 className != NULL ? className : "(unknown)", getuid());
Andy McFaddenf70188a2009-03-31 15:52:13 -0700957
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100958 static const String8 startSystemServer("start-system-server");
959
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700960 /*
961 * 'startSystemServer == true' means runtime is obsolete and not run from
Andy McFaddenf70188a2009-03-31 15:52:13 -0700962 * init.rc anymore, so we print out the boot start event here.
963 */
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100964 for (size_t i = 0; i < options.size(); ++i) {
965 if (options[i] == startSystemServer) {
966 /* track our progress through the boot sequence */
967 const int LOG_BOOT_PROGRESS_START = 3000;
968 LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));
969 }
Andy McFaddenf70188a2009-03-31 15:52:13 -0700970 }
971
972 const char* rootDir = getenv("ANDROID_ROOT");
973 if (rootDir == NULL) {
974 rootDir = "/system";
975 if (!hasDir("/system")) {
976 LOG_FATAL("No root directory specified, and /android does not exist.");
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700977 return;
Andy McFaddenf70188a2009-03-31 15:52:13 -0700978 }
979 setenv("ANDROID_ROOT", rootDir, 1);
980 }
981
982 //const char* kernelHack = getenv("LD_ASSUME_KERNEL");
Steve Block5baa3a62011-12-20 16:23:08 +0000983 //ALOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack);
Andy McFaddenf70188a2009-03-31 15:52:13 -0700984
985 /* start the virtual machine */
Brian Carlstrom9f8203a2013-06-19 13:49:36 -0700986 JniInvocation jni_invocation;
987 jni_invocation.Init(NULL);
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700988 JNIEnv* env;
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200989 if (startVm(&mJavaVM, &env, zygote) != 0) {
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700990 return;
991 }
992 onVmCreated(env);
Andy McFaddenf70188a2009-03-31 15:52:13 -0700993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994 /*
995 * Register android functions.
996 */
997 if (startReg(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +0000998 ALOGE("Unable to register all android natives\n");
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700999 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 }
1001
1002 /*
1003 * We want to call main() with a String array with arguments in it.
Jeff Brownebed7d62011-05-16 17:08:42 -07001004 * At present we have two arguments, the class name and an option string.
1005 * Create an array to hold them.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001006 */
1007 jclass stringClass;
1008 jobjectArray strArray;
1009 jstring classNameStr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010
1011 stringClass = env->FindClass("java/lang/String");
1012 assert(stringClass != NULL);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001013 strArray = env->NewObjectArray(options.size() + 1, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 assert(strArray != NULL);
1015 classNameStr = env->NewStringUTF(className);
1016 assert(classNameStr != NULL);
1017 env->SetObjectArrayElement(strArray, 0, classNameStr);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001018
1019 for (size_t i = 0; i < options.size(); ++i) {
1020 jstring optionsStr = env->NewStringUTF(options.itemAt(i).string());
1021 assert(optionsStr != NULL);
1022 env->SetObjectArrayElement(strArray, i + 1, optionsStr);
1023 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001024
1025 /*
1026 * Start VM. This thread becomes the main thread of the VM, and will
1027 * not return until the VM exits.
1028 */
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001029 char* slashClassName = toSlashClassName(className);
1030 jclass startClass = env->FindClass(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001031 if (startClass == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001032 ALOGE("JavaVM unable to locate class '%s'\n", slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001033 /* keep going */
1034 } else {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001035 jmethodID startMeth = env->GetStaticMethodID(startClass, "main",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 "([Ljava/lang/String;)V");
1037 if (startMeth == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001038 ALOGE("JavaVM unable to find main() in '%s'\n", className);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 /* keep going */
1040 } else {
1041 env->CallStaticVoidMethod(startClass, startMeth, strArray);
1042
1043#if 0
1044 if (env->ExceptionCheck())
1045 threadExitUncaughtException(env);
1046#endif
1047 }
1048 }
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001049 free(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050
Steve Block5baa3a62011-12-20 16:23:08 +00001051 ALOGD("Shutting down VM\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052 if (mJavaVM->DetachCurrentThread() != JNI_OK)
Steve Block8564c8d2012-01-05 23:22:43 +00001053 ALOGW("Warning: unable to detach main thread\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001054 if (mJavaVM->DestroyJavaVM() != 0)
Steve Block8564c8d2012-01-05 23:22:43 +00001055 ALOGW("Warning: VM did not shut down cleanly\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001056}
1057
Jeff Brown4280c4a2012-03-15 17:48:02 -07001058void AndroidRuntime::exit(int code)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059{
Jeff Brown4280c4a2012-03-15 17:48:02 -07001060 if (mExitWithoutCleanup) {
1061 ALOGI("VM exiting with result code %d, cleanup skipped.", code);
1062 ::_exit(code);
1063 } else {
1064 ALOGI("VM exiting with result code %d.", code);
1065 onExit(code);
1066 ::exit(code);
1067 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068}
1069
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001070void AndroidRuntime::onVmCreated(JNIEnv* env)
1071{
1072 // If AndroidRuntime had anything to do here, we'd have done it in 'start'.
1073}
1074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001075/*
Andreas Huber9ae000c2014-02-13 17:22:33 +00001076 * Get the JNIEnv pointer for this thread.
1077 *
1078 * Returns NULL if the slot wasn't allocated or populated.
1079 */
1080/*static*/ JNIEnv* AndroidRuntime::getJNIEnv()
1081{
1082 JNIEnv* env;
1083 JavaVM* vm = AndroidRuntime::getJavaVM();
1084 assert(vm != NULL);
1085
1086 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
1087 return NULL;
1088 return env;
1089}
1090
1091/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 * Makes the current thread visible to the VM.
1093 *
1094 * The JNIEnv pointer returned is only valid for the current thread, and
1095 * thus must be tucked into thread-local storage.
1096 */
1097static int javaAttachThread(const char* threadName, JNIEnv** pEnv)
1098{
1099 JavaVMAttachArgs args;
1100 JavaVM* vm;
1101 jint result;
1102
1103 vm = AndroidRuntime::getJavaVM();
1104 assert(vm != NULL);
1105
1106 args.version = JNI_VERSION_1_4;
1107 args.name = (char*) threadName;
1108 args.group = NULL;
1109
1110 result = vm->AttachCurrentThread(pEnv, (void*) &args);
1111 if (result != JNI_OK)
Steve Block6215d3f2012-01-04 20:05:49 +00001112 ALOGI("NOTE: attach of thread '%s' failed\n", threadName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113
1114 return result;
1115}
1116
1117/*
1118 * Detach the current thread from the set visible to the VM.
1119 */
1120static int javaDetachThread(void)
1121{
1122 JavaVM* vm;
1123 jint result;
1124
1125 vm = AndroidRuntime::getJavaVM();
1126 assert(vm != NULL);
1127
1128 result = vm->DetachCurrentThread();
1129 if (result != JNI_OK)
Steve Block3762c312012-01-06 19:20:56 +00001130 ALOGE("ERROR: thread detach failed\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 return result;
1132}
1133
1134/*
1135 * When starting a native thread that will be visible from the VM, we
1136 * bounce through this to get the right attach/detach action.
1137 * Note that this function calls free(args)
1138 */
1139/*static*/ int AndroidRuntime::javaThreadShell(void* args) {
1140 void* start = ((void**)args)[0];
1141 void* userData = ((void **)args)[1];
1142 char* name = (char*) ((void **)args)[2]; // we own this storage
1143 free(args);
1144 JNIEnv* env;
1145 int result;
1146
1147 /* hook us into the VM */
1148 if (javaAttachThread(name, &env) != JNI_OK)
1149 return -1;
1150
1151 /* start the thread running */
1152 result = (*(android_thread_func_t)start)(userData);
1153
1154 /* unhook us */
1155 javaDetachThread();
1156 free(name);
1157
1158 return result;
1159}
1160
1161/*
1162 * This is invoked from androidCreateThreadEtc() via the callback
1163 * set with androidSetCreateThreadFunc().
1164 *
1165 * We need to create the new thread in such a way that it gets hooked
1166 * into the VM before it really starts executing.
1167 */
1168/*static*/ int AndroidRuntime::javaCreateThreadEtc(
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001169 android_thread_func_t entryFunction,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170 void* userData,
1171 const char* threadName,
1172 int32_t threadPriority,
1173 size_t threadStackSize,
1174 android_thread_id_t* threadId)
1175{
1176 void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free
1177 int result;
1178
Mike Lockwood32f2e622013-10-10 10:11:27 -07001179 if (!threadName)
1180 threadName = "unnamed thread";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001181
1182 args[0] = (void*) entryFunction;
1183 args[1] = userData;
1184 args[2] = (void*) strdup(threadName); // javaThreadShell must free
1185
1186 result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args,
1187 threadName, threadPriority, threadStackSize, threadId);
1188 return result;
1189}
1190
1191/*
1192 * Create a thread that is visible from the VM.
1193 *
1194 * This is called from elsewhere in the library.
1195 */
Mike Lockwoodf602d362010-06-20 14:28:16 -07001196/*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 void (*start)(void *), void* arg)
1198{
Mike Lockwoodf602d362010-06-20 14:28:16 -07001199 android_thread_id_t threadId = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001200 javaCreateThreadEtc((android_thread_func_t) start, arg, name,
Mike Lockwoodf602d362010-06-20 14:28:16 -07001201 ANDROID_PRIORITY_DEFAULT, 0, &threadId);
1202 return threadId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203}
1204
1205#if 0
1206static void quickTest(void* arg)
1207{
1208 const char* str = (const char*) arg;
1209
1210 printf("In quickTest: %s\n", str);
1211}
1212#endif
1213
1214#ifdef NDEBUG
1215 #define REG_JNI(name) { name }
1216 struct RegJNIRec {
1217 int (*mProc)(JNIEnv*);
1218 };
1219#else
1220 #define REG_JNI(name) { name, #name }
1221 struct RegJNIRec {
1222 int (*mProc)(JNIEnv*);
1223 const char* mName;
1224 };
1225#endif
1226
1227typedef void (*RegJAMProc)();
1228
1229static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env)
1230{
1231 for (size_t i = 0; i < count; i++) {
1232 if (array[i].mProc(env) < 0) {
1233#ifndef NDEBUG
Steve Block5baa3a62011-12-20 16:23:08 +00001234 ALOGD("----------!!! %s failed to load\n", array[i].mName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235#endif
1236 return -1;
1237 }
1238 }
1239 return 0;
1240}
1241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242static const RegJNIRec gRegJNI[] = {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 REG_JNI(register_com_android_internal_os_RuntimeInit),
1244 REG_JNI(register_android_os_SystemClock),
1245 REG_JNI(register_android_util_EventLog),
1246 REG_JNI(register_android_util_Log),
Doris Liucdd23f92015-11-11 14:31:13 -08001247 REG_JNI(register_android_util_PathParser),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 REG_JNI(register_android_content_AssetManager),
1249 REG_JNI(register_android_content_StringBlock),
1250 REG_JNI(register_android_content_XmlBlock),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251 REG_JNI(register_android_text_AndroidCharacter),
Anish Athalye88b5b0b2014-06-24 14:39:43 -07001252 REG_JNI(register_android_text_StaticLayout),
Doug Feltdae8e942010-02-24 14:33:15 -08001253 REG_JNI(register_android_text_AndroidBidi),
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001254 REG_JNI(register_android_view_InputDevice),
1255 REG_JNI(register_android_view_KeyCharacterMap),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 REG_JNI(register_android_os_Process),
Andreas Hubera8079bf2010-11-16 14:40:31 -08001257 REG_JNI(register_android_os_SystemProperties),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001258 REG_JNI(register_android_os_Binder),
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -08001259 REG_JNI(register_android_os_Parcel),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001260 REG_JNI(register_android_nio_utils),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001261 REG_JNI(register_android_graphics_Graphics),
Chris Craik54389792013-12-20 13:28:11 -08001262 REG_JNI(register_android_view_DisplayEventReceiver),
John Reckf666ad72014-03-14 16:24:57 -07001263 REG_JNI(register_android_view_RenderNode),
John Recke45b1fd2014-04-15 09:50:16 -07001264 REG_JNI(register_android_view_RenderNodeAnimator),
Romain Guy3b748a42013-04-17 18:54:38 -07001265 REG_JNI(register_android_view_GraphicBuffer),
Chris Craikc9070eb2015-03-09 18:50:14 -07001266 REG_JNI(register_android_view_DisplayListCanvas),
John Reck04fc5832014-02-05 16:38:25 -08001267 REG_JNI(register_android_view_HardwareLayer),
John Reckcec24ae2013-11-05 13:27:50 -08001268 REG_JNI(register_android_view_ThreadedRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269 REG_JNI(register_android_view_Surface),
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001270 REG_JNI(register_android_view_SurfaceControl),
Jeff Brown64a55af2012-08-26 02:47:39 -07001271 REG_JNI(register_android_view_SurfaceSession),
Romain Guy8f0095c2011-05-02 17:24:22 -07001272 REG_JNI(register_android_view_TextureView),
John Reck315c3292014-05-09 19:21:04 -07001273 REG_JNI(register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001274 REG_JNI(register_com_google_android_gles_jni_EGLImpl),
1275 REG_JNI(register_com_google_android_gles_jni_GLImpl),
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001276 REG_JNI(register_android_opengl_jni_EGL14),
Jesse Hall237c2b82013-05-06 11:36:57 -07001277 REG_JNI(register_android_opengl_jni_EGLExt),
Jack Palevich1c4907e2009-04-13 16:22:25 -07001278 REG_JNI(register_android_opengl_jni_GLES10),
1279 REG_JNI(register_android_opengl_jni_GLES10Ext),
1280 REG_JNI(register_android_opengl_jni_GLES11),
1281 REG_JNI(register_android_opengl_jni_GLES11Ext),
Jack Palevich560814f2009-11-19 16:34:55 +08001282 REG_JNI(register_android_opengl_jni_GLES20),
Jesse Halld877efe2013-04-29 15:59:35 -07001283 REG_JNI(register_android_opengl_jni_GLES30),
Jesse Hall7ab63ac2014-05-19 15:13:41 -07001284 REG_JNI(register_android_opengl_jni_GLES31),
1285 REG_JNI(register_android_opengl_jni_GLES31Ext),
Pablo Ceballos38c1a7e2015-10-30 10:34:30 -07001286 REG_JNI(register_android_opengl_jni_GLES32),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287
1288 REG_JNI(register_android_graphics_Bitmap),
1289 REG_JNI(register_android_graphics_BitmapFactory),
Wei-Ta Chen6b849e22010-09-07 17:32:18 +08001290 REG_JNI(register_android_graphics_BitmapRegionDecoder),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001291 REG_JNI(register_android_graphics_Camera),
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -04001292 REG_JNI(register_android_graphics_CreateJavaOutputStreamAdaptor),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001293 REG_JNI(register_android_graphics_Canvas),
John Reck52244ff2014-05-01 21:27:37 -07001294 REG_JNI(register_android_graphics_CanvasProperty),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001295 REG_JNI(register_android_graphics_ColorFilter),
1296 REG_JNI(register_android_graphics_DrawFilter),
Raph Levien1a73f7322014-01-30 16:06:28 -08001297 REG_JNI(register_android_graphics_FontFamily),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001298 REG_JNI(register_android_graphics_Interpolator),
1299 REG_JNI(register_android_graphics_LayerRasterizer),
1300 REG_JNI(register_android_graphics_MaskFilter),
1301 REG_JNI(register_android_graphics_Matrix),
1302 REG_JNI(register_android_graphics_Movie),
1303 REG_JNI(register_android_graphics_NinePatch),
1304 REG_JNI(register_android_graphics_Paint),
1305 REG_JNI(register_android_graphics_Path),
1306 REG_JNI(register_android_graphics_PathMeasure),
1307 REG_JNI(register_android_graphics_PathEffect),
1308 REG_JNI(register_android_graphics_Picture),
1309 REG_JNI(register_android_graphics_PorterDuff),
1310 REG_JNI(register_android_graphics_Rasterizer),
1311 REG_JNI(register_android_graphics_Region),
1312 REG_JNI(register_android_graphics_Shader),
Jamie Gennisaa0ce332011-01-06 17:04:26 -08001313 REG_JNI(register_android_graphics_SurfaceTexture),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001314 REG_JNI(register_android_graphics_Typeface),
1315 REG_JNI(register_android_graphics_Xfermode),
Wei-Ta Chenbca2d612009-11-30 17:52:05 +08001316 REG_JNI(register_android_graphics_YuvImage),
Doris Liu4bbc2932015-12-01 17:59:40 -08001317 REG_JNI(register_android_graphics_drawable_VectorDrawable),
Svetoslav6811f4e2013-09-18 15:58:28 -07001318 REG_JNI(register_android_graphics_pdf_PdfDocument),
Svetoslav62ce3322014-09-04 21:17:17 -07001319 REG_JNI(register_android_graphics_pdf_PdfEditor),
Svetoslav29617692014-04-24 18:40:42 -07001320 REG_JNI(register_android_graphics_pdf_PdfRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001321
1322 REG_JNI(register_android_database_CursorWindow),
Jeff Browne5360fb2011-10-31 17:48:13 -07001323 REG_JNI(register_android_database_SQLiteConnection),
1324 REG_JNI(register_android_database_SQLiteGlobal),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001325 REG_JNI(register_android_database_SQLiteDebug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001326 REG_JNI(register_android_os_Debug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001327 REG_JNI(register_android_os_FileObserver),
Christopher Tatefa9e7c02010-05-06 12:07:10 -07001328 REG_JNI(register_android_os_MessageQueue),
Stephen Smalleyc07fca32012-01-13 08:31:39 -05001329 REG_JNI(register_android_os_SELinux),
Jeff Brown481c1572012-03-09 14:41:15 -08001330 REG_JNI(register_android_os_Trace),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001331 REG_JNI(register_android_os_UEventObserver),
1332 REG_JNI(register_android_net_LocalSocketImpl),
1333 REG_JNI(register_android_net_NetworkUtils),
Dan Egnor2b4abcd2010-04-07 17:30:50 -07001334 REG_JNI(register_android_net_TrafficStats),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001335 REG_JNI(register_android_os_MemoryFile),
Narayan Kamath973b4662014-03-31 13:41:26 +01001336 REG_JNI(register_com_android_internal_os_Zygote),
John Reck9fa40712014-05-09 15:26:59 -07001337 REG_JNI(register_com_android_internal_util_VirtualRefBasePtr),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001338 REG_JNI(register_android_hardware_Camera),
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07001339 REG_JNI(register_android_hardware_camera2_CameraMetadata),
Ruben Brunkfeb50af2014-05-09 19:58:49 -07001340 REG_JNI(register_android_hardware_camera2_legacy_LegacyCameraDevice),
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -07001341 REG_JNI(register_android_hardware_camera2_legacy_PerfMeasurement),
Ruben Brunkb6079002014-05-22 12:33:54 -07001342 REG_JNI(register_android_hardware_camera2_DngCreator),
Eric Laurent633cb562015-03-05 15:17:20 -08001343 REG_JNI(register_android_hardware_Radio),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001344 REG_JNI(register_android_hardware_SensorManager),
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04001345 REG_JNI(register_android_hardware_SerialPort),
Eric Laurent60b62bc2014-04-18 17:50:49 -07001346 REG_JNI(register_android_hardware_SoundTrigger),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001347 REG_JNI(register_android_hardware_UsbDevice),
Mike Lockwoodacc29cc2011-03-11 08:18:08 -05001348 REG_JNI(register_android_hardware_UsbDeviceConnection),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001349 REG_JNI(register_android_hardware_UsbRequest),
destradaaa4fa3b52014-07-09 10:46:39 -07001350 REG_JNI(register_android_hardware_location_ActivityRecognitionHardware),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351 REG_JNI(register_android_media_AudioRecord),
1352 REG_JNI(register_android_media_AudioSystem),
1353 REG_JNI(register_android_media_AudioTrack),
1354 REG_JNI(register_android_media_JetPlayer),
Jeff Browncbad9762012-09-04 21:57:59 -07001355 REG_JNI(register_android_media_RemoteDisplay),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356 REG_JNI(register_android_media_ToneGenerator),
1357
1358 REG_JNI(register_android_opengl_classes),
JP Abgrall98a4f7e2011-09-02 15:36:33 -07001359 REG_JNI(register_android_server_NetworkManagementSocketTagger),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001360 REG_JNI(register_android_ddm_DdmHandleNativeHeap),
Joe Onorato1cf58742009-06-12 11:06:24 -07001361 REG_JNI(register_android_backup_BackupDataInput),
Joe Onoratod2110db2009-05-19 13:41:21 -07001362 REG_JNI(register_android_backup_BackupDataOutput),
Joe Onorato06290a42009-06-18 20:10:37 -07001363 REG_JNI(register_android_backup_FileBackupHelperBase),
Joe Onorato4ababd92009-06-25 18:29:18 -04001364 REG_JNI(register_android_backup_BackupHelperDispatcher),
Christopher Tate4a627c72011-04-01 14:43:32 -07001365 REG_JNI(register_android_app_backup_FullBackup),
Chet Haase9c1e23b2011-03-24 10:51:31 -07001366 REG_JNI(register_android_app_ActivityThread),
Dianne Hackborn69969e42010-05-04 11:40:40 -07001367 REG_JNI(register_android_app_NativeActivity),
Przemyslaw Szczepaniak8a7c1602015-11-03 09:47:56 +00001368 REG_JNI(register_android_util_jar_StrictJarFile),
Jeff Brown46b9ac02010-04-22 18:58:52 -07001369 REG_JNI(register_android_view_InputChannel),
Jeff Brown32cbc38552011-12-01 14:01:49 -08001370 REG_JNI(register_android_view_InputEventReceiver),
Jeff Brownc28867a2013-03-26 15:42:39 -07001371 REG_JNI(register_android_view_InputEventSender),
Michael Wrighta44dd262013-04-10 21:12:00 -07001372 REG_JNI(register_android_view_InputQueue),
Jeff Brown46b9ac02010-04-22 18:58:52 -07001373 REG_JNI(register_android_view_KeyEvent),
1374 REG_JNI(register_android_view_MotionEvent),
Jeff Brown2352b972011-04-12 22:39:53 -07001375 REG_JNI(register_android_view_PointerIcon),
Jeff Brown2ed24622011-03-14 19:39:54 -07001376 REG_JNI(register_android_view_VelocityTracker),
Kenny Root02c87302010-07-01 08:10:18 -07001377
1378 REG_JNI(register_android_content_res_ObbScanner),
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -07001379 REG_JNI(register_android_content_res_Configuration),
Chet Haase6e0ecb42010-11-03 19:41:18 -07001380
1381 REG_JNI(register_android_animation_PropertyValuesHolder),
Kenny Root66269ea2011-07-12 14:14:01 -07001382 REG_JNI(register_com_android_internal_content_NativeLibraryHelper),
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -08001383 REG_JNI(register_com_android_internal_net_NetworkStatsFactory),
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01001384 REG_JNI(register_android_os_HardwarePropertiesManager),
Przemyslaw Szczepaniak8a7c1602015-11-03 09:47:56 +00001385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001386};
1387
1388/*
1389 * Register android native functions with the VM.
1390 */
1391/*static*/ int AndroidRuntime::startReg(JNIEnv* env)
1392{
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001393 ATRACE_NAME("RegisterAndroidNatives");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001394 /*
1395 * This hook causes all future threads created in this process to be
1396 * attached to the JavaVM. (This needs to go away in favor of JNI
1397 * Attach calls.)
1398 */
1399 androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc);
1400
Steve Block71f2cf12011-10-20 11:56:00 +01001401 ALOGV("--- registering native functions ---\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001402
1403 /*
1404 * Every "register" function calls one or more things that return
1405 * a local reference (e.g. FindClass). Because we haven't really
1406 * started the VM yet, they're all getting stored in the base frame
1407 * and never released. Use Push/Pop to manage the storage.
1408 */
1409 env->PushLocalFrame(200);
1410
1411 if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) {
1412 env->PopLocalFrame(NULL);
1413 return -1;
1414 }
1415 env->PopLocalFrame(NULL);
1416
1417 //createJavaThread("fubar", quickTest, (void*) "hello");
1418
1419 return 0;
1420}
1421
1422AndroidRuntime* AndroidRuntime::getRuntime()
1423{
1424 return gCurRuntime;
1425}
1426
1427/**
Narayan Kamathc21dab92015-06-25 14:22:00 +01001428 * Used by surface flinger's DdmConnection to register native methods from
1429 * the framework.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001430 */
Narayan Kamathc21dab92015-06-25 14:22:00 +01001431extern "C" jint registerFrameworkNatives(JNIEnv* env) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1433}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001434} // namespace android