Index: runtime/vm/heap.cc |
diff --git a/runtime/vm/heap.cc b/runtime/vm/heap.cc |
index 84f55df0d3f954157bc3432aa83bc725b0d63639..eb9dfcdb28e7fa850d9544864da3ff5e934db5d2 100644 |
--- a/runtime/vm/heap.cc |
+++ b/runtime/vm/heap.cc |
@@ -9,11 +9,13 @@ |
#include "vm/compiler_stats.h" |
#include "vm/flags.h" |
#include "vm/heap_profiler.h" |
+#include "vm/heap_trace.h" |
#include "vm/isolate.h" |
#include "vm/object.h" |
#include "vm/object_set.h" |
#include "vm/os.h" |
#include "vm/pages.h" |
+#include "vm/raw_object.h" |
#include "vm/scavenger.h" |
#include "vm/stack_frame.h" |
#include "vm/verifier.h" |
@@ -38,6 +40,7 @@ Heap::Heap() : read_only_(false) { |
(FLAG_new_gen_heap_size * MB), |
kNewObjectAlignmentOffset); |
old_space_ = new PageSpace(this, (FLAG_old_gen_heap_size * MB)); |
+ heap_trace_ = HeapTrace::is_enabled() ? new HeapTrace : NULL; |
siva
2012/12/05 16:06:40
new HeapTrace() ?
cshapiro
2012/12/08 03:23:08
Parenthesis are not required. We do not put paren
|
} |
@@ -50,15 +53,17 @@ Heap::~Heap() { |
uword Heap::AllocateNew(intptr_t size) { |
ASSERT(Isolate::Current()->no_gc_scope_depth() == 0); |
uword addr = new_space_->TryAllocate(size); |
- if (addr != 0) { |
- return addr; |
+ if (addr == 0) { |
+ CollectGarbage(kNew); |
+ addr = new_space_->TryAllocate(size); |
+ if (addr == 0) { |
+ return AllocateOld(size, HeapPage::kData); |
+ } |
} |
- CollectGarbage(kNew); |
- addr = new_space_->TryAllocate(size); |
- if (addr != 0) { |
- return addr; |
+ if (HeapTrace::is_enabled()) { |
+ heap_trace_->TraceAllocation(addr, size); |
} |
- return AllocateOld(size, HeapPage::kData); |
+ return addr; |
} |
@@ -71,8 +76,12 @@ uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) { |
if (addr == 0) { |
OS::PrintErr("Exhausted heap space, trying to allocate %"Pd" bytes.\n", |
size); |
+ return 0; |
} |
} |
+ if (HeapTrace::is_enabled()) { |
+ heap_trace_->TraceAllocation(addr, size); |
+ } |
return addr; |
} |
@@ -268,7 +277,7 @@ void Heap::PrintSizes() const { |
} |
-void Heap::Profile(Dart_HeapProfileWriteCallback callback, void* stream) const { |
+void Heap::Profile(Dart_FileWriteCallback callback, void* stream) const { |
HeapProfiler profiler(callback, stream); |
// Dump the root set. |