diff --git a/include/iocore/eventsystem/Event.h b/include/iocore/eventsystem/Event.h index aef3db53aed..84e313db161 100644 --- a/include/iocore/eventsystem/Event.h +++ b/include/iocore/eventsystem/Event.h @@ -280,7 +280,7 @@ class Event : public Action // // Event Allocator // -extern ClassAllocator eventAllocator; +extern ClassAllocator eventAllocator; #define EVENT_ALLOC(_a, _t) THREAD_ALLOC(_a, _t) #define EVENT_FREE(_p, _a, _t) \ diff --git a/include/iocore/eventsystem/IOBuffer.h b/include/iocore/eventsystem/IOBuffer.h index de01b59a6ad..18c35fa917b 100644 --- a/include/iocore/eventsystem/IOBuffer.h +++ b/include/iocore/eventsystem/IOBuffer.h @@ -251,7 +251,7 @@ class IOBufferData : public RefCountObj IOBufferData &operator=(const IOBufferData &) = delete; }; -extern ClassAllocator ioDataAllocator; +extern ClassAllocator ioDataAllocator; /** A linkable portion of IOBufferData. IOBufferBlock is a chainable @@ -494,7 +494,7 @@ class IOBufferBlock : public RefCountObj IOBufferBlock &operator=(const IOBufferBlock &) = delete; }; -extern ClassAllocator ioBlockAllocator; +extern ClassAllocator ioBlockAllocator; /** A class for holding a chain of IO buffer blocks. This class is intended to be used as a member variable for other classes that diff --git a/include/iocore/eventsystem/Lock.h b/include/iocore/eventsystem/Lock.h index 031ee9ef1a4..f41c862ba71 100644 --- a/include/iocore/eventsystem/Lock.h +++ b/include/iocore/eventsystem/Lock.h @@ -247,7 +247,7 @@ class ProxyMutex : public RefCountObj }; // The ClassAllocator for ProxyMutexes -extern ClassAllocator mutexAllocator; +extern ClassAllocator mutexAllocator; inline bool Mutex_trylock( diff --git a/include/iocore/utils/OneWayMultiTunnel.h b/include/iocore/utils/OneWayMultiTunnel.h index d8e3e5cf543..643c4fe61e9 100644 --- a/include/iocore/utils/OneWayMultiTunnel.h +++ b/include/iocore/utils/OneWayMultiTunnel.h @@ -131,4 +131,4 @@ struct OneWayMultiTunnel : public OneWayTunnel { VIO *vioTargets[ONE_WAY_MULTI_TUNNEL_LIMIT]; }; -extern ClassAllocator OneWayMultiTunnelAllocator; +extern ClassAllocator OneWayMultiTunnelAllocator; diff --git a/include/proxy/http/Http1ClientSession.h b/include/proxy/http/Http1ClientSession.h index 7d808cc0214..b7c83a74d03 100644 --- a/include/proxy/http/Http1ClientSession.h +++ b/include/proxy/http/Http1ClientSession.h @@ -130,4 +130,4 @@ class Http1ClientSession : public ProxySession Http1ClientTransaction trans; }; -extern ClassAllocator http1ClientSessionAllocator; +extern ClassAllocator http1ClientSessionAllocator; diff --git a/include/proxy/http/Http1ServerSession.h b/include/proxy/http/Http1ServerSession.h index abb26f94e86..46dc08c2bf6 100644 --- a/include/proxy/http/Http1ServerSession.h +++ b/include/proxy/http/Http1ServerSession.h @@ -105,7 +105,7 @@ class Http1ServerSession : public PoolableSession Http1ServerTransaction trans; }; -extern ClassAllocator httpServerSessionAllocator; +extern ClassAllocator httpServerSessionAllocator; //////////////////////////////////////////// // INLINE diff --git a/include/proxy/http/HttpSM.h b/include/proxy/http/HttpSM.h index 84ab9e3654b..3bbbd802a14 100644 --- a/include/proxy/http/HttpSM.h +++ b/include/proxy/http/HttpSM.h @@ -187,7 +187,7 @@ class HttpSM : public Continuation, public PluginUserArgs public: HttpSM(); - void cleanup(); + ~HttpSM() override; virtual void destroy(); static HttpSM *allocate(); diff --git a/include/proxy/http/HttpTransact.h b/include/proxy/http/HttpTransact.h index 01bcb8182ef..e6736467f55 100644 --- a/include/proxy/http/HttpTransact.h +++ b/include/proxy/http/HttpTransact.h @@ -849,6 +849,8 @@ class HttpTransact // memset((void *)&host_db_info, 0, sizeof(host_db_info)); } + ~State() { destroy(); } + void destroy() { @@ -857,8 +859,10 @@ class HttpTransact free_internal_msg_buffer(); ats_free(internal_msg_buffer_type); - ParentConfig::release(parent_params); - parent_params = nullptr; + if (parent_params != nullptr) { + ParentConfig::release(parent_params); + parent_params = nullptr; + } hdr_info.client_request.destroy(); hdr_info.client_response.destroy(); @@ -877,7 +881,6 @@ class HttpTransact url_map.clear(); arena.reset(); unmapped_url.clear(); - dns_info.~ResolveInfo(); outbound_conn_track_state.clear(); delete[] ranges; diff --git a/include/proxy/http/PreWarmManager.h b/include/proxy/http/PreWarmManager.h index 3b2d453f650..05f49bd9090 100644 --- a/include/proxy/http/PreWarmManager.h +++ b/include/proxy/http/PreWarmManager.h @@ -138,8 +138,7 @@ class PreWarmSM; class PreWarmManager; class SNIConfigParams; -extern ClassAllocator preWarmSMAllocator; -extern PreWarmManager prewarmManager; +extern PreWarmManager prewarmManager; /** @class PreWarmSM @@ -230,6 +229,8 @@ class PreWarmSM : public Continuation Event *_retry_event = nullptr; }; +extern ClassAllocator preWarmSMAllocator; + /** @class PreWarmQueue @detail diff --git a/include/proxy/http2/Http2ClientSession.h b/include/proxy/http2/Http2ClientSession.h index ec25e9778be..f9ae4ea4304 100644 --- a/include/proxy/http2/Http2ClientSession.h +++ b/include/proxy/http2/Http2ClientSession.h @@ -79,4 +79,4 @@ class Http2ClientSession : public ProxySession, public Http2CommonSession IpEndpoint cached_local_addr; }; -extern ClassAllocator http2ClientSessionAllocator; +extern ClassAllocator http2ClientSessionAllocator; diff --git a/include/proxy/http2/Http2ServerSession.h b/include/proxy/http2/Http2ServerSession.h index ceea1496df9..5b98c78e8e9 100644 --- a/include/proxy/http2/Http2ServerSession.h +++ b/include/proxy/http2/Http2ServerSession.h @@ -103,4 +103,4 @@ class Http2ServerSession : public PoolableSession, public Http2CommonSession bool in_session_table = false; }; -extern ClassAllocator http2ServerSessionAllocator; +extern ClassAllocator http2ServerSessionAllocator; diff --git a/include/proxy/http2/Http2Stream.h b/include/proxy/http2/Http2Stream.h index cb3f15505cb..f9961e777bf 100644 --- a/include/proxy/http2/Http2Stream.h +++ b/include/proxy/http2/Http2Stream.h @@ -287,7 +287,7 @@ class Http2Stream : public ProxyTransaction Event *_write_vio_event = nullptr; }; -extern ClassAllocator http2StreamAllocator; +extern ClassAllocator http2StreamAllocator; //////////////////////////////////////////////////// // INLINE diff --git a/include/proxy/http3/Http3Frame.h b/include/proxy/http3/Http3Frame.h index d1de4e5efd4..cd8d5e860e2 100644 --- a/include/proxy/http3/Http3Frame.h +++ b/include/proxy/http3/Http3Frame.h @@ -175,10 +175,10 @@ using Http3FrameUPtr = std::unique_ptr using Http3DataFrameUPtr = std::unique_ptr; using Http3HeadersFrameUPtr = std::unique_ptr; -extern ClassAllocator http3FrameAllocator; -extern ClassAllocator http3DataFrameAllocator; -extern ClassAllocator http3HeadersFrameAllocator; -extern ClassAllocator http3SettingsFrameAllocator; +extern ClassAllocator http3FrameAllocator; +extern ClassAllocator http3DataFrameAllocator; +extern ClassAllocator http3HeadersFrameAllocator; +extern ClassAllocator http3SettingsFrameAllocator; class Http3FrameDeleter { diff --git a/include/tscore/Allocator.h b/include/tscore/Allocator.h index 50d59fde778..7172e15b1c7 100644 --- a/include/tscore/Allocator.h +++ b/include/tscore/Allocator.h @@ -329,7 +329,7 @@ using Allocator = FreelistAllocator; Allocator for Class objects. */ -template class ClassAllocator : public BaseAllocator +template class ClassAllocator : public BaseAllocator { public: using Value_type = C; @@ -380,8 +380,8 @@ template ~C(); + if constexpr (Destruct_on_free) { + std::destroy_at(ptr); } } @@ -390,7 +390,7 @@ template = sizeof(void *), "Can not allocate instances of this class using ClassAllocator"); }; -template class TrackerClassAllocator : public ClassAllocator +template class TrackerClassAllocator : public ClassAllocator { public: TrackerClassAllocator(const char *name, unsigned int chunk_size = 128, unsigned int alignment = 16) diff --git a/plugins/experimental/memcache/tsmemcache.cc b/plugins/experimental/memcache/tsmemcache.cc index 5f622e8605f..2d33cdde760 100644 --- a/plugins/experimental/memcache/tsmemcache.cc +++ b/plugins/experimental/memcache/tsmemcache.cc @@ -37,7 +37,7 @@ #define REALTIME_MAXDELTA 60 * 60 * 24 * 30 #define STRCMP_REST(_c, _s, _e) (((_e) - (_s)) < (int)sizeof(_c) || STRCMP(_s, _c) || !isspace((_s)[sizeof(_c) - 1])) -ClassAllocator theMCAllocator("MC"); +ClassAllocator theMCAllocator("MC"); static time_t base_day_time; diff --git a/plugins/header_rewrite/matcher_tests.cc b/plugins/header_rewrite/matcher_tests.cc index d7b0820789e..ea0ae607ecb 100644 --- a/plugins/header_rewrite/matcher_tests.cc +++ b/plugins/header_rewrite/matcher_tests.cc @@ -83,7 +83,7 @@ TSHttpTxnServerRespGet(TSHttpTxn, TSMBuffer *, TSMLoc *) return TS_SUCCESS; } -ClassAllocator mutexAllocator("mutexAllocator"); +ClassAllocator mutexAllocator("mutexAllocator"); TEST_CASE("Matcher", "[plugins][header_rewrite]") { diff --git a/src/api/APIHooks.cc b/src/api/APIHooks.cc index 49eb99c9ae1..eb3828c13b1 100644 --- a/src/api/APIHooks.cc +++ b/src/api/APIHooks.cc @@ -30,7 +30,7 @@ #include "iocore/eventsystem/ProxyAllocator.h" #include "iocore/eventsystem/Thread.h" -static ClassAllocator apiHookAllocator("apiHookAllocator"); +static ClassAllocator apiHookAllocator("apiHookAllocator"); APIHook * APIHooks::head() const diff --git a/src/api/InkAPI.cc b/src/api/InkAPI.cc index f1869503f02..df1f4c2aa1a 100644 --- a/src/api/InkAPI.cc +++ b/src/api/InkAPI.cc @@ -129,7 +129,7 @@ static ts::Metrics &global_api_metrics = ts::Metrics::instance(); ConfigUpdateCbTable *global_config_cbs = nullptr; // Fetchpages SM -extern ClassAllocator FetchSMAllocator; +extern ClassAllocator FetchSMAllocator; /* From proxy/http/HttpProxyServerMain.c: */ extern bool ssl_register_protocol(const char *, Continuation *); @@ -139,12 +139,12 @@ extern SSLSessionCache *session_cache; // declared extern in P_SSLConfig.h // External converters. extern MgmtConverter const &HttpDownServerCacheTimeConv; -extern HttpSessionAccept *plugin_http_accept; -extern HttpSessionAccept *plugin_http_transparent_accept; -extern thread_local PluginThreadContext *pluginThreadContext; -extern ClassAllocator INKContAllocator; -extern ClassAllocator INKVConnAllocator; -static ClassAllocator mHandleAllocator("MIMEFieldSDKHandle"); +extern HttpSessionAccept *plugin_http_accept; +extern HttpSessionAccept *plugin_http_transparent_accept; +extern thread_local PluginThreadContext *pluginThreadContext; +extern ClassAllocator INKContAllocator; +extern ClassAllocator INKVConnAllocator; +static ClassAllocator mHandleAllocator("MIMEFieldSDKHandle"); // forward declarations TSReturnCode sdk_sanity_check_null_ptr(void const *ptr); diff --git a/src/api/InkAPITest.cc b/src/api/InkAPITest.cc index 21d80fc57f3..780a60aeb7b 100644 --- a/src/api/InkAPITest.cc +++ b/src/api/InkAPITest.cc @@ -8831,7 +8831,7 @@ std::array SDK_Overridable_Configs = { }; // clang-format on -extern ClassAllocator httpSMAllocator; +extern ClassAllocator httpSMAllocator; REGRESSION_TEST(SDK_API_OVERRIDABLE_CONFIGS)(RegressionTest *test, int /* atype ATS_UNUSED */, int *pstatus) { diff --git a/src/api/InkContInternal.cc b/src/api/InkContInternal.cc index b79ffc1bcdc..5d5ac2cdc61 100644 --- a/src/api/InkContInternal.cc +++ b/src/api/InkContInternal.cc @@ -40,7 +40,7 @@ #include "iocore/eventsystem/ProxyAllocator.h" #include "iocore/eventsystem/VConnection.h" -ClassAllocator INKContAllocator("INKContAllocator"); +ClassAllocator INKContAllocator("INKContAllocator"); namespace { diff --git a/src/api/InkVConnInternal.cc b/src/api/InkVConnInternal.cc index c0898f883f7..ccb740c4c4d 100644 --- a/src/api/InkVConnInternal.cc +++ b/src/api/InkVConnInternal.cc @@ -24,7 +24,7 @@ #include "ts/apidefs.h" #include "ts/InkAPIPrivateIOCore.h" -ClassAllocator INKVConnAllocator("INKVConnAllocator"); +ClassAllocator INKVConnAllocator("INKVConnAllocator"); INKVConnInternal::INKVConnInternal() : INKContInternal(), m_read_vio(), m_write_vio(), m_output_vc(nullptr) { diff --git a/src/iocore/cache/Cache.cc b/src/iocore/cache/Cache.cc index b713f944656..295a4eadb8c 100644 --- a/src/iocore/cache/Cache.cc +++ b/src/iocore/cache/Cache.cc @@ -85,21 +85,21 @@ int cache_config_persist_bad_disks = false; // Globals -CacheStatsBlock cache_rsb; -Cache *theCache = nullptr; -std::vector> gdisks; -int gndisks = 0; -Cache *caches[NUM_CACHE_FRAG_TYPES] = {nullptr}; -CacheSync *cacheDirSync = nullptr; -Store theCacheStore; -StripeSM **gstripes = nullptr; -std::atomic gnstripes = 0; -ClassAllocator cacheVConnectionAllocator("cacheVConnection"); -ClassAllocator cacheEvacuateDocVConnectionAllocator("cacheEvacuateDocVC"); -ClassAllocator evacuationBlockAllocator("evacuationBlock"); -ClassAllocator cacheRemoveContAllocator("cacheRemoveCont"); -ClassAllocator evacuationKeyAllocator("evacuationKey"); -std::unordered_set known_bad_disks; +CacheStatsBlock cache_rsb; +Cache *theCache = nullptr; +std::vector> gdisks; +int gndisks = 0; +Cache *caches[NUM_CACHE_FRAG_TYPES] = {nullptr}; +CacheSync *cacheDirSync = nullptr; +Store theCacheStore; +StripeSM **gstripes = nullptr; +std::atomic gnstripes = 0; +ClassAllocator cacheVConnectionAllocator("cacheVConnection"); +ClassAllocator cacheEvacuateDocVConnectionAllocator("cacheEvacuateDocVC"); +ClassAllocator evacuationBlockAllocator("evacuationBlock"); +ClassAllocator cacheRemoveContAllocator("cacheRemoveCont"); +ClassAllocator evacuationKeyAllocator("evacuationKey"); +std::unordered_set known_bad_disks; namespace { diff --git a/src/iocore/cache/CacheDir.cc b/src/iocore/cache/CacheDir.cc index 76b32a298e5..9d5202c591c 100644 --- a/src/iocore/cache/CacheDir.cc +++ b/src/iocore/cache/CacheDir.cc @@ -58,7 +58,7 @@ DbgCtl dbg_ctl_dir_lookaside{"dir_lookaside"}; // Globals -ClassAllocator openDirEntryAllocator("openDirEntry"); +ClassAllocator openDirEntryAllocator("openDirEntry"); // OpenDir diff --git a/src/iocore/cache/CacheEvacuateDocVC.h b/src/iocore/cache/CacheEvacuateDocVC.h index 51a734c2a3f..f53c7f7ae84 100644 --- a/src/iocore/cache/CacheEvacuateDocVC.h +++ b/src/iocore/cache/CacheEvacuateDocVC.h @@ -48,7 +48,7 @@ class CacheEvacuateDocVC : public CacheVC int evacuateReadHead(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */); }; -extern ClassAllocator cacheEvacuateDocVConnectionAllocator; +extern ClassAllocator cacheEvacuateDocVConnectionAllocator; inline CacheEvacuateDocVC * new_CacheEvacuateDocVC(Continuation *cont) diff --git a/src/iocore/cache/P_CacheInternal.h b/src/iocore/cache/P_CacheInternal.h index 87a21053211..7846f81d5a9 100644 --- a/src/iocore/cache/P_CacheInternal.h +++ b/src/iocore/cache/P_CacheInternal.h @@ -138,9 +138,9 @@ struct CacheRemoveCont : public Continuation { }; // Global Data -extern ClassAllocator cacheVConnectionAllocator; -extern ClassAllocator cacheEvacuateDocVConnectionAllocator; -extern CacheSync *cacheDirSync; +extern ClassAllocator cacheVConnectionAllocator; +extern ClassAllocator cacheEvacuateDocVConnectionAllocator; +extern CacheSync *cacheDirSync; // Function Prototypes int cache_write(CacheVC *, CacheHTTPInfoVector *); int get_alternate_index(CacheHTTPInfoVector *cache_vector, CacheKey key); @@ -411,7 +411,7 @@ next_rand(unsigned int *p) return seed; } -extern ClassAllocator cacheRemoveContAllocator; +extern ClassAllocator cacheRemoveContAllocator; inline CacheRemoveCont * new_CacheRemoveCont() diff --git a/src/iocore/cache/PreservationTable.h b/src/iocore/cache/PreservationTable.h index 1b55258f025..26735f8beff 100644 --- a/src/iocore/cache/PreservationTable.h +++ b/src/iocore/cache/PreservationTable.h @@ -197,8 +197,8 @@ PreservationTable::evac_bucket_valid(off_t bucket) const return (bucket >= 0 && bucket < evacuate_size); } -extern ClassAllocator evacuationBlockAllocator; -extern ClassAllocator evacuationKeyAllocator; +extern ClassAllocator evacuationBlockAllocator; +extern ClassAllocator evacuationKeyAllocator; inline EvacuationBlock * new_EvacuationBlock() diff --git a/src/iocore/cache/RamCacheCLFUS.cc b/src/iocore/cache/RamCacheCLFUS.cc index 578852e6831..639d2faa33c 100644 --- a/src/iocore/cache/RamCacheCLFUS.cc +++ b/src/iocore/cache/RamCacheCLFUS.cc @@ -173,7 +173,7 @@ RamCacheCLFUSCompressor::mainEvent(int /* event ATS_UNUSED */, Event *e) return EVENT_CONT; } -ClassAllocator ramCacheCLFUSEntryAllocator("RamCacheCLFUSEntry"); +ClassAllocator ramCacheCLFUSEntryAllocator("RamCacheCLFUSEntry"); static const int bucket_sizes[] = {127, 251, 509, 1021, 2039, 4093, 8191, 16381, 32749, 65521, 131071, 262139, 524287, 1048573, 2097143, 4194301, 8388593, 16777213, diff --git a/src/iocore/cache/RamCacheLRU.cc b/src/iocore/cache/RamCacheLRU.cc index cf2f5be2709..ca3d8a384ad 100644 --- a/src/iocore/cache/RamCacheLRU.cc +++ b/src/iocore/cache/RamCacheLRU.cc @@ -89,7 +89,7 @@ RamCacheLRU::size() const return s; } -ClassAllocator ramCacheLRUEntryAllocator("RamCacheLRUEntry"); +ClassAllocator ramCacheLRUEntryAllocator("RamCacheLRUEntry"); static const int bucket_sizes[] = {8191, 16381, 32749, 65521, 131071, 262139, 524287, 1048573, 2097143, 4194301, 8388593, 16777213, 33554393, 67108859, 134217689, 268435399, 536870909, 1073741827}; diff --git a/src/iocore/cache/StripeSM.h b/src/iocore/cache/StripeSM.h index a51021de9fc..3ae476ac69e 100644 --- a/src/iocore/cache/StripeSM.h +++ b/src/iocore/cache/StripeSM.h @@ -247,10 +247,10 @@ class StripeSM : public Continuation, public Stripe // Global Data -extern StripeSM **gstripes; -extern std::atomic gnstripes; -extern ClassAllocator openDirEntryAllocator; -extern unsigned short *vol_hash_table; +extern StripeSM **gstripes; +extern std::atomic gnstripes; +extern ClassAllocator openDirEntryAllocator; +extern unsigned short *vol_hash_table; // inline Functions diff --git a/src/iocore/cache/unit_tests/stub.cc b/src/iocore/cache/unit_tests/stub.cc index 7fb06a10a75..177f20be1ee 100644 --- a/src/iocore/cache/unit_tests/stub.cc +++ b/src/iocore/cache/unit_tests/stub.cc @@ -56,7 +56,7 @@ TSIOBufferReaderConsume(TSIOBufferReader /* readerp ATS_UNUSED */, int64_t /* nb } #include "proxy/FetchSM.h" -ClassAllocator FetchSMAllocator("unusedFetchSMAllocator"); +ClassAllocator FetchSMAllocator("unusedFetchSMAllocator"); bool FetchSM::is_initialized() { diff --git a/src/iocore/dns/DNS.cc b/src/iocore/dns/DNS.cc index 50cbcace804..4d107238e96 100644 --- a/src/iocore/dns/DNS.cc +++ b/src/iocore/dns/DNS.cc @@ -90,11 +90,11 @@ is_addr_query(int qtype) } } // namespace -DNSProcessor dnsProcessor; -ClassAllocator dnsEntryAllocator("dnsEntryAllocator"); +DNSProcessor dnsProcessor; +ClassAllocator dnsEntryAllocator("dnsEntryAllocator"); // Users are expected to free these entries in short order! // We could page align this buffer to enable page flipping for recv... -ClassAllocator dnsBufAllocator("dnsBufAllocator", 2); +ClassAllocator dnsBufAllocator("dnsBufAllocator", 2); // // Function Prototypes diff --git a/src/iocore/dns/SplitDNS.cc b/src/iocore/dns/SplitDNS.cc index ed145c46ab5..7542143e1c6 100644 --- a/src/iocore/dns/SplitDNS.cc +++ b/src/iocore/dns/SplitDNS.cc @@ -48,7 +48,7 @@ static const char modulePrefix[] = "[SplitDNS]"; ConfigUpdateHandler *SplitDNSConfig::splitDNSUpdate = nullptr; -static ClassAllocator DNSReqAllocator("DNSRequestDataAllocator"); +static ClassAllocator DNSReqAllocator("DNSRequestDataAllocator"); /* -------------------------------------------------------------- used by a lot of protocols. We do not have dest ip in most diff --git a/src/iocore/eventsystem/IOBuffer.cc b/src/iocore/eventsystem/IOBuffer.cc index 66decc4bac6..34d7cb1c36c 100644 --- a/src/iocore/eventsystem/IOBuffer.cc +++ b/src/iocore/eventsystem/IOBuffer.cc @@ -40,12 +40,12 @@ MeteredAllocator ioBufAllocator[DEFAULT_BUFFER_SIZES]; #else FreelistAllocator ioBufAllocator[DEFAULT_BUFFER_SIZES]; #endif -ClassAllocator ioAllocator("ioAllocator", DEFAULT_BUFFER_NUMBER); -ClassAllocator ioDataAllocator("ioDataAllocator", DEFAULT_BUFFER_NUMBER); -ClassAllocator ioBlockAllocator("ioBlockAllocator", DEFAULT_BUFFER_NUMBER); -int64_t default_large_iobuffer_size = DEFAULT_LARGE_BUFFER_SIZE; -int64_t default_small_iobuffer_size = DEFAULT_SMALL_BUFFER_SIZE; -int64_t max_iobuffer_size = DEFAULT_BUFFER_SIZES - 1; +ClassAllocator ioAllocator("ioAllocator", DEFAULT_BUFFER_NUMBER); +ClassAllocator ioDataAllocator("ioDataAllocator", DEFAULT_BUFFER_NUMBER); +ClassAllocator ioBlockAllocator("ioBlockAllocator", DEFAULT_BUFFER_NUMBER); +int64_t default_large_iobuffer_size = DEFAULT_LARGE_BUFFER_SIZE; +int64_t default_small_iobuffer_size = DEFAULT_SMALL_BUFFER_SIZE; +int64_t max_iobuffer_size = DEFAULT_BUFFER_SIZES - 1; // // Initialization diff --git a/src/iocore/eventsystem/Lock.cc b/src/iocore/eventsystem/Lock.cc index bee54f43a31..e038f0bca04 100644 --- a/src/iocore/eventsystem/Lock.cc +++ b/src/iocore/eventsystem/Lock.cc @@ -31,7 +31,7 @@ #include "P_EventSystem.h" #include "tscore/Diags.h" -ClassAllocator mutexAllocator("mutexAllocator"); +ClassAllocator mutexAllocator("mutexAllocator"); namespace { diff --git a/src/iocore/eventsystem/P_IOBuffer.h b/src/iocore/eventsystem/P_IOBuffer.h index e159cbafc57..7fc98aeb26d 100644 --- a/src/iocore/eventsystem/P_IOBuffer.h +++ b/src/iocore/eventsystem/P_IOBuffer.h @@ -619,7 +619,7 @@ IOBufferReader::reset() // inline functions definitions // //////////////////////////////////////////////////////////////// -extern ClassAllocator ioAllocator; +extern ClassAllocator ioAllocator; TS_INLINE MIOBuffer::MIOBuffer(int64_t default_size_index) diff --git a/src/iocore/eventsystem/ProtectedQueue.cc b/src/iocore/eventsystem/ProtectedQueue.cc index 6be82e388df..2d31d76d1dd 100644 --- a/src/iocore/eventsystem/ProtectedQueue.cc +++ b/src/iocore/eventsystem/ProtectedQueue.cc @@ -41,7 +41,7 @@ // // #define EAGER_SIGNALLING -extern ClassAllocator eventAllocator; +extern ClassAllocator eventAllocator; void ProtectedQueue::enqueue(Event *e) diff --git a/src/iocore/eventsystem/UnixEvent.cc b/src/iocore/eventsystem/UnixEvent.cc index 8043155b769..8fad18cb56c 100644 --- a/src/iocore/eventsystem/UnixEvent.cc +++ b/src/iocore/eventsystem/UnixEvent.cc @@ -31,7 +31,7 @@ #include "tscore/ink_stack_trace.h" -ClassAllocator eventAllocator("eventAllocator", 256); +ClassAllocator eventAllocator("eventAllocator", 256); void Event::schedule_imm(int acallback_event) diff --git a/src/iocore/hostdb/HostDB.cc b/src/iocore/hostdb/HostDB.cc index 4db02ef94cc..dbcf25d87cd 100644 --- a/src/iocore/hostdb/HostDB.cc +++ b/src/iocore/hostdb/HostDB.cc @@ -72,7 +72,7 @@ static swoc::file::path hostdb_hostfile_path; int hostdb_disable_reverse_lookup = 0; int hostdb_max_iobuf_index = BUFFER_SIZE_INDEX_32K; -ClassAllocator hostDBContAllocator("hostDBContAllocator"); +ClassAllocator hostDBContAllocator("hostDBContAllocator"); namespace { diff --git a/src/iocore/hostdb/P_RefCountCache.h b/src/iocore/hostdb/P_RefCountCache.h index be75881cac9..6560313b5e6 100644 --- a/src/iocore/hostdb/P_RefCountCache.h +++ b/src/iocore/hostdb/P_RefCountCache.h @@ -115,7 +115,7 @@ class RefCountCacheHashEntry }; // Since the hashing values are all fixed size, we can simply use a classAllocator to avoid mallocs -extern ClassAllocator> expiryQueueEntry; +extern ClassAllocator, false> expiryQueueEntry; struct RefCountCacheLinkage { using key_type = uint64_t const; diff --git a/src/iocore/hostdb/RefCountCache.cc b/src/iocore/hostdb/RefCountCache.cc index 8e3e590218e..3fa1e9c6eae 100644 --- a/src/iocore/hostdb/RefCountCache.cc +++ b/src/iocore/hostdb/RefCountCache.cc @@ -22,9 +22,9 @@ #include "P_RefCountCache.h" // Since the hashing values are all fixed size, we can simply use a classAllocator to avoid mallocs -static ClassAllocator refCountCacheHashingValueAllocator("refCountCacheHashingValueAllocator"); +static ClassAllocator refCountCacheHashingValueAllocator("refCountCacheHashingValueAllocator"); -ClassAllocator> expiryQueueEntry("expiryQueueEntry"); +ClassAllocator, false> expiryQueueEntry("expiryQueueEntry"); RefCountCacheHashEntry * RefCountCacheHashEntry::alloc() diff --git a/src/iocore/net/OCSPStapling.cc b/src/iocore/net/OCSPStapling.cc index af6d9f18197..23ac23c0a0b 100644 --- a/src/iocore/net/OCSPStapling.cc +++ b/src/iocore/net/OCSPStapling.cc @@ -49,7 +49,7 @@ // bytes #define MAX_OCSP_GET_ENCODED_LENGTH 255 // maximum of 254 bytes + \0 -extern ClassAllocator FetchSMAllocator; +extern ClassAllocator FetchSMAllocator; // clang-format off #pragma GCC diagnostic push diff --git a/src/iocore/net/P_QUICNet.h b/src/iocore/net/P_QUICNet.h index 29f02c5e700..fa045daa8aa 100644 --- a/src/iocore/net/P_QUICNet.h +++ b/src/iocore/net/P_QUICNet.h @@ -74,4 +74,4 @@ get_QUICPollCont(EThread *t) return static_cast(ETHREAD_GET_PTR(t, quic_NetProcessor.quicPollCont_offset)); } -extern ClassAllocator quicPollEventAllocator; +extern ClassAllocator quicPollEventAllocator; diff --git a/src/iocore/net/P_QUICNetVConnection.h b/src/iocore/net/P_QUICNetVConnection.h index 4f30e3ba74b..e6fec2b8ea5 100644 --- a/src/iocore/net/P_QUICNetVConnection.h +++ b/src/iocore/net/P_QUICNetVConnection.h @@ -236,4 +236,4 @@ class QUICNetVConnection : public UnixNetVConnection, bool _is_cert_verified = false; }; -extern ClassAllocator quicNetVCAllocator; +extern ClassAllocator quicNetVCAllocator; diff --git a/src/iocore/net/P_SSLNetVConnection.h b/src/iocore/net/P_SSLNetVConnection.h index 74174774805..fdc52726e49 100644 --- a/src/iocore/net/P_SSLNetVConnection.h +++ b/src/iocore/net/P_SSLNetVConnection.h @@ -438,4 +438,4 @@ class SSLNetVConnection : public UnixNetVConnection, using SSLNetVConnHandler = int (SSLNetVConnection::*)(int, void *); -extern ClassAllocator sslNetVCAllocator; +extern ClassAllocator sslNetVCAllocator; diff --git a/src/iocore/net/P_Socks.h b/src/iocore/net/P_Socks.h index d513b7dfa2a..d26c8ee38f3 100644 --- a/src/iocore/net/P_Socks.h +++ b/src/iocore/net/P_Socks.h @@ -125,4 +125,4 @@ struct SocksEntry : public Continuation { using SocksEntryHandler = int (SocksEntry::*)(int, void *); -extern ClassAllocator socksAllocator; +extern ClassAllocator socksAllocator; diff --git a/src/iocore/net/P_UDPIOEvent.h b/src/iocore/net/P_UDPIOEvent.h index e08e2f5be51..075ad7ddee3 100644 --- a/src/iocore/net/P_UDPIOEvent.h +++ b/src/iocore/net/P_UDPIOEvent.h @@ -100,7 +100,7 @@ class UDPIOEvent : public Event int bytesTransferred = 0; // actual bytes transferred }; -extern ClassAllocator UDPIOEventAllocator; +extern ClassAllocator UDPIOEventAllocator; TS_INLINE void UDPIOEvent::free(UDPIOEvent *e) { diff --git a/src/iocore/net/P_UnixNetVConnection.h b/src/iocore/net/P_UnixNetVConnection.h index 90923dda6b2..71d27374541 100644 --- a/src/iocore/net/P_UnixNetVConnection.h +++ b/src/iocore/net/P_UnixNetVConnection.h @@ -251,7 +251,7 @@ class UnixNetVConnection : public NetVConnection, public NetEvent std::shared_ptr conn_track_group; }; -extern ClassAllocator netVCAllocator; +extern ClassAllocator netVCAllocator; using NetVConnHandler = int (UnixNetVConnection::*)(int, void *); diff --git a/src/iocore/net/QUICNet.cc b/src/iocore/net/QUICNet.cc index 9a0e62128c4..5dc5b9393b6 100644 --- a/src/iocore/net/QUICNet.cc +++ b/src/iocore/net/QUICNet.cc @@ -30,7 +30,7 @@ #include "tscore/ink_atomic.h" #include -ClassAllocator quicPollEventAllocator("quicPollEvent"); +ClassAllocator quicPollEventAllocator("quicPollEvent"); void QUICPollEvent::init(QUICConnection *con, UDPPacket *packet) diff --git a/src/iocore/net/QUICNetVConnection.cc b/src/iocore/net/QUICNetVConnection.cc index d3bc4a76d12..d113ae593e1 100644 --- a/src/iocore/net/QUICNetVConnection.cc +++ b/src/iocore/net/QUICNetVConnection.cc @@ -50,7 +50,7 @@ DbgCtl dbg_ctl_v_quic_net{"v_quic_net"}; #define QUICConDebug(fmt, ...) Dbg(dbg_ctl_quic_net, "[%s] " fmt, this->cids().data(), ##__VA_ARGS__) #define QUICConVDebug(fmt, ...) Dbg(dbg_ctl_v_quic_net, "[%s] " fmt, this->cids().data(), ##__VA_ARGS__) -ClassAllocator quicNetVCAllocator("quicNetVCAllocator"); +ClassAllocator quicNetVCAllocator("quicNetVCAllocator"); QUICNetVConnection::QUICNetVConnection() { diff --git a/src/iocore/net/SSLNetVConnection.cc b/src/iocore/net/SSLNetVConnection.cc index 2e242334628..787936fb76c 100644 --- a/src/iocore/net/SSLNetVConnection.cc +++ b/src/iocore/net/SSLNetVConnection.cc @@ -74,7 +74,7 @@ using namespace std::literals; #define SSL_WAIT_FOR_ASYNC 12 #define SSL_RESTART 13 -ClassAllocator sslNetVCAllocator("sslNetVCAllocator"); +ClassAllocator sslNetVCAllocator("sslNetVCAllocator"); namespace { diff --git a/src/iocore/net/Socks.cc b/src/iocore/net/Socks.cc index 06ccd424050..94618286821 100644 --- a/src/iocore/net/Socks.cc +++ b/src/iocore/net/Socks.cc @@ -39,7 +39,7 @@ using namespace swoc::literals; -ClassAllocator socksAllocator("socksAllocator"); +ClassAllocator socksAllocator("socksAllocator"); namespace { diff --git a/src/iocore/net/UDPIOEvent.cc b/src/iocore/net/UDPIOEvent.cc index 12c7b97c15c..f25767d83d4 100644 --- a/src/iocore/net/UDPIOEvent.cc +++ b/src/iocore/net/UDPIOEvent.cc @@ -24,4 +24,4 @@ #include "tscore/Allocator.h" #include "P_UDPIOEvent.h" -ClassAllocator UDPIOEventAllocator("UDPIOEventAllocator"); +ClassAllocator UDPIOEventAllocator("UDPIOEventAllocator"); diff --git a/src/iocore/net/UnixNetVConnection.cc b/src/iocore/net/UnixNetVConnection.cc index 7285e618f9b..29e1b4dead5 100644 --- a/src/iocore/net/UnixNetVConnection.cc +++ b/src/iocore/net/UnixNetVConnection.cc @@ -38,7 +38,7 @@ #define STATE_FROM_VIO(_x) ((NetState *)(((char *)(_x)) - STATE_VIO_OFFSET)) // Global -ClassAllocator netVCAllocator("netVCAllocator"); +ClassAllocator netVCAllocator("netVCAllocator"); namespace { diff --git a/src/iocore/net/UnixUDPNet.cc b/src/iocore/net/UnixUDPNet.cc index 29a771ab1c0..b0a012f9827 100644 --- a/src/iocore/net/UnixUDPNet.cc +++ b/src/iocore/net/UnixUDPNet.cc @@ -64,8 +64,8 @@ using UDPNetContHandler = int (UDPNetHandler::*)(int, void *); -ClassAllocator udpPacketAllocator("udpPacketAllocator"); -EventType ET_UDP; +ClassAllocator udpPacketAllocator("udpPacketAllocator"); +EventType ET_UDP; namespace { @@ -746,7 +746,7 @@ class UDPReadContinuation : public Continuation ink_hrtime timeout_interval = 0; }; -ClassAllocator udpReadContAllocator("udpReadContAllocator"); +ClassAllocator udpReadContAllocator("udpReadContAllocator"); UDPReadContinuation::UDPReadContinuation(Event *completionToken) : Continuation(nullptr), diff --git a/src/iocore/net/libinknet_stub.cc b/src/iocore/net/libinknet_stub.cc index 9d1c8b6441c..de113b89378 100644 --- a/src/iocore/net/libinknet_stub.cc +++ b/src/iocore/net/libinknet_stub.cc @@ -26,7 +26,7 @@ AppVersionInfo appVersionInfo; #include "proxy/FetchSM.h" -ClassAllocator FetchSMAllocator("unusedFetchSMAllocator"); +ClassAllocator FetchSMAllocator("unusedFetchSMAllocator"); bool FetchSM::is_initialized() { diff --git a/src/iocore/utils/OneWayMultiTunnel.cc b/src/iocore/utils/OneWayMultiTunnel.cc index d439a987f0b..ec33175fafc 100644 --- a/src/iocore/utils/OneWayMultiTunnel.cc +++ b/src/iocore/utils/OneWayMultiTunnel.cc @@ -38,7 +38,7 @@ // ////////////////////////////////////////////////////////////////////////////// -ClassAllocator OneWayMultiTunnelAllocator("OneWayMultiTunnelAllocator"); +ClassAllocator OneWayMultiTunnelAllocator("OneWayMultiTunnelAllocator"); OneWayMultiTunnel::OneWayMultiTunnel() : OneWayTunnel() { diff --git a/src/iocore/utils/OneWayTunnel.cc b/src/iocore/utils/OneWayTunnel.cc index 8274fcf5175..f51dc85bc44 100644 --- a/src/iocore/utils/OneWayTunnel.cc +++ b/src/iocore/utils/OneWayTunnel.cc @@ -43,7 +43,7 @@ // ////////////////////////////////////////////////////////////////////////////// -ClassAllocator OneWayTunnelAllocator("OneWayTunnelAllocator"); +ClassAllocator OneWayTunnelAllocator("OneWayTunnelAllocator"); namespace { diff --git a/src/proxy/FetchSM.cc b/src/proxy/FetchSM.cc index cc024c88366..6880b5570d6 100644 --- a/src/proxy/FetchSM.cc +++ b/src/proxy/FetchSM.cc @@ -32,7 +32,7 @@ #define DEBUG_TAG "FetchSM" #define FETCH_LOCK_RETRY_TIME HRTIME_MSECONDS(10) -ClassAllocator FetchSMAllocator("FetchSMAllocator"); +ClassAllocator FetchSMAllocator("FetchSMAllocator"); namespace { diff --git a/src/proxy/ProxyTransaction.cc b/src/proxy/ProxyTransaction.cc index 3d0bea20086..db72902dcc7 100644 --- a/src/proxy/ProxyTransaction.cc +++ b/src/proxy/ProxyTransaction.cc @@ -32,7 +32,7 @@ DbgCtl dbg_ctl_http_txn{"http_txn"}; #define HttpTxnDebug(fmt, ...) SsnDbg(this, dbg_ctl_http_txn, fmt, __VA_ARGS__) -extern ClassAllocator httpSMAllocator; +extern ClassAllocator httpSMAllocator; ProxyTransaction::ProxyTransaction(ProxySession *session) : VConnection(nullptr), _proxy_ssn(session) {} diff --git a/src/proxy/hdrs/HTTP.cc b/src/proxy/hdrs/HTTP.cc index a6c41c5f4a3..b7a8db27bda 100644 --- a/src/proxy/hdrs/HTTP.cc +++ b/src/proxy/hdrs/HTTP.cc @@ -1936,7 +1936,7 @@ HTTPHdrImpl::check_strings(HeapCheck *heaps, int num_heaps) } } -ClassAllocator httpCacheAltAllocator("httpCacheAltAllocator"); +ClassAllocator httpCacheAltAllocator("httpCacheAltAllocator"); /*------------------------------------------------------------------------- -------------------------------------------------------------------------*/ diff --git a/src/proxy/http/Http1ClientSession.cc b/src/proxy/http/Http1ClientSession.cc index 4a9cdcb5145..999e0c0ad69 100644 --- a/src/proxy/http/Http1ClientSession.cc +++ b/src/proxy/http/Http1ClientSession.cc @@ -59,7 +59,7 @@ ink_mutex debug_cs_list_mutex; #endif /* USE_HTTP_DEBUG_LISTS */ -ClassAllocator http1ClientSessionAllocator("http1ClientSessionAllocator"); +ClassAllocator http1ClientSessionAllocator("http1ClientSessionAllocator"); namespace { diff --git a/src/proxy/http/Http1ServerSession.cc b/src/proxy/http/Http1ServerSession.cc index 38a617e9227..bcfe5996928 100644 --- a/src/proxy/http/Http1ServerSession.cc +++ b/src/proxy/http/Http1ServerSession.cc @@ -36,7 +36,7 @@ #include "proxy/http/HttpSessionManager.h" #include "proxy/http/HttpSM.h" -ClassAllocator httpServerSessionAllocator("httpServerSessionAllocator"); +ClassAllocator httpServerSessionAllocator("httpServerSessionAllocator"); namespace { diff --git a/src/proxy/http/HttpSM.cc b/src/proxy/http/HttpSM.cc index fb306a7f6b3..c61480e2073 100644 --- a/src/proxy/http/HttpSM.cc +++ b/src/proxy/http/HttpSM.cc @@ -176,7 +176,7 @@ do_outbound_proxy_protocol(MIOBuffer *miob, NetVConnection *vc_out, NetVConnecti return len; } -ClassAllocator httpSMAllocator("httpSMAllocator"); +ClassAllocator httpSMAllocator("httpSMAllocator"); void initialize_thread_for_connecting_pools(EThread *thread) @@ -251,11 +251,8 @@ HttpSM::get_server_connect_timeout() HttpSM::HttpSM() : Continuation(nullptr), vc_table(this) {} -void -HttpSM::cleanup() +HttpSM::~HttpSM() { - t_state.destroy(); - api_hooks.clear(); http_parser_clear(&http_parser); HttpConfig::release(t_state.http_config_param); @@ -280,7 +277,6 @@ HttpSM::cleanup() void HttpSM::destroy() { - cleanup(); THREAD_FREE(this, httpSMAllocator, this_thread()); } diff --git a/src/proxy/http/PreWarmManager.cc b/src/proxy/http/PreWarmManager.cc index 416e6a55d85..c70be8a54c5 100644 --- a/src/proxy/http/PreWarmManager.cc +++ b/src/proxy/http/PreWarmManager.cc @@ -40,8 +40,8 @@ #define PreWarmSMDbg(fmt, ...) Dbg(dbg_ctl_prewarm_sm, "[%p] " fmt, this, ##__VA_ARGS__); #define PreWarmSMVDbg(fmt, ...) Dbg(dbg_ctl_v_prewarm_sm, "[%p] " fmt, this, ##__VA_ARGS__); -ClassAllocator preWarmSMAllocator("preWarmSMAllocator"); -PreWarmManager prewarmManager; +ClassAllocator preWarmSMAllocator("preWarmSMAllocator"); +PreWarmManager prewarmManager; namespace { diff --git a/src/proxy/http/remap/RemapPlugins.cc b/src/proxy/http/remap/RemapPlugins.cc index bda83973703..9c55ee26659 100644 --- a/src/proxy/http/remap/RemapPlugins.cc +++ b/src/proxy/http/remap/RemapPlugins.cc @@ -26,7 +26,7 @@ namespace { -ClassAllocator pluginAllocator("RemapPluginsAlloc"); +ClassAllocator pluginAllocator("RemapPluginsAlloc"); DbgCtl dbg_ctl_url_rewrite{"url_rewrite"}; diff --git a/src/proxy/http/remap/unit-tests/nexthop_test_stubs.cc b/src/proxy/http/remap/unit-tests/nexthop_test_stubs.cc index d5945d30c6c..bf76965cf5d 100644 --- a/src/proxy/http/remap/unit-tests/nexthop_test_stubs.cc +++ b/src/proxy/http/remap/unit-tests/nexthop_test_stubs.cc @@ -32,11 +32,10 @@ #include "proxy/http/HttpSM.h" #include "nexthop_test_stubs.h" +int ParentConfig::m_id = 0; + HttpSM::HttpSM() : Continuation(nullptr), vc_table(this) {} -void -HttpSM::cleanup() -{ -} +HttpSM::~HttpSM() {} void HttpSM::destroy() { diff --git a/src/proxy/http/remap/unit-tests/plugin_stub.cc b/src/proxy/http/remap/unit-tests/plugin_stub.cc index c998d666a35..58e670c0513 100644 --- a/src/proxy/http/remap/unit-tests/plugin_stub.cc +++ b/src/proxy/http/remap/unit-tests/plugin_stub.cc @@ -25,4 +25,4 @@ #include "proxy/http/remap/PluginFactory.h" thread_local PluginThreadContext *pluginThreadContext; -ClassAllocator mutexAllocator("mutexAllocator"); +ClassAllocator mutexAllocator("mutexAllocator"); diff --git a/src/proxy/http2/Http2ClientSession.cc b/src/proxy/http2/Http2ClientSession.cc index 22876704191..da42c2ef9b2 100644 --- a/src/proxy/http2/Http2ClientSession.cc +++ b/src/proxy/http2/Http2ClientSession.cc @@ -29,7 +29,7 @@ #include "iocore/net/TLSSNISupport.h" #include "iocore/net/TLSEarlyDataSupport.h" -ClassAllocator http2ClientSessionAllocator("http2ClientSessionAllocator"); +ClassAllocator http2ClientSessionAllocator("http2ClientSessionAllocator"); namespace { diff --git a/src/proxy/http2/Http2ServerSession.cc b/src/proxy/http2/Http2ServerSession.cc index e201bc8ae14..e62dfc853e1 100644 --- a/src/proxy/http2/Http2ServerSession.cc +++ b/src/proxy/http2/Http2ServerSession.cc @@ -29,7 +29,7 @@ #include "proxy/http2/Http2CommonSessionInternal.h" #include "proxy/http/HttpSessionManager.h" -ClassAllocator http2ServerSessionAllocator("http2ServerSessionAllocator"); +ClassAllocator http2ServerSessionAllocator("http2ServerSessionAllocator"); static int send_connection_event(Continuation *cont, int event, void *edata) diff --git a/src/proxy/http2/Http2Stream.cc b/src/proxy/http2/Http2Stream.cc index 536b8f4ffb0..a5cdc20b8ac 100644 --- a/src/proxy/http2/Http2Stream.cc +++ b/src/proxy/http2/Http2Stream.cc @@ -49,7 +49,7 @@ DbgCtl dbg_ctl_http2_stream{"http2_stream"}; #define Http2StreamDebug(fmt, ...) \ SsnDbg(_proxy_ssn, dbg_ctl_http2_stream, "[%" PRId64 "] [%u] " fmt, _proxy_ssn->connection_id(), this->get_id(), ##__VA_ARGS__); -ClassAllocator http2StreamAllocator("http2StreamAllocator"); +ClassAllocator http2StreamAllocator("http2StreamAllocator"); Http2Stream::Http2Stream(ProxySession *session, Http2StreamId sid, ssize_t initial_peer_rwnd, ssize_t initial_local_rwnd, bool registered_stream) diff --git a/src/proxy/http3/Http3Frame.cc b/src/proxy/http3/Http3Frame.cc index 8fe815b217f..b3de9d2bffe 100644 --- a/src/proxy/http3/Http3Frame.cc +++ b/src/proxy/http3/Http3Frame.cc @@ -27,10 +27,10 @@ #include "proxy/http3/Http3Frame.h" #include "proxy/http3/Http3Config.h" -ClassAllocator http3FrameAllocator("http3FrameAllocator"); -ClassAllocator http3DataFrameAllocator("http3DataFrameAllocator"); -ClassAllocator http3HeadersFrameAllocator("http3HeadersFrameAllocator"); -ClassAllocator http3SettingsFrameAllocator("http3SettingsFrameAllocator"); +ClassAllocator http3FrameAllocator("http3FrameAllocator"); +ClassAllocator http3DataFrameAllocator("http3DataFrameAllocator"); +ClassAllocator http3HeadersFrameAllocator("http3HeadersFrameAllocator"); +ClassAllocator http3SettingsFrameAllocator("http3SettingsFrameAllocator"); namespace { diff --git a/src/traffic_quic/traffic_quic.cc b/src/traffic_quic/traffic_quic.cc index 860b57c1ea6..b46bdac0461 100644 --- a/src/traffic_quic/traffic_quic.cc +++ b/src/traffic_quic/traffic_quic.cc @@ -314,8 +314,8 @@ HttpSM::init(bool from_early_data) ink_abort("do not call stub"); } -ClassAllocator httpSMAllocator("httpSMAllocator"); -HttpAPIHooks *http_global_hooks; +ClassAllocator httpSMAllocator("httpSMAllocator"); +HttpAPIHooks *http_global_hooks; HttpVCTable::HttpVCTable(HttpSM *) {} @@ -345,7 +345,7 @@ PreWarmManager::reconfigure() PreWarmManager prewarmManager; #include "proxy/FetchSM.h" -ClassAllocator FetchSMAllocator("unusedFetchSMAllocator"); +ClassAllocator FetchSMAllocator("unusedFetchSMAllocator"); bool FetchSM::is_initialized() { diff --git a/src/traffic_server/SocksProxy.cc b/src/traffic_server/SocksProxy.cc index 97aa76ac90d..798ad80e8da 100644 --- a/src/traffic_server/SocksProxy.cc +++ b/src/traffic_server/SocksProxy.cc @@ -139,7 +139,7 @@ struct SocksProxy : public Continuation { int recursion = 0; }; -ClassAllocator socksProxyAllocator("socksProxyAllocator"); +ClassAllocator socksProxyAllocator("socksProxyAllocator"); void SocksProxy::init(NetVConnection *netVC) diff --git a/src/tscore/CMakeLists.txt b/src/tscore/CMakeLists.txt index b9f856f56c1..8b064525ea2 100644 --- a/src/tscore/CMakeLists.txt +++ b/src/tscore/CMakeLists.txt @@ -177,6 +177,7 @@ if(BUILD_TESTING) unit_tests/test_scoped_resource.cc unit_tests/test_Version.cc unit_tests/test_ArgParser_MutexGroup.cc + unit_tests/test_Allocator.cc ) target_link_libraries( test_tscore diff --git a/src/tscore/unit_tests/test_Allocator.cc b/src/tscore/unit_tests/test_Allocator.cc new file mode 100644 index 00000000000..5d1a6afce7c --- /dev/null +++ b/src/tscore/unit_tests/test_Allocator.cc @@ -0,0 +1,330 @@ +/** @file + + Allocator tests. + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#include "tscore/Allocator.h" + +#include +#include +#include + +// Counter to track constructor/destructor calls +static int g_construct_count = 0; +static int g_destruct_count = 0; + +// Simple POD type +struct SimplePOD { + int x; + double y; + void *ptr; +}; + +// Type with non-trivial destructor that tracks calls +// Must be at least sizeof(void*) for ClassAllocator +struct TrackedObject { + int value; + void *padding; // Ensure size >= sizeof(void*) + + TrackedObject(int v = 0) : value(v), padding(nullptr) { g_construct_count++; } + + ~TrackedObject() { g_destruct_count++; } +}; + +// Type with resource management (RAII) +struct ResourceHolder { + std::unique_ptr resource; + bool *destroyed_flag; + + ResourceHolder(int val, bool *flag) : resource(std::make_unique(val)), destroyed_flag(flag) {} + + ~ResourceHolder() + { + if (destroyed_flag) { + *destroyed_flag = true; + } + } +}; + +// Type with complex state +struct ComplexObject { + std::string name; + int id; + double data[10]; + + ComplexObject(std::string n, int i) : name(std::move(n)), id(i) + { + for (int j = 0; j < 10; ++j) { + data[j] = i * j; + } + } + + ~ComplexObject() = default; +}; + +// Type with explicit cleanup +struct CleanupTracker { + int *counter; + + explicit CleanupTracker(int *c) : counter(c) + { + if (counter) { + (*counter)++; + } + } + + ~CleanupTracker() + { + if (counter) { + (*counter)--; + } + } + + // Delete copy operations to ensure proper lifecycle + CleanupTracker(const CleanupTracker &) = delete; + CleanupTracker &operator=(const CleanupTracker &) = delete; +}; + +TEST_CASE("ClassAllocator basic allocation", "[libts][allocator]") +{ + ClassAllocator allocator("test_simple_pod"); + + SECTION("Allocate and free simple POD") + { + SimplePOD *obj = allocator.alloc(); + REQUIRE(obj != nullptr); + + obj->x = 42; + obj->y = 3.14; + obj->ptr = nullptr; + + REQUIRE(obj->x == 42); + REQUIRE(obj->y == 3.14); + + allocator.free(obj); + } + + SECTION("Allocate multiple objects") + { + constexpr int count = 10; + std::vector objects; + + for (int i = 0; i < count; ++i) { + SimplePOD *obj = allocator.alloc(); + REQUIRE(obj != nullptr); + obj->x = i; + objects.push_back(obj); + } + + for (int i = 0; i < count; ++i) { + REQUIRE(objects[i]->x == i); + } + + for (auto *obj : objects) { + allocator.free(obj); + } + } +} + +TEST_CASE("ClassAllocator destructor calls", "[libts][allocator]") +{ + SECTION("Destructor called on free") + { + g_construct_count = 0; + g_destruct_count = 0; + + ClassAllocator allocator("test_tracked"); + + TrackedObject *obj = allocator.alloc(42); + REQUIRE(obj != nullptr); + REQUIRE(obj->value == 42); + REQUIRE(g_construct_count == 1); + REQUIRE(g_destruct_count == 0); + + allocator.free(obj); + REQUIRE(g_destruct_count == 1); + } + + SECTION("Multiple destructor calls") + { + g_construct_count = 0; + g_destruct_count = 0; + + ClassAllocator allocator("test_tracked_multi"); + + constexpr int count = 5; + std::vector objects; + + for (int i = 0; i < count; ++i) { + objects.push_back(allocator.alloc(i)); + } + + REQUIRE(g_construct_count == count); + REQUIRE(g_destruct_count == 0); + + for (auto *obj : objects) { + allocator.free(obj); + } + + REQUIRE(g_destruct_count == count); + } +} + +TEST_CASE("ClassAllocator with RAII types", "[libts][allocator]") +{ + ClassAllocator allocator("test_resource_holder"); + + SECTION("RAII cleanup on free") + { + bool destroyed = false; + + ResourceHolder *obj = allocator.alloc(123, &destroyed); + REQUIRE(obj != nullptr); + REQUIRE(obj->resource != nullptr); + REQUIRE(*obj->resource == 123); + REQUIRE(destroyed == false); + + allocator.free(obj); + REQUIRE(destroyed == true); + } + + SECTION("Multiple RAII objects") + { + constexpr int count = 3; + bool destroyed_flags[count] = {false, false, false}; + std::vector objects; + + for (int i = 0; i < count; ++i) { + objects.push_back(allocator.alloc(i * 100, &destroyed_flags[i])); + } + + for (int i = 0; i < count; ++i) { + REQUIRE(destroyed_flags[i] == false); + } + + for (auto *obj : objects) { + allocator.free(obj); + } + + for (int i = 0; i < count; ++i) { + REQUIRE(destroyed_flags[i] == true); + } + } +} + +TEST_CASE("ClassAllocator with complex types", "[libts][allocator]") +{ + ClassAllocator allocator("test_complex"); + + SECTION("Complex object with std::string") + { + ComplexObject *obj = allocator.alloc("test_object", 7); + REQUIRE(obj != nullptr); + REQUIRE(obj->name == "test_object"); + REQUIRE(obj->id == 7); + REQUIRE(obj->data[5] == 35.0); // 7 * 5 + + allocator.free(obj); + // If destructor isn't called, this would leak the std::string + } + + SECTION("Multiple complex objects") + { + std::vector objects; + std::string prefix = "this needs to be long to avoid short string optimizations, hopefully this is enough: obj_"; + + for (int i = 0; i < 5; ++i) { + objects.push_back(allocator.alloc(prefix + std::to_string(i), i)); + } + + for (int i = 0; i < 5; ++i) { + REQUIRE(objects[i]->name == prefix + std::to_string(i)); + REQUIRE(objects[i]->id == i); + } + + for (auto *obj : objects) { + allocator.free(obj); + } + } +} + +TEST_CASE("ClassAllocator cleanup tracking", "[libts][allocator]") +{ + ClassAllocator allocator("test_cleanup"); + + SECTION("Cleanup counter decremented on free") + { + int counter = 0; + + CleanupTracker *obj = allocator.alloc(&counter); + REQUIRE(obj != nullptr); + REQUIRE(counter == 1); + + allocator.free(obj); + REQUIRE(counter == 0); + } + + SECTION("Multiple cleanup objects") + { + int counter = 0; + std::vector objects; + + for (int i = 0; i < 10; ++i) { + objects.push_back(allocator.alloc(&counter)); + } + + REQUIRE(counter == 10); + + for (auto *obj : objects) { + allocator.free(obj); + } + + REQUIRE(counter == 0); + } +} + +TEST_CASE("ClassAllocator constructor forwarding", "[libts][allocator]") +{ + ClassAllocator allocator("test_forwarding"); + + SECTION("Perfect forwarding of constructor arguments") + { + std::string name = "forwarded"; + ComplexObject *obj = allocator.alloc(name, 99); + + REQUIRE(obj != nullptr); + REQUIRE(obj->name == "forwarded"); + REQUIRE(obj->id == 99); + + allocator.free(obj); + } + + SECTION("Move semantics") + { + ComplexObject *obj = allocator.alloc(std::string("moved"), 42); + + REQUIRE(obj != nullptr); + REQUIRE(obj->name == "moved"); + REQUIRE(obj->id == 42); + + allocator.free(obj); + } +} diff --git a/tools/benchmark/benchmark_ProxyAllocator.cc b/tools/benchmark/benchmark_ProxyAllocator.cc index 232b559a5fc..7822b4bb582 100644 --- a/tools/benchmark/benchmark_ProxyAllocator.cc +++ b/tools/benchmark/benchmark_ProxyAllocator.cc @@ -52,7 +52,7 @@ struct BItem { } // namespace // THREAD_ALLOC/FREE requires allocators be global variables and are named after one of the defined ProxyAllocator members -ClassAllocator ioAllocator("io"); +ClassAllocator ioAllocator("io"); #define OLD_THREAD_FREE(_p, _a, _t) \ do { \