More tab stuffs
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
global gc_init, gc_alloc
|
global gc_init, gc_alloc
|
||||||
|
|
||||||
section .bss
|
section .bss
|
||||||
alloc_list: resq 1
|
alloc_list: resq 1
|
||||||
stack_start: resq 1
|
stack_start: resq 1
|
||||||
|
|
||||||
section .data
|
section .data
|
||||||
gc_threshold_b: dq 4096 ; default of 4096 bytes, this will scale when gc_collect is ran
|
gc_threshold_b: dq 4096 ; default of 4096 bytes, this will scale when gc_collect is ran
|
||||||
gc_threshold_c: dq 1024 ; default of 1024 allocations
|
gc_threshold_c: dq 1024 ; default of 1024 allocations
|
||||||
total_alloc_b: dq 0 ; counts the allocated bytes
|
total_alloc_b: dq 0 ; counts the allocated bytes
|
||||||
total_alloc_c: dq 0 ; count the amount of allocations
|
total_alloc_c: dq 0 ; count the amount of allocations
|
||||||
|
|
||||||
section .text
|
section .text
|
||||||
gc_init:
|
gc_init:
|
||||||
@@ -32,14 +32,14 @@ gc_alloc:
|
|||||||
add [total_alloc_b], rdi ; update total allocated bytes
|
add [total_alloc_b], rdi ; update total allocated bytes
|
||||||
inc qword [total_alloc_c] ; update total allocation count
|
inc qword [total_alloc_c] ; update total allocation count
|
||||||
push rdi
|
push rdi
|
||||||
call sys_mmap ; allocate size + metadata
|
call sys_mmap ; allocate size + metadata
|
||||||
pop rdi
|
pop rdi
|
||||||
mov byte [rax], 0 ; set mark to 0
|
mov byte [rax], 0 ; set mark to 0
|
||||||
mov qword [rax + 1], rdi ; set total size of object (including metadata)
|
mov qword [rax + 1], rdi ; set total size of object (including metadata)
|
||||||
mov rsi, [alloc_list] ; load first item in allocation list
|
mov rsi, [alloc_list] ; load first item in allocation list
|
||||||
mov qword [rax + 9], rsi ; make current head of allocation list the next item in this object
|
mov qword [rax + 9], rsi ; make current head of allocation list the next item in this object
|
||||||
mov [alloc_list], rax ; update head of allocation list so it points to this object
|
mov [alloc_list], rax ; update head of allocation list so it points to this object
|
||||||
add rax, 17 ; skip metadata for return value
|
add rax, 17 ; skip metadata for return value
|
||||||
ret
|
ret
|
||||||
|
|
||||||
gc_collect:
|
gc_collect:
|
||||||
@@ -53,7 +53,7 @@ gc_collect:
|
|||||||
mov qword [gc_threshold_b], rax ; update threshold to new value
|
mov qword [gc_threshold_b], rax ; update threshold to new value
|
||||||
ret
|
ret
|
||||||
|
|
||||||
gc_mark_stack:
|
gc_mark_stack:
|
||||||
mov r8, rsp ; load current stack pointer
|
mov r8, rsp ; load current stack pointer
|
||||||
mov r9, [stack_start] ; load start of stack
|
mov r9, [stack_start] ; load start of stack
|
||||||
.loop:
|
.loop:
|
||||||
@@ -116,7 +116,7 @@ gc_sweep:
|
|||||||
mov [rsi + 9], rdx ; unlink the current node by setting the previous node's next to the next node's address
|
mov [rsi + 9], rdx ; unlink the current node by setting the previous node's next to the next node's address
|
||||||
jmp .free_memory
|
jmp .free_memory
|
||||||
.remove_head:
|
.remove_head:
|
||||||
mov [alloc_list], rdx ; update head node to be the next node
|
mov [alloc_list], rdx ; update head node to be the next node
|
||||||
.free_memory:
|
.free_memory:
|
||||||
push rsi ; save previous node since it will also be the previous node for the next item
|
push rsi ; save previous node since it will also be the previous node for the next item
|
||||||
push rdx ; save next node
|
push rdx ; save next node
|
||||||
|
|||||||
Reference in New Issue
Block a user