-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmemory.cpp
More file actions
146 lines (132 loc) · 5.18 KB
/
Copy pathmemory.cpp
File metadata and controls
146 lines (132 loc) · 5.18 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* memory.cpp
*
* Author: Hao Xu
*/
#include "stdlib.h"
#include "memory.h"
#include "utils.h"
#include "stack.h"
size_t total_memory_usage;
void printMemoryUsage(bool verbose) {
if(verbose) {
printf("===========\n");
printf("Sub region size total %s\n", formatSize(region_data_size(subRegion)));
printf("InstStack region size total %s\n", formatSize(region_data_size(instStackRegion)));
printf("TermMatrix region size total %s\n", formatSize(region_data_size(termMatrixRegion)));
printf("TermMatrix hashtable region size total %s\n", formatSize(region_data_size(termMatrixHashtableRegion)));
printf("TermCache region size total %s\n", formatSize(region_data_size(termCacheRegion)));
printf("Clause region size total %s\n", formatSize(region_data_size(clauseRegion)));
printf("Clause component region size total %s\n", formatSize(region_data_size(clauseComponentRegion)));
printf("Trie node region size total %s\n", formatSize(region_data_size(modelTrieRegion)));
printf("Trie hashtable region size total %s\n", formatSize(region_data_size(globalTrieHashtableRegion)));
printf("CoroutineState region size total %s\n", formatSize(region_data_size(coroutineStateRegion)));
printf("First Gen Stack region size total %s\n", formatSize(region_data_size(firstGenStackRegion)));
printf("Second Gen Stack region size total %s\n", formatSize(region_data_size(secondGenStackRegion)));
printf("Curr Gen Stack region size total %s\n", formatSize(region_data_size(stackRegion)));
printf("===========\n");
}
printf("Total memory pool size %s\n", formatSize(regionPagePool.size));
printf("Total memory pool in use %s\n", formatSize(regionPagePool.inUse));
printf("Total memory allocation in use %s\n", formatSize(TOTAL_MEMORY_USAGE));
}
ActivationRecordCommon *copyActivationRecord(int level, ActivationRecordCommon *c, Region *gen1, Region *gen2, Region *newGen2) {
#ifdef DEBUG_RESTART
printf("%d: start copying %p\n", level, c);
fflush(stdout);
#endif
if(c==NULL) {
#ifdef DEBUG_RESTART
printf("%d: done copying %p\n", level, c);
fflush(stdout);
#endif
return NULL;
}
if(REGIONDESCOF(c)->r == gen1) { // do not copy if already in new region
return c;
}
if(DELETED(c)) {
// if an activation record is deleted then it must have been copied earlier,
// now the pointer points to the new address
#ifdef DEBUG_RESTART
printf("copy %p, del = %d, it has already been copied to %p\n", c, REGIONDESCOF(c)->del, *reinterpret_cast<ActivationRecordCommon **>(c));
assert((*reinterpret_cast<ActivationRecordCommon **>(c))->nestingLevel == 1 || (*reinterpret_cast<ActivationRecordCommon **>(c))->nestingLevel == 2);
printf("%d: done copying %p\n", level, c);
fflush(stdout);
#endif
return *reinterpret_cast<ActivationRecordCommon **>(c);
}
ActivationRecordCommon **ar = c->arBottoms;
for(int i = 0; i < LEVEL_OF_NESTING; i++) {
ar[i] = copyActivationRecord(level +1, ar[i], gen1, gen2, newGen2);
}
ActivationRecordCommon *newPtr = (REGIONDESCOF(c)->r == gen2) ?
(ActivationRecordCommon *) region_alloc(gen1, SIZE(c)) :
(ActivationRecordCommon *) region_alloc(newGen2, SIZE(c));
// now copy it self because there is no cyclic stack, we don't need to test DELETED(c) again here
memcpy(newPtr, c, SIZE(c));
SET_DELETE(c);
// record the new address
*reinterpret_cast<ActivationRecordCommon **>(c) = newPtr;
#ifdef DEBUG_RESTART
printf("copy %p to %p\n", c, newPtr);
printf("%d: done copying %p\n", level, c);
fflush(stdout);
#endif
return newPtr;
}
void gc(ActivationRecordCommon **arbs) {
{
// clause component
Region *newClauseComponentRegion = make_region();
FIRST_OBJ_REGION(clauseRegion, x, o);
while(o != NULL) {
if(!DELETED(o)) {
Clause *c = (Clause *) o;
#ifdef DEBUG_RESTART
char buf[STRING_BUF_SIZE];
c->toString(buf, symtable);
printf("copy clause %s\n", buf);
#endif
Term **literals = c->literals;
bool *signs = c->signs;
c->literals = (Term **) region_alloc(newClauseComponentRegion, sizeof(Term *)*c->numberOfLiterals);
c->signs = (bool *) region_alloc(newClauseComponentRegion, sizeof(bool)*c->numberOfLiterals);
memcpy(c->literals, literals, sizeof(Term *)*c->numberOfLiterals);
memcpy(c->signs, signs, sizeof(bool) *c->numberOfLiterals);
}
NEXT_OBJ_REGION(x, o);
}
region_free(clauseComponentRegion);
clauseComponentRegion = newClauseComponentRegion;
}{
// stack
Region *newStackRegion = make_region();
Region *newGen2 = make_region();
for(int i = 0; i < LEVEL_OF_NESTING; i++) {
arbs[i] = copyActivationRecord(0, arbs[i], firstGenStackRegion, secondGenStackRegion, newGen2);
}
FIRST_OBJ_REGION(coroutineStateRegion, x, o);
while(o != NULL) {
if(!DELETED(o)) {
CoroutineState *c = (CoroutineState *) o;
if(c->threadId!=0) { // it is a data dependency record if threadId = 0
#ifdef DEBUG_RESTART
printf("copy activation record from coroutine state");
printByType(c);
printf("\n");
#endif
ActivationRecordCommon **ar = c->arBottoms;
for(int i = 0; i < LEVEL_OF_NESTING; i++) {
ar[i] = copyActivationRecord(0, ar[i], firstGenStackRegion, secondGenStackRegion, newGen2);
}
}
}
NEXT_OBJ_REGION(x, o);
}
region_free(stackRegion);
region_free(secondGenStackRegion);
secondGenStackRegion = newGen2;
stackRegion = newStackRegion;
}
}