forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeCodeData.cpp
More file actions
106 lines (95 loc) · 2.92 KB
/
NativeCodeData.cpp
File metadata and controls
106 lines (95 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "Backend.h"
NativeCodeData::NativeCodeData(DataChunk * chunkList) : chunkList(chunkList)
{
#ifdef PERF_COUNTERS
this->size = 0;
#endif
}
NativeCodeData::~NativeCodeData()
{
NativeCodeData::DeleteChunkList(this->chunkList);
PERF_COUNTER_SUB(Code, DynamicNativeCodeDataSize, this->size);
PERF_COUNTER_SUB(Code, TotalNativeCodeDataSize, this->size);
}
void
NativeCodeData::DeleteChunkList(DataChunk * chunkList)
{
DataChunk * next = chunkList;
while (next != nullptr)
{
DataChunk * current = next;
next = next->next;
delete current;
}
}
NativeCodeData::Allocator::Allocator() : chunkList(nullptr)
{
#if DBG
this->finalized = false;
#endif
#ifdef PERF_COUNTERS
this->size = 0;
#endif
}
NativeCodeData::Allocator::~Allocator()
{
Assert(!finalized || this->chunkList == nullptr);
NativeCodeData::DeleteChunkList(this->chunkList);
PERF_COUNTER_SUB(Code, DynamicNativeCodeDataSize, this->size);
PERF_COUNTER_SUB(Code, TotalNativeCodeDataSize, this->size);
}
char *
NativeCodeData::Allocator::Alloc(size_t requestSize)
{
char * data = nullptr;
Assert(!finalized);
DataChunk * newChunk = HeapNewStructPlus(requestSize, DataChunk);
newChunk->next = this->chunkList;
this->chunkList = newChunk;
data = newChunk->data;
#ifdef PERF_COUNTERS
this->size += requestSize;
PERF_COUNTER_ADD(Code, DynamicNativeCodeDataSize, requestSize);
#endif
PERF_COUNTER_ADD(Code, TotalNativeCodeDataSize, requestSize);
return data;
}
char *
NativeCodeData::Allocator::AllocZero(size_t requestSize)
{
char * data = Alloc(requestSize);
memset(data, 0, requestSize);
return data;
}
NativeCodeData *
NativeCodeData::Allocator::Finalize()
{
NativeCodeData * data = nullptr;
if (this->chunkList != nullptr)
{
data = HeapNew(NativeCodeData, this->chunkList);
this->chunkList = nullptr;
#ifdef PERF_COUNTERS
data->size = this->size;
this->size = 0;
#endif
}
#if DBG
this->finalized = true;
#endif
return data;
}
//////////////////////////////////////////////////////////////////////////
//NativeCodeData::Allocator::Free
//This function should not be called at all because the life time is active during the run time
//This function is added to enable Dictionary(has calls to Free() Method - which will never be called as it will be
//allocated as a NativeAllocator to be allocated with NativeAllocator)
//////////////////////////////////////////////////////////////////////////
void
NativeCodeData::Allocator::Free(void * buffer, size_t byteSize)
{
}