void zone_register(void) { /* * If something else replaced the system default zone allocator, don't * register jemalloc's. */ default_zone = zone_default_get(); if (!default_zone->zone_name || strcmp(default_zone->zone_name, "DefaultMallocZone") != 0) return; /* * The default purgeable zone is created lazily by OSX's libc. It uses * the default zone when it is created for "small" allocations * (< 15 KiB), but assumes the default zone is a scalable_zone. This * obviously fails when the default zone is the jemalloc zone, so * malloc_default_purgeable_zone() is called beforehand so that the * default purgeable zone is created when the default zone is still * a scalable_zone. As purgeable zones only exist on >= 10.6, we need * to check for the existence of malloc_default_purgeable_zone() at * run time. */ purgeable_zone = (malloc_default_purgeable_zone == NULL) ? NULL : malloc_default_purgeable_zone(); /* Register the custom zone. At this point it won't be the default. */ zone_init(); malloc_zone_register(&jemalloc_zone); /* Promote the custom zone to be default. */ zone_promote(); }
Zone::Zone() { malloc_zone_t::size = &bmalloc::zoneSize; malloc_zone_t::zone_name = "WebKit Malloc"; malloc_zone_t::introspect = const_cast<malloc_introspection_t*>(&bmalloc::zoneIntrospect); malloc_zone_t::version = 4; malloc_zone_register(this); }
Zone::Zone() { malloc_zone_t::size = &bmalloc::size; malloc_zone_t::zone_name = "WebKit Malloc"; malloc_zone_t::introspect = &bmalloc::introspect; malloc_zone_t::version = 4; malloc_zone_register(this); }
Zone::Zone(std::lock_guard<StaticMutex>&) { malloc_zone_t::size = &bmalloc::zoneSize; malloc_zone_t::zone_name = "WebKit Malloc"; malloc_zone_t::introspect = const_cast<malloc_introspection_t*>(&bmalloc::zoneIntrospect); malloc_zone_t::version = 4; malloc_zone_register(this); }
/* As written, this function can only promote jemalloc_zone. */ static void zone_promote(void) { malloc_zone_t *zone; do { /* * Unregister and reregister the default zone. On OSX >= 10.6, * unregistering takes the last registered zone and places it * at the location of the specified zone. Unregistering the * default zone thus makes the last registered one the default. * On OSX < 10.6, unregistering shifts all registered zones. * The first registered zone then becomes the default. */ malloc_zone_unregister(default_zone); malloc_zone_register(default_zone); /* * On OSX 10.6, having the default purgeable zone appear before * the default zone makes some things crash because it thinks it * owns the default zone allocated pointers. We thus * unregister/re-register it in order to ensure it's always * after the default zone. On OSX < 10.6, there is no purgeable * zone, so this does nothing. On OSX >= 10.6, unregistering * replaces the purgeable zone with the last registered zone * above, i.e. the default zone. Registering it again then puts * it at the end, obviously after the default zone. */ if (purgeable_zone != NULL) { malloc_zone_unregister(purgeable_zone); malloc_zone_register(purgeable_zone); } zone = zone_default_get(); } while (zone != &jemalloc_zone); }
CollectorHeapIntrospector::CollectorHeapIntrospector(CollectorHeap* heap) : m_heap(heap) { memset(&m_zone, 0, sizeof(m_zone)); m_zone.zone_name = "JavaScriptCore Collector"; m_zone.size = &CollectorHeapIntrospector::size; m_zone.malloc = &CollectorHeapIntrospector::zoneMalloc; m_zone.calloc = &CollectorHeapIntrospector::zoneCalloc; m_zone.realloc = &CollectorHeapIntrospector::zoneRealloc; m_zone.free = &CollectorHeapIntrospector::zoneFree; m_zone.valloc = &CollectorHeapIntrospector::zoneValloc; m_zone.destroy = &CollectorHeapIntrospector::zoneDestroy; m_zone.introspect = &jscore_collector_introspection; malloc_zone_register(&m_zone); }
void register_zone(void) { /* * If something else replaced the system default zone allocator, don't * register jemalloc's. */ malloc_zone_t *default_zone = malloc_default_zone(); if (!default_zone->zone_name || strcmp(default_zone->zone_name, "DefaultMallocZone") != 0) { return; } zone.size = (void *)zone_size; zone.malloc = (void *)zone_malloc; zone.calloc = (void *)zone_calloc; zone.valloc = (void *)zone_valloc; zone.free = (void *)zone_free; zone.realloc = (void *)zone_realloc; zone.destroy = (void *)zone_destroy; zone.zone_name = "jemalloc_zone"; zone.batch_malloc = NULL; zone.batch_free = NULL; zone.introspect = &zone_introspect; zone.version = JEMALLOC_ZONE_VERSION; #if (JEMALLOC_ZONE_VERSION >= 5) zone.memalign = zone_memalign; #endif #if (JEMALLOC_ZONE_VERSION >= 6) zone.free_definite_size = zone_free_definite_size; #endif #if (JEMALLOC_ZONE_VERSION >= 8) zone.pressure_relief = NULL; #endif zone_introspect.enumerator = NULL; zone_introspect.good_size = (void *)zone_good_size; zone_introspect.check = NULL; zone_introspect.print = NULL; zone_introspect.log = NULL; zone_introspect.force_lock = (void *)zone_force_lock; zone_introspect.force_unlock = (void *)zone_force_unlock; zone_introspect.statistics = NULL; #if (JEMALLOC_ZONE_VERSION >= 6) zone_introspect.zone_locked = NULL; #endif #if (JEMALLOC_ZONE_VERSION >= 7) zone_introspect.enable_discharge_checking = NULL; zone_introspect.disable_discharge_checking = NULL; zone_introspect.discharge = NULL; #ifdef __BLOCKS__ zone_introspect.enumerate_discharged_pointers = NULL; #else zone_introspect.enumerate_unavailable_without_blocks = NULL; #endif #endif /* * The default purgeable zone is created lazily by OSX's libc. It uses * the default zone when it is created for "small" allocations * (< 15 KiB), but assumes the default zone is a scalable_zone. This * obviously fails when the default zone is the jemalloc zone, so * malloc_default_purgeable_zone is called beforehand so that the * default purgeable zone is created when the default zone is still * a scalable_zone. As purgeable zones only exist on >= 10.6, we need * to check for the existence of malloc_default_purgeable_zone() at * run time. */ if (malloc_default_purgeable_zone != NULL) malloc_default_purgeable_zone(); /* Register the custom zone. At this point it won't be the default. */ malloc_zone_register(&zone); /* * Unregister and reregister the default zone. On OSX >= 10.6, * unregistering takes the last registered zone and places it at the * location of the specified zone. Unregistering the default zone thus * makes the last registered one the default. On OSX < 10.6, * unregistering shifts all registered zones. The first registered zone * then becomes the default. */ do { default_zone = malloc_default_zone(); malloc_zone_unregister(default_zone); malloc_zone_register(default_zone); } while (malloc_default_zone() != &zone); }
__attribute__((constructor)) void register_zone(void) { zone.size = (void *)zone_size; zone.malloc = (void *)zone_malloc; zone.calloc = (void *)zone_calloc; zone.valloc = (void *)zone_valloc; zone.free = (void *)zone_free; zone.realloc = (void *)zone_realloc; zone.destroy = (void *)zone_destroy; zone.zone_name = "replace_malloc_zone"; zone.batch_malloc = NULL; zone.batch_free = NULL; zone.introspect = &zone_introspect; zone.version = JEMALLOC_ZONE_VERSION; zone.memalign = zone_memalign; zone.free_definite_size = zone_free_definite_size; #if (JEMALLOC_ZONE_VERSION >= 8) zone.pressure_relief = NULL; #endif zone_introspect.enumerator = NULL; zone_introspect.good_size = (void *)zone_good_size; zone_introspect.check = NULL; zone_introspect.print = NULL; zone_introspect.log = NULL; zone_introspect.force_lock = (void *)zone_force_lock; zone_introspect.force_unlock = (void *)zone_force_unlock; zone_introspect.statistics = NULL; zone_introspect.zone_locked = NULL; #if (JEMALLOC_ZONE_VERSION >= 7) zone_introspect.enable_discharge_checking = NULL; zone_introspect.disable_discharge_checking = NULL; zone_introspect.discharge = NULL; #ifdef __BLOCKS__ zone_introspect.enumerate_discharged_pointers = NULL; #else zone_introspect.enumerate_unavailable_without_blocks = NULL; #endif #endif /* * The default purgeable zone is created lazily by OSX's libc. It uses * the default zone when it is created for "small" allocations * (< 15 KiB), but assumes the default zone is a scalable_zone. This * obviously fails when the default zone is the jemalloc zone, so * malloc_default_purgeable_zone is called beforehand so that the * default purgeable zone is created when the default zone is still * a scalable_zone. */ malloc_zone_t *purgeable_zone = malloc_default_purgeable_zone(); /* Register the custom zone. At this point it won't be the default. */ malloc_zone_register(&zone); do { malloc_zone_t *default_zone = malloc_default_zone(); /* * Unregister and reregister the default zone. On OSX >= 10.6, * unregistering takes the last registered zone and places it at the * location of the specified zone. Unregistering the default zone thus * makes the last registered one the default. On OSX < 10.6, * unregistering shifts all registered zones. The first registered zone * then becomes the default. */ malloc_zone_unregister(default_zone); malloc_zone_register(default_zone); /* * On OSX 10.6, having the default purgeable zone appear before the default * zone makes some things crash because it thinks it owns the default * zone allocated pointers. We thus unregister/re-register it in order to * ensure it's always after the default zone. On OSX < 10.6, as * unregistering shifts registered zones, this simply removes the purgeable * zone from the list and adds it back at the end, after the default zone. * On OSX >= 10.6, unregistering replaces the purgeable zone with the last * registered zone above, i.e the default zone. Registering it again then * puts it at the end, obviously after the default zone. */ malloc_zone_unregister(purgeable_zone); malloc_zone_register(purgeable_zone); } while (malloc_default_zone() != &zone); }