From 098e2edf44035eb4d3e1db9a4f2054ade571eb6e Mon Sep 17 00:00:00 2001 From: Dmitrii Kuvaiskii Date: Thu, 14 Nov 2019 18:25:09 -0800 Subject: [PATCH] [Pal/Linux] Remove unused TRACE_HEAP_LEAK macro and code --- Pal/src/host/Linux/db_object.c | 46 ----------------------- Pal/src/host/Linux/pal_host.h | 67 ---------------------------------- Pal/src/pal_defs.h | 3 -- 3 files changed, 116 deletions(-) diff --git a/Pal/src/host/Linux/db_object.c b/Pal/src/host/Linux/db_object.c index d1758c24..aa351bfc 100644 --- a/Pal/src/host/Linux/db_object.c +++ b/Pal/src/host/Linux/db_object.c @@ -262,49 +262,3 @@ int _DkObjectsWaitAny(int count, PAL_HANDLE* handleArray, int64_t timeout_us, *polled = polled_hdl; return polled_hdl ? 0 : -PAL_ERROR_TRYAGAIN; } - -#if TRACE_HEAP_LEAK == 1 - -PAL_HANDLE heap_alloc_head; -PAL_LOCK heap_alloc_trace_lock = LOCK_INIT; - -HEAP_ALLOC_RECORD * collect_heap_alloc_records (PAL_NUM max_records) -{ - HEAP_ALLOC_RECORD * records = - malloc(sizeof(HEAP_ALLOC_RECORD) * max_records); - - if (!records) - return NULL; - - memset(records, 0, sizeof(HEAP_ALLOC_RECORD) * max_records); - - _DkInternalLock(&heap_alloc_trace_lock); - - PAL_HANDLE ptr = heap_alloc_head; - int nrecords = 0, i; - - for (; ptr ; ptr = ptr->hdr.heap_trace.next) { - assert(!ptr->hdr.heap_trace.next || - ptr->hdr.heap_trace.next->hdr.heap_trace.pprev == - &ptr->hdr.heap_trace.next); - - for (i = 0 ; i < nrecords ; i++) - if (ptr->hdr.heap_trace.caller == records[i].caller) { - records[i].count++; - break; - } - - if (i == nrecords) { - if (nrecords == max_records) break; - records[nrecords].caller = ptr->hdr.heap_trace.caller; - records[nrecords].count = 1; - nrecords++; - } - } - - _DkInternalUnlock(&heap_alloc_trace_lock); - - return records; -} - -#endif /* TRACE_HEAP_LEAK == 0 */ diff --git a/Pal/src/host/Linux/pal_host.h b/Pal/src/host/Linux/pal_host.h index d594fd95..4c73da68 100644 --- a/Pal/src/host/Linux/pal_host.h +++ b/Pal/src/host/Linux/pal_host.h @@ -57,14 +57,6 @@ int _DkMutexUnlock(struct mutex_handle* mut); typedef struct { PAL_HDR hdr; -#if TRACE_HEAP_LEAK == 1 - struct heap_trace_info { - /* maintaining a list of handles */ - struct pal_handle ** pprev, * next; - /* trace the PC where the handle is created */ - PAL_PTR caller; - } heap_trace; -#endif } PAL_RESERVED_HDR; typedef struct pal_handle @@ -194,63 +186,4 @@ extern void __check_pending_event (void); #define LEAVE_PAL_CALL_RETURN(retval) \ do { __check_pending_event(); return (retval); } while (0) -#if TRACE_HEAP_LEAK == 1 - -/* The following code adds a piece of information - in each handle to trace heap leakage. */ - -extern PAL_HANDLE heap_alloc_head; -extern PAL_LOCK heap_alloc_trace_lock; - -/* call the following function in GDB */ -typedef struct { - PAL_PTR caller; - PAL_NUM count; -} HEAP_ALLOC_RECORD; - -extern HEAP_ALLOC_RECORD * collect_heap_alloc_records (PAL_NUM max_records); - -static inline -void __trace_heap (PAL_HANDLE handle, struct pal_frame * frame) -{ - _DkInternalLock(&heap_alloc_trace_lock); - - handle->hdr.heap_trace.caller = ((PAL_PTR *)frame->arch.rbp)[1]; - - /* Add the handle to the list */ - if (heap_alloc_head) - heap_alloc_head->hdr.heap_trace.pprev - = &handle->hdr.heap_trace.next; - handle->hdr.heap_trace.next = heap_alloc_head; - handle->hdr.heap_trace.pprev = &heap_alloc_head; - heap_alloc_head = handle; - - _DkInternalUnlock(&heap_alloc_trace_lock); -} - -#define TRACE_HEAP(handle) \ - do { if (handle) __trace_heap(handle, &frame); } while (0) - -static inline -void __untrace_heap (PAL_HANDLE handle) -{ - _DkInternalLock(&heap_alloc_trace_lock); - - /* remove the handle from the list */ - *handle->hdr.heap_trace.pprev = handle->hdr.heap_trace.next; - if (handle->hdr.heap_trace.next) - handle->hdr.heap_trace.next->hdr.heap_trace.pprev - = handle->hdr.heap_trace.pprev; - - handle->hdr.heap_trace.pprev = NULL; - handle->hdr.heap_trace.next = NULL; - - _DkInternalUnlock(&heap_alloc_trace_lock); -} - -#define UNTRACE_HEAP(handle) \ - do { if (handle) __untrace_heap(handle); } while (0) - -#endif /* TRACE_HEAP_LEAK == 1 */ - #endif /* PAL_HOST_H */ diff --git a/Pal/src/pal_defs.h b/Pal/src/pal_defs.h index 67c1f9af..da41c7fd 100644 --- a/Pal/src/pal_defs.h +++ b/Pal/src/pal_defs.h @@ -14,7 +14,4 @@ /* allow binding sockets to ANY addresses (e.g., 0.0.0.0:0) */ #define ALLOW_BIND_ANY 1 -/* turn on the following option to trace heap memory leak */ -#define TRACE_HEAP_LEAK 0 - #endif /* PAL_DEFS_H */