blob: c522bc46184d8b6c75038056b364f73ed805dbbd [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"
Joe Onorato82ba91d2017-04-27 16:18:05 -070019#define LOG_NDEBUG 1
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020
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>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033
34#include "jni.h"
Steven Moreland2279b252017-07-19 09:50:45 -070035#include <nativehelper/JNIHelp.h>
36#include <nativehelper/JniInvocation.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037#include "android_util_Binder.h"
38
39#include <stdio.h>
40#include <signal.h>
41#include <sys/stat.h>
42#include <sys/types.h>
43#include <signal.h>
44#include <dirent.h>
45#include <assert.h>
46
Narayan Kamathbf882052015-08-11 15:40:34 +010047#include <string>
48#include <vector>
49
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050
51using namespace android;
52
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053extern int register_android_os_Binder(JNIEnv* env);
54extern int register_android_os_Process(JNIEnv* env);
55extern int register_android_graphics_Bitmap(JNIEnv*);
56extern int register_android_graphics_BitmapFactory(JNIEnv*);
Wei-Ta Chen6b849e22010-09-07 17:32:18 +080057extern int register_android_graphics_BitmapRegionDecoder(JNIEnv*);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058extern int register_android_graphics_Camera(JNIEnv* env);
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -040059extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env);
sergeyv0a0f2312017-01-04 13:58:52 -080060extern int register_android_graphics_GraphicBuffer(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);
Craig Donner1a4d07d2017-01-09 13:01:22 -080090extern int register_android_hardware_HardwareBuffer(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 */
Michal Karpinski6235a942016-03-15 12:07:23 +0000111extern int register_android_app_admin_SecurityLog(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112extern int register_android_content_AssetManager(JNIEnv* env);
113extern int register_android_util_EventLog(JNIEnv* env);
114extern int register_android_util_Log(JNIEnv* env);
Svet Ganov53a441c2016-04-19 19:38:00 -0700115extern int register_android_util_MemoryIntArray(JNIEnv* env);
Doris Liucdd23f92015-11-11 14:31:13 -0800116extern int register_android_util_PathParser(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117extern int register_android_content_StringBlock(JNIEnv* env);
118extern int register_android_content_XmlBlock(JNIEnv* env);
119extern int register_android_graphics_Canvas(JNIEnv* env);
John Reck52244ff2014-05-01 21:27:37 -0700120extern int register_android_graphics_CanvasProperty(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121extern int register_android_graphics_ColorFilter(JNIEnv* env);
122extern int register_android_graphics_DrawFilter(JNIEnv* env);
Raph Levien1a73f7322014-01-30 16:06:28 -0800123extern int register_android_graphics_FontFamily(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124extern int register_android_graphics_Matrix(JNIEnv* env);
125extern int register_android_graphics_Paint(JNIEnv* env);
126extern int register_android_graphics_Path(JNIEnv* env);
127extern int register_android_graphics_PathMeasure(JNIEnv* env);
128extern int register_android_graphics_Picture(JNIEnv*);
Jeff Brownfbf09772011-01-16 14:06:57 -0800129extern int register_android_graphics_Region(JNIEnv* env);
Jamie Gennisaa0ce332011-01-06 17:04:26 -0800130extern int register_android_graphics_SurfaceTexture(JNIEnv* env);
Doris Liu766431a2016-02-04 22:17:11 +0000131extern int register_android_graphics_drawable_AnimatedVectorDrawable(JNIEnv* env);
Doris Liu4bbc2932015-12-01 17:59:40 -0800132extern int register_android_graphics_drawable_VectorDrawable(JNIEnv* env);
Svetoslav6811f4e2013-09-18 15:58:28 -0700133extern int register_android_graphics_pdf_PdfDocument(JNIEnv* env);
Svetoslav62ce3322014-09-04 21:17:17 -0700134extern int register_android_graphics_pdf_PdfEditor(JNIEnv* env);
Svetoslav29617692014-04-24 18:40:42 -0700135extern int register_android_graphics_pdf_PdfRenderer(JNIEnv* env);
Jeff Brown0a0a1242011-12-02 02:25:22 -0800136extern int register_android_view_DisplayEventReceiver(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700137extern int register_android_view_DisplayListCanvas(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700138extern int register_android_view_HardwareLayer(JNIEnv* env);
John Reckf666ad72014-03-14 16:24:57 -0700139extern int register_android_view_RenderNode(JNIEnv* env);
John Recke45b1fd2014-04-15 09:50:16 -0700140extern int register_android_view_RenderNodeAnimator(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141extern int register_android_view_Surface(JNIEnv* env);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800142extern int register_android_view_SurfaceControl(JNIEnv* env);
Jeff Brown64a55af2012-08-26 02:47:39 -0700143extern int register_android_view_SurfaceSession(JNIEnv* env);
Romain Guy8f0095c2011-05-02 17:24:22 -0700144extern int register_android_view_TextureView(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700145extern int register_android_view_ThreadedRenderer(JNIEnv* env);
John Reck315c3292014-05-09 19:21:04 -0700146extern int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147extern int register_android_database_CursorWindow(JNIEnv* env);
Jeff Browne5360fb2011-10-31 17:48:13 -0700148extern int register_android_database_SQLiteConnection(JNIEnv* env);
149extern int register_android_database_SQLiteGlobal(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150extern int register_android_database_SQLiteDebug(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151extern int register_android_nio_utils(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152extern int register_android_os_Debug(JNIEnv* env);
Jesse Hallb12249b2016-12-12 12:53:02 -0800153extern int register_android_os_GraphicsEnvironment(JNIEnv* env);
Andreas Huberc0b6c532016-08-15 09:25:02 -0700154extern int register_android_os_HwBinder(JNIEnv *env);
Andreas Huberdc263212016-08-25 11:21:21 -0700155extern int register_android_os_HwBlob(JNIEnv *env);
Andreas Huberc0b6c532016-08-15 09:25:02 -0700156extern int register_android_os_HwParcel(JNIEnv *env);
157extern int register_android_os_HwRemoteBinder(JNIEnv *env);
Christopher Tatefa9e7c02010-05-06 12:07:10 -0700158extern int register_android_os_MessageQueue(JNIEnv* env);
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -0800159extern int register_android_os_Parcel(JNIEnv* env);
Stephen Smalleyc07fca32012-01-13 08:31:39 -0500160extern int register_android_os_SELinux(JNIEnv* env);
Yifan Hongbecc56d2017-04-05 14:42:05 -0700161extern int register_android_os_VintfObject(JNIEnv *env);
Yifan Hong1bda6732017-04-26 11:38:01 -0700162extern int register_android_os_VintfRuntimeInfo(JNIEnv *env);
Paul Lawrenceef854772017-01-31 09:54:31 -0800163extern int register_android_os_seccomp(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164extern int register_android_os_SystemProperties(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165extern int register_android_os_SystemClock(JNIEnv* env);
Jeff Brown481c1572012-03-09 14:41:15 -0800166extern int register_android_os_Trace(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167extern int register_android_os_FileObserver(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168extern int register_android_os_UEventObserver(JNIEnv* env);
169extern int register_android_os_MemoryFile(JNIEnv* env);
John Reckdea6a022017-05-25 17:09:33 -0700170extern int register_android_os_SharedMemory(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171extern int register_android_net_LocalSocketImpl(JNIEnv* env);
172extern int register_android_net_NetworkUtils(JNIEnv* env);
Dan Egnor2b4abcd2010-04-07 17:30:50 -0700173extern int register_android_net_TrafficStats(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174extern int register_android_text_AndroidCharacter(JNIEnv *env);
Anish Athalye88b5b0b2014-06-24 14:39:43 -0700175extern int register_android_text_StaticLayout(JNIEnv *env);
Doug Feltdae8e942010-02-24 14:33:15 -0800176extern int register_android_text_AndroidBidi(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177extern int register_android_opengl_classes(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
Narayan Kamath29564cd2014-08-07 10:57:40 +0100179extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env);
Joe Onorato1cf58742009-06-12 11:06:24 -0700180extern int register_android_backup_BackupDataInput(JNIEnv *env);
Joe Onoratod2110db2009-05-19 13:41:21 -0700181extern int register_android_backup_BackupDataOutput(JNIEnv *env);
Joe Onorato06290a42009-06-18 20:10:37 -0700182extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
Joe Onorato4ababd92009-06-25 18:29:18 -0400183extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
Christopher Tate4a627c72011-04-01 14:43:32 -0700184extern int register_android_app_backup_FullBackup(JNIEnv *env);
Dimitry Ivanov4449ef52016-02-25 17:41:13 -0800185extern int register_android_app_Activity(JNIEnv *env);
Chet Haase9c1e23b2011-03-24 10:51:31 -0700186extern int register_android_app_ActivityThread(JNIEnv *env);
Dimitry Ivanov09979082016-04-19 11:11:01 -0700187extern int register_android_app_ApplicationLoaders(JNIEnv *env);
Dianne Hackborn69969e42010-05-04 11:40:40 -0700188extern int register_android_app_NativeActivity(JNIEnv *env);
Jeff Browncbad9762012-09-04 21:57:59 -0700189extern int register_android_media_RemoteDisplay(JNIEnv *env);
Przemyslaw Szczepaniak8a7c1602015-11-03 09:47:56 +0000190extern int register_android_util_jar_StrictJarFile(JNIEnv* env);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700191extern int register_android_view_InputChannel(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700192extern int register_android_view_InputDevice(JNIEnv* env);
Jeff Brown32cbc38552011-12-01 14:01:49 -0800193extern int register_android_view_InputEventReceiver(JNIEnv* env);
Jeff Brownc28867a2013-03-26 15:42:39 -0700194extern int register_android_view_InputEventSender(JNIEnv* env);
Michael Wrighta44dd262013-04-10 21:12:00 -0700195extern int register_android_view_InputQueue(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700196extern int register_android_view_KeyCharacterMap(JNIEnv *env);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700197extern int register_android_view_KeyEvent(JNIEnv* env);
198extern int register_android_view_MotionEvent(JNIEnv* env);
Jeff Brown2352b972011-04-12 22:39:53 -0700199extern int register_android_view_PointerIcon(JNIEnv* env);
Jeff Brown2ed24622011-03-14 19:39:54 -0700200extern int register_android_view_VelocityTracker(JNIEnv* env);
Kenny Root02c87302010-07-01 08:10:18 -0700201extern int register_android_content_res_ObbScanner(JNIEnv* env);
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700202extern int register_android_content_res_Configuration(JNIEnv* env);
Chet Haase6e0ecb42010-11-03 19:41:18 -0700203extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
Kenny Root66269ea2011-07-12 14:14:01 -0700204extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -0800205extern int register_com_android_internal_net_NetworkStatsFactory(JNIEnv *env);
Narayan Kamathf9419f02017-06-15 11:35:38 +0100206extern int register_com_android_internal_os_ClassLoaderFactory(JNIEnv* env);
Daichi Hirono878e86f2016-10-31 09:33:30 +0900207extern int register_com_android_internal_os_FuseAppLoop(JNIEnv* env);
Narayan Kamath973b4662014-03-31 13:41:26 +0100208extern int register_com_android_internal_os_Zygote(JNIEnv *env);
Jesse Hall1fe1dc02017-07-06 15:30:39 -0700209extern int register_com_android_internal_os_ZygoteInit(JNIEnv *env);
John Reck9fa40712014-05-09 15:26:59 -0700210extern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211
212static AndroidRuntime* gCurRuntime = NULL;
213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214/*
215 * Code written in the Java Programming Language calls here from main().
216 */
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700217static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218{
219 gCurRuntime->onStarted();
220}
221
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800222static void com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223{
224 gCurRuntime->onZygoteInit();
225}
226
Jeff Brown4280c4a2012-03-15 17:48:02 -0700227static void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIEnv* env,
228 jobject clazz, jboolean exitWithoutCleanup)
229{
230 gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup);
231}
232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233/*
234 * JNI registration.
235 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236
237int register_com_android_internal_os_RuntimeInit(JNIEnv* env)
238{
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800239 const JNINativeMethod methods[] = {
240 { "nativeFinishInit", "()V",
241 (void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
242 { "nativeSetExitWithoutCleanup", "(Z)V",
243 (void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
244 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800246 methods, NELEM(methods));
247}
248
Jesse Hall1fe1dc02017-07-06 15:30:39 -0700249int register_com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv* env)
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800250{
251 const JNINativeMethod methods[] = {
252 { "nativeZygoteInit", "()V",
253 (void*) com_android_internal_os_ZygoteInit_nativeZygoteInit },
254 };
255 return jniRegisterNativeMethods(env, "com/android/internal/os/ZygoteInit",
256 methods, NELEM(methods));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257}
258
259// ----------------------------------------------------------------------
260
Andreas Huber9ae000c2014-02-13 17:22:33 +0000261/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
262
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000263AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) :
264 mExitWithoutCleanup(false),
265 mArgBlockStart(argBlockStart),
266 mArgBlockLength(argBlockLength)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700268 SkGraphics::Init();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269
270 // Pre-allocate enough space to hold a fair number of options.
271 mOptions.setCapacity(20);
272
273 assert(gCurRuntime == NULL); // one per process
274 gCurRuntime = this;
275}
276
277AndroidRuntime::~AndroidRuntime()
278{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279}
280
Andreas Huber9ae000c2014-02-13 17:22:33 +0000281/*
282 * Register native methods using JNI.
283 */
284/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
285 const char* className, const JNINativeMethod* gMethods, int numMethods)
286{
287 return jniRegisterNativeMethods(env, className, gMethods, numMethods);
288}
289
Dmitriy Filchenkof5b6e552016-07-18 16:00:35 -0700290void AndroidRuntime::setArgv0(const char* argv0, bool setProcName) {
291 if (setProcName) {
292 int len = strlen(argv0);
293 if (len < 15) {
294 pthread_setname_np(pthread_self(), argv0);
295 } else {
296 pthread_setname_np(pthread_self(), argv0 + len - 15);
297 }
298 }
Jeff Brown00c0cd42014-09-10 16:48:46 -0700299 memset(mArgBlockStart, 0, mArgBlockLength);
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000300 strlcpy(mArgBlockStart, argv0, mArgBlockLength);
301}
302
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100303status_t AndroidRuntime::callMain(const String8& className, jclass clazz,
304 const Vector<String8>& args)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305{
306 JNIEnv* env;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 jmethodID methodId;
308
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100309 ALOGD("Calling main entry %s", className.string());
Dianne Hackborn08e60f22010-09-01 18:17:17 -0700310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 env = getJNIEnv();
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700312 if (clazz == NULL || env == NULL) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313 return UNKNOWN_ERROR;
314 }
315
316 methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
317 if (methodId == NULL) {
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100318 ALOGE("ERROR: could not find method %s.main(String[])\n", className.string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 return UNKNOWN_ERROR;
320 }
321
322 /*
323 * We want to call main() with a String array with our arguments in it.
324 * Create an array and populate it.
325 */
326 jclass stringClass;
327 jobjectArray strArray;
328
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100329 const size_t numArgs = args.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330 stringClass = env->FindClass("java/lang/String");
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100331 strArray = env->NewObjectArray(numArgs, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100333 for (size_t i = 0; i < numArgs; i++) {
334 jstring argStr = env->NewStringUTF(args[i].string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 env->SetObjectArrayElement(strArray, i, argStr);
336 }
337
338 env->CallStaticVoidMethod(clazz, methodId, strArray);
339 return NO_ERROR;
340}
341
342/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 * The VM calls this through the "exit" hook.
344 */
345static void runtime_exit(int code)
346{
Jeff Brown4280c4a2012-03-15 17:48:02 -0700347 gCurRuntime->exit(code);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800348}
349
350/*
351 * The VM calls this through the "vfprintf" hook.
352 *
353 * We ignore "fp" and just write the results to the log file.
354 */
355static void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
356{
357 LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
358}
359
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800360/**
361 * The VM calls this when mutex contention debugging is enabled to
362 * determine whether or not the blocked thread was a "sensitive thread"
363 * for user responsiveness/smoothess.
364 *
365 * Our policy for this is whether or not we're tracing any StrictMode
366 * events on this thread (which we might've inherited via Binder calls
367 * into us)
368 */
369static bool runtime_isSensitiveThread() {
370 IPCThreadState* state = IPCThreadState::selfOrNull();
371 return state && state->getStrictModePolicy() != 0;
372}
373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374static int hasDir(const char* dir)
375{
376 struct stat s;
377 int res = stat(dir, &s);
378 if (res == 0) {
379 return S_ISDIR(s.st_mode);
380 }
381 return 0;
382}
383
Andreas Gampe995c62d2014-11-14 16:15:17 -0800384static bool hasFile(const char* file) {
385 struct stat s;
386 int res = stat(file, &s);
387 if (res == 0) {
388 return S_ISREG(s.st_mode);
389 }
390 return false;
391}
392
Narayan Kamathbf882052015-08-11 15:40:34 +0100393// Convenience wrapper over the property API that returns an
394// std::string.
395std::string getProperty(const char* key, const char* defaultValue) {
396 std::vector<char> temp(PROPERTY_VALUE_MAX);
397 const int len = property_get(key, &temp[0], defaultValue);
398 if (len < 0) {
399 return "";
400 }
401 return std::string(&temp[0], len);
402}
403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404/*
Narayan Kamathbf882052015-08-11 15:40:34 +0100405 * Read the persistent locale. Inspects the following system properties
406 * (in order) and returns the first non-empty property in the list :
407 *
408 * (1) persist.sys.locale
409 * (2) persist.sys.language/country/localevar (country and localevar are
410 * inspected iff. language is non-empty.
411 * (3) ro.product.locale
412 * (4) ro.product.locale.language/region
413 *
414 * Note that we need to inspect persist.sys.language/country/localevar to
415 * preserve language settings for devices that are upgrading from Lollipop
416 * to M. The same goes for ro.product.locale.language/region as well.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 */
Narayan Kamathbf882052015-08-11 15:40:34 +0100418const std::string readLocale()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419{
Narayan Kamathbf882052015-08-11 15:40:34 +0100420 const std::string locale = getProperty("persist.sys.locale", "");
421 if (!locale.empty()) {
422 return locale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 }
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000424
Narayan Kamathbf882052015-08-11 15:40:34 +0100425 const std::string language = getProperty("persist.sys.language", "");
426 if (!language.empty()) {
427 const std::string country = getProperty("persist.sys.country", "");
428 const std::string variant = getProperty("persist.sys.localevar", "");
429
430 std::string out = language;
431 if (!country.empty()) {
432 out = out + "-" + country;
433 }
434
435 if (!variant.empty()) {
436 out = out + "-" + variant;
437 }
438
439 return out;
440 }
441
442 const std::string productLocale = getProperty("ro.product.locale", "");
443 if (!productLocale.empty()) {
444 return productLocale;
445 }
446
447 // If persist.sys.locale and ro.product.locale are missing,
448 // construct a locale value from the individual locale components.
449 const std::string productLanguage = getProperty("ro.product.locale.language", "en");
450 const std::string productRegion = getProperty("ro.product.locale.region", "US");
451
452 return productLanguage + "-" + productRegion;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453}
454
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700455void AndroidRuntime::addOption(const char* optionString, void* extraInfo)
456{
457 JavaVMOption opt;
458 opt.optionString = optionString;
459 opt.extraInfo = extraInfo;
460 mOptions.add(opt);
461}
462
Andy McFaddenf70188a2009-03-31 15:52:13 -0700463/*
Andy McFaddene4d81f22010-07-14 16:02:20 -0700464 * Parse a property containing space-separated options that should be
465 * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
466 *
467 * This will cut up "extraOptsBuf" as we chop it into individual options.
468 *
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800469 * If "quotingArg" is non-null, it is passed before each extra option in mOptions.
470 *
Andy McFaddene4d81f22010-07-14 16:02:20 -0700471 * Adds the strings, if any, to mOptions.
472 */
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800473void AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg)
Andy McFaddene4d81f22010-07-14 16:02:20 -0700474{
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800475 char* start = extraOptsBuf;
476 char* end = NULL;
Andy McFaddene4d81f22010-07-14 16:02:20 -0700477 while (*start != '\0') {
478 while (*start == ' ') /* skip leading whitespace */
479 start++;
480 if (*start == '\0') /* was trailing ws, bail */
481 break;
482
483 end = start+1;
484 while (*end != ' ' && *end != '\0') /* find end of token */
485 end++;
486 if (*end == ' ')
487 *end++ = '\0'; /* mark end, advance to indicate more */
488
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800489 if (quotingArg != NULL) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700490 addOption(quotingArg);
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800491 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700492 addOption(start);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700493 start = end;
494 }
495}
496
497/*
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700498 * Reads a "property" into "buffer" with a default of "defaultArg". If
499 * the property is non-empty, it is treated as a runtime option such
500 * as "-Xmx32m".
501 *
502 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
503 *
504 * If an argument is found, it is added to mOptions.
505 *
506 * If an option is found, it is added to mOptions and true is
507 * returned. Otherwise false is returned.
508 */
509bool AndroidRuntime::parseRuntimeOption(const char* property,
510 char* buffer,
511 const char* runtimeArg,
512 const char* defaultArg)
513{
514 strcpy(buffer, runtimeArg);
515 size_t runtimeArgLen = strlen(runtimeArg);
516 property_get(property, buffer+runtimeArgLen, defaultArg);
517 if (buffer[runtimeArgLen] == '\0') {
518 return false;
519 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700520 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700521 return true;
522}
523
524/*
525 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700526 * is treated as a dex2oat compiler option that should be
Nicolas Geoffraybe7b0d12017-04-25 12:29:07 +0100527 * passed as a quoted option, e.g. "-Ximage-compiler-option --compiler-filter=assume-verified".
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700528 *
529 * The "compilerArg" is a prefix for the option such as "--compiler-filter=".
530 *
531 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
532 *
533 * If an option is found, it is added to mOptions and true is
534 * returned. Otherwise false is returned.
535 */
536bool AndroidRuntime::parseCompilerOption(const char* property,
537 char* buffer,
538 const char* compilerArg,
539 const char* quotingArg)
540{
541 strcpy(buffer, compilerArg);
542 size_t compilerArgLen = strlen(compilerArg);
543 property_get(property, buffer+compilerArgLen, "");
544 if (buffer[compilerArgLen] == '\0') {
545 return false;
546 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700547 addOption(quotingArg);
548 addOption(buffer);
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700549 return true;
550}
551
552/*
553 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700554 * is treated as a dex2oat compiler runtime option that should be
555 * passed as a quoted option, e.g. "-Ximage-compiler-option
556 * --runtime-arg -Ximage-compiler-option -Xmx32m".
557 *
558 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
559 *
560 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
561 *
562 * If an option is found, it is added to mOptions and true is
563 * returned. Otherwise false is returned.
564 */
565bool AndroidRuntime::parseCompilerRuntimeOption(const char* property,
566 char* buffer,
567 const char* runtimeArg,
568 const char* quotingArg)
569{
570 strcpy(buffer, runtimeArg);
571 size_t runtimeArgLen = strlen(runtimeArg);
572 property_get(property, buffer+runtimeArgLen, "");
573 if (buffer[runtimeArgLen] == '\0') {
574 return false;
575 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700576 addOption(quotingArg);
577 addOption("--runtime-arg");
578 addOption(quotingArg);
579 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700580 return true;
581}
582
583/*
Andy McFaddenf70188a2009-03-31 15:52:13 -0700584 * Start the Dalvik Virtual Machine.
585 *
586 * Various arguments, most determined by system properties, are passed in.
587 * The "mOptions" vector is updated.
588 *
Dave Allison07a1e232014-03-14 08:54:33 -0700589 * CAUTION: when adding options in here, be careful not to put the
590 * char buffer inside a nested scope. Adding the buffer to the
591 * options using mOptions.add() does not copy the buffer, so if the
592 * buffer goes out of scope the option may be overwritten. It's best
593 * to put the buffer at the top of the function so that it is more
594 * unlikely that someone will surround it in a scope at a later time
595 * and thus introduce a bug.
596 *
Andy McFaddenf70188a2009-03-31 15:52:13 -0700597 * Returns 0 on success.
598 */
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200599int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 JavaVMInitArgs initArgs;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602 char propBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700603 char stackTraceFileBuf[sizeof("-Xstacktracefile:")-1 + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro38cfa8c2010-12-07 16:48:29 -0800605 char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700606 char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro8cdf27c32011-01-19 12:33:12 -0800607 char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700608 char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
609 char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800610 char usejitOptsBuf[sizeof("-Xusejit:")-1 + PROPERTY_VALUE_MAX];
Nicolas Geoffraycdf1dff2015-11-19 13:48:35 +0000611 char jitmaxsizeOptsBuf[sizeof("-Xjitmaxsize:")-1 + PROPERTY_VALUE_MAX];
612 char jitinitialsizeOptsBuf[sizeof("-Xjitinitialsize:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800613 char jitthresholdOptsBuf[sizeof("-Xjitthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravledb4a79a2015-12-23 18:55:08 +0200614 char useJitProfilesOptsBuf[sizeof("-Xjitsaveprofilinginfo:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle0de80b92016-04-12 14:12:04 +0100615 char jitprithreadweightOptBuf[sizeof("-Xjitprithreadweight:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle8d74de52016-04-27 14:12:00 +0100616 char jittransitionweightOptBuf[sizeof("-Xjittransitionweight:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier5eee0042017-06-07 17:34:22 -0700617 char hotstartupsamplesOptsBuf[sizeof("-Xps-hot-startup-method-samples:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartiercd0caf52017-10-13 11:29:27 -0700618 char madviseRandomOptsBuf[sizeof("-XX:MadviseRandomAccess:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier7e4fdec2013-12-02 15:46:51 -0800619 char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700620 char backgroundgcOptsBuf[sizeof("-XX:BackgroundGC=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700621 char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee324ba02015-03-31 16:15:17 -0700622 char cachePruneBuf[sizeof("-Xzygote-max-boot-retry=")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700623 char dex2oatXmsImageFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
624 char dex2oatXmxImageFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
625 char dex2oatXmsFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
626 char dex2oatXmxFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700627 char dex2oatCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
628 char dex2oatImageCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee0352382015-03-30 18:43:39 -0700629 char dex2oatThreadsBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
630 char dex2oatThreadsImageBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
Andreas Gampe605cca12015-04-02 23:12:56 -0700631 char dex2oat_isa_variant_key[PROPERTY_KEY_MAX];
632 char dex2oat_isa_variant[sizeof("--instruction-set-variant=") -1 + PROPERTY_VALUE_MAX];
633 char dex2oat_isa_features_key[PROPERTY_KEY_MAX];
634 char dex2oat_isa_features[sizeof("--instruction-set-features=") -1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800635 char dex2oatFlagsBuf[PROPERTY_VALUE_MAX];
636 char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX];
Andy McFaddene4d81f22010-07-14 16:02:20 -0700637 char extraOptsBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700638 char voldDecryptBuf[PROPERTY_VALUE_MAX];
Ben Cheng52b0e732009-06-19 13:31:12 -0700639 enum {
640 kEMDefault,
641 kEMIntPortable,
642 kEMIntFast,
Ben Cheng52b0e732009-06-19 13:31:12 -0700643 kEMJitCompiler,
Ben Cheng52b0e732009-06-19 13:31:12 -0700644 } executionMode = kEMDefault;
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000645 char localeOption[sizeof("-Duser.locale=") + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700646 char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle01db9162014-08-07 14:45:53 +0100647 char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX];
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700648 char cpuAbiListBuf[sizeof("--cpu-abilist=") + PROPERTY_VALUE_MAX];
Andreas Gampe98f406f2015-06-22 21:09:36 -0700649 char methodTraceFileBuf[sizeof("-Xmethod-trace-file:") + PROPERTY_VALUE_MAX];
650 char methodTraceFileSizeBuf[sizeof("-Xmethod-trace-file-size:") + PROPERTY_VALUE_MAX];
Andreas Gampee6082502015-07-24 14:19:44 -0700651 char fingerprintBuf[sizeof("-Xfingerprint:") + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700653 bool checkJni = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654 property_get("dalvik.vm.checkjni", propBuf, "");
655 if (strcmp(propBuf, "true") == 0) {
656 checkJni = true;
657 } else if (strcmp(propBuf, "false") != 0) {
658 /* property is neither true nor false; fall back on kernel parameter */
659 property_get("ro.kernel.android.checkjni", propBuf, "");
660 if (propBuf[0] == '1') {
661 checkJni = true;
662 }
663 }
Joe Onorato82ba91d2017-04-27 16:18:05 -0700664 ALOGV("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700665 if (checkJni) {
666 /* extended JNI checking */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700667 addOption("-Xcheck:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700668
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700669 /* with -Xcheck:jni, this provides a JNI function call trace */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700670 //addOption("-verbose:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700671 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672
673 property_get("dalvik.vm.execution-mode", propBuf, "");
674 if (strcmp(propBuf, "int:portable") == 0) {
675 executionMode = kEMIntPortable;
676 } else if (strcmp(propBuf, "int:fast") == 0) {
677 executionMode = kEMIntFast;
Ben Cheng52b0e732009-06-19 13:31:12 -0700678 } else if (strcmp(propBuf, "int:jit") == 0) {
679 executionMode = kEMJitCompiler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800680 }
681
Narayan Kamath93f2e382017-04-25 14:24:07 +0100682 // If dalvik.vm.stack-trace-dir is set, it enables the "new" stack trace
683 // dump scheme and a new file is created for each stack dump. If it isn't set,
684 // the old scheme is enabled.
Narayan Kamath23941e52017-05-10 18:56:12 +0100685 property_get("dalvik.vm.stack-trace-dir", propBuf, "");
686 if (strlen(propBuf) > 0) {
687 addOption("-Xusetombstonedtraces");
688 } else {
Narayan Kamath93f2e382017-04-25 14:24:07 +0100689 parseRuntimeOption("dalvik.vm.stack-trace-file", stackTraceFileBuf, "-Xstacktracefile:");
690 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 strcpy(jniOptsBuf, "-Xjniopts:");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700693 if (parseRuntimeOption("dalvik.vm.jniopts", jniOptsBuf, "-Xjniopts:")) {
694 ALOGI("JNI options: '%s'\n", jniOptsBuf);
695 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800697 /* route exit() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700698 addOption("exit", (void*) runtime_exit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800699
700 /* route fprintf() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700701 addOption("vfprintf", (void*) runtime_vfprintf);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800702
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800703 /* register the framework-specific "is sensitive thread" hook */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700704 addOption("sensitiveThread", (void*) runtime_isSensitiveThread);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800705
706 /* enable verbose; standard options are { jni, gc, class } */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700707 //addOption("-verbose:jni");
708 addOption("-verbose:gc");
709 //addOption("-verbose:class");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710
Carl Shapiro9e4c8842010-12-08 12:14:46 -0800711 /*
712 * The default starting and maximum size of the heap. Larger
713 * values should be specified in a product property override.
714 */
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700715 parseRuntimeOption("dalvik.vm.heapstartsize", heapstartsizeOptsBuf, "-Xms", "4m");
716 parseRuntimeOption("dalvik.vm.heapsize", heapsizeOptsBuf, "-Xmx", "16m");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700718 parseRuntimeOption("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
719 parseRuntimeOption("dalvik.vm.heapminfree", heapminfreeOptsBuf, "-XX:HeapMinFree=");
720 parseRuntimeOption("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf, "-XX:HeapMaxFree=");
721 parseRuntimeOption("dalvik.vm.heaptargetutilization",
722 heaptargetutilizationOptsBuf,
723 "-XX:HeapTargetUtilization=");
Ian Rogers53250102012-09-23 16:38:03 -0700724
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800725 /*
726 * JIT related options.
727 */
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700728 parseRuntimeOption("dalvik.vm.usejit", usejitOptsBuf, "-Xusejit:");
Nicolas Geoffraycdf1dff2015-11-19 13:48:35 +0000729 parseRuntimeOption("dalvik.vm.jitmaxsize", jitmaxsizeOptsBuf, "-Xjitmaxsize:");
730 parseRuntimeOption("dalvik.vm.jitinitialsize", jitinitialsizeOptsBuf, "-Xjitinitialsize:");
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700731 parseRuntimeOption("dalvik.vm.jitthreshold", jitthresholdOptsBuf, "-Xjitthreshold:");
Calin Juravledb4a79a2015-12-23 18:55:08 +0200732 property_get("dalvik.vm.usejitprofiles", useJitProfilesOptsBuf, "");
733 if (strcmp(useJitProfilesOptsBuf, "true") == 0) {
734 addOption("-Xjitsaveprofilinginfo");
735 }
Calin Juravle8d74de52016-04-27 14:12:00 +0100736
Calin Juravle0de80b92016-04-12 14:12:04 +0100737 parseRuntimeOption("dalvik.vm.jitprithreadweight",
738 jitprithreadweightOptBuf,
739 "-Xjitprithreadweight:");
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800740
Calin Juravle8d74de52016-04-27 14:12:00 +0100741 parseRuntimeOption("dalvik.vm.jittransitionweight",
742 jittransitionweightOptBuf,
743 "-Xjittransitionweight:");
744
Mathieu Chartier5eee0042017-06-07 17:34:22 -0700745 /*
Mathieu Chartiercd0caf52017-10-13 11:29:27 -0700746 * Madvise related options.
747 */
748 parseRuntimeOption("dalvik.vm.madvise-random", madviseRandomOptsBuf, "-XX:MadviseRandomAccess:");
749
750 /*
Mathieu Chartier5eee0042017-06-07 17:34:22 -0700751 * 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 Chartierf99e70e2017-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 Chartierf99e70e2017-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 }
Jeff Hao52cde7d2017-07-31 13:35:01 -0700823
824 // If there is a dirty-image-objects file, push it.
825 if (hasFile("/system/etc/dirty-image-objects")) {
826 addOption("-Ximage-compiler-option");
827 addOption("--dirty-image-objects=/system/etc/dirty-image-objects");
828 }
Andreas Gampe08b2d582014-12-18 14:39:22 -0800829 }
830
831 property_get("dalvik.vm.image-dex2oat-flags", dex2oatImageFlagsBuf, "");
832 parseExtraOpts(dex2oatImageFlagsBuf, "-Ximage-compiler-option");
833
834 // Extra options for DexClassLoader.
835 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xms", dex2oatXmsFlagsBuf,
836 "-Xms", "-Xcompiler-option");
837 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xmx", dex2oatXmxFlagsBuf,
838 "-Xmx", "-Xcompiler-option");
839 if (skip_compilation) {
840 addOption("-Xcompiler-option");
Nicolas Geoffraybe7b0d12017-04-25 12:29:07 +0100841 addOption("--compiler-filter=assume-verified");
neo.chae155118f2015-01-07 15:32:15 +0900842
843 // We skip compilation when a minimal runtime is brought up for decryption. In that case
844 // /data is temporarily backed by a tmpfs, which is usually small.
845 // If the system image contains prebuilts, they will be relocated into the tmpfs. In this
846 // specific situation it is acceptable to *not* relocate and run out of the prebuilts
847 // directly instead.
848 addOption("--runtime-arg");
849 addOption("-Xnorelocate");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800850 } else {
851 parseCompilerOption("dalvik.vm.dex2oat-filter", dex2oatCompilerFilterBuf,
852 "--compiler-filter=", "-Xcompiler-option");
853 }
Andreas Gampee0352382015-03-30 18:43:39 -0700854 parseCompilerOption("dalvik.vm.dex2oat-threads", dex2oatThreadsBuf, "-j", "-Xcompiler-option");
855 parseCompilerOption("dalvik.vm.image-dex2oat-threads", dex2oatThreadsImageBuf, "-j",
856 "-Ximage-compiler-option");
Andreas Gampe605cca12015-04-02 23:12:56 -0700857
858 // The runtime will compile a boot image, when necessary, not using installd. Thus, we need to
859 // pass the instruction-set-features/variant as an image-compiler-option.
860 // TODO: Find a better way for the instruction-set.
861#if defined(__arm__)
862 constexpr const char* instruction_set = "arm";
863#elif defined(__aarch64__)
864 constexpr const char* instruction_set = "arm64";
865#elif defined(__mips__) && !defined(__LP64__)
866 constexpr const char* instruction_set = "mips";
867#elif defined(__mips__) && defined(__LP64__)
868 constexpr const char* instruction_set = "mips64";
869#elif defined(__i386__)
870 constexpr const char* instruction_set = "x86";
871#elif defined(__x86_64__)
872 constexpr const char* instruction_set = "x86_64";
873#else
874 constexpr const char* instruction_set = "unknown";
875#endif
876 // Note: it is OK to reuse the buffer, as the values are exactly the same between
877 // * compiler-option, used for runtime compilation (DexClassLoader)
878 // * image-compiler-option, used for boot-image compilation on device
879
880 // Copy the variant.
881 sprintf(dex2oat_isa_variant_key, "dalvik.vm.isa.%s.variant", instruction_set);
882 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
883 "--instruction-set-variant=", "-Ximage-compiler-option");
884 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
885 "--instruction-set-variant=", "-Xcompiler-option");
886 // Copy the features.
887 sprintf(dex2oat_isa_features_key, "dalvik.vm.isa.%s.features", instruction_set);
888 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
889 "--instruction-set-features=", "-Ximage-compiler-option");
890 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
891 "--instruction-set-features=", "-Xcompiler-option");
892
893
Andreas Gampe08b2d582014-12-18 14:39:22 -0800894 property_get("dalvik.vm.dex2oat-flags", dex2oatFlagsBuf, "");
895 parseExtraOpts(dex2oatFlagsBuf, "-Xcompiler-option");
896
Andy McFaddene4d81f22010-07-14 16:02:20 -0700897 /* extra options; parse this late so it overrides others */
898 property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800899 parseExtraOpts(extraOptsBuf, NULL);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 /* Set the properties for locale */
902 {
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000903 strcpy(localeOption, "-Duser.locale=");
Narayan Kamathbf882052015-08-11 15:40:34 +0100904 const std::string locale = readLocale();
905 strncat(localeOption, locale.c_str(), PROPERTY_VALUE_MAX);
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000906 addOption(localeOption);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800907 }
908
Calin Juravle92290b82015-11-10 19:30:45 +0000909 // Trace files are stored in /data/misc/trace which is writable only in debug mode.
910 property_get("ro.debuggable", propBuf, "0");
911 if (strcmp(propBuf, "1") == 0) {
912 property_get("dalvik.vm.method-trace", propBuf, "false");
Andreas Gampe98f406f2015-06-22 21:09:36 -0700913 if (strcmp(propBuf, "true") == 0) {
Calin Juravle92290b82015-11-10 19:30:45 +0000914 addOption("-Xmethod-trace");
915 parseRuntimeOption("dalvik.vm.method-trace-file",
916 methodTraceFileBuf,
917 "-Xmethod-trace-file:");
918 parseRuntimeOption("dalvik.vm.method-trace-file-siz",
919 methodTraceFileSizeBuf,
920 "-Xmethod-trace-file-size:");
921 property_get("dalvik.vm.method-trace-stream", propBuf, "false");
922 if (strcmp(propBuf, "true") == 0) {
923 addOption("-Xmethod-trace-stream");
924 }
Andreas Gampe98f406f2015-06-22 21:09:36 -0700925 }
926 }
927
Andreas Gampe08b2d582014-12-18 14:39:22 -0800928 // Native bridge library. "0" means that native bridge is disabled.
929 property_get("ro.dalvik.vm.native.bridge", propBuf, "");
930 if (propBuf[0] == '\0') {
931 ALOGW("ro.dalvik.vm.native.bridge is not expected to be empty");
932 } else if (strcmp(propBuf, "0") != 0) {
933 snprintf(nativeBridgeLibrary, sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX,
934 "-XX:NativeBridge=%s", propBuf);
935 addOption(nativeBridgeLibrary);
Calin Juravlebe20ed42014-08-26 23:00:11 +0100936 }
Calin Juravle01db9162014-08-07 14:45:53 +0100937
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700938#if defined(__LP64__)
939 const char* cpu_abilist_property_name = "ro.product.cpu.abilist64";
940#else
941 const char* cpu_abilist_property_name = "ro.product.cpu.abilist32";
942#endif // defined(__LP64__)
943 property_get(cpu_abilist_property_name, propBuf, "");
944 if (propBuf[0] == '\0') {
945 ALOGE("%s is not expected to be empty", cpu_abilist_property_name);
946 return -1;
947 }
948 snprintf(cpuAbiListBuf, sizeof(cpuAbiListBuf), "--cpu-abilist=%s", propBuf);
949 addOption(cpuAbiListBuf);
950
Andreas Gampee324ba02015-03-31 16:15:17 -0700951 // Dalvik-cache pruning counter.
952 parseRuntimeOption("dalvik.vm.zygote.max-boot-retry", cachePruneBuf,
953 "-Xzygote-max-boot-retry=");
954
Andreas Gampe27c39f12015-04-27 18:28:18 +0000955 /*
David Srbecky065075e2015-05-28 17:16:09 +0100956 * When running with debug.generate-debug-info, add --generate-debug-info to
957 * the compiler options so that the boot image, if it is compiled on device,
958 * will include native debugging information.
Andreas Gampe27c39f12015-04-27 18:28:18 +0000959 */
David Srbecky065075e2015-05-28 17:16:09 +0100960 property_get("debug.generate-debug-info", propBuf, "");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000961 if (strcmp(propBuf, "true") == 0) {
962 addOption("-Xcompiler-option");
David Srbecky065075e2015-05-28 17:16:09 +0100963 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000964 addOption("-Ximage-compiler-option");
David Srbecky065075e2015-05-28 17:16:09 +0100965 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000966 }
967
Andreas Gampee6082502015-07-24 14:19:44 -0700968 /*
969 * Retrieve the build fingerprint and provide it to the runtime. That way, ANR dumps will
970 * contain the fingerprint and can be parsed.
971 */
972 parseRuntimeOption("ro.build.fingerprint", fingerprintBuf, "-Xfingerprint:");
973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800974 initArgs.version = JNI_VERSION_1_4;
975 initArgs.options = mOptions.editArray();
976 initArgs.nOptions = mOptions.size();
977 initArgs.ignoreUnrecognized = JNI_FALSE;
978
979 /*
980 * Initialize the VM.
981 *
982 * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread.
983 * If this call succeeds, the VM is ready, and we can start issuing
984 * JNI calls.
985 */
Andy McFaddenf70188a2009-03-31 15:52:13 -0700986 if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) {
Steve Block3762c312012-01-06 19:20:56 +0000987 ALOGE("JNI_CreateJavaVM failed\n");
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700988 return -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 }
990
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700991 return 0;
Andy McFaddenf70188a2009-03-31 15:52:13 -0700992}
993
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700994char* AndroidRuntime::toSlashClassName(const char* className)
995{
996 char* result = strdup(className);
997 for (char* cp = result; *cp != '\0'; cp++) {
998 if (*cp == '.') {
999 *cp = '/';
1000 }
1001 }
1002 return result;
1003}
1004
Mike Lockwood9ee5e7e2014-09-08 16:15:21 -07001005/** Create a Java string from an ASCII or Latin-1 string */
1006jstring AndroidRuntime::NewStringLatin1(JNIEnv* env, const char* bytes) {
1007 if (!bytes) return NULL;
1008 int length = strlen(bytes);
1009 jchar* buffer = (jchar *)alloca(length * sizeof(jchar));
1010 if (!buffer) return NULL;
1011 jchar* chp = buffer;
1012 for (int i = 0; i < length; i++) {
1013 *chp++ = *bytes++;
1014 }
1015 return env->NewString(buffer, length);
1016}
1017
1018
Andy McFaddenf70188a2009-03-31 15:52:13 -07001019/*
1020 * Start the Android runtime. This involves starting the virtual machine
1021 * and calling the "static void main(String[] args)" method in the class
1022 * named by "className".
Jeff Brownebed7d62011-05-16 17:08:42 -07001023 *
1024 * Passes the main function two arguments, the class name and the specified
1025 * options string.
Andy McFaddenf70188a2009-03-31 15:52:13 -07001026 */
Sebastien Hertz7a09b832015-08-10 18:55:34 +02001027void AndroidRuntime::start(const char* className, const Vector<String8>& options, bool zygote)
Andy McFaddenf70188a2009-03-31 15:52:13 -07001028{
Dianne Hackborn8e5aafe2014-10-27 18:04:10 -07001029 ALOGD(">>>>>> START %s uid %d <<<<<<\n",
1030 className != NULL ? className : "(unknown)", getuid());
Andy McFaddenf70188a2009-03-31 15:52:13 -07001031
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001032 static const String8 startSystemServer("start-system-server");
1033
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001034 /*
1035 * 'startSystemServer == true' means runtime is obsolete and not run from
Andy McFaddenf70188a2009-03-31 15:52:13 -07001036 * init.rc anymore, so we print out the boot start event here.
1037 */
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001038 for (size_t i = 0; i < options.size(); ++i) {
1039 if (options[i] == startSystemServer) {
1040 /* track our progress through the boot sequence */
1041 const int LOG_BOOT_PROGRESS_START = 3000;
1042 LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));
1043 }
Andy McFaddenf70188a2009-03-31 15:52:13 -07001044 }
1045
1046 const char* rootDir = getenv("ANDROID_ROOT");
1047 if (rootDir == NULL) {
1048 rootDir = "/system";
1049 if (!hasDir("/system")) {
1050 LOG_FATAL("No root directory specified, and /android does not exist.");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001051 return;
Andy McFaddenf70188a2009-03-31 15:52:13 -07001052 }
1053 setenv("ANDROID_ROOT", rootDir, 1);
1054 }
1055
1056 //const char* kernelHack = getenv("LD_ASSUME_KERNEL");
Steve Block5baa3a62011-12-20 16:23:08 +00001057 //ALOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001058
1059 /* start the virtual machine */
Brian Carlstrom9f8203a2013-06-19 13:49:36 -07001060 JniInvocation jni_invocation;
1061 jni_invocation.Init(NULL);
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001062 JNIEnv* env;
Sebastien Hertz7a09b832015-08-10 18:55:34 +02001063 if (startVm(&mJavaVM, &env, zygote) != 0) {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001064 return;
1065 }
1066 onVmCreated(env);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 /*
1069 * Register android functions.
1070 */
1071 if (startReg(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001072 ALOGE("Unable to register all android natives\n");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001073 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001074 }
1075
1076 /*
1077 * We want to call main() with a String array with arguments in it.
Jeff Brownebed7d62011-05-16 17:08:42 -07001078 * At present we have two arguments, the class name and an option string.
1079 * Create an array to hold them.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 */
1081 jclass stringClass;
1082 jobjectArray strArray;
1083 jstring classNameStr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084
1085 stringClass = env->FindClass("java/lang/String");
1086 assert(stringClass != NULL);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001087 strArray = env->NewObjectArray(options.size() + 1, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001088 assert(strArray != NULL);
1089 classNameStr = env->NewStringUTF(className);
1090 assert(classNameStr != NULL);
1091 env->SetObjectArrayElement(strArray, 0, classNameStr);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001092
1093 for (size_t i = 0; i < options.size(); ++i) {
1094 jstring optionsStr = env->NewStringUTF(options.itemAt(i).string());
1095 assert(optionsStr != NULL);
1096 env->SetObjectArrayElement(strArray, i + 1, optionsStr);
1097 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098
1099 /*
1100 * Start VM. This thread becomes the main thread of the VM, and will
1101 * not return until the VM exits.
1102 */
George Burgess IVd657a382017-06-20 23:53:29 -07001103 char* slashClassName = toSlashClassName(className != NULL ? className : "");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001104 jclass startClass = env->FindClass(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 if (startClass == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001106 ALOGE("JavaVM unable to locate class '%s'\n", slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 /* keep going */
1108 } else {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001109 jmethodID startMeth = env->GetStaticMethodID(startClass, "main",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 "([Ljava/lang/String;)V");
1111 if (startMeth == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001112 ALOGE("JavaVM unable to find main() in '%s'\n", className);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 /* keep going */
1114 } else {
1115 env->CallStaticVoidMethod(startClass, startMeth, strArray);
1116
1117#if 0
1118 if (env->ExceptionCheck())
1119 threadExitUncaughtException(env);
1120#endif
1121 }
1122 }
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001123 free(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124
Steve Block5baa3a62011-12-20 16:23:08 +00001125 ALOGD("Shutting down VM\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 if (mJavaVM->DetachCurrentThread() != JNI_OK)
Steve Block8564c8d2012-01-05 23:22:43 +00001127 ALOGW("Warning: unable to detach main thread\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 if (mJavaVM->DestroyJavaVM() != 0)
Steve Block8564c8d2012-01-05 23:22:43 +00001129 ALOGW("Warning: VM did not shut down cleanly\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001130}
1131
Jeff Brown4280c4a2012-03-15 17:48:02 -07001132void AndroidRuntime::exit(int code)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001133{
Jeff Brown4280c4a2012-03-15 17:48:02 -07001134 if (mExitWithoutCleanup) {
1135 ALOGI("VM exiting with result code %d, cleanup skipped.", code);
1136 ::_exit(code);
1137 } else {
1138 ALOGI("VM exiting with result code %d.", code);
1139 onExit(code);
1140 ::exit(code);
1141 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142}
1143
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001144void AndroidRuntime::onVmCreated(JNIEnv* env)
1145{
1146 // If AndroidRuntime had anything to do here, we'd have done it in 'start'.
1147}
1148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149/*
Andreas Huber9ae000c2014-02-13 17:22:33 +00001150 * Get the JNIEnv pointer for this thread.
1151 *
1152 * Returns NULL if the slot wasn't allocated or populated.
1153 */
1154/*static*/ JNIEnv* AndroidRuntime::getJNIEnv()
1155{
1156 JNIEnv* env;
1157 JavaVM* vm = AndroidRuntime::getJavaVM();
1158 assert(vm != NULL);
1159
1160 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
1161 return NULL;
1162 return env;
1163}
1164
1165/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 * Makes the current thread visible to the VM.
1167 *
1168 * The JNIEnv pointer returned is only valid for the current thread, and
1169 * thus must be tucked into thread-local storage.
1170 */
1171static int javaAttachThread(const char* threadName, JNIEnv** pEnv)
1172{
1173 JavaVMAttachArgs args;
1174 JavaVM* vm;
1175 jint result;
1176
1177 vm = AndroidRuntime::getJavaVM();
1178 assert(vm != NULL);
1179
1180 args.version = JNI_VERSION_1_4;
1181 args.name = (char*) threadName;
1182 args.group = NULL;
1183
1184 result = vm->AttachCurrentThread(pEnv, (void*) &args);
1185 if (result != JNI_OK)
Steve Block6215d3f2012-01-04 20:05:49 +00001186 ALOGI("NOTE: attach of thread '%s' failed\n", threadName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001187
1188 return result;
1189}
1190
1191/*
1192 * Detach the current thread from the set visible to the VM.
1193 */
1194static int javaDetachThread(void)
1195{
1196 JavaVM* vm;
1197 jint result;
1198
1199 vm = AndroidRuntime::getJavaVM();
1200 assert(vm != NULL);
1201
1202 result = vm->DetachCurrentThread();
1203 if (result != JNI_OK)
Steve Block3762c312012-01-06 19:20:56 +00001204 ALOGE("ERROR: thread detach failed\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001205 return result;
1206}
1207
1208/*
1209 * When starting a native thread that will be visible from the VM, we
1210 * bounce through this to get the right attach/detach action.
1211 * Note that this function calls free(args)
1212 */
1213/*static*/ int AndroidRuntime::javaThreadShell(void* args) {
1214 void* start = ((void**)args)[0];
1215 void* userData = ((void **)args)[1];
1216 char* name = (char*) ((void **)args)[2]; // we own this storage
1217 free(args);
1218 JNIEnv* env;
1219 int result;
1220
1221 /* hook us into the VM */
1222 if (javaAttachThread(name, &env) != JNI_OK)
1223 return -1;
1224
1225 /* start the thread running */
1226 result = (*(android_thread_func_t)start)(userData);
1227
1228 /* unhook us */
1229 javaDetachThread();
1230 free(name);
1231
1232 return result;
1233}
1234
1235/*
1236 * This is invoked from androidCreateThreadEtc() via the callback
1237 * set with androidSetCreateThreadFunc().
1238 *
1239 * We need to create the new thread in such a way that it gets hooked
1240 * into the VM before it really starts executing.
1241 */
1242/*static*/ int AndroidRuntime::javaCreateThreadEtc(
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001243 android_thread_func_t entryFunction,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 void* userData,
1245 const char* threadName,
1246 int32_t threadPriority,
1247 size_t threadStackSize,
1248 android_thread_id_t* threadId)
1249{
1250 void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free
1251 int result;
1252
Brian Carlstrom66f48312016-03-12 16:07:48 -08001253 LOG_ALWAYS_FATAL_IF(threadName == nullptr, "threadName not provided to javaCreateThreadEtc");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001254
1255 args[0] = (void*) entryFunction;
1256 args[1] = userData;
1257 args[2] = (void*) strdup(threadName); // javaThreadShell must free
1258
1259 result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args,
1260 threadName, threadPriority, threadStackSize, threadId);
1261 return result;
1262}
1263
1264/*
1265 * Create a thread that is visible from the VM.
1266 *
1267 * This is called from elsewhere in the library.
1268 */
Mike Lockwoodf602d362010-06-20 14:28:16 -07001269/*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001270 void (*start)(void *), void* arg)
1271{
Mike Lockwoodf602d362010-06-20 14:28:16 -07001272 android_thread_id_t threadId = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001273 javaCreateThreadEtc((android_thread_func_t) start, arg, name,
Mike Lockwoodf602d362010-06-20 14:28:16 -07001274 ANDROID_PRIORITY_DEFAULT, 0, &threadId);
1275 return threadId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001276}
1277
1278#if 0
1279static void quickTest(void* arg)
1280{
1281 const char* str = (const char*) arg;
1282
1283 printf("In quickTest: %s\n", str);
1284}
1285#endif
1286
1287#ifdef NDEBUG
1288 #define REG_JNI(name) { name }
1289 struct RegJNIRec {
1290 int (*mProc)(JNIEnv*);
1291 };
1292#else
1293 #define REG_JNI(name) { name, #name }
1294 struct RegJNIRec {
1295 int (*mProc)(JNIEnv*);
1296 const char* mName;
1297 };
1298#endif
1299
1300typedef void (*RegJAMProc)();
1301
1302static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env)
1303{
1304 for (size_t i = 0; i < count; i++) {
1305 if (array[i].mProc(env) < 0) {
1306#ifndef NDEBUG
Steve Block5baa3a62011-12-20 16:23:08 +00001307 ALOGD("----------!!! %s failed to load\n", array[i].mName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001308#endif
1309 return -1;
1310 }
1311 }
1312 return 0;
1313}
1314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315static const RegJNIRec gRegJNI[] = {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001316 REG_JNI(register_com_android_internal_os_RuntimeInit),
Jesse Hall1fe1dc02017-07-06 15:30:39 -07001317 REG_JNI(register_com_android_internal_os_ZygoteInit_nativeZygoteInit),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001318 REG_JNI(register_android_os_SystemClock),
1319 REG_JNI(register_android_util_EventLog),
1320 REG_JNI(register_android_util_Log),
Svet Ganov53a441c2016-04-19 19:38:00 -07001321 REG_JNI(register_android_util_MemoryIntArray),
Doris Liucdd23f92015-11-11 14:31:13 -08001322 REG_JNI(register_android_util_PathParser),
Michal Karpinski6235a942016-03-15 12:07:23 +00001323 REG_JNI(register_android_app_admin_SecurityLog),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001324 REG_JNI(register_android_content_AssetManager),
1325 REG_JNI(register_android_content_StringBlock),
1326 REG_JNI(register_android_content_XmlBlock),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001327 REG_JNI(register_android_text_AndroidCharacter),
Anish Athalye88b5b0b2014-06-24 14:39:43 -07001328 REG_JNI(register_android_text_StaticLayout),
Doug Feltdae8e942010-02-24 14:33:15 -08001329 REG_JNI(register_android_text_AndroidBidi),
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001330 REG_JNI(register_android_view_InputDevice),
1331 REG_JNI(register_android_view_KeyCharacterMap),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001332 REG_JNI(register_android_os_Process),
Andreas Hubera8079bf2010-11-16 14:40:31 -08001333 REG_JNI(register_android_os_SystemProperties),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001334 REG_JNI(register_android_os_Binder),
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -08001335 REG_JNI(register_android_os_Parcel),
Andreas Huberc0b6c532016-08-15 09:25:02 -07001336 REG_JNI(register_android_os_HwBinder),
Andreas Huberdc263212016-08-25 11:21:21 -07001337 REG_JNI(register_android_os_HwBlob),
Andreas Huberc0b6c532016-08-15 09:25:02 -07001338 REG_JNI(register_android_os_HwParcel),
1339 REG_JNI(register_android_os_HwRemoteBinder),
Yifan Hongbecc56d2017-04-05 14:42:05 -07001340 REG_JNI(register_android_os_VintfObject),
Yifan Hong1bda6732017-04-26 11:38:01 -07001341 REG_JNI(register_android_os_VintfRuntimeInfo),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001342 REG_JNI(register_android_nio_utils),
Richard Uhler775873a2015-12-29 12:37:39 -08001343 REG_JNI(register_android_graphics_Canvas),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001344 REG_JNI(register_android_graphics_Graphics),
Chris Craik54389792013-12-20 13:28:11 -08001345 REG_JNI(register_android_view_DisplayEventReceiver),
John Reckf666ad72014-03-14 16:24:57 -07001346 REG_JNI(register_android_view_RenderNode),
John Recke45b1fd2014-04-15 09:50:16 -07001347 REG_JNI(register_android_view_RenderNodeAnimator),
Chris Craikc9070eb2015-03-09 18:50:14 -07001348 REG_JNI(register_android_view_DisplayListCanvas),
John Reck04fc5832014-02-05 16:38:25 -08001349 REG_JNI(register_android_view_HardwareLayer),
John Reckcec24ae2013-11-05 13:27:50 -08001350 REG_JNI(register_android_view_ThreadedRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351 REG_JNI(register_android_view_Surface),
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001352 REG_JNI(register_android_view_SurfaceControl),
Jeff Brown64a55af2012-08-26 02:47:39 -07001353 REG_JNI(register_android_view_SurfaceSession),
Romain Guy8f0095c2011-05-02 17:24:22 -07001354 REG_JNI(register_android_view_TextureView),
John Reck315c3292014-05-09 19:21:04 -07001355 REG_JNI(register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356 REG_JNI(register_com_google_android_gles_jni_EGLImpl),
1357 REG_JNI(register_com_google_android_gles_jni_GLImpl),
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001358 REG_JNI(register_android_opengl_jni_EGL14),
Jesse Hall237c2b82013-05-06 11:36:57 -07001359 REG_JNI(register_android_opengl_jni_EGLExt),
Jack Palevich1c4907e2009-04-13 16:22:25 -07001360 REG_JNI(register_android_opengl_jni_GLES10),
1361 REG_JNI(register_android_opengl_jni_GLES10Ext),
1362 REG_JNI(register_android_opengl_jni_GLES11),
1363 REG_JNI(register_android_opengl_jni_GLES11Ext),
Jack Palevich560814f2009-11-19 16:34:55 +08001364 REG_JNI(register_android_opengl_jni_GLES20),
Jesse Halld877efe2013-04-29 15:59:35 -07001365 REG_JNI(register_android_opengl_jni_GLES30),
Jesse Hall7ab63ac2014-05-19 15:13:41 -07001366 REG_JNI(register_android_opengl_jni_GLES31),
1367 REG_JNI(register_android_opengl_jni_GLES31Ext),
Pablo Ceballos38c1a7e2015-10-30 10:34:30 -07001368 REG_JNI(register_android_opengl_jni_GLES32),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001369
1370 REG_JNI(register_android_graphics_Bitmap),
1371 REG_JNI(register_android_graphics_BitmapFactory),
Wei-Ta Chen6b849e22010-09-07 17:32:18 +08001372 REG_JNI(register_android_graphics_BitmapRegionDecoder),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001373 REG_JNI(register_android_graphics_Camera),
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -04001374 REG_JNI(register_android_graphics_CreateJavaOutputStreamAdaptor),
John Reck52244ff2014-05-01 21:27:37 -07001375 REG_JNI(register_android_graphics_CanvasProperty),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001376 REG_JNI(register_android_graphics_ColorFilter),
1377 REG_JNI(register_android_graphics_DrawFilter),
Raph Levien1a73f7322014-01-30 16:06:28 -08001378 REG_JNI(register_android_graphics_FontFamily),
sergeyv0a0f2312017-01-04 13:58:52 -08001379 REG_JNI(register_android_graphics_GraphicBuffer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001380 REG_JNI(register_android_graphics_Interpolator),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001381 REG_JNI(register_android_graphics_MaskFilter),
1382 REG_JNI(register_android_graphics_Matrix),
1383 REG_JNI(register_android_graphics_Movie),
1384 REG_JNI(register_android_graphics_NinePatch),
1385 REG_JNI(register_android_graphics_Paint),
1386 REG_JNI(register_android_graphics_Path),
1387 REG_JNI(register_android_graphics_PathMeasure),
1388 REG_JNI(register_android_graphics_PathEffect),
1389 REG_JNI(register_android_graphics_Picture),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001390 REG_JNI(register_android_graphics_Region),
1391 REG_JNI(register_android_graphics_Shader),
Jamie Gennisaa0ce332011-01-06 17:04:26 -08001392 REG_JNI(register_android_graphics_SurfaceTexture),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001393 REG_JNI(register_android_graphics_Typeface),
Wei-Ta Chenbca2d612009-11-30 17:52:05 +08001394 REG_JNI(register_android_graphics_YuvImage),
Doris Liu766431a2016-02-04 22:17:11 +00001395 REG_JNI(register_android_graphics_drawable_AnimatedVectorDrawable),
Doris Liu4bbc2932015-12-01 17:59:40 -08001396 REG_JNI(register_android_graphics_drawable_VectorDrawable),
Svetoslav6811f4e2013-09-18 15:58:28 -07001397 REG_JNI(register_android_graphics_pdf_PdfDocument),
Svetoslav62ce3322014-09-04 21:17:17 -07001398 REG_JNI(register_android_graphics_pdf_PdfEditor),
Svetoslav29617692014-04-24 18:40:42 -07001399 REG_JNI(register_android_graphics_pdf_PdfRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001400
1401 REG_JNI(register_android_database_CursorWindow),
Jeff Browne5360fb2011-10-31 17:48:13 -07001402 REG_JNI(register_android_database_SQLiteConnection),
1403 REG_JNI(register_android_database_SQLiteGlobal),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001404 REG_JNI(register_android_database_SQLiteDebug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001405 REG_JNI(register_android_os_Debug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406 REG_JNI(register_android_os_FileObserver),
Jesse Hallb12249b2016-12-12 12:53:02 -08001407 REG_JNI(register_android_os_GraphicsEnvironment),
Christopher Tatefa9e7c02010-05-06 12:07:10 -07001408 REG_JNI(register_android_os_MessageQueue),
Stephen Smalleyc07fca32012-01-13 08:31:39 -05001409 REG_JNI(register_android_os_SELinux),
Paul Lawrenceef854772017-01-31 09:54:31 -08001410 REG_JNI(register_android_os_seccomp),
Jeff Brown481c1572012-03-09 14:41:15 -08001411 REG_JNI(register_android_os_Trace),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001412 REG_JNI(register_android_os_UEventObserver),
1413 REG_JNI(register_android_net_LocalSocketImpl),
1414 REG_JNI(register_android_net_NetworkUtils),
Dan Egnor2b4abcd2010-04-07 17:30:50 -07001415 REG_JNI(register_android_net_TrafficStats),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001416 REG_JNI(register_android_os_MemoryFile),
John Reckdea6a022017-05-25 17:09:33 -07001417 REG_JNI(register_android_os_SharedMemory),
Narayan Kamathf9419f02017-06-15 11:35:38 +01001418 REG_JNI(register_com_android_internal_os_ClassLoaderFactory),
Narayan Kamath973b4662014-03-31 13:41:26 +01001419 REG_JNI(register_com_android_internal_os_Zygote),
Jesse Hall1fe1dc02017-07-06 15:30:39 -07001420 REG_JNI(register_com_android_internal_os_ZygoteInit),
John Reck9fa40712014-05-09 15:26:59 -07001421 REG_JNI(register_com_android_internal_util_VirtualRefBasePtr),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422 REG_JNI(register_android_hardware_Camera),
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07001423 REG_JNI(register_android_hardware_camera2_CameraMetadata),
Ruben Brunkfeb50af2014-05-09 19:58:49 -07001424 REG_JNI(register_android_hardware_camera2_legacy_LegacyCameraDevice),
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -07001425 REG_JNI(register_android_hardware_camera2_legacy_PerfMeasurement),
Ruben Brunkb6079002014-05-22 12:33:54 -07001426 REG_JNI(register_android_hardware_camera2_DngCreator),
Craig Donner1a4d07d2017-01-09 13:01:22 -08001427 REG_JNI(register_android_hardware_HardwareBuffer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001428 REG_JNI(register_android_hardware_SensorManager),
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04001429 REG_JNI(register_android_hardware_SerialPort),
Eric Laurent60b62bc2014-04-18 17:50:49 -07001430 REG_JNI(register_android_hardware_SoundTrigger),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001431 REG_JNI(register_android_hardware_UsbDevice),
Mike Lockwoodacc29cc2011-03-11 08:18:08 -05001432 REG_JNI(register_android_hardware_UsbDeviceConnection),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001433 REG_JNI(register_android_hardware_UsbRequest),
destradaaa4fa3b52014-07-09 10:46:39 -07001434 REG_JNI(register_android_hardware_location_ActivityRecognitionHardware),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435 REG_JNI(register_android_media_AudioRecord),
1436 REG_JNI(register_android_media_AudioSystem),
1437 REG_JNI(register_android_media_AudioTrack),
1438 REG_JNI(register_android_media_JetPlayer),
Jeff Browncbad9762012-09-04 21:57:59 -07001439 REG_JNI(register_android_media_RemoteDisplay),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001440 REG_JNI(register_android_media_ToneGenerator),
1441
1442 REG_JNI(register_android_opengl_classes),
JP Abgrall98a4f7e2011-09-02 15:36:33 -07001443 REG_JNI(register_android_server_NetworkManagementSocketTagger),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 REG_JNI(register_android_ddm_DdmHandleNativeHeap),
Joe Onorato1cf58742009-06-12 11:06:24 -07001445 REG_JNI(register_android_backup_BackupDataInput),
Joe Onoratod2110db2009-05-19 13:41:21 -07001446 REG_JNI(register_android_backup_BackupDataOutput),
Joe Onorato06290a42009-06-18 20:10:37 -07001447 REG_JNI(register_android_backup_FileBackupHelperBase),
Joe Onorato4ababd92009-06-25 18:29:18 -04001448 REG_JNI(register_android_backup_BackupHelperDispatcher),
Christopher Tate4a627c72011-04-01 14:43:32 -07001449 REG_JNI(register_android_app_backup_FullBackup),
Dimitry Ivanov4449ef52016-02-25 17:41:13 -08001450 REG_JNI(register_android_app_Activity),
Chet Haase9c1e23b2011-03-24 10:51:31 -07001451 REG_JNI(register_android_app_ActivityThread),
Dimitry Ivanov09979082016-04-19 11:11:01 -07001452 REG_JNI(register_android_app_ApplicationLoaders),
Dianne Hackborn69969e42010-05-04 11:40:40 -07001453 REG_JNI(register_android_app_NativeActivity),
Przemyslaw Szczepaniak8a7c1602015-11-03 09:47:56 +00001454 REG_JNI(register_android_util_jar_StrictJarFile),
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001455 REG_JNI(register_android_view_InputChannel),
Jeff Brown32cbc38552011-12-01 14:01:49 -08001456 REG_JNI(register_android_view_InputEventReceiver),
Jeff Brownc28867a2013-03-26 15:42:39 -07001457 REG_JNI(register_android_view_InputEventSender),
Michael Wrighta44dd262013-04-10 21:12:00 -07001458 REG_JNI(register_android_view_InputQueue),
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001459 REG_JNI(register_android_view_KeyEvent),
1460 REG_JNI(register_android_view_MotionEvent),
Jeff Brown2352b972011-04-12 22:39:53 -07001461 REG_JNI(register_android_view_PointerIcon),
Jeff Brown2ed24622011-03-14 19:39:54 -07001462 REG_JNI(register_android_view_VelocityTracker),
Kenny Root02c87302010-07-01 08:10:18 -07001463
1464 REG_JNI(register_android_content_res_ObbScanner),
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -07001465 REG_JNI(register_android_content_res_Configuration),
Chet Haase6e0ecb42010-11-03 19:41:18 -07001466
1467 REG_JNI(register_android_animation_PropertyValuesHolder),
Kenny Root66269ea2011-07-12 14:14:01 -07001468 REG_JNI(register_com_android_internal_content_NativeLibraryHelper),
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -08001469 REG_JNI(register_com_android_internal_net_NetworkStatsFactory),
Daichi Hirono878e86f2016-10-31 09:33:30 +09001470 REG_JNI(register_com_android_internal_os_FuseAppLoop),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001471};
1472
1473/*
1474 * Register android native functions with the VM.
1475 */
1476/*static*/ int AndroidRuntime::startReg(JNIEnv* env)
1477{
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001478 ATRACE_NAME("RegisterAndroidNatives");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479 /*
1480 * This hook causes all future threads created in this process to be
1481 * attached to the JavaVM. (This needs to go away in favor of JNI
1482 * Attach calls.)
1483 */
1484 androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc);
1485
Steve Block71f2cf12011-10-20 11:56:00 +01001486 ALOGV("--- registering native functions ---\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001487
1488 /*
1489 * Every "register" function calls one or more things that return
1490 * a local reference (e.g. FindClass). Because we haven't really
1491 * started the VM yet, they're all getting stored in the base frame
1492 * and never released. Use Push/Pop to manage the storage.
1493 */
1494 env->PushLocalFrame(200);
1495
1496 if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) {
1497 env->PopLocalFrame(NULL);
1498 return -1;
1499 }
1500 env->PopLocalFrame(NULL);
1501
1502 //createJavaThread("fubar", quickTest, (void*) "hello");
1503
1504 return 0;
1505}
1506
1507AndroidRuntime* AndroidRuntime::getRuntime()
1508{
1509 return gCurRuntime;
1510}
1511
1512/**
Narayan Kamathc21dab92015-06-25 14:22:00 +01001513 * Used by surface flinger's DdmConnection to register native methods from
1514 * the framework.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 */
Narayan Kamathc21dab92015-06-25 14:22:00 +01001516extern "C" jint registerFrameworkNatives(JNIEnv* env) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1518}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001519} // namespace android