Skip to content

[MemProf][NFC] Clean up runtime code #80581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions compiler-rt/lib/memprof/memprof_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,7 @@ struct Allocator {
return ptr;
}

void CommitBack(MemprofThreadLocalMallocStorage *ms,
BufferedStackTrace *stack) {
void CommitBack(MemprofThreadLocalMallocStorage *ms) {
AllocatorCache *ac = GetAllocatorCache(ms);
allocator.SwallowCache(ac);
}
Expand Down Expand Up @@ -561,7 +560,7 @@ struct Allocator {
return reinterpret_cast<MemprofChunk *>(p - kChunkHeaderSize)->UsedSize();
}

void Purge(BufferedStackTrace *stack) { allocator.ForceReleaseToOS(); }
void Purge() { allocator.ForceReleaseToOS(); }

void PrintStats() { allocator.PrintStats(); }

Expand All @@ -583,8 +582,7 @@ static MemprofAllocator &get_allocator() { return instance.allocator; }
void InitializeAllocator() { instance.InitLinkerInitialized(); }

void MemprofThreadLocalMallocStorage::CommitBack() {
GET_STACK_TRACE_MALLOC;
instance.CommitBack(this, &stack);
instance.CommitBack(this);
}

void PrintInternalAllocatorStats() { instance.PrintStats(); }
Expand Down Expand Up @@ -699,7 +697,7 @@ static const void *memprof_malloc_begin(const void *p) {
return (const void *)m->Beg();
}

uptr memprof_malloc_usable_size(const void *ptr, uptr pc, uptr bp) {
uptr memprof_malloc_usable_size(const void *ptr) {
if (!ptr)
return 0;
uptr usable_size = instance.AllocationSize(reinterpret_cast<uptr>(ptr));
Expand All @@ -714,15 +712,15 @@ using namespace __memprof;
uptr __sanitizer_get_estimated_allocated_size(uptr size) { return size; }

int __sanitizer_get_ownership(const void *p) {
return memprof_malloc_usable_size(p, 0, 0) != 0;
return memprof_malloc_usable_size(p) != 0;
}

const void *__sanitizer_get_allocated_begin(const void *p) {
return memprof_malloc_begin(p);
}

uptr __sanitizer_get_allocated_size(const void *p) {
return memprof_malloc_usable_size(p, 0, 0);
return memprof_malloc_usable_size(p);
}

uptr __sanitizer_get_allocated_size_fast(const void *p) {
Expand All @@ -732,6 +730,8 @@ uptr __sanitizer_get_allocated_size_fast(const void *p) {
return ret;
}

void __sanitizer_purge_allocator() { instance.Purge(); }

int __memprof_profile_dump() {
instance.FinishAndWrite();
// In the future we may want to return non-zero if there are any errors
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/memprof/memprof_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void *memprof_aligned_alloc(uptr alignment, uptr size,
BufferedStackTrace *stack);
int memprof_posix_memalign(void **memptr, uptr alignment, uptr size,
BufferedStackTrace *stack);
uptr memprof_malloc_usable_size(const void *ptr, uptr pc, uptr bp);
uptr memprof_malloc_usable_size(const void *ptr);

void PrintInternalAllocatorStats();

Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/memprof/memprof_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ INTERCEPTOR(int, pthread_create, void *thread, void *attr,
}

INTERCEPTOR(int, pthread_join, void *t, void **arg) {
return real_pthread_join(t, arg);
return REAL(pthread_join)(t, arg);
}

DEFINE_REAL_PTHREAD_FUNCTIONS
Expand Down
4 changes: 0 additions & 4 deletions compiler-rt/lib/memprof/memprof_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
#include "sanitizer_common/sanitizer_libc.h"
#include "sanitizer_common/sanitizer_stacktrace.h"

#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
#error "The MemProfiler run-time should not be instrumented by MemProfiler"
#endif

// Build-time configuration options.

// If set, memprof will intercept C++ exception api call(s).
Expand Down
4 changes: 1 addition & 3 deletions compiler-rt/lib/memprof/memprof_malloc_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ INTERCEPTOR(void *, aligned_alloc, uptr boundary, uptr size) {
#endif // SANITIZER_INTERCEPT_ALIGNED_ALLOC

INTERCEPTOR(uptr, malloc_usable_size, void *ptr) {
GET_CURRENT_PC_BP_SP;
(void)sp;
return memprof_malloc_usable_size(ptr, pc, bp);
return memprof_malloc_usable_size(ptr);
}

#if SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO
Expand Down