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"
199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project//#define LOG_NDEBUG 0
209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <android_runtime/AndroidRuntime.h>
220795272aa226f4e965968a03daddc53ce30b7cdaMathias Agopian#include <binder/IBinder.h>
230bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick#include <binder/IPCThreadState.h>
240795272aa226f4e965968a03daddc53ce30b7cdaMathias Agopian#include <binder/IServiceManager.h>
259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <utils/Log.h>
269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <utils/misc.h>
271ab43d5978813f56899dbd3115fd7d9f96b4fe55Yasuhiro Matsuda#include <utils/Trace.h>
280795272aa226f4e965968a03daddc53ce30b7cdaMathias Agopian#include <binder/Parcel.h>
299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <utils/threads.h>
309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <cutils/properties.h>
319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <SkGraphics.h>
339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <SkImageDecoder.h>
349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include "jni.h"
369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include "JNIHelp.h"
379f8203a159d46124a0907a0d9500e599533beed3Brian Carlstrom#include "JniInvocation.h"
389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include "android_util_Binder.h"
399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <stdio.h>
419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <signal.h>
429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <sys/stat.h>
439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <sys/types.h>
449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <signal.h>
459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <dirent.h>
469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <assert.h>
479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
48bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath#include <string>
49bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath#include <vector>
50bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath
519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectusing namespace android;
539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_os_Binder(JNIEnv* env);
559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_os_Process(JNIEnv* env);
569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Bitmap(JNIEnv*);
579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_BitmapFactory(JNIEnv*);
586b849e2123be98eb2a1a25b8abf0b13a279ce952Wei-Ta Chenextern int register_android_graphics_BitmapRegionDecoder(JNIEnv*);
599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Camera(JNIEnv* env);
60d0d7eaf129b48ea04c06902a11c2a4f74056d76cLeon Scroggins IIIextern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env);
619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Graphics(JNIEnv* env);
629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Interpolator(JNIEnv* env);
639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_MaskFilter(JNIEnv* env);
649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Movie(JNIEnv* env);
659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_NinePatch(JNIEnv*);
669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_PathEffect(JNIEnv* env);
679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Shader(JNIEnv* env);
689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Typeface(JNIEnv* env);
69bca2d613e0d6d2630fedd302c0d779b7610adbcfWei-Ta Chenextern int register_android_graphics_YuvImage(JNIEnv* env);
709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env);
729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env);
736b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferextern int register_android_opengl_jni_EGL14(JNIEnv* env);
74237c2b871f66e06498ad03aaa92964f4434982c5Jesse Hallextern int register_android_opengl_jni_EGLExt(JNIEnv* env);
751c4907ee77392afb768c2f088e0dedbe4239f6fbJack Palevichextern int register_android_opengl_jni_GLES10(JNIEnv* env);
761c4907ee77392afb768c2f088e0dedbe4239f6fbJack Palevichextern int register_android_opengl_jni_GLES10Ext(JNIEnv* env);
771c4907ee77392afb768c2f088e0dedbe4239f6fbJack Palevichextern int register_android_opengl_jni_GLES11(JNIEnv* env);
781c4907ee77392afb768c2f088e0dedbe4239f6fbJack Palevichextern int register_android_opengl_jni_GLES11Ext(JNIEnv* env);
79560814f6b11abe83ff0c4ed18cac015c276b3181Jack Palevichextern int register_android_opengl_jni_GLES20(JNIEnv* env);
80d877efe3b12afdd84f06c180369f9d7399858f6eJesse Hallextern int register_android_opengl_jni_GLES30(JNIEnv* env);
817ab63acdd0a257272512d0bcf5e06036fa0b9fdfJesse Hallextern int register_android_opengl_jni_GLES31(JNIEnv* env);
827ab63acdd0a257272512d0bcf5e06036fa0b9fdfJesse Hallextern int register_android_opengl_jni_GLES31Ext(JNIEnv* env);
8338c1a7e732660212687cf375f5e5ed354b91e431Pablo Ceballosextern int register_android_opengl_jni_GLES32(JNIEnv* env);
849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_hardware_Camera(JNIEnv *env);
862f1a2e423e0fbb64467d6fcfa4e82c6384f31210Eino-Ville Talvalaextern int register_android_hardware_camera2_CameraMetadata(JNIEnv *env);
87feb50af361e4305a25758966b6b5df2738c00259Ruben Brunkextern int register_android_hardware_camera2_legacy_LegacyCameraDevice(JNIEnv *env);
88e1f57d6f44909a66c7ab0af33dbc5289287e823aEino-Ville Talvalaextern int register_android_hardware_camera2_legacy_PerfMeasurement(JNIEnv *env);
89b6079005ed0631c3972ff427f56e12523ec214a7Ruben Brunkextern int register_android_hardware_camera2_DngCreator(JNIEnv *env);
90633cb563f36001d6973b69291086cbdfe50612c5Eric Laurentextern int register_android_hardware_Radio(JNIEnv *env);
919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_hardware_SensorManager(JNIEnv *env);
92b01e8bf57b7492b77e3445db51471edcbadda75eMike Lockwoodextern int register_android_hardware_SerialPort(JNIEnv *env);
9360b62bc5c11c0bfcdf84ca8f5b2053e5747f86bcEric Laurentextern int register_android_hardware_SoundTrigger(JNIEnv *env);
94e7d511e148bc901ef41ac44d7b3593e5d803f72fMike Lockwoodextern int register_android_hardware_UsbDevice(JNIEnv *env);
95acc29cc91be634070c92a807df412ced97b9b375Mike Lockwoodextern int register_android_hardware_UsbDeviceConnection(JNIEnv *env);
96e7d511e148bc901ef41ac44d7b3593e5d803f72fMike Lockwoodextern int register_android_hardware_UsbRequest(JNIEnv *env);
97a4fa3b5aa53cf677b623fe346c585cb8a0c1ce26destradaaextern int register_android_hardware_location_ActivityRecognitionHardware(JNIEnv* env);
989ff7d2235427b211344fa58b608424805a21aa24Peng Xuextern int register_android_hardware_location_ContextHubService(JNIEnv* env);
999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_media_AudioRecord(JNIEnv *env);
1019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_media_AudioSystem(JNIEnv *env);
1029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_media_AudioTrack(JNIEnv *env);
1039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_media_JetPlayer(JNIEnv *env);
1049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_media_ToneGenerator(JNIEnv *env);
1059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectnamespace android {
1079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
1099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * JNI-based registration functions.  Note these are properly contained in
1109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * namespace android.
1119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
1126235a94ffaed1d82cee2317481c18776f601da1bMichal Karpinskiextern int register_android_app_admin_SecurityLog(JNIEnv* env);
1139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_content_AssetManager(JNIEnv* env);
1149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_util_EventLog(JNIEnv* env);
1159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_util_Log(JNIEnv* env);
11653a441ca8eda5a3e6209a952b1bbd32a39e19a1cSvet Ganovextern int register_android_util_MemoryIntArray(JNIEnv* env);
117cdd23f9d45ea2974c3f295754b89f5462bdd2c0dDoris Liuextern int register_android_util_PathParser(JNIEnv* env);
1189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_content_StringBlock(JNIEnv* env);
1199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_content_XmlBlock(JNIEnv* env);
1209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Canvas(JNIEnv* env);
12152244fff29042926e21fa897ef5ab11148e35299John Reckextern int register_android_graphics_CanvasProperty(JNIEnv* env);
1229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_ColorFilter(JNIEnv* env);
1239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_DrawFilter(JNIEnv* env);
1241a73f732f91e97c9c66b808c245ddda36a10e987Raph Levienextern int register_android_graphics_FontFamily(JNIEnv* env);
1254c9355c35a0f62805739823a62ad41ca1cbc6502Mike Reedextern int register_android_graphics_LayerRasterizer(JNIEnv*);
1269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Matrix(JNIEnv* env);
1279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Paint(JNIEnv* env);
1289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Path(JNIEnv* env);
1299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_PathMeasure(JNIEnv* env);
1309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Picture(JNIEnv*);
1319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_PorterDuff(JNIEnv* env);
1329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Rasterizer(JNIEnv* env);
133fbf097732137a32930d151f7ba6816a5b870c32aJeff Brownextern int register_android_graphics_Region(JNIEnv* env);
134aa0ce3396c096c97e3394c53e3912cb08b66fe20Jamie Gennisextern int register_android_graphics_SurfaceTexture(JNIEnv* env);
1359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_graphics_Xfermode(JNIEnv* env);
136766431aa57c16ece8842287a92b2e7208e3b8ac3Doris Liuextern int register_android_graphics_drawable_AnimatedVectorDrawable(JNIEnv* env);
1374bbc2931263b232fba61807fca00e127573eff42Doris Liuextern int register_android_graphics_drawable_VectorDrawable(JNIEnv* env);
1386811f4e92cbb64e72a0d13eb9b99b5894bd59c76Svetoslavextern int register_android_graphics_pdf_PdfDocument(JNIEnv* env);
13962ce332c141cf7bc7200c4c87d63e395874fc3ecSvetoslavextern int register_android_graphics_pdf_PdfEditor(JNIEnv* env);
1402961769ea94f69c191a2dd785b2504666c7292d0Svetoslavextern int register_android_graphics_pdf_PdfRenderer(JNIEnv* env);
1410a0a1248cfc03940174cbd9af677bafd7280a3bcJeff Brownextern int register_android_view_DisplayEventReceiver(JNIEnv* env);
142c9070ebd13263a341511cf779087a46750021196Chris Craikextern int register_android_view_DisplayListCanvas(JNIEnv* env);
1433b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guyextern int register_android_view_GraphicBuffer(JNIEnv* env);
14404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reckextern int register_android_view_HardwareLayer(JNIEnv* env);
145c9070ebd13263a341511cf779087a46750021196Chris Craikextern int register_android_view_RenderNode(JNIEnv* env);
146c9070ebd13263a341511cf779087a46750021196Chris Craikextern int register_android_view_RenderNodeAnimator(JNIEnv* env);
1479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_view_Surface(JNIEnv* env);
1483866f0d581ceaa165710feeee9f37fe1b0d7067dMathias Agopianextern int register_android_view_SurfaceControl(JNIEnv* env);
14964a55af0ac700baecb0877235eb42caac59a3560Jeff Brownextern int register_android_view_SurfaceSession(JNIEnv* env);
1508f0095cd33558e9cc8a440047908e53b68906f5fRomain Guyextern int register_android_view_TextureView(JNIEnv* env);
151c9070ebd13263a341511cf779087a46750021196Chris Craikextern int register_android_view_ThreadedRenderer(JNIEnv* env);
152315c329544d7c593d1072b071cbb92d9afe74021John Reckextern int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv *env);
1539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_database_CursorWindow(JNIEnv* env);
154e5360fbf3efe85427f7e7f59afe7bbeddb4949acJeff Brownextern int register_android_database_SQLiteConnection(JNIEnv* env);
155e5360fbf3efe85427f7e7f59afe7bbeddb4949acJeff Brownextern int register_android_database_SQLiteGlobal(JNIEnv* env);
1569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_database_SQLiteDebug(JNIEnv* env);
1579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_nio_utils(JNIEnv* env);
1589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_os_Debug(JNIEnv* env);
159fa9e7c05c7be6891a6cf85a11dc635a6e6853078Christopher Tateextern int register_android_os_MessageQueue(JNIEnv* env);
160d84e1ce0b535128f03416145554fb405f9fade3eJeff Sharkeyextern int register_android_os_Parcel(JNIEnv* env);
161c07fca3831baf4d812dd724f506b4ed23dcc39e0Stephen Smalleyextern int register_android_os_SELinux(JNIEnv* env);
1629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_os_SystemProperties(JNIEnv *env);
1639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_os_SystemClock(JNIEnv* env);
164481c1570dc5cdf58265b53f657801709dd05d1dfJeff Brownextern int register_android_os_Trace(JNIEnv* env);
1659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_os_FileObserver(JNIEnv *env);
1669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_os_UEventObserver(JNIEnv* env);
1679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_os_MemoryFile(JNIEnv* env);
1689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_net_LocalSocketImpl(JNIEnv* env);
1699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_net_NetworkUtils(JNIEnv* env);
1702b4abcd0c7c4361af8ab6d5d7b073fb75ac6d219Dan Egnorextern int register_android_net_TrafficStats(JNIEnv* env);
1719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_text_AndroidCharacter(JNIEnv *env);
17288b5b0be887fc5dc3b0b879b4179dde200d2e4d6Anish Athalyeextern int register_android_text_StaticLayout(JNIEnv *env);
173dae8e94cce0881f3e10ef5e34b881f512bb52a75Doug Feltextern int register_android_text_AndroidBidi(JNIEnv *env);
1749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_opengl_classes(JNIEnv *env);
1759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectextern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
17629564cd24589867f653cd22cabbaac6493cfc530Narayan Kamathextern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env);
1771cf587496fcb1d652bab9fc6792fb106b6fefaa4Joe Onoratoextern int register_android_backup_BackupDataInput(JNIEnv *env);
178d2110dbce071a236b6176de344ca797b737542ebJoe Onoratoextern int register_android_backup_BackupDataOutput(JNIEnv *env);
17906290a4bb9b280fa14a2bbeb2d3ceb09396a78c3Joe Onoratoextern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
1804ababd922eac5931e0222862ff082dc29e012816Joe Onoratoextern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
1814a627c71ff53a4fca1f961f4b1dcc0461df18a06Christopher Tateextern int register_android_app_backup_FullBackup(JNIEnv *env);
1824449ef5b6a85ef4e16dbd5d939db7b11eac0b586Dimitry Ivanovextern int register_android_app_Activity(JNIEnv *env);
1839c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haaseextern int register_android_app_ActivityThread(JNIEnv *env);
1840997908c95151ce24609c10731990e648156b95dDimitry Ivanovextern int register_android_app_ApplicationLoaders(JNIEnv *env);
18569969e48f2bca9339662dddfacff0bbf6374ed7fDianne Hackbornextern int register_android_app_NativeActivity(JNIEnv *env);
186cbad976b2a36a0895ca94510d5208a86f66cf596Jeff Brownextern int register_android_media_RemoteDisplay(JNIEnv *env);
1878a7c1606d88873c5a1b5764c16cb046b6f2275b2Przemyslaw Szczepaniakextern int register_android_util_jar_StrictJarFile(JNIEnv* env);
18846b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brownextern int register_android_view_InputChannel(JNIEnv* env);
1899f25b7fdf216c9ef0bd2322cd223eeaf0d60f77fJeff Brownextern int register_android_view_InputDevice(JNIEnv* env);
19032cbc3855c2a971aa5a801fd339fb6a37db91a1aJeff Brownextern int register_android_view_InputEventReceiver(JNIEnv* env);
191c28867a1d67121ce5963de135e3ae2b1dbd9a33dJeff Brownextern int register_android_view_InputEventSender(JNIEnv* env);
192a44dd26a75e24cc021802288fb81f4761e47be6bMichael Wrightextern int register_android_view_InputQueue(JNIEnv* env);
1939f25b7fdf216c9ef0bd2322cd223eeaf0d60f77fJeff Brownextern int register_android_view_KeyCharacterMap(JNIEnv *env);
19446b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brownextern int register_android_view_KeyEvent(JNIEnv* env);
19546b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brownextern int register_android_view_MotionEvent(JNIEnv* env);
1962352b978a3c94cd88f41d0d908f961333fdac1e9Jeff Brownextern int register_android_view_PointerIcon(JNIEnv* env);
1972ed2462aa29c564f5231f317c27b3188da875e52Jeff Brownextern int register_android_view_VelocityTracker(JNIEnv* env);
19802c8730c1bf19daf48bec8c6995df676a00a73b1Kenny Rootextern int register_android_content_res_ObbScanner(JNIEnv* env);
19908d5b8fad8d46ccb64db2fdcb4d66972ec87bf48Dianne Hackbornextern int register_android_content_res_Configuration(JNIEnv* env);
2006e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haaseextern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
20166269ea6f68f2f25888ce1080c94ac782742fafcKenny Rootextern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
2029a2c2a6da90abbcc9a064c20e93ed885651f4ae1Jeff Sharkeyextern int register_com_android_internal_net_NetworkStatsFactory(JNIEnv *env);
203b1ef62bb3834af6bdf8017e56b2cc614a566229eDimitry Ivanovextern int register_com_android_internal_os_PathClassLoaderFactory(JNIEnv* env);
204973b4663b0b5ee62006522bf4742af076096e548Narayan Kamathextern int register_com_android_internal_os_Zygote(JNIEnv *env);
2059fa4071c4768c63902c6a74a4b480b51a8b95d43John Reckextern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env);
2069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic AndroidRuntime* gCurRuntime = NULL;
2089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
2109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Code written in the Java Programming Language calls here from main().
2119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
21216f5f5cc9d4c480fac3dc7f176f3f1edfbd256f4Jeff Brownstatic void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz)
2139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
2149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    gCurRuntime->onStarted();
2159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
2169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
21716f5f5cc9d4c480fac3dc7f176f3f1edfbd256f4Jeff Brownstatic void com_android_internal_os_RuntimeInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
2189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
2199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    gCurRuntime->onZygoteInit();
2209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
2219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2224280c4a93ea17f2e9d3f651e49d8c13dc3fb92aaJeff Brownstatic void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIEnv* env,
2234280c4a93ea17f2e9d3f651e49d8c13dc3fb92aaJeff Brown        jobject clazz, jboolean exitWithoutCleanup)
2244280c4a93ea17f2e9d3f651e49d8c13dc3fb92aaJeff Brown{
2254280c4a93ea17f2e9d3f651e49d8c13dc3fb92aaJeff Brown    gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup);
2264280c4a93ea17f2e9d3f651e49d8c13dc3fb92aaJeff Brown}
2274280c4a93ea17f2e9d3f651e49d8c13dc3fb92aaJeff Brown
2289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
2299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * JNI registration.
2309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
23176f6a86de25e1bf74717e047e55fd44b089673f3Daniel Micaystatic const JNINativeMethod gMethods[] = {
23216f5f5cc9d4c480fac3dc7f176f3f1edfbd256f4Jeff Brown    { "nativeFinishInit", "()V",
23316f5f5cc9d4c480fac3dc7f176f3f1edfbd256f4Jeff Brown        (void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
23416f5f5cc9d4c480fac3dc7f176f3f1edfbd256f4Jeff Brown    { "nativeZygoteInit", "()V",
23516f5f5cc9d4c480fac3dc7f176f3f1edfbd256f4Jeff Brown        (void*) com_android_internal_os_RuntimeInit_nativeZygoteInit },
2364280c4a93ea17f2e9d3f651e49d8c13dc3fb92aaJeff Brown    { "nativeSetExitWithoutCleanup", "(Z)V",
2374280c4a93ea17f2e9d3f651e49d8c13dc3fb92aaJeff Brown        (void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
2389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project};
2399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectint register_com_android_internal_os_RuntimeInit(JNIEnv* env)
2419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
2429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
2439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        gMethods, NELEM(gMethods));
2449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
2459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project// ----------------------------------------------------------------------
2479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2489ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
2499ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber
250a23fcd7be8e40078a913b1a99222cdd89229e67bNarayan KamathAndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) :
251a23fcd7be8e40078a913b1a99222cdd89229e67bNarayan Kamath        mExitWithoutCleanup(false),
252a23fcd7be8e40078a913b1a99222cdd89229e67bNarayan Kamath        mArgBlockStart(argBlockStart),
253a23fcd7be8e40078a913b1a99222cdd89229e67bNarayan Kamath        mArgBlockLength(argBlockLength)
2549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
255c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project    SkGraphics::Init();
256177612335aa5df21d8c21125608413d02289a6b3Ben Wagner    // There is also a global font cache, but its budget is specified by
257177612335aa5df21d8c21125608413d02289a6b3Ben Wagner    // SK_DEFAULT_FONT_CACHE_COUNT_LIMIT and SK_DEFAULT_FONT_CACHE_LIMIT.
2589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    // Pre-allocate enough space to hold a fair number of options.
2609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    mOptions.setCapacity(20);
2619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    assert(gCurRuntime == NULL);        // one per process
2639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    gCurRuntime = this;
2649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
2659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source ProjectAndroidRuntime::~AndroidRuntime()
2679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
2689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    SkGraphics::Term();
2699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
2709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2719ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber/*
2729ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber * Register native methods using JNI.
2739ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber */
2749ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
2759ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber    const char* className, const JNINativeMethod* gMethods, int numMethods)
2769ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber{
2779ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber    return jniRegisterNativeMethods(env, className, gMethods, numMethods);
2789ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber}
2799ae000ca8c05ad6f700ad7bf119bbc92fb964b57Andreas Huber
280a23fcd7be8e40078a913b1a99222cdd89229e67bNarayan Kamathvoid AndroidRuntime::setArgv0(const char* argv0) {
28100c0cd4a24bd0f040055f9e786e2df1fa3b7d2d3Jeff Brown    memset(mArgBlockStart, 0, mArgBlockLength);
282a23fcd7be8e40078a913b1a99222cdd89229e67bNarayan Kamath    strlcpy(mArgBlockStart, argv0, mArgBlockLength);
283a23fcd7be8e40078a913b1a99222cdd89229e67bNarayan Kamath}
284a23fcd7be8e40078a913b1a99222cdd89229e67bNarayan Kamath
28522ec1eefa4dc8e12f7da8e8750d4770144941526Narayan Kamathstatus_t AndroidRuntime::callMain(const String8& className, jclass clazz,
28622ec1eefa4dc8e12f7da8e8750d4770144941526Narayan Kamath    const Vector<String8>& args)
2879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
2889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    JNIEnv* env;
2899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    jmethodID methodId;
2909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
29122ec1eefa4dc8e12f7da8e8750d4770144941526Narayan Kamath    ALOGD("Calling main entry %s", className.string());
29208e60f2a165d23b53f41993374aa074165bb5863Dianne Hackborn
2939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    env = getJNIEnv();
294d195e5ab401432ddac659791640a2927fc668699Elliott Hughes    if (clazz == NULL || env == NULL) {
2959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return UNKNOWN_ERROR;
2969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
2999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (methodId == NULL) {
30022ec1eefa4dc8e12f7da8e8750d4770144941526Narayan Kamath        ALOGE("ERROR: could not find method %s.main(String[])\n", className.string());
3019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return UNKNOWN_ERROR;
3029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /*
3059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * We want to call main() with a String array with our arguments in it.
3069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Create an array and populate it.
3079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    jclass stringClass;
3099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    jobjectArray strArray;
3109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
31122ec1eefa4dc8e12f7da8e8750d4770144941526Narayan Kamath    const size_t numArgs = args.size();
3129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    stringClass = env->FindClass("java/lang/String");
31322ec1eefa4dc8e12f7da8e8750d4770144941526Narayan Kamath    strArray = env->NewObjectArray(numArgs, stringClass, NULL);
3149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
31522ec1eefa4dc8e12f7da8e8750d4770144941526Narayan Kamath    for (size_t i = 0; i < numArgs; i++) {
31622ec1eefa4dc8e12f7da8e8750d4770144941526Narayan Kamath        jstring argStr = env->NewStringUTF(args[i].string());
3179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        env->SetObjectArrayElement(strArray, i, argStr);
3189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    env->CallStaticVoidMethod(clazz, methodId, strArray);
3219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return NO_ERROR;
3229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
3239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
3259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * The VM calls this through the "exit" hook.
3269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
3279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic void runtime_exit(int code)
3289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
3294280c4a93ea17f2e9d3f651e49d8c13dc3fb92aaJeff Brown    gCurRuntime->exit(code);
3309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
3319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
3339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * The VM calls this through the "vfprintf" hook.
3349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
3359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * We ignore "fp" and just write the results to the log file.
3369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
3379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
3389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
3399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
3409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
3419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3420bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick/**
3430bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick * The VM calls this when mutex contention debugging is enabled to
3440bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick * determine whether or not the blocked thread was a "sensitive thread"
3450bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick * for user responsiveness/smoothess.
3460bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick *
3470bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick * Our policy for this is whether or not we're tracing any StrictMode
3480bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick * events on this thread (which we might've inherited via Binder calls
3490bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick * into us)
3500bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick */
3510bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrickstatic bool runtime_isSensitiveThread() {
3520bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick    IPCThreadState* state = IPCThreadState::selfOrNull();
3530bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick    return state && state->getStrictModePolicy() != 0;
3540bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick}
3550bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick
3569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic int hasDir(const char* dir)
3579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
3589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    struct stat s;
3599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    int res = stat(dir, &s);
3609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (res == 0) {
3619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return S_ISDIR(s.st_mode);
3629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    return 0;
3649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
3659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
366995c62d6abd4b7080e52a60d1bffa32ae4a798a3Andreas Gampestatic bool hasFile(const char* file) {
367995c62d6abd4b7080e52a60d1bffa32ae4a798a3Andreas Gampe    struct stat s;
368995c62d6abd4b7080e52a60d1bffa32ae4a798a3Andreas Gampe    int res = stat(file, &s);
369995c62d6abd4b7080e52a60d1bffa32ae4a798a3Andreas Gampe    if (res == 0) {
370995c62d6abd4b7080e52a60d1bffa32ae4a798a3Andreas Gampe        return S_ISREG(s.st_mode);
371995c62d6abd4b7080e52a60d1bffa32ae4a798a3Andreas Gampe    }
372995c62d6abd4b7080e52a60d1bffa32ae4a798a3Andreas Gampe    return false;
373995c62d6abd4b7080e52a60d1bffa32ae4a798a3Andreas Gampe}
374995c62d6abd4b7080e52a60d1bffa32ae4a798a3Andreas Gampe
375bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath// Convenience wrapper over the property API that returns an
376bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath// std::string.
377bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamathstd::string getProperty(const char* key, const char* defaultValue) {
378bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    std::vector<char> temp(PROPERTY_VALUE_MAX);
379bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    const int len = property_get(key, &temp[0], defaultValue);
380bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    if (len < 0) {
381bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath        return "";
382bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    }
383bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    return std::string(&temp[0], len);
384bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath}
385bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath
3869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
387bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * Read the persistent locale. Inspects the following system properties
388bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * (in order) and returns the first non-empty property in the list :
389bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath *
390bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * (1) persist.sys.locale
391bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * (2) persist.sys.language/country/localevar (country and localevar are
392bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * inspected iff. language is non-empty.
393bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * (3) ro.product.locale
394bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * (4) ro.product.locale.language/region
395bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath *
396bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * Note that we need to inspect persist.sys.language/country/localevar to
397bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * preserve language settings for devices that are upgrading from Lollipop
398bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath * to M. The same goes for ro.product.locale.language/region as well.
3999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
400bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamathconst std::string readLocale()
4019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
402bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    const std::string locale = getProperty("persist.sys.locale", "");
403bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    if (!locale.empty()) {
404bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath        return locale;
405bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    }
406bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath
407bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    const std::string language = getProperty("persist.sys.language", "");
408bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    if (!language.empty()) {
409bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath        const std::string country = getProperty("persist.sys.country", "");
410bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath        const std::string variant = getProperty("persist.sys.localevar", "");
411bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath
412bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath        std::string out = language;
413bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath        if (!country.empty()) {
414bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath            out = out + "-" + country;
415bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath        }
416bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath
417bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath        if (!variant.empty()) {
418bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath            out = out + "-" + variant;
419d30dbb8ae12e6e83e3035f12dd291f92e1f22c18Narayan Kamath        }
420bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath
421bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath        return out;
4229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
423d30dbb8ae12e6e83e3035f12dd291f92e1f22c18Narayan Kamath
424bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    const std::string productLocale = getProperty("ro.product.locale", "");
425bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    if (!productLocale.empty()) {
426bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath        return productLocale;
427bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    }
428bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath
429bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    // If persist.sys.locale and ro.product.locale are missing,
430bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    // construct a locale value from the individual locale components.
431bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    const std::string productLanguage = getProperty("ro.product.locale.language", "en");
432bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    const std::string productRegion = getProperty("ro.product.locale.region", "US");
433bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath
434bf88205bef88f78ade5c6830e6203aa343387820Narayan Kamath    return productLanguage + "-" + productRegion;
4359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
4369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4370d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstromvoid AndroidRuntime::addOption(const char* optionString, void* extraInfo)
4380d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom{
4390d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    JavaVMOption opt;
4400d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    opt.optionString = optionString;
4410d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    opt.extraInfo = extraInfo;
4420d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    mOptions.add(opt);
4430d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom}
4440d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom
445f70188aa4716625781d9952c6b883180528d4644Andy McFadden/*
446e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden * Parse a property containing space-separated options that should be
447e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
448e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden *
449e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden * This will cut up "extraOptsBuf" as we chop it into individual options.
450e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden *
4513beff1e023193b485c67a3003a7f363f105d96d4Brian Carlstrom * If "quotingArg" is non-null, it is passed before each extra option in mOptions.
4523beff1e023193b485c67a3003a7f363f105d96d4Brian Carlstrom *
453e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden * Adds the strings, if any, to mOptions.
454e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden */
4553beff1e023193b485c67a3003a7f363f105d96d4Brian Carlstromvoid AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg)
456e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden{
4573beff1e023193b485c67a3003a7f363f105d96d4Brian Carlstrom    char* start = extraOptsBuf;
4583beff1e023193b485c67a3003a7f363f105d96d4Brian Carlstrom    char* end = NULL;
459e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden    while (*start != '\0') {
460e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden        while (*start == ' ')                   /* skip leading whitespace */
461e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden            start++;
462e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden        if (*start == '\0')                     /* was trailing ws, bail */
463e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden            break;
464e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden
465e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden        end = start+1;
466e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden        while (*end != ' ' && *end != '\0')     /* find end of token */
467e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden            end++;
468e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden        if (*end == ' ')
469e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden            *end++ = '\0';          /* mark end, advance to indicate more */
470e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden
4713beff1e023193b485c67a3003a7f363f105d96d4Brian Carlstrom        if (quotingArg != NULL) {
4720d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom            addOption(quotingArg);
4733beff1e023193b485c67a3003a7f363f105d96d4Brian Carlstrom        }
4740d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom        addOption(start);
475e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden        start = end;
476e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden    }
477e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden}
478e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden
479e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden/*
4806d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * Reads a "property" into "buffer" with a default of "defaultArg". If
4816d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * the property is non-empty, it is treated as a runtime option such
4826d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * as "-Xmx32m".
4836d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom *
4846d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
4856d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom *
4866d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * If an argument is found, it is added to mOptions.
4876d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom *
4886d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * If an option is found, it is added to mOptions and true is
4896d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * returned. Otherwise false is returned.
4906d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom */
4916d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrombool AndroidRuntime::parseRuntimeOption(const char* property,
4926d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom                                        char* buffer,
4936d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom                                        const char* runtimeArg,
4946d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom                                        const char* defaultArg)
4956d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom{
4966d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    strcpy(buffer, runtimeArg);
4976d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    size_t runtimeArgLen = strlen(runtimeArg);
4986d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    property_get(property, buffer+runtimeArgLen, defaultArg);
4996d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    if (buffer[runtimeArgLen] == '\0') {
5006d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom        return false;
5016d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    }
5020d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption(buffer);
5036d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    return true;
5046d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom}
5056d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom
5066d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom/*
5076d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * Reads a "property" into "buffer". If the property is non-empty, it
5083fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom * is treated as a dex2oat compiler option that should be
5093fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom * passed as a quoted option, e.g. "-Ximage-compiler-option --compiler-filter=verify-none".
5103fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom *
5113fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom * The "compilerArg" is a prefix for the option such as "--compiler-filter=".
5123fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom *
5133fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
5143fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom *
5153fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom * If an option is found, it is added to mOptions and true is
5163fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom * returned. Otherwise false is returned.
5173fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom */
5183fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrombool AndroidRuntime::parseCompilerOption(const char* property,
5193fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom                                         char* buffer,
5203fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom                                         const char* compilerArg,
5213fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom                                         const char* quotingArg)
5223fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom{
5233fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom    strcpy(buffer, compilerArg);
5243fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom    size_t compilerArgLen = strlen(compilerArg);
5253fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom    property_get(property, buffer+compilerArgLen, "");
5263fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom    if (buffer[compilerArgLen] == '\0') {
5273fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom        return false;
5283fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom    }
5290d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption(quotingArg);
5300d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption(buffer);
5313fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom    return true;
5323fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom}
5333fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom
5343fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom/*
5353fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom * Reads a "property" into "buffer". If the property is non-empty, it
5366d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * is treated as a dex2oat compiler runtime option that should be
5376d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * passed as a quoted option, e.g. "-Ximage-compiler-option
5386d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * --runtime-arg -Ximage-compiler-option -Xmx32m".
5396d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom *
5406d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
5416d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom *
5426d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
5436d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom *
5446d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * If an option is found, it is added to mOptions and true is
5456d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom * returned. Otherwise false is returned.
5466d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom */
5476d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrombool AndroidRuntime::parseCompilerRuntimeOption(const char* property,
5486d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom                                                char* buffer,
5496d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom                                                const char* runtimeArg,
5506d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom                                                const char* quotingArg)
5516d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom{
5526d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    strcpy(buffer, runtimeArg);
5536d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    size_t runtimeArgLen = strlen(runtimeArg);
5546d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    property_get(property, buffer+runtimeArgLen, "");
5556d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    if (buffer[runtimeArgLen] == '\0') {
5566d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom        return false;
5576d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    }
5580d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption(quotingArg);
5590d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption("--runtime-arg");
5600d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption(quotingArg);
5610d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption(buffer);
5626d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    return true;
5636d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom}
5646d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom
5656d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom/*
566f70188aa4716625781d9952c6b883180528d4644Andy McFadden * Start the Dalvik Virtual Machine.
567f70188aa4716625781d9952c6b883180528d4644Andy McFadden *
568f70188aa4716625781d9952c6b883180528d4644Andy McFadden * Various arguments, most determined by system properties, are passed in.
569f70188aa4716625781d9952c6b883180528d4644Andy McFadden * The "mOptions" vector is updated.
570f70188aa4716625781d9952c6b883180528d4644Andy McFadden *
57107a1e2323b1e6765f220a045bd05783dd99b2914Dave Allison * CAUTION: when adding options in here, be careful not to put the
57207a1e2323b1e6765f220a045bd05783dd99b2914Dave Allison * char buffer inside a nested scope.  Adding the buffer to the
57307a1e2323b1e6765f220a045bd05783dd99b2914Dave Allison * options using mOptions.add() does not copy the buffer, so if the
57407a1e2323b1e6765f220a045bd05783dd99b2914Dave Allison * buffer goes out of scope the option may be overwritten.  It's best
57507a1e2323b1e6765f220a045bd05783dd99b2914Dave Allison * to put the buffer at the top of the function so that it is more
57607a1e2323b1e6765f220a045bd05783dd99b2914Dave Allison * unlikely that someone will surround it in a scope at a later time
57707a1e2323b1e6765f220a045bd05783dd99b2914Dave Allison * and thus introduce a bug.
57807a1e2323b1e6765f220a045bd05783dd99b2914Dave Allison *
579f70188aa4716625781d9952c6b883180528d4644Andy McFadden * Returns 0 on success.
580f70188aa4716625781d9952c6b883180528d4644Andy McFadden */
5817a09b8322cab26d6e3da1362d3c74964ae66b5d4Sebastien Hertzint AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote)
5829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
5839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    JavaVMInitArgs initArgs;
5849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    char propBuf[PROPERTY_VALUE_MAX];
5856d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    char stackTraceFileBuf[sizeof("-Xstacktracefile:")-1 + PROPERTY_VALUE_MAX];
5869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
58738cfa8ca8bc67f4342431cea7e35643ddf9254ccCarl Shapiro    char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
588bdcef70e15e86e592d725355c96c7fab0b85ac83Dianne Hackborn    char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
5898cdf27c36a5b697396144925b3f61e4802dd3558Carl Shapiro    char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
5905325010486a13553a8597aab92f90abc141a25e8Ian Rogers    char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
5915325010486a13553a8597aab92f90abc141a25e8Ian Rogers    char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
5926909c0e1e7bbf6e8050330244bbe47bff9587225Mathieu Chartier    char usejitOptsBuf[sizeof("-Xusejit:")-1 + PROPERTY_VALUE_MAX];
593cdf1dfff8f850da7b1ae3a34b78de7313064f5e0Nicolas Geoffray    char jitmaxsizeOptsBuf[sizeof("-Xjitmaxsize:")-1 + PROPERTY_VALUE_MAX];
594cdf1dfff8f850da7b1ae3a34b78de7313064f5e0Nicolas Geoffray    char jitinitialsizeOptsBuf[sizeof("-Xjitinitialsize:")-1 + PROPERTY_VALUE_MAX];
5956909c0e1e7bbf6e8050330244bbe47bff9587225Mathieu Chartier    char jitthresholdOptsBuf[sizeof("-Xjitthreshold:")-1 + PROPERTY_VALUE_MAX];
596db4a79a5d7d348e9d2286d95d4e5a59dd484456fCalin Juravle    char useJitProfilesOptsBuf[sizeof("-Xjitsaveprofilinginfo:")-1 + PROPERTY_VALUE_MAX];
597aa9ecac10b90af84ab8cb9fb40f42df3460a4eb3Calin Juravle    char jitprithreadweightOptBuf[sizeof("-Xjitprithreadweight:")-1 + PROPERTY_VALUE_MAX];
5988d74de55464c885b602b34252ee8721a9e810dcfCalin Juravle    char jittransitionweightOptBuf[sizeof("-Xjittransitionweight:")-1 + PROPERTY_VALUE_MAX];
5997e4fdec6f0ac6385c5f8aeaf0f2e12e162138ac3Mathieu Chartier    char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
600c01936a686ff75c872629b219898021e8ae49afaMathieu Chartier    char backgroundgcOptsBuf[sizeof("-XX:BackgroundGC=")-1 + PROPERTY_VALUE_MAX];
6015325010486a13553a8597aab92f90abc141a25e8Ian Rogers    char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
602e324ba0e7cc1b831f86c5d2f0578c9b881a3130bAndreas Gampe    char cachePruneBuf[sizeof("-Xzygote-max-boot-retry=")-1 + PROPERTY_VALUE_MAX];
6036d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    char dex2oatXmsImageFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
6046d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    char dex2oatXmxImageFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
6056d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    char dex2oatXmsFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
6066d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    char dex2oatXmxFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
6073fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom    char dex2oatCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
6083fbfbb4adeec1dda1e149758ea302c386101f267Brian Carlstrom    char dex2oatImageCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
609e0352388238875ef7e7b31d914fc903b08ff0f6bAndreas Gampe    char dex2oatThreadsBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
610e0352388238875ef7e7b31d914fc903b08ff0f6bAndreas Gampe    char dex2oatThreadsImageBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
611605cca1a985be74c00582853ee2c84b086cfade8Andreas Gampe    char dex2oat_isa_variant_key[PROPERTY_KEY_MAX];
612605cca1a985be74c00582853ee2c84b086cfade8Andreas Gampe    char dex2oat_isa_variant[sizeof("--instruction-set-variant=") -1 + PROPERTY_VALUE_MAX];
613605cca1a985be74c00582853ee2c84b086cfade8Andreas Gampe    char dex2oat_isa_features_key[PROPERTY_KEY_MAX];
614605cca1a985be74c00582853ee2c84b086cfade8Andreas Gampe    char dex2oat_isa_features[sizeof("--instruction-set-features=") -1 + PROPERTY_VALUE_MAX];
6153beff1e023193b485c67a3003a7f363f105d96d4Brian Carlstrom    char dex2oatFlagsBuf[PROPERTY_VALUE_MAX];
6163beff1e023193b485c67a3003a7f363f105d96d4Brian Carlstrom    char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX];
617e4d81f25bd4dc1a5c909b56ab56a56406290da30Andy McFadden    char extraOptsBuf[PROPERTY_VALUE_MAX];
6180d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    char voldDecryptBuf[PROPERTY_VALUE_MAX];
61952b0e73443ff8da195fbf0df851a028e07a691b2Ben Cheng    enum {
62052b0e73443ff8da195fbf0df851a028e07a691b2Ben Cheng      kEMDefault,
62152b0e73443ff8da195fbf0df851a028e07a691b2Ben Cheng      kEMIntPortable,
62252b0e73443ff8da195fbf0df851a028e07a691b2Ben Cheng      kEMIntFast,
62352b0e73443ff8da195fbf0df851a028e07a691b2Ben Cheng      kEMJitCompiler,
62452b0e73443ff8da195fbf0df851a028e07a691b2Ben Cheng    } executionMode = kEMDefault;
625d30dbb8ae12e6e83e3035f12dd291f92e1f22c18Narayan Kamath    char localeOption[sizeof("-Duser.locale=") + PROPERTY_VALUE_MAX];
6266d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX];
62701db916970ece2382ebf9e06873a14aee9543a9dCalin Juravle    char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX];
628ff193d642eea7128faad837d19e347cd25212c27Dmitriy Ivanov    char cpuAbiListBuf[sizeof("--cpu-abilist=") + PROPERTY_VALUE_MAX];
62998f406f6f31660d0f5ee32113ffadc720b426dc6Andreas Gampe    char methodTraceFileBuf[sizeof("-Xmethod-trace-file:") + PROPERTY_VALUE_MAX];
63098f406f6f31660d0f5ee32113ffadc720b426dc6Andreas Gampe    char methodTraceFileSizeBuf[sizeof("-Xmethod-trace-file-size:") + PROPERTY_VALUE_MAX];
631e60825033fdde9eefaeec768a28b907e2d22f10cAndreas Gampe    char fingerprintBuf[sizeof("-Xfingerprint:") + PROPERTY_VALUE_MAX];
6329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6336d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    bool checkJni = false;
6349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    property_get("dalvik.vm.checkjni", propBuf, "");
6359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (strcmp(propBuf, "true") == 0) {
6369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkJni = true;
6379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    } else if (strcmp(propBuf, "false") != 0) {
6389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /* property is neither true nor false; fall back on kernel parameter */
6399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        property_get("ro.kernel.android.checkjni", propBuf, "");
6409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (propBuf[0] == '1') {
6419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            checkJni = true;
6429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
6439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6446d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    ALOGD("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
6456d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    if (checkJni) {
6466d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom        /* extended JNI checking */
6470d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom        addOption("-Xcheck:jni");
6486d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom
6496d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom        /* with -Xcheck:jni, this provides a JNI function call trace */
6500d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom        //addOption("-verbose:jni");
6516d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    }
6529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    property_get("dalvik.vm.execution-mode", propBuf, "");
6549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (strcmp(propBuf, "int:portable") == 0) {
6559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        executionMode = kEMIntPortable;
6569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    } else if (strcmp(propBuf, "int:fast") == 0) {
6579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        executionMode = kEMIntFast;
65852b0e73443ff8da195fbf0df851a028e07a691b2Ben Cheng    } else if (strcmp(propBuf, "int:jit") == 0) {
65952b0e73443ff8da195fbf0df851a028e07a691b2Ben Cheng        executionMode = kEMJitCompiler;
6609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6626d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    parseRuntimeOption("dalvik.vm.stack-trace-file", stackTraceFileBuf, "-Xstacktracefile:");
6639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    strcpy(jniOptsBuf, "-Xjniopts:");
6656d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    if (parseRuntimeOption("dalvik.vm.jniopts", jniOptsBuf, "-Xjniopts:")) {
6666d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom        ALOGI("JNI options: '%s'\n", jniOptsBuf);
6676d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    }
6689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /* route exit() to our handler */
6700d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption("exit", (void*) runtime_exit);
6719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /* route fprintf() to our handler */
6730d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption("vfprintf", (void*) runtime_vfprintf);
6749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6750bd5243b751c9cad317758158f79b3347e7948afBrad Fitzpatrick    /* register the framework-specific "is sensitive thread" hook */
6760d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption("sensitiveThread", (void*) runtime_isSensitiveThread);
6779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /* enable verbose; standard options are { jni, gc, class } */
6790d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    //addOption("-verbose:jni");
6800d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    addOption("-verbose:gc");
6810d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom    //addOption("-verbose:class");
6829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6839e4c884e7a7acd6b75399b180dc339295cda5a43Carl Shapiro    /*
6849e4c884e7a7acd6b75399b180dc339295cda5a43Carl Shapiro     * The default starting and maximum size of the heap.  Larger
6859e4c884e7a7acd6b75399b180dc339295cda5a43Carl Shapiro     * values should be specified in a product property override.
6869e4c884e7a7acd6b75399b180dc339295cda5a43Carl Shapiro     */
6876d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    parseRuntimeOption("dalvik.vm.heapstartsize", heapstartsizeOptsBuf, "-Xms", "4m");
6886d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    parseRuntimeOption("dalvik.vm.heapsize", heapsizeOptsBuf, "-Xmx", "16m");
6899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6906d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    parseRuntimeOption("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
6916d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    parseRuntimeOption("dalvik.vm.heapminfree", heapminfreeOptsBuf, "-XX:HeapMinFree=");
6926d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    parseRuntimeOption("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf, "-XX:HeapMaxFree=");
6936d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    parseRuntimeOption("dalvik.vm.heaptargetutilization",
6946d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom                       heaptargetutilizationOptsBuf,
6956d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom                       "-XX:HeapTargetUtilization=");
6965325010486a13553a8597aab92f90abc141a25e8Ian Rogers
6976909c0e1e7bbf6e8050330244bbe47bff9587225Mathieu Chartier    /*
6986909c0e1e7bbf6e8050330244bbe47bff9587225Mathieu Chartier     * JIT related options.
6996909c0e1e7bbf6e8050330244bbe47bff9587225Mathieu Chartier     */
7001fb7aab9b235fa526a1b8e6e2efd71c7df66096dMathieu Chartier    parseRuntimeOption("dalvik.vm.usejit", usejitOptsBuf, "-Xusejit:");
701cdf1dfff8f850da7b1ae3a34b78de7313064f5e0Nicolas Geoffray    parseRuntimeOption("dalvik.vm.jitmaxsize", jitmaxsizeOptsBuf, "-Xjitmaxsize:");
702cdf1dfff8f850da7b1ae3a34b78de7313064f5e0Nicolas Geoffray    parseRuntimeOption("dalvik.vm.jitinitialsize", jitinitialsizeOptsBuf, "-Xjitinitialsize:");
7031fb7aab9b235fa526a1b8e6e2efd71c7df66096dMathieu Chartier    parseRuntimeOption("dalvik.vm.jitthreshold", jitthresholdOptsBuf, "-Xjitthreshold:");
704db4a79a5d7d348e9d2286d95d4e5a59dd484456fCalin Juravle    property_get("dalvik.vm.usejitprofiles", useJitProfilesOptsBuf, "");
705db4a79a5d7d348e9d2286d95d4e5a59dd484456fCalin Juravle    if (strcmp(useJitProfilesOptsBuf, "true") == 0) {
706db4a79a5d7d348e9d2286d95d4e5a59dd484456fCalin Juravle        addOption("-Xjitsaveprofilinginfo");
707db4a79a5d7d348e9d2286d95d4e5a59dd484456fCalin Juravle    }
7088d74de55464c885b602b34252ee8721a9e810dcfCalin Juravle
709aa9ecac10b90af84ab8cb9fb40f42df3460a4eb3Calin Juravle    parseRuntimeOption("dalvik.vm.jitprithreadweight",
710aa9ecac10b90af84ab8cb9fb40f42df3460a4eb3Calin Juravle                       jitprithreadweightOptBuf,
711aa9ecac10b90af84ab8cb9fb40f42df3460a4eb3Calin Juravle                       "-Xjitprithreadweight:");
7126909c0e1e7bbf6e8050330244bbe47bff9587225Mathieu Chartier
7138d74de55464c885b602b34252ee8721a9e810dcfCalin Juravle    parseRuntimeOption("dalvik.vm.jittransitionweight",
7148d74de55464c885b602b34252ee8721a9e810dcfCalin Juravle                       jittransitionweightOptBuf,
7158d74de55464c885b602b34252ee8721a9e810dcfCalin Juravle                       "-Xjittransitionweight:");
7168d74de55464c885b602b34252ee8721a9e810dcfCalin Juravle
717e6c2241f7a1e6bca3fd8d5d0c49abbbd348366b7Mathieu Chartier    property_get("ro.config.low_ram", propBuf, "");
718e6c2241f7a1e6bca3fd8d5d0c49abbbd348366b7Mathieu Chartier    if (strcmp(propBuf, "true") == 0) {
7190d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom      addOption("-XX:LowMemoryMode");
720e6c2241f7a1e6bca3fd8d5d0c49abbbd348366b7Mathieu Chartier    }
721e6c2241f7a1e6bca3fd8d5d0c49abbbd348366b7Mathieu Chartier
7226d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    parseRuntimeOption("dalvik.vm.gctype", gctypeOptsBuf, "-Xgc:");
7236d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    parseRuntimeOption("dalvik.vm.backgroundgctype", backgroundgcOptsBuf, "-XX:BackgroundGC=");
724c01936a686ff75c872629b219898021e8ae49afaMathieu Chartier
7257a09b8322cab26d6e3da1362d3c74964ae66b5d4Sebastien Hertz    /*
7267a09b8322cab26d6e3da1362d3c74964ae66b5d4Sebastien Hertz     * Enable debugging only for apps forked from zygote.
7277a09b8322cab26d6e3da1362d3c74964ae66b5d4Sebastien Hertz     * Set suspend=y to pause during VM init and use android ADB transport.
7287a09b8322cab26d6e3da1362d3c74964ae66b5d4Sebastien Hertz     */
7297a09b8322cab26d6e3da1362d3c74964ae66b5d4Sebastien Hertz    if (zygote) {
7307a09b8322cab26d6e3da1362d3c74964ae66b5d4Sebastien Hertz      addOption("-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y");
7317a09b8322cab26d6e3da1362d3c74964ae66b5d4Sebastien Hertz    }
7329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7336d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom    parseRuntimeOption("dalvik.vm.lockprof.threshold",
7346d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom                       lockProfThresholdBuf,
7356d77eb99bfc5471f9765e3fa7ea42022197aa9f5Brian Carlstrom                       "-Xlockprofthreshold:");
736d8f3ec6e8308400e9446b254fcca457f6e53ea13Carl Shapiro
7379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    if (executionMode == kEMIntPortable) {
7380d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom        addOption("-Xint:portable");
7399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    } else if (executionMode == kEMIntFast) {
7400d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom        addOption("-Xint:fast");
74152b0e73443ff8da195fbf0df851a028e07a691b2Ben Cheng    } else if (executionMode == kEMJitCompiler) {
7420d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom        addOption("-Xint:jit");
7439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
744e2b23e11a5475e5c35eb07ba883cb05eca18796fAndy McFadden
74508b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    // If we are booting without the real /data, don't spend time compiling.
74608b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    property_get("vold.decrypt", voldDecryptBuf, "");
74708b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    bool skip_compilation = ((strcmp(voldDecryptBuf, "trigger_restart_min_framework") == 0) ||
74808b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe                             (strcmp(voldDecryptBuf, "1") == 0));
74908b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe
75008b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    // Extra options for boot.art/boot.oat image generation.
75108b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xms", dex2oatXmsImageFlagsBuf,
75208b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe                               "-Xms", "-Ximage-compiler-option");
75308b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xmx", dex2oatXmxImageFlagsBuf,
75408b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe                               "-Xmx", "-Ximage-compiler-option");
75508b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    if (skip_compilation) {
756ce5bbbea08e9dca963a208f5199aad699d4a854dBrian Carlstrom        addOption("-Ximage-compiler-option");
75708b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe        addOption("--compiler-filter=verify-none");
75808b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    } else {
75908b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe        parseCompilerOption("dalvik.vm.image-dex2oat-filter", dex2oatImageCompilerFilterBuf,
76008b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe                            "--compiler-filter=", "-Ximage-compiler-option");
76108b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    }
762995c62d6abd4b7080e52a60d1bffa32ae4a798a3Andreas Gampe
76308b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    // Make sure there is a preloaded-classes file.
76408b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    if (!hasFile("/system/etc/preloaded-classes")) {
76508b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe        ALOGE("Missing preloaded-classes file, /system/etc/preloaded-classes not found: %s\n",
76608b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe              strerror(errno));
767ff193d642eea7128faad837d19e347cd25212c27Dmitriy Ivanov        return -1;
76808b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    }
76908b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    addOption("-Ximage-compiler-option");
77008b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    addOption("--image-classes=/system/etc/preloaded-classes");
771ca775941f3b7981aabf3a6a3b84d6c94f4f76affAndreas Gampe
77208b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    // If there is a compiled-classes file, push it.
77308b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    if (hasFile("/system/etc/compiled-classes")) {
77408b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe        addOption("-Ximage-compiler-option");
77508b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe        addOption("--compiled-classes=/system/etc/compiled-classes");
77608b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    }
7770d8fb019633300a6636f1bf99f0716e8579dab35Brian Carlstrom
77808b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    property_get("dalvik.vm.image-dex2oat-flags", dex2oatImageFlagsBuf, "");
77908b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    parseExtraOpts(dex2oatImageFlagsBuf, "-Ximage-compiler-option");
78008b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe
78108b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    // Extra options for DexClassLoader.
78208b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xms", dex2oatXmsFlagsBuf,
78308b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe                               "-Xms", "-Xcompiler-option");
78408b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xmx", dex2oatXmxFlagsBuf,
78508b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe                               "-Xmx", "-Xcompiler-option");
78608b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    if (skip_compilation) {
78708b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe        addOption("-Xcompiler-option");
78808b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe        addOption("--compiler-filter=verify-none");
789155118fee81f2761289438f4c4cd47d740ff8f88neo.chae
790155118fee81f2761289438f4c4cd47d740ff8f88neo.chae        // We skip compilation when a minimal runtime is brought up for decryption. In that case
791155118fee81f2761289438f4c4cd47d740ff8f88neo.chae        // /data is temporarily backed by a tmpfs, which is usually small.
792155118fee81f2761289438f4c4cd47d740ff8f88neo.chae        // If the system image contains prebuilts, they will be relocated into the tmpfs. In this
793155118fee81f2761289438f4c4cd47d740ff8f88neo.chae        // specific situation it is acceptable to *not* relocate and run out of the prebuilts
794155118fee81f2761289438f4c4cd47d740ff8f88neo.chae        // directly instead.
795155118fee81f2761289438f4c4cd47d740ff8f88neo.chae        addOption("--runtime-arg");
796155118fee81f2761289438f4c4cd47d740ff8f88neo.chae        addOption("-Xnorelocate");
79708b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe    } else {
79808b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe        parseCompilerOption("dalvik.vm.dex2oat-filter", dex2oatCompilerFilterBuf,
79908b2d585b11a07d1df12919467722d9c5c80a0f4Andreas Gampe                            "--compiler-filter=", "-Xcompiler-option");
8003beff1e023193b485c67a3003a7f363f105d96d4Brian Carlstrom    }
801e0352388238875ef7e7b31d914fc903b08ff0f6bAndreas Gampe    parseCompilerOption("dalvik.vm.dex2oat-threads", dex2oatThreadsBuf, "-j", "-Xcompiler-option");
802e0352388238875ef7e7b31d914fc903b08ff0f6bAndreas Gampe    parseCompilerOption("dalvik.vm.image-dex2oat-threads", dex2oatThreadsImageBuf, "-j",
803e0352388238875ef7e7b31d914fc903b08ff0f6bAndreas Gampe                        "-Ximage-compiler-option");
804605cca1a985be74c00582853ee2c84b086cfade8Andreas Gampe
805605cca1a985be74c00582853ee2c84b086cfade8Andreas Gampe    // The runtime will compile a boot image, when necessary, not using installd. Thus, we need to
806605cca1a985be74c00582853ee2c84b086cfade8Andreas Gampe    // pass the instruction-set-features/variant as an image-compiler-option.
807605cca1a985be74c00582853ee2c84b086cfade8Andreas Gampe    // TODO: Find a better way for the instruction-set.
808605cca1a985be74c00582853ee2c84b086cfade8Andreas Gampe#if defined(__arm__)
809605cca1a985be74c00582853ee2c84b086cfade8Andreas Gampe    constexpr const char* instruction_set = "arm";
810605cca1a985be74c00582853ee2c84b086cfade8Andreas Gampe#elif defined(__aarch64__)
811605cca1a985be74c00582853ee2c84b086cfade8Andreas Gampe    constexpr const char* instruction_set = "arm64";
812605cca1a985be74c00582853ee2c84b086cfade8Andreas Gampe#elif defined(__mips__) && !defined(__LP64__)
813605cca1a985be74c00582853ee2c84b086cfade8Andreas Gampe    constexpr const char* instruction_set = "mips";
814605cca1a985be74c00582853ee2c84b086cfade8Andreas Gampe#elif defined(__mips__) && defined(__LP64__)
815