summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Mythri Alle <mythria@google.com> 2025-03-18 13:19:07 +0000
committer Mythri Alle <mythria@google.com> 2025-03-18 10:17:28 -0700
commit75cfb5844d61540495fa9a701b4e1db20e7515a0 (patch)
treef3cc7708abe69cb8baa0527114e0d5dd92fdf8f8
parent14c9edceee51cf1f4fb0b79b3f726e331051e673 (diff)
Fix iterating over long running method buffers when flushing
When iterating over the long running buffers, we used to use unsigned indices and the way the loop was written it was expecting signed values. The loop exit check expected -1 but for unsigned this doesn't work. Fixed the check to not expect -1 and also used signed index. Drive-by-fix: Use correct type for unique_ptr. Bug: 352518093 Test: Manual test Change-Id: I8461919d7c20e3d76fa9e10783f8dd1f7ef950e0
-rw-r--r--runtime/trace_profile.cc12
1 files changed, 6 insertions, 6 deletions
diff --git a/runtime/trace_profile.cc b/runtime/trace_profile.cc
index 6039cd999e..6eff2cdfe1 100644
--- a/runtime/trace_profile.cc
+++ b/runtime/trace_profile.cc
@@ -514,9 +514,9 @@ size_t TraceProfiler::DumpLongRunningMethodBuffer(uint32_t thread_id,
int num_records = 0;
uintptr_t prev_time_action_encoding = 0;
uintptr_t prev_method_ptr = 0;
- size_t end_index = end_trace_entries - method_trace_entries;
- for (size_t i = kAlwaysOnTraceBufSize - 1; i >= end_index;) {
- uintptr_t event = method_trace_entries[i--];
+ int64_t end_index = end_trace_entries - method_trace_entries;
+ for (int64_t i = kAlwaysOnTraceBufSize; i > end_index;) {
+ uintptr_t event = method_trace_entries[--i];
if (event == 0x1) {
// This is a placeholder event. Ignore this event.
continue;
@@ -531,7 +531,7 @@ size_t TraceProfiler::DumpLongRunningMethodBuffer(uint32_t thread_id,
} else {
// method entry
method_ptr = event;
- event_time = TimestampCounter::GetNanoTime(method_trace_entries[i--] & ~0x1);
+ event_time = TimestampCounter::GetNanoTime(method_trace_entries[--i] & ~0x1);
}
uint64_t time_action_encoding = event_time << 1;
@@ -590,7 +590,7 @@ void TraceProfiler::FlushBufferAndRecordTraceEvent(ArtMethod* method,
size_t num_occupied_entries = (processed_events_ptr - *method_trace_curr_ptr);
size_t index = kAlwaysOnTraceBufSize;
- std::unique_ptr<uint8_t> buffer_ptr(new uint8_t[kBufSizeForEncodedData]);
+ std::unique_ptr<uint8_t[]> buffer_ptr(new uint8_t[kBufSizeForEncodedData]);
size_t num_bytes;
if (num_occupied_entries > kMaxEntriesAfterFlush) {
// If we don't have sufficient space just record a placeholder exit and flush all the existing
@@ -659,7 +659,7 @@ void TraceDumpCheckpoint::Run(Thread* thread) {
std::unordered_set<ArtMethod*> traced_methods;
if (trace_data_->GetTraceType() == LowOverheadTraceType::kLongRunningMethods) {
uintptr_t* method_trace_curr_ptr = *(thread->GetTraceBufferCurrEntryPtr());
- std::unique_ptr<uint8_t> buffer_ptr(new uint8_t[kBufSizeForEncodedData]);
+ std::unique_ptr<uint8_t[]> buffer_ptr(new uint8_t[kBufSizeForEncodedData]);
size_t num_bytes = TraceProfiler::DumpLongRunningMethodBuffer(thread->GetTid(),
method_trace_entries,
method_trace_curr_ptr,