blob: c90071a0de440537a58a5516bb1746feb4476135 [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>
34
35#include <SkGraphics.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
37#include "jni.h"
Steven Moreland2279b252017-07-19 09:50:45 -070038#include <nativehelper/JNIHelp.h>
39#include <nativehelper/JniInvocation.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040#include "android_util_Binder.h"
41
42#include <stdio.h>
43#include <signal.h>
44#include <sys/stat.h>
45#include <sys/types.h>
46#include <signal.h>
47#include <dirent.h>
48#include <assert.h>
49
Narayan Kamathbf882052015-08-11 15:40:34 +010050#include <string>
51#include <vector>
52
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053using namespace android;
Tom Cherry93099e42017-10-11 13:44:21 -070054using android::base::GetProperty;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056extern int register_android_os_Binder(JNIEnv* env);
57extern int register_android_os_Process(JNIEnv* env);
58extern int register_android_graphics_Bitmap(JNIEnv*);
59extern int register_android_graphics_BitmapFactory(JNIEnv*);
Wei-Ta Chen6b849e22010-09-07 17:32:18 +080060extern int register_android_graphics_BitmapRegionDecoder(JNIEnv*);
Leon Scroggins III0c01dbf2017-10-20 14:08:11 -040061extern int register_android_graphics_ByteBufferStreamAdaptor(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062extern int register_android_graphics_Camera(JNIEnv* env);
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -040063extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env);
sergeyv0a0f2312017-01-04 13:58:52 -080064extern int register_android_graphics_GraphicBuffer(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065extern int register_android_graphics_Graphics(JNIEnv* env);
Leon Scroggins III0c01dbf2017-10-20 14:08:11 -040066extern int register_android_graphics_ImageDecoder(JNIEnv*);
Leon Scroggins III671cce22018-01-14 16:52:17 -050067extern int register_android_graphics_drawable_AnimatedImageDrawable(JNIEnv*);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068extern int register_android_graphics_Interpolator(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069extern int register_android_graphics_MaskFilter(JNIEnv* env);
70extern int register_android_graphics_Movie(JNIEnv* env);
71extern int register_android_graphics_NinePatch(JNIEnv*);
72extern int register_android_graphics_PathEffect(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073extern int register_android_graphics_Shader(JNIEnv* env);
74extern int register_android_graphics_Typeface(JNIEnv* env);
Wei-Ta Chenbca2d612009-11-30 17:52:05 +080075extern int register_android_graphics_YuvImage(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076
77extern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env);
78extern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070079extern int register_android_opengl_jni_EGL14(JNIEnv* env);
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -060080extern int register_android_opengl_jni_EGL15(JNIEnv* env);
Jesse Hall237c2b82013-05-06 11:36:57 -070081extern int register_android_opengl_jni_EGLExt(JNIEnv* env);
Jack Palevich1c4907e2009-04-13 16:22:25 -070082extern int register_android_opengl_jni_GLES10(JNIEnv* env);
83extern int register_android_opengl_jni_GLES10Ext(JNIEnv* env);
84extern int register_android_opengl_jni_GLES11(JNIEnv* env);
85extern int register_android_opengl_jni_GLES11Ext(JNIEnv* env);
Jack Palevich560814f2009-11-19 16:34:55 +080086extern int register_android_opengl_jni_GLES20(JNIEnv* env);
Jesse Halld877efe2013-04-29 15:59:35 -070087extern int register_android_opengl_jni_GLES30(JNIEnv* env);
Jesse Hall7ab63ac2014-05-19 15:13:41 -070088extern int register_android_opengl_jni_GLES31(JNIEnv* env);
89extern int register_android_opengl_jni_GLES31Ext(JNIEnv* env);
Pablo Ceballos38c1a7e2015-10-30 10:34:30 -070090extern int register_android_opengl_jni_GLES32(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091
92extern int register_android_hardware_Camera(JNIEnv *env);
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -070093extern int register_android_hardware_camera2_CameraMetadata(JNIEnv *env);
Ruben Brunkfeb50af2014-05-09 19:58:49 -070094extern int register_android_hardware_camera2_legacy_LegacyCameraDevice(JNIEnv *env);
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -070095extern int register_android_hardware_camera2_legacy_PerfMeasurement(JNIEnv *env);
Ruben Brunkb6079002014-05-22 12:33:54 -070096extern int register_android_hardware_camera2_DngCreator(JNIEnv *env);
Craig Donner1a4d07d2017-01-09 13:01:22 -080097extern int register_android_hardware_HardwareBuffer(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098extern int register_android_hardware_SensorManager(JNIEnv *env);
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -040099extern int register_android_hardware_SerialPort(JNIEnv *env);
Eric Laurent60b62bc2014-04-18 17:50:49 -0700100extern int register_android_hardware_SoundTrigger(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500101extern int register_android_hardware_UsbDevice(JNIEnv *env);
Mike Lockwoodacc29cc2011-03-11 08:18:08 -0500102extern int register_android_hardware_UsbDeviceConnection(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500103extern int register_android_hardware_UsbRequest(JNIEnv *env);
Brian Duddiecfa5b5b2019-01-22 18:01:40 +0000104extern int register_android_hardware_location_ActivityRecognitionHardware(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105
Eric Laurent7c31847e2018-11-29 14:33:56 -0800106extern int register_android_media_AudioEffectDescriptor(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107extern int register_android_media_AudioRecord(JNIEnv *env);
108extern int register_android_media_AudioSystem(JNIEnv *env);
109extern int register_android_media_AudioTrack(JNIEnv *env);
François Gaffieb4691282018-07-09 13:07:32 +0200110extern int register_android_media_AudioAttributes(JNIEnv *env);
jiabinc0f49442018-01-05 10:23:50 -0800111extern int register_android_media_MicrophoneInfo(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112extern int register_android_media_JetPlayer(JNIEnv *env);
113extern int register_android_media_ToneGenerator(JNIEnv *env);
Paul McLean84b491302018-05-09 10:03:57 -0600114extern int register_android_media_midi(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116namespace android {
117
118/*
119 * JNI-based registration functions. Note these are properly contained in
120 * namespace android.
121 */
Michal Karpinski6235a942016-03-15 12:07:23 +0000122extern int register_android_app_admin_SecurityLog(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123extern int register_android_content_AssetManager(JNIEnv* env);
124extern int register_android_util_EventLog(JNIEnv* env);
Chenjie Yu671b1b52017-08-30 22:14:05 -0700125extern int register_android_util_StatsLog(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126extern int register_android_util_Log(JNIEnv* env);
Svet Ganov53a441c2016-04-19 19:38:00 -0700127extern int register_android_util_MemoryIntArray(JNIEnv* env);
Doris Liucdd23f92015-11-11 14:31:13 -0800128extern int register_android_util_PathParser(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129extern int register_android_content_StringBlock(JNIEnv* env);
130extern int register_android_content_XmlBlock(JNIEnv* env);
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800131extern int register_android_content_res_ApkAssets(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132extern int register_android_graphics_Canvas(JNIEnv* env);
John Reck52244ff2014-05-01 21:27:37 -0700133extern int register_android_graphics_CanvasProperty(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134extern int register_android_graphics_ColorFilter(JNIEnv* env);
Leon Scroggins III0e443d12018-12-19 11:38:35 -0500135extern int register_android_graphics_ColorSpace(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136extern int register_android_graphics_DrawFilter(JNIEnv* env);
Raph Levien1a73f7322014-01-30 16:06:28 -0800137extern int register_android_graphics_FontFamily(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138extern int register_android_graphics_Matrix(JNIEnv* env);
139extern int register_android_graphics_Paint(JNIEnv* env);
140extern int register_android_graphics_Path(JNIEnv* env);
141extern int register_android_graphics_PathMeasure(JNIEnv* env);
142extern int register_android_graphics_Picture(JNIEnv*);
Jeff Brownfbf09772011-01-16 14:06:57 -0800143extern int register_android_graphics_Region(JNIEnv* env);
Jamie Gennisaa0ce332011-01-06 17:04:26 -0800144extern int register_android_graphics_SurfaceTexture(JNIEnv* env);
Doris Liu766431a2016-02-04 22:17:11 +0000145extern int register_android_graphics_drawable_AnimatedVectorDrawable(JNIEnv* env);
Doris Liu4bbc2932015-12-01 17:59:40 -0800146extern int register_android_graphics_drawable_VectorDrawable(JNIEnv* env);
Seigo Nonakaa1c21c02018-07-20 15:57:39 -0700147extern int register_android_graphics_fonts_Font(JNIEnv* env);
Seigo Nonaka88930f12018-07-24 17:09:23 -0700148extern int register_android_graphics_fonts_FontFamily(JNIEnv* env);
Svetoslav6811f4e2013-09-18 15:58:28 -0700149extern int register_android_graphics_pdf_PdfDocument(JNIEnv* env);
Svetoslav62ce3322014-09-04 21:17:17 -0700150extern int register_android_graphics_pdf_PdfEditor(JNIEnv* env);
Svetoslav29617692014-04-24 18:40:42 -0700151extern int register_android_graphics_pdf_PdfRenderer(JNIEnv* env);
Seigo Nonaka70200b02018-10-01 16:04:11 -0700152extern int register_android_graphics_text_MeasuredText(JNIEnv* env);
153extern int register_android_graphics_text_LineBreaker(JNIEnv *env);
Jeff Brown0a0a1242011-12-02 02:25:22 -0800154extern int register_android_view_DisplayEventReceiver(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700155extern int register_android_view_DisplayListCanvas(JNIEnv* env);
Riddle Hsucd958bc2019-01-23 15:40:26 +0800156extern int register_android_view_InputApplicationHandle(JNIEnv* env);
157extern int register_android_view_InputWindowHandle(JNIEnv* env);
John Reck9d8d99d2018-02-21 12:55:41 -0800158extern int register_android_view_TextureLayer(JNIEnv* env);
John Reckf666ad72014-03-14 16:24:57 -0700159extern int register_android_view_RenderNode(JNIEnv* env);
John Recke45b1fd2014-04-15 09:50:16 -0700160extern int register_android_view_RenderNodeAnimator(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161extern int register_android_view_Surface(JNIEnv* env);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800162extern int register_android_view_SurfaceControl(JNIEnv* env);
Jeff Brown64a55af2012-08-26 02:47:39 -0700163extern int register_android_view_SurfaceSession(JNIEnv* env);
Romain Guy8f0095c2011-05-02 17:24:22 -0700164extern int register_android_view_TextureView(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700165extern int register_android_view_ThreadedRenderer(JNIEnv* env);
John Reck315c3292014-05-09 19:21:04 -0700166extern int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167extern int register_android_database_CursorWindow(JNIEnv* env);
Jeff Browne5360fb2011-10-31 17:48:13 -0700168extern int register_android_database_SQLiteConnection(JNIEnv* env);
169extern int register_android_database_SQLiteGlobal(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170extern int register_android_database_SQLiteDebug(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171extern int register_android_nio_utils(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172extern int register_android_os_Debug(JNIEnv* env);
Jesse Hallb12249b2016-12-12 12:53:02 -0800173extern int register_android_os_GraphicsEnvironment(JNIEnv* env);
Yifan Hongbb0bd002017-11-14 16:14:04 -0800174extern int register_android_os_HidlSupport(JNIEnv* env);
Andreas Huberc0b6c532016-08-15 09:25:02 -0700175extern int register_android_os_HwBinder(JNIEnv *env);
Andreas Huberdc263212016-08-25 11:21:21 -0700176extern int register_android_os_HwBlob(JNIEnv *env);
Andreas Huberc0b6c532016-08-15 09:25:02 -0700177extern int register_android_os_HwParcel(JNIEnv *env);
178extern int register_android_os_HwRemoteBinder(JNIEnv *env);
Nirav Atre9850dd92018-07-24 17:03:44 -0700179extern int register_android_os_NativeHandle(JNIEnv *env);
Christopher Tatefa9e7c02010-05-06 12:07:10 -0700180extern int register_android_os_MessageQueue(JNIEnv* env);
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -0800181extern int register_android_os_Parcel(JNIEnv* env);
Stephen Smalleyc07fca32012-01-13 08:31:39 -0500182extern int register_android_os_SELinux(JNIEnv* env);
Yifan Hongbecc56d2017-04-05 14:42:05 -0700183extern int register_android_os_VintfObject(JNIEnv *env);
Yifan Hong1bda6732017-04-26 11:38:01 -0700184extern int register_android_os_VintfRuntimeInfo(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185extern int register_android_os_SystemProperties(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186extern int register_android_os_SystemClock(JNIEnv* env);
Jeff Brown481c1572012-03-09 14:41:15 -0800187extern int register_android_os_Trace(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188extern int register_android_os_FileObserver(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189extern int register_android_os_UEventObserver(JNIEnv* env);
190extern int register_android_os_MemoryFile(JNIEnv* env);
John Reckdea6a022017-05-25 17:09:33 -0700191extern int register_android_os_SharedMemory(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192extern int register_android_net_LocalSocketImpl(JNIEnv* env);
193extern int register_android_net_NetworkUtils(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194extern int register_android_text_AndroidCharacter(JNIEnv *env);
Seigo Nonaka44a1df22017-08-31 18:22:38 -0700195extern int register_android_text_Hyphenator(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196extern int register_android_opengl_classes(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
Narayan Kamath29564cd2014-08-07 10:57:40 +0100198extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env);
Joe Onorato1cf58742009-06-12 11:06:24 -0700199extern int register_android_backup_BackupDataInput(JNIEnv *env);
Joe Onoratod2110db2009-05-19 13:41:21 -0700200extern int register_android_backup_BackupDataOutput(JNIEnv *env);
Joe Onorato06290a42009-06-18 20:10:37 -0700201extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
Joe Onorato4ababd92009-06-25 18:29:18 -0400202extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
Christopher Tate4a627c72011-04-01 14:43:32 -0700203extern int register_android_app_backup_FullBackup(JNIEnv *env);
Dimitry Ivanov4449ef52016-02-25 17:41:13 -0800204extern int register_android_app_Activity(JNIEnv *env);
Chet Haase9c1e23b2011-03-24 10:51:31 -0700205extern int register_android_app_ActivityThread(JNIEnv *env);
Dianne Hackborn69969e42010-05-04 11:40:40 -0700206extern int register_android_app_NativeActivity(JNIEnv *env);
Jeff Browncbad9762012-09-04 21:57:59 -0700207extern int register_android_media_RemoteDisplay(JNIEnv *env);
Przemyslaw Szczepaniak8a7c1602015-11-03 09:47:56 +0000208extern int register_android_util_jar_StrictJarFile(JNIEnv* env);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700209extern int register_android_view_InputChannel(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700210extern int register_android_view_InputDevice(JNIEnv* env);
Jeff Brown32cbc38552011-12-01 14:01:49 -0800211extern int register_android_view_InputEventReceiver(JNIEnv* env);
Jeff Brownc28867a2013-03-26 15:42:39 -0700212extern int register_android_view_InputEventSender(JNIEnv* env);
Michael Wrighta44dd262013-04-10 21:12:00 -0700213extern int register_android_view_InputQueue(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700214extern int register_android_view_KeyCharacterMap(JNIEnv *env);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700215extern int register_android_view_KeyEvent(JNIEnv* env);
216extern int register_android_view_MotionEvent(JNIEnv* env);
Jeff Brown2352b972011-04-12 22:39:53 -0700217extern int register_android_view_PointerIcon(JNIEnv* env);
Jeff Brown2ed24622011-03-14 19:39:54 -0700218extern int register_android_view_VelocityTracker(JNIEnv* env);
Kenny Root02c87302010-07-01 08:10:18 -0700219extern int register_android_content_res_ObbScanner(JNIEnv* env);
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700220extern int register_android_content_res_Configuration(JNIEnv* env);
Chet Haase6e0ecb42010-11-03 19:41:18 -0700221extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
Bo Zhu09856132018-04-01 12:24:09 -0700222extern int register_android_security_Scrypt(JNIEnv *env);
Kenny Root66269ea2011-07-12 14:14:01 -0700223extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -0800224extern int register_com_android_internal_net_NetworkStatsFactory(JNIEnv *env);
Svet Ganov8455ba22019-01-02 13:05:56 -0800225extern int register_com_android_internal_os_AtomicDirectory(JNIEnv *env);
Narayan Kamathf9419f02017-06-15 11:35:38 +0100226extern int register_com_android_internal_os_ClassLoaderFactory(JNIEnv* env);
Daichi Hirono878e86f2016-10-31 09:33:30 +0900227extern int register_com_android_internal_os_FuseAppLoop(JNIEnv* env);
Narayan Kamath973b4662014-03-31 13:41:26 +0100228extern int register_com_android_internal_os_Zygote(JNIEnv *env);
Jesse Hall1fe1dc02017-07-06 15:30:39 -0700229extern int register_com_android_internal_os_ZygoteInit(JNIEnv *env);
John Reck9fa40712014-05-09 15:26:59 -0700230extern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231
232static AndroidRuntime* gCurRuntime = NULL;
233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800234/*
235 * Code written in the Java Programming Language calls here from main().
236 */
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700237static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238{
239 gCurRuntime->onStarted();
240}
241
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800242static void com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243{
244 gCurRuntime->onZygoteInit();
245}
246
Jeff Brown4280c4a2012-03-15 17:48:02 -0700247static void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIEnv* env,
248 jobject clazz, jboolean exitWithoutCleanup)
249{
250 gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup);
251}
252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253/*
254 * JNI registration.
255 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256
257int register_com_android_internal_os_RuntimeInit(JNIEnv* env)
258{
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800259 const JNINativeMethod methods[] = {
260 { "nativeFinishInit", "()V",
261 (void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
262 { "nativeSetExitWithoutCleanup", "(Z)V",
263 (void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
264 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800266 methods, NELEM(methods));
267}
268
Jesse Hall1fe1dc02017-07-06 15:30:39 -0700269int register_com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv* env)
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800270{
271 const JNINativeMethod methods[] = {
272 { "nativeZygoteInit", "()V",
273 (void*) com_android_internal_os_ZygoteInit_nativeZygoteInit },
274 };
275 return jniRegisterNativeMethods(env, "com/android/internal/os/ZygoteInit",
276 methods, NELEM(methods));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277}
278
279// ----------------------------------------------------------------------
280
Andreas Huber9ae000c2014-02-13 17:22:33 +0000281/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
282
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000283AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) :
284 mExitWithoutCleanup(false),
285 mArgBlockStart(argBlockStart),
286 mArgBlockLength(argBlockLength)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700288 SkGraphics::Init();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289
290 // Pre-allocate enough space to hold a fair number of options.
291 mOptions.setCapacity(20);
292
293 assert(gCurRuntime == NULL); // one per process
294 gCurRuntime = this;
295}
296
297AndroidRuntime::~AndroidRuntime()
298{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299}
300
Andreas Huber9ae000c2014-02-13 17:22:33 +0000301/*
302 * Register native methods using JNI.
303 */
304/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
305 const char* className, const JNINativeMethod* gMethods, int numMethods)
306{
307 return jniRegisterNativeMethods(env, className, gMethods, numMethods);
308}
309
Dmitriy Filchenkof5b6e552016-07-18 16:00:35 -0700310void AndroidRuntime::setArgv0(const char* argv0, bool setProcName) {
311 if (setProcName) {
312 int len = strlen(argv0);
313 if (len < 15) {
314 pthread_setname_np(pthread_self(), argv0);
315 } else {
316 pthread_setname_np(pthread_self(), argv0 + len - 15);
317 }
318 }
Jeff Brown00c0cd42014-09-10 16:48:46 -0700319 memset(mArgBlockStart, 0, mArgBlockLength);
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000320 strlcpy(mArgBlockStart, argv0, mArgBlockLength);
321}
322
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100323status_t AndroidRuntime::callMain(const String8& className, jclass clazz,
324 const Vector<String8>& args)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325{
326 JNIEnv* env;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327 jmethodID methodId;
328
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100329 ALOGD("Calling main entry %s", className.string());
Dianne Hackborn08e60f22010-09-01 18:17:17 -0700330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 env = getJNIEnv();
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700332 if (clazz == NULL || env == NULL) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333 return UNKNOWN_ERROR;
334 }
335
336 methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
337 if (methodId == NULL) {
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100338 ALOGE("ERROR: could not find method %s.main(String[])\n", className.string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 return UNKNOWN_ERROR;
340 }
341
342 /*
343 * We want to call main() with a String array with our arguments in it.
344 * Create an array and populate it.
345 */
346 jclass stringClass;
347 jobjectArray strArray;
348
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100349 const size_t numArgs = args.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350 stringClass = env->FindClass("java/lang/String");
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100351 strArray = env->NewObjectArray(numArgs, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100353 for (size_t i = 0; i < numArgs; i++) {
354 jstring argStr = env->NewStringUTF(args[i].string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 env->SetObjectArrayElement(strArray, i, argStr);
356 }
357
358 env->CallStaticVoidMethod(clazz, methodId, strArray);
359 return NO_ERROR;
360}
361
362/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 * The VM calls this through the "exit" hook.
364 */
365static void runtime_exit(int code)
366{
Jeff Brown4280c4a2012-03-15 17:48:02 -0700367 gCurRuntime->exit(code);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368}
369
370/*
371 * The VM calls this through the "vfprintf" hook.
372 *
373 * We ignore "fp" and just write the results to the log file.
374 */
375static void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
376{
377 LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
378}
379
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800380/**
381 * The VM calls this when mutex contention debugging is enabled to
382 * determine whether or not the blocked thread was a "sensitive thread"
383 * for user responsiveness/smoothess.
384 *
385 * Our policy for this is whether or not we're tracing any StrictMode
386 * events on this thread (which we might've inherited via Binder calls
387 * into us)
388 */
389static bool runtime_isSensitiveThread() {
390 IPCThreadState* state = IPCThreadState::selfOrNull();
391 return state && state->getStrictModePolicy() != 0;
392}
393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394static int hasDir(const char* dir)
395{
396 struct stat s;
397 int res = stat(dir, &s);
398 if (res == 0) {
399 return S_ISDIR(s.st_mode);
400 }
401 return 0;
402}
403
Andreas Gampe995c62d2014-11-14 16:15:17 -0800404static bool hasFile(const char* file) {
405 struct stat s;
406 int res = stat(file, &s);
407 if (res == 0) {
408 return S_ISREG(s.st_mode);
409 }
410 return false;
411}
412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413/*
Narayan Kamathbf882052015-08-11 15:40:34 +0100414 * Read the persistent locale. Inspects the following system properties
415 * (in order) and returns the first non-empty property in the list :
416 *
417 * (1) persist.sys.locale
418 * (2) persist.sys.language/country/localevar (country and localevar are
419 * inspected iff. language is non-empty.
420 * (3) ro.product.locale
421 * (4) ro.product.locale.language/region
422 *
423 * Note that we need to inspect persist.sys.language/country/localevar to
424 * preserve language settings for devices that are upgrading from Lollipop
425 * to M. The same goes for ro.product.locale.language/region as well.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 */
Narayan Kamathbf882052015-08-11 15:40:34 +0100427const std::string readLocale()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428{
Tom Cherry93099e42017-10-11 13:44:21 -0700429 const std::string locale = GetProperty("persist.sys.locale", "");
Narayan Kamathbf882052015-08-11 15:40:34 +0100430 if (!locale.empty()) {
431 return locale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 }
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000433
Tom Cherry93099e42017-10-11 13:44:21 -0700434 const std::string language = GetProperty("persist.sys.language", "");
Narayan Kamathbf882052015-08-11 15:40:34 +0100435 if (!language.empty()) {
Tom Cherry93099e42017-10-11 13:44:21 -0700436 const std::string country = GetProperty("persist.sys.country", "");
437 const std::string variant = GetProperty("persist.sys.localevar", "");
Narayan Kamathbf882052015-08-11 15:40:34 +0100438
439 std::string out = language;
440 if (!country.empty()) {
441 out = out + "-" + country;
442 }
443
444 if (!variant.empty()) {
445 out = out + "-" + variant;
446 }
447
448 return out;
449 }
450
Tom Cherry93099e42017-10-11 13:44:21 -0700451 const std::string productLocale = GetProperty("ro.product.locale", "");
Narayan Kamathbf882052015-08-11 15:40:34 +0100452 if (!productLocale.empty()) {
453 return productLocale;
454 }
455
456 // If persist.sys.locale and ro.product.locale are missing,
457 // construct a locale value from the individual locale components.
Tom Cherry93099e42017-10-11 13:44:21 -0700458 const std::string productLanguage = GetProperty("ro.product.locale.language", "en");
459 const std::string productRegion = GetProperty("ro.product.locale.region", "US");
Narayan Kamathbf882052015-08-11 15:40:34 +0100460
461 return productLanguage + "-" + productRegion;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462}
463
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700464void AndroidRuntime::addOption(const char* optionString, void* extraInfo)
465{
466 JavaVMOption opt;
467 opt.optionString = optionString;
468 opt.extraInfo = extraInfo;
469 mOptions.add(opt);
470}
471
Andy McFaddenf70188a2009-03-31 15:52:13 -0700472/*
Andy McFaddene4d81f22010-07-14 16:02:20 -0700473 * Parse a property containing space-separated options that should be
474 * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
475 *
476 * This will cut up "extraOptsBuf" as we chop it into individual options.
477 *
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800478 * If "quotingArg" is non-null, it is passed before each extra option in mOptions.
479 *
Andy McFaddene4d81f22010-07-14 16:02:20 -0700480 * Adds the strings, if any, to mOptions.
481 */
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800482void AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg)
Andy McFaddene4d81f22010-07-14 16:02:20 -0700483{
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800484 char* start = extraOptsBuf;
485 char* end = NULL;
Andy McFaddene4d81f22010-07-14 16:02:20 -0700486 while (*start != '\0') {
487 while (*start == ' ') /* skip leading whitespace */
488 start++;
489 if (*start == '\0') /* was trailing ws, bail */
490 break;
491
492 end = start+1;
493 while (*end != ' ' && *end != '\0') /* find end of token */
494 end++;
495 if (*end == ' ')
496 *end++ = '\0'; /* mark end, advance to indicate more */
497
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800498 if (quotingArg != NULL) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700499 addOption(quotingArg);
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800500 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700501 addOption(start);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700502 start = end;
503 }
504}
505
506/*
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700507 * Reads a "property" into "buffer" with a default of "defaultArg". If
508 * the property is non-empty, it is treated as a runtime option such
509 * as "-Xmx32m".
510 *
511 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
512 *
513 * If an argument is found, it is added to mOptions.
514 *
515 * If an option is found, it is added to mOptions and true is
516 * returned. Otherwise false is returned.
517 */
518bool AndroidRuntime::parseRuntimeOption(const char* property,
519 char* buffer,
520 const char* runtimeArg,
521 const char* defaultArg)
522{
523 strcpy(buffer, runtimeArg);
524 size_t runtimeArgLen = strlen(runtimeArg);
525 property_get(property, buffer+runtimeArgLen, defaultArg);
526 if (buffer[runtimeArgLen] == '\0') {
527 return false;
528 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700529 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700530 return true;
531}
532
533/*
534 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700535 * is treated as a dex2oat compiler option that should be
Nicolas Geoffraybe7b0d12017-04-25 12:29:07 +0100536 * passed as a quoted option, e.g. "-Ximage-compiler-option --compiler-filter=assume-verified".
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700537 *
538 * The "compilerArg" is a prefix for the option such as "--compiler-filter=".
539 *
540 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
541 *
542 * If an option is found, it is added to mOptions and true is
543 * returned. Otherwise false is returned.
544 */
545bool AndroidRuntime::parseCompilerOption(const char* property,
546 char* buffer,
547 const char* compilerArg,
548 const char* quotingArg)
549{
550 strcpy(buffer, compilerArg);
551 size_t compilerArgLen = strlen(compilerArg);
552 property_get(property, buffer+compilerArgLen, "");
553 if (buffer[compilerArgLen] == '\0') {
554 return false;
555 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700556 addOption(quotingArg);
557 addOption(buffer);
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700558 return true;
559}
560
561/*
562 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700563 * is treated as a dex2oat compiler runtime option that should be
564 * passed as a quoted option, e.g. "-Ximage-compiler-option
565 * --runtime-arg -Ximage-compiler-option -Xmx32m".
566 *
567 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
568 *
569 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
570 *
571 * If an option is found, it is added to mOptions and true is
572 * returned. Otherwise false is returned.
573 */
574bool AndroidRuntime::parseCompilerRuntimeOption(const char* property,
575 char* buffer,
576 const char* runtimeArg,
577 const char* quotingArg)
578{
579 strcpy(buffer, runtimeArg);
580 size_t runtimeArgLen = strlen(runtimeArg);
581 property_get(property, buffer+runtimeArgLen, "");
582 if (buffer[runtimeArgLen] == '\0') {
583 return false;
584 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700585 addOption(quotingArg);
586 addOption("--runtime-arg");
587 addOption(quotingArg);
588 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700589 return true;
590}
591
592/*
Andy McFaddenf70188a2009-03-31 15:52:13 -0700593 * Start the Dalvik Virtual Machine.
594 *
595 * Various arguments, most determined by system properties, are passed in.
596 * The "mOptions" vector is updated.
597 *
Dave Allison07a1e232014-03-14 08:54:33 -0700598 * CAUTION: when adding options in here, be careful not to put the
599 * char buffer inside a nested scope. Adding the buffer to the
600 * options using mOptions.add() does not copy the buffer, so if the
601 * buffer goes out of scope the option may be overwritten. It's best
602 * to put the buffer at the top of the function so that it is more
603 * unlikely that someone will surround it in a scope at a later time
604 * and thus introduce a bug.
605 *
Andy McFaddenf70188a2009-03-31 15:52:13 -0700606 * Returns 0 on success.
607 */
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200608int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 JavaVMInitArgs initArgs;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800611 char propBuf[PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro38cfa8c2010-12-07 16:48:29 -0800613 char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700614 char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro8cdf27c2011-01-19 12:33:12 -0800615 char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700616 char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
617 char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800618 char usejitOptsBuf[sizeof("-Xusejit:")-1 + PROPERTY_VALUE_MAX];
Nicolas Geoffray24934a92018-05-16 17:22:37 +0100619 char jitpthreadpriorityOptsBuf[sizeof("-Xjitpthreadpriority:")-1 + PROPERTY_VALUE_MAX];
Nicolas Geoffraycdf1dff2015-11-19 13:48:35 +0000620 char jitmaxsizeOptsBuf[sizeof("-Xjitmaxsize:")-1 + PROPERTY_VALUE_MAX];
621 char jitinitialsizeOptsBuf[sizeof("-Xjitinitialsize:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800622 char jitthresholdOptsBuf[sizeof("-Xjitthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravledb4a79a2015-12-23 18:55:08 +0200623 char useJitProfilesOptsBuf[sizeof("-Xjitsaveprofilinginfo:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle0de80b92016-04-12 14:12:04 +0100624 char jitprithreadweightOptBuf[sizeof("-Xjitprithreadweight:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle8d74de52016-04-27 14:12:00 +0100625 char jittransitionweightOptBuf[sizeof("-Xjittransitionweight:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier5eee0042017-06-07 17:34:22 -0700626 char hotstartupsamplesOptsBuf[sizeof("-Xps-hot-startup-method-samples:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartiercd0caf52017-10-13 11:29:27 -0700627 char madviseRandomOptsBuf[sizeof("-XX:MadviseRandomAccess:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier7e4fdec2013-12-02 15:46:51 -0800628 char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700629 char backgroundgcOptsBuf[sizeof("-XX:BackgroundGC=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700630 char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartierebc3b4c2017-10-15 21:13:28 -0700631 char foregroundHeapGrowthMultiplierOptsBuf[
632 sizeof("-XX:ForegroundHeapGrowthMultiplier=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee324ba02015-03-31 16:15:17 -0700633 char cachePruneBuf[sizeof("-Xzygote-max-boot-retry=")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700634 char dex2oatXmsImageFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
635 char dex2oatXmxImageFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
636 char dex2oatXmsFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
637 char dex2oatXmxFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700638 char dex2oatCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
639 char dex2oatImageCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee0352382015-03-30 18:43:39 -0700640 char dex2oatThreadsBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
641 char dex2oatThreadsImageBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
Andreas Gampe605cca12015-04-02 23:12:56 -0700642 char dex2oat_isa_variant_key[PROPERTY_KEY_MAX];
643 char dex2oat_isa_variant[sizeof("--instruction-set-variant=") -1 + PROPERTY_VALUE_MAX];
644 char dex2oat_isa_features_key[PROPERTY_KEY_MAX];
645 char dex2oat_isa_features[sizeof("--instruction-set-features=") -1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800646 char dex2oatFlagsBuf[PROPERTY_VALUE_MAX];
647 char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX];
Andy McFaddene4d81f22010-07-14 16:02:20 -0700648 char extraOptsBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700649 char voldDecryptBuf[PROPERTY_VALUE_MAX];
Ben Cheng52b0e732009-06-19 13:31:12 -0700650 enum {
651 kEMDefault,
652 kEMIntPortable,
653 kEMIntFast,
Ben Cheng52b0e732009-06-19 13:31:12 -0700654 kEMJitCompiler,
Ben Cheng52b0e732009-06-19 13:31:12 -0700655 } executionMode = kEMDefault;
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000656 char localeOption[sizeof("-Duser.locale=") + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700657 char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle01db9162014-08-07 14:45:53 +0100658 char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX];
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700659 char cpuAbiListBuf[sizeof("--cpu-abilist=") + PROPERTY_VALUE_MAX];
Andreas Gampe98f406f2015-06-22 21:09:36 -0700660 char methodTraceFileBuf[sizeof("-Xmethod-trace-file:") + PROPERTY_VALUE_MAX];
661 char methodTraceFileSizeBuf[sizeof("-Xmethod-trace-file-size:") + PROPERTY_VALUE_MAX];
Tom Cherry93099e42017-10-11 13:44:21 -0700662 std::string fingerprintBuf;
Alex Lightfffb2732017-11-20 13:01:01 -0800663 char jdwpProviderBuf[sizeof("-XjdwpProvider:") - 1 + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800664
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700665 bool checkJni = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 property_get("dalvik.vm.checkjni", propBuf, "");
667 if (strcmp(propBuf, "true") == 0) {
668 checkJni = true;
669 } else if (strcmp(propBuf, "false") != 0) {
670 /* property is neither true nor false; fall back on kernel parameter */
671 property_get("ro.kernel.android.checkjni", propBuf, "");
672 if (propBuf[0] == '1') {
673 checkJni = true;
674 }
675 }
Joe Onorato82ba91d2017-04-27 16:18:05 -0700676 ALOGV("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700677 if (checkJni) {
678 /* extended JNI checking */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700679 addOption("-Xcheck:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700680
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700681 /* with -Xcheck:jni, this provides a JNI function call trace */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700682 //addOption("-verbose:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700683 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684
685 property_get("dalvik.vm.execution-mode", propBuf, "");
686 if (strcmp(propBuf, "int:portable") == 0) {
687 executionMode = kEMIntPortable;
688 } else if (strcmp(propBuf, "int:fast") == 0) {
689 executionMode = kEMIntFast;
Ben Cheng52b0e732009-06-19 13:31:12 -0700690 } else if (strcmp(propBuf, "int:jit") == 0) {
691 executionMode = kEMJitCompiler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 }
693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694 strcpy(jniOptsBuf, "-Xjniopts:");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700695 if (parseRuntimeOption("dalvik.vm.jniopts", jniOptsBuf, "-Xjniopts:")) {
696 ALOGI("JNI options: '%s'\n", jniOptsBuf);
697 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800699 /* route exit() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700700 addOption("exit", (void*) runtime_exit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701
702 /* route fprintf() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700703 addOption("vfprintf", (void*) runtime_vfprintf);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800704
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800705 /* register the framework-specific "is sensitive thread" hook */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700706 addOption("sensitiveThread", (void*) runtime_isSensitiveThread);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707
708 /* enable verbose; standard options are { jni, gc, class } */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700709 //addOption("-verbose:jni");
710 addOption("-verbose:gc");
711 //addOption("-verbose:class");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800712
Carl Shapiro9e4c8842010-12-08 12:14:46 -0800713 /*
714 * The default starting and maximum size of the heap. Larger
715 * values should be specified in a product property override.
716 */
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700717 parseRuntimeOption("dalvik.vm.heapstartsize", heapstartsizeOptsBuf, "-Xms", "4m");
718 parseRuntimeOption("dalvik.vm.heapsize", heapsizeOptsBuf, "-Xmx", "16m");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700720 parseRuntimeOption("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
721 parseRuntimeOption("dalvik.vm.heapminfree", heapminfreeOptsBuf, "-XX:HeapMinFree=");
722 parseRuntimeOption("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf, "-XX:HeapMaxFree=");
723 parseRuntimeOption("dalvik.vm.heaptargetutilization",
724 heaptargetutilizationOptsBuf,
725 "-XX:HeapTargetUtilization=");
Ian Rogers53250102012-09-23 16:38:03 -0700726
Mathieu Chartierebc3b4c2017-10-15 21:13:28 -0700727 /* Foreground heap growth multiplier option */
728 parseRuntimeOption("dalvik.vm.foreground-heap-growth-multiplier",
729 foregroundHeapGrowthMultiplierOptsBuf,
730 "-XX:ForegroundHeapGrowthMultiplier=");
731
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800732 /*
733 * JIT related options.
734 */
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700735 parseRuntimeOption("dalvik.vm.usejit", usejitOptsBuf, "-Xusejit:");
Nicolas Geoffraycdf1dff2015-11-19 13:48:35 +0000736 parseRuntimeOption("dalvik.vm.jitmaxsize", jitmaxsizeOptsBuf, "-Xjitmaxsize:");
737 parseRuntimeOption("dalvik.vm.jitinitialsize", jitinitialsizeOptsBuf, "-Xjitinitialsize:");
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700738 parseRuntimeOption("dalvik.vm.jitthreshold", jitthresholdOptsBuf, "-Xjitthreshold:");
Nicolas Geoffray24934a92018-05-16 17:22:37 +0100739 parseRuntimeOption("dalvik.vm.jitpthreadpriority",
740 jitpthreadpriorityOptsBuf,
741 "-Xjitpthreadpriority:");
Calin Juravledb4a79a2015-12-23 18:55:08 +0200742 property_get("dalvik.vm.usejitprofiles", useJitProfilesOptsBuf, "");
743 if (strcmp(useJitProfilesOptsBuf, "true") == 0) {
744 addOption("-Xjitsaveprofilinginfo");
745 }
Calin Juravle8d74de52016-04-27 14:12:00 +0100746
Calin Juravle0de80b92016-04-12 14:12:04 +0100747 parseRuntimeOption("dalvik.vm.jitprithreadweight",
748 jitprithreadweightOptBuf,
749 "-Xjitprithreadweight:");
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800750
Calin Juravle8d74de52016-04-27 14:12:00 +0100751 parseRuntimeOption("dalvik.vm.jittransitionweight",
752 jittransitionweightOptBuf,
753 "-Xjittransitionweight:");
754
Calin Juravle62cd4bb2018-05-08 12:42:30 -0700755 property_get("dalvik.vm.profilebootimage", propBuf, "");
756 if (strcmp(propBuf, "true") == 0) {
757 addOption("-Xps-profile-boot-class-path");
758 addOption("-Xps-profile-aot-code");
759 }
760
Mathieu Chartier5eee0042017-06-07 17:34:22 -0700761 /*
Mathieu Chartiercd0caf52017-10-13 11:29:27 -0700762 * Madvise related options.
763 */
764 parseRuntimeOption("dalvik.vm.madvise-random", madviseRandomOptsBuf, "-XX:MadviseRandomAccess:");
765
766 /*
Mathieu Chartier5eee0042017-06-07 17:34:22 -0700767 * Profile related options.
768 */
769 parseRuntimeOption("dalvik.vm.hot-startup-method-samples", hotstartupsamplesOptsBuf,
770 "-Xps-hot-startup-method-samples:");
771
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700772 property_get("ro.config.low_ram", propBuf, "");
773 if (strcmp(propBuf, "true") == 0) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700774 addOption("-XX:LowMemoryMode");
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700775 }
776
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700777 parseRuntimeOption("dalvik.vm.gctype", gctypeOptsBuf, "-Xgc:");
778 parseRuntimeOption("dalvik.vm.backgroundgctype", backgroundgcOptsBuf, "-XX:BackgroundGC=");
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700779
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200780 /*
781 * Enable debugging only for apps forked from zygote.
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200782 */
783 if (zygote) {
Alex Lightc50928b2018-01-31 16:47:29 +0000784 // Set the JDWP provider and required arguments. By default let the runtime choose how JDWP is
785 // implemented. When this is not set the runtime defaults to not allowing JDWP.
Alex Lightfffb2732017-11-20 13:01:01 -0800786 addOption("-XjdwpOptions:suspend=n,server=y");
Alex Lightc50928b2018-01-31 16:47:29 +0000787 parseRuntimeOption("dalvik.vm.jdwp-provider",
788 jdwpProviderBuf,
789 "-XjdwpProvider:",
790 "default");
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200791 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800792
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700793 parseRuntimeOption("dalvik.vm.lockprof.threshold",
794 lockProfThresholdBuf,
795 "-Xlockprofthreshold:");
Carl Shapirod8f3ec62010-04-12 16:31:59 -0700796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797 if (executionMode == kEMIntPortable) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700798 addOption("-Xint:portable");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 } else if (executionMode == kEMIntFast) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700800 addOption("-Xint:fast");
Ben Cheng52b0e732009-06-19 13:31:12 -0700801 } else if (executionMode == kEMJitCompiler) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700802 addOption("-Xint:jit");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800803 }
Andy McFaddene2b23e12009-04-03 11:09:46 -0700804
Andreas Gampe08b2d582014-12-18 14:39:22 -0800805 // If we are booting without the real /data, don't spend time compiling.
806 property_get("vold.decrypt", voldDecryptBuf, "");
807 bool skip_compilation = ((strcmp(voldDecryptBuf, "trigger_restart_min_framework") == 0) ||
808 (strcmp(voldDecryptBuf, "1") == 0));
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800809
Andreas Gampe08b2d582014-12-18 14:39:22 -0800810 // Extra options for boot.art/boot.oat image generation.
811 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xms", dex2oatXmsImageFlagsBuf,
812 "-Xms", "-Ximage-compiler-option");
813 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xmx", dex2oatXmxImageFlagsBuf,
814 "-Xmx", "-Ximage-compiler-option");
815 if (skip_compilation) {
Brian Carlstromce5bbbe2014-07-30 15:13:17 -0700816 addOption("-Ximage-compiler-option");
Nicolas Geoffraybe7b0d12017-04-25 12:29:07 +0100817 addOption("--compiler-filter=assume-verified");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800818 } else {
819 parseCompilerOption("dalvik.vm.image-dex2oat-filter", dex2oatImageCompilerFilterBuf,
820 "--compiler-filter=", "-Ximage-compiler-option");
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800821 }
822
Mathieu Chartierf99e70e2017-06-30 11:47:38 -0700823 // If there is a boot profile, it takes precedence over the image and preloaded classes.
824 if (hasFile("/system/etc/boot-image.prof")) {
Andreas Gampe08b2d582014-12-18 14:39:22 -0800825 addOption("-Ximage-compiler-option");
Mathieu Chartierf99e70e2017-06-30 11:47:38 -0700826 addOption("--profile-file=/system/etc/boot-image.prof");
827 addOption("-Ximage-compiler-option");
828 addOption("--compiler-filter=speed-profile");
829 } else {
830 // Make sure there is a preloaded-classes file.
831 if (!hasFile("/system/etc/preloaded-classes")) {
832 ALOGE("Missing preloaded-classes file, /system/etc/preloaded-classes not found: %s\n",
833 strerror(errno));
834 return -1;
835 }
836 addOption("-Ximage-compiler-option");
837 addOption("--image-classes=/system/etc/preloaded-classes");
838
Jeff Hao37641ae2017-07-31 13:35:01 -0700839 // If there is a dirty-image-objects file, push it.
840 if (hasFile("/system/etc/dirty-image-objects")) {
841 addOption("-Ximage-compiler-option");
842 addOption("--dirty-image-objects=/system/etc/dirty-image-objects");
843 }
Andreas Gampe08b2d582014-12-18 14:39:22 -0800844 }
845
846 property_get("dalvik.vm.image-dex2oat-flags", dex2oatImageFlagsBuf, "");
847 parseExtraOpts(dex2oatImageFlagsBuf, "-Ximage-compiler-option");
848
849 // Extra options for DexClassLoader.
850 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xms", dex2oatXmsFlagsBuf,
851 "-Xms", "-Xcompiler-option");
852 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xmx", dex2oatXmxFlagsBuf,
853 "-Xmx", "-Xcompiler-option");
854 if (skip_compilation) {
855 addOption("-Xcompiler-option");
Nicolas Geoffraybe7b0d12017-04-25 12:29:07 +0100856 addOption("--compiler-filter=assume-verified");
neo.chae155118f2015-01-07 15:32:15 +0900857
858 // We skip compilation when a minimal runtime is brought up for decryption. In that case
859 // /data is temporarily backed by a tmpfs, which is usually small.
860 // If the system image contains prebuilts, they will be relocated into the tmpfs. In this
861 // specific situation it is acceptable to *not* relocate and run out of the prebuilts
862 // directly instead.
863 addOption("--runtime-arg");
864 addOption("-Xnorelocate");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800865 } else {
866 parseCompilerOption("dalvik.vm.dex2oat-filter", dex2oatCompilerFilterBuf,
867 "--compiler-filter=", "-Xcompiler-option");
868 }
Andreas Gampee0352382015-03-30 18:43:39 -0700869 parseCompilerOption("dalvik.vm.dex2oat-threads", dex2oatThreadsBuf, "-j", "-Xcompiler-option");
870 parseCompilerOption("dalvik.vm.image-dex2oat-threads", dex2oatThreadsImageBuf, "-j",
871 "-Ximage-compiler-option");
Andreas Gampe605cca12015-04-02 23:12:56 -0700872
873 // The runtime will compile a boot image, when necessary, not using installd. Thus, we need to
874 // pass the instruction-set-features/variant as an image-compiler-option.
Andreas Gampe605cca12015-04-02 23:12:56 -0700875 // Note: it is OK to reuse the buffer, as the values are exactly the same between
876 // * compiler-option, used for runtime compilation (DexClassLoader)
877 // * image-compiler-option, used for boot-image compilation on device
878
879 // Copy the variant.
Elliott Hughesa1194cb2018-03-23 11:27:04 -0700880 sprintf(dex2oat_isa_variant_key, "dalvik.vm.isa.%s.variant", ABI_STRING);
Andreas Gampe605cca12015-04-02 23:12:56 -0700881 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
882 "--instruction-set-variant=", "-Ximage-compiler-option");
883 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
884 "--instruction-set-variant=", "-Xcompiler-option");
885 // Copy the features.
Elliott Hughesa1194cb2018-03-23 11:27:04 -0700886 sprintf(dex2oat_isa_features_key, "dalvik.vm.isa.%s.features", ABI_STRING);
Andreas Gampe605cca12015-04-02 23:12:56 -0700887 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
888 "--instruction-set-features=", "-Ximage-compiler-option");
889 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
890 "--instruction-set-features=", "-Xcompiler-option");
891
892
Andreas Gampe08b2d582014-12-18 14:39:22 -0800893 property_get("dalvik.vm.dex2oat-flags", dex2oatFlagsBuf, "");
894 parseExtraOpts(dex2oatFlagsBuf, "-Xcompiler-option");
895
Andy McFaddene4d81f22010-07-14 16:02:20 -0700896 /* extra options; parse this late so it overrides others */
897 property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800898 parseExtraOpts(extraOptsBuf, NULL);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 /* Set the properties for locale */
901 {
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000902 strcpy(localeOption, "-Duser.locale=");
Narayan Kamathbf882052015-08-11 15:40:34 +0100903 const std::string locale = readLocale();
904 strncat(localeOption, locale.c_str(), PROPERTY_VALUE_MAX);
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000905 addOption(localeOption);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 }
907
Calin Juravle92290b82015-11-10 19:30:45 +0000908 // Trace files are stored in /data/misc/trace which is writable only in debug mode.
909 property_get("ro.debuggable", propBuf, "0");
910 if (strcmp(propBuf, "1") == 0) {
911 property_get("dalvik.vm.method-trace", propBuf, "false");
Andreas Gampe98f406f2015-06-22 21:09:36 -0700912 if (strcmp(propBuf, "true") == 0) {
Calin Juravle92290b82015-11-10 19:30:45 +0000913 addOption("-Xmethod-trace");
914 parseRuntimeOption("dalvik.vm.method-trace-file",
915 methodTraceFileBuf,
916 "-Xmethod-trace-file:");
917 parseRuntimeOption("dalvik.vm.method-trace-file-siz",
918 methodTraceFileSizeBuf,
919 "-Xmethod-trace-file-size:");
920 property_get("dalvik.vm.method-trace-stream", propBuf, "false");
921 if (strcmp(propBuf, "true") == 0) {
922 addOption("-Xmethod-trace-stream");
923 }
Andreas Gampe98f406f2015-06-22 21:09:36 -0700924 }
925 }
926
Andreas Gampe08b2d582014-12-18 14:39:22 -0800927 // Native bridge library. "0" means that native bridge is disabled.
Andreas Gampe14a1cd92018-06-07 09:42:02 -0700928 //
929 // Note: bridging is only enabled for the zygote. Other runs of
930 // app_process may not have the permissions to mount etc.
Andreas Gampe08b2d582014-12-18 14:39:22 -0800931 property_get("ro.dalvik.vm.native.bridge", propBuf, "");
932 if (propBuf[0] == '\0') {
933 ALOGW("ro.dalvik.vm.native.bridge is not expected to be empty");
Andreas Gampe14a1cd92018-06-07 09:42:02 -0700934 } else if (zygote && strcmp(propBuf, "0") != 0) {
Andreas Gampe08b2d582014-12-18 14:39:22 -0800935 snprintf(nativeBridgeLibrary, sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX,
936 "-XX:NativeBridge=%s", propBuf);
937 addOption(nativeBridgeLibrary);
Calin Juravlebe20ed42014-08-26 23:00:11 +0100938 }
Calin Juravle01db9162014-08-07 14:45:53 +0100939
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700940#if defined(__LP64__)
941 const char* cpu_abilist_property_name = "ro.product.cpu.abilist64";
942#else
943 const char* cpu_abilist_property_name = "ro.product.cpu.abilist32";
944#endif // defined(__LP64__)
945 property_get(cpu_abilist_property_name, propBuf, "");
946 if (propBuf[0] == '\0') {
947 ALOGE("%s is not expected to be empty", cpu_abilist_property_name);
948 return -1;
949 }
950 snprintf(cpuAbiListBuf, sizeof(cpuAbiListBuf), "--cpu-abilist=%s", propBuf);
951 addOption(cpuAbiListBuf);
952
Andreas Gampee324ba02015-03-31 16:15:17 -0700953 // Dalvik-cache pruning counter.
954 parseRuntimeOption("dalvik.vm.zygote.max-boot-retry", cachePruneBuf,
955 "-Xzygote-max-boot-retry=");
956
Andreas Gampe27c39f12015-04-27 18:28:18 +0000957 /*
David Srbecky065075e2015-05-28 17:16:09 +0100958 * When running with debug.generate-debug-info, add --generate-debug-info to
959 * the compiler options so that the boot image, if it is compiled on device,
960 * will include native debugging information.
Andreas Gampe27c39f12015-04-27 18:28:18 +0000961 */
David Srbecky065075e2015-05-28 17:16:09 +0100962 property_get("debug.generate-debug-info", propBuf, "");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000963 if (strcmp(propBuf, "true") == 0) {
964 addOption("-Xcompiler-option");
David Srbecky065075e2015-05-28 17:16:09 +0100965 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000966 addOption("-Ximage-compiler-option");
David Srbecky065075e2015-05-28 17:16:09 +0100967 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000968 }
969
David Srbecky3bb32502018-01-23 17:57:24 +0000970 // The mini-debug-info makes it possible to backtrace through JIT code.
971 if (property_get_bool("dalvik.vm.minidebuginfo", 0)) {
972 addOption("-Xcompiler-option");
973 addOption("--generate-mini-debug-info");
974 }
975
Andreas Gampee6082502015-07-24 14:19:44 -0700976 /*
977 * Retrieve the build fingerprint and provide it to the runtime. That way, ANR dumps will
978 * contain the fingerprint and can be parsed.
Tom Cherry93099e42017-10-11 13:44:21 -0700979 * Fingerprints are potentially longer than PROPERTY_VALUE_MAX, so parseRuntimeOption() cannot
980 * be used here.
981 * Do not ever re-assign fingerprintBuf as its c_str() value is stored in mOptions.
Andreas Gampee6082502015-07-24 14:19:44 -0700982 */
Tom Cherry93099e42017-10-11 13:44:21 -0700983 std::string fingerprint = GetProperty("ro.build.fingerprint", "");
984 if (!fingerprint.empty()) {
985 fingerprintBuf = "-Xfingerprint:" + fingerprint;
986 addOption(fingerprintBuf.c_str());
987 }
Andreas Gampee6082502015-07-24 14:19:44 -0700988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 initArgs.version = JNI_VERSION_1_4;
990 initArgs.options = mOptions.editArray();
991 initArgs.nOptions = mOptions.size();
992 initArgs.ignoreUnrecognized = JNI_FALSE;
993
994 /*
995 * Initialize the VM.
996 *
997 * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread.
998 * If this call succeeds, the VM is ready, and we can start issuing
999 * JNI calls.
1000 */
Andy McFaddenf70188a2009-03-31 15:52:13 -07001001 if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001002 ALOGE("JNI_CreateJavaVM failed\n");
Dmitriy Ivanovff193d62014-09-30 15:10:48 -07001003 return -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004 }
1005
Dmitriy Ivanovff193d62014-09-30 15:10:48 -07001006 return 0;
Andy McFaddenf70188a2009-03-31 15:52:13 -07001007}
1008
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001009char* AndroidRuntime::toSlashClassName(const char* className)
1010{
1011 char* result = strdup(className);
1012 for (char* cp = result; *cp != '\0'; cp++) {
1013 if (*cp == '.') {
1014 *cp = '/';
1015 }
1016 }
1017 return result;
1018}
1019
Mike Lockwood9ee5e7e2014-09-08 16:15:21 -07001020/** Create a Java string from an ASCII or Latin-1 string */
1021jstring AndroidRuntime::NewStringLatin1(JNIEnv* env, const char* bytes) {
1022 if (!bytes) return NULL;
1023 int length = strlen(bytes);
1024 jchar* buffer = (jchar *)alloca(length * sizeof(jchar));
1025 if (!buffer) return NULL;
1026 jchar* chp = buffer;
1027 for (int i = 0; i < length; i++) {
1028 *chp++ = *bytes++;
1029 }
1030 return env->NewString(buffer, length);
1031}
1032
1033
Andy McFaddenf70188a2009-03-31 15:52:13 -07001034/*
1035 * Start the Android runtime. This involves starting the virtual machine
1036 * and calling the "static void main(String[] args)" method in the class
1037 * named by "className".
Jeff Brownebed7d62011-05-16 17:08:42 -07001038 *
1039 * Passes the main function two arguments, the class name and the specified
1040 * options string.
Andy McFaddenf70188a2009-03-31 15:52:13 -07001041 */
Sebastien Hertz7a09b832015-08-10 18:55:34 +02001042void AndroidRuntime::start(const char* className, const Vector<String8>& options, bool zygote)
Andy McFaddenf70188a2009-03-31 15:52:13 -07001043{
Dianne Hackborn8e5aafe2014-10-27 18:04:10 -07001044 ALOGD(">>>>>> START %s uid %d <<<<<<\n",
1045 className != NULL ? className : "(unknown)", getuid());
Andy McFaddenf70188a2009-03-31 15:52:13 -07001046
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001047 static const String8 startSystemServer("start-system-server");
1048
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001049 /*
1050 * 'startSystemServer == true' means runtime is obsolete and not run from
Andy McFaddenf70188a2009-03-31 15:52:13 -07001051 * init.rc anymore, so we print out the boot start event here.
1052 */
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001053 for (size_t i = 0; i < options.size(); ++i) {
1054 if (options[i] == startSystemServer) {
1055 /* track our progress through the boot sequence */
1056 const int LOG_BOOT_PROGRESS_START = 3000;
1057 LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));
1058 }
Andy McFaddenf70188a2009-03-31 15:52:13 -07001059 }
1060
1061 const char* rootDir = getenv("ANDROID_ROOT");
1062 if (rootDir == NULL) {
1063 rootDir = "/system";
1064 if (!hasDir("/system")) {
Neil Fuller3ce4cce2018-11-23 19:00:32 +00001065 LOG_FATAL("No root directory specified, and /system does not exist.");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001066 return;
Andy McFaddenf70188a2009-03-31 15:52:13 -07001067 }
1068 setenv("ANDROID_ROOT", rootDir, 1);
1069 }
1070
Neil Fuller3ce4cce2018-11-23 19:00:32 +00001071 const char* runtimeRootDir = getenv("ANDROID_RUNTIME_ROOT");
1072 if (runtimeRootDir == NULL) {
1073 LOG_FATAL("No runtime directory specified with ANDROID_RUNTIME_ROOT environment variable.");
1074 return;
1075 }
1076
Andy McFaddenf70188a2009-03-31 15:52:13 -07001077 //const char* kernelHack = getenv("LD_ASSUME_KERNEL");
Steve Block5baa3a62011-12-20 16:23:08 +00001078 //ALOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001079
1080 /* start the virtual machine */
Brian Carlstrom9f8203a2013-06-19 13:49:36 -07001081 JniInvocation jni_invocation;
1082 jni_invocation.Init(NULL);
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001083 JNIEnv* env;
Sebastien Hertz7a09b832015-08-10 18:55:34 +02001084 if (startVm(&mJavaVM, &env, zygote) != 0) {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001085 return;
1086 }
1087 onVmCreated(env);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 /*
1090 * Register android functions.
1091 */
1092 if (startReg(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001093 ALOGE("Unable to register all android natives\n");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001094 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 }
1096
1097 /*
1098 * We want to call main() with a String array with arguments in it.
Jeff Brownebed7d62011-05-16 17:08:42 -07001099 * At present we have two arguments, the class name and an option string.
1100 * Create an array to hold them.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 */
1102 jclass stringClass;
1103 jobjectArray strArray;
1104 jstring classNameStr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105
1106 stringClass = env->FindClass("java/lang/String");
1107 assert(stringClass != NULL);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001108 strArray = env->NewObjectArray(options.size() + 1, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 assert(strArray != NULL);
1110 classNameStr = env->NewStringUTF(className);
1111 assert(classNameStr != NULL);
1112 env->SetObjectArrayElement(strArray, 0, classNameStr);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001113
1114 for (size_t i = 0; i < options.size(); ++i) {
1115 jstring optionsStr = env->NewStringUTF(options.itemAt(i).string());
1116 assert(optionsStr != NULL);
1117 env->SetObjectArrayElement(strArray, i + 1, optionsStr);
1118 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119
1120 /*
1121 * Start VM. This thread becomes the main thread of the VM, and will
1122 * not return until the VM exits.
1123 */
George Burgess IVd657a382017-06-20 23:53:29 -07001124 char* slashClassName = toSlashClassName(className != NULL ? className : "");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001125 jclass startClass = env->FindClass(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 if (startClass == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001127 ALOGE("JavaVM unable to locate class '%s'\n", slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 /* keep going */
1129 } else {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001130 jmethodID startMeth = env->GetStaticMethodID(startClass, "main",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 "([Ljava/lang/String;)V");
1132 if (startMeth == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001133 ALOGE("JavaVM unable to find main() in '%s'\n", className);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 /* keep going */
1135 } else {
1136 env->CallStaticVoidMethod(startClass, startMeth, strArray);
1137
1138#if 0
1139 if (env->ExceptionCheck())
1140 threadExitUncaughtException(env);
1141#endif
1142 }
1143 }
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001144 free(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145
Steve Block5baa3a62011-12-20 16:23:08 +00001146 ALOGD("Shutting down VM\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001147 if (mJavaVM->DetachCurrentThread() != JNI_OK)
Steve Block8564c8d2012-01-05 23:22:43 +00001148 ALOGW("Warning: unable to detach main thread\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 if (mJavaVM->DestroyJavaVM() != 0)
Steve Block8564c8d2012-01-05 23:22:43 +00001150 ALOGW("Warning: VM did not shut down cleanly\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151}
1152
Jeff Brown4280c4a2012-03-15 17:48:02 -07001153void AndroidRuntime::exit(int code)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154{
Jeff Brown4280c4a2012-03-15 17:48:02 -07001155 if (mExitWithoutCleanup) {
1156 ALOGI("VM exiting with result code %d, cleanup skipped.", code);
1157 ::_exit(code);
1158 } else {
1159 ALOGI("VM exiting with result code %d.", code);
1160 onExit(code);
1161 ::exit(code);
1162 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001163}
1164
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001165void AndroidRuntime::onVmCreated(JNIEnv* env)
1166{
1167 // If AndroidRuntime had anything to do here, we'd have done it in 'start'.
1168}
1169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170/*
Andreas Huber9ae000c2014-02-13 17:22:33 +00001171 * Get the JNIEnv pointer for this thread.
1172 *
1173 * Returns NULL if the slot wasn't allocated or populated.
1174 */
1175/*static*/ JNIEnv* AndroidRuntime::getJNIEnv()
1176{
1177 JNIEnv* env;
1178 JavaVM* vm = AndroidRuntime::getJavaVM();
1179 assert(vm != NULL);
1180
1181 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
1182 return NULL;
1183 return env;
1184}
1185
1186/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001187 * Makes the current thread visible to the VM.
1188 *
1189 * The JNIEnv pointer returned is only valid for the current thread, and
1190 * thus must be tucked into thread-local storage.
1191 */
1192static int javaAttachThread(const char* threadName, JNIEnv** pEnv)
1193{
1194 JavaVMAttachArgs args;
1195 JavaVM* vm;
1196 jint result;
1197
1198 vm = AndroidRuntime::getJavaVM();
1199 assert(vm != NULL);
1200
1201 args.version = JNI_VERSION_1_4;
1202 args.name = (char*) threadName;
1203 args.group = NULL;
1204
1205 result = vm->AttachCurrentThread(pEnv, (void*) &args);
1206 if (result != JNI_OK)
Steve Block6215d3f2012-01-04 20:05:49 +00001207 ALOGI("NOTE: attach of thread '%s' failed\n", threadName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208
1209 return result;
1210}
1211
1212/*
1213 * Detach the current thread from the set visible to the VM.
1214 */
1215static int javaDetachThread(void)
1216{
1217 JavaVM* vm;
1218 jint result;
1219
1220 vm = AndroidRuntime::getJavaVM();
1221 assert(vm != NULL);
1222
1223 result = vm->DetachCurrentThread();
1224 if (result != JNI_OK)
Steve Block3762c312012-01-06 19:20:56 +00001225 ALOGE("ERROR: thread detach failed\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 return result;
1227}
1228
1229/*
1230 * When starting a native thread that will be visible from the VM, we
1231 * bounce through this to get the right attach/detach action.
1232 * Note that this function calls free(args)
1233 */
1234/*static*/ int AndroidRuntime::javaThreadShell(void* args) {
1235 void* start = ((void**)args)[0];
1236 void* userData = ((void **)args)[1];
1237 char* name = (char*) ((void **)args)[2]; // we own this storage
1238 free(args);
1239 JNIEnv* env;
1240 int result;
1241
1242 /* hook us into the VM */
1243 if (javaAttachThread(name, &env) != JNI_OK)
1244 return -1;
1245
1246 /* start the thread running */
1247 result = (*(android_thread_func_t)start)(userData);
1248
1249 /* unhook us */
1250 javaDetachThread();
1251 free(name);
1252
1253 return result;
1254}
1255
1256/*
1257 * This is invoked from androidCreateThreadEtc() via the callback
1258 * set with androidSetCreateThreadFunc().
1259 *
1260 * We need to create the new thread in such a way that it gets hooked
1261 * into the VM before it really starts executing.
1262 */
1263/*static*/ int AndroidRuntime::javaCreateThreadEtc(
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001264 android_thread_func_t entryFunction,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 void* userData,
1266 const char* threadName,
1267 int32_t threadPriority,
1268 size_t threadStackSize,
1269 android_thread_id_t* threadId)
1270{
1271 void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free
1272 int result;
1273
Brian Carlstrom66f48312016-03-12 16:07:48 -08001274 LOG_ALWAYS_FATAL_IF(threadName == nullptr, "threadName not provided to javaCreateThreadEtc");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275
1276 args[0] = (void*) entryFunction;
1277 args[1] = userData;
1278 args[2] = (void*) strdup(threadName); // javaThreadShell must free
1279
1280 result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args,
1281 threadName, threadPriority, threadStackSize, threadId);
1282 return result;
1283}
1284
1285/*
1286 * Create a thread that is visible from the VM.
1287 *
1288 * This is called from elsewhere in the library.
1289 */
Mike Lockwoodf602d362010-06-20 14:28:16 -07001290/*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001291 void (*start)(void *), void* arg)
1292{
Mike Lockwoodf602d362010-06-20 14:28:16 -07001293 android_thread_id_t threadId = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001294 javaCreateThreadEtc((android_thread_func_t) start, arg, name,
Mike Lockwoodf602d362010-06-20 14:28:16 -07001295 ANDROID_PRIORITY_DEFAULT, 0, &threadId);
1296 return threadId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001297}
1298
1299#if 0
1300static void quickTest(void* arg)
1301{
1302 const char* str = (const char*) arg;
1303
1304 printf("In quickTest: %s\n", str);
1305}
1306#endif
1307
1308#ifdef NDEBUG
1309 #define REG_JNI(name) { name }
1310 struct RegJNIRec {
1311 int (*mProc)(JNIEnv*);
1312 };
1313#else
1314 #define REG_JNI(name) { name, #name }
1315 struct RegJNIRec {
1316 int (*mProc)(JNIEnv*);
1317 const char* mName;
1318 };
1319#endif
1320
1321typedef void (*RegJAMProc)();
1322
1323static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env)
1324{
1325 for (size_t i = 0; i < count; i++) {
1326 if (array[i].mProc(env) < 0) {
1327#ifndef NDEBUG
Steve Block5baa3a62011-12-20 16:23:08 +00001328 ALOGD("----------!!! %s failed to load\n", array[i].mName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329#endif
1330 return -1;
1331 }
1332 }
1333 return 0;
1334}
1335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001336static const RegJNIRec gRegJNI[] = {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001337 REG_JNI(register_com_android_internal_os_RuntimeInit),
Jesse Hall1fe1dc02017-07-06 15:30:39 -07001338 REG_JNI(register_com_android_internal_os_ZygoteInit_nativeZygoteInit),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001339 REG_JNI(register_android_os_SystemClock),
1340 REG_JNI(register_android_util_EventLog),
1341 REG_JNI(register_android_util_Log),
Svet Ganov53a441c2016-04-19 19:38:00 -07001342 REG_JNI(register_android_util_MemoryIntArray),
Doris Liucdd23f92015-11-11 14:31:13 -08001343 REG_JNI(register_android_util_PathParser),
Yao Chend54f9dd2017-10-17 17:37:48 +00001344 REG_JNI(register_android_util_StatsLog),
Michal Karpinski6235a942016-03-15 12:07:23 +00001345 REG_JNI(register_android_app_admin_SecurityLog),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001346 REG_JNI(register_android_content_AssetManager),
1347 REG_JNI(register_android_content_StringBlock),
1348 REG_JNI(register_android_content_XmlBlock),
Adam Lesinskibebfcc42018-02-12 14:27:46 -08001349 REG_JNI(register_android_content_res_ApkAssets),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001350 REG_JNI(register_android_text_AndroidCharacter),
Seigo Nonaka44a1df22017-08-31 18:22:38 -07001351 REG_JNI(register_android_text_Hyphenator),
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001352 REG_JNI(register_android_view_InputDevice),
1353 REG_JNI(register_android_view_KeyCharacterMap),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001354 REG_JNI(register_android_os_Process),
Andreas Hubera8079bf2010-11-16 14:40:31 -08001355 REG_JNI(register_android_os_SystemProperties),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356 REG_JNI(register_android_os_Binder),
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -08001357 REG_JNI(register_android_os_Parcel),
Yifan Hongbb0bd002017-11-14 16:14:04 -08001358 REG_JNI(register_android_os_HidlSupport),
Andreas Huberc0b6c532016-08-15 09:25:02 -07001359 REG_JNI(register_android_os_HwBinder),
Andreas Huberdc263212016-08-25 11:21:21 -07001360 REG_JNI(register_android_os_HwBlob),
Andreas Huberc0b6c532016-08-15 09:25:02 -07001361 REG_JNI(register_android_os_HwParcel),
1362 REG_JNI(register_android_os_HwRemoteBinder),
Nirav Atre9850dd92018-07-24 17:03:44 -07001363 REG_JNI(register_android_os_NativeHandle),
Yifan Hongbecc56d2017-04-05 14:42:05 -07001364 REG_JNI(register_android_os_VintfObject),
Yifan Hong1bda6732017-04-26 11:38:01 -07001365 REG_JNI(register_android_os_VintfRuntimeInfo),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001366 REG_JNI(register_android_nio_utils),
Richard Uhler775873a2015-12-29 12:37:39 -08001367 REG_JNI(register_android_graphics_Canvas),
Leon Scroggins III0e443d12018-12-19 11:38:35 -05001368 // This needs to be before register_android_graphics_Graphics, or the latter
1369 // will not be able to find the jmethodID for ColorSpace.get().
1370 REG_JNI(register_android_graphics_ColorSpace),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001371 REG_JNI(register_android_graphics_Graphics),
Chris Craik54389792013-12-20 13:28:11 -08001372 REG_JNI(register_android_view_DisplayEventReceiver),
John Reckf666ad72014-03-14 16:24:57 -07001373 REG_JNI(register_android_view_RenderNode),
John Recke45b1fd2014-04-15 09:50:16 -07001374 REG_JNI(register_android_view_RenderNodeAnimator),
Chris Craikc9070eb2015-03-09 18:50:14 -07001375 REG_JNI(register_android_view_DisplayListCanvas),
Riddle Hsucd958bc2019-01-23 15:40:26 +08001376 REG_JNI(register_android_view_InputApplicationHandle),
1377 REG_JNI(register_android_view_InputWindowHandle),
John Reck9d8d99d2018-02-21 12:55:41 -08001378 REG_JNI(register_android_view_TextureLayer),
John Reckcec24ae2013-11-05 13:27:50 -08001379 REG_JNI(register_android_view_ThreadedRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001380 REG_JNI(register_android_view_Surface),
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001381 REG_JNI(register_android_view_SurfaceControl),
Jeff Brown64a55af2012-08-26 02:47:39 -07001382 REG_JNI(register_android_view_SurfaceSession),
Romain Guy8f0095c2011-05-02 17:24:22 -07001383 REG_JNI(register_android_view_TextureView),
John Reck315c3292014-05-09 19:21:04 -07001384 REG_JNI(register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001385 REG_JNI(register_com_google_android_gles_jni_EGLImpl),
1386 REG_JNI(register_com_google_android_gles_jni_GLImpl),
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001387 REG_JNI(register_android_opengl_jni_EGL14),
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -06001388 REG_JNI(register_android_opengl_jni_EGL15),
Jesse Hall237c2b82013-05-06 11:36:57 -07001389 REG_JNI(register_android_opengl_jni_EGLExt),
Jack Palevich1c4907e2009-04-13 16:22:25 -07001390 REG_JNI(register_android_opengl_jni_GLES10),
1391 REG_JNI(register_android_opengl_jni_GLES10Ext),
1392 REG_JNI(register_android_opengl_jni_GLES11),
1393 REG_JNI(register_android_opengl_jni_GLES11Ext),
Jack Palevich560814f2009-11-19 16:34:55 +08001394 REG_JNI(register_android_opengl_jni_GLES20),
Jesse Halld877efe2013-04-29 15:59:35 -07001395 REG_JNI(register_android_opengl_jni_GLES30),
Jesse Hall7ab63ac2014-05-19 15:13:41 -07001396 REG_JNI(register_android_opengl_jni_GLES31),
1397 REG_JNI(register_android_opengl_jni_GLES31Ext),
Pablo Ceballos38c1a7e2015-10-30 10:34:30 -07001398 REG_JNI(register_android_opengl_jni_GLES32),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001399
1400 REG_JNI(register_android_graphics_Bitmap),
1401 REG_JNI(register_android_graphics_BitmapFactory),
Wei-Ta Chen6b849e22010-09-07 17:32:18 +08001402 REG_JNI(register_android_graphics_BitmapRegionDecoder),
Leon Scroggins III0c01dbf2017-10-20 14:08:11 -04001403 REG_JNI(register_android_graphics_ByteBufferStreamAdaptor),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001404 REG_JNI(register_android_graphics_Camera),
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -04001405 REG_JNI(register_android_graphics_CreateJavaOutputStreamAdaptor),
John Reck52244ff2014-05-01 21:27:37 -07001406 REG_JNI(register_android_graphics_CanvasProperty),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001407 REG_JNI(register_android_graphics_ColorFilter),
1408 REG_JNI(register_android_graphics_DrawFilter),
Raph Levien1a73f7322014-01-30 16:06:28 -08001409 REG_JNI(register_android_graphics_FontFamily),
sergeyv0a0f2312017-01-04 13:58:52 -08001410 REG_JNI(register_android_graphics_GraphicBuffer),
Leon Scroggins III0c01dbf2017-10-20 14:08:11 -04001411 REG_JNI(register_android_graphics_ImageDecoder),
Leon Scroggins III671cce22018-01-14 16:52:17 -05001412 REG_JNI(register_android_graphics_drawable_AnimatedImageDrawable),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001413 REG_JNI(register_android_graphics_Interpolator),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001414 REG_JNI(register_android_graphics_MaskFilter),
1415 REG_JNI(register_android_graphics_Matrix),
1416 REG_JNI(register_android_graphics_Movie),
1417 REG_JNI(register_android_graphics_NinePatch),
1418 REG_JNI(register_android_graphics_Paint),
1419 REG_JNI(register_android_graphics_Path),
1420 REG_JNI(register_android_graphics_PathMeasure),
1421 REG_JNI(register_android_graphics_PathEffect),
1422 REG_JNI(register_android_graphics_Picture),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001423 REG_JNI(register_android_graphics_Region),
1424 REG_JNI(register_android_graphics_Shader),
Jamie Gennisaa0ce332011-01-06 17:04:26 -08001425 REG_JNI(register_android_graphics_SurfaceTexture),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001426 REG_JNI(register_android_graphics_Typeface),
Wei-Ta Chenbca2d612009-11-30 17:52:05 +08001427 REG_JNI(register_android_graphics_YuvImage),
Doris Liu766431a2016-02-04 22:17:11 +00001428 REG_JNI(register_android_graphics_drawable_AnimatedVectorDrawable),
Doris Liu4bbc2932015-12-01 17:59:40 -08001429 REG_JNI(register_android_graphics_drawable_VectorDrawable),
Seigo Nonakaa1c21c02018-07-20 15:57:39 -07001430 REG_JNI(register_android_graphics_fonts_Font),
Seigo Nonaka88930f12018-07-24 17:09:23 -07001431 REG_JNI(register_android_graphics_fonts_FontFamily),
Svetoslav6811f4e2013-09-18 15:58:28 -07001432 REG_JNI(register_android_graphics_pdf_PdfDocument),
Svetoslav62ce3322014-09-04 21:17:17 -07001433 REG_JNI(register_android_graphics_pdf_PdfEditor),
Svetoslav29617692014-04-24 18:40:42 -07001434 REG_JNI(register_android_graphics_pdf_PdfRenderer),
Seigo Nonaka70200b02018-10-01 16:04:11 -07001435 REG_JNI(register_android_graphics_text_MeasuredText),
1436 REG_JNI(register_android_graphics_text_LineBreaker),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437
1438 REG_JNI(register_android_database_CursorWindow),
Jeff Browne5360fb2011-10-31 17:48:13 -07001439 REG_JNI(register_android_database_SQLiteConnection),
1440 REG_JNI(register_android_database_SQLiteGlobal),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001441 REG_JNI(register_android_database_SQLiteDebug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001442 REG_JNI(register_android_os_Debug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001443 REG_JNI(register_android_os_FileObserver),
Jesse Hallb12249b2016-12-12 12:53:02 -08001444 REG_JNI(register_android_os_GraphicsEnvironment),
Christopher Tatefa9e7c02010-05-06 12:07:10 -07001445 REG_JNI(register_android_os_MessageQueue),
Stephen Smalleyc07fca32012-01-13 08:31:39 -05001446 REG_JNI(register_android_os_SELinux),
Jeff Brown481c1572012-03-09 14:41:15 -08001447 REG_JNI(register_android_os_Trace),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001448 REG_JNI(register_android_os_UEventObserver),
1449 REG_JNI(register_android_net_LocalSocketImpl),
1450 REG_JNI(register_android_net_NetworkUtils),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001451 REG_JNI(register_android_os_MemoryFile),
John Reckdea6a022017-05-25 17:09:33 -07001452 REG_JNI(register_android_os_SharedMemory),
Narayan Kamathf9419f02017-06-15 11:35:38 +01001453 REG_JNI(register_com_android_internal_os_ClassLoaderFactory),
Narayan Kamath973b4662014-03-31 13:41:26 +01001454 REG_JNI(register_com_android_internal_os_Zygote),
Jesse Hall1fe1dc02017-07-06 15:30:39 -07001455 REG_JNI(register_com_android_internal_os_ZygoteInit),
John Reck9fa40712014-05-09 15:26:59 -07001456 REG_JNI(register_com_android_internal_util_VirtualRefBasePtr),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001457 REG_JNI(register_android_hardware_Camera),
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07001458 REG_JNI(register_android_hardware_camera2_CameraMetadata),
Ruben Brunkfeb50af2014-05-09 19:58:49 -07001459 REG_JNI(register_android_hardware_camera2_legacy_LegacyCameraDevice),
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -07001460 REG_JNI(register_android_hardware_camera2_legacy_PerfMeasurement),
Ruben Brunkb6079002014-05-22 12:33:54 -07001461 REG_JNI(register_android_hardware_camera2_DngCreator),
Craig Donner1a4d07d2017-01-09 13:01:22 -08001462 REG_JNI(register_android_hardware_HardwareBuffer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 REG_JNI(register_android_hardware_SensorManager),
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04001464 REG_JNI(register_android_hardware_SerialPort),
Eric Laurent60b62bc2014-04-18 17:50:49 -07001465 REG_JNI(register_android_hardware_SoundTrigger),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001466 REG_JNI(register_android_hardware_UsbDevice),
Mike Lockwoodacc29cc2011-03-11 08:18:08 -05001467 REG_JNI(register_android_hardware_UsbDeviceConnection),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001468 REG_JNI(register_android_hardware_UsbRequest),
Brian Duddiecfa5b5b2019-01-22 18:01:40 +00001469 REG_JNI(register_android_hardware_location_ActivityRecognitionHardware),
Eric Laurent7c31847e2018-11-29 14:33:56 -08001470 REG_JNI(register_android_media_AudioEffectDescriptor),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001471 REG_JNI(register_android_media_AudioSystem),
Paul McLeanb3ae6d92018-11-05 15:16:59 -07001472 REG_JNI(register_android_media_AudioRecord),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 REG_JNI(register_android_media_AudioTrack),
François Gaffieb4691282018-07-09 13:07:32 +02001474 REG_JNI(register_android_media_AudioAttributes),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 REG_JNI(register_android_media_JetPlayer),
jiabinc0f49442018-01-05 10:23:50 -08001476 REG_JNI(register_android_media_MicrophoneInfo),
Jeff Browncbad9762012-09-04 21:57:59 -07001477 REG_JNI(register_android_media_RemoteDisplay),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001478 REG_JNI(register_android_media_ToneGenerator),
Paul McLean84b491302018-05-09 10:03:57 -06001479 REG_JNI(register_android_media_midi),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001480
1481 REG_JNI(register_android_opengl_classes),
JP Abgrall98a4f7e2011-09-02 15:36:33 -07001482 REG_JNI(register_android_server_NetworkManagementSocketTagger),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001483 REG_JNI(register_android_ddm_DdmHandleNativeHeap),
Joe Onorato1cf58742009-06-12 11:06:24 -07001484 REG_JNI(register_android_backup_BackupDataInput),
Joe Onoratod2110db2009-05-19 13:41:21 -07001485 REG_JNI(register_android_backup_BackupDataOutput),
Joe Onorato06290a42009-06-18 20:10:37 -07001486 REG_JNI(register_android_backup_FileBackupHelperBase),
Joe Onorato4ababd92009-06-25 18:29:18 -04001487 REG_JNI(register_android_backup_BackupHelperDispatcher),
Christopher Tate4a627c72011-04-01 14:43:32 -07001488 REG_JNI(register_android_app_backup_FullBackup),
Dimitry Ivanov4449ef52016-02-25 17:41:13 -08001489 REG_JNI(register_android_app_Activity),
Chet Haase9c1e23b2011-03-24 10:51:31 -07001490 REG_JNI(register_android_app_ActivityThread),
Dianne Hackborn69969e42010-05-04 11:40:40 -07001491 REG_JNI(register_android_app_NativeActivity),
Przemyslaw Szczepaniak8a7c1602015-11-03 09:47:56 +00001492 REG_JNI(register_android_util_jar_StrictJarFile),
Jeff Brown46b9ac02010-04-22 18:58:52 -07001493 REG_JNI(register_android_view_InputChannel),
Jeff Brown32cbc38552011-12-01 14:01:49 -08001494 REG_JNI(register_android_view_InputEventReceiver),
Jeff Brownc28867a2013-03-26 15:42:39 -07001495 REG_JNI(register_android_view_InputEventSender),
Michael Wrighta44dd262013-04-10 21:12:00 -07001496 REG_JNI(register_android_view_InputQueue),
Jeff Brown46b9ac02010-04-22 18:58:52 -07001497 REG_JNI(register_android_view_KeyEvent),
1498 REG_JNI(register_android_view_MotionEvent),
Jeff Brown2352b972011-04-12 22:39:53 -07001499 REG_JNI(register_android_view_PointerIcon),
Jeff Brown2ed24622011-03-14 19:39:54 -07001500 REG_JNI(register_android_view_VelocityTracker),
Kenny Root02c87302010-07-01 08:10:18 -07001501
1502 REG_JNI(register_android_content_res_ObbScanner),
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -07001503 REG_JNI(register_android_content_res_Configuration),
Chet Haase6e0ecb42010-11-03 19:41:18 -07001504
1505 REG_JNI(register_android_animation_PropertyValuesHolder),
Bo Zhu09856132018-04-01 12:24:09 -07001506 REG_JNI(register_android_security_Scrypt),
Kenny Root66269ea2011-07-12 14:14:01 -07001507 REG_JNI(register_com_android_internal_content_NativeLibraryHelper),
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -08001508 REG_JNI(register_com_android_internal_net_NetworkStatsFactory),
Svet Ganov8455ba22019-01-02 13:05:56 -08001509 REG_JNI(register_com_android_internal_os_AtomicDirectory),
Daichi Hirono878e86f2016-10-31 09:33:30 +09001510 REG_JNI(register_com_android_internal_os_FuseAppLoop),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001511};
1512
1513/*
1514 * Register android native functions with the VM.
1515 */
1516/*static*/ int AndroidRuntime::startReg(JNIEnv* env)
1517{
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001518 ATRACE_NAME("RegisterAndroidNatives");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001519 /*
1520 * This hook causes all future threads created in this process to be
1521 * attached to the JavaVM. (This needs to go away in favor of JNI
1522 * Attach calls.)
1523 */
1524 androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc);
1525
Steve Block71f2cf12011-10-20 11:56:00 +01001526 ALOGV("--- registering native functions ---\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001527
1528 /*
1529 * Every "register" function calls one or more things that return
1530 * a local reference (e.g. FindClass). Because we haven't really
1531 * started the VM yet, they're all getting stored in the base frame
1532 * and never released. Use Push/Pop to manage the storage.
1533 */
1534 env->PushLocalFrame(200);
1535
1536 if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) {
1537 env->PopLocalFrame(NULL);
1538 return -1;
1539 }
1540 env->PopLocalFrame(NULL);
1541
1542 //createJavaThread("fubar", quickTest, (void*) "hello");
1543
1544 return 0;
1545}
1546
1547AndroidRuntime* AndroidRuntime::getRuntime()
1548{
1549 return gCurRuntime;
1550}
1551
1552/**
Narayan Kamathc21dab92015-06-25 14:22:00 +01001553 * Used by surface flinger's DdmConnection to register native methods from
1554 * the framework.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001555 */
Narayan Kamathc21dab92015-06-25 14:22:00 +01001556extern "C" jint registerFrameworkNatives(JNIEnv* env) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001557 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1558}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001559} // namespace android