Debian Codegraph @

core/jni/AndroidRuntime.cpp

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