blob: b6ee0fe782a612815c3ff80b6a0183a7ea89f8ae [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>
Tom Cherry93099e42017-10-11 13:44:21 -070022
Elliott Hughesa1194cb2018-03-23 11:27:04 -070023#include <android-base/macros.h>
Tom Cherry93099e42017-10-11 13:44:21 -070024#include <android-base/properties.h>
Mathias Agopian07952722009-05-19 19:08:10 -070025#include <binder/IBinder.h>
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -080026#include <binder/IPCThreadState.h>
Mathias Agopian07952722009-05-19 19:08:10 -070027#include <binder/IServiceManager.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028#include <utils/Log.h>
29#include <utils/misc.h>
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +090030#include <utils/Trace.h>
Mathias Agopian07952722009-05-19 19:08:10 -070031#include <binder/Parcel.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032#include <utils/threads.h>
33#include <cutils/properties.h>
Mathieu Chartierd2a975a2019-01-28 11:11:25 -080034#include <server_configurable_flags/get_flags.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035
36#include <SkGraphics.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
38#include "jni.h"
Steven Moreland2279b252017-07-19 09:50:45 -070039#include <nativehelper/JNIHelp.h>
40#include <nativehelper/JniInvocation.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041#include "android_util_Binder.h"
42
43#include <stdio.h>
44#include <signal.h>
45#include <sys/stat.h>
46#include <sys/types.h>
47#include <signal.h>
48#include <dirent.h>
49#include <assert.h>
50
Narayan Kamathbf882052015-08-11 15:40:34 +010051#include <string>
52#include <vector>
53
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054using namespace android;
Tom Cherry93099e42017-10-11 13:44:21 -070055using android::base::GetProperty;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057extern int register_android_os_Binder(JNIEnv* env);
58extern int register_android_os_Process(JNIEnv* env);
59extern int register_android_graphics_Bitmap(JNIEnv*);
60extern int register_android_graphics_BitmapFactory(JNIEnv*);
Wei-Ta Chen6b849e22010-09-07 17:32:18 +080061extern int register_android_graphics_BitmapRegionDecoder(JNIEnv*);
Leon Scroggins III0c01dbf2017-10-20 14:08:11 -040062extern int register_android_graphics_ByteBufferStreamAdaptor(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063extern int register_android_graphics_Camera(JNIEnv* env);
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -040064extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env);
sergeyv0a0f2312017-01-04 13:58:52 -080065extern int register_android_graphics_GraphicBuffer(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066extern int register_android_graphics_Graphics(JNIEnv* env);
Leon Scroggins III0c01dbf2017-10-20 14:08:11 -040067extern int register_android_graphics_ImageDecoder(JNIEnv*);
Leon Scroggins III671cce22018-01-14 16:52:17 -050068extern int register_android_graphics_drawable_AnimatedImageDrawable(JNIEnv*);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069extern int register_android_graphics_Interpolator(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070extern int register_android_graphics_MaskFilter(JNIEnv* env);
71extern int register_android_graphics_Movie(JNIEnv* env);
72extern int register_android_graphics_NinePatch(JNIEnv*);
73extern int register_android_graphics_PathEffect(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074extern int register_android_graphics_Shader(JNIEnv* env);
75extern int register_android_graphics_Typeface(JNIEnv* env);
Wei-Ta Chenbca2d612009-11-30 17:52:05 +080076extern int register_android_graphics_YuvImage(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077
78extern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env);
79extern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070080extern int register_android_opengl_jni_EGL14(JNIEnv* env);
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -060081extern int register_android_opengl_jni_EGL15(JNIEnv* env);
Jesse Hall237c2b82013-05-06 11:36:57 -070082extern int register_android_opengl_jni_EGLExt(JNIEnv* env);
Jack Palevich1c4907e2009-04-13 16:22:25 -070083extern int register_android_opengl_jni_GLES10(JNIEnv* env);
84extern int register_android_opengl_jni_GLES10Ext(JNIEnv* env);
85extern int register_android_opengl_jni_GLES11(JNIEnv* env);
86extern int register_android_opengl_jni_GLES11Ext(JNIEnv* env);
Jack Palevich560814f2009-11-19 16:34:55 +080087extern int register_android_opengl_jni_GLES20(JNIEnv* env);
Jesse Halld877efe2013-04-29 15:59:35 -070088extern int register_android_opengl_jni_GLES30(JNIEnv* env);
Jesse Hall7ab63ac2014-05-19 15:13:41 -070089extern int register_android_opengl_jni_GLES31(JNIEnv* env);
90extern int register_android_opengl_jni_GLES31Ext(JNIEnv* env);
Pablo Ceballos38c1a7e2015-10-30 10:34:30 -070091extern int register_android_opengl_jni_GLES32(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092
93extern int register_android_hardware_Camera(JNIEnv *env);
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -070094extern int register_android_hardware_camera2_CameraMetadata(JNIEnv *env);
Ruben Brunkfeb50af2014-05-09 19:58:49 -070095extern int register_android_hardware_camera2_legacy_LegacyCameraDevice(JNIEnv *env);
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -070096extern int register_android_hardware_camera2_legacy_PerfMeasurement(JNIEnv *env);
Ruben Brunkb6079002014-05-22 12:33:54 -070097extern int register_android_hardware_camera2_DngCreator(JNIEnv *env);
Craig Donner1a4d07d2017-01-09 13:01:22 -080098extern int register_android_hardware_HardwareBuffer(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099extern int register_android_hardware_SensorManager(JNIEnv *env);
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -0400100extern int register_android_hardware_SerialPort(JNIEnv *env);
Eric Laurent60b62bc2014-04-18 17:50:49 -0700101extern int register_android_hardware_SoundTrigger(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500102extern int register_android_hardware_UsbDevice(JNIEnv *env);
Mike Lockwoodacc29cc2011-03-11 08:18:08 -0500103extern int register_android_hardware_UsbDeviceConnection(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500104extern int register_android_hardware_UsbRequest(JNIEnv *env);
Brian Duddiecfa5b5b2019-01-22 18:01:40 +0000105extern int register_android_hardware_location_ActivityRecognitionHardware(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106
Eric Laurent7c31847e2018-11-29 14:33:56 -0800107extern int register_android_media_AudioEffectDescriptor(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108extern int register_android_media_AudioRecord(JNIEnv *env);
109extern int register_android_media_AudioSystem(JNIEnv *env);
110extern int register_android_media_AudioTrack(JNIEnv *env);
François Gaffieb4691282018-07-09 13:07:32 +0200111extern int register_android_media_AudioAttributes(JNIEnv *env);
François Gaffiec01fa3a2018-03-15 14:33:24 +0100112extern int register_android_media_AudioProductStrategies(JNIEnv *env);
François Gaffieadcd00a2018-09-18 17:06:26 +0200113extern int register_android_media_AudioVolumeGroups(JNIEnv *env);
114extern int register_android_media_AudioVolumeGroupChangeHandler(JNIEnv *env);
jiabinc0f49442018-01-05 10:23:50 -0800115extern int register_android_media_MicrophoneInfo(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116extern int register_android_media_JetPlayer(JNIEnv *env);
117extern int register_android_media_ToneGenerator(JNIEnv *env);
Paul McLean84b491302018-05-09 10:03:57 -0600118extern int register_android_media_midi(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120namespace android {
121
122/*
123 * JNI-based registration functions. Note these are properly contained in
124 * namespace android.
125 */
Michal Karpinski6235a942016-03-15 12:07:23 +0000126extern int register_android_app_admin_SecurityLog(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127extern int register_android_content_AssetManager(JNIEnv* env);
128extern int register_android_util_EventLog(JNIEnv* env);
Chenjie Yu671b1b52017-08-30 22:14:05 -0700129extern int register_android_util_StatsLog(JNIEnv* env);
Tej Singhbe0482b2019-03-19 22:01:57 -0700130extern int register_android_util_StatsLogInternal(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131extern int register_android_util_Log(JNIEnv* env);
Svet Ganov53a441c2016-04-19 19:38:00 -0700132extern int register_android_util_MemoryIntArray(JNIEnv* env);
Doris Liucdd23f92015-11-11 14:31:13 -0800133extern int register_android_util_PathParser(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134extern int register_android_content_StringBlock(JNIEnv* env);
135extern int register_android_content_XmlBlock(JNIEnv* env);
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800136extern int register_android_content_res_ApkAssets(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137extern int register_android_graphics_Canvas(JNIEnv* env);
John Reck52244ff2014-05-01 21:27:37 -0700138extern int register_android_graphics_CanvasProperty(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139extern int register_android_graphics_ColorFilter(JNIEnv* env);
Leon Scroggins III0e443d12018-12-19 11:38:35 -0500140extern int register_android_graphics_ColorSpace(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141extern int register_android_graphics_DrawFilter(JNIEnv* env);
Raph Levien1a73f7322014-01-30 16:06:28 -0800142extern int register_android_graphics_FontFamily(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143extern int register_android_graphics_Matrix(JNIEnv* env);
144extern int register_android_graphics_Paint(JNIEnv* env);
145extern int register_android_graphics_Path(JNIEnv* env);
146extern int register_android_graphics_PathMeasure(JNIEnv* env);
147extern int register_android_graphics_Picture(JNIEnv*);
Jeff Brownfbf09772011-01-16 14:06:57 -0800148extern int register_android_graphics_Region(JNIEnv* env);
Jamie Gennisaa0ce332011-01-06 17:04:26 -0800149extern int register_android_graphics_SurfaceTexture(JNIEnv* env);
Doris Liu766431a2016-02-04 22:17:11 +0000150extern int register_android_graphics_drawable_AnimatedVectorDrawable(JNIEnv* env);
Doris Liu4bbc2932015-12-01 17:59:40 -0800151extern int register_android_graphics_drawable_VectorDrawable(JNIEnv* env);
Seigo Nonakaa1c21c02018-07-20 15:57:39 -0700152extern int register_android_graphics_fonts_Font(JNIEnv* env);
Seigo Nonaka88930f12018-07-24 17:09:23 -0700153extern int register_android_graphics_fonts_FontFamily(JNIEnv* env);
Svetoslav6811f4e2013-09-18 15:58:28 -0700154extern int register_android_graphics_pdf_PdfDocument(JNIEnv* env);
Svetoslav62ce3322014-09-04 21:17:17 -0700155extern int register_android_graphics_pdf_PdfEditor(JNIEnv* env);
Svetoslav29617692014-04-24 18:40:42 -0700156extern int register_android_graphics_pdf_PdfRenderer(JNIEnv* env);
Seigo Nonaka70200b02018-10-01 16:04:11 -0700157extern int register_android_graphics_text_MeasuredText(JNIEnv* env);
158extern int register_android_graphics_text_LineBreaker(JNIEnv *env);
Jeff Brown0a0a1242011-12-02 02:25:22 -0800159extern int register_android_view_DisplayEventReceiver(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700160extern int register_android_view_DisplayListCanvas(JNIEnv* env);
Riddle Hsucd958bc2019-01-23 15:40:26 +0800161extern int register_android_view_InputApplicationHandle(JNIEnv* env);
162extern int register_android_view_InputWindowHandle(JNIEnv* env);
John Reck9d8d99d2018-02-21 12:55:41 -0800163extern int register_android_view_TextureLayer(JNIEnv* env);
John Reckf666ad72014-03-14 16:24:57 -0700164extern int register_android_view_RenderNode(JNIEnv* env);
John Recke45b1fd2014-04-15 09:50:16 -0700165extern int register_android_view_RenderNodeAnimator(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166extern int register_android_view_Surface(JNIEnv* env);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800167extern int register_android_view_SurfaceControl(JNIEnv* env);
Jeff Brown64a55af2012-08-26 02:47:39 -0700168extern int register_android_view_SurfaceSession(JNIEnv* env);
Adrian Roos9b963d32019-02-13 18:39:36 +0000169extern int register_android_view_CompositionSamplingListener(JNIEnv* env);
Romain Guy8f0095c2011-05-02 17:24:22 -0700170extern int register_android_view_TextureView(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700171extern int register_android_view_ThreadedRenderer(JNIEnv* env);
John Reck315c3292014-05-09 19:21:04 -0700172extern int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173extern int register_android_database_CursorWindow(JNIEnv* env);
Jeff Browne5360fb2011-10-31 17:48:13 -0700174extern int register_android_database_SQLiteConnection(JNIEnv* env);
175extern int register_android_database_SQLiteGlobal(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176extern int register_android_database_SQLiteDebug(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177extern int register_android_os_Debug(JNIEnv* env);
Jesse Hallb12249b2016-12-12 12:53:02 -0800178extern int register_android_os_GraphicsEnvironment(JNIEnv* env);
Yifan Hongbb0bd002017-11-14 16:14:04 -0800179extern int register_android_os_HidlSupport(JNIEnv* env);
Andreas Huberc0b6c532016-08-15 09:25:02 -0700180extern int register_android_os_HwBinder(JNIEnv *env);
Andreas Huberdc263212016-08-25 11:21:21 -0700181extern int register_android_os_HwBlob(JNIEnv *env);
Andreas Huberc0b6c532016-08-15 09:25:02 -0700182extern int register_android_os_HwParcel(JNIEnv *env);
183extern int register_android_os_HwRemoteBinder(JNIEnv *env);
Nirav Atre9850dd92018-07-24 17:03:44 -0700184extern int register_android_os_NativeHandle(JNIEnv *env);
Christopher Tatefa9e7c02010-05-06 12:07:10 -0700185extern int register_android_os_MessageQueue(JNIEnv* env);
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -0800186extern int register_android_os_Parcel(JNIEnv* env);
Stephen Smalleyc07fca32012-01-13 08:31:39 -0500187extern int register_android_os_SELinux(JNIEnv* env);
Yifan Hongbecc56d2017-04-05 14:42:05 -0700188extern int register_android_os_VintfObject(JNIEnv *env);
Yifan Hong1bda6732017-04-26 11:38:01 -0700189extern int register_android_os_VintfRuntimeInfo(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190extern int register_android_os_SystemProperties(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191extern int register_android_os_SystemClock(JNIEnv* env);
Jeff Brown481c1572012-03-09 14:41:15 -0800192extern int register_android_os_Trace(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193extern int register_android_os_FileObserver(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194extern int register_android_os_UEventObserver(JNIEnv* env);
195extern int register_android_os_MemoryFile(JNIEnv* env);
John Reckdea6a022017-05-25 17:09:33 -0700196extern int register_android_os_SharedMemory(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197extern int register_android_net_LocalSocketImpl(JNIEnv* env);
198extern int register_android_net_NetworkUtils(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199extern int register_android_text_AndroidCharacter(JNIEnv *env);
Seigo Nonaka44a1df22017-08-31 18:22:38 -0700200extern int register_android_text_Hyphenator(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201extern int register_android_opengl_classes(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
Narayan Kamath29564cd2014-08-07 10:57:40 +0100203extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env);
Joe Onorato1cf58742009-06-12 11:06:24 -0700204extern int register_android_backup_BackupDataInput(JNIEnv *env);
Joe Onoratod2110db2009-05-19 13:41:21 -0700205extern int register_android_backup_BackupDataOutput(JNIEnv *env);
Joe Onorato06290a42009-06-18 20:10:37 -0700206extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
Joe Onorato4ababd92009-06-25 18:29:18 -0400207extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
Christopher Tate4a627c72011-04-01 14:43:32 -0700208extern int register_android_app_backup_FullBackup(JNIEnv *env);
Dimitry Ivanov4449ef52016-02-25 17:41:13 -0800209extern int register_android_app_Activity(JNIEnv *env);
Chet Haase9c1e23b2011-03-24 10:51:31 -0700210extern int register_android_app_ActivityThread(JNIEnv *env);
Dianne Hackborn69969e42010-05-04 11:40:40 -0700211extern int register_android_app_NativeActivity(JNIEnv *env);
Jeff Browncbad9762012-09-04 21:57:59 -0700212extern int register_android_media_RemoteDisplay(JNIEnv *env);
Przemyslaw Szczepaniak8a7c1602015-11-03 09:47:56 +0000213extern int register_android_util_jar_StrictJarFile(JNIEnv* env);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700214extern int register_android_view_InputChannel(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700215extern int register_android_view_InputDevice(JNIEnv* env);
Jeff Brown32cbc38552011-12-01 14:01:49 -0800216extern int register_android_view_InputEventReceiver(JNIEnv* env);
Jeff Brownc28867a2013-03-26 15:42:39 -0700217extern int register_android_view_InputEventSender(JNIEnv* env);
Michael Wrighta44dd262013-04-10 21:12:00 -0700218extern int register_android_view_InputQueue(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700219extern int register_android_view_KeyCharacterMap(JNIEnv *env);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700220extern int register_android_view_KeyEvent(JNIEnv* env);
221extern int register_android_view_MotionEvent(JNIEnv* env);
Jeff Brown2352b972011-04-12 22:39:53 -0700222extern int register_android_view_PointerIcon(JNIEnv* env);
Jeff Brown2ed24622011-03-14 19:39:54 -0700223extern int register_android_view_VelocityTracker(JNIEnv* env);
Kenny Root02c87302010-07-01 08:10:18 -0700224extern int register_android_content_res_ObbScanner(JNIEnv* env);
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700225extern int register_android_content_res_Configuration(JNIEnv* env);
Chet Haase6e0ecb42010-11-03 19:41:18 -0700226extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
Bo Zhu09856132018-04-01 12:24:09 -0700227extern int register_android_security_Scrypt(JNIEnv *env);
Kenny Root66269ea2011-07-12 14:14:01 -0700228extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
Svet Ganov8455ba22019-01-02 13:05:56 -0800229extern int register_com_android_internal_os_AtomicDirectory(JNIEnv *env);
Narayan Kamathf9419f02017-06-15 11:35:38 +0100230extern int register_com_android_internal_os_ClassLoaderFactory(JNIEnv* env);
Daichi Hirono878e86f2016-10-31 09:33:30 +0900231extern int register_com_android_internal_os_FuseAppLoop(JNIEnv* env);
Narayan Kamath973b4662014-03-31 13:41:26 +0100232extern int register_com_android_internal_os_Zygote(JNIEnv *env);
Jesse Hall1fe1dc02017-07-06 15:30:39 -0700233extern int register_com_android_internal_os_ZygoteInit(JNIEnv *env);
John Reck9fa40712014-05-09 15:26:59 -0700234extern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235
Roland Levillain7b098c82019-02-04 15:48:09 +0000236// Namespace for Android Runtime flags applied during boot time.
237static const char* RUNTIME_NATIVE_BOOT_NAMESPACE = "runtime_native_boot";
Roland Levillain72b16f02019-02-19 18:09:58 +0000238// Feature flag name to enable/disable generational garbage collection in ART's
239// Concurrent Copying (CC) garbage collector.
240static const char* ENABLE_GENERATIONAL_CC = "enable_generational_cc";
241// Runtime option enabling generational garbage collection in ART's Concurrent
242// Copying (CC) garbage collector.
243static const char* kGenerationalCCRuntimeOption = "-Xgc:generational_cc";
244// Runtime option disabling generational garbage collection in ART's Concurrent
245// Copying (CC) garbage collector.
246static const char* kNoGenerationalCCRuntimeOption = "-Xgc:nogenerational_cc";
Roland Levillain7b098c82019-02-04 15:48:09 +0000247
Nicolas Geoffray7a6a0da2019-02-25 13:26:31 +0000248// Feature flag name for running the JIT in Zygote experiment, b/119800099.
249static const char* ENABLE_APEX_IMAGE = "enable_apex_image";
250// Flag to pass to the runtime when using the apex image.
251static const char* kApexImageOption = "-Ximage:/system/framework/apex.art";
252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253static AndroidRuntime* gCurRuntime = NULL;
254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255/*
256 * Code written in the Java Programming Language calls here from main().
257 */
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700258static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259{
260 gCurRuntime->onStarted();
261}
262
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800263static void com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264{
265 gCurRuntime->onZygoteInit();
266}
267
Jeff Brown4280c4a2012-03-15 17:48:02 -0700268static void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIEnv* env,
269 jobject clazz, jboolean exitWithoutCleanup)
270{
271 gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup);
272}
273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274/*
275 * JNI registration.
276 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277
278int register_com_android_internal_os_RuntimeInit(JNIEnv* env)
279{
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800280 const JNINativeMethod methods[] = {
281 { "nativeFinishInit", "()V",
282 (void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
283 { "nativeSetExitWithoutCleanup", "(Z)V",
284 (void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
285 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800287 methods, NELEM(methods));
288}
289
Jesse Hall1fe1dc02017-07-06 15:30:39 -0700290int register_com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv* env)
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800291{
292 const JNINativeMethod methods[] = {
293 { "nativeZygoteInit", "()V",
294 (void*) com_android_internal_os_ZygoteInit_nativeZygoteInit },
295 };
296 return jniRegisterNativeMethods(env, "com/android/internal/os/ZygoteInit",
297 methods, NELEM(methods));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298}
299
300// ----------------------------------------------------------------------
301
Andreas Huber9ae000c2014-02-13 17:22:33 +0000302/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
303
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000304AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) :
305 mExitWithoutCleanup(false),
306 mArgBlockStart(argBlockStart),
307 mArgBlockLength(argBlockLength)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700309 SkGraphics::Init();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310
311 // Pre-allocate enough space to hold a fair number of options.
312 mOptions.setCapacity(20);
313
314 assert(gCurRuntime == NULL); // one per process
315 gCurRuntime = this;
316}
317
318AndroidRuntime::~AndroidRuntime()
319{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320}
321
Andreas Huber9ae000c2014-02-13 17:22:33 +0000322/*
323 * Register native methods using JNI.
324 */
325/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
326 const char* className, const JNINativeMethod* gMethods, int numMethods)
327{
328 return jniRegisterNativeMethods(env, className, gMethods, numMethods);
329}
330
Dmitriy Filchenkof5b6e552016-07-18 16:00:35 -0700331void AndroidRuntime::setArgv0(const char* argv0, bool setProcName) {
332 if (setProcName) {
333 int len = strlen(argv0);
334 if (len < 15) {
335 pthread_setname_np(pthread_self(), argv0);
336 } else {
337 pthread_setname_np(pthread_self(), argv0 + len - 15);
338 }
339 }
Jeff Brown00c0cd42014-09-10 16:48:46 -0700340 memset(mArgBlockStart, 0, mArgBlockLength);
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000341 strlcpy(mArgBlockStart, argv0, mArgBlockLength);
342}
343
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100344status_t AndroidRuntime::callMain(const String8& className, jclass clazz,
345 const Vector<String8>& args)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346{
347 JNIEnv* env;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800348 jmethodID methodId;
349
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100350 ALOGD("Calling main entry %s", className.string());
Dianne Hackborn08e60f22010-09-01 18:17:17 -0700351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 env = getJNIEnv();
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700353 if (clazz == NULL || env == NULL) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 return UNKNOWN_ERROR;
355 }
356
357 methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
358 if (methodId == NULL) {
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100359 ALOGE("ERROR: could not find method %s.main(String[])\n", className.string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 return UNKNOWN_ERROR;
361 }
362
363 /*
364 * We want to call main() with a String array with our arguments in it.
365 * Create an array and populate it.
366 */
367 jclass stringClass;
368 jobjectArray strArray;
369
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100370 const size_t numArgs = args.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 stringClass = env->FindClass("java/lang/String");
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100372 strArray = env->NewObjectArray(numArgs, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100374 for (size_t i = 0; i < numArgs; i++) {
375 jstring argStr = env->NewStringUTF(args[i].string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 env->SetObjectArrayElement(strArray, i, argStr);
377 }
378
379 env->CallStaticVoidMethod(clazz, methodId, strArray);
380 return NO_ERROR;
381}
382
383/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 * The VM calls this through the "exit" hook.
385 */
386static void runtime_exit(int code)
387{
Jeff Brown4280c4a2012-03-15 17:48:02 -0700388 gCurRuntime->exit(code);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389}
390
391/*
392 * The VM calls this through the "vfprintf" hook.
393 *
394 * We ignore "fp" and just write the results to the log file.
395 */
396static void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
397{
398 LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
399}
400
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800401/**
402 * The VM calls this when mutex contention debugging is enabled to
403 * determine whether or not the blocked thread was a "sensitive thread"
404 * for user responsiveness/smoothess.
405 *
406 * Our policy for this is whether or not we're tracing any StrictMode
407 * events on this thread (which we might've inherited via Binder calls
408 * into us)
409 */
410static bool runtime_isSensitiveThread() {
411 IPCThreadState* state = IPCThreadState::selfOrNull();
412 return state && state->getStrictModePolicy() != 0;
413}
414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415static int hasDir(const char* dir)
416{
417 struct stat s;
418 int res = stat(dir, &s);
419 if (res == 0) {
420 return S_ISDIR(s.st_mode);
421 }
422 return 0;
423}
424
Andreas Gampe995c62d2014-11-14 16:15:17 -0800425static bool hasFile(const char* file) {
426 struct stat s;
427 int res = stat(file, &s);
428 if (res == 0) {
429 return S_ISREG(s.st_mode);
430 }
431 return false;
432}
433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434/*
Narayan Kamathbf882052015-08-11 15:40:34 +0100435 * Read the persistent locale. Inspects the following system properties
436 * (in order) and returns the first non-empty property in the list :
437 *
438 * (1) persist.sys.locale
439 * (2) persist.sys.language/country/localevar (country and localevar are
440 * inspected iff. language is non-empty.
441 * (3) ro.product.locale
442 * (4) ro.product.locale.language/region
443 *
444 * Note that we need to inspect persist.sys.language/country/localevar to
445 * preserve language settings for devices that are upgrading from Lollipop
446 * to M. The same goes for ro.product.locale.language/region as well.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447 */
Narayan Kamathbf882052015-08-11 15:40:34 +0100448const std::string readLocale()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449{
Tom Cherry93099e42017-10-11 13:44:21 -0700450 const std::string locale = GetProperty("persist.sys.locale", "");
Narayan Kamathbf882052015-08-11 15:40:34 +0100451 if (!locale.empty()) {
452 return locale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 }
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000454
Tom Cherry93099e42017-10-11 13:44:21 -0700455 const std::string language = GetProperty("persist.sys.language", "");
Narayan Kamathbf882052015-08-11 15:40:34 +0100456 if (!language.empty()) {
Tom Cherry93099e42017-10-11 13:44:21 -0700457 const std::string country = GetProperty("persist.sys.country", "");
458 const std::string variant = GetProperty("persist.sys.localevar", "");
Narayan Kamathbf882052015-08-11 15:40:34 +0100459
460 std::string out = language;
461 if (!country.empty()) {
462 out = out + "-" + country;
463 }
464
465 if (!variant.empty()) {
466 out = out + "-" + variant;
467 }
468
469 return out;
470 }
471
Tom Cherry93099e42017-10-11 13:44:21 -0700472 const std::string productLocale = GetProperty("ro.product.locale", "");
Narayan Kamathbf882052015-08-11 15:40:34 +0100473 if (!productLocale.empty()) {
474 return productLocale;
475 }
476
477 // If persist.sys.locale and ro.product.locale are missing,
478 // construct a locale value from the individual locale components.
Tom Cherry93099e42017-10-11 13:44:21 -0700479 const std::string productLanguage = GetProperty("ro.product.locale.language", "en");
480 const std::string productRegion = GetProperty("ro.product.locale.region", "US");
Narayan Kamathbf882052015-08-11 15:40:34 +0100481
482 return productLanguage + "-" + productRegion;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483}
484
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700485void AndroidRuntime::addOption(const char* optionString, void* extraInfo)
486{
487 JavaVMOption opt;
488 opt.optionString = optionString;
489 opt.extraInfo = extraInfo;
490 mOptions.add(opt);
491}
492
Andy McFaddenf70188a2009-03-31 15:52:13 -0700493/*
Andy McFaddene4d81f22010-07-14 16:02:20 -0700494 * Parse a property containing space-separated options that should be
495 * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
496 *
497 * This will cut up "extraOptsBuf" as we chop it into individual options.
498 *
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800499 * If "quotingArg" is non-null, it is passed before each extra option in mOptions.
500 *
Andy McFaddene4d81f22010-07-14 16:02:20 -0700501 * Adds the strings, if any, to mOptions.
502 */
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800503void AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg)
Andy McFaddene4d81f22010-07-14 16:02:20 -0700504{
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800505 char* start = extraOptsBuf;
506 char* end = NULL;
Andy McFaddene4d81f22010-07-14 16:02:20 -0700507 while (*start != '\0') {
508 while (*start == ' ') /* skip leading whitespace */
509 start++;
510 if (*start == '\0') /* was trailing ws, bail */
511 break;
512
513 end = start+1;
514 while (*end != ' ' && *end != '\0') /* find end of token */
515 end++;
516 if (*end == ' ')
517 *end++ = '\0'; /* mark end, advance to indicate more */
518
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800519 if (quotingArg != NULL) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700520 addOption(quotingArg);
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800521 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700522 addOption(start);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700523 start = end;
524 }
525}
526
527/*
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700528 * Reads a "property" into "buffer" with a default of "defaultArg". If
529 * the property is non-empty, it is treated as a runtime option such
530 * as "-Xmx32m".
531 *
532 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
533 *
534 * If an argument is found, it is added to mOptions.
535 *
536 * If an option is found, it is added to mOptions and true is
537 * returned. Otherwise false is returned.
538 */
539bool AndroidRuntime::parseRuntimeOption(const char* property,
540 char* buffer,
541 const char* runtimeArg,
542 const char* defaultArg)
543{
544 strcpy(buffer, runtimeArg);
545 size_t runtimeArgLen = strlen(runtimeArg);
546 property_get(property, buffer+runtimeArgLen, defaultArg);
547 if (buffer[runtimeArgLen] == '\0') {
548 return false;
549 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700550 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700551 return true;
552}
553
554/*
555 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700556 * is treated as a dex2oat compiler option that should be
Nicolas Geoffraybe7b0d12017-04-25 12:29:07 +0100557 * passed as a quoted option, e.g. "-Ximage-compiler-option --compiler-filter=assume-verified".
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700558 *
559 * The "compilerArg" is a prefix for the option such as "--compiler-filter=".
560 *
561 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
562 *
563 * If an option is found, it is added to mOptions and true is
564 * returned. Otherwise false is returned.
565 */
566bool AndroidRuntime::parseCompilerOption(const char* property,
567 char* buffer,
568 const char* compilerArg,
569 const char* quotingArg)
570{
571 strcpy(buffer, compilerArg);
572 size_t compilerArgLen = strlen(compilerArg);
573 property_get(property, buffer+compilerArgLen, "");
574 if (buffer[compilerArgLen] == '\0') {
575 return false;
576 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700577 addOption(quotingArg);
578 addOption(buffer);
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700579 return true;
580}
581
582/*
583 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700584 * is treated as a dex2oat compiler runtime option that should be
585 * passed as a quoted option, e.g. "-Ximage-compiler-option
586 * --runtime-arg -Ximage-compiler-option -Xmx32m".
587 *
588 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
589 *
590 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
591 *
592 * If an option is found, it is added to mOptions and true is
593 * returned. Otherwise false is returned.
594 */
595bool AndroidRuntime::parseCompilerRuntimeOption(const char* property,
596 char* buffer,
597 const char* runtimeArg,
598 const char* quotingArg)
599{
600 strcpy(buffer, runtimeArg);
601 size_t runtimeArgLen = strlen(runtimeArg);
602 property_get(property, buffer+runtimeArgLen, "");
603 if (buffer[runtimeArgLen] == '\0') {
604 return false;
605 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700606 addOption(quotingArg);
607 addOption("--runtime-arg");
608 addOption(quotingArg);
609 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700610 return true;
611}
612
613/*
Andy McFaddenf70188a2009-03-31 15:52:13 -0700614 * Start the Dalvik Virtual Machine.
615 *
616 * Various arguments, most determined by system properties, are passed in.
617 * The "mOptions" vector is updated.
618 *
Dave Allison07a1e232014-03-14 08:54:33 -0700619 * CAUTION: when adding options in here, be careful not to put the
620 * char buffer inside a nested scope. Adding the buffer to the
621 * options using mOptions.add() does not copy the buffer, so if the
622 * buffer goes out of scope the option may be overwritten. It's best
623 * to put the buffer at the top of the function so that it is more
624 * unlikely that someone will surround it in a scope at a later time
625 * and thus introduce a bug.
626 *
Andy McFaddenf70188a2009-03-31 15:52:13 -0700627 * Returns 0 on success.
628 */
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200629int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 JavaVMInitArgs initArgs;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 char propBuf[PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro38cfa8c2010-12-07 16:48:29 -0800634 char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700635 char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro8cdf27c2011-01-19 12:33:12 -0800636 char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700637 char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
638 char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800639 char usejitOptsBuf[sizeof("-Xusejit:")-1 + PROPERTY_VALUE_MAX];
Nicolas Geoffray24934a92018-05-16 17:22:37 +0100640 char jitpthreadpriorityOptsBuf[sizeof("-Xjitpthreadpriority:")-1 + PROPERTY_VALUE_MAX];
Nicolas Geoffraycdf1dff2015-11-19 13:48:35 +0000641 char jitmaxsizeOptsBuf[sizeof("-Xjitmaxsize:")-1 + PROPERTY_VALUE_MAX];
642 char jitinitialsizeOptsBuf[sizeof("-Xjitinitialsize:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800643 char jitthresholdOptsBuf[sizeof("-Xjitthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravledb4a79a2015-12-23 18:55:08 +0200644 char useJitProfilesOptsBuf[sizeof("-Xjitsaveprofilinginfo:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle0de80b92016-04-12 14:12:04 +0100645 char jitprithreadweightOptBuf[sizeof("-Xjitprithreadweight:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle8d74de52016-04-27 14:12:00 +0100646 char jittransitionweightOptBuf[sizeof("-Xjittransitionweight:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier5eee0042017-06-07 17:34:22 -0700647 char hotstartupsamplesOptsBuf[sizeof("-Xps-hot-startup-method-samples:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartiercd0caf52017-10-13 11:29:27 -0700648 char madviseRandomOptsBuf[sizeof("-XX:MadviseRandomAccess:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier7e4fdec2013-12-02 15:46:51 -0800649 char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700650 char backgroundgcOptsBuf[sizeof("-XX:BackgroundGC=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700651 char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartierebc3b4c2017-10-15 21:13:28 -0700652 char foregroundHeapGrowthMultiplierOptsBuf[
653 sizeof("-XX:ForegroundHeapGrowthMultiplier=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee324ba02015-03-31 16:15:17 -0700654 char cachePruneBuf[sizeof("-Xzygote-max-boot-retry=")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700655 char dex2oatXmsImageFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
656 char dex2oatXmxImageFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
657 char dex2oatXmsFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
658 char dex2oatXmxFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700659 char dex2oatCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
660 char dex2oatImageCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee0352382015-03-30 18:43:39 -0700661 char dex2oatThreadsBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
662 char dex2oatThreadsImageBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
Andreas Gampe605cca12015-04-02 23:12:56 -0700663 char dex2oat_isa_variant_key[PROPERTY_KEY_MAX];
664 char dex2oat_isa_variant[sizeof("--instruction-set-variant=") -1 + PROPERTY_VALUE_MAX];
665 char dex2oat_isa_features_key[PROPERTY_KEY_MAX];
666 char dex2oat_isa_features[sizeof("--instruction-set-features=") -1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800667 char dex2oatFlagsBuf[PROPERTY_VALUE_MAX];
668 char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX];
Andy McFaddene4d81f22010-07-14 16:02:20 -0700669 char extraOptsBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700670 char voldDecryptBuf[PROPERTY_VALUE_MAX];
Ben Cheng52b0e732009-06-19 13:31:12 -0700671 enum {
672 kEMDefault,
673 kEMIntPortable,
674 kEMIntFast,
Ben Cheng52b0e732009-06-19 13:31:12 -0700675 kEMJitCompiler,
Ben Cheng52b0e732009-06-19 13:31:12 -0700676 } executionMode = kEMDefault;
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000677 char localeOption[sizeof("-Duser.locale=") + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700678 char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle01db9162014-08-07 14:45:53 +0100679 char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX];
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700680 char cpuAbiListBuf[sizeof("--cpu-abilist=") + PROPERTY_VALUE_MAX];
Andreas Gampe98f406f2015-06-22 21:09:36 -0700681 char methodTraceFileBuf[sizeof("-Xmethod-trace-file:") + PROPERTY_VALUE_MAX];
682 char methodTraceFileSizeBuf[sizeof("-Xmethod-trace-file-size:") + PROPERTY_VALUE_MAX];
Tom Cherry93099e42017-10-11 13:44:21 -0700683 std::string fingerprintBuf;
Alex Lightfffb2732017-11-20 13:01:01 -0800684 char jdwpProviderBuf[sizeof("-XjdwpProvider:") - 1 + PROPERTY_VALUE_MAX];
Nicolas Geoffray79eeb982019-02-14 15:55:20 +0000685 char bootImageBuf[sizeof("-Ximage:") - 1 + PROPERTY_VALUE_MAX];
686
Nicolas Geoffray7a6a0da2019-02-25 13:26:31 +0000687 std::string use_apex_image =
688 server_configurable_flags::GetServerConfigurableFlag(RUNTIME_NATIVE_BOOT_NAMESPACE,
689 ENABLE_APEX_IMAGE,
690 /*default_value=*/ "");
691 if (use_apex_image == "true") {
692 addOption(kApexImageOption);
693 ALOGI("Using Apex boot image: '%s'\n", kApexImageOption);
694 } else if (parseRuntimeOption("dalvik.vm.boot-image", bootImageBuf, "-Ximage:")) {
695 ALOGI("Using dalvik.vm.boot-image: '%s'\n", bootImageBuf);
696 } else {
697 ALOGI("Using default boot image");
Nicolas Geoffray79eeb982019-02-14 15:55:20 +0000698 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800699
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700700 bool checkJni = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701 property_get("dalvik.vm.checkjni", propBuf, "");
702 if (strcmp(propBuf, "true") == 0) {
703 checkJni = true;
704 } else if (strcmp(propBuf, "false") != 0) {
705 /* property is neither true nor false; fall back on kernel parameter */
706 property_get("ro.kernel.android.checkjni", propBuf, "");
707 if (propBuf[0] == '1') {
708 checkJni = true;
709 }
710 }
Joe Onorato82ba91d2017-04-27 16:18:05 -0700711 ALOGV("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700712 if (checkJni) {
713 /* extended JNI checking */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700714 addOption("-Xcheck:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700715
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700716 /* with -Xcheck:jni, this provides a JNI function call trace */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700717 //addOption("-verbose:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700718 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719
720 property_get("dalvik.vm.execution-mode", propBuf, "");
721 if (strcmp(propBuf, "int:portable") == 0) {
722 executionMode = kEMIntPortable;
723 } else if (strcmp(propBuf, "int:fast") == 0) {
724 executionMode = kEMIntFast;
Ben Cheng52b0e732009-06-19 13:31:12 -0700725 } else if (strcmp(propBuf, "int:jit") == 0) {
726 executionMode = kEMJitCompiler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 }
728
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729 strcpy(jniOptsBuf, "-Xjniopts:");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700730 if (parseRuntimeOption("dalvik.vm.jniopts", jniOptsBuf, "-Xjniopts:")) {
731 ALOGI("JNI options: '%s'\n", jniOptsBuf);
732 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800734 /* route exit() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700735 addOption("exit", (void*) runtime_exit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736
737 /* route fprintf() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700738 addOption("vfprintf", (void*) runtime_vfprintf);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800740 /* register the framework-specific "is sensitive thread" hook */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700741 addOption("sensitiveThread", (void*) runtime_isSensitiveThread);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800742
743 /* enable verbose; standard options are { jni, gc, class } */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700744 //addOption("-verbose:jni");
745 addOption("-verbose:gc");
746 //addOption("-verbose:class");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747
Carl Shapiro9e4c8842010-12-08 12:14:46 -0800748 /*
749 * The default starting and maximum size of the heap. Larger
750 * values should be specified in a product property override.
751 */
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700752 parseRuntimeOption("dalvik.vm.heapstartsize", heapstartsizeOptsBuf, "-Xms", "4m");
753 parseRuntimeOption("dalvik.vm.heapsize", heapsizeOptsBuf, "-Xmx", "16m");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700755 parseRuntimeOption("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
756 parseRuntimeOption("dalvik.vm.heapminfree", heapminfreeOptsBuf, "-XX:HeapMinFree=");
757 parseRuntimeOption("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf, "-XX:HeapMaxFree=");
758 parseRuntimeOption("dalvik.vm.heaptargetutilization",
759 heaptargetutilizationOptsBuf,
760 "-XX:HeapTargetUtilization=");
Ian Rogers53250102012-09-23 16:38:03 -0700761
Mathieu Chartierebc3b4c2017-10-15 21:13:28 -0700762 /* Foreground heap growth multiplier option */
763 parseRuntimeOption("dalvik.vm.foreground-heap-growth-multiplier",
764 foregroundHeapGrowthMultiplierOptsBuf,
765 "-XX:ForegroundHeapGrowthMultiplier=");
766
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800767 /*
768 * JIT related options.
769 */
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700770 parseRuntimeOption("dalvik.vm.usejit", usejitOptsBuf, "-Xusejit:");
Nicolas Geoffraycdf1dff2015-11-19 13:48:35 +0000771 parseRuntimeOption("dalvik.vm.jitmaxsize", jitmaxsizeOptsBuf, "-Xjitmaxsize:");
772 parseRuntimeOption("dalvik.vm.jitinitialsize", jitinitialsizeOptsBuf, "-Xjitinitialsize:");
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700773 parseRuntimeOption("dalvik.vm.jitthreshold", jitthresholdOptsBuf, "-Xjitthreshold:");
Nicolas Geoffray24934a92018-05-16 17:22:37 +0100774 parseRuntimeOption("dalvik.vm.jitpthreadpriority",
775 jitpthreadpriorityOptsBuf,
776 "-Xjitpthreadpriority:");
Calin Juravledb4a79a2015-12-23 18:55:08 +0200777 property_get("dalvik.vm.usejitprofiles", useJitProfilesOptsBuf, "");
778 if (strcmp(useJitProfilesOptsBuf, "true") == 0) {
779 addOption("-Xjitsaveprofilinginfo");
780 }
Calin Juravle8d74de52016-04-27 14:12:00 +0100781
Calin Juravle0de80b92016-04-12 14:12:04 +0100782 parseRuntimeOption("dalvik.vm.jitprithreadweight",
783 jitprithreadweightOptBuf,
784 "-Xjitprithreadweight:");
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800785
Calin Juravle8d74de52016-04-27 14:12:00 +0100786 parseRuntimeOption("dalvik.vm.jittransitionweight",
787 jittransitionweightOptBuf,
788 "-Xjittransitionweight:");
789
Calin Juravle62cd4bb2018-05-08 12:42:30 -0700790 property_get("dalvik.vm.profilebootimage", propBuf, "");
791 if (strcmp(propBuf, "true") == 0) {
792 addOption("-Xps-profile-boot-class-path");
793 addOption("-Xps-profile-aot-code");
794 }
795
Mathieu Chartier5eee0042017-06-07 17:34:22 -0700796 /*
Mathieu Chartiercd0caf52017-10-13 11:29:27 -0700797 * Madvise related options.
798 */
799 parseRuntimeOption("dalvik.vm.madvise-random", madviseRandomOptsBuf, "-XX:MadviseRandomAccess:");
800
801 /*
Mathieu Chartier5eee0042017-06-07 17:34:22 -0700802 * Profile related options.
803 */
804 parseRuntimeOption("dalvik.vm.hot-startup-method-samples", hotstartupsamplesOptsBuf,
805 "-Xps-hot-startup-method-samples:");
806
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700807 property_get("ro.config.low_ram", propBuf, "");
808 if (strcmp(propBuf, "true") == 0) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700809 addOption("-XX:LowMemoryMode");
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700810 }
811
Roland Levillain72b16f02019-02-19 18:09:58 +0000812 /*
813 * Garbage-collection related options.
814 */
815 parseRuntimeOption("dalvik.vm.gctype", gctypeOptsBuf, "-Xgc:");
816
817 // If it set, honor the "enable_generational_cc" device configuration;
818 // otherwise, let the runtime use its default behavior.
819 std::string enable_generational_cc =
820 server_configurable_flags::GetServerConfigurableFlag(RUNTIME_NATIVE_BOOT_NAMESPACE,
821 ENABLE_GENERATIONAL_CC,
822 /*default_value=*/ "");
823 if (enable_generational_cc == "true") {
824 addOption(kGenerationalCCRuntimeOption);
825 } else if (enable_generational_cc == "false") {
826 addOption(kNoGenerationalCCRuntimeOption);
Mathieu Chartierd2a975a2019-01-28 11:11:25 -0800827 }
828
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700829 parseRuntimeOption("dalvik.vm.backgroundgctype", backgroundgcOptsBuf, "-XX:BackgroundGC=");
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700830
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200831 /*
832 * Enable debugging only for apps forked from zygote.
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200833 */
834 if (zygote) {
Alex Lightc50928b2018-01-31 16:47:29 +0000835 // Set the JDWP provider and required arguments. By default let the runtime choose how JDWP is
836 // implemented. When this is not set the runtime defaults to not allowing JDWP.
Alex Lightfffb2732017-11-20 13:01:01 -0800837 addOption("-XjdwpOptions:suspend=n,server=y");
Alex Lightc50928b2018-01-31 16:47:29 +0000838 parseRuntimeOption("dalvik.vm.jdwp-provider",
839 jdwpProviderBuf,
840 "-XjdwpProvider:",
841 "default");
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200842 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800843
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700844 parseRuntimeOption("dalvik.vm.lockprof.threshold",
845 lockProfThresholdBuf,
846 "-Xlockprofthreshold:");
Carl Shapirod8f3ec62010-04-12 16:31:59 -0700847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 if (executionMode == kEMIntPortable) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700849 addOption("-Xint:portable");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 } else if (executionMode == kEMIntFast) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700851 addOption("-Xint:fast");
Ben Cheng52b0e732009-06-19 13:31:12 -0700852 } else if (executionMode == kEMJitCompiler) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700853 addOption("-Xint:jit");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 }
Andy McFaddene2b23e12009-04-03 11:09:46 -0700855
Andreas Gampe08b2d582014-12-18 14:39:22 -0800856 // If we are booting without the real /data, don't spend time compiling.
857 property_get("vold.decrypt", voldDecryptBuf, "");
858 bool skip_compilation = ((strcmp(voldDecryptBuf, "trigger_restart_min_framework") == 0) ||
859 (strcmp(voldDecryptBuf, "1") == 0));
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800860
Andreas Gampe08b2d582014-12-18 14:39:22 -0800861 // Extra options for boot.art/boot.oat image generation.
862 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xms", dex2oatXmsImageFlagsBuf,
863 "-Xms", "-Ximage-compiler-option");
864 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xmx", dex2oatXmxImageFlagsBuf,
865 "-Xmx", "-Ximage-compiler-option");
866 if (skip_compilation) {
Brian Carlstromce5bbbe2014-07-30 15:13:17 -0700867 addOption("-Ximage-compiler-option");
Nicolas Geoffraybe7b0d12017-04-25 12:29:07 +0100868 addOption("--compiler-filter=assume-verified");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800869 } else {
870 parseCompilerOption("dalvik.vm.image-dex2oat-filter", dex2oatImageCompilerFilterBuf,
871 "--compiler-filter=", "-Ximage-compiler-option");
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800872 }
873
Mathieu Chartierf99e70e2017-06-30 11:47:38 -0700874 // If there is a boot profile, it takes precedence over the image and preloaded classes.
875 if (hasFile("/system/etc/boot-image.prof")) {
Andreas Gampe08b2d582014-12-18 14:39:22 -0800876 addOption("-Ximage-compiler-option");
Mathieu Chartierf99e70e2017-06-30 11:47:38 -0700877 addOption("--profile-file=/system/etc/boot-image.prof");
878 addOption("-Ximage-compiler-option");
879 addOption("--compiler-filter=speed-profile");
880 } else {
881 // Make sure there is a preloaded-classes file.
882 if (!hasFile("/system/etc/preloaded-classes")) {
883 ALOGE("Missing preloaded-classes file, /system/etc/preloaded-classes not found: %s\n",
884 strerror(errno));
885 return -1;
886 }
887 addOption("-Ximage-compiler-option");
888 addOption("--image-classes=/system/etc/preloaded-classes");
889
Jeff Hao37641ae2017-07-31 13:35:01 -0700890 // If there is a dirty-image-objects file, push it.
891 if (hasFile("/system/etc/dirty-image-objects")) {
892 addOption("-Ximage-compiler-option");
893 addOption("--dirty-image-objects=/system/etc/dirty-image-objects");
894 }
Andreas Gampe08b2d582014-12-18 14:39:22 -0800895 }
896
897 property_get("dalvik.vm.image-dex2oat-flags", dex2oatImageFlagsBuf, "");
898 parseExtraOpts(dex2oatImageFlagsBuf, "-Ximage-compiler-option");
899
900 // Extra options for DexClassLoader.
901 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xms", dex2oatXmsFlagsBuf,
902 "-Xms", "-Xcompiler-option");
903 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xmx", dex2oatXmxFlagsBuf,
904 "-Xmx", "-Xcompiler-option");
905 if (skip_compilation) {
906 addOption("-Xcompiler-option");
Nicolas Geoffraybe7b0d12017-04-25 12:29:07 +0100907 addOption("--compiler-filter=assume-verified");
neo.chae155118f2015-01-07 15:32:15 +0900908
909 // We skip compilation when a minimal runtime is brought up for decryption. In that case
910 // /data is temporarily backed by a tmpfs, which is usually small.
911 // If the system image contains prebuilts, they will be relocated into the tmpfs. In this
912 // specific situation it is acceptable to *not* relocate and run out of the prebuilts
913 // directly instead.
914 addOption("--runtime-arg");
915 addOption("-Xnorelocate");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800916 } else {
917 parseCompilerOption("dalvik.vm.dex2oat-filter", dex2oatCompilerFilterBuf,
918 "--compiler-filter=", "-Xcompiler-option");
919 }
Andreas Gampee0352382015-03-30 18:43:39 -0700920 parseCompilerOption("dalvik.vm.dex2oat-threads", dex2oatThreadsBuf, "-j", "-Xcompiler-option");
921 parseCompilerOption("dalvik.vm.image-dex2oat-threads", dex2oatThreadsImageBuf, "-j",
922 "-Ximage-compiler-option");
Andreas Gampe605cca12015-04-02 23:12:56 -0700923
924 // The runtime will compile a boot image, when necessary, not using installd. Thus, we need to
925 // pass the instruction-set-features/variant as an image-compiler-option.
Andreas Gampe605cca12015-04-02 23:12:56 -0700926 // Note: it is OK to reuse the buffer, as the values are exactly the same between
927 // * compiler-option, used for runtime compilation (DexClassLoader)
928 // * image-compiler-option, used for boot-image compilation on device
929
930 // Copy the variant.
Elliott Hughesa1194cb2018-03-23 11:27:04 -0700931 sprintf(dex2oat_isa_variant_key, "dalvik.vm.isa.%s.variant", ABI_STRING);
Andreas Gampe605cca12015-04-02 23:12:56 -0700932 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
933 "--instruction-set-variant=", "-Ximage-compiler-option");
934 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
935 "--instruction-set-variant=", "-Xcompiler-option");
936 // Copy the features.
Elliott Hughesa1194cb2018-03-23 11:27:04 -0700937 sprintf(dex2oat_isa_features_key, "dalvik.vm.isa.%s.features", ABI_STRING);
Andreas Gampe605cca12015-04-02 23:12:56 -0700938 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
939 "--instruction-set-features=", "-Ximage-compiler-option");
940 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
941 "--instruction-set-features=", "-Xcompiler-option");
942
943
Andreas Gampe08b2d582014-12-18 14:39:22 -0800944 property_get("dalvik.vm.dex2oat-flags", dex2oatFlagsBuf, "");
945 parseExtraOpts(dex2oatFlagsBuf, "-Xcompiler-option");
946
Andy McFaddene4d81f22010-07-14 16:02:20 -0700947 /* extra options; parse this late so it overrides others */
948 property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800949 parseExtraOpts(extraOptsBuf, NULL);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800951 /* Set the properties for locale */
952 {
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000953 strcpy(localeOption, "-Duser.locale=");
Narayan Kamathbf882052015-08-11 15:40:34 +0100954 const std::string locale = readLocale();
955 strncat(localeOption, locale.c_str(), PROPERTY_VALUE_MAX);
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000956 addOption(localeOption);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800957 }
958
Calin Juravle92290b82015-11-10 19:30:45 +0000959 // Trace files are stored in /data/misc/trace which is writable only in debug mode.
960 property_get("ro.debuggable", propBuf, "0");
961 if (strcmp(propBuf, "1") == 0) {
962 property_get("dalvik.vm.method-trace", propBuf, "false");
Andreas Gampe98f406f2015-06-22 21:09:36 -0700963 if (strcmp(propBuf, "true") == 0) {
Calin Juravle92290b82015-11-10 19:30:45 +0000964 addOption("-Xmethod-trace");
965 parseRuntimeOption("dalvik.vm.method-trace-file",
966 methodTraceFileBuf,
967 "-Xmethod-trace-file:");
968 parseRuntimeOption("dalvik.vm.method-trace-file-siz",
969 methodTraceFileSizeBuf,
970 "-Xmethod-trace-file-size:");
971 property_get("dalvik.vm.method-trace-stream", propBuf, "false");
972 if (strcmp(propBuf, "true") == 0) {
973 addOption("-Xmethod-trace-stream");
974 }
Andreas Gampe98f406f2015-06-22 21:09:36 -0700975 }
976 }
977
Andreas Gampe08b2d582014-12-18 14:39:22 -0800978 // Native bridge library. "0" means that native bridge is disabled.
Andreas Gampe14a1cd92018-06-07 09:42:02 -0700979 //
980 // Note: bridging is only enabled for the zygote. Other runs of
981 // app_process may not have the permissions to mount etc.
Andreas Gampe08b2d582014-12-18 14:39:22 -0800982 property_get("ro.dalvik.vm.native.bridge", propBuf, "");
983 if (propBuf[0] == '\0') {
984 ALOGW("ro.dalvik.vm.native.bridge is not expected to be empty");
Andreas Gampe14a1cd92018-06-07 09:42:02 -0700985 } else if (zygote && strcmp(propBuf, "0") != 0) {
Andreas Gampe08b2d582014-12-18 14:39:22 -0800986 snprintf(nativeBridgeLibrary, sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX,
987 "-XX:NativeBridge=%s", propBuf);
988 addOption(nativeBridgeLibrary);
Calin Juravlebe20ed42014-08-26 23:00:11 +0100989 }
Calin Juravle01db9162014-08-07 14:45:53 +0100990
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700991#if defined(__LP64__)
992 const char* cpu_abilist_property_name = "ro.product.cpu.abilist64";
993#else
994 const char* cpu_abilist_property_name = "ro.product.cpu.abilist32";
995#endif // defined(__LP64__)
996 property_get(cpu_abilist_property_name, propBuf, "");
997 if (propBuf[0] == '\0') {
998 ALOGE("%s is not expected to be empty", cpu_abilist_property_name);
999 return -1;
1000 }
1001 snprintf(cpuAbiListBuf, sizeof(cpuAbiListBuf), "--cpu-abilist=%s", propBuf);
1002 addOption(cpuAbiListBuf);
1003
Andreas Gampee324ba02015-03-31 16:15:17 -07001004 // Dalvik-cache pruning counter.
1005 parseRuntimeOption("dalvik.vm.zygote.max-boot-retry", cachePruneBuf,
1006 "-Xzygote-max-boot-retry=");
1007
Andreas Gampe27c39f12015-04-27 18:28:18 +00001008 /*
David Srbecky065075e2015-05-28 17:16:09 +01001009 * When running with debug.generate-debug-info, add --generate-debug-info to
1010 * the compiler options so that the boot image, if it is compiled on device,
1011 * will include native debugging information.
Andreas Gampe27c39f12015-04-27 18:28:18 +00001012 */
David Srbecky065075e2015-05-28 17:16:09 +01001013 property_get("debug.generate-debug-info", propBuf, "");
Andreas Gampe27c39f12015-04-27 18:28:18 +00001014 if (strcmp(propBuf, "true") == 0) {
1015 addOption("-Xcompiler-option");
David Srbecky065075e2015-05-28 17:16:09 +01001016 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +00001017 addOption("-Ximage-compiler-option");
David Srbecky065075e2015-05-28 17:16:09 +01001018 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +00001019 }
1020
David Srbecky3bb32502018-01-23 17:57:24 +00001021 // The mini-debug-info makes it possible to backtrace through JIT code.
1022 if (property_get_bool("dalvik.vm.minidebuginfo", 0)) {
1023 addOption("-Xcompiler-option");
1024 addOption("--generate-mini-debug-info");
1025 }
1026
Andreas Gampee6082502015-07-24 14:19:44 -07001027 /*
1028 * Retrieve the build fingerprint and provide it to the runtime. That way, ANR dumps will
1029 * contain the fingerprint and can be parsed.
Tom Cherry93099e42017-10-11 13:44:21 -07001030 * Fingerprints are potentially longer than PROPERTY_VALUE_MAX, so parseRuntimeOption() cannot
1031 * be used here.
1032 * Do not ever re-assign fingerprintBuf as its c_str() value is stored in mOptions.
Andreas Gampee6082502015-07-24 14:19:44 -07001033 */
Tom Cherry93099e42017-10-11 13:44:21 -07001034 std::string fingerprint = GetProperty("ro.build.fingerprint", "");
1035 if (!fingerprint.empty()) {
1036 fingerprintBuf = "-Xfingerprint:" + fingerprint;
1037 addOption(fingerprintBuf.c_str());
1038 }
Andreas Gampee6082502015-07-24 14:19:44 -07001039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001040 initArgs.version = JNI_VERSION_1_4;
1041 initArgs.options = mOptions.editArray();
1042 initArgs.nOptions = mOptions.size();
1043 initArgs.ignoreUnrecognized = JNI_FALSE;
1044
1045 /*
1046 * Initialize the VM.
1047 *
1048 * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread.
1049 * If this call succeeds, the VM is ready, and we can start issuing
1050 * JNI calls.
1051 */
Andy McFaddenf70188a2009-03-31 15:52:13 -07001052 if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001053 ALOGE("JNI_CreateJavaVM failed\n");
Dmitriy Ivanovff193d62014-09-30 15:10:48 -07001054 return -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001055 }
1056
Dmitriy Ivanovff193d62014-09-30 15:10:48 -07001057 return 0;
Andy McFaddenf70188a2009-03-31 15:52:13 -07001058}
1059
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001060char* AndroidRuntime::toSlashClassName(const char* className)
1061{
1062 char* result = strdup(className);
1063 for (char* cp = result; *cp != '\0'; cp++) {
1064 if (*cp == '.') {
1065 *cp = '/';
1066 }
1067 }
1068 return result;
1069}
1070
Mike Lockwood9ee5e7e2014-09-08 16:15:21 -07001071/** Create a Java string from an ASCII or Latin-1 string */
1072jstring AndroidRuntime::NewStringLatin1(JNIEnv* env, const char* bytes) {
1073 if (!bytes) return NULL;
1074 int length = strlen(bytes);
1075 jchar* buffer = (jchar *)alloca(length * sizeof(jchar));
1076 if (!buffer) return NULL;
1077 jchar* chp = buffer;
1078 for (int i = 0; i < length; i++) {
1079 *chp++ = *bytes++;
1080 }
1081 return env->NewString(buffer, length);
1082}
1083
1084
Andy McFaddenf70188a2009-03-31 15:52:13 -07001085/*
1086 * Start the Android runtime. This involves starting the virtual machine
1087 * and calling the "static void main(String[] args)" method in the class
1088 * named by "className".
Jeff Brownebed7d62011-05-16 17:08:42 -07001089 *
1090 * Passes the main function two arguments, the class name and the specified
1091 * options string.
Andy McFaddenf70188a2009-03-31 15:52:13 -07001092 */
Sebastien Hertz7a09b832015-08-10 18:55:34 +02001093void AndroidRuntime::start(const char* className, const Vector<String8>& options, bool zygote)
Andy McFaddenf70188a2009-03-31 15:52:13 -07001094{
Dianne Hackborn8e5aafe2014-10-27 18:04:10 -07001095 ALOGD(">>>>>> START %s uid %d <<<<<<\n",
1096 className != NULL ? className : "(unknown)", getuid());
Andy McFaddenf70188a2009-03-31 15:52:13 -07001097
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001098 static const String8 startSystemServer("start-system-server");
1099
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001100 /*
1101 * 'startSystemServer == true' means runtime is obsolete and not run from
Andy McFaddenf70188a2009-03-31 15:52:13 -07001102 * init.rc anymore, so we print out the boot start event here.
1103 */
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001104 for (size_t i = 0; i < options.size(); ++i) {
1105 if (options[i] == startSystemServer) {
1106 /* track our progress through the boot sequence */
1107 const int LOG_BOOT_PROGRESS_START = 3000;
1108 LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));
1109 }
Andy McFaddenf70188a2009-03-31 15:52:13 -07001110 }
1111
1112 const char* rootDir = getenv("ANDROID_ROOT");
1113 if (rootDir == NULL) {
1114 rootDir = "/system";
1115 if (!hasDir("/system")) {
Neil Fuller3ce4cce2018-11-23 19:00:32 +00001116 LOG_FATAL("No root directory specified, and /system does not exist.");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001117 return;
Andy McFaddenf70188a2009-03-31 15:52:13 -07001118 }
1119 setenv("ANDROID_ROOT", rootDir, 1);
1120 }
1121
Neil Fuller3ce4cce2018-11-23 19:00:32 +00001122 const char* runtimeRootDir = getenv("ANDROID_RUNTIME_ROOT");
1123 if (runtimeRootDir == NULL) {
1124 LOG_FATAL("No runtime directory specified with ANDROID_RUNTIME_ROOT environment variable.");
1125 return;
1126 }
1127
Neil Fullerb99050d2019-03-13 15:29:48 +00001128 const char* tzdataRootDir = getenv("ANDROID_TZDATA_ROOT");
1129 if (tzdataRootDir == NULL) {
1130 LOG_FATAL("No tz data directory specified with ANDROID_TZDATA_ROOT environment variable.");
1131 return;
1132 }
1133
Andy McFaddenf70188a2009-03-31 15:52:13 -07001134 //const char* kernelHack = getenv("LD_ASSUME_KERNEL");
Steve Block5baa3a62011-12-20 16:23:08 +00001135 //ALOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001136
1137 /* start the virtual machine */
Brian Carlstrom9f8203a2013-06-19 13:49:36 -07001138 JniInvocation jni_invocation;
1139 jni_invocation.Init(NULL);
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001140 JNIEnv* env;
Sebastien Hertz7a09b832015-08-10 18:55:34 +02001141 if (startVm(&mJavaVM, &env, zygote) != 0) {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001142 return;
1143 }
1144 onVmCreated(env);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 /*
1147 * Register android functions.
1148 */
1149 if (startReg(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001150 ALOGE("Unable to register all android natives\n");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001151 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 }
1153
1154 /*
1155 * We want to call main() with a String array with arguments in it.
Jeff Brownebed7d62011-05-16 17:08:42 -07001156 * At present we have two arguments, the class name and an option string.
1157 * Create an array to hold them.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001158 */
1159 jclass stringClass;
1160 jobjectArray strArray;
1161 jstring classNameStr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001162
1163 stringClass = env->FindClass("java/lang/String");
1164 assert(stringClass != NULL);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001165 strArray = env->NewObjectArray(options.size() + 1, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 assert(strArray != NULL);
1167 classNameStr = env->NewStringUTF(className);
1168 assert(classNameStr != NULL);
1169 env->SetObjectArrayElement(strArray, 0, classNameStr);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001170
1171 for (size_t i = 0; i < options.size(); ++i) {
1172 jstring optionsStr = env->NewStringUTF(options.itemAt(i).string());
1173 assert(optionsStr != NULL);
1174 env->SetObjectArrayElement(strArray, i + 1, optionsStr);
1175 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176
1177 /*
1178 * Start VM. This thread becomes the main thread of the VM, and will
1179 * not return until the VM exits.
1180 */
George Burgess IVd657a382017-06-20 23:53:29 -07001181 char* slashClassName = toSlashClassName(className != NULL ? className : "");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001182 jclass startClass = env->FindClass(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183 if (startClass == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001184 ALOGE("JavaVM unable to locate class '%s'\n", slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001185 /* keep going */
1186 } else {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001187 jmethodID startMeth = env->GetStaticMethodID(startClass, "main",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 "([Ljava/lang/String;)V");
1189 if (startMeth == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001190 ALOGE("JavaVM unable to find main() in '%s'\n", className);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001191 /* keep going */
1192 } else {
1193 env->CallStaticVoidMethod(startClass, startMeth, strArray);
1194
1195#if 0
1196 if (env->ExceptionCheck())
1197 threadExitUncaughtException(env);
1198#endif
1199 }
1200 }
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001201 free(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001202
Steve Block5baa3a62011-12-20 16:23:08 +00001203 ALOGD("Shutting down VM\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001204 if (mJavaVM->DetachCurrentThread() != JNI_OK)
Steve Block8564c8d2012-01-05 23:22:43 +00001205 ALOGW("Warning: unable to detach main thread\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001206 if (mJavaVM->DestroyJavaVM() != 0)
Steve Block8564c8d2012-01-05 23:22:43 +00001207 ALOGW("Warning: VM did not shut down cleanly\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208}
1209
Jeff Brown4280c4a2012-03-15 17:48:02 -07001210void AndroidRuntime::exit(int code)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211{
Jeff Brown4280c4a2012-03-15 17:48:02 -07001212 if (mExitWithoutCleanup) {
1213 ALOGI("VM exiting with result code %d, cleanup skipped.", code);
1214 ::_exit(code);
1215 } else {
1216 ALOGI("VM exiting with result code %d.", code);
1217 onExit(code);
1218 ::exit(code);
1219 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001220}
1221
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001222void AndroidRuntime::onVmCreated(JNIEnv* env)
1223{
1224 // If AndroidRuntime had anything to do here, we'd have done it in 'start'.
1225}
1226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001227/*
Andreas Huber9ae000c2014-02-13 17:22:33 +00001228 * Get the JNIEnv pointer for this thread.
1229 *
1230 * Returns NULL if the slot wasn't allocated or populated.
1231 */
1232/*static*/ JNIEnv* AndroidRuntime::getJNIEnv()
1233{
1234 JNIEnv* env;
1235 JavaVM* vm = AndroidRuntime::getJavaVM();
1236 assert(vm != NULL);
1237
1238 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
1239 return NULL;
1240 return env;
1241}
1242
1243/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 * Makes the current thread visible to the VM.
1245 *
1246 * The JNIEnv pointer returned is only valid for the current thread, and
1247 * thus must be tucked into thread-local storage.
1248 */
1249static int javaAttachThread(const char* threadName, JNIEnv** pEnv)
1250{
1251 JavaVMAttachArgs args;
1252 JavaVM* vm;
1253 jint result;
1254
1255 vm = AndroidRuntime::getJavaVM();
1256 assert(vm != NULL);
1257
1258 args.version = JNI_VERSION_1_4;
1259 args.name = (char*) threadName;
1260 args.group = NULL;
1261
1262 result = vm->AttachCurrentThread(pEnv, (void*) &args);
1263 if (result != JNI_OK)
Steve Block6215d3f2012-01-04 20:05:49 +00001264 ALOGI("NOTE: attach of thread '%s' failed\n", threadName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265
1266 return result;
1267}
1268
1269/*
1270 * Detach the current thread from the set visible to the VM.
1271 */
1272static int javaDetachThread(void)
1273{
1274 JavaVM* vm;
1275 jint result;
1276
1277 vm = AndroidRuntime::getJavaVM();
1278 assert(vm != NULL);
1279
1280 result = vm->DetachCurrentThread();
1281 if (result != JNI_OK)
Steve Block3762c312012-01-06 19:20:56 +00001282 ALOGE("ERROR: thread detach failed\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283 return result;
1284}
1285
1286/*
1287 * When starting a native thread that will be visible from the VM, we
1288 * bounce through this to get the right attach/detach action.
1289 * Note that this function calls free(args)
1290 */
1291/*static*/ int AndroidRuntime::javaThreadShell(void* args) {
1292 void* start = ((void**)args)[0];
1293 void* userData = ((void **)args)[1];
1294 char* name = (char*) ((void **)args)[2]; // we own this storage
1295 free(args);
1296 JNIEnv* env;
1297 int result;
1298
1299 /* hook us into the VM */
1300 if (javaAttachThread(name, &env) != JNI_OK)
1301 return -1;
1302
1303 /* start the thread running */
1304 result = (*(android_thread_func_t)start)(userData);
1305
1306 /* unhook us */
1307 javaDetachThread();
1308 free(name);
1309
1310 return result;
1311}
1312
1313/*
1314 * This is invoked from androidCreateThreadEtc() via the callback
1315 * set with androidSetCreateThreadFunc().
1316 *
1317 * We need to create the new thread in such a way that it gets hooked
1318 * into the VM before it really starts executing.
1319 */
1320/*static*/ int AndroidRuntime::javaCreateThreadEtc(
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001321 android_thread_func_t entryFunction,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001322 void* userData,
1323 const char* threadName,
1324 int32_t threadPriority,
1325 size_t threadStackSize,
1326 android_thread_id_t* threadId)
1327{
1328 void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free
1329 int result;
1330
Brian Carlstrom66f48312016-03-12 16:07:48 -08001331 LOG_ALWAYS_FATAL_IF(threadName == nullptr, "threadName not provided to javaCreateThreadEtc");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001332
1333 args[0] = (void*) entryFunction;
1334 args[1] = userData;
1335 args[2] = (void*) strdup(threadName); // javaThreadShell must free
1336
1337 result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args,
1338 threadName, threadPriority, threadStackSize, threadId);
1339 return result;
1340}
1341
1342/*
1343 * Create a thread that is visible from the VM.
1344 *
1345 * This is called from elsewhere in the library.
1346 */
Mike Lockwoodf602d362010-06-20 14:28:16 -07001347/*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001348 void (*start)(void *), void* arg)
1349{
Mike Lockwoodf602d362010-06-20 14:28:16 -07001350 android_thread_id_t threadId = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351 javaCreateThreadEtc((android_thread_func_t) start, arg, name,
Mike Lockwoodf602d362010-06-20 14:28:16 -07001352 ANDROID_PRIORITY_DEFAULT, 0, &threadId);
1353 return threadId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001354}
1355
1356#if 0
1357static void quickTest(void* arg)
1358{
1359 const char* str = (const char*) arg;
1360
1361 printf("In quickTest: %s\n", str);
1362}
1363#endif
1364
1365#ifdef NDEBUG
1366 #define REG_JNI(name) { name }
1367 struct RegJNIRec {
1368 int (*mProc)(JNIEnv*);
1369 };
1370#else
1371 #define REG_JNI(name) { name, #name }
1372 struct RegJNIRec {
1373 int (*mProc)(JNIEnv*);
1374 const char* mName;
1375 };
1376#endif
1377
1378typedef void (*RegJAMProc)();
1379
1380static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env)
1381{
1382 for (size_t i = 0; i < count; i++) {
1383 if (array[i].mProc(env) < 0) {
1384#ifndef NDEBUG
Steve Block5baa3a62011-12-20 16:23:08 +00001385 ALOGD("----------!!! %s failed to load\n", array[i].mName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001386#endif
1387 return -1;
1388 }
1389 }
1390 return 0;
1391}
1392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001393static const RegJNIRec gRegJNI[] = {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001394 REG_JNI(register_com_android_internal_os_RuntimeInit),
Jesse Hall1fe1dc02017-07-06 15:30:39 -07001395 REG_JNI(register_com_android_internal_os_ZygoteInit_nativeZygoteInit),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001396 REG_JNI(register_android_os_SystemClock),
1397 REG_JNI(register_android_util_EventLog),
1398 REG_JNI(register_android_util_Log),
Svet Ganov53a441c2016-04-19 19:38:00 -07001399 REG_JNI(register_android_util_MemoryIntArray),
Doris Liucdd23f92015-11-11 14:31:13 -08001400 REG_JNI(register_android_util_PathParser),
Yao Chend54f9dd2017-10-17 17:37:48 +00001401 REG_JNI(register_android_util_StatsLog),
Tej Singhbe0482b2019-03-19 22:01:57 -07001402 REG_JNI(register_android_util_StatsLogInternal),
Michal Karpinski6235a942016-03-15 12:07:23 +00001403 REG_JNI(register_android_app_admin_SecurityLog),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001404 REG_JNI(register_android_content_AssetManager),
1405 REG_JNI(register_android_content_StringBlock),
1406 REG_JNI(register_android_content_XmlBlock),
Adam Lesinskibebfcc42018-02-12 14:27:46 -08001407 REG_JNI(register_android_content_res_ApkAssets),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001408 REG_JNI(register_android_text_AndroidCharacter),
Seigo Nonaka44a1df22017-08-31 18:22:38 -07001409 REG_JNI(register_android_text_Hyphenator),
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001410 REG_JNI(register_android_view_InputDevice),
1411 REG_JNI(register_android_view_KeyCharacterMap),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001412 REG_JNI(register_android_os_Process),
Andreas Hubera8079bf2010-11-16 14:40:31 -08001413 REG_JNI(register_android_os_SystemProperties),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001414 REG_JNI(register_android_os_Binder),
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -08001415 REG_JNI(register_android_os_Parcel),
Yifan Hongbb0bd002017-11-14 16:14:04 -08001416 REG_JNI(register_android_os_HidlSupport),
Andreas Huberc0b6c532016-08-15 09:25:02 -07001417 REG_JNI(register_android_os_HwBinder),
Andreas Huberdc263212016-08-25 11:21:21 -07001418 REG_JNI(register_android_os_HwBlob),
Andreas Huberc0b6c532016-08-15 09:25:02 -07001419 REG_JNI(register_android_os_HwParcel),
1420 REG_JNI(register_android_os_HwRemoteBinder),
Nirav Atre9850dd92018-07-24 17:03:44 -07001421 REG_JNI(register_android_os_NativeHandle),
Yifan Hongbecc56d2017-04-05 14:42:05 -07001422 REG_JNI(register_android_os_VintfObject),
Yifan Hong1bda6732017-04-26 11:38:01 -07001423 REG_JNI(register_android_os_VintfRuntimeInfo),
Richard Uhler775873a2015-12-29 12:37:39 -08001424 REG_JNI(register_android_graphics_Canvas),
Leon Scroggins III0e443d12018-12-19 11:38:35 -05001425 // This needs to be before register_android_graphics_Graphics, or the latter
1426 // will not be able to find the jmethodID for ColorSpace.get().
1427 REG_JNI(register_android_graphics_ColorSpace),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001428 REG_JNI(register_android_graphics_Graphics),
Chris Craik54389792013-12-20 13:28:11 -08001429 REG_JNI(register_android_view_DisplayEventReceiver),
John Reckf666ad72014-03-14 16:24:57 -07001430 REG_JNI(register_android_view_RenderNode),
John Recke45b1fd2014-04-15 09:50:16 -07001431 REG_JNI(register_android_view_RenderNodeAnimator),
Chris Craikc9070eb2015-03-09 18:50:14 -07001432 REG_JNI(register_android_view_DisplayListCanvas),
Riddle Hsucd958bc2019-01-23 15:40:26 +08001433 REG_JNI(register_android_view_InputApplicationHandle),
1434 REG_JNI(register_android_view_InputWindowHandle),
John Reck9d8d99d2018-02-21 12:55:41 -08001435 REG_JNI(register_android_view_TextureLayer),
John Reckcec24ae2013-11-05 13:27:50 -08001436 REG_JNI(register_android_view_ThreadedRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437 REG_JNI(register_android_view_Surface),
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001438 REG_JNI(register_android_view_SurfaceControl),
Jeff Brown64a55af2012-08-26 02:47:39 -07001439 REG_JNI(register_android_view_SurfaceSession),
Adrian Roos9b963d32019-02-13 18:39:36 +00001440 REG_JNI(register_android_view_CompositionSamplingListener),
Romain Guy8f0095c2011-05-02 17:24:22 -07001441 REG_JNI(register_android_view_TextureView),
John Reck315c3292014-05-09 19:21:04 -07001442 REG_JNI(register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001443 REG_JNI(register_com_google_android_gles_jni_EGLImpl),
1444 REG_JNI(register_com_google_android_gles_jni_GLImpl),
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001445 REG_JNI(register_android_opengl_jni_EGL14),
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -06001446 REG_JNI(register_android_opengl_jni_EGL15),
Jesse Hall237c2b82013-05-06 11:36:57 -07001447 REG_JNI(register_android_opengl_jni_EGLExt),
Jack Palevich1c4907e2009-04-13 16:22:25 -07001448 REG_JNI(register_android_opengl_jni_GLES10),
1449 REG_JNI(register_android_opengl_jni_GLES10Ext),
1450 REG_JNI(register_android_opengl_jni_GLES11),
1451 REG_JNI(register_android_opengl_jni_GLES11Ext),
Jack Palevich560814f2009-11-19 16:34:55 +08001452 REG_JNI(register_android_opengl_jni_GLES20),
Jesse Halld877efe2013-04-29 15:59:35 -07001453 REG_JNI(register_android_opengl_jni_GLES30),
Jesse Hall7ab63ac2014-05-19 15:13:41 -07001454 REG_JNI(register_android_opengl_jni_GLES31),
1455 REG_JNI(register_android_opengl_jni_GLES31Ext),
Pablo Ceballos38c1a7e2015-10-30 10:34:30 -07001456 REG_JNI(register_android_opengl_jni_GLES32),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001457
1458 REG_JNI(register_android_graphics_Bitmap),
1459 REG_JNI(register_android_graphics_BitmapFactory),
Wei-Ta Chen6b849e22010-09-07 17:32:18 +08001460 REG_JNI(register_android_graphics_BitmapRegionDecoder),
Leon Scroggins III0c01dbf2017-10-20 14:08:11 -04001461 REG_JNI(register_android_graphics_ByteBufferStreamAdaptor),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001462 REG_JNI(register_android_graphics_Camera),
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -04001463 REG_JNI(register_android_graphics_CreateJavaOutputStreamAdaptor),
John Reck52244ff2014-05-01 21:27:37 -07001464 REG_JNI(register_android_graphics_CanvasProperty),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001465 REG_JNI(register_android_graphics_ColorFilter),
1466 REG_JNI(register_android_graphics_DrawFilter),
Raph Levien1a73f7322014-01-30 16:06:28 -08001467 REG_JNI(register_android_graphics_FontFamily),
sergeyv0a0f2312017-01-04 13:58:52 -08001468 REG_JNI(register_android_graphics_GraphicBuffer),
Leon Scroggins III0c01dbf2017-10-20 14:08:11 -04001469 REG_JNI(register_android_graphics_ImageDecoder),
Leon Scroggins III671cce22018-01-14 16:52:17 -05001470 REG_JNI(register_android_graphics_drawable_AnimatedImageDrawable),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001471 REG_JNI(register_android_graphics_Interpolator),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001472 REG_JNI(register_android_graphics_MaskFilter),
1473 REG_JNI(register_android_graphics_Matrix),
1474 REG_JNI(register_android_graphics_Movie),
1475 REG_JNI(register_android_graphics_NinePatch),
1476 REG_JNI(register_android_graphics_Paint),
1477 REG_JNI(register_android_graphics_Path),
1478 REG_JNI(register_android_graphics_PathMeasure),
1479 REG_JNI(register_android_graphics_PathEffect),
1480 REG_JNI(register_android_graphics_Picture),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001481 REG_JNI(register_android_graphics_Region),
1482 REG_JNI(register_android_graphics_Shader),
Jamie Gennisaa0ce332011-01-06 17:04:26 -08001483 REG_JNI(register_android_graphics_SurfaceTexture),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001484 REG_JNI(register_android_graphics_Typeface),
Wei-Ta Chenbca2d612009-11-30 17:52:05 +08001485 REG_JNI(register_android_graphics_YuvImage),
Doris Liu766431a2016-02-04 22:17:11 +00001486 REG_JNI(register_android_graphics_drawable_AnimatedVectorDrawable),
Doris Liu4bbc2932015-12-01 17:59:40 -08001487 REG_JNI(register_android_graphics_drawable_VectorDrawable),
Seigo Nonakaa1c21c02018-07-20 15:57:39 -07001488 REG_JNI(register_android_graphics_fonts_Font),
Seigo Nonaka88930f12018-07-24 17:09:23 -07001489 REG_JNI(register_android_graphics_fonts_FontFamily),
Svetoslav6811f4e2013-09-18 15:58:28 -07001490 REG_JNI(register_android_graphics_pdf_PdfDocument),
Svetoslav62ce3322014-09-04 21:17:17 -07001491 REG_JNI(register_android_graphics_pdf_PdfEditor),
Svetoslav29617692014-04-24 18:40:42 -07001492 REG_JNI(register_android_graphics_pdf_PdfRenderer),
Seigo Nonaka70200b02018-10-01 16:04:11 -07001493 REG_JNI(register_android_graphics_text_MeasuredText),
1494 REG_JNI(register_android_graphics_text_LineBreaker),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495
1496 REG_JNI(register_android_database_CursorWindow),
Jeff Browne5360fb2011-10-31 17:48:13 -07001497 REG_JNI(register_android_database_SQLiteConnection),
1498 REG_JNI(register_android_database_SQLiteGlobal),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 REG_JNI(register_android_database_SQLiteDebug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001500 REG_JNI(register_android_os_Debug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001501 REG_JNI(register_android_os_FileObserver),
Jesse Hallb12249b2016-12-12 12:53:02 -08001502 REG_JNI(register_android_os_GraphicsEnvironment),
Christopher Tatefa9e7c02010-05-06 12:07:10 -07001503 REG_JNI(register_android_os_MessageQueue),
Stephen Smalleyc07fca32012-01-13 08:31:39 -05001504 REG_JNI(register_android_os_SELinux),
Jeff Brown481c1572012-03-09 14:41:15 -08001505 REG_JNI(register_android_os_Trace),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001506 REG_JNI(register_android_os_UEventObserver),
1507 REG_JNI(register_android_net_LocalSocketImpl),
1508 REG_JNI(register_android_net_NetworkUtils),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 REG_JNI(register_android_os_MemoryFile),
John Reckdea6a022017-05-25 17:09:33 -07001510 REG_JNI(register_android_os_SharedMemory),
Narayan Kamathf9419f02017-06-15 11:35:38 +01001511 REG_JNI(register_com_android_internal_os_ClassLoaderFactory),
Narayan Kamath973b4662014-03-31 13:41:26 +01001512 REG_JNI(register_com_android_internal_os_Zygote),
Jesse Hall1fe1dc02017-07-06 15:30:39 -07001513 REG_JNI(register_com_android_internal_os_ZygoteInit),
John Reck9fa40712014-05-09 15:26:59 -07001514 REG_JNI(register_com_android_internal_util_VirtualRefBasePtr),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 REG_JNI(register_android_hardware_Camera),
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07001516 REG_JNI(register_android_hardware_camera2_CameraMetadata),
Ruben Brunkfeb50af2014-05-09 19:58:49 -07001517 REG_JNI(register_android_hardware_camera2_legacy_LegacyCameraDevice),
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -07001518 REG_JNI(register_android_hardware_camera2_legacy_PerfMeasurement),
Ruben Brunkb6079002014-05-22 12:33:54 -07001519 REG_JNI(register_android_hardware_camera2_DngCreator),
Craig Donner1a4d07d2017-01-09 13:01:22 -08001520 REG_JNI(register_android_hardware_HardwareBuffer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 REG_JNI(register_android_hardware_SensorManager),
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04001522 REG_JNI(register_android_hardware_SerialPort),
Eric Laurent60b62bc2014-04-18 17:50:49 -07001523 REG_JNI(register_android_hardware_SoundTrigger),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001524 REG_JNI(register_android_hardware_UsbDevice),
Mike Lockwoodacc29cc2011-03-11 08:18:08 -05001525 REG_JNI(register_android_hardware_UsbDeviceConnection),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001526 REG_JNI(register_android_hardware_UsbRequest),
Brian Duddiecfa5b5b2019-01-22 18:01:40 +00001527 REG_JNI(register_android_hardware_location_ActivityRecognitionHardware),
Eric Laurent7c31847e2018-11-29 14:33:56 -08001528 REG_JNI(register_android_media_AudioEffectDescriptor),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 REG_JNI(register_android_media_AudioSystem),
Paul McLeanb3ae6d92018-11-05 15:16:59 -07001530 REG_JNI(register_android_media_AudioRecord),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531 REG_JNI(register_android_media_AudioTrack),
François Gaffieb4691282018-07-09 13:07:32 +02001532 REG_JNI(register_android_media_AudioAttributes),
François Gaffiec01fa3a2018-03-15 14:33:24 +01001533 REG_JNI(register_android_media_AudioProductStrategies),
François Gaffieadcd00a2018-09-18 17:06:26 +02001534 REG_JNI(register_android_media_AudioVolumeGroups),
1535 REG_JNI(register_android_media_AudioVolumeGroupChangeHandler),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001536 REG_JNI(register_android_media_JetPlayer),
jiabinc0f49442018-01-05 10:23:50 -08001537 REG_JNI(register_android_media_MicrophoneInfo),
Jeff Browncbad9762012-09-04 21:57:59 -07001538 REG_JNI(register_android_media_RemoteDisplay),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001539 REG_JNI(register_android_media_ToneGenerator),
Paul McLean84b491302018-05-09 10:03:57 -06001540 REG_JNI(register_android_media_midi),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001541
1542 REG_JNI(register_android_opengl_classes),
JP Abgrall98a4f7e2011-09-02 15:36:33 -07001543 REG_JNI(register_android_server_NetworkManagementSocketTagger),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 REG_JNI(register_android_ddm_DdmHandleNativeHeap),
Joe Onorato1cf58742009-06-12 11:06:24 -07001545 REG_JNI(register_android_backup_BackupDataInput),
Joe Onoratod2110db2009-05-19 13:41:21 -07001546 REG_JNI(register_android_backup_BackupDataOutput),
Joe Onorato06290a42009-06-18 20:10:37 -07001547 REG_JNI(register_android_backup_FileBackupHelperBase),
Joe Onorato4ababd92009-06-25 18:29:18 -04001548 REG_JNI(register_android_backup_BackupHelperDispatcher),
Christopher Tate4a627c72011-04-01 14:43:32 -07001549 REG_JNI(register_android_app_backup_FullBackup),
Dimitry Ivanov4449ef52016-02-25 17:41:13 -08001550 REG_JNI(register_android_app_Activity),
Chet Haase9c1e23b2011-03-24 10:51:31 -07001551 REG_JNI(register_android_app_ActivityThread),
Dianne Hackborn69969e42010-05-04 11:40:40 -07001552 REG_JNI(register_android_app_NativeActivity),
Przemyslaw Szczepaniak8a7c1602015-11-03 09:47:56 +00001553 REG_JNI(register_android_util_jar_StrictJarFile),
Jeff Brown46b9ac02010-04-22 18:58:52 -07001554 REG_JNI(register_android_view_InputChannel),
Jeff Brown32cbc38552011-12-01 14:01:49 -08001555 REG_JNI(register_android_view_InputEventReceiver),
Jeff Brownc28867a2013-03-26 15:42:39 -07001556 REG_JNI(register_android_view_InputEventSender),
Michael Wrighta44dd262013-04-10 21:12:00 -07001557 REG_JNI(register_android_view_InputQueue),
Jeff Brown46b9ac02010-04-22 18:58:52 -07001558 REG_JNI(register_android_view_KeyEvent),
1559 REG_JNI(register_android_view_MotionEvent),
Jeff Brown2352b972011-04-12 22:39:53 -07001560 REG_JNI(register_android_view_PointerIcon),
Jeff Brown2ed24622011-03-14 19:39:54 -07001561 REG_JNI(register_android_view_VelocityTracker),
Kenny Root02c87302010-07-01 08:10:18 -07001562
1563 REG_JNI(register_android_content_res_ObbScanner),
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -07001564 REG_JNI(register_android_content_res_Configuration),
Chet Haase6e0ecb42010-11-03 19:41:18 -07001565
1566 REG_JNI(register_android_animation_PropertyValuesHolder),
Bo Zhu09856132018-04-01 12:24:09 -07001567 REG_JNI(register_android_security_Scrypt),
Kenny Root66269ea2011-07-12 14:14:01 -07001568 REG_JNI(register_com_android_internal_content_NativeLibraryHelper),
Svet Ganov8455ba22019-01-02 13:05:56 -08001569 REG_JNI(register_com_android_internal_os_AtomicDirectory),
Daichi Hirono878e86f2016-10-31 09:33:30 +09001570 REG_JNI(register_com_android_internal_os_FuseAppLoop),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571};
1572
1573/*
1574 * Register android native functions with the VM.
1575 */
1576/*static*/ int AndroidRuntime::startReg(JNIEnv* env)
1577{
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001578 ATRACE_NAME("RegisterAndroidNatives");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579 /*
1580 * This hook causes all future threads created in this process to be
1581 * attached to the JavaVM. (This needs to go away in favor of JNI
1582 * Attach calls.)
1583 */
1584 androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc);
1585
Steve Block71f2cf12011-10-20 11:56:00 +01001586 ALOGV("--- registering native functions ---\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001587
1588 /*
1589 * Every "register" function calls one or more things that return
1590 * a local reference (e.g. FindClass). Because we haven't really
1591 * started the VM yet, they're all getting stored in the base frame
1592 * and never released. Use Push/Pop to manage the storage.
1593 */
1594 env->PushLocalFrame(200);
1595
1596 if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) {
1597 env->PopLocalFrame(NULL);
1598 return -1;
1599 }
1600 env->PopLocalFrame(NULL);
1601
1602 //createJavaThread("fubar", quickTest, (void*) "hello");
1603
1604 return 0;
1605}
1606
1607AndroidRuntime* AndroidRuntime::getRuntime()
1608{
1609 return gCurRuntime;
1610}
1611
1612/**
Narayan Kamathc21dab92015-06-25 14:22:00 +01001613 * Used by surface flinger's DdmConnection to register native methods from
1614 * the framework.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001615 */
Narayan Kamathc21dab92015-06-25 14:22:00 +01001616extern "C" jint registerFrameworkNatives(JNIEnv* env) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001617 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1618}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001619} // namespace android