summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Stefano Cianciulli <scianciulli@google.com> 2024-01-18 14:32:50 +0000
committer Stefano Cianciulli <scianciulli@google.com> 2024-01-23 17:40:13 +0000
commit828160aaf192ab7c60d0efd2811fb51c59b14efb (patch)
treed456347cd20db1e26eaf22d16c6bd902c6cf0863
parenta76fb27923650738acd7f26c35d19f88d7e33ee7 (diff)
Add the current GC in the dumpsys output
This CL surfaces the Garbage Collector currently in use in the Android Runtime in the output for the 'adb dumpsys package dexopt' command, for debugging purposes. Bug: 320283802 Test: atest art_standalone_libartservice_tests Test: atest ArtServiceTests Test: adb shell dumpsys package dexopt (to contain the current GC) Test: adb shell dumpsys package com.android.bluetooth (to not contain the current GC) Test: adb shell pm art dump (to contain the current GC) Test: adb shell pm art dump com.android.bluetooth (to not contain the current GC) (cherry picked from https://android-review.googlesource.com/q/commit:0c36cea9ffc17d0fbdb3797917b095818ca15973) Merged-In: Idce3e11c79c8e28ea1c17c184756c052c69a1fe5 Change-Id: Idce3e11c79c8e28ea1c17c184756c052c69a1fe5
-rw-r--r--libartservice/service/java/com/android/server/art/ArtJni.java9
-rw-r--r--libartservice/service/java/com/android/server/art/DumpHelper.java1
-rw-r--r--libartservice/service/javatests/com/android/server/art/DumpHelperTest.java8
-rw-r--r--libartservice/service/native/service.cc11
-rw-r--r--libartservice/service/native/service.h2
-rw-r--r--libartservice/service/native/service_test.cc7
-rw-r--r--runtime/gc/heap.cc24
-rw-r--r--runtime/gc/heap.h1
8 files changed, 53 insertions, 10 deletions
diff --git a/libartservice/service/java/com/android/server/art/ArtJni.java b/libartservice/service/java/com/android/server/art/ArtJni.java
index 2cc9ea8911..f2868eb0d2 100644
--- a/libartservice/service/java/com/android/server/art/ArtJni.java
+++ b/libartservice/service/java/com/android/server/art/ArtJni.java
@@ -56,8 +56,17 @@ public class ArtJni {
return validateClassLoaderContextNative(dexPath, classLoaderContext);
}
+ /**
+ * Returns the name of the Garbage Collector currently in use in the Android Runtime.
+ */
+ @NonNull
+ public static String getGarbageCollector() {
+ return getGarbageCollectorNative();
+ }
+
@Nullable private static native String validateDexPathNative(@NonNull String dexPath);
@Nullable
private static native String validateClassLoaderContextNative(
@NonNull String dexPath, @NonNull String classLoaderContext);
+ @NonNull private static native String getGarbageCollectorNative();
}
diff --git a/libartservice/service/java/com/android/server/art/DumpHelper.java b/libartservice/service/java/com/android/server/art/DumpHelper.java
index 2a640ec48d..70d7f8ce0f 100644
--- a/libartservice/service/java/com/android/server/art/DumpHelper.java
+++ b/libartservice/service/java/com/android/server/art/DumpHelper.java
@@ -75,6 +75,7 @@ public class DumpHelper {
.stream()
.sorted(Comparator.comparing(PackageState::getPackageName))
.forEach(pkgState -> dumpPackage(pw, snapshot, pkgState));
+ pw.printf("\nCurrent GC: %s\n", ArtJni.getGarbageCollector());
}
/**
diff --git a/libartservice/service/javatests/com/android/server/art/DumpHelperTest.java b/libartservice/service/javatests/com/android/server/art/DumpHelperTest.java
index 3833249cb9..5dbe2137a9 100644
--- a/libartservice/service/javatests/com/android/server/art/DumpHelperTest.java
+++ b/libartservice/service/javatests/com/android/server/art/DumpHelperTest.java
@@ -62,7 +62,7 @@ public class DumpHelperTest {
@Rule
public StaticMockitoRule mockitoRule =
- new StaticMockitoRule(SystemProperties.class, Constants.class);
+ new StaticMockitoRule(SystemProperties.class, Constants.class, ArtJni.class);
@Mock private DumpHelper.Injector mInjector;
@Mock private ArtManagerLocal mArtManagerLocal;
@@ -83,6 +83,8 @@ public class DumpHelperTest {
.when(SystemProperties.get(argThat(arg -> arg.startsWith("ro.dalvik.vm.isa."))))
.thenReturn("");
+ lenient().when(ArtJni.getGarbageCollector()).thenReturn("CollectorTypeCMC");
+
lenient().when(mInjector.getArtManagerLocal()).thenReturn(mArtManagerLocal);
lenient().when(mInjector.getDexUseManager()).thenReturn(mDexUseManagerLocal);
lenient().when(mInjector.getArtd()).thenReturn(mArtd);
@@ -132,7 +134,9 @@ public class DumpHelperTest {
+ " arm: [status=verify] [reason=install] [primary-abi]\n"
+ " [location is /data/app/bar/oat/arm/base.odex]\n"
+ " arm64: [status=verify] [reason=install]\n"
- + " [location is /data/app/bar/oat/arm64/base.odex]\n";
+ + " [location is /data/app/bar/oat/arm64/base.odex]\n"
+ + "\n"
+ + "Current GC: CollectorTypeCMC\n";
var stringWriter = new StringWriter();
mDumpHelper.dump(new PrintWriter(stringWriter), mSnapshot);
diff --git a/libartservice/service/native/service.cc b/libartservice/service/native/service.cc
index 7d223e5c35..5901efd9f6 100644
--- a/libartservice/service/native/service.cc
+++ b/libartservice/service/native/service.cc
@@ -24,7 +24,9 @@
#include "android-base/file.h"
#include "android-base/result.h"
#include "class_loader_context.h"
+#include "gc/heap.h"
#include "nativehelper/utils.h"
+#include "runtime.h"
namespace art {
namespace service {
@@ -76,6 +78,10 @@ Result<void> ValidateDexPath(const std::string& dex_path) {
return {};
}
+std::string GetGarbageCollector() {
+ return Runtime::Current()->GetHeap()->GetForegroundCollectorName();
+}
+
extern "C" JNIEXPORT jstring JNICALL
Java_com_android_server_art_ArtJni_validateDexPathNative(JNIEnv* env, jobject, jstring j_dex_path) {
std::string dex_path(GET_UTF_OR_RETURN(env, j_dex_path));
@@ -116,5 +122,10 @@ Java_com_android_server_art_ArtJni_validateClassLoaderContextNative(
return nullptr;
}
+extern "C" JNIEXPORT jstring JNICALL
+Java_com_android_server_art_ArtJni_getGarbageCollectorNative(JNIEnv* env, jobject) {
+ return CREATE_UTF_OR_RETURN(env, GetGarbageCollector()).release();
+}
+
} // namespace service
} // namespace art
diff --git a/libartservice/service/native/service.h b/libartservice/service/native/service.h
index 7f43f17f0b..85c7dcd39f 100644
--- a/libartservice/service/native/service.h
+++ b/libartservice/service/native/service.h
@@ -34,6 +34,8 @@ android::base::Result<void> ValidatePathElement(const std::string& path_element,
android::base::Result<void> ValidateDexPath(const std::string& dex_path);
+std::string GetGarbageCollector();
+
} // namespace service
} // namespace art
diff --git a/libartservice/service/native/service_test.cc b/libartservice/service/native/service_test.cc
index 8300bf5e76..d1d429edd7 100644
--- a/libartservice/service/native/service_test.cc
+++ b/libartservice/service/native/service_test.cc
@@ -17,6 +17,7 @@
#include "service.h"
#include "android-base/result-gmock.h"
+#include "common_runtime_test.h"
#include "gtest/gtest.h"
namespace art {
@@ -106,6 +107,12 @@ TEST_F(ArtServiceTest, ValidateDexPathNul) {
HasError(WithMessage("Path '/a/\0/b.apk' has invalid character '\\0'"s)));
}
+class ArtServiceGcTest : public CommonRuntimeTest {};
+
+TEST_F(ArtServiceGcTest, GetGarbageCollector) {
+ EXPECT_THAT(GetGarbageCollector(), testing::HasSubstr("CollectorType"));
+}
+
} // namespace
} // namespace service
} // namespace art
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 95c88c717f..ab82f14c53 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -16,20 +16,18 @@
#include "heap.h"
+#include <sys/types.h>
+#include <unistd.h>
+
#include <limits>
-#include "android-base/thread_annotations.h"
-#if defined(__BIONIC__) || defined(__GLIBC__) || defined(ANDROID_HOST_MUSL)
-#include <malloc.h> // For mallinfo()
-#endif
#include <memory>
#include <random>
-#include <unistd.h>
-#include <sys/types.h>
+#include <sstream>
#include <vector>
-#include "android-base/stringprintf.h"
-
#include "allocation_listener.h"
+#include "android-base/stringprintf.h"
+#include "android-base/thread_annotations.h"
#include "art_field-inl.h"
#include "backtrace_helper.h"
#include "base/allocator.h"
@@ -108,6 +106,10 @@
#include "verify_object-inl.h"
#include "well_known_classes.h"
+#if defined(__BIONIC__) || defined(__GLIBC__) || defined(ANDROID_HOST_MUSL)
+#include <malloc.h> // For mallinfo()
+#endif
+
namespace art {
#ifdef ART_TARGET_ANDROID
@@ -4758,5 +4760,11 @@ bool Heap::AddHeapTask(gc::HeapTask* task) {
return true;
}
+std::string Heap::GetForegroundCollectorName() {
+ std::ostringstream oss;
+ oss << foreground_collector_type_;
+ return oss.str();
+}
+
} // namespace gc
} // namespace art
diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h
index d7f6948b85..489be370ee 100644
--- a/runtime/gc/heap.h
+++ b/runtime/gc/heap.h
@@ -843,6 +843,7 @@ class Heap {
bool IsMovingGc() const { return IsMovingGc(CurrentCollectorType()); }
CollectorType GetForegroundCollectorType() const { return foreground_collector_type_; }
+ std::string GetForegroundCollectorName();
bool IsGcConcurrentAndMoving() const {
if (IsGcConcurrent() && IsMovingGc(collector_type_)) {