-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhaseEnum.h
106 lines (96 loc) · 2.48 KB
/
PhaseEnum.h
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
#ifndef CPPGCPTR_PHASEENUM_H
#define CPPGCPTR_PHASEENUM_H
#include <string>
#include <stdexcept>
enum class MarkState {
//INVALID,
REMAPPED,
M0,
M1,
DE_ALLOCATED,
COPIED
};
enum class MarkStateBit {
NOT_ALLOCATED,
REMAPPED,
M0,
M1
};
enum class eGCPhase {
NONE,
CONCURRENT_MARK,
REMARK,
SWEEP
};
class MarkStateUtil {
public:
static MarkState switchState(MarkState state) {
switch (state) {
case MarkState::M0:
return MarkState::M1;
case MarkState::M1:
return MarkState::M0;
case MarkState::REMAPPED:
return MarkState::M0;
default:
throw std::exception();
}
}
static std::string toString(MarkState state) {
switch (state) {
case MarkState::REMAPPED:
return "Remapped";
case MarkState::M0:
return "M0";
case MarkState::M1:
return "M1";
case MarkState::DE_ALLOCATED:
return "Deallocated";
default:
return "Invalid";
}
}
static MarkStateBit toMarkState(unsigned char state) {
switch (state) {
case 0:
return MarkStateBit::NOT_ALLOCATED;
case 1:
return MarkStateBit::REMAPPED;
case 2:
return MarkStateBit::M0;
case 3:
return MarkStateBit::M1;
default:
throw std::invalid_argument("Invalid argument converting from char to MarkStateBit");
}
}
static unsigned char toChar(MarkStateBit state) {
switch (state) {
case MarkStateBit::NOT_ALLOCATED:
return 0;
case MarkStateBit::REMAPPED:
return 1;
case MarkStateBit::M0:
return 2;
case MarkStateBit::M1:
return 3;
default:
return 0;
}
}
static const char* toString(MarkStateBit state) {
switch (state) {
case MarkStateBit::NOT_ALLOCATED:
return "NOT_ALLOCATED";
case MarkStateBit::REMAPPED:
return "REMAPPED";
case MarkStateBit::M0:
return "M0";
case MarkStateBit::M1:
return "M1";
default:
return "???";
}
}
};
#endif //CPPGCPTR_PHASEENUM_H