blob: 378e125a3a3ea2b3b6a90d705d2248c886d39df6 [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>
Derek Sollenberger9ca0c522019-08-29 13:08:02 -040025#include <android/graphics/jni_runtime.h>
Mathias Agopian07952722009-05-19 19:08:10 -070026#include <binder/IBinder.h>
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -080027#include <binder/IPCThreadState.h>
Mathias Agopian07952722009-05-19 19:08:10 -070028#include <binder/IServiceManager.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029#include <utils/Log.h>
30#include <utils/misc.h>
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +090031#include <utils/Trace.h>
Mathias Agopian07952722009-05-19 19:08:10 -070032#include <binder/Parcel.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033#include <utils/threads.h>
34#include <cutils/properties.h>
Mathieu Chartierd2a975a2019-01-28 11:11:25 -080035#include <server_configurable_flags/get_flags.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037#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);
sergeyv0a0f2312017-01-04 13:58:52 -080058extern int register_android_graphics_GraphicBuffer(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059
60extern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env);
61extern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070062extern int register_android_opengl_jni_EGL14(JNIEnv* env);
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -060063extern int register_android_opengl_jni_EGL15(JNIEnv* env);
Jesse Hall237c2b82013-05-06 11:36:57 -070064extern int register_android_opengl_jni_EGLExt(JNIEnv* env);
Jack Palevich1c4907e2009-04-13 16:22:25 -070065extern int register_android_opengl_jni_GLES10(JNIEnv* env);
66extern int register_android_opengl_jni_GLES10Ext(JNIEnv* env);
67extern int register_android_opengl_jni_GLES11(JNIEnv* env);
68extern int register_android_opengl_jni_GLES11Ext(JNIEnv* env);
Jack Palevich560814f2009-11-19 16:34:55 +080069extern int register_android_opengl_jni_GLES20(JNIEnv* env);
Jesse Halld877efe2013-04-29 15:59:35 -070070extern int register_android_opengl_jni_GLES30(JNIEnv* env);
Jesse Hall7ab63ac2014-05-19 15:13:41 -070071extern int register_android_opengl_jni_GLES31(JNIEnv* env);
72extern int register_android_opengl_jni_GLES31Ext(JNIEnv* env);
Pablo Ceballos38c1a7e2015-10-30 10:34:30 -070073extern int register_android_opengl_jni_GLES32(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074
75extern int register_android_hardware_Camera(JNIEnv *env);
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -070076extern int register_android_hardware_camera2_CameraMetadata(JNIEnv *env);
Ruben Brunkfeb50af2014-05-09 19:58:49 -070077extern int register_android_hardware_camera2_legacy_LegacyCameraDevice(JNIEnv *env);
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -070078extern int register_android_hardware_camera2_legacy_PerfMeasurement(JNIEnv *env);
Ruben Brunkb6079002014-05-22 12:33:54 -070079extern int register_android_hardware_camera2_DngCreator(JNIEnv *env);
Craig Donner1a4d07d2017-01-09 13:01:22 -080080extern int register_android_hardware_HardwareBuffer(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081extern int register_android_hardware_SensorManager(JNIEnv *env);
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -040082extern int register_android_hardware_SerialPort(JNIEnv *env);
Eric Laurent60b62bc2014-04-18 17:50:49 -070083extern int register_android_hardware_SoundTrigger(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -050084extern int register_android_hardware_UsbDevice(JNIEnv *env);
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050085extern int register_android_hardware_UsbDeviceConnection(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -050086extern int register_android_hardware_UsbRequest(JNIEnv *env);
Brian Duddiecfa5b5b2019-01-22 18:01:40 +000087extern int register_android_hardware_location_ActivityRecognitionHardware(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088
Eric Laurent7c31847e2018-11-29 14:33:56 -080089extern int register_android_media_AudioEffectDescriptor(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090extern int register_android_media_AudioRecord(JNIEnv *env);
91extern int register_android_media_AudioSystem(JNIEnv *env);
92extern int register_android_media_AudioTrack(JNIEnv *env);
François Gaffieb4691282018-07-09 13:07:32 +020093extern int register_android_media_AudioAttributes(JNIEnv *env);
François Gaffiec01fa3a2018-03-15 14:33:24 +010094extern int register_android_media_AudioProductStrategies(JNIEnv *env);
François Gaffieadcd00a2018-09-18 17:06:26 +020095extern int register_android_media_AudioVolumeGroups(JNIEnv *env);
96extern int register_android_media_AudioVolumeGroupChangeHandler(JNIEnv *env);
jiabinc0f49442018-01-05 10:23:50 -080097extern int register_android_media_MicrophoneInfo(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098extern int register_android_media_ToneGenerator(JNIEnv *env);
Paul McLean84b491302018-05-09 10:03:57 -060099extern int register_android_media_midi(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101namespace android {
102
103/*
104 * JNI-based registration functions. Note these are properly contained in
105 * namespace android.
106 */
Michal Karpinski6235a942016-03-15 12:07:23 +0000107extern int register_android_app_admin_SecurityLog(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108extern int register_android_content_AssetManager(JNIEnv* env);
109extern int register_android_util_EventLog(JNIEnv* env);
Chenjie Yu671b1b52017-08-30 22:14:05 -0700110extern int register_android_util_StatsLog(JNIEnv* env);
Tej Singhbe0482b2019-03-19 22:01:57 -0700111extern int register_android_util_StatsLogInternal(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112extern int register_android_util_Log(JNIEnv* env);
Svet Ganov53a441c2016-04-19 19:38:00 -0700113extern int register_android_util_MemoryIntArray(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114extern int register_android_content_StringBlock(JNIEnv* env);
115extern int register_android_content_XmlBlock(JNIEnv* env);
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800116extern int register_android_content_res_ApkAssets(JNIEnv* env);
Robert Carr48ec4e02019-07-16 14:28:47 -0700117extern int register_android_graphics_BLASTBufferQueue(JNIEnv* env);
Jeff Brown0a0a1242011-12-02 02:25:22 -0800118extern int register_android_view_DisplayEventReceiver(JNIEnv* env);
Riddle Hsucd958bc2019-01-23 15:40:26 +0800119extern int register_android_view_InputApplicationHandle(JNIEnv* env);
120extern int register_android_view_InputWindowHandle(JNIEnv* env);
John Recke45b1fd2014-04-15 09:50:16 -0700121extern int register_android_view_RenderNodeAnimator(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122extern int register_android_view_Surface(JNIEnv* env);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800123extern int register_android_view_SurfaceControl(JNIEnv* env);
Jeff Brown64a55af2012-08-26 02:47:39 -0700124extern int register_android_view_SurfaceSession(JNIEnv* env);
Adrian Roos9b963d32019-02-13 18:39:36 +0000125extern int register_android_view_CompositionSamplingListener(JNIEnv* env);
Romain Guy8f0095c2011-05-02 17:24:22 -0700126extern int register_android_view_TextureView(JNIEnv* env);
John Reck315c3292014-05-09 19:21:04 -0700127extern int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128extern int register_android_database_CursorWindow(JNIEnv* env);
Jeff Browne5360fb2011-10-31 17:48:13 -0700129extern int register_android_database_SQLiteConnection(JNIEnv* env);
130extern int register_android_database_SQLiteGlobal(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131extern int register_android_database_SQLiteDebug(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132extern int register_android_os_Debug(JNIEnv* env);
Jesse Hallb12249b2016-12-12 12:53:02 -0800133extern int register_android_os_GraphicsEnvironment(JNIEnv* env);
Yifan Hongbb0bd002017-11-14 16:14:04 -0800134extern int register_android_os_HidlSupport(JNIEnv* env);
Andreas Huberc0b6c532016-08-15 09:25:02 -0700135extern int register_android_os_HwBinder(JNIEnv *env);
Andreas Huberdc263212016-08-25 11:21:21 -0700136extern int register_android_os_HwBlob(JNIEnv *env);
Andreas Huberc0b6c532016-08-15 09:25:02 -0700137extern int register_android_os_HwParcel(JNIEnv *env);
138extern int register_android_os_HwRemoteBinder(JNIEnv *env);
Nirav Atre9850dd92018-07-24 17:03:44 -0700139extern int register_android_os_NativeHandle(JNIEnv *env);
Christopher Tatefa9e7c02010-05-06 12:07:10 -0700140extern int register_android_os_MessageQueue(JNIEnv* env);
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -0800141extern int register_android_os_Parcel(JNIEnv* env);
Stephen Smalleyc07fca32012-01-13 08:31:39 -0500142extern int register_android_os_SELinux(JNIEnv* env);
Yifan Hongbecc56d2017-04-05 14:42:05 -0700143extern int register_android_os_VintfObject(JNIEnv *env);
Yifan Hong1bda6732017-04-26 11:38:01 -0700144extern int register_android_os_VintfRuntimeInfo(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145extern int register_android_os_SystemProperties(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146extern int register_android_os_SystemClock(JNIEnv* env);
Jeff Brown481c1572012-03-09 14:41:15 -0800147extern int register_android_os_Trace(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148extern int register_android_os_FileObserver(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149extern int register_android_os_UEventObserver(JNIEnv* env);
Ytai Ben-Tsvi4659e182019-11-06 09:53:34 -0800150extern int register_android_os_HidlMemory(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151extern int register_android_os_MemoryFile(JNIEnv* env);
John Reckdea6a022017-05-25 17:09:33 -0700152extern int register_android_os_SharedMemory(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153extern int register_android_net_LocalSocketImpl(JNIEnv* env);
154extern int register_android_net_NetworkUtils(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155extern int register_android_text_AndroidCharacter(JNIEnv *env);
Seigo Nonaka44a1df22017-08-31 18:22:38 -0700156extern int register_android_text_Hyphenator(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157extern int register_android_opengl_classes(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
Narayan Kamath29564cd2014-08-07 10:57:40 +0100159extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env);
Joe Onorato1cf58742009-06-12 11:06:24 -0700160extern int register_android_backup_BackupDataInput(JNIEnv *env);
Joe Onoratod2110db2009-05-19 13:41:21 -0700161extern int register_android_backup_BackupDataOutput(JNIEnv *env);
Joe Onorato06290a42009-06-18 20:10:37 -0700162extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
Joe Onorato4ababd92009-06-25 18:29:18 -0400163extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
Christopher Tate4a627c72011-04-01 14:43:32 -0700164extern int register_android_app_backup_FullBackup(JNIEnv *env);
Dimitry Ivanov4449ef52016-02-25 17:41:13 -0800165extern int register_android_app_Activity(JNIEnv *env);
Chet Haase9c1e23b2011-03-24 10:51:31 -0700166extern int register_android_app_ActivityThread(JNIEnv *env);
Dianne Hackborn69969e42010-05-04 11:40:40 -0700167extern int register_android_app_NativeActivity(JNIEnv *env);
Jeff Browncbad9762012-09-04 21:57:59 -0700168extern int register_android_media_RemoteDisplay(JNIEnv *env);
Przemyslaw Szczepaniak8a7c1602015-11-03 09:47:56 +0000169extern int register_android_util_jar_StrictJarFile(JNIEnv* env);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700170extern int register_android_view_InputChannel(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700171extern int register_android_view_InputDevice(JNIEnv* env);
Jeff Brown32cbc38552011-12-01 14:01:49 -0800172extern int register_android_view_InputEventReceiver(JNIEnv* env);
Jeff Brownc28867a2013-03-26 15:42:39 -0700173extern int register_android_view_InputEventSender(JNIEnv* env);
Michael Wrighta44dd262013-04-10 21:12:00 -0700174extern int register_android_view_InputQueue(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700175extern int register_android_view_KeyCharacterMap(JNIEnv *env);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700176extern int register_android_view_KeyEvent(JNIEnv* env);
177extern int register_android_view_MotionEvent(JNIEnv* env);
Jeff Brown2352b972011-04-12 22:39:53 -0700178extern int register_android_view_PointerIcon(JNIEnv* env);
Jeff Brown2ed24622011-03-14 19:39:54 -0700179extern int register_android_view_VelocityTracker(JNIEnv* env);
Kenny Root02c87302010-07-01 08:10:18 -0700180extern int register_android_content_res_ObbScanner(JNIEnv* env);
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700181extern int register_android_content_res_Configuration(JNIEnv* env);
Chet Haase6e0ecb42010-11-03 19:41:18 -0700182extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
Bo Zhu09856132018-04-01 12:24:09 -0700183extern int register_android_security_Scrypt(JNIEnv *env);
Kenny Root66269ea2011-07-12 14:14:01 -0700184extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
Narayan Kamathf9419f02017-06-15 11:35:38 +0100185extern int register_com_android_internal_os_ClassLoaderFactory(JNIEnv* env);
Daichi Hirono878e86f2016-10-31 09:33:30 +0900186extern int register_com_android_internal_os_FuseAppLoop(JNIEnv* env);
Narayan Kamath973b4662014-03-31 13:41:26 +0100187extern int register_com_android_internal_os_Zygote(JNIEnv *env);
Jesse Hall1fe1dc02017-07-06 15:30:39 -0700188extern int register_com_android_internal_os_ZygoteInit(JNIEnv *env);
John Reck9fa40712014-05-09 15:26:59 -0700189extern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190
Roland Levillain7b098c82019-02-04 15:48:09 +0000191// Namespace for Android Runtime flags applied during boot time.
192static const char* RUNTIME_NATIVE_BOOT_NAMESPACE = "runtime_native_boot";
Roland Levillain72b16f02019-02-19 18:09:58 +0000193// Feature flag name to enable/disable generational garbage collection in ART's
194// Concurrent Copying (CC) garbage collector.
195static const char* ENABLE_GENERATIONAL_CC = "enable_generational_cc";
196// Runtime option enabling generational garbage collection in ART's Concurrent
197// Copying (CC) garbage collector.
198static const char* kGenerationalCCRuntimeOption = "-Xgc:generational_cc";
199// Runtime option disabling generational garbage collection in ART's Concurrent
200// Copying (CC) garbage collector.
201static const char* kNoGenerationalCCRuntimeOption = "-Xgc:nogenerational_cc";
Roland Levillain7b098c82019-02-04 15:48:09 +0000202
Mathieu Chartier72539612019-08-19 11:12:37 -0700203// Phenotype property name for enabling profiling the boot class path.
204static const char* PROFILE_BOOT_CLASS_PATH = "profilebootclasspath";
205
Nicolas Geoffray7a6a0da2019-02-25 13:26:31 +0000206// Feature flag name for running the JIT in Zygote experiment, b/119800099.
207static const char* ENABLE_APEX_IMAGE = "enable_apex_image";
208// Flag to pass to the runtime when using the apex image.
209static const char* kApexImageOption = "-Ximage:/system/framework/apex.art";
210
David Sehr26a64272019-05-30 13:40:23 -0700211// Feature flag name for disabling lock profiling.
212static const char* DISABLE_LOCK_PROFILING = "disable_lock_profiling";
213// Runtime option disabling lock profiling.
214static const char* kLockProfThresholdRuntimeOption = "-Xlockprofthreshold:0";
215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216static AndroidRuntime* gCurRuntime = NULL;
217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218/*
219 * Code written in the Java Programming Language calls here from main().
220 */
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700221static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222{
223 gCurRuntime->onStarted();
224}
225
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800226static void com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227{
228 gCurRuntime->onZygoteInit();
229}
230
Jeff Brown4280c4a2012-03-15 17:48:02 -0700231static void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIEnv* env,
232 jobject clazz, jboolean exitWithoutCleanup)
233{
234 gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup);
235}
236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237/*
238 * JNI registration.
239 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240
241int register_com_android_internal_os_RuntimeInit(JNIEnv* env)
242{
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800243 const JNINativeMethod methods[] = {
244 { "nativeFinishInit", "()V",
245 (void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
246 { "nativeSetExitWithoutCleanup", "(Z)V",
247 (void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
248 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800250 methods, NELEM(methods));
251}
252
Jesse Hall1fe1dc02017-07-06 15:30:39 -0700253int register_com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv* env)
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800254{
255 const JNINativeMethod methods[] = {
256 { "nativeZygoteInit", "()V",
257 (void*) com_android_internal_os_ZygoteInit_nativeZygoteInit },
258 };
259 return jniRegisterNativeMethods(env, "com/android/internal/os/ZygoteInit",
260 methods, NELEM(methods));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261}
262
263// ----------------------------------------------------------------------
264
Andreas Huber9ae000c2014-02-13 17:22:33 +0000265/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
266
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000267AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) :
268 mExitWithoutCleanup(false),
269 mArgBlockStart(argBlockStart),
270 mArgBlockLength(argBlockLength)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271{
Derek Sollenberger9ca0c522019-08-29 13:08:02 -0400272 init_android_graphics();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273
274 // Pre-allocate enough space to hold a fair number of options.
275 mOptions.setCapacity(20);
276
277 assert(gCurRuntime == NULL); // one per process
278 gCurRuntime = this;
279}
280
281AndroidRuntime::~AndroidRuntime()
282{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283}
284
Andreas Huber9ae000c2014-02-13 17:22:33 +0000285/*
286 * Register native methods using JNI.
287 */
288/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
289 const char* className, const JNINativeMethod* gMethods, int numMethods)
290{
291 return jniRegisterNativeMethods(env, className, gMethods, numMethods);
292}
293
Dmitriy Filchenkof5b6e552016-07-18 16:00:35 -0700294void AndroidRuntime::setArgv0(const char* argv0, bool setProcName) {
295 if (setProcName) {
296 int len = strlen(argv0);
297 if (len < 15) {
298 pthread_setname_np(pthread_self(), argv0);
299 } else {
300 pthread_setname_np(pthread_self(), argv0 + len - 15);
301 }
302 }
Jeff Brown00c0cd42014-09-10 16:48:46 -0700303 memset(mArgBlockStart, 0, mArgBlockLength);
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000304 strlcpy(mArgBlockStart, argv0, mArgBlockLength);
305}
306
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100307status_t AndroidRuntime::callMain(const String8& className, jclass clazz,
308 const Vector<String8>& args)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309{
310 JNIEnv* env;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 jmethodID methodId;
312
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100313 ALOGD("Calling main entry %s", className.string());
Dianne Hackborn08e60f22010-09-01 18:17:17 -0700314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 env = getJNIEnv();
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700316 if (clazz == NULL || env == NULL) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 return UNKNOWN_ERROR;
318 }
319
320 methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
321 if (methodId == NULL) {
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100322 ALOGE("ERROR: could not find method %s.main(String[])\n", className.string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 return UNKNOWN_ERROR;
324 }
325
326 /*
327 * We want to call main() with a String array with our arguments in it.
328 * Create an array and populate it.
329 */
330 jclass stringClass;
331 jobjectArray strArray;
332
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100333 const size_t numArgs = args.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 stringClass = env->FindClass("java/lang/String");
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100335 strArray = env->NewObjectArray(numArgs, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100337 for (size_t i = 0; i < numArgs; i++) {
338 jstring argStr = env->NewStringUTF(args[i].string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 env->SetObjectArrayElement(strArray, i, argStr);
340 }
341
342 env->CallStaticVoidMethod(clazz, methodId, strArray);
343 return NO_ERROR;
344}
345
346/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 * The VM calls this through the "exit" hook.
348 */
349static void runtime_exit(int code)
350{
Jeff Brown4280c4a2012-03-15 17:48:02 -0700351 gCurRuntime->exit(code);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352}
353
354/*
355 * The VM calls this through the "vfprintf" hook.
356 *
357 * We ignore "fp" and just write the results to the log file.
358 */
359static void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
360{
361 LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
362}
363
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800364/**
365 * The VM calls this when mutex contention debugging is enabled to
366 * determine whether or not the blocked thread was a "sensitive thread"
367 * for user responsiveness/smoothess.
368 *
369 * Our policy for this is whether or not we're tracing any StrictMode
370 * events on this thread (which we might've inherited via Binder calls
371 * into us)
372 */
373static bool runtime_isSensitiveThread() {
374 IPCThreadState* state = IPCThreadState::selfOrNull();
375 return state && state->getStrictModePolicy() != 0;
376}
377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378static int hasDir(const char* dir)
379{
380 struct stat s;
381 int res = stat(dir, &s);
382 if (res == 0) {
383 return S_ISDIR(s.st_mode);
384 }
385 return 0;
386}
387
Andreas Gampe995c62d2014-11-14 16:15:17 -0800388static bool hasFile(const char* file) {
389 struct stat s;
390 int res = stat(file, &s);
391 if (res == 0) {
392 return S_ISREG(s.st_mode);
393 }
394 return false;
395}
396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800397/*
Narayan Kamathbf882052015-08-11 15:40:34 +0100398 * Read the persistent locale. Inspects the following system properties
399 * (in order) and returns the first non-empty property in the list :
400 *
401 * (1) persist.sys.locale
402 * (2) persist.sys.language/country/localevar (country and localevar are
403 * inspected iff. language is non-empty.
404 * (3) ro.product.locale
405 * (4) ro.product.locale.language/region
406 *
407 * Note that we need to inspect persist.sys.language/country/localevar to
408 * preserve language settings for devices that are upgrading from Lollipop
409 * to M. The same goes for ro.product.locale.language/region as well.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 */
Narayan Kamathbf882052015-08-11 15:40:34 +0100411const std::string readLocale()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412{
Tom Cherry93099e42017-10-11 13:44:21 -0700413 const std::string locale = GetProperty("persist.sys.locale", "");
Narayan Kamathbf882052015-08-11 15:40:34 +0100414 if (!locale.empty()) {
415 return locale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416 }
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000417
Tom Cherry93099e42017-10-11 13:44:21 -0700418 const std::string language = GetProperty("persist.sys.language", "");
Narayan Kamathbf882052015-08-11 15:40:34 +0100419 if (!language.empty()) {
Tom Cherry93099e42017-10-11 13:44:21 -0700420 const std::string country = GetProperty("persist.sys.country", "");
421 const std::string variant = GetProperty("persist.sys.localevar", "");
Narayan Kamathbf882052015-08-11 15:40:34 +0100422
423 std::string out = language;
424 if (!country.empty()) {
425 out = out + "-" + country;
426 }
427
428 if (!variant.empty()) {
429 out = out + "-" + variant;
430 }
431
432 return out;
433 }
434
Tom Cherry93099e42017-10-11 13:44:21 -0700435 const std::string productLocale = GetProperty("ro.product.locale", "");
Narayan Kamathbf882052015-08-11 15:40:34 +0100436 if (!productLocale.empty()) {
437 return productLocale;
438 }
439
440 // If persist.sys.locale and ro.product.locale are missing,
441 // construct a locale value from the individual locale components.
Tom Cherry93099e42017-10-11 13:44:21 -0700442 const std::string productLanguage = GetProperty("ro.product.locale.language", "en");
443 const std::string productRegion = GetProperty("ro.product.locale.region", "US");
Narayan Kamathbf882052015-08-11 15:40:34 +0100444
445 return productLanguage + "-" + productRegion;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446}
447
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700448void AndroidRuntime::addOption(const char* optionString, void* extraInfo)
449{
450 JavaVMOption opt;
451 opt.optionString = optionString;
452 opt.extraInfo = extraInfo;
453 mOptions.add(opt);
454}
455
Andy McFaddenf70188a2009-03-31 15:52:13 -0700456/*
Andy McFaddene4d81f22010-07-14 16:02:20 -0700457 * Parse a property containing space-separated options that should be
458 * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
459 *
460 * This will cut up "extraOptsBuf" as we chop it into individual options.
461 *
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800462 * If "quotingArg" is non-null, it is passed before each extra option in mOptions.
463 *
Andy McFaddene4d81f22010-07-14 16:02:20 -0700464 * Adds the strings, if any, to mOptions.
465 */
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800466void AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg)
Andy McFaddene4d81f22010-07-14 16:02:20 -0700467{
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800468 char* start = extraOptsBuf;
469 char* end = NULL;
Andy McFaddene4d81f22010-07-14 16:02:20 -0700470 while (*start != '\0') {
471 while (*start == ' ') /* skip leading whitespace */
472 start++;
473 if (*start == '\0') /* was trailing ws, bail */
474 break;
475
476 end = start+1;
477 while (*end != ' ' && *end != '\0') /* find end of token */
478 end++;
479 if (*end == ' ')
480 *end++ = '\0'; /* mark end, advance to indicate more */
481
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800482 if (quotingArg != NULL) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700483 addOption(quotingArg);
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800484 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700485 addOption(start);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700486 start = end;
487 }
488}
489
490/*
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700491 * Reads a "property" into "buffer" with a default of "defaultArg". If
492 * the property is non-empty, it is treated as a runtime option such
493 * as "-Xmx32m".
494 *
495 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
496 *
497 * If an argument is found, it is added to mOptions.
498 *
499 * If an option is found, it is added to mOptions and true is
500 * returned. Otherwise false is returned.
501 */
502bool AndroidRuntime::parseRuntimeOption(const char* property,
503 char* buffer,
504 const char* runtimeArg,
505 const char* defaultArg)
506{
507 strcpy(buffer, runtimeArg);
508 size_t runtimeArgLen = strlen(runtimeArg);
509 property_get(property, buffer+runtimeArgLen, defaultArg);
510 if (buffer[runtimeArgLen] == '\0') {
511 return false;
512 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700513 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700514 return true;
515}
516
517/*
518 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700519 * is treated as a dex2oat compiler option that should be
Nicolas Geoffraybe7b0d12017-04-25 12:29:07 +0100520 * passed as a quoted option, e.g. "-Ximage-compiler-option --compiler-filter=assume-verified".
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700521 *
522 * The "compilerArg" is a prefix for the option such as "--compiler-filter=".
523 *
524 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
525 *
526 * If an option is found, it is added to mOptions and true is
527 * returned. Otherwise false is returned.
528 */
529bool AndroidRuntime::parseCompilerOption(const char* property,
530 char* buffer,
531 const char* compilerArg,
532 const char* quotingArg)
533{
534 strcpy(buffer, compilerArg);
535 size_t compilerArgLen = strlen(compilerArg);
536 property_get(property, buffer+compilerArgLen, "");
537 if (buffer[compilerArgLen] == '\0') {
538 return false;
539 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700540 addOption(quotingArg);
541 addOption(buffer);
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700542 return true;
543}
544
545/*
546 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700547 * is treated as a dex2oat compiler runtime option that should be
548 * passed as a quoted option, e.g. "-Ximage-compiler-option
549 * --runtime-arg -Ximage-compiler-option -Xmx32m".
550 *
551 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
552 *
553 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
554 *
555 * If an option is found, it is added to mOptions and true is
556 * returned. Otherwise false is returned.
557 */
558bool AndroidRuntime::parseCompilerRuntimeOption(const char* property,
559 char* buffer,
560 const char* runtimeArg,
561 const char* quotingArg)
562{
563 strcpy(buffer, runtimeArg);
564 size_t runtimeArgLen = strlen(runtimeArg);
565 property_get(property, buffer+runtimeArgLen, "");
566 if (buffer[runtimeArgLen] == '\0') {
567 return false;
568 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700569 addOption(quotingArg);
570 addOption("--runtime-arg");
571 addOption(quotingArg);
572 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700573 return true;
574}
575
576/*
Andy McFaddenf70188a2009-03-31 15:52:13 -0700577 * Start the Dalvik Virtual Machine.
578 *
579 * Various arguments, most determined by system properties, are passed in.
580 * The "mOptions" vector is updated.
581 *
Dave Allison07a1e232014-03-14 08:54:33 -0700582 * CAUTION: when adding options in here, be careful not to put the
583 * char buffer inside a nested scope. Adding the buffer to the
584 * options using mOptions.add() does not copy the buffer, so if the
585 * buffer goes out of scope the option may be overwritten. It's best
586 * to put the buffer at the top of the function so that it is more
587 * unlikely that someone will surround it in a scope at a later time
588 * and thus introduce a bug.
589 *
Andy McFaddenf70188a2009-03-31 15:52:13 -0700590 * Returns 0 on success.
591 */
Nicolas Geoffrayce4f5c42019-06-10 14:11:04 +0100592int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote, bool primary_zygote)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 JavaVMInitArgs initArgs;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 char propBuf[PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro38cfa8c2010-12-07 16:48:29 -0800597 char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700598 char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro8cdf27c2011-01-19 12:33:12 -0800599 char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700600 char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
601 char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800602 char usejitOptsBuf[sizeof("-Xusejit:")-1 + PROPERTY_VALUE_MAX];
Nicolas Geoffray24934a92018-05-16 17:22:37 +0100603 char jitpthreadpriorityOptsBuf[sizeof("-Xjitpthreadpriority:")-1 + PROPERTY_VALUE_MAX];
Nicolas Geoffraycdf1dff2015-11-19 13:48:35 +0000604 char jitmaxsizeOptsBuf[sizeof("-Xjitmaxsize:")-1 + PROPERTY_VALUE_MAX];
605 char jitinitialsizeOptsBuf[sizeof("-Xjitinitialsize:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800606 char jitthresholdOptsBuf[sizeof("-Xjitthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravledb4a79a2015-12-23 18:55:08 +0200607 char useJitProfilesOptsBuf[sizeof("-Xjitsaveprofilinginfo:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle0de80b92016-04-12 14:12:04 +0100608 char jitprithreadweightOptBuf[sizeof("-Xjitprithreadweight:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle8d74de52016-04-27 14:12:00 +0100609 char jittransitionweightOptBuf[sizeof("-Xjittransitionweight:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier5eee0042017-06-07 17:34:22 -0700610 char hotstartupsamplesOptsBuf[sizeof("-Xps-hot-startup-method-samples:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartiercd0caf52017-10-13 11:29:27 -0700611 char madviseRandomOptsBuf[sizeof("-XX:MadviseRandomAccess:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier7e4fdec2013-12-02 15:46:51 -0800612 char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700613 char backgroundgcOptsBuf[sizeof("-XX:BackgroundGC=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700614 char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartierebc3b4c2017-10-15 21:13:28 -0700615 char foregroundHeapGrowthMultiplierOptsBuf[
616 sizeof("-XX:ForegroundHeapGrowthMultiplier=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee324ba02015-03-31 16:15:17 -0700617 char cachePruneBuf[sizeof("-Xzygote-max-boot-retry=")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700618 char dex2oatXmsImageFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
619 char dex2oatXmxImageFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
620 char dex2oatXmsFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
621 char dex2oatXmxFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700622 char dex2oatCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
623 char dex2oatImageCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee0352382015-03-30 18:43:39 -0700624 char dex2oatThreadsBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
625 char dex2oatThreadsImageBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
Orion Hodson870ce3f2019-11-14 18:18:30 +0000626 char dex2oatCpuSetBuf[sizeof("--cpu-set=")-1 + PROPERTY_VALUE_MAX];
627 char dex2oatCpuSetImageBuf[sizeof("--cpu-set=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampe605cca12015-04-02 23:12:56 -0700628 char dex2oat_isa_variant_key[PROPERTY_KEY_MAX];
629 char dex2oat_isa_variant[sizeof("--instruction-set-variant=") -1 + PROPERTY_VALUE_MAX];
630 char dex2oat_isa_features_key[PROPERTY_KEY_MAX];
631 char dex2oat_isa_features[sizeof("--instruction-set-features=") -1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800632 char dex2oatFlagsBuf[PROPERTY_VALUE_MAX];
633 char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX];
Andy McFaddene4d81f22010-07-14 16:02:20 -0700634 char extraOptsBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700635 char voldDecryptBuf[PROPERTY_VALUE_MAX];
Ben Cheng52b0e732009-06-19 13:31:12 -0700636 enum {
637 kEMDefault,
638 kEMIntPortable,
639 kEMIntFast,
Ben Cheng52b0e732009-06-19 13:31:12 -0700640 kEMJitCompiler,
Ben Cheng52b0e732009-06-19 13:31:12 -0700641 } executionMode = kEMDefault;
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000642 char localeOption[sizeof("-Duser.locale=") + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700643 char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle01db9162014-08-07 14:45:53 +0100644 char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX];
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700645 char cpuAbiListBuf[sizeof("--cpu-abilist=") + PROPERTY_VALUE_MAX];
David Brazdil1e58e8e2019-04-12 11:18:07 +0100646 char corePlatformApiPolicyBuf[sizeof("-Xcore-platform-api-policy:") + PROPERTY_VALUE_MAX];
Andreas Gampe98f406f2015-06-22 21:09:36 -0700647 char methodTraceFileBuf[sizeof("-Xmethod-trace-file:") + PROPERTY_VALUE_MAX];
648 char methodTraceFileSizeBuf[sizeof("-Xmethod-trace-file-size:") + PROPERTY_VALUE_MAX];
Tom Cherry93099e42017-10-11 13:44:21 -0700649 std::string fingerprintBuf;
Alex Lightfffb2732017-11-20 13:01:01 -0800650 char jdwpProviderBuf[sizeof("-XjdwpProvider:") - 1 + PROPERTY_VALUE_MAX];
Nicolas Geoffray79eeb982019-02-14 15:55:20 +0000651 char bootImageBuf[sizeof("-Ximage:") - 1 + PROPERTY_VALUE_MAX];
652
Mathieu Chartier72539612019-08-19 11:12:37 -0700653 // Read if we are using the profile configuration, do this at the start since the last ART args
654 // take precedence.
655 property_get("dalvik.vm.profilebootclasspath", propBuf, "");
Mathieu Chartiera5575542019-09-20 16:07:51 -0700656 std::string profile_boot_class_path_flag = propBuf;
Mathieu Chartier72539612019-08-19 11:12:37 -0700657 // Empty means the property is unset and we should default to the phenotype property.
658 // The possible values are {"true", "false", ""}
Mathieu Chartiera5575542019-09-20 16:07:51 -0700659 if (profile_boot_class_path_flag.empty()) {
660 profile_boot_class_path_flag = server_configurable_flags::GetServerConfigurableFlag(
Mathieu Chartier72539612019-08-19 11:12:37 -0700661 RUNTIME_NATIVE_BOOT_NAMESPACE,
662 PROFILE_BOOT_CLASS_PATH,
663 /*default_value=*/ "");
664 }
Mathieu Chartiera5575542019-09-20 16:07:51 -0700665 const bool profile_boot_class_path = (profile_boot_class_path_flag == "true");
666 if (profile_boot_class_path) {
667 addOption("-Xcompiler-option");
668 addOption("--count-hotness-in-compiled-code");
Mathieu Chartier72539612019-08-19 11:12:37 -0700669 addOption("-Xps-profile-boot-class-path");
670 addOption("-Xps-profile-aot-code");
671 addOption("-Xjitsaveprofilinginfo");
672 }
673
Mathieu Chartiera5575542019-09-20 16:07:51 -0700674 std::string use_apex_image_flag =
Nicolas Geoffray7a6a0da2019-02-25 13:26:31 +0000675 server_configurable_flags::GetServerConfigurableFlag(RUNTIME_NATIVE_BOOT_NAMESPACE,
676 ENABLE_APEX_IMAGE,
677 /*default_value=*/ "");
Mathieu Chartiera5575542019-09-20 16:07:51 -0700678 // Use the APEX boot image for boot class path profiling to get JIT samples on BCP methods.
679 // Also use the APEX boot image if it's explicitly enabled via configuration flag.
680 const bool use_apex_image = profile_boot_class_path || (use_apex_image_flag == "true");
681 if (use_apex_image) {
Nicolas Geoffray7a6a0da2019-02-25 13:26:31 +0000682 addOption(kApexImageOption);
683 ALOGI("Using Apex boot image: '%s'\n", kApexImageOption);
684 } else if (parseRuntimeOption("dalvik.vm.boot-image", bootImageBuf, "-Ximage:")) {
685 ALOGI("Using dalvik.vm.boot-image: '%s'\n", bootImageBuf);
686 } else {
687 ALOGI("Using default boot image");
Nicolas Geoffray79eeb982019-02-14 15:55:20 +0000688 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689
David Sehr26a64272019-05-30 13:40:23 -0700690 std::string disable_lock_profiling =
691 server_configurable_flags::GetServerConfigurableFlag(RUNTIME_NATIVE_BOOT_NAMESPACE,
692 DISABLE_LOCK_PROFILING,
693 /*default_value=*/ "");
694 if (disable_lock_profiling == "true") {
695 addOption(kLockProfThresholdRuntimeOption);
696 ALOGI("Disabling lock profiling: '%s'\n", kLockProfThresholdRuntimeOption);
697 } else {
698 ALOGI("Leaving lock profiling enabled");
699 }
700
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700701 bool checkJni = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800702 property_get("dalvik.vm.checkjni", propBuf, "");
703 if (strcmp(propBuf, "true") == 0) {
704 checkJni = true;
705 } else if (strcmp(propBuf, "false") != 0) {
706 /* property is neither true nor false; fall back on kernel parameter */
707 property_get("ro.kernel.android.checkjni", propBuf, "");
708 if (propBuf[0] == '1') {
709 checkJni = true;
710 }
711 }
Joe Onorato82ba91d2017-04-27 16:18:05 -0700712 ALOGV("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700713 if (checkJni) {
714 /* extended JNI checking */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700715 addOption("-Xcheck:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700716
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700717 /* with -Xcheck:jni, this provides a JNI function call trace */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700718 //addOption("-verbose:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700719 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720
721 property_get("dalvik.vm.execution-mode", propBuf, "");
722 if (strcmp(propBuf, "int:portable") == 0) {
723 executionMode = kEMIntPortable;
724 } else if (strcmp(propBuf, "int:fast") == 0) {
725 executionMode = kEMIntFast;
Ben Cheng52b0e732009-06-19 13:31:12 -0700726 } else if (strcmp(propBuf, "int:jit") == 0) {
727 executionMode = kEMJitCompiler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800728 }
729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 strcpy(jniOptsBuf, "-Xjniopts:");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700731 if (parseRuntimeOption("dalvik.vm.jniopts", jniOptsBuf, "-Xjniopts:")) {
732 ALOGI("JNI options: '%s'\n", jniOptsBuf);
733 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 /* route exit() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700736 addOption("exit", (void*) runtime_exit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737
738 /* route fprintf() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700739 addOption("vfprintf", (void*) runtime_vfprintf);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800740
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800741 /* register the framework-specific "is sensitive thread" hook */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700742 addOption("sensitiveThread", (void*) runtime_isSensitiveThread);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743
744 /* enable verbose; standard options are { jni, gc, class } */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700745 //addOption("-verbose:jni");
746 addOption("-verbose:gc");
747 //addOption("-verbose:class");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800748
Nicolas Geoffrayce4f5c42019-06-10 14:11:04 +0100749 if (primary_zygote) {
750 addOption("-Xprimaryzygote");
751 }
752
Carl Shapiro9e4c8842010-12-08 12:14:46 -0800753 /*
754 * The default starting and maximum size of the heap. Larger
755 * values should be specified in a product property override.
756 */
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700757 parseRuntimeOption("dalvik.vm.heapstartsize", heapstartsizeOptsBuf, "-Xms", "4m");
758 parseRuntimeOption("dalvik.vm.heapsize", heapsizeOptsBuf, "-Xmx", "16m");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700760 parseRuntimeOption("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
761 parseRuntimeOption("dalvik.vm.heapminfree", heapminfreeOptsBuf, "-XX:HeapMinFree=");
762 parseRuntimeOption("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf, "-XX:HeapMaxFree=");
763 parseRuntimeOption("dalvik.vm.heaptargetutilization",
764 heaptargetutilizationOptsBuf,
765 "-XX:HeapTargetUtilization=");
Ian Rogers53250102012-09-23 16:38:03 -0700766
Mathieu Chartierebc3b4c2017-10-15 21:13:28 -0700767 /* Foreground heap growth multiplier option */
768 parseRuntimeOption("dalvik.vm.foreground-heap-growth-multiplier",
769 foregroundHeapGrowthMultiplierOptsBuf,
770 "-XX:ForegroundHeapGrowthMultiplier=");
771
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800772 /*
773 * JIT related options.
774 */
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700775 parseRuntimeOption("dalvik.vm.usejit", usejitOptsBuf, "-Xusejit:");
Nicolas Geoffraycdf1dff2015-11-19 13:48:35 +0000776 parseRuntimeOption("dalvik.vm.jitmaxsize", jitmaxsizeOptsBuf, "-Xjitmaxsize:");
777 parseRuntimeOption("dalvik.vm.jitinitialsize", jitinitialsizeOptsBuf, "-Xjitinitialsize:");
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700778 parseRuntimeOption("dalvik.vm.jitthreshold", jitthresholdOptsBuf, "-Xjitthreshold:");
Nicolas Geoffray24934a92018-05-16 17:22:37 +0100779 parseRuntimeOption("dalvik.vm.jitpthreadpriority",
780 jitpthreadpriorityOptsBuf,
781 "-Xjitpthreadpriority:");
Calin Juravledb4a79a2015-12-23 18:55:08 +0200782 property_get("dalvik.vm.usejitprofiles", useJitProfilesOptsBuf, "");
783 if (strcmp(useJitProfilesOptsBuf, "true") == 0) {
784 addOption("-Xjitsaveprofilinginfo");
785 }
Calin Juravle8d74de52016-04-27 14:12:00 +0100786
Calin Juravle0de80b92016-04-12 14:12:04 +0100787 parseRuntimeOption("dalvik.vm.jitprithreadweight",
788 jitprithreadweightOptBuf,
789 "-Xjitprithreadweight:");
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800790
Calin Juravle8d74de52016-04-27 14:12:00 +0100791 parseRuntimeOption("dalvik.vm.jittransitionweight",
792 jittransitionweightOptBuf,
793 "-Xjittransitionweight:");
Mathieu Chartier5eee0042017-06-07 17:34:22 -0700794 /*
Mathieu Chartiercd0caf52017-10-13 11:29:27 -0700795 * Madvise related options.
796 */
797 parseRuntimeOption("dalvik.vm.madvise-random", madviseRandomOptsBuf, "-XX:MadviseRandomAccess:");
798
799 /*
Mathieu Chartier5eee0042017-06-07 17:34:22 -0700800 * Profile related options.
801 */
802 parseRuntimeOption("dalvik.vm.hot-startup-method-samples", hotstartupsamplesOptsBuf,
803 "-Xps-hot-startup-method-samples:");
804
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700805 property_get("ro.config.low_ram", propBuf, "");
806 if (strcmp(propBuf, "true") == 0) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700807 addOption("-XX:LowMemoryMode");
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700808 }
809
Roland Levillain72b16f02019-02-19 18:09:58 +0000810 /*
811 * Garbage-collection related options.
812 */
813 parseRuntimeOption("dalvik.vm.gctype", gctypeOptsBuf, "-Xgc:");
814
815 // If it set, honor the "enable_generational_cc" device configuration;
816 // otherwise, let the runtime use its default behavior.
817 std::string enable_generational_cc =
818 server_configurable_flags::GetServerConfigurableFlag(RUNTIME_NATIVE_BOOT_NAMESPACE,
819 ENABLE_GENERATIONAL_CC,
820 /*default_value=*/ "");
821 if (enable_generational_cc == "true") {
822 addOption(kGenerationalCCRuntimeOption);
823 } else if (enable_generational_cc == "false") {
824 addOption(kNoGenerationalCCRuntimeOption);
Mathieu Chartierd2a975a2019-01-28 11:11:25 -0800825 }
826
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700827 parseRuntimeOption("dalvik.vm.backgroundgctype", backgroundgcOptsBuf, "-XX:BackgroundGC=");
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700828
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200829 /*
830 * Enable debugging only for apps forked from zygote.
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200831 */
832 if (zygote) {
Alex Lightc50928b2018-01-31 16:47:29 +0000833 // Set the JDWP provider and required arguments. By default let the runtime choose how JDWP is
834 // implemented. When this is not set the runtime defaults to not allowing JDWP.
Alex Lightfffb2732017-11-20 13:01:01 -0800835 addOption("-XjdwpOptions:suspend=n,server=y");
Alex Lightc50928b2018-01-31 16:47:29 +0000836 parseRuntimeOption("dalvik.vm.jdwp-provider",
837 jdwpProviderBuf,
838 "-XjdwpProvider:",
839 "default");
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200840 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700842 parseRuntimeOption("dalvik.vm.lockprof.threshold",
843 lockProfThresholdBuf,
844 "-Xlockprofthreshold:");
Carl Shapirod8f3ec62010-04-12 16:31:59 -0700845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800846 if (executionMode == kEMIntPortable) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700847 addOption("-Xint:portable");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 } else if (executionMode == kEMIntFast) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700849 addOption("-Xint:fast");
Ben Cheng52b0e732009-06-19 13:31:12 -0700850 } else if (executionMode == kEMJitCompiler) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700851 addOption("-Xint:jit");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 }
Andy McFaddene2b23e12009-04-03 11:09:46 -0700853
Andreas Gampe08b2d582014-12-18 14:39:22 -0800854 // If we are booting without the real /data, don't spend time compiling.
855 property_get("vold.decrypt", voldDecryptBuf, "");
856 bool skip_compilation = ((strcmp(voldDecryptBuf, "trigger_restart_min_framework") == 0) ||
857 (strcmp(voldDecryptBuf, "1") == 0));
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800858
Andreas Gampe08b2d582014-12-18 14:39:22 -0800859 // Extra options for boot.art/boot.oat image generation.
860 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xms", dex2oatXmsImageFlagsBuf,
861 "-Xms", "-Ximage-compiler-option");
862 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xmx", dex2oatXmxImageFlagsBuf,
863 "-Xmx", "-Ximage-compiler-option");
864 if (skip_compilation) {
Brian Carlstromce5bbbe2014-07-30 15:13:17 -0700865 addOption("-Ximage-compiler-option");
Nicolas Geoffraybe7b0d12017-04-25 12:29:07 +0100866 addOption("--compiler-filter=assume-verified");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800867 } else {
868 parseCompilerOption("dalvik.vm.image-dex2oat-filter", dex2oatImageCompilerFilterBuf,
869 "--compiler-filter=", "-Ximage-compiler-option");
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800870 }
871
Mathieu Chartierf99e70e2017-06-30 11:47:38 -0700872 // If there is a boot profile, it takes precedence over the image and preloaded classes.
873 if (hasFile("/system/etc/boot-image.prof")) {
Andreas Gampe08b2d582014-12-18 14:39:22 -0800874 addOption("-Ximage-compiler-option");
Mathieu Chartierf99e70e2017-06-30 11:47:38 -0700875 addOption("--profile-file=/system/etc/boot-image.prof");
876 addOption("-Ximage-compiler-option");
877 addOption("--compiler-filter=speed-profile");
878 } else {
Mathieu Chartier96fab6e2019-06-27 15:19:34 -0700879 ALOGE("Missing boot-image.prof file, /system/etc/boot-image.prof not found: %s\n",
880 strerror(errno));
881 return -1;
882 }
Mathieu Chartierf99e70e2017-06-30 11:47:38 -0700883
Mathieu Chartier96fab6e2019-06-27 15:19:34 -0700884
885 // If there is a dirty-image-objects file, push it.
886 if (hasFile("/system/etc/dirty-image-objects")) {
887 addOption("-Ximage-compiler-option");
888 addOption("--dirty-image-objects=/system/etc/dirty-image-objects");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800889 }
890
891 property_get("dalvik.vm.image-dex2oat-flags", dex2oatImageFlagsBuf, "");
892 parseExtraOpts(dex2oatImageFlagsBuf, "-Ximage-compiler-option");
893
894 // Extra options for DexClassLoader.
895 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xms", dex2oatXmsFlagsBuf,
896 "-Xms", "-Xcompiler-option");
897 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xmx", dex2oatXmxFlagsBuf,
898 "-Xmx", "-Xcompiler-option");
899 if (skip_compilation) {
900 addOption("-Xcompiler-option");
Nicolas Geoffraybe7b0d12017-04-25 12:29:07 +0100901 addOption("--compiler-filter=assume-verified");
neo.chae155118f2015-01-07 15:32:15 +0900902
903 // We skip compilation when a minimal runtime is brought up for decryption. In that case
904 // /data is temporarily backed by a tmpfs, which is usually small.
905 // If the system image contains prebuilts, they will be relocated into the tmpfs. In this
906 // specific situation it is acceptable to *not* relocate and run out of the prebuilts
907 // directly instead.
908 addOption("--runtime-arg");
909 addOption("-Xnorelocate");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800910 } else {
911 parseCompilerOption("dalvik.vm.dex2oat-filter", dex2oatCompilerFilterBuf,
912 "--compiler-filter=", "-Xcompiler-option");
913 }
Andreas Gampee0352382015-03-30 18:43:39 -0700914 parseCompilerOption("dalvik.vm.dex2oat-threads", dex2oatThreadsBuf, "-j", "-Xcompiler-option");
915 parseCompilerOption("dalvik.vm.image-dex2oat-threads", dex2oatThreadsImageBuf, "-j",
916 "-Ximage-compiler-option");
Orion Hodson870ce3f2019-11-14 18:18:30 +0000917 parseCompilerOption("dalvik.vm.dex2oat-cpu-set", dex2oatCpuSetBuf, "--cpu-set=",
918 "-Xcompiler-option");
919 parseCompilerOption("dalvik.vm.image-dex2oat-cpu-set", dex2oatCpuSetImageBuf, "--cpu-set=",
920 "-Ximage-compiler-option");
Andreas Gampe605cca12015-04-02 23:12:56 -0700921
922 // The runtime will compile a boot image, when necessary, not using installd. Thus, we need to
923 // pass the instruction-set-features/variant as an image-compiler-option.
Andreas Gampe605cca12015-04-02 23:12:56 -0700924 // Note: it is OK to reuse the buffer, as the values are exactly the same between
925 // * compiler-option, used for runtime compilation (DexClassLoader)
926 // * image-compiler-option, used for boot-image compilation on device
927
928 // Copy the variant.
Elliott Hughesa1194cb2018-03-23 11:27:04 -0700929 sprintf(dex2oat_isa_variant_key, "dalvik.vm.isa.%s.variant", ABI_STRING);
Andreas Gampe605cca12015-04-02 23:12:56 -0700930 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
931 "--instruction-set-variant=", "-Ximage-compiler-option");
932 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
933 "--instruction-set-variant=", "-Xcompiler-option");
934 // Copy the features.
Elliott Hughesa1194cb2018-03-23 11:27:04 -0700935 sprintf(dex2oat_isa_features_key, "dalvik.vm.isa.%s.features", ABI_STRING);
Andreas Gampe605cca12015-04-02 23:12:56 -0700936 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
937 "--instruction-set-features=", "-Ximage-compiler-option");
938 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
939 "--instruction-set-features=", "-Xcompiler-option");
940
941
Andreas Gampe08b2d582014-12-18 14:39:22 -0800942 property_get("dalvik.vm.dex2oat-flags", dex2oatFlagsBuf, "");
943 parseExtraOpts(dex2oatFlagsBuf, "-Xcompiler-option");
944
Andy McFaddene4d81f22010-07-14 16:02:20 -0700945 /* extra options; parse this late so it overrides others */
946 property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800947 parseExtraOpts(extraOptsBuf, NULL);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800949 /* Set the properties for locale */
950 {
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000951 strcpy(localeOption, "-Duser.locale=");
Narayan Kamathbf882052015-08-11 15:40:34 +0100952 const std::string locale = readLocale();
953 strncat(localeOption, locale.c_str(), PROPERTY_VALUE_MAX);
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000954 addOption(localeOption);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800955 }
956
Calin Juravle92290b82015-11-10 19:30:45 +0000957 // Trace files are stored in /data/misc/trace which is writable only in debug mode.
958 property_get("ro.debuggable", propBuf, "0");
959 if (strcmp(propBuf, "1") == 0) {
960 property_get("dalvik.vm.method-trace", propBuf, "false");
Andreas Gampe98f406f2015-06-22 21:09:36 -0700961 if (strcmp(propBuf, "true") == 0) {
Calin Juravle92290b82015-11-10 19:30:45 +0000962 addOption("-Xmethod-trace");
963 parseRuntimeOption("dalvik.vm.method-trace-file",
964 methodTraceFileBuf,
965 "-Xmethod-trace-file:");
966 parseRuntimeOption("dalvik.vm.method-trace-file-siz",
967 methodTraceFileSizeBuf,
968 "-Xmethod-trace-file-size:");
969 property_get("dalvik.vm.method-trace-stream", propBuf, "false");
970 if (strcmp(propBuf, "true") == 0) {
971 addOption("-Xmethod-trace-stream");
972 }
Andreas Gampe98f406f2015-06-22 21:09:36 -0700973 }
974 }
975
Andreas Gampe08b2d582014-12-18 14:39:22 -0800976 // Native bridge library. "0" means that native bridge is disabled.
Andreas Gampe14a1cd92018-06-07 09:42:02 -0700977 //
978 // Note: bridging is only enabled for the zygote. Other runs of
979 // app_process may not have the permissions to mount etc.
Andreas Gampe08b2d582014-12-18 14:39:22 -0800980 property_get("ro.dalvik.vm.native.bridge", propBuf, "");
981 if (propBuf[0] == '\0') {
982 ALOGW("ro.dalvik.vm.native.bridge is not expected to be empty");
Andreas Gampe14a1cd92018-06-07 09:42:02 -0700983 } else if (zygote && strcmp(propBuf, "0") != 0) {
Andreas Gampe08b2d582014-12-18 14:39:22 -0800984 snprintf(nativeBridgeLibrary, sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX,
985 "-XX:NativeBridge=%s", propBuf);
986 addOption(nativeBridgeLibrary);
Calin Juravlebe20ed42014-08-26 23:00:11 +0100987 }
Calin Juravle01db9162014-08-07 14:45:53 +0100988
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700989#if defined(__LP64__)
990 const char* cpu_abilist_property_name = "ro.product.cpu.abilist64";
991#else
992 const char* cpu_abilist_property_name = "ro.product.cpu.abilist32";
993#endif // defined(__LP64__)
994 property_get(cpu_abilist_property_name, propBuf, "");
995 if (propBuf[0] == '\0') {
996 ALOGE("%s is not expected to be empty", cpu_abilist_property_name);
997 return -1;
998 }
999 snprintf(cpuAbiListBuf, sizeof(cpuAbiListBuf), "--cpu-abilist=%s", propBuf);
1000 addOption(cpuAbiListBuf);
1001
Andreas Gampee324ba02015-03-31 16:15:17 -07001002 // Dalvik-cache pruning counter.
1003 parseRuntimeOption("dalvik.vm.zygote.max-boot-retry", cachePruneBuf,
1004 "-Xzygote-max-boot-retry=");
1005
Andreas Gampe27c39f12015-04-27 18:28:18 +00001006 /*
David Srbecky065075e2015-05-28 17:16:09 +01001007 * When running with debug.generate-debug-info, add --generate-debug-info to
1008 * the compiler options so that the boot image, if it is compiled on device,
1009 * will include native debugging information.
Andreas Gampe27c39f12015-04-27 18:28:18 +00001010 */
David Srbecky065075e2015-05-28 17:16:09 +01001011 property_get("debug.generate-debug-info", propBuf, "");
Andreas Gampe27c39f12015-04-27 18:28:18 +00001012 if (strcmp(propBuf, "true") == 0) {
1013 addOption("-Xcompiler-option");
David Srbecky065075e2015-05-28 17:16:09 +01001014 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +00001015 addOption("-Ximage-compiler-option");
David Srbecky065075e2015-05-28 17:16:09 +01001016 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +00001017 }
1018
David Srbecky3bb32502018-01-23 17:57:24 +00001019 // The mini-debug-info makes it possible to backtrace through JIT code.
1020 if (property_get_bool("dalvik.vm.minidebuginfo", 0)) {
1021 addOption("-Xcompiler-option");
1022 addOption("--generate-mini-debug-info");
1023 }
1024
David Brazdil1e58e8e2019-04-12 11:18:07 +01001025 // If set, the property below can be used to enable core platform API violation reporting.
1026 property_get("persist.debug.dalvik.vm.core_platform_api_policy", propBuf, "");
1027 if (propBuf[0] != '\0') {
1028 snprintf(corePlatformApiPolicyBuf,
1029 sizeof(corePlatformApiPolicyBuf),
1030 "-Xcore-platform-api-policy:%s",
1031 propBuf);
1032 addOption(corePlatformApiPolicyBuf);
1033 }
1034
Andreas Gampee6082502015-07-24 14:19:44 -07001035 /*
1036 * Retrieve the build fingerprint and provide it to the runtime. That way, ANR dumps will
1037 * contain the fingerprint and can be parsed.
Tom Cherry93099e42017-10-11 13:44:21 -07001038 * Fingerprints are potentially longer than PROPERTY_VALUE_MAX, so parseRuntimeOption() cannot
1039 * be used here.
1040 * Do not ever re-assign fingerprintBuf as its c_str() value is stored in mOptions.
Andreas Gampee6082502015-07-24 14:19:44 -07001041 */
Tom Cherry93099e42017-10-11 13:44:21 -07001042 std::string fingerprint = GetProperty("ro.build.fingerprint", "");
1043 if (!fingerprint.empty()) {
1044 fingerprintBuf = "-Xfingerprint:" + fingerprint;
1045 addOption(fingerprintBuf.c_str());
1046 }
Andreas Gampee6082502015-07-24 14:19:44 -07001047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001048 initArgs.version = JNI_VERSION_1_4;
1049 initArgs.options = mOptions.editArray();
1050 initArgs.nOptions = mOptions.size();
1051 initArgs.ignoreUnrecognized = JNI_FALSE;
1052
1053 /*
1054 * Initialize the VM.
1055 *
1056 * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread.
1057 * If this call succeeds, the VM is ready, and we can start issuing
1058 * JNI calls.
1059 */
Andy McFaddenf70188a2009-03-31 15:52:13 -07001060 if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001061 ALOGE("JNI_CreateJavaVM failed\n");
Dmitriy Ivanovff193d62014-09-30 15:10:48 -07001062 return -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 }
1064
Dmitriy Ivanovff193d62014-09-30 15:10:48 -07001065 return 0;
Andy McFaddenf70188a2009-03-31 15:52:13 -07001066}
1067
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001068char* AndroidRuntime::toSlashClassName(const char* className)
1069{
1070 char* result = strdup(className);
1071 for (char* cp = result; *cp != '\0'; cp++) {
1072 if (*cp == '.') {
1073 *cp = '/';
1074 }
1075 }
1076 return result;
1077}
1078
Mike Lockwood9ee5e7e2014-09-08 16:15:21 -07001079/** Create a Java string from an ASCII or Latin-1 string */
1080jstring AndroidRuntime::NewStringLatin1(JNIEnv* env, const char* bytes) {
1081 if (!bytes) return NULL;
1082 int length = strlen(bytes);
1083 jchar* buffer = (jchar *)alloca(length * sizeof(jchar));
1084 if (!buffer) return NULL;
1085 jchar* chp = buffer;
1086 for (int i = 0; i < length; i++) {
1087 *chp++ = *bytes++;
1088 }
1089 return env->NewString(buffer, length);
1090}
1091
1092
Andy McFaddenf70188a2009-03-31 15:52:13 -07001093/*
1094 * Start the Android runtime. This involves starting the virtual machine
1095 * and calling the "static void main(String[] args)" method in the class
1096 * named by "className".
Jeff Brownebed7d62011-05-16 17:08:42 -07001097 *
1098 * Passes the main function two arguments, the class name and the specified
1099 * options string.
Andy McFaddenf70188a2009-03-31 15:52:13 -07001100 */
Sebastien Hertz7a09b832015-08-10 18:55:34 +02001101void AndroidRuntime::start(const char* className, const Vector<String8>& options, bool zygote)
Andy McFaddenf70188a2009-03-31 15:52:13 -07001102{
Dianne Hackborn8e5aafe2014-10-27 18:04:10 -07001103 ALOGD(">>>>>> START %s uid %d <<<<<<\n",
1104 className != NULL ? className : "(unknown)", getuid());
Andy McFaddenf70188a2009-03-31 15:52:13 -07001105
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001106 static const String8 startSystemServer("start-system-server");
Nicolas Geoffrayce4f5c42019-06-10 14:11:04 +01001107 // Whether this is the primary zygote, meaning the zygote which will fork system server.
1108 bool primary_zygote = false;
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001109
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001110 /*
1111 * 'startSystemServer == true' means runtime is obsolete and not run from
Andy McFaddenf70188a2009-03-31 15:52:13 -07001112 * init.rc anymore, so we print out the boot start event here.
1113 */
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001114 for (size_t i = 0; i < options.size(); ++i) {
1115 if (options[i] == startSystemServer) {
Nicolas Geoffrayce4f5c42019-06-10 14:11:04 +01001116 primary_zygote = true;
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001117 /* track our progress through the boot sequence */
1118 const int LOG_BOOT_PROGRESS_START = 3000;
1119 LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));
1120 }
Andy McFaddenf70188a2009-03-31 15:52:13 -07001121 }
1122
1123 const char* rootDir = getenv("ANDROID_ROOT");
1124 if (rootDir == NULL) {
1125 rootDir = "/system";
1126 if (!hasDir("/system")) {
Neil Fuller3ce4cce2018-11-23 19:00:32 +00001127 LOG_FATAL("No root directory specified, and /system does not exist.");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001128 return;
Andy McFaddenf70188a2009-03-31 15:52:13 -07001129 }
1130 setenv("ANDROID_ROOT", rootDir, 1);
1131 }
1132
Martin Stjernholm5bbffbc2019-09-20 16:14:22 +01001133 const char* artRootDir = getenv("ANDROID_ART_ROOT");
1134 if (artRootDir == NULL) {
1135 LOG_FATAL("No ART directory specified with ANDROID_ART_ROOT environment variable.");
Neil Fuller3ce4cce2018-11-23 19:00:32 +00001136 return;
1137 }
1138
Victor Chang3079c6c2019-09-24 14:55:02 +01001139 const char* i18nRootDir = getenv("ANDROID_I18N_ROOT");
1140 if (i18nRootDir == NULL) {
1141 LOG_FATAL("No runtime directory specified with ANDROID_I18N_ROOT environment variable.");
1142 return;
1143 }
1144
Neil Fullerb99050d2019-03-13 15:29:48 +00001145 const char* tzdataRootDir = getenv("ANDROID_TZDATA_ROOT");
1146 if (tzdataRootDir == NULL) {
1147 LOG_FATAL("No tz data directory specified with ANDROID_TZDATA_ROOT environment variable.");
1148 return;
1149 }
1150
Andy McFaddenf70188a2009-03-31 15:52:13 -07001151 //const char* kernelHack = getenv("LD_ASSUME_KERNEL");
Steve Block5baa3a62011-12-20 16:23:08 +00001152 //ALOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001153
1154 /* start the virtual machine */
Brian Carlstrom9f8203a2013-06-19 13:49:36 -07001155 JniInvocation jni_invocation;
1156 jni_invocation.Init(NULL);
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001157 JNIEnv* env;
Nicolas Geoffrayce4f5c42019-06-10 14:11:04 +01001158 if (startVm(&mJavaVM, &env, zygote, primary_zygote) != 0) {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001159 return;
1160 }
1161 onVmCreated(env);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001163 /*
1164 * Register android functions.
1165 */
1166 if (startReg(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001167 ALOGE("Unable to register all android natives\n");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001168 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001169 }
1170
1171 /*
1172 * We want to call main() with a String array with arguments in it.
Jeff Brownebed7d62011-05-16 17:08:42 -07001173 * At present we have two arguments, the class name and an option string.
1174 * Create an array to hold them.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 */
1176 jclass stringClass;
1177 jobjectArray strArray;
1178 jstring classNameStr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179
1180 stringClass = env->FindClass("java/lang/String");
1181 assert(stringClass != NULL);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001182 strArray = env->NewObjectArray(options.size() + 1, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183 assert(strArray != NULL);
1184 classNameStr = env->NewStringUTF(className);
1185 assert(classNameStr != NULL);
1186 env->SetObjectArrayElement(strArray, 0, classNameStr);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001187
1188 for (size_t i = 0; i < options.size(); ++i) {
1189 jstring optionsStr = env->NewStringUTF(options.itemAt(i).string());
1190 assert(optionsStr != NULL);
1191 env->SetObjectArrayElement(strArray, i + 1, optionsStr);
1192 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193
1194 /*
1195 * Start VM. This thread becomes the main thread of the VM, and will
1196 * not return until the VM exits.
1197 */
George Burgess IVd657a382017-06-20 23:53:29 -07001198 char* slashClassName = toSlashClassName(className != NULL ? className : "");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001199 jclass startClass = env->FindClass(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001200 if (startClass == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001201 ALOGE("JavaVM unable to locate class '%s'\n", slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001202 /* keep going */
1203 } else {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001204 jmethodID startMeth = env->GetStaticMethodID(startClass, "main",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001205 "([Ljava/lang/String;)V");
1206 if (startMeth == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001207 ALOGE("JavaVM unable to find main() in '%s'\n", className);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208 /* keep going */
1209 } else {
1210 env->CallStaticVoidMethod(startClass, startMeth, strArray);
1211
1212#if 0
1213 if (env->ExceptionCheck())
1214 threadExitUncaughtException(env);
1215#endif
1216 }
1217 }
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001218 free(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219
Steve Block5baa3a62011-12-20 16:23:08 +00001220 ALOGD("Shutting down VM\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221 if (mJavaVM->DetachCurrentThread() != JNI_OK)
Steve Block8564c8d2012-01-05 23:22:43 +00001222 ALOGW("Warning: unable to detach main thread\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 if (mJavaVM->DestroyJavaVM() != 0)
Steve Block8564c8d2012-01-05 23:22:43 +00001224 ALOGW("Warning: VM did not shut down cleanly\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225}
1226
Jeff Brown4280c4a2012-03-15 17:48:02 -07001227void AndroidRuntime::exit(int code)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001228{
Jeff Brown4280c4a2012-03-15 17:48:02 -07001229 if (mExitWithoutCleanup) {
1230 ALOGI("VM exiting with result code %d, cleanup skipped.", code);
1231 ::_exit(code);
1232 } else {
1233 ALOGI("VM exiting with result code %d.", code);
1234 onExit(code);
1235 ::exit(code);
1236 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237}
1238
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001239void AndroidRuntime::onVmCreated(JNIEnv* env)
1240{
1241 // If AndroidRuntime had anything to do here, we'd have done it in 'start'.
1242}
1243
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +01001244/*static*/ JavaVM* AndroidRuntime::getJavaVM() {
1245 return AndroidRuntime::mJavaVM;
1246}
1247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248/*
Andreas Huber9ae000c2014-02-13 17:22:33 +00001249 * Get the JNIEnv pointer for this thread.
1250 *
1251 * Returns NULL if the slot wasn't allocated or populated.
1252 */
1253/*static*/ JNIEnv* AndroidRuntime::getJNIEnv()
1254{
1255 JNIEnv* env;
1256 JavaVM* vm = AndroidRuntime::getJavaVM();
1257 assert(vm != NULL);
1258
1259 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
1260 return NULL;
1261 return env;
1262}
1263
1264/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 * Makes the current thread visible to the VM.
1266 *
1267 * The JNIEnv pointer returned is only valid for the current thread, and
1268 * thus must be tucked into thread-local storage.
1269 */
1270static int javaAttachThread(const char* threadName, JNIEnv** pEnv)
1271{
1272 JavaVMAttachArgs args;
1273 JavaVM* vm;
1274 jint result;
1275
1276 vm = AndroidRuntime::getJavaVM();
1277 assert(vm != NULL);
1278
1279 args.version = JNI_VERSION_1_4;
1280 args.name = (char*) threadName;
1281 args.group = NULL;
1282
1283 result = vm->AttachCurrentThread(pEnv, (void*) &args);
1284 if (result != JNI_OK)
Steve Block6215d3f2012-01-04 20:05:49 +00001285 ALOGI("NOTE: attach of thread '%s' failed\n", threadName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001286
1287 return result;
1288}
1289
1290/*
1291 * Detach the current thread from the set visible to the VM.
1292 */
1293static int javaDetachThread(void)
1294{
1295 JavaVM* vm;
1296 jint result;
1297
1298 vm = AndroidRuntime::getJavaVM();
1299 assert(vm != NULL);
1300
1301 result = vm->DetachCurrentThread();
1302 if (result != JNI_OK)
Steve Block3762c312012-01-06 19:20:56 +00001303 ALOGE("ERROR: thread detach failed\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001304 return result;
1305}
1306
1307/*
1308 * When starting a native thread that will be visible from the VM, we
1309 * bounce through this to get the right attach/detach action.
1310 * Note that this function calls free(args)
1311 */
1312/*static*/ int AndroidRuntime::javaThreadShell(void* args) {
1313 void* start = ((void**)args)[0];
1314 void* userData = ((void **)args)[1];
1315 char* name = (char*) ((void **)args)[2]; // we own this storage
1316 free(args);
1317 JNIEnv* env;
1318 int result;
1319
1320 /* hook us into the VM */
1321 if (javaAttachThread(name, &env) != JNI_OK)
1322 return -1;
1323
1324 /* start the thread running */
1325 result = (*(android_thread_func_t)start)(userData);
1326
1327 /* unhook us */
1328 javaDetachThread();
1329 free(name);
1330
1331 return result;
1332}
1333
1334/*
1335 * This is invoked from androidCreateThreadEtc() via the callback
1336 * set with androidSetCreateThreadFunc().
1337 *
1338 * We need to create the new thread in such a way that it gets hooked
1339 * into the VM before it really starts executing.
1340 */
1341/*static*/ int AndroidRuntime::javaCreateThreadEtc(
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001342 android_thread_func_t entryFunction,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001343 void* userData,
1344 const char* threadName,
1345 int32_t threadPriority,
1346 size_t threadStackSize,
1347 android_thread_id_t* threadId)
1348{
1349 void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free
1350 int result;
1351
Brian Carlstrom66f48312016-03-12 16:07:48 -08001352 LOG_ALWAYS_FATAL_IF(threadName == nullptr, "threadName not provided to javaCreateThreadEtc");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001353
1354 args[0] = (void*) entryFunction;
1355 args[1] = userData;
1356 args[2] = (void*) strdup(threadName); // javaThreadShell must free
1357
1358 result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args,
1359 threadName, threadPriority, threadStackSize, threadId);
1360 return result;
1361}
1362
1363/*
1364 * Create a thread that is visible from the VM.
1365 *
1366 * This is called from elsewhere in the library.
1367 */
Mike Lockwoodf602d362010-06-20 14:28:16 -07001368/*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001369 void (*start)(void *), void* arg)
1370{
Mike Lockwoodf602d362010-06-20 14:28:16 -07001371 android_thread_id_t threadId = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001372 javaCreateThreadEtc((android_thread_func_t) start, arg, name,
Mike Lockwoodf602d362010-06-20 14:28:16 -07001373 ANDROID_PRIORITY_DEFAULT, 0, &threadId);
1374 return threadId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001375}
1376
1377#if 0
1378static void quickTest(void* arg)
1379{
1380 const char* str = (const char*) arg;
1381
1382 printf("In quickTest: %s\n", str);
1383}
1384#endif
1385
1386#ifdef NDEBUG
1387 #define REG_JNI(name) { name }
1388 struct RegJNIRec {
1389 int (*mProc)(JNIEnv*);
1390 };
1391#else
1392 #define REG_JNI(name) { name, #name }
1393 struct RegJNIRec {
1394 int (*mProc)(JNIEnv*);
1395 const char* mName;
1396 };
1397#endif
1398
1399typedef void (*RegJAMProc)();
1400
1401static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env)
1402{
1403 for (size_t i = 0; i < count; i++) {
1404 if (array[i].mProc(env) < 0) {
1405#ifndef NDEBUG
Steve Block5baa3a62011-12-20 16:23:08 +00001406 ALOGD("----------!!! %s failed to load\n", array[i].mName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001407#endif
1408 return -1;
1409 }
1410 }
1411 return 0;
1412}
1413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001414static const RegJNIRec gRegJNI[] = {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001415 REG_JNI(register_com_android_internal_os_RuntimeInit),
Jesse Hall1fe1dc02017-07-06 15:30:39 -07001416 REG_JNI(register_com_android_internal_os_ZygoteInit_nativeZygoteInit),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001417 REG_JNI(register_android_os_SystemClock),
1418 REG_JNI(register_android_util_EventLog),
1419 REG_JNI(register_android_util_Log),
Svet Ganov53a441c2016-04-19 19:38:00 -07001420 REG_JNI(register_android_util_MemoryIntArray),
Yao Chend54f9dd2017-10-17 17:37:48 +00001421 REG_JNI(register_android_util_StatsLog),
Tej Singhbe0482b2019-03-19 22:01:57 -07001422 REG_JNI(register_android_util_StatsLogInternal),
Michal Karpinski6235a942016-03-15 12:07:23 +00001423 REG_JNI(register_android_app_admin_SecurityLog),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001424 REG_JNI(register_android_content_AssetManager),
1425 REG_JNI(register_android_content_StringBlock),
1426 REG_JNI(register_android_content_XmlBlock),
Adam Lesinskibebfcc42018-02-12 14:27:46 -08001427 REG_JNI(register_android_content_res_ApkAssets),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001428 REG_JNI(register_android_text_AndroidCharacter),
Seigo Nonaka44a1df22017-08-31 18:22:38 -07001429 REG_JNI(register_android_text_Hyphenator),
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001430 REG_JNI(register_android_view_InputDevice),
1431 REG_JNI(register_android_view_KeyCharacterMap),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 REG_JNI(register_android_os_Process),
Andreas Hubera8079bf2010-11-16 14:40:31 -08001433 REG_JNI(register_android_os_SystemProperties),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001434 REG_JNI(register_android_os_Binder),
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -08001435 REG_JNI(register_android_os_Parcel),
Ytai Ben-Tsvi4659e182019-11-06 09:53:34 -08001436 REG_JNI(register_android_os_HidlMemory),
Yifan Hongbb0bd002017-11-14 16:14:04 -08001437 REG_JNI(register_android_os_HidlSupport),
Andreas Huberc0b6c532016-08-15 09:25:02 -07001438 REG_JNI(register_android_os_HwBinder),
Andreas Huberdc263212016-08-25 11:21:21 -07001439 REG_JNI(register_android_os_HwBlob),
Andreas Huberc0b6c532016-08-15 09:25:02 -07001440 REG_JNI(register_android_os_HwParcel),
1441 REG_JNI(register_android_os_HwRemoteBinder),
Nirav Atre9850dd92018-07-24 17:03:44 -07001442 REG_JNI(register_android_os_NativeHandle),
Yifan Hongbecc56d2017-04-05 14:42:05 -07001443 REG_JNI(register_android_os_VintfObject),
Yifan Hong1bda6732017-04-26 11:38:01 -07001444 REG_JNI(register_android_os_VintfRuntimeInfo),
Chris Craik54389792013-12-20 13:28:11 -08001445 REG_JNI(register_android_view_DisplayEventReceiver),
John Recke45b1fd2014-04-15 09:50:16 -07001446 REG_JNI(register_android_view_RenderNodeAnimator),
Riddle Hsucd958bc2019-01-23 15:40:26 +08001447 REG_JNI(register_android_view_InputApplicationHandle),
1448 REG_JNI(register_android_view_InputWindowHandle),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001449 REG_JNI(register_android_view_Surface),
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001450 REG_JNI(register_android_view_SurfaceControl),
Jeff Brown64a55af2012-08-26 02:47:39 -07001451 REG_JNI(register_android_view_SurfaceSession),
Adrian Roos9b963d32019-02-13 18:39:36 +00001452 REG_JNI(register_android_view_CompositionSamplingListener),
Romain Guy8f0095c2011-05-02 17:24:22 -07001453 REG_JNI(register_android_view_TextureView),
John Reck315c3292014-05-09 19:21:04 -07001454 REG_JNI(register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001455 REG_JNI(register_com_google_android_gles_jni_EGLImpl),
1456 REG_JNI(register_com_google_android_gles_jni_GLImpl),
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001457 REG_JNI(register_android_opengl_jni_EGL14),
Courtney Goeltzenleuchter367ed8b2018-07-18 10:45:37 -06001458 REG_JNI(register_android_opengl_jni_EGL15),
Jesse Hall237c2b82013-05-06 11:36:57 -07001459 REG_JNI(register_android_opengl_jni_EGLExt),
Jack Palevich1c4907e2009-04-13 16:22:25 -07001460 REG_JNI(register_android_opengl_jni_GLES10),
1461 REG_JNI(register_android_opengl_jni_GLES10Ext),
1462 REG_JNI(register_android_opengl_jni_GLES11),
1463 REG_JNI(register_android_opengl_jni_GLES11Ext),
Jack Palevich560814f2009-11-19 16:34:55 +08001464 REG_JNI(register_android_opengl_jni_GLES20),
Jesse Halld877efe2013-04-29 15:59:35 -07001465 REG_JNI(register_android_opengl_jni_GLES30),
Jesse Hall7ab63ac2014-05-19 15:13:41 -07001466 REG_JNI(register_android_opengl_jni_GLES31),
1467 REG_JNI(register_android_opengl_jni_GLES31Ext),
Pablo Ceballos38c1a7e2015-10-30 10:34:30 -07001468 REG_JNI(register_android_opengl_jni_GLES32),
Derek Sollenberger9ca0c522019-08-29 13:08:02 -04001469 REG_JNI(register_android_graphics_classes),
Robert Carr48ec4e02019-07-16 14:28:47 -07001470 REG_JNI(register_android_graphics_BLASTBufferQueue),
sergeyv0a0f2312017-01-04 13:58:52 -08001471 REG_JNI(register_android_graphics_GraphicBuffer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001472 REG_JNI(register_android_database_CursorWindow),
Jeff Browne5360fb2011-10-31 17:48:13 -07001473 REG_JNI(register_android_database_SQLiteConnection),
1474 REG_JNI(register_android_database_SQLiteGlobal),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 REG_JNI(register_android_database_SQLiteDebug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001476 REG_JNI(register_android_os_Debug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001477 REG_JNI(register_android_os_FileObserver),
Jesse Hallb12249b2016-12-12 12:53:02 -08001478 REG_JNI(register_android_os_GraphicsEnvironment),
Christopher Tatefa9e7c02010-05-06 12:07:10 -07001479 REG_JNI(register_android_os_MessageQueue),
Stephen Smalleyc07fca32012-01-13 08:31:39 -05001480 REG_JNI(register_android_os_SELinux),
Jeff Brown481c1572012-03-09 14:41:15 -08001481 REG_JNI(register_android_os_Trace),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001482 REG_JNI(register_android_os_UEventObserver),
1483 REG_JNI(register_android_net_LocalSocketImpl),
1484 REG_JNI(register_android_net_NetworkUtils),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001485 REG_JNI(register_android_os_MemoryFile),
John Reckdea6a022017-05-25 17:09:33 -07001486 REG_JNI(register_android_os_SharedMemory),
Narayan Kamathf9419f02017-06-15 11:35:38 +01001487 REG_JNI(register_com_android_internal_os_ClassLoaderFactory),
Narayan Kamath973b4662014-03-31 13:41:26 +01001488 REG_JNI(register_com_android_internal_os_Zygote),
Jesse Hall1fe1dc02017-07-06 15:30:39 -07001489 REG_JNI(register_com_android_internal_os_ZygoteInit),
John Reck9fa40712014-05-09 15:26:59 -07001490 REG_JNI(register_com_android_internal_util_VirtualRefBasePtr),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001491 REG_JNI(register_android_hardware_Camera),
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07001492 REG_JNI(register_android_hardware_camera2_CameraMetadata),
Ruben Brunkfeb50af2014-05-09 19:58:49 -07001493 REG_JNI(register_android_hardware_camera2_legacy_LegacyCameraDevice),
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -07001494 REG_JNI(register_android_hardware_camera2_legacy_PerfMeasurement),
Ruben Brunkb6079002014-05-22 12:33:54 -07001495 REG_JNI(register_android_hardware_camera2_DngCreator),
Craig Donner1a4d07d2017-01-09 13:01:22 -08001496 REG_JNI(register_android_hardware_HardwareBuffer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497 REG_JNI(register_android_hardware_SensorManager),
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04001498 REG_JNI(register_android_hardware_SerialPort),
Eric Laurent60b62bc2014-04-18 17:50:49 -07001499 REG_JNI(register_android_hardware_SoundTrigger),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001500 REG_JNI(register_android_hardware_UsbDevice),
Mike Lockwoodacc29cc2011-03-11 08:18:08 -05001501 REG_JNI(register_android_hardware_UsbDeviceConnection),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001502 REG_JNI(register_android_hardware_UsbRequest),
Brian Duddiecfa5b5b2019-01-22 18:01:40 +00001503 REG_JNI(register_android_hardware_location_ActivityRecognitionHardware),
Eric Laurent7c31847e2018-11-29 14:33:56 -08001504 REG_JNI(register_android_media_AudioEffectDescriptor),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001505 REG_JNI(register_android_media_AudioSystem),
Paul McLeanb3ae6d92018-11-05 15:16:59 -07001506 REG_JNI(register_android_media_AudioRecord),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001507 REG_JNI(register_android_media_AudioTrack),
François Gaffieb4691282018-07-09 13:07:32 +02001508 REG_JNI(register_android_media_AudioAttributes),
François Gaffiec01fa3a2018-03-15 14:33:24 +01001509 REG_JNI(register_android_media_AudioProductStrategies),
François Gaffieadcd00a2018-09-18 17:06:26 +02001510 REG_JNI(register_android_media_AudioVolumeGroups),
1511 REG_JNI(register_android_media_AudioVolumeGroupChangeHandler),
jiabinc0f49442018-01-05 10:23:50 -08001512 REG_JNI(register_android_media_MicrophoneInfo),
Jeff Browncbad9762012-09-04 21:57:59 -07001513 REG_JNI(register_android_media_RemoteDisplay),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514 REG_JNI(register_android_media_ToneGenerator),
Paul McLean84b491302018-05-09 10:03:57 -06001515 REG_JNI(register_android_media_midi),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516
1517 REG_JNI(register_android_opengl_classes),
JP Abgrall98a4f7e2011-09-02 15:36:33 -07001518 REG_JNI(register_android_server_NetworkManagementSocketTagger),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001519 REG_JNI(register_android_ddm_DdmHandleNativeHeap),
Joe Onorato1cf58742009-06-12 11:06:24 -07001520 REG_JNI(register_android_backup_BackupDataInput),
Joe Onoratod2110db2009-05-19 13:41:21 -07001521 REG_JNI(register_android_backup_BackupDataOutput),
Joe Onorato06290a42009-06-18 20:10:37 -07001522 REG_JNI(register_android_backup_FileBackupHelperBase),
Joe Onorato4ababd92009-06-25 18:29:18 -04001523 REG_JNI(register_android_backup_BackupHelperDispatcher),
Christopher Tate4a627c72011-04-01 14:43:32 -07001524 REG_JNI(register_android_app_backup_FullBackup),
Dimitry Ivanov4449ef52016-02-25 17:41:13 -08001525 REG_JNI(register_android_app_Activity),
Chet Haase9c1e23b2011-03-24 10:51:31 -07001526 REG_JNI(register_android_app_ActivityThread),
Dianne Hackborn69969e42010-05-04 11:40:40 -07001527 REG_JNI(register_android_app_NativeActivity),
Przemyslaw Szczepaniak8a7c1602015-11-03 09:47:56 +00001528 REG_JNI(register_android_util_jar_StrictJarFile),
Jeff Brown46b9ac02010-04-22 18:58:52 -07001529 REG_JNI(register_android_view_InputChannel),
Jeff Brown32cbc38552011-12-01 14:01:49 -08001530 REG_JNI(register_android_view_InputEventReceiver),
Jeff Brownc28867a2013-03-26 15:42:39 -07001531 REG_JNI(register_android_view_InputEventSender),
Michael Wrighta44dd262013-04-10 21:12:00 -07001532 REG_JNI(register_android_view_InputQueue),
Jeff Brown46b9ac02010-04-22 18:58:52 -07001533 REG_JNI(register_android_view_KeyEvent),
1534 REG_JNI(register_android_view_MotionEvent),
Jeff Brown2352b972011-04-12 22:39:53 -07001535 REG_JNI(register_android_view_PointerIcon),
Jeff Brown2ed24622011-03-14 19:39:54 -07001536 REG_JNI(register_android_view_VelocityTracker),
Kenny Root02c87302010-07-01 08:10:18 -07001537
1538 REG_JNI(register_android_content_res_ObbScanner),
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -07001539 REG_JNI(register_android_content_res_Configuration),
Chet Haase6e0ecb42010-11-03 19:41:18 -07001540
1541 REG_JNI(register_android_animation_PropertyValuesHolder),
Bo Zhu09856132018-04-01 12:24:09 -07001542 REG_JNI(register_android_security_Scrypt),
Kenny Root66269ea2011-07-12 14:14:01 -07001543 REG_JNI(register_com_android_internal_content_NativeLibraryHelper),
Daichi Hirono878e86f2016-10-31 09:33:30 +09001544 REG_JNI(register_com_android_internal_os_FuseAppLoop),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001545};
1546
1547/*
1548 * Register android native functions with the VM.
1549 */
1550/*static*/ int AndroidRuntime::startReg(JNIEnv* env)
1551{
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001552 ATRACE_NAME("RegisterAndroidNatives");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001553 /*
1554 * This hook causes all future threads created in this process to be
1555 * attached to the JavaVM. (This needs to go away in favor of JNI
1556 * Attach calls.)
1557 */
1558 androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc);
1559
Steve Block71f2cf12011-10-20 11:56:00 +01001560 ALOGV("--- registering native functions ---\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561
1562 /*
1563 * Every "register" function calls one or more things that return
1564 * a local reference (e.g. FindClass). Because we haven't really
1565 * started the VM yet, they're all getting stored in the base frame
1566 * and never released. Use Push/Pop to manage the storage.
1567 */
1568 env->PushLocalFrame(200);
1569
1570 if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) {
1571 env->PopLocalFrame(NULL);
1572 return -1;
1573 }
1574 env->PopLocalFrame(NULL);
1575
1576 //createJavaThread("fubar", quickTest, (void*) "hello");
1577
1578 return 0;
1579}
1580
1581AndroidRuntime* AndroidRuntime::getRuntime()
1582{
1583 return gCurRuntime;
1584}
1585
1586/**
Narayan Kamathc21dab92015-06-25 14:22:00 +01001587 * Used by surface flinger's DdmConnection to register native methods from
1588 * the framework.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 */
Narayan Kamathc21dab92015-06-25 14:22:00 +01001590extern "C" jint registerFrameworkNatives(JNIEnv* env) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001591 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1592}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001593} // namespace android