summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Tim Murray <timmurray@google.com> 2021-01-25 15:25:08 -0800
committer Tim Murray <timmurray@google.com> 2021-01-27 15:39:45 -0800
commit5ccd04c3e074d0f676a1b7cb31f579c1359f76c4 (patch)
treea667525c5aa299f8e7200fd7bd7e9683fd8b5797
parente7ce67f421730938e26abce67fa09e411a8549d4 (diff)
DynamicCodeLoggingService: avoid object churn
Recreating Matchers seems to incur a large memory cost until GC. Reuse the Matcher and reset it to avoid the worst of this. Test: atest DynamicCodeLoggerIntegrationTests Bug: 178402808 Change-Id: I959a5a6eb92366495cf343116636703d1e752742
-rw-r--r--services/core/java/com/android/server/pm/DynamicCodeLoggingService.java6
1 files changed, 4 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/pm/DynamicCodeLoggingService.java b/services/core/java/com/android/server/pm/DynamicCodeLoggingService.java
index da65fe2bc0ab..c65c2b112706 100644
--- a/services/core/java/com/android/server/pm/DynamicCodeLoggingService.java
+++ b/services/core/java/com/android/server/pm/DynamicCodeLoggingService.java
@@ -234,7 +234,7 @@ public class DynamicCodeLoggingService extends JobService {
List<EventLog.Event> events = new ArrayList<>();
EventLog.readEvents(tags, events);
-
+ Matcher matcher = EXECUTE_NATIVE_AUDIT_PATTERN.matcher("");
for (int i = 0; i < events.size(); ++i) {
if (mAuditWatchingStopRequested) {
Log.w(TAG, "Stopping AuditWatchingJob run at scheduler request");
@@ -259,7 +259,9 @@ public class DynamicCodeLoggingService extends JobService {
// And then use a regular expression to verify it's one of the messages we're
// interested in and to extract the path of the file being loaded.
- Matcher matcher = EXECUTE_NATIVE_AUDIT_PATTERN.matcher(message);
+ // Reuse the Matcher to avoid unnecessary string garbage caused by libcore's
+ // regex matching.
+ matcher.reset(message);
if (!matcher.matches()) {
continue;
}