-
Notifications
You must be signed in to change notification settings - Fork 0
/
GCPtrBase.h
76 lines (58 loc) · 1.76 KB
/
GCPtrBase.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
#ifndef CPPGCPTR_GCPTRBASE_H
#define CPPGCPTR_GCPTRBASE_H
#include <memory>
#include <atomic>
#include "ObjectInfo.h"
#include "GCPhase.h"
#include "GCParameter.h"
constexpr int GCPTR_IDENTIFIER_HEAD = 0x1f1e33fc;
constexpr int GCPTR_IDENTIFIER_TAIL = 0x03e0e1cc;
class GCPtrBase {
private:
const int identifier_head = GCPTR_IDENTIFIER_HEAD;
protected:
std::atomic<MarkState> inlineMarkState;
private:
size_t rootset_offset = 0;
public:
GCPtrBase() {
if (GCPhase::duringGC())
inlineMarkState = GCPhase::getCurrentMarkState();
else
inlineMarkState = MarkState::REMAPPED;
}
GCPtrBase(const GCPtrBase& other) {
setInlineMarkState(other);
}
virtual ~GCPtrBase() {
inlineMarkState = MarkState::DE_ALLOCATED;
}
virtual void* getVoidPtr() = 0;
virtual ObjectInfo getObjectInfo() = 0;
MarkState getInlineMarkState() const {
return inlineMarkState;
}
void setInlineMarkState(MarkState markstate) {
this->inlineMarkState = markstate;
}
void setInlineMarkState(const GCPtrBase& other) {
if (GCPhase::duringMarking()) {
if constexpr (GCParameter::useCopiedMarkstate)
inlineMarkState = MarkState::COPIED;
else
inlineMarkState = GCPhase::getCurrentMarkState();
} else {
inlineMarkState.store(other.getInlineMarkState());
}
}
bool casInlineMarkState(MarkState expected, MarkState target) {
return inlineMarkState.compare_exchange_weak(expected, target);
}
void setRootsetOffset(size_t p) {
this->rootset_offset = p;
}
size_t getRootsetOffset() const {
return this->rootset_offset;
}
};
#endif //CPPGCPTR_GCPTRBASE_H