1 /*========================== begin_copyright_notice ============================
2 
3 Copyright (C) 2017-2021 Intel Corporation
4 
5 SPDX-License-Identifier: MIT
6 
7 ============================= end_copyright_notice ===========================*/
8 
9 #include "Arena.h"
10 
11 #ifdef COLLECT_ALLOCATION_STATS
12 int numAllocations = 0;
13 int numMallocCalls = 0;
14 int totalAllocSize = 0;
15 int totalMallocSize = 0;
16 int numMemManagers = 0;
17 int maxArenaLength = 0;
18 int currentMallocSize = 0;
19 #endif
20 using namespace vISA;
21 
22 void*
AllocSpace(size_t size,size_t al)23 ArenaHeader::AllocSpace(size_t size, size_t al)
24 {
25     assert(DefaultAlign(size_t(_nextByte)) == size_t(_nextByte));
26 
27     void* allocSpace = (void*) AlignAddr((size_t) _nextByte, al);
28 
29     if (size)
30     {
31         size = DefaultAlign(size);  // round up size so that next address is at least max aligned
32 
33         if (_nextByte + size <= _lastByte) {
34             _nextByte += size;
35         }
36         else {
37             allocSpace = 0;
38         }
39     }
40     else
41     {
42         allocSpace = 0;
43     }
44 
45     return allocSpace;
46 }
47 
48 
49 void
FreeArenas()50 ArenaManager::FreeArenas()
51 {
52     while (_arenas)
53     {
54 #ifdef COLLECT_ALLOCATION_STATS
55         currentMallocSize -= _arenas->size;
56 #endif
57         unsigned char* killed = (unsigned char*) _arenas;
58         _arenas = _arenas->_nextArena;
59         delete [] killed;
60     }
61 
62     _arenas = 0;
63 }
64