blob: 815d3302ee0b42b29239262443848f2e30701ea3 [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>
33#include <SkImageDecoder.h>
34
35#include "jni.h"
36#include "JNIHelp.h"
Brian Carlstrom9f8203a2013-06-19 13:49:36 -070037#include "JniInvocation.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038#include "android_util_Binder.h"
39
40#include <stdio.h>
41#include <signal.h>
42#include <sys/stat.h>
43#include <sys/types.h>
44#include <signal.h>
45#include <dirent.h>
46#include <assert.h>
47
Narayan Kamathbf882052015-08-11 15:40:34 +010048#include <string>
49#include <vector>
50
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051
52using namespace android;
53
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054extern int register_android_os_Binder(JNIEnv* env);
55extern int register_android_os_Process(JNIEnv* env);
56extern int register_android_graphics_Bitmap(JNIEnv*);
57extern int register_android_graphics_BitmapFactory(JNIEnv*);
Wei-Ta Chen6b849e22010-09-07 17:32:18 +080058extern int register_android_graphics_BitmapRegionDecoder(JNIEnv*);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059extern int register_android_graphics_Camera(JNIEnv* env);
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -040060extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061extern int register_android_graphics_Graphics(JNIEnv* env);
62extern int register_android_graphics_Interpolator(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063extern int register_android_graphics_MaskFilter(JNIEnv* env);
64extern int register_android_graphics_Movie(JNIEnv* env);
65extern int register_android_graphics_NinePatch(JNIEnv*);
66extern int register_android_graphics_PathEffect(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067extern int register_android_graphics_Shader(JNIEnv* env);
68extern int register_android_graphics_Typeface(JNIEnv* env);
Wei-Ta Chenbca2d612009-11-30 17:52:05 +080069extern int register_android_graphics_YuvImage(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070
71extern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env);
72extern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070073extern int register_android_opengl_jni_EGL14(JNIEnv* env);
Jesse Hall237c2b82013-05-06 11:36:57 -070074extern int register_android_opengl_jni_EGLExt(JNIEnv* env);
Jack Palevich1c4907e2009-04-13 16:22:25 -070075extern int register_android_opengl_jni_GLES10(JNIEnv* env);
76extern int register_android_opengl_jni_GLES10Ext(JNIEnv* env);
77extern int register_android_opengl_jni_GLES11(JNIEnv* env);
78extern int register_android_opengl_jni_GLES11Ext(JNIEnv* env);
Jack Palevich560814f2009-11-19 16:34:55 +080079extern int register_android_opengl_jni_GLES20(JNIEnv* env);
Jesse Halld877efe2013-04-29 15:59:35 -070080extern int register_android_opengl_jni_GLES30(JNIEnv* env);
Jesse Hall7ab63ac2014-05-19 15:13:41 -070081extern int register_android_opengl_jni_GLES31(JNIEnv* env);
82extern int register_android_opengl_jni_GLES31Ext(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);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097
98extern int register_android_media_AudioRecord(JNIEnv *env);
99extern int register_android_media_AudioSystem(JNIEnv *env);
100extern int register_android_media_AudioTrack(JNIEnv *env);
101extern int register_android_media_JetPlayer(JNIEnv *env);
102extern int register_android_media_ToneGenerator(JNIEnv *env);
103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104namespace android {
105
106/*
107 * JNI-based registration functions. Note these are properly contained in
108 * namespace android.
109 */
110extern int register_android_content_AssetManager(JNIEnv* env);
111extern int register_android_util_EventLog(JNIEnv* env);
112extern int register_android_util_Log(JNIEnv* env);
Doris Liucdd23f92015-11-11 14:31:13 -0800113extern int register_android_util_PathParser(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114extern int register_android_content_StringBlock(JNIEnv* env);
115extern int register_android_content_XmlBlock(JNIEnv* env);
116extern int register_android_graphics_Canvas(JNIEnv* env);
John Reck52244ff2014-05-01 21:27:37 -0700117extern int register_android_graphics_CanvasProperty(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118extern int register_android_graphics_ColorFilter(JNIEnv* env);
119extern int register_android_graphics_DrawFilter(JNIEnv* env);
Raph Levien1a73f7322014-01-30 16:06:28 -0800120extern int register_android_graphics_FontFamily(JNIEnv* env);
Mike Reed4c9355c2014-05-07 11:48:37 -0400121extern int register_android_graphics_LayerRasterizer(JNIEnv*);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122extern int register_android_graphics_Matrix(JNIEnv* env);
123extern int register_android_graphics_Paint(JNIEnv* env);
124extern int register_android_graphics_Path(JNIEnv* env);
125extern int register_android_graphics_PathMeasure(JNIEnv* env);
126extern int register_android_graphics_Picture(JNIEnv*);
127extern int register_android_graphics_PorterDuff(JNIEnv* env);
128extern int register_android_graphics_Rasterizer(JNIEnv* env);
Jeff Brownfbf09772011-01-16 14:06:57 -0800129extern int register_android_graphics_Region(JNIEnv* env);
Jamie Gennisaa0ce332011-01-06 17:04:26 -0800130extern int register_android_graphics_SurfaceTexture(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131extern int register_android_graphics_Xfermode(JNIEnv* env);
Svetoslav6811f4e2013-09-18 15:58:28 -0700132extern int register_android_graphics_pdf_PdfDocument(JNIEnv* env);
Svetoslav62ce3322014-09-04 21:17:17 -0700133extern int register_android_graphics_pdf_PdfEditor(JNIEnv* env);
Svetoslav29617692014-04-24 18:40:42 -0700134extern int register_android_graphics_pdf_PdfRenderer(JNIEnv* env);
Jeff Brown0a0a1242011-12-02 02:25:22 -0800135extern int register_android_view_DisplayEventReceiver(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700136extern int register_android_view_DisplayListCanvas(JNIEnv* env);
137extern int register_android_view_GraphicBuffer(JNIEnv* env);
138extern int register_android_view_HardwareLayer(JNIEnv* env);
John Reckf666ad72014-03-14 16:24:57 -0700139extern int register_android_view_RenderNode(JNIEnv* env);
John Recke45b1fd2014-04-15 09:50:16 -0700140extern int register_android_view_RenderNodeAnimator(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141extern int register_android_view_Surface(JNIEnv* env);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800142extern int register_android_view_SurfaceControl(JNIEnv* env);
Jeff Brown64a55af2012-08-26 02:47:39 -0700143extern int register_android_view_SurfaceSession(JNIEnv* env);
Romain Guy8f0095c2011-05-02 17:24:22 -0700144extern int register_android_view_TextureView(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700145extern int register_android_view_ThreadedRenderer(JNIEnv* env);
John Reck315c3292014-05-09 19:21:04 -0700146extern int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147extern int register_android_database_CursorWindow(JNIEnv* env);
Jeff Browne5360fb2011-10-31 17:48:13 -0700148extern int register_android_database_SQLiteConnection(JNIEnv* env);
149extern int register_android_database_SQLiteGlobal(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150extern int register_android_database_SQLiteDebug(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151extern int register_android_nio_utils(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152extern int register_android_os_Debug(JNIEnv* env);
Christopher Tatefa9e7c02010-05-06 12:07:10 -0700153extern int register_android_os_MessageQueue(JNIEnv* env);
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -0800154extern int register_android_os_Parcel(JNIEnv* env);
Stephen Smalleyc07fca32012-01-13 08:31:39 -0500155extern int register_android_os_SELinux(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156extern int register_android_os_SystemProperties(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157extern int register_android_os_SystemClock(JNIEnv* env);
Jeff Brown481c1572012-03-09 14:41:15 -0800158extern int register_android_os_Trace(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159extern int register_android_os_FileObserver(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160extern int register_android_os_UEventObserver(JNIEnv* env);
161extern int register_android_os_MemoryFile(JNIEnv* env);
162extern int register_android_net_LocalSocketImpl(JNIEnv* env);
163extern int register_android_net_NetworkUtils(JNIEnv* env);
Dan Egnor2b4abcd2010-04-07 17:30:50 -0700164extern int register_android_net_TrafficStats(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165extern int register_android_text_AndroidCharacter(JNIEnv *env);
Anish Athalye88b5b0b2014-06-24 14:39:43 -0700166extern int register_android_text_StaticLayout(JNIEnv *env);
Doug Feltdae8e942010-02-24 14:33:15 -0800167extern int register_android_text_AndroidBidi(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168extern int register_android_opengl_classes(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
Narayan Kamath29564cd2014-08-07 10:57:40 +0100170extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env);
Joe Onorato1cf58742009-06-12 11:06:24 -0700171extern int register_android_backup_BackupDataInput(JNIEnv *env);
Joe Onoratod2110db2009-05-19 13:41:21 -0700172extern int register_android_backup_BackupDataOutput(JNIEnv *env);
Joe Onorato06290a42009-06-18 20:10:37 -0700173extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
Joe Onorato4ababd92009-06-25 18:29:18 -0400174extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
Christopher Tate4a627c72011-04-01 14:43:32 -0700175extern int register_android_app_backup_FullBackup(JNIEnv *env);
Chet Haase9c1e23b2011-03-24 10:51:31 -0700176extern int register_android_app_ActivityThread(JNIEnv *env);
Dianne Hackborn69969e42010-05-04 11:40:40 -0700177extern int register_android_app_NativeActivity(JNIEnv *env);
Jeff Browncbad9762012-09-04 21:57:59 -0700178extern int register_android_media_RemoteDisplay(JNIEnv *env);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700179extern int register_android_view_InputChannel(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700180extern int register_android_view_InputDevice(JNIEnv* env);
Jeff Brown32cbc38552011-12-01 14:01:49 -0800181extern int register_android_view_InputEventReceiver(JNIEnv* env);
Jeff Brownc28867a2013-03-26 15:42:39 -0700182extern int register_android_view_InputEventSender(JNIEnv* env);
Michael Wrighta44dd262013-04-10 21:12:00 -0700183extern int register_android_view_InputQueue(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700184extern int register_android_view_KeyCharacterMap(JNIEnv *env);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700185extern int register_android_view_KeyEvent(JNIEnv* env);
186extern int register_android_view_MotionEvent(JNIEnv* env);
Jeff Brown2352b972011-04-12 22:39:53 -0700187extern int register_android_view_PointerIcon(JNIEnv* env);
Jeff Brown2ed24622011-03-14 19:39:54 -0700188extern int register_android_view_VelocityTracker(JNIEnv* env);
Kenny Root02c87302010-07-01 08:10:18 -0700189extern int register_android_content_res_ObbScanner(JNIEnv* env);
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700190extern int register_android_content_res_Configuration(JNIEnv* env);
Chet Haase6e0ecb42010-11-03 19:41:18 -0700191extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
Kenny Root66269ea2011-07-12 14:14:01 -0700192extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -0800193extern int register_com_android_internal_net_NetworkStatsFactory(JNIEnv *env);
Narayan Kamath973b4662014-03-31 13:41:26 +0100194extern int register_com_android_internal_os_Zygote(JNIEnv *env);
John Reck9fa40712014-05-09 15:26:59 -0700195extern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196
197static AndroidRuntime* gCurRuntime = NULL;
198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199/*
200 * Code written in the Java Programming Language calls here from main().
201 */
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700202static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203{
204 gCurRuntime->onStarted();
205}
206
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700207static void com_android_internal_os_RuntimeInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208{
209 gCurRuntime->onZygoteInit();
210}
211
Jeff Brown4280c4a2012-03-15 17:48:02 -0700212static void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIEnv* env,
213 jobject clazz, jboolean exitWithoutCleanup)
214{
215 gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup);
216}
217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218/*
219 * JNI registration.
220 */
Daniel Micay76f6a862015-09-19 17:31:01 -0400221static const JNINativeMethod gMethods[] = {
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700222 { "nativeFinishInit", "()V",
223 (void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
224 { "nativeZygoteInit", "()V",
225 (void*) com_android_internal_os_RuntimeInit_nativeZygoteInit },
Jeff Brown4280c4a2012-03-15 17:48:02 -0700226 { "nativeSetExitWithoutCleanup", "(Z)V",
227 (void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228};
229
230int register_com_android_internal_os_RuntimeInit(JNIEnv* env)
231{
232 return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
233 gMethods, NELEM(gMethods));
234}
235
236// ----------------------------------------------------------------------
237
Andreas Huber9ae000c2014-02-13 17:22:33 +0000238/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
239
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000240AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) :
241 mExitWithoutCleanup(false),
242 mArgBlockStart(argBlockStart),
243 mArgBlockLength(argBlockLength)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700245 SkGraphics::Init();
Ben Wagner177612332015-01-15 14:16:46 -0500246 // There is also a global font cache, but its budget is specified by
247 // SK_DEFAULT_FONT_CACHE_COUNT_LIMIT and SK_DEFAULT_FONT_CACHE_LIMIT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248
249 // Pre-allocate enough space to hold a fair number of options.
250 mOptions.setCapacity(20);
251
252 assert(gCurRuntime == NULL); // one per process
253 gCurRuntime = this;
254}
255
256AndroidRuntime::~AndroidRuntime()
257{
258 SkGraphics::Term();
259}
260
Andreas Huber9ae000c2014-02-13 17:22:33 +0000261/*
262 * Register native methods using JNI.
263 */
264/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
265 const char* className, const JNINativeMethod* gMethods, int numMethods)
266{
267 return jniRegisterNativeMethods(env, className, gMethods, numMethods);
268}
269
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000270void AndroidRuntime::setArgv0(const char* argv0) {
Jeff Brown00c0cd42014-09-10 16:48:46 -0700271 memset(mArgBlockStart, 0, mArgBlockLength);
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000272 strlcpy(mArgBlockStart, argv0, mArgBlockLength);
273}
274
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100275status_t AndroidRuntime::callMain(const String8& className, jclass clazz,
276 const Vector<String8>& args)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277{
278 JNIEnv* env;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 jmethodID methodId;
280
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100281 ALOGD("Calling main entry %s", className.string());
Dianne Hackborn08e60f22010-09-01 18:17:17 -0700282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 env = getJNIEnv();
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700284 if (clazz == NULL || env == NULL) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 return UNKNOWN_ERROR;
286 }
287
288 methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
289 if (methodId == NULL) {
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100290 ALOGE("ERROR: could not find method %s.main(String[])\n", className.string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291 return UNKNOWN_ERROR;
292 }
293
294 /*
295 * We want to call main() with a String array with our arguments in it.
296 * Create an array and populate it.
297 */
298 jclass stringClass;
299 jobjectArray strArray;
300
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100301 const size_t numArgs = args.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 stringClass = env->FindClass("java/lang/String");
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100303 strArray = env->NewObjectArray(numArgs, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100305 for (size_t i = 0; i < numArgs; i++) {
306 jstring argStr = env->NewStringUTF(args[i].string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 env->SetObjectArrayElement(strArray, i, argStr);
308 }
309
310 env->CallStaticVoidMethod(clazz, methodId, strArray);
311 return NO_ERROR;
312}
313
314/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 * The VM calls this through the "exit" hook.
316 */
317static void runtime_exit(int code)
318{
Jeff Brown4280c4a2012-03-15 17:48:02 -0700319 gCurRuntime->exit(code);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320}
321
322/*
323 * The VM calls this through the "vfprintf" hook.
324 *
325 * We ignore "fp" and just write the results to the log file.
326 */
327static void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
328{
329 LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
330}
331
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800332/**
333 * The VM calls this when mutex contention debugging is enabled to
334 * determine whether or not the blocked thread was a "sensitive thread"
335 * for user responsiveness/smoothess.
336 *
337 * Our policy for this is whether or not we're tracing any StrictMode
338 * events on this thread (which we might've inherited via Binder calls
339 * into us)
340 */
341static bool runtime_isSensitiveThread() {
342 IPCThreadState* state = IPCThreadState::selfOrNull();
343 return state && state->getStrictModePolicy() != 0;
344}
345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346static int hasDir(const char* dir)
347{
348 struct stat s;
349 int res = stat(dir, &s);
350 if (res == 0) {
351 return S_ISDIR(s.st_mode);
352 }
353 return 0;
354}
355
Andreas Gampe995c62d2014-11-14 16:15:17 -0800356static bool hasFile(const char* file) {
357 struct stat s;
358 int res = stat(file, &s);
359 if (res == 0) {
360 return S_ISREG(s.st_mode);
361 }
362 return false;
363}
364
Narayan Kamathbf882052015-08-11 15:40:34 +0100365// Convenience wrapper over the property API that returns an
366// std::string.
367std::string getProperty(const char* key, const char* defaultValue) {
368 std::vector<char> temp(PROPERTY_VALUE_MAX);
369 const int len = property_get(key, &temp[0], defaultValue);
370 if (len < 0) {
371 return "";
372 }
373 return std::string(&temp[0], len);
374}
375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376/*
Narayan Kamathbf882052015-08-11 15:40:34 +0100377 * Read the persistent locale. Inspects the following system properties
378 * (in order) and returns the first non-empty property in the list :
379 *
380 * (1) persist.sys.locale
381 * (2) persist.sys.language/country/localevar (country and localevar are
382 * inspected iff. language is non-empty.
383 * (3) ro.product.locale
384 * (4) ro.product.locale.language/region
385 *
386 * Note that we need to inspect persist.sys.language/country/localevar to
387 * preserve language settings for devices that are upgrading from Lollipop
388 * to M. The same goes for ro.product.locale.language/region as well.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 */
Narayan Kamathbf882052015-08-11 15:40:34 +0100390const std::string readLocale()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391{
Narayan Kamathbf882052015-08-11 15:40:34 +0100392 const std::string locale = getProperty("persist.sys.locale", "");
393 if (!locale.empty()) {
394 return locale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 }
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000396
Narayan Kamathbf882052015-08-11 15:40:34 +0100397 const std::string language = getProperty("persist.sys.language", "");
398 if (!language.empty()) {
399 const std::string country = getProperty("persist.sys.country", "");
400 const std::string variant = getProperty("persist.sys.localevar", "");
401
402 std::string out = language;
403 if (!country.empty()) {
404 out = out + "-" + country;
405 }
406
407 if (!variant.empty()) {
408 out = out + "-" + variant;
409 }
410
411 return out;
412 }
413
414 const std::string productLocale = getProperty("ro.product.locale", "");
415 if (!productLocale.empty()) {
416 return productLocale;
417 }
418
419 // If persist.sys.locale and ro.product.locale are missing,
420 // construct a locale value from the individual locale components.
421 const std::string productLanguage = getProperty("ro.product.locale.language", "en");
422 const std::string productRegion = getProperty("ro.product.locale.region", "US");
423
424 return productLanguage + "-" + productRegion;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425}
426
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700427void AndroidRuntime::addOption(const char* optionString, void* extraInfo)
428{
429 JavaVMOption opt;
430 opt.optionString = optionString;
431 opt.extraInfo = extraInfo;
432 mOptions.add(opt);
433}
434
Andy McFaddenf70188a2009-03-31 15:52:13 -0700435/*
Andy McFaddene4d81f22010-07-14 16:02:20 -0700436 * Parse a property containing space-separated options that should be
437 * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
438 *
439 * This will cut up "extraOptsBuf" as we chop it into individual options.
440 *
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800441 * If "quotingArg" is non-null, it is passed before each extra option in mOptions.
442 *
Andy McFaddene4d81f22010-07-14 16:02:20 -0700443 * Adds the strings, if any, to mOptions.
444 */
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800445void AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg)
Andy McFaddene4d81f22010-07-14 16:02:20 -0700446{
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800447 char* start = extraOptsBuf;
448 char* end = NULL;
Andy McFaddene4d81f22010-07-14 16:02:20 -0700449 while (*start != '\0') {
450 while (*start == ' ') /* skip leading whitespace */
451 start++;
452 if (*start == '\0') /* was trailing ws, bail */
453 break;
454
455 end = start+1;
456 while (*end != ' ' && *end != '\0') /* find end of token */
457 end++;
458 if (*end == ' ')
459 *end++ = '\0'; /* mark end, advance to indicate more */
460
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800461 if (quotingArg != NULL) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700462 addOption(quotingArg);
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800463 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700464 addOption(start);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700465 start = end;
466 }
467}
468
469/*
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700470 * Reads a "property" into "buffer" with a default of "defaultArg". If
471 * the property is non-empty, it is treated as a runtime option such
472 * as "-Xmx32m".
473 *
474 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
475 *
476 * If an argument is found, it is added to mOptions.
477 *
478 * If an option is found, it is added to mOptions and true is
479 * returned. Otherwise false is returned.
480 */
481bool AndroidRuntime::parseRuntimeOption(const char* property,
482 char* buffer,
483 const char* runtimeArg,
484 const char* defaultArg)
485{
486 strcpy(buffer, runtimeArg);
487 size_t runtimeArgLen = strlen(runtimeArg);
488 property_get(property, buffer+runtimeArgLen, defaultArg);
489 if (buffer[runtimeArgLen] == '\0') {
490 return false;
491 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700492 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700493 return true;
494}
495
496/*
497 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700498 * is treated as a dex2oat compiler option that should be
499 * passed as a quoted option, e.g. "-Ximage-compiler-option --compiler-filter=verify-none".
500 *
501 * The "compilerArg" is a prefix for the option such as "--compiler-filter=".
502 *
503 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
504 *
505 * If an option is found, it is added to mOptions and true is
506 * returned. Otherwise false is returned.
507 */
508bool AndroidRuntime::parseCompilerOption(const char* property,
509 char* buffer,
510 const char* compilerArg,
511 const char* quotingArg)
512{
513 strcpy(buffer, compilerArg);
514 size_t compilerArgLen = strlen(compilerArg);
515 property_get(property, buffer+compilerArgLen, "");
516 if (buffer[compilerArgLen] == '\0') {
517 return false;
518 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700519 addOption(quotingArg);
520 addOption(buffer);
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700521 return true;
522}
523
524/*
525 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700526 * is treated as a dex2oat compiler runtime option that should be
527 * passed as a quoted option, e.g. "-Ximage-compiler-option
528 * --runtime-arg -Ximage-compiler-option -Xmx32m".
529 *
530 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
531 *
532 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
533 *
534 * If an option is found, it is added to mOptions and true is
535 * returned. Otherwise false is returned.
536 */
537bool AndroidRuntime::parseCompilerRuntimeOption(const char* property,
538 char* buffer,
539 const char* runtimeArg,
540 const char* quotingArg)
541{
542 strcpy(buffer, runtimeArg);
543 size_t runtimeArgLen = strlen(runtimeArg);
544 property_get(property, buffer+runtimeArgLen, "");
545 if (buffer[runtimeArgLen] == '\0') {
546 return false;
547 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700548 addOption(quotingArg);
549 addOption("--runtime-arg");
550 addOption(quotingArg);
551 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700552 return true;
553}
554
555/*
Andy McFaddenf70188a2009-03-31 15:52:13 -0700556 * Start the Dalvik Virtual Machine.
557 *
558 * Various arguments, most determined by system properties, are passed in.
559 * The "mOptions" vector is updated.
560 *
Dave Allison07a1e232014-03-14 08:54:33 -0700561 * CAUTION: when adding options in here, be careful not to put the
562 * char buffer inside a nested scope. Adding the buffer to the
563 * options using mOptions.add() does not copy the buffer, so if the
564 * buffer goes out of scope the option may be overwritten. It's best
565 * to put the buffer at the top of the function so that it is more
566 * unlikely that someone will surround it in a scope at a later time
567 * and thus introduce a bug.
568 *
Andy McFaddenf70188a2009-03-31 15:52:13 -0700569 * Returns 0 on success.
570 */
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200571int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573 JavaVMInitArgs initArgs;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 char propBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700575 char stackTraceFileBuf[sizeof("-Xstacktracefile:")-1 + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro38cfa8c2010-12-07 16:48:29 -0800577 char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700578 char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro8cdf27c32011-01-19 12:33:12 -0800579 char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700580 char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
581 char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800582 char usejitOptsBuf[sizeof("-Xusejit:")-1 + PROPERTY_VALUE_MAX];
583 char jitcodecachesizeOptsBuf[sizeof("-Xjitcodecachesize:")-1 + PROPERTY_VALUE_MAX];
584 char jitthresholdOptsBuf[sizeof("-Xjitthreshold:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier7e4fdec2013-12-02 15:46:51 -0800585 char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700586 char backgroundgcOptsBuf[sizeof("-XX:BackgroundGC=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700587 char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee324ba02015-03-31 16:15:17 -0700588 char cachePruneBuf[sizeof("-Xzygote-max-boot-retry=")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700589 char dex2oatXmsImageFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
590 char dex2oatXmxImageFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
591 char dex2oatXmsFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
592 char dex2oatXmxFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700593 char dex2oatCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
594 char dex2oatImageCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee0352382015-03-30 18:43:39 -0700595 char dex2oatThreadsBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
596 char dex2oatThreadsImageBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
Andreas Gampe605cca12015-04-02 23:12:56 -0700597 char dex2oat_isa_variant_key[PROPERTY_KEY_MAX];
598 char dex2oat_isa_variant[sizeof("--instruction-set-variant=") -1 + PROPERTY_VALUE_MAX];
599 char dex2oat_isa_features_key[PROPERTY_KEY_MAX];
600 char dex2oat_isa_features[sizeof("--instruction-set-features=") -1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800601 char dex2oatFlagsBuf[PROPERTY_VALUE_MAX];
602 char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX];
Andy McFaddene4d81f22010-07-14 16:02:20 -0700603 char extraOptsBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700604 char voldDecryptBuf[PROPERTY_VALUE_MAX];
Ben Cheng52b0e732009-06-19 13:31:12 -0700605 enum {
606 kEMDefault,
607 kEMIntPortable,
608 kEMIntFast,
Ben Cheng52b0e732009-06-19 13:31:12 -0700609 kEMJitCompiler,
Ben Cheng52b0e732009-06-19 13:31:12 -0700610 } executionMode = kEMDefault;
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700611 char profilePeriod[sizeof("-Xprofile-period:")-1 + PROPERTY_VALUE_MAX];
612 char profileDuration[sizeof("-Xprofile-duration:")-1 + PROPERTY_VALUE_MAX];
613 char profileInterval[sizeof("-Xprofile-interval:")-1 + PROPERTY_VALUE_MAX];
614 char profileBackoff[sizeof("-Xprofile-backoff:")-1 + PROPERTY_VALUE_MAX];
615 char profileTopKThreshold[sizeof("-Xprofile-top-k-threshold:")-1 + PROPERTY_VALUE_MAX];
616 char profileTopKChangeThreshold[sizeof("-Xprofile-top-k-change-threshold:")-1 +
617 PROPERTY_VALUE_MAX];
618 char profileType[sizeof("-Xprofile-type:")-1 + PROPERTY_VALUE_MAX];
619 char profileMaxStackDepth[sizeof("-Xprofile-max-stack-depth:")-1 + PROPERTY_VALUE_MAX];
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000620 char localeOption[sizeof("-Duser.locale=") + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700621 char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle01db9162014-08-07 14:45:53 +0100622 char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX];
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700623 char cpuAbiListBuf[sizeof("--cpu-abilist=") + PROPERTY_VALUE_MAX];
Andreas Gampe98f406f2015-06-22 21:09:36 -0700624 char methodTraceFileBuf[sizeof("-Xmethod-trace-file:") + PROPERTY_VALUE_MAX];
625 char methodTraceFileSizeBuf[sizeof("-Xmethod-trace-file-size:") + PROPERTY_VALUE_MAX];
Andreas Gampee6082502015-07-24 14:19:44 -0700626 char fingerprintBuf[sizeof("-Xfingerprint:") + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700628 bool checkJni = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 property_get("dalvik.vm.checkjni", propBuf, "");
630 if (strcmp(propBuf, "true") == 0) {
631 checkJni = true;
632 } else if (strcmp(propBuf, "false") != 0) {
633 /* property is neither true nor false; fall back on kernel parameter */
634 property_get("ro.kernel.android.checkjni", propBuf, "");
635 if (propBuf[0] == '1') {
636 checkJni = true;
637 }
638 }
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700639 ALOGD("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
640 if (checkJni) {
641 /* extended JNI checking */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700642 addOption("-Xcheck:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700643
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700644 /* with -Xcheck:jni, this provides a JNI function call trace */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700645 //addOption("-verbose:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700646 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647
648 property_get("dalvik.vm.execution-mode", propBuf, "");
649 if (strcmp(propBuf, "int:portable") == 0) {
650 executionMode = kEMIntPortable;
651 } else if (strcmp(propBuf, "int:fast") == 0) {
652 executionMode = kEMIntFast;
Ben Cheng52b0e732009-06-19 13:31:12 -0700653 } else if (strcmp(propBuf, "int:jit") == 0) {
654 executionMode = kEMJitCompiler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655 }
656
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700657 parseRuntimeOption("dalvik.vm.stack-trace-file", stackTraceFileBuf, "-Xstacktracefile:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 strcpy(jniOptsBuf, "-Xjniopts:");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700660 if (parseRuntimeOption("dalvik.vm.jniopts", jniOptsBuf, "-Xjniopts:")) {
661 ALOGI("JNI options: '%s'\n", jniOptsBuf);
662 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800664 /* route exit() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700665 addOption("exit", (void*) runtime_exit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666
667 /* route fprintf() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700668 addOption("vfprintf", (void*) runtime_vfprintf);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800670 /* register the framework-specific "is sensitive thread" hook */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700671 addOption("sensitiveThread", (void*) runtime_isSensitiveThread);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672
673 /* enable verbose; standard options are { jni, gc, class } */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700674 //addOption("-verbose:jni");
675 addOption("-verbose:gc");
676 //addOption("-verbose:class");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677
Carl Shapiro9e4c8842010-12-08 12:14:46 -0800678 /*
679 * The default starting and maximum size of the heap. Larger
680 * values should be specified in a product property override.
681 */
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700682 parseRuntimeOption("dalvik.vm.heapstartsize", heapstartsizeOptsBuf, "-Xms", "4m");
683 parseRuntimeOption("dalvik.vm.heapsize", heapsizeOptsBuf, "-Xmx", "16m");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700685 parseRuntimeOption("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
686 parseRuntimeOption("dalvik.vm.heapminfree", heapminfreeOptsBuf, "-XX:HeapMinFree=");
687 parseRuntimeOption("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf, "-XX:HeapMaxFree=");
688 parseRuntimeOption("dalvik.vm.heaptargetutilization",
689 heaptargetutilizationOptsBuf,
690 "-XX:HeapTargetUtilization=");
Ian Rogers53250102012-09-23 16:38:03 -0700691
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800692 /*
693 * JIT related options.
694 */
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700695 parseRuntimeOption("dalvik.vm.usejit", usejitOptsBuf, "-Xusejit:");
696 parseRuntimeOption("dalvik.vm.jitcodecachesize", jitcodecachesizeOptsBuf, "-Xjitcodecachesize:");
697 parseRuntimeOption("dalvik.vm.jitthreshold", jitthresholdOptsBuf, "-Xjitthreshold:");
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800698
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700699 property_get("ro.config.low_ram", propBuf, "");
700 if (strcmp(propBuf, "true") == 0) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700701 addOption("-XX:LowMemoryMode");
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700702 }
703
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700704 parseRuntimeOption("dalvik.vm.gctype", gctypeOptsBuf, "-Xgc:");
705 parseRuntimeOption("dalvik.vm.backgroundgctype", backgroundgcOptsBuf, "-XX:BackgroundGC=");
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700706
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200707 /*
708 * Enable debugging only for apps forked from zygote.
709 * Set suspend=y to pause during VM init and use android ADB transport.
710 */
711 if (zygote) {
712 addOption("-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y");
713 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800714
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700715 parseRuntimeOption("dalvik.vm.lockprof.threshold",
716 lockProfThresholdBuf,
717 "-Xlockprofthreshold:");
Carl Shapirod8f3ec62010-04-12 16:31:59 -0700718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719 if (executionMode == kEMIntPortable) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700720 addOption("-Xint:portable");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800721 } else if (executionMode == kEMIntFast) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700722 addOption("-Xint:fast");
Ben Cheng52b0e732009-06-19 13:31:12 -0700723 } else if (executionMode == kEMJitCompiler) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700724 addOption("-Xint:jit");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 }
Andy McFaddene2b23e12009-04-03 11:09:46 -0700726
Andreas Gampe08b2d582014-12-18 14:39:22 -0800727 // If we are booting without the real /data, don't spend time compiling.
728 property_get("vold.decrypt", voldDecryptBuf, "");
729 bool skip_compilation = ((strcmp(voldDecryptBuf, "trigger_restart_min_framework") == 0) ||
730 (strcmp(voldDecryptBuf, "1") == 0));
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800731
Andreas Gampe08b2d582014-12-18 14:39:22 -0800732 // Extra options for boot.art/boot.oat image generation.
733 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xms", dex2oatXmsImageFlagsBuf,
734 "-Xms", "-Ximage-compiler-option");
735 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xmx", dex2oatXmxImageFlagsBuf,
736 "-Xmx", "-Ximage-compiler-option");
737 if (skip_compilation) {
Brian Carlstromce5bbbe2014-07-30 15:13:17 -0700738 addOption("-Ximage-compiler-option");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800739 addOption("--compiler-filter=verify-none");
740 } else {
741 parseCompilerOption("dalvik.vm.image-dex2oat-filter", dex2oatImageCompilerFilterBuf,
742 "--compiler-filter=", "-Ximage-compiler-option");
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800743 }
744
Andreas Gampe08b2d582014-12-18 14:39:22 -0800745 // Make sure there is a preloaded-classes file.
746 if (!hasFile("/system/etc/preloaded-classes")) {
747 ALOGE("Missing preloaded-classes file, /system/etc/preloaded-classes not found: %s\n",
748 strerror(errno));
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700749 return -1;
Andreas Gampe08b2d582014-12-18 14:39:22 -0800750 }
751 addOption("-Ximage-compiler-option");
752 addOption("--image-classes=/system/etc/preloaded-classes");
753
754 // If there is a compiled-classes file, push it.
755 if (hasFile("/system/etc/compiled-classes")) {
756 addOption("-Ximage-compiler-option");
757 addOption("--compiled-classes=/system/etc/compiled-classes");
758 }
759
760 property_get("dalvik.vm.image-dex2oat-flags", dex2oatImageFlagsBuf, "");
761 parseExtraOpts(dex2oatImageFlagsBuf, "-Ximage-compiler-option");
762
763 // Extra options for DexClassLoader.
764 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xms", dex2oatXmsFlagsBuf,
765 "-Xms", "-Xcompiler-option");
766 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xmx", dex2oatXmxFlagsBuf,
767 "-Xmx", "-Xcompiler-option");
768 if (skip_compilation) {
769 addOption("-Xcompiler-option");
770 addOption("--compiler-filter=verify-none");
neo.chae155118f2015-01-07 15:32:15 +0900771
772 // We skip compilation when a minimal runtime is brought up for decryption. In that case
773 // /data is temporarily backed by a tmpfs, which is usually small.
774 // If the system image contains prebuilts, they will be relocated into the tmpfs. In this
775 // specific situation it is acceptable to *not* relocate and run out of the prebuilts
776 // directly instead.
777 addOption("--runtime-arg");
778 addOption("-Xnorelocate");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800779 } else {
780 parseCompilerOption("dalvik.vm.dex2oat-filter", dex2oatCompilerFilterBuf,
781 "--compiler-filter=", "-Xcompiler-option");
782 }
Andreas Gampee0352382015-03-30 18:43:39 -0700783 parseCompilerOption("dalvik.vm.dex2oat-threads", dex2oatThreadsBuf, "-j", "-Xcompiler-option");
784 parseCompilerOption("dalvik.vm.image-dex2oat-threads", dex2oatThreadsImageBuf, "-j",
785 "-Ximage-compiler-option");
Andreas Gampe605cca12015-04-02 23:12:56 -0700786
787 // The runtime will compile a boot image, when necessary, not using installd. Thus, we need to
788 // pass the instruction-set-features/variant as an image-compiler-option.
789 // TODO: Find a better way for the instruction-set.
790#if defined(__arm__)
791 constexpr const char* instruction_set = "arm";
792#elif defined(__aarch64__)
793 constexpr const char* instruction_set = "arm64";
794#elif defined(__mips__) && !defined(__LP64__)
795 constexpr const char* instruction_set = "mips";
796#elif defined(__mips__) && defined(__LP64__)
797 constexpr const char* instruction_set = "mips64";
798#elif defined(__i386__)
799 constexpr const char* instruction_set = "x86";
800#elif defined(__x86_64__)
801 constexpr const char* instruction_set = "x86_64";
802#else
803 constexpr const char* instruction_set = "unknown";
804#endif
805 // Note: it is OK to reuse the buffer, as the values are exactly the same between
806 // * compiler-option, used for runtime compilation (DexClassLoader)
807 // * image-compiler-option, used for boot-image compilation on device
808
809 // Copy the variant.
810 sprintf(dex2oat_isa_variant_key, "dalvik.vm.isa.%s.variant", instruction_set);
811 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
812 "--instruction-set-variant=", "-Ximage-compiler-option");
813 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
814 "--instruction-set-variant=", "-Xcompiler-option");
815 // Copy the features.
816 sprintf(dex2oat_isa_features_key, "dalvik.vm.isa.%s.features", instruction_set);
817 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
818 "--instruction-set-features=", "-Ximage-compiler-option");
819 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
820 "--instruction-set-features=", "-Xcompiler-option");
821
822
Andreas Gampe08b2d582014-12-18 14:39:22 -0800823 property_get("dalvik.vm.dex2oat-flags", dex2oatFlagsBuf, "");
824 parseExtraOpts(dex2oatFlagsBuf, "-Xcompiler-option");
825
Andy McFaddene4d81f22010-07-14 16:02:20 -0700826 /* extra options; parse this late so it overrides others */
827 property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800828 parseExtraOpts(extraOptsBuf, NULL);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830 /* Set the properties for locale */
831 {
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000832 strcpy(localeOption, "-Duser.locale=");
Narayan Kamathbf882052015-08-11 15:40:34 +0100833 const std::string locale = readLocale();
834 strncat(localeOption, locale.c_str(), PROPERTY_VALUE_MAX);
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000835 addOption(localeOption);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800836 }
837
Dave Allison0efbd9a2014-01-30 14:19:51 -0800838 /*
839 * Set profiler options
840 */
Andreas Gampe08b2d582014-12-18 14:39:22 -0800841 // Whether or not the profiler should be enabled.
842 property_get("dalvik.vm.profiler", propBuf, "0");
843 if (propBuf[0] == '1') {
844 addOption("-Xenable-profiler");
845 }
Dave Allison0efbd9a2014-01-30 14:19:51 -0800846
Andreas Gampe08b2d582014-12-18 14:39:22 -0800847 // Whether the profile should start upon app startup or be delayed by some random offset
848 // (in seconds) that is bound between 0 and a fixed value.
849 property_get("dalvik.vm.profile.start-immed", propBuf, "0");
850 if (propBuf[0] == '1') {
851 addOption("-Xprofile-start-immediately");
852 }
Dave Allison0efbd9a2014-01-30 14:19:51 -0800853
Andreas Gampe08b2d582014-12-18 14:39:22 -0800854 // Number of seconds during profile runs.
855 parseRuntimeOption("dalvik.vm.profile.period-secs", profilePeriod, "-Xprofile-period:");
Dave Allison0efbd9a2014-01-30 14:19:51 -0800856
Andreas Gampe08b2d582014-12-18 14:39:22 -0800857 // Length of each profile run (seconds).
858 parseRuntimeOption("dalvik.vm.profile.duration-secs",
859 profileDuration,
860 "-Xprofile-duration:");
Dave Allison0efbd9a2014-01-30 14:19:51 -0800861
Andreas Gampe08b2d582014-12-18 14:39:22 -0800862 // Polling interval during profile run (microseconds).
863 parseRuntimeOption("dalvik.vm.profile.interval-us", profileInterval, "-Xprofile-interval:");
Calin Juravle9828d062014-06-02 16:45:13 +0100864
Andreas Gampe08b2d582014-12-18 14:39:22 -0800865 // Coefficient for period backoff. The the period is multiplied
866 // by this value after each profile run.
867 parseRuntimeOption("dalvik.vm.profile.backoff-coeff", profileBackoff, "-Xprofile-backoff:");
Calin Juravle9828d062014-06-02 16:45:13 +0100868
Andreas Gampe08b2d582014-12-18 14:39:22 -0800869 // Top K% of samples that are considered relevant when
870 // deciding if the app should be recompiled.
871 parseRuntimeOption("dalvik.vm.profile.top-k-thr",
872 profileTopKThreshold,
873 "-Xprofile-top-k-threshold:");
Calin Juravle9828d062014-06-02 16:45:13 +0100874
Andreas Gampe08b2d582014-12-18 14:39:22 -0800875 // The threshold after which a change in the structure of the
876 // top K% profiled samples becomes significant and triggers
877 // recompilation. A change in profile is considered
878 // significant if X% (top-k-change-threshold) of the top K%
879 // (top-k-threshold property) samples has changed.
880 parseRuntimeOption("dalvik.vm.profile.top-k-ch-thr",
881 profileTopKChangeThreshold,
882 "-Xprofile-top-k-change-threshold:");
Wei Jin54fc18b2014-06-09 16:29:54 -0700883
Andreas Gampe08b2d582014-12-18 14:39:22 -0800884 // Type of profile data.
885 parseRuntimeOption("dalvik.vm.profiler.type", profileType, "-Xprofile-type:");
Wei Jin54fc18b2014-06-09 16:29:54 -0700886
Andreas Gampe08b2d582014-12-18 14:39:22 -0800887 // Depth of bounded stack data
888 parseRuntimeOption("dalvik.vm.profile.stack-depth",
889 profileMaxStackDepth,
890 "-Xprofile-max-stack-depth:");
Dave Allison0efbd9a2014-01-30 14:19:51 -0800891
Calin Juravle92290b82015-11-10 19:30:45 +0000892 // Trace files are stored in /data/misc/trace which is writable only in debug mode.
893 property_get("ro.debuggable", propBuf, "0");
894 if (strcmp(propBuf, "1") == 0) {
895 property_get("dalvik.vm.method-trace", propBuf, "false");
Andreas Gampe98f406f2015-06-22 21:09:36 -0700896 if (strcmp(propBuf, "true") == 0) {
Calin Juravle92290b82015-11-10 19:30:45 +0000897 addOption("-Xmethod-trace");
898 parseRuntimeOption("dalvik.vm.method-trace-file",
899 methodTraceFileBuf,
900 "-Xmethod-trace-file:");
901 parseRuntimeOption("dalvik.vm.method-trace-file-siz",
902 methodTraceFileSizeBuf,
903 "-Xmethod-trace-file-size:");
904 property_get("dalvik.vm.method-trace-stream", propBuf, "false");
905 if (strcmp(propBuf, "true") == 0) {
906 addOption("-Xmethod-trace-stream");
907 }
Andreas Gampe98f406f2015-06-22 21:09:36 -0700908 }
909 }
910
Andreas Gampe08b2d582014-12-18 14:39:22 -0800911 // Native bridge library. "0" means that native bridge is disabled.
912 property_get("ro.dalvik.vm.native.bridge", propBuf, "");
913 if (propBuf[0] == '\0') {
914 ALOGW("ro.dalvik.vm.native.bridge is not expected to be empty");
915 } else if (strcmp(propBuf, "0") != 0) {
916 snprintf(nativeBridgeLibrary, sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX,
917 "-XX:NativeBridge=%s", propBuf);
918 addOption(nativeBridgeLibrary);
Calin Juravlebe20ed42014-08-26 23:00:11 +0100919 }
Calin Juravle01db9162014-08-07 14:45:53 +0100920
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700921#if defined(__LP64__)
922 const char* cpu_abilist_property_name = "ro.product.cpu.abilist64";
923#else
924 const char* cpu_abilist_property_name = "ro.product.cpu.abilist32";
925#endif // defined(__LP64__)
926 property_get(cpu_abilist_property_name, propBuf, "");
927 if (propBuf[0] == '\0') {
928 ALOGE("%s is not expected to be empty", cpu_abilist_property_name);
929 return -1;
930 }
931 snprintf(cpuAbiListBuf, sizeof(cpuAbiListBuf), "--cpu-abilist=%s", propBuf);
932 addOption(cpuAbiListBuf);
933
Andreas Gampee324ba02015-03-31 16:15:17 -0700934 // Dalvik-cache pruning counter.
935 parseRuntimeOption("dalvik.vm.zygote.max-boot-retry", cachePruneBuf,
936 "-Xzygote-max-boot-retry=");
937
Andreas Gampe27c39f12015-04-27 18:28:18 +0000938 /*
David Srbecky065075e2015-05-28 17:16:09 +0100939 * When running with debug.generate-debug-info, add --generate-debug-info to
940 * the compiler options so that the boot image, if it is compiled on device,
941 * will include native debugging information.
Andreas Gampe27c39f12015-04-27 18:28:18 +0000942 */
David Srbecky065075e2015-05-28 17:16:09 +0100943 property_get("debug.generate-debug-info", propBuf, "");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000944 if (strcmp(propBuf, "true") == 0) {
945 addOption("-Xcompiler-option");
David Srbecky065075e2015-05-28 17:16:09 +0100946 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000947 addOption("-Ximage-compiler-option");
David Srbecky065075e2015-05-28 17:16:09 +0100948 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000949 }
950
Andreas Gampee6082502015-07-24 14:19:44 -0700951 /*
952 * Retrieve the build fingerprint and provide it to the runtime. That way, ANR dumps will
953 * contain the fingerprint and can be parsed.
954 */
955 parseRuntimeOption("ro.build.fingerprint", fingerprintBuf, "-Xfingerprint:");
956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800957 initArgs.version = JNI_VERSION_1_4;
958 initArgs.options = mOptions.editArray();
959 initArgs.nOptions = mOptions.size();
960 initArgs.ignoreUnrecognized = JNI_FALSE;
961
962 /*
963 * Initialize the VM.
964 *
965 * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread.
966 * If this call succeeds, the VM is ready, and we can start issuing
967 * JNI calls.
968 */
Andy McFaddenf70188a2009-03-31 15:52:13 -0700969 if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) {
Steve Block3762c312012-01-06 19:20:56 +0000970 ALOGE("JNI_CreateJavaVM failed\n");
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700971 return -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 }
973
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700974 return 0;
Andy McFaddenf70188a2009-03-31 15:52:13 -0700975}
976
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700977char* AndroidRuntime::toSlashClassName(const char* className)
978{
979 char* result = strdup(className);
980 for (char* cp = result; *cp != '\0'; cp++) {
981 if (*cp == '.') {
982 *cp = '/';
983 }
984 }
985 return result;
986}
987
Mike Lockwood9ee5e7e2014-09-08 16:15:21 -0700988/** Create a Java string from an ASCII or Latin-1 string */
989jstring AndroidRuntime::NewStringLatin1(JNIEnv* env, const char* bytes) {
990 if (!bytes) return NULL;
991 int length = strlen(bytes);
992 jchar* buffer = (jchar *)alloca(length * sizeof(jchar));
993 if (!buffer) return NULL;
994 jchar* chp = buffer;
995 for (int i = 0; i < length; i++) {
996 *chp++ = *bytes++;
997 }
998 return env->NewString(buffer, length);
999}
1000
1001
Andy McFaddenf70188a2009-03-31 15:52:13 -07001002/*
1003 * Start the Android runtime. This involves starting the virtual machine
1004 * and calling the "static void main(String[] args)" method in the class
1005 * named by "className".
Jeff Brownebed7d62011-05-16 17:08:42 -07001006 *
1007 * Passes the main function two arguments, the class name and the specified
1008 * options string.
Andy McFaddenf70188a2009-03-31 15:52:13 -07001009 */
Sebastien Hertz7a09b832015-08-10 18:55:34 +02001010void AndroidRuntime::start(const char* className, const Vector<String8>& options, bool zygote)
Andy McFaddenf70188a2009-03-31 15:52:13 -07001011{
Dianne Hackborn8e5aafe2014-10-27 18:04:10 -07001012 ALOGD(">>>>>> START %s uid %d <<<<<<\n",
1013 className != NULL ? className : "(unknown)", getuid());
Andy McFaddenf70188a2009-03-31 15:52:13 -07001014
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001015 static const String8 startSystemServer("start-system-server");
1016
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001017 /*
1018 * 'startSystemServer == true' means runtime is obsolete and not run from
Andy McFaddenf70188a2009-03-31 15:52:13 -07001019 * init.rc anymore, so we print out the boot start event here.
1020 */
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001021 for (size_t i = 0; i < options.size(); ++i) {
1022 if (options[i] == startSystemServer) {
1023 /* track our progress through the boot sequence */
1024 const int LOG_BOOT_PROGRESS_START = 3000;
1025 LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));
1026 }
Andy McFaddenf70188a2009-03-31 15:52:13 -07001027 }
1028
1029 const char* rootDir = getenv("ANDROID_ROOT");
1030 if (rootDir == NULL) {
1031 rootDir = "/system";
1032 if (!hasDir("/system")) {
1033 LOG_FATAL("No root directory specified, and /android does not exist.");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001034 return;
Andy McFaddenf70188a2009-03-31 15:52:13 -07001035 }
1036 setenv("ANDROID_ROOT", rootDir, 1);
1037 }
1038
1039 //const char* kernelHack = getenv("LD_ASSUME_KERNEL");
Steve Block5baa3a62011-12-20 16:23:08 +00001040 //ALOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001041
1042 /* start the virtual machine */
Brian Carlstrom9f8203a2013-06-19 13:49:36 -07001043 JniInvocation jni_invocation;
1044 jni_invocation.Init(NULL);
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001045 JNIEnv* env;
Sebastien Hertz7a09b832015-08-10 18:55:34 +02001046 if (startVm(&mJavaVM, &env, zygote) != 0) {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001047 return;
1048 }
1049 onVmCreated(env);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 /*
1052 * Register android functions.
1053 */
1054 if (startReg(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001055 ALOGE("Unable to register all android natives\n");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001056 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001057 }
1058
1059 /*
1060 * We want to call main() with a String array with arguments in it.
Jeff Brownebed7d62011-05-16 17:08:42 -07001061 * At present we have two arguments, the class name and an option string.
1062 * Create an array to hold them.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 */
1064 jclass stringClass;
1065 jobjectArray strArray;
1066 jstring classNameStr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067
1068 stringClass = env->FindClass("java/lang/String");
1069 assert(stringClass != NULL);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001070 strArray = env->NewObjectArray(options.size() + 1, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 assert(strArray != NULL);
1072 classNameStr = env->NewStringUTF(className);
1073 assert(classNameStr != NULL);
1074 env->SetObjectArrayElement(strArray, 0, classNameStr);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001075
1076 for (size_t i = 0; i < options.size(); ++i) {
1077 jstring optionsStr = env->NewStringUTF(options.itemAt(i).string());
1078 assert(optionsStr != NULL);
1079 env->SetObjectArrayElement(strArray, i + 1, optionsStr);
1080 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081
1082 /*
1083 * Start VM. This thread becomes the main thread of the VM, and will
1084 * not return until the VM exits.
1085 */
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001086 char* slashClassName = toSlashClassName(className);
1087 jclass startClass = env->FindClass(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001088 if (startClass == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001089 ALOGE("JavaVM unable to locate class '%s'\n", slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090 /* keep going */
1091 } else {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001092 jmethodID startMeth = env->GetStaticMethodID(startClass, "main",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 "([Ljava/lang/String;)V");
1094 if (startMeth == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001095 ALOGE("JavaVM unable to find main() in '%s'\n", className);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096 /* keep going */
1097 } else {
1098 env->CallStaticVoidMethod(startClass, startMeth, strArray);
1099
1100#if 0
1101 if (env->ExceptionCheck())
1102 threadExitUncaughtException(env);
1103#endif
1104 }
1105 }
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001106 free(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107
Steve Block5baa3a62011-12-20 16:23:08 +00001108 ALOGD("Shutting down VM\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 if (mJavaVM->DetachCurrentThread() != JNI_OK)
Steve Block8564c8d2012-01-05 23:22:43 +00001110 ALOGW("Warning: unable to detach main thread\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001111 if (mJavaVM->DestroyJavaVM() != 0)
Steve Block8564c8d2012-01-05 23:22:43 +00001112 ALOGW("Warning: VM did not shut down cleanly\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113}
1114
Jeff Brown4280c4a2012-03-15 17:48:02 -07001115void AndroidRuntime::exit(int code)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116{
Jeff Brown4280c4a2012-03-15 17:48:02 -07001117 if (mExitWithoutCleanup) {
1118 ALOGI("VM exiting with result code %d, cleanup skipped.", code);
1119 ::_exit(code);
1120 } else {
1121 ALOGI("VM exiting with result code %d.", code);
1122 onExit(code);
1123 ::exit(code);
1124 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125}
1126
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001127void AndroidRuntime::onVmCreated(JNIEnv* env)
1128{
1129 // If AndroidRuntime had anything to do here, we'd have done it in 'start'.
1130}
1131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132/*
Andreas Huber9ae000c2014-02-13 17:22:33 +00001133 * Get the JNIEnv pointer for this thread.
1134 *
1135 * Returns NULL if the slot wasn't allocated or populated.
1136 */
1137/*static*/ JNIEnv* AndroidRuntime::getJNIEnv()
1138{
1139 JNIEnv* env;
1140 JavaVM* vm = AndroidRuntime::getJavaVM();
1141 assert(vm != NULL);
1142
1143 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
1144 return NULL;
1145 return env;
1146}
1147
1148/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 * Makes the current thread visible to the VM.
1150 *
1151 * The JNIEnv pointer returned is only valid for the current thread, and
1152 * thus must be tucked into thread-local storage.
1153 */
1154static int javaAttachThread(const char* threadName, JNIEnv** pEnv)
1155{
1156 JavaVMAttachArgs args;
1157 JavaVM* vm;
1158 jint result;
1159
1160 vm = AndroidRuntime::getJavaVM();
1161 assert(vm != NULL);
1162
1163 args.version = JNI_VERSION_1_4;
1164 args.name = (char*) threadName;
1165 args.group = NULL;
1166
1167 result = vm->AttachCurrentThread(pEnv, (void*) &args);
1168 if (result != JNI_OK)
Steve Block6215d3f2012-01-04 20:05:49 +00001169 ALOGI("NOTE: attach of thread '%s' failed\n", threadName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170
1171 return result;
1172}
1173
1174/*
1175 * Detach the current thread from the set visible to the VM.
1176 */
1177static int javaDetachThread(void)
1178{
1179 JavaVM* vm;
1180 jint result;
1181
1182 vm = AndroidRuntime::getJavaVM();
1183 assert(vm != NULL);
1184
1185 result = vm->DetachCurrentThread();
1186 if (result != JNI_OK)
Steve Block3762c312012-01-06 19:20:56 +00001187 ALOGE("ERROR: thread detach failed\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 return result;
1189}
1190
1191/*
1192 * When starting a native thread that will be visible from the VM, we
1193 * bounce through this to get the right attach/detach action.
1194 * Note that this function calls free(args)
1195 */
1196/*static*/ int AndroidRuntime::javaThreadShell(void* args) {
1197 void* start = ((void**)args)[0];
1198 void* userData = ((void **)args)[1];
1199 char* name = (char*) ((void **)args)[2]; // we own this storage
1200 free(args);
1201 JNIEnv* env;
1202 int result;
1203
1204 /* hook us into the VM */
1205 if (javaAttachThread(name, &env) != JNI_OK)
1206 return -1;
1207
1208 /* start the thread running */
1209 result = (*(android_thread_func_t)start)(userData);
1210
1211 /* unhook us */
1212 javaDetachThread();
1213 free(name);
1214
1215 return result;
1216}
1217
1218/*
1219 * This is invoked from androidCreateThreadEtc() via the callback
1220 * set with androidSetCreateThreadFunc().
1221 *
1222 * We need to create the new thread in such a way that it gets hooked
1223 * into the VM before it really starts executing.
1224 */
1225/*static*/ int AndroidRuntime::javaCreateThreadEtc(
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001226 android_thread_func_t entryFunction,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001227 void* userData,
1228 const char* threadName,
1229 int32_t threadPriority,
1230 size_t threadStackSize,
1231 android_thread_id_t* threadId)
1232{
1233 void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free
1234 int result;
1235
Mike Lockwood32f2e622013-10-10 10:11:27 -07001236 if (!threadName)
1237 threadName = "unnamed thread";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001238
1239 args[0] = (void*) entryFunction;
1240 args[1] = userData;
1241 args[2] = (void*) strdup(threadName); // javaThreadShell must free
1242
1243 result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args,
1244 threadName, threadPriority, threadStackSize, threadId);
1245 return result;
1246}
1247
1248/*
1249 * Create a thread that is visible from the VM.
1250 *
1251 * This is called from elsewhere in the library.
1252 */
Mike Lockwoodf602d362010-06-20 14:28:16 -07001253/*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001254 void (*start)(void *), void* arg)
1255{
Mike Lockwoodf602d362010-06-20 14:28:16 -07001256 android_thread_id_t threadId = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001257 javaCreateThreadEtc((android_thread_func_t) start, arg, name,
Mike Lockwoodf602d362010-06-20 14:28:16 -07001258 ANDROID_PRIORITY_DEFAULT, 0, &threadId);
1259 return threadId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001260}
1261
1262#if 0
1263static void quickTest(void* arg)
1264{
1265 const char* str = (const char*) arg;
1266
1267 printf("In quickTest: %s\n", str);
1268}
1269#endif
1270
1271#ifdef NDEBUG
1272 #define REG_JNI(name) { name }
1273 struct RegJNIRec {
1274 int (*mProc)(JNIEnv*);
1275 };
1276#else
1277 #define REG_JNI(name) { name, #name }
1278 struct RegJNIRec {
1279 int (*mProc)(JNIEnv*);
1280 const char* mName;
1281 };
1282#endif
1283
1284typedef void (*RegJAMProc)();
1285
1286static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env)
1287{
1288 for (size_t i = 0; i < count; i++) {
1289 if (array[i].mProc(env) < 0) {
1290#ifndef NDEBUG
Steve Block5baa3a62011-12-20 16:23:08 +00001291 ALOGD("----------!!! %s failed to load\n", array[i].mName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001292#endif
1293 return -1;
1294 }
1295 }
1296 return 0;
1297}
1298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001299static const RegJNIRec gRegJNI[] = {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001300 REG_JNI(register_com_android_internal_os_RuntimeInit),
1301 REG_JNI(register_android_os_SystemClock),
1302 REG_JNI(register_android_util_EventLog),
1303 REG_JNI(register_android_util_Log),
Doris Liucdd23f92015-11-11 14:31:13 -08001304 REG_JNI(register_android_util_PathParser),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001305 REG_JNI(register_android_content_AssetManager),
1306 REG_JNI(register_android_content_StringBlock),
1307 REG_JNI(register_android_content_XmlBlock),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001308 REG_JNI(register_android_text_AndroidCharacter),
Anish Athalye88b5b0b2014-06-24 14:39:43 -07001309 REG_JNI(register_android_text_StaticLayout),
Doug Feltdae8e942010-02-24 14:33:15 -08001310 REG_JNI(register_android_text_AndroidBidi),
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001311 REG_JNI(register_android_view_InputDevice),
1312 REG_JNI(register_android_view_KeyCharacterMap),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001313 REG_JNI(register_android_os_Process),
Andreas Hubera8079bf2010-11-16 14:40:31 -08001314 REG_JNI(register_android_os_SystemProperties),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 REG_JNI(register_android_os_Binder),
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -08001316 REG_JNI(register_android_os_Parcel),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001317 REG_JNI(register_android_nio_utils),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001318 REG_JNI(register_android_graphics_Graphics),
Chris Craik54389792013-12-20 13:28:11 -08001319 REG_JNI(register_android_view_DisplayEventReceiver),
John Reckf666ad72014-03-14 16:24:57 -07001320 REG_JNI(register_android_view_RenderNode),
John Recke45b1fd2014-04-15 09:50:16 -07001321 REG_JNI(register_android_view_RenderNodeAnimator),
Romain Guy3b748a42013-04-17 18:54:38 -07001322 REG_JNI(register_android_view_GraphicBuffer),
Chris Craikc9070eb2015-03-09 18:50:14 -07001323 REG_JNI(register_android_view_DisplayListCanvas),
John Reck04fc5832014-02-05 16:38:25 -08001324 REG_JNI(register_android_view_HardwareLayer),
John Reckcec24ae2013-11-05 13:27:50 -08001325 REG_JNI(register_android_view_ThreadedRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001326 REG_JNI(register_android_view_Surface),
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001327 REG_JNI(register_android_view_SurfaceControl),
Jeff Brown64a55af2012-08-26 02:47:39 -07001328 REG_JNI(register_android_view_SurfaceSession),
Romain Guy8f0095c2011-05-02 17:24:22 -07001329 REG_JNI(register_android_view_TextureView),
John Reck315c3292014-05-09 19:21:04 -07001330 REG_JNI(register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001331 REG_JNI(register_com_google_android_gles_jni_EGLImpl),
1332 REG_JNI(register_com_google_android_gles_jni_GLImpl),
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001333 REG_JNI(register_android_opengl_jni_EGL14),
Jesse Hall237c2b82013-05-06 11:36:57 -07001334 REG_JNI(register_android_opengl_jni_EGLExt),
Jack Palevich1c4907e2009-04-13 16:22:25 -07001335 REG_JNI(register_android_opengl_jni_GLES10),
1336 REG_JNI(register_android_opengl_jni_GLES10Ext),
1337 REG_JNI(register_android_opengl_jni_GLES11),
1338 REG_JNI(register_android_opengl_jni_GLES11Ext),
Jack Palevich560814f2009-11-19 16:34:55 +08001339 REG_JNI(register_android_opengl_jni_GLES20),
Jesse Halld877efe2013-04-29 15:59:35 -07001340 REG_JNI(register_android_opengl_jni_GLES30),
Jesse Hall7ab63ac2014-05-19 15:13:41 -07001341 REG_JNI(register_android_opengl_jni_GLES31),
1342 REG_JNI(register_android_opengl_jni_GLES31Ext),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001343
1344 REG_JNI(register_android_graphics_Bitmap),
1345 REG_JNI(register_android_graphics_BitmapFactory),
Wei-Ta Chen6b849e22010-09-07 17:32:18 +08001346 REG_JNI(register_android_graphics_BitmapRegionDecoder),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 REG_JNI(register_android_graphics_Camera),
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -04001348 REG_JNI(register_android_graphics_CreateJavaOutputStreamAdaptor),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001349 REG_JNI(register_android_graphics_Canvas),
John Reck52244ff2014-05-01 21:27:37 -07001350 REG_JNI(register_android_graphics_CanvasProperty),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351 REG_JNI(register_android_graphics_ColorFilter),
1352 REG_JNI(register_android_graphics_DrawFilter),
Raph Levien1a73f7322014-01-30 16:06:28 -08001353 REG_JNI(register_android_graphics_FontFamily),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001354 REG_JNI(register_android_graphics_Interpolator),
1355 REG_JNI(register_android_graphics_LayerRasterizer),
1356 REG_JNI(register_android_graphics_MaskFilter),
1357 REG_JNI(register_android_graphics_Matrix),
1358 REG_JNI(register_android_graphics_Movie),
1359 REG_JNI(register_android_graphics_NinePatch),
1360 REG_JNI(register_android_graphics_Paint),
1361 REG_JNI(register_android_graphics_Path),
1362 REG_JNI(register_android_graphics_PathMeasure),
1363 REG_JNI(register_android_graphics_PathEffect),
1364 REG_JNI(register_android_graphics_Picture),
1365 REG_JNI(register_android_graphics_PorterDuff),
1366 REG_JNI(register_android_graphics_Rasterizer),
1367 REG_JNI(register_android_graphics_Region),
1368 REG_JNI(register_android_graphics_Shader),
Jamie Gennisaa0ce332011-01-06 17:04:26 -08001369 REG_JNI(register_android_graphics_SurfaceTexture),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001370 REG_JNI(register_android_graphics_Typeface),
1371 REG_JNI(register_android_graphics_Xfermode),
Wei-Ta Chenbca2d612009-11-30 17:52:05 +08001372 REG_JNI(register_android_graphics_YuvImage),
Svetoslav6811f4e2013-09-18 15:58:28 -07001373 REG_JNI(register_android_graphics_pdf_PdfDocument),
Svetoslav62ce3322014-09-04 21:17:17 -07001374 REG_JNI(register_android_graphics_pdf_PdfEditor),
Svetoslav29617692014-04-24 18:40:42 -07001375 REG_JNI(register_android_graphics_pdf_PdfRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001376
1377 REG_JNI(register_android_database_CursorWindow),
Jeff Browne5360fb2011-10-31 17:48:13 -07001378 REG_JNI(register_android_database_SQLiteConnection),
1379 REG_JNI(register_android_database_SQLiteGlobal),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001380 REG_JNI(register_android_database_SQLiteDebug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001381 REG_JNI(register_android_os_Debug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382 REG_JNI(register_android_os_FileObserver),
Christopher Tatefa9e7c02010-05-06 12:07:10 -07001383 REG_JNI(register_android_os_MessageQueue),
Stephen Smalleyc07fca32012-01-13 08:31:39 -05001384 REG_JNI(register_android_os_SELinux),
Jeff Brown481c1572012-03-09 14:41:15 -08001385 REG_JNI(register_android_os_Trace),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001386 REG_JNI(register_android_os_UEventObserver),
1387 REG_JNI(register_android_net_LocalSocketImpl),
1388 REG_JNI(register_android_net_NetworkUtils),
Dan Egnor2b4abcd2010-04-07 17:30:50 -07001389 REG_JNI(register_android_net_TrafficStats),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001390 REG_JNI(register_android_os_MemoryFile),
Narayan Kamath973b4662014-03-31 13:41:26 +01001391 REG_JNI(register_com_android_internal_os_Zygote),
John Reck9fa40712014-05-09 15:26:59 -07001392 REG_JNI(register_com_android_internal_util_VirtualRefBasePtr),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001393 REG_JNI(register_android_hardware_Camera),
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07001394 REG_JNI(register_android_hardware_camera2_CameraMetadata),
Ruben Brunkfeb50af2014-05-09 19:58:49 -07001395 REG_JNI(register_android_hardware_camera2_legacy_LegacyCameraDevice),
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -07001396 REG_JNI(register_android_hardware_camera2_legacy_PerfMeasurement),
Ruben Brunkb6079002014-05-22 12:33:54 -07001397 REG_JNI(register_android_hardware_camera2_DngCreator),
Eric Laurent633cb562015-03-05 15:17:20 -08001398 REG_JNI(register_android_hardware_Radio),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001399 REG_JNI(register_android_hardware_SensorManager),
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04001400 REG_JNI(register_android_hardware_SerialPort),
Eric Laurent60b62bc2014-04-18 17:50:49 -07001401 REG_JNI(register_android_hardware_SoundTrigger),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001402 REG_JNI(register_android_hardware_UsbDevice),
Mike Lockwoodacc29cc2011-03-11 08:18:08 -05001403 REG_JNI(register_android_hardware_UsbDeviceConnection),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001404 REG_JNI(register_android_hardware_UsbRequest),
destradaaa4fa3b52014-07-09 10:46:39 -07001405 REG_JNI(register_android_hardware_location_ActivityRecognitionHardware),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406 REG_JNI(register_android_media_AudioRecord),
1407 REG_JNI(register_android_media_AudioSystem),
1408 REG_JNI(register_android_media_AudioTrack),
1409 REG_JNI(register_android_media_JetPlayer),
Jeff Browncbad9762012-09-04 21:57:59 -07001410 REG_JNI(register_android_media_RemoteDisplay),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001411 REG_JNI(register_android_media_ToneGenerator),
1412
1413 REG_JNI(register_android_opengl_classes),
JP Abgrall98a4f7e2011-09-02 15:36:33 -07001414 REG_JNI(register_android_server_NetworkManagementSocketTagger),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001415 REG_JNI(register_android_ddm_DdmHandleNativeHeap),
Joe Onorato1cf58742009-06-12 11:06:24 -07001416 REG_JNI(register_android_backup_BackupDataInput),
Joe Onoratod2110db2009-05-19 13:41:21 -07001417 REG_JNI(register_android_backup_BackupDataOutput),
Joe Onorato06290a42009-06-18 20:10:37 -07001418 REG_JNI(register_android_backup_FileBackupHelperBase),
Joe Onorato4ababd92009-06-25 18:29:18 -04001419 REG_JNI(register_android_backup_BackupHelperDispatcher),
Christopher Tate4a627c72011-04-01 14:43:32 -07001420 REG_JNI(register_android_app_backup_FullBackup),
Chet Haase9c1e23b2011-03-24 10:51:31 -07001421 REG_JNI(register_android_app_ActivityThread),
Dianne Hackborn69969e42010-05-04 11:40:40 -07001422 REG_JNI(register_android_app_NativeActivity),
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001423 REG_JNI(register_android_view_InputChannel),
Jeff Brown32cbc38552011-12-01 14:01:49 -08001424 REG_JNI(register_android_view_InputEventReceiver),
Jeff Brownc28867a2013-03-26 15:42:39 -07001425 REG_JNI(register_android_view_InputEventSender),
Michael Wrighta44dd262013-04-10 21:12:00 -07001426 REG_JNI(register_android_view_InputQueue),
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001427 REG_JNI(register_android_view_KeyEvent),
1428 REG_JNI(register_android_view_MotionEvent),
Jeff Brown2352b972011-04-12 22:39:53 -07001429 REG_JNI(register_android_view_PointerIcon),
Jeff Brown2ed24622011-03-14 19:39:54 -07001430 REG_JNI(register_android_view_VelocityTracker),
Kenny Root02c87302010-07-01 08:10:18 -07001431
1432 REG_JNI(register_android_content_res_ObbScanner),
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -07001433 REG_JNI(register_android_content_res_Configuration),
Chet Haase6e0ecb42010-11-03 19:41:18 -07001434
1435 REG_JNI(register_android_animation_PropertyValuesHolder),
Kenny Root66269ea2011-07-12 14:14:01 -07001436 REG_JNI(register_com_android_internal_content_NativeLibraryHelper),
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -08001437 REG_JNI(register_com_android_internal_net_NetworkStatsFactory),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001438};
1439
1440/*
1441 * Register android native functions with the VM.
1442 */
1443/*static*/ int AndroidRuntime::startReg(JNIEnv* env)
1444{
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001445 ATRACE_NAME("RegisterAndroidNatives");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 /*
1447 * This hook causes all future threads created in this process to be
1448 * attached to the JavaVM. (This needs to go away in favor of JNI
1449 * Attach calls.)
1450 */
1451 androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc);
1452
Steve Block71f2cf12011-10-20 11:56:00 +01001453 ALOGV("--- registering native functions ---\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001454
1455 /*
1456 * Every "register" function calls one or more things that return
1457 * a local reference (e.g. FindClass). Because we haven't really
1458 * started the VM yet, they're all getting stored in the base frame
1459 * and never released. Use Push/Pop to manage the storage.
1460 */
1461 env->PushLocalFrame(200);
1462
1463 if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) {
1464 env->PopLocalFrame(NULL);
1465 return -1;
1466 }
1467 env->PopLocalFrame(NULL);
1468
1469 //createJavaThread("fubar", quickTest, (void*) "hello");
1470
1471 return 0;
1472}
1473
1474AndroidRuntime* AndroidRuntime::getRuntime()
1475{
1476 return gCurRuntime;
1477}
1478
1479/**
Narayan Kamathc21dab92015-06-25 14:22:00 +01001480 * Used by surface flinger's DdmConnection to register native methods from
1481 * the framework.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001482 */
Narayan Kamathc21dab92015-06-25 14:22:00 +01001483extern "C" jint registerFrameworkNatives(JNIEnv* env) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001484 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1485}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486} // namespace android