Index: runtime/vm/profiler.cc |
diff --git a/runtime/vm/profiler.cc b/runtime/vm/profiler.cc |
index da856e2844ba9f3dd8efcd6f961407a9533460b5..b416aeb5095f7de3cee46e1c4e3a521c57c5e33a 100644 |
--- a/runtime/vm/profiler.cc |
+++ b/runtime/vm/profiler.cc |
@@ -129,16 +129,29 @@ uword* Sample::GetPCArray() const { |
SampleBuffer::SampleBuffer(intptr_t capacity) { |
ASSERT(Sample::instance_size() > 0); |
- samples_ = |
- reinterpret_cast<Sample*>(calloc(capacity, Sample::instance_size())); |
+ |
+ const intptr_t size = Utils::RoundUp(capacity * Sample::instance_size(), |
+ VirtualMemory::PageSize()); |
+ const bool kNotExecutable = false; |
+ memory_ = VirtualMemory::Reserve(size); |
+ if ((memory_ == NULL) || !memory_->Commit(kNotExecutable, "dart-profiler")) { |
+ OUT_OF_MEMORY(); |
+ } |
+ |
+ samples_ = reinterpret_cast<Sample*>(memory_->address()); |
+ capacity_ = capacity; |
+ cursor_ = 0; |
+ |
if (FLAG_trace_profiler) { |
OS::Print("Profiler holds %" Pd " samples\n", capacity); |
OS::Print("Profiler sample is %" Pd " bytes\n", Sample::instance_size()); |
- OS::Print("Profiler memory usage = %" Pd " bytes\n", |
- capacity * Sample::instance_size()); |
+ OS::Print("Profiler memory usage = %" Pd " bytes\n", size); |
} |
- capacity_ = capacity; |
- cursor_ = 0; |
+} |
+ |
+ |
+SampleBuffer::~SampleBuffer() { |
+ delete memory_; |
} |