Skip to content
  • Mike Hommey's avatar
    Bug 1361258 - Use Thread Local Storage in mozjemalloc on mac. r=erahm · fcd9a555
    Mike Hommey authored
    NO_TLS used to be hardcoded on mac because up to 10.6, __thread was not
    supported. Until recently, we still supported for 10.6, and it's not the
    case anymore, so we could make mac builds use __thread.
    
    Unfortunately, on OSX, __thread circles back calling malloc to allocate
    storage on first access, so we have an infinite loop problem here.
    Fortunately, pthread_keys don't have this property, so we can use that
    instead. It doesn't appear to have significantly more overhead (and TLS
    overhead is small anyways compared to the amount of work involved in
    allocating memory with mozjemalloc).
    
    At the same time, we uniformize the initialization sequence between
    mozjemalloc and mozjemalloc+replace-malloc, such that we have less
    occasions for surprises when riding the trains (replace-malloc being
    nightly only), ensuring the zone registration happens at the end of
    mozjemalloc's initialization.
    fcd9a555