Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16 | |
Yasuhiro Matsuda | 1ab43d5 | 2015-06-30 17:07:32 +0900 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_DALVIK |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | #define LOG_TAG "AndroidRuntime" |
Joe Onorato | 82ba91d | 2017-04-27 16:18:05 -0700 | [diff] [blame] | 19 | #define LOG_NDEBUG 1 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | |
| 21 | #include <android_runtime/AndroidRuntime.h> |
Tom Cherry | 93099e4 | 2017-10-11 13:44:21 -0700 | [diff] [blame] | 22 | |
Elliott Hughes | a1194cb | 2018-03-23 11:27:04 -0700 | [diff] [blame] | 23 | #include <android-base/macros.h> |
Tom Cherry | 93099e4 | 2017-10-11 13:44:21 -0700 | [diff] [blame] | 24 | #include <android-base/properties.h> |
Mathias Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 25 | #include <binder/IBinder.h> |
Brad Fitzpatrick | 0bd5243 | 2010-12-13 16:52:35 -0800 | [diff] [blame] | 26 | #include <binder/IPCThreadState.h> |
Mathias Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 27 | #include <binder/IServiceManager.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | #include <utils/Log.h> |
| 29 | #include <utils/misc.h> |
Yasuhiro Matsuda | 1ab43d5 | 2015-06-30 17:07:32 +0900 | [diff] [blame] | 30 | #include <utils/Trace.h> |
Mathias Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 31 | #include <binder/Parcel.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | #include <utils/threads.h> |
| 33 | #include <cutils/properties.h> |
Mathieu Chartier | d2a975a | 2019-01-28 11:11:25 -0800 | [diff] [blame] | 34 | #include <server_configurable_flags/get_flags.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | |
| 36 | #include <SkGraphics.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | |
| 38 | #include "jni.h" |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 39 | #include <nativehelper/JNIHelp.h> |
| 40 | #include <nativehelper/JniInvocation.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | #include "android_util_Binder.h" |
| 42 | |
| 43 | #include <stdio.h> |
| 44 | #include <signal.h> |
| 45 | #include <sys/stat.h> |
| 46 | #include <sys/types.h> |
| 47 | #include <signal.h> |
| 48 | #include <dirent.h> |
| 49 | #include <assert.h> |
| 50 | |
Narayan Kamath | bf88205 | 2015-08-11 15:40:34 +0100 | [diff] [blame] | 51 | #include <string> |
| 52 | #include <vector> |
| 53 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | using namespace android; |
Tom Cherry | 93099e4 | 2017-10-11 13:44:21 -0700 | [diff] [blame] | 55 | using android::base::GetProperty; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | extern int register_android_os_Binder(JNIEnv* env); |
| 58 | extern int register_android_os_Process(JNIEnv* env); |
| 59 | extern int register_android_graphics_Bitmap(JNIEnv*); |
| 60 | extern int register_android_graphics_BitmapFactory(JNIEnv*); |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 61 | extern int register_android_graphics_BitmapRegionDecoder(JNIEnv*); |
Leon Scroggins III | 0c01dbf | 2017-10-20 14:08:11 -0400 | [diff] [blame] | 62 | extern int register_android_graphics_ByteBufferStreamAdaptor(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | extern int register_android_graphics_Camera(JNIEnv* env); |
Leon Scroggins III | d0d7eaf | 2013-09-06 16:46:57 -0400 | [diff] [blame] | 64 | extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env); |
sergeyv | 0a0f231 | 2017-01-04 13:58:52 -0800 | [diff] [blame] | 65 | extern int register_android_graphics_GraphicBuffer(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | extern int register_android_graphics_Graphics(JNIEnv* env); |
Leon Scroggins III | 0c01dbf | 2017-10-20 14:08:11 -0400 | [diff] [blame] | 67 | extern int register_android_graphics_ImageDecoder(JNIEnv*); |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 68 | extern int register_android_graphics_drawable_AnimatedImageDrawable(JNIEnv*); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | extern int register_android_graphics_Interpolator(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | extern int register_android_graphics_MaskFilter(JNIEnv* env); |
| 71 | extern int register_android_graphics_Movie(JNIEnv* env); |
| 72 | extern int register_android_graphics_NinePatch(JNIEnv*); |
| 73 | extern int register_android_graphics_PathEffect(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | extern int register_android_graphics_Shader(JNIEnv* env); |
| 75 | extern int register_android_graphics_Typeface(JNIEnv* env); |
Wei-Ta Chen | bca2d61 | 2009-11-30 17:52:05 +0800 | [diff] [blame] | 76 | extern int register_android_graphics_YuvImage(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | |
| 78 | extern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env); |
| 79 | extern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env); |
Thomas Tafertshofer | 6b1e838 | 2012-07-03 13:37:35 -0700 | [diff] [blame] | 80 | extern int register_android_opengl_jni_EGL14(JNIEnv* env); |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 81 | extern int register_android_opengl_jni_EGL15(JNIEnv* env); |
Jesse Hall | 237c2b8 | 2013-05-06 11:36:57 -0700 | [diff] [blame] | 82 | extern int register_android_opengl_jni_EGLExt(JNIEnv* env); |
Jack Palevich | 1c4907e | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 83 | extern int register_android_opengl_jni_GLES10(JNIEnv* env); |
| 84 | extern int register_android_opengl_jni_GLES10Ext(JNIEnv* env); |
| 85 | extern int register_android_opengl_jni_GLES11(JNIEnv* env); |
| 86 | extern int register_android_opengl_jni_GLES11Ext(JNIEnv* env); |
Jack Palevich | 560814f | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 87 | extern int register_android_opengl_jni_GLES20(JNIEnv* env); |
Jesse Hall | d877efe | 2013-04-29 15:59:35 -0700 | [diff] [blame] | 88 | extern int register_android_opengl_jni_GLES30(JNIEnv* env); |
Jesse Hall | 7ab63ac | 2014-05-19 15:13:41 -0700 | [diff] [blame] | 89 | extern int register_android_opengl_jni_GLES31(JNIEnv* env); |
| 90 | extern int register_android_opengl_jni_GLES31Ext(JNIEnv* env); |
Pablo Ceballos | 38c1a7e | 2015-10-30 10:34:30 -0700 | [diff] [blame] | 91 | extern int register_android_opengl_jni_GLES32(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | |
| 93 | extern int register_android_hardware_Camera(JNIEnv *env); |
Eino-Ville Talvala | 2f1a2e4 | 2013-07-25 17:12:05 -0700 | [diff] [blame] | 94 | extern int register_android_hardware_camera2_CameraMetadata(JNIEnv *env); |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 95 | extern int register_android_hardware_camera2_legacy_LegacyCameraDevice(JNIEnv *env); |
Eino-Ville Talvala | e1f57d6 | 2014-05-29 17:17:07 -0700 | [diff] [blame] | 96 | extern int register_android_hardware_camera2_legacy_PerfMeasurement(JNIEnv *env); |
Ruben Brunk | b607900 | 2014-05-22 12:33:54 -0700 | [diff] [blame] | 97 | extern int register_android_hardware_camera2_DngCreator(JNIEnv *env); |
Craig Donner | 1a4d07d | 2017-01-09 13:01:22 -0800 | [diff] [blame] | 98 | extern int register_android_hardware_HardwareBuffer(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | extern int register_android_hardware_SensorManager(JNIEnv *env); |
Mike Lockwood | b01e8bf | 2011-08-29 20:11:07 -0400 | [diff] [blame] | 100 | extern int register_android_hardware_SerialPort(JNIEnv *env); |
Eric Laurent | 60b62bc | 2014-04-18 17:50:49 -0700 | [diff] [blame] | 101 | extern int register_android_hardware_SoundTrigger(JNIEnv *env); |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 102 | extern int register_android_hardware_UsbDevice(JNIEnv *env); |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 103 | extern int register_android_hardware_UsbDeviceConnection(JNIEnv *env); |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 104 | extern int register_android_hardware_UsbRequest(JNIEnv *env); |
Brian Duddie | cfa5b5b | 2019-01-22 18:01:40 +0000 | [diff] [blame] | 105 | extern int register_android_hardware_location_ActivityRecognitionHardware(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | |
Eric Laurent | 7c31847e | 2018-11-29 14:33:56 -0800 | [diff] [blame] | 107 | extern int register_android_media_AudioEffectDescriptor(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | extern int register_android_media_AudioRecord(JNIEnv *env); |
| 109 | extern int register_android_media_AudioSystem(JNIEnv *env); |
| 110 | extern int register_android_media_AudioTrack(JNIEnv *env); |
François Gaffie | b469128 | 2018-07-09 13:07:32 +0200 | [diff] [blame] | 111 | extern int register_android_media_AudioAttributes(JNIEnv *env); |
François Gaffie | c01fa3a | 2018-03-15 14:33:24 +0100 | [diff] [blame] | 112 | extern int register_android_media_AudioProductStrategies(JNIEnv *env); |
François Gaffie | adcd00a | 2018-09-18 17:06:26 +0200 | [diff] [blame] | 113 | extern int register_android_media_AudioVolumeGroups(JNIEnv *env); |
| 114 | extern int register_android_media_AudioVolumeGroupChangeHandler(JNIEnv *env); |
jiabin | c0f4944 | 2018-01-05 10:23:50 -0800 | [diff] [blame] | 115 | extern int register_android_media_MicrophoneInfo(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | extern int register_android_media_JetPlayer(JNIEnv *env); |
| 117 | extern int register_android_media_ToneGenerator(JNIEnv *env); |
Paul McLean | 84b49130 | 2018-05-09 10:03:57 -0600 | [diff] [blame] | 118 | extern int register_android_media_midi(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | namespace android { |
| 121 | |
| 122 | /* |
| 123 | * JNI-based registration functions. Note these are properly contained in |
| 124 | * namespace android. |
| 125 | */ |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 126 | extern int register_android_app_admin_SecurityLog(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | extern int register_android_content_AssetManager(JNIEnv* env); |
| 128 | extern int register_android_util_EventLog(JNIEnv* env); |
Chenjie Yu | 671b1b5 | 2017-08-30 22:14:05 -0700 | [diff] [blame] | 129 | extern int register_android_util_StatsLog(JNIEnv* env); |
Tej Singh | be0482b | 2019-03-19 22:01:57 -0700 | [diff] [blame] | 130 | extern int register_android_util_StatsLogInternal(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | extern int register_android_util_Log(JNIEnv* env); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 132 | extern int register_android_util_MemoryIntArray(JNIEnv* env); |
Doris Liu | cdd23f9 | 2015-11-11 14:31:13 -0800 | [diff] [blame] | 133 | extern int register_android_util_PathParser(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | extern int register_android_content_StringBlock(JNIEnv* env); |
| 135 | extern int register_android_content_XmlBlock(JNIEnv* env); |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 136 | extern int register_android_content_res_ApkAssets(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | extern int register_android_graphics_Canvas(JNIEnv* env); |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 138 | extern int register_android_graphics_CanvasProperty(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | extern int register_android_graphics_ColorFilter(JNIEnv* env); |
Leon Scroggins III | 0e443d1 | 2018-12-19 11:38:35 -0500 | [diff] [blame] | 140 | extern int register_android_graphics_ColorSpace(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | extern int register_android_graphics_DrawFilter(JNIEnv* env); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 142 | extern int register_android_graphics_FontFamily(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | extern int register_android_graphics_Matrix(JNIEnv* env); |
| 144 | extern int register_android_graphics_Paint(JNIEnv* env); |
| 145 | extern int register_android_graphics_Path(JNIEnv* env); |
| 146 | extern int register_android_graphics_PathMeasure(JNIEnv* env); |
| 147 | extern int register_android_graphics_Picture(JNIEnv*); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 148 | extern int register_android_graphics_Region(JNIEnv* env); |
Jamie Gennis | aa0ce33 | 2011-01-06 17:04:26 -0800 | [diff] [blame] | 149 | extern int register_android_graphics_SurfaceTexture(JNIEnv* env); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 150 | extern int register_android_graphics_drawable_AnimatedVectorDrawable(JNIEnv* env); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 151 | extern int register_android_graphics_drawable_VectorDrawable(JNIEnv* env); |
Seigo Nonaka | a1c21c0 | 2018-07-20 15:57:39 -0700 | [diff] [blame] | 152 | extern int register_android_graphics_fonts_Font(JNIEnv* env); |
Seigo Nonaka | 88930f1 | 2018-07-24 17:09:23 -0700 | [diff] [blame] | 153 | extern int register_android_graphics_fonts_FontFamily(JNIEnv* env); |
Svetoslav | 6811f4e | 2013-09-18 15:58:28 -0700 | [diff] [blame] | 154 | extern int register_android_graphics_pdf_PdfDocument(JNIEnv* env); |
Svetoslav | 62ce332 | 2014-09-04 21:17:17 -0700 | [diff] [blame] | 155 | extern int register_android_graphics_pdf_PdfEditor(JNIEnv* env); |
Svetoslav | 2961769 | 2014-04-24 18:40:42 -0700 | [diff] [blame] | 156 | extern int register_android_graphics_pdf_PdfRenderer(JNIEnv* env); |
Seigo Nonaka | 70200b0 | 2018-10-01 16:04:11 -0700 | [diff] [blame] | 157 | extern int register_android_graphics_text_MeasuredText(JNIEnv* env); |
| 158 | extern int register_android_graphics_text_LineBreaker(JNIEnv *env); |
Jeff Brown | 0a0a124 | 2011-12-02 02:25:22 -0800 | [diff] [blame] | 159 | extern int register_android_view_DisplayEventReceiver(JNIEnv* env); |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 160 | extern int register_android_view_DisplayListCanvas(JNIEnv* env); |
Riddle Hsu | cd958bc | 2019-01-23 15:40:26 +0800 | [diff] [blame] | 161 | extern int register_android_view_InputApplicationHandle(JNIEnv* env); |
| 162 | extern int register_android_view_InputWindowHandle(JNIEnv* env); |
John Reck | 9d8d99d | 2018-02-21 12:55:41 -0800 | [diff] [blame] | 163 | extern int register_android_view_TextureLayer(JNIEnv* env); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 164 | extern int register_android_view_RenderNode(JNIEnv* env); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 165 | extern int register_android_view_RenderNodeAnimator(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | extern int register_android_view_Surface(JNIEnv* env); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 167 | extern int register_android_view_SurfaceControl(JNIEnv* env); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 168 | extern int register_android_view_SurfaceSession(JNIEnv* env); |
Adrian Roos | 9b963d3 | 2019-02-13 18:39:36 +0000 | [diff] [blame] | 169 | extern int register_android_view_CompositionSamplingListener(JNIEnv* env); |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 170 | extern int register_android_view_TextureView(JNIEnv* env); |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 171 | extern int register_android_view_ThreadedRenderer(JNIEnv* env); |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 172 | extern int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | extern int register_android_database_CursorWindow(JNIEnv* env); |
Jeff Brown | e5360fb | 2011-10-31 17:48:13 -0700 | [diff] [blame] | 174 | extern int register_android_database_SQLiteConnection(JNIEnv* env); |
| 175 | extern int register_android_database_SQLiteGlobal(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | extern int register_android_database_SQLiteDebug(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | extern int register_android_os_Debug(JNIEnv* env); |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 178 | extern int register_android_os_GraphicsEnvironment(JNIEnv* env); |
Yifan Hong | bb0bd00 | 2017-11-14 16:14:04 -0800 | [diff] [blame] | 179 | extern int register_android_os_HidlSupport(JNIEnv* env); |
Andreas Huber | c0b6c53 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 180 | extern int register_android_os_HwBinder(JNIEnv *env); |
Andreas Huber | dc26321 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 181 | extern int register_android_os_HwBlob(JNIEnv *env); |
Andreas Huber | c0b6c53 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 182 | extern int register_android_os_HwParcel(JNIEnv *env); |
| 183 | extern int register_android_os_HwRemoteBinder(JNIEnv *env); |
Nirav Atre | 9850dd9 | 2018-07-24 17:03:44 -0700 | [diff] [blame] | 184 | extern int register_android_os_NativeHandle(JNIEnv *env); |
Christopher Tate | fa9e7c0 | 2010-05-06 12:07:10 -0700 | [diff] [blame] | 185 | extern int register_android_os_MessageQueue(JNIEnv* env); |
Jeff Sharkey | d84e1ce | 2012-03-06 18:26:19 -0800 | [diff] [blame] | 186 | extern int register_android_os_Parcel(JNIEnv* env); |
Stephen Smalley | c07fca3 | 2012-01-13 08:31:39 -0500 | [diff] [blame] | 187 | extern int register_android_os_SELinux(JNIEnv* env); |
Yifan Hong | becc56d | 2017-04-05 14:42:05 -0700 | [diff] [blame] | 188 | extern int register_android_os_VintfObject(JNIEnv *env); |
Yifan Hong | 1bda673 | 2017-04-26 11:38:01 -0700 | [diff] [blame] | 189 | extern int register_android_os_VintfRuntimeInfo(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | extern int register_android_os_SystemProperties(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | extern int register_android_os_SystemClock(JNIEnv* env); |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 192 | extern int register_android_os_Trace(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | extern int register_android_os_FileObserver(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | extern int register_android_os_UEventObserver(JNIEnv* env); |
| 195 | extern int register_android_os_MemoryFile(JNIEnv* env); |
John Reck | dea6a02 | 2017-05-25 17:09:33 -0700 | [diff] [blame] | 196 | extern int register_android_os_SharedMemory(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | extern int register_android_net_LocalSocketImpl(JNIEnv* env); |
| 198 | extern int register_android_net_NetworkUtils(JNIEnv* env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | extern int register_android_text_AndroidCharacter(JNIEnv *env); |
Seigo Nonaka | 44a1df2 | 2017-08-31 18:22:38 -0700 | [diff] [blame] | 200 | extern int register_android_text_Hyphenator(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | extern int register_android_opengl_classes(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env); |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 203 | extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env); |
Joe Onorato | 1cf5874 | 2009-06-12 11:06:24 -0700 | [diff] [blame] | 204 | extern int register_android_backup_BackupDataInput(JNIEnv *env); |
Joe Onorato | d2110db | 2009-05-19 13:41:21 -0700 | [diff] [blame] | 205 | extern int register_android_backup_BackupDataOutput(JNIEnv *env); |
Joe Onorato | 06290a4 | 2009-06-18 20:10:37 -0700 | [diff] [blame] | 206 | extern int register_android_backup_FileBackupHelperBase(JNIEnv *env); |
Joe Onorato | 4ababd9 | 2009-06-25 18:29:18 -0400 | [diff] [blame] | 207 | extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env); |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 208 | extern int register_android_app_backup_FullBackup(JNIEnv *env); |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 209 | extern int register_android_app_Activity(JNIEnv *env); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 210 | extern int register_android_app_ActivityThread(JNIEnv *env); |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 211 | extern int register_android_app_NativeActivity(JNIEnv *env); |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 212 | extern int register_android_media_RemoteDisplay(JNIEnv *env); |
Przemyslaw Szczepaniak | 8a7c160 | 2015-11-03 09:47:56 +0000 | [diff] [blame] | 213 | extern int register_android_util_jar_StrictJarFile(JNIEnv* env); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 214 | extern int register_android_view_InputChannel(JNIEnv* env); |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 215 | extern int register_android_view_InputDevice(JNIEnv* env); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 216 | extern int register_android_view_InputEventReceiver(JNIEnv* env); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 217 | extern int register_android_view_InputEventSender(JNIEnv* env); |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 218 | extern int register_android_view_InputQueue(JNIEnv* env); |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 219 | extern int register_android_view_KeyCharacterMap(JNIEnv *env); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 220 | extern int register_android_view_KeyEvent(JNIEnv* env); |
| 221 | extern int register_android_view_MotionEvent(JNIEnv* env); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 222 | extern int register_android_view_PointerIcon(JNIEnv* env); |
Jeff Brown | 2ed2462 | 2011-03-14 19:39:54 -0700 | [diff] [blame] | 223 | extern int register_android_view_VelocityTracker(JNIEnv* env); |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 224 | extern int register_android_content_res_ObbScanner(JNIEnv* env); |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 225 | extern int register_android_content_res_Configuration(JNIEnv* env); |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 226 | extern int register_android_animation_PropertyValuesHolder(JNIEnv *env); |
Bo Zhu | 0985613 | 2018-04-01 12:24:09 -0700 | [diff] [blame] | 227 | extern int register_android_security_Scrypt(JNIEnv *env); |
Kenny Root | 66269ea | 2011-07-12 14:14:01 -0700 | [diff] [blame] | 228 | extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 229 | extern int register_com_android_internal_os_AtomicDirectory(JNIEnv *env); |
Narayan Kamath | f9419f0 | 2017-06-15 11:35:38 +0100 | [diff] [blame] | 230 | extern int register_com_android_internal_os_ClassLoaderFactory(JNIEnv* env); |
Daichi Hirono | 878e86f | 2016-10-31 09:33:30 +0900 | [diff] [blame] | 231 | extern int register_com_android_internal_os_FuseAppLoop(JNIEnv* env); |
Narayan Kamath | 973b466 | 2014-03-31 13:41:26 +0100 | [diff] [blame] | 232 | extern int register_com_android_internal_os_Zygote(JNIEnv *env); |
Jesse Hall | 1fe1dc0 | 2017-07-06 15:30:39 -0700 | [diff] [blame] | 233 | extern int register_com_android_internal_os_ZygoteInit(JNIEnv *env); |
John Reck | 9fa4071 | 2014-05-09 15:26:59 -0700 | [diff] [blame] | 234 | extern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | |
Roland Levillain | 7b098c8 | 2019-02-04 15:48:09 +0000 | [diff] [blame] | 236 | // Namespace for Android Runtime flags applied during boot time. |
| 237 | static const char* RUNTIME_NATIVE_BOOT_NAMESPACE = "runtime_native_boot"; |
Roland Levillain | 72b16f0 | 2019-02-19 18:09:58 +0000 | [diff] [blame] | 238 | // Feature flag name to enable/disable generational garbage collection in ART's |
| 239 | // Concurrent Copying (CC) garbage collector. |
| 240 | static const char* ENABLE_GENERATIONAL_CC = "enable_generational_cc"; |
| 241 | // Runtime option enabling generational garbage collection in ART's Concurrent |
| 242 | // Copying (CC) garbage collector. |
| 243 | static const char* kGenerationalCCRuntimeOption = "-Xgc:generational_cc"; |
| 244 | // Runtime option disabling generational garbage collection in ART's Concurrent |
| 245 | // Copying (CC) garbage collector. |
| 246 | static const char* kNoGenerationalCCRuntimeOption = "-Xgc:nogenerational_cc"; |
Roland Levillain | 7b098c8 | 2019-02-04 15:48:09 +0000 | [diff] [blame] | 247 | |
Nicolas Geoffray | 7a6a0da | 2019-02-25 13:26:31 +0000 | [diff] [blame] | 248 | // Feature flag name for running the JIT in Zygote experiment, b/119800099. |
| 249 | static const char* ENABLE_APEX_IMAGE = "enable_apex_image"; |
| 250 | // Flag to pass to the runtime when using the apex image. |
| 251 | static const char* kApexImageOption = "-Ximage:/system/framework/apex.art"; |
| 252 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | static AndroidRuntime* gCurRuntime = NULL; |
| 254 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | /* |
| 256 | * Code written in the Java Programming Language calls here from main(). |
| 257 | */ |
Jeff Brown | 16f5f5c | 2012-03-15 16:53:55 -0700 | [diff] [blame] | 258 | static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | { |
| 260 | gCurRuntime->onStarted(); |
| 261 | } |
| 262 | |
Andreas Gampe | 76d4fc8 | 2017-02-07 19:44:37 -0800 | [diff] [blame] | 263 | static void com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv* env, jobject clazz) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | { |
| 265 | gCurRuntime->onZygoteInit(); |
| 266 | } |
| 267 | |
Jeff Brown | 4280c4a | 2012-03-15 17:48:02 -0700 | [diff] [blame] | 268 | static void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIEnv* env, |
| 269 | jobject clazz, jboolean exitWithoutCleanup) |
| 270 | { |
| 271 | gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup); |
| 272 | } |
| 273 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | /* |
| 275 | * JNI registration. |
| 276 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | |
| 278 | int register_com_android_internal_os_RuntimeInit(JNIEnv* env) |
| 279 | { |
Andreas Gampe | 76d4fc8 | 2017-02-07 19:44:37 -0800 | [diff] [blame] | 280 | const JNINativeMethod methods[] = { |
| 281 | { "nativeFinishInit", "()V", |
| 282 | (void*) com_android_internal_os_RuntimeInit_nativeFinishInit }, |
| 283 | { "nativeSetExitWithoutCleanup", "(Z)V", |
| 284 | (void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup }, |
| 285 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit", |
Andreas Gampe | 76d4fc8 | 2017-02-07 19:44:37 -0800 | [diff] [blame] | 287 | methods, NELEM(methods)); |
| 288 | } |
| 289 | |
Jesse Hall | 1fe1dc0 | 2017-07-06 15:30:39 -0700 | [diff] [blame] | 290 | int register_com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv* env) |
Andreas Gampe | 76d4fc8 | 2017-02-07 19:44:37 -0800 | [diff] [blame] | 291 | { |
| 292 | const JNINativeMethod methods[] = { |
| 293 | { "nativeZygoteInit", "()V", |
| 294 | (void*) com_android_internal_os_ZygoteInit_nativeZygoteInit }, |
| 295 | }; |
| 296 | return jniRegisterNativeMethods(env, "com/android/internal/os/ZygoteInit", |
| 297 | methods, NELEM(methods)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | // ---------------------------------------------------------------------- |
| 301 | |
Andreas Huber | 9ae000c | 2014-02-13 17:22:33 +0000 | [diff] [blame] | 302 | /*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL; |
| 303 | |
Narayan Kamath | a23fcd7 | 2014-03-28 13:39:21 +0000 | [diff] [blame] | 304 | AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) : |
| 305 | mExitWithoutCleanup(false), |
| 306 | mArgBlockStart(argBlockStart), |
| 307 | mArgBlockLength(argBlockLength) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 309 | SkGraphics::Init(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | |
| 311 | // Pre-allocate enough space to hold a fair number of options. |
| 312 | mOptions.setCapacity(20); |
| 313 | |
| 314 | assert(gCurRuntime == NULL); // one per process |
| 315 | gCurRuntime = this; |
| 316 | } |
| 317 | |
| 318 | AndroidRuntime::~AndroidRuntime() |
| 319 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 320 | } |
| 321 | |
Andreas Huber | 9ae000c | 2014-02-13 17:22:33 +0000 | [diff] [blame] | 322 | /* |
| 323 | * Register native methods using JNI. |
| 324 | */ |
| 325 | /*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env, |
| 326 | const char* className, const JNINativeMethod* gMethods, int numMethods) |
| 327 | { |
| 328 | return jniRegisterNativeMethods(env, className, gMethods, numMethods); |
| 329 | } |
| 330 | |
Dmitriy Filchenko | f5b6e55 | 2016-07-18 16:00:35 -0700 | [diff] [blame] | 331 | void AndroidRuntime::setArgv0(const char* argv0, bool setProcName) { |
| 332 | if (setProcName) { |
| 333 | int len = strlen(argv0); |
| 334 | if (len < 15) { |
| 335 | pthread_setname_np(pthread_self(), argv0); |
| 336 | } else { |
| 337 | pthread_setname_np(pthread_self(), argv0 + len - 15); |
| 338 | } |
| 339 | } |
Jeff Brown | 00c0cd4 | 2014-09-10 16:48:46 -0700 | [diff] [blame] | 340 | memset(mArgBlockStart, 0, mArgBlockLength); |
Narayan Kamath | a23fcd7 | 2014-03-28 13:39:21 +0000 | [diff] [blame] | 341 | strlcpy(mArgBlockStart, argv0, mArgBlockLength); |
| 342 | } |
| 343 | |
Narayan Kamath | 22ec1ee | 2014-04-07 12:44:58 +0100 | [diff] [blame] | 344 | status_t AndroidRuntime::callMain(const String8& className, jclass clazz, |
| 345 | const Vector<String8>& args) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | { |
| 347 | JNIEnv* env; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | jmethodID methodId; |
| 349 | |
Narayan Kamath | 22ec1ee | 2014-04-07 12:44:58 +0100 | [diff] [blame] | 350 | ALOGD("Calling main entry %s", className.string()); |
Dianne Hackborn | 08e60f2 | 2010-09-01 18:17:17 -0700 | [diff] [blame] | 351 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | env = getJNIEnv(); |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 353 | if (clazz == NULL || env == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | return UNKNOWN_ERROR; |
| 355 | } |
| 356 | |
| 357 | methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V"); |
| 358 | if (methodId == NULL) { |
Narayan Kamath | 22ec1ee | 2014-04-07 12:44:58 +0100 | [diff] [blame] | 359 | ALOGE("ERROR: could not find method %s.main(String[])\n", className.string()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 360 | return UNKNOWN_ERROR; |
| 361 | } |
| 362 | |
| 363 | /* |
| 364 | * We want to call main() with a String array with our arguments in it. |
| 365 | * Create an array and populate it. |
| 366 | */ |
| 367 | jclass stringClass; |
| 368 | jobjectArray strArray; |
| 369 | |
Narayan Kamath | 22ec1ee | 2014-04-07 12:44:58 +0100 | [diff] [blame] | 370 | const size_t numArgs = args.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 371 | stringClass = env->FindClass("java/lang/String"); |
Narayan Kamath | 22ec1ee | 2014-04-07 12:44:58 +0100 | [diff] [blame] | 372 | strArray = env->NewObjectArray(numArgs, stringClass, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | |
Narayan Kamath | 22ec1ee | 2014-04-07 12:44:58 +0100 | [diff] [blame] | 374 | for (size_t i = 0; i < numArgs; i++) { |
| 375 | jstring argStr = env->NewStringUTF(args[i].string()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | env->SetObjectArrayElement(strArray, i, argStr); |
| 377 | } |
| 378 | |
| 379 | env->CallStaticVoidMethod(clazz, methodId, strArray); |
| 380 | return NO_ERROR; |
| 381 | } |
| 382 | |
| 383 | /* |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | * The VM calls this through the "exit" hook. |
| 385 | */ |
| 386 | static void runtime_exit(int code) |
| 387 | { |
Jeff Brown | 4280c4a | 2012-03-15 17:48:02 -0700 | [diff] [blame] | 388 | gCurRuntime->exit(code); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /* |
| 392 | * The VM calls this through the "vfprintf" hook. |
| 393 | * |
| 394 | * We ignore "fp" and just write the results to the log file. |
| 395 | */ |
| 396 | static void runtime_vfprintf(FILE* fp, const char* format, va_list ap) |
| 397 | { |
| 398 | LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap); |
| 399 | } |
| 400 | |
Brad Fitzpatrick | 0bd5243 | 2010-12-13 16:52:35 -0800 | [diff] [blame] | 401 | /** |
| 402 | * The VM calls this when mutex contention debugging is enabled to |
| 403 | * determine whether or not the blocked thread was a "sensitive thread" |
| 404 | * for user responsiveness/smoothess. |
| 405 | * |
| 406 | * Our policy for this is whether or not we're tracing any StrictMode |
| 407 | * events on this thread (which we might've inherited via Binder calls |
| 408 | * into us) |
| 409 | */ |
| 410 | static bool runtime_isSensitiveThread() { |
| 411 | IPCThreadState* state = IPCThreadState::selfOrNull(); |
| 412 | return state && state->getStrictModePolicy() != 0; |
| 413 | } |
| 414 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | static int hasDir(const char* dir) |
| 416 | { |
| 417 | struct stat s; |
| 418 | int res = stat(dir, &s); |
| 419 | if (res == 0) { |
| 420 | return S_ISDIR(s.st_mode); |
| 421 | } |
| 422 | return 0; |
| 423 | } |
| 424 | |
Andreas Gampe | 995c62d | 2014-11-14 16:15:17 -0800 | [diff] [blame] | 425 | static bool hasFile(const char* file) { |
| 426 | struct stat s; |
| 427 | int res = stat(file, &s); |
| 428 | if (res == 0) { |
| 429 | return S_ISREG(s.st_mode); |
| 430 | } |
| 431 | return false; |
| 432 | } |
| 433 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | /* |
Narayan Kamath | bf88205 | 2015-08-11 15:40:34 +0100 | [diff] [blame] | 435 | * Read the persistent locale. Inspects the following system properties |
| 436 | * (in order) and returns the first non-empty property in the list : |
| 437 | * |
| 438 | * (1) persist.sys.locale |
| 439 | * (2) persist.sys.language/country/localevar (country and localevar are |
| 440 | * inspected iff. language is non-empty. |
| 441 | * (3) ro.product.locale |
| 442 | * (4) ro.product.locale.language/region |
| 443 | * |
| 444 | * Note that we need to inspect persist.sys.language/country/localevar to |
| 445 | * preserve language settings for devices that are upgrading from Lollipop |
| 446 | * to M. The same goes for ro.product.locale.language/region as well. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | */ |
Narayan Kamath | bf88205 | 2015-08-11 15:40:34 +0100 | [diff] [blame] | 448 | const std::string readLocale() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | { |
Tom Cherry | 93099e4 | 2017-10-11 13:44:21 -0700 | [diff] [blame] | 450 | const std::string locale = GetProperty("persist.sys.locale", ""); |
Narayan Kamath | bf88205 | 2015-08-11 15:40:34 +0100 | [diff] [blame] | 451 | if (!locale.empty()) { |
| 452 | return locale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | } |
Narayan Kamath | d30dbb8 | 2015-01-15 14:48:15 +0000 | [diff] [blame] | 454 | |
Tom Cherry | 93099e4 | 2017-10-11 13:44:21 -0700 | [diff] [blame] | 455 | const std::string language = GetProperty("persist.sys.language", ""); |
Narayan Kamath | bf88205 | 2015-08-11 15:40:34 +0100 | [diff] [blame] | 456 | if (!language.empty()) { |
Tom Cherry | 93099e4 | 2017-10-11 13:44:21 -0700 | [diff] [blame] | 457 | const std::string country = GetProperty("persist.sys.country", ""); |
| 458 | const std::string variant = GetProperty("persist.sys.localevar", ""); |
Narayan Kamath | bf88205 | 2015-08-11 15:40:34 +0100 | [diff] [blame] | 459 | |
| 460 | std::string out = language; |
| 461 | if (!country.empty()) { |
| 462 | out = out + "-" + country; |
| 463 | } |
| 464 | |
| 465 | if (!variant.empty()) { |
| 466 | out = out + "-" + variant; |
| 467 | } |
| 468 | |
| 469 | return out; |
| 470 | } |
| 471 | |
Tom Cherry | 93099e4 | 2017-10-11 13:44:21 -0700 | [diff] [blame] | 472 | const std::string productLocale = GetProperty("ro.product.locale", ""); |
Narayan Kamath | bf88205 | 2015-08-11 15:40:34 +0100 | [diff] [blame] | 473 | if (!productLocale.empty()) { |
| 474 | return productLocale; |
| 475 | } |
| 476 | |
| 477 | // If persist.sys.locale and ro.product.locale are missing, |
| 478 | // construct a locale value from the individual locale components. |
Tom Cherry | 93099e4 | 2017-10-11 13:44:21 -0700 | [diff] [blame] | 479 | const std::string productLanguage = GetProperty("ro.product.locale.language", "en"); |
| 480 | const std::string productRegion = GetProperty("ro.product.locale.region", "US"); |
Narayan Kamath | bf88205 | 2015-08-11 15:40:34 +0100 | [diff] [blame] | 481 | |
| 482 | return productLanguage + "-" + productRegion; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 483 | } |
| 484 | |
Brian Carlstrom | 0d8fb01 | 2014-07-30 12:11:41 -0700 | [diff] [blame] | 485 | void AndroidRuntime::addOption(const char* optionString, void* extraInfo) |
| 486 | { |
| 487 | JavaVMOption opt; |
| 488 | opt.optionString = optionString; |
| 489 | opt.extraInfo = extraInfo; |
| 490 | mOptions.add(opt); |
| 491 | } |
| 492 | |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 493 | /* |
Andy McFadden | e4d81f2 | 2010-07-14 16:02:20 -0700 | [diff] [blame] | 494 | * Parse a property containing space-separated options that should be |
| 495 | * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap". |
| 496 | * |
| 497 | * This will cut up "extraOptsBuf" as we chop it into individual options. |
| 498 | * |
Brian Carlstrom | 3beff1e | 2014-02-28 23:27:22 -0800 | [diff] [blame] | 499 | * If "quotingArg" is non-null, it is passed before each extra option in mOptions. |
| 500 | * |
Andy McFadden | e4d81f2 | 2010-07-14 16:02:20 -0700 | [diff] [blame] | 501 | * Adds the strings, if any, to mOptions. |
| 502 | */ |
Brian Carlstrom | 3beff1e | 2014-02-28 23:27:22 -0800 | [diff] [blame] | 503 | void AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg) |
Andy McFadden | e4d81f2 | 2010-07-14 16:02:20 -0700 | [diff] [blame] | 504 | { |
Brian Carlstrom | 3beff1e | 2014-02-28 23:27:22 -0800 | [diff] [blame] | 505 | char* start = extraOptsBuf; |
| 506 | char* end = NULL; |
Andy McFadden | e4d81f2 | 2010-07-14 16:02:20 -0700 | [diff] [blame] | 507 | while (*start != '\0') { |
| 508 | while (*start == ' ') /* skip leading whitespace */ |
| 509 | start++; |
| 510 | if (*start == '\0') /* was trailing ws, bail */ |
| 511 | break; |
| 512 | |
| 513 | end = start+1; |
| 514 | while (*end != ' ' && *end != '\0') /* find end of token */ |
| 515 | end++; |
| 516 | if (*end == ' ') |
| 517 | *end++ = '\0'; /* mark end, advance to indicate more */ |
| 518 | |
Brian Carlstrom | 3beff1e | 2014-02-28 23:27:22 -0800 | [diff] [blame] | 519 | if (quotingArg != NULL) { |
Brian Carlstrom | 0d8fb01 | 2014-07-30 12:11:41 -0700 | [diff] [blame] | 520 | addOption(quotingArg); |
Brian Carlstrom | 3beff1e | 2014-02-28 23:27:22 -0800 | [diff] [blame] | 521 | } |
Brian Carlstrom | 0d8fb01 | 2014-07-30 12:11:41 -0700 | [diff] [blame] | 522 | addOption(start); |
Andy McFadden | e4d81f2 | 2010-07-14 16:02:20 -0700 | [diff] [blame] | 523 | start = end; |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | /* |
Brian Carlstrom | 6d77eb9 | 2014-07-08 10:40:59 -0700 | [diff] [blame] | 528 | * Reads a "property" into "buffer" with a default of "defaultArg". If |
| 529 | * the property is non-empty, it is treated as a runtime option such |
| 530 | * as "-Xmx32m". |
| 531 | * |
| 532 | * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx". |
| 533 | * |
| 534 | * If an argument is found, it is added to mOptions. |
| 535 | * |
| 536 | * If an option is found, it is added to mOptions and true is |
| 537 | * returned. Otherwise false is returned. |
| 538 | */ |
| 539 | bool AndroidRuntime::parseRuntimeOption(const char* property, |
| 540 | char* buffer, |
| 541 | const char* runtimeArg, |
| 542 | const char* defaultArg) |
| 543 | { |
| 544 | strcpy(buffer, runtimeArg); |
| 545 | size_t runtimeArgLen = strlen(runtimeArg); |
| 546 | property_get(property, buffer+runtimeArgLen, defaultArg); |
| 547 | if (buffer[runtimeArgLen] == '\0') { |
| 548 | return false; |
| 549 | } |
Brian Carlstrom | 0d8fb01 | 2014-07-30 12:11:41 -0700 | [diff] [blame] | 550 | addOption(buffer); |
Brian Carlstrom | 6d77eb9 | 2014-07-08 10:40:59 -0700 | [diff] [blame] | 551 | return true; |
| 552 | } |
| 553 | |
| 554 | /* |
| 555 | * Reads a "property" into "buffer". If the property is non-empty, it |
Brian Carlstrom | 3fbfbb4 | 2014-07-28 19:13:28 -0700 | [diff] [blame] | 556 | * is treated as a dex2oat compiler option that should be |
Nicolas Geoffray | be7b0d1 | 2017-04-25 12:29:07 +0100 | [diff] [blame] | 557 | * passed as a quoted option, e.g. "-Ximage-compiler-option --compiler-filter=assume-verified". |
Brian Carlstrom | 3fbfbb4 | 2014-07-28 19:13:28 -0700 | [diff] [blame] | 558 | * |
| 559 | * The "compilerArg" is a prefix for the option such as "--compiler-filter=". |
| 560 | * |
| 561 | * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option". |
| 562 | * |
| 563 | * If an option is found, it is added to mOptions and true is |
| 564 | * returned. Otherwise false is returned. |
| 565 | */ |
| 566 | bool AndroidRuntime::parseCompilerOption(const char* property, |
| 567 | char* buffer, |
| 568 | const char* compilerArg, |
| 569 | const char* quotingArg) |
| 570 | { |
| 571 | strcpy(buffer, compilerArg); |
| 572 | size_t compilerArgLen = strlen(compilerArg); |
| 573 | property_get(property, buffer+compilerArgLen, ""); |
| 574 | if (buffer[compilerArgLen] == '\0') { |
| 575 | return false; |
| 576 | } |
Brian Carlstrom | 0d8fb01 | 2014-07-30 12:11:41 -0700 | [diff] [blame] | 577 | addOption(quotingArg); |
| 578 | addOption(buffer); |
Brian Carlstrom | 3fbfbb4 | 2014-07-28 19:13:28 -0700 | [diff] [blame] | 579 | return true; |
| 580 | } |
| 581 | |
| 582 | /* |
| 583 | * Reads a "property" into "buffer". If the property is non-empty, it |
Brian Carlstrom | 6d77eb9 | 2014-07-08 10:40:59 -0700 | [diff] [blame] | 584 | * is treated as a dex2oat compiler runtime option that should be |
| 585 | * passed as a quoted option, e.g. "-Ximage-compiler-option |
| 586 | * --runtime-arg -Ximage-compiler-option -Xmx32m". |
| 587 | * |
| 588 | * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx". |
| 589 | * |
| 590 | * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option". |
| 591 | * |
| 592 | * If an option is found, it is added to mOptions and true is |
| 593 | * returned. Otherwise false is returned. |
| 594 | */ |
| 595 | bool AndroidRuntime::parseCompilerRuntimeOption(const char* property, |
| 596 | char* buffer, |
| 597 | const char* runtimeArg, |
| 598 | const char* quotingArg) |
| 599 | { |
| 600 | strcpy(buffer, runtimeArg); |
| 601 | size_t runtimeArgLen = strlen(runtimeArg); |
| 602 | property_get(property, buffer+runtimeArgLen, ""); |
| 603 | if (buffer[runtimeArgLen] == '\0') { |
| 604 | return false; |
| 605 | } |
Brian Carlstrom | 0d8fb01 | 2014-07-30 12:11:41 -0700 | [diff] [blame] | 606 | addOption(quotingArg); |
| 607 | addOption("--runtime-arg"); |
| 608 | addOption(quotingArg); |
| 609 | addOption(buffer); |
Brian Carlstrom | 6d77eb9 | 2014-07-08 10:40:59 -0700 | [diff] [blame] | 610 | return true; |
| 611 | } |
| 612 | |
| 613 | /* |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 614 | * Start the Dalvik Virtual Machine. |
| 615 | * |
| 616 | * Various arguments, most determined by system properties, are passed in. |
| 617 | * The "mOptions" vector is updated. |
| 618 | * |
Dave Allison | 07a1e23 | 2014-03-14 08:54:33 -0700 | [diff] [blame] | 619 | * CAUTION: when adding options in here, be careful not to put the |
| 620 | * char buffer inside a nested scope. Adding the buffer to the |
| 621 | * options using mOptions.add() does not copy the buffer, so if the |
| 622 | * buffer goes out of scope the option may be overwritten. It's best |
| 623 | * to put the buffer at the top of the function so that it is more |
| 624 | * unlikely that someone will surround it in a scope at a later time |
| 625 | * and thus introduce a bug. |
| 626 | * |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 627 | * Returns 0 on success. |
| 628 | */ |
Sebastien Hertz | 7a09b83 | 2015-08-10 18:55:34 +0200 | [diff] [blame] | 629 | int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | JavaVMInitArgs initArgs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | char propBuf[PROPERTY_VALUE_MAX]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX]; |
Carl Shapiro | 38cfa8c | 2010-12-07 16:48:29 -0800 | [diff] [blame] | 634 | char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX]; |
Dianne Hackborn | bdcef70 | 2009-08-18 19:15:36 -0700 | [diff] [blame] | 635 | char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX]; |
Carl Shapiro | 8cdf27c | 2011-01-19 12:33:12 -0800 | [diff] [blame] | 636 | char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX]; |
Ian Rogers | 5325010 | 2012-09-23 16:38:03 -0700 | [diff] [blame] | 637 | char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX]; |
| 638 | char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX]; |
Mathieu Chartier | 6909c0e | 2015-03-05 17:00:41 -0800 | [diff] [blame] | 639 | char usejitOptsBuf[sizeof("-Xusejit:")-1 + PROPERTY_VALUE_MAX]; |
Nicolas Geoffray | 24934a9 | 2018-05-16 17:22:37 +0100 | [diff] [blame] | 640 | char jitpthreadpriorityOptsBuf[sizeof("-Xjitpthreadpriority:")-1 + PROPERTY_VALUE_MAX]; |
Nicolas Geoffray | cdf1dff | 2015-11-19 13:48:35 +0000 | [diff] [blame] | 641 | char jitmaxsizeOptsBuf[sizeof("-Xjitmaxsize:")-1 + PROPERTY_VALUE_MAX]; |
| 642 | char jitinitialsizeOptsBuf[sizeof("-Xjitinitialsize:")-1 + PROPERTY_VALUE_MAX]; |
Mathieu Chartier | 6909c0e | 2015-03-05 17:00:41 -0800 | [diff] [blame] | 643 | char jitthresholdOptsBuf[sizeof("-Xjitthreshold:")-1 + PROPERTY_VALUE_MAX]; |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 644 | char useJitProfilesOptsBuf[sizeof("-Xjitsaveprofilinginfo:")-1 + PROPERTY_VALUE_MAX]; |
Calin Juravle | 0de80b9 | 2016-04-12 14:12:04 +0100 | [diff] [blame] | 645 | char jitprithreadweightOptBuf[sizeof("-Xjitprithreadweight:")-1 + PROPERTY_VALUE_MAX]; |
Calin Juravle | 8d74de5 | 2016-04-27 14:12:00 +0100 | [diff] [blame] | 646 | char jittransitionweightOptBuf[sizeof("-Xjittransitionweight:")-1 + PROPERTY_VALUE_MAX]; |
Mathieu Chartier | 5eee004 | 2017-06-07 17:34:22 -0700 | [diff] [blame] | 647 | char hotstartupsamplesOptsBuf[sizeof("-Xps-hot-startup-method-samples:")-1 + PROPERTY_VALUE_MAX]; |
Mathieu Chartier | cd0caf5 | 2017-10-13 11:29:27 -0700 | [diff] [blame] | 648 | char madviseRandomOptsBuf[sizeof("-XX:MadviseRandomAccess:")-1 + PROPERTY_VALUE_MAX]; |
Mathieu Chartier | 7e4fdec | 2013-12-02 15:46:51 -0800 | [diff] [blame] | 649 | char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX]; |
Mathieu Chartier | c01936a | 2014-05-14 15:44:49 -0700 | [diff] [blame] | 650 | char backgroundgcOptsBuf[sizeof("-XX:BackgroundGC=")-1 + PROPERTY_VALUE_MAX]; |
Ian Rogers | 5325010 | 2012-09-23 16:38:03 -0700 | [diff] [blame] | 651 | char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX]; |
Mathieu Chartier | ebc3b4c | 2017-10-15 21:13:28 -0700 | [diff] [blame] | 652 | char foregroundHeapGrowthMultiplierOptsBuf[ |
| 653 | sizeof("-XX:ForegroundHeapGrowthMultiplier=")-1 + PROPERTY_VALUE_MAX]; |
Andreas Gampe | e324ba0 | 2015-03-31 16:15:17 -0700 | [diff] [blame] | 654 | char cachePruneBuf[sizeof("-Xzygote-max-boot-retry=")-1 + PROPERTY_VALUE_MAX]; |
Brian Carlstrom | 6d77eb9 | 2014-07-08 10:40:59 -0700 | [diff] [blame] | 655 | char dex2oatXmsImageFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX]; |
| 656 | char dex2oatXmxImageFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX]; |
| 657 | char dex2oatXmsFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX]; |
| 658 | char dex2oatXmxFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX]; |
Brian Carlstrom | 3fbfbb4 | 2014-07-28 19:13:28 -0700 | [diff] [blame] | 659 | char dex2oatCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX]; |
| 660 | char dex2oatImageCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX]; |
Andreas Gampe | e035238 | 2015-03-30 18:43:39 -0700 | [diff] [blame] | 661 | char dex2oatThreadsBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX]; |
| 662 | char dex2oatThreadsImageBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX]; |
Andreas Gampe | 605cca1 | 2015-04-02 23:12:56 -0700 | [diff] [blame] | 663 | char dex2oat_isa_variant_key[PROPERTY_KEY_MAX]; |
| 664 | char dex2oat_isa_variant[sizeof("--instruction-set-variant=") -1 + PROPERTY_VALUE_MAX]; |
| 665 | char dex2oat_isa_features_key[PROPERTY_KEY_MAX]; |
| 666 | char dex2oat_isa_features[sizeof("--instruction-set-features=") -1 + PROPERTY_VALUE_MAX]; |
Brian Carlstrom | 3beff1e | 2014-02-28 23:27:22 -0800 | [diff] [blame] | 667 | char dex2oatFlagsBuf[PROPERTY_VALUE_MAX]; |
| 668 | char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX]; |
Andy McFadden | e4d81f2 | 2010-07-14 16:02:20 -0700 | [diff] [blame] | 669 | char extraOptsBuf[PROPERTY_VALUE_MAX]; |
Brian Carlstrom | 0d8fb01 | 2014-07-30 12:11:41 -0700 | [diff] [blame] | 670 | char voldDecryptBuf[PROPERTY_VALUE_MAX]; |
Ben Cheng | 52b0e73 | 2009-06-19 13:31:12 -0700 | [diff] [blame] | 671 | enum { |
| 672 | kEMDefault, |
| 673 | kEMIntPortable, |
| 674 | kEMIntFast, |
Ben Cheng | 52b0e73 | 2009-06-19 13:31:12 -0700 | [diff] [blame] | 675 | kEMJitCompiler, |
Ben Cheng | 52b0e73 | 2009-06-19 13:31:12 -0700 | [diff] [blame] | 676 | } executionMode = kEMDefault; |
Narayan Kamath | d30dbb8 | 2015-01-15 14:48:15 +0000 | [diff] [blame] | 677 | char localeOption[sizeof("-Duser.locale=") + PROPERTY_VALUE_MAX]; |
Brian Carlstrom | 6d77eb9 | 2014-07-08 10:40:59 -0700 | [diff] [blame] | 678 | char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX]; |
Calin Juravle | 01db916 | 2014-08-07 14:45:53 +0100 | [diff] [blame] | 679 | char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX]; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 680 | char cpuAbiListBuf[sizeof("--cpu-abilist=") + PROPERTY_VALUE_MAX]; |
David Brazdil | 896d036 | 2019-04-12 11:18:07 +0100 | [diff] [blame] | 681 | char corePlatformApiPolicyBuf[sizeof("-Xcore-platform-api-policy:") + PROPERTY_VALUE_MAX]; |
Andreas Gampe | 98f406f | 2015-06-22 21:09:36 -0700 | [diff] [blame] | 682 | char methodTraceFileBuf[sizeof("-Xmethod-trace-file:") + PROPERTY_VALUE_MAX]; |
| 683 | char methodTraceFileSizeBuf[sizeof("-Xmethod-trace-file-size:") + PROPERTY_VALUE_MAX]; |
Tom Cherry | 93099e4 | 2017-10-11 13:44:21 -0700 | [diff] [blame] | 684 | std::string fingerprintBuf; |
Alex Light | fffb273 | 2017-11-20 13:01:01 -0800 | [diff] [blame] | 685 | char jdwpProviderBuf[sizeof("-XjdwpProvider:") - 1 + PROPERTY_VALUE_MAX]; |
Nicolas Geoffray | 79eeb98 | 2019-02-14 15:55:20 +0000 | [diff] [blame] | 686 | char bootImageBuf[sizeof("-Ximage:") - 1 + PROPERTY_VALUE_MAX]; |
| 687 | |
Nicolas Geoffray | 7a6a0da | 2019-02-25 13:26:31 +0000 | [diff] [blame] | 688 | std::string use_apex_image = |
| 689 | server_configurable_flags::GetServerConfigurableFlag(RUNTIME_NATIVE_BOOT_NAMESPACE, |
| 690 | ENABLE_APEX_IMAGE, |
| 691 | /*default_value=*/ ""); |
| 692 | if (use_apex_image == "true") { |
| 693 | addOption(kApexImageOption); |
| 694 | ALOGI("Using Apex boot image: '%s'\n", kApexImageOption); |
| 695 | } else if (parseRuntimeOption("dalvik.vm.boot-image", bootImageBuf, "-Ximage:")) { |
| 696 | ALOGI("Using dalvik.vm.boot-image: '%s'\n", bootImageBuf); |
| 697 | } else { |
| 698 | ALOGI("Using default boot image"); |
Nicolas Geoffray | 79eeb98 | 2019-02-14 15:55:20 +0000 | [diff] [blame] | 699 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 700 | |
Brian Carlstrom | 6d77eb9 | 2014-07-08 10:40:59 -0700 | [diff] [blame] | 701 | bool checkJni = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 702 | property_get("dalvik.vm.checkjni", propBuf, ""); |
| 703 | if (strcmp(propBuf, "true") == 0) { |
| 704 | checkJni = true; |
| 705 | } else if (strcmp(propBuf, "false") != 0) { |
| 706 | /* property is neither true nor false; fall back on kernel parameter */ |
| 707 | property_get("ro.kernel.android.checkjni", propBuf, ""); |
| 708 | if (propBuf[0] == '1') { |
| 709 | checkJni = true; |
| 710 | } |
| 711 | } |
Joe Onorato | 82ba91d | 2017-04-27 16:18:05 -0700 | [diff] [blame] | 712 | ALOGV("CheckJNI is %s\n", checkJni ? "ON" : "OFF"); |
Brian Carlstrom | 6d77eb9 | 2014-07-08 10:40:59 -0700 | [diff] [blame] | 713 | if (checkJni) { |
| 714 | /* extended JNI checking */ |
Brian Carlstrom | 0d8fb01 | 2014-07-30 12:11:41 -0700 | [diff] [blame] | 715 | addOption("-Xcheck:jni"); |
Brian Carlstrom | 6d77eb9 | 2014-07-08 10:40:59 -0700 | [diff] [blame] | 716 | |
Brian Carlstrom | 6d77eb9 | 2014-07-08 10:40:59 -0700 | [diff] [blame] | 717 | /* with -Xcheck:jni, this provides a JNI function call trace */ |
Brian Carlstrom | 0d8fb01 | 2014-07-30 12:11:41 -0700 | [diff] [blame] | 718 | //addOption("-verbose:jni"); |
Brian Carlstrom | 6d77eb9 | 2014-07-08 10:40:59 -0700 | [diff] [blame] | 719 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 720 | |
| 721 | property_get("dalvik.vm.execution-mode", propBuf, ""); |
| 722 | if (strcmp(propBuf, "int:portable") == 0) { |
| 723 | executionMode = kEMIntPortable; |
| 724 | } else if (strcmp(propBuf, "int:fast") == 0) { |
| 725 | executionMode = kEMIntFast; |
Ben Cheng | 52b0e73 | 2009-06-19 13:31:12 -0700 | [diff] [blame] | 726 | } else if (strcmp(propBuf, "int:jit") == 0) { |
| 727 | executionMode = kEMJitCompiler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | } |
| 729 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 730 | strcpy(jniOptsBuf, "-Xjniopts:"); |
Brian Carlstrom | 6d77eb9 | 2014-07-08 10:40:59 -0700 | [diff] [blame] | 731 | if (parseRuntimeOption("dalvik.vm.jniopts", jniOptsBuf, "-Xjniopts:")) { |
| 732 | ALOGI("JNI options: '%s'\n", jniOptsBuf); |
| 733 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 734 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 735 | /* route exit() to our handler */ |
Brian Carlstrom | 0d8fb01 | 2014-07-30 12:11:41 -0700 | [diff] [blame] | 736 | addOption("exit", (void*) runtime_exit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 737 | |
| 738 | /* route fprintf() to our handler */ |
Brian Carlstrom | 0d8fb01 | 2014-07-30 12:11:41 -0700 | [diff] [blame] | 739 | addOption("vfprintf", (void*) runtime_vfprintf); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 740 | |
Brad Fitzpatrick | 0bd5243 | 2010-12-13 16:52:35 -0800 | [diff] [blame] | 741 | /* register the framework-specific "is sensitive thread" hook */ |
Brian Carlstrom | 0d8fb01 | 2014-07-30 12:11:41 -0700 | [diff] [blame] | 742 | addOption("sensitiveThread", (void*) runtime_isSensitiveThread); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 743 | |
| 744 | /* enable verbose; standard options are { jni, gc, class } */ |
Brian Carlstrom | 0d8fb01 | 2014-07-30 12:11:41 -0700 | [diff] [blame] | 745 | //addOption("-verbose:jni"); |
| 746 | addOption("-verbose:gc"); |
| 747 | //addOption("-verbose:class"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 748 | |
Carl Shapiro | 9e4c884 | 2010-12-08 12:14:46 -0800 | [diff] [blame] | 749 | /* |
| 750 | * The default starting and maximum size of the heap. Larger |
| 751 | * values should be specified in a product property override. |
| 752 | */ |
Brian Carlstrom | 6d77eb9 | 2014-07-08 10:40:59 -0700 | [diff] [blame] | 753 | parseRuntimeOption("dalvik.vm.heapstartsize", heapstartsizeOptsBuf, "-Xms", "4m"); |
| 754 | parseRuntimeOption("dalvik.vm.heapsize", heapsizeOptsBuf, "-Xmx", "16m"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 755 | |
Brian Carlstrom | 6d77eb9 | 2014-07-08 10:40:59 -0700 | [diff] [blame] | 756 | parseRuntimeOption("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit="); |
| 757 | parseRuntimeOption("dalvik.vm.heapminfree", heapminfreeOptsBuf, "-XX:HeapMinFree="); |
| 758 | parseRuntimeOption("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf, "-XX:HeapMaxFree="); |
| 759 | parseRuntimeOption("dalvik.vm.heaptargetutilization", |
| 760 | heaptargetutilizationOptsBuf, |
| 761 | "-XX:HeapTargetUtilization="); |
Ian Rogers | 5325010 | 2012-09-23 16:38:03 -0700 | [diff] [blame] | 762 | |
Mathieu Chartier | ebc3b4c | 2017-10-15 21:13:28 -0700 | [diff] [blame] | 763 | /* Foreground heap growth multiplier option */ |
| 764 | parseRuntimeOption("dalvik.vm.foreground-heap-growth-multiplier", |
| 765 | foregroundHeapGrowthMultiplierOptsBuf, |
| 766 | "-XX:ForegroundHeapGrowthMultiplier="); |
| 767 | |
Mathieu Chartier | 6909c0e | 2015-03-05 17:00:41 -0800 | [diff] [blame] | 768 | /* |
| 769 | * JIT related options. |
| 770 | */ |
Mathieu Chartier | 1fb7aab | 2015-03-18 18:54:36 -0700 | [diff] [blame] | 771 | parseRuntimeOption("dalvik.vm.usejit", usejitOptsBuf, "-Xusejit:"); |
Nicolas Geoffray | cdf1dff | 2015-11-19 13:48:35 +0000 | [diff] [blame] | 772 | parseRuntimeOption("dalvik.vm.jitmaxsize", jitmaxsizeOptsBuf, "-Xjitmaxsize:"); |
| 773 | parseRuntimeOption("dalvik.vm.jitinitialsize", jitinitialsizeOptsBuf, "-Xjitinitialsize:"); |
Mathieu Chartier | 1fb7aab | 2015-03-18 18:54:36 -0700 | [diff] [blame] | 774 | parseRuntimeOption("dalvik.vm.jitthreshold", jitthresholdOptsBuf, "-Xjitthreshold:"); |
Nicolas Geoffray | 24934a9 | 2018-05-16 17:22:37 +0100 | [diff] [blame] | 775 | parseRuntimeOption("dalvik.vm.jitpthreadpriority", |
| 776 | jitpthreadpriorityOptsBuf, |
| 777 | "-Xjitpthreadpriority:"); |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 778 | property_get("dalvik.vm.usejitprofiles", useJitProfilesOptsBuf, ""); |
| 779 | if (strcmp(useJitProfilesOptsBuf, "true") == 0) { |
| 780 | addOption("-Xjitsaveprofilinginfo"); |
| 781 | } |
Calin Juravle | 8d74de5 | 2016-04-27 14:12:00 +0100 | [diff] [blame] | 782 | |
Calin Juravle | 0de80b9 | 2016-04-12 14:12:04 +0100 | [diff] [blame] | 783 | parseRuntimeOption("dalvik.vm.jitprithreadweight", |
| 784 | jitprithreadweightOptBuf, |
| 785 | "-Xjitprithreadweight:"); |
Mathieu Chartier | 6909c0e | 2015-03-05 17:00:41 -0800 | [diff] [blame] | 786 | |
Calin Juravle | 8d74de5 | 2016-04-27 14:12:00 +0100 | [diff] [blame] | 787 | parseRuntimeOption("dalvik.vm.jittransitionweight", |
| 788 | jittransitionweightOptBuf, |
| 789 | "-Xjittransitionweight:"); |
| 790 | |
Calin Juravle | 62cd4bb | 2018-05-08 12:42:30 -0700 | [diff] [blame] | 791 | property_get("dalvik.vm.profilebootimage", propBuf, ""); |
| 792 | if (strcmp(propBuf, "true") == 0) { |
| 793 | addOption("-Xps-profile-boot-class-path"); |
| 794 | addOption("-Xps-profile-aot-code"); |
| 795 | } |
| 796 | |
Mathieu Chartier | 5eee004 | 2017-06-07 17:34:22 -0700 | [diff] [blame] | 797 | /* |
Mathieu Chartier | cd0caf5 | 2017-10-13 11:29:27 -0700 | [diff] [blame] | 798 | * Madvise related options. |
| 799 | */ |
| 800 | parseRuntimeOption("dalvik.vm.madvise-random", madviseRandomOptsBuf, "-XX:MadviseRandomAccess:"); |
| 801 | |
| 802 | /* |
Mathieu Chartier | 5eee004 | 2017-06-07 17:34:22 -0700 | [diff] [blame] | 803 | * Profile related options. |
| 804 | */ |
| 805 | parseRuntimeOption("dalvik.vm.hot-startup-method-samples", hotstartupsamplesOptsBuf, |
| 806 | "-Xps-hot-startup-method-samples:"); |
| 807 | |
Mathieu Chartier | e6c2241 | 2013-08-20 17:16:03 -0700 | [diff] [blame] | 808 | property_get("ro.config.low_ram", propBuf, ""); |
| 809 | if (strcmp(propBuf, "true") == 0) { |
Brian Carlstrom | 0d8fb01 | 2014-07-30 12:11:41 -0700 | [diff] [blame] | 810 | addOption("-XX:LowMemoryMode"); |
Mathieu Chartier | e6c2241 | 2013-08-20 17:16:03 -0700 | [diff] [blame] | 811 | } |
| 812 | |
Roland Levillain | 72b16f0 | 2019-02-19 18:09:58 +0000 | [diff] [blame] | 813 | /* |
| 814 | * Garbage-collection related options. |
| 815 | */ |
| 816 | parseRuntimeOption("dalvik.vm.gctype", gctypeOptsBuf, "-Xgc:"); |
| 817 | |
| 818 | // If it set, honor the "enable_generational_cc" device configuration; |
| 819 | // otherwise, let the runtime use its default behavior. |
| 820 | std::string enable_generational_cc = |
| 821 | server_configurable_flags::GetServerConfigurableFlag(RUNTIME_NATIVE_BOOT_NAMESPACE, |
| 822 | ENABLE_GENERATIONAL_CC, |
| 823 | /*default_value=*/ ""); |
| 824 | if (enable_generational_cc == "true") { |
| 825 | addOption(kGenerationalCCRuntimeOption); |
| 826 | } else if (enable_generational_cc == "false") { |
| 827 | addOption(kNoGenerationalCCRuntimeOption); |
Mathieu Chartier | d2a975a | 2019-01-28 11:11:25 -0800 | [diff] [blame] | 828 | } |
| 829 | |
Brian Carlstrom | 6d77eb9 | 2014-07-08 10:40:59 -0700 | [diff] [blame] | 830 | parseRuntimeOption("dalvik.vm.backgroundgctype", backgroundgcOptsBuf, "-XX:BackgroundGC="); |
Mathieu Chartier | c01936a | 2014-05-14 15:44:49 -0700 | [diff] [blame] | 831 | |
Sebastien Hertz | 7a09b83 | 2015-08-10 18:55:34 +0200 | [diff] [blame] | 832 | /* |
| 833 | * Enable debugging only for apps forked from zygote. |
Sebastien Hertz | 7a09b83 | 2015-08-10 18:55:34 +0200 | [diff] [blame] | 834 | */ |
| 835 | if (zygote) { |
Alex Light | c50928b | 2018-01-31 16:47:29 +0000 | [diff] [blame] | 836 | // Set the JDWP provider and required arguments. By default let the runtime choose how JDWP is |
| 837 | // implemented. When this is not set the runtime defaults to not allowing JDWP. |
Alex Light | fffb273 | 2017-11-20 13:01:01 -0800 | [diff] [blame] | 838 | addOption("-XjdwpOptions:suspend=n,server=y"); |
Alex Light | c50928b | 2018-01-31 16:47:29 +0000 | [diff] [blame] | 839 | parseRuntimeOption("dalvik.vm.jdwp-provider", |
| 840 | jdwpProviderBuf, |
| 841 | "-XjdwpProvider:", |
| 842 | "default"); |
Sebastien Hertz | 7a09b83 | 2015-08-10 18:55:34 +0200 | [diff] [blame] | 843 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 844 | |
Brian Carlstrom | 6d77eb9 | 2014-07-08 10:40:59 -0700 | [diff] [blame] | 845 | parseRuntimeOption("dalvik.vm.lockprof.threshold", |
| 846 | lockProfThresholdBuf, |
| 847 | "-Xlockprofthreshold:"); |
Carl Shapiro | d8f3ec6 | 2010-04-12 16:31:59 -0700 | [diff] [blame] | 848 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 849 | if (executionMode == kEMIntPortable) { |
Brian Carlstrom | 0d8fb01 | 2014-07-30 12:11:41 -0700 | [diff] [blame] | 850 | addOption("-Xint:portable"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 851 | } else if (executionMode == kEMIntFast) { |
Brian Carlstrom | 0d8fb01 | 2014-07-30 12:11:41 -0700 | [diff] [blame] | 852 | addOption("-Xint:fast"); |
Ben Cheng | 52b0e73 | 2009-06-19 13:31:12 -0700 | [diff] [blame] | 853 | } else if (executionMode == kEMJitCompiler) { |
Brian Carlstrom | 0d8fb01 | 2014-07-30 12:11:41 -0700 | [diff] [blame] | 854 | addOption("-Xint:jit"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | } |
Andy McFadden | e2b23e1 | 2009-04-03 11:09:46 -0700 | [diff] [blame] | 856 | |
Andreas Gampe | 08b2d58 | 2014-12-18 14:39:22 -0800 | [diff] [blame] | 857 | // If we are booting without the real /data, don't spend time compiling. |
| 858 | property_get("vold.decrypt", voldDecryptBuf, ""); |
| 859 | bool skip_compilation = ((strcmp(voldDecryptBuf, "trigger_restart_min_framework") == 0) || |
| 860 | (strcmp(voldDecryptBuf, "1") == 0)); |
Brian Carlstrom | 3beff1e | 2014-02-28 23:27:22 -0800 | [diff] [blame] | 861 | |
Andreas Gampe | 08b2d58 | 2014-12-18 14:39:22 -0800 | [diff] [blame] | 862 | // Extra options for boot.art/boot.oat image generation. |
| 863 | parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xms", dex2oatXmsImageFlagsBuf, |
| 864 | "-Xms", "-Ximage-compiler-option"); |
| 865 | parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xmx", dex2oatXmxImageFlagsBuf, |
| 866 | "-Xmx", "-Ximage-compiler-option"); |
| 867 | if (skip_compilation) { |
Brian Carlstrom | ce5bbbe | 2014-07-30 15:13:17 -0700 | [diff] [blame] | 868 | addOption("-Ximage-compiler-option"); |
Nicolas Geoffray | be7b0d1 | 2017-04-25 12:29:07 +0100 | [diff] [blame] | 869 | addOption("--compiler-filter=assume-verified"); |
Andreas Gampe | 08b2d58 | 2014-12-18 14:39:22 -0800 | [diff] [blame] | 870 | } else { |
| 871 | parseCompilerOption("dalvik.vm.image-dex2oat-filter", dex2oatImageCompilerFilterBuf, |
| 872 | "--compiler-filter=", "-Ximage-compiler-option"); |
Brian Carlstrom | 3beff1e | 2014-02-28 23:27:22 -0800 | [diff] [blame] | 873 | } |
| 874 | |
Mathieu Chartier | f99e70e | 2017-06-30 11:47:38 -0700 | [diff] [blame] | 875 | // If there is a boot profile, it takes precedence over the image and preloaded classes. |
| 876 | if (hasFile("/system/etc/boot-image.prof")) { |
Andreas Gampe | 08b2d58 | 2014-12-18 14:39:22 -0800 | [diff] [blame] | 877 | addOption("-Ximage-compiler-option"); |
Mathieu Chartier | f99e70e | 2017-06-30 11:47:38 -0700 | [diff] [blame] | 878 | addOption("--profile-file=/system/etc/boot-image.prof"); |
| 879 | addOption("-Ximage-compiler-option"); |
| 880 | addOption("--compiler-filter=speed-profile"); |
| 881 | } else { |
| 882 | // Make sure there is a preloaded-classes file. |
| 883 | if (!hasFile("/system/etc/preloaded-classes")) { |
| 884 | ALOGE("Missing preloaded-classes file, /system/etc/preloaded-classes not found: %s\n", |
| 885 | strerror(errno)); |
| 886 | return -1; |
| 887 | } |
| 888 | addOption("-Ximage-compiler-option"); |
| 889 | addOption("--image-classes=/system/etc/preloaded-classes"); |
| 890 | |
Jeff Hao | 37641ae | 2017-07-31 13:35:01 -0700 | [diff] [blame] | 891 | // If there is a dirty-image-objects file, push it. |
| 892 | if (hasFile("/system/etc/dirty-image-objects")) { |
| 893 | addOption("-Ximage-compiler-option"); |
| 894 | addOption("--dirty-image-objects=/system/etc/dirty-image-objects"); |
| 895 | } |
Andreas Gampe | 08b2d58 | 2014-12-18 14:39:22 -0800 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | property_get("dalvik.vm.image-dex2oat-flags", dex2oatImageFlagsBuf, ""); |
| 899 | parseExtraOpts(dex2oatImageFlagsBuf, "-Ximage-compiler-option"); |
| 900 | |
| 901 | // Extra options for DexClassLoader. |
| 902 | parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xms", dex2oatXmsFlagsBuf, |
| 903 | "-Xms", "-Xcompiler-option"); |
| 904 | parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xmx", dex2oatXmxFlagsBuf, |
| 905 | "-Xmx", "-Xcompiler-option"); |
| 906 | if (skip_compilation) { |
| 907 | addOption("-Xcompiler-option"); |
Nicolas Geoffray | be7b0d1 | 2017-04-25 12:29:07 +0100 | [diff] [blame] | 908 | addOption("--compiler-filter=assume-verified"); |
neo.chae | 155118f | 2015-01-07 15:32:15 +0900 | [diff] [blame] | 909 | |
| 910 | // We skip compilation when a minimal runtime is brought up for decryption. In that case |
| 911 | // /data is temporarily backed by a tmpfs, which is usually small. |
| 912 | // If the system image contains prebuilts, they will be relocated into the tmpfs. In this |
| 913 | // specific situation it is acceptable to *not* relocate and run out of the prebuilts |
| 914 | // directly instead. |
| 915 | addOption("--runtime-arg"); |
| 916 | addOption("-Xnorelocate"); |
Andreas Gampe | 08b2d58 | 2014-12-18 14:39:22 -0800 | [diff] [blame] | 917 | } else { |
| 918 | parseCompilerOption("dalvik.vm.dex2oat-filter", dex2oatCompilerFilterBuf, |
| 919 | "--compiler-filter=", "-Xcompiler-option"); |
| 920 | } |
Andreas Gampe | e035238 | 2015-03-30 18:43:39 -0700 | [diff] [blame] | 921 | parseCompilerOption("dalvik.vm.dex2oat-threads", dex2oatThreadsBuf, "-j", "-Xcompiler-option"); |
| 922 | parseCompilerOption("dalvik.vm.image-dex2oat-threads", dex2oatThreadsImageBuf, "-j", |
| 923 | "-Ximage-compiler-option"); |
Andreas Gampe | 605cca1 | 2015-04-02 23:12:56 -0700 | [diff] [blame] | 924 | |
| 925 | // The runtime will compile a boot image, when necessary, not using installd. Thus, we need to |
| 926 | // pass the instruction-set-features/variant as an image-compiler-option. |
Andreas Gampe | 605cca1 | 2015-04-02 23:12:56 -0700 | [diff] [blame] | 927 | // Note: it is OK to reuse the buffer, as the values are exactly the same between |
| 928 | // * compiler-option, used for runtime compilation (DexClassLoader) |
| 929 | // * image-compiler-option, used for boot-image compilation on device |
| 930 | |
| 931 | // Copy the variant. |
Elliott Hughes | a1194cb | 2018-03-23 11:27:04 -0700 | [diff] [blame] | 932 | sprintf(dex2oat_isa_variant_key, "dalvik.vm.isa.%s.variant", ABI_STRING); |
Andreas Gampe | 605cca1 | 2015-04-02 23:12:56 -0700 | [diff] [blame] | 933 | parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant, |
| 934 | "--instruction-set-variant=", "-Ximage-compiler-option"); |
| 935 | parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant, |
| 936 | "--instruction-set-variant=", "-Xcompiler-option"); |
| 937 | // Copy the features. |
Elliott Hughes | a1194cb | 2018-03-23 11:27:04 -0700 | [diff] [blame] | 938 | sprintf(dex2oat_isa_features_key, "dalvik.vm.isa.%s.features", ABI_STRING); |
Andreas Gampe | 605cca1 | 2015-04-02 23:12:56 -0700 | [diff] [blame] | 939 | parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features, |
| 940 | "--instruction-set-features=", "-Ximage-compiler-option"); |
| 941 | parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features, |
| 942 | "--instruction-set-features=", "-Xcompiler-option"); |
| 943 | |
| 944 | |
Andreas Gampe | 08b2d58 | 2014-12-18 14:39:22 -0800 | [diff] [blame] | 945 | property_get("dalvik.vm.dex2oat-flags", dex2oatFlagsBuf, ""); |
| 946 | parseExtraOpts(dex2oatFlagsBuf, "-Xcompiler-option"); |
| 947 | |
Andy McFadden | e4d81f2 | 2010-07-14 16:02:20 -0700 | [diff] [blame] | 948 | /* extra options; parse this late so it overrides others */ |
| 949 | property_get("dalvik.vm.extra-opts", extraOptsBuf, ""); |
Brian Carlstrom | 3beff1e | 2014-02-28 23:27:22 -0800 | [diff] [blame] | 950 | parseExtraOpts(extraOptsBuf, NULL); |
Andy McFadden | e4d81f2 | 2010-07-14 16:02:20 -0700 | [diff] [blame] | 951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 952 | /* Set the properties for locale */ |
| 953 | { |
Narayan Kamath | d30dbb8 | 2015-01-15 14:48:15 +0000 | [diff] [blame] | 954 | strcpy(localeOption, "-Duser.locale="); |
Narayan Kamath | bf88205 | 2015-08-11 15:40:34 +0100 | [diff] [blame] | 955 | const std::string locale = readLocale(); |
| 956 | strncat(localeOption, locale.c_str(), PROPERTY_VALUE_MAX); |
Narayan Kamath | d30dbb8 | 2015-01-15 14:48:15 +0000 | [diff] [blame] | 957 | addOption(localeOption); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 958 | } |
| 959 | |
Calin Juravle | 92290b8 | 2015-11-10 19:30:45 +0000 | [diff] [blame] | 960 | // Trace files are stored in /data/misc/trace which is writable only in debug mode. |
| 961 | property_get("ro.debuggable", propBuf, "0"); |
| 962 | if (strcmp(propBuf, "1") == 0) { |
| 963 | property_get("dalvik.vm.method-trace", propBuf, "false"); |
Andreas Gampe | 98f406f | 2015-06-22 21:09:36 -0700 | [diff] [blame] | 964 | if (strcmp(propBuf, "true") == 0) { |
Calin Juravle | 92290b8 | 2015-11-10 19:30:45 +0000 | [diff] [blame] | 965 | addOption("-Xmethod-trace"); |
| 966 | parseRuntimeOption("dalvik.vm.method-trace-file", |
| 967 | methodTraceFileBuf, |
| 968 | "-Xmethod-trace-file:"); |
| 969 | parseRuntimeOption("dalvik.vm.method-trace-file-siz", |
| 970 | methodTraceFileSizeBuf, |
| 971 | "-Xmethod-trace-file-size:"); |
| 972 | property_get("dalvik.vm.method-trace-stream", propBuf, "false"); |
| 973 | if (strcmp(propBuf, "true") == 0) { |
| 974 | addOption("-Xmethod-trace-stream"); |
| 975 | } |
Andreas Gampe | 98f406f | 2015-06-22 21:09:36 -0700 | [diff] [blame] | 976 | } |
| 977 | } |
| 978 | |
Andreas Gampe | 08b2d58 | 2014-12-18 14:39:22 -0800 | [diff] [blame] | 979 | // Native bridge library. "0" means that native bridge is disabled. |
Andreas Gampe | 14a1cd9 | 2018-06-07 09:42:02 -0700 | [diff] [blame] | 980 | // |
| 981 | // Note: bridging is only enabled for the zygote. Other runs of |
| 982 | // app_process may not have the permissions to mount etc. |
Andreas Gampe | 08b2d58 | 2014-12-18 14:39:22 -0800 | [diff] [blame] | 983 | property_get("ro.dalvik.vm.native.bridge", propBuf, ""); |
| 984 | if (propBuf[0] == '\0') { |
| 985 | ALOGW("ro.dalvik.vm.native.bridge is not expected to be empty"); |
Andreas Gampe | 14a1cd9 | 2018-06-07 09:42:02 -0700 | [diff] [blame] | 986 | } else if (zygote && strcmp(propBuf, "0") != 0) { |
Andreas Gampe | 08b2d58 | 2014-12-18 14:39:22 -0800 | [diff] [blame] | 987 | snprintf(nativeBridgeLibrary, sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX, |
| 988 | "-XX:NativeBridge=%s", propBuf); |
| 989 | addOption(nativeBridgeLibrary); |
Calin Juravle | be20ed4 | 2014-08-26 23:00:11 +0100 | [diff] [blame] | 990 | } |
Calin Juravle | 01db916 | 2014-08-07 14:45:53 +0100 | [diff] [blame] | 991 | |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 992 | #if defined(__LP64__) |
| 993 | const char* cpu_abilist_property_name = "ro.product.cpu.abilist64"; |
| 994 | #else |
| 995 | const char* cpu_abilist_property_name = "ro.product.cpu.abilist32"; |
| 996 | #endif // defined(__LP64__) |
| 997 | property_get(cpu_abilist_property_name, propBuf, ""); |
| 998 | if (propBuf[0] == '\0') { |
| 999 | ALOGE("%s is not expected to be empty", cpu_abilist_property_name); |
| 1000 | return -1; |
| 1001 | } |
| 1002 | snprintf(cpuAbiListBuf, sizeof(cpuAbiListBuf), "--cpu-abilist=%s", propBuf); |
| 1003 | addOption(cpuAbiListBuf); |
| 1004 | |
Andreas Gampe | e324ba0 | 2015-03-31 16:15:17 -0700 | [diff] [blame] | 1005 | // Dalvik-cache pruning counter. |
| 1006 | parseRuntimeOption("dalvik.vm.zygote.max-boot-retry", cachePruneBuf, |
| 1007 | "-Xzygote-max-boot-retry="); |
| 1008 | |
Andreas Gampe | 27c39f1 | 2015-04-27 18:28:18 +0000 | [diff] [blame] | 1009 | /* |
David Srbecky | 065075e | 2015-05-28 17:16:09 +0100 | [diff] [blame] | 1010 | * When running with debug.generate-debug-info, add --generate-debug-info to |
| 1011 | * the compiler options so that the boot image, if it is compiled on device, |
| 1012 | * will include native debugging information. |
Andreas Gampe | 27c39f1 | 2015-04-27 18:28:18 +0000 | [diff] [blame] | 1013 | */ |
David Srbecky | 065075e | 2015-05-28 17:16:09 +0100 | [diff] [blame] | 1014 | property_get("debug.generate-debug-info", propBuf, ""); |
Andreas Gampe | 27c39f1 | 2015-04-27 18:28:18 +0000 | [diff] [blame] | 1015 | if (strcmp(propBuf, "true") == 0) { |
| 1016 | addOption("-Xcompiler-option"); |
David Srbecky | 065075e | 2015-05-28 17:16:09 +0100 | [diff] [blame] | 1017 | addOption("--generate-debug-info"); |
Andreas Gampe | 27c39f1 | 2015-04-27 18:28:18 +0000 | [diff] [blame] | 1018 | addOption("-Ximage-compiler-option"); |
David Srbecky | 065075e | 2015-05-28 17:16:09 +0100 | [diff] [blame] | 1019 | addOption("--generate-debug-info"); |
Andreas Gampe | 27c39f1 | 2015-04-27 18:28:18 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
David Srbecky | 3bb3250 | 2018-01-23 17:57:24 +0000 | [diff] [blame] | 1022 | // The mini-debug-info makes it possible to backtrace through JIT code. |
| 1023 | if (property_get_bool("dalvik.vm.minidebuginfo", 0)) { |
| 1024 | addOption("-Xcompiler-option"); |
| 1025 | addOption("--generate-mini-debug-info"); |
| 1026 | } |
| 1027 | |
David Brazdil | 896d036 | 2019-04-12 11:18:07 +0100 | [diff] [blame] | 1028 | // If set, the property below can be used to enable core platform API violation reporting. |
| 1029 | property_get("persist.debug.dalvik.vm.core_platform_api_policy", propBuf, ""); |
| 1030 | if (propBuf[0] != '\0') { |
| 1031 | snprintf(corePlatformApiPolicyBuf, |
| 1032 | sizeof(corePlatformApiPolicyBuf), |
| 1033 | "-Xcore-platform-api-policy:%s", |
| 1034 | propBuf); |
| 1035 | addOption(corePlatformApiPolicyBuf); |
| 1036 | } |
| 1037 | |
Andreas Gampe | e608250 | 2015-07-24 14:19:44 -0700 | [diff] [blame] | 1038 | /* |
| 1039 | * Retrieve the build fingerprint and provide it to the runtime. That way, ANR dumps will |
| 1040 | * contain the fingerprint and can be parsed. |
Tom Cherry | 93099e4 | 2017-10-11 13:44:21 -0700 | [diff] [blame] | 1041 | * Fingerprints are potentially longer than PROPERTY_VALUE_MAX, so parseRuntimeOption() cannot |
| 1042 | * be used here. |
| 1043 | * Do not ever re-assign fingerprintBuf as its c_str() value is stored in mOptions. |
Andreas Gampe | e608250 | 2015-07-24 14:19:44 -0700 | [diff] [blame] | 1044 | */ |
Tom Cherry | 93099e4 | 2017-10-11 13:44:21 -0700 | [diff] [blame] | 1045 | std::string fingerprint = GetProperty("ro.build.fingerprint", ""); |
| 1046 | if (!fingerprint.empty()) { |
| 1047 | fingerprintBuf = "-Xfingerprint:" + fingerprint; |
| 1048 | addOption(fingerprintBuf.c_str()); |
| 1049 | } |
Andreas Gampe | e608250 | 2015-07-24 14:19:44 -0700 | [diff] [blame] | 1050 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1051 | initArgs.version = JNI_VERSION_1_4; |
| 1052 | initArgs.options = mOptions.editArray(); |
| 1053 | initArgs.nOptions = mOptions.size(); |
| 1054 | initArgs.ignoreUnrecognized = JNI_FALSE; |
| 1055 | |
| 1056 | /* |
| 1057 | * Initialize the VM. |
| 1058 | * |
| 1059 | * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread. |
| 1060 | * If this call succeeds, the VM is ready, and we can start issuing |
| 1061 | * JNI calls. |
| 1062 | */ |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 1063 | if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1064 | ALOGE("JNI_CreateJavaVM failed\n"); |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 1065 | return -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1066 | } |
| 1067 | |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 1068 | return 0; |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 1071 | char* AndroidRuntime::toSlashClassName(const char* className) |
| 1072 | { |
| 1073 | char* result = strdup(className); |
| 1074 | for (char* cp = result; *cp != '\0'; cp++) { |
| 1075 | if (*cp == '.') { |
| 1076 | *cp = '/'; |
| 1077 | } |
| 1078 | } |
| 1079 | return result; |
| 1080 | } |
| 1081 | |
Mike Lockwood | 9ee5e7e | 2014-09-08 16:15:21 -0700 | [diff] [blame] | 1082 | /** Create a Java string from an ASCII or Latin-1 string */ |
| 1083 | jstring AndroidRuntime::NewStringLatin1(JNIEnv* env, const char* bytes) { |
| 1084 | if (!bytes) return NULL; |
| 1085 | int length = strlen(bytes); |
| 1086 | jchar* buffer = (jchar *)alloca(length * sizeof(jchar)); |
| 1087 | if (!buffer) return NULL; |
| 1088 | jchar* chp = buffer; |
| 1089 | for (int i = 0; i < length; i++) { |
| 1090 | *chp++ = *bytes++; |
| 1091 | } |
| 1092 | return env->NewString(buffer, length); |
| 1093 | } |
| 1094 | |
| 1095 | |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 1096 | /* |
| 1097 | * Start the Android runtime. This involves starting the virtual machine |
| 1098 | * and calling the "static void main(String[] args)" method in the class |
| 1099 | * named by "className". |
Jeff Brown | ebed7d6 | 2011-05-16 17:08:42 -0700 | [diff] [blame] | 1100 | * |
| 1101 | * Passes the main function two arguments, the class name and the specified |
| 1102 | * options string. |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 1103 | */ |
Sebastien Hertz | 7a09b83 | 2015-08-10 18:55:34 +0200 | [diff] [blame] | 1104 | void AndroidRuntime::start(const char* className, const Vector<String8>& options, bool zygote) |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 1105 | { |
Dianne Hackborn | 8e5aafe | 2014-10-27 18:04:10 -0700 | [diff] [blame] | 1106 | ALOGD(">>>>>> START %s uid %d <<<<<<\n", |
| 1107 | className != NULL ? className : "(unknown)", getuid()); |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 1108 | |
Narayan Kamath | 22ec1ee | 2014-04-07 12:44:58 +0100 | [diff] [blame] | 1109 | static const String8 startSystemServer("start-system-server"); |
| 1110 | |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 1111 | /* |
| 1112 | * 'startSystemServer == true' means runtime is obsolete and not run from |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 1113 | * init.rc anymore, so we print out the boot start event here. |
| 1114 | */ |
Narayan Kamath | 22ec1ee | 2014-04-07 12:44:58 +0100 | [diff] [blame] | 1115 | for (size_t i = 0; i < options.size(); ++i) { |
| 1116 | if (options[i] == startSystemServer) { |
| 1117 | /* track our progress through the boot sequence */ |
| 1118 | const int LOG_BOOT_PROGRESS_START = 3000; |
| 1119 | LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, ns2ms(systemTime(SYSTEM_TIME_MONOTONIC))); |
| 1120 | } |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | const char* rootDir = getenv("ANDROID_ROOT"); |
| 1124 | if (rootDir == NULL) { |
| 1125 | rootDir = "/system"; |
| 1126 | if (!hasDir("/system")) { |
Neil Fuller | 3ce4cce | 2018-11-23 19:00:32 +0000 | [diff] [blame] | 1127 | LOG_FATAL("No root directory specified, and /system does not exist."); |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 1128 | return; |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 1129 | } |
| 1130 | setenv("ANDROID_ROOT", rootDir, 1); |
| 1131 | } |
| 1132 | |
Neil Fuller | 3ce4cce | 2018-11-23 19:00:32 +0000 | [diff] [blame] | 1133 | const char* runtimeRootDir = getenv("ANDROID_RUNTIME_ROOT"); |
| 1134 | if (runtimeRootDir == NULL) { |
| 1135 | LOG_FATAL("No runtime directory specified with ANDROID_RUNTIME_ROOT environment variable."); |
| 1136 | return; |
| 1137 | } |
| 1138 | |
Neil Fuller | b99050d | 2019-03-13 15:29:48 +0000 | [diff] [blame] | 1139 | const char* tzdataRootDir = getenv("ANDROID_TZDATA_ROOT"); |
| 1140 | if (tzdataRootDir == NULL) { |
| 1141 | LOG_FATAL("No tz data directory specified with ANDROID_TZDATA_ROOT environment variable."); |
| 1142 | return; |
| 1143 | } |
| 1144 | |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 1145 | //const char* kernelHack = getenv("LD_ASSUME_KERNEL"); |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1146 | //ALOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack); |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 1147 | |
| 1148 | /* start the virtual machine */ |
Brian Carlstrom | 9f8203a | 2013-06-19 13:49:36 -0700 | [diff] [blame] | 1149 | JniInvocation jni_invocation; |
| 1150 | jni_invocation.Init(NULL); |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 1151 | JNIEnv* env; |
Sebastien Hertz | 7a09b83 | 2015-08-10 18:55:34 +0200 | [diff] [blame] | 1152 | if (startVm(&mJavaVM, &env, zygote) != 0) { |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 1153 | return; |
| 1154 | } |
| 1155 | onVmCreated(env); |
Andy McFadden | f70188a | 2009-03-31 15:52:13 -0700 | [diff] [blame] | 1156 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1157 | /* |
| 1158 | * Register android functions. |
| 1159 | */ |
| 1160 | if (startReg(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1161 | ALOGE("Unable to register all android natives\n"); |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 1162 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | /* |
| 1166 | * We want to call main() with a String array with arguments in it. |
Jeff Brown | ebed7d6 | 2011-05-16 17:08:42 -0700 | [diff] [blame] | 1167 | * At present we have two arguments, the class name and an option string. |
| 1168 | * Create an array to hold them. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1169 | */ |
| 1170 | jclass stringClass; |
| 1171 | jobjectArray strArray; |
| 1172 | jstring classNameStr; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1173 | |
| 1174 | stringClass = env->FindClass("java/lang/String"); |
| 1175 | assert(stringClass != NULL); |
Narayan Kamath | 22ec1ee | 2014-04-07 12:44:58 +0100 | [diff] [blame] | 1176 | strArray = env->NewObjectArray(options.size() + 1, stringClass, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1177 | assert(strArray != NULL); |
| 1178 | classNameStr = env->NewStringUTF(className); |
| 1179 | assert(classNameStr != NULL); |
| 1180 | env->SetObjectArrayElement(strArray, 0, classNameStr); |
Narayan Kamath | 22ec1ee | 2014-04-07 12:44:58 +0100 | [diff] [blame] | 1181 | |
| 1182 | for (size_t i = 0; i < options.size(); ++i) { |
| 1183 | jstring optionsStr = env->NewStringUTF(options.itemAt(i).string()); |
| 1184 | assert(optionsStr != NULL); |
| 1185 | env->SetObjectArrayElement(strArray, i + 1, optionsStr); |
| 1186 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1187 | |
| 1188 | /* |
| 1189 | * Start VM. This thread becomes the main thread of the VM, and will |
| 1190 | * not return until the VM exits. |
| 1191 | */ |
George Burgess IV | d657a38 | 2017-06-20 23:53:29 -0700 | [diff] [blame] | 1192 | char* slashClassName = toSlashClassName(className != NULL ? className : ""); |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 1193 | jclass startClass = env->FindClass(slashClassName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1194 | if (startClass == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1195 | ALOGE("JavaVM unable to locate class '%s'\n", slashClassName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1196 | /* keep going */ |
| 1197 | } else { |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 1198 | jmethodID startMeth = env->GetStaticMethodID(startClass, "main", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1199 | "([Ljava/lang/String;)V"); |
| 1200 | if (startMeth == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1201 | ALOGE("JavaVM unable to find main() in '%s'\n", className); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1202 | /* keep going */ |
| 1203 | } else { |
| 1204 | env->CallStaticVoidMethod(startClass, startMeth, strArray); |
| 1205 | |
| 1206 | #if 0 |
| 1207 | if (env->ExceptionCheck()) |
| 1208 | threadExitUncaughtException(env); |
| 1209 | #endif |
| 1210 | } |
| 1211 | } |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 1212 | free(slashClassName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1213 | |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1214 | ALOGD("Shutting down VM\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1215 | if (mJavaVM->DetachCurrentThread() != JNI_OK) |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 1216 | ALOGW("Warning: unable to detach main thread\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1217 | if (mJavaVM->DestroyJavaVM() != 0) |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 1218 | ALOGW("Warning: VM did not shut down cleanly\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1219 | } |
| 1220 | |
Jeff Brown | 4280c4a | 2012-03-15 17:48:02 -0700 | [diff] [blame] | 1221 | void AndroidRuntime::exit(int code) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1222 | { |
Jeff Brown | 4280c4a | 2012-03-15 17:48:02 -0700 | [diff] [blame] | 1223 | if (mExitWithoutCleanup) { |
| 1224 | ALOGI("VM exiting with result code %d, cleanup skipped.", code); |
| 1225 | ::_exit(code); |
| 1226 | } else { |
| 1227 | ALOGI("VM exiting with result code %d.", code); |
| 1228 | onExit(code); |
| 1229 | ::exit(code); |
| 1230 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1231 | } |
| 1232 | |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 1233 | void AndroidRuntime::onVmCreated(JNIEnv* env) |
| 1234 | { |
| 1235 | // If AndroidRuntime had anything to do here, we'd have done it in 'start'. |
| 1236 | } |
| 1237 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1238 | /* |
Andreas Huber | 9ae000c | 2014-02-13 17:22:33 +0000 | [diff] [blame] | 1239 | * Get the JNIEnv pointer for this thread. |
| 1240 | * |
| 1241 | * Returns NULL if the slot wasn't allocated or populated. |
| 1242 | */ |
| 1243 | /*static*/ JNIEnv* AndroidRuntime::getJNIEnv() |
| 1244 | { |
| 1245 | JNIEnv* env; |
| 1246 | JavaVM* vm = AndroidRuntime::getJavaVM(); |
| 1247 | assert(vm != NULL); |
| 1248 | |
| 1249 | if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) |
| 1250 | return NULL; |
| 1251 | return env; |
| 1252 | } |
| 1253 | |
| 1254 | /* |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1255 | * Makes the current thread visible to the VM. |
| 1256 | * |
| 1257 | * The JNIEnv pointer returned is only valid for the current thread, and |
| 1258 | * thus must be tucked into thread-local storage. |
| 1259 | */ |
| 1260 | static int javaAttachThread(const char* threadName, JNIEnv** pEnv) |
| 1261 | { |
| 1262 | JavaVMAttachArgs args; |
| 1263 | JavaVM* vm; |
| 1264 | jint result; |
| 1265 | |
| 1266 | vm = AndroidRuntime::getJavaVM(); |
| 1267 | assert(vm != NULL); |
| 1268 | |
| 1269 | args.version = JNI_VERSION_1_4; |
| 1270 | args.name = (char*) threadName; |
| 1271 | args.group = NULL; |
| 1272 | |
| 1273 | result = vm->AttachCurrentThread(pEnv, (void*) &args); |
| 1274 | if (result != JNI_OK) |
Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 1275 | ALOGI("NOTE: attach of thread '%s' failed\n", threadName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1276 | |
| 1277 | return result; |
| 1278 | } |
| 1279 | |
| 1280 | /* |
| 1281 | * Detach the current thread from the set visible to the VM. |
| 1282 | */ |
| 1283 | static int javaDetachThread(void) |
| 1284 | { |
| 1285 | JavaVM* vm; |
| 1286 | jint result; |
| 1287 | |
| 1288 | vm = AndroidRuntime::getJavaVM(); |
| 1289 | assert(vm != NULL); |
| 1290 | |
| 1291 | result = vm->DetachCurrentThread(); |
| 1292 | if (result != JNI_OK) |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1293 | ALOGE("ERROR: thread detach failed\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1294 | return result; |
| 1295 | } |
| 1296 | |
| 1297 | /* |
| 1298 | * When starting a native thread that will be visible from the VM, we |
| 1299 | * bounce through this to get the right attach/detach action. |
| 1300 | * Note that this function calls free(args) |
| 1301 | */ |
| 1302 | /*static*/ int AndroidRuntime::javaThreadShell(void* args) { |
| 1303 | void* start = ((void**)args)[0]; |
| 1304 | void* userData = ((void **)args)[1]; |
| 1305 | char* name = (char*) ((void **)args)[2]; // we own this storage |
| 1306 | free(args); |
| 1307 | JNIEnv* env; |
| 1308 | int result; |
| 1309 | |
| 1310 | /* hook us into the VM */ |
| 1311 | if (javaAttachThread(name, &env) != JNI_OK) |
| 1312 | return -1; |
| 1313 | |
| 1314 | /* start the thread running */ |
| 1315 | result = (*(android_thread_func_t)start)(userData); |
| 1316 | |
| 1317 | /* unhook us */ |
| 1318 | javaDetachThread(); |
| 1319 | free(name); |
| 1320 | |
| 1321 | return result; |
| 1322 | } |
| 1323 | |
| 1324 | /* |
| 1325 | * This is invoked from androidCreateThreadEtc() via the callback |
| 1326 | * set with androidSetCreateThreadFunc(). |
| 1327 | * |
| 1328 | * We need to create the new thread in such a way that it gets hooked |
| 1329 | * into the VM before it really starts executing. |
| 1330 | */ |
| 1331 | /*static*/ int AndroidRuntime::javaCreateThreadEtc( |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 1332 | android_thread_func_t entryFunction, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1333 | void* userData, |
| 1334 | const char* threadName, |
| 1335 | int32_t threadPriority, |
| 1336 | size_t threadStackSize, |
| 1337 | android_thread_id_t* threadId) |
| 1338 | { |
| 1339 | void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free |
| 1340 | int result; |
| 1341 | |
Brian Carlstrom | 66f4831 | 2016-03-12 16:07:48 -0800 | [diff] [blame] | 1342 | LOG_ALWAYS_FATAL_IF(threadName == nullptr, "threadName not provided to javaCreateThreadEtc"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1343 | |
| 1344 | args[0] = (void*) entryFunction; |
| 1345 | args[1] = userData; |
| 1346 | args[2] = (void*) strdup(threadName); // javaThreadShell must free |
| 1347 | |
| 1348 | result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args, |
| 1349 | threadName, threadPriority, threadStackSize, threadId); |
| 1350 | return result; |
| 1351 | } |
| 1352 | |
| 1353 | /* |
| 1354 | * Create a thread that is visible from the VM. |
| 1355 | * |
| 1356 | * This is called from elsewhere in the library. |
| 1357 | */ |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 1358 | /*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1359 | void (*start)(void *), void* arg) |
| 1360 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 1361 | android_thread_id_t threadId = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1362 | javaCreateThreadEtc((android_thread_func_t) start, arg, name, |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 1363 | ANDROID_PRIORITY_DEFAULT, 0, &threadId); |
| 1364 | return threadId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | #if 0 |
| 1368 | static void quickTest(void* arg) |
| 1369 | { |
| 1370 | const char* str = (const char*) arg; |
| 1371 | |
| 1372 | printf("In quickTest: %s\n", str); |
| 1373 | } |
| 1374 | #endif |
| 1375 | |
| 1376 | #ifdef NDEBUG |
| 1377 | #define REG_JNI(name) { name } |
| 1378 | struct RegJNIRec { |
| 1379 | int (*mProc)(JNIEnv*); |
| 1380 | }; |
| 1381 | #else |
| 1382 | #define REG_JNI(name) { name, #name } |
| 1383 | struct RegJNIRec { |
| 1384 | int (*mProc)(JNIEnv*); |
| 1385 | const char* mName; |
| 1386 | }; |
| 1387 | #endif |
| 1388 | |
| 1389 | typedef void (*RegJAMProc)(); |
| 1390 | |
| 1391 | static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env) |
| 1392 | { |
| 1393 | for (size_t i = 0; i < count; i++) { |
| 1394 | if (array[i].mProc(env) < 0) { |
| 1395 | #ifndef NDEBUG |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1396 | ALOGD("----------!!! %s failed to load\n", array[i].mName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1397 | #endif |
| 1398 | return -1; |
| 1399 | } |
| 1400 | } |
| 1401 | return 0; |
| 1402 | } |
| 1403 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1404 | static const RegJNIRec gRegJNI[] = { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1405 | REG_JNI(register_com_android_internal_os_RuntimeInit), |
Jesse Hall | 1fe1dc0 | 2017-07-06 15:30:39 -0700 | [diff] [blame] | 1406 | REG_JNI(register_com_android_internal_os_ZygoteInit_nativeZygoteInit), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1407 | REG_JNI(register_android_os_SystemClock), |
| 1408 | REG_JNI(register_android_util_EventLog), |
| 1409 | REG_JNI(register_android_util_Log), |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1410 | REG_JNI(register_android_util_MemoryIntArray), |
Doris Liu | cdd23f9 | 2015-11-11 14:31:13 -0800 | [diff] [blame] | 1411 | REG_JNI(register_android_util_PathParser), |
Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 1412 | REG_JNI(register_android_util_StatsLog), |
Tej Singh | be0482b | 2019-03-19 22:01:57 -0700 | [diff] [blame] | 1413 | REG_JNI(register_android_util_StatsLogInternal), |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 1414 | REG_JNI(register_android_app_admin_SecurityLog), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1415 | REG_JNI(register_android_content_AssetManager), |
| 1416 | REG_JNI(register_android_content_StringBlock), |
| 1417 | REG_JNI(register_android_content_XmlBlock), |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1418 | REG_JNI(register_android_content_res_ApkAssets), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1419 | REG_JNI(register_android_text_AndroidCharacter), |
Seigo Nonaka | 44a1df2 | 2017-08-31 18:22:38 -0700 | [diff] [blame] | 1420 | REG_JNI(register_android_text_Hyphenator), |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1421 | REG_JNI(register_android_view_InputDevice), |
| 1422 | REG_JNI(register_android_view_KeyCharacterMap), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1423 | REG_JNI(register_android_os_Process), |
Andreas Huber | a8079bf | 2010-11-16 14:40:31 -0800 | [diff] [blame] | 1424 | REG_JNI(register_android_os_SystemProperties), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1425 | REG_JNI(register_android_os_Binder), |
Jeff Sharkey | d84e1ce | 2012-03-06 18:26:19 -0800 | [diff] [blame] | 1426 | REG_JNI(register_android_os_Parcel), |
Yifan Hong | bb0bd00 | 2017-11-14 16:14:04 -0800 | [diff] [blame] | 1427 | REG_JNI(register_android_os_HidlSupport), |
Andreas Huber | c0b6c53 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 1428 | REG_JNI(register_android_os_HwBinder), |
Andreas Huber | dc26321 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 1429 | REG_JNI(register_android_os_HwBlob), |
Andreas Huber | c0b6c53 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 1430 | REG_JNI(register_android_os_HwParcel), |
| 1431 | REG_JNI(register_android_os_HwRemoteBinder), |
Nirav Atre | 9850dd9 | 2018-07-24 17:03:44 -0700 | [diff] [blame] | 1432 | REG_JNI(register_android_os_NativeHandle), |
Yifan Hong | becc56d | 2017-04-05 14:42:05 -0700 | [diff] [blame] | 1433 | REG_JNI(register_android_os_VintfObject), |
Yifan Hong | 1bda673 | 2017-04-26 11:38:01 -0700 | [diff] [blame] | 1434 | REG_JNI(register_android_os_VintfRuntimeInfo), |
Richard Uhler | 775873a | 2015-12-29 12:37:39 -0800 | [diff] [blame] | 1435 | REG_JNI(register_android_graphics_Canvas), |
Leon Scroggins III | 0e443d1 | 2018-12-19 11:38:35 -0500 | [diff] [blame] | 1436 | // This needs to be before register_android_graphics_Graphics, or the latter |
| 1437 | // will not be able to find the jmethodID for ColorSpace.get(). |
| 1438 | REG_JNI(register_android_graphics_ColorSpace), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1439 | REG_JNI(register_android_graphics_Graphics), |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 1440 | REG_JNI(register_android_view_DisplayEventReceiver), |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 1441 | REG_JNI(register_android_view_RenderNode), |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 1442 | REG_JNI(register_android_view_RenderNodeAnimator), |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 1443 | REG_JNI(register_android_view_DisplayListCanvas), |
Riddle Hsu | cd958bc | 2019-01-23 15:40:26 +0800 | [diff] [blame] | 1444 | REG_JNI(register_android_view_InputApplicationHandle), |
| 1445 | REG_JNI(register_android_view_InputWindowHandle), |
John Reck | 9d8d99d | 2018-02-21 12:55:41 -0800 | [diff] [blame] | 1446 | REG_JNI(register_android_view_TextureLayer), |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 1447 | REG_JNI(register_android_view_ThreadedRenderer), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1448 | REG_JNI(register_android_view_Surface), |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1449 | REG_JNI(register_android_view_SurfaceControl), |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 1450 | REG_JNI(register_android_view_SurfaceSession), |
Adrian Roos | 9b963d3 | 2019-02-13 18:39:36 +0000 | [diff] [blame] | 1451 | REG_JNI(register_android_view_CompositionSamplingListener), |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 1452 | REG_JNI(register_android_view_TextureView), |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 1453 | REG_JNI(register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1454 | REG_JNI(register_com_google_android_gles_jni_EGLImpl), |
| 1455 | REG_JNI(register_com_google_android_gles_jni_GLImpl), |
Thomas Tafertshofer | 6b1e838 | 2012-07-03 13:37:35 -0700 | [diff] [blame] | 1456 | REG_JNI(register_android_opengl_jni_EGL14), |
Courtney Goeltzenleuchter | 367ed8b | 2018-07-18 10:45:37 -0600 | [diff] [blame] | 1457 | REG_JNI(register_android_opengl_jni_EGL15), |
Jesse Hall | 237c2b8 | 2013-05-06 11:36:57 -0700 | [diff] [blame] | 1458 | REG_JNI(register_android_opengl_jni_EGLExt), |
Jack Palevich | 1c4907e | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 1459 | REG_JNI(register_android_opengl_jni_GLES10), |
| 1460 | REG_JNI(register_android_opengl_jni_GLES10Ext), |
| 1461 | REG_JNI(register_android_opengl_jni_GLES11), |
| 1462 | REG_JNI(register_android_opengl_jni_GLES11Ext), |
Jack Palevich | 560814f | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 1463 | REG_JNI(register_android_opengl_jni_GLES20), |
Jesse Hall | d877efe | 2013-04-29 15:59:35 -0700 | [diff] [blame] | 1464 | REG_JNI(register_android_opengl_jni_GLES30), |
Jesse Hall | 7ab63ac | 2014-05-19 15:13:41 -0700 | [diff] [blame] | 1465 | REG_JNI(register_android_opengl_jni_GLES31), |
| 1466 | REG_JNI(register_android_opengl_jni_GLES31Ext), |
Pablo Ceballos | 38c1a7e | 2015-10-30 10:34:30 -0700 | [diff] [blame] | 1467 | REG_JNI(register_android_opengl_jni_GLES32), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1468 | |
| 1469 | REG_JNI(register_android_graphics_Bitmap), |
| 1470 | REG_JNI(register_android_graphics_BitmapFactory), |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 1471 | REG_JNI(register_android_graphics_BitmapRegionDecoder), |
Leon Scroggins III | 0c01dbf | 2017-10-20 14:08:11 -0400 | [diff] [blame] | 1472 | REG_JNI(register_android_graphics_ByteBufferStreamAdaptor), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1473 | REG_JNI(register_android_graphics_Camera), |
Leon Scroggins III | d0d7eaf | 2013-09-06 16:46:57 -0400 | [diff] [blame] | 1474 | REG_JNI(register_android_graphics_CreateJavaOutputStreamAdaptor), |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 1475 | REG_JNI(register_android_graphics_CanvasProperty), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1476 | REG_JNI(register_android_graphics_ColorFilter), |
| 1477 | REG_JNI(register_android_graphics_DrawFilter), |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 1478 | REG_JNI(register_android_graphics_FontFamily), |
sergeyv | 0a0f231 | 2017-01-04 13:58:52 -0800 | [diff] [blame] | 1479 | REG_JNI(register_android_graphics_GraphicBuffer), |
Leon Scroggins III | 0c01dbf | 2017-10-20 14:08:11 -0400 | [diff] [blame] | 1480 | REG_JNI(register_android_graphics_ImageDecoder), |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 1481 | REG_JNI(register_android_graphics_drawable_AnimatedImageDrawable), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1482 | REG_JNI(register_android_graphics_Interpolator), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1483 | REG_JNI(register_android_graphics_MaskFilter), |
| 1484 | REG_JNI(register_android_graphics_Matrix), |
| 1485 | REG_JNI(register_android_graphics_Movie), |
| 1486 | REG_JNI(register_android_graphics_NinePatch), |
| 1487 | REG_JNI(register_android_graphics_Paint), |
| 1488 | REG_JNI(register_android_graphics_Path), |
| 1489 | REG_JNI(register_android_graphics_PathMeasure), |
| 1490 | REG_JNI(register_android_graphics_PathEffect), |
| 1491 | REG_JNI(register_android_graphics_Picture), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1492 | REG_JNI(register_android_graphics_Region), |
| 1493 | REG_JNI(register_android_graphics_Shader), |
Jamie Gennis | aa0ce33 | 2011-01-06 17:04:26 -0800 | [diff] [blame] | 1494 | REG_JNI(register_android_graphics_SurfaceTexture), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | REG_JNI(register_android_graphics_Typeface), |
Wei-Ta Chen | bca2d61 | 2009-11-30 17:52:05 +0800 | [diff] [blame] | 1496 | REG_JNI(register_android_graphics_YuvImage), |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 1497 | REG_JNI(register_android_graphics_drawable_AnimatedVectorDrawable), |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 1498 | REG_JNI(register_android_graphics_drawable_VectorDrawable), |
Seigo Nonaka | a1c21c0 | 2018-07-20 15:57:39 -0700 | [diff] [blame] | 1499 | REG_JNI(register_android_graphics_fonts_Font), |
Seigo Nonaka | 88930f1 | 2018-07-24 17:09:23 -0700 | [diff] [blame] | 1500 | REG_JNI(register_android_graphics_fonts_FontFamily), |
Svetoslav | 6811f4e | 2013-09-18 15:58:28 -0700 | [diff] [blame] | 1501 | REG_JNI(register_android_graphics_pdf_PdfDocument), |
Svetoslav | 62ce332 | 2014-09-04 21:17:17 -0700 | [diff] [blame] | 1502 | REG_JNI(register_android_graphics_pdf_PdfEditor), |
Svetoslav | 2961769 | 2014-04-24 18:40:42 -0700 | [diff] [blame] | 1503 | REG_JNI(register_android_graphics_pdf_PdfRenderer), |
Seigo Nonaka | 70200b0 | 2018-10-01 16:04:11 -0700 | [diff] [blame] | 1504 | REG_JNI(register_android_graphics_text_MeasuredText), |
| 1505 | REG_JNI(register_android_graphics_text_LineBreaker), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1506 | |
| 1507 | REG_JNI(register_android_database_CursorWindow), |
Jeff Brown | e5360fb | 2011-10-31 17:48:13 -0700 | [diff] [blame] | 1508 | REG_JNI(register_android_database_SQLiteConnection), |
| 1509 | REG_JNI(register_android_database_SQLiteGlobal), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1510 | REG_JNI(register_android_database_SQLiteDebug), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1511 | REG_JNI(register_android_os_Debug), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1512 | REG_JNI(register_android_os_FileObserver), |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 1513 | REG_JNI(register_android_os_GraphicsEnvironment), |
Christopher Tate | fa9e7c0 | 2010-05-06 12:07:10 -0700 | [diff] [blame] | 1514 | REG_JNI(register_android_os_MessageQueue), |
Stephen Smalley | c07fca3 | 2012-01-13 08:31:39 -0500 | [diff] [blame] | 1515 | REG_JNI(register_android_os_SELinux), |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 1516 | REG_JNI(register_android_os_Trace), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1517 | REG_JNI(register_android_os_UEventObserver), |
| 1518 | REG_JNI(register_android_net_LocalSocketImpl), |
| 1519 | REG_JNI(register_android_net_NetworkUtils), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1520 | REG_JNI(register_android_os_MemoryFile), |
John Reck | dea6a02 | 2017-05-25 17:09:33 -0700 | [diff] [blame] | 1521 | REG_JNI(register_android_os_SharedMemory), |
Narayan Kamath | f9419f0 | 2017-06-15 11:35:38 +0100 | [diff] [blame] | 1522 | REG_JNI(register_com_android_internal_os_ClassLoaderFactory), |
Narayan Kamath | 973b466 | 2014-03-31 13:41:26 +0100 | [diff] [blame] | 1523 | REG_JNI(register_com_android_internal_os_Zygote), |
Jesse Hall | 1fe1dc0 | 2017-07-06 15:30:39 -0700 | [diff] [blame] | 1524 | REG_JNI(register_com_android_internal_os_ZygoteInit), |
John Reck | 9fa4071 | 2014-05-09 15:26:59 -0700 | [diff] [blame] | 1525 | REG_JNI(register_com_android_internal_util_VirtualRefBasePtr), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1526 | REG_JNI(register_android_hardware_Camera), |
Eino-Ville Talvala | 2f1a2e4 | 2013-07-25 17:12:05 -0700 | [diff] [blame] | 1527 | REG_JNI(register_android_hardware_camera2_CameraMetadata), |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 1528 | REG_JNI(register_android_hardware_camera2_legacy_LegacyCameraDevice), |
Eino-Ville Talvala | e1f57d6 | 2014-05-29 17:17:07 -0700 | [diff] [blame] | 1529 | REG_JNI(register_android_hardware_camera2_legacy_PerfMeasurement), |
Ruben Brunk | b607900 | 2014-05-22 12:33:54 -0700 | [diff] [blame] | 1530 | REG_JNI(register_android_hardware_camera2_DngCreator), |
Craig Donner | 1a4d07d | 2017-01-09 13:01:22 -0800 | [diff] [blame] | 1531 | REG_JNI(register_android_hardware_HardwareBuffer), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1532 | REG_JNI(register_android_hardware_SensorManager), |
Mike Lockwood | b01e8bf | 2011-08-29 20:11:07 -0400 | [diff] [blame] | 1533 | REG_JNI(register_android_hardware_SerialPort), |
Eric Laurent | 60b62bc | 2014-04-18 17:50:49 -0700 | [diff] [blame] | 1534 | REG_JNI(register_android_hardware_SoundTrigger), |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 1535 | REG_JNI(register_android_hardware_UsbDevice), |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 1536 | REG_JNI(register_android_hardware_UsbDeviceConnection), |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 1537 | REG_JNI(register_android_hardware_UsbRequest), |
Brian Duddie | cfa5b5b | 2019-01-22 18:01:40 +0000 | [diff] [blame] | 1538 | REG_JNI(register_android_hardware_location_ActivityRecognitionHardware), |
Eric Laurent | 7c31847e | 2018-11-29 14:33:56 -0800 | [diff] [blame] | 1539 | REG_JNI(register_android_media_AudioEffectDescriptor), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1540 | REG_JNI(register_android_media_AudioSystem), |
Paul McLean | b3ae6d9 | 2018-11-05 15:16:59 -0700 | [diff] [blame] | 1541 | REG_JNI(register_android_media_AudioRecord), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1542 | REG_JNI(register_android_media_AudioTrack), |
François Gaffie | b469128 | 2018-07-09 13:07:32 +0200 | [diff] [blame] | 1543 | REG_JNI(register_android_media_AudioAttributes), |
François Gaffie | c01fa3a | 2018-03-15 14:33:24 +0100 | [diff] [blame] | 1544 | REG_JNI(register_android_media_AudioProductStrategies), |
François Gaffie | adcd00a | 2018-09-18 17:06:26 +0200 | [diff] [blame] | 1545 | REG_JNI(register_android_media_AudioVolumeGroups), |
| 1546 | REG_JNI(register_android_media_AudioVolumeGroupChangeHandler), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1547 | REG_JNI(register_android_media_JetPlayer), |
jiabin | c0f4944 | 2018-01-05 10:23:50 -0800 | [diff] [blame] | 1548 | REG_JNI(register_android_media_MicrophoneInfo), |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 1549 | REG_JNI(register_android_media_RemoteDisplay), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1550 | REG_JNI(register_android_media_ToneGenerator), |
Paul McLean | 84b49130 | 2018-05-09 10:03:57 -0600 | [diff] [blame] | 1551 | REG_JNI(register_android_media_midi), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1552 | |
| 1553 | REG_JNI(register_android_opengl_classes), |
JP Abgrall | 98a4f7e | 2011-09-02 15:36:33 -0700 | [diff] [blame] | 1554 | REG_JNI(register_android_server_NetworkManagementSocketTagger), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1555 | REG_JNI(register_android_ddm_DdmHandleNativeHeap), |
Joe Onorato | 1cf5874 | 2009-06-12 11:06:24 -0700 | [diff] [blame] | 1556 | REG_JNI(register_android_backup_BackupDataInput), |
Joe Onorato | d2110db | 2009-05-19 13:41:21 -0700 | [diff] [blame] | 1557 | REG_JNI(register_android_backup_BackupDataOutput), |
Joe Onorato | 06290a4 | 2009-06-18 20:10:37 -0700 | [diff] [blame] | 1558 | REG_JNI(register_android_backup_FileBackupHelperBase), |
Joe Onorato | 4ababd9 | 2009-06-25 18:29:18 -0400 | [diff] [blame] | 1559 | REG_JNI(register_android_backup_BackupHelperDispatcher), |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 1560 | REG_JNI(register_android_app_backup_FullBackup), |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 1561 | REG_JNI(register_android_app_Activity), |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1562 | REG_JNI(register_android_app_ActivityThread), |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 1563 | REG_JNI(register_android_app_NativeActivity), |
Przemyslaw Szczepaniak | 8a7c160 | 2015-11-03 09:47:56 +0000 | [diff] [blame] | 1564 | REG_JNI(register_android_util_jar_StrictJarFile), |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1565 | REG_JNI(register_android_view_InputChannel), |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 1566 | REG_JNI(register_android_view_InputEventReceiver), |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1567 | REG_JNI(register_android_view_InputEventSender), |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 1568 | REG_JNI(register_android_view_InputQueue), |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1569 | REG_JNI(register_android_view_KeyEvent), |
| 1570 | REG_JNI(register_android_view_MotionEvent), |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 1571 | REG_JNI(register_android_view_PointerIcon), |
Jeff Brown | 2ed2462 | 2011-03-14 19:39:54 -0700 | [diff] [blame] | 1572 | REG_JNI(register_android_view_VelocityTracker), |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 1573 | |
| 1574 | REG_JNI(register_android_content_res_ObbScanner), |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 1575 | REG_JNI(register_android_content_res_Configuration), |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 1576 | |
| 1577 | REG_JNI(register_android_animation_PropertyValuesHolder), |
Bo Zhu | 0985613 | 2018-04-01 12:24:09 -0700 | [diff] [blame] | 1578 | REG_JNI(register_android_security_Scrypt), |
Kenny Root | 66269ea | 2011-07-12 14:14:01 -0700 | [diff] [blame] | 1579 | REG_JNI(register_com_android_internal_content_NativeLibraryHelper), |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 1580 | REG_JNI(register_com_android_internal_os_AtomicDirectory), |
Daichi Hirono | 878e86f | 2016-10-31 09:33:30 +0900 | [diff] [blame] | 1581 | REG_JNI(register_com_android_internal_os_FuseAppLoop), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1582 | }; |
| 1583 | |
| 1584 | /* |
| 1585 | * Register android native functions with the VM. |
| 1586 | */ |
| 1587 | /*static*/ int AndroidRuntime::startReg(JNIEnv* env) |
| 1588 | { |
Yasuhiro Matsuda | 1ab43d5 | 2015-06-30 17:07:32 +0900 | [diff] [blame] | 1589 | ATRACE_NAME("RegisterAndroidNatives"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1590 | /* |
| 1591 | * This hook causes all future threads created in this process to be |
| 1592 | * attached to the JavaVM. (This needs to go away in favor of JNI |
| 1593 | * Attach calls.) |
| 1594 | */ |
| 1595 | androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc); |
| 1596 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1597 | ALOGV("--- registering native functions ---\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1598 | |
| 1599 | /* |
| 1600 | * Every "register" function calls one or more things that return |
| 1601 | * a local reference (e.g. FindClass). Because we haven't really |
| 1602 | * started the VM yet, they're all getting stored in the base frame |
| 1603 | * and never released. Use Push/Pop to manage the storage. |
| 1604 | */ |
| 1605 | env->PushLocalFrame(200); |
| 1606 | |
| 1607 | if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) { |
| 1608 | env->PopLocalFrame(NULL); |
| 1609 | return -1; |
| 1610 | } |
| 1611 | env->PopLocalFrame(NULL); |
| 1612 | |
| 1613 | //createJavaThread("fubar", quickTest, (void*) "hello"); |
| 1614 | |
| 1615 | return 0; |
| 1616 | } |
| 1617 | |
| 1618 | AndroidRuntime* AndroidRuntime::getRuntime() |
| 1619 | { |
| 1620 | return gCurRuntime; |
| 1621 | } |
| 1622 | |
| 1623 | /** |
Narayan Kamath | c21dab9 | 2015-06-25 14:22:00 +0100 | [diff] [blame] | 1624 | * Used by surface flinger's DdmConnection to register native methods from |
| 1625 | * the framework. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1626 | */ |
Narayan Kamath | c21dab9 | 2015-06-25 14:22:00 +0100 | [diff] [blame] | 1627 | extern "C" jint registerFrameworkNatives(JNIEnv* env) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1628 | return register_jni_procs(gRegJNI, NELEM(gRegJNI), env); |
| 1629 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1630 | } // namespace android |