summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/trace.cc11
-rw-r--r--runtime/trace.h23
2 files changed, 7 insertions, 27 deletions
diff --git a/runtime/trace.cc b/runtime/trace.cc
index 3a0d7048d4..9ab268351d 100644
--- a/runtime/trace.cc
+++ b/runtime/trace.cc
@@ -757,7 +757,7 @@ Trace::Trace(File* trace_file,
}
static_assert(18 <= kMinBufSize, "Minimum buffer size not large enough for trace header");
- cur_offset_.store(kTraceHeaderLength, std::memory_order_relaxed);
+ cur_offset_ = kTraceHeaderLength;
if (output_mode == TraceOutputMode::kStreaming) {
// Flush the header information to the file. We use a per thread buffer, so
@@ -765,7 +765,7 @@ Trace::Trace(File* trace_file,
if (!trace_file_->WriteFully(buf_.get(), kTraceHeaderLength)) {
PLOG(WARNING) << "Failed streaming a tracing event.";
}
- cur_offset_.store(0, std::memory_order_relaxed);
+ cur_offset_ = 0;
}
// Thread index of 0 is a special identifier used to distinguish between trace
@@ -776,7 +776,8 @@ Trace::Trace(File* trace_file,
void Trace::FinishTracing() {
size_t final_offset = 0;
if (trace_output_mode_ != TraceOutputMode::kStreaming) {
- final_offset = cur_offset_.load(std::memory_order_relaxed);
+ MutexLock mu(Thread::Current(), tracing_lock_);
+ final_offset = cur_offset_;
}
// Compute elapsed time.
@@ -1069,7 +1070,7 @@ void Trace::FlushBuffer(Thread* thread) {
} else {
buffer_size = buffer_size_;
buffer_ptr = buf_.get();
- current_index = cur_offset_.load(std::memory_order_relaxed);
+ current_index = cur_offset_;
}
size_t num_entries = *(thread->GetMethodTraceIndexPtr());
@@ -1119,7 +1120,7 @@ void Trace::FlushBuffer(Thread* thread) {
} else {
// In non-streaming mode, we keep the data in the buffer and write to the
// file when tracing has stopped. Just updated the offset of the buffer.
- cur_offset_.store(current_index, std::memory_order_relaxed);
+ cur_offset_ = current_index;
}
}
diff --git a/runtime/trace.h b/runtime/trace.h
index 6eee9f9f78..7e62af4871 100644
--- a/runtime/trace.h
+++ b/runtime/trace.h
@@ -364,28 +364,7 @@ class Trace final : public instrumentation::InstrumentationListener {
// Clock overhead.
const uint32_t clock_overhead_ns_;
- // Offset into buf_. The field is atomic to allow multiple writers
- // to concurrently reserve space in the buffer. The newly written
- // buffer contents are not read without some other form of thread
- // synchronization, such as suspending all potential writers or
- // acquiring *tracing_lock_. Reading cur_offset_ is thus never
- // used to ensure visibility of any other objects, and all accesses
- // are memory_order_relaxed.
- //
- // All accesses to buf_ in streaming mode occur whilst holding the
- // streaming lock. In streaming mode, the buffer may be written out
- // so cur_offset_ can move forwards and backwards.
- //
- // When not in streaming mode, the buf_ writes can come from
- // multiple threads when the trace mode is kMethodTracing. When
- // trace mode is kSampling, writes only come from the sampling
- // thread.
- //
- // Reads to the buffer happen after the event sources writing to the
- // buffer have been shutdown and all stores have completed. The
- // stores are made visible in StopTracing() when execution leaves
- // the ScopedSuspendAll block.
- AtomicInteger cur_offset_;
+ size_t cur_offset_ GUARDED_BY(tracing_lock_);
// Did we overflow the buffer recording traces?
bool overflow_;