blob: 8b6fc59758e42241f28170fde503fb758ce4a183 [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
23#include <android-base/properties.h>
Mathias Agopian07952722009-05-19 19:08:10 -070024#include <binder/IBinder.h>
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -080025#include <binder/IPCThreadState.h>
Mathias Agopian07952722009-05-19 19:08:10 -070026#include <binder/IServiceManager.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027#include <utils/Log.h>
28#include <utils/misc.h>
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +090029#include <utils/Trace.h>
Mathias Agopian07952722009-05-19 19:08:10 -070030#include <binder/Parcel.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031#include <utils/threads.h>
32#include <cutils/properties.h>
33
34#include <SkGraphics.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035
36#include "jni.h"
Steven Moreland2279b252017-07-19 09:50:45 -070037#include <nativehelper/JNIHelp.h>
38#include <nativehelper/JniInvocation.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039#include "android_util_Binder.h"
40
41#include <stdio.h>
42#include <signal.h>
43#include <sys/stat.h>
44#include <sys/types.h>
45#include <signal.h>
46#include <dirent.h>
47#include <assert.h>
48
Narayan Kamathbf882052015-08-11 15:40:34 +010049#include <string>
50#include <vector>
51
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052using namespace android;
Tom Cherry93099e42017-10-11 13:44:21 -070053using android::base::GetProperty;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055extern int register_android_os_Binder(JNIEnv* env);
56extern int register_android_os_Process(JNIEnv* env);
57extern int register_android_graphics_Bitmap(JNIEnv*);
58extern int register_android_graphics_BitmapFactory(JNIEnv*);
Wei-Ta Chen6b849e22010-09-07 17:32:18 +080059extern int register_android_graphics_BitmapRegionDecoder(JNIEnv*);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060extern int register_android_graphics_Camera(JNIEnv* env);
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -040061extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env);
sergeyv0a0f2312017-01-04 13:58:52 -080062extern int register_android_graphics_GraphicBuffer(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063extern int register_android_graphics_Graphics(JNIEnv* env);
64extern int register_android_graphics_Interpolator(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065extern int register_android_graphics_MaskFilter(JNIEnv* env);
66extern int register_android_graphics_Movie(JNIEnv* env);
67extern int register_android_graphics_NinePatch(JNIEnv*);
68extern int register_android_graphics_PathEffect(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069extern int register_android_graphics_Shader(JNIEnv* env);
70extern int register_android_graphics_Typeface(JNIEnv* env);
Wei-Ta Chenbca2d612009-11-30 17:52:05 +080071extern int register_android_graphics_YuvImage(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072
73extern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env);
74extern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070075extern int register_android_opengl_jni_EGL14(JNIEnv* env);
Jesse Hall237c2b82013-05-06 11:36:57 -070076extern int register_android_opengl_jni_EGLExt(JNIEnv* env);
Jack Palevich1c4907e2009-04-13 16:22:25 -070077extern int register_android_opengl_jni_GLES10(JNIEnv* env);
78extern int register_android_opengl_jni_GLES10Ext(JNIEnv* env);
79extern int register_android_opengl_jni_GLES11(JNIEnv* env);
80extern int register_android_opengl_jni_GLES11Ext(JNIEnv* env);
Jack Palevich560814f2009-11-19 16:34:55 +080081extern int register_android_opengl_jni_GLES20(JNIEnv* env);
Jesse Halld877efe2013-04-29 15:59:35 -070082extern int register_android_opengl_jni_GLES30(JNIEnv* env);
Jesse Hall7ab63ac2014-05-19 15:13:41 -070083extern int register_android_opengl_jni_GLES31(JNIEnv* env);
84extern int register_android_opengl_jni_GLES31Ext(JNIEnv* env);
Pablo Ceballos38c1a7e2015-10-30 10:34:30 -070085extern int register_android_opengl_jni_GLES32(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086
87extern int register_android_hardware_Camera(JNIEnv *env);
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -070088extern int register_android_hardware_camera2_CameraMetadata(JNIEnv *env);
Ruben Brunkfeb50af2014-05-09 19:58:49 -070089extern int register_android_hardware_camera2_legacy_LegacyCameraDevice(JNIEnv *env);
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -070090extern int register_android_hardware_camera2_legacy_PerfMeasurement(JNIEnv *env);
Ruben Brunkb6079002014-05-22 12:33:54 -070091extern int register_android_hardware_camera2_DngCreator(JNIEnv *env);
Craig Donner1a4d07d2017-01-09 13:01:22 -080092extern int register_android_hardware_HardwareBuffer(JNIEnv *env);
Eric Laurent633cb562015-03-05 15:17:20 -080093extern int register_android_hardware_Radio(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094extern int register_android_hardware_SensorManager(JNIEnv *env);
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -040095extern int register_android_hardware_SerialPort(JNIEnv *env);
Eric Laurent60b62bc2014-04-18 17:50:49 -070096extern int register_android_hardware_SoundTrigger(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -050097extern int register_android_hardware_UsbDevice(JNIEnv *env);
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050098extern int register_android_hardware_UsbDeviceConnection(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -050099extern int register_android_hardware_UsbRequest(JNIEnv *env);
destradaaa4fa3b52014-07-09 10:46:39 -0700100extern int register_android_hardware_location_ActivityRecognitionHardware(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101
102extern int register_android_media_AudioRecord(JNIEnv *env);
103extern int register_android_media_AudioSystem(JNIEnv *env);
104extern int register_android_media_AudioTrack(JNIEnv *env);
105extern int register_android_media_JetPlayer(JNIEnv *env);
106extern int register_android_media_ToneGenerator(JNIEnv *env);
107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108namespace android {
109
110/*
111 * JNI-based registration functions. Note these are properly contained in
112 * namespace android.
113 */
Michal Karpinski6235a942016-03-15 12:07:23 +0000114extern int register_android_app_admin_SecurityLog(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115extern int register_android_content_AssetManager(JNIEnv* env);
116extern int register_android_util_EventLog(JNIEnv* env);
117extern int register_android_util_Log(JNIEnv* env);
Svet Ganov53a441c2016-04-19 19:38:00 -0700118extern int register_android_util_MemoryIntArray(JNIEnv* env);
Doris Liucdd23f92015-11-11 14:31:13 -0800119extern int register_android_util_PathParser(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120extern int register_android_content_StringBlock(JNIEnv* env);
121extern int register_android_content_XmlBlock(JNIEnv* env);
122extern int register_android_graphics_Canvas(JNIEnv* env);
John Reck52244ff2014-05-01 21:27:37 -0700123extern int register_android_graphics_CanvasProperty(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124extern int register_android_graphics_ColorFilter(JNIEnv* env);
125extern int register_android_graphics_DrawFilter(JNIEnv* env);
Raph Levien1a73f7322014-01-30 16:06:28 -0800126extern int register_android_graphics_FontFamily(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127extern int register_android_graphics_Matrix(JNIEnv* env);
128extern int register_android_graphics_Paint(JNIEnv* env);
129extern int register_android_graphics_Path(JNIEnv* env);
130extern int register_android_graphics_PathMeasure(JNIEnv* env);
131extern int register_android_graphics_Picture(JNIEnv*);
Jeff Brownfbf09772011-01-16 14:06:57 -0800132extern int register_android_graphics_Region(JNIEnv* env);
Jamie Gennisaa0ce332011-01-06 17:04:26 -0800133extern int register_android_graphics_SurfaceTexture(JNIEnv* env);
Doris Liu766431a2016-02-04 22:17:11 +0000134extern int register_android_graphics_drawable_AnimatedVectorDrawable(JNIEnv* env);
Doris Liu4bbc2932015-12-01 17:59:40 -0800135extern int register_android_graphics_drawable_VectorDrawable(JNIEnv* env);
Svetoslav6811f4e2013-09-18 15:58:28 -0700136extern int register_android_graphics_pdf_PdfDocument(JNIEnv* env);
Svetoslav62ce3322014-09-04 21:17:17 -0700137extern int register_android_graphics_pdf_PdfEditor(JNIEnv* env);
Svetoslav29617692014-04-24 18:40:42 -0700138extern int register_android_graphics_pdf_PdfRenderer(JNIEnv* env);
Jeff Brown0a0a1242011-12-02 02:25:22 -0800139extern int register_android_view_DisplayEventReceiver(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700140extern int register_android_view_DisplayListCanvas(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700141extern int register_android_view_HardwareLayer(JNIEnv* env);
John Reckf666ad72014-03-14 16:24:57 -0700142extern int register_android_view_RenderNode(JNIEnv* env);
John Recke45b1fd2014-04-15 09:50:16 -0700143extern int register_android_view_RenderNodeAnimator(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144extern int register_android_view_Surface(JNIEnv* env);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800145extern int register_android_view_SurfaceControl(JNIEnv* env);
Jeff Brown64a55af2012-08-26 02:47:39 -0700146extern int register_android_view_SurfaceSession(JNIEnv* env);
Romain Guy8f0095c2011-05-02 17:24:22 -0700147extern int register_android_view_TextureView(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700148extern int register_android_view_ThreadedRenderer(JNIEnv* env);
John Reck315c3292014-05-09 19:21:04 -0700149extern int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150extern int register_android_database_CursorWindow(JNIEnv* env);
Jeff Browne5360fb2011-10-31 17:48:13 -0700151extern int register_android_database_SQLiteConnection(JNIEnv* env);
152extern int register_android_database_SQLiteGlobal(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153extern int register_android_database_SQLiteDebug(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154extern int register_android_nio_utils(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155extern int register_android_os_Debug(JNIEnv* env);
Jesse Hallb12249b2016-12-12 12:53:02 -0800156extern int register_android_os_GraphicsEnvironment(JNIEnv* env);
Andreas Huberc0b6c532016-08-15 09:25:02 -0700157extern int register_android_os_HwBinder(JNIEnv *env);
Andreas Huberdc263212016-08-25 11:21:21 -0700158extern int register_android_os_HwBlob(JNIEnv *env);
Andreas Huberc0b6c532016-08-15 09:25:02 -0700159extern int register_android_os_HwParcel(JNIEnv *env);
160extern int register_android_os_HwRemoteBinder(JNIEnv *env);
Christopher Tatefa9e7c02010-05-06 12:07:10 -0700161extern int register_android_os_MessageQueue(JNIEnv* env);
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -0800162extern int register_android_os_Parcel(JNIEnv* env);
Stephen Smalleyc07fca32012-01-13 08:31:39 -0500163extern int register_android_os_SELinux(JNIEnv* env);
Yifan Hongbecc56d2017-04-05 14:42:05 -0700164extern int register_android_os_VintfObject(JNIEnv *env);
Yifan Hong1bda6732017-04-26 11:38:01 -0700165extern int register_android_os_VintfRuntimeInfo(JNIEnv *env);
Paul Lawrenceef854772017-01-31 09:54:31 -0800166extern int register_android_os_seccomp(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167extern int register_android_os_SystemProperties(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168extern int register_android_os_SystemClock(JNIEnv* env);
Jeff Brown481c1572012-03-09 14:41:15 -0800169extern int register_android_os_Trace(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170extern int register_android_os_FileObserver(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171extern int register_android_os_UEventObserver(JNIEnv* env);
172extern int register_android_os_MemoryFile(JNIEnv* env);
173extern int register_android_net_LocalSocketImpl(JNIEnv* env);
174extern int register_android_net_NetworkUtils(JNIEnv* env);
Dan Egnor2b4abcd2010-04-07 17:30:50 -0700175extern int register_android_net_TrafficStats(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176extern int register_android_text_AndroidCharacter(JNIEnv *env);
Anish Athalye88b5b0b2014-06-24 14:39:43 -0700177extern int register_android_text_StaticLayout(JNIEnv *env);
Doug Feltdae8e942010-02-24 14:33:15 -0800178extern int register_android_text_AndroidBidi(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179extern int register_android_opengl_classes(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
Narayan Kamath29564cd2014-08-07 10:57:40 +0100181extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env);
Joe Onorato1cf58742009-06-12 11:06:24 -0700182extern int register_android_backup_BackupDataInput(JNIEnv *env);
Joe Onoratod2110db2009-05-19 13:41:21 -0700183extern int register_android_backup_BackupDataOutput(JNIEnv *env);
Joe Onorato06290a42009-06-18 20:10:37 -0700184extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
Joe Onorato4ababd92009-06-25 18:29:18 -0400185extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
Christopher Tate4a627c72011-04-01 14:43:32 -0700186extern int register_android_app_backup_FullBackup(JNIEnv *env);
Dimitry Ivanov4449ef52016-02-25 17:41:13 -0800187extern int register_android_app_Activity(JNIEnv *env);
Chet Haase9c1e23b2011-03-24 10:51:31 -0700188extern int register_android_app_ActivityThread(JNIEnv *env);
Dimitry Ivanov09979082016-04-19 11:11:01 -0700189extern int register_android_app_ApplicationLoaders(JNIEnv *env);
Dianne Hackborn69969e42010-05-04 11:40:40 -0700190extern int register_android_app_NativeActivity(JNIEnv *env);
Jeff Browncbad9762012-09-04 21:57:59 -0700191extern int register_android_media_RemoteDisplay(JNIEnv *env);
Przemyslaw Szczepaniak8a7c1602015-11-03 09:47:56 +0000192extern int register_android_util_jar_StrictJarFile(JNIEnv* env);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700193extern int register_android_view_InputChannel(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700194extern int register_android_view_InputDevice(JNIEnv* env);
Jeff Brown32cbc38552011-12-01 14:01:49 -0800195extern int register_android_view_InputEventReceiver(JNIEnv* env);
Jeff Brownc28867a2013-03-26 15:42:39 -0700196extern int register_android_view_InputEventSender(JNIEnv* env);
Michael Wrighta44dd262013-04-10 21:12:00 -0700197extern int register_android_view_InputQueue(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700198extern int register_android_view_KeyCharacterMap(JNIEnv *env);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700199extern int register_android_view_KeyEvent(JNIEnv* env);
200extern int register_android_view_MotionEvent(JNIEnv* env);
Jeff Brown2352b972011-04-12 22:39:53 -0700201extern int register_android_view_PointerIcon(JNIEnv* env);
Jeff Brown2ed24622011-03-14 19:39:54 -0700202extern int register_android_view_VelocityTracker(JNIEnv* env);
Kenny Root02c87302010-07-01 08:10:18 -0700203extern int register_android_content_res_ObbScanner(JNIEnv* env);
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700204extern int register_android_content_res_Configuration(JNIEnv* env);
Chet Haase6e0ecb42010-11-03 19:41:18 -0700205extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
Kenny Root66269ea2011-07-12 14:14:01 -0700206extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -0800207extern int register_com_android_internal_net_NetworkStatsFactory(JNIEnv *env);
Daichi Hirono878e86f2016-10-31 09:33:30 +0900208extern int register_com_android_internal_os_FuseAppLoop(JNIEnv* env);
Dimitry Ivanov5d7d7772016-04-20 14:09:32 -0700209extern int register_com_android_internal_os_PathClassLoaderFactory(JNIEnv* env);
Narayan Kamath973b4662014-03-31 13:41:26 +0100210extern int register_com_android_internal_os_Zygote(JNIEnv *env);
Jesse Hall42cf26e2017-07-06 15:30:39 -0700211extern int register_com_android_internal_os_ZygoteInit(JNIEnv *env);
John Reck9fa40712014-05-09 15:26:59 -0700212extern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213
214static AndroidRuntime* gCurRuntime = NULL;
215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216/*
217 * Code written in the Java Programming Language calls here from main().
218 */
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700219static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220{
221 gCurRuntime->onStarted();
222}
223
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800224static void com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225{
226 gCurRuntime->onZygoteInit();
227}
228
Jeff Brown4280c4a2012-03-15 17:48:02 -0700229static void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIEnv* env,
230 jobject clazz, jboolean exitWithoutCleanup)
231{
232 gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup);
233}
234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235/*
236 * JNI registration.
237 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238
239int register_com_android_internal_os_RuntimeInit(JNIEnv* env)
240{
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800241 const JNINativeMethod methods[] = {
242 { "nativeFinishInit", "()V",
243 (void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
244 { "nativeSetExitWithoutCleanup", "(Z)V",
245 (void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
246 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800248 methods, NELEM(methods));
249}
250
Jesse Hall42cf26e2017-07-06 15:30:39 -0700251int register_com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv* env)
Andreas Gampe76d4fc82017-02-07 19:44:37 -0800252{
253 const JNINativeMethod methods[] = {
254 { "nativeZygoteInit", "()V",
255 (void*) com_android_internal_os_ZygoteInit_nativeZygoteInit },
256 };
257 return jniRegisterNativeMethods(env, "com/android/internal/os/ZygoteInit",
258 methods, NELEM(methods));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259}
260
261// ----------------------------------------------------------------------
262
Andreas Huber9ae000c2014-02-13 17:22:33 +0000263/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
264
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000265AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) :
266 mExitWithoutCleanup(false),
267 mArgBlockStart(argBlockStart),
268 mArgBlockLength(argBlockLength)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700270 SkGraphics::Init();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271
272 // Pre-allocate enough space to hold a fair number of options.
273 mOptions.setCapacity(20);
274
275 assert(gCurRuntime == NULL); // one per process
276 gCurRuntime = this;
277}
278
279AndroidRuntime::~AndroidRuntime()
280{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281}
282
Andreas Huber9ae000c2014-02-13 17:22:33 +0000283/*
284 * Register native methods using JNI.
285 */
286/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
287 const char* className, const JNINativeMethod* gMethods, int numMethods)
288{
289 return jniRegisterNativeMethods(env, className, gMethods, numMethods);
290}
291
Dmitriy Filchenkof5b6e552016-07-18 16:00:35 -0700292void AndroidRuntime::setArgv0(const char* argv0, bool setProcName) {
293 if (setProcName) {
294 int len = strlen(argv0);
295 if (len < 15) {
296 pthread_setname_np(pthread_self(), argv0);
297 } else {
298 pthread_setname_np(pthread_self(), argv0 + len - 15);
299 }
300 }
Jeff Brown00c0cd42014-09-10 16:48:46 -0700301 memset(mArgBlockStart, 0, mArgBlockLength);
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000302 strlcpy(mArgBlockStart, argv0, mArgBlockLength);
303}
304
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100305status_t AndroidRuntime::callMain(const String8& className, jclass clazz,
306 const Vector<String8>& args)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307{
308 JNIEnv* env;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 jmethodID methodId;
310
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100311 ALOGD("Calling main entry %s", className.string());
Dianne Hackborn08e60f22010-09-01 18:17:17 -0700312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313 env = getJNIEnv();
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700314 if (clazz == NULL || env == NULL) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 return UNKNOWN_ERROR;
316 }
317
318 methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
319 if (methodId == NULL) {
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100320 ALOGE("ERROR: could not find method %s.main(String[])\n", className.string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321 return UNKNOWN_ERROR;
322 }
323
324 /*
325 * We want to call main() with a String array with our arguments in it.
326 * Create an array and populate it.
327 */
328 jclass stringClass;
329 jobjectArray strArray;
330
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100331 const size_t numArgs = args.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 stringClass = env->FindClass("java/lang/String");
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100333 strArray = env->NewObjectArray(numArgs, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100335 for (size_t i = 0; i < numArgs; i++) {
336 jstring argStr = env->NewStringUTF(args[i].string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337 env->SetObjectArrayElement(strArray, i, argStr);
338 }
339
340 env->CallStaticVoidMethod(clazz, methodId, strArray);
341 return NO_ERROR;
342}
343
344/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 * The VM calls this through the "exit" hook.
346 */
347static void runtime_exit(int code)
348{
Jeff Brown4280c4a2012-03-15 17:48:02 -0700349 gCurRuntime->exit(code);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350}
351
352/*
353 * The VM calls this through the "vfprintf" hook.
354 *
355 * We ignore "fp" and just write the results to the log file.
356 */
357static void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
358{
359 LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
360}
361
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800362/**
363 * The VM calls this when mutex contention debugging is enabled to
364 * determine whether or not the blocked thread was a "sensitive thread"
365 * for user responsiveness/smoothess.
366 *
367 * Our policy for this is whether or not we're tracing any StrictMode
368 * events on this thread (which we might've inherited via Binder calls
369 * into us)
370 */
371static bool runtime_isSensitiveThread() {
372 IPCThreadState* state = IPCThreadState::selfOrNull();
373 return state && state->getStrictModePolicy() != 0;
374}
375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376static int hasDir(const char* dir)
377{
378 struct stat s;
379 int res = stat(dir, &s);
380 if (res == 0) {
381 return S_ISDIR(s.st_mode);
382 }
383 return 0;
384}
385
Andreas Gampe995c62d2014-11-14 16:15:17 -0800386static bool hasFile(const char* file) {
387 struct stat s;
388 int res = stat(file, &s);
389 if (res == 0) {
390 return S_ISREG(s.st_mode);
391 }
392 return false;
393}
394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395/*
Narayan Kamathbf882052015-08-11 15:40:34 +0100396 * Read the persistent locale. Inspects the following system properties
397 * (in order) and returns the first non-empty property in the list :
398 *
399 * (1) persist.sys.locale
400 * (2) persist.sys.language/country/localevar (country and localevar are
401 * inspected iff. language is non-empty.
402 * (3) ro.product.locale
403 * (4) ro.product.locale.language/region
404 *
405 * Note that we need to inspect persist.sys.language/country/localevar to
406 * preserve language settings for devices that are upgrading from Lollipop
407 * to M. The same goes for ro.product.locale.language/region as well.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408 */
Narayan Kamathbf882052015-08-11 15:40:34 +0100409const std::string readLocale()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410{
Tom Cherry93099e42017-10-11 13:44:21 -0700411 const std::string locale = GetProperty("persist.sys.locale", "");
Narayan Kamathbf882052015-08-11 15:40:34 +0100412 if (!locale.empty()) {
413 return locale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800414 }
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000415
Tom Cherry93099e42017-10-11 13:44:21 -0700416 const std::string language = GetProperty("persist.sys.language", "");
Narayan Kamathbf882052015-08-11 15:40:34 +0100417 if (!language.empty()) {
Tom Cherry93099e42017-10-11 13:44:21 -0700418 const std::string country = GetProperty("persist.sys.country", "");
419 const std::string variant = GetProperty("persist.sys.localevar", "");
Narayan Kamathbf882052015-08-11 15:40:34 +0100420
421 std::string out = language;
422 if (!country.empty()) {
423 out = out + "-" + country;
424 }
425
426 if (!variant.empty()) {
427 out = out + "-" + variant;
428 }
429
430 return out;
431 }
432
Tom Cherry93099e42017-10-11 13:44:21 -0700433 const std::string productLocale = GetProperty("ro.product.locale", "");
Narayan Kamathbf882052015-08-11 15:40:34 +0100434 if (!productLocale.empty()) {
435 return productLocale;
436 }
437
438 // If persist.sys.locale and ro.product.locale are missing,
439 // construct a locale value from the individual locale components.
Tom Cherry93099e42017-10-11 13:44:21 -0700440 const std::string productLanguage = GetProperty("ro.product.locale.language", "en");
441 const std::string productRegion = GetProperty("ro.product.locale.region", "US");
Narayan Kamathbf882052015-08-11 15:40:34 +0100442
443 return productLanguage + "-" + productRegion;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444}
445
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700446void AndroidRuntime::addOption(const char* optionString, void* extraInfo)
447{
448 JavaVMOption opt;
449 opt.optionString = optionString;
450 opt.extraInfo = extraInfo;
451 mOptions.add(opt);
452}
453
Andy McFaddenf70188a2009-03-31 15:52:13 -0700454/*
Andy McFaddene4d81f22010-07-14 16:02:20 -0700455 * Parse a property containing space-separated options that should be
456 * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
457 *
458 * This will cut up "extraOptsBuf" as we chop it into individual options.
459 *
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800460 * If "quotingArg" is non-null, it is passed before each extra option in mOptions.
461 *
Andy McFaddene4d81f22010-07-14 16:02:20 -0700462 * Adds the strings, if any, to mOptions.
463 */
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800464void AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg)
Andy McFaddene4d81f22010-07-14 16:02:20 -0700465{
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800466 char* start = extraOptsBuf;
467 char* end = NULL;
Andy McFaddene4d81f22010-07-14 16:02:20 -0700468 while (*start != '\0') {
469 while (*start == ' ') /* skip leading whitespace */
470 start++;
471 if (*start == '\0') /* was trailing ws, bail */
472 break;
473
474 end = start+1;
475 while (*end != ' ' && *end != '\0') /* find end of token */
476 end++;
477 if (*end == ' ')
478 *end++ = '\0'; /* mark end, advance to indicate more */
479
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800480 if (quotingArg != NULL) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700481 addOption(quotingArg);
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800482 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700483 addOption(start);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700484 start = end;
485 }
486}
487
488/*
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700489 * Reads a "property" into "buffer" with a default of "defaultArg". If
490 * the property is non-empty, it is treated as a runtime option such
491 * as "-Xmx32m".
492 *
493 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
494 *
495 * If an argument is found, it is added to mOptions.
496 *
497 * If an option is found, it is added to mOptions and true is
498 * returned. Otherwise false is returned.
499 */
500bool AndroidRuntime::parseRuntimeOption(const char* property,
501 char* buffer,
502 const char* runtimeArg,
503 const char* defaultArg)
504{
505 strcpy(buffer, runtimeArg);
506 size_t runtimeArgLen = strlen(runtimeArg);
507 property_get(property, buffer+runtimeArgLen, defaultArg);
508 if (buffer[runtimeArgLen] == '\0') {
509 return false;
510 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700511 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700512 return true;
513}
514
515/*
516 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700517 * is treated as a dex2oat compiler option that should be
Nicolas Geoffraybe7b0d12017-04-25 12:29:07 +0100518 * passed as a quoted option, e.g. "-Ximage-compiler-option --compiler-filter=assume-verified".
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700519 *
520 * The "compilerArg" is a prefix for the option such as "--compiler-filter=".
521 *
522 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
523 *
524 * If an option is found, it is added to mOptions and true is
525 * returned. Otherwise false is returned.
526 */
527bool AndroidRuntime::parseCompilerOption(const char* property,
528 char* buffer,
529 const char* compilerArg,
530 const char* quotingArg)
531{
532 strcpy(buffer, compilerArg);
533 size_t compilerArgLen = strlen(compilerArg);
534 property_get(property, buffer+compilerArgLen, "");
535 if (buffer[compilerArgLen] == '\0') {
536 return false;
537 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700538 addOption(quotingArg);
539 addOption(buffer);
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700540 return true;
541}
542
543/*
544 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700545 * is treated as a dex2oat compiler runtime option that should be
546 * passed as a quoted option, e.g. "-Ximage-compiler-option
547 * --runtime-arg -Ximage-compiler-option -Xmx32m".
548 *
549 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
550 *
551 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
552 *
553 * If an option is found, it is added to mOptions and true is
554 * returned. Otherwise false is returned.
555 */
556bool AndroidRuntime::parseCompilerRuntimeOption(const char* property,
557 char* buffer,
558 const char* runtimeArg,
559 const char* quotingArg)
560{
561 strcpy(buffer, runtimeArg);
562 size_t runtimeArgLen = strlen(runtimeArg);
563 property_get(property, buffer+runtimeArgLen, "");
564 if (buffer[runtimeArgLen] == '\0') {
565 return false;
566 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700567 addOption(quotingArg);
568 addOption("--runtime-arg");
569 addOption(quotingArg);
570 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700571 return true;
572}
573
574/*
Andy McFaddenf70188a2009-03-31 15:52:13 -0700575 * Start the Dalvik Virtual Machine.
576 *
577 * Various arguments, most determined by system properties, are passed in.
578 * The "mOptions" vector is updated.
579 *
Dave Allison07a1e232014-03-14 08:54:33 -0700580 * CAUTION: when adding options in here, be careful not to put the
581 * char buffer inside a nested scope. Adding the buffer to the
582 * options using mOptions.add() does not copy the buffer, so if the
583 * buffer goes out of scope the option may be overwritten. It's best
584 * to put the buffer at the top of the function so that it is more
585 * unlikely that someone will surround it in a scope at a later time
586 * and thus introduce a bug.
587 *
Andy McFaddenf70188a2009-03-31 15:52:13 -0700588 * Returns 0 on success.
589 */
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200590int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 JavaVMInitArgs initArgs;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 char propBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700594 char stackTraceFileBuf[sizeof("-Xstacktracefile:")-1 + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro38cfa8c2010-12-07 16:48:29 -0800596 char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700597 char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro8cdf27c32011-01-19 12:33:12 -0800598 char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700599 char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
600 char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800601 char usejitOptsBuf[sizeof("-Xusejit:")-1 + PROPERTY_VALUE_MAX];
Nicolas Geoffraycdf1dff2015-11-19 13:48:35 +0000602 char jitmaxsizeOptsBuf[sizeof("-Xjitmaxsize:")-1 + PROPERTY_VALUE_MAX];
603 char jitinitialsizeOptsBuf[sizeof("-Xjitinitialsize:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800604 char jitthresholdOptsBuf[sizeof("-Xjitthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravledb4a79a2015-12-23 18:55:08 +0200605 char useJitProfilesOptsBuf[sizeof("-Xjitsaveprofilinginfo:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle0de80b92016-04-12 14:12:04 +0100606 char jitprithreadweightOptBuf[sizeof("-Xjitprithreadweight:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle8d74de52016-04-27 14:12:00 +0100607 char jittransitionweightOptBuf[sizeof("-Xjittransitionweight:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier42cd2652017-06-07 17:34:22 -0700608 char hotstartupsamplesOptsBuf[sizeof("-Xps-hot-startup-method-samples:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier7e4fdec2013-12-02 15:46:51 -0800609 char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700610 char backgroundgcOptsBuf[sizeof("-XX:BackgroundGC=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700611 char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee324ba02015-03-31 16:15:17 -0700612 char cachePruneBuf[sizeof("-Xzygote-max-boot-retry=")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700613 char dex2oatXmsImageFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
614 char dex2oatXmxImageFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
615 char dex2oatXmsFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
616 char dex2oatXmxFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700617 char dex2oatCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
618 char dex2oatImageCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee0352382015-03-30 18:43:39 -0700619 char dex2oatThreadsBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
620 char dex2oatThreadsImageBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
Andreas Gampe605cca12015-04-02 23:12:56 -0700621 char dex2oat_isa_variant_key[PROPERTY_KEY_MAX];
622 char dex2oat_isa_variant[sizeof("--instruction-set-variant=") -1 + PROPERTY_VALUE_MAX];
623 char dex2oat_isa_features_key[PROPERTY_KEY_MAX];
624 char dex2oat_isa_features[sizeof("--instruction-set-features=") -1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800625 char dex2oatFlagsBuf[PROPERTY_VALUE_MAX];
626 char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX];
Andy McFaddene4d81f22010-07-14 16:02:20 -0700627 char extraOptsBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700628 char voldDecryptBuf[PROPERTY_VALUE_MAX];
Ben Cheng52b0e732009-06-19 13:31:12 -0700629 enum {
630 kEMDefault,
631 kEMIntPortable,
632 kEMIntFast,
Ben Cheng52b0e732009-06-19 13:31:12 -0700633 kEMJitCompiler,
Ben Cheng52b0e732009-06-19 13:31:12 -0700634 } executionMode = kEMDefault;
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000635 char localeOption[sizeof("-Duser.locale=") + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700636 char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle01db9162014-08-07 14:45:53 +0100637 char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX];
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700638 char cpuAbiListBuf[sizeof("--cpu-abilist=") + PROPERTY_VALUE_MAX];
Andreas Gampe98f406f2015-06-22 21:09:36 -0700639 char methodTraceFileBuf[sizeof("-Xmethod-trace-file:") + PROPERTY_VALUE_MAX];
640 char methodTraceFileSizeBuf[sizeof("-Xmethod-trace-file-size:") + PROPERTY_VALUE_MAX];
Tom Cherry93099e42017-10-11 13:44:21 -0700641 std::string fingerprintBuf;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800642
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700643 bool checkJni = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 property_get("dalvik.vm.checkjni", propBuf, "");
645 if (strcmp(propBuf, "true") == 0) {
646 checkJni = true;
647 } else if (strcmp(propBuf, "false") != 0) {
648 /* property is neither true nor false; fall back on kernel parameter */
649 property_get("ro.kernel.android.checkjni", propBuf, "");
650 if (propBuf[0] == '1') {
651 checkJni = true;
652 }
653 }
Joe Onorato82ba91d2017-04-27 16:18:05 -0700654 ALOGV("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700655 if (checkJni) {
656 /* extended JNI checking */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700657 addOption("-Xcheck:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700658
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700659 /* with -Xcheck:jni, this provides a JNI function call trace */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700660 //addOption("-verbose:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700661 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662
663 property_get("dalvik.vm.execution-mode", propBuf, "");
664 if (strcmp(propBuf, "int:portable") == 0) {
665 executionMode = kEMIntPortable;
666 } else if (strcmp(propBuf, "int:fast") == 0) {
667 executionMode = kEMIntFast;
Ben Cheng52b0e732009-06-19 13:31:12 -0700668 } else if (strcmp(propBuf, "int:jit") == 0) {
669 executionMode = kEMJitCompiler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 }
671
Narayan Kamath93f2e382017-04-25 14:24:07 +0100672 // If dalvik.vm.stack-trace-dir is set, it enables the "new" stack trace
673 // dump scheme and a new file is created for each stack dump. If it isn't set,
674 // the old scheme is enabled.
Narayan Kamath23941e52017-05-10 18:56:12 +0100675 property_get("dalvik.vm.stack-trace-dir", propBuf, "");
676 if (strlen(propBuf) > 0) {
677 addOption("-Xusetombstonedtraces");
678 } else {
Narayan Kamath93f2e382017-04-25 14:24:07 +0100679 parseRuntimeOption("dalvik.vm.stack-trace-file", stackTraceFileBuf, "-Xstacktracefile:");
680 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 strcpy(jniOptsBuf, "-Xjniopts:");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700683 if (parseRuntimeOption("dalvik.vm.jniopts", jniOptsBuf, "-Xjniopts:")) {
684 ALOGI("JNI options: '%s'\n", jniOptsBuf);
685 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 /* route exit() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700688 addOption("exit", (void*) runtime_exit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689
690 /* route fprintf() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700691 addOption("vfprintf", (void*) runtime_vfprintf);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800693 /* register the framework-specific "is sensitive thread" hook */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700694 addOption("sensitiveThread", (void*) runtime_isSensitiveThread);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800695
696 /* enable verbose; standard options are { jni, gc, class } */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700697 //addOption("-verbose:jni");
698 addOption("-verbose:gc");
699 //addOption("-verbose:class");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800700
Carl Shapiro9e4c8842010-12-08 12:14:46 -0800701 /*
702 * The default starting and maximum size of the heap. Larger
703 * values should be specified in a product property override.
704 */
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700705 parseRuntimeOption("dalvik.vm.heapstartsize", heapstartsizeOptsBuf, "-Xms", "4m");
706 parseRuntimeOption("dalvik.vm.heapsize", heapsizeOptsBuf, "-Xmx", "16m");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700708 parseRuntimeOption("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
709 parseRuntimeOption("dalvik.vm.heapminfree", heapminfreeOptsBuf, "-XX:HeapMinFree=");
710 parseRuntimeOption("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf, "-XX:HeapMaxFree=");
711 parseRuntimeOption("dalvik.vm.heaptargetutilization",
712 heaptargetutilizationOptsBuf,
713 "-XX:HeapTargetUtilization=");
Ian Rogers53250102012-09-23 16:38:03 -0700714
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800715 /*
716 * JIT related options.
717 */
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700718 parseRuntimeOption("dalvik.vm.usejit", usejitOptsBuf, "-Xusejit:");
Nicolas Geoffraycdf1dff2015-11-19 13:48:35 +0000719 parseRuntimeOption("dalvik.vm.jitmaxsize", jitmaxsizeOptsBuf, "-Xjitmaxsize:");
720 parseRuntimeOption("dalvik.vm.jitinitialsize", jitinitialsizeOptsBuf, "-Xjitinitialsize:");
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700721 parseRuntimeOption("dalvik.vm.jitthreshold", jitthresholdOptsBuf, "-Xjitthreshold:");
Calin Juravledb4a79a2015-12-23 18:55:08 +0200722 property_get("dalvik.vm.usejitprofiles", useJitProfilesOptsBuf, "");
723 if (strcmp(useJitProfilesOptsBuf, "true") == 0) {
724 addOption("-Xjitsaveprofilinginfo");
725 }
Calin Juravle8d74de52016-04-27 14:12:00 +0100726
Calin Juravle0de80b92016-04-12 14:12:04 +0100727 parseRuntimeOption("dalvik.vm.jitprithreadweight",
728 jitprithreadweightOptBuf,
729 "-Xjitprithreadweight:");
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800730
Calin Juravle8d74de52016-04-27 14:12:00 +0100731 parseRuntimeOption("dalvik.vm.jittransitionweight",
732 jittransitionweightOptBuf,
733 "-Xjittransitionweight:");
734
Mathieu Chartier42cd2652017-06-07 17:34:22 -0700735 /*
736 * Profile related options.
737 */
738 parseRuntimeOption("dalvik.vm.hot-startup-method-samples", hotstartupsamplesOptsBuf,
739 "-Xps-hot-startup-method-samples:");
740
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700741 property_get("ro.config.low_ram", propBuf, "");
742 if (strcmp(propBuf, "true") == 0) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700743 addOption("-XX:LowMemoryMode");
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700744 }
745
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700746 parseRuntimeOption("dalvik.vm.gctype", gctypeOptsBuf, "-Xgc:");
747 parseRuntimeOption("dalvik.vm.backgroundgctype", backgroundgcOptsBuf, "-XX:BackgroundGC=");
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700748
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200749 /*
750 * Enable debugging only for apps forked from zygote.
751 * Set suspend=y to pause during VM init and use android ADB transport.
752 */
753 if (zygote) {
754 addOption("-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y");
755 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800756
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700757 parseRuntimeOption("dalvik.vm.lockprof.threshold",
758 lockProfThresholdBuf,
759 "-Xlockprofthreshold:");
Carl Shapirod8f3ec62010-04-12 16:31:59 -0700760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 if (executionMode == kEMIntPortable) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700762 addOption("-Xint:portable");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800763 } else if (executionMode == kEMIntFast) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700764 addOption("-Xint:fast");
Ben Cheng52b0e732009-06-19 13:31:12 -0700765 } else if (executionMode == kEMJitCompiler) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700766 addOption("-Xint:jit");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 }
Andy McFaddene2b23e12009-04-03 11:09:46 -0700768
Andreas Gampe08b2d582014-12-18 14:39:22 -0800769 // If we are booting without the real /data, don't spend time compiling.
770 property_get("vold.decrypt", voldDecryptBuf, "");
771 bool skip_compilation = ((strcmp(voldDecryptBuf, "trigger_restart_min_framework") == 0) ||
772 (strcmp(voldDecryptBuf, "1") == 0));
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800773
Andreas Gampe08b2d582014-12-18 14:39:22 -0800774 // Extra options for boot.art/boot.oat image generation.
775 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xms", dex2oatXmsImageFlagsBuf,
776 "-Xms", "-Ximage-compiler-option");
777 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xmx", dex2oatXmxImageFlagsBuf,
778 "-Xmx", "-Ximage-compiler-option");
779 if (skip_compilation) {
Brian Carlstromce5bbbe2014-07-30 15:13:17 -0700780 addOption("-Ximage-compiler-option");
Nicolas Geoffraybe7b0d12017-04-25 12:29:07 +0100781 addOption("--compiler-filter=assume-verified");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800782 } else {
783 parseCompilerOption("dalvik.vm.image-dex2oat-filter", dex2oatImageCompilerFilterBuf,
784 "--compiler-filter=", "-Ximage-compiler-option");
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800785 }
786
Mathieu Chartier5f50c872017-06-30 11:47:38 -0700787 // If there is a boot profile, it takes precedence over the image and preloaded classes.
788 if (hasFile("/system/etc/boot-image.prof")) {
Andreas Gampe08b2d582014-12-18 14:39:22 -0800789 addOption("-Ximage-compiler-option");
Mathieu Chartier5f50c872017-06-30 11:47:38 -0700790 addOption("--profile-file=/system/etc/boot-image.prof");
791 addOption("-Ximage-compiler-option");
792 addOption("--compiler-filter=speed-profile");
793 } else {
794 // Make sure there is a preloaded-classes file.
795 if (!hasFile("/system/etc/preloaded-classes")) {
796 ALOGE("Missing preloaded-classes file, /system/etc/preloaded-classes not found: %s\n",
797 strerror(errno));
798 return -1;
799 }
800 addOption("-Ximage-compiler-option");
801 addOption("--image-classes=/system/etc/preloaded-classes");
802
803 // If there is a compiled-classes file, push it.
804 if (hasFile("/system/etc/compiled-classes")) {
805 addOption("-Ximage-compiler-option");
806 addOption("--compiled-classes=/system/etc/compiled-classes");
807 }
Jeff Hao6aa5d712017-07-31 13:35:01 -0700808
809 // If there is a dirty-image-objects file, push it.
810 if (hasFile("/system/etc/dirty-image-objects")) {
811 addOption("-Ximage-compiler-option");
812 addOption("--dirty-image-objects=/system/etc/dirty-image-objects");
813 }
Andreas Gampe08b2d582014-12-18 14:39:22 -0800814 }
815
816 property_get("dalvik.vm.image-dex2oat-flags", dex2oatImageFlagsBuf, "");
817 parseExtraOpts(dex2oatImageFlagsBuf, "-Ximage-compiler-option");
818
819 // Extra options for DexClassLoader.
820 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xms", dex2oatXmsFlagsBuf,
821 "-Xms", "-Xcompiler-option");
822 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xmx", dex2oatXmxFlagsBuf,
823 "-Xmx", "-Xcompiler-option");
824 if (skip_compilation) {
825 addOption("-Xcompiler-option");
Nicolas Geoffraybe7b0d12017-04-25 12:29:07 +0100826 addOption("--compiler-filter=assume-verified");
neo.chae155118f2015-01-07 15:32:15 +0900827
828 // We skip compilation when a minimal runtime is brought up for decryption. In that case
829 // /data is temporarily backed by a tmpfs, which is usually small.
830 // If the system image contains prebuilts, they will be relocated into the tmpfs. In this
831 // specific situation it is acceptable to *not* relocate and run out of the prebuilts
832 // directly instead.
833 addOption("--runtime-arg");
834 addOption("-Xnorelocate");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800835 } else {
836 parseCompilerOption("dalvik.vm.dex2oat-filter", dex2oatCompilerFilterBuf,
837 "--compiler-filter=", "-Xcompiler-option");
838 }
Andreas Gampee0352382015-03-30 18:43:39 -0700839 parseCompilerOption("dalvik.vm.dex2oat-threads", dex2oatThreadsBuf, "-j", "-Xcompiler-option");
840 parseCompilerOption("dalvik.vm.image-dex2oat-threads", dex2oatThreadsImageBuf, "-j",
841 "-Ximage-compiler-option");
Andreas Gampe605cca12015-04-02 23:12:56 -0700842
843 // The runtime will compile a boot image, when necessary, not using installd. Thus, we need to
844 // pass the instruction-set-features/variant as an image-compiler-option.
845 // TODO: Find a better way for the instruction-set.
846#if defined(__arm__)
847 constexpr const char* instruction_set = "arm";
848#elif defined(__aarch64__)
849 constexpr const char* instruction_set = "arm64";
850#elif defined(__mips__) && !defined(__LP64__)
851 constexpr const char* instruction_set = "mips";
852#elif defined(__mips__) && defined(__LP64__)
853 constexpr const char* instruction_set = "mips64";
854#elif defined(__i386__)
855 constexpr const char* instruction_set = "x86";
856#elif defined(__x86_64__)
857 constexpr const char* instruction_set = "x86_64";
858#else
859 constexpr const char* instruction_set = "unknown";
860#endif
861 // Note: it is OK to reuse the buffer, as the values are exactly the same between
862 // * compiler-option, used for runtime compilation (DexClassLoader)
863 // * image-compiler-option, used for boot-image compilation on device
864
865 // Copy the variant.
866 sprintf(dex2oat_isa_variant_key, "dalvik.vm.isa.%s.variant", instruction_set);
867 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
868 "--instruction-set-variant=", "-Ximage-compiler-option");
869 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
870 "--instruction-set-variant=", "-Xcompiler-option");
871 // Copy the features.
872 sprintf(dex2oat_isa_features_key, "dalvik.vm.isa.%s.features", instruction_set);
873 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
874 "--instruction-set-features=", "-Ximage-compiler-option");
875 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
876 "--instruction-set-features=", "-Xcompiler-option");
877
878
Andreas Gampe08b2d582014-12-18 14:39:22 -0800879 property_get("dalvik.vm.dex2oat-flags", dex2oatFlagsBuf, "");
880 parseExtraOpts(dex2oatFlagsBuf, "-Xcompiler-option");
881
Andy McFaddene4d81f22010-07-14 16:02:20 -0700882 /* extra options; parse this late so it overrides others */
883 property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800884 parseExtraOpts(extraOptsBuf, NULL);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800886 /* Set the properties for locale */
887 {
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000888 strcpy(localeOption, "-Duser.locale=");
Narayan Kamathbf882052015-08-11 15:40:34 +0100889 const std::string locale = readLocale();
890 strncat(localeOption, locale.c_str(), PROPERTY_VALUE_MAX);
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000891 addOption(localeOption);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892 }
893
Calin Juravle92290b82015-11-10 19:30:45 +0000894 // Trace files are stored in /data/misc/trace which is writable only in debug mode.
895 property_get("ro.debuggable", propBuf, "0");
896 if (strcmp(propBuf, "1") == 0) {
897 property_get("dalvik.vm.method-trace", propBuf, "false");
Andreas Gampe98f406f2015-06-22 21:09:36 -0700898 if (strcmp(propBuf, "true") == 0) {
Calin Juravle92290b82015-11-10 19:30:45 +0000899 addOption("-Xmethod-trace");
900 parseRuntimeOption("dalvik.vm.method-trace-file",
901 methodTraceFileBuf,
902 "-Xmethod-trace-file:");
903 parseRuntimeOption("dalvik.vm.method-trace-file-siz",
904 methodTraceFileSizeBuf,
905 "-Xmethod-trace-file-size:");
906 property_get("dalvik.vm.method-trace-stream", propBuf, "false");
907 if (strcmp(propBuf, "true") == 0) {
908 addOption("-Xmethod-trace-stream");
909 }
Andreas Gampe98f406f2015-06-22 21:09:36 -0700910 }
911 }
912
Andreas Gampe08b2d582014-12-18 14:39:22 -0800913 // Native bridge library. "0" means that native bridge is disabled.
914 property_get("ro.dalvik.vm.native.bridge", propBuf, "");
915 if (propBuf[0] == '\0') {
916 ALOGW("ro.dalvik.vm.native.bridge is not expected to be empty");
917 } else if (strcmp(propBuf, "0") != 0) {
918 snprintf(nativeBridgeLibrary, sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX,
919 "-XX:NativeBridge=%s", propBuf);
920 addOption(nativeBridgeLibrary);
Calin Juravlebe20ed42014-08-26 23:00:11 +0100921 }
Calin Juravle01db9162014-08-07 14:45:53 +0100922
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700923#if defined(__LP64__)
924 const char* cpu_abilist_property_name = "ro.product.cpu.abilist64";
925#else
926 const char* cpu_abilist_property_name = "ro.product.cpu.abilist32";
927#endif // defined(__LP64__)
928 property_get(cpu_abilist_property_name, propBuf, "");
929 if (propBuf[0] == '\0') {
930 ALOGE("%s is not expected to be empty", cpu_abilist_property_name);
931 return -1;
932 }
933 snprintf(cpuAbiListBuf, sizeof(cpuAbiListBuf), "--cpu-abilist=%s", propBuf);
934 addOption(cpuAbiListBuf);
935
Andreas Gampee324ba02015-03-31 16:15:17 -0700936 // Dalvik-cache pruning counter.
937 parseRuntimeOption("dalvik.vm.zygote.max-boot-retry", cachePruneBuf,
938 "-Xzygote-max-boot-retry=");
939
Andreas Gampe27c39f12015-04-27 18:28:18 +0000940 /*
David Srbecky065075e2015-05-28 17:16:09 +0100941 * When running with debug.generate-debug-info, add --generate-debug-info to
942 * the compiler options so that the boot image, if it is compiled on device,
943 * will include native debugging information.
Andreas Gampe27c39f12015-04-27 18:28:18 +0000944 */
David Srbecky065075e2015-05-28 17:16:09 +0100945 property_get("debug.generate-debug-info", propBuf, "");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000946 if (strcmp(propBuf, "true") == 0) {
947 addOption("-Xcompiler-option");
David Srbecky065075e2015-05-28 17:16:09 +0100948 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000949 addOption("-Ximage-compiler-option");
David Srbecky065075e2015-05-28 17:16:09 +0100950 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000951 }
952
Andreas Gampee6082502015-07-24 14:19:44 -0700953 /*
954 * Retrieve the build fingerprint and provide it to the runtime. That way, ANR dumps will
955 * contain the fingerprint and can be parsed.
Tom Cherry93099e42017-10-11 13:44:21 -0700956 * Fingerprints are potentially longer than PROPERTY_VALUE_MAX, so parseRuntimeOption() cannot
957 * be used here.
958 * Do not ever re-assign fingerprintBuf as its c_str() value is stored in mOptions.
Andreas Gampee6082502015-07-24 14:19:44 -0700959 */
Tom Cherry93099e42017-10-11 13:44:21 -0700960 std::string fingerprint = GetProperty("ro.build.fingerprint", "");
961 if (!fingerprint.empty()) {
962 fingerprintBuf = "-Xfingerprint:" + fingerprint;
963 addOption(fingerprintBuf.c_str());
964 }
Andreas Gampee6082502015-07-24 14:19:44 -0700965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 initArgs.version = JNI_VERSION_1_4;
967 initArgs.options = mOptions.editArray();
968 initArgs.nOptions = mOptions.size();
969 initArgs.ignoreUnrecognized = JNI_FALSE;
970
971 /*
972 * Initialize the VM.
973 *
974 * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread.
975 * If this call succeeds, the VM is ready, and we can start issuing
976 * JNI calls.
977 */
Andy McFaddenf70188a2009-03-31 15:52:13 -0700978 if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) {
Steve Block3762c312012-01-06 19:20:56 +0000979 ALOGE("JNI_CreateJavaVM failed\n");
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700980 return -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 }
982
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700983 return 0;
Andy McFaddenf70188a2009-03-31 15:52:13 -0700984}
985
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700986char* AndroidRuntime::toSlashClassName(const char* className)
987{
988 char* result = strdup(className);
989 for (char* cp = result; *cp != '\0'; cp++) {
990 if (*cp == '.') {
991 *cp = '/';
992 }
993 }
994 return result;
995}
996
Mike Lockwood9ee5e7e2014-09-08 16:15:21 -0700997/** Create a Java string from an ASCII or Latin-1 string */
998jstring AndroidRuntime::NewStringLatin1(JNIEnv* env, const char* bytes) {
999 if (!bytes) return NULL;
1000 int length = strlen(bytes);
1001 jchar* buffer = (jchar *)alloca(length * sizeof(jchar));
1002 if (!buffer) return NULL;
1003 jchar* chp = buffer;
1004 for (int i = 0; i < length; i++) {
1005 *chp++ = *bytes++;
1006 }
1007 return env->NewString(buffer, length);
1008}
1009
1010
Andy McFaddenf70188a2009-03-31 15:52:13 -07001011/*
1012 * Start the Android runtime. This involves starting the virtual machine
1013 * and calling the "static void main(String[] args)" method in the class
1014 * named by "className".
Jeff Brownebed7d62011-05-16 17:08:42 -07001015 *
1016 * Passes the main function two arguments, the class name and the specified
1017 * options string.
Andy McFaddenf70188a2009-03-31 15:52:13 -07001018 */
Sebastien Hertz7a09b832015-08-10 18:55:34 +02001019void AndroidRuntime::start(const char* className, const Vector<String8>& options, bool zygote)
Andy McFaddenf70188a2009-03-31 15:52:13 -07001020{
Dianne Hackborn8e5aafe2014-10-27 18:04:10 -07001021 ALOGD(">>>>>> START %s uid %d <<<<<<\n",
1022 className != NULL ? className : "(unknown)", getuid());
Andy McFaddenf70188a2009-03-31 15:52:13 -07001023
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001024 static const String8 startSystemServer("start-system-server");
1025
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001026 /*
1027 * 'startSystemServer == true' means runtime is obsolete and not run from
Andy McFaddenf70188a2009-03-31 15:52:13 -07001028 * init.rc anymore, so we print out the boot start event here.
1029 */
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001030 for (size_t i = 0; i < options.size(); ++i) {
1031 if (options[i] == startSystemServer) {
1032 /* track our progress through the boot sequence */
1033 const int LOG_BOOT_PROGRESS_START = 3000;
1034 LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));
1035 }
Andy McFaddenf70188a2009-03-31 15:52:13 -07001036 }
1037
1038 const char* rootDir = getenv("ANDROID_ROOT");
1039 if (rootDir == NULL) {
1040 rootDir = "/system";
1041 if (!hasDir("/system")) {
1042 LOG_FATAL("No root directory specified, and /android does not exist.");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001043 return;
Andy McFaddenf70188a2009-03-31 15:52:13 -07001044 }
1045 setenv("ANDROID_ROOT", rootDir, 1);
1046 }
1047
1048 //const char* kernelHack = getenv("LD_ASSUME_KERNEL");
Steve Block5baa3a62011-12-20 16:23:08 +00001049 //ALOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001050
1051 /* start the virtual machine */
Brian Carlstrom9f8203a2013-06-19 13:49:36 -07001052 JniInvocation jni_invocation;
1053 jni_invocation.Init(NULL);
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001054 JNIEnv* env;
Sebastien Hertz7a09b832015-08-10 18:55:34 +02001055 if (startVm(&mJavaVM, &env, zygote) != 0) {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001056 return;
1057 }
1058 onVmCreated(env);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001060 /*
1061 * Register android functions.
1062 */
1063 if (startReg(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001064 ALOGE("Unable to register all android natives\n");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001065 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 }
1067
1068 /*
1069 * We want to call main() with a String array with arguments in it.
Jeff Brownebed7d62011-05-16 17:08:42 -07001070 * At present we have two arguments, the class name and an option string.
1071 * Create an array to hold them.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 */
1073 jclass stringClass;
1074 jobjectArray strArray;
1075 jstring classNameStr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076
1077 stringClass = env->FindClass("java/lang/String");
1078 assert(stringClass != NULL);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001079 strArray = env->NewObjectArray(options.size() + 1, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 assert(strArray != NULL);
1081 classNameStr = env->NewStringUTF(className);
1082 assert(classNameStr != NULL);
1083 env->SetObjectArrayElement(strArray, 0, classNameStr);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001084
1085 for (size_t i = 0; i < options.size(); ++i) {
1086 jstring optionsStr = env->NewStringUTF(options.itemAt(i).string());
1087 assert(optionsStr != NULL);
1088 env->SetObjectArrayElement(strArray, i + 1, optionsStr);
1089 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090
1091 /*
1092 * Start VM. This thread becomes the main thread of the VM, and will
1093 * not return until the VM exits.
1094 */
George Burgess IVd657a382017-06-20 23:53:29 -07001095 char* slashClassName = toSlashClassName(className != NULL ? className : "");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001096 jclass startClass = env->FindClass(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097 if (startClass == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001098 ALOGE("JavaVM unable to locate class '%s'\n", slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 /* keep going */
1100 } else {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001101 jmethodID startMeth = env->GetStaticMethodID(startClass, "main",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102 "([Ljava/lang/String;)V");
1103 if (startMeth == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001104 ALOGE("JavaVM unable to find main() in '%s'\n", className);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 /* keep going */
1106 } else {
1107 env->CallStaticVoidMethod(startClass, startMeth, strArray);
1108
1109#if 0
1110 if (env->ExceptionCheck())
1111 threadExitUncaughtException(env);
1112#endif
1113 }
1114 }
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001115 free(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116
Steve Block5baa3a62011-12-20 16:23:08 +00001117 ALOGD("Shutting down VM\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 if (mJavaVM->DetachCurrentThread() != JNI_OK)
Steve Block8564c8d2012-01-05 23:22:43 +00001119 ALOGW("Warning: unable to detach main thread\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 if (mJavaVM->DestroyJavaVM() != 0)
Steve Block8564c8d2012-01-05 23:22:43 +00001121 ALOGW("Warning: VM did not shut down cleanly\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001122}
1123
Jeff Brown4280c4a2012-03-15 17:48:02 -07001124void AndroidRuntime::exit(int code)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125{
Jeff Brown4280c4a2012-03-15 17:48:02 -07001126 if (mExitWithoutCleanup) {
1127 ALOGI("VM exiting with result code %d, cleanup skipped.", code);
1128 ::_exit(code);
1129 } else {
1130 ALOGI("VM exiting with result code %d.", code);
1131 onExit(code);
1132 ::exit(code);
1133 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134}
1135
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001136void AndroidRuntime::onVmCreated(JNIEnv* env)
1137{
1138 // If AndroidRuntime had anything to do here, we'd have done it in 'start'.
1139}
1140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141/*
Andreas Huber9ae000c2014-02-13 17:22:33 +00001142 * Get the JNIEnv pointer for this thread.
1143 *
1144 * Returns NULL if the slot wasn't allocated or populated.
1145 */
1146/*static*/ JNIEnv* AndroidRuntime::getJNIEnv()
1147{
1148 JNIEnv* env;
1149 JavaVM* vm = AndroidRuntime::getJavaVM();
1150 assert(vm != NULL);
1151
1152 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
1153 return NULL;
1154 return env;
1155}
1156
1157/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001158 * Makes the current thread visible to the VM.
1159 *
1160 * The JNIEnv pointer returned is only valid for the current thread, and
1161 * thus must be tucked into thread-local storage.
1162 */
1163static int javaAttachThread(const char* threadName, JNIEnv** pEnv)
1164{
1165 JavaVMAttachArgs args;
1166 JavaVM* vm;
1167 jint result;
1168
1169 vm = AndroidRuntime::getJavaVM();
1170 assert(vm != NULL);
1171
1172 args.version = JNI_VERSION_1_4;
1173 args.name = (char*) threadName;
1174 args.group = NULL;
1175
1176 result = vm->AttachCurrentThread(pEnv, (void*) &args);
1177 if (result != JNI_OK)
Steve Block6215d3f2012-01-04 20:05:49 +00001178 ALOGI("NOTE: attach of thread '%s' failed\n", threadName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179
1180 return result;
1181}
1182
1183/*
1184 * Detach the current thread from the set visible to the VM.
1185 */
1186static int javaDetachThread(void)
1187{
1188 JavaVM* vm;
1189 jint result;
1190
1191 vm = AndroidRuntime::getJavaVM();
1192 assert(vm != NULL);
1193
1194 result = vm->DetachCurrentThread();
1195 if (result != JNI_OK)
Steve Block3762c312012-01-06 19:20:56 +00001196 ALOGE("ERROR: thread detach failed\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 return result;
1198}
1199
1200/*
1201 * When starting a native thread that will be visible from the VM, we
1202 * bounce through this to get the right attach/detach action.
1203 * Note that this function calls free(args)
1204 */
1205/*static*/ int AndroidRuntime::javaThreadShell(void* args) {
1206 void* start = ((void**)args)[0];
1207 void* userData = ((void **)args)[1];
1208 char* name = (char*) ((void **)args)[2]; // we own this storage
1209 free(args);
1210 JNIEnv* env;
1211 int result;
1212
1213 /* hook us into the VM */
1214 if (javaAttachThread(name, &env) != JNI_OK)
1215 return -1;
1216
1217 /* start the thread running */
1218 result = (*(android_thread_func_t)start)(userData);
1219
1220 /* unhook us */
1221 javaDetachThread();
1222 free(name);
1223
1224 return result;
1225}
1226
1227/*
1228 * This is invoked from androidCreateThreadEtc() via the callback
1229 * set with androidSetCreateThreadFunc().
1230 *
1231 * We need to create the new thread in such a way that it gets hooked
1232 * into the VM before it really starts executing.
1233 */
1234/*static*/ int AndroidRuntime::javaCreateThreadEtc(
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001235 android_thread_func_t entryFunction,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001236 void* userData,
1237 const char* threadName,
1238 int32_t threadPriority,
1239 size_t threadStackSize,
1240 android_thread_id_t* threadId)
1241{
1242 void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free
1243 int result;
1244
Brian Carlstrom66f48312016-03-12 16:07:48 -08001245 LOG_ALWAYS_FATAL_IF(threadName == nullptr, "threadName not provided to javaCreateThreadEtc");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001246
1247 args[0] = (void*) entryFunction;
1248 args[1] = userData;
1249 args[2] = (void*) strdup(threadName); // javaThreadShell must free
1250
1251 result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args,
1252 threadName, threadPriority, threadStackSize, threadId);
1253 return result;
1254}
1255
1256/*
1257 * Create a thread that is visible from the VM.
1258 *
1259 * This is called from elsewhere in the library.
1260 */
Mike Lockwoodf602d362010-06-20 14:28:16 -07001261/*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001262 void (*start)(void *), void* arg)
1263{
Mike Lockwoodf602d362010-06-20 14:28:16 -07001264 android_thread_id_t threadId = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 javaCreateThreadEtc((android_thread_func_t) start, arg, name,
Mike Lockwoodf602d362010-06-20 14:28:16 -07001266 ANDROID_PRIORITY_DEFAULT, 0, &threadId);
1267 return threadId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268}
1269
1270#if 0
1271static void quickTest(void* arg)
1272{
1273 const char* str = (const char*) arg;
1274
1275 printf("In quickTest: %s\n", str);
1276}
1277#endif
1278
1279#ifdef NDEBUG
1280 #define REG_JNI(name) { name }
1281 struct RegJNIRec {
1282 int (*mProc)(JNIEnv*);
1283 };
1284#else
1285 #define REG_JNI(name) { name, #name }
1286 struct RegJNIRec {
1287 int (*mProc)(JNIEnv*);
1288 const char* mName;
1289 };
1290#endif
1291
1292typedef void (*RegJAMProc)();
1293
1294static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env)
1295{
1296 for (size_t i = 0; i < count; i++) {
1297 if (array[i].mProc(env) < 0) {
1298#ifndef NDEBUG
Steve Block5baa3a62011-12-20 16:23:08 +00001299 ALOGD("----------!!! %s failed to load\n", array[i].mName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001300#endif
1301 return -1;
1302 }
1303 }
1304 return 0;
1305}
1306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307static const RegJNIRec gRegJNI[] = {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001308 REG_JNI(register_com_android_internal_os_RuntimeInit),
Jesse Hall42cf26e2017-07-06 15:30:39 -07001309 REG_JNI(register_com_android_internal_os_ZygoteInit_nativeZygoteInit),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001310 REG_JNI(register_android_os_SystemClock),
1311 REG_JNI(register_android_util_EventLog),
1312 REG_JNI(register_android_util_Log),
Svet Ganov53a441c2016-04-19 19:38:00 -07001313 REG_JNI(register_android_util_MemoryIntArray),
Doris Liucdd23f92015-11-11 14:31:13 -08001314 REG_JNI(register_android_util_PathParser),
Michal Karpinski6235a942016-03-15 12:07:23 +00001315 REG_JNI(register_android_app_admin_SecurityLog),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001316 REG_JNI(register_android_content_AssetManager),
1317 REG_JNI(register_android_content_StringBlock),
1318 REG_JNI(register_android_content_XmlBlock),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001319 REG_JNI(register_android_text_AndroidCharacter),
Anish Athalye88b5b0b2014-06-24 14:39:43 -07001320 REG_JNI(register_android_text_StaticLayout),
Doug Feltdae8e942010-02-24 14:33:15 -08001321 REG_JNI(register_android_text_AndroidBidi),
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001322 REG_JNI(register_android_view_InputDevice),
1323 REG_JNI(register_android_view_KeyCharacterMap),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001324 REG_JNI(register_android_os_Process),
Andreas Hubera8079bf2010-11-16 14:40:31 -08001325 REG_JNI(register_android_os_SystemProperties),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001326 REG_JNI(register_android_os_Binder),
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -08001327 REG_JNI(register_android_os_Parcel),
Andreas Huberc0b6c532016-08-15 09:25:02 -07001328 REG_JNI(register_android_os_HwBinder),
Andreas Huberdc263212016-08-25 11:21:21 -07001329 REG_JNI(register_android_os_HwBlob),
Andreas Huberc0b6c532016-08-15 09:25:02 -07001330 REG_JNI(register_android_os_HwParcel),
1331 REG_JNI(register_android_os_HwRemoteBinder),
Yifan Hongbecc56d2017-04-05 14:42:05 -07001332 REG_JNI(register_android_os_VintfObject),
Yifan Hong1bda6732017-04-26 11:38:01 -07001333 REG_JNI(register_android_os_VintfRuntimeInfo),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001334 REG_JNI(register_android_nio_utils),
Richard Uhler775873a2015-12-29 12:37:39 -08001335 REG_JNI(register_android_graphics_Canvas),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001336 REG_JNI(register_android_graphics_Graphics),
Chris Craik54389792013-12-20 13:28:11 -08001337 REG_JNI(register_android_view_DisplayEventReceiver),
John Reckf666ad72014-03-14 16:24:57 -07001338 REG_JNI(register_android_view_RenderNode),
John Recke45b1fd2014-04-15 09:50:16 -07001339 REG_JNI(register_android_view_RenderNodeAnimator),
Chris Craikc9070eb2015-03-09 18:50:14 -07001340 REG_JNI(register_android_view_DisplayListCanvas),
John Reck04fc5832014-02-05 16:38:25 -08001341 REG_JNI(register_android_view_HardwareLayer),
John Reckcec24ae2013-11-05 13:27:50 -08001342 REG_JNI(register_android_view_ThreadedRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001343 REG_JNI(register_android_view_Surface),
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001344 REG_JNI(register_android_view_SurfaceControl),
Jeff Brown64a55af2012-08-26 02:47:39 -07001345 REG_JNI(register_android_view_SurfaceSession),
Romain Guy8f0095c2011-05-02 17:24:22 -07001346 REG_JNI(register_android_view_TextureView),
John Reck315c3292014-05-09 19:21:04 -07001347 REG_JNI(register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001348 REG_JNI(register_com_google_android_gles_jni_EGLImpl),
1349 REG_JNI(register_com_google_android_gles_jni_GLImpl),
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001350 REG_JNI(register_android_opengl_jni_EGL14),
Jesse Hall237c2b82013-05-06 11:36:57 -07001351 REG_JNI(register_android_opengl_jni_EGLExt),
Jack Palevich1c4907e2009-04-13 16:22:25 -07001352 REG_JNI(register_android_opengl_jni_GLES10),
1353 REG_JNI(register_android_opengl_jni_GLES10Ext),
1354 REG_JNI(register_android_opengl_jni_GLES11),
1355 REG_JNI(register_android_opengl_jni_GLES11Ext),
Jack Palevich560814f2009-11-19 16:34:55 +08001356 REG_JNI(register_android_opengl_jni_GLES20),
Jesse Halld877efe2013-04-29 15:59:35 -07001357 REG_JNI(register_android_opengl_jni_GLES30),
Jesse Hall7ab63ac2014-05-19 15:13:41 -07001358 REG_JNI(register_android_opengl_jni_GLES31),
1359 REG_JNI(register_android_opengl_jni_GLES31Ext),
Pablo Ceballos38c1a7e2015-10-30 10:34:30 -07001360 REG_JNI(register_android_opengl_jni_GLES32),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001361
1362 REG_JNI(register_android_graphics_Bitmap),
1363 REG_JNI(register_android_graphics_BitmapFactory),
Wei-Ta Chen6b849e22010-09-07 17:32:18 +08001364 REG_JNI(register_android_graphics_BitmapRegionDecoder),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001365 REG_JNI(register_android_graphics_Camera),
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -04001366 REG_JNI(register_android_graphics_CreateJavaOutputStreamAdaptor),
John Reck52244ff2014-05-01 21:27:37 -07001367 REG_JNI(register_android_graphics_CanvasProperty),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001368 REG_JNI(register_android_graphics_ColorFilter),
1369 REG_JNI(register_android_graphics_DrawFilter),
Raph Levien1a73f7322014-01-30 16:06:28 -08001370 REG_JNI(register_android_graphics_FontFamily),
sergeyv0a0f2312017-01-04 13:58:52 -08001371 REG_JNI(register_android_graphics_GraphicBuffer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001372 REG_JNI(register_android_graphics_Interpolator),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001373 REG_JNI(register_android_graphics_MaskFilter),
1374 REG_JNI(register_android_graphics_Matrix),
1375 REG_JNI(register_android_graphics_Movie),
1376 REG_JNI(register_android_graphics_NinePatch),
1377 REG_JNI(register_android_graphics_Paint),
1378 REG_JNI(register_android_graphics_Path),
1379 REG_JNI(register_android_graphics_PathMeasure),
1380 REG_JNI(register_android_graphics_PathEffect),
1381 REG_JNI(register_android_graphics_Picture),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382 REG_JNI(register_android_graphics_Region),
1383 REG_JNI(register_android_graphics_Shader),
Jamie Gennisaa0ce332011-01-06 17:04:26 -08001384 REG_JNI(register_android_graphics_SurfaceTexture),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001385 REG_JNI(register_android_graphics_Typeface),
Wei-Ta Chenbca2d612009-11-30 17:52:05 +08001386 REG_JNI(register_android_graphics_YuvImage),
Doris Liu766431a2016-02-04 22:17:11 +00001387 REG_JNI(register_android_graphics_drawable_AnimatedVectorDrawable),
Doris Liu4bbc2932015-12-01 17:59:40 -08001388 REG_JNI(register_android_graphics_drawable_VectorDrawable),
Svetoslav6811f4e2013-09-18 15:58:28 -07001389 REG_JNI(register_android_graphics_pdf_PdfDocument),
Svetoslav62ce3322014-09-04 21:17:17 -07001390 REG_JNI(register_android_graphics_pdf_PdfEditor),
Svetoslav29617692014-04-24 18:40:42 -07001391 REG_JNI(register_android_graphics_pdf_PdfRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001392
1393 REG_JNI(register_android_database_CursorWindow),
Jeff Browne5360fb2011-10-31 17:48:13 -07001394 REG_JNI(register_android_database_SQLiteConnection),
1395 REG_JNI(register_android_database_SQLiteGlobal),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001396 REG_JNI(register_android_database_SQLiteDebug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001397 REG_JNI(register_android_os_Debug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001398 REG_JNI(register_android_os_FileObserver),
Jesse Hallb12249b2016-12-12 12:53:02 -08001399 REG_JNI(register_android_os_GraphicsEnvironment),
Christopher Tatefa9e7c02010-05-06 12:07:10 -07001400 REG_JNI(register_android_os_MessageQueue),
Stephen Smalleyc07fca32012-01-13 08:31:39 -05001401 REG_JNI(register_android_os_SELinux),
Paul Lawrenceef854772017-01-31 09:54:31 -08001402 REG_JNI(register_android_os_seccomp),
Jeff Brown481c1572012-03-09 14:41:15 -08001403 REG_JNI(register_android_os_Trace),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001404 REG_JNI(register_android_os_UEventObserver),
1405 REG_JNI(register_android_net_LocalSocketImpl),
1406 REG_JNI(register_android_net_NetworkUtils),
Dan Egnor2b4abcd2010-04-07 17:30:50 -07001407 REG_JNI(register_android_net_TrafficStats),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001408 REG_JNI(register_android_os_MemoryFile),
Dimitry Ivanov5d7d7772016-04-20 14:09:32 -07001409 REG_JNI(register_com_android_internal_os_PathClassLoaderFactory),
Narayan Kamath973b4662014-03-31 13:41:26 +01001410 REG_JNI(register_com_android_internal_os_Zygote),
Jesse Hall42cf26e2017-07-06 15:30:39 -07001411 REG_JNI(register_com_android_internal_os_ZygoteInit),
John Reck9fa40712014-05-09 15:26:59 -07001412 REG_JNI(register_com_android_internal_util_VirtualRefBasePtr),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001413 REG_JNI(register_android_hardware_Camera),
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07001414 REG_JNI(register_android_hardware_camera2_CameraMetadata),
Ruben Brunkfeb50af2014-05-09 19:58:49 -07001415 REG_JNI(register_android_hardware_camera2_legacy_LegacyCameraDevice),
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -07001416 REG_JNI(register_android_hardware_camera2_legacy_PerfMeasurement),
Ruben Brunkb6079002014-05-22 12:33:54 -07001417 REG_JNI(register_android_hardware_camera2_DngCreator),
Craig Donner1a4d07d2017-01-09 13:01:22 -08001418 REG_JNI(register_android_hardware_HardwareBuffer),
Eric Laurent633cb562015-03-05 15:17:20 -08001419 REG_JNI(register_android_hardware_Radio),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001420 REG_JNI(register_android_hardware_SensorManager),
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04001421 REG_JNI(register_android_hardware_SerialPort),
Eric Laurent60b62bc2014-04-18 17:50:49 -07001422 REG_JNI(register_android_hardware_SoundTrigger),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001423 REG_JNI(register_android_hardware_UsbDevice),
Mike Lockwoodacc29cc2011-03-11 08:18:08 -05001424 REG_JNI(register_android_hardware_UsbDeviceConnection),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001425 REG_JNI(register_android_hardware_UsbRequest),
destradaaa4fa3b52014-07-09 10:46:39 -07001426 REG_JNI(register_android_hardware_location_ActivityRecognitionHardware),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 REG_JNI(register_android_media_AudioRecord),
1428 REG_JNI(register_android_media_AudioSystem),
1429 REG_JNI(register_android_media_AudioTrack),
1430 REG_JNI(register_android_media_JetPlayer),
Jeff Browncbad9762012-09-04 21:57:59 -07001431 REG_JNI(register_android_media_RemoteDisplay),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 REG_JNI(register_android_media_ToneGenerator),
1433
1434 REG_JNI(register_android_opengl_classes),
JP Abgrall98a4f7e2011-09-02 15:36:33 -07001435 REG_JNI(register_android_server_NetworkManagementSocketTagger),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001436 REG_JNI(register_android_ddm_DdmHandleNativeHeap),
Joe Onorato1cf58742009-06-12 11:06:24 -07001437 REG_JNI(register_android_backup_BackupDataInput),
Joe Onoratod2110db2009-05-19 13:41:21 -07001438 REG_JNI(register_android_backup_BackupDataOutput),
Joe Onorato06290a42009-06-18 20:10:37 -07001439 REG_JNI(register_android_backup_FileBackupHelperBase),
Joe Onorato4ababd92009-06-25 18:29:18 -04001440 REG_JNI(register_android_backup_BackupHelperDispatcher),
Christopher Tate4a627c72011-04-01 14:43:32 -07001441 REG_JNI(register_android_app_backup_FullBackup),
Dimitry Ivanov4449ef52016-02-25 17:41:13 -08001442 REG_JNI(register_android_app_Activity),
Chet Haase9c1e23b2011-03-24 10:51:31 -07001443 REG_JNI(register_android_app_ActivityThread),
Dimitry Ivanov09979082016-04-19 11:11:01 -07001444 REG_JNI(register_android_app_ApplicationLoaders),
Dianne Hackborn69969e42010-05-04 11:40:40 -07001445 REG_JNI(register_android_app_NativeActivity),
Przemyslaw Szczepaniak8a7c1602015-11-03 09:47:56 +00001446 REG_JNI(register_android_util_jar_StrictJarFile),
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001447 REG_JNI(register_android_view_InputChannel),
Jeff Brown32cbc38552011-12-01 14:01:49 -08001448 REG_JNI(register_android_view_InputEventReceiver),
Jeff Brownc28867a2013-03-26 15:42:39 -07001449 REG_JNI(register_android_view_InputEventSender),
Michael Wrighta44dd262013-04-10 21:12:00 -07001450 REG_JNI(register_android_view_InputQueue),
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001451 REG_JNI(register_android_view_KeyEvent),
1452 REG_JNI(register_android_view_MotionEvent),
Jeff Brown2352b972011-04-12 22:39:53 -07001453 REG_JNI(register_android_view_PointerIcon),
Jeff Brown2ed24622011-03-14 19:39:54 -07001454 REG_JNI(register_android_view_VelocityTracker),
Kenny Root02c87302010-07-01 08:10:18 -07001455
1456 REG_JNI(register_android_content_res_ObbScanner),
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -07001457 REG_JNI(register_android_content_res_Configuration),
Chet Haase6e0ecb42010-11-03 19:41:18 -07001458
1459 REG_JNI(register_android_animation_PropertyValuesHolder),
Kenny Root66269ea2011-07-12 14:14:01 -07001460 REG_JNI(register_com_android_internal_content_NativeLibraryHelper),
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -08001461 REG_JNI(register_com_android_internal_net_NetworkStatsFactory),
Daichi Hirono878e86f2016-10-31 09:33:30 +09001462 REG_JNI(register_com_android_internal_os_FuseAppLoop),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463};
1464
1465/*
1466 * Register android native functions with the VM.
1467 */
1468/*static*/ int AndroidRuntime::startReg(JNIEnv* env)
1469{
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001470 ATRACE_NAME("RegisterAndroidNatives");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001471 /*
1472 * This hook causes all future threads created in this process to be
1473 * attached to the JavaVM. (This needs to go away in favor of JNI
1474 * Attach calls.)
1475 */
1476 androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc);
1477
Steve Block71f2cf12011-10-20 11:56:00 +01001478 ALOGV("--- registering native functions ---\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479
1480 /*
1481 * Every "register" function calls one or more things that return
1482 * a local reference (e.g. FindClass). Because we haven't really
1483 * started the VM yet, they're all getting stored in the base frame
1484 * and never released. Use Push/Pop to manage the storage.
1485 */
1486 env->PushLocalFrame(200);
1487
1488 if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) {
1489 env->PopLocalFrame(NULL);
1490 return -1;
1491 }
1492 env->PopLocalFrame(NULL);
1493
1494 //createJavaThread("fubar", quickTest, (void*) "hello");
1495
1496 return 0;
1497}
1498
1499AndroidRuntime* AndroidRuntime::getRuntime()
1500{
1501 return gCurRuntime;
1502}
1503
1504/**
Narayan Kamathc21dab92015-06-25 14:22:00 +01001505 * Used by surface flinger's DdmConnection to register native methods from
1506 * the framework.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001507 */
Narayan Kamathc21dab92015-06-25 14:22:00 +01001508extern "C" jint registerFrameworkNatives(JNIEnv* env) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1510}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001511} // namespace android