Skip to content

Commit

Permalink
Consolidate hot_cold-hinted new implementation into malloc extension.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 699233090
Change-Id: Ia032f900ab69c4a98048c07868dfe2b22473ffd6
  • Loading branch information
ckennelly authored and copybara-github committed Nov 22, 2024
1 parent 78e9b9b commit 0b936f8
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 90 deletions.
2 changes: 1 addition & 1 deletion tcmalloc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1231,9 +1231,9 @@ cc_library(

cc_library(
name = "new_extension",
srcs = ["new_extension.cc"],
hdrs = ["new_extension.h"],
copts = TCMALLOC_DEFAULT_COPTS,
deprecation = "Use :malloc_extension directly",
visibility = [":__subpackages__"],
deps = [
":malloc_extension",
Expand Down
47 changes: 47 additions & 0 deletions tcmalloc/malloc_extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -893,3 +893,50 @@ tcmalloc_size_returning_operator_new_aligned_hot_cold_nothrow(
}

#endif // _LIBCPP_VERSION && __cpp_aligned_new

ABSL_ATTRIBUTE_WEAK void* operator new(
size_t size, tcmalloc::hot_cold_t hot_cold) noexcept(false) {
return ::operator new(size);
}

ABSL_ATTRIBUTE_WEAK void* operator new(size_t size, const std::nothrow_t&,
tcmalloc::hot_cold_t hot_cold) noexcept {
return ::operator new(size, std::nothrow);
}

ABSL_ATTRIBUTE_WEAK void* operator new[](
size_t size, tcmalloc::hot_cold_t hot_cold) noexcept(false) {
return ::operator new[](size);
}

ABSL_ATTRIBUTE_WEAK void* operator new[](
size_t size, const std::nothrow_t&,
tcmalloc::hot_cold_t hot_cold) noexcept {
return ::operator new[](size, std::nothrow);
}

#ifdef __cpp_aligned_new
ABSL_ATTRIBUTE_WEAK void* operator new(
size_t size, std::align_val_t alignment,
tcmalloc::hot_cold_t hot_cold) noexcept(false) {
return ::operator new(size, alignment);
}

ABSL_ATTRIBUTE_WEAK void* operator new(size_t size, std::align_val_t alignment,
const std::nothrow_t&,
tcmalloc::hot_cold_t hot_cold) noexcept {
return ::operator new(size, alignment, std::nothrow);
}

ABSL_ATTRIBUTE_WEAK void* operator new[](
size_t size, std::align_val_t alignment,
tcmalloc::hot_cold_t hot_cold) noexcept(false) {
return ::operator new[](size, alignment);
}

ABSL_ATTRIBUTE_WEAK void* operator new[](
size_t size, std::align_val_t alignment, const std::nothrow_t&,
tcmalloc::hot_cold_t hot_cold) noexcept {
return ::operator new[](size, alignment, std::nothrow);
}
#endif // __cpp_aligned_new
21 changes: 21 additions & 0 deletions tcmalloc/malloc_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,27 @@ __sized_ptr_t tcmalloc_size_returning_operator_new_aligned_hot_cold_nothrow(

} // extern "C"

void* operator new(size_t size, tcmalloc::hot_cold_t hot_cold) noexcept(false);
void* operator new(size_t size, const std::nothrow_t&,
tcmalloc::hot_cold_t hot_cold) noexcept;
void* operator new[](size_t size,
tcmalloc::hot_cold_t hot_cold) noexcept(false);
void* operator new[](size_t size, const std::nothrow_t&,
tcmalloc::hot_cold_t hot_cold) noexcept;

#ifdef __cpp_aligned_new
void* operator new(size_t size, std::align_val_t alignment,
tcmalloc::hot_cold_t hot_cold) noexcept(false);
void* operator new(size_t size, std::align_val_t alignment,
const std::nothrow_t&,
tcmalloc::hot_cold_t hot_cold) noexcept;
void* operator new[](size_t size, std::align_val_t alignment,
tcmalloc::hot_cold_t hot_cold) noexcept(false);
void* operator new[](size_t size, std::align_val_t alignment,
const std::nothrow_t&,
tcmalloc::hot_cold_t hot_cold) noexcept;
#endif // __cpp_aligned_new

#ifndef MALLOCX_LG_ALIGN
#define MALLOCX_LG_ALIGN(la) (la)
#endif
Expand Down
68 changes: 0 additions & 68 deletions tcmalloc/new_extension.cc

This file was deleted.

21 changes: 0 additions & 21 deletions tcmalloc/new_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,4 @@

#include "tcmalloc/malloc_extension.h"

void* operator new(size_t size, tcmalloc::hot_cold_t hot_cold) noexcept(false);
void* operator new(size_t size, const std::nothrow_t&,
tcmalloc::hot_cold_t hot_cold) noexcept;
void* operator new[](size_t size,
tcmalloc::hot_cold_t hot_cold) noexcept(false);
void* operator new[](size_t size, const std::nothrow_t&,
tcmalloc::hot_cold_t hot_cold) noexcept;

#ifdef __cpp_aligned_new
void* operator new(size_t size, std::align_val_t alignment,
tcmalloc::hot_cold_t hot_cold) noexcept(false);
void* operator new(size_t size, std::align_val_t alignment,
const std::nothrow_t&,
tcmalloc::hot_cold_t hot_cold) noexcept;
void* operator new[](size_t size, std::align_val_t alignment,
tcmalloc::hot_cold_t hot_cold) noexcept(false);
void* operator new[](size_t size, std::align_val_t alignment,
const std::nothrow_t&,
tcmalloc::hot_cold_t hot_cold) noexcept;
#endif // __cpp_aligned_new

#endif // TCMALLOC_NEW_EXTENSION_H_

0 comments on commit 0b936f8

Please sign in to comment.