blob: 0bacebda69b97f1bbf8487db57ed265dfde957c8 [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);
113extern int register_android_content_StringBlock(JNIEnv* env);
114extern int register_android_content_XmlBlock(JNIEnv* env);
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700115extern int register_android_emoji_EmojiFactory(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116extern 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);
Przemyslaw Szczepaniak6a8ad6d2015-11-03 09:47:56 +0000179extern int register_android_util_jar_StrictJarFile(JNIEnv* env);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700180extern int register_android_view_InputChannel(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700181extern int register_android_view_InputDevice(JNIEnv* env);
Jeff Brown32cbc38552011-12-01 14:01:49 -0800182extern int register_android_view_InputEventReceiver(JNIEnv* env);
Jeff Brownc28867a2013-03-26 15:42:39 -0700183extern int register_android_view_InputEventSender(JNIEnv* env);
Michael Wrighta44dd262013-04-10 21:12:00 -0700184extern int register_android_view_InputQueue(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700185extern int register_android_view_KeyCharacterMap(JNIEnv *env);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700186extern int register_android_view_KeyEvent(JNIEnv* env);
187extern int register_android_view_MotionEvent(JNIEnv* env);
Jeff Brown2352b972011-04-12 22:39:53 -0700188extern int register_android_view_PointerIcon(JNIEnv* env);
Jeff Brown2ed24622011-03-14 19:39:54 -0700189extern int register_android_view_VelocityTracker(JNIEnv* env);
Kenny Root02c87302010-07-01 08:10:18 -0700190extern int register_android_content_res_ObbScanner(JNIEnv* env);
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700191extern int register_android_content_res_Configuration(JNIEnv* env);
Chet Haase6e0ecb42010-11-03 19:41:18 -0700192extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
Kenny Root66269ea2011-07-12 14:14:01 -0700193extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -0800194extern int register_com_android_internal_net_NetworkStatsFactory(JNIEnv *env);
Dimitry Ivanov5d7d7772016-04-20 14:09:32 -0700195extern int register_com_android_internal_os_PathClassLoaderFactory(JNIEnv* env);
Narayan Kamath973b4662014-03-31 13:41:26 +0100196extern int register_com_android_internal_os_Zygote(JNIEnv *env);
John Reck9fa40712014-05-09 15:26:59 -0700197extern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198
199static AndroidRuntime* gCurRuntime = NULL;
200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201/*
202 * Code written in the Java Programming Language calls here from main().
203 */
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700204static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205{
206 gCurRuntime->onStarted();
207}
208
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700209static void com_android_internal_os_RuntimeInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210{
211 gCurRuntime->onZygoteInit();
212}
213
Jeff Brown4280c4a2012-03-15 17:48:02 -0700214static void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIEnv* env,
215 jobject clazz, jboolean exitWithoutCleanup)
216{
217 gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup);
218}
219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220/*
221 * JNI registration.
222 */
Daniel Micay76f6a862015-09-19 17:31:01 -0400223static const JNINativeMethod gMethods[] = {
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700224 { "nativeFinishInit", "()V",
225 (void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
226 { "nativeZygoteInit", "()V",
227 (void*) com_android_internal_os_RuntimeInit_nativeZygoteInit },
Jeff Brown4280c4a2012-03-15 17:48:02 -0700228 { "nativeSetExitWithoutCleanup", "(Z)V",
229 (void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230};
231
232int register_com_android_internal_os_RuntimeInit(JNIEnv* env)
233{
234 return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
235 gMethods, NELEM(gMethods));
236}
237
238// ----------------------------------------------------------------------
239
Andreas Huber9ae000c2014-02-13 17:22:33 +0000240/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
241
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000242AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) :
243 mExitWithoutCleanup(false),
244 mArgBlockStart(argBlockStart),
245 mArgBlockLength(argBlockLength)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700247 SkGraphics::Init();
Ben Wagner177612332015-01-15 14:16:46 -0500248 // There is also a global font cache, but its budget is specified by
249 // SK_DEFAULT_FONT_CACHE_COUNT_LIMIT and SK_DEFAULT_FONT_CACHE_LIMIT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250
251 // Pre-allocate enough space to hold a fair number of options.
252 mOptions.setCapacity(20);
253
254 assert(gCurRuntime == NULL); // one per process
255 gCurRuntime = this;
256}
257
258AndroidRuntime::~AndroidRuntime()
259{
260 SkGraphics::Term();
261}
262
Andreas Huber9ae000c2014-02-13 17:22:33 +0000263/*
264 * Register native methods using JNI.
265 */
266/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
267 const char* className, const JNINativeMethod* gMethods, int numMethods)
268{
269 return jniRegisterNativeMethods(env, className, gMethods, numMethods);
270}
271
Dmitriy Filchenkof5b6e552016-07-18 16:00:35 -0700272void AndroidRuntime::setArgv0(const char* argv0, bool setProcName) {
273 if (setProcName) {
274 int len = strlen(argv0);
275 if (len < 15) {
276 pthread_setname_np(pthread_self(), argv0);
277 } else {
278 pthread_setname_np(pthread_self(), argv0 + len - 15);
279 }
280 }
Jeff Brown00c0cd42014-09-10 16:48:46 -0700281 memset(mArgBlockStart, 0, mArgBlockLength);
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000282 strlcpy(mArgBlockStart, argv0, mArgBlockLength);
283}
284
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100285status_t AndroidRuntime::callMain(const String8& className, jclass clazz,
286 const Vector<String8>& args)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287{
288 JNIEnv* env;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289 jmethodID methodId;
290
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100291 ALOGD("Calling main entry %s", className.string());
Dianne Hackborn08e60f22010-09-01 18:17:17 -0700292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 env = getJNIEnv();
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700294 if (clazz == NULL || env == NULL) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 return UNKNOWN_ERROR;
296 }
297
298 methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
299 if (methodId == NULL) {
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100300 ALOGE("ERROR: could not find method %s.main(String[])\n", className.string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 return UNKNOWN_ERROR;
302 }
303
304 /*
305 * We want to call main() with a String array with our arguments in it.
306 * Create an array and populate it.
307 */
308 jclass stringClass;
309 jobjectArray strArray;
310
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100311 const size_t numArgs = args.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312 stringClass = env->FindClass("java/lang/String");
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100313 strArray = env->NewObjectArray(numArgs, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100315 for (size_t i = 0; i < numArgs; i++) {
316 jstring argStr = env->NewStringUTF(args[i].string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 env->SetObjectArrayElement(strArray, i, argStr);
318 }
319
320 env->CallStaticVoidMethod(clazz, methodId, strArray);
321 return NO_ERROR;
322}
323
324/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 * The VM calls this through the "exit" hook.
326 */
327static void runtime_exit(int code)
328{
Jeff Brown4280c4a2012-03-15 17:48:02 -0700329 gCurRuntime->exit(code);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330}
331
332/*
333 * The VM calls this through the "vfprintf" hook.
334 *
335 * We ignore "fp" and just write the results to the log file.
336 */
337static void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
338{
339 LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
340}
341
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800342/**
343 * The VM calls this when mutex contention debugging is enabled to
344 * determine whether or not the blocked thread was a "sensitive thread"
345 * for user responsiveness/smoothess.
346 *
347 * Our policy for this is whether or not we're tracing any StrictMode
348 * events on this thread (which we might've inherited via Binder calls
349 * into us)
350 */
351static bool runtime_isSensitiveThread() {
352 IPCThreadState* state = IPCThreadState::selfOrNull();
353 return state && state->getStrictModePolicy() != 0;
354}
355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356static int hasDir(const char* dir)
357{
358 struct stat s;
359 int res = stat(dir, &s);
360 if (res == 0) {
361 return S_ISDIR(s.st_mode);
362 }
363 return 0;
364}
365
Andreas Gampe995c62d2014-11-14 16:15:17 -0800366static bool hasFile(const char* file) {
367 struct stat s;
368 int res = stat(file, &s);
369 if (res == 0) {
370 return S_ISREG(s.st_mode);
371 }
372 return false;
373}
374
Narayan Kamathbf882052015-08-11 15:40:34 +0100375// Convenience wrapper over the property API that returns an
376// std::string.
377std::string getProperty(const char* key, const char* defaultValue) {
378 std::vector<char> temp(PROPERTY_VALUE_MAX);
379 const int len = property_get(key, &temp[0], defaultValue);
380 if (len < 0) {
381 return "";
382 }
383 return std::string(&temp[0], len);
384}
385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386/*
Narayan Kamathbf882052015-08-11 15:40:34 +0100387 * Read the persistent locale. Inspects the following system properties
388 * (in order) and returns the first non-empty property in the list :
389 *
390 * (1) persist.sys.locale
391 * (2) persist.sys.language/country/localevar (country and localevar are
392 * inspected iff. language is non-empty.
393 * (3) ro.product.locale
394 * (4) ro.product.locale.language/region
395 *
396 * Note that we need to inspect persist.sys.language/country/localevar to
397 * preserve language settings for devices that are upgrading from Lollipop
398 * to M. The same goes for ro.product.locale.language/region as well.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 */
Narayan Kamathbf882052015-08-11 15:40:34 +0100400const std::string readLocale()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401{
Narayan Kamathbf882052015-08-11 15:40:34 +0100402 const std::string locale = getProperty("persist.sys.locale", "");
403 if (!locale.empty()) {
404 return locale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 }
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000406
Narayan Kamathbf882052015-08-11 15:40:34 +0100407 const std::string language = getProperty("persist.sys.language", "");
408 if (!language.empty()) {
409 const std::string country = getProperty("persist.sys.country", "");
410 const std::string variant = getProperty("persist.sys.localevar", "");
411
412 std::string out = language;
413 if (!country.empty()) {
414 out = out + "-" + country;
415 }
416
417 if (!variant.empty()) {
418 out = out + "-" + variant;
419 }
420
421 return out;
422 }
423
424 const std::string productLocale = getProperty("ro.product.locale", "");
425 if (!productLocale.empty()) {
426 return productLocale;
427 }
428
429 // If persist.sys.locale and ro.product.locale are missing,
430 // construct a locale value from the individual locale components.
431 const std::string productLanguage = getProperty("ro.product.locale.language", "en");
432 const std::string productRegion = getProperty("ro.product.locale.region", "US");
433
434 return productLanguage + "-" + productRegion;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435}
436
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700437void AndroidRuntime::addOption(const char* optionString, void* extraInfo)
438{
439 JavaVMOption opt;
440 opt.optionString = optionString;
441 opt.extraInfo = extraInfo;
442 mOptions.add(opt);
443}
444
Andy McFaddenf70188a2009-03-31 15:52:13 -0700445/*
Andy McFaddene4d81f22010-07-14 16:02:20 -0700446 * Parse a property containing space-separated options that should be
447 * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
448 *
449 * This will cut up "extraOptsBuf" as we chop it into individual options.
450 *
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800451 * If "quotingArg" is non-null, it is passed before each extra option in mOptions.
452 *
Andy McFaddene4d81f22010-07-14 16:02:20 -0700453 * Adds the strings, if any, to mOptions.
454 */
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800455void AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg)
Andy McFaddene4d81f22010-07-14 16:02:20 -0700456{
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800457 char* start = extraOptsBuf;
458 char* end = NULL;
Andy McFaddene4d81f22010-07-14 16:02:20 -0700459 while (*start != '\0') {
460 while (*start == ' ') /* skip leading whitespace */
461 start++;
462 if (*start == '\0') /* was trailing ws, bail */
463 break;
464
465 end = start+1;
466 while (*end != ' ' && *end != '\0') /* find end of token */
467 end++;
468 if (*end == ' ')
469 *end++ = '\0'; /* mark end, advance to indicate more */
470
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800471 if (quotingArg != NULL) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700472 addOption(quotingArg);
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800473 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700474 addOption(start);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700475 start = end;
476 }
477}
478
479/*
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700480 * Reads a "property" into "buffer" with a default of "defaultArg". If
481 * the property is non-empty, it is treated as a runtime option such
482 * as "-Xmx32m".
483 *
484 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
485 *
486 * If an argument is found, it is added to mOptions.
487 *
488 * If an option is found, it is added to mOptions and true is
489 * returned. Otherwise false is returned.
490 */
491bool AndroidRuntime::parseRuntimeOption(const char* property,
492 char* buffer,
493 const char* runtimeArg,
494 const char* defaultArg)
495{
496 strcpy(buffer, runtimeArg);
497 size_t runtimeArgLen = strlen(runtimeArg);
498 property_get(property, buffer+runtimeArgLen, defaultArg);
499 if (buffer[runtimeArgLen] == '\0') {
500 return false;
501 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700502 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700503 return true;
504}
505
506/*
507 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700508 * is treated as a dex2oat compiler option that should be
509 * passed as a quoted option, e.g. "-Ximage-compiler-option --compiler-filter=verify-none".
510 *
511 * The "compilerArg" is a prefix for the option such as "--compiler-filter=".
512 *
513 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
514 *
515 * If an option is found, it is added to mOptions and true is
516 * returned. Otherwise false is returned.
517 */
518bool AndroidRuntime::parseCompilerOption(const char* property,
519 char* buffer,
520 const char* compilerArg,
521 const char* quotingArg)
522{
523 strcpy(buffer, compilerArg);
524 size_t compilerArgLen = strlen(compilerArg);
525 property_get(property, buffer+compilerArgLen, "");
526 if (buffer[compilerArgLen] == '\0') {
527 return false;
528 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700529 addOption(quotingArg);
530 addOption(buffer);
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700531 return true;
532}
533
534/*
535 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700536 * is treated as a dex2oat compiler runtime option that should be
537 * passed as a quoted option, e.g. "-Ximage-compiler-option
538 * --runtime-arg -Ximage-compiler-option -Xmx32m".
539 *
540 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
541 *
542 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
543 *
544 * If an option is found, it is added to mOptions and true is
545 * returned. Otherwise false is returned.
546 */
547bool AndroidRuntime::parseCompilerRuntimeOption(const char* property,
548 char* buffer,
549 const char* runtimeArg,
550 const char* quotingArg)
551{
552 strcpy(buffer, runtimeArg);
553 size_t runtimeArgLen = strlen(runtimeArg);
554 property_get(property, buffer+runtimeArgLen, "");
555 if (buffer[runtimeArgLen] == '\0') {
556 return false;
557 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700558 addOption(quotingArg);
559 addOption("--runtime-arg");
560 addOption(quotingArg);
561 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700562 return true;
563}
564
565/*
Andy McFaddenf70188a2009-03-31 15:52:13 -0700566 * Start the Dalvik Virtual Machine.
567 *
568 * Various arguments, most determined by system properties, are passed in.
569 * The "mOptions" vector is updated.
570 *
Dave Allison07a1e232014-03-14 08:54:33 -0700571 * CAUTION: when adding options in here, be careful not to put the
572 * char buffer inside a nested scope. Adding the buffer to the
573 * options using mOptions.add() does not copy the buffer, so if the
574 * buffer goes out of scope the option may be overwritten. It's best
575 * to put the buffer at the top of the function so that it is more
576 * unlikely that someone will surround it in a scope at a later time
577 * and thus introduce a bug.
578 *
Andy McFaddenf70188a2009-03-31 15:52:13 -0700579 * Returns 0 on success.
580 */
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200581int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 JavaVMInitArgs initArgs;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 char propBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700585 char stackTraceFileBuf[sizeof("-Xstacktracefile:")-1 + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro38cfa8c2010-12-07 16:48:29 -0800587 char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700588 char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro8cdf27c2011-01-19 12:33:12 -0800589 char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700590 char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
591 char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800592 char usejitOptsBuf[sizeof("-Xusejit:")-1 + PROPERTY_VALUE_MAX];
Nicolas Geoffraycdf1dff2015-11-19 13:48:35 +0000593 char jitmaxsizeOptsBuf[sizeof("-Xjitmaxsize:")-1 + PROPERTY_VALUE_MAX];
594 char jitinitialsizeOptsBuf[sizeof("-Xjitinitialsize:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800595 char jitthresholdOptsBuf[sizeof("-Xjitthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravlee86e8a62016-04-22 16:40:50 +0100596 char useJitProfilesOptsBuf[sizeof("-Xjitsaveprofilinginfo:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle0de80b92016-04-12 14:12:04 +0100597 char jitprithreadweightOptBuf[sizeof("-Xjitprithreadweight:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle7116e4b2016-04-27 14:12:00 +0100598 char jittransitionweightOptBuf[sizeof("-Xjittransitionweight:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier7e4fdec2013-12-02 15:46:51 -0800599 char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700600 char backgroundgcOptsBuf[sizeof("-XX:BackgroundGC=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700601 char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee324ba02015-03-31 16:15:17 -0700602 char cachePruneBuf[sizeof("-Xzygote-max-boot-retry=")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700603 char dex2oatXmsImageFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
604 char dex2oatXmxImageFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
605 char dex2oatXmsFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
606 char dex2oatXmxFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700607 char dex2oatCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
608 char dex2oatImageCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee0352382015-03-30 18:43:39 -0700609 char dex2oatThreadsBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
610 char dex2oatThreadsImageBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
Andreas Gampe605cca12015-04-02 23:12:56 -0700611 char dex2oat_isa_variant_key[PROPERTY_KEY_MAX];
612 char dex2oat_isa_variant[sizeof("--instruction-set-variant=") -1 + PROPERTY_VALUE_MAX];
613 char dex2oat_isa_features_key[PROPERTY_KEY_MAX];
614 char dex2oat_isa_features[sizeof("--instruction-set-features=") -1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800615 char dex2oatFlagsBuf[PROPERTY_VALUE_MAX];
616 char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX];
Andy McFaddene4d81f22010-07-14 16:02:20 -0700617 char extraOptsBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700618 char voldDecryptBuf[PROPERTY_VALUE_MAX];
Ben Cheng52b0e732009-06-19 13:31:12 -0700619 enum {
620 kEMDefault,
621 kEMIntPortable,
622 kEMIntFast,
Ben Cheng52b0e732009-06-19 13:31:12 -0700623 kEMJitCompiler,
Ben Cheng52b0e732009-06-19 13:31:12 -0700624 } executionMode = kEMDefault;
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000625 char localeOption[sizeof("-Duser.locale=") + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700626 char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle01db9162014-08-07 14:45:53 +0100627 char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX];
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700628 char cpuAbiListBuf[sizeof("--cpu-abilist=") + PROPERTY_VALUE_MAX];
Andreas Gampe98f406f2015-06-22 21:09:36 -0700629 char methodTraceFileBuf[sizeof("-Xmethod-trace-file:") + PROPERTY_VALUE_MAX];
630 char methodTraceFileSizeBuf[sizeof("-Xmethod-trace-file-size:") + PROPERTY_VALUE_MAX];
Andreas Gampee6082502015-07-24 14:19:44 -0700631 char fingerprintBuf[sizeof("-Xfingerprint:") + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700633 bool checkJni = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800634 property_get("dalvik.vm.checkjni", propBuf, "");
635 if (strcmp(propBuf, "true") == 0) {
636 checkJni = true;
637 } else if (strcmp(propBuf, "false") != 0) {
638 /* property is neither true nor false; fall back on kernel parameter */
639 property_get("ro.kernel.android.checkjni", propBuf, "");
640 if (propBuf[0] == '1') {
641 checkJni = true;
642 }
643 }
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700644 ALOGD("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
645 if (checkJni) {
646 /* extended JNI checking */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700647 addOption("-Xcheck:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700648
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700649 /* with -Xcheck:jni, this provides a JNI function call trace */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700650 //addOption("-verbose:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700651 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652
653 property_get("dalvik.vm.execution-mode", propBuf, "");
654 if (strcmp(propBuf, "int:portable") == 0) {
655 executionMode = kEMIntPortable;
656 } else if (strcmp(propBuf, "int:fast") == 0) {
657 executionMode = kEMIntFast;
Ben Cheng52b0e732009-06-19 13:31:12 -0700658 } else if (strcmp(propBuf, "int:jit") == 0) {
659 executionMode = kEMJitCompiler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800660 }
661
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700662 parseRuntimeOption("dalvik.vm.stack-trace-file", stackTraceFileBuf, "-Xstacktracefile:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800664 strcpy(jniOptsBuf, "-Xjniopts:");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700665 if (parseRuntimeOption("dalvik.vm.jniopts", jniOptsBuf, "-Xjniopts:")) {
666 ALOGI("JNI options: '%s'\n", jniOptsBuf);
667 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 /* route exit() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700670 addOption("exit", (void*) runtime_exit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671
672 /* route fprintf() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700673 addOption("vfprintf", (void*) runtime_vfprintf);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800675 /* register the framework-specific "is sensitive thread" hook */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700676 addOption("sensitiveThread", (void*) runtime_isSensitiveThread);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677
678 /* enable verbose; standard options are { jni, gc, class } */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700679 //addOption("-verbose:jni");
680 addOption("-verbose:gc");
681 //addOption("-verbose:class");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682
Carl Shapiro9e4c8842010-12-08 12:14:46 -0800683 /*
684 * The default starting and maximum size of the heap. Larger
685 * values should be specified in a product property override.
686 */
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700687 parseRuntimeOption("dalvik.vm.heapstartsize", heapstartsizeOptsBuf, "-Xms", "4m");
688 parseRuntimeOption("dalvik.vm.heapsize", heapsizeOptsBuf, "-Xmx", "16m");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700690 parseRuntimeOption("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
691 parseRuntimeOption("dalvik.vm.heapminfree", heapminfreeOptsBuf, "-XX:HeapMinFree=");
692 parseRuntimeOption("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf, "-XX:HeapMaxFree=");
693 parseRuntimeOption("dalvik.vm.heaptargetutilization",
694 heaptargetutilizationOptsBuf,
695 "-XX:HeapTargetUtilization=");
Ian Rogers53250102012-09-23 16:38:03 -0700696
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800697 /*
698 * JIT related options.
699 */
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700700 parseRuntimeOption("dalvik.vm.usejit", usejitOptsBuf, "-Xusejit:");
Nicolas Geoffraycdf1dff2015-11-19 13:48:35 +0000701 parseRuntimeOption("dalvik.vm.jitmaxsize", jitmaxsizeOptsBuf, "-Xjitmaxsize:");
702 parseRuntimeOption("dalvik.vm.jitinitialsize", jitinitialsizeOptsBuf, "-Xjitinitialsize:");
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700703 parseRuntimeOption("dalvik.vm.jitthreshold", jitthresholdOptsBuf, "-Xjitthreshold:");
Calin Juravlee86e8a62016-04-22 16:40:50 +0100704 property_get("dalvik.vm.usejitprofiles", useJitProfilesOptsBuf, "");
705 if (strcmp(useJitProfilesOptsBuf, "true") == 0) {
706 addOption("-Xjitsaveprofilinginfo");
707 }
Calin Juravle7116e4b2016-04-27 14:12:00 +0100708
Calin Juravle0de80b92016-04-12 14:12:04 +0100709 parseRuntimeOption("dalvik.vm.jitprithreadweight",
710 jitprithreadweightOptBuf,
711 "-Xjitprithreadweight:");
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800712
Calin Juravle7116e4b2016-04-27 14:12:00 +0100713 parseRuntimeOption("dalvik.vm.jittransitionweight",
714 jittransitionweightOptBuf,
715 "-Xjittransitionweight:");
716
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700717 property_get("ro.config.low_ram", propBuf, "");
718 if (strcmp(propBuf, "true") == 0) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700719 addOption("-XX:LowMemoryMode");
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700720 }
721
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700722 parseRuntimeOption("dalvik.vm.gctype", gctypeOptsBuf, "-Xgc:");
723 parseRuntimeOption("dalvik.vm.backgroundgctype", backgroundgcOptsBuf, "-XX:BackgroundGC=");
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700724
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200725 /*
726 * Enable debugging only for apps forked from zygote.
727 * Set suspend=y to pause during VM init and use android ADB transport.
728 */
729 if (zygote) {
730 addOption("-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y");
731 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700733 parseRuntimeOption("dalvik.vm.lockprof.threshold",
734 lockProfThresholdBuf,
735 "-Xlockprofthreshold:");
Carl Shapirod8f3ec62010-04-12 16:31:59 -0700736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 if (executionMode == kEMIntPortable) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700738 addOption("-Xint:portable");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 } else if (executionMode == kEMIntFast) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700740 addOption("-Xint:fast");
Ben Cheng52b0e732009-06-19 13:31:12 -0700741 } else if (executionMode == kEMJitCompiler) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700742 addOption("-Xint:jit");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 }
Andy McFaddene2b23e12009-04-03 11:09:46 -0700744
Andreas Gampe08b2d582014-12-18 14:39:22 -0800745 // If we are booting without the real /data, don't spend time compiling.
746 property_get("vold.decrypt", voldDecryptBuf, "");
747 bool skip_compilation = ((strcmp(voldDecryptBuf, "trigger_restart_min_framework") == 0) ||
748 (strcmp(voldDecryptBuf, "1") == 0));
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800749
Andreas Gampe08b2d582014-12-18 14:39:22 -0800750 // Extra options for boot.art/boot.oat image generation.
751 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xms", dex2oatXmsImageFlagsBuf,
752 "-Xms", "-Ximage-compiler-option");
753 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xmx", dex2oatXmxImageFlagsBuf,
754 "-Xmx", "-Ximage-compiler-option");
755 if (skip_compilation) {
Brian Carlstromce5bbbe2014-07-30 15:13:17 -0700756 addOption("-Ximage-compiler-option");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800757 addOption("--compiler-filter=verify-none");
758 } else {
759 parseCompilerOption("dalvik.vm.image-dex2oat-filter", dex2oatImageCompilerFilterBuf,
760 "--compiler-filter=", "-Ximage-compiler-option");
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800761 }
762
Andreas Gampe08b2d582014-12-18 14:39:22 -0800763 // Make sure there is a preloaded-classes file.
764 if (!hasFile("/system/etc/preloaded-classes")) {
765 ALOGE("Missing preloaded-classes file, /system/etc/preloaded-classes not found: %s\n",
766 strerror(errno));
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700767 return -1;
Andreas Gampe08b2d582014-12-18 14:39:22 -0800768 }
769 addOption("-Ximage-compiler-option");
770 addOption("--image-classes=/system/etc/preloaded-classes");
771
772 // If there is a compiled-classes file, push it.
773 if (hasFile("/system/etc/compiled-classes")) {
774 addOption("-Ximage-compiler-option");
775 addOption("--compiled-classes=/system/etc/compiled-classes");
776 }
777
778 property_get("dalvik.vm.image-dex2oat-flags", dex2oatImageFlagsBuf, "");
779 parseExtraOpts(dex2oatImageFlagsBuf, "-Ximage-compiler-option");
780
781 // Extra options for DexClassLoader.
782 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xms", dex2oatXmsFlagsBuf,
783 "-Xms", "-Xcompiler-option");
784 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xmx", dex2oatXmxFlagsBuf,
785 "-Xmx", "-Xcompiler-option");
786 if (skip_compilation) {
787 addOption("-Xcompiler-option");
788 addOption("--compiler-filter=verify-none");
neo.chae155118f2015-01-07 15:32:15 +0900789
790 // We skip compilation when a minimal runtime is brought up for decryption. In that case
791 // /data is temporarily backed by a tmpfs, which is usually small.
792 // If the system image contains prebuilts, they will be relocated into the tmpfs. In this
793 // specific situation it is acceptable to *not* relocate and run out of the prebuilts
794 // directly instead.
795 addOption("--runtime-arg");
796 addOption("-Xnorelocate");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800797 } else {
798 parseCompilerOption("dalvik.vm.dex2oat-filter", dex2oatCompilerFilterBuf,
799 "--compiler-filter=", "-Xcompiler-option");
800 }
Andreas Gampee0352382015-03-30 18:43:39 -0700801 parseCompilerOption("dalvik.vm.dex2oat-threads", dex2oatThreadsBuf, "-j", "-Xcompiler-option");
802 parseCompilerOption("dalvik.vm.image-dex2oat-threads", dex2oatThreadsImageBuf, "-j",
803 "-Ximage-compiler-option");
Andreas Gampe605cca12015-04-02 23:12:56 -0700804
805 // The runtime will compile a boot image, when necessary, not using installd. Thus, we need to
806 // pass the instruction-set-features/variant as an image-compiler-option.
807 // TODO: Find a better way for the instruction-set.
808#if defined(__arm__)
809 constexpr const char* instruction_set = "arm";
810#elif defined(__aarch64__)
811 constexpr const char* instruction_set = "arm64";
812#elif defined(__mips__) && !defined(__LP64__)
813 constexpr const char* instruction_set = "mips";
814#elif defined(__mips__) && defined(__LP64__)
815 constexpr const char* instruction_set = "mips64";
816#elif defined(__i386__)
817 constexpr const char* instruction_set = "x86";
818#elif defined(__x86_64__)
819 constexpr const char* instruction_set = "x86_64";
820#else
821 constexpr const char* instruction_set = "unknown";
822#endif
823 // Note: it is OK to reuse the buffer, as the values are exactly the same between
824 // * compiler-option, used for runtime compilation (DexClassLoader)
825 // * image-compiler-option, used for boot-image compilation on device
826
827 // Copy the variant.
828 sprintf(dex2oat_isa_variant_key, "dalvik.vm.isa.%s.variant", instruction_set);
829 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
830 "--instruction-set-variant=", "-Ximage-compiler-option");
831 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
832 "--instruction-set-variant=", "-Xcompiler-option");
833 // Copy the features.
834 sprintf(dex2oat_isa_features_key, "dalvik.vm.isa.%s.features", instruction_set);
835 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
836 "--instruction-set-features=", "-Ximage-compiler-option");
837 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
838 "--instruction-set-features=", "-Xcompiler-option");
839
840
Andreas Gampe08b2d582014-12-18 14:39:22 -0800841 property_get("dalvik.vm.dex2oat-flags", dex2oatFlagsBuf, "");
842 parseExtraOpts(dex2oatFlagsBuf, "-Xcompiler-option");
843
Andy McFaddene4d81f22010-07-14 16:02:20 -0700844 /* extra options; parse this late so it overrides others */
845 property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800846 parseExtraOpts(extraOptsBuf, NULL);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 /* Set the properties for locale */
849 {
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000850 strcpy(localeOption, "-Duser.locale=");
Narayan Kamathbf882052015-08-11 15:40:34 +0100851 const std::string locale = readLocale();
852 strncat(localeOption, locale.c_str(), PROPERTY_VALUE_MAX);
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000853 addOption(localeOption);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 }
855
Calin Juravle92290b82015-11-10 19:30:45 +0000856 // Trace files are stored in /data/misc/trace which is writable only in debug mode.
857 property_get("ro.debuggable", propBuf, "0");
858 if (strcmp(propBuf, "1") == 0) {
859 property_get("dalvik.vm.method-trace", propBuf, "false");
Andreas Gampe98f406f2015-06-22 21:09:36 -0700860 if (strcmp(propBuf, "true") == 0) {
Calin Juravle92290b82015-11-10 19:30:45 +0000861 addOption("-Xmethod-trace");
862 parseRuntimeOption("dalvik.vm.method-trace-file",
863 methodTraceFileBuf,
864 "-Xmethod-trace-file:");
865 parseRuntimeOption("dalvik.vm.method-trace-file-siz",
866 methodTraceFileSizeBuf,
867 "-Xmethod-trace-file-size:");
868 property_get("dalvik.vm.method-trace-stream", propBuf, "false");
869 if (strcmp(propBuf, "true") == 0) {
870 addOption("-Xmethod-trace-stream");
871 }
Andreas Gampe98f406f2015-06-22 21:09:36 -0700872 }
873 }
874
Andreas Gampe08b2d582014-12-18 14:39:22 -0800875 // Native bridge library. "0" means that native bridge is disabled.
876 property_get("ro.dalvik.vm.native.bridge", propBuf, "");
877 if (propBuf[0] == '\0') {
878 ALOGW("ro.dalvik.vm.native.bridge is not expected to be empty");
879 } else if (strcmp(propBuf, "0") != 0) {
880 snprintf(nativeBridgeLibrary, sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX,
881 "-XX:NativeBridge=%s", propBuf);
882 addOption(nativeBridgeLibrary);
Calin Juravlebe20ed42014-08-26 23:00:11 +0100883 }
Calin Juravle01db9162014-08-07 14:45:53 +0100884
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700885#if defined(__LP64__)
886 const char* cpu_abilist_property_name = "ro.product.cpu.abilist64";
887#else
888 const char* cpu_abilist_property_name = "ro.product.cpu.abilist32";
889#endif // defined(__LP64__)
890 property_get(cpu_abilist_property_name, propBuf, "");
891 if (propBuf[0] == '\0') {
892 ALOGE("%s is not expected to be empty", cpu_abilist_property_name);
893 return -1;
894 }
895 snprintf(cpuAbiListBuf, sizeof(cpuAbiListBuf), "--cpu-abilist=%s", propBuf);
896 addOption(cpuAbiListBuf);
897
Andreas Gampee324ba02015-03-31 16:15:17 -0700898 // Dalvik-cache pruning counter.
899 parseRuntimeOption("dalvik.vm.zygote.max-boot-retry", cachePruneBuf,
900 "-Xzygote-max-boot-retry=");
901
Andreas Gampe27c39f12015-04-27 18:28:18 +0000902 /*
David Srbecky065075e2015-05-28 17:16:09 +0100903 * When running with debug.generate-debug-info, add --generate-debug-info to
904 * the compiler options so that the boot image, if it is compiled on device,
905 * will include native debugging information.
Andreas Gampe27c39f12015-04-27 18:28:18 +0000906 */
David Srbecky065075e2015-05-28 17:16:09 +0100907 property_get("debug.generate-debug-info", propBuf, "");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000908 if (strcmp(propBuf, "true") == 0) {
909 addOption("-Xcompiler-option");
David Srbecky065075e2015-05-28 17:16:09 +0100910 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000911 addOption("-Ximage-compiler-option");
David Srbecky065075e2015-05-28 17:16:09 +0100912 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000913 }
914
Andreas Gampee6082502015-07-24 14:19:44 -0700915 /*
916 * Retrieve the build fingerprint and provide it to the runtime. That way, ANR dumps will
917 * contain the fingerprint and can be parsed.
918 */
919 parseRuntimeOption("ro.build.fingerprint", fingerprintBuf, "-Xfingerprint:");
920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 initArgs.version = JNI_VERSION_1_4;
922 initArgs.options = mOptions.editArray();
923 initArgs.nOptions = mOptions.size();
924 initArgs.ignoreUnrecognized = JNI_FALSE;
925
926 /*
927 * Initialize the VM.
928 *
929 * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread.
930 * If this call succeeds, the VM is ready, and we can start issuing
931 * JNI calls.
932 */
Andy McFaddenf70188a2009-03-31 15:52:13 -0700933 if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) {
Steve Block3762c312012-01-06 19:20:56 +0000934 ALOGE("JNI_CreateJavaVM failed\n");
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700935 return -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 }
937
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700938 return 0;
Andy McFaddenf70188a2009-03-31 15:52:13 -0700939}
940
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700941char* AndroidRuntime::toSlashClassName(const char* className)
942{
943 char* result = strdup(className);
944 for (char* cp = result; *cp != '\0'; cp++) {
945 if (*cp == '.') {
946 *cp = '/';
947 }
948 }
949 return result;
950}
951
Mike Lockwood9ee5e7e2014-09-08 16:15:21 -0700952/** Create a Java string from an ASCII or Latin-1 string */
953jstring AndroidRuntime::NewStringLatin1(JNIEnv* env, const char* bytes) {
954 if (!bytes) return NULL;
955 int length = strlen(bytes);
956 jchar* buffer = (jchar *)alloca(length * sizeof(jchar));
957 if (!buffer) return NULL;
958 jchar* chp = buffer;
959 for (int i = 0; i < length; i++) {
960 *chp++ = *bytes++;
961 }
962 return env->NewString(buffer, length);
963}
964
965
Andy McFaddenf70188a2009-03-31 15:52:13 -0700966/*
967 * Start the Android runtime. This involves starting the virtual machine
968 * and calling the "static void main(String[] args)" method in the class
969 * named by "className".
Jeff Brownebed7d62011-05-16 17:08:42 -0700970 *
971 * Passes the main function two arguments, the class name and the specified
972 * options string.
Andy McFaddenf70188a2009-03-31 15:52:13 -0700973 */
Sebastien Hertz7a09b832015-08-10 18:55:34 +0200974void AndroidRuntime::start(const char* className, const Vector<String8>& options, bool zygote)
Andy McFaddenf70188a2009-03-31 15:52:13 -0700975{
Dianne Hackborn8e5aafe2014-10-27 18:04:10 -0700976 ALOGD(">>>>>> START %s uid %d <<<<<<\n",
977 className != NULL ? className : "(unknown)", getuid());
Andy McFaddenf70188a2009-03-31 15:52:13 -0700978
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100979 static const String8 startSystemServer("start-system-server");
980
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700981 /*
982 * 'startSystemServer == true' means runtime is obsolete and not run from
Andy McFaddenf70188a2009-03-31 15:52:13 -0700983 * init.rc anymore, so we print out the boot start event here.
984 */
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100985 for (size_t i = 0; i < options.size(); ++i) {
986 if (options[i] == startSystemServer) {
987 /* track our progress through the boot sequence */
988 const int LOG_BOOT_PROGRESS_START = 3000;
989 LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));
990 }
Andy McFaddenf70188a2009-03-31 15:52:13 -0700991 }
992
993 const char* rootDir = getenv("ANDROID_ROOT");
994 if (rootDir == NULL) {
995 rootDir = "/system";
996 if (!hasDir("/system")) {
997 LOG_FATAL("No root directory specified, and /android does not exist.");
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700998 return;
Andy McFaddenf70188a2009-03-31 15:52:13 -0700999 }
1000 setenv("ANDROID_ROOT", rootDir, 1);
1001 }
1002
1003 //const char* kernelHack = getenv("LD_ASSUME_KERNEL");
Steve Block5baa3a62011-12-20 16:23:08 +00001004 //ALOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001005
1006 /* start the virtual machine */
Brian Carlstrom9f8203a2013-06-19 13:49:36 -07001007 JniInvocation jni_invocation;
1008 jni_invocation.Init(NULL);
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001009 JNIEnv* env;
Sebastien Hertz7a09b832015-08-10 18:55:34 +02001010 if (startVm(&mJavaVM, &env, zygote) != 0) {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001011 return;
1012 }
1013 onVmCreated(env);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001015 /*
1016 * Register android functions.
1017 */
1018 if (startReg(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001019 ALOGE("Unable to register all android natives\n");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001020 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001021 }
1022
1023 /*
1024 * We want to call main() with a String array with arguments in it.
Jeff Brownebed7d62011-05-16 17:08:42 -07001025 * At present we have two arguments, the class name and an option string.
1026 * Create an array to hold them.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001027 */
1028 jclass stringClass;
1029 jobjectArray strArray;
1030 jstring classNameStr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001031
1032 stringClass = env->FindClass("java/lang/String");
1033 assert(stringClass != NULL);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001034 strArray = env->NewObjectArray(options.size() + 1, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 assert(strArray != NULL);
1036 classNameStr = env->NewStringUTF(className);
1037 assert(classNameStr != NULL);
1038 env->SetObjectArrayElement(strArray, 0, classNameStr);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001039
1040 for (size_t i = 0; i < options.size(); ++i) {
1041 jstring optionsStr = env->NewStringUTF(options.itemAt(i).string());
1042 assert(optionsStr != NULL);
1043 env->SetObjectArrayElement(strArray, i + 1, optionsStr);
1044 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045
1046 /*
1047 * Start VM. This thread becomes the main thread of the VM, and will
1048 * not return until the VM exits.
1049 */
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001050 char* slashClassName = toSlashClassName(className);
1051 jclass startClass = env->FindClass(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052 if (startClass == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001053 ALOGE("JavaVM unable to locate class '%s'\n", slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001054 /* keep going */
1055 } else {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001056 jmethodID startMeth = env->GetStaticMethodID(startClass, "main",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001057 "([Ljava/lang/String;)V");
1058 if (startMeth == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001059 ALOGE("JavaVM unable to find main() in '%s'\n", className);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001060 /* keep going */
1061 } else {
1062 env->CallStaticVoidMethod(startClass, startMeth, strArray);
1063
1064#if 0
1065 if (env->ExceptionCheck())
1066 threadExitUncaughtException(env);
1067#endif
1068 }
1069 }
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001070 free(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071
Steve Block5baa3a62011-12-20 16:23:08 +00001072 ALOGD("Shutting down VM\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 if (mJavaVM->DetachCurrentThread() != JNI_OK)
Steve Block8564c8d2012-01-05 23:22:43 +00001074 ALOGW("Warning: unable to detach main thread\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001075 if (mJavaVM->DestroyJavaVM() != 0)
Steve Block8564c8d2012-01-05 23:22:43 +00001076 ALOGW("Warning: VM did not shut down cleanly\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077}
1078
Jeff Brown4280c4a2012-03-15 17:48:02 -07001079void AndroidRuntime::exit(int code)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080{
Jeff Brown4280c4a2012-03-15 17:48:02 -07001081 if (mExitWithoutCleanup) {
1082 ALOGI("VM exiting with result code %d, cleanup skipped.", code);
1083 ::_exit(code);
1084 } else {
1085 ALOGI("VM exiting with result code %d.", code);
1086 onExit(code);
1087 ::exit(code);
1088 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089}
1090
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001091void AndroidRuntime::onVmCreated(JNIEnv* env)
1092{
1093 // If AndroidRuntime had anything to do here, we'd have done it in 'start'.
1094}
1095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096/*
Andreas Huber9ae000c2014-02-13 17:22:33 +00001097 * Get the JNIEnv pointer for this thread.
1098 *
1099 * Returns NULL if the slot wasn't allocated or populated.
1100 */
1101/*static*/ JNIEnv* AndroidRuntime::getJNIEnv()
1102{
1103 JNIEnv* env;
1104 JavaVM* vm = AndroidRuntime::getJavaVM();
1105 assert(vm != NULL);
1106
1107 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
1108 return NULL;
1109 return env;
1110}
1111
1112/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 * Makes the current thread visible to the VM.
1114 *
1115 * The JNIEnv pointer returned is only valid for the current thread, and
1116 * thus must be tucked into thread-local storage.
1117 */
1118static int javaAttachThread(const char* threadName, JNIEnv** pEnv)
1119{
1120 JavaVMAttachArgs args;
1121 JavaVM* vm;
1122 jint result;
1123
1124 vm = AndroidRuntime::getJavaVM();
1125 assert(vm != NULL);
1126
1127 args.version = JNI_VERSION_1_4;
1128 args.name = (char*) threadName;
1129 args.group = NULL;
1130
1131 result = vm->AttachCurrentThread(pEnv, (void*) &args);
1132 if (result != JNI_OK)
Steve Block6215d3f2012-01-04 20:05:49 +00001133 ALOGI("NOTE: attach of thread '%s' failed\n", threadName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134
1135 return result;
1136}
1137
1138/*
1139 * Detach the current thread from the set visible to the VM.
1140 */
1141static int javaDetachThread(void)
1142{
1143 JavaVM* vm;
1144 jint result;
1145
1146 vm = AndroidRuntime::getJavaVM();
1147 assert(vm != NULL);
1148
1149 result = vm->DetachCurrentThread();
1150 if (result != JNI_OK)
Steve Block3762c312012-01-06 19:20:56 +00001151 ALOGE("ERROR: thread detach failed\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 return result;
1153}
1154
1155/*
1156 * When starting a native thread that will be visible from the VM, we
1157 * bounce through this to get the right attach/detach action.
1158 * Note that this function calls free(args)
1159 */
1160/*static*/ int AndroidRuntime::javaThreadShell(void* args) {
1161 void* start = ((void**)args)[0];
1162 void* userData = ((void **)args)[1];
1163 char* name = (char*) ((void **)args)[2]; // we own this storage
1164 free(args);
1165 JNIEnv* env;
1166 int result;
1167
1168 /* hook us into the VM */
1169 if (javaAttachThread(name, &env) != JNI_OK)
1170 return -1;
1171
1172 /* start the thread running */
1173 result = (*(android_thread_func_t)start)(userData);
1174
1175 /* unhook us */
1176 javaDetachThread();
1177 free(name);
1178
1179 return result;
1180}
1181
1182/*
1183 * This is invoked from androidCreateThreadEtc() via the callback
1184 * set with androidSetCreateThreadFunc().
1185 *
1186 * We need to create the new thread in such a way that it gets hooked
1187 * into the VM before it really starts executing.
1188 */
1189/*static*/ int AndroidRuntime::javaCreateThreadEtc(
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001190 android_thread_func_t entryFunction,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001191 void* userData,
1192 const char* threadName,
1193 int32_t threadPriority,
1194 size_t threadStackSize,
1195 android_thread_id_t* threadId)
1196{
1197 void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free
1198 int result;
1199
Mike Lockwood32f2e622013-10-10 10:11:27 -07001200 if (!threadName)
1201 threadName = "unnamed thread";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001202
1203 args[0] = (void*) entryFunction;
1204 args[1] = userData;
1205 args[2] = (void*) strdup(threadName); // javaThreadShell must free
1206
1207 result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args,
1208 threadName, threadPriority, threadStackSize, threadId);
1209 return result;
1210}
1211
1212/*
1213 * Create a thread that is visible from the VM.
1214 *
1215 * This is called from elsewhere in the library.
1216 */
Mike Lockwoodf602d362010-06-20 14:28:16 -07001217/*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001218 void (*start)(void *), void* arg)
1219{
Mike Lockwoodf602d362010-06-20 14:28:16 -07001220 android_thread_id_t threadId = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221 javaCreateThreadEtc((android_thread_func_t) start, arg, name,
Mike Lockwoodf602d362010-06-20 14:28:16 -07001222 ANDROID_PRIORITY_DEFAULT, 0, &threadId);
1223 return threadId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224}
1225
1226#if 0
1227static void quickTest(void* arg)
1228{
1229 const char* str = (const char*) arg;
1230
1231 printf("In quickTest: %s\n", str);
1232}
1233#endif
1234
1235#ifdef NDEBUG
1236 #define REG_JNI(name) { name }
1237 struct RegJNIRec {
1238 int (*mProc)(JNIEnv*);
1239 };
1240#else
1241 #define REG_JNI(name) { name, #name }
1242 struct RegJNIRec {
1243 int (*mProc)(JNIEnv*);
1244 const char* mName;
1245 };
1246#endif
1247
1248typedef void (*RegJAMProc)();
1249
1250static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env)
1251{
1252 for (size_t i = 0; i < count; i++) {
1253 if (array[i].mProc(env) < 0) {
1254#ifndef NDEBUG
Steve Block5baa3a62011-12-20 16:23:08 +00001255 ALOGD("----------!!! %s failed to load\n", array[i].mName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256#endif
1257 return -1;
1258 }
1259 }
1260 return 0;
1261}
1262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263static const RegJNIRec gRegJNI[] = {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001264 REG_JNI(register_com_android_internal_os_RuntimeInit),
1265 REG_JNI(register_android_os_SystemClock),
1266 REG_JNI(register_android_util_EventLog),
1267 REG_JNI(register_android_util_Log),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 REG_JNI(register_android_content_AssetManager),
1269 REG_JNI(register_android_content_StringBlock),
1270 REG_JNI(register_android_content_XmlBlock),
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001271 REG_JNI(register_android_emoji_EmojiFactory),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272 REG_JNI(register_android_text_AndroidCharacter),
Anish Athalye88b5b0b2014-06-24 14:39:43 -07001273 REG_JNI(register_android_text_StaticLayout),
Doug Feltdae8e942010-02-24 14:33:15 -08001274 REG_JNI(register_android_text_AndroidBidi),
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001275 REG_JNI(register_android_view_InputDevice),
1276 REG_JNI(register_android_view_KeyCharacterMap),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 REG_JNI(register_android_os_Process),
Andreas Hubera8079bf2010-11-16 14:40:31 -08001278 REG_JNI(register_android_os_SystemProperties),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001279 REG_JNI(register_android_os_Binder),
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -08001280 REG_JNI(register_android_os_Parcel),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001281 REG_JNI(register_android_nio_utils),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001282 REG_JNI(register_android_graphics_Graphics),
Chris Craik54389792013-12-20 13:28:11 -08001283 REG_JNI(register_android_view_DisplayEventReceiver),
John Reckf666ad72014-03-14 16:24:57 -07001284 REG_JNI(register_android_view_RenderNode),
John Recke45b1fd2014-04-15 09:50:16 -07001285 REG_JNI(register_android_view_RenderNodeAnimator),
Romain Guy3b748a42013-04-17 18:54:38 -07001286 REG_JNI(register_android_view_GraphicBuffer),
Chris Craikc9070eb2015-03-09 18:50:14 -07001287 REG_JNI(register_android_view_DisplayListCanvas),
John Reck04fc5832014-02-05 16:38:25 -08001288 REG_JNI(register_android_view_HardwareLayer),
John Reckcec24ae2013-11-05 13:27:50 -08001289 REG_JNI(register_android_view_ThreadedRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001290 REG_JNI(register_android_view_Surface),
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001291 REG_JNI(register_android_view_SurfaceControl),
Jeff Brown64a55af2012-08-26 02:47:39 -07001292 REG_JNI(register_android_view_SurfaceSession),
Romain Guy8f0095c2011-05-02 17:24:22 -07001293 REG_JNI(register_android_view_TextureView),
John Reck315c3292014-05-09 19:21:04 -07001294 REG_JNI(register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001295 REG_JNI(register_com_google_android_gles_jni_EGLImpl),
1296 REG_JNI(register_com_google_android_gles_jni_GLImpl),
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001297 REG_JNI(register_android_opengl_jni_EGL14),
Jesse Hall237c2b82013-05-06 11:36:57 -07001298 REG_JNI(register_android_opengl_jni_EGLExt),
Jack Palevich1c4907e2009-04-13 16:22:25 -07001299 REG_JNI(register_android_opengl_jni_GLES10),
1300 REG_JNI(register_android_opengl_jni_GLES10Ext),
1301 REG_JNI(register_android_opengl_jni_GLES11),
1302 REG_JNI(register_android_opengl_jni_GLES11Ext),
Jack Palevich560814f2009-11-19 16:34:55 +08001303 REG_JNI(register_android_opengl_jni_GLES20),
Jesse Halld877efe2013-04-29 15:59:35 -07001304 REG_JNI(register_android_opengl_jni_GLES30),
Jesse Hall7ab63ac2014-05-19 15:13:41 -07001305 REG_JNI(register_android_opengl_jni_GLES31),
1306 REG_JNI(register_android_opengl_jni_GLES31Ext),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307
1308 REG_JNI(register_android_graphics_Bitmap),
1309 REG_JNI(register_android_graphics_BitmapFactory),
Wei-Ta Chen6b849e22010-09-07 17:32:18 +08001310 REG_JNI(register_android_graphics_BitmapRegionDecoder),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311 REG_JNI(register_android_graphics_Camera),
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -04001312 REG_JNI(register_android_graphics_CreateJavaOutputStreamAdaptor),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001313 REG_JNI(register_android_graphics_Canvas),
John Reck52244ff2014-05-01 21:27:37 -07001314 REG_JNI(register_android_graphics_CanvasProperty),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 REG_JNI(register_android_graphics_ColorFilter),
1316 REG_JNI(register_android_graphics_DrawFilter),
Raph Levien1a73f7322014-01-30 16:06:28 -08001317 REG_JNI(register_android_graphics_FontFamily),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001318 REG_JNI(register_android_graphics_Interpolator),
1319 REG_JNI(register_android_graphics_LayerRasterizer),
1320 REG_JNI(register_android_graphics_MaskFilter),
1321 REG_JNI(register_android_graphics_Matrix),
1322 REG_JNI(register_android_graphics_Movie),
1323 REG_JNI(register_android_graphics_NinePatch),
1324 REG_JNI(register_android_graphics_Paint),
1325 REG_JNI(register_android_graphics_Path),
1326 REG_JNI(register_android_graphics_PathMeasure),
1327 REG_JNI(register_android_graphics_PathEffect),
1328 REG_JNI(register_android_graphics_Picture),
1329 REG_JNI(register_android_graphics_PorterDuff),
1330 REG_JNI(register_android_graphics_Rasterizer),
1331 REG_JNI(register_android_graphics_Region),
1332 REG_JNI(register_android_graphics_Shader),
Jamie Gennisaa0ce332011-01-06 17:04:26 -08001333 REG_JNI(register_android_graphics_SurfaceTexture),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001334 REG_JNI(register_android_graphics_Typeface),
1335 REG_JNI(register_android_graphics_Xfermode),
Wei-Ta Chenbca2d612009-11-30 17:52:05 +08001336 REG_JNI(register_android_graphics_YuvImage),
Svetoslav6811f4e2013-09-18 15:58:28 -07001337 REG_JNI(register_android_graphics_pdf_PdfDocument),
Svetoslav62ce3322014-09-04 21:17:17 -07001338 REG_JNI(register_android_graphics_pdf_PdfEditor),
Svetoslav29617692014-04-24 18:40:42 -07001339 REG_JNI(register_android_graphics_pdf_PdfRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001340
1341 REG_JNI(register_android_database_CursorWindow),
Jeff Browne5360fb2011-10-31 17:48:13 -07001342 REG_JNI(register_android_database_SQLiteConnection),
1343 REG_JNI(register_android_database_SQLiteGlobal),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001344 REG_JNI(register_android_database_SQLiteDebug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001345 REG_JNI(register_android_os_Debug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001346 REG_JNI(register_android_os_FileObserver),
Christopher Tatefa9e7c02010-05-06 12:07:10 -07001347 REG_JNI(register_android_os_MessageQueue),
Stephen Smalleyc07fca32012-01-13 08:31:39 -05001348 REG_JNI(register_android_os_SELinux),
Jeff Brown481c1572012-03-09 14:41:15 -08001349 REG_JNI(register_android_os_Trace),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001350 REG_JNI(register_android_os_UEventObserver),
1351 REG_JNI(register_android_net_LocalSocketImpl),
1352 REG_JNI(register_android_net_NetworkUtils),
Dan Egnor2b4abcd2010-04-07 17:30:50 -07001353 REG_JNI(register_android_net_TrafficStats),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001354 REG_JNI(register_android_os_MemoryFile),
Dimitry Ivanov5d7d7772016-04-20 14:09:32 -07001355 REG_JNI(register_com_android_internal_os_PathClassLoaderFactory),
Narayan Kamath973b4662014-03-31 13:41:26 +01001356 REG_JNI(register_com_android_internal_os_Zygote),
John Reck9fa40712014-05-09 15:26:59 -07001357 REG_JNI(register_com_android_internal_util_VirtualRefBasePtr),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001358 REG_JNI(register_android_hardware_Camera),
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07001359 REG_JNI(register_android_hardware_camera2_CameraMetadata),
Ruben Brunkfeb50af2014-05-09 19:58:49 -07001360 REG_JNI(register_android_hardware_camera2_legacy_LegacyCameraDevice),
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -07001361 REG_JNI(register_android_hardware_camera2_legacy_PerfMeasurement),
Ruben Brunkb6079002014-05-22 12:33:54 -07001362 REG_JNI(register_android_hardware_camera2_DngCreator),
Eric Laurent633cb562015-03-05 15:17:20 -08001363 REG_JNI(register_android_hardware_Radio),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001364 REG_JNI(register_android_hardware_SensorManager),
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04001365 REG_JNI(register_android_hardware_SerialPort),
Eric Laurent60b62bc2014-04-18 17:50:49 -07001366 REG_JNI(register_android_hardware_SoundTrigger),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001367 REG_JNI(register_android_hardware_UsbDevice),
Mike Lockwoodacc29cc2011-03-11 08:18:08 -05001368 REG_JNI(register_android_hardware_UsbDeviceConnection),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001369 REG_JNI(register_android_hardware_UsbRequest),
destradaaa4fa3b52014-07-09 10:46:39 -07001370 REG_JNI(register_android_hardware_location_ActivityRecognitionHardware),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001371 REG_JNI(register_android_media_AudioRecord),
1372 REG_JNI(register_android_media_AudioSystem),
1373 REG_JNI(register_android_media_AudioTrack),
1374 REG_JNI(register_android_media_JetPlayer),
Jeff Browncbad9762012-09-04 21:57:59 -07001375 REG_JNI(register_android_media_RemoteDisplay),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001376 REG_JNI(register_android_media_ToneGenerator),
1377
1378 REG_JNI(register_android_opengl_classes),
JP Abgrall98a4f7e2011-09-02 15:36:33 -07001379 REG_JNI(register_android_server_NetworkManagementSocketTagger),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001380 REG_JNI(register_android_ddm_DdmHandleNativeHeap),
Joe Onorato1cf58742009-06-12 11:06:24 -07001381 REG_JNI(register_android_backup_BackupDataInput),
Joe Onoratod2110db2009-05-19 13:41:21 -07001382 REG_JNI(register_android_backup_BackupDataOutput),
Joe Onorato06290a42009-06-18 20:10:37 -07001383 REG_JNI(register_android_backup_FileBackupHelperBase),
Joe Onorato4ababd92009-06-25 18:29:18 -04001384 REG_JNI(register_android_backup_BackupHelperDispatcher),
Christopher Tate4a627c72011-04-01 14:43:32 -07001385 REG_JNI(register_android_app_backup_FullBackup),
Chet Haase9c1e23b2011-03-24 10:51:31 -07001386 REG_JNI(register_android_app_ActivityThread),
Dianne Hackborn69969e42010-05-04 11:40:40 -07001387 REG_JNI(register_android_app_NativeActivity),
Przemyslaw Szczepaniak6a8ad6d2015-11-03 09:47:56 +00001388 REG_JNI(register_android_util_jar_StrictJarFile),
Jeff Brown46b9ac02010-04-22 18:58:52 -07001389 REG_JNI(register_android_view_InputChannel),
Jeff Brown32cbc38552011-12-01 14:01:49 -08001390 REG_JNI(register_android_view_InputEventReceiver),
Jeff Brownc28867a2013-03-26 15:42:39 -07001391 REG_JNI(register_android_view_InputEventSender),
Michael Wrighta44dd262013-04-10 21:12:00 -07001392 REG_JNI(register_android_view_InputQueue),
Jeff Brown46b9ac02010-04-22 18:58:52 -07001393 REG_JNI(register_android_view_KeyEvent),
1394 REG_JNI(register_android_view_MotionEvent),
Jeff Brown2352b972011-04-12 22:39:53 -07001395 REG_JNI(register_android_view_PointerIcon),
Jeff Brown2ed24622011-03-14 19:39:54 -07001396 REG_JNI(register_android_view_VelocityTracker),
Kenny Root02c87302010-07-01 08:10:18 -07001397
1398 REG_JNI(register_android_content_res_ObbScanner),
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -07001399 REG_JNI(register_android_content_res_Configuration),
Chet Haase6e0ecb42010-11-03 19:41:18 -07001400
1401 REG_JNI(register_android_animation_PropertyValuesHolder),
Kenny Root66269ea2011-07-12 14:14:01 -07001402 REG_JNI(register_com_android_internal_content_NativeLibraryHelper),
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -08001403 REG_JNI(register_com_android_internal_net_NetworkStatsFactory),
Przemyslaw Szczepaniak6a8ad6d2015-11-03 09:47:56 +00001404
1405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406};
1407
1408/*
1409 * Register android native functions with the VM.
1410 */
1411/*static*/ int AndroidRuntime::startReg(JNIEnv* env)
1412{
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001413 ATRACE_NAME("RegisterAndroidNatives");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001414 /*
1415 * This hook causes all future threads created in this process to be
1416 * attached to the JavaVM. (This needs to go away in favor of JNI
1417 * Attach calls.)
1418 */
1419 androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc);
1420
Steve Block71f2cf12011-10-20 11:56:00 +01001421 ALOGV("--- registering native functions ---\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422
1423 /*
1424 * Every "register" function calls one or more things that return
1425 * a local reference (e.g. FindClass). Because we haven't really
1426 * started the VM yet, they're all getting stored in the base frame
1427 * and never released. Use Push/Pop to manage the storage.
1428 */
1429 env->PushLocalFrame(200);
1430
1431 if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) {
1432 env->PopLocalFrame(NULL);
1433 return -1;
1434 }
1435 env->PopLocalFrame(NULL);
1436
1437 //createJavaThread("fubar", quickTest, (void*) "hello");
1438
1439 return 0;
1440}
1441
1442AndroidRuntime* AndroidRuntime::getRuntime()
1443{
1444 return gCurRuntime;
1445}
1446
1447/**
Narayan Kamathc21dab92015-06-25 14:22:00 +01001448 * Used by surface flinger's DdmConnection to register native methods from
1449 * the framework.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001450 */
Narayan Kamathc21dab92015-06-25 14:22:00 +01001451extern "C" jint registerFrameworkNatives(JNIEnv* env) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001452 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1453}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001454} // namespace android