blob: facc0f998bdaa4cb458280508cc244cbc5392287 [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);
Peng Xu9ff7d222016-02-11 13:02:05 -080098extern int register_android_hardware_location_ContextHubService(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099
100extern int register_android_media_AudioRecord(JNIEnv *env);
101extern int register_android_media_AudioSystem(JNIEnv *env);
102extern int register_android_media_AudioTrack(JNIEnv *env);
103extern int register_android_media_JetPlayer(JNIEnv *env);
104extern int register_android_media_ToneGenerator(JNIEnv *env);
105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106namespace android {
107
108/*
109 * JNI-based registration functions. Note these are properly contained in
110 * namespace android.
111 */
Michal Karpinski6235a942016-03-15 12:07:23 +0000112extern int register_android_app_admin_SecurityLog(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113extern int register_android_content_AssetManager(JNIEnv* env);
114extern int register_android_util_EventLog(JNIEnv* env);
115extern int register_android_util_Log(JNIEnv* env);
Svet Ganov53a441c2016-04-19 19:38:00 -0700116extern int register_android_util_MemoryIntArray(JNIEnv* env);
Doris Liucdd23f92015-11-11 14:31:13 -0800117extern int register_android_util_PathParser(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118extern int register_android_content_StringBlock(JNIEnv* env);
119extern int register_android_content_XmlBlock(JNIEnv* env);
120extern int register_android_graphics_Canvas(JNIEnv* env);
John Reck52244ff2014-05-01 21:27:37 -0700121extern int register_android_graphics_CanvasProperty(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122extern int register_android_graphics_ColorFilter(JNIEnv* env);
123extern int register_android_graphics_DrawFilter(JNIEnv* env);
Raph Levien1a73f7322014-01-30 16:06:28 -0800124extern int register_android_graphics_FontFamily(JNIEnv* env);
Mike Reed4c9355c2014-05-07 11:48:37 -0400125extern int register_android_graphics_LayerRasterizer(JNIEnv*);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126extern int register_android_graphics_Matrix(JNIEnv* env);
127extern int register_android_graphics_Paint(JNIEnv* env);
128extern int register_android_graphics_Path(JNIEnv* env);
129extern int register_android_graphics_PathMeasure(JNIEnv* env);
130extern int register_android_graphics_Picture(JNIEnv*);
131extern int register_android_graphics_PorterDuff(JNIEnv* env);
132extern int register_android_graphics_Rasterizer(JNIEnv* env);
Jeff Brownfbf09772011-01-16 14:06:57 -0800133extern int register_android_graphics_Region(JNIEnv* env);
Jamie Gennisaa0ce332011-01-06 17:04:26 -0800134extern int register_android_graphics_SurfaceTexture(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135extern int register_android_graphics_Xfermode(JNIEnv* env);
Doris Liu766431a2016-02-04 22:17:11 +0000136extern int register_android_graphics_drawable_AnimatedVectorDrawable(JNIEnv* env);
Doris Liu4bbc2932015-12-01 17:59:40 -0800137extern int register_android_graphics_drawable_VectorDrawable(JNIEnv* env);
Svetoslav6811f4e2013-09-18 15:58:28 -0700138extern int register_android_graphics_pdf_PdfDocument(JNIEnv* env);
Svetoslav62ce3322014-09-04 21:17:17 -0700139extern int register_android_graphics_pdf_PdfEditor(JNIEnv* env);
Svetoslav29617692014-04-24 18:40:42 -0700140extern int register_android_graphics_pdf_PdfRenderer(JNIEnv* env);
Jeff Brown0a0a1242011-12-02 02:25:22 -0800141extern int register_android_view_DisplayEventReceiver(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700142extern int register_android_view_DisplayListCanvas(JNIEnv* env);
143extern int register_android_view_GraphicBuffer(JNIEnv* env);
144extern int register_android_view_HardwareLayer(JNIEnv* env);
John Reckf666ad72014-03-14 16:24:57 -0700145extern int register_android_view_RenderNode(JNIEnv* env);
John Recke45b1fd2014-04-15 09:50:16 -0700146extern int register_android_view_RenderNodeAnimator(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147extern int register_android_view_Surface(JNIEnv* env);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800148extern int register_android_view_SurfaceControl(JNIEnv* env);
Jeff Brown64a55af2012-08-26 02:47:39 -0700149extern int register_android_view_SurfaceSession(JNIEnv* env);
Romain Guy8f0095c2011-05-02 17:24:22 -0700150extern int register_android_view_TextureView(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700151extern int register_android_view_ThreadedRenderer(JNIEnv* env);
John Reck315c3292014-05-09 19:21:04 -0700152extern int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153extern int register_android_database_CursorWindow(JNIEnv* env);
Jeff Browne5360fb2011-10-31 17:48:13 -0700154extern int register_android_database_SQLiteConnection(JNIEnv* env);
155extern int register_android_database_SQLiteGlobal(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156extern int register_android_database_SQLiteDebug(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157extern int register_android_nio_utils(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158extern int register_android_os_Debug(JNIEnv* env);
Jesse Hall17ee3aa2016-12-12 12:53:02 -0800159extern int register_android_os_GraphicsEnvironment(JNIEnv* env);
Andreas Huber7f5fcab2016-08-15 09:25:02 -0700160extern int register_android_os_HwBinder(JNIEnv *env);
Andreas Huber50546a92016-08-25 11:21:21 -0700161extern int register_android_os_HwBlob(JNIEnv *env);
Andreas Huber7f5fcab2016-08-15 09:25:02 -0700162extern int register_android_os_HwParcel(JNIEnv *env);
163extern int register_android_os_HwRemoteBinder(JNIEnv *env);
Christopher Tatefa9e7c02010-05-06 12:07:10 -0700164extern int register_android_os_MessageQueue(JNIEnv* env);
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -0800165extern int register_android_os_Parcel(JNIEnv* env);
Stephen Smalleyc07fca32012-01-13 08:31:39 -0500166extern int register_android_os_SELinux(JNIEnv* env);
Yifan Hong4e01db82017-04-05 14:42:05 -0700167extern int register_android_os_VintfObject(JNIEnv *env);
Yifan Hong1bda6732017-04-26 11:38:01 -0700168extern int register_android_os_VintfRuntimeInfo(JNIEnv *env);
Paul Lawrenceef854772017-01-31 09:54:31 -0800169extern int register_android_os_seccomp(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170extern int register_android_os_SystemProperties(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171extern int register_android_os_SystemClock(JNIEnv* env);
Jeff Brown481c1572012-03-09 14:41:15 -0800172extern int register_android_os_Trace(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173extern int register_android_os_FileObserver(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174extern int register_android_os_UEventObserver(JNIEnv* env);
175extern int register_android_os_MemoryFile(JNIEnv* env);
176extern int register_android_net_LocalSocketImpl(JNIEnv* env);
177extern int register_android_net_NetworkUtils(JNIEnv* env);
Dan Egnor2b4abcd2010-04-07 17:30:50 -0700178extern int register_android_net_TrafficStats(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179extern int register_android_text_AndroidCharacter(JNIEnv *env);
Anish Athalye88b5b0b2014-06-24 14:39:43 -0700180extern int register_android_text_StaticLayout(JNIEnv *env);
Doug Feltdae8e942010-02-24 14:33:15 -0800181extern int register_android_text_AndroidBidi(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182extern int register_android_opengl_classes(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
Narayan Kamath29564cd2014-08-07 10:57:40 +0100184extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env);
Joe Onorato1cf58742009-06-12 11:06:24 -0700185extern int register_android_backup_BackupDataInput(JNIEnv *env);
Joe Onoratod2110db2009-05-19 13:41:21 -0700186extern int register_android_backup_BackupDataOutput(JNIEnv *env);
Joe Onorato06290a42009-06-18 20:10:37 -0700187extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
Joe Onorato4ababd92009-06-25 18:29:18 -0400188extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
Christopher Tate4a627c72011-04-01 14:43:32 -0700189extern int register_android_app_backup_FullBackup(JNIEnv *env);
Dimitry Ivanov4449ef52016-02-25 17:41:13 -0800190extern int register_android_app_Activity(JNIEnv *env);
Chet Haase9c1e23b2011-03-24 10:51:31 -0700191extern int register_android_app_ActivityThread(JNIEnv *env);
Dimitry Ivanov09979082016-04-19 11:11:01 -0700192extern int register_android_app_ApplicationLoaders(JNIEnv *env);
Dianne Hackborn69969e42010-05-04 11:40:40 -0700193extern int register_android_app_NativeActivity(JNIEnv *env);
Jeff Browncbad9762012-09-04 21:57:59 -0700194extern int register_android_media_RemoteDisplay(JNIEnv *env);
Przemyslaw Szczepaniak8a7c1602015-11-03 09:47:56 +0000195extern int register_android_util_jar_StrictJarFile(JNIEnv* env);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700196extern int register_android_view_InputChannel(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700197extern int register_android_view_InputDevice(JNIEnv* env);
Jeff Brown32cbc38552011-12-01 14:01:49 -0800198extern int register_android_view_InputEventReceiver(JNIEnv* env);
Jeff Brownc28867a2013-03-26 15:42:39 -0700199extern int register_android_view_InputEventSender(JNIEnv* env);
Michael Wrighta44dd262013-04-10 21:12:00 -0700200extern int register_android_view_InputQueue(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700201extern int register_android_view_KeyCharacterMap(JNIEnv *env);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700202extern int register_android_view_KeyEvent(JNIEnv* env);
203extern int register_android_view_MotionEvent(JNIEnv* env);
Jeff Brown2352b972011-04-12 22:39:53 -0700204extern int register_android_view_PointerIcon(JNIEnv* env);
Jeff Brown2ed24622011-03-14 19:39:54 -0700205extern int register_android_view_VelocityTracker(JNIEnv* env);
Kenny Root02c87302010-07-01 08:10:18 -0700206extern int register_android_content_res_ObbScanner(JNIEnv* env);
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700207extern int register_android_content_res_Configuration(JNIEnv* env);
Chet Haase6e0ecb42010-11-03 19:41:18 -0700208extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
Kenny Root66269ea2011-07-12 14:14:01 -0700209extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -0800210extern int register_com_android_internal_net_NetworkStatsFactory(JNIEnv *env);
Dimitry Ivanovb1ef62b2016-04-20 14:09:32 -0700211extern int register_com_android_internal_os_PathClassLoaderFactory(JNIEnv* env);
Narayan Kamath973b4662014-03-31 13:41:26 +0100212extern int register_com_android_internal_os_Zygote(JNIEnv *env);
John Reck9fa40712014-05-09 15:26:59 -0700213extern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214
215static AndroidRuntime* gCurRuntime = NULL;
216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217/*
218 * Code written in the Java Programming Language calls here from main().
219 */
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700220static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221{
222 gCurRuntime->onStarted();
223}
224
Andreas Gampe4e66db82017-02-07 19:44:37 -0800225static void com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226{
227 gCurRuntime->onZygoteInit();
228}
229
Jeff Brown4280c4a2012-03-15 17:48:02 -0700230static void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIEnv* env,
231 jobject clazz, jboolean exitWithoutCleanup)
232{
233 gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup);
234}
235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236/*
237 * JNI registration.
238 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239
240int register_com_android_internal_os_RuntimeInit(JNIEnv* env)
241{
Andreas Gampe4e66db82017-02-07 19:44:37 -0800242 const JNINativeMethod methods[] = {
243 { "nativeFinishInit", "()V",
244 (void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
245 { "nativeSetExitWithoutCleanup", "(Z)V",
246 (void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
247 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
Andreas Gampe4e66db82017-02-07 19:44:37 -0800249 methods, NELEM(methods));
250}
251
252int register_com_android_internal_os_ZygoteInit(JNIEnv* env)
253{
254 const JNINativeMethod methods[] = {
255 { "nativeZygoteInit", "()V",
256 (void*) com_android_internal_os_ZygoteInit_nativeZygoteInit },
257 };
258 return jniRegisterNativeMethods(env, "com/android/internal/os/ZygoteInit",
259 methods, NELEM(methods));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260}
261
262// ----------------------------------------------------------------------
263
Andreas Huber9ae000c2014-02-13 17:22:33 +0000264/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
265
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000266AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) :
267 mExitWithoutCleanup(false),
268 mArgBlockStart(argBlockStart),
269 mArgBlockLength(argBlockLength)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700271 SkGraphics::Init();
Ben Wagner177612332015-01-15 14:16:46 -0500272 // There is also a global font cache, but its budget is specified by
273 // SK_DEFAULT_FONT_CACHE_COUNT_LIMIT and SK_DEFAULT_FONT_CACHE_LIMIT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274
275 // Pre-allocate enough space to hold a fair number of options.
276 mOptions.setCapacity(20);
277
278 assert(gCurRuntime == NULL); // one per process
279 gCurRuntime = this;
280}
281
282AndroidRuntime::~AndroidRuntime()
283{
284 SkGraphics::Term();
285}
286
Andreas Huber9ae000c2014-02-13 17:22:33 +0000287/*
288 * Register native methods using JNI.
289 */
290/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
291 const char* className, const JNINativeMethod* gMethods, int numMethods)
292{
293 return jniRegisterNativeMethods(env, className, gMethods, numMethods);
294}
295
Dmitriy Filchenkof5b6e552016-07-18 16:00:35 -0700296void AndroidRuntime::setArgv0(const char* argv0, bool setProcName) {
297 if (setProcName) {
298 int len = strlen(argv0);
299 if (len < 15) {
300 pthread_setname_np(pthread_self(), argv0);
301 } else {
302 pthread_setname_np(pthread_self(), argv0 + len - 15);
303 }
304 }
Jeff Brown00c0cd42014-09-10 16:48:46 -0700305 memset(mArgBlockStart, 0, mArgBlockLength);
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000306 strlcpy(mArgBlockStart, argv0, mArgBlockLength);
307}
308
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100309status_t AndroidRuntime::callMain(const String8& className, jclass clazz,
310 const Vector<String8>& args)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311{
312 JNIEnv* env;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313 jmethodID methodId;
314
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100315 ALOGD("Calling main entry %s", className.string());
Dianne Hackborn08e60f22010-09-01 18:17:17 -0700316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 env = getJNIEnv();
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700318 if (clazz == NULL || env == NULL) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 return UNKNOWN_ERROR;
320 }
321
322 methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
323 if (methodId == NULL) {
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100324 ALOGE("ERROR: could not find method %s.main(String[])\n", className.string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 return UNKNOWN_ERROR;
326 }
327
328 /*
329 * We want to call main() with a String array with our arguments in it.
330 * Create an array and populate it.
331 */
332 jclass stringClass;
333 jobjectArray strArray;
334
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100335 const size_t numArgs = args.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336 stringClass = env->FindClass("java/lang/String");
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100337 strArray = env->NewObjectArray(numArgs, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100339 for (size_t i = 0; i < numArgs; i++) {
340 jstring argStr = env->NewStringUTF(args[i].string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 env->SetObjectArrayElement(strArray, i, argStr);
342 }
343
344 env->CallStaticVoidMethod(clazz, methodId, strArray);
345 return NO_ERROR;
346}
347
348/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 * The VM calls this through the "exit" hook.
350 */
351static void runtime_exit(int code)
352{
Jeff Brown4280c4a2012-03-15 17:48:02 -0700353 gCurRuntime->exit(code);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354}
355
356/*
357 * The VM calls this through the "vfprintf" hook.
358 *
359 * We ignore "fp" and just write the results to the log file.
360 */
361static void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
362{
363 LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
364}
365
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800366/**
367 * The VM calls this when mutex contention debugging is enabled to
368 * determine whether or not the blocked thread was a "sensitive thread"
369 * for user responsiveness/smoothess.
370 *
371 * Our policy for this is whether or not we're tracing any StrictMode
372 * events on this thread (which we might've inherited via Binder calls
373 * into us)
374 */
375static bool runtime_isSensitiveThread() {
376 IPCThreadState* state = IPCThreadState::selfOrNull();
377 return state && state->getStrictModePolicy() != 0;
378}
379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380static int hasDir(const char* dir)
381{
382 struct stat s;
383 int res = stat(dir, &s);
384 if (res == 0) {
385 return S_ISDIR(s.st_mode);
386 }
387 return 0;
388}
389
Andreas Gampe995c62d2014-11-14 16:15:17 -0800390static bool hasFile(const char* file) {
391 struct stat s;
392 int res = stat(file, &s);
393 if (res == 0) {
394 return S_ISREG(s.st_mode);
395 }
396 return false;
397}
398
Narayan Kamathbf882052015-08-11 15:40:34 +0100399// Convenience wrapper over the property API that returns an
400// std::string.
401std::string getProperty(const char* key, const char* defaultValue) {
402 std::vector<char> temp(PROPERTY_VALUE_MAX);
403 const int len = property_get(key, &temp[0], defaultValue);
404 if (len < 0) {
405 return "";
406 }
407 return std::string(&temp[0], len);
408}
409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410/*
Narayan Kamathbf882052015-08-11 15:40:34 +0100411 * Read the persistent locale. Inspects the following system properties
412 * (in order) and returns the first non-empty property in the list :
413 *
414 * (1) persist.sys.locale
415 * (2) persist.sys.language/country/localevar (country and localevar are
416 * inspected iff. language is non-empty.
417 * (3) ro.product.locale
418 * (4) ro.product.locale.language/region
419 *
420 * Note that we need to inspect persist.sys.language/country/localevar to
421 * preserve language settings for devices that are upgrading from Lollipop
422 * to M. The same goes for ro.product.locale.language/region as well.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 */
Narayan Kamathbf882052015-08-11 15:40:34 +0100424const std::string readLocale()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425{
Narayan Kamathbf882052015-08-11 15:40:34 +0100426 const std::string locale = getProperty("persist.sys.locale", "");
427 if (!locale.empty()) {
428 return locale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 }
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000430
Narayan Kamathbf882052015-08-11 15:40:34 +0100431 const std::string language = getProperty("persist.sys.language", "");
432 if (!language.empty()) {
433 const std::string country = getProperty("persist.sys.country", "");
434 const std::string variant = getProperty("persist.sys.localevar", "");
435
436 std::string out = language;
437 if (!country.empty()) {
438 out = out + "-" + country;
439 }
440
441 if (!variant.empty()) {
442 out = out + "-" + variant;
443 }
444
445 return out;
446 }
447
448 const std::string productLocale = getProperty("ro.product.locale", "");
449 if (!productLocale.empty()) {
450 return productLocale;
451 }
452
453 // If persist.sys.locale and ro.product.locale are missing,
454 // construct a locale value from the individual locale components.
455 const std::string productLanguage = getProperty("ro.product.locale.language", "en");
456 const std::string productRegion = getProperty("ro.product.locale.region", "US");
457
458 return productLanguage + "-" + productRegion;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459}
460
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700461void AndroidRuntime::addOption(const char* optionString, void* extraInfo)
462{
463 JavaVMOption opt;
464 opt.optionString = optionString;
465 opt.extraInfo = extraInfo;
466 mOptions.add(opt);
467}
468
Andy McFaddenf70188a2009-03-31 15:52:13 -0700469/*
Andy McFaddene4d81f22010-07-14 16:02:20 -0700470 * Parse a property containing space-separated options that should be
471 * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
472 *
473 * This will cut up "extraOptsBuf" as we chop it into individual options.
474 *
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800475 * If "quotingArg" is non-null, it is passed before each extra option in mOptions.
476 *
Andy McFaddene4d81f22010-07-14 16:02:20 -0700477 * Adds the strings, if any, to mOptions.
478 */
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800479void AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg)
Andy McFaddene4d81f22010-07-14 16:02:20 -0700480{
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800481 char* start = extraOptsBuf;
482 char* end = NULL;
Andy McFaddene4d81f22010-07-14 16:02:20 -0700483 while (*start != '\0') {
484 while (*start == ' ') /* skip leading whitespace */
485 start++;
486 if (*start == '\0') /* was trailing ws, bail */
487 break;
488
489 end = start+1;
490 while (*end != ' ' && *end != '\0') /* find end of token */
491 end++;
492 if (*end == ' ')
493 *end++ = '\0'; /* mark end, advance to indicate more */
494
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800495 if (quotingArg != NULL) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700496 addOption(quotingArg);
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800497 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700498 addOption(start);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700499 start = end;
500 }
501}
502
503/*
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700504 * Reads a "property" into "buffer" with a default of "defaultArg". If
505 * the property is non-empty, it is treated as a runtime option such
506 * as "-Xmx32m".
507 *
508 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
509 *
510 * If an argument is found, it is added to mOptions.
511 *
512 * If an option is found, it is added to mOptions and true is
513 * returned. Otherwise false is returned.
514 */
515bool AndroidRuntime::parseRuntimeOption(const char* property,
516 char* buffer,
517 const char* runtimeArg,
518 const char* defaultArg)
519{
520 strcpy(buffer, runtimeArg);
521 size_t runtimeArgLen = strlen(runtimeArg);
522 property_get(property, buffer+runtimeArgLen, defaultArg);
523 if (buffer[runtimeArgLen] == '\0') {
524 return false;
525 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700526 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700527 return true;
528}
529
530/*
531 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700532 * is treated as a dex2oat compiler option that should be
Nicolas Geoffraybe7b0d12017-04-25 12:29:07 +0100533 * passed as a quoted option, e.g. "-Ximage-compiler-option --compiler-filter=assume-verified".
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700534 *
535 * The "compilerArg" is a prefix for the option such as "--compiler-filter=".
536 *
537 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
538 *
539 * If an option is found, it is added to mOptions and true is
540 * returned. Otherwise false is returned.
541 */
542bool AndroidRuntime::parseCompilerOption(const char* property,
543 char* buffer,
544 const char* compilerArg,
545 const char* quotingArg)
546{
547 strcpy(buffer, compilerArg);
548 size_t compilerArgLen = strlen(compilerArg);
549 property_get(property, buffer+compilerArgLen, "");
550 if (buffer[compilerArgLen] == '\0') {
551 return false;
552 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700553 addOption(quotingArg);
554 addOption(buffer);
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700555 return true;
556}
557
558/*
559 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700560 * is treated as a dex2oat compiler runtime option that should be
561 * passed as a quoted option, e.g. "-Ximage-compiler-option
562 * --runtime-arg -Ximage-compiler-option -Xmx32m".
563 *
564 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
565 *
566 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
567 *
568 * If an option is found, it is added to mOptions and true is
569 * returned. Otherwise false is returned.
570 */
571bool AndroidRuntime::parseCompilerRuntimeOption(const char* property,
572 char* buffer,
573 const char* runtimeArg,
574 const char* quotingArg)
575{
576 strcpy(buffer, runtimeArg);
577 size_t runtimeArgLen = strlen(runtimeArg);
578 property_get(property, buffer+runtimeArgLen, "");
579 if (buffer[runtimeArgLen] == '\0') {
580 return false;
581 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700582 addOption(quotingArg);
583 addOption("--runtime-arg");
584 addOption(quotingArg);
585 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700586 return true;
587}
588
589/*
Andy McFaddenf70188a2009-03-31 15:52:13 -0700590 * Start the Dalvik Virtual Machine.
591 *
592 * Various arguments, most determined by system properties, are passed in.
593 * The "mOptions" vector is updated.
594 *
Dave Allison07a1e232014-03-14 08:54:33 -0700595 * CAUTION: when adding options in here, be careful not to put the
596 * char buffer inside a nested scope. Adding the buffer to the
597 * options using mOptions.add() does not copy the buffer, so if the
598 * buffer goes out of scope the option may be overwritten. It's best
599 * to put the buffer at the top of the function so that it is more
600 * unlikely that someone will surround it in a scope at a later time
601 * and thus introduce a bug.
602 *
Andy McFaddenf70188a2009-03-31 15:52:13 -0700603 * Returns 0 on success.
604 */
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200605int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800606{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 JavaVMInitArgs initArgs;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 char propBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700609 char stackTraceFileBuf[sizeof("-Xstacktracefile:")-1 + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro38cfa8c2010-12-07 16:48:29 -0800611 char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700612 char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro8cdf27c32011-01-19 12:33:12 -0800613 char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700614 char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
615 char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800616 char usejitOptsBuf[sizeof("-Xusejit:")-1 + PROPERTY_VALUE_MAX];
Nicolas Geoffraycdf1dff2015-11-19 13:48:35 +0000617 char jitmaxsizeOptsBuf[sizeof("-Xjitmaxsize:")-1 + PROPERTY_VALUE_MAX];
618 char jitinitialsizeOptsBuf[sizeof("-Xjitinitialsize:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800619 char jitthresholdOptsBuf[sizeof("-Xjitthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravledb4a79a2015-12-23 18:55:08 +0200620 char useJitProfilesOptsBuf[sizeof("-Xjitsaveprofilinginfo:")-1 + PROPERTY_VALUE_MAX];
Calin Juravleaa9ecac2016-04-12 14:12:04 +0100621 char jitprithreadweightOptBuf[sizeof("-Xjitprithreadweight:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle8d74de52016-04-27 14:12:00 +0100622 char jittransitionweightOptBuf[sizeof("-Xjittransitionweight:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier42cd2652017-06-07 17:34:22 -0700623 char hotstartupsamplesOptsBuf[sizeof("-Xps-hot-startup-method-samples:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier7e4fdec2013-12-02 15:46:51 -0800624 char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700625 char backgroundgcOptsBuf[sizeof("-XX:BackgroundGC=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700626 char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee324ba02015-03-31 16:15:17 -0700627 char cachePruneBuf[sizeof("-Xzygote-max-boot-retry=")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700628 char dex2oatXmsImageFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
629 char dex2oatXmxImageFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
630 char dex2oatXmsFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
631 char dex2oatXmxFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700632 char dex2oatCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
633 char dex2oatImageCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee0352382015-03-30 18:43:39 -0700634 char dex2oatThreadsBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
635 char dex2oatThreadsImageBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
Andreas Gampe605cca12015-04-02 23:12:56 -0700636 char dex2oat_isa_variant_key[PROPERTY_KEY_MAX];
637 char dex2oat_isa_variant[sizeof("--instruction-set-variant=") -1 + PROPERTY_VALUE_MAX];
638 char dex2oat_isa_features_key[PROPERTY_KEY_MAX];
639 char dex2oat_isa_features[sizeof("--instruction-set-features=") -1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800640 char dex2oatFlagsBuf[PROPERTY_VALUE_MAX];
641 char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX];
Andy McFaddene4d81f22010-07-14 16:02:20 -0700642 char extraOptsBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700643 char voldDecryptBuf[PROPERTY_VALUE_MAX];
Ben Cheng52b0e732009-06-19 13:31:12 -0700644 enum {
645 kEMDefault,
646 kEMIntPortable,
647 kEMIntFast,
Ben Cheng52b0e732009-06-19 13:31:12 -0700648 kEMJitCompiler,
Ben Cheng52b0e732009-06-19 13:31:12 -0700649 } executionMode = kEMDefault;
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000650 char localeOption[sizeof("-Duser.locale=") + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700651 char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle01db9162014-08-07 14:45:53 +0100652 char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX];
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700653 char cpuAbiListBuf[sizeof("--cpu-abilist=") + PROPERTY_VALUE_MAX];
Andreas Gampe98f406f2015-06-22 21:09:36 -0700654 char methodTraceFileBuf[sizeof("-Xmethod-trace-file:") + PROPERTY_VALUE_MAX];
655 char methodTraceFileSizeBuf[sizeof("-Xmethod-trace-file-size:") + PROPERTY_VALUE_MAX];
Andreas Gampee6082502015-07-24 14:19:44 -0700656 char fingerprintBuf[sizeof("-Xfingerprint:") + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800657
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700658 bool checkJni = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 property_get("dalvik.vm.checkjni", propBuf, "");
660 if (strcmp(propBuf, "true") == 0) {
661 checkJni = true;
662 } else if (strcmp(propBuf, "false") != 0) {
663 /* property is neither true nor false; fall back on kernel parameter */
664 property_get("ro.kernel.android.checkjni", propBuf, "");
665 if (propBuf[0] == '1') {
666 checkJni = true;
667 }
668 }
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700669 ALOGD("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
670 if (checkJni) {
671 /* extended JNI checking */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700672 addOption("-Xcheck:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700673
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700674 /* with -Xcheck:jni, this provides a JNI function call trace */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700675 //addOption("-verbose:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700676 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677
678 property_get("dalvik.vm.execution-mode", propBuf, "");
679 if (strcmp(propBuf, "int:portable") == 0) {
680 executionMode = kEMIntPortable;
681 } else if (strcmp(propBuf, "int:fast") == 0) {
682 executionMode = kEMIntFast;
Ben Cheng52b0e732009-06-19 13:31:12 -0700683 } else if (strcmp(propBuf, "int:jit") == 0) {
684 executionMode = kEMJitCompiler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 }
686
Narayan Kamath93f2e382017-04-25 14:24:07 +0100687 // If dalvik.vm.stack-trace-dir is set, it enables the "new" stack trace
688 // dump scheme and a new file is created for each stack dump. If it isn't set,
689 // the old scheme is enabled.
Narayan Kamath23941e52017-05-10 18:56:12 +0100690 property_get("dalvik.vm.stack-trace-dir", propBuf, "");
691 if (strlen(propBuf) > 0) {
692 addOption("-Xusetombstonedtraces");
693 } else {
Narayan Kamath93f2e382017-04-25 14:24:07 +0100694 parseRuntimeOption("dalvik.vm.stack-trace-file", stackTraceFileBuf, "-Xstacktracefile:");
695 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800697 strcpy(jniOptsBuf, "-Xjniopts:");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700698 if (parseRuntimeOption("dalvik.vm.jniopts", jniOptsBuf, "-Xjniopts:")) {
699 ALOGI("JNI options: '%s'\n", jniOptsBuf);
700 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800702 /* route exit() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700703 addOption("exit", (void*) runtime_exit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800704
705 /* route fprintf() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700706 addOption("vfprintf", (void*) runtime_vfprintf);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800708 /* register the framework-specific "is sensitive thread" hook */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700709 addOption("sensitiveThread", (void*) runtime_isSensitiveThread);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710
711 /* enable verbose; standard options are { jni, gc, class } */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700712 //addOption("-verbose:jni");
713 addOption("-verbose:gc");
714 //addOption("-verbose:class");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800715
Carl Shapiro9e4c8842010-12-08 12:14:46 -0800716 /*
717 * The default starting and maximum size of the heap. Larger
718 * values should be specified in a product property override.
719 */
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700720 parseRuntimeOption("dalvik.vm.heapstartsize", heapstartsizeOptsBuf, "-Xms", "4m");
721 parseRuntimeOption("dalvik.vm.heapsize", heapsizeOptsBuf, "-Xmx", "16m");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700723 parseRuntimeOption("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
724 parseRuntimeOption("dalvik.vm.heapminfree", heapminfreeOptsBuf, "-XX:HeapMinFree=");
725 parseRuntimeOption("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf, "-XX:HeapMaxFree=");
726 parseRuntimeOption("dalvik.vm.heaptargetutilization",
727 heaptargetutilizationOptsBuf,
728 "-XX:HeapTargetUtilization=");
Ian Rogers53250102012-09-23 16:38:03 -0700729
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800730 /*
731 * JIT related options.
732 */
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700733 parseRuntimeOption("dalvik.vm.usejit", usejitOptsBuf, "-Xusejit:");
Nicolas Geoffraycdf1dff2015-11-19 13:48:35 +0000734 parseRuntimeOption("dalvik.vm.jitmaxsize", jitmaxsizeOptsBuf, "-Xjitmaxsize:");
735 parseRuntimeOption("dalvik.vm.jitinitialsize", jitinitialsizeOptsBuf, "-Xjitinitialsize:");
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700736 parseRuntimeOption("dalvik.vm.jitthreshold", jitthresholdOptsBuf, "-Xjitthreshold:");
Calin Juravledb4a79a2015-12-23 18:55:08 +0200737 property_get("dalvik.vm.usejitprofiles", useJitProfilesOptsBuf, "");
738 if (strcmp(useJitProfilesOptsBuf, "true") == 0) {
739 addOption("-Xjitsaveprofilinginfo");
740 }
Calin Juravle8d74de52016-04-27 14:12:00 +0100741
Calin Juravleaa9ecac2016-04-12 14:12:04 +0100742 parseRuntimeOption("dalvik.vm.jitprithreadweight",
743 jitprithreadweightOptBuf,
744 "-Xjitprithreadweight:");
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800745
Calin Juravle8d74de52016-04-27 14:12:00 +0100746 parseRuntimeOption("dalvik.vm.jittransitionweight",
747 jittransitionweightOptBuf,
748 "-Xjittransitionweight:");
749
Mathieu Chartier42cd2652017-06-07 17:34:22 -0700750 /*
751 * Profile related options.
752 */
753 parseRuntimeOption("dalvik.vm.hot-startup-method-samples", hotstartupsamplesOptsBuf,
754 "-Xps-hot-startup-method-samples:");
755
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700756 property_get("ro.config.low_ram", propBuf, "");
757 if (strcmp(propBuf, "true") == 0) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700758 addOption("-XX:LowMemoryMode");
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700759 }
760
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700761 parseRuntimeOption("dalvik.vm.gctype", gctypeOptsBuf, "-Xgc:");
762 parseRuntimeOption("dalvik.vm.backgroundgctype", backgroundgcOptsBuf, "-XX:BackgroundGC=");
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700763
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200764 /*
765 * Enable debugging only for apps forked from zygote.
766 * Set suspend=y to pause during VM init and use android ADB transport.
767 */
768 if (zygote) {
769 addOption("-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y");
770 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700772 parseRuntimeOption("dalvik.vm.lockprof.threshold",
773 lockProfThresholdBuf,
774 "-Xlockprofthreshold:");
Carl Shapirod8f3ec62010-04-12 16:31:59 -0700775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800776 if (executionMode == kEMIntPortable) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700777 addOption("-Xint:portable");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800778 } else if (executionMode == kEMIntFast) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700779 addOption("-Xint:fast");
Ben Cheng52b0e732009-06-19 13:31:12 -0700780 } else if (executionMode == kEMJitCompiler) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700781 addOption("-Xint:jit");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800782 }
Andy McFaddene2b23e12009-04-03 11:09:46 -0700783
Andreas Gampe08b2d582014-12-18 14:39:22 -0800784 // If we are booting without the real /data, don't spend time compiling.
785 property_get("vold.decrypt", voldDecryptBuf, "");
786 bool skip_compilation = ((strcmp(voldDecryptBuf, "trigger_restart_min_framework") == 0) ||
787 (strcmp(voldDecryptBuf, "1") == 0));
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800788
Andreas Gampe08b2d582014-12-18 14:39:22 -0800789 // Extra options for boot.art/boot.oat image generation.
790 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xms", dex2oatXmsImageFlagsBuf,
791 "-Xms", "-Ximage-compiler-option");
792 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xmx", dex2oatXmxImageFlagsBuf,
793 "-Xmx", "-Ximage-compiler-option");
794 if (skip_compilation) {
Brian Carlstromce5bbbe2014-07-30 15:13:17 -0700795 addOption("-Ximage-compiler-option");
Nicolas Geoffraybe7b0d12017-04-25 12:29:07 +0100796 addOption("--compiler-filter=assume-verified");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800797 } else {
798 parseCompilerOption("dalvik.vm.image-dex2oat-filter", dex2oatImageCompilerFilterBuf,
799 "--compiler-filter=", "-Ximage-compiler-option");
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800800 }
801
Mathieu Chartier5f50c872017-06-30 11:47:38 -0700802 // If there is a boot profile, it takes precedence over the image and preloaded classes.
803 if (hasFile("/system/etc/boot-image.prof")) {
Andreas Gampe08b2d582014-12-18 14:39:22 -0800804 addOption("-Ximage-compiler-option");
Mathieu Chartier5f50c872017-06-30 11:47:38 -0700805 addOption("--profile-file=/system/etc/boot-image.prof");
806 addOption("-Ximage-compiler-option");
807 addOption("--compiler-filter=speed-profile");
808 } else {
809 // Make sure there is a preloaded-classes file.
810 if (!hasFile("/system/etc/preloaded-classes")) {
811 ALOGE("Missing preloaded-classes file, /system/etc/preloaded-classes not found: %s\n",
812 strerror(errno));
813 return -1;
814 }
815 addOption("-Ximage-compiler-option");
816 addOption("--image-classes=/system/etc/preloaded-classes");
817
818 // If there is a compiled-classes file, push it.
819 if (hasFile("/system/etc/compiled-classes")) {
820 addOption("-Ximage-compiler-option");
821 addOption("--compiled-classes=/system/etc/compiled-classes");
822 }
Andreas Gampe08b2d582014-12-18 14:39:22 -0800823 }
824
825 property_get("dalvik.vm.image-dex2oat-flags", dex2oatImageFlagsBuf, "");
826 parseExtraOpts(dex2oatImageFlagsBuf, "-Ximage-compiler-option");
827
828 // Extra options for DexClassLoader.
829 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xms", dex2oatXmsFlagsBuf,
830 "-Xms", "-Xcompiler-option");
831 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xmx", dex2oatXmxFlagsBuf,
832 "-Xmx", "-Xcompiler-option");
833 if (skip_compilation) {
834 addOption("-Xcompiler-option");
Nicolas Geoffraybe7b0d12017-04-25 12:29:07 +0100835 addOption("--compiler-filter=assume-verified");
neo.chae155118f2015-01-07 15:32:15 +0900836
837 // We skip compilation when a minimal runtime is brought up for decryption. In that case
838 // /data is temporarily backed by a tmpfs, which is usually small.
839 // If the system image contains prebuilts, they will be relocated into the tmpfs. In this
840 // specific situation it is acceptable to *not* relocate and run out of the prebuilts
841 // directly instead.
842 addOption("--runtime-arg");
843 addOption("-Xnorelocate");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800844 } else {
845 parseCompilerOption("dalvik.vm.dex2oat-filter", dex2oatCompilerFilterBuf,
846 "--compiler-filter=", "-Xcompiler-option");
847 }
Andreas Gampee0352382015-03-30 18:43:39 -0700848 parseCompilerOption("dalvik.vm.dex2oat-threads", dex2oatThreadsBuf, "-j", "-Xcompiler-option");
849 parseCompilerOption("dalvik.vm.image-dex2oat-threads", dex2oatThreadsImageBuf, "-j",
850 "-Ximage-compiler-option");
Andreas Gampe605cca12015-04-02 23:12:56 -0700851
852 // The runtime will compile a boot image, when necessary, not using installd. Thus, we need to
853 // pass the instruction-set-features/variant as an image-compiler-option.
854 // TODO: Find a better way for the instruction-set.
855#if defined(__arm__)
856 constexpr const char* instruction_set = "arm";
857#elif defined(__aarch64__)
858 constexpr const char* instruction_set = "arm64";
859#elif defined(__mips__) && !defined(__LP64__)
860 constexpr const char* instruction_set = "mips";
861#elif defined(__mips__) && defined(__LP64__)
862 constexpr const char* instruction_set = "mips64";
863#elif defined(__i386__)
864 constexpr const char* instruction_set = "x86";
865#elif defined(__x86_64__)
866 constexpr const char* instruction_set = "x86_64";
867#else
868 constexpr const char* instruction_set = "unknown";
869#endif
870 // Note: it is OK to reuse the buffer, as the values are exactly the same between
871 // * compiler-option, used for runtime compilation (DexClassLoader)
872 // * image-compiler-option, used for boot-image compilation on device
873
874 // Copy the variant.
875 sprintf(dex2oat_isa_variant_key, "dalvik.vm.isa.%s.variant", instruction_set);
876 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
877 "--instruction-set-variant=", "-Ximage-compiler-option");
878 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
879 "--instruction-set-variant=", "-Xcompiler-option");
880 // Copy the features.
881 sprintf(dex2oat_isa_features_key, "dalvik.vm.isa.%s.features", instruction_set);
882 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
883 "--instruction-set-features=", "-Ximage-compiler-option");
884 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
885 "--instruction-set-features=", "-Xcompiler-option");
886
887
Andreas Gampe08b2d582014-12-18 14:39:22 -0800888 property_get("dalvik.vm.dex2oat-flags", dex2oatFlagsBuf, "");
889 parseExtraOpts(dex2oatFlagsBuf, "-Xcompiler-option");
890
Andy McFaddene4d81f22010-07-14 16:02:20 -0700891 /* extra options; parse this late so it overrides others */
892 property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800893 parseExtraOpts(extraOptsBuf, NULL);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 /* Set the properties for locale */
896 {
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000897 strcpy(localeOption, "-Duser.locale=");
Narayan Kamathbf882052015-08-11 15:40:34 +0100898 const std::string locale = readLocale();
899 strncat(localeOption, locale.c_str(), PROPERTY_VALUE_MAX);
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000900 addOption(localeOption);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 }
902
Calin Juravle92290b82015-11-10 19:30:45 +0000903 // Trace files are stored in /data/misc/trace which is writable only in debug mode.
904 property_get("ro.debuggable", propBuf, "0");
905 if (strcmp(propBuf, "1") == 0) {
906 property_get("dalvik.vm.method-trace", propBuf, "false");
Andreas Gampe98f406f2015-06-22 21:09:36 -0700907 if (strcmp(propBuf, "true") == 0) {
Calin Juravle92290b82015-11-10 19:30:45 +0000908 addOption("-Xmethod-trace");
909 parseRuntimeOption("dalvik.vm.method-trace-file",
910 methodTraceFileBuf,
911 "-Xmethod-trace-file:");
912 parseRuntimeOption("dalvik.vm.method-trace-file-siz",
913 methodTraceFileSizeBuf,
914 "-Xmethod-trace-file-size:");
915 property_get("dalvik.vm.method-trace-stream", propBuf, "false");
916 if (strcmp(propBuf, "true") == 0) {
917 addOption("-Xmethod-trace-stream");
918 }
Andreas Gampe98f406f2015-06-22 21:09:36 -0700919 }
920 }
921
Andreas Gampe08b2d582014-12-18 14:39:22 -0800922 // Native bridge library. "0" means that native bridge is disabled.
923 property_get("ro.dalvik.vm.native.bridge", propBuf, "");
924 if (propBuf[0] == '\0') {
925 ALOGW("ro.dalvik.vm.native.bridge is not expected to be empty");
926 } else if (strcmp(propBuf, "0") != 0) {
927 snprintf(nativeBridgeLibrary, sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX,
928 "-XX:NativeBridge=%s", propBuf);
929 addOption(nativeBridgeLibrary);
Calin Juravlebe20ed42014-08-26 23:00:11 +0100930 }
Calin Juravle01db9162014-08-07 14:45:53 +0100931
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700932#if defined(__LP64__)
933 const char* cpu_abilist_property_name = "ro.product.cpu.abilist64";
934#else
935 const char* cpu_abilist_property_name = "ro.product.cpu.abilist32";
936#endif // defined(__LP64__)
937 property_get(cpu_abilist_property_name, propBuf, "");
938 if (propBuf[0] == '\0') {
939 ALOGE("%s is not expected to be empty", cpu_abilist_property_name);
940 return -1;
941 }
942 snprintf(cpuAbiListBuf, sizeof(cpuAbiListBuf), "--cpu-abilist=%s", propBuf);
943 addOption(cpuAbiListBuf);
944
Andreas Gampee324ba02015-03-31 16:15:17 -0700945 // Dalvik-cache pruning counter.
946 parseRuntimeOption("dalvik.vm.zygote.max-boot-retry", cachePruneBuf,
947 "-Xzygote-max-boot-retry=");
948
Andreas Gampe27c39f12015-04-27 18:28:18 +0000949 /*
David Srbecky065075e2015-05-28 17:16:09 +0100950 * When running with debug.generate-debug-info, add --generate-debug-info to
951 * the compiler options so that the boot image, if it is compiled on device,
952 * will include native debugging information.
Andreas Gampe27c39f12015-04-27 18:28:18 +0000953 */
David Srbecky065075e2015-05-28 17:16:09 +0100954 property_get("debug.generate-debug-info", propBuf, "");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000955 if (strcmp(propBuf, "true") == 0) {
956 addOption("-Xcompiler-option");
David Srbecky065075e2015-05-28 17:16:09 +0100957 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000958 addOption("-Ximage-compiler-option");
David Srbecky065075e2015-05-28 17:16:09 +0100959 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000960 }
961
Andreas Gampee6082502015-07-24 14:19:44 -0700962 /*
963 * Retrieve the build fingerprint and provide it to the runtime. That way, ANR dumps will
964 * contain the fingerprint and can be parsed.
965 */
966 parseRuntimeOption("ro.build.fingerprint", fingerprintBuf, "-Xfingerprint:");
967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968 initArgs.version = JNI_VERSION_1_4;
969 initArgs.options = mOptions.editArray();
970 initArgs.nOptions = mOptions.size();
971 initArgs.ignoreUnrecognized = JNI_FALSE;
972
973 /*
974 * Initialize the VM.
975 *
976 * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread.
977 * If this call succeeds, the VM is ready, and we can start issuing
978 * JNI calls.
979 */
Andy McFaddenf70188a2009-03-31 15:52:13 -0700980 if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) {
Steve Block3762c312012-01-06 19:20:56 +0000981 ALOGE("JNI_CreateJavaVM failed\n");
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700982 return -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 }
984
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700985 return 0;
Andy McFaddenf70188a2009-03-31 15:52:13 -0700986}
987
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700988char* AndroidRuntime::toSlashClassName(const char* className)
989{
990 char* result = strdup(className);
991 for (char* cp = result; *cp != '\0'; cp++) {
992 if (*cp == '.') {
993 *cp = '/';
994 }
995 }
996 return result;
997}
998
Mike Lockwood9ee5e7e2014-09-08 16:15:21 -0700999/** Create a Java string from an ASCII or Latin-1 string */
1000jstring AndroidRuntime::NewStringLatin1(JNIEnv* env, const char* bytes) {
1001 if (!bytes) return NULL;
1002 int length = strlen(bytes);
1003 jchar* buffer = (jchar *)alloca(length * sizeof(jchar));
1004 if (!buffer) return NULL;
1005 jchar* chp = buffer;
1006 for (int i = 0; i < length; i++) {
1007 *chp++ = *bytes++;
1008 }
1009 return env->NewString(buffer, length);
1010}
1011
1012
Andy McFaddenf70188a2009-03-31 15:52:13 -07001013/*
1014 * Start the Android runtime. This involves starting the virtual machine
1015 * and calling the "static void main(String[] args)" method in the class
1016 * named by "className".
Jeff Brownebed7d62011-05-16 17:08:42 -07001017 *
1018 * Passes the main function two arguments, the class name and the specified
1019 * options string.
Andy McFaddenf70188a2009-03-31 15:52:13 -07001020 */
Sebastien Hertz7a09b832015-08-10 18:55:34 +02001021void AndroidRuntime::start(const char* className, const Vector<String8>& options, bool zygote)
Andy McFaddenf70188a2009-03-31 15:52:13 -07001022{
Dianne Hackborn8e5aafe2014-10-27 18:04:10 -07001023 ALOGD(">>>>>> START %s uid %d <<<<<<\n",
1024 className != NULL ? className : "(unknown)", getuid());
Andy McFaddenf70188a2009-03-31 15:52:13 -07001025
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001026 static const String8 startSystemServer("start-system-server");
1027
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001028 /*
1029 * 'startSystemServer == true' means runtime is obsolete and not run from
Andy McFaddenf70188a2009-03-31 15:52:13 -07001030 * init.rc anymore, so we print out the boot start event here.
1031 */
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001032 for (size_t i = 0; i < options.size(); ++i) {
1033 if (options[i] == startSystemServer) {
1034 /* track our progress through the boot sequence */
1035 const int LOG_BOOT_PROGRESS_START = 3000;
1036 LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));
1037 }
Andy McFaddenf70188a2009-03-31 15:52:13 -07001038 }
1039
1040 const char* rootDir = getenv("ANDROID_ROOT");
1041 if (rootDir == NULL) {
1042 rootDir = "/system";
1043 if (!hasDir("/system")) {
1044 LOG_FATAL("No root directory specified, and /android does not exist.");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001045 return;
Andy McFaddenf70188a2009-03-31 15:52:13 -07001046 }
1047 setenv("ANDROID_ROOT", rootDir, 1);
1048 }
1049
1050 //const char* kernelHack = getenv("LD_ASSUME_KERNEL");
Steve Block5baa3a62011-12-20 16:23:08 +00001051 //ALOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001052
1053 /* start the virtual machine */
Brian Carlstrom9f8203a2013-06-19 13:49:36 -07001054 JniInvocation jni_invocation;
1055 jni_invocation.Init(NULL);
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001056 JNIEnv* env;
Sebastien Hertz7a09b832015-08-10 18:55:34 +02001057 if (startVm(&mJavaVM, &env, zygote) != 0) {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001058 return;
1059 }
1060 onVmCreated(env);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001062 /*
1063 * Register android functions.
1064 */
1065 if (startReg(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001066 ALOGE("Unable to register all android natives\n");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001067 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 }
1069
1070 /*
1071 * We want to call main() with a String array with arguments in it.
Jeff Brownebed7d62011-05-16 17:08:42 -07001072 * At present we have two arguments, the class name and an option string.
1073 * Create an array to hold them.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001074 */
1075 jclass stringClass;
1076 jobjectArray strArray;
1077 jstring classNameStr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078
1079 stringClass = env->FindClass("java/lang/String");
1080 assert(stringClass != NULL);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001081 strArray = env->NewObjectArray(options.size() + 1, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 assert(strArray != NULL);
1083 classNameStr = env->NewStringUTF(className);
1084 assert(classNameStr != NULL);
1085 env->SetObjectArrayElement(strArray, 0, classNameStr);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001086
1087 for (size_t i = 0; i < options.size(); ++i) {
1088 jstring optionsStr = env->NewStringUTF(options.itemAt(i).string());
1089 assert(optionsStr != NULL);
1090 env->SetObjectArrayElement(strArray, i + 1, optionsStr);
1091 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092
1093 /*
1094 * Start VM. This thread becomes the main thread of the VM, and will
1095 * not return until the VM exits.
1096 */
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001097 char* slashClassName = toSlashClassName(className);
1098 jclass startClass = env->FindClass(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 if (startClass == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001100 ALOGE("JavaVM unable to locate class '%s'\n", slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 /* keep going */
1102 } else {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001103 jmethodID startMeth = env->GetStaticMethodID(startClass, "main",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 "([Ljava/lang/String;)V");
1105 if (startMeth == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001106 ALOGE("JavaVM unable to find main() in '%s'\n", className);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 /* keep going */
1108 } else {
1109 env->CallStaticVoidMethod(startClass, startMeth, strArray);
1110
1111#if 0
1112 if (env->ExceptionCheck())
1113 threadExitUncaughtException(env);
1114#endif
1115 }
1116 }
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001117 free(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118
Steve Block5baa3a62011-12-20 16:23:08 +00001119 ALOGD("Shutting down VM\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 if (mJavaVM->DetachCurrentThread() != JNI_OK)
Steve Block8564c8d2012-01-05 23:22:43 +00001121 ALOGW("Warning: unable to detach main thread\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001122 if (mJavaVM->DestroyJavaVM() != 0)
Steve Block8564c8d2012-01-05 23:22:43 +00001123 ALOGW("Warning: VM did not shut down cleanly\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124}
1125
Jeff Brown4280c4a2012-03-15 17:48:02 -07001126void AndroidRuntime::exit(int code)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001127{
Jeff Brown4280c4a2012-03-15 17:48:02 -07001128 if (mExitWithoutCleanup) {
1129 ALOGI("VM exiting with result code %d, cleanup skipped.", code);
1130 ::_exit(code);
1131 } else {
1132 ALOGI("VM exiting with result code %d.", code);
1133 onExit(code);
1134 ::exit(code);
1135 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136}
1137
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001138void AndroidRuntime::onVmCreated(JNIEnv* env)
1139{
1140 // If AndroidRuntime had anything to do here, we'd have done it in 'start'.
1141}
1142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143/*
Andreas Huber9ae000c2014-02-13 17:22:33 +00001144 * Get the JNIEnv pointer for this thread.
1145 *
1146 * Returns NULL if the slot wasn't allocated or populated.
1147 */
1148/*static*/ JNIEnv* AndroidRuntime::getJNIEnv()
1149{
1150 JNIEnv* env;
1151 JavaVM* vm = AndroidRuntime::getJavaVM();
1152 assert(vm != NULL);
1153
1154 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
1155 return NULL;
1156 return env;
1157}
1158
1159/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 * Makes the current thread visible to the VM.
1161 *
1162 * The JNIEnv pointer returned is only valid for the current thread, and
1163 * thus must be tucked into thread-local storage.
1164 */
1165static int javaAttachThread(const char* threadName, JNIEnv** pEnv)
1166{
1167 JavaVMAttachArgs args;
1168 JavaVM* vm;
1169 jint result;
1170
1171 vm = AndroidRuntime::getJavaVM();
1172 assert(vm != NULL);
1173
1174 args.version = JNI_VERSION_1_4;
1175 args.name = (char*) threadName;
1176 args.group = NULL;
1177
1178 result = vm->AttachCurrentThread(pEnv, (void*) &args);
1179 if (result != JNI_OK)
Steve Block6215d3f2012-01-04 20:05:49 +00001180 ALOGI("NOTE: attach of thread '%s' failed\n", threadName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001181
1182 return result;
1183}
1184
1185/*
1186 * Detach the current thread from the set visible to the VM.
1187 */
1188static int javaDetachThread(void)
1189{
1190 JavaVM* vm;
1191 jint result;
1192
1193 vm = AndroidRuntime::getJavaVM();
1194 assert(vm != NULL);
1195
1196 result = vm->DetachCurrentThread();
1197 if (result != JNI_OK)
Steve Block3762c312012-01-06 19:20:56 +00001198 ALOGE("ERROR: thread detach failed\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199 return result;
1200}
1201
1202/*
1203 * When starting a native thread that will be visible from the VM, we
1204 * bounce through this to get the right attach/detach action.
1205 * Note that this function calls free(args)
1206 */
1207/*static*/ int AndroidRuntime::javaThreadShell(void* args) {
1208 void* start = ((void**)args)[0];
1209 void* userData = ((void **)args)[1];
1210 char* name = (char*) ((void **)args)[2]; // we own this storage
1211 free(args);
1212 JNIEnv* env;
1213 int result;
1214
1215 /* hook us into the VM */
1216 if (javaAttachThread(name, &env) != JNI_OK)
1217 return -1;
1218
1219 /* start the thread running */
1220 result = (*(android_thread_func_t)start)(userData);
1221
1222 /* unhook us */
1223 javaDetachThread();
1224 free(name);
1225
1226 return result;
1227}
1228
1229/*
1230 * This is invoked from androidCreateThreadEtc() via the callback
1231 * set with androidSetCreateThreadFunc().
1232 *
1233 * We need to create the new thread in such a way that it gets hooked
1234 * into the VM before it really starts executing.
1235 */
1236/*static*/ int AndroidRuntime::javaCreateThreadEtc(
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001237 android_thread_func_t entryFunction,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001238 void* userData,
1239 const char* threadName,
1240 int32_t threadPriority,
1241 size_t threadStackSize,
1242 android_thread_id_t* threadId)
1243{
1244 void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free
1245 int result;
1246
Brian Carlstrom66f48312016-03-12 16:07:48 -08001247 LOG_ALWAYS_FATAL_IF(threadName == nullptr, "threadName not provided to javaCreateThreadEtc");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248
1249 args[0] = (void*) entryFunction;
1250 args[1] = userData;
1251 args[2] = (void*) strdup(threadName); // javaThreadShell must free
1252
1253 result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args,
1254 threadName, threadPriority, threadStackSize, threadId);
1255 return result;
1256}
1257
1258/*
1259 * Create a thread that is visible from the VM.
1260 *
1261 * This is called from elsewhere in the library.
1262 */
Mike Lockwoodf602d362010-06-20 14:28:16 -07001263/*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001264 void (*start)(void *), void* arg)
1265{
Mike Lockwoodf602d362010-06-20 14:28:16 -07001266 android_thread_id_t threadId = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001267 javaCreateThreadEtc((android_thread_func_t) start, arg, name,
Mike Lockwoodf602d362010-06-20 14:28:16 -07001268 ANDROID_PRIORITY_DEFAULT, 0, &threadId);
1269 return threadId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001270}
1271
1272#if 0
1273static void quickTest(void* arg)
1274{
1275 const char* str = (const char*) arg;
1276
1277 printf("In quickTest: %s\n", str);
1278}
1279#endif
1280
1281#ifdef NDEBUG
1282 #define REG_JNI(name) { name }
1283 struct RegJNIRec {
1284 int (*mProc)(JNIEnv*);
1285 };
1286#else
1287 #define REG_JNI(name) { name, #name }
1288 struct RegJNIRec {
1289 int (*mProc)(JNIEnv*);
1290 const char* mName;
1291 };
1292#endif
1293
1294typedef void (*RegJAMProc)();
1295
1296static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env)
1297{
1298 for (size_t i = 0; i < count; i++) {
1299 if (array[i].mProc(env) < 0) {
1300#ifndef NDEBUG
Steve Block5baa3a62011-12-20 16:23:08 +00001301 ALOGD("----------!!! %s failed to load\n", array[i].mName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001302#endif
1303 return -1;
1304 }
1305 }
1306 return 0;
1307}
1308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001309static const RegJNIRec gRegJNI[] = {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001310 REG_JNI(register_com_android_internal_os_RuntimeInit),
Andreas Gampe4e66db82017-02-07 19:44:37 -08001311 REG_JNI(register_com_android_internal_os_ZygoteInit),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001312 REG_JNI(register_android_os_SystemClock),
1313 REG_JNI(register_android_util_EventLog),
1314 REG_JNI(register_android_util_Log),
Svet Ganov53a441c2016-04-19 19:38:00 -07001315 REG_JNI(register_android_util_MemoryIntArray),
Doris Liucdd23f92015-11-11 14:31:13 -08001316 REG_JNI(register_android_util_PathParser),
Michal Karpinski6235a942016-03-15 12:07:23 +00001317 REG_JNI(register_android_app_admin_SecurityLog),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001318 REG_JNI(register_android_content_AssetManager),
1319 REG_JNI(register_android_content_StringBlock),
1320 REG_JNI(register_android_content_XmlBlock),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001321 REG_JNI(register_android_text_AndroidCharacter),
Anish Athalye88b5b0b2014-06-24 14:39:43 -07001322 REG_JNI(register_android_text_StaticLayout),
Doug Feltdae8e942010-02-24 14:33:15 -08001323 REG_JNI(register_android_text_AndroidBidi),
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001324 REG_JNI(register_android_view_InputDevice),
1325 REG_JNI(register_android_view_KeyCharacterMap),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001326 REG_JNI(register_android_os_Process),
Andreas Hubera8079bf2010-11-16 14:40:31 -08001327 REG_JNI(register_android_os_SystemProperties),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001328 REG_JNI(register_android_os_Binder),
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -08001329 REG_JNI(register_android_os_Parcel),
Andreas Huber7f5fcab2016-08-15 09:25:02 -07001330 REG_JNI(register_android_os_HwBinder),
Andreas Huber50546a92016-08-25 11:21:21 -07001331 REG_JNI(register_android_os_HwBlob),
Andreas Huber7f5fcab2016-08-15 09:25:02 -07001332 REG_JNI(register_android_os_HwParcel),
1333 REG_JNI(register_android_os_HwRemoteBinder),
Yifan Hong4e01db82017-04-05 14:42:05 -07001334 REG_JNI(register_android_os_VintfObject),
Yifan Hong1bda6732017-04-26 11:38:01 -07001335 REG_JNI(register_android_os_VintfRuntimeInfo),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001336 REG_JNI(register_android_nio_utils),
Richard Uhler775873a2015-12-29 12:37:39 -08001337 REG_JNI(register_android_graphics_Canvas),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001338 REG_JNI(register_android_graphics_Graphics),
Chris Craik54389792013-12-20 13:28:11 -08001339 REG_JNI(register_android_view_DisplayEventReceiver),
John Reckf666ad72014-03-14 16:24:57 -07001340 REG_JNI(register_android_view_RenderNode),
John Recke45b1fd2014-04-15 09:50:16 -07001341 REG_JNI(register_android_view_RenderNodeAnimator),
Romain Guy3b748a42013-04-17 18:54:38 -07001342 REG_JNI(register_android_view_GraphicBuffer),
Chris Craikc9070eb2015-03-09 18:50:14 -07001343 REG_JNI(register_android_view_DisplayListCanvas),
John Reck04fc5832014-02-05 16:38:25 -08001344 REG_JNI(register_android_view_HardwareLayer),
John Reckcec24ae2013-11-05 13:27:50 -08001345 REG_JNI(register_android_view_ThreadedRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001346 REG_JNI(register_android_view_Surface),
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001347 REG_JNI(register_android_view_SurfaceControl),
Jeff Brown64a55af2012-08-26 02:47:39 -07001348 REG_JNI(register_android_view_SurfaceSession),
Romain Guy8f0095c2011-05-02 17:24:22 -07001349 REG_JNI(register_android_view_TextureView),
John Reck315c3292014-05-09 19:21:04 -07001350 REG_JNI(register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351 REG_JNI(register_com_google_android_gles_jni_EGLImpl),
1352 REG_JNI(register_com_google_android_gles_jni_GLImpl),
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001353 REG_JNI(register_android_opengl_jni_EGL14),
Jesse Hall237c2b82013-05-06 11:36:57 -07001354 REG_JNI(register_android_opengl_jni_EGLExt),
Jack Palevich1c4907e2009-04-13 16:22:25 -07001355 REG_JNI(register_android_opengl_jni_GLES10),
1356 REG_JNI(register_android_opengl_jni_GLES10Ext),
1357 REG_JNI(register_android_opengl_jni_GLES11),
1358 REG_JNI(register_android_opengl_jni_GLES11Ext),
Jack Palevich560814f2009-11-19 16:34:55 +08001359 REG_JNI(register_android_opengl_jni_GLES20),
Jesse Halld877efe2013-04-29 15:59:35 -07001360 REG_JNI(register_android_opengl_jni_GLES30),
Jesse Hall7ab63ac2014-05-19 15:13:41 -07001361 REG_JNI(register_android_opengl_jni_GLES31),
1362 REG_JNI(register_android_opengl_jni_GLES31Ext),
Pablo Ceballos38c1a7e2015-10-30 10:34:30 -07001363 REG_JNI(register_android_opengl_jni_GLES32),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001364
1365 REG_JNI(register_android_graphics_Bitmap),
1366 REG_JNI(register_android_graphics_BitmapFactory),
Wei-Ta Chen6b849e22010-09-07 17:32:18 +08001367 REG_JNI(register_android_graphics_BitmapRegionDecoder),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001368 REG_JNI(register_android_graphics_Camera),
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -04001369 REG_JNI(register_android_graphics_CreateJavaOutputStreamAdaptor),
John Reck52244ff2014-05-01 21:27:37 -07001370 REG_JNI(register_android_graphics_CanvasProperty),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001371 REG_JNI(register_android_graphics_ColorFilter),
1372 REG_JNI(register_android_graphics_DrawFilter),
Raph Levien1a73f7322014-01-30 16:06:28 -08001373 REG_JNI(register_android_graphics_FontFamily),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001374 REG_JNI(register_android_graphics_Interpolator),
1375 REG_JNI(register_android_graphics_LayerRasterizer),
1376 REG_JNI(register_android_graphics_MaskFilter),
1377 REG_JNI(register_android_graphics_Matrix),
1378 REG_JNI(register_android_graphics_Movie),
1379 REG_JNI(register_android_graphics_NinePatch),
1380 REG_JNI(register_android_graphics_Paint),
1381 REG_JNI(register_android_graphics_Path),
1382 REG_JNI(register_android_graphics_PathMeasure),
1383 REG_JNI(register_android_graphics_PathEffect),
1384 REG_JNI(register_android_graphics_Picture),
1385 REG_JNI(register_android_graphics_PorterDuff),
1386 REG_JNI(register_android_graphics_Rasterizer),
1387 REG_JNI(register_android_graphics_Region),
1388 REG_JNI(register_android_graphics_Shader),
Jamie Gennisaa0ce332011-01-06 17:04:26 -08001389 REG_JNI(register_android_graphics_SurfaceTexture),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001390 REG_JNI(register_android_graphics_Typeface),
1391 REG_JNI(register_android_graphics_Xfermode),
Wei-Ta Chenbca2d612009-11-30 17:52:05 +08001392 REG_JNI(register_android_graphics_YuvImage),
Doris Liu766431a2016-02-04 22:17:11 +00001393 REG_JNI(register_android_graphics_drawable_AnimatedVectorDrawable),
Doris Liu4bbc2932015-12-01 17:59:40 -08001394 REG_JNI(register_android_graphics_drawable_VectorDrawable),
Svetoslav6811f4e2013-09-18 15:58:28 -07001395 REG_JNI(register_android_graphics_pdf_PdfDocument),
Svetoslav62ce3322014-09-04 21:17:17 -07001396 REG_JNI(register_android_graphics_pdf_PdfEditor),
Svetoslav29617692014-04-24 18:40:42 -07001397 REG_JNI(register_android_graphics_pdf_PdfRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001398
1399 REG_JNI(register_android_database_CursorWindow),
Jeff Browne5360fb2011-10-31 17:48:13 -07001400 REG_JNI(register_android_database_SQLiteConnection),
1401 REG_JNI(register_android_database_SQLiteGlobal),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001402 REG_JNI(register_android_database_SQLiteDebug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001403 REG_JNI(register_android_os_Debug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001404 REG_JNI(register_android_os_FileObserver),
Jesse Hall17ee3aa2016-12-12 12:53:02 -08001405 REG_JNI(register_android_os_GraphicsEnvironment),
Christopher Tatefa9e7c02010-05-06 12:07:10 -07001406 REG_JNI(register_android_os_MessageQueue),
Stephen Smalleyc07fca32012-01-13 08:31:39 -05001407 REG_JNI(register_android_os_SELinux),
Paul Lawrenceef854772017-01-31 09:54:31 -08001408 REG_JNI(register_android_os_seccomp),
Jeff Brown481c1572012-03-09 14:41:15 -08001409 REG_JNI(register_android_os_Trace),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001410 REG_JNI(register_android_os_UEventObserver),
1411 REG_JNI(register_android_net_LocalSocketImpl),
1412 REG_JNI(register_android_net_NetworkUtils),
Dan Egnor2b4abcd2010-04-07 17:30:50 -07001413 REG_JNI(register_android_net_TrafficStats),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001414 REG_JNI(register_android_os_MemoryFile),
Dimitry Ivanovb1ef62b2016-04-20 14:09:32 -07001415 REG_JNI(register_com_android_internal_os_PathClassLoaderFactory),
Narayan Kamath973b4662014-03-31 13:41:26 +01001416 REG_JNI(register_com_android_internal_os_Zygote),
John Reck9fa40712014-05-09 15:26:59 -07001417 REG_JNI(register_com_android_internal_util_VirtualRefBasePtr),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001418 REG_JNI(register_android_hardware_Camera),
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07001419 REG_JNI(register_android_hardware_camera2_CameraMetadata),
Ruben Brunkfeb50af2014-05-09 19:58:49 -07001420 REG_JNI(register_android_hardware_camera2_legacy_LegacyCameraDevice),
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -07001421 REG_JNI(register_android_hardware_camera2_legacy_PerfMeasurement),
Ruben Brunkb6079002014-05-22 12:33:54 -07001422 REG_JNI(register_android_hardware_camera2_DngCreator),
Eric Laurent633cb562015-03-05 15:17:20 -08001423 REG_JNI(register_android_hardware_Radio),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001424 REG_JNI(register_android_hardware_SensorManager),
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04001425 REG_JNI(register_android_hardware_SerialPort),
Eric Laurent60b62bc2014-04-18 17:50:49 -07001426 REG_JNI(register_android_hardware_SoundTrigger),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001427 REG_JNI(register_android_hardware_UsbDevice),
Mike Lockwoodacc29cc2011-03-11 08:18:08 -05001428 REG_JNI(register_android_hardware_UsbDeviceConnection),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001429 REG_JNI(register_android_hardware_UsbRequest),
destradaaa4fa3b52014-07-09 10:46:39 -07001430 REG_JNI(register_android_hardware_location_ActivityRecognitionHardware),
Peng Xu9ff7d222016-02-11 13:02:05 -08001431 REG_JNI(register_android_hardware_location_ContextHubService),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 REG_JNI(register_android_media_AudioRecord),
1433 REG_JNI(register_android_media_AudioSystem),
1434 REG_JNI(register_android_media_AudioTrack),
1435 REG_JNI(register_android_media_JetPlayer),
Jeff Browncbad9762012-09-04 21:57:59 -07001436 REG_JNI(register_android_media_RemoteDisplay),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437 REG_JNI(register_android_media_ToneGenerator),
1438
1439 REG_JNI(register_android_opengl_classes),
JP Abgrall98a4f7e2011-09-02 15:36:33 -07001440 REG_JNI(register_android_server_NetworkManagementSocketTagger),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001441 REG_JNI(register_android_ddm_DdmHandleNativeHeap),
Joe Onorato1cf58742009-06-12 11:06:24 -07001442 REG_JNI(register_android_backup_BackupDataInput),
Joe Onoratod2110db2009-05-19 13:41:21 -07001443 REG_JNI(register_android_backup_BackupDataOutput),
Joe Onorato06290a42009-06-18 20:10:37 -07001444 REG_JNI(register_android_backup_FileBackupHelperBase),
Joe Onorato4ababd92009-06-25 18:29:18 -04001445 REG_JNI(register_android_backup_BackupHelperDispatcher),
Christopher Tate4a627c72011-04-01 14:43:32 -07001446 REG_JNI(register_android_app_backup_FullBackup),
Dimitry Ivanov4449ef52016-02-25 17:41:13 -08001447 REG_JNI(register_android_app_Activity),
Chet Haase9c1e23b2011-03-24 10:51:31 -07001448 REG_JNI(register_android_app_ActivityThread),
Dimitry Ivanov09979082016-04-19 11:11:01 -07001449 REG_JNI(register_android_app_ApplicationLoaders),
Dianne Hackborn69969e42010-05-04 11:40:40 -07001450 REG_JNI(register_android_app_NativeActivity),
Przemyslaw Szczepaniak8a7c1602015-11-03 09:47:56 +00001451 REG_JNI(register_android_util_jar_StrictJarFile),
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001452 REG_JNI(register_android_view_InputChannel),
Jeff Brown32cbc38552011-12-01 14:01:49 -08001453 REG_JNI(register_android_view_InputEventReceiver),
Jeff Brownc28867a2013-03-26 15:42:39 -07001454 REG_JNI(register_android_view_InputEventSender),
Michael Wrighta44dd262013-04-10 21:12:00 -07001455 REG_JNI(register_android_view_InputQueue),
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001456 REG_JNI(register_android_view_KeyEvent),
1457 REG_JNI(register_android_view_MotionEvent),
Jeff Brown2352b972011-04-12 22:39:53 -07001458 REG_JNI(register_android_view_PointerIcon),
Jeff Brown2ed24622011-03-14 19:39:54 -07001459 REG_JNI(register_android_view_VelocityTracker),
Kenny Root02c87302010-07-01 08:10:18 -07001460
1461 REG_JNI(register_android_content_res_ObbScanner),
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -07001462 REG_JNI(register_android_content_res_Configuration),
Chet Haase6e0ecb42010-11-03 19:41:18 -07001463
1464 REG_JNI(register_android_animation_PropertyValuesHolder),
Kenny Root66269ea2011-07-12 14:14:01 -07001465 REG_JNI(register_com_android_internal_content_NativeLibraryHelper),
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -08001466 REG_JNI(register_com_android_internal_net_NetworkStatsFactory),
Przemyslaw Szczepaniak8a7c1602015-11-03 09:47:56 +00001467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001468};
1469
1470/*
1471 * Register android native functions with the VM.
1472 */
1473/*static*/ int AndroidRuntime::startReg(JNIEnv* env)
1474{
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001475 ATRACE_NAME("RegisterAndroidNatives");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001476 /*
1477 * This hook causes all future threads created in this process to be
1478 * attached to the JavaVM. (This needs to go away in favor of JNI
1479 * Attach calls.)
1480 */
1481 androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc);
1482
Steve Block71f2cf12011-10-20 11:56:00 +01001483 ALOGV("--- registering native functions ---\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001484
1485 /*
1486 * Every "register" function calls one or more things that return
1487 * a local reference (e.g. FindClass). Because we haven't really
1488 * started the VM yet, they're all getting stored in the base frame
1489 * and never released. Use Push/Pop to manage the storage.
1490 */
1491 env->PushLocalFrame(200);
1492
1493 if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) {
1494 env->PopLocalFrame(NULL);
1495 return -1;
1496 }
1497 env->PopLocalFrame(NULL);
1498
1499 //createJavaThread("fubar", quickTest, (void*) "hello");
1500
1501 return 0;
1502}
1503
1504AndroidRuntime* AndroidRuntime::getRuntime()
1505{
1506 return gCurRuntime;
1507}
1508
1509/**
Narayan Kamathc21dab92015-06-25 14:22:00 +01001510 * Used by surface flinger's DdmConnection to register native methods from
1511 * the framework.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001512 */
Narayan Kamathc21dab92015-06-25 14:22:00 +01001513extern "C" jint registerFrameworkNatives(JNIEnv* env) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1515}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516} // namespace android