blob: ce7f0d58300037e7ee183febfca60093308240ae [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
17#define LOG_TAG "AndroidRuntime"
18//#define LOG_NDEBUG 0
19
20#include <android_runtime/AndroidRuntime.h>
Mathias Agopian07952722009-05-19 19:08:10 -070021#include <binder/IBinder.h>
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -080022#include <binder/IPCThreadState.h>
Mathias Agopian07952722009-05-19 19:08:10 -070023#include <binder/IServiceManager.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024#include <utils/Log.h>
25#include <utils/misc.h>
Mathias Agopian07952722009-05-19 19:08:10 -070026#include <binder/Parcel.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027#include <utils/threads.h>
28#include <cutils/properties.h>
29
30#include <SkGraphics.h>
31#include <SkImageDecoder.h>
32
33#include "jni.h"
34#include "JNIHelp.h"
Brian Carlstrom9f8203a2013-06-19 13:49:36 -070035#include "JniInvocation.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036#include "android_util_Binder.h"
37
38#include <stdio.h>
39#include <signal.h>
40#include <sys/stat.h>
41#include <sys/types.h>
42#include <signal.h>
43#include <dirent.h>
44#include <assert.h>
45
46
47using namespace android;
48
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049extern int register_android_os_Binder(JNIEnv* env);
50extern int register_android_os_Process(JNIEnv* env);
51extern int register_android_graphics_Bitmap(JNIEnv*);
52extern int register_android_graphics_BitmapFactory(JNIEnv*);
Wei-Ta Chen6b849e22010-09-07 17:32:18 +080053extern int register_android_graphics_BitmapRegionDecoder(JNIEnv*);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054extern int register_android_graphics_Camera(JNIEnv* env);
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -040055extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056extern int register_android_graphics_Graphics(JNIEnv* env);
57extern int register_android_graphics_Interpolator(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058extern int register_android_graphics_MaskFilter(JNIEnv* env);
59extern int register_android_graphics_Movie(JNIEnv* env);
60extern int register_android_graphics_NinePatch(JNIEnv*);
61extern int register_android_graphics_PathEffect(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062extern int register_android_graphics_Shader(JNIEnv* env);
63extern int register_android_graphics_Typeface(JNIEnv* env);
Wei-Ta Chenbca2d612009-11-30 17:52:05 +080064extern int register_android_graphics_YuvImage(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065
66extern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env);
67extern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070068extern int register_android_opengl_jni_EGL14(JNIEnv* env);
Jesse Hall237c2b82013-05-06 11:36:57 -070069extern int register_android_opengl_jni_EGLExt(JNIEnv* env);
Jack Palevich1c4907e2009-04-13 16:22:25 -070070extern int register_android_opengl_jni_GLES10(JNIEnv* env);
71extern int register_android_opengl_jni_GLES10Ext(JNIEnv* env);
72extern int register_android_opengl_jni_GLES11(JNIEnv* env);
73extern int register_android_opengl_jni_GLES11Ext(JNIEnv* env);
Jack Palevich560814f2009-11-19 16:34:55 +080074extern int register_android_opengl_jni_GLES20(JNIEnv* env);
Jesse Halld877efe2013-04-29 15:59:35 -070075extern int register_android_opengl_jni_GLES30(JNIEnv* env);
Jesse Hall7ab63ac2014-05-19 15:13:41 -070076extern int register_android_opengl_jni_GLES31(JNIEnv* env);
77extern int register_android_opengl_jni_GLES31Ext(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078
79extern int register_android_hardware_Camera(JNIEnv *env);
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -070080extern int register_android_hardware_camera2_CameraMetadata(JNIEnv *env);
Ruben Brunkfeb50af2014-05-09 19:58:49 -070081extern int register_android_hardware_camera2_legacy_LegacyCameraDevice(JNIEnv *env);
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -070082extern int register_android_hardware_camera2_legacy_PerfMeasurement(JNIEnv *env);
Ruben Brunkb6079002014-05-22 12:33:54 -070083extern int register_android_hardware_camera2_DngCreator(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084extern int register_android_hardware_SensorManager(JNIEnv *env);
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -040085extern int register_android_hardware_SerialPort(JNIEnv *env);
Eric Laurent60b62bc2014-04-18 17:50:49 -070086extern int register_android_hardware_SoundTrigger(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -050087extern int register_android_hardware_UsbDevice(JNIEnv *env);
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050088extern int register_android_hardware_UsbDeviceConnection(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -050089extern int register_android_hardware_UsbRequest(JNIEnv *env);
destradaaa4fa3b52014-07-09 10:46:39 -070090extern int register_android_hardware_location_ActivityRecognitionHardware(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091
92extern int register_android_media_AudioRecord(JNIEnv *env);
93extern int register_android_media_AudioSystem(JNIEnv *env);
94extern int register_android_media_AudioTrack(JNIEnv *env);
95extern int register_android_media_JetPlayer(JNIEnv *env);
96extern int register_android_media_ToneGenerator(JNIEnv *env);
97
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098namespace android {
99
100/*
101 * JNI-based registration functions. Note these are properly contained in
102 * namespace android.
103 */
104extern int register_android_content_AssetManager(JNIEnv* env);
105extern int register_android_util_EventLog(JNIEnv* env);
106extern int register_android_util_Log(JNIEnv* env);
107extern int register_android_content_StringBlock(JNIEnv* env);
108extern int register_android_content_XmlBlock(JNIEnv* env);
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700109extern int register_android_emoji_EmojiFactory(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110extern int register_android_graphics_Canvas(JNIEnv* env);
John Reck52244ff2014-05-01 21:27:37 -0700111extern int register_android_graphics_CanvasProperty(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112extern int register_android_graphics_ColorFilter(JNIEnv* env);
113extern int register_android_graphics_DrawFilter(JNIEnv* env);
Raph Levien1a73f7322014-01-30 16:06:28 -0800114extern int register_android_graphics_FontFamily(JNIEnv* env);
Mike Reed4c9355c2014-05-07 11:48:37 -0400115extern int register_android_graphics_LayerRasterizer(JNIEnv*);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116extern int register_android_graphics_Matrix(JNIEnv* env);
117extern int register_android_graphics_Paint(JNIEnv* env);
118extern int register_android_graphics_Path(JNIEnv* env);
119extern int register_android_graphics_PathMeasure(JNIEnv* env);
120extern int register_android_graphics_Picture(JNIEnv*);
121extern int register_android_graphics_PorterDuff(JNIEnv* env);
122extern int register_android_graphics_Rasterizer(JNIEnv* env);
Jeff Brownfbf09772011-01-16 14:06:57 -0800123extern int register_android_graphics_Region(JNIEnv* env);
Jamie Gennisaa0ce332011-01-06 17:04:26 -0800124extern int register_android_graphics_SurfaceTexture(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125extern int register_android_graphics_Xfermode(JNIEnv* env);
Svetoslav6811f4e2013-09-18 15:58:28 -0700126extern int register_android_graphics_pdf_PdfDocument(JNIEnv* env);
Svetoslav62ce3322014-09-04 21:17:17 -0700127extern int register_android_graphics_pdf_PdfEditor(JNIEnv* env);
Svetoslav29617692014-04-24 18:40:42 -0700128extern int register_android_graphics_pdf_PdfRenderer(JNIEnv* env);
Jeff Brown0a0a1242011-12-02 02:25:22 -0800129extern int register_android_view_DisplayEventReceiver(JNIEnv* env);
John Reckf666ad72014-03-14 16:24:57 -0700130extern int register_android_view_RenderNode(JNIEnv* env);
John Recke45b1fd2014-04-15 09:50:16 -0700131extern int register_android_view_RenderNodeAnimator(JNIEnv* env);
Romain Guy3b748a42013-04-17 18:54:38 -0700132extern int register_android_view_GraphicBuffer(JNIEnv* env);
Romain Guye4d01122010-06-16 18:44:05 -0700133extern int register_android_view_GLES20Canvas(JNIEnv* env);
John Reck04fc5832014-02-05 16:38:25 -0800134extern int register_android_view_HardwareLayer(JNIEnv* env);
John Reckcec24ae2013-11-05 13:27:50 -0800135extern int register_android_view_ThreadedRenderer(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136extern int register_android_view_Surface(JNIEnv* env);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800137extern int register_android_view_SurfaceControl(JNIEnv* env);
Jeff Brown64a55af2012-08-26 02:47:39 -0700138extern int register_android_view_SurfaceSession(JNIEnv* env);
Romain Guy8f0095c2011-05-02 17:24:22 -0700139extern int register_android_view_TextureView(JNIEnv* env);
John Reck315c3292014-05-09 19:21:04 -0700140extern int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141extern int register_android_database_CursorWindow(JNIEnv* env);
Jeff Browne5360fb2011-10-31 17:48:13 -0700142extern int register_android_database_SQLiteConnection(JNIEnv* env);
143extern int register_android_database_SQLiteGlobal(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144extern int register_android_database_SQLiteDebug(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145extern int register_android_nio_utils(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146extern int register_android_os_Debug(JNIEnv* env);
Christopher Tatefa9e7c02010-05-06 12:07:10 -0700147extern int register_android_os_MessageQueue(JNIEnv* env);
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -0800148extern int register_android_os_Parcel(JNIEnv* env);
Stephen Smalleyc07fca32012-01-13 08:31:39 -0500149extern int register_android_os_SELinux(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150extern int register_android_os_SystemProperties(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151extern int register_android_os_SystemClock(JNIEnv* env);
Jeff Brown481c1572012-03-09 14:41:15 -0800152extern int register_android_os_Trace(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153extern int register_android_os_FileObserver(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154extern int register_android_os_UEventObserver(JNIEnv* env);
155extern int register_android_os_MemoryFile(JNIEnv* env);
156extern int register_android_net_LocalSocketImpl(JNIEnv* env);
157extern int register_android_net_NetworkUtils(JNIEnv* env);
Dan Egnor2b4abcd2010-04-07 17:30:50 -0700158extern int register_android_net_TrafficStats(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159extern int register_android_text_AndroidCharacter(JNIEnv *env);
Anish Athalye88b5b0b2014-06-24 14:39:43 -0700160extern int register_android_text_StaticLayout(JNIEnv *env);
Doug Feltdae8e942010-02-24 14:33:15 -0800161extern int register_android_text_AndroidBidi(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162extern int register_android_opengl_classes(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
Narayan Kamath29564cd2014-08-07 10:57:40 +0100164extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env);
Joe Onorato1cf58742009-06-12 11:06:24 -0700165extern int register_android_backup_BackupDataInput(JNIEnv *env);
Joe Onoratod2110db2009-05-19 13:41:21 -0700166extern int register_android_backup_BackupDataOutput(JNIEnv *env);
Joe Onorato06290a42009-06-18 20:10:37 -0700167extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
Joe Onorato4ababd92009-06-25 18:29:18 -0400168extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
Christopher Tate4a627c72011-04-01 14:43:32 -0700169extern int register_android_app_backup_FullBackup(JNIEnv *env);
Chet Haase9c1e23b2011-03-24 10:51:31 -0700170extern int register_android_app_ActivityThread(JNIEnv *env);
Dianne Hackborn69969e42010-05-04 11:40:40 -0700171extern int register_android_app_NativeActivity(JNIEnv *env);
Jeff Browncbad9762012-09-04 21:57:59 -0700172extern int register_android_media_RemoteDisplay(JNIEnv *env);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700173extern int register_android_view_InputChannel(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700174extern int register_android_view_InputDevice(JNIEnv* env);
Jeff Brown32cbc38552011-12-01 14:01:49 -0800175extern int register_android_view_InputEventReceiver(JNIEnv* env);
Jeff Brownc28867a2013-03-26 15:42:39 -0700176extern int register_android_view_InputEventSender(JNIEnv* env);
Michael Wrighta44dd262013-04-10 21:12:00 -0700177extern int register_android_view_InputQueue(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700178extern int register_android_view_KeyCharacterMap(JNIEnv *env);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700179extern int register_android_view_KeyEvent(JNIEnv* env);
180extern int register_android_view_MotionEvent(JNIEnv* env);
Jeff Brown2352b972011-04-12 22:39:53 -0700181extern int register_android_view_PointerIcon(JNIEnv* env);
Jeff Brown2ed24622011-03-14 19:39:54 -0700182extern int register_android_view_VelocityTracker(JNIEnv* env);
Kenny Root02c87302010-07-01 08:10:18 -0700183extern int register_android_content_res_ObbScanner(JNIEnv* env);
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700184extern int register_android_content_res_Configuration(JNIEnv* env);
Chet Haase6e0ecb42010-11-03 19:41:18 -0700185extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
Kenny Root66269ea2011-07-12 14:14:01 -0700186extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -0800187extern int register_com_android_internal_net_NetworkStatsFactory(JNIEnv *env);
Narayan Kamath973b4662014-03-31 13:41:26 +0100188extern int register_com_android_internal_os_Zygote(JNIEnv *env);
John Reck9fa40712014-05-09 15:26:59 -0700189extern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190
191static AndroidRuntime* gCurRuntime = NULL;
192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193/*
194 * Code written in the Java Programming Language calls here from main().
195 */
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700196static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197{
198 gCurRuntime->onStarted();
199}
200
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700201static void com_android_internal_os_RuntimeInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202{
203 gCurRuntime->onZygoteInit();
204}
205
Jeff Brown4280c4a2012-03-15 17:48:02 -0700206static void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIEnv* env,
207 jobject clazz, jboolean exitWithoutCleanup)
208{
209 gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup);
210}
211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212/*
213 * JNI registration.
214 */
215static JNINativeMethod gMethods[] = {
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700216 { "nativeFinishInit", "()V",
217 (void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
218 { "nativeZygoteInit", "()V",
219 (void*) com_android_internal_os_RuntimeInit_nativeZygoteInit },
Jeff Brown4280c4a2012-03-15 17:48:02 -0700220 { "nativeSetExitWithoutCleanup", "(Z)V",
221 (void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222};
223
224int register_com_android_internal_os_RuntimeInit(JNIEnv* env)
225{
226 return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
227 gMethods, NELEM(gMethods));
228}
229
230// ----------------------------------------------------------------------
231
Andreas Huber9ae000c2014-02-13 17:22:33 +0000232/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
233
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000234AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) :
235 mExitWithoutCleanup(false),
236 mArgBlockStart(argBlockStart),
237 mArgBlockLength(argBlockLength)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700239 SkGraphics::Init();
Mike Reedfc8db532009-04-27 11:43:30 -0400240 // There is also a global font cache, but its budget is specified in code
241 // see SkFontHost_android.cpp
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242
243 // Pre-allocate enough space to hold a fair number of options.
244 mOptions.setCapacity(20);
245
246 assert(gCurRuntime == NULL); // one per process
247 gCurRuntime = this;
248}
249
250AndroidRuntime::~AndroidRuntime()
251{
252 SkGraphics::Term();
253}
254
Andreas Huber9ae000c2014-02-13 17:22:33 +0000255/*
256 * Register native methods using JNI.
257 */
258/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
259 const char* className, const JNINativeMethod* gMethods, int numMethods)
260{
261 return jniRegisterNativeMethods(env, className, gMethods, numMethods);
262}
263
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000264void AndroidRuntime::setArgv0(const char* argv0) {
Jeff Brown00c0cd42014-09-10 16:48:46 -0700265 memset(mArgBlockStart, 0, mArgBlockLength);
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000266 strlcpy(mArgBlockStart, argv0, mArgBlockLength);
267}
268
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100269status_t AndroidRuntime::callMain(const String8& className, jclass clazz,
270 const Vector<String8>& args)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271{
272 JNIEnv* env;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 jmethodID methodId;
274
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100275 ALOGD("Calling main entry %s", className.string());
Dianne Hackborn08e60f22010-09-01 18:17:17 -0700276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 env = getJNIEnv();
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700278 if (clazz == NULL || env == NULL) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 return UNKNOWN_ERROR;
280 }
281
282 methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
283 if (methodId == NULL) {
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100284 ALOGE("ERROR: could not find method %s.main(String[])\n", className.string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 return UNKNOWN_ERROR;
286 }
287
288 /*
289 * We want to call main() with a String array with our arguments in it.
290 * Create an array and populate it.
291 */
292 jclass stringClass;
293 jobjectArray strArray;
294
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100295 const size_t numArgs = args.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 stringClass = env->FindClass("java/lang/String");
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100297 strArray = env->NewObjectArray(numArgs, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100299 for (size_t i = 0; i < numArgs; i++) {
300 jstring argStr = env->NewStringUTF(args[i].string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 env->SetObjectArrayElement(strArray, i, argStr);
302 }
303
304 env->CallStaticVoidMethod(clazz, methodId, strArray);
305 return NO_ERROR;
306}
307
308/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 * The VM calls this through the "exit" hook.
310 */
311static void runtime_exit(int code)
312{
Jeff Brown4280c4a2012-03-15 17:48:02 -0700313 gCurRuntime->exit(code);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314}
315
316/*
317 * The VM calls this through the "vfprintf" hook.
318 *
319 * We ignore "fp" and just write the results to the log file.
320 */
321static void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
322{
323 LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
324}
325
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800326/**
327 * The VM calls this when mutex contention debugging is enabled to
328 * determine whether or not the blocked thread was a "sensitive thread"
329 * for user responsiveness/smoothess.
330 *
331 * Our policy for this is whether or not we're tracing any StrictMode
332 * events on this thread (which we might've inherited via Binder calls
333 * into us)
334 */
335static bool runtime_isSensitiveThread() {
336 IPCThreadState* state = IPCThreadState::selfOrNull();
337 return state && state->getStrictModePolicy() != 0;
338}
339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340static int hasDir(const char* dir)
341{
342 struct stat s;
343 int res = stat(dir, &s);
344 if (res == 0) {
345 return S_ISDIR(s.st_mode);
346 }
347 return 0;
348}
349
Andreas Gampe65ff8ee2014-11-14 16:15:17 -0800350static bool hasFile(const char* file) {
351 struct stat s;
352 int res = stat(file, &s);
353 if (res == 0) {
354 return S_ISREG(s.st_mode);
355 }
356 return false;
357}
358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 * Read the persistent locale.
361 */
362static void readLocale(char* language, char* region)
363{
364 char propLang[PROPERTY_VALUE_MAX], propRegn[PROPERTY_VALUE_MAX];
Brian Carlstrom171ea892010-08-24 21:27:52 -0700365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 property_get("persist.sys.language", propLang, "");
367 property_get("persist.sys.country", propRegn, "");
368 if (*propLang == 0 && *propRegn == 0) {
369 /* Set to ro properties, default is en_US */
370 property_get("ro.product.locale.language", propLang, "en");
371 property_get("ro.product.locale.region", propRegn, "US");
372 }
Narayan Kamath37151b52014-07-01 12:44:51 +0100373 strncat(language, propLang, 3);
374 strncat(region, propRegn, 3);
Steve Block5baa3a62011-12-20 16:23:08 +0000375 //ALOGD("language=%s region=%s\n", language, region);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376}
377
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700378void AndroidRuntime::addOption(const char* optionString, void* extraInfo)
379{
380 JavaVMOption opt;
381 opt.optionString = optionString;
382 opt.extraInfo = extraInfo;
383 mOptions.add(opt);
384}
385
Andy McFaddenf70188a2009-03-31 15:52:13 -0700386/*
Andy McFaddene4d81f22010-07-14 16:02:20 -0700387 * Parse a property containing space-separated options that should be
388 * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
389 *
390 * This will cut up "extraOptsBuf" as we chop it into individual options.
391 *
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800392 * If "quotingArg" is non-null, it is passed before each extra option in mOptions.
393 *
Andy McFaddene4d81f22010-07-14 16:02:20 -0700394 * Adds the strings, if any, to mOptions.
395 */
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800396void AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg)
Andy McFaddene4d81f22010-07-14 16:02:20 -0700397{
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800398 char* start = extraOptsBuf;
399 char* end = NULL;
Andy McFaddene4d81f22010-07-14 16:02:20 -0700400 while (*start != '\0') {
401 while (*start == ' ') /* skip leading whitespace */
402 start++;
403 if (*start == '\0') /* was trailing ws, bail */
404 break;
405
406 end = start+1;
407 while (*end != ' ' && *end != '\0') /* find end of token */
408 end++;
409 if (*end == ' ')
410 *end++ = '\0'; /* mark end, advance to indicate more */
411
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800412 if (quotingArg != NULL) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700413 addOption(quotingArg);
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800414 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700415 addOption(start);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700416 start = end;
417 }
418}
419
420/*
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700421 * Reads a "property" into "buffer" with a default of "defaultArg". If
422 * the property is non-empty, it is treated as a runtime option such
423 * as "-Xmx32m".
424 *
425 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
426 *
427 * If an argument is found, it is added to mOptions.
428 *
429 * If an option is found, it is added to mOptions and true is
430 * returned. Otherwise false is returned.
431 */
432bool AndroidRuntime::parseRuntimeOption(const char* property,
433 char* buffer,
434 const char* runtimeArg,
435 const char* defaultArg)
436{
437 strcpy(buffer, runtimeArg);
438 size_t runtimeArgLen = strlen(runtimeArg);
439 property_get(property, buffer+runtimeArgLen, defaultArg);
440 if (buffer[runtimeArgLen] == '\0') {
441 return false;
442 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700443 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700444 return true;
445}
446
447/*
448 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700449 * is treated as a dex2oat compiler option that should be
450 * passed as a quoted option, e.g. "-Ximage-compiler-option --compiler-filter=verify-none".
451 *
452 * The "compilerArg" is a prefix for the option such as "--compiler-filter=".
453 *
454 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
455 *
456 * If an option is found, it is added to mOptions and true is
457 * returned. Otherwise false is returned.
458 */
459bool AndroidRuntime::parseCompilerOption(const char* property,
460 char* buffer,
461 const char* compilerArg,
462 const char* quotingArg)
463{
464 strcpy(buffer, compilerArg);
465 size_t compilerArgLen = strlen(compilerArg);
466 property_get(property, buffer+compilerArgLen, "");
467 if (buffer[compilerArgLen] == '\0') {
468 return false;
469 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700470 addOption(quotingArg);
471 addOption(buffer);
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700472 return true;
473}
474
475/*
476 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700477 * is treated as a dex2oat compiler runtime option that should be
478 * passed as a quoted option, e.g. "-Ximage-compiler-option
479 * --runtime-arg -Ximage-compiler-option -Xmx32m".
480 *
481 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
482 *
483 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
484 *
485 * If an option is found, it is added to mOptions and true is
486 * returned. Otherwise false is returned.
487 */
488bool AndroidRuntime::parseCompilerRuntimeOption(const char* property,
489 char* buffer,
490 const char* runtimeArg,
491 const char* quotingArg)
492{
493 strcpy(buffer, runtimeArg);
494 size_t runtimeArgLen = strlen(runtimeArg);
495 property_get(property, buffer+runtimeArgLen, "");
496 if (buffer[runtimeArgLen] == '\0') {
497 return false;
498 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700499 addOption(quotingArg);
500 addOption("--runtime-arg");
501 addOption(quotingArg);
502 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700503 return true;
504}
505
506/*
Andy McFaddenf70188a2009-03-31 15:52:13 -0700507 * Start the Dalvik Virtual Machine.
508 *
509 * Various arguments, most determined by system properties, are passed in.
510 * The "mOptions" vector is updated.
511 *
Dave Allison07a1e232014-03-14 08:54:33 -0700512 * CAUTION: when adding options in here, be careful not to put the
513 * char buffer inside a nested scope. Adding the buffer to the
514 * options using mOptions.add() does not copy the buffer, so if the
515 * buffer goes out of scope the option may be overwritten. It's best
516 * to put the buffer at the top of the function so that it is more
517 * unlikely that someone will surround it in a scope at a later time
518 * and thus introduce a bug.
519 *
Andy McFaddenf70188a2009-03-31 15:52:13 -0700520 * Returns 0 on success.
521 */
522int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523{
Andy McFaddenf70188a2009-03-31 15:52:13 -0700524 int result = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525 JavaVMInitArgs initArgs;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526 char propBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700527 char stackTraceFileBuf[sizeof("-Xstacktracefile:")-1 + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro38cfa8c2010-12-07 16:48:29 -0800529 char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700530 char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro8cdf27c32011-01-19 12:33:12 -0800531 char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700532 char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
533 char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier7e4fdec2013-12-02 15:46:51 -0800534 char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700535 char backgroundgcOptsBuf[sizeof("-XX:BackgroundGC=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700536 char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700537 char dex2oatXmsImageFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
538 char dex2oatXmxImageFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
539 char dex2oatXmsFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
540 char dex2oatXmxFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700541 char dex2oatCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
542 char dex2oatImageCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800543 char dex2oatFlagsBuf[PROPERTY_VALUE_MAX];
544 char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX];
Andy McFaddene4d81f22010-07-14 16:02:20 -0700545 char extraOptsBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700546 char voldDecryptBuf[PROPERTY_VALUE_MAX];
Ben Cheng52b0e732009-06-19 13:31:12 -0700547 enum {
548 kEMDefault,
549 kEMIntPortable,
550 kEMIntFast,
Ben Cheng52b0e732009-06-19 13:31:12 -0700551 kEMJitCompiler,
Ben Cheng52b0e732009-06-19 13:31:12 -0700552 } executionMode = kEMDefault;
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700553 char profilePeriod[sizeof("-Xprofile-period:")-1 + PROPERTY_VALUE_MAX];
554 char profileDuration[sizeof("-Xprofile-duration:")-1 + PROPERTY_VALUE_MAX];
555 char profileInterval[sizeof("-Xprofile-interval:")-1 + PROPERTY_VALUE_MAX];
556 char profileBackoff[sizeof("-Xprofile-backoff:")-1 + PROPERTY_VALUE_MAX];
557 char profileTopKThreshold[sizeof("-Xprofile-top-k-threshold:")-1 + PROPERTY_VALUE_MAX];
558 char profileTopKChangeThreshold[sizeof("-Xprofile-top-k-change-threshold:")-1 +
559 PROPERTY_VALUE_MAX];
560 char profileType[sizeof("-Xprofile-type:")-1 + PROPERTY_VALUE_MAX];
561 char profileMaxStackDepth[sizeof("-Xprofile-max-stack-depth:")-1 + PROPERTY_VALUE_MAX];
Dave Allison07a1e232014-03-14 08:54:33 -0700562 char langOption[sizeof("-Duser.language=") + 3];
563 char regionOption[sizeof("-Duser.region=") + 3];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700564 char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle01db9162014-08-07 14:45:53 +0100565 char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700567 bool checkJni = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 property_get("dalvik.vm.checkjni", propBuf, "");
569 if (strcmp(propBuf, "true") == 0) {
570 checkJni = true;
571 } else if (strcmp(propBuf, "false") != 0) {
572 /* property is neither true nor false; fall back on kernel parameter */
573 property_get("ro.kernel.android.checkjni", propBuf, "");
574 if (propBuf[0] == '1') {
575 checkJni = true;
576 }
577 }
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700578 ALOGD("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
579 if (checkJni) {
580 /* extended JNI checking */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700581 addOption("-Xcheck:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700582
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700583 /* with -Xcheck:jni, this provides a JNI function call trace */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700584 //addOption("-verbose:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700585 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586
587 property_get("dalvik.vm.execution-mode", propBuf, "");
588 if (strcmp(propBuf, "int:portable") == 0) {
589 executionMode = kEMIntPortable;
590 } else if (strcmp(propBuf, "int:fast") == 0) {
591 executionMode = kEMIntFast;
Ben Cheng52b0e732009-06-19 13:31:12 -0700592 } else if (strcmp(propBuf, "int:jit") == 0) {
593 executionMode = kEMJitCompiler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 }
595
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700596 parseRuntimeOption("dalvik.vm.stack-trace-file", stackTraceFileBuf, "-Xstacktracefile:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 strcpy(jniOptsBuf, "-Xjniopts:");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700599 if (parseRuntimeOption("dalvik.vm.jniopts", jniOptsBuf, "-Xjniopts:")) {
600 ALOGI("JNI options: '%s'\n", jniOptsBuf);
601 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 /* route exit() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700604 addOption("exit", (void*) runtime_exit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605
606 /* route fprintf() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700607 addOption("vfprintf", (void*) runtime_vfprintf);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800609 /* register the framework-specific "is sensitive thread" hook */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700610 addOption("sensitiveThread", (void*) runtime_isSensitiveThread);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800611
612 /* enable verbose; standard options are { jni, gc, class } */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700613 //addOption("-verbose:jni");
614 addOption("-verbose:gc");
615 //addOption("-verbose:class");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800616
Carl Shapiro9e4c8842010-12-08 12:14:46 -0800617 /*
618 * The default starting and maximum size of the heap. Larger
619 * values should be specified in a product property override.
620 */
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700621 parseRuntimeOption("dalvik.vm.heapstartsize", heapstartsizeOptsBuf, "-Xms", "4m");
622 parseRuntimeOption("dalvik.vm.heapsize", heapsizeOptsBuf, "-Xmx", "16m");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700624 parseRuntimeOption("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
625 parseRuntimeOption("dalvik.vm.heapminfree", heapminfreeOptsBuf, "-XX:HeapMinFree=");
626 parseRuntimeOption("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf, "-XX:HeapMaxFree=");
627 parseRuntimeOption("dalvik.vm.heaptargetutilization",
628 heaptargetutilizationOptsBuf,
629 "-XX:HeapTargetUtilization=");
Ian Rogers53250102012-09-23 16:38:03 -0700630
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700631 property_get("ro.config.low_ram", propBuf, "");
632 if (strcmp(propBuf, "true") == 0) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700633 addOption("-XX:LowMemoryMode");
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700634 }
635
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700636 parseRuntimeOption("dalvik.vm.gctype", gctypeOptsBuf, "-Xgc:");
637 parseRuntimeOption("dalvik.vm.backgroundgctype", backgroundgcOptsBuf, "-XX:BackgroundGC=");
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 /* enable debugging; set suspend=y to pause during VM init */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 /* use android ADB transport */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700641 addOption("-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800642
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700643 parseRuntimeOption("dalvik.vm.lockprof.threshold",
644 lockProfThresholdBuf,
645 "-Xlockprofthreshold:");
Carl Shapirod8f3ec62010-04-12 16:31:59 -0700646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647 if (executionMode == kEMIntPortable) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700648 addOption("-Xint:portable");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800649 } else if (executionMode == kEMIntFast) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700650 addOption("-Xint:fast");
Ben Cheng52b0e732009-06-19 13:31:12 -0700651 } else if (executionMode == kEMJitCompiler) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700652 addOption("-Xint:jit");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 }
Andy McFaddene2b23e12009-04-03 11:09:46 -0700654
Andreas Gampe08b2d582014-12-18 14:39:22 -0800655 // If we are booting without the real /data, don't spend time compiling.
656 property_get("vold.decrypt", voldDecryptBuf, "");
657 bool skip_compilation = ((strcmp(voldDecryptBuf, "trigger_restart_min_framework") == 0) ||
658 (strcmp(voldDecryptBuf, "1") == 0));
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800659
Andreas Gampe08b2d582014-12-18 14:39:22 -0800660 // Extra options for boot.art/boot.oat image generation.
661 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xms", dex2oatXmsImageFlagsBuf,
662 "-Xms", "-Ximage-compiler-option");
663 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xmx", dex2oatXmxImageFlagsBuf,
664 "-Xmx", "-Ximage-compiler-option");
665 if (skip_compilation) {
Brian Carlstromce5bbbe2014-07-30 15:13:17 -0700666 addOption("-Ximage-compiler-option");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800667 addOption("--compiler-filter=verify-none");
668 } else {
669 parseCompilerOption("dalvik.vm.image-dex2oat-filter", dex2oatImageCompilerFilterBuf,
670 "--compiler-filter=", "-Ximage-compiler-option");
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800671 }
672
Andreas Gampe08b2d582014-12-18 14:39:22 -0800673 // Make sure there is a preloaded-classes file.
674 if (!hasFile("/system/etc/preloaded-classes")) {
675 ALOGE("Missing preloaded-classes file, /system/etc/preloaded-classes not found: %s\n",
676 strerror(errno));
677 goto bail;
678 }
679 addOption("-Ximage-compiler-option");
680 addOption("--image-classes=/system/etc/preloaded-classes");
681
682 // If there is a compiled-classes file, push it.
683 if (hasFile("/system/etc/compiled-classes")) {
684 addOption("-Ximage-compiler-option");
685 addOption("--compiled-classes=/system/etc/compiled-classes");
686 }
687
688 property_get("dalvik.vm.image-dex2oat-flags", dex2oatImageFlagsBuf, "");
689 parseExtraOpts(dex2oatImageFlagsBuf, "-Ximage-compiler-option");
690
691 // Extra options for DexClassLoader.
692 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xms", dex2oatXmsFlagsBuf,
693 "-Xms", "-Xcompiler-option");
694 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xmx", dex2oatXmxFlagsBuf,
695 "-Xmx", "-Xcompiler-option");
696 if (skip_compilation) {
697 addOption("-Xcompiler-option");
698 addOption("--compiler-filter=verify-none");
neo.chae155118f2015-01-07 15:32:15 +0900699
700 // We skip compilation when a minimal runtime is brought up for decryption. In that case
701 // /data is temporarily backed by a tmpfs, which is usually small.
702 // If the system image contains prebuilts, they will be relocated into the tmpfs. In this
703 // specific situation it is acceptable to *not* relocate and run out of the prebuilts
704 // directly instead.
705 addOption("--runtime-arg");
706 addOption("-Xnorelocate");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800707 } else {
708 parseCompilerOption("dalvik.vm.dex2oat-filter", dex2oatCompilerFilterBuf,
709 "--compiler-filter=", "-Xcompiler-option");
710 }
711 property_get("dalvik.vm.dex2oat-flags", dex2oatFlagsBuf, "");
712 parseExtraOpts(dex2oatFlagsBuf, "-Xcompiler-option");
713
Andy McFaddene4d81f22010-07-14 16:02:20 -0700714 /* extra options; parse this late so it overrides others */
715 property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
Brian Carlstrom3beff1e02014-02-28 23:27:22 -0800716 parseExtraOpts(extraOptsBuf, NULL);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800718 /* Set the properties for locale */
719 {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720 strcpy(langOption, "-Duser.language=");
721 strcpy(regionOption, "-Duser.region=");
722 readLocale(langOption, regionOption);
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700723 addOption(langOption);
724 addOption(regionOption);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 }
726
Dave Allison0efbd9a2014-01-30 14:19:51 -0800727 /*
728 * Set profiler options
729 */
Andreas Gampe08b2d582014-12-18 14:39:22 -0800730 // Whether or not the profiler should be enabled.
731 property_get("dalvik.vm.profiler", propBuf, "0");
732 if (propBuf[0] == '1') {
733 addOption("-Xenable-profiler");
734 }
Dave Allison0efbd9a2014-01-30 14:19:51 -0800735
Andreas Gampe08b2d582014-12-18 14:39:22 -0800736 // Whether the profile should start upon app startup or be delayed by some random offset
737 // (in seconds) that is bound between 0 and a fixed value.
738 property_get("dalvik.vm.profile.start-immed", propBuf, "0");
739 if (propBuf[0] == '1') {
740 addOption("-Xprofile-start-immediately");
741 }
Dave Allison0efbd9a2014-01-30 14:19:51 -0800742
Andreas Gampe08b2d582014-12-18 14:39:22 -0800743 // Number of seconds during profile runs.
744 parseRuntimeOption("dalvik.vm.profile.period-secs", profilePeriod, "-Xprofile-period:");
Dave Allison0efbd9a2014-01-30 14:19:51 -0800745
Andreas Gampe08b2d582014-12-18 14:39:22 -0800746 // Length of each profile run (seconds).
747 parseRuntimeOption("dalvik.vm.profile.duration-secs",
748 profileDuration,
749 "-Xprofile-duration:");
Dave Allison0efbd9a2014-01-30 14:19:51 -0800750
Andreas Gampe08b2d582014-12-18 14:39:22 -0800751 // Polling interval during profile run (microseconds).
752 parseRuntimeOption("dalvik.vm.profile.interval-us", profileInterval, "-Xprofile-interval:");
Calin Juravle9828d062014-06-02 16:45:13 +0100753
Andreas Gampe08b2d582014-12-18 14:39:22 -0800754 // Coefficient for period backoff. The the period is multiplied
755 // by this value after each profile run.
756 parseRuntimeOption("dalvik.vm.profile.backoff-coeff", profileBackoff, "-Xprofile-backoff:");
Calin Juravle9828d062014-06-02 16:45:13 +0100757
Andreas Gampe08b2d582014-12-18 14:39:22 -0800758 // Top K% of samples that are considered relevant when
759 // deciding if the app should be recompiled.
760 parseRuntimeOption("dalvik.vm.profile.top-k-thr",
761 profileTopKThreshold,
762 "-Xprofile-top-k-threshold:");
Calin Juravle9828d062014-06-02 16:45:13 +0100763
Andreas Gampe08b2d582014-12-18 14:39:22 -0800764 // The threshold after which a change in the structure of the
765 // top K% profiled samples becomes significant and triggers
766 // recompilation. A change in profile is considered
767 // significant if X% (top-k-change-threshold) of the top K%
768 // (top-k-threshold property) samples has changed.
769 parseRuntimeOption("dalvik.vm.profile.top-k-ch-thr",
770 profileTopKChangeThreshold,
771 "-Xprofile-top-k-change-threshold:");
Wei Jin54fc18b2014-06-09 16:29:54 -0700772
Andreas Gampe08b2d582014-12-18 14:39:22 -0800773 // Type of profile data.
774 parseRuntimeOption("dalvik.vm.profiler.type", profileType, "-Xprofile-type:");
Wei Jin54fc18b2014-06-09 16:29:54 -0700775
Andreas Gampe08b2d582014-12-18 14:39:22 -0800776 // Depth of bounded stack data
777 parseRuntimeOption("dalvik.vm.profile.stack-depth",
778 profileMaxStackDepth,
779 "-Xprofile-max-stack-depth:");
Dave Allison0efbd9a2014-01-30 14:19:51 -0800780
Andreas Gampe08b2d582014-12-18 14:39:22 -0800781 // Native bridge library. "0" means that native bridge is disabled.
782 property_get("ro.dalvik.vm.native.bridge", propBuf, "");
783 if (propBuf[0] == '\0') {
784 ALOGW("ro.dalvik.vm.native.bridge is not expected to be empty");
785 } else if (strcmp(propBuf, "0") != 0) {
786 snprintf(nativeBridgeLibrary, sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX,
787 "-XX:NativeBridge=%s", propBuf);
788 addOption(nativeBridgeLibrary);
Calin Juravlebe20ed42014-08-26 23:00:11 +0100789 }
Calin Juravle01db9162014-08-07 14:45:53 +0100790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800791 initArgs.version = JNI_VERSION_1_4;
792 initArgs.options = mOptions.editArray();
793 initArgs.nOptions = mOptions.size();
794 initArgs.ignoreUnrecognized = JNI_FALSE;
795
796 /*
797 * Initialize the VM.
798 *
799 * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread.
800 * If this call succeeds, the VM is ready, and we can start issuing
801 * JNI calls.
802 */
Andy McFaddenf70188a2009-03-31 15:52:13 -0700803 if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) {
Steve Block3762c312012-01-06 19:20:56 +0000804 ALOGE("JNI_CreateJavaVM failed\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805 goto bail;
806 }
807
Andy McFaddenf70188a2009-03-31 15:52:13 -0700808 result = 0;
809
810bail:
Andy McFaddenf70188a2009-03-31 15:52:13 -0700811 return result;
812}
813
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700814char* AndroidRuntime::toSlashClassName(const char* className)
815{
816 char* result = strdup(className);
817 for (char* cp = result; *cp != '\0'; cp++) {
818 if (*cp == '.') {
819 *cp = '/';
820 }
821 }
822 return result;
823}
824
Mike Lockwood9ee5e7e2014-09-08 16:15:21 -0700825/** Create a Java string from an ASCII or Latin-1 string */
826jstring AndroidRuntime::NewStringLatin1(JNIEnv* env, const char* bytes) {
827 if (!bytes) return NULL;
828 int length = strlen(bytes);
829 jchar* buffer = (jchar *)alloca(length * sizeof(jchar));
830 if (!buffer) return NULL;
831 jchar* chp = buffer;
832 for (int i = 0; i < length; i++) {
833 *chp++ = *bytes++;
834 }
835 return env->NewString(buffer, length);
836}
837
838
Andy McFaddenf70188a2009-03-31 15:52:13 -0700839/*
840 * Start the Android runtime. This involves starting the virtual machine
841 * and calling the "static void main(String[] args)" method in the class
842 * named by "className".
Jeff Brownebed7d62011-05-16 17:08:42 -0700843 *
844 * Passes the main function two arguments, the class name and the specified
845 * options string.
Andy McFaddenf70188a2009-03-31 15:52:13 -0700846 */
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100847void AndroidRuntime::start(const char* className, const Vector<String8>& options)
Andy McFaddenf70188a2009-03-31 15:52:13 -0700848{
Steve Block5baa3a62011-12-20 16:23:08 +0000849 ALOGD("\n>>>>>> AndroidRuntime START %s <<<<<<\n",
Dianne Hackborn08e60f22010-09-01 18:17:17 -0700850 className != NULL ? className : "(unknown)");
Andy McFaddenf70188a2009-03-31 15:52:13 -0700851
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100852 static const String8 startSystemServer("start-system-server");
853
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700854 /*
855 * 'startSystemServer == true' means runtime is obsolete and not run from
Andy McFaddenf70188a2009-03-31 15:52:13 -0700856 * init.rc anymore, so we print out the boot start event here.
857 */
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100858 for (size_t i = 0; i < options.size(); ++i) {
859 if (options[i] == startSystemServer) {
860 /* track our progress through the boot sequence */
861 const int LOG_BOOT_PROGRESS_START = 3000;
862 LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));
863 }
Andy McFaddenf70188a2009-03-31 15:52:13 -0700864 }
865
866 const char* rootDir = getenv("ANDROID_ROOT");
867 if (rootDir == NULL) {
868 rootDir = "/system";
869 if (!hasDir("/system")) {
870 LOG_FATAL("No root directory specified, and /android does not exist.");
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700871 return;
Andy McFaddenf70188a2009-03-31 15:52:13 -0700872 }
873 setenv("ANDROID_ROOT", rootDir, 1);
874 }
875
876 //const char* kernelHack = getenv("LD_ASSUME_KERNEL");
Steve Block5baa3a62011-12-20 16:23:08 +0000877 //ALOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack);
Andy McFaddenf70188a2009-03-31 15:52:13 -0700878
879 /* start the virtual machine */
Brian Carlstrom9f8203a2013-06-19 13:49:36 -0700880 JniInvocation jni_invocation;
881 jni_invocation.Init(NULL);
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700882 JNIEnv* env;
883 if (startVm(&mJavaVM, &env) != 0) {
884 return;
885 }
886 onVmCreated(env);
Andy McFaddenf70188a2009-03-31 15:52:13 -0700887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800888 /*
889 * Register android functions.
890 */
891 if (startReg(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +0000892 ALOGE("Unable to register all android natives\n");
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700893 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800894 }
895
896 /*
897 * We want to call main() with a String array with arguments in it.
Jeff Brownebed7d62011-05-16 17:08:42 -0700898 * At present we have two arguments, the class name and an option string.
899 * Create an array to hold them.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 */
901 jclass stringClass;
902 jobjectArray strArray;
903 jstring classNameStr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800904
905 stringClass = env->FindClass("java/lang/String");
906 assert(stringClass != NULL);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100907 strArray = env->NewObjectArray(options.size() + 1, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800908 assert(strArray != NULL);
909 classNameStr = env->NewStringUTF(className);
910 assert(classNameStr != NULL);
911 env->SetObjectArrayElement(strArray, 0, classNameStr);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100912
913 for (size_t i = 0; i < options.size(); ++i) {
914 jstring optionsStr = env->NewStringUTF(options.itemAt(i).string());
915 assert(optionsStr != NULL);
916 env->SetObjectArrayElement(strArray, i + 1, optionsStr);
917 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800918
919 /*
920 * Start VM. This thread becomes the main thread of the VM, and will
921 * not return until the VM exits.
922 */
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700923 char* slashClassName = toSlashClassName(className);
924 jclass startClass = env->FindClass(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 if (startClass == NULL) {
Steve Block3762c312012-01-06 19:20:56 +0000926 ALOGE("JavaVM unable to locate class '%s'\n", slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 /* keep going */
928 } else {
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700929 jmethodID startMeth = env->GetStaticMethodID(startClass, "main",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 "([Ljava/lang/String;)V");
931 if (startMeth == NULL) {
Steve Block3762c312012-01-06 19:20:56 +0000932 ALOGE("JavaVM unable to find main() in '%s'\n", className);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 /* keep going */
934 } else {
935 env->CallStaticVoidMethod(startClass, startMeth, strArray);
936
937#if 0
938 if (env->ExceptionCheck())
939 threadExitUncaughtException(env);
940#endif
941 }
942 }
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700943 free(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944
Steve Block5baa3a62011-12-20 16:23:08 +0000945 ALOGD("Shutting down VM\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 if (mJavaVM->DetachCurrentThread() != JNI_OK)
Steve Block8564c8d2012-01-05 23:22:43 +0000947 ALOGW("Warning: unable to detach main thread\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 if (mJavaVM->DestroyJavaVM() != 0)
Steve Block8564c8d2012-01-05 23:22:43 +0000949 ALOGW("Warning: VM did not shut down cleanly\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950}
951
Jeff Brown4280c4a2012-03-15 17:48:02 -0700952void AndroidRuntime::exit(int code)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953{
Jeff Brown4280c4a2012-03-15 17:48:02 -0700954 if (mExitWithoutCleanup) {
955 ALOGI("VM exiting with result code %d, cleanup skipped.", code);
956 ::_exit(code);
957 } else {
958 ALOGI("VM exiting with result code %d.", code);
959 onExit(code);
960 ::exit(code);
961 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800962}
963
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700964void AndroidRuntime::onVmCreated(JNIEnv* env)
965{
966 // If AndroidRuntime had anything to do here, we'd have done it in 'start'.
967}
968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969/*
Andreas Huber9ae000c2014-02-13 17:22:33 +0000970 * Get the JNIEnv pointer for this thread.
971 *
972 * Returns NULL if the slot wasn't allocated or populated.
973 */
974/*static*/ JNIEnv* AndroidRuntime::getJNIEnv()
975{
976 JNIEnv* env;
977 JavaVM* vm = AndroidRuntime::getJavaVM();
978 assert(vm != NULL);
979
980 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
981 return NULL;
982 return env;
983}
984
985/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986 * Makes the current thread visible to the VM.
987 *
988 * The JNIEnv pointer returned is only valid for the current thread, and
989 * thus must be tucked into thread-local storage.
990 */
991static int javaAttachThread(const char* threadName, JNIEnv** pEnv)
992{
993 JavaVMAttachArgs args;
994 JavaVM* vm;
995 jint result;
996
997 vm = AndroidRuntime::getJavaVM();
998 assert(vm != NULL);
999
1000 args.version = JNI_VERSION_1_4;
1001 args.name = (char*) threadName;
1002 args.group = NULL;
1003
1004 result = vm->AttachCurrentThread(pEnv, (void*) &args);
1005 if (result != JNI_OK)
Steve Block6215d3f2012-01-04 20:05:49 +00001006 ALOGI("NOTE: attach of thread '%s' failed\n", threadName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001007
1008 return result;
1009}
1010
1011/*
1012 * Detach the current thread from the set visible to the VM.
1013 */
1014static int javaDetachThread(void)
1015{
1016 JavaVM* vm;
1017 jint result;
1018
1019 vm = AndroidRuntime::getJavaVM();
1020 assert(vm != NULL);
1021
1022 result = vm->DetachCurrentThread();
1023 if (result != JNI_OK)
Steve Block3762c312012-01-06 19:20:56 +00001024 ALOGE("ERROR: thread detach failed\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 return result;
1026}
1027
1028/*
1029 * When starting a native thread that will be visible from the VM, we
1030 * bounce through this to get the right attach/detach action.
1031 * Note that this function calls free(args)
1032 */
1033/*static*/ int AndroidRuntime::javaThreadShell(void* args) {
1034 void* start = ((void**)args)[0];
1035 void* userData = ((void **)args)[1];
1036 char* name = (char*) ((void **)args)[2]; // we own this storage
1037 free(args);
1038 JNIEnv* env;
1039 int result;
1040
1041 /* hook us into the VM */
1042 if (javaAttachThread(name, &env) != JNI_OK)
1043 return -1;
1044
1045 /* start the thread running */
1046 result = (*(android_thread_func_t)start)(userData);
1047
1048 /* unhook us */
1049 javaDetachThread();
1050 free(name);
1051
1052 return result;
1053}
1054
1055/*
1056 * This is invoked from androidCreateThreadEtc() via the callback
1057 * set with androidSetCreateThreadFunc().
1058 *
1059 * We need to create the new thread in such a way that it gets hooked
1060 * into the VM before it really starts executing.
1061 */
1062/*static*/ int AndroidRuntime::javaCreateThreadEtc(
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001063 android_thread_func_t entryFunction,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001064 void* userData,
1065 const char* threadName,
1066 int32_t threadPriority,
1067 size_t threadStackSize,
1068 android_thread_id_t* threadId)
1069{
1070 void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free
1071 int result;
1072
Mike Lockwood32f2e622013-10-10 10:11:27 -07001073 if (!threadName)
1074 threadName = "unnamed thread";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001075
1076 args[0] = (void*) entryFunction;
1077 args[1] = userData;
1078 args[2] = (void*) strdup(threadName); // javaThreadShell must free
1079
1080 result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args,
1081 threadName, threadPriority, threadStackSize, threadId);
1082 return result;
1083}
1084
1085/*
1086 * Create a thread that is visible from the VM.
1087 *
1088 * This is called from elsewhere in the library.
1089 */
Mike Lockwoodf602d362010-06-20 14:28:16 -07001090/*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 void (*start)(void *), void* arg)
1092{
Mike Lockwoodf602d362010-06-20 14:28:16 -07001093 android_thread_id_t threadId = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 javaCreateThreadEtc((android_thread_func_t) start, arg, name,
Mike Lockwoodf602d362010-06-20 14:28:16 -07001095 ANDROID_PRIORITY_DEFAULT, 0, &threadId);
1096 return threadId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097}
1098
1099#if 0
1100static void quickTest(void* arg)
1101{
1102 const char* str = (const char*) arg;
1103
1104 printf("In quickTest: %s\n", str);
1105}
1106#endif
1107
1108#ifdef NDEBUG
1109 #define REG_JNI(name) { name }
1110 struct RegJNIRec {
1111 int (*mProc)(JNIEnv*);
1112 };
1113#else
1114 #define REG_JNI(name) { name, #name }
1115 struct RegJNIRec {
1116 int (*mProc)(JNIEnv*);
1117 const char* mName;
1118 };
1119#endif
1120
1121typedef void (*RegJAMProc)();
1122
1123static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env)
1124{
1125 for (size_t i = 0; i < count; i++) {
1126 if (array[i].mProc(env) < 0) {
1127#ifndef NDEBUG
Steve Block5baa3a62011-12-20 16:23:08 +00001128 ALOGD("----------!!! %s failed to load\n", array[i].mName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001129#endif
1130 return -1;
1131 }
1132 }
1133 return 0;
1134}
1135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136static const RegJNIRec gRegJNI[] = {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 REG_JNI(register_com_android_internal_os_RuntimeInit),
1138 REG_JNI(register_android_os_SystemClock),
1139 REG_JNI(register_android_util_EventLog),
1140 REG_JNI(register_android_util_Log),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 REG_JNI(register_android_content_AssetManager),
1142 REG_JNI(register_android_content_StringBlock),
1143 REG_JNI(register_android_content_XmlBlock),
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001144 REG_JNI(register_android_emoji_EmojiFactory),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 REG_JNI(register_android_text_AndroidCharacter),
Anish Athalye88b5b0b2014-06-24 14:39:43 -07001146 REG_JNI(register_android_text_StaticLayout),
Doug Feltdae8e942010-02-24 14:33:15 -08001147 REG_JNI(register_android_text_AndroidBidi),
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001148 REG_JNI(register_android_view_InputDevice),
1149 REG_JNI(register_android_view_KeyCharacterMap),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 REG_JNI(register_android_os_Process),
Andreas Hubera8079bf2010-11-16 14:40:31 -08001151 REG_JNI(register_android_os_SystemProperties),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 REG_JNI(register_android_os_Binder),
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -08001153 REG_JNI(register_android_os_Parcel),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 REG_JNI(register_android_nio_utils),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 REG_JNI(register_android_graphics_Graphics),
Chris Craik54389792013-12-20 13:28:11 -08001156 REG_JNI(register_android_view_DisplayEventReceiver),
John Reckf666ad72014-03-14 16:24:57 -07001157 REG_JNI(register_android_view_RenderNode),
John Recke45b1fd2014-04-15 09:50:16 -07001158 REG_JNI(register_android_view_RenderNodeAnimator),
Romain Guy3b748a42013-04-17 18:54:38 -07001159 REG_JNI(register_android_view_GraphicBuffer),
Romain Guye4d01122010-06-16 18:44:05 -07001160 REG_JNI(register_android_view_GLES20Canvas),
John Reck04fc5832014-02-05 16:38:25 -08001161 REG_JNI(register_android_view_HardwareLayer),
John Reckcec24ae2013-11-05 13:27:50 -08001162 REG_JNI(register_android_view_ThreadedRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001163 REG_JNI(register_android_view_Surface),
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001164 REG_JNI(register_android_view_SurfaceControl),
Jeff Brown64a55af2012-08-26 02:47:39 -07001165 REG_JNI(register_android_view_SurfaceSession),
Romain Guy8f0095c2011-05-02 17:24:22 -07001166 REG_JNI(register_android_view_TextureView),
John Reck315c3292014-05-09 19:21:04 -07001167 REG_JNI(register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 REG_JNI(register_com_google_android_gles_jni_EGLImpl),
1169 REG_JNI(register_com_google_android_gles_jni_GLImpl),
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001170 REG_JNI(register_android_opengl_jni_EGL14),
Jesse Hall237c2b82013-05-06 11:36:57 -07001171 REG_JNI(register_android_opengl_jni_EGLExt),
Jack Palevich1c4907e2009-04-13 16:22:25 -07001172 REG_JNI(register_android_opengl_jni_GLES10),
1173 REG_JNI(register_android_opengl_jni_GLES10Ext),
1174 REG_JNI(register_android_opengl_jni_GLES11),
1175 REG_JNI(register_android_opengl_jni_GLES11Ext),
Jack Palevich560814f2009-11-19 16:34:55 +08001176 REG_JNI(register_android_opengl_jni_GLES20),
Jesse Halld877efe2013-04-29 15:59:35 -07001177 REG_JNI(register_android_opengl_jni_GLES30),
Jesse Hall7ab63ac2014-05-19 15:13:41 -07001178 REG_JNI(register_android_opengl_jni_GLES31),
1179 REG_JNI(register_android_opengl_jni_GLES31Ext),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001180
1181 REG_JNI(register_android_graphics_Bitmap),
1182 REG_JNI(register_android_graphics_BitmapFactory),
Wei-Ta Chen6b849e22010-09-07 17:32:18 +08001183 REG_JNI(register_android_graphics_BitmapRegionDecoder),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 REG_JNI(register_android_graphics_Camera),
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -04001185 REG_JNI(register_android_graphics_CreateJavaOutputStreamAdaptor),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 REG_JNI(register_android_graphics_Canvas),
John Reck52244ff2014-05-01 21:27:37 -07001187 REG_JNI(register_android_graphics_CanvasProperty),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 REG_JNI(register_android_graphics_ColorFilter),
1189 REG_JNI(register_android_graphics_DrawFilter),
Raph Levien1a73f7322014-01-30 16:06:28 -08001190 REG_JNI(register_android_graphics_FontFamily),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001191 REG_JNI(register_android_graphics_Interpolator),
1192 REG_JNI(register_android_graphics_LayerRasterizer),
1193 REG_JNI(register_android_graphics_MaskFilter),
1194 REG_JNI(register_android_graphics_Matrix),
1195 REG_JNI(register_android_graphics_Movie),
1196 REG_JNI(register_android_graphics_NinePatch),
1197 REG_JNI(register_android_graphics_Paint),
1198 REG_JNI(register_android_graphics_Path),
1199 REG_JNI(register_android_graphics_PathMeasure),
1200 REG_JNI(register_android_graphics_PathEffect),
1201 REG_JNI(register_android_graphics_Picture),
1202 REG_JNI(register_android_graphics_PorterDuff),
1203 REG_JNI(register_android_graphics_Rasterizer),
1204 REG_JNI(register_android_graphics_Region),
1205 REG_JNI(register_android_graphics_Shader),
Jamie Gennisaa0ce332011-01-06 17:04:26 -08001206 REG_JNI(register_android_graphics_SurfaceTexture),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001207 REG_JNI(register_android_graphics_Typeface),
1208 REG_JNI(register_android_graphics_Xfermode),
Wei-Ta Chenbca2d612009-11-30 17:52:05 +08001209 REG_JNI(register_android_graphics_YuvImage),
Svetoslav6811f4e2013-09-18 15:58:28 -07001210 REG_JNI(register_android_graphics_pdf_PdfDocument),
Svetoslav62ce3322014-09-04 21:17:17 -07001211 REG_JNI(register_android_graphics_pdf_PdfEditor),
Svetoslav29617692014-04-24 18:40:42 -07001212 REG_JNI(register_android_graphics_pdf_PdfRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001213
1214 REG_JNI(register_android_database_CursorWindow),
Jeff Browne5360fb2011-10-31 17:48:13 -07001215 REG_JNI(register_android_database_SQLiteConnection),
1216 REG_JNI(register_android_database_SQLiteGlobal),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 REG_JNI(register_android_database_SQLiteDebug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001218 REG_JNI(register_android_os_Debug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 REG_JNI(register_android_os_FileObserver),
Christopher Tatefa9e7c02010-05-06 12:07:10 -07001220 REG_JNI(register_android_os_MessageQueue),
Stephen Smalleyc07fca32012-01-13 08:31:39 -05001221 REG_JNI(register_android_os_SELinux),
Jeff Brown481c1572012-03-09 14:41:15 -08001222 REG_JNI(register_android_os_Trace),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 REG_JNI(register_android_os_UEventObserver),
1224 REG_JNI(register_android_net_LocalSocketImpl),
1225 REG_JNI(register_android_net_NetworkUtils),
Dan Egnor2b4abcd2010-04-07 17:30:50 -07001226 REG_JNI(register_android_net_TrafficStats),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001227 REG_JNI(register_android_os_MemoryFile),
Narayan Kamath973b4662014-03-31 13:41:26 +01001228 REG_JNI(register_com_android_internal_os_Zygote),
John Reck9fa40712014-05-09 15:26:59 -07001229 REG_JNI(register_com_android_internal_util_VirtualRefBasePtr),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001230 REG_JNI(register_android_hardware_Camera),
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07001231 REG_JNI(register_android_hardware_camera2_CameraMetadata),
Ruben Brunkfeb50af2014-05-09 19:58:49 -07001232 REG_JNI(register_android_hardware_camera2_legacy_LegacyCameraDevice),
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -07001233 REG_JNI(register_android_hardware_camera2_legacy_PerfMeasurement),
Ruben Brunkb6079002014-05-22 12:33:54 -07001234 REG_JNI(register_android_hardware_camera2_DngCreator),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 REG_JNI(register_android_hardware_SensorManager),
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04001236 REG_JNI(register_android_hardware_SerialPort),
Eric Laurent60b62bc2014-04-18 17:50:49 -07001237 REG_JNI(register_android_hardware_SoundTrigger),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001238 REG_JNI(register_android_hardware_UsbDevice),
Mike Lockwoodacc29cc2011-03-11 08:18:08 -05001239 REG_JNI(register_android_hardware_UsbDeviceConnection),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001240 REG_JNI(register_android_hardware_UsbRequest),
destradaaa4fa3b52014-07-09 10:46:39 -07001241 REG_JNI(register_android_hardware_location_ActivityRecognitionHardware),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242 REG_JNI(register_android_media_AudioRecord),
1243 REG_JNI(register_android_media_AudioSystem),
1244 REG_JNI(register_android_media_AudioTrack),
1245 REG_JNI(register_android_media_JetPlayer),
Jeff Browncbad9762012-09-04 21:57:59 -07001246 REG_JNI(register_android_media_RemoteDisplay),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 REG_JNI(register_android_media_ToneGenerator),
1248
1249 REG_JNI(register_android_opengl_classes),
JP Abgrall98a4f7e2011-09-02 15:36:33 -07001250 REG_JNI(register_android_server_NetworkManagementSocketTagger),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251 REG_JNI(register_android_ddm_DdmHandleNativeHeap),
Joe Onorato1cf58742009-06-12 11:06:24 -07001252 REG_JNI(register_android_backup_BackupDataInput),
Joe Onoratod2110db2009-05-19 13:41:21 -07001253 REG_JNI(register_android_backup_BackupDataOutput),
Joe Onorato06290a42009-06-18 20:10:37 -07001254 REG_JNI(register_android_backup_FileBackupHelperBase),
Joe Onorato4ababd92009-06-25 18:29:18 -04001255 REG_JNI(register_android_backup_BackupHelperDispatcher),
Christopher Tate4a627c72011-04-01 14:43:32 -07001256 REG_JNI(register_android_app_backup_FullBackup),
Chet Haase9c1e23b2011-03-24 10:51:31 -07001257 REG_JNI(register_android_app_ActivityThread),
Dianne Hackborn69969e42010-05-04 11:40:40 -07001258 REG_JNI(register_android_app_NativeActivity),
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001259 REG_JNI(register_android_view_InputChannel),
Jeff Brown32cbc38552011-12-01 14:01:49 -08001260 REG_JNI(register_android_view_InputEventReceiver),
Jeff Brownc28867a2013-03-26 15:42:39 -07001261 REG_JNI(register_android_view_InputEventSender),
Michael Wrighta44dd262013-04-10 21:12:00 -07001262 REG_JNI(register_android_view_InputQueue),
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001263 REG_JNI(register_android_view_KeyEvent),
1264 REG_JNI(register_android_view_MotionEvent),
Jeff Brown2352b972011-04-12 22:39:53 -07001265 REG_JNI(register_android_view_PointerIcon),
Jeff Brown2ed24622011-03-14 19:39:54 -07001266 REG_JNI(register_android_view_VelocityTracker),
Kenny Root02c87302010-07-01 08:10:18 -07001267
1268 REG_JNI(register_android_content_res_ObbScanner),
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -07001269 REG_JNI(register_android_content_res_Configuration),
Chet Haase6e0ecb42010-11-03 19:41:18 -07001270
1271 REG_JNI(register_android_animation_PropertyValuesHolder),
Kenny Root66269ea2011-07-12 14:14:01 -07001272 REG_JNI(register_com_android_internal_content_NativeLibraryHelper),
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -08001273 REG_JNI(register_com_android_internal_net_NetworkStatsFactory),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001274};
1275
1276/*
1277 * Register android native functions with the VM.
1278 */
1279/*static*/ int AndroidRuntime::startReg(JNIEnv* env)
1280{
1281 /*
1282 * This hook causes all future threads created in this process to be
1283 * attached to the JavaVM. (This needs to go away in favor of JNI
1284 * Attach calls.)
1285 */
1286 androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc);
1287
Steve Block71f2cf12011-10-20 11:56:00 +01001288 ALOGV("--- registering native functions ---\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001289
1290 /*
1291 * Every "register" function calls one or more things that return
1292 * a local reference (e.g. FindClass). Because we haven't really
1293 * started the VM yet, they're all getting stored in the base frame
1294 * and never released. Use Push/Pop to manage the storage.
1295 */
1296 env->PushLocalFrame(200);
1297
1298 if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) {
1299 env->PopLocalFrame(NULL);
1300 return -1;
1301 }
1302 env->PopLocalFrame(NULL);
1303
1304 //createJavaThread("fubar", quickTest, (void*) "hello");
1305
1306 return 0;
1307}
1308
1309AndroidRuntime* AndroidRuntime::getRuntime()
1310{
1311 return gCurRuntime;
1312}
1313
1314/**
1315 * Used by WithFramework to register native functions.
1316 */
1317extern "C"
1318jint Java_com_android_internal_util_WithFramework_registerNatives(
1319 JNIEnv* env, jclass clazz) {
1320 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1321}
1322
1323/**
1324 * Used by LoadClass to register native functions.
1325 */
1326extern "C"
1327jint Java_LoadClass_registerNatives(JNIEnv* env, jclass clazz) {
1328 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1329}
1330
1331} // namespace android