1 /*
2  * Copyright (C) 2018 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 #include "jni.h"
18 #include <nativehelper/JNIHelp.h>
19 
20 #include "core_jni_helpers.h"
21 #include <unistd.h>
22 
23 #include <bionic/malloc.h>
24 #include <android/graphics/renderthread.h>
25 
26 namespace android {
27 
android_app_ActivityThread_purgePendingResources(JNIEnv * env,jobject clazz)28 static void android_app_ActivityThread_purgePendingResources(JNIEnv* env, jobject clazz) {
29     // Don't care about return values.
30     mallopt(M_PURGE, 0);
31 }
32 
33 static void
android_app_ActivityThread_dumpGraphics(JNIEnv * env,jobject clazz,jobject javaFileDescriptor)34 android_app_ActivityThread_dumpGraphics(JNIEnv* env, jobject clazz, jobject javaFileDescriptor) {
35     int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor);
36     ARenderThread_dumpGraphicsMemory(fd);
37 }
38 
android_app_ActivityThread_initZygoteChildHeapProfiling(JNIEnv * env,jobject clazz)39 static void android_app_ActivityThread_initZygoteChildHeapProfiling(JNIEnv* env, jobject clazz) {
40     android_mallopt(M_INIT_ZYGOTE_CHILD_PROFILING, nullptr, 0);
41 }
42 
43 static JNINativeMethod gActivityThreadMethods[] = {
44     // ------------ Regular JNI ------------------
45     { "nPurgePendingResources",        "()V",
46       (void*) android_app_ActivityThread_purgePendingResources },
47     { "nDumpGraphicsInfo",        "(Ljava/io/FileDescriptor;)V",
48       (void*) android_app_ActivityThread_dumpGraphics },
49     { "nInitZygoteChildHeapProfiling",        "()V",
50       (void*) android_app_ActivityThread_initZygoteChildHeapProfiling }
51 };
52 
register_android_app_ActivityThread(JNIEnv * env)53 int register_android_app_ActivityThread(JNIEnv* env) {
54     return RegisterMethodsOrDie(env, "android/app/ActivityThread",
55             gActivityThreadMethods, NELEM(gActivityThreadMethods));
56 }
57 
58 };
59