Skip to content

Commit

Permalink
main
Browse files Browse the repository at this point in the history
  • Loading branch information
LizBing committed Dec 22, 2022
1 parent 5d9ebc5 commit 4bbdc2c
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 161 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.vscode
build
debug
debug
plan
demo
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
## 为什么要做这个?
单纯是对这门技术感兴趣,花自己空闲时间研究了八个月,做出来给众多C/C++同好开发使用。

## 为什么要用C做?
C是一门非常优秀的语言,它的语法简单,编译速度快,运行速度快,内存管理简单。
## 说好的C++支持我不做了,反正也没人用。这个0.0.0dev5版本我连测试都没做就挂上来了,没什么动力,最近还得了新冠太累了,往后吧。

## 基本操作接口(v0.0.0dev2, v0.0.0dev3的自己估计看看就懂了吧
## 基本操作接口(v0.0.0dev2, 更新的版本的看接口名估计就懂了吧,dev版本我都不再更新接口说明了

### 1. 垃圾回收器的初始化
void uboa_init(int nGCWorkers, size_t xmx, long timerInterval_min, bool enableRuleProactive, const char* logFilePath);
Expand Down
86 changes: 0 additions & 86 deletions demo/test.c

This file was deleted.

4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ std = -std=c11
out = build/lib/libuboa.a

macro = \
-DBUILD_DATE="\"12/19/2022, Monday\"" \
-DGC_VERSION="\"0.0.0.dev4\"" \
-DBUILD_DATE="\"12/12/2022, Tursday\"" \
-DGC_VERSION="\"0.0.0.dev5\"" \
-DCOPYRIGHT="\"Copyright\(c\) 2022, Lizbing. All rights reserved.\"" \
-DGC_PRODUCT_NAME="\"Uboa Garbage Collector\"" \
-DFEEDBACK_EMAIL="\"feedback@relight.team\""
Expand Down
10 changes: 6 additions & 4 deletions src/share/allocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ inline void* memAlloc(size_t s) {
return survAllocSmall(align(s, alignmentSmall), NULL);
}

void uboa_new(uboa_appThrdHandle hdl, uboa_reference r, size_t s, uboa_reference oopRef) {
uboa_newArray(hdl, r, s, 1, oopRef);
void uboa_new(uboa_appThrdHandle hdl, uboa_reference r, size_t s, Oop oop) {
uboa_newArray(hdl, r, s, 1, oop);
}

inline void Object_init(Object* this, Page* p) {
Expand All @@ -137,7 +137,9 @@ inline void Object_init(Object* this, Page* p) {
LargeObject_push(this);
}

void uboa_newArray(uboa_appThrdHandle hdl, uboa_reference r, size_t s, size_t count, uboa_reference oopRef) {
void uboa_newArray(uboa_appThrdHandle hdl, uboa_reference r, size_t s, size_t count, Oop oop) {
uboa_assert(!hdl->free, "memory allocation should be done in bound region.");

Object* ptr = NULL;
Page* src = NULL;

Expand All @@ -156,7 +158,7 @@ void uboa_newArray(uboa_appThrdHandle hdl, uboa_reference r, size_t s, size_t co
recordAllocation(size);

Object_init(ptr, src);
uboa_assign(&ptr->oopObj, oopRef);
ptr->oop = oop;
ptr->count = count;
ptr->size = size;
ptr->unit = s;
Expand Down
14 changes: 11 additions & 3 deletions src/share/appThrd.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ void forEachRoot(void(*func)(AppThrd*)) {
n = iter;
iter = n->next;

atomic_flag_test_and_set(&n->flag);
atomic_flag_test_and_set(&n->lock);

atomic_flag_clear(&sl);

func(n);
atomic_flag_clear(&n->flag);
atomic_flag_clear(&n->lock);
}
}

Expand Down Expand Up @@ -71,7 +71,7 @@ void uboa_destroyAppThrdHandle(uboa_appThrdHandle hdl) {

atomic_flag_clear(&sl);

while(atomic_flag_test_and_set(&hdl->flag));
while(atomic_flag_test_and_set(&hdl->lock));
}

uboa_reference uboa_pushReference(uboa_appThrdHandle hdl) {
Expand All @@ -82,4 +82,12 @@ uboa_reference uboa_pushReference(uboa_appThrdHandle hdl) {

void uboa_popReferences(uboa_appThrdHandle hdl, size_t n) {
hdl->size -= n;
}

void uboa_enterRiskRegion(uboa_appThrdHandle hdl) {
hdl->free = true;
}

void uboa_exitRiskRegion(uboa_appThrdHandle hdl) {
hdl->free = false;
}
5 changes: 3 additions & 2 deletions src/share/appThrd.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ typedef struct AppThrd AppThrd, *uboa_appThrdHandle;
struct AppThrd {
_Atomic(Page*) TLAB;

atomic_flag flag;
bool free;
atomic_flag lock;
AppThrd* prev, *next;

atomic_size_t size;
atomic_intptr_t stack[0];
uboa_pointer stack[0];
};

void forEachRoot(void(*func)(AppThrd*));
Expand Down
9 changes: 3 additions & 6 deletions src/share/mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,12 @@ void worker_markFollowings() {
Object* n = NULL;
while((n = Following_pop())) {
bool trigger = false;
if(n->oopObj) {
mark(&n->oopObj);
Oop oop = ((Object*)n->oopObj)->data;

if(n->oop) {
for(long i = 0; i < n->count; ++i) {
void* base = n->data + n->unit * i;

for(long j = 0; j < oop->size; ++j)
if(mark(base + oop->map[j]))
for(long j = 0; j < n->oop->size; ++j)
if(mark(base + n->oop->map[j]))
trigger = true;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/share/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
#define UBOA_GC_OBJECT_

#include "page.h"
#include "oop.h"

struct Object {
ListNode nodeFollowing, nodeLiveSet;
atomic_flag flag;

Page* page;

atomic_intptr_t oopObj;
Oop oop;
size_t size, unit, count;

byte data[0];
Expand Down
19 changes: 0 additions & 19 deletions src/share/oop.c

This file was deleted.

20 changes: 0 additions & 20 deletions src/share/oop.h

This file was deleted.

15 changes: 12 additions & 3 deletions src/share/operate.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
*
*/

#include "appThrd.h"
#include "barrier.h"

static const intptr_t null = 0;

uboa_reference uboa_null() {
uboa_reference uboa_nullref() {
static const uboa_pointer null = 0;
return &null;
}

Expand All @@ -23,6 +23,15 @@ bool uboa_isNull(uboa_reference r) {
return !*r;
}

void* uboa_castToObject(uboa_appThrdHandle hdl, uboa_reference r) {
uboa_assert(hdl->free, "called 'uboa_getObject' in bound region.");
return loadValueBarrier(r)->data;
}

uboa_pointer uboa_castToPointer(void* p) {
return p - sizeof(Object);
}

void uboa_loadReference(uboa_reference dst, uboa_reference src, off_t off) {
uboa_assign(dst, loadValueBarrier(src)->data + off);
}
Expand Down
28 changes: 18 additions & 10 deletions src/uboa.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* @file uboa.h
* @author Lizbing (lizbing@relight.team)
* @brief
* @version 0.0.0dev5
* @date 2022-12-20
*
Expand All @@ -15,13 +14,20 @@
#include <stdint.h>
#include <stdbool.h>
#include <stdatomic.h>
#include <stdio.h>

#ifndef UBOA_GC_SOURCE_
typedef void* uboa_appThrdHandle;
#endif

typedef long off_t;
typedef atomic_intptr_t* uboa_reference;
typedef atomic_intptr_t* uboa_reference, uboa_pointer;
#define uboa_weakReference(ptr) (&(ptr))

typedef struct {
size_t size;
off_t* map;
} OopDec, *Oop;

const char* uboa_copyright();
const char* uboa_name();
Expand All @@ -38,22 +44,24 @@ void uboa_popReferences(uboa_appThrdHandle, size_t);

void uboa_enterSafeRegion();
void uboa_exitSafeRegion();
#define uboa_safeRegion(...) \
uboa_enterSafeRegion(); \
__VA_ARGS__ \
uboa_exitSafeRegion();
void uboa_enterRiskRegion(uboa_appThrdHandle);
void uboa_exitRiskRegion(uboa_appThrdHandle);

void uboa_gc(const char* reason);

void uboa_new_Oop(uboa_appThrdHandle, uboa_reference, size_t, off_t*);
void uboa_new(uboa_appThrdHandle, uboa_reference, size_t, uboa_reference oopRef);
void uboa_newArray(uboa_appThrdHandle, uboa_reference, size_t, size_t count, uboa_reference oopRef);
void uboa_new(uboa_appThrdHandle, uboa_reference, size_t, Oop oop);
void uboa_newArray(uboa_appThrdHandle, uboa_reference, size_t, size_t count, Oop oop);

#define uboa_nullptr ((uboa_pointer)0)
uboa_reference uboa_nullref();

uboa_reference uboa_null();
void uboa_assign(uboa_reference dst, uboa_reference src);
bool uboa_isNull(uboa_reference);
bool uboa_equal(uboa_reference, uboa_reference);

void* uboa_castToObject(uboa_appThrdHandle, uboa_reference);
uboa_pointer uboa_castToPointer(void*);

int8_t uboa_loadInt8(uboa_reference, off_t);
int16_t uboa_loadInt16(uboa_reference, off_t);
int32_t uboa_loadInt32(uboa_reference, off_t);
Expand Down

0 comments on commit 4bbdc2c

Please sign in to comment.