Bug 1125185 - Define MOZ_COLD for marking "cold" functions r=waldo

This commit is contained in:
Dan Gohman 2015-01-26 17:30:19 -08:00
parent 3c6597a307
commit ab5b55adc2
9 changed files with 32 additions and 15 deletions

View File

@ -53,7 +53,7 @@ namespace js {}
#define JS_STATIC_ASSERT(cond) static_assert(cond, "JS_STATIC_ASSERT")
#define JS_STATIC_ASSERT_IF(cond, expr) MOZ_STATIC_ASSERT_IF(cond, expr, "JS_STATIC_ASSERT_IF")
extern MOZ_NORETURN JS_PUBLIC_API(void)
extern MOZ_NORETURN MOZ_COLD JS_PUBLIC_API(void)
JS_Assert(const char *s, const char *file, int ln);
/*

View File

@ -148,9 +148,6 @@ class BumpChunk
} // namespace detail
MOZ_NORETURN void
CrashAtUnhandlableOOM(const char *reason);
// LIFO bump allocator: used for phase-oriented and fast LIFO allocations.
//
// Note: |latest| is not necessary "last". We leave BumpChunks latent in the

View File

@ -19,10 +19,6 @@
#include "js/MemoryMetrics.h"
namespace js {
MOZ_NORETURN void
CrashAtUnhandlableOOM(const char *reason);
namespace gc {
/*

View File

@ -1773,7 +1773,7 @@ inline const char * TypeObjectString(TypeObject *type) { return nullptr; }
#endif
/* Print a warning, dump state and abort the program. */
MOZ_NORETURN void TypeFailure(JSContext *cx, const char *fmt, ...);
MOZ_NORETURN MOZ_COLD void TypeFailure(JSContext *cx, const char *fmt, ...);
} /* namespace types */
} /* namespace js */

View File

@ -50,7 +50,7 @@ namespace js {
// This function calls all the vanilla heap allocation functions. It is never
// called, and exists purely to help config/check_vanilla_allocations.py. See
// that script for more details.
extern void
extern MOZ_COLD void
AllTheNonBasicVanillaNewAllocations()
{
// posix_memalign and aligned_alloc aren't available on all Linux

View File

@ -43,6 +43,9 @@ js_memcpy(void *dst_, const void *src_, size_t len)
namespace js {
MOZ_NORETURN MOZ_COLD void
CrashAtUnhandlableOOM(const char *reason);
template <class T>
struct AlignmentTestStruct
{

View File

@ -63,13 +63,13 @@ extern mozilla::ThreadLocal<PerThreadData*> TlsPerThreadData;
struct DtoaState;
extern void
extern MOZ_COLD void
js_ReportOutOfMemory(js::ExclusiveContext *cx);
extern void
extern MOZ_COLD void
js_ReportAllocationOverflow(js::ExclusiveContext *maybecx);
extern void
extern MOZ_COLD void
js_ReportOverRecursed(js::ExclusiveContext *cx);
namespace js {

View File

@ -131,7 +131,7 @@ extern "C" {
* method is primarily for internal use in this header, and only secondarily
* for use in implementing release-build assertions.
*/
static MOZ_ALWAYS_INLINE void
static MOZ_COLD MOZ_ALWAYS_INLINE void
MOZ_ReportAssertionFailure(const char* aStr, const char* aFilename, int aLine)
MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS
{
@ -148,7 +148,7 @@ MOZ_ReportAssertionFailure(const char* aStr, const char* aFilename, int aLine)
#endif
}
static MOZ_ALWAYS_INLINE void
static MOZ_COLD MOZ_ALWAYS_INLINE void
MOZ_ReportCrash(const char* aStr, const char* aFilename, int aLine)
MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS
{

View File

@ -191,6 +191,27 @@
# define MOZ_NORETURN /* no support */
#endif
/**
* MOZ_COLD tells the compiler that a function is "cold", meaning infrequently
* executed. This may lead it to optimize for size more aggressively than speed,
* or to allocate the body of the function in a distant part of the text segment
* to help keep it from taking up unnecessary icache when it isn't in use.
*
* Place this attribute at the very beginning of a function definition. For
* example, write
*
* MOZ_COLD int foo();
*
* or
*
* MOZ_COLD int foo() { return 42; }
*/
#if defined(__GNUC__) || defined(__clang__)
# define MOZ_COLD __attribute__ ((cold))
#else
# define MOZ_COLD
#endif
/*
* MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS, specified at the end of a function
* declaration, indicates that for the purposes of static analysis, this