blob: 3fc001b9c034a168e8020e6d6ce5c0ecd95127fd [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
48
49using namespace android;
50
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051extern int register_android_os_Binder(JNIEnv* env);
52extern int register_android_os_Process(JNIEnv* env);
53extern int register_android_graphics_Bitmap(JNIEnv*);
54extern int register_android_graphics_BitmapFactory(JNIEnv*);
Wei-Ta Chen6b849e22010-09-07 17:32:18 +080055extern int register_android_graphics_BitmapRegionDecoder(JNIEnv*);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056extern int register_android_graphics_Camera(JNIEnv* env);
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -040057extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058extern int register_android_graphics_Graphics(JNIEnv* env);
59extern int register_android_graphics_Interpolator(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060extern int register_android_graphics_MaskFilter(JNIEnv* env);
61extern int register_android_graphics_Movie(JNIEnv* env);
62extern int register_android_graphics_NinePatch(JNIEnv*);
63extern int register_android_graphics_PathEffect(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064extern int register_android_graphics_Shader(JNIEnv* env);
65extern int register_android_graphics_Typeface(JNIEnv* env);
Wei-Ta Chenbca2d612009-11-30 17:52:05 +080066extern int register_android_graphics_YuvImage(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067
68extern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env);
69extern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070070extern int register_android_opengl_jni_EGL14(JNIEnv* env);
Jesse Hall237c2b82013-05-06 11:36:57 -070071extern int register_android_opengl_jni_EGLExt(JNIEnv* env);
Jack Palevich1c4907e2009-04-13 16:22:25 -070072extern int register_android_opengl_jni_GLES10(JNIEnv* env);
73extern int register_android_opengl_jni_GLES10Ext(JNIEnv* env);
74extern int register_android_opengl_jni_GLES11(JNIEnv* env);
75extern int register_android_opengl_jni_GLES11Ext(JNIEnv* env);
Jack Palevich560814f2009-11-19 16:34:55 +080076extern int register_android_opengl_jni_GLES20(JNIEnv* env);
Jesse Halld877efe2013-04-29 15:59:35 -070077extern int register_android_opengl_jni_GLES30(JNIEnv* env);
Jesse Hall7ab63ac2014-05-19 15:13:41 -070078extern int register_android_opengl_jni_GLES31(JNIEnv* env);
79extern int register_android_opengl_jni_GLES31Ext(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080
81extern int register_android_hardware_Camera(JNIEnv *env);
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -070082extern int register_android_hardware_camera2_CameraMetadata(JNIEnv *env);
Ruben Brunkfeb50af2014-05-09 19:58:49 -070083extern int register_android_hardware_camera2_legacy_LegacyCameraDevice(JNIEnv *env);
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -070084extern int register_android_hardware_camera2_legacy_PerfMeasurement(JNIEnv *env);
Ruben Brunkb6079002014-05-22 12:33:54 -070085extern int register_android_hardware_camera2_DngCreator(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086extern int register_android_hardware_SensorManager(JNIEnv *env);
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -040087extern int register_android_hardware_SerialPort(JNIEnv *env);
Eric Laurent60b62bc2014-04-18 17:50:49 -070088extern int register_android_hardware_SoundTrigger(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -050089extern int register_android_hardware_UsbDevice(JNIEnv *env);
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050090extern int register_android_hardware_UsbDeviceConnection(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -050091extern int register_android_hardware_UsbRequest(JNIEnv *env);
destradaaa4fa3b52014-07-09 10:46:39 -070092extern int register_android_hardware_location_ActivityRecognitionHardware(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093
94extern int register_android_media_AudioRecord(JNIEnv *env);
95extern int register_android_media_AudioSystem(JNIEnv *env);
96extern int register_android_media_AudioTrack(JNIEnv *env);
97extern int register_android_media_JetPlayer(JNIEnv *env);
98extern int register_android_media_ToneGenerator(JNIEnv *env);
99
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100namespace android {
101
102/*
103 * JNI-based registration functions. Note these are properly contained in
104 * namespace android.
105 */
106extern int register_android_content_AssetManager(JNIEnv* env);
107extern int register_android_util_EventLog(JNIEnv* env);
108extern int register_android_util_Log(JNIEnv* env);
109extern int register_android_content_StringBlock(JNIEnv* env);
110extern int register_android_content_XmlBlock(JNIEnv* env);
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700111extern int register_android_emoji_EmojiFactory(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112extern int register_android_graphics_Canvas(JNIEnv* env);
John Reck52244ff2014-05-01 21:27:37 -0700113extern int register_android_graphics_CanvasProperty(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114extern int register_android_graphics_ColorFilter(JNIEnv* env);
115extern int register_android_graphics_DrawFilter(JNIEnv* env);
Raph Levien1a73f7322014-01-30 16:06:28 -0800116extern int register_android_graphics_FontFamily(JNIEnv* env);
Mike Reed4c9355c2014-05-07 11:48:37 -0400117extern int register_android_graphics_LayerRasterizer(JNIEnv*);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118extern int register_android_graphics_Matrix(JNIEnv* env);
119extern int register_android_graphics_Paint(JNIEnv* env);
120extern int register_android_graphics_Path(JNIEnv* env);
121extern int register_android_graphics_PathMeasure(JNIEnv* env);
122extern int register_android_graphics_Picture(JNIEnv*);
123extern int register_android_graphics_PorterDuff(JNIEnv* env);
124extern int register_android_graphics_Rasterizer(JNIEnv* env);
Jeff Brownfbf09772011-01-16 14:06:57 -0800125extern int register_android_graphics_Region(JNIEnv* env);
Jamie Gennisaa0ce332011-01-06 17:04:26 -0800126extern int register_android_graphics_SurfaceTexture(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127extern int register_android_graphics_Xfermode(JNIEnv* env);
Svetoslav6811f4e2013-09-18 15:58:28 -0700128extern int register_android_graphics_pdf_PdfDocument(JNIEnv* env);
Svetoslav62ce3322014-09-04 21:17:17 -0700129extern int register_android_graphics_pdf_PdfEditor(JNIEnv* env);
Svetoslav29617692014-04-24 18:40:42 -0700130extern int register_android_graphics_pdf_PdfRenderer(JNIEnv* env);
Jeff Brown0a0a1242011-12-02 02:25:22 -0800131extern int register_android_view_DisplayEventReceiver(JNIEnv* env);
John Reckf666ad72014-03-14 16:24:57 -0700132extern int register_android_view_RenderNode(JNIEnv* env);
John Recke45b1fd2014-04-15 09:50:16 -0700133extern int register_android_view_RenderNodeAnimator(JNIEnv* env);
Romain Guy3b748a42013-04-17 18:54:38 -0700134extern int register_android_view_GraphicBuffer(JNIEnv* env);
Romain Guye4d01122010-06-16 18:44:05 -0700135extern int register_android_view_GLES20Canvas(JNIEnv* env);
John Reck04fc5832014-02-05 16:38:25 -0800136extern int register_android_view_HardwareLayer(JNIEnv* env);
John Reckcec24ae2013-11-05 13:27:50 -0800137extern int register_android_view_ThreadedRenderer(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138extern int register_android_view_Surface(JNIEnv* env);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800139extern int register_android_view_SurfaceControl(JNIEnv* env);
Jeff Brown64a55af2012-08-26 02:47:39 -0700140extern int register_android_view_SurfaceSession(JNIEnv* env);
Romain Guy8f0095c2011-05-02 17:24:22 -0700141extern int register_android_view_TextureView(JNIEnv* env);
John Reck315c3292014-05-09 19:21:04 -0700142extern int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143extern int register_android_database_CursorWindow(JNIEnv* env);
Jeff Browne5360fb2011-10-31 17:48:13 -0700144extern int register_android_database_SQLiteConnection(JNIEnv* env);
145extern int register_android_database_SQLiteGlobal(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146extern int register_android_database_SQLiteDebug(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147extern int register_android_nio_utils(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148extern int register_android_os_Debug(JNIEnv* env);
Christopher Tatefa9e7c02010-05-06 12:07:10 -0700149extern int register_android_os_MessageQueue(JNIEnv* env);
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -0800150extern int register_android_os_Parcel(JNIEnv* env);
Stephen Smalleyc07fca32012-01-13 08:31:39 -0500151extern int register_android_os_SELinux(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152extern int register_android_os_SystemProperties(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153extern int register_android_os_SystemClock(JNIEnv* env);
Jeff Brown481c1572012-03-09 14:41:15 -0800154extern int register_android_os_Trace(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155extern int register_android_os_FileObserver(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156extern int register_android_os_UEventObserver(JNIEnv* env);
157extern int register_android_os_MemoryFile(JNIEnv* env);
158extern int register_android_net_LocalSocketImpl(JNIEnv* env);
159extern int register_android_net_NetworkUtils(JNIEnv* env);
Dan Egnor2b4abcd2010-04-07 17:30:50 -0700160extern int register_android_net_TrafficStats(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161extern int register_android_text_AndroidCharacter(JNIEnv *env);
Anish Athalye88b5b0b2014-06-24 14:39:43 -0700162extern int register_android_text_StaticLayout(JNIEnv *env);
Doug Feltdae8e942010-02-24 14:33:15 -0800163extern int register_android_text_AndroidBidi(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164extern int register_android_opengl_classes(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
Narayan Kamath29564cd2014-08-07 10:57:40 +0100166extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env);
Joe Onorato1cf58742009-06-12 11:06:24 -0700167extern int register_android_backup_BackupDataInput(JNIEnv *env);
Joe Onoratod2110db2009-05-19 13:41:21 -0700168extern int register_android_backup_BackupDataOutput(JNIEnv *env);
Joe Onorato06290a42009-06-18 20:10:37 -0700169extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
Joe Onorato4ababd92009-06-25 18:29:18 -0400170extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
Christopher Tate4a627c72011-04-01 14:43:32 -0700171extern int register_android_app_backup_FullBackup(JNIEnv *env);
Chet Haase9c1e23b2011-03-24 10:51:31 -0700172extern int register_android_app_ActivityThread(JNIEnv *env);
Dianne Hackborn69969e42010-05-04 11:40:40 -0700173extern int register_android_app_NativeActivity(JNIEnv *env);
Jeff Browncbad9762012-09-04 21:57:59 -0700174extern int register_android_media_RemoteDisplay(JNIEnv *env);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700175extern int register_android_view_InputChannel(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700176extern int register_android_view_InputDevice(JNIEnv* env);
Jeff Brown32cbc38552011-12-01 14:01:49 -0800177extern int register_android_view_InputEventReceiver(JNIEnv* env);
Jeff Brownc28867a2013-03-26 15:42:39 -0700178extern int register_android_view_InputEventSender(JNIEnv* env);
Michael Wrighta44dd262013-04-10 21:12:00 -0700179extern int register_android_view_InputQueue(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700180extern int register_android_view_KeyCharacterMap(JNIEnv *env);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700181extern int register_android_view_KeyEvent(JNIEnv* env);
182extern int register_android_view_MotionEvent(JNIEnv* env);
Jeff Brown2352b972011-04-12 22:39:53 -0700183extern int register_android_view_PointerIcon(JNIEnv* env);
Jeff Brown2ed24622011-03-14 19:39:54 -0700184extern int register_android_view_VelocityTracker(JNIEnv* env);
Kenny Root02c87302010-07-01 08:10:18 -0700185extern int register_android_content_res_ObbScanner(JNIEnv* env);
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700186extern int register_android_content_res_Configuration(JNIEnv* env);
Chet Haase6e0ecb42010-11-03 19:41:18 -0700187extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
Kenny Root66269ea2011-07-12 14:14:01 -0700188extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -0800189extern int register_com_android_internal_net_NetworkStatsFactory(JNIEnv *env);
Narayan Kamath973b4662014-03-31 13:41:26 +0100190extern int register_com_android_internal_os_Zygote(JNIEnv *env);
John Reck9fa40712014-05-09 15:26:59 -0700191extern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192
193static AndroidRuntime* gCurRuntime = NULL;
194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195/*
196 * Code written in the Java Programming Language calls here from main().
197 */
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700198static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199{
200 gCurRuntime->onStarted();
201}
202
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700203static void com_android_internal_os_RuntimeInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204{
205 gCurRuntime->onZygoteInit();
206}
207
Jeff Brown4280c4a2012-03-15 17:48:02 -0700208static void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIEnv* env,
209 jobject clazz, jboolean exitWithoutCleanup)
210{
211 gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup);
212}
213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214/*
215 * JNI registration.
216 */
Daniel Micay76f6a862015-09-19 17:31:01 -0400217static const JNINativeMethod gMethods[] = {
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700218 { "nativeFinishInit", "()V",
219 (void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
220 { "nativeZygoteInit", "()V",
221 (void*) com_android_internal_os_RuntimeInit_nativeZygoteInit },
Jeff Brown4280c4a2012-03-15 17:48:02 -0700222 { "nativeSetExitWithoutCleanup", "(Z)V",
223 (void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224};
225
226int register_com_android_internal_os_RuntimeInit(JNIEnv* env)
227{
228 return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
229 gMethods, NELEM(gMethods));
230}
231
232// ----------------------------------------------------------------------
233
Andreas Huber9ae000c2014-02-13 17:22:33 +0000234/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
235
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000236AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) :
237 mExitWithoutCleanup(false),
238 mArgBlockStart(argBlockStart),
239 mArgBlockLength(argBlockLength)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700241 SkGraphics::Init();
Mike Reedfc8db532009-04-27 11:43:30 -0400242 // There is also a global font cache, but its budget is specified in code
243 // see SkFontHost_android.cpp
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244
245 // Pre-allocate enough space to hold a fair number of options.
246 mOptions.setCapacity(20);
247
248 assert(gCurRuntime == NULL); // one per process
249 gCurRuntime = this;
250}
251
252AndroidRuntime::~AndroidRuntime()
253{
254 SkGraphics::Term();
255}
256
Andreas Huber9ae000c2014-02-13 17:22:33 +0000257/*
258 * Register native methods using JNI.
259 */
260/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
261 const char* className, const JNINativeMethod* gMethods, int numMethods)
262{
263 return jniRegisterNativeMethods(env, className, gMethods, numMethods);
264}
265
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000266void AndroidRuntime::setArgv0(const char* argv0) {
Jeff Brown00c0cd42014-09-10 16:48:46 -0700267 memset(mArgBlockStart, 0, mArgBlockLength);
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000268 strlcpy(mArgBlockStart, argv0, mArgBlockLength);
269}
270
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100271status_t AndroidRuntime::callMain(const String8& className, jclass clazz,
272 const Vector<String8>& args)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273{
274 JNIEnv* env;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 jmethodID methodId;
276
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100277 ALOGD("Calling main entry %s", className.string());
Dianne Hackborn08e60f22010-09-01 18:17:17 -0700278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 env = getJNIEnv();
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700280 if (clazz == NULL || env == NULL) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 return UNKNOWN_ERROR;
282 }
283
284 methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
285 if (methodId == NULL) {
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100286 ALOGE("ERROR: could not find method %s.main(String[])\n", className.string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 return UNKNOWN_ERROR;
288 }
289
290 /*
291 * We want to call main() with a String array with our arguments in it.
292 * Create an array and populate it.
293 */
294 jclass stringClass;
295 jobjectArray strArray;
296
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100297 const size_t numArgs = args.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 stringClass = env->FindClass("java/lang/String");
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100299 strArray = env->NewObjectArray(numArgs, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100301 for (size_t i = 0; i < numArgs; i++) {
302 jstring argStr = env->NewStringUTF(args[i].string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 env->SetObjectArrayElement(strArray, i, argStr);
304 }
305
306 env->CallStaticVoidMethod(clazz, methodId, strArray);
307 return NO_ERROR;
308}
309
310/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 * The VM calls this through the "exit" hook.
312 */
313static void runtime_exit(int code)
314{
Jeff Brown4280c4a2012-03-15 17:48:02 -0700315 gCurRuntime->exit(code);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316}
317
318/*
319 * The VM calls this through the "vfprintf" hook.
320 *
321 * We ignore "fp" and just write the results to the log file.
322 */
323static void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
324{
325 LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
326}
327
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800328/**
329 * The VM calls this when mutex contention debugging is enabled to
330 * determine whether or not the blocked thread was a "sensitive thread"
331 * for user responsiveness/smoothess.
332 *
333 * Our policy for this is whether or not we're tracing any StrictMode
334 * events on this thread (which we might've inherited via Binder calls
335 * into us)
336 */
337static bool runtime_isSensitiveThread() {
338 IPCThreadState* state = IPCThreadState::selfOrNull();
339 return state && state->getStrictModePolicy() != 0;
340}
341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342static int hasDir(const char* dir)
343{
344 struct stat s;
345 int res = stat(dir, &s);
346 if (res == 0) {
347 return S_ISDIR(s.st_mode);
348 }
349 return 0;
350}
351
Andreas Gampe995c62d2014-11-14 16:15:17 -0800352static bool hasFile(const char* file) {
353 struct stat s;
354 int res = stat(file, &s);
355 if (res == 0) {
356 return S_ISREG(s.st_mode);
357 }
358 return false;
359}
360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361/*
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000362 * Read the persistent locale. Attempts to read to persist.sys.locale
363 * and falls back to the default locale (ro.product.locale) if
364 * persist.sys.locale is empty.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 */
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000366static void readLocale(char* locale)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367{
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000368 // Allocate 4 extra bytes because we might read a property into
369 // this array at offset 4.
370 char propLocale[PROPERTY_VALUE_MAX + 4];
Brian Carlstrom171ea892010-08-24 21:27:52 -0700371
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000372 property_get("persist.sys.locale", propLocale, "");
373 if (propLocale[0] == 0) {
374 property_get("ro.product.locale", propLocale, "");
375
376 if (propLocale[0] == 0) {
377 // If persist.sys.locale and ro.product.locale are missing,
378 // construct a locale value from the individual locale components.
379 property_get("ro.product.locale.language", propLocale, "en");
380
381 // The language code is either two or three chars in length. If it
382 // isn't 2 chars long, assume three. Anything else is an error
383 // anyway.
384 const int offset = (propLocale[2] == 0) ? 2 : 3;
385 propLocale[offset] = '-';
386
387 property_get("ro.product.locale.region", propLocale + offset + 1, "US");
388 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 }
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000390
391 strncat(locale, propLocale, PROPERTY_VALUE_MAX);
392 // ALOGD("[DEBUG] locale=%s", locale);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393}
394
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700395void AndroidRuntime::addOption(const char* optionString, void* extraInfo)
396{
397 JavaVMOption opt;
398 opt.optionString = optionString;
399 opt.extraInfo = extraInfo;
400 mOptions.add(opt);
401}
402
Andy McFaddenf70188a2009-03-31 15:52:13 -0700403/*
Andy McFaddene4d81f22010-07-14 16:02:20 -0700404 * Parse a property containing space-separated options that should be
405 * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
406 *
407 * This will cut up "extraOptsBuf" as we chop it into individual options.
408 *
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800409 * If "quotingArg" is non-null, it is passed before each extra option in mOptions.
410 *
Andy McFaddene4d81f22010-07-14 16:02:20 -0700411 * Adds the strings, if any, to mOptions.
412 */
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800413void AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg)
Andy McFaddene4d81f22010-07-14 16:02:20 -0700414{
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800415 char* start = extraOptsBuf;
416 char* end = NULL;
Andy McFaddene4d81f22010-07-14 16:02:20 -0700417 while (*start != '\0') {
418 while (*start == ' ') /* skip leading whitespace */
419 start++;
420 if (*start == '\0') /* was trailing ws, bail */
421 break;
422
423 end = start+1;
424 while (*end != ' ' && *end != '\0') /* find end of token */
425 end++;
426 if (*end == ' ')
427 *end++ = '\0'; /* mark end, advance to indicate more */
428
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800429 if (quotingArg != NULL) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700430 addOption(quotingArg);
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800431 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700432 addOption(start);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700433 start = end;
434 }
435}
436
437/*
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700438 * Reads a "property" into "buffer" with a default of "defaultArg". If
439 * the property is non-empty, it is treated as a runtime option such
440 * as "-Xmx32m".
441 *
442 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
443 *
444 * If an argument is found, it is added to mOptions.
445 *
446 * If an option is found, it is added to mOptions and true is
447 * returned. Otherwise false is returned.
448 */
449bool AndroidRuntime::parseRuntimeOption(const char* property,
450 char* buffer,
451 const char* runtimeArg,
452 const char* defaultArg)
453{
454 strcpy(buffer, runtimeArg);
455 size_t runtimeArgLen = strlen(runtimeArg);
456 property_get(property, buffer+runtimeArgLen, defaultArg);
457 if (buffer[runtimeArgLen] == '\0') {
458 return false;
459 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700460 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700461 return true;
462}
463
464/*
465 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700466 * is treated as a dex2oat compiler option that should be
467 * passed as a quoted option, e.g. "-Ximage-compiler-option --compiler-filter=verify-none".
468 *
469 * The "compilerArg" is a prefix for the option such as "--compiler-filter=".
470 *
471 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
472 *
473 * If an option is found, it is added to mOptions and true is
474 * returned. Otherwise false is returned.
475 */
476bool AndroidRuntime::parseCompilerOption(const char* property,
477 char* buffer,
478 const char* compilerArg,
479 const char* quotingArg)
480{
481 strcpy(buffer, compilerArg);
482 size_t compilerArgLen = strlen(compilerArg);
483 property_get(property, buffer+compilerArgLen, "");
484 if (buffer[compilerArgLen] == '\0') {
485 return false;
486 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700487 addOption(quotingArg);
488 addOption(buffer);
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700489 return true;
490}
491
492/*
493 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700494 * is treated as a dex2oat compiler runtime option that should be
495 * passed as a quoted option, e.g. "-Ximage-compiler-option
496 * --runtime-arg -Ximage-compiler-option -Xmx32m".
497 *
498 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
499 *
500 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
501 *
502 * If an option is found, it is added to mOptions and true is
503 * returned. Otherwise false is returned.
504 */
505bool AndroidRuntime::parseCompilerRuntimeOption(const char* property,
506 char* buffer,
507 const char* runtimeArg,
508 const char* quotingArg)
509{
510 strcpy(buffer, runtimeArg);
511 size_t runtimeArgLen = strlen(runtimeArg);
512 property_get(property, buffer+runtimeArgLen, "");
513 if (buffer[runtimeArgLen] == '\0') {
514 return false;
515 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700516 addOption(quotingArg);
517 addOption("--runtime-arg");
518 addOption(quotingArg);
519 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700520 return true;
521}
522
523/*
Andy McFaddenf70188a2009-03-31 15:52:13 -0700524 * Start the Dalvik Virtual Machine.
525 *
526 * Various arguments, most determined by system properties, are passed in.
527 * The "mOptions" vector is updated.
528 *
Dave Allison07a1e232014-03-14 08:54:33 -0700529 * CAUTION: when adding options in here, be careful not to put the
530 * char buffer inside a nested scope. Adding the buffer to the
531 * options using mOptions.add() does not copy the buffer, so if the
532 * buffer goes out of scope the option may be overwritten. It's best
533 * to put the buffer at the top of the function so that it is more
534 * unlikely that someone will surround it in a scope at a later time
535 * and thus introduce a bug.
536 *
Andy McFaddenf70188a2009-03-31 15:52:13 -0700537 * Returns 0 on success.
538 */
539int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 JavaVMInitArgs initArgs;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 char propBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700543 char stackTraceFileBuf[sizeof("-Xstacktracefile:")-1 + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro38cfa8c2010-12-07 16:48:29 -0800545 char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700546 char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro8cdf27c32011-01-19 12:33:12 -0800547 char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700548 char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
549 char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800550 char usejitOptsBuf[sizeof("-Xusejit:")-1 + PROPERTY_VALUE_MAX];
551 char jitcodecachesizeOptsBuf[sizeof("-Xjitcodecachesize:")-1 + PROPERTY_VALUE_MAX];
552 char jitthresholdOptsBuf[sizeof("-Xjitthreshold:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier7e4fdec2013-12-02 15:46:51 -0800553 char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700554 char backgroundgcOptsBuf[sizeof("-XX:BackgroundGC=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700555 char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee324ba02015-03-31 16:15:17 -0700556 char cachePruneBuf[sizeof("-Xzygote-max-boot-retry=")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700557 char dex2oatXmsImageFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
558 char dex2oatXmxImageFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
559 char dex2oatXmsFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
560 char dex2oatXmxFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700561 char dex2oatCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
562 char dex2oatImageCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee0352382015-03-30 18:43:39 -0700563 char dex2oatThreadsBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
564 char dex2oatThreadsImageBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
Andreas Gampe605cca12015-04-02 23:12:56 -0700565 char dex2oat_isa_variant_key[PROPERTY_KEY_MAX];
566 char dex2oat_isa_variant[sizeof("--instruction-set-variant=") -1 + PROPERTY_VALUE_MAX];
567 char dex2oat_isa_features_key[PROPERTY_KEY_MAX];
568 char dex2oat_isa_features[sizeof("--instruction-set-features=") -1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800569 char dex2oatFlagsBuf[PROPERTY_VALUE_MAX];
570 char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX];
Andy McFaddene4d81f22010-07-14 16:02:20 -0700571 char extraOptsBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700572 char voldDecryptBuf[PROPERTY_VALUE_MAX];
Ben Cheng52b0e732009-06-19 13:31:12 -0700573 enum {
574 kEMDefault,
575 kEMIntPortable,
576 kEMIntFast,
Ben Cheng52b0e732009-06-19 13:31:12 -0700577 kEMJitCompiler,
Ben Cheng52b0e732009-06-19 13:31:12 -0700578 } executionMode = kEMDefault;
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700579 char profilePeriod[sizeof("-Xprofile-period:")-1 + PROPERTY_VALUE_MAX];
580 char profileDuration[sizeof("-Xprofile-duration:")-1 + PROPERTY_VALUE_MAX];
581 char profileInterval[sizeof("-Xprofile-interval:")-1 + PROPERTY_VALUE_MAX];
582 char profileBackoff[sizeof("-Xprofile-backoff:")-1 + PROPERTY_VALUE_MAX];
583 char profileTopKThreshold[sizeof("-Xprofile-top-k-threshold:")-1 + PROPERTY_VALUE_MAX];
584 char profileTopKChangeThreshold[sizeof("-Xprofile-top-k-change-threshold:")-1 +
585 PROPERTY_VALUE_MAX];
586 char profileType[sizeof("-Xprofile-type:")-1 + PROPERTY_VALUE_MAX];
587 char profileMaxStackDepth[sizeof("-Xprofile-max-stack-depth:")-1 + PROPERTY_VALUE_MAX];
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000588 char localeOption[sizeof("-Duser.locale=") + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700589 char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle01db9162014-08-07 14:45:53 +0100590 char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX];
Dmitriy Ivanovdec46882014-09-30 15:10:48 -0700591 char cpuAbiListBuf[sizeof("--cpu-abilist=") + PROPERTY_VALUE_MAX];
Andreas Gampecadcd512015-06-22 21:09:36 -0700592 char methodTraceFileBuf[sizeof("-Xmethod-trace-file:") + PROPERTY_VALUE_MAX];
593 char methodTraceFileSizeBuf[sizeof("-Xmethod-trace-file-size:") + PROPERTY_VALUE_MAX];
Andreas Gampe1f105a62015-07-24 14:19:44 -0700594 char fingerprintBuf[sizeof("-Xfingerprint:") + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700596 bool checkJni = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800597 property_get("dalvik.vm.checkjni", propBuf, "");
598 if (strcmp(propBuf, "true") == 0) {
599 checkJni = true;
600 } else if (strcmp(propBuf, "false") != 0) {
601 /* property is neither true nor false; fall back on kernel parameter */
602 property_get("ro.kernel.android.checkjni", propBuf, "");
603 if (propBuf[0] == '1') {
604 checkJni = true;
605 }
606 }
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700607 ALOGD("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
608 if (checkJni) {
609 /* extended JNI checking */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700610 addOption("-Xcheck:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700611
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700612 /* with -Xcheck:jni, this provides a JNI function call trace */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700613 //addOption("-verbose:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700614 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800615
616 property_get("dalvik.vm.execution-mode", propBuf, "");
617 if (strcmp(propBuf, "int:portable") == 0) {
618 executionMode = kEMIntPortable;
619 } else if (strcmp(propBuf, "int:fast") == 0) {
620 executionMode = kEMIntFast;
Ben Cheng52b0e732009-06-19 13:31:12 -0700621 } else if (strcmp(propBuf, "int:jit") == 0) {
622 executionMode = kEMJitCompiler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 }
624
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700625 parseRuntimeOption("dalvik.vm.stack-trace-file", stackTraceFileBuf, "-Xstacktracefile:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 strcpy(jniOptsBuf, "-Xjniopts:");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700628 if (parseRuntimeOption("dalvik.vm.jniopts", jniOptsBuf, "-Xjniopts:")) {
629 ALOGI("JNI options: '%s'\n", jniOptsBuf);
630 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 /* route exit() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700633 addOption("exit", (void*) runtime_exit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800634
635 /* route fprintf() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700636 addOption("vfprintf", (void*) runtime_vfprintf);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800638 /* register the framework-specific "is sensitive thread" hook */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700639 addOption("sensitiveThread", (void*) runtime_isSensitiveThread);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640
641 /* enable verbose; standard options are { jni, gc, class } */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700642 //addOption("-verbose:jni");
643 addOption("-verbose:gc");
644 //addOption("-verbose:class");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645
Carl Shapiro9e4c8842010-12-08 12:14:46 -0800646 /*
647 * The default starting and maximum size of the heap. Larger
648 * values should be specified in a product property override.
649 */
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700650 parseRuntimeOption("dalvik.vm.heapstartsize", heapstartsizeOptsBuf, "-Xms", "4m");
651 parseRuntimeOption("dalvik.vm.heapsize", heapsizeOptsBuf, "-Xmx", "16m");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700653 parseRuntimeOption("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
654 parseRuntimeOption("dalvik.vm.heapminfree", heapminfreeOptsBuf, "-XX:HeapMinFree=");
655 parseRuntimeOption("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf, "-XX:HeapMaxFree=");
656 parseRuntimeOption("dalvik.vm.heaptargetutilization",
657 heaptargetutilizationOptsBuf,
658 "-XX:HeapTargetUtilization=");
Ian Rogers53250102012-09-23 16:38:03 -0700659
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800660 /*
661 * JIT related options.
662 */
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700663 parseRuntimeOption("dalvik.vm.usejit", usejitOptsBuf, "-Xusejit:");
664 parseRuntimeOption("dalvik.vm.jitcodecachesize", jitcodecachesizeOptsBuf, "-Xjitcodecachesize:");
665 parseRuntimeOption("dalvik.vm.jitthreshold", jitthresholdOptsBuf, "-Xjitthreshold:");
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800666
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700667 property_get("ro.config.low_ram", propBuf, "");
668 if (strcmp(propBuf, "true") == 0) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700669 addOption("-XX:LowMemoryMode");
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700670 }
671
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700672 parseRuntimeOption("dalvik.vm.gctype", gctypeOptsBuf, "-Xgc:");
673 parseRuntimeOption("dalvik.vm.backgroundgctype", backgroundgcOptsBuf, "-XX:BackgroundGC=");
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 /* enable debugging; set suspend=y to pause during VM init */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 /* use android ADB transport */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700677 addOption("-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700679 parseRuntimeOption("dalvik.vm.lockprof.threshold",
680 lockProfThresholdBuf,
681 "-Xlockprofthreshold:");
Carl Shapirod8f3ec62010-04-12 16:31:59 -0700682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 if (executionMode == kEMIntPortable) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700684 addOption("-Xint:portable");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 } else if (executionMode == kEMIntFast) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700686 addOption("-Xint:fast");
Ben Cheng52b0e732009-06-19 13:31:12 -0700687 } else if (executionMode == kEMJitCompiler) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700688 addOption("-Xint:jit");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689 }
Andy McFaddene2b23e12009-04-03 11:09:46 -0700690
Andreas Gampe08b2d582014-12-18 14:39:22 -0800691 // If we are booting without the real /data, don't spend time compiling.
692 property_get("vold.decrypt", voldDecryptBuf, "");
693 bool skip_compilation = ((strcmp(voldDecryptBuf, "trigger_restart_min_framework") == 0) ||
694 (strcmp(voldDecryptBuf, "1") == 0));
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800695
Andreas Gampe08b2d582014-12-18 14:39:22 -0800696 // Extra options for boot.art/boot.oat image generation.
697 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xms", dex2oatXmsImageFlagsBuf,
698 "-Xms", "-Ximage-compiler-option");
699 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xmx", dex2oatXmxImageFlagsBuf,
700 "-Xmx", "-Ximage-compiler-option");
701 if (skip_compilation) {
Brian Carlstromce5bbbe2014-07-30 15:13:17 -0700702 addOption("-Ximage-compiler-option");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800703 addOption("--compiler-filter=verify-none");
704 } else {
705 parseCompilerOption("dalvik.vm.image-dex2oat-filter", dex2oatImageCompilerFilterBuf,
706 "--compiler-filter=", "-Ximage-compiler-option");
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800707 }
708
Andreas Gampe08b2d582014-12-18 14:39:22 -0800709 // Make sure there is a preloaded-classes file.
710 if (!hasFile("/system/etc/preloaded-classes")) {
711 ALOGE("Missing preloaded-classes file, /system/etc/preloaded-classes not found: %s\n",
712 strerror(errno));
Andreas Gampe605cca12015-04-02 23:12:56 -0700713 return -1;
Andreas Gampe08b2d582014-12-18 14:39:22 -0800714 }
715 addOption("-Ximage-compiler-option");
716 addOption("--image-classes=/system/etc/preloaded-classes");
717
718 // If there is a compiled-classes file, push it.
719 if (hasFile("/system/etc/compiled-classes")) {
720 addOption("-Ximage-compiler-option");
721 addOption("--compiled-classes=/system/etc/compiled-classes");
722 }
723
724 property_get("dalvik.vm.image-dex2oat-flags", dex2oatImageFlagsBuf, "");
725 parseExtraOpts(dex2oatImageFlagsBuf, "-Ximage-compiler-option");
726
727 // Extra options for DexClassLoader.
728 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xms", dex2oatXmsFlagsBuf,
729 "-Xms", "-Xcompiler-option");
730 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xmx", dex2oatXmxFlagsBuf,
731 "-Xmx", "-Xcompiler-option");
732 if (skip_compilation) {
733 addOption("-Xcompiler-option");
734 addOption("--compiler-filter=verify-none");
neo.chae155118f2015-01-07 15:32:15 +0900735
736 // We skip compilation when a minimal runtime is brought up for decryption. In that case
737 // /data is temporarily backed by a tmpfs, which is usually small.
738 // If the system image contains prebuilts, they will be relocated into the tmpfs. In this
739 // specific situation it is acceptable to *not* relocate and run out of the prebuilts
740 // directly instead.
741 addOption("--runtime-arg");
742 addOption("-Xnorelocate");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800743 } else {
744 parseCompilerOption("dalvik.vm.dex2oat-filter", dex2oatCompilerFilterBuf,
745 "--compiler-filter=", "-Xcompiler-option");
746 }
Andreas Gampee0352382015-03-30 18:43:39 -0700747 parseCompilerOption("dalvik.vm.dex2oat-threads", dex2oatThreadsBuf, "-j", "-Xcompiler-option");
748 parseCompilerOption("dalvik.vm.image-dex2oat-threads", dex2oatThreadsImageBuf, "-j",
749 "-Ximage-compiler-option");
Andreas Gampe605cca12015-04-02 23:12:56 -0700750
751 // The runtime will compile a boot image, when necessary, not using installd. Thus, we need to
752 // pass the instruction-set-features/variant as an image-compiler-option.
753 // TODO: Find a better way for the instruction-set.
754#if defined(__arm__)
755 constexpr const char* instruction_set = "arm";
756#elif defined(__aarch64__)
757 constexpr const char* instruction_set = "arm64";
758#elif defined(__mips__) && !defined(__LP64__)
759 constexpr const char* instruction_set = "mips";
760#elif defined(__mips__) && defined(__LP64__)
761 constexpr const char* instruction_set = "mips64";
762#elif defined(__i386__)
763 constexpr const char* instruction_set = "x86";
764#elif defined(__x86_64__)
765 constexpr const char* instruction_set = "x86_64";
766#else
767 constexpr const char* instruction_set = "unknown";
768#endif
769 // Note: it is OK to reuse the buffer, as the values are exactly the same between
770 // * compiler-option, used for runtime compilation (DexClassLoader)
771 // * image-compiler-option, used for boot-image compilation on device
772
773 // Copy the variant.
774 sprintf(dex2oat_isa_variant_key, "dalvik.vm.isa.%s.variant", instruction_set);
775 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
776 "--instruction-set-variant=", "-Ximage-compiler-option");
777 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
778 "--instruction-set-variant=", "-Xcompiler-option");
779 // Copy the features.
780 sprintf(dex2oat_isa_features_key, "dalvik.vm.isa.%s.features", instruction_set);
781 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
782 "--instruction-set-features=", "-Ximage-compiler-option");
783 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
784 "--instruction-set-features=", "-Xcompiler-option");
785
786
Andreas Gampe08b2d582014-12-18 14:39:22 -0800787 property_get("dalvik.vm.dex2oat-flags", dex2oatFlagsBuf, "");
788 parseExtraOpts(dex2oatFlagsBuf, "-Xcompiler-option");
789
Andy McFaddene4d81f22010-07-14 16:02:20 -0700790 /* extra options; parse this late so it overrides others */
791 property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800792 parseExtraOpts(extraOptsBuf, NULL);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 /* Set the properties for locale */
795 {
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000796 strcpy(localeOption, "-Duser.locale=");
797 readLocale(localeOption);
798 addOption(localeOption);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 }
800
Dave Allison0efbd9a2014-01-30 14:19:51 -0800801 /*
802 * Set profiler options
803 */
Andreas Gampe08b2d582014-12-18 14:39:22 -0800804 // Whether or not the profiler should be enabled.
805 property_get("dalvik.vm.profiler", propBuf, "0");
806 if (propBuf[0] == '1') {
807 addOption("-Xenable-profiler");
808 }
Dave Allison0efbd9a2014-01-30 14:19:51 -0800809
Andreas Gampe08b2d582014-12-18 14:39:22 -0800810 // Whether the profile should start upon app startup or be delayed by some random offset
811 // (in seconds) that is bound between 0 and a fixed value.
812 property_get("dalvik.vm.profile.start-immed", propBuf, "0");
813 if (propBuf[0] == '1') {
814 addOption("-Xprofile-start-immediately");
815 }
Dave Allison0efbd9a2014-01-30 14:19:51 -0800816
Andreas Gampe08b2d582014-12-18 14:39:22 -0800817 // Number of seconds during profile runs.
818 parseRuntimeOption("dalvik.vm.profile.period-secs", profilePeriod, "-Xprofile-period:");
Dave Allison0efbd9a2014-01-30 14:19:51 -0800819
Andreas Gampe08b2d582014-12-18 14:39:22 -0800820 // Length of each profile run (seconds).
821 parseRuntimeOption("dalvik.vm.profile.duration-secs",
822 profileDuration,
823 "-Xprofile-duration:");
Dave Allison0efbd9a2014-01-30 14:19:51 -0800824
Andreas Gampe08b2d582014-12-18 14:39:22 -0800825 // Polling interval during profile run (microseconds).
826 parseRuntimeOption("dalvik.vm.profile.interval-us", profileInterval, "-Xprofile-interval:");
Calin Juravle9828d062014-06-02 16:45:13 +0100827
Andreas Gampe08b2d582014-12-18 14:39:22 -0800828 // Coefficient for period backoff. The the period is multiplied
829 // by this value after each profile run.
830 parseRuntimeOption("dalvik.vm.profile.backoff-coeff", profileBackoff, "-Xprofile-backoff:");
Calin Juravle9828d062014-06-02 16:45:13 +0100831
Andreas Gampe08b2d582014-12-18 14:39:22 -0800832 // Top K% of samples that are considered relevant when
833 // deciding if the app should be recompiled.
834 parseRuntimeOption("dalvik.vm.profile.top-k-thr",
835 profileTopKThreshold,
836 "-Xprofile-top-k-threshold:");
Calin Juravle9828d062014-06-02 16:45:13 +0100837
Andreas Gampe08b2d582014-12-18 14:39:22 -0800838 // The threshold after which a change in the structure of the
839 // top K% profiled samples becomes significant and triggers
840 // recompilation. A change in profile is considered
841 // significant if X% (top-k-change-threshold) of the top K%
842 // (top-k-threshold property) samples has changed.
843 parseRuntimeOption("dalvik.vm.profile.top-k-ch-thr",
844 profileTopKChangeThreshold,
845 "-Xprofile-top-k-change-threshold:");
Wei Jin54fc18b2014-06-09 16:29:54 -0700846
Andreas Gampe08b2d582014-12-18 14:39:22 -0800847 // Type of profile data.
848 parseRuntimeOption("dalvik.vm.profiler.type", profileType, "-Xprofile-type:");
Wei Jin54fc18b2014-06-09 16:29:54 -0700849
Andreas Gampe08b2d582014-12-18 14:39:22 -0800850 // Depth of bounded stack data
851 parseRuntimeOption("dalvik.vm.profile.stack-depth",
852 profileMaxStackDepth,
853 "-Xprofile-max-stack-depth:");
Dave Allison0efbd9a2014-01-30 14:19:51 -0800854
Andreas Gampecadcd512015-06-22 21:09:36 -0700855 /*
856 * Tracing options.
857 */
858 property_get("dalvik.vm.method-trace", propBuf, "false");
859 if (strcmp(propBuf, "true") == 0) {
860 addOption("-Xmethod-trace");
861 parseRuntimeOption("dalvik.vm.method-trace-file",
862 methodTraceFileBuf,
863 "-Xmethod-trace-file:");
864 parseRuntimeOption("dalvik.vm.method-trace-file-siz",
865 methodTraceFileSizeBuf,
866 "-Xmethod-trace-file-size:");
867 property_get("dalvik.vm.method-trace-stream", propBuf, "false");
868 if (strcmp(propBuf, "true") == 0) {
869 addOption("-Xmethod-trace-stream");
870 }
871 }
872
Andreas Gampe08b2d582014-12-18 14:39:22 -0800873 // Native bridge library. "0" means that native bridge is disabled.
874 property_get("ro.dalvik.vm.native.bridge", propBuf, "");
875 if (propBuf[0] == '\0') {
876 ALOGW("ro.dalvik.vm.native.bridge is not expected to be empty");
877 } else if (strcmp(propBuf, "0") != 0) {
878 snprintf(nativeBridgeLibrary, sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX,
879 "-XX:NativeBridge=%s", propBuf);
880 addOption(nativeBridgeLibrary);
Calin Juravlebe20ed42014-08-26 23:00:11 +0100881 }
Calin Juravle01db9162014-08-07 14:45:53 +0100882
Andreas Gampee324ba02015-03-31 16:15:17 -0700883 // Dalvik-cache pruning counter.
884 parseRuntimeOption("dalvik.vm.zygote.max-boot-retry", cachePruneBuf,
885 "-Xzygote-max-boot-retry=");
Dmitriy Ivanovdec46882014-09-30 15:10:48 -0700886#if defined(__LP64__)
887 const char* cpu_abilist_property_name = "ro.product.cpu.abilist64";
888#else
889 const char* cpu_abilist_property_name = "ro.product.cpu.abilist32";
890#endif // defined(__LP64__)
891 property_get(cpu_abilist_property_name, propBuf, "");
892 if (propBuf[0] == '\0') {
893 ALOGE("%s is not expected to be empty", cpu_abilist_property_name);
894 return -1;
895 }
896 snprintf(cpuAbiListBuf, sizeof(cpuAbiListBuf), "--cpu-abilist=%s", propBuf);
897 addOption(cpuAbiListBuf);
Andreas Gampee324ba02015-03-31 16:15:17 -0700898
Andreas Gampea876b352015-04-24 16:28:48 -0700899 /*
David Srbeckyf39477b2015-05-28 17:16:09 +0100900 * When running with debug.generate-debug-info, add --generate-debug-info to
901 * the compiler options so that the boot image, if it is compiled on device,
902 * will include native debugging information.
Andreas Gampea876b352015-04-24 16:28:48 -0700903 */
David Srbeckyf39477b2015-05-28 17:16:09 +0100904 property_get("debug.generate-debug-info", propBuf, "");
Andreas Gampea876b352015-04-24 16:28:48 -0700905 if (strcmp(propBuf, "true") == 0) {
906 addOption("-Xcompiler-option");
David Srbeckyf39477b2015-05-28 17:16:09 +0100907 addOption("--generate-debug-info");
Andreas Gampea876b352015-04-24 16:28:48 -0700908 addOption("-Ximage-compiler-option");
David Srbeckyf39477b2015-05-28 17:16:09 +0100909 addOption("--generate-debug-info");
Andreas Gampea876b352015-04-24 16:28:48 -0700910 }
911
Andreas Gampe1f105a62015-07-24 14:19:44 -0700912 /*
913 * Retrieve the build fingerprint and provide it to the runtime. That way, ANR dumps will
914 * contain the fingerprint and can be parsed.
915 */
916 parseRuntimeOption("ro.build.fingerprint", fingerprintBuf, "-Xfingerprint:");
917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800918 initArgs.version = JNI_VERSION_1_4;
919 initArgs.options = mOptions.editArray();
920 initArgs.nOptions = mOptions.size();
921 initArgs.ignoreUnrecognized = JNI_FALSE;
922
923 /*
924 * Initialize the VM.
925 *
926 * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread.
927 * If this call succeeds, the VM is ready, and we can start issuing
928 * JNI calls.
929 */
Andy McFaddenf70188a2009-03-31 15:52:13 -0700930 if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) {
Steve Block3762c312012-01-06 19:20:56 +0000931 ALOGE("JNI_CreateJavaVM failed\n");
Andreas Gampe605cca12015-04-02 23:12:56 -0700932 return -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 }
934
Andreas Gampe605cca12015-04-02 23:12:56 -0700935 return 0;
Andy McFaddenf70188a2009-03-31 15:52:13 -0700936}
937
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700938char* AndroidRuntime::toSlashClassName(const char* className)
939{
940 char* result = strdup(className);
941 for (char* cp = result; *cp != '\0'; cp++) {
942 if (*cp == '.') {
943 *cp = '/';
944 }
945 }
946 return result;
947}
948
Mike Lockwood9ee5e7e2014-09-08 16:15:21 -0700949/** Create a Java string from an ASCII or Latin-1 string */
950jstring AndroidRuntime::NewStringLatin1(JNIEnv* env, const char* bytes) {
951 if (!bytes) return NULL;
952 int length = strlen(bytes);
953 jchar* buffer = (jchar *)alloca(length * sizeof(jchar));
954 if (!buffer) return NULL;
955 jchar* chp = buffer;
956 for (int i = 0; i < length; i++) {
957 *chp++ = *bytes++;
958 }
959 return env->NewString(buffer, length);
960}
961
962
Andy McFaddenf70188a2009-03-31 15:52:13 -0700963/*
964 * Start the Android runtime. This involves starting the virtual machine
965 * and calling the "static void main(String[] args)" method in the class
966 * named by "className".
Jeff Brownebed7d62011-05-16 17:08:42 -0700967 *
968 * Passes the main function two arguments, the class name and the specified
969 * options string.
Andy McFaddenf70188a2009-03-31 15:52:13 -0700970 */
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100971void AndroidRuntime::start(const char* className, const Vector<String8>& options)
Andy McFaddenf70188a2009-03-31 15:52:13 -0700972{
Dianne Hackborn8e5aafe2014-10-27 18:04:10 -0700973 ALOGD(">>>>>> START %s uid %d <<<<<<\n",
974 className != NULL ? className : "(unknown)", getuid());
Andy McFaddenf70188a2009-03-31 15:52:13 -0700975
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100976 static const String8 startSystemServer("start-system-server");
977
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700978 /*
979 * 'startSystemServer == true' means runtime is obsolete and not run from
Andy McFaddenf70188a2009-03-31 15:52:13 -0700980 * init.rc anymore, so we print out the boot start event here.
981 */
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100982 for (size_t i = 0; i < options.size(); ++i) {
983 if (options[i] == startSystemServer) {
984 /* track our progress through the boot sequence */
985 const int LOG_BOOT_PROGRESS_START = 3000;
986 LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));
987 }
Andy McFaddenf70188a2009-03-31 15:52:13 -0700988 }
989
990 const char* rootDir = getenv("ANDROID_ROOT");
991 if (rootDir == NULL) {
992 rootDir = "/system";
993 if (!hasDir("/system")) {
994 LOG_FATAL("No root directory specified, and /android does not exist.");
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700995 return;
Andy McFaddenf70188a2009-03-31 15:52:13 -0700996 }
997 setenv("ANDROID_ROOT", rootDir, 1);
998 }
999
1000 //const char* kernelHack = getenv("LD_ASSUME_KERNEL");
Steve Block5baa3a62011-12-20 16:23:08 +00001001 //ALOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001002
1003 /* start the virtual machine */
Brian Carlstrom9f8203a2013-06-19 13:49:36 -07001004 JniInvocation jni_invocation;
1005 jni_invocation.Init(NULL);
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001006 JNIEnv* env;
1007 if (startVm(&mJavaVM, &env) != 0) {
1008 return;
1009 }
1010 onVmCreated(env);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001012 /*
1013 * Register android functions.
1014 */
1015 if (startReg(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001016 ALOGE("Unable to register all android natives\n");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001017 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001018 }
1019
1020 /*
1021 * We want to call main() with a String array with arguments in it.
Jeff Brownebed7d62011-05-16 17:08:42 -07001022 * At present we have two arguments, the class name and an option string.
1023 * Create an array to hold them.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001024 */
1025 jclass stringClass;
1026 jobjectArray strArray;
1027 jstring classNameStr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028
1029 stringClass = env->FindClass("java/lang/String");
1030 assert(stringClass != NULL);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001031 strArray = env->NewObjectArray(options.size() + 1, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 assert(strArray != NULL);
1033 classNameStr = env->NewStringUTF(className);
1034 assert(classNameStr != NULL);
1035 env->SetObjectArrayElement(strArray, 0, classNameStr);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001036
1037 for (size_t i = 0; i < options.size(); ++i) {
1038 jstring optionsStr = env->NewStringUTF(options.itemAt(i).string());
1039 assert(optionsStr != NULL);
1040 env->SetObjectArrayElement(strArray, i + 1, optionsStr);
1041 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001042
1043 /*
1044 * Start VM. This thread becomes the main thread of the VM, and will
1045 * not return until the VM exits.
1046 */
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001047 char* slashClassName = toSlashClassName(className);
1048 jclass startClass = env->FindClass(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 if (startClass == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001050 ALOGE("JavaVM unable to locate class '%s'\n", slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 /* keep going */
1052 } else {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001053 jmethodID startMeth = env->GetStaticMethodID(startClass, "main",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001054 "([Ljava/lang/String;)V");
1055 if (startMeth == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001056 ALOGE("JavaVM unable to find main() in '%s'\n", className);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001057 /* keep going */
1058 } else {
1059 env->CallStaticVoidMethod(startClass, startMeth, strArray);
1060
1061#if 0
1062 if (env->ExceptionCheck())
1063 threadExitUncaughtException(env);
1064#endif
1065 }
1066 }
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001067 free(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068
Steve Block5baa3a62011-12-20 16:23:08 +00001069 ALOGD("Shutting down VM\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001070 if (mJavaVM->DetachCurrentThread() != JNI_OK)
Steve Block8564c8d2012-01-05 23:22:43 +00001071 ALOGW("Warning: unable to detach main thread\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 if (mJavaVM->DestroyJavaVM() != 0)
Steve Block8564c8d2012-01-05 23:22:43 +00001073 ALOGW("Warning: VM did not shut down cleanly\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001074}
1075
Jeff Brown4280c4a2012-03-15 17:48:02 -07001076void AndroidRuntime::exit(int code)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077{
Jeff Brown4280c4a2012-03-15 17:48:02 -07001078 if (mExitWithoutCleanup) {
1079 ALOGI("VM exiting with result code %d, cleanup skipped.", code);
1080 ::_exit(code);
1081 } else {
1082 ALOGI("VM exiting with result code %d.", code);
1083 onExit(code);
1084 ::exit(code);
1085 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086}
1087
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001088void AndroidRuntime::onVmCreated(JNIEnv* env)
1089{
1090 // If AndroidRuntime had anything to do here, we'd have done it in 'start'.
1091}
1092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093/*
Andreas Huber9ae000c2014-02-13 17:22:33 +00001094 * Get the JNIEnv pointer for this thread.
1095 *
1096 * Returns NULL if the slot wasn't allocated or populated.
1097 */
1098/*static*/ JNIEnv* AndroidRuntime::getJNIEnv()
1099{
1100 JNIEnv* env;
1101 JavaVM* vm = AndroidRuntime::getJavaVM();
1102 assert(vm != NULL);
1103
1104 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
1105 return NULL;
1106 return env;
1107}
1108
1109/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 * Makes the current thread visible to the VM.
1111 *
1112 * The JNIEnv pointer returned is only valid for the current thread, and
1113 * thus must be tucked into thread-local storage.
1114 */
1115static int javaAttachThread(const char* threadName, JNIEnv** pEnv)
1116{
1117 JavaVMAttachArgs args;
1118 JavaVM* vm;
1119 jint result;
1120
1121 vm = AndroidRuntime::getJavaVM();
1122 assert(vm != NULL);
1123
1124 args.version = JNI_VERSION_1_4;
1125 args.name = (char*) threadName;
1126 args.group = NULL;
1127
1128 result = vm->AttachCurrentThread(pEnv, (void*) &args);
1129 if (result != JNI_OK)
Steve Block6215d3f2012-01-04 20:05:49 +00001130 ALOGI("NOTE: attach of thread '%s' failed\n", threadName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131
1132 return result;
1133}
1134
1135/*
1136 * Detach the current thread from the set visible to the VM.
1137 */
1138static int javaDetachThread(void)
1139{
1140 JavaVM* vm;
1141 jint result;
1142
1143 vm = AndroidRuntime::getJavaVM();
1144 assert(vm != NULL);
1145
1146 result = vm->DetachCurrentThread();
1147 if (result != JNI_OK)
Steve Block3762c312012-01-06 19:20:56 +00001148 ALOGE("ERROR: thread detach failed\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 return result;
1150}
1151
1152/*
1153 * When starting a native thread that will be visible from the VM, we
1154 * bounce through this to get the right attach/detach action.
1155 * Note that this function calls free(args)
1156 */
1157/*static*/ int AndroidRuntime::javaThreadShell(void* args) {
1158 void* start = ((void**)args)[0];
1159 void* userData = ((void **)args)[1];
1160 char* name = (char*) ((void **)args)[2]; // we own this storage
1161 free(args);
1162 JNIEnv* env;
1163 int result;
1164
1165 /* hook us into the VM */
1166 if (javaAttachThread(name, &env) != JNI_OK)
1167 return -1;
1168
1169 /* start the thread running */
1170 result = (*(android_thread_func_t)start)(userData);
1171
1172 /* unhook us */
1173 javaDetachThread();
1174 free(name);
1175
1176 return result;
1177}
1178
1179/*
1180 * This is invoked from androidCreateThreadEtc() via the callback
1181 * set with androidSetCreateThreadFunc().
1182 *
1183 * We need to create the new thread in such a way that it gets hooked
1184 * into the VM before it really starts executing.
1185 */
1186/*static*/ int AndroidRuntime::javaCreateThreadEtc(
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001187 android_thread_func_t entryFunction,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 void* userData,
1189 const char* threadName,
1190 int32_t threadPriority,
1191 size_t threadStackSize,
1192 android_thread_id_t* threadId)
1193{
1194 void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free
1195 int result;
1196
Mike Lockwood32f2e622013-10-10 10:11:27 -07001197 if (!threadName)
1198 threadName = "unnamed thread";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199
1200 args[0] = (void*) entryFunction;
1201 args[1] = userData;
1202 args[2] = (void*) strdup(threadName); // javaThreadShell must free
1203
1204 result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args,
1205 threadName, threadPriority, threadStackSize, threadId);
1206 return result;
1207}
1208
1209/*
1210 * Create a thread that is visible from the VM.
1211 *
1212 * This is called from elsewhere in the library.
1213 */
Mike Lockwoodf602d362010-06-20 14:28:16 -07001214/*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001215 void (*start)(void *), void* arg)
1216{
Mike Lockwoodf602d362010-06-20 14:28:16 -07001217 android_thread_id_t threadId = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001218 javaCreateThreadEtc((android_thread_func_t) start, arg, name,
Mike Lockwoodf602d362010-06-20 14:28:16 -07001219 ANDROID_PRIORITY_DEFAULT, 0, &threadId);
1220 return threadId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221}
1222
1223#if 0
1224static void quickTest(void* arg)
1225{
1226 const char* str = (const char*) arg;
1227
1228 printf("In quickTest: %s\n", str);
1229}
1230#endif
1231
1232#ifdef NDEBUG
1233 #define REG_JNI(name) { name }
1234 struct RegJNIRec {
1235 int (*mProc)(JNIEnv*);
1236 };
1237#else
1238 #define REG_JNI(name) { name, #name }
1239 struct RegJNIRec {
1240 int (*mProc)(JNIEnv*);
1241 const char* mName;
1242 };
1243#endif
1244
1245typedef void (*RegJAMProc)();
1246
1247static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env)
1248{
1249 for (size_t i = 0; i < count; i++) {
1250 if (array[i].mProc(env) < 0) {
1251#ifndef NDEBUG
Steve Block5baa3a62011-12-20 16:23:08 +00001252 ALOGD("----------!!! %s failed to load\n", array[i].mName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253#endif
1254 return -1;
1255 }
1256 }
1257 return 0;
1258}
1259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001260static const RegJNIRec gRegJNI[] = {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001261 REG_JNI(register_com_android_internal_os_RuntimeInit),
1262 REG_JNI(register_android_os_SystemClock),
1263 REG_JNI(register_android_util_EventLog),
1264 REG_JNI(register_android_util_Log),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 REG_JNI(register_android_content_AssetManager),
1266 REG_JNI(register_android_content_StringBlock),
1267 REG_JNI(register_android_content_XmlBlock),
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001268 REG_JNI(register_android_emoji_EmojiFactory),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269 REG_JNI(register_android_text_AndroidCharacter),
Anish Athalye88b5b0b2014-06-24 14:39:43 -07001270 REG_JNI(register_android_text_StaticLayout),
Doug Feltdae8e942010-02-24 14:33:15 -08001271 REG_JNI(register_android_text_AndroidBidi),
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001272 REG_JNI(register_android_view_InputDevice),
1273 REG_JNI(register_android_view_KeyCharacterMap),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001274 REG_JNI(register_android_os_Process),
Andreas Hubera8079bf2010-11-16 14:40:31 -08001275 REG_JNI(register_android_os_SystemProperties),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001276 REG_JNI(register_android_os_Binder),
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -08001277 REG_JNI(register_android_os_Parcel),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 REG_JNI(register_android_nio_utils),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001279 REG_JNI(register_android_graphics_Graphics),
Chris Craik54389792013-12-20 13:28:11 -08001280 REG_JNI(register_android_view_DisplayEventReceiver),
John Reckf666ad72014-03-14 16:24:57 -07001281 REG_JNI(register_android_view_RenderNode),
John Recke45b1fd2014-04-15 09:50:16 -07001282 REG_JNI(register_android_view_RenderNodeAnimator),
Romain Guy3b748a42013-04-17 18:54:38 -07001283 REG_JNI(register_android_view_GraphicBuffer),
Romain Guye4d01122010-06-16 18:44:05 -07001284 REG_JNI(register_android_view_GLES20Canvas),
John Reck04fc5832014-02-05 16:38:25 -08001285 REG_JNI(register_android_view_HardwareLayer),
John Reckcec24ae2013-11-05 13:27:50 -08001286 REG_JNI(register_android_view_ThreadedRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 REG_JNI(register_android_view_Surface),
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001288 REG_JNI(register_android_view_SurfaceControl),
Jeff Brown64a55af2012-08-26 02:47:39 -07001289 REG_JNI(register_android_view_SurfaceSession),
Romain Guy8f0095c2011-05-02 17:24:22 -07001290 REG_JNI(register_android_view_TextureView),
John Reck315c3292014-05-09 19:21:04 -07001291 REG_JNI(register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001292 REG_JNI(register_com_google_android_gles_jni_EGLImpl),
1293 REG_JNI(register_com_google_android_gles_jni_GLImpl),
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001294 REG_JNI(register_android_opengl_jni_EGL14),
Jesse Hall237c2b82013-05-06 11:36:57 -07001295 REG_JNI(register_android_opengl_jni_EGLExt),
Jack Palevich1c4907e2009-04-13 16:22:25 -07001296 REG_JNI(register_android_opengl_jni_GLES10),
1297 REG_JNI(register_android_opengl_jni_GLES10Ext),
1298 REG_JNI(register_android_opengl_jni_GLES11),
1299 REG_JNI(register_android_opengl_jni_GLES11Ext),
Jack Palevich560814f2009-11-19 16:34:55 +08001300 REG_JNI(register_android_opengl_jni_GLES20),
Jesse Halld877efe2013-04-29 15:59:35 -07001301 REG_JNI(register_android_opengl_jni_GLES30),
Jesse Hall7ab63ac2014-05-19 15:13:41 -07001302 REG_JNI(register_android_opengl_jni_GLES31),
1303 REG_JNI(register_android_opengl_jni_GLES31Ext),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001304
1305 REG_JNI(register_android_graphics_Bitmap),
1306 REG_JNI(register_android_graphics_BitmapFactory),
Wei-Ta Chen6b849e22010-09-07 17:32:18 +08001307 REG_JNI(register_android_graphics_BitmapRegionDecoder),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001308 REG_JNI(register_android_graphics_Camera),
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -04001309 REG_JNI(register_android_graphics_CreateJavaOutputStreamAdaptor),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001310 REG_JNI(register_android_graphics_Canvas),
John Reck52244ff2014-05-01 21:27:37 -07001311 REG_JNI(register_android_graphics_CanvasProperty),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001312 REG_JNI(register_android_graphics_ColorFilter),
1313 REG_JNI(register_android_graphics_DrawFilter),
Raph Levien1a73f7322014-01-30 16:06:28 -08001314 REG_JNI(register_android_graphics_FontFamily),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 REG_JNI(register_android_graphics_Interpolator),
1316 REG_JNI(register_android_graphics_LayerRasterizer),
1317 REG_JNI(register_android_graphics_MaskFilter),
1318 REG_JNI(register_android_graphics_Matrix),
1319 REG_JNI(register_android_graphics_Movie),
1320 REG_JNI(register_android_graphics_NinePatch),
1321 REG_JNI(register_android_graphics_Paint),
1322 REG_JNI(register_android_graphics_Path),
1323 REG_JNI(register_android_graphics_PathMeasure),
1324 REG_JNI(register_android_graphics_PathEffect),
1325 REG_JNI(register_android_graphics_Picture),
1326 REG_JNI(register_android_graphics_PorterDuff),
1327 REG_JNI(register_android_graphics_Rasterizer),
1328 REG_JNI(register_android_graphics_Region),
1329 REG_JNI(register_android_graphics_Shader),
Jamie Gennisaa0ce332011-01-06 17:04:26 -08001330 REG_JNI(register_android_graphics_SurfaceTexture),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001331 REG_JNI(register_android_graphics_Typeface),
1332 REG_JNI(register_android_graphics_Xfermode),
Wei-Ta Chenbca2d612009-11-30 17:52:05 +08001333 REG_JNI(register_android_graphics_YuvImage),
Svetoslav6811f4e2013-09-18 15:58:28 -07001334 REG_JNI(register_android_graphics_pdf_PdfDocument),
Svetoslav62ce3322014-09-04 21:17:17 -07001335 REG_JNI(register_android_graphics_pdf_PdfEditor),
Svetoslav29617692014-04-24 18:40:42 -07001336 REG_JNI(register_android_graphics_pdf_PdfRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001337
1338 REG_JNI(register_android_database_CursorWindow),
Jeff Browne5360fb2011-10-31 17:48:13 -07001339 REG_JNI(register_android_database_SQLiteConnection),
1340 REG_JNI(register_android_database_SQLiteGlobal),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001341 REG_JNI(register_android_database_SQLiteDebug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001342 REG_JNI(register_android_os_Debug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001343 REG_JNI(register_android_os_FileObserver),
Christopher Tatefa9e7c02010-05-06 12:07:10 -07001344 REG_JNI(register_android_os_MessageQueue),
Stephen Smalleyc07fca32012-01-13 08:31:39 -05001345 REG_JNI(register_android_os_SELinux),
Jeff Brown481c1572012-03-09 14:41:15 -08001346 REG_JNI(register_android_os_Trace),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 REG_JNI(register_android_os_UEventObserver),
1348 REG_JNI(register_android_net_LocalSocketImpl),
1349 REG_JNI(register_android_net_NetworkUtils),
Dan Egnor2b4abcd2010-04-07 17:30:50 -07001350 REG_JNI(register_android_net_TrafficStats),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351 REG_JNI(register_android_os_MemoryFile),
Narayan Kamath973b4662014-03-31 13:41:26 +01001352 REG_JNI(register_com_android_internal_os_Zygote),
John Reck9fa40712014-05-09 15:26:59 -07001353 REG_JNI(register_com_android_internal_util_VirtualRefBasePtr),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001354 REG_JNI(register_android_hardware_Camera),
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07001355 REG_JNI(register_android_hardware_camera2_CameraMetadata),
Ruben Brunkfeb50af2014-05-09 19:58:49 -07001356 REG_JNI(register_android_hardware_camera2_legacy_LegacyCameraDevice),
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -07001357 REG_JNI(register_android_hardware_camera2_legacy_PerfMeasurement),
Ruben Brunkb6079002014-05-22 12:33:54 -07001358 REG_JNI(register_android_hardware_camera2_DngCreator),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001359 REG_JNI(register_android_hardware_SensorManager),
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04001360 REG_JNI(register_android_hardware_SerialPort),
Eric Laurent60b62bc2014-04-18 17:50:49 -07001361 REG_JNI(register_android_hardware_SoundTrigger),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001362 REG_JNI(register_android_hardware_UsbDevice),
Mike Lockwoodacc29cc2011-03-11 08:18:08 -05001363 REG_JNI(register_android_hardware_UsbDeviceConnection),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001364 REG_JNI(register_android_hardware_UsbRequest),
destradaaa4fa3b52014-07-09 10:46:39 -07001365 REG_JNI(register_android_hardware_location_ActivityRecognitionHardware),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001366 REG_JNI(register_android_media_AudioRecord),
1367 REG_JNI(register_android_media_AudioSystem),
1368 REG_JNI(register_android_media_AudioTrack),
1369 REG_JNI(register_android_media_JetPlayer),
Jeff Browncbad9762012-09-04 21:57:59 -07001370 REG_JNI(register_android_media_RemoteDisplay),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001371 REG_JNI(register_android_media_ToneGenerator),
1372
1373 REG_JNI(register_android_opengl_classes),
JP Abgrall98a4f7e2011-09-02 15:36:33 -07001374 REG_JNI(register_android_server_NetworkManagementSocketTagger),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001375 REG_JNI(register_android_ddm_DdmHandleNativeHeap),
Joe Onorato1cf58742009-06-12 11:06:24 -07001376 REG_JNI(register_android_backup_BackupDataInput),
Joe Onoratod2110db2009-05-19 13:41:21 -07001377 REG_JNI(register_android_backup_BackupDataOutput),
Joe Onorato06290a42009-06-18 20:10:37 -07001378 REG_JNI(register_android_backup_FileBackupHelperBase),
Joe Onorato4ababd92009-06-25 18:29:18 -04001379 REG_JNI(register_android_backup_BackupHelperDispatcher),
Christopher Tate4a627c72011-04-01 14:43:32 -07001380 REG_JNI(register_android_app_backup_FullBackup),
Chet Haase9c1e23b2011-03-24 10:51:31 -07001381 REG_JNI(register_android_app_ActivityThread),
Dianne Hackborn69969e42010-05-04 11:40:40 -07001382 REG_JNI(register_android_app_NativeActivity),
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001383 REG_JNI(register_android_view_InputChannel),
Jeff Brown32cbc38552011-12-01 14:01:49 -08001384 REG_JNI(register_android_view_InputEventReceiver),
Jeff Brownc28867a2013-03-26 15:42:39 -07001385 REG_JNI(register_android_view_InputEventSender),
Michael Wrighta44dd262013-04-10 21:12:00 -07001386 REG_JNI(register_android_view_InputQueue),
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001387 REG_JNI(register_android_view_KeyEvent),
1388 REG_JNI(register_android_view_MotionEvent),
Jeff Brown2352b972011-04-12 22:39:53 -07001389 REG_JNI(register_android_view_PointerIcon),
Jeff Brown2ed24622011-03-14 19:39:54 -07001390 REG_JNI(register_android_view_VelocityTracker),
Kenny Root02c87302010-07-01 08:10:18 -07001391
1392 REG_JNI(register_android_content_res_ObbScanner),
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -07001393 REG_JNI(register_android_content_res_Configuration),
Chet Haase6e0ecb42010-11-03 19:41:18 -07001394
1395 REG_JNI(register_android_animation_PropertyValuesHolder),
Kenny Root66269ea2011-07-12 14:14:01 -07001396 REG_JNI(register_com_android_internal_content_NativeLibraryHelper),
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -08001397 REG_JNI(register_com_android_internal_net_NetworkStatsFactory),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001398};
1399
1400/*
1401 * Register android native functions with the VM.
1402 */
1403/*static*/ int AndroidRuntime::startReg(JNIEnv* env)
1404{
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001405 ATRACE_NAME("RegisterAndroidNatives");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406 /*
1407 * This hook causes all future threads created in this process to be
1408 * attached to the JavaVM. (This needs to go away in favor of JNI
1409 * Attach calls.)
1410 */
1411 androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc);
1412
Steve Block71f2cf12011-10-20 11:56:00 +01001413 ALOGV("--- registering native functions ---\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001414
1415 /*
1416 * Every "register" function calls one or more things that return
1417 * a local reference (e.g. FindClass). Because we haven't really
1418 * started the VM yet, they're all getting stored in the base frame
1419 * and never released. Use Push/Pop to manage the storage.
1420 */
1421 env->PushLocalFrame(200);
1422
1423 if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) {
1424 env->PopLocalFrame(NULL);
1425 return -1;
1426 }
1427 env->PopLocalFrame(NULL);
1428
1429 //createJavaThread("fubar", quickTest, (void*) "hello");
1430
1431 return 0;
1432}
1433
1434AndroidRuntime* AndroidRuntime::getRuntime()
1435{
1436 return gCurRuntime;
1437}
1438
1439/**
Narayan Kamathc21dab92015-06-25 14:22:00 +01001440 * Used by surface flinger's DdmConnection to register native methods from
1441 * the framework.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001442 */
Narayan Kamathc21dab92015-06-25 14:22:00 +01001443extern "C" jint registerFrameworkNatives(JNIEnv* env) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1445}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446} // namespace android