Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(461)

Unified Diff: runtime/vm/malloc_hooks.cc

Issue 2771293003: Resubmission of native memory allocation info surfacing in Observatory. Fixed crashing tests and st… (Closed)
Patch Set: Added page to Observatory to display native memory allocation information. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/malloc_hooks.h ('k') | runtime/vm/malloc_hooks_arm.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/malloc_hooks.cc
diff --git a/runtime/vm/malloc_hooks.cc b/runtime/vm/malloc_hooks.cc
index e3cbdd10175501ad5c758aa8193121d17af636cc..6502bbb3a06ecfcad03a192cd283c6983a794643 100644
--- a/runtime/vm/malloc_hooks.cc
+++ b/runtime/vm/malloc_hooks.cc
@@ -131,13 +131,15 @@ class MallocLocker : public ValueObject {
// -Stack trace corresponding to the location of allocation, if applicable
class AllocationInfo {
public:
- explicit AllocationInfo(intptr_t allocation_size)
- : sample_(NULL), allocation_size_(allocation_size) {
+ AllocationInfo(uword address, intptr_t allocation_size)
+ : sample_(NULL), address_(address), allocation_size_(allocation_size) {
// Stack trace collection is disabled when we are in the process of creating
// the first OSThread in order to prevent deadlocks.
if (MallocHooksState::ProfilingEnabled() &&
MallocHooksState::stack_trace_collection_enabled()) {
- sample_ = Profiler::SampleNativeAllocation(kSkipCount);
+ sample_ = Profiler::SampleNativeAllocation(kSkipCount, address,
+ allocation_size);
+ ASSERT(sample_->native_allocation_address() == address_);
}
}
@@ -145,16 +147,13 @@ class AllocationInfo {
intptr_t allocation_size() const { return allocation_size_; }
private:
+ // Note: sample_ is not owned by AllocationInfo, but by the SampleBuffer
+ // created by the profiler. As such, this is only here to track if the sample
+ // is still associated with a native allocation, and its fields are never
+ // accessed from this class.
Sample* sample_;
+ uword address_;
intptr_t allocation_size_;
-
- // The number of frames that are generated by the malloc hooks and collection
- // of the stack trace. These frames are ignored when collecting the stack
- // trace for a memory allocation. If this number is incorrect, some tests in
- // malloc_hook_tests.cc might fail, particularily
- // StackTraceMallocHookLengthTest. If this value is updated, please make sure
- // that the MallocHooks test cases pass on all platforms.
- static const intptr_t kSkipCount = 5;
};
@@ -416,7 +415,8 @@ void MallocHooksState::RecordAllocHook(const void* ptr, size_t size) {
// Now that we hold the lock, check to make sure everything is still active.
if ((ptr != NULL) && MallocHooksState::Active()) {
MallocHooksState::IncrementHeapAllocatedMemoryInBytes(size);
- MallocHooksState::address_map()->Insert(ptr, new AllocationInfo(size));
+ MallocHooksState::address_map()->Insert(
+ ptr, new AllocationInfo(reinterpret_cast<uword>(ptr), size));
}
}
@@ -435,7 +435,8 @@ void MallocHooksState::RecordFreeHook(const void* ptr) {
if (MallocHooksState::address_map()->Lookup(ptr, &allocation_info)) {
MallocHooksState::DecrementHeapAllocatedMemoryInBytes(
allocation_info->allocation_size());
- MallocHooksState::address_map()->Remove(ptr);
+ const bool result = MallocHooksState::address_map()->Remove(ptr);
+ ASSERT(result);
delete allocation_info;
}
}
« no previous file with comments | « runtime/vm/malloc_hooks.h ('k') | runtime/vm/malloc_hooks_arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698