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