1d195e5ab401432ddac659791640a2927fc668699Elliott Hughes/*
2d195e5ab401432ddac659791640a2927fc668699Elliott Hughes * Copyright (C) 2006 The Android Open Source Project
3d195e5ab401432ddac659791640a2927fc668699Elliott Hughes *
4d195e5ab401432ddac659791640a2927fc668699Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
5d195e5ab401432ddac659791640a2927fc668699Elliott Hughes * you may not use this file except in compliance with the License.
6d195e5ab401432ddac659791640a2927fc668699Elliott Hughes * You may obtain a copy of the License at
7d195e5ab401432ddac659791640a2927fc668699Elliott Hughes *
8d195e5ab401432ddac659791640a2927fc668699Elliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
9d195e5ab401432ddac659791640a2927fc668699Elliott Hughes *
10d195e5ab401432ddac659791640a2927fc668699Elliott Hughes * Unless required by applicable law or agreed to in writing, software
11d195e5ab401432ddac659791640a2927fc668699Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
12d195e5ab401432ddac659791640a2927fc668699Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d195e5ab401432ddac659791640a2927fc668699Elliott Hughes * See the License for the specific language governing permissions and
14d195e5ab401432ddac659791640a2927fc668699Elliott Hughes * limitations under the License.
15d195e5ab401432ddac659791640a2927fc668699Elliott Hughes */
169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
171ab43d5978813f56899dbd3115fd7d9f96b4fe55Yasuhiro Matsuda#define ATRACE_TAG ATRACE_TAG_DALVIK
189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#define LOG_TAG "AndroidRuntime"
1982ba91ddb4fe9d9ff8245e27f70dea64cc20553dJoe Onorato#define LOG_NDEBUG 1
209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <android_runtime/AndroidRuntime.h>
2293099e4485d62fc8cd900cb213c17117c17c3351Tom Cherry
2393099e4485d62fc8cd900cb213c17117c17c3351Tom Cherry#include <android-base/properties.h>
240795272aa226f4e965968a03daddc53ce30b7cdaMathias Agopian#include <binder/IBinder.h>
250bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick#include <binder/IPCThreadState.h>
260795272aa226f4e965968a03daddc53ce30b7cdaMathias Agopian#include <binder/IServiceManager.h>
279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <utils/Log.h>
289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <utils/misc.h>
291ab43d5978813f56899dbd3115fd7d9f96b4fe55Yasuhiro Matsuda#include <utils/Trace.h>
300795272aa226f4e965968a03daddc53ce30b7cdaMathias Agopian#include <binder/Parcel.h>
319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <utils/threads.h>
329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <cutils/properties.h>
339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <SkGraphics.h>
359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include "jni.h"
372279b2534272282a5b5152723235da397e49195cSteven Moreland#include <nativehelper/JNIHelp.h>
382279b2534272282a5b5152723235da397e49195cSteven Moreland#include <nativehelper/JniInvocation.h>
399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include "android_util_Binder.h"
409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <stdio.h>
429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <signal.h>
439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <sys/stat.h>
449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <sys/types.h>
459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <signal.h>
469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <dirent.h>
479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <assert.h>
489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
49bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath#include <string>
50bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath#include <vector>
51bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath
529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectusing namespace android;
5393099e4485d62fc8cd900cb213c17117c17c3351Tom Cherryusing android::base::GetProperty;
549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_os_Binder(JNIEnv* env);
569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_os_Process(JNIEnv* env);
579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Bitmap(JNIEnv*);
589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_BitmapFactory(JNIEnv*);
596b849e2123be98eb2a1a25b8abf0b13a279ce952Wei-Ta Chenextern int register_android_graphics_BitmapRegionDecoder(JNIEnv*);
600c01dbf8f283b7bcaf6babf540a501735c73b4f5Leon Scroggins IIIextern int register_android_graphics_ByteBufferStreamAdaptor(JNIEnv* env);
619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Camera(JNIEnv* env);
62d0d7eaf129b48ea04c06902a11c2a4f74056d76cLeon Scroggins IIIextern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env);
630a0f23163a7a62900d46c7f81d109320d73d6c6bsergeyvextern int register_android_graphics_GraphicBuffer(JNIEnv* env);
649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Graphics(JNIEnv* env);
650c01dbf8f283b7bcaf6babf540a501735c73b4f5Leon Scroggins IIIextern int register_android_graphics_ImageDecoder(JNIEnv*);
66671cce2605ed50c9aba73ab5bd530cb7741c53cdLeon Scroggins IIIextern int register_android_graphics_drawable_AnimatedImageDrawable(JNIEnv*);
679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Interpolator(JNIEnv* env);
689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_MaskFilter(JNIEnv* env);
699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Movie(JNIEnv* env);
709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_NinePatch(JNIEnv*);
719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_PathEffect(JNIEnv* env);
729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Shader(JNIEnv* env);
739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Typeface(JNIEnv* env);
74bca2d613e0d6d2630fedd302c0d779b7610adbcfWei-Ta Chenextern int register_android_graphics_YuvImage(JNIEnv* env);
759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env);
779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env);
786b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferextern int register_android_opengl_jni_EGL14(JNIEnv* env);
79237c2b871f66e06498ad03aaa92964f4434982c5Jesse Hallextern int register_android_opengl_jni_EGLExt(JNIEnv* env);
801c4907ee77392afb768c2f088e0dedbe4239f6fbJack Palevichextern int register_android_opengl_jni_GLES10(JNIEnv* env);
811c4907ee77392afb768c2f088e0dedbe4239f6fbJack Palevichextern int register_android_opengl_jni_GLES10Ext(JNIEnv* env);
821c4907ee77392afb768c2f088e0dedbe4239f6fbJack Palevichextern int register_android_opengl_jni_GLES11(JNIEnv* env);
831c4907ee77392afb768c2f088e0dedbe4239f6fbJack Palevichextern int register_android_opengl_jni_GLES11Ext(JNIEnv* env);
84560814f6b11abe83ff0c4ed18cac015c276b3181Jack Palevichextern int register_android_opengl_jni_GLES20(JNIEnv* env);
85d877efe3b12afdd84f06c180369f9d7399858f6eJesse Hallextern int register_android_opengl_jni_GLES30(JNIEnv* env);
867ab63acdd0a257272512d0bcf5e06036fa0b9fdfJesse Hallextern int register_android_opengl_jni_GLES31(JNIEnv* env);
877ab63acdd0a257272512d0bcf5e06036fa0b9fdfJesse Hallextern int register_android_opengl_jni_GLES31Ext(JNIEnv* env);
8838c1a7e732660212687cf375f5e5ed354b91e431Pablo Ceballosextern int register_android_opengl_jni_GLES32(JNIEnv* env);
899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_hardware_Camera(JNIEnv *env);
912f1a2e423e0fbb64467d6fcfa4e82c6384f31210Eino-Ville Talvalaextern int register_android_hardware_camera2_CameraMetadata(JNIEnv *env);
92feb50af361e4305a25758966b6b5df2738c00259Ruben Brunkextern int register_android_hardware_camera2_legacy_LegacyCameraDevice(JNIEnv *env);
93e1f57d6f44909a66c7ab0af33dbc5289287e823aEino-Ville Talvalaextern int register_android_hardware_camera2_legacy_PerfMeasurement(JNIEnv *env);
94b6079005ed0631c3972ff427f56e12523ec214a7Ruben Brunkextern int register_android_hardware_camera2_DngCreator(JNIEnv *env);
951a4d07d9193f843ebf4403ef49bac4cd61d34165Craig Donnerextern int register_android_hardware_HardwareBuffer(JNIEnv *env);
969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_hardware_SensorManager(JNIEnv *env);
97b01e8bf57b7492b77e3445db51471edcbadda75eMike Lockwoodextern int register_android_hardware_SerialPort(JNIEnv *env);
9860b62bc5c11c0bfcdf84ca8f5b2053e5747f86bcEric Laurentextern int register_android_hardware_SoundTrigger(JNIEnv *env);
99e7d511e148bc901ef41ac44d7b3593e5d803f72fMike Lockwoodextern int register_android_hardware_UsbDevice(JNIEnv *env);
100acc29cc91be634070c92a807df412ced97b9b375Mike Lockwoodextern int register_android_hardware_UsbDeviceConnection(JNIEnv *env);
101e7d511e148bc901ef41ac44d7b3593e5d803f72fMike Lockwoodextern int register_android_hardware_UsbRequest(JNIEnv *env);
102a4fa3b5aa53cf677b623fe346c585cb8a0c1ce26destradaaextern int register_android_hardware_location_ActivityRecognitionHardware(JNIEnv* env);
1039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_media_AudioRecord(JNIEnv *env);
1059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_media_AudioSystem(JNIEnv *env);
1069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_media_AudioTrack(JNIEnv *env);
107c0f494403873435d463c4817066f9c68d57310a7jiabinextern int register_android_media_MicrophoneInfo(JNIEnv *env);
1089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_media_JetPlayer(JNIEnv *env);
1099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_media_ToneGenerator(JNIEnv *env);
1109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectnamespace android {
1129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
1149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * JNI-based registration functions.  Note these are properly contained in
1159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * namespace android.
1169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
1176235a94ffaed1d82cee2317481c18776f601da1bMichal Karpinskiextern int register_android_app_admin_SecurityLog(JNIEnv* env);
1189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_content_AssetManager(JNIEnv* env);
1199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_util_EventLog(JNIEnv* env);
120671b1b5b837b85612bc00949af921265d896bb8fChenjie Yuextern int register_android_util_StatsLog(JNIEnv* env);
1219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_util_Log(JNIEnv* env);
12253a441ca8eda5a3e6209a952b1bbd32a39e19a1cSvet Ganovextern int register_android_util_MemoryIntArray(JNIEnv* env);
123cdd23f9d45ea2974c3f295754b89f5462bdd2c0dDoris Liuextern int register_android_util_PathParser(JNIEnv* env);
1249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_content_StringBlock(JNIEnv* env);
1259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_content_XmlBlock(JNIEnv* env);
126bebfcc46a249a70af04bc18490a897888a142fb8Adam Lesinskiextern int register_android_content_res_ApkAssets(JNIEnv* env);
1279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Canvas(JNIEnv* env);
12852244fff29042926e21fa897ef5ab11148e35299John Reckextern int register_android_graphics_CanvasProperty(JNIEnv* env);
1299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_ColorFilter(JNIEnv* env);
1309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_DrawFilter(JNIEnv* env);
1311a73f732f91e97c9c66b808c245ddda36a10e987Raph Levienextern int register_android_graphics_FontFamily(JNIEnv* env);
1329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Matrix(JNIEnv* env);
1339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Paint(JNIEnv* env);
1349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Path(JNIEnv* env);
1359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_PathMeasure(JNIEnv* env);
1369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Picture(JNIEnv*);
137fbf097732137a32930d151f7ba6816a5b870c32aJeff Brownextern int register_android_graphics_Region(JNIEnv* env);
138aa0ce3396c096c97e3394c53e3912cb08b66fe20Jamie Gennisextern int register_android_graphics_SurfaceTexture(JNIEnv* env);
139766431aa57c16ece8842287a92b2e7208e3b8ac3Doris Liuextern int register_android_graphics_drawable_AnimatedVectorDrawable(JNIEnv* env);
1404bbc2931263b232fba61807fca00e127573eff42Doris Liuextern int register_android_graphics_drawable_VectorDrawable(JNIEnv* env);
1416811f4e92cbb64e72a0d13eb9b99b5894bd59c76Svetoslavextern int register_android_graphics_pdf_PdfDocument(JNIEnv* env);
14262ce332c141cf7bc7200c4c87d63e395874fc3ecSvetoslavextern int register_android_graphics_pdf_PdfEditor(JNIEnv* env);
1432961769ea94f69c191a2dd785b2504666c7292d0Svetoslavextern int register_android_graphics_pdf_PdfRenderer(JNIEnv* env);
1440a0a1248cfc03940174cbd9af677bafd7280a3bcJeff Brownextern int register_android_view_DisplayEventReceiver(JNIEnv* env);
145c9070ebd13263a341511cf779087a46750021196Chris Craikextern int register_android_view_DisplayListCanvas(JNIEnv* env);
1469d8d99de971b62e85c459f43d96c6cd07f3c3fe4John Reckextern int register_android_view_TextureLayer(JNIEnv* env);
147c9070ebd13263a341511cf779087a46750021196Chris Craikextern int register_android_view_RenderNode(JNIEnv* env);
148c9070ebd13263a341511cf779087a46750021196Chris Craikextern int register_android_view_RenderNodeAnimator(JNIEnv* env);
1499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_view_Surface(JNIEnv* env);
1503866f0d581ceaa165710feeee9f37fe1b0d7067dMathias Agopianextern int register_android_view_SurfaceControl(JNIEnv* env);
15164a55af0ac700baecb0877235eb42caac59a3560Jeff Brownextern int register_android_view_SurfaceSession(JNIEnv* env);
1528f0095cd33558e9cc8a440047908e53b68906f5fRomain Guyextern int register_android_view_TextureView(JNIEnv* env);
153c9070ebd13263a341511cf779087a46750021196Chris Craikextern int register_android_view_ThreadedRenderer(JNIEnv* env);
154315c329544d7c593d1072b071cbb92d9afe74021John Reckextern int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv *env);
1559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_database_CursorWindow(JNIEnv* env);
156e5360fbf3efe85427f7e7f59afe7bbeddb4949acJeff Brownextern int register_android_database_SQLiteConnection(JNIEnv* env);
157e5360fbf3efe85427f7e7f59afe7bbeddb4949acJeff Brownextern int register_android_database_SQLiteGlobal(JNIEnv* env);
1589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_database_SQLiteDebug(JNIEnv* env);
1599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_nio_utils(JNIEnv* env);
1609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_os_Debug(JNIEnv* env);
161b12249b67193df07a8ffc3cad0c41643662b887bJesse Hallextern int register_android_os_GraphicsEnvironment(JNIEnv* env);
162bb0bd00b009bdd78fc5f94296702fc109bfecaf3Yifan Hongextern int register_android_os_HidlSupport(JNIEnv* env);
163c0b6c530766eb5f59e321a1fdbf3d27c05560024Andreas Huberextern int register_android_os_HwBinder(JNIEnv *env);
164dc26321e0b8293a29b4b1c5700938a5445b230baAndreas Huberextern int register_android_os_HwBlob(JNIEnv *env);
165c0b6c530766eb5f59e321a1fdbf3d27c05560024Andreas Huberextern int register_android_os_HwParcel(JNIEnv *env);
166c0b6c530766eb5f59e321a1fdbf3d27c05560024Andreas Huberextern int register_android_os_HwRemoteBinder(JNIEnv *env);
167fa9e7c05c7be6891a6cf85a11dc635a6e6853078Christopher Tateextern int register_android_os_MessageQueue(JNIEnv* env);
168d84e1ce0b535128f03416145554fb405f9fade3eJeff Sharkeyextern int register_android_os_Parcel(JNIEnv* env);
169c07fca3831baf4d812dd724f506b4ed23dcc39e0Stephen Smalleyextern int register_android_os_SELinux(JNIEnv* env);
170becc56d7ea523aa153219446232cbf5e561726f4Yifan Hongextern int register_android_os_VintfObject(JNIEnv *env);
1711bda67369ca48d284a9a55300f58f6cf13ad9aa6Yifan Hongextern int register_android_os_VintfRuntimeInfo(JNIEnv *env);
1729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_os_SystemProperties(JNIEnv *env);
1739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_os_SystemClock(JNIEnv* env);
174481c1570dc5cdf58265b53f657801709dd05d1dfJeff Brownextern int register_android_os_Trace(JNIEnv* env);
1759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_os_FileObserver(JNIEnv *env);
1769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_os_UEventObserver(JNIEnv* env);
1779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_os_MemoryFile(JNIEnv* env);
178dea6a027610951541981467276d8cd8ba8abc28bJohn Reckextern int register_android_os_SharedMemory(JNIEnv* env);
1799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_net_LocalSocketImpl(JNIEnv* env);
1809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_net_NetworkUtils(JNIEnv* env);
1819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_text_AndroidCharacter(JNIEnv *env);
18244a1df2cf3857692ca95149d4fa70017982f2211Seigo Nonakaextern int register_android_text_Hyphenator(JNIEnv *env);
1839d3bd08ebab564ed9231c8ee112e8085cda74ce8Seigo Nonakaextern int register_android_text_MeasuredParagraph(JNIEnv* env);
18488b5b0be887fc5dc3b0b879b4179dde200d2e4d6Anish Athalyeextern int register_android_text_StaticLayout(JNIEnv *env);
1859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_opengl_classes(JNIEnv *env);
1869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
18729564cd24589867f653cd22cabbaac6493cfc530Narayan Kamathextern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env);
1881cf587496fcb1d652bab9fc6792fb106b6fefaa4Joe Onoratoextern int register_android_backup_BackupDataInput(JNIEnv *env);
189d2110dbce071a236b6176de344ca797b737542ebJoe Onoratoextern int register_android_backup_BackupDataOutput(JNIEnv *env);
19006290a4bb9b280fa14a2bbeb2d3ceb09396a78c3Joe Onoratoextern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
1914ababd922eac5931e0222862ff082dc29e012816Joe Onoratoextern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
1924a627c71ff53a4fca1f961f4b1dcc0461df18a06Christopher Tateextern int register_android_app_backup_FullBackup(JNIEnv *env);
1934449ef5b6a85ef4e16dbd5d939db7b11eac0b586Dimitry Ivanovextern int register_android_app_Activity(JNIEnv *env);
1949c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haaseextern int register_android_app_ActivityThread(JNIEnv *env);
19569969e48f2bca9339662dddfacff0bbf6374ed7fDianne Hackbornextern int register_android_app_NativeActivity(JNIEnv *env);
196cbad976b2a36a0895ca94510d5208a86f66cf596Jeff Brownextern int register_android_media_RemoteDisplay(JNIEnv *env);
1978a7c1606d88873c5a1b5764c16cb046b6f2275b2Przemyslaw Szczepaniakextern int register_android_util_jar_StrictJarFile(JNIEnv* env);
19846b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brownextern int register_android_view_InputChannel(JNIEnv* env);
1999f25b7fdf216c9ef0bd2322cd223eeaf0d60f77fJeff Brownextern int register_android_view_InputDevice(JNIEnv* env);
20032cbc3855c2a971aa5a801fd339fb6a37db91a1aJeff Brownextern int register_android_view_InputEventReceiver(JNIEnv* env);
201c28867a1d67121ce5963de135e3ae2b1dbd9a33dJeff Brownextern int register_android_view_InputEventSender(JNIEnv* env);
202a44dd26a75e24cc021802288fb81f4761e47be6bMichael Wrightextern int register_android_view_InputQueue(JNIEnv* env);
2039f25b7fdf216c9ef0bd2322cd223eeaf0d60f77fJeff Brownextern int register_android_view_KeyCharacterMap(JNIEnv *env);
20446b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brownextern int register_android_view_KeyEvent(JNIEnv* env);
20546b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brownextern int register_android_view_MotionEvent(JNIEnv* env);
2062352b978a3c94cd88f41d0d908f961333fdac1e9Jeff Brownextern int register_android_view_PointerIcon(JNIEnv* env);
2072ed2462aa29c564f5231f317c27b3188da875e52Jeff Brownextern int register_android_view_VelocityTracker(JNIEnv* env);
20802c8730c1bf19daf48bec8c6995df676a00a73b1Kenny Rootextern int register_android_content_res_ObbScanner(JNIEnv* env);
20908d5b8fad8d46ccb64db2fdcb4d66972ec87bf48Dianne Hackbornextern int register_android_content_res_Configuration(JNIEnv* env);
2106e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haaseextern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
21109856135e35c069bab58e7487ccfc733b9a6811cBo Zhuextern int register_android_security_Scrypt(JNIEnv *env);
21266269ea6f68f2f25888ce1080c94ac782742fafcKenny Rootextern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
2139a2c2a6da90abbcc9a064c20e93ed885651f4ae1Jeff Sharkeyextern int register_com_android_internal_net_NetworkStatsFactory(JNIEnv *env);
214f9419f0f8524da4980726e06130a80e0fb226763Narayan Kamathextern int register_com_android_internal_os_ClassLoaderFactory(JNIEnv* env);
215878e86f38f87cc5dc537ffc623b04f9a779fb080Daichi Hironoextern int register_com_android_internal_os_FuseAppLoop(JNIEnv* env);
216973b4663b0b5ee62006522bf4742af076096e548Narayan Kamathextern int register_com_android_internal_os_Zygote(JNIEnv *env);
2171fe1dc0131f8251703ad54ac5e79eefa84affc2bJesse Hallextern int register_com_android_internal_os_ZygoteInit(JNIEnv *env);
2189fa4071c4768c63902c6a74a4b480b51a8b95d43John Reckextern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env);
2199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic AndroidRuntime* gCurRuntime = NULL;
2219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
2239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Code written in the Java Programming Language calls here from main().
2249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
22516f5f5cc9d4c480fac3dc7f176f3f1edfbd256f4Jeff Brownstatic void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz)
2269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
2279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    gCurRuntime->onStarted();
2289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
2299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
23076d4fc84518b3560fc0e8d912a09c1eefefe85acAndreas Gampestatic void com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
2319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
2329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    gCurRuntime->onZygoteInit();
2339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
2349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2354280c4a93ea17f2e9d3f651e49d8c13dc3fb92aaJeff Brownstatic void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIEnv* env,
2364280c4a93ea17f2e9d3f651e49d8c13dc3fb92aaJeff Brown        jobject clazz, jboolean exitWithoutCleanup)
2374280c4a93ea17f2e9d3f651e49d8c13dc3fb92aaJeff Brown{
2384280c4a93ea17f2e9d3f651e49d8c13dc3fb92aaJeff Brown    gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup);
2394280c4a93ea17f2e9d3f651e49d8c13dc3fb92aaJeff Brown}
2404280c4a93ea17f2e9d3f651e49d8c13dc3fb92aaJeff Brown
2419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
2429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * JNI registration.
2439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
2449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectint register_com_android_internal_os_RuntimeInit(JNIEnv* env)
2469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
24776d4fc84518b3560fc0e8d912a09c1eefefe85acAndreas Gampe    const JNINativeMethod methods[] = {
24876d4fc84518b3560fc0e8d912a09c1eefefe85acAndreas Gampe        { "nativeFinishInit", "()V",
24976d4fc84518b3560fc0e8d912a09c1eefefe85acAndreas Gampe            (void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
25076d4fc84518b3560fc0e8d912a09c1eefefe85acAndreas Gampe        { "nativeSetExitWithoutCleanup", "(Z)V",
25176d4fc84518b3560fc0e8d912a09c1eefefe85acAndreas Gampe            (void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
25276d4fc84518b3560fc0e8d912a09c1eefefe85acAndreas Gampe    };
2539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
25476d4fc84518b3560fc0e8d912a09c1eefefe85acAndreas Gampe        methods, NELEM(methods));
25576d4fc84518b3560fc0e8d912a09c1eefefe85acAndreas Gampe}
25676d4fc84518b3560fc0e8d912a09c1eefefe85acAndreas Gampe
2571fe1dc0131f8251703ad54ac5e79eefa84affc2bJesse Hallint register_com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv* env)
25876d4fc84518b3560fc0e8d912a09c1eefefe85acAndreas Gampe{
25976d4fc84518b3560fc0e8d912a09c1eefefe85acAndreas Gampe    const JNINativeMethod methods[] = {
26076d4fc84518b3560fc0e8d912a09c1eefefe85acAndreas Gampe        { "nativeZygoteInit", "()V",
26176d4fc84518b3560fc0e8d912a09c1eefefe85acAndreas Gampe            (void*) com_android_internal_os_ZygoteInit_nativeZygoteInit },
26276d4fc84518b3560fc0e8d912a09c1eefefe85acAndreas Gampe    };
26376d4fc84518b3560fc0e8d912a09c1eefefe85acAndreas Gampe    return jniRegisterNativeMethods(env, "com/android/internal/os/ZygoteInit",
26476d4fc84518b3560fc0e8d912a09c1eefefe85acAndreas Gampe        methods, NELEM(methods));
2659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
2669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project// ----------------------------------------------------------------------
2689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2699ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
2709ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber
271a23fcd7be8e40078a913b1a99222cdd89229e67bNarayan KamathAndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) :
272a23fcd7be8e40078a913b1a99222cdd89229e67bNarayan Kamath        mExitWithoutCleanup(false),
273a23fcd7be8e40078a913b1a99222cdd89229e67bNarayan Kamath        mArgBlockStart(argBlockStart),
274a23fcd7be8e40078a913b1a99222cdd89229e67bNarayan Kamath        mArgBlockLength(argBlockLength)
2759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
276c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project    SkGraphics::Init();
2779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    // Pre-allocate enough space to hold a fair number of options.
2799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    mOptions.setCapacity(20);
2809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    assert(gCurRuntime == NULL);        // one per process
2829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    gCurRuntime = this;
2839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
2849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source ProjectAndroidRuntime::~AndroidRuntime()
2869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
2879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
2889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2899ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber/*
2909ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber * Register native methods using JNI.
2919ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber */
2929ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
2939ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber    const char* className, const JNINativeMethod* gMethods, int numMethods)
2949ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber{
2959ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber    return jniRegisterNativeMethods(env, className, gMethods, numMethods);
2969ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber}
2979ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber
298f5b6e5590e0a2c1be10bc0bd0a3b141256fdf7fdDmitriy Filchenkovoid AndroidRuntime::setArgv0(const char* argv0, bool setProcName) {
299f5b6e5590e0a2c1be10bc0bd0a3b141256fdf7fdDmitriy Filchenko    if (setProcName) {
300f5b6e5590e0a2c1be10bc0bd0a3b141256fdf7fdDmitriy Filchenko        int len = strlen(argv0);
301f5b6e5590e0a2c1be10bc0bd0a3b141256fdf7fdDmitriy Filchenko        if (len < 15) {
302f5b6e5590e0a2c1be10bc0bd0a3b141256fdf7fdDmitriy Filchenko            pthread_setname_np(pthread_self(), argv0);
303f5b6e5590e0a2c1be10bc0bd0a3b141256fdf7fdDmitriy Filchenko        } else {
304f5b6e5590e0a2c1be10bc0bd0a3b141256fdf7fdDmitriy Filchenko            pthread_setname_np(pthread_self(), argv0 + len - 15);
305f5b6e5590e0a2c1be10bc0bd0a3b141256fdf7fdDmitriy Filchenko        }
306f5b6e5590e0a2c1be10bc0bd0a3b141256fdf7fdDmitriy Filchenko    }
30700c0cd4a24bd0f040055f9e786e2df1fa3b7d2d3Jeff Brown    memset(mArgBlockStart, 0, mArgBlockLength);
308a23fcd7be8e40078a913b1a99222cdd89229e67bNarayan Kamath    strlcpy(mArgBlockStart, argv0, mArgBlockLength);
309a23fcd7be8e40078a913b1a99222cdd89229e67bNarayan Kamath}
310a23fcd7be8e40078a913b1a99222cdd89229e67bNarayan Kamath
31122ec1eefa4dc8e12f7da8e8750d4770144941526Narayan Kamathstatus_t AndroidRuntime::callMain(const String8& className, jclass clazz,
31222ec1eefa4dc8e12f7da8e8750d4770144941526Narayan Kamath    const Vector<String8>& args)
3139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
3149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    JNIEnv* env;
3159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    jmethodID methodId;
3169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
31722ec1eefa4dc8e12f7da8e8750d4770144941526Narayan Kamath    ALOGD("Calling main entry %s", className.string());
31808e60f2a165d23b53f41993374aa074165bb5863Dianne Hackborn
3199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    env = getJNIEnv();
320d195e5ab401432ddac659791640a2927fc668699Elliott Hughes    if (clazz == NULL || env == NULL) {
3219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return UNKNOWN_ERROR;
3229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
3259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (methodId == NULL) {
32622ec1eefa4dc8e12f7da8e8750d4770144941526Narayan Kamath        ALOGE("ERROR: could not find method %s.main(String[])\n", className.string());
3279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return UNKNOWN_ERROR;
3289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /*
3319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * We want to call main() with a String array with our arguments in it.
3329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Create an array and populate it.
3339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    jclass stringClass;
3359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    jobjectArray strArray;
3369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
33722ec1eefa4dc8e12f7da8e8750d4770144941526Narayan Kamath    const size_t numArgs = args.size();
3389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    stringClass = env->FindClass("java/lang/String");
33922ec1eefa4dc8e12f7da8e8750d4770144941526Narayan Kamath    strArray = env->NewObjectArray(numArgs, stringClass, NULL);
3409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
34122ec1eefa4dc8e12f7da8e8750d4770144941526Narayan Kamath    for (size_t i = 0; i < numArgs; i++) {
34222ec1eefa4dc8e12f7da8e8750d4770144941526Narayan Kamath        jstring argStr = env->NewStringUTF(args[i].string());
3439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        env->SetObjectArrayElement(strArray, i, argStr);
3449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    env->CallStaticVoidMethod(clazz, methodId, strArray);
3479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return NO_ERROR;
3489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
3499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
3519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * The VM calls this through the "exit" hook.
3529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
3539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic void runtime_exit(int code)
3549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
3554280c4a93ea17f2e9d3f651e49d8c13dc3fb92aaJeff Brown    gCurRuntime->exit(code);
3569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
3579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
3599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * The VM calls this through the "vfprintf" hook.
3609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
3619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * We ignore "fp" and just write the results to the log file.
3629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
3639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
3649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
3659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
3669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
3679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3680bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick/**
3690bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick * The VM calls this when mutex contention debugging is enabled to
3700bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick * determine whether or not the blocked thread was a "sensitive thread"
3710bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick * for user responsiveness/smoothess.
3720bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick *
3730bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick * Our policy for this is whether or not we're tracing any StrictMode
3740bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick * events on this thread (which we might've inherited via Binder calls
3750bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick * into us)
3760bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick */
3770bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrickstatic bool runtime_isSensitiveThread() {
3780bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick    IPCThreadState* state = IPCThreadState::selfOrNull();
3790bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick    return state && state->getStrictModePolicy() != 0;
3800bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick}
3810bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick
3829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic int hasDir(const char* dir)
3839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
3849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    struct stat s;
3859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    int res = stat(dir, &s);
3869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (res == 0) {
3879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return S_ISDIR(s.st_mode);
3889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return 0;
3909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
3919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
392995c62d6abd4b7080e52a60d1bffa32ae4a798a3Andreas Gampestatic bool hasFile(const char* file) {
393995c62d6abd4b7080e52a60d1bffa32ae4a798a3Andreas Gampe    struct stat s;
394995c62d6abd4b7080e52a60d1bffa32ae4a798a3Andreas Gampe    int res = stat(file, &s);
395995c62d6abd4b7080e52a60d1bffa32ae4a798a3Andreas Gampe    if (res == 0) {
396995c62d6abd4b7080e52a60d1bffa32ae4a798a3Andreas Gampe        return S_ISREG(s.st_mode);
397995c62d6abd4b7080e52a60d1bffa32ae4a798a3Andreas Gampe    }
398995c62d6abd4b7080e52a60d1bffa32ae4a798a3Andreas Gampe    return false;
399995c62d6abd4b7080e52a60d1bffa32ae4a798a3Andreas Gampe}
400995c62d6abd4b7080e52a60d1bffa32ae4a798a3Andreas Gampe
4019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
402bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * Read the persistent locale. Inspects the following system properties
403bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * (in order) and returns the first non-empty property in the list :
404bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath *
405bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * (1) persist.sys.locale
406bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * (2) persist.sys.language/country/localevar (country and localevar are
407bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * inspected iff. language is non-empty.
408bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * (3) ro.product.locale
409bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * (4) ro.product.locale.language/region
410bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath *
411bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * Note that we need to inspect persist.sys.language/country/localevar to
412bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * preserve language settings for devices that are upgrading from Lollipop
413bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * to M. The same goes for ro.product.locale.language/region as well.
4149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
415bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamathconst std::string readLocale()
4169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
41793099e4485d62fc8cd900cb213c17117c17c3351Tom Cherry    const std::string locale = GetProperty("persist.sys.locale", "");
418bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    if (!locale.empty()) {
419bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath        return locale;
420bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    }
421bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath
42293099e4485d62fc8cd900cb213c17117c17c3351Tom Cherry    const std::string language = GetProperty("persist.sys.language", "");
423bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    if (!language.empty()) {
42493099e4485d62fc8cd900cb213c17117c17c3351Tom Cherry        const std::string country = GetProperty("persist.sys.country", "");
42593099e4485d62fc8cd900cb213c17117c17c3351Tom Cherry        const std::string variant = GetProperty("persist.sys.localevar", "");
426bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath
427bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath        std::string out = language;
428bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath        if (!country.empty()) {
429bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath            out = out + "-" + country;
430bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath        }
431bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath
432bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath        if (!variant.empty()) {
433bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath            out = out + "-" + variant;
434d30dbb8ae12e6e83e3035f12dd291f92e1f22c18Narayan Kamath        }
435bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath
436bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath        return out;
4379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
438d30dbb8ae12e6e83e3035f12dd291f92e1f22c18Narayan Kamath
43993099e4485d62fc8cd900cb213c17117c17c3351Tom Cherry    const std::string productLocale = GetProperty("ro.product.locale", "");
440bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    if (!productLocale.empty()) {
441bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath        return productLocale;
442bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    }
443bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath
444bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    // If persist.sys.locale and ro.product.locale are missing,
445bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    // construct a locale value from the individual locale components.
44693099e4485d62fc8cd900cb213c17117c17c3351Tom Cherry    const std::string productLanguage = GetProperty("ro.product.locale.language", "en");
44793099e4485d62fc8cd900cb213c17117c17c3351Tom Cherry    const std::string productRegion = GetProperty("ro.product.locale.region", "US");
448bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath
449bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    return productLanguage + "-" + productRegion;
4509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
4519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4520d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstromvoid AndroidRuntime::addOption(const char* optionString, void* extraInfo)
4530d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom{
4540d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    JavaVMOption opt;
4550d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    opt.optionString = optionString;
4560d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    opt.extraInfo = extraInfo;
4570d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    mOptions.add(opt);
4580d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom}
4590d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom
460f70188aa4716625781d9952c6b883180528d4644Andy McFadden/*
461e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden * Parse a property containing space-separated options that should be
462e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
463e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden *
464e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden * This will cut up "extraOptsBuf" as we chop it into individual options.
465e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden *
4663beff1e023193b485c67a3003a7f363f105d96d4Brian Carlstrom * If "quotingArg" is non-null, it is passed before each extra option in mOptions.
4673beff1e023193b485c67a3003a7f363f105d96d4Brian Carlstrom *
468e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden * Adds the strings, if any, to mOptions.
469e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden */
4703beff1e023193b485c67a3003a7f363f105d96d4Brian Carlstromvoid AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg)
471e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden{
4723beff1e023193b485c67a3003a7f363f105d96d4Brian Carlstrom    char* start = extraOptsBuf;
4733beff1e023193b485c67a3003a7f363f105d96d4Brian Carlstrom    char* end = NULL;
474e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden    while (*start != '\0') {
475e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden        while (*start == ' ')                   /* skip leading whitespace */
476e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden            start++;
477e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden        if (*start == '\0')                     /* was trailing ws, bail */
478e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden            break;
479e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden
480e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden        end = start+1;
481e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden        while (*end != ' ' && *end != '\0')     /* find end of token */
482e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden            end++;
483e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden        if (*end == ' ')
484e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden            *end++ = '\0';          /* mark end, advance to indicate more */
485e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden
4863beff1e023193b485c67a3003a7f363f105d96d4Brian Carlstrom        if (quotingArg != NULL) {
4870d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom            addOption(quotingArg);
4883beff1e023193b485c67a3003a7f363f105d96d4Brian Carlstrom        }
4890d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom        addOption(start);
490e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden        start = end;
491e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden    }
492e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden}
493e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden
494e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden/*
4956d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * Reads a "property" into "buffer" with a default of "defaultArg". If
4966d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * the property is non-empty, it is treated as a runtime option such
4976d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * as "-Xmx32m".
4986d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom *
4996d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
5006d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom *
5016d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * If an argument is found, it is added to mOptions.
5026d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom *
5036d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * If an option is found, it is added to mOptions and true is
5046d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * returned. Otherwise false is returned.
5056d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom */
5066d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrombool AndroidRuntime::parseRuntimeOption(const char* property,
5076d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom                                        char* buffer,
5086d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom                                        const char* runtimeArg,
5096d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom                                        const char* defaultArg)
5106d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom{
5116d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    strcpy(buffer, runtimeArg);
5126d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    size_t runtimeArgLen = strlen(runtimeArg);
5136d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    property_get(property, buffer+runtimeArgLen, defaultArg);
5146d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    if (buffer[runtimeArgLen] == '\0') {
5156d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom        return false;
5166d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    }
5170d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption(buffer);
5186d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    return true;
5196d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom}
5206d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom
5216d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom/*
5226d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * Reads a "property" into "buffer". If the property is non-empty, it
5233fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom * is treated as a dex2oat compiler option that should be
524be7b0d18a7d68aa79dc8256ee904f0a94767d5d9Nicolas Geoffray * passed as a quoted option, e.g. "-Ximage-compiler-option --compiler-filter=assume-verified".
5253fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom *
5263fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom * The "compilerArg" is a prefix for the option such as "--compiler-filter=".
5273fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom *
5283fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
5293fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom *
5303fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom * If an option is found, it is added to mOptions and true is
5313fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom * returned. Otherwise false is returned.
5323fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom */
5333fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrombool AndroidRuntime::parseCompilerOption(const char* property,
5343fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom                                         char* buffer,
5353fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom                                         const char* compilerArg,
5363fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom                                         const char* quotingArg)
5373fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom{
5383fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom    strcpy(buffer, compilerArg);
5393fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom    size_t compilerArgLen = strlen(compilerArg);
5403fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom    property_get(property, buffer+compilerArgLen, "");
5413fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom    if (buffer[compilerArgLen] == '\0') {
5423fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom        return false;
5433fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom    }
5440d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption(quotingArg);
5450d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption(buffer);
5463fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom    return true;
5473fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom}
5483fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom
5493fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom/*
5503fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom * Reads a "property" into "buffer". If the property is non-empty, it
5516d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * is treated as a dex2oat compiler runtime option that should be
5526d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * passed as a quoted option, e.g. "-Ximage-compiler-option
5536d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * --runtime-arg -Ximage-compiler-option -Xmx32m".
5546d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom *
5556d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
5566d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom *
5576d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
5586d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom *
5596d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * If an option is found, it is added to mOptions and true is
5606d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * returned. Otherwise false is returned.
5616d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom */
5626d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrombool AndroidRuntime::parseCompilerRuntimeOption(const char* property,
5636d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom                                                char* buffer,
5646d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom                                                const char* runtimeArg,
5656d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom                                                const char* quotingArg)
5666d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom{
5676d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    strcpy(buffer, runtimeArg);
5686d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    size_t runtimeArgLen = strlen(runtimeArg);
5696d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    property_get(property, buffer+runtimeArgLen, "");
5706d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    if (buffer[runtimeArgLen] == '\0') {
5716d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom        return false;
5726d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    }
5730d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption(quotingArg);
5740d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption("--runtime-arg");
5750d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption(quotingArg);
5760d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption(buffer);
5776d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    return true;
5786d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom}
5796d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom
5806d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom/*
581f70188aa4716625781d9952c6b883180528d4644Andy McFadden * Start the Dalvik Virtual Machine.
582f70188aa4716625781d9952c6b883180528d4644Andy McFadden *
583f70188aa4716625781d9952c6b883180528d4644Andy McFadden * Various arguments, most determined by system properties, are passed in.
584f70188aa4716625781d9952c6b883180528d4644Andy McFadden * The "mOptions" vector is updated.
585f70188aa4716625781d9952c6b883180528d4644Andy McFadden *
58607a1e2323b1e6765f220a045bd05783dd99b2914Dave Allison * CAUTION: when adding options in here, be careful not to put the
58707a1e2323b1e6765f220a045bd05783dd99b2914Dave Allison * char buffer inside a nested scope.  Adding the buffer to the
58807a1e2323b1e6765f220a045bd05783dd99b2914Dave Allison * options using mOptions.add() does not copy the buffer, so if the
58907a1e2323b1e6765f220a045bd05783dd99b2914Dave Allison * buffer goes out of scope the option may be overwritten.  It's best
59007a1e2323b1e6765f220a045bd05783dd99b2914Dave Allison * to put the buffer at the top of the function so that it is more
59107a1e2323b1e6765f220a045bd05783dd99b2914Dave Allison * unlikely that someone will surround it in a scope at a later time
59207a1e2323b1e6765f220a045bd05783dd99b2914Dave Allison * and thus introduce a bug.
59307a1e2323b1e6765f220a045bd05783dd99b2914Dave Allison *
594f70188aa4716625781d9952c6b883180528d4644Andy McFadden * Returns 0 on success.
595f70188aa4716625781d9952c6b883180528d4644Andy McFadden */
5967a09b8322cab26d6e3da1362d3c74964ae66b5d4Sebastien Hertzint AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote)
5979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
5989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    JavaVMInitArgs initArgs;
5999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    char propBuf[PROPERTY_VALUE_MAX];
6006d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    char stackTraceFileBuf[sizeof("-Xstacktracefile:")-1 + PROPERTY_VALUE_MAX];
6019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
60238cfa8ca8bc67f4342431cea7e35643ddf9254ccCarl Shapiro    char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
603bdcef70e15e86e592d725355c96c7fab0b85ac83Dianne Hackborn    char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
6048cdf27c36a5b697396144925b3f61e4802dd3558Carl Shapiro    char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
6055325010486a13553a8597aab92f90abc141a25e8Ian Rogers    char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
6065325010486a13553a8597aab92f90abc141a25e8Ian Rogers    char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
6076909c0e1e7bbf6e8050330244bbe47bff9587225Mathieu Chartier    char usejitOptsBuf[sizeof("-Xusejit:")-1 + PROPERTY_VALUE_MAX];
608cdf1dfff8f850da7b1ae3a34b78de7313064f5e0Nicolas Geoffray    char jitmaxsizeOptsBuf[sizeof("-Xjitmaxsize:")-1 + PROPERTY_VALUE_MAX];
609cdf1dfff8f850da7b1ae3a34b78de7313064f5e0Nicolas Geoffray    char jitinitialsizeOptsBuf[sizeof("-Xjitinitialsize:")-1 + PROPERTY_VALUE_MAX];
6106909c0e1e7bbf6e8050330244bbe47bff9587225Mathieu Chartier    char jitthresholdOptsBuf[sizeof("-Xjitthreshold:")-1 + PROPERTY_VALUE_MAX];
611db4a79a5d7d348e9d2286d95d4e5a59dd484456fCalin Juravle    char useJitProfilesOptsBuf[sizeof("-Xjitsaveprofilinginfo:")-1 + PROPERTY_VALUE_MAX];
6120de80b9f550fc8ff1f46d5f95cf229745d71eb2aCalin Juravle    char jitprithreadweightOptBuf[sizeof("-Xjitprithreadweight:")-1 + PROPERTY_VALUE_MAX];
6138d74de55464c885b602b34252ee8721a9e810dcfCalin Juravle    char jittransitionweightOptBuf[sizeof("-Xjittransitionweight:")-1 + PROPERTY_VALUE_MAX];
6145eee004b926dc0fc02640de09c9d9a7f8fe1f052Mathieu Chartier    char hotstartupsamplesOptsBuf[sizeof("-Xps-hot-startup-method-samples:")-1 + PROPERTY_VALUE_MAX];
615cd0caf5e8e8056ee714d8da5d4f76d08feabca5cMathieu Chartier    char madviseRandomOptsBuf[sizeof("-XX:MadviseRandomAccess:")-1 + PROPERTY_VALUE_MAX];
6167e4fdec6f0ac6385c5f8aeaf0f2e12e162138ac3Mathieu Chartier    char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
617c01936a686ff75c872629b219898021e8ae49afaMathieu Chartier    char backgroundgcOptsBuf[sizeof("-XX:BackgroundGC=")-1 + PROPERTY_VALUE_MAX];
6185325010486a13553a8597aab92f90abc141a25e8Ian Rogers    char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
619ebc3b4c033e8a48855091cc2229753c274aac768Mathieu Chartier    char foregroundHeapGrowthMultiplierOptsBuf[
620ebc3b4c033e8a48855091cc2229753c274aac768Mathieu Chartier            sizeof("-XX:ForegroundHeapGrowthMultiplier=")-1 + PROPERTY_VALUE_MAX];
621e324ba0e7cc1b831f86c5d2f0578c9b881a3130bAndreas Gampe    char cachePruneBuf[sizeof("-Xzygote-max-boot-retry=")-1 + PROPERTY_VALUE_MAX];
6226d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    char dex2oatXmsImageFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
6236d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    char dex2oatXmxImageFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
6246d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    char dex2oatXmsFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
6256d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    char dex2oatXmxFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
6263fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom    char dex2oatCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
6273fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom    char dex2oatImageCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
628e0352388238875ef7e7b31d914fc903b08ff0f6bAndreas Gampe    char dex2oatThreadsBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
629e0352388238875ef7e7b31d914fc903b08ff0f6bAndreas Gampe    char dex2oatThreadsImageBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
630605cca1a985be74c00582853ee2c84b086cfade8Andreas Gampe    char dex2oat_isa_variant_key[PROPERTY_KEY_MAX];
631605cca1a985be74c00582853ee2c84b086cfade8Andreas Gampe    char dex2oat_isa_variant[sizeof("--instruction-set-variant=") -1 + PROPERTY_VALUE_MAX];
632605cca1a985be74c00582853ee2c84b086cfade8Andreas Gampe    char dex2oat_isa_features_key[PROPERTY_KEY_MAX];
633605cca1a985be74c00582853ee2c84b086cfade8Andreas Gampe    char dex2oat_isa_features[sizeof("--instruction-set-features=") -1 + PROPERTY_VALUE_MAX];
6343beff1e023193b485c67a3003a7f363f105d96d4Brian Carlstrom    char dex2oatFlagsBuf[PROPERTY_VALUE_MAX];
6353beff1e023193b485c67a3003a7f363f105d96d4Brian Carlstrom    char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX];
636e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden    char extraOptsBuf[PROPERTY_VALUE_MAX];
6370d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    char voldDecryptBuf[PROPERTY_VALUE_MAX];
63852b0e73443ff8da195fbf0df851a028e07a691b2Ben Cheng    enum {
63952b0e73443ff8da195fbf0df851a028e07a691b2Ben Cheng      kEMDefault,
64052b0e73443ff8da195fbf0df851a028e07a691b2Ben Cheng      kEMIntPortable,
64152b0e73443ff8da195fbf0df851a028e07a691b2Ben Cheng      kEMIntFast,
64252b0e73443ff8da195fbf0df851a028e07a691b2Ben Cheng      kEMJitCompiler,
64352b0e73443ff8da195fbf0df851a028e07a691b2Ben Cheng    } executionMode = kEMDefault;
644d30dbb8ae12e6e83e3035f12dd291f92e1f22c18Narayan Kamath    char localeOption[sizeof("-Duser.locale=") + PROPERTY_VALUE_MAX];
6456d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX];
64601db916970ece2382ebf9e06873a14aee9543a9dCalin Juravle    char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX];
647ff193d642eea7128faad837d19e347cd25212c27Dmitriy Ivanov    char cpuAbiListBuf[sizeof("--cpu-abilist=") + PROPERTY_VALUE_MAX];
64898f406f6f31660d0f5ee32113ffadc720b426dc6Andreas Gampe    char methodTraceFileBuf[sizeof("-Xmethod-trace-file:") + PROPERTY_VALUE_MAX];
64998f406f6f31660d0f5ee32113ffadc720b426dc6Andreas Gampe    char methodTraceFileSizeBuf[sizeof("-Xmethod-trace-file-size:") + PROPERTY_VALUE_MAX];
65093099e4485d62fc8cd900cb213c17117c17c3351Tom Cherry    std::string fingerprintBuf;
651fffb273affa011d1d062487f91aa4b3db8a029aaAlex Light    char jdwpProviderBuf[sizeof("-XjdwpProvider:") - 1 + PROPERTY_VALUE_MAX];
6529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6536d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    bool checkJni = false;
6549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    property_get("dalvik.vm.checkjni", propBuf, "");
6559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (strcmp(propBuf, "true") == 0) {
6569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkJni = true;
6579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    } else if (strcmp(propBuf, "false") != 0) {
6589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /* property is neither true nor false; fall back on kernel parameter */
6599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        property_get("ro.kernel.android.checkjni", propBuf, "");
6609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (propBuf[0] == '1') {
6619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            checkJni = true;
6629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
6639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
66482ba91ddb4fe9d9ff8245e27f70dea64cc20553dJoe Onorato    ALOGV("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
6656d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    if (checkJni) {
6666d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom        /* extended JNI checking */
6670d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom        addOption("-Xcheck:jni");
6686d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom
6696d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom        /* with -Xcheck:jni, this provides a JNI function call trace */
6700d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom        //addOption("-verbose:jni");
6716d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    }
6729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    property_get("dalvik.vm.execution-mode", propBuf, "");
6749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (strcmp(propBuf, "int:portable") == 0) {
6759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        executionMode = kEMIntPortable;
6769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    } else if (strcmp(propBuf, "int:fast") == 0) {
6779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        executionMode = kEMIntFast;
67852b0e73443ff8da195fbf0df851a028e07a691b2Ben Cheng    } else if (strcmp(propBuf, "int:jit") == 0) {
67952b0e73443ff8da195fbf0df851a028e07a691b2Ben Cheng        executionMode = kEMJitCompiler;
6809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
68293f2e38160cc774c311ee8fcf6e8d7975b0912ffNarayan Kamath    // If dalvik.vm.stack-trace-dir is set, it enables the "new" stack trace
68393f2e38160cc774c311ee8fcf6e8d7975b0912ffNarayan Kamath    // dump scheme and a new file is created for each stack dump. If it isn't set,
68493f2e38160cc774c311ee8fcf6e8d7975b0912ffNarayan Kamath    // the old scheme is enabled.
68523941e5c222bb300bf809cbf6f4d6057803a3c68Narayan Kamath    property_get("dalvik.vm.stack-trace-dir", propBuf, "");
68623941e5c222bb300bf809cbf6f4d6057803a3c68Narayan Kamath    if (strlen(propBuf) > 0) {
68723941e5c222bb300bf809cbf6f4d6057803a3c68Narayan Kamath        addOption("-Xusetombstonedtraces");
68823941e5c222bb300bf809cbf6f4d6057803a3c68Narayan Kamath    } else {
68993f2e38160cc774c311ee8fcf6e8d7975b0912ffNarayan Kamath        parseRuntimeOption("dalvik.vm.stack-trace-file", stackTraceFileBuf, "-Xstacktracefile:");
69093f2e38160cc774c311ee8fcf6e8d7975b0912ffNarayan Kamath    }
6919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    strcpy(jniOptsBuf, "-Xjniopts:");
6936d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    if (parseRuntimeOption("dalvik.vm.jniopts", jniOptsBuf, "-Xjniopts:")) {
6946d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom        ALOGI("JNI options: '%s'\n", jniOptsBuf);
6956d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    }
6969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /* route exit() to our handler */
6980d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption("exit", (void*) runtime_exit);
6999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /* route fprintf() to our handler */
7010d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption("vfprintf", (void*) runtime_vfprintf);
7029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7030bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick    /* register the framework-specific "is sensitive thread" hook */
7040d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption("sensitiveThread", (void*) runtime_isSensitiveThread);
7059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /* enable verbose; standard options are { jni, gc, class } */
7070d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    //addOption("-verbose:jni");
7080d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption("-verbose:gc");
7090d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    //addOption("-verbose:class");
7109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7119e4c884e7a7acd6b75399b180dc339295cda5a43Carl Shapiro    /*
7129e4c884e7a7acd6b75399b180dc339295cda5a43Carl Shapiro     * The default starting and maximum size of the heap.  Larger
7139e4c884e7a7acd6b75399b180dc339295cda5a43Carl Shapiro     * values should be specified in a product property override.
7149e4c884e7a7acd6b75399b180dc339295cda5a43Carl Shapiro     */
7156d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    parseRuntimeOption("dalvik.vm.heapstartsize", heapstartsizeOptsBuf, "-Xms", "4m");
7166d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    parseRuntimeOption("dalvik.vm.heapsize", heapsizeOptsBuf, "-Xmx", "16m");
7179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7186d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    parseRuntimeOption("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
7196d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    parseRuntimeOption("dalvik.vm.heapminfree", heapminfreeOptsBuf, "-XX:HeapMinFree=");
7206d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    parseRuntimeOption("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf, "-XX:HeapMaxFree=");
7216d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    parseRuntimeOption("dalvik.vm.heaptargetutilization",
7226d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom                       heaptargetutilizationOptsBuf,
7236d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom                       "-XX:HeapTargetUtilization=");
7245325010486a13553a8597aab92f90abc141a25e8Ian Rogers
725ebc3b4c033e8a48855091cc2229753c274aac768Mathieu Chartier    /* Foreground heap growth multiplier option */
726ebc3b4c033e8a48855091cc2229753c274aac768Mathieu Chartier    parseRuntimeOption("dalvik.vm.foreground-heap-growth-multiplier",
727ebc3b4c033e8a48855091cc2229753c274aac768Mathieu Chartier                       foregroundHeapGrowthMultiplierOptsBuf,
728ebc3b4c033e8a48855091cc2229753c274aac768Mathieu Chartier                       "-XX:ForegroundHeapGrowthMultiplier=");
729ebc3b4c033e8a48855091cc2229753c274aac768Mathieu Chartier
7306909c0e1e7bbf6e8050330244bbe47bff9587225Mathieu Chartier    /*
7316909c0e1e7bbf6e8050330244bbe47bff9587225Mathieu Chartier     * JIT related options.
7326909c0e1e7bbf6e8050330244bbe47bff9587225Mathieu Chartier     */
7331fb7aab9b235fa526a1b8e6e2efd71c7df66096dMathieu Chartier    parseRuntimeOption("dalvik.vm.usejit", usejitOptsBuf, "-Xusejit:");
734cdf1dfff8f850da7b1ae3a34b78de7313064f5e0Nicolas Geoffray    parseRuntimeOption("dalvik.vm.jitmaxsize", jitmaxsizeOptsBuf, "-Xjitmaxsize:");
735cdf1dfff8f850da7b1ae3a34b78de7313064f5e0Nicolas Geoffray    parseRuntimeOption("dalvik.vm.jitinitialsize", jitinitialsizeOptsBuf, "-Xjitinitialsize:");
7361fb7aab9b235fa526a1b8e6e2efd71c7df66096dMathieu Chartier    parseRuntimeOption("dalvik.vm.jitthreshold", jitthresholdOptsBuf, "-Xjitthreshold:");
737db4a79a5d7d348e9d2286d95d4e5a59dd484456fCalin Juravle    property_get("dalvik.vm.usejitprofiles", useJitProfilesOptsBuf, "");
738db4a79a5d7d348e9d2286d95d4e5a59dd484456fCalin Juravle    if (strcmp(useJitProfilesOptsBuf, "true") == 0) {
739