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