965333d95c
Apparently libc 2.33 deprecates the mallinfo API in favor of the new mallinfo2 API. The API stays nearly the same, only the types in the struct containing the malloc information has changed. Fields in the new API are size_t instead of int. These changes would allow use of mallinfo2 as a build time configuration on systems that have mallinfo2 available. TEST=cq BUG= Change-Id: Ib074dea3fb1f7c971c2987d8117319bf073ce732 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/218161 Reviewed-by: Zach Anderson <zra@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Siva Annamalai <asiva@google.com>
111 lines
2.6 KiB
C++
111 lines
2.6 KiB
C++
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "platform/globals.h"
|
|
|
|
#if !defined(DEBUG) || !defined(DART_USE_TCMALLOC)
|
|
|
|
#include "vm/malloc_hooks.h"
|
|
|
|
#include "vm/json_stream.h"
|
|
|
|
#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID)
|
|
#include <malloc.h>
|
|
#elif defined(DART_HOST_OS_MACOS)
|
|
#include <malloc/malloc.h>
|
|
#endif
|
|
|
|
#if !defined(DART_HOST_OS_WINDOWS) && !defined(DART_HOST_OS_MACOS)
|
|
extern "C" {
|
|
__attribute__((weak)) uintptr_t __sanitizer_get_current_allocated_bytes();
|
|
__attribute__((weak)) uintptr_t __sanitizer_get_heap_size();
|
|
__attribute__((weak)) int __sanitizer_install_malloc_and_free_hooks(
|
|
void (*malloc_hook)(const void*, uintptr_t),
|
|
void (*free_hook)(const void*));
|
|
}
|
|
#endif
|
|
|
|
namespace dart {
|
|
|
|
void MallocHooks::Init() {
|
|
// Do nothing.
|
|
}
|
|
|
|
void MallocHooks::Cleanup() {
|
|
// Do nothing.
|
|
}
|
|
|
|
bool MallocHooks::ProfilingEnabled() {
|
|
return false;
|
|
}
|
|
|
|
bool MallocHooks::stack_trace_collection_enabled() {
|
|
return false;
|
|
}
|
|
|
|
void MallocHooks::set_stack_trace_collection_enabled(bool enabled) {
|
|
// Do nothing.
|
|
}
|
|
|
|
void MallocHooks::ResetStats() {
|
|
// Do nothing.
|
|
}
|
|
|
|
bool MallocHooks::Active() {
|
|
return false;
|
|
}
|
|
|
|
bool MallocHooks::GetStats(intptr_t* used,
|
|
intptr_t* capacity,
|
|
const char** implementation) {
|
|
#if !defined(PRODUCT)
|
|
#if !defined(DART_HOST_OS_WINDOWS) && !defined(DART_HOST_OS_MACOS)
|
|
if (__sanitizer_get_current_allocated_bytes != nullptr &&
|
|
__sanitizer_get_heap_size != nullptr) {
|
|
*used = __sanitizer_get_current_allocated_bytes();
|
|
*capacity = __sanitizer_get_heap_size();
|
|
*implementation = "scudo";
|
|
return true;
|
|
}
|
|
#endif
|
|
#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID)
|
|
#if defined(DART_USE_MALLINFO2)
|
|
struct mallinfo2 info = mallinfo2();
|
|
#else
|
|
struct mallinfo info = mallinfo();
|
|
#endif // defined(DART_USE_MALLINFO2)
|
|
*used = info.uordblks;
|
|
*capacity = *used + info.fordblks;
|
|
*implementation = "unknown";
|
|
return true;
|
|
#elif defined(DART_HOST_OS_MACOS)
|
|
struct mstats stats = mstats();
|
|
*used = stats.bytes_used;
|
|
*capacity = stats.bytes_total;
|
|
*implementation = "macos";
|
|
return true;
|
|
#else
|
|
return false;
|
|
#endif
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
|
|
Sample* MallocHooks::GetSample(const void* ptr) {
|
|
return NULL;
|
|
}
|
|
|
|
intptr_t MallocHooks::allocation_count() {
|
|
return 0;
|
|
}
|
|
|
|
intptr_t MallocHooks::heap_allocated_memory_in_bytes() {
|
|
return 0;
|
|
}
|
|
|
|
} // namespace dart
|
|
|
|
#endif // !defined(DART_USE_TCMALLOC) && ...
|