Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/alice/alice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ int alice(Firebird::UtilSvc* uSvc)
#if defined(DEBUG_GDS_ALLOC)
if (!uSvc->isService())
{
gds_alloc_report(0 ALLOC_ARGS);
gds_alloc_report(0, __FILE__, __LINE__);
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/alice/exe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int EXE_action(const TEXT* database, const SINT64 switches)
bool error = false;
AliceGlobals* tdgbl = AliceGlobals::getSpecific();
{
Firebird::AutoMemoryPool newPool(MemoryPool::createPool(ALLOC_ARGS0));
Firebird::AutoMemoryPool newPool(MemoryPool::createPool());
AliceContextPoolHolder context(tdgbl, newPool);

for (USHORT i = 0; i < MAX_VAL_ERRORS; i++)
Expand Down Expand Up @@ -145,7 +145,7 @@ int EXE_two_phase(const TEXT* database, const SINT64 switches)
bool error = false;
AliceGlobals* tdgbl = AliceGlobals::getSpecific();
{
Firebird::AutoMemoryPool newPool(MemoryPool::createPool(ALLOC_ARGS0));
Firebird::AutoMemoryPool newPool(MemoryPool::createPool());
AliceContextPoolHolder context(tdgbl, newPool);

for (USHORT i = 0; i < MAX_VAL_ERRORS; i++)
Expand Down
6 changes: 3 additions & 3 deletions src/burp/burp.h
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ class GblPool
}

explicit GblPool(bool ownPool)
: gbl_pool(ownPool ? MemoryPool::createPool(ALLOC_ARGS1 getDefaultMemoryPool()) : getDefaultMemoryPool())
: gbl_pool(ownPool ? MemoryPool::createPool(getDefaultMemoryPool()) : getDefaultMemoryPool())
{ }

~GblPool()
Expand Down Expand Up @@ -1386,13 +1386,13 @@ class OutputVersion : public Firebird::IVersionCallbackImpl<OutputVersion, Fireb
static inline UCHAR* BURP_alloc(ULONG size)
{
BurpGlobals* tdgbl = BurpGlobals::getSpecific();
return (UCHAR*)(tdgbl->getPool().allocate(size ALLOC_ARGS));
return (UCHAR*)(tdgbl->getPool().allocate(size));
}

static inline UCHAR* BURP_alloc_zero(ULONG size)
{
BurpGlobals* tdgbl = BurpGlobals::getSpecific();
return (UCHAR*)(tdgbl->getPool().calloc(size ALLOC_ARGS));
return (UCHAR*)(tdgbl->getPool().calloc(size));
}

static inline void BURP_free(void* block) noexcept
Expand Down
17 changes: 17 additions & 0 deletions src/common/StdHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <utility>
#include <variant>
#include <cstddef>
#include <source_location>
#include <stdexcept>
#include "boost/type_traits/copy_cv.hpp"

Expand Down Expand Up @@ -157,6 +158,22 @@ constexpr auto getVariantIndexAndSpan(V& message)
}


struct CustomSourceLocation
{
static constexpr CustomSourceLocation current(
const std::source_location& location = std::source_location::current())
{
return {
.fileName = location.file_name(),
.line = static_cast<int>(location.line())
};
}

const char* fileName;
int line;
};


} // namespace Firebird

#endif // FB_COMMON_STD_HELPER_H
33 changes: 15 additions & 18 deletions src/common/classes/alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,7 @@ class MemHeader

public:
#ifdef DEBUG_GDS_ALLOC
INT32 lineNumber = -1;
const char *fileName = nullptr;
Firebird::CustomSourceLocation location;
#elif (SIZEOF_VOID_P == 4)
FB_UINT64 dummyAlign;
#endif
Expand Down Expand Up @@ -412,16 +411,16 @@ class MemHeader
{
bool filter = filter_path != NULL;

if (isActive() && filter && fileName)
filter = strncmp(filter_path, fileName, filter_len) != 0;
if (isActive() && filter && location.fileName)
filter = strncmp(filter_path, location.fileName, filter_len) != 0;

if (!filter)
{
if (isActive() || redirected())
{
fprintf(file, "%s %p: size=%" SIZEFORMAT " allocated at %s:%d",
isExtent() ? "EXTN" : redirected() ? "RDIR" : "USED",
this, getSize(), fileName, lineNumber);
this, getSize(), location.fileName, location.line);
}
else
fprintf(file, "FREE %p: size=%" SIZEFORMAT, this, getSize());
Expand Down Expand Up @@ -2126,16 +2125,15 @@ void MemPool::newExtent(size_t& size, Extent** linkedList)
size = extent->spaceRemaining;
}

MemoryPool* MemoryPool::createPool(ALLOC_PARAMS1 MemoryPool* parentPool, MemoryStats& stats)
MemoryPool* MemoryPool::createPool(MemoryPool* parentPool, MemoryStats& stats ALLOC_PARAMS_DEF)
{
if (!parentPool)
parentPool = getDefaultMemoryPool();

MemPool* p = new(*parentPool ALLOC_PASS_ARGS) MemPool(*(parentPool->pool), stats, &defaultExtentsCache);
#ifdef MEM_DEBUG
#ifdef DEBUG_LOST_POOLS
p->fileName = file;
p->lineNum = line;
p->location = location;

static std::atomic<int> seqGen = 0;
p->seq = ++seqGen;
Expand Down Expand Up @@ -2231,7 +2229,7 @@ MemBlock* MemPool::allocateInternal2(size_t from, size_t& length, bool flagRedir
return hunk->block;
}

MemBlock* MemPool::allocateRange(size_t from, size_t& size ALLOC_PARAMS)
MemBlock* MemPool::allocateRange(size_t from, size_t& size ALLOC_PARAMS_DEF)
{
size_t length = from ? size : ROUNDUP(size + VALGRIND_REDZONE, roundingSize) + GUARD_BYTES;
MemBlock* memory = allocateInternal(from, length, true);
Expand All @@ -2242,8 +2240,7 @@ MemBlock* MemPool::allocateRange(size_t from, size_t& size ALLOC_PARAMS)
#endif

#ifdef DEBUG_GDS_ALLOC
memory->fileName = file;
memory->lineNumber = line;
memory->location = location;
#endif

#ifdef MEM_DEBUG
Expand All @@ -2260,7 +2257,7 @@ MemBlock* MemPool::allocateRange(size_t from, size_t& size ALLOC_PARAMS)
}


void* MemPool::allocate(size_t size ALLOC_PARAMS)
void* MemPool::allocate(size_t size ALLOC_PARAMS_DEF)
{
#ifdef VALIDATE_POOL
MutexLockGuard guard(mutex, "MemPool::allocate");
Expand Down Expand Up @@ -2335,7 +2332,7 @@ void MemPool::releaseMemory(void* object, bool flagExtent) noexcept
block->valgrindInternal();

#ifdef DEBUG_GDS_ALLOC
block->fileName = NULL;
block->location.fileName = nullptr;
#endif

// Finally delete it
Expand Down Expand Up @@ -2506,7 +2503,7 @@ void* MemPool::getExtent(size_t from, size_t& to) // pass desired minimum size,
#ifdef VALIDATE_POOL
MutexLockGuard guard(mutex, "MemPool::getExtent");
#endif
MemBlock* extent = allocateRange(from, to ALLOC_ARGS);
MemBlock* extent = allocateRange(from, to);
extent->setExtent();
return &extent->body;
}
Expand Down Expand Up @@ -2622,7 +2619,7 @@ void MemPool::globalFree(void* block) noexcept
deallocate(block);
}

void* MemoryPool::calloc(size_t size ALLOC_PARAMS)
void* MemoryPool::calloc(size_t size ALLOC_PARAMS_DEF)
{
void* block = allocate(size ALLOC_PASS_ARGS);
memset(block, 0, size);
Expand Down Expand Up @@ -2768,7 +2765,7 @@ MemoryPool& AutoStorage::getAutoMemoryPool()
return *p;
}

void* MemoryPool::allocate(size_t size ALLOC_PARAMS)
void* MemoryPool::allocate(size_t size ALLOC_PARAMS_DEF)
{
return pool->allocate(size ALLOC_PASS_ARGS);
}
Expand Down Expand Up @@ -3037,12 +3034,12 @@ void AutoStorage::ProbeStack() const noexcept

void* operator new(size_t s)
{
return getExternalMemoryPool()->allocate(s ALLOC_ARGS);
return getExternalMemoryPool()->allocate(s);
}

void* operator new[](size_t s)
{
return getExternalMemoryPool()->allocate(s ALLOC_ARGS);
return getExternalMemoryPool()->allocate(s);
}

void operator delete(void* mem) noexcept
Expand Down
39 changes: 15 additions & 24 deletions src/common/classes/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,13 @@

#include <memory.h>
#include <memory>

#ifdef DEBUG_GDS_ALLOC
#define FB_NEW new(*getDefaultMemoryPool(), __FILE__, __LINE__)
#define FB_NEW_POOL(pool) new(pool, __FILE__, __LINE__)
#define FB_NEW_RPT(pool, count) new(pool, count, __FILE__, __LINE__)
#else // DEBUG_GDS_ALLOC
#include "../common/StdHelper.h"
#endif

#define FB_NEW new(*getDefaultMemoryPool())
#define FB_NEW_POOL(pool) new(pool)
#define FB_NEW_RPT(pool, count) new(pool, count)
#endif // DEBUG_GDS_ALLOC

namespace Firebird {

Expand Down Expand Up @@ -185,29 +182,23 @@ friend class ExternalMemoryHandler;

public:
#ifdef DEBUG_GDS_ALLOC
#define ALLOC_ARGS , __FILE__, __LINE__
#define ALLOC_ARGS1 __FILE__, __LINE__,
#define ALLOC_ARGS0 __FILE__, __LINE__
#define ALLOC_PARAMS , const char* file, int line
#define ALLOC_PARAMS1 const char* file, int line,
#define ALLOC_PARAMS0 const char* file, int line
#define ALLOC_PASS_ARGS , file, line
#define ALLOC_PASS_ARGS1 file, line,
#define ALLOC_PASS_ARGS0 file, line
#define ALLOC_PARAMS , const Firebird::CustomSourceLocation location = Firebird::CustomSourceLocation::current()
#define ALLOC_PARAMS_NO_COMMA const Firebird::CustomSourceLocation location = Firebird::CustomSourceLocation::current()
#define ALLOC_PARAMS_DEF , const Firebird::CustomSourceLocation location
#define ALLOC_PARAMS_NO_COMMA_DEF const Firebird::CustomSourceLocation location
#define ALLOC_PASS_ARGS , location
#define ALLOC_PASS_ARGS_NO_COMMA location
#else
#define ALLOC_ARGS
#define ALLOC_PARAMS
#define ALLOC_PARAMS_NO_COMMA
#define ALLOC_PARAMS_DEF
#define ALLOC_PARAMS_NO_COMMA_DEF
#define ALLOC_PASS_ARGS
#define ALLOC_ARGS1
#define ALLOC_PARAMS1
#define ALLOC_PASS_ARGS1
#define ALLOC_ARGS0
#define ALLOC_PARAMS0
#define ALLOC_PASS_ARGS0
#define ALLOC_PASS_ARGS_NO_COMMA
#endif // DEBUG_GDS_ALLOC

// Create memory pool instance
static MemoryPool* createPool(ALLOC_PARAMS1 MemoryPool* parent = NULL, MemoryStats& stats = *default_stats_group);
static MemoryPool* createPool(MemoryPool* parent = NULL, MemoryStats& stats = *default_stats_group ALLOC_PARAMS);
// Delete memory pool instance
static void deletePool(MemoryPool* pool);

Expand Down Expand Up @@ -524,7 +515,7 @@ namespace Firebird
public:
constexpr pointer allocate(size_type n, const void* hint = nullptr)
{
return static_cast<T*>(pool.allocate(n * sizeof(T) ALLOC_ARGS));
return static_cast<T*>(pool.allocate(n * sizeof(T)));
}

constexpr void deallocate(pointer p, size_type n)
Expand Down
2 changes: 1 addition & 1 deletion src/common/classes/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ class Array : public Storage
fb_assert(newcapacity < FB_MAX_SIZEOF / sizeof(T));

T* newdata = static_cast<T*>
(this->getPool().allocate(sizeof(T) * newcapacity ALLOC_ARGS));
(this->getPool().allocate(sizeof(T) * newcapacity));
if (preserve)
memcpy(static_cast<void*>(newdata), data, sizeof(T) * count);
freeData();
Expand Down
2 changes: 1 addition & 1 deletion src/common/classes/misc/class_perf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ static void testAllocatorMemoryPool()
{
printf("Test run for Firebird::MemoryPool...\n");
start();
Firebird::MemoryPool* pool = Firebird::MemoryPool::createPool(ALLOC_ARGS0);
Firebird::MemoryPool* pool = Firebird::MemoryPool::createPool();
MallocAllocator allocator;
BePlusTree<AllocItem, AllocItem, MallocAllocator, DefaultKeyValue<AllocItem>, AllocItem> items(&allocator),
bigItems(&allocator);
Expand Down
8 changes: 4 additions & 4 deletions src/common/classes/misc/class_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ void testAllocator()
printf("Allocate %d large items: ", LARGE_ITEMS);
int i;
for (i = 0; i<LARGE_ITEMS; i++) {
la.add(pool->allocate(LARGE_ITEM_SIZE ALLOC_ARGS));
la.add(pool->allocate(LARGE_ITEM_SIZE));
VERIFY_POOL(pool);
}
VERIFY_POOL(pool);
Expand All @@ -518,7 +518,7 @@ void testAllocator()
for (i = 0; i < ALLOC_ITEMS; i++) {
n = n * 47163 - 57412;
// n = n * 45578 - 17651;
AllocItem temp = {n, pool->allocate((n % MAX_ITEM_SIZE + MAX_ITEM_SIZE) / 2 + 1 ALLOC_ARGS)};
AllocItem temp = {n, pool->allocate((n % MAX_ITEM_SIZE + MAX_ITEM_SIZE) / 2 + 1)};
items.add(temp);
}
printf(" DONE\n");
Expand All @@ -541,15 +541,15 @@ void testAllocator()
for (i = 0; i < BIG_ITEMS; i++) {
n = n * 47163 - 57412;
// n = n * 45578 - 17651;
AllocItem temp = {n, pool->allocate((n % BIG_SIZE + BIG_SIZE) / 2 + 1 ALLOC_ARGS)};
AllocItem temp = {n, pool->allocate((n % BIG_SIZE + BIG_SIZE) / 2 + 1)};
bigItems.add(temp);
}
printf(" DONE\n");
VERIFY_POOL(pool);
VERIFY_POOL(parent);

printf("Allocate max recommended medium buffer (%d bytes): ", MemoryPool::MAX_MEDIUM_BLOCK_SIZE);
void* maxMedium = pool->allocate(MemoryPool::MAX_MEDIUM_BLOCK_SIZE ALLOC_ARGS);
void* maxMedium = pool->allocate(MemoryPool::MAX_MEDIUM_BLOCK_SIZE);
printf(" DONE\n");
VERIFY_POOL(pool);
VERIFY_POOL(parent);
Expand Down
2 changes: 1 addition & 1 deletion src/common/classes/zip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void* ZLib::allocFunc(void*, uInt items, uInt size)
{
try
{
return MemoryPool::globalAlloc(items * size ALLOC_ARGS);
return MemoryPool::globalAlloc(items * size);
}
catch (const Exception&)
{
Expand Down
8 changes: 4 additions & 4 deletions src/common/tests/StringTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ BOOST_AUTO_TEST_CASE(DefaultPoolMoveTest)

BOOST_AUTO_TEST_CASE(NewPoolMoveTest)
{
AutoMemoryPool pool(MemoryPool::createPool(ALLOC_ARGS0));
AutoMemoryPool pool(MemoryPool::createPool());
string sourceString(*pool, BigStringValue.data(), length(BigStringValue));

// Move c'tor
Expand All @@ -664,7 +664,7 @@ BOOST_AUTO_TEST_SUITE(CannotMoveTests)
// Do not move
BOOST_AUTO_TEST_CASE(DifferentVsDefaultPoolMove)
{
AutoMemoryPool pool(MemoryPool::createPool(ALLOC_ARGS0));
AutoMemoryPool pool(MemoryPool::createPool());
string sourceString(*pool, BigStringValue.data(), length(BigStringValue));

// Move c'tor
Expand All @@ -685,8 +685,8 @@ BOOST_AUTO_TEST_CASE(DifferentVsDefaultPoolMove)
// Do not move
BOOST_AUTO_TEST_CASE(DifferentPoolsMove)
{
AutoMemoryPool pool1(MemoryPool::createPool(ALLOC_ARGS0));
AutoMemoryPool pool2(MemoryPool::createPool(ALLOC_ARGS0));
AutoMemoryPool pool1(MemoryPool::createPool());
AutoMemoryPool pool2(MemoryPool::createPool());
string sourceString(*pool1, BigStringValue.data(), length(BigStringValue));

// Move c'tor
Expand Down
Loading
Loading