blob: be53cf343dd702cd772a313d78460d1eaff9bd2e [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"
19//#define LOG_NDEBUG 0
20
21#include <android_runtime/AndroidRuntime.h>
Mathias Agopian07952722009-05-19 19:08:10 -070022#include <binder/IBinder.h>
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -080023#include <binder/IPCThreadState.h>
Mathias Agopian07952722009-05-19 19:08:10 -070024#include <binder/IServiceManager.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025#include <utils/Log.h>
26#include <utils/misc.h>
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +090027#include <utils/Trace.h>
Mathias Agopian07952722009-05-19 19:08:10 -070028#include <binder/Parcel.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029#include <utils/threads.h>
30#include <cutils/properties.h>
31
32#include <SkGraphics.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033
34#include "jni.h"
35#include "JNIHelp.h"
Brian Carlstrom9f8203a2013-06-19 13:49:36 -070036#include "JniInvocation.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037#include "android_util_Binder.h"
38
39#include <stdio.h>
40#include <signal.h>
41#include <sys/stat.h>
42#include <sys/types.h>
43#include <signal.h>
44#include <dirent.h>
45#include <assert.h>
46
Narayan Kamathbf882052015-08-11 15:40:34 +010047#include <string>
48#include <vector>
49
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050
51using namespace android;
52
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053extern int register_android_os_Binder(JNIEnv* env);
54extern int register_android_os_Process(JNIEnv* env);
55extern int register_android_graphics_Bitmap(JNIEnv*);
56extern int register_android_graphics_BitmapFactory(JNIEnv*);
Wei-Ta Chen6b849e22010-09-07 17:32:18 +080057extern int register_android_graphics_BitmapRegionDecoder(JNIEnv*);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058extern int register_android_graphics_Camera(JNIEnv* env);
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -040059extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060extern int register_android_graphics_Graphics(JNIEnv* env);
61extern int register_android_graphics_Interpolator(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062extern int register_android_graphics_MaskFilter(JNIEnv* env);
63extern int register_android_graphics_Movie(JNIEnv* env);
64extern int register_android_graphics_NinePatch(JNIEnv*);
65extern int register_android_graphics_PathEffect(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066extern int register_android_graphics_Shader(JNIEnv* env);
67extern int register_android_graphics_Typeface(JNIEnv* env);
Wei-Ta Chenbca2d612009-11-30 17:52:05 +080068extern int register_android_graphics_YuvImage(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069
70extern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env);
71extern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070072extern int register_android_opengl_jni_EGL14(JNIEnv* env);
Jesse Hall237c2b82013-05-06 11:36:57 -070073extern int register_android_opengl_jni_EGLExt(JNIEnv* env);
Jack Palevich1c4907e2009-04-13 16:22:25 -070074extern int register_android_opengl_jni_GLES10(JNIEnv* env);
75extern int register_android_opengl_jni_GLES10Ext(JNIEnv* env);
76extern int register_android_opengl_jni_GLES11(JNIEnv* env);
77extern int register_android_opengl_jni_GLES11Ext(JNIEnv* env);
Jack Palevich560814f2009-11-19 16:34:55 +080078extern int register_android_opengl_jni_GLES20(JNIEnv* env);
Jesse Halld877efe2013-04-29 15:59:35 -070079extern int register_android_opengl_jni_GLES30(JNIEnv* env);
Jesse Hall7ab63ac2014-05-19 15:13:41 -070080extern int register_android_opengl_jni_GLES31(JNIEnv* env);
81extern int register_android_opengl_jni_GLES31Ext(JNIEnv* env);
Pablo Ceballos38c1a7e2015-10-30 10:34:30 -070082extern int register_android_opengl_jni_GLES32(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083
84extern int register_android_hardware_Camera(JNIEnv *env);
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -070085extern int register_android_hardware_camera2_CameraMetadata(JNIEnv *env);
Ruben Brunkfeb50af2014-05-09 19:58:49 -070086extern int register_android_hardware_camera2_legacy_LegacyCameraDevice(JNIEnv *env);
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -070087extern int register_android_hardware_camera2_legacy_PerfMeasurement(JNIEnv *env);
Ruben Brunkb6079002014-05-22 12:33:54 -070088extern int register_android_hardware_camera2_DngCreator(JNIEnv *env);
Eric Laurent633cb562015-03-05 15:17:20 -080089extern int register_android_hardware_Radio(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090extern int register_android_hardware_SensorManager(JNIEnv *env);
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -040091extern int register_android_hardware_SerialPort(JNIEnv *env);
Eric Laurent60b62bc2014-04-18 17:50:49 -070092extern int register_android_hardware_SoundTrigger(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -050093extern int register_android_hardware_UsbDevice(JNIEnv *env);
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050094extern int register_android_hardware_UsbDeviceConnection(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -050095extern int register_android_hardware_UsbRequest(JNIEnv *env);
destradaaa4fa3b52014-07-09 10:46:39 -070096extern int register_android_hardware_location_ActivityRecognitionHardware(JNIEnv* env);
Peng Xu9ff7d222016-02-11 13:02:05 -080097extern int register_android_hardware_location_ContextHubService(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098
99extern int register_android_media_AudioRecord(JNIEnv *env);
100extern int register_android_media_AudioSystem(JNIEnv *env);
101extern int register_android_media_AudioTrack(JNIEnv *env);
102extern int register_android_media_JetPlayer(JNIEnv *env);
103extern int register_android_media_ToneGenerator(JNIEnv *env);
104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105namespace android {
106
107/*
108 * JNI-based registration functions. Note these are properly contained in
109 * namespace android.
110 */
Michal Karpinski6235a942016-03-15 12:07:23 +0000111extern int register_android_app_admin_SecurityLog(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112extern int register_android_content_AssetManager(JNIEnv* env);
113extern int register_android_util_EventLog(JNIEnv* env);
114extern int register_android_util_Log(JNIEnv* env);
Svet Ganov53a441c2016-04-19 19:38:00 -0700115extern int register_android_util_MemoryIntArray(JNIEnv* env);
Doris Liucdd23f92015-11-11 14:31:13 -0800116extern int register_android_util_PathParser(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117extern int register_android_content_StringBlock(JNIEnv* env);
118extern int register_android_content_XmlBlock(JNIEnv* env);
119extern int register_android_graphics_Canvas(JNIEnv* env);
John Reck52244ff2014-05-01 21:27:37 -0700120extern int register_android_graphics_CanvasProperty(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121extern int register_android_graphics_ColorFilter(JNIEnv* env);
122extern int register_android_graphics_DrawFilter(JNIEnv* env);
Raph Levien1a73f7322014-01-30 16:06:28 -0800123extern int register_android_graphics_FontFamily(JNIEnv* env);
Mike Reed4c9355c2014-05-07 11:48:37 -0400124extern int register_android_graphics_LayerRasterizer(JNIEnv*);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125extern int register_android_graphics_Matrix(JNIEnv* env);
126extern int register_android_graphics_Paint(JNIEnv* env);
127extern int register_android_graphics_Path(JNIEnv* env);
128extern int register_android_graphics_PathMeasure(JNIEnv* env);
129extern int register_android_graphics_Picture(JNIEnv*);
130extern int register_android_graphics_PorterDuff(JNIEnv* env);
131extern int register_android_graphics_Rasterizer(JNIEnv* env);
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);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134extern int register_android_graphics_Xfermode(JNIEnv* env);
Doris Liu766431a2016-02-04 22:17:11 +0000135extern int register_android_graphics_drawable_AnimatedVectorDrawable(JNIEnv* env);
Doris Liu4bbc2932015-12-01 17:59:40 -0800136extern int register_android_graphics_drawable_VectorDrawable(JNIEnv* env);
Svetoslav6811f4e2013-09-18 15:58:28 -0700137extern int register_android_graphics_pdf_PdfDocument(JNIEnv* env);
Svetoslav62ce3322014-09-04 21:17:17 -0700138extern int register_android_graphics_pdf_PdfEditor(JNIEnv* env);
Svetoslav29617692014-04-24 18:40:42 -0700139extern int register_android_graphics_pdf_PdfRenderer(JNIEnv* env);
Jeff Brown0a0a1242011-12-02 02:25:22 -0800140extern int register_android_view_DisplayEventReceiver(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700141extern int register_android_view_DisplayListCanvas(JNIEnv* env);
142extern int register_android_view_GraphicBuffer(JNIEnv* env);
143extern int register_android_view_HardwareLayer(JNIEnv* env);
John Reckf666ad72014-03-14 16:24:57 -0700144extern int register_android_view_RenderNode(JNIEnv* env);
John Recke45b1fd2014-04-15 09:50:16 -0700145extern int register_android_view_RenderNodeAnimator(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146extern int register_android_view_Surface(JNIEnv* env);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800147extern int register_android_view_SurfaceControl(JNIEnv* env);
Jeff Brown64a55af2012-08-26 02:47:39 -0700148extern int register_android_view_SurfaceSession(JNIEnv* env);
Romain Guy8f0095c2011-05-02 17:24:22 -0700149extern int register_android_view_TextureView(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700150extern int register_android_view_ThreadedRenderer(JNIEnv* env);
John Reck315c3292014-05-09 19:21:04 -0700151extern int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152extern int register_android_database_CursorWindow(JNIEnv* env);
Jeff Browne5360fb2011-10-31 17:48:13 -0700153extern int register_android_database_SQLiteConnection(JNIEnv* env);
154extern int register_android_database_SQLiteGlobal(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155extern int register_android_database_SQLiteDebug(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156extern int register_android_nio_utils(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157extern int register_android_os_Debug(JNIEnv* env);
Christopher Tatefa9e7c02010-05-06 12:07:10 -0700158extern int register_android_os_MessageQueue(JNIEnv* env);
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -0800159extern int register_android_os_Parcel(JNIEnv* env);
Stephen Smalleyc07fca32012-01-13 08:31:39 -0500160extern int register_android_os_SELinux(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161extern int register_android_os_SystemProperties(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162extern int register_android_os_SystemClock(JNIEnv* env);
Jeff Brown481c1572012-03-09 14:41:15 -0800163extern int register_android_os_Trace(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164extern int register_android_os_FileObserver(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165extern int register_android_os_UEventObserver(JNIEnv* env);
166extern int register_android_os_MemoryFile(JNIEnv* env);
167extern int register_android_net_LocalSocketImpl(JNIEnv* env);
168extern int register_android_net_NetworkUtils(JNIEnv* env);
Dan Egnor2b4abcd2010-04-07 17:30:50 -0700169extern int register_android_net_TrafficStats(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170extern int register_android_text_AndroidCharacter(JNIEnv *env);
Anish Athalye88b5b0b2014-06-24 14:39:43 -0700171extern int register_android_text_StaticLayout(JNIEnv *env);
Doug Feltdae8e942010-02-24 14:33:15 -0800172extern int register_android_text_AndroidBidi(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173extern int register_android_opengl_classes(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
Narayan Kamath29564cd2014-08-07 10:57:40 +0100175extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env);
Joe Onorato1cf58742009-06-12 11:06:24 -0700176extern int register_android_backup_BackupDataInput(JNIEnv *env);
Joe Onoratod2110db2009-05-19 13:41:21 -0700177extern int register_android_backup_BackupDataOutput(JNIEnv *env);
Joe Onorato06290a42009-06-18 20:10:37 -0700178extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
Joe Onorato4ababd92009-06-25 18:29:18 -0400179extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
Christopher Tate4a627c72011-04-01 14:43:32 -0700180extern int register_android_app_backup_FullBackup(JNIEnv *env);
Dimitry Ivanov4449ef52016-02-25 17:41:13 -0800181extern int register_android_app_Activity(JNIEnv *env);
Chet Haase9c1e23b2011-03-24 10:51:31 -0700182extern int register_android_app_ActivityThread(JNIEnv *env);
Dimitry Ivanov09979082016-04-19 11:11:01 -0700183extern int register_android_app_ApplicationLoaders(JNIEnv *env);
Dianne Hackborn69969e42010-05-04 11:40:40 -0700184extern int register_android_app_NativeActivity(JNIEnv *env);
Jeff Browncbad9762012-09-04 21:57:59 -0700185extern int register_android_media_RemoteDisplay(JNIEnv *env);
Przemyslaw Szczepaniak8a7c1602015-11-03 09:47:56 +0000186extern int register_android_util_jar_StrictJarFile(JNIEnv* env);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700187extern int register_android_view_InputChannel(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700188extern int register_android_view_InputDevice(JNIEnv* env);
Jeff Brown32cbc38552011-12-01 14:01:49 -0800189extern int register_android_view_InputEventReceiver(JNIEnv* env);
Jeff Brownc28867a2013-03-26 15:42:39 -0700190extern int register_android_view_InputEventSender(JNIEnv* env);
Michael Wrighta44dd262013-04-10 21:12:00 -0700191extern int register_android_view_InputQueue(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700192extern int register_android_view_KeyCharacterMap(JNIEnv *env);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700193extern int register_android_view_KeyEvent(JNIEnv* env);
194extern int register_android_view_MotionEvent(JNIEnv* env);
Jeff Brown2352b972011-04-12 22:39:53 -0700195extern int register_android_view_PointerIcon(JNIEnv* env);
Jeff Brown2ed24622011-03-14 19:39:54 -0700196extern int register_android_view_VelocityTracker(JNIEnv* env);
Kenny Root02c87302010-07-01 08:10:18 -0700197extern int register_android_content_res_ObbScanner(JNIEnv* env);
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700198extern int register_android_content_res_Configuration(JNIEnv* env);
Chet Haase6e0ecb42010-11-03 19:41:18 -0700199extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
Kenny Root66269ea2011-07-12 14:14:01 -0700200extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -0800201extern int register_com_android_internal_net_NetworkStatsFactory(JNIEnv *env);
Dimitry Ivanov5d7d7772016-04-20 14:09:32 -0700202extern int register_com_android_internal_os_PathClassLoaderFactory(JNIEnv* env);
Narayan Kamath973b4662014-03-31 13:41:26 +0100203extern int register_com_android_internal_os_Zygote(JNIEnv *env);
John Reck9fa40712014-05-09 15:26:59 -0700204extern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205
206static AndroidRuntime* gCurRuntime = NULL;
207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208/*
209 * Code written in the Java Programming Language calls here from main().
210 */
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700211static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212{
213 gCurRuntime->onStarted();
214}
215
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700216static void com_android_internal_os_RuntimeInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217{
218 gCurRuntime->onZygoteInit();
219}
220
Jeff Brown4280c4a2012-03-15 17:48:02 -0700221static void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIEnv* env,
222 jobject clazz, jboolean exitWithoutCleanup)
223{
224 gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup);
225}
226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227/*
228 * JNI registration.
229 */
Daniel Micay76f6a862015-09-19 17:31:01 -0400230static const JNINativeMethod gMethods[] = {
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700231 { "nativeFinishInit", "()V",
232 (void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
233 { "nativeZygoteInit", "()V",
234 (void*) com_android_internal_os_RuntimeInit_nativeZygoteInit },
Jeff Brown4280c4a2012-03-15 17:48:02 -0700235 { "nativeSetExitWithoutCleanup", "(Z)V",
236 (void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237};
238
239int register_com_android_internal_os_RuntimeInit(JNIEnv* env)
240{
241 return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
242 gMethods, NELEM(gMethods));
243}
244
245// ----------------------------------------------------------------------
246
Andreas Huber9ae000c2014-02-13 17:22:33 +0000247/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
248
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000249AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) :
250 mExitWithoutCleanup(false),
251 mArgBlockStart(argBlockStart),
252 mArgBlockLength(argBlockLength)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700254 SkGraphics::Init();
Ben Wagner177612332015-01-15 14:16:46 -0500255 // There is also a global font cache, but its budget is specified by
256 // SK_DEFAULT_FONT_CACHE_COUNT_LIMIT and SK_DEFAULT_FONT_CACHE_LIMIT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257
258 // Pre-allocate enough space to hold a fair number of options.
259 mOptions.setCapacity(20);
260
261 assert(gCurRuntime == NULL); // one per process
262 gCurRuntime = this;
263}
264
265AndroidRuntime::~AndroidRuntime()
266{
267 SkGraphics::Term();
268}
269
Andreas Huber9ae000c2014-02-13 17:22:33 +0000270/*
271 * Register native methods using JNI.
272 */
273/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
274 const char* className, const JNINativeMethod* gMethods, int numMethods)
275{
276 return jniRegisterNativeMethods(env, className, gMethods, numMethods);
277}
278
Dmitriy Filchenkof5b6e552016-07-18 16:00:35 -0700279void AndroidRuntime::setArgv0(const char* argv0, bool setProcName) {
280 if (setProcName) {
281 int len = strlen(argv0);
282 if (len < 15) {
283 pthread_setname_np(pthread_self(), argv0);
284 } else {
285 pthread_setname_np(pthread_self(), argv0 + len - 15);
286 }
287 }
Jeff Brown00c0cd42014-09-10 16:48:46 -0700288 memset(mArgBlockStart, 0, mArgBlockLength);
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000289 strlcpy(mArgBlockStart, argv0, mArgBlockLength);
290}
291
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100292status_t AndroidRuntime::callMain(const String8& className, jclass clazz,
293 const Vector<String8>& args)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294{
295 JNIEnv* env;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 jmethodID methodId;
297
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100298 ALOGD("Calling main entry %s", className.string());
Dianne Hackborn08e60f22010-09-01 18:17:17 -0700299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300 env = getJNIEnv();
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700301 if (clazz == NULL || env == NULL) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 return UNKNOWN_ERROR;
303 }
304
305 methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
306 if (methodId == NULL) {
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100307 ALOGE("ERROR: could not find method %s.main(String[])\n", className.string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 return UNKNOWN_ERROR;
309 }
310
311 /*
312 * We want to call main() with a String array with our arguments in it.
313 * Create an array and populate it.
314 */
315 jclass stringClass;
316 jobjectArray strArray;
317
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100318 const size_t numArgs = args.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 stringClass = env->FindClass("java/lang/String");
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100320 strArray = env->NewObjectArray(numArgs, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100322 for (size_t i = 0; i < numArgs; i++) {
323 jstring argStr = env->NewStringUTF(args[i].string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324 env->SetObjectArrayElement(strArray, i, argStr);
325 }
326
327 env->CallStaticVoidMethod(clazz, methodId, strArray);
328 return NO_ERROR;
329}
330
331/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 * The VM calls this through the "exit" hook.
333 */
334static void runtime_exit(int code)
335{
Jeff Brown4280c4a2012-03-15 17:48:02 -0700336 gCurRuntime->exit(code);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337}
338
339/*
340 * The VM calls this through the "vfprintf" hook.
341 *
342 * We ignore "fp" and just write the results to the log file.
343 */
344static void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
345{
346 LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
347}
348
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800349/**
350 * The VM calls this when mutex contention debugging is enabled to
351 * determine whether or not the blocked thread was a "sensitive thread"
352 * for user responsiveness/smoothess.
353 *
354 * Our policy for this is whether or not we're tracing any StrictMode
355 * events on this thread (which we might've inherited via Binder calls
356 * into us)
357 */
358static bool runtime_isSensitiveThread() {
359 IPCThreadState* state = IPCThreadState::selfOrNull();
360 return state && state->getStrictModePolicy() != 0;
361}
362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363static int hasDir(const char* dir)
364{
365 struct stat s;
366 int res = stat(dir, &s);
367 if (res == 0) {
368 return S_ISDIR(s.st_mode);
369 }
370 return 0;
371}
372
Andreas Gampe995c62d2014-11-14 16:15:17 -0800373static bool hasFile(const char* file) {
374 struct stat s;
375 int res = stat(file, &s);
376 if (res == 0) {
377 return S_ISREG(s.st_mode);
378 }
379 return false;
380}
381
Narayan Kamathbf882052015-08-11 15:40:34 +0100382// Convenience wrapper over the property API that returns an
383// std::string.
384std::string getProperty(const char* key, const char* defaultValue) {
385 std::vector<char> temp(PROPERTY_VALUE_MAX);
386 const int len = property_get(key, &temp[0], defaultValue);
387 if (len < 0) {
388 return "";
389 }
390 return std::string(&temp[0], len);
391}
392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393/*
Narayan Kamathbf882052015-08-11 15:40:34 +0100394 * Read the persistent locale. Inspects the following system properties
395 * (in order) and returns the first non-empty property in the list :
396 *
397 * (1) persist.sys.locale
398 * (2) persist.sys.language/country/localevar (country and localevar are
399 * inspected iff. language is non-empty.
400 * (3) ro.product.locale
401 * (4) ro.product.locale.language/region
402 *
403 * Note that we need to inspect persist.sys.language/country/localevar to
404 * preserve language settings for devices that are upgrading from Lollipop
405 * to M. The same goes for ro.product.locale.language/region as well.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 */
Narayan Kamathbf882052015-08-11 15:40:34 +0100407const std::string readLocale()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408{
Narayan Kamathbf882052015-08-11 15:40:34 +0100409 const std::string locale = getProperty("persist.sys.locale", "");
410 if (!locale.empty()) {
411 return locale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 }
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000413
Narayan Kamathbf882052015-08-11 15:40:34 +0100414 const std::string language = getProperty("persist.sys.language", "");
415 if (!language.empty()) {
416 const std::string country = getProperty("persist.sys.country", "");
417 const std::string variant = getProperty("persist.sys.localevar", "");
418
419 std::string out = language;
420 if (!country.empty()) {
421 out = out + "-" + country;
422 }
423
424 if (!variant.empty()) {
425 out = out + "-" + variant;
426 }
427
428 return out;
429 }
430
431 const std::string productLocale = getProperty("ro.product.locale", "");
432 if (!productLocale.empty()) {
433 return productLocale;
434 }
435
436 // If persist.sys.locale and ro.product.locale are missing,
437 // construct a locale value from the individual locale components.
438 const std::string productLanguage = getProperty("ro.product.locale.language", "en");
439 const std::string productRegion = getProperty("ro.product.locale.region", "US");
440
441 return productLanguage + "-" + productRegion;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442}
443
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700444void AndroidRuntime::addOption(const char* optionString, void* extraInfo)
445{
446 JavaVMOption opt;
447 opt.optionString = optionString;
448 opt.extraInfo = extraInfo;
449 mOptions.add(opt);
450}
451
Andy McFaddenf70188a2009-03-31 15:52:13 -0700452/*
Andy McFaddene4d81f22010-07-14 16:02:20 -0700453 * Parse a property containing space-separated options that should be
454 * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
455 *
456 * This will cut up "extraOptsBuf" as we chop it into individual options.
457 *
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800458 * If "quotingArg" is non-null, it is passed before each extra option in mOptions.
459 *
Andy McFaddene4d81f22010-07-14 16:02:20 -0700460 * Adds the strings, if any, to mOptions.
461 */
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800462void AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg)
Andy McFaddene4d81f22010-07-14 16:02:20 -0700463{
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800464 char* start = extraOptsBuf;
465 char* end = NULL;
Andy McFaddene4d81f22010-07-14 16:02:20 -0700466 while (*start != '\0') {
467 while (*start == ' ') /* skip leading whitespace */
468 start++;
469 if (*start == '\0') /* was trailing ws, bail */
470 break;
471
472 end = start+1;
473 while (*end != ' ' && *end != '\0') /* find end of token */
474 end++;
475 if (*end == ' ')
476 *end++ = '\0'; /* mark end, advance to indicate more */
477
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800478 if (quotingArg != NULL) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700479 addOption(quotingArg);
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800480 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700481 addOption(start);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700482 start = end;
483 }
484}
485
486/*
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700487 * Reads a "property" into "buffer" with a default of "defaultArg". If
488 * the property is non-empty, it is treated as a runtime option such
489 * as "-Xmx32m".
490 *
491 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
492 *
493 * If an argument is found, it is added to mOptions.
494 *
495 * If an option is found, it is added to mOptions and true is
496 * returned. Otherwise false is returned.
497 */
498bool AndroidRuntime::parseRuntimeOption(const char* property,
499 char* buffer,
500 const char* runtimeArg,
501 const char* defaultArg)
502{
503 strcpy(buffer, runtimeArg);
504 size_t runtimeArgLen = strlen(runtimeArg);
505 property_get(property, buffer+runtimeArgLen, defaultArg);
506 if (buffer[runtimeArgLen] == '\0') {
507 return false;
508 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700509 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700510 return true;
511}
512
513/*
514 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700515 * is treated as a dex2oat compiler option that should be
516 * passed as a quoted option, e.g. "-Ximage-compiler-option --compiler-filter=verify-none".
517 *
518 * The "compilerArg" is a prefix for the option such as "--compiler-filter=".
519 *
520 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
521 *
522 * If an option is found, it is added to mOptions and true is
523 * returned. Otherwise false is returned.
524 */
525bool AndroidRuntime::parseCompilerOption(const char* property,
526 char* buffer,
527 const char* compilerArg,
528 const char* quotingArg)
529{
530 strcpy(buffer, compilerArg);
531 size_t compilerArgLen = strlen(compilerArg);
532 property_get(property, buffer+compilerArgLen, "");
533 if (buffer[compilerArgLen] == '\0') {
534 return false;
535 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700536 addOption(quotingArg);
537 addOption(buffer);
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700538 return true;
539}
540
541/*
542 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700543 * is treated as a dex2oat compiler runtime option that should be
544 * passed as a quoted option, e.g. "-Ximage-compiler-option
545 * --runtime-arg -Ximage-compiler-option -Xmx32m".
546 *
547 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
548 *
549 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
550 *
551 * If an option is found, it is added to mOptions and true is
552 * returned. Otherwise false is returned.
553 */
554bool AndroidRuntime::parseCompilerRuntimeOption(const char* property,
555 char* buffer,
556 const char* runtimeArg,
557 const char* quotingArg)
558{
559 strcpy(buffer, runtimeArg);
560 size_t runtimeArgLen = strlen(runtimeArg);
561 property_get(property, buffer+runtimeArgLen, "");
562 if (buffer[runtimeArgLen] == '\0') {
563 return false;
564 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700565 addOption(quotingArg);
566 addOption("--runtime-arg");
567 addOption(quotingArg);
568 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700569 return true;
570}
571
572/*
Andy McFaddenf70188a2009-03-31 15:52:13 -0700573 * Start the Dalvik Virtual Machine.
574 *
575 * Various arguments, most determined by system properties, are passed in.
576 * The "mOptions" vector is updated.
577 *
Dave Allison07a1e232014-03-14 08:54:33 -0700578 * CAUTION: when adding options in here, be careful not to put the
579 * char buffer inside a nested scope. Adding the buffer to the
580 * options using mOptions.add() does not copy the buffer, so if the
581 * buffer goes out of scope the option may be overwritten. It's best
582 * to put the buffer at the top of the function so that it is more
583 * unlikely that someone will surround it in a scope at a later time
584 * and thus introduce a bug.
585 *
Andy McFaddenf70188a2009-03-31 15:52:13 -0700586 * Returns 0 on success.
587 */
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200588int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 JavaVMInitArgs initArgs;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591 char propBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700592 char stackTraceFileBuf[sizeof("-Xstacktracefile:")-1 + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro38cfa8c2010-12-07 16:48:29 -0800594 char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700595 char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro8cdf27c2011-01-19 12:33:12 -0800596 char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700597 char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
598 char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800599 char usejitOptsBuf[sizeof("-Xusejit:")-1 + PROPERTY_VALUE_MAX];
Nicolas Geoffraycdf1dff2015-11-19 13:48:35 +0000600 char jitmaxsizeOptsBuf[sizeof("-Xjitmaxsize:")-1 + PROPERTY_VALUE_MAX];
601 char jitinitialsizeOptsBuf[sizeof("-Xjitinitialsize:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800602 char jitthresholdOptsBuf[sizeof("-Xjitthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravledb4a79a2015-12-23 18:55:08 +0200603 char useJitProfilesOptsBuf[sizeof("-Xjitsaveprofilinginfo:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle0de80b92016-04-12 14:12:04 +0100604 char jitprithreadweightOptBuf[sizeof("-Xjitprithreadweight:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle8d74de52016-04-27 14:12:00 +0100605 char jittransitionweightOptBuf[sizeof("-Xjittransitionweight:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier7e4fdec2013-12-02 15:46:51 -0800606 char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700607 char backgroundgcOptsBuf[sizeof("-XX:BackgroundGC=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700608 char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee324ba02015-03-31 16:15:17 -0700609 char cachePruneBuf[sizeof("-Xzygote-max-boot-retry=")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700610 char dex2oatXmsImageFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
611 char dex2oatXmxImageFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
612 char dex2oatXmsFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
613 char dex2oatXmxFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700614 char dex2oatCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
615 char dex2oatImageCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee0352382015-03-30 18:43:39 -0700616 char dex2oatThreadsBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
617 char dex2oatThreadsImageBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
Andreas Gampe605cca12015-04-02 23:12:56 -0700618 char dex2oat_isa_variant_key[PROPERTY_KEY_MAX];
619 char dex2oat_isa_variant[sizeof("--instruction-set-variant=") -1 + PROPERTY_VALUE_MAX];
620 char dex2oat_isa_features_key[PROPERTY_KEY_MAX];
621 char dex2oat_isa_features[sizeof("--instruction-set-features=") -1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800622 char dex2oatFlagsBuf[PROPERTY_VALUE_MAX];
623 char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX];
Andy McFaddene4d81f22010-07-14 16:02:20 -0700624 char extraOptsBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700625 char voldDecryptBuf[PROPERTY_VALUE_MAX];
Ben Cheng52b0e732009-06-19 13:31:12 -0700626 enum {
627 kEMDefault,
628 kEMIntPortable,
629 kEMIntFast,
Ben Cheng52b0e732009-06-19 13:31:12 -0700630 kEMJitCompiler,
Ben Cheng52b0e732009-06-19 13:31:12 -0700631 } executionMode = kEMDefault;
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000632 char localeOption[sizeof("-Duser.locale=") + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700633 char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle01db9162014-08-07 14:45:53 +0100634 char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX];
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700635 char cpuAbiListBuf[sizeof("--cpu-abilist=") + PROPERTY_VALUE_MAX];
Andreas Gampe98f406f2015-06-22 21:09:36 -0700636 char methodTraceFileBuf[sizeof("-Xmethod-trace-file:") + PROPERTY_VALUE_MAX];
637 char methodTraceFileSizeBuf[sizeof("-Xmethod-trace-file-size:") + PROPERTY_VALUE_MAX];
Andreas Gampee6082502015-07-24 14:19:44 -0700638 char fingerprintBuf[sizeof("-Xfingerprint:") + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700640 bool checkJni = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800641 property_get("dalvik.vm.checkjni", propBuf, "");
642 if (strcmp(propBuf, "true") == 0) {
643 checkJni = true;
644 } else if (strcmp(propBuf, "false") != 0) {
645 /* property is neither true nor false; fall back on kernel parameter */
646 property_get("ro.kernel.android.checkjni", propBuf, "");
647 if (propBuf[0] == '1') {
648 checkJni = true;
649 }
650 }
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700651 ALOGD("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
652 if (checkJni) {
653 /* extended JNI checking */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700654 addOption("-Xcheck:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700655
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700656 /* with -Xcheck:jni, this provides a JNI function call trace */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700657 //addOption("-verbose:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700658 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659
660 property_get("dalvik.vm.execution-mode", propBuf, "");
661 if (strcmp(propBuf, "int:portable") == 0) {
662 executionMode = kEMIntPortable;
663 } else if (strcmp(propBuf, "int:fast") == 0) {
664 executionMode = kEMIntFast;
Ben Cheng52b0e732009-06-19 13:31:12 -0700665 } else if (strcmp(propBuf, "int:jit") == 0) {
666 executionMode = kEMJitCompiler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 }
668
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700669 parseRuntimeOption("dalvik.vm.stack-trace-file", stackTraceFileBuf, "-Xstacktracefile:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671 strcpy(jniOptsBuf, "-Xjniopts:");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700672 if (parseRuntimeOption("dalvik.vm.jniopts", jniOptsBuf, "-Xjniopts:")) {
673 ALOGI("JNI options: '%s'\n", jniOptsBuf);
674 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 /* route exit() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700677 addOption("exit", (void*) runtime_exit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678
679 /* route fprintf() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700680 addOption("vfprintf", (void*) runtime_vfprintf);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800682 /* register the framework-specific "is sensitive thread" hook */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700683 addOption("sensitiveThread", (void*) runtime_isSensitiveThread);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684
685 /* enable verbose; standard options are { jni, gc, class } */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700686 //addOption("-verbose:jni");
687 addOption("-verbose:gc");
688 //addOption("-verbose:class");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689
Carl Shapiro9e4c8842010-12-08 12:14:46 -0800690 /*
691 * The default starting and maximum size of the heap. Larger
692 * values should be specified in a product property override.
693 */
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700694 parseRuntimeOption("dalvik.vm.heapstartsize", heapstartsizeOptsBuf, "-Xms", "4m");
695 parseRuntimeOption("dalvik.vm.heapsize", heapsizeOptsBuf, "-Xmx", "16m");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800696
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700697 parseRuntimeOption("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
698 parseRuntimeOption("dalvik.vm.heapminfree", heapminfreeOptsBuf, "-XX:HeapMinFree=");
699 parseRuntimeOption("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf, "-XX:HeapMaxFree=");
700 parseRuntimeOption("dalvik.vm.heaptargetutilization",
701 heaptargetutilizationOptsBuf,
702 "-XX:HeapTargetUtilization=");
Ian Rogers53250102012-09-23 16:38:03 -0700703
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800704 /*
705 * JIT related options.
706 */
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700707 parseRuntimeOption("dalvik.vm.usejit", usejitOptsBuf, "-Xusejit:");
Nicolas Geoffraycdf1dff2015-11-19 13:48:35 +0000708 parseRuntimeOption("dalvik.vm.jitmaxsize", jitmaxsizeOptsBuf, "-Xjitmaxsize:");
709 parseRuntimeOption("dalvik.vm.jitinitialsize", jitinitialsizeOptsBuf, "-Xjitinitialsize:");
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700710 parseRuntimeOption("dalvik.vm.jitthreshold", jitthresholdOptsBuf, "-Xjitthreshold:");
Calin Juravledb4a79a2015-12-23 18:55:08 +0200711 property_get("dalvik.vm.usejitprofiles", useJitProfilesOptsBuf, "");
712 if (strcmp(useJitProfilesOptsBuf, "true") == 0) {
713 addOption("-Xjitsaveprofilinginfo");
714 }
Calin Juravle8d74de52016-04-27 14:12:00 +0100715
Calin Juravle0de80b92016-04-12 14:12:04 +0100716 parseRuntimeOption("dalvik.vm.jitprithreadweight",
717 jitprithreadweightOptBuf,
718 "-Xjitprithreadweight:");
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800719
Calin Juravle8d74de52016-04-27 14:12:00 +0100720 parseRuntimeOption("dalvik.vm.jittransitionweight",
721 jittransitionweightOptBuf,
722 "-Xjittransitionweight:");
723
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700724 property_get("ro.config.low_ram", propBuf, "");
725 if (strcmp(propBuf, "true") == 0) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700726 addOption("-XX:LowMemoryMode");
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700727 }
728
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700729 parseRuntimeOption("dalvik.vm.gctype", gctypeOptsBuf, "-Xgc:");
730 parseRuntimeOption("dalvik.vm.backgroundgctype", backgroundgcOptsBuf, "-XX:BackgroundGC=");
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700731
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200732 /*
733 * Enable debugging only for apps forked from zygote.
734 * Set suspend=y to pause during VM init and use android ADB transport.
735 */
736 if (zygote) {
737 addOption("-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y");
738 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700740 parseRuntimeOption("dalvik.vm.lockprof.threshold",
741 lockProfThresholdBuf,
742 "-Xlockprofthreshold:");
Carl Shapirod8f3ec62010-04-12 16:31:59 -0700743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 if (executionMode == kEMIntPortable) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700745 addOption("-Xint:portable");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800746 } else if (executionMode == kEMIntFast) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700747 addOption("-Xint:fast");
Ben Cheng52b0e732009-06-19 13:31:12 -0700748 } else if (executionMode == kEMJitCompiler) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700749 addOption("-Xint:jit");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 }
Andy McFaddene2b23e12009-04-03 11:09:46 -0700751
Andreas Gampe08b2d582014-12-18 14:39:22 -0800752 // If we are booting without the real /data, don't spend time compiling.
753 property_get("vold.decrypt", voldDecryptBuf, "");
754 bool skip_compilation = ((strcmp(voldDecryptBuf, "trigger_restart_min_framework") == 0) ||
755 (strcmp(voldDecryptBuf, "1") == 0));
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800756
Andreas Gampe08b2d582014-12-18 14:39:22 -0800757 // Extra options for boot.art/boot.oat image generation.
758 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xms", dex2oatXmsImageFlagsBuf,
759 "-Xms", "-Ximage-compiler-option");
760 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xmx", dex2oatXmxImageFlagsBuf,
761 "-Xmx", "-Ximage-compiler-option");
762 if (skip_compilation) {
Brian Carlstromce5bbbe2014-07-30 15:13:17 -0700763 addOption("-Ximage-compiler-option");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800764 addOption("--compiler-filter=verify-none");
765 } else {
766 parseCompilerOption("dalvik.vm.image-dex2oat-filter", dex2oatImageCompilerFilterBuf,
767 "--compiler-filter=", "-Ximage-compiler-option");
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800768 }
769
Andreas Gampe08b2d582014-12-18 14:39:22 -0800770 // Make sure there is a preloaded-classes file.
771 if (!hasFile("/system/etc/preloaded-classes")) {
772 ALOGE("Missing preloaded-classes file, /system/etc/preloaded-classes not found: %s\n",
773 strerror(errno));
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700774 return -1;
Andreas Gampe08b2d582014-12-18 14:39:22 -0800775 }
776 addOption("-Ximage-compiler-option");
777 addOption("--image-classes=/system/etc/preloaded-classes");
778
779 // If there is a compiled-classes file, push it.
780 if (hasFile("/system/etc/compiled-classes")) {
781 addOption("-Ximage-compiler-option");
782 addOption("--compiled-classes=/system/etc/compiled-classes");
783 }
784
785 property_get("dalvik.vm.image-dex2oat-flags", dex2oatImageFlagsBuf, "");
786 parseExtraOpts(dex2oatImageFlagsBuf, "-Ximage-compiler-option");
787
788 // Extra options for DexClassLoader.
789 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xms", dex2oatXmsFlagsBuf,
790 "-Xms", "-Xcompiler-option");
791 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xmx", dex2oatXmxFlagsBuf,
792 "-Xmx", "-Xcompiler-option");
793 if (skip_compilation) {
794 addOption("-Xcompiler-option");
795 addOption("--compiler-filter=verify-none");
neo.chae155118f2015-01-07 15:32:15 +0900796
797 // We skip compilation when a minimal runtime is brought up for decryption. In that case
798 // /data is temporarily backed by a tmpfs, which is usually small.
799 // If the system image contains prebuilts, they will be relocated into the tmpfs. In this
800 // specific situation it is acceptable to *not* relocate and run out of the prebuilts
801 // directly instead.
802 addOption("--runtime-arg");
803 addOption("-Xnorelocate");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800804 } else {
805 parseCompilerOption("dalvik.vm.dex2oat-filter", dex2oatCompilerFilterBuf,
806 "--compiler-filter=", "-Xcompiler-option");
807 }
Andreas Gampee0352382015-03-30 18:43:39 -0700808 parseCompilerOption("dalvik.vm.dex2oat-threads", dex2oatThreadsBuf, "-j", "-Xcompiler-option");
809 parseCompilerOption("dalvik.vm.image-dex2oat-threads", dex2oatThreadsImageBuf, "-j",
810 "-Ximage-compiler-option");
Andreas Gampe605cca12015-04-02 23:12:56 -0700811
812 // The runtime will compile a boot image, when necessary, not using installd. Thus, we need to
813 // pass the instruction-set-features/variant as an image-compiler-option.
814 // TODO: Find a better way for the instruction-set.
815#if defined(__arm__)
816 constexpr const char* instruction_set = "arm";
817#elif defined(__aarch64__)
818 constexpr const char* instruction_set = "arm64";
819#elif defined(__mips__) && !defined(__LP64__)
820 constexpr const char* instruction_set = "mips";
821#elif defined(__mips__) && defined(__LP64__)
822 constexpr const char* instruction_set = "mips64";
823#elif defined(__i386__)
824 constexpr const char* instruction_set = "x86";
825#elif defined(__x86_64__)
826 constexpr const char* instruction_set = "x86_64";
827#else
828 constexpr const char* instruction_set = "unknown";
829#endif
830 // Note: it is OK to reuse the buffer, as the values are exactly the same between
831 // * compiler-option, used for runtime compilation (DexClassLoader)
832 // * image-compiler-option, used for boot-image compilation on device
833
834 // Copy the variant.
835 sprintf(dex2oat_isa_variant_key, "dalvik.vm.isa.%s.variant", instruction_set);
836 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
837 "--instruction-set-variant=", "-Ximage-compiler-option");
838 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
839 "--instruction-set-variant=", "-Xcompiler-option");
840 // Copy the features.
841 sprintf(dex2oat_isa_features_key, "dalvik.vm.isa.%s.features", instruction_set);
842 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
843 "--instruction-set-features=", "-Ximage-compiler-option");
844 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
845 "--instruction-set-features=", "-Xcompiler-option");
846
847
Andreas Gampe08b2d582014-12-18 14:39:22 -0800848 property_get("dalvik.vm.dex2oat-flags", dex2oatFlagsBuf, "");
849 parseExtraOpts(dex2oatFlagsBuf, "-Xcompiler-option");
850
Andy McFaddene4d81f22010-07-14 16:02:20 -0700851 /* extra options; parse this late so it overrides others */
852 property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800853 parseExtraOpts(extraOptsBuf, NULL);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855 /* Set the properties for locale */
856 {
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000857 strcpy(localeOption, "-Duser.locale=");
Narayan Kamathbf882052015-08-11 15:40:34 +0100858 const std::string locale = readLocale();
859 strncat(localeOption, locale.c_str(), PROPERTY_VALUE_MAX);
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000860 addOption(localeOption);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 }
862
Calin Juravle92290b82015-11-10 19:30:45 +0000863 // Trace files are stored in /data/misc/trace which is writable only in debug mode.
864 property_get("ro.debuggable", propBuf, "0");
865 if (strcmp(propBuf, "1") == 0) {
866 property_get("dalvik.vm.method-trace", propBuf, "false");
Andreas Gampe98f406f2015-06-22 21:09:36 -0700867 if (strcmp(propBuf, "true") == 0) {
Calin Juravle92290b82015-11-10 19:30:45 +0000868 addOption("-Xmethod-trace");
869 parseRuntimeOption("dalvik.vm.method-trace-file",
870 methodTraceFileBuf,
871 "-Xmethod-trace-file:");
872 parseRuntimeOption("dalvik.vm.method-trace-file-siz",
873 methodTraceFileSizeBuf,
874 "-Xmethod-trace-file-size:");
875 property_get("dalvik.vm.method-trace-stream", propBuf, "false");
876 if (strcmp(propBuf, "true") == 0) {
877 addOption("-Xmethod-trace-stream");
878 }
Andreas Gampe98f406f2015-06-22 21:09:36 -0700879 }
880 }
881
Andreas Gampe08b2d582014-12-18 14:39:22 -0800882 // Native bridge library. "0" means that native bridge is disabled.
883 property_get("ro.dalvik.vm.native.bridge", propBuf, "");
884 if (propBuf[0] == '\0') {
885 ALOGW("ro.dalvik.vm.native.bridge is not expected to be empty");
886 } else if (strcmp(propBuf, "0") != 0) {
887 snprintf(nativeBridgeLibrary, sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX,
888 "-XX:NativeBridge=%s", propBuf);
889 addOption(nativeBridgeLibrary);
Calin Juravlebe20ed42014-08-26 23:00:11 +0100890 }
Calin Juravle01db9162014-08-07 14:45:53 +0100891
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700892#if defined(__LP64__)
893 const char* cpu_abilist_property_name = "ro.product.cpu.abilist64";
894#else
895 const char* cpu_abilist_property_name = "ro.product.cpu.abilist32";
896#endif // defined(__LP64__)
897 property_get(cpu_abilist_property_name, propBuf, "");
898 if (propBuf[0] == '\0') {
899 ALOGE("%s is not expected to be empty", cpu_abilist_property_name);
900 return -1;
901 }
902 snprintf(cpuAbiListBuf, sizeof(cpuAbiListBuf), "--cpu-abilist=%s", propBuf);
903 addOption(cpuAbiListBuf);
904
Andreas Gampee324ba02015-03-31 16:15:17 -0700905 // Dalvik-cache pruning counter.
906 parseRuntimeOption("dalvik.vm.zygote.max-boot-retry", cachePruneBuf,
907 "-Xzygote-max-boot-retry=");
908
Andreas Gampe27c39f12015-04-27 18:28:18 +0000909 /*
David Srbecky065075e2015-05-28 17:16:09 +0100910 * When running with debug.generate-debug-info, add --generate-debug-info to
911 * the compiler options so that the boot image, if it is compiled on device,
912 * will include native debugging information.
Andreas Gampe27c39f12015-04-27 18:28:18 +0000913 */
David Srbecky065075e2015-05-28 17:16:09 +0100914 property_get("debug.generate-debug-info", propBuf, "");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000915 if (strcmp(propBuf, "true") == 0) {
916 addOption("-Xcompiler-option");
David Srbecky065075e2015-05-28 17:16:09 +0100917 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000918 addOption("-Ximage-compiler-option");
David Srbecky065075e2015-05-28 17:16:09 +0100919 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000920 }
921
Andreas Gampee6082502015-07-24 14:19:44 -0700922 /*
923 * Retrieve the build fingerprint and provide it to the runtime. That way, ANR dumps will
924 * contain the fingerprint and can be parsed.
925 */
926 parseRuntimeOption("ro.build.fingerprint", fingerprintBuf, "-Xfingerprint:");
927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 initArgs.version = JNI_VERSION_1_4;
929 initArgs.options = mOptions.editArray();
930 initArgs.nOptions = mOptions.size();
931 initArgs.ignoreUnrecognized = JNI_FALSE;
932
933 /*
934 * Initialize the VM.
935 *
936 * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread.
937 * If this call succeeds, the VM is ready, and we can start issuing
938 * JNI calls.
939 */
Andy McFaddenf70188a2009-03-31 15:52:13 -0700940 if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) {
Steve Block3762c312012-01-06 19:20:56 +0000941 ALOGE("JNI_CreateJavaVM failed\n");
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700942 return -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800943 }
944
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700945 return 0;
Andy McFaddenf70188a2009-03-31 15:52:13 -0700946}
947
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700948char* AndroidRuntime::toSlashClassName(const char* className)
949{
950 char* result = strdup(className);
951 for (char* cp = result; *cp != '\0'; cp++) {
952 if (*cp == '.') {
953 *cp = '/';
954 }
955 }
956 return result;
957}
958
Mike Lockwood9ee5e7e2014-09-08 16:15:21 -0700959/** Create a Java string from an ASCII or Latin-1 string */
960jstring AndroidRuntime::NewStringLatin1(JNIEnv* env, const char* bytes) {
961 if (!bytes) return NULL;
962 int length = strlen(bytes);
963 jchar* buffer = (jchar *)alloca(length * sizeof(jchar));
964 if (!buffer) return NULL;
965 jchar* chp = buffer;
966 for (int i = 0; i < length; i++) {
967 *chp++ = *bytes++;
968 }
969 return env->NewString(buffer, length);
970}
971
972
Andy McFaddenf70188a2009-03-31 15:52:13 -0700973/*
974 * Start the Android runtime. This involves starting the virtual machine
975 * and calling the "static void main(String[] args)" method in the class
976 * named by "className".
Jeff Brownebed7d62011-05-16 17:08:42 -0700977 *
978 * Passes the main function two arguments, the class name and the specified
979 * options string.
Andy McFaddenf70188a2009-03-31 15:52:13 -0700980 */
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200981void AndroidRuntime::start(const char* className, const Vector<String8>& options, bool zygote)
Andy McFaddenf70188a2009-03-31 15:52:13 -0700982{
Dianne Hackborn8e5aafe2014-10-27 18:04:10 -0700983 ALOGD(">>>>>> START %s uid %d <<<<<<\n",
984 className != NULL ? className : "(unknown)", getuid());
Andy McFaddenf70188a2009-03-31 15:52:13 -0700985
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100986 static const String8 startSystemServer("start-system-server");
987
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700988 /*
989 * 'startSystemServer == true' means runtime is obsolete and not run from
Andy McFaddenf70188a2009-03-31 15:52:13 -0700990 * init.rc anymore, so we print out the boot start event here.
991 */
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100992 for (size_t i = 0; i < options.size(); ++i) {
993 if (options[i] == startSystemServer) {
994 /* track our progress through the boot sequence */
995 const int LOG_BOOT_PROGRESS_START = 3000;
996 LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));
997 }
Andy McFaddenf70188a2009-03-31 15:52:13 -0700998 }
999
1000 const char* rootDir = getenv("ANDROID_ROOT");
1001 if (rootDir == NULL) {
1002 rootDir = "/system";
1003 if (!hasDir("/system")) {
1004 LOG_FATAL("No root directory specified, and /android does not exist.");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001005 return;
Andy McFaddenf70188a2009-03-31 15:52:13 -07001006 }
1007 setenv("ANDROID_ROOT", rootDir, 1);
1008 }
1009
1010 //const char* kernelHack = getenv("LD_ASSUME_KERNEL");
Steve Block5baa3a62011-12-20 16:23:08 +00001011 //ALOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001012
1013 /* start the virtual machine */
Brian Carlstrom9f8203a2013-06-19 13:49:36 -07001014 JniInvocation jni_invocation;
1015 jni_invocation.Init(NULL);
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001016 JNIEnv* env;
Sebastien Hertz7a09b832015-08-10 18:55:34 +02001017 if (startVm(&mJavaVM, &env, zygote) != 0) {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001018 return;
1019 }
1020 onVmCreated(env);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001022 /*
1023 * Register android functions.
1024 */
1025 if (startReg(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001026 ALOGE("Unable to register all android natives\n");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001027 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 }
1029
1030 /*
1031 * We want to call main() with a String array with arguments in it.
Jeff Brownebed7d62011-05-16 17:08:42 -07001032 * At present we have two arguments, the class name and an option string.
1033 * Create an array to hold them.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001034 */
1035 jclass stringClass;
1036 jobjectArray strArray;
1037 jstring classNameStr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001038
1039 stringClass = env->FindClass("java/lang/String");
1040 assert(stringClass != NULL);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001041 strArray = env->NewObjectArray(options.size() + 1, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001042 assert(strArray != NULL);
1043 classNameStr = env->NewStringUTF(className);
1044 assert(classNameStr != NULL);
1045 env->SetObjectArrayElement(strArray, 0, classNameStr);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001046
1047 for (size_t i = 0; i < options.size(); ++i) {
1048 jstring optionsStr = env->NewStringUTF(options.itemAt(i).string());
1049 assert(optionsStr != NULL);
1050 env->SetObjectArrayElement(strArray, i + 1, optionsStr);
1051 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052
1053 /*
1054 * Start VM. This thread becomes the main thread of the VM, and will
1055 * not return until the VM exits.
1056 */
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001057 char* slashClassName = toSlashClassName(className);
1058 jclass startClass = env->FindClass(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 if (startClass == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001060 ALOGE("JavaVM unable to locate class '%s'\n", slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001061 /* keep going */
1062 } else {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001063 jmethodID startMeth = env->GetStaticMethodID(startClass, "main",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001064 "([Ljava/lang/String;)V");
1065 if (startMeth == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001066 ALOGE("JavaVM unable to find main() in '%s'\n", className);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 /* keep going */
1068 } else {
1069 env->CallStaticVoidMethod(startClass, startMeth, strArray);
1070
1071#if 0
1072 if (env->ExceptionCheck())
1073 threadExitUncaughtException(env);
1074#endif
1075 }
1076 }
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001077 free(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078
Steve Block5baa3a62011-12-20 16:23:08 +00001079 ALOGD("Shutting down VM\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 if (mJavaVM->DetachCurrentThread() != JNI_OK)
Steve Block8564c8d2012-01-05 23:22:43 +00001081 ALOGW("Warning: unable to detach main thread\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 if (mJavaVM->DestroyJavaVM() != 0)
Steve Block8564c8d2012-01-05 23:22:43 +00001083 ALOGW("Warning: VM did not shut down cleanly\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084}
1085
Jeff Brown4280c4a2012-03-15 17:48:02 -07001086void AndroidRuntime::exit(int code)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087{
Jeff Brown4280c4a2012-03-15 17:48:02 -07001088 if (mExitWithoutCleanup) {
1089 ALOGI("VM exiting with result code %d, cleanup skipped.", code);
1090 ::_exit(code);
1091 } else {
1092 ALOGI("VM exiting with result code %d.", code);
1093 onExit(code);
1094 ::exit(code);
1095 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096}
1097
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001098void AndroidRuntime::onVmCreated(JNIEnv* env)
1099{
1100 // If AndroidRuntime had anything to do here, we'd have done it in 'start'.
1101}
1102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103/*
Andreas Huber9ae000c2014-02-13 17:22:33 +00001104 * Get the JNIEnv pointer for this thread.
1105 *
1106 * Returns NULL if the slot wasn't allocated or populated.
1107 */
1108/*static*/ JNIEnv* AndroidRuntime::getJNIEnv()
1109{
1110 JNIEnv* env;
1111 JavaVM* vm = AndroidRuntime::getJavaVM();
1112 assert(vm != NULL);
1113
1114 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
1115 return NULL;
1116 return env;
1117}
1118
1119/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 * Makes the current thread visible to the VM.
1121 *
1122 * The JNIEnv pointer returned is only valid for the current thread, and
1123 * thus must be tucked into thread-local storage.
1124 */
1125static int javaAttachThread(const char* threadName, JNIEnv** pEnv)
1126{
1127 JavaVMAttachArgs args;
1128 JavaVM* vm;
1129 jint result;
1130
1131 vm = AndroidRuntime::getJavaVM();
1132 assert(vm != NULL);
1133
1134 args.version = JNI_VERSION_1_4;
1135 args.name = (char*) threadName;
1136 args.group = NULL;
1137
1138 result = vm->AttachCurrentThread(pEnv, (void*) &args);
1139 if (result != JNI_OK)
Steve Block6215d3f2012-01-04 20:05:49 +00001140 ALOGI("NOTE: attach of thread '%s' failed\n", threadName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141
1142 return result;
1143}
1144
1145/*
1146 * Detach the current thread from the set visible to the VM.
1147 */
1148static int javaDetachThread(void)
1149{
1150 JavaVM* vm;
1151 jint result;
1152
1153 vm = AndroidRuntime::getJavaVM();
1154 assert(vm != NULL);
1155
1156 result = vm->DetachCurrentThread();
1157 if (result != JNI_OK)
Steve Block3762c312012-01-06 19:20:56 +00001158 ALOGE("ERROR: thread detach failed\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 return result;
1160}
1161
1162/*
1163 * When starting a native thread that will be visible from the VM, we
1164 * bounce through this to get the right attach/detach action.
1165 * Note that this function calls free(args)
1166 */
1167/*static*/ int AndroidRuntime::javaThreadShell(void* args) {
1168 void* start = ((void**)args)[0];
1169 void* userData = ((void **)args)[1];
1170 char* name = (char*) ((void **)args)[2]; // we own this storage
1171 free(args);
1172 JNIEnv* env;
1173 int result;
1174
1175 /* hook us into the VM */
1176 if (javaAttachThread(name, &env) != JNI_OK)
1177 return -1;
1178
1179 /* start the thread running */
1180 result = (*(android_thread_func_t)start)(userData);
1181
1182 /* unhook us */
1183 javaDetachThread();
1184 free(name);
1185
1186 return result;
1187}
1188
1189/*
1190 * This is invoked from androidCreateThreadEtc() via the callback
1191 * set with androidSetCreateThreadFunc().
1192 *
1193 * We need to create the new thread in such a way that it gets hooked
1194 * into the VM before it really starts executing.
1195 */
1196/*static*/ int AndroidRuntime::javaCreateThreadEtc(
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001197 android_thread_func_t entryFunction,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001198 void* userData,
1199 const char* threadName,
1200 int32_t threadPriority,
1201 size_t threadStackSize,
1202 android_thread_id_t* threadId)
1203{
1204 void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free
1205 int result;
1206
Brian Carlstrom66f48312016-03-12 16:07:48 -08001207 LOG_ALWAYS_FATAL_IF(threadName == nullptr, "threadName not provided to javaCreateThreadEtc");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208
1209 args[0] = (void*) entryFunction;
1210 args[1] = userData;
1211 args[2] = (void*) strdup(threadName); // javaThreadShell must free
1212
1213 result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args,
1214 threadName, threadPriority, threadStackSize, threadId);
1215 return result;
1216}
1217
1218/*
1219 * Create a thread that is visible from the VM.
1220 *
1221 * This is called from elsewhere in the library.
1222 */
Mike Lockwoodf602d362010-06-20 14:28:16 -07001223/*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 void (*start)(void *), void* arg)
1225{
Mike Lockwoodf602d362010-06-20 14:28:16 -07001226 android_thread_id_t threadId = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001227 javaCreateThreadEtc((android_thread_func_t) start, arg, name,
Mike Lockwoodf602d362010-06-20 14:28:16 -07001228 ANDROID_PRIORITY_DEFAULT, 0, &threadId);
1229 return threadId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001230}
1231
1232#if 0
1233static void quickTest(void* arg)
1234{
1235 const char* str = (const char*) arg;
1236
1237 printf("In quickTest: %s\n", str);
1238}
1239#endif
1240
1241#ifdef NDEBUG
1242 #define REG_JNI(name) { name }
1243 struct RegJNIRec {
1244 int (*mProc)(JNIEnv*);
1245 };
1246#else
1247 #define REG_JNI(name) { name, #name }
1248 struct RegJNIRec {
1249 int (*mProc)(JNIEnv*);
1250 const char* mName;
1251 };
1252#endif
1253
1254typedef void (*RegJAMProc)();
1255
1256static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env)
1257{
1258 for (size_t i = 0; i < count; i++) {
1259 if (array[i].mProc(env) < 0) {
1260#ifndef NDEBUG
Steve Block5baa3a62011-12-20 16:23:08 +00001261 ALOGD("----------!!! %s failed to load\n", array[i].mName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001262#endif
1263 return -1;
1264 }
1265 }
1266 return 0;
1267}
1268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269static const RegJNIRec gRegJNI[] = {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001270 REG_JNI(register_com_android_internal_os_RuntimeInit),
1271 REG_JNI(register_android_os_SystemClock),
1272 REG_JNI(register_android_util_EventLog),
1273 REG_JNI(register_android_util_Log),
Svet Ganov53a441c2016-04-19 19:38:00 -07001274 REG_JNI(register_android_util_MemoryIntArray),
Doris Liucdd23f92015-11-11 14:31:13 -08001275 REG_JNI(register_android_util_PathParser),
Michal Karpinski6235a942016-03-15 12:07:23 +00001276 REG_JNI(register_android_app_admin_SecurityLog),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 REG_JNI(register_android_content_AssetManager),
1278 REG_JNI(register_android_content_StringBlock),
1279 REG_JNI(register_android_content_XmlBlock),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001280 REG_JNI(register_android_text_AndroidCharacter),
Anish Athalye88b5b0b2014-06-24 14:39:43 -07001281 REG_JNI(register_android_text_StaticLayout),
Doug Feltdae8e942010-02-24 14:33:15 -08001282 REG_JNI(register_android_text_AndroidBidi),
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001283 REG_JNI(register_android_view_InputDevice),
1284 REG_JNI(register_android_view_KeyCharacterMap),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285 REG_JNI(register_android_os_Process),
Andreas Hubera8079bf2010-11-16 14:40:31 -08001286 REG_JNI(register_android_os_SystemProperties),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 REG_JNI(register_android_os_Binder),
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -08001288 REG_JNI(register_android_os_Parcel),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001289 REG_JNI(register_android_nio_utils),
Richard Uhler775873a2015-12-29 12:37:39 -08001290 REG_JNI(register_android_graphics_Canvas),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001291 REG_JNI(register_android_graphics_Graphics),
Chris Craik54389792013-12-20 13:28:11 -08001292 REG_JNI(register_android_view_DisplayEventReceiver),
John Reckf666ad72014-03-14 16:24:57 -07001293 REG_JNI(register_android_view_RenderNode),
John Recke45b1fd2014-04-15 09:50:16 -07001294 REG_JNI(register_android_view_RenderNodeAnimator),
Romain Guy3b748a42013-04-17 18:54:38 -07001295 REG_JNI(register_android_view_GraphicBuffer),
Chris Craikc9070eb2015-03-09 18:50:14 -07001296 REG_JNI(register_android_view_DisplayListCanvas),
John Reck04fc5832014-02-05 16:38:25 -08001297 REG_JNI(register_android_view_HardwareLayer),
John Reckcec24ae2013-11-05 13:27:50 -08001298 REG_JNI(register_android_view_ThreadedRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001299 REG_JNI(register_android_view_Surface),
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001300 REG_JNI(register_android_view_SurfaceControl),
Jeff Brown64a55af2012-08-26 02:47:39 -07001301 REG_JNI(register_android_view_SurfaceSession),
Romain Guy8f0095c2011-05-02 17:24:22 -07001302 REG_JNI(register_android_view_TextureView),
John Reck315c3292014-05-09 19:21:04 -07001303 REG_JNI(register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001304 REG_JNI(register_com_google_android_gles_jni_EGLImpl),
1305 REG_JNI(register_com_google_android_gles_jni_GLImpl),
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001306 REG_JNI(register_android_opengl_jni_EGL14),
Jesse Hall237c2b82013-05-06 11:36:57 -07001307 REG_JNI(register_android_opengl_jni_EGLExt),
Jack Palevich1c4907e2009-04-13 16:22:25 -07001308 REG_JNI(register_android_opengl_jni_GLES10),
1309 REG_JNI(register_android_opengl_jni_GLES10Ext),
1310 REG_JNI(register_android_opengl_jni_GLES11),
1311 REG_JNI(register_android_opengl_jni_GLES11Ext),
Jack Palevich560814f2009-11-19 16:34:55 +08001312 REG_JNI(register_android_opengl_jni_GLES20),
Jesse Halld877efe2013-04-29 15:59:35 -07001313 REG_JNI(register_android_opengl_jni_GLES30),
Jesse Hall7ab63ac2014-05-19 15:13:41 -07001314 REG_JNI(register_android_opengl_jni_GLES31),
1315 REG_JNI(register_android_opengl_jni_GLES31Ext),
Pablo Ceballos38c1a7e2015-10-30 10:34:30 -07001316 REG_JNI(register_android_opengl_jni_GLES32),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001317
1318 REG_JNI(register_android_graphics_Bitmap),
1319 REG_JNI(register_android_graphics_BitmapFactory),
Wei-Ta Chen6b849e22010-09-07 17:32:18 +08001320 REG_JNI(register_android_graphics_BitmapRegionDecoder),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001321 REG_JNI(register_android_graphics_Camera),
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -04001322 REG_JNI(register_android_graphics_CreateJavaOutputStreamAdaptor),
John Reck52244ff2014-05-01 21:27:37 -07001323 REG_JNI(register_android_graphics_CanvasProperty),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001324 REG_JNI(register_android_graphics_ColorFilter),
1325 REG_JNI(register_android_graphics_DrawFilter),
Raph Levien1a73f7322014-01-30 16:06:28 -08001326 REG_JNI(register_android_graphics_FontFamily),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001327 REG_JNI(register_android_graphics_Interpolator),
1328 REG_JNI(register_android_graphics_LayerRasterizer),
1329 REG_JNI(register_android_graphics_MaskFilter),
1330 REG_JNI(register_android_graphics_Matrix),
1331 REG_JNI(register_android_graphics_Movie),
1332 REG_JNI(register_android_graphics_NinePatch),
1333 REG_JNI(register_android_graphics_Paint),
1334 REG_JNI(register_android_graphics_Path),
1335 REG_JNI(register_android_graphics_PathMeasure),
1336 REG_JNI(register_android_graphics_PathEffect),
1337 REG_JNI(register_android_graphics_Picture),
1338 REG_JNI(register_android_graphics_PorterDuff),
1339 REG_JNI(register_android_graphics_Rasterizer),
1340 REG_JNI(register_android_graphics_Region),
1341 REG_JNI(register_android_graphics_Shader),
Jamie Gennisaa0ce332011-01-06 17:04:26 -08001342 REG_JNI(register_android_graphics_SurfaceTexture),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001343 REG_JNI(register_android_graphics_Typeface),
1344 REG_JNI(register_android_graphics_Xfermode),
Wei-Ta Chenbca2d612009-11-30 17:52:05 +08001345 REG_JNI(register_android_graphics_YuvImage),
Doris Liu766431a2016-02-04 22:17:11 +00001346 REG_JNI(register_android_graphics_drawable_AnimatedVectorDrawable),
Doris Liu4bbc2932015-12-01 17:59:40 -08001347 REG_JNI(register_android_graphics_drawable_VectorDrawable),
Svetoslav6811f4e2013-09-18 15:58:28 -07001348 REG_JNI(register_android_graphics_pdf_PdfDocument),
Svetoslav62ce3322014-09-04 21:17:17 -07001349 REG_JNI(register_android_graphics_pdf_PdfEditor),
Svetoslav29617692014-04-24 18:40:42 -07001350 REG_JNI(register_android_graphics_pdf_PdfRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351
1352 REG_JNI(register_android_database_CursorWindow),
Jeff Browne5360fb2011-10-31 17:48:13 -07001353 REG_JNI(register_android_database_SQLiteConnection),
1354 REG_JNI(register_android_database_SQLiteGlobal),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001355 REG_JNI(register_android_database_SQLiteDebug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356 REG_JNI(register_android_os_Debug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001357 REG_JNI(register_android_os_FileObserver),
Christopher Tatefa9e7c02010-05-06 12:07:10 -07001358 REG_JNI(register_android_os_MessageQueue),
Stephen Smalleyc07fca32012-01-13 08:31:39 -05001359 REG_JNI(register_android_os_SELinux),
Jeff Brown481c1572012-03-09 14:41:15 -08001360 REG_JNI(register_android_os_Trace),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001361 REG_JNI(register_android_os_UEventObserver),
1362 REG_JNI(register_android_net_LocalSocketImpl),
1363 REG_JNI(register_android_net_NetworkUtils),
Dan Egnor2b4abcd2010-04-07 17:30:50 -07001364 REG_JNI(register_android_net_TrafficStats),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001365 REG_JNI(register_android_os_MemoryFile),
Dimitry Ivanov5d7d7772016-04-20 14:09:32 -07001366 REG_JNI(register_com_android_internal_os_PathClassLoaderFactory),
Narayan Kamath973b4662014-03-31 13:41:26 +01001367 REG_JNI(register_com_android_internal_os_Zygote),
John Reck9fa40712014-05-09 15:26:59 -07001368 REG_JNI(register_com_android_internal_util_VirtualRefBasePtr),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001369 REG_JNI(register_android_hardware_Camera),
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07001370 REG_JNI(register_android_hardware_camera2_CameraMetadata),
Ruben Brunkfeb50af2014-05-09 19:58:49 -07001371 REG_JNI(register_android_hardware_camera2_legacy_LegacyCameraDevice),
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -07001372 REG_JNI(register_android_hardware_camera2_legacy_PerfMeasurement),
Ruben Brunkb6079002014-05-22 12:33:54 -07001373 REG_JNI(register_android_hardware_camera2_DngCreator),
Eric Laurent633cb562015-03-05 15:17:20 -08001374 REG_JNI(register_android_hardware_Radio),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001375 REG_JNI(register_android_hardware_SensorManager),
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04001376 REG_JNI(register_android_hardware_SerialPort),
Eric Laurent60b62bc2014-04-18 17:50:49 -07001377 REG_JNI(register_android_hardware_SoundTrigger),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001378 REG_JNI(register_android_hardware_UsbDevice),
Mike Lockwoodacc29cc2011-03-11 08:18:08 -05001379 REG_JNI(register_android_hardware_UsbDeviceConnection),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001380 REG_JNI(register_android_hardware_UsbRequest),
destradaaa4fa3b52014-07-09 10:46:39 -07001381 REG_JNI(register_android_hardware_location_ActivityRecognitionHardware),
Peng Xu9ff7d222016-02-11 13:02:05 -08001382 REG_JNI(register_android_hardware_location_ContextHubService),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001383 REG_JNI(register_android_media_AudioRecord),
1384 REG_JNI(register_android_media_AudioSystem),
1385 REG_JNI(register_android_media_AudioTrack),
1386 REG_JNI(register_android_media_JetPlayer),
Jeff Browncbad9762012-09-04 21:57:59 -07001387 REG_JNI(register_android_media_RemoteDisplay),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001388 REG_JNI(register_android_media_ToneGenerator),
1389
1390 REG_JNI(register_android_opengl_classes),
JP Abgrall98a4f7e2011-09-02 15:36:33 -07001391 REG_JNI(register_android_server_NetworkManagementSocketTagger),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001392 REG_JNI(register_android_ddm_DdmHandleNativeHeap),
Joe Onorato1cf58742009-06-12 11:06:24 -07001393 REG_JNI(register_android_backup_BackupDataInput),
Joe Onoratod2110db2009-05-19 13:41:21 -07001394 REG_JNI(register_android_backup_BackupDataOutput),
Joe Onorato06290a42009-06-18 20:10:37 -07001395 REG_JNI(register_android_backup_FileBackupHelperBase),
Joe Onorato4ababd92009-06-25 18:29:18 -04001396 REG_JNI(register_android_backup_BackupHelperDispatcher),
Christopher Tate4a627c72011-04-01 14:43:32 -07001397 REG_JNI(register_android_app_backup_FullBackup),
Dimitry Ivanov4449ef52016-02-25 17:41:13 -08001398 REG_JNI(register_android_app_Activity),
Chet Haase9c1e23b2011-03-24 10:51:31 -07001399 REG_JNI(register_android_app_ActivityThread),
Dimitry Ivanov09979082016-04-19 11:11:01 -07001400 REG_JNI(register_android_app_ApplicationLoaders),
Dianne Hackborn69969e42010-05-04 11:40:40 -07001401 REG_JNI(register_android_app_NativeActivity),
Przemyslaw Szczepaniak8a7c1602015-11-03 09:47:56 +00001402 REG_JNI(register_android_util_jar_StrictJarFile),
Jeff Brown46b9ac02010-04-22 18:58:52 -07001403 REG_JNI(register_android_view_InputChannel),
Jeff Brown32cbc38552011-12-01 14:01:49 -08001404 REG_JNI(register_android_view_InputEventReceiver),
Jeff Brownc28867a2013-03-26 15:42:39 -07001405 REG_JNI(register_android_view_InputEventSender),
Michael Wrighta44dd262013-04-10 21:12:00 -07001406 REG_JNI(register_android_view_InputQueue),
Jeff Brown46b9ac02010-04-22 18:58:52 -07001407 REG_JNI(register_android_view_KeyEvent),
1408 REG_JNI(register_android_view_MotionEvent),
Jeff Brown2352b972011-04-12 22:39:53 -07001409 REG_JNI(register_android_view_PointerIcon),
Jeff Brown2ed24622011-03-14 19:39:54 -07001410 REG_JNI(register_android_view_VelocityTracker),
Kenny Root02c87302010-07-01 08:10:18 -07001411
1412 REG_JNI(register_android_content_res_ObbScanner),
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -07001413 REG_JNI(register_android_content_res_Configuration),
Chet Haase6e0ecb42010-11-03 19:41:18 -07001414
1415 REG_JNI(register_android_animation_PropertyValuesHolder),
Kenny Root66269ea2011-07-12 14:14:01 -07001416 REG_JNI(register_com_android_internal_content_NativeLibraryHelper),
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -08001417 REG_JNI(register_com_android_internal_net_NetworkStatsFactory),
Przemyslaw Szczepaniak8a7c1602015-11-03 09:47:56 +00001418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001419};
1420
1421/*
1422 * Register android native functions with the VM.
1423 */
1424/*static*/ int AndroidRuntime::startReg(JNIEnv* env)
1425{
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001426 ATRACE_NAME("RegisterAndroidNatives");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 /*
1428 * This hook causes all future threads created in this process to be
1429 * attached to the JavaVM. (This needs to go away in favor of JNI
1430 * Attach calls.)
1431 */
1432 androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc);
1433
Steve Block71f2cf12011-10-20 11:56:00 +01001434 ALOGV("--- registering native functions ---\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435
1436 /*
1437 * Every "register" function calls one or more things that return
1438 * a local reference (e.g. FindClass). Because we haven't really
1439 * started the VM yet, they're all getting stored in the base frame
1440 * and never released. Use Push/Pop to manage the storage.
1441 */
1442 env->PushLocalFrame(200);
1443
1444 if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) {
1445 env->PopLocalFrame(NULL);
1446 return -1;
1447 }
1448 env->PopLocalFrame(NULL);
1449
1450 //createJavaThread("fubar", quickTest, (void*) "hello");
1451
1452 return 0;
1453}
1454
1455AndroidRuntime* AndroidRuntime::getRuntime()
1456{
1457 return gCurRuntime;
1458}
1459
1460/**
Narayan Kamathc21dab92015-06-25 14:22:00 +01001461 * Used by surface flinger's DdmConnection to register native methods from
1462 * the framework.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 */
Narayan Kamathc21dab92015-06-25 14:22:00 +01001464extern "C" jint registerFrameworkNatives(JNIEnv* env) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001465 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1466}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001467} // namespace android