Commit dd968699 authored by John van Groningen's avatar John van Groningen
Browse files

in mark using pointer reversal of the garbage collector, change marking of arrays with pointers,

the arrays are not reordered anymore

also change the mark bits that are used when marking the first argument of the arguments part of a node:
set the least significant 2 bits to 3 instead of 1

to mark such an array:
- temporarily overwrite the _ARRAY_ descriptor with the address of the pointer (of a previously marked node) to this node
- elements are marked in reverse order, so starting with the last pointer element
- temporarily overwrite the last pointer with a pointer to the beginning of the array
- mark the first pointer of the array, or the first pointer of the last record element if the record also contains non pointers,
  by setting the least significant 2 bits to 1
- continue marking by marking the elements, or the last record element
- after marking these elements, the beginning of the array can be recognized because we have a pointer to the array (in the element)
  and therefore the address of the first element
- if it was not the first element, we have marked a record element that also contains non pointers, we can load the record descriptor
  of the elements using the pointer to the array and compute the first and last pointer addresses of the previous record element,
  then temporarily store the address of the array in the last pointer and mark the least significant 2 bits of the first pointer
  with 1 and continue with marking this record element
- otherwise, the array has been marked, restore the _ARRAY_descriptor and
  continue marking using the address of the pointer that was stored there at the beginning
parent 8e4680a9
......@@ -5,7 +5,6 @@
mov qword ptr n_marked_words+0,rbx
shl rax,6
mov qword ptr lazy_array_list+0,rbx
mov qword ptr heap_size_64_65+0,rax
lea rsi,(-4000)[rsp]
......@@ -54,84 +53,6 @@ _end_mark_cafs:
continue_mark_after_pmark:
mov qword ptr n_marked_words+0,r14
mov rcx,qword ptr lazy_array_list+0
test rcx,rcx
je end_restore_arrays
restore_arrays:
mov rbx,qword ptr [rcx]
lea r9,__ARRAY__+2+0
mov qword ptr [rcx],r9
cmp rbx,1
je restore_array_size_1
lea rdx,[rcx+rbx*8]
mov rax,qword ptr 16[rdx]
test rax,rax
je restore_lazy_array
mov rbp,rax
push rdx
xor rdx,rdx
mov rax,rbx
movzx rbx,word ptr (-2+2)[rbp]
div rbx
mov rbx,rax
pop rdx
mov rax,rbp
restore_lazy_array:
mov rdi,qword ptr 16[rcx]
mov rbp,qword ptr 8[rcx]
mov qword ptr 8[rcx],rbx
mov rsi,qword ptr 8[rdx]
mov qword ptr 16[rcx],rax
mov qword ptr 8[rdx],rbp
mov qword ptr 16[rdx],rdi
test rax,rax
je no_reorder_array
movzx rdx,word ptr (-2)[rax]
sub rdx,256
movzx rbp,word ptr (-2+2)[rax]
cmp rbp,rdx
je no_reorder_array
add rcx,24
imul rbx,rdx
mov rax,rdx
lea rdx,[rcx+rbx*8]
mov rbx,rbp
sub rax,rbp
call reorder
no_reorder_array:
mov rcx,rsi
test rcx,rcx
jne restore_arrays
jmp end_restore_arrays
restore_array_size_1:
mov rbp,qword ptr 8[rcx]
mov rdx,qword ptr 16[rcx]
mov qword ptr 8[rcx],rbx
mov rax,qword ptr 24[rcx]
mov qword ptr 24[rcx],rbp
mov qword ptr 16[rcx],rax
mov rcx,rdx
test rcx,rcx
jne restore_arrays
end_restore_arrays:
mov rdi,qword ptr heap_vector+0
lea rcx,finalizer_list+0
lea rdx,free_finalizer_list+0
......@@ -1015,7 +936,7 @@ _mark_array:
je _mark_a_record_array
_mark_ab_record_array:
or dword ptr [rdi+rbx*4],esi
or dword ptr [rdi+rbx*4],esi
mov rbp,qword ptr 8[rcx]
imul rax,rbp
......@@ -1030,19 +951,19 @@ _mark_ab_record_array:
cmp rbx,rax
jae _end_set_ab_array_bits
inc rbx
inc rbx
mov rbp,1
cmp rbx,rax
cmp rbx,rax
jae _last_ab_array_bits
_mark_ab_array_lp:
or dword ptr [rdi+rbx*4],ebp
or dword ptr [rdi+rbx*4],ebp
inc rbx
cmp rbx,rax
cmp rbx,rax
jb _mark_ab_array_lp
_last_ab_array_bits:
or dword ptr [rdi+rbx*4],ebp
or dword ptr [rdi+rbx*4],ebp
_end_set_ab_array_bits:
mov rax,qword ptr 8[rcx]
......@@ -1092,10 +1013,10 @@ _mark_a_record_array:
add rax,r10
shr rax,8
cmp rbx,rax
cmp rbx,rax
jae _end_set_a_array_bits
inc rbx
inc rbx
mov rbp,1
cmp rbx,rax
jae _last_a_array_bits
......@@ -1262,7 +1183,7 @@ __mark_arguments:
add rcx,8
cmp rbp,256
jae __mark__record
jae __mark_record
sub rbp,2
je __mark_hnf_2
......@@ -1313,7 +1234,7 @@ __no_shared_argument_part:
add rcx,8
shl rbp,3
or qword ptr [rdx],1
or qword ptr [rdx],3
add rax,rbp
add rdx,rbp
......@@ -1733,17 +1654,18 @@ __mark_next_node:
jmp __mark_node
__mark_parent:
test rsi,2
je __mark_end_or_in_array
mov rbx,rsi
and rsi,-4
je __end_mark_using_reversal
and rbx,3
mov rbp,qword ptr [rsi]
mov qword ptr [rsi],rcx
sub rbx,1
je __argument_part_parent
test rbx,1
jne __argument_part_parent
lea rcx,(-8)[rsi]
mov rsi,rbp
jmp __mark_next_node
......@@ -1758,6 +1680,52 @@ __argument_part_parent:
lea rsi,(2-8)[rbp]
jmp __mark_node
__mark_end_or_in_array:
sub rsi,1
je __end_mark_using_reversal
mov rbp,qword ptr [rsi]
mov qword ptr [rsi],rcx
lea rbx,(-24)[rsi]
cmp rbx,rbp
je __end_array
mov rbx,qword ptr 16[rbp]
movzx rax,byte ptr (-2)[rbx]
movzx rbx,word ptr (-2+2)[rbx]
cmp rbx,1
je __in_array_a1
sub rbx,rax
neg rax
or qword ptr [rsi+rax*8],1
lea rsi,(-8)[rsi+rbx*8]
mov rcx,qword ptr [rsi]
mov qword ptr [rsi],rbp
jmp __mark_node
__in_array_a1:
shl rax,3
sub rsi,rax
mov rcx,qword ptr [rsi]
mov qword ptr [rsi],rbp
or rsi,1
jmp __mark_node
__end_array:
mov rsi,qword ptr [rbp]
lea r9,__ARRAY__+2+0
mov qword ptr [rbp],r9
mov rcx,rbp
jmp __mark_next_node
__mark_lazy_node:
movsxd rbp,dword ptr(-4)[rax]
test rbp,rbp
......@@ -1931,7 +1899,7 @@ __mark_node2_bb:
or dword ptr 4[rdi+rbx*4],1
jmp __mark_next_node
__mark__record:
__mark_record:
sub rbp,258
je __mark_record_2
jl __mark_record_1
......@@ -1969,7 +1937,7 @@ fits__in__word__13:
jne __shared_record_argument_part
add rbp,1
or dword ptr [rdi+rax *4],esi
or dword ptr [rdi+rax*4],esi
lea rdx,[rdx+rbp*8]
add r14,rbp
......@@ -1993,7 +1961,7 @@ fits__in__word__14:
lea rsi,[rdx+rbx*8]
mov rax,qword ptr [rdx]
or rax,1
or rax,3
mov rbp,qword ptr [rsi]
mov qword ptr [rdx],rax
mov qword ptr [rsi],rcx
......@@ -2007,7 +1975,7 @@ __mark_record_3_bb:
__mark_record_3_aab:
mov rbp,qword ptr [rdx]
mov qword ptr [rdx],rcx
lea rsi,1[rdx]
lea rsi,3[rdx]
mov rcx,rbp
jmp __mark_node
......@@ -2073,50 +2041,76 @@ __mark_array:
je __mark_a_record_array
__mark__ab__record__array:
push rdx
push rbx
mov rbx,rbp
ifdef PIC
lea r9,bit_set_table2+0
mov edx,dword ptr [r9+rdx]
else
mov edx,dword ptr (bit_set_table2)[rdx]
endif
or dword ptr [rdi+rbx*4],edx
mov rbp,qword ptr 8[rcx]
mov rdx,rax
imul rax,qword ptr 8[rcx]
mov r9,rbp
mov rbp,r10
add rcx,16
push rcx
shl rbp,3
mov rdx,rax
imul rdx,rbp
add rbp,rcx
lea rbp,[rbp+rax*8]
sub rax,rbx
add rcx,8
add rdx,rcx
shr rbp,8
call reorder
pop rcx
cmp rbx,rbp
jae __skip_mark_array_ab_bits
xchg rax,rbx
mov rbp,qword ptr (-8)[rcx]
imul rax,rbp
imul rbx,rbp
add r14,rbx
add rbx,rax
inc rbx
shl rbx,3
lea rbp,[r10+rcx]
add rbp,rbx
__mark_array_ab_bits:
or dword ptr [rdi+rbx*4],1
inc rbx
cmp rbx,rbp
jbe __mark_array_ab_bits
pop rbx
pop rdx
__skip_mark_array_ab_bits:
add r14,3
add r14,rax
ifdef PIC
lea r9,bit_set_table2+0
mov edx,dword ptr [r9+rdx]
else
mov edx,dword ptr (bit_set_table2)[rdx]
endif
or dword ptr [rdi+rbx*4],edx
mov rbp,r9
lea rdx,[rcx+rax*8]
jmp __mark_r_array
test rax,rax
je __mark_array_ab_length_0
sub rax,rdx
lea rbx,(-16)[rcx]
cmp rbp,1
je __mark_array_a_length_1
add rbp,rax
lea rdx,[rcx+rbp*8]
mov rcx,qword ptr [rdx]
mov qword ptr [rdx],rbx
mov qword ptr [rbx],rsi
or qword ptr 24[rbx+rax*8],1
mov rsi,rdx
jmp __mark_node
__mark_array_ab_length_0:
lea rcx,(-16)[rcx]
jmp __mark_next_node
__mark_array_a_length_1:
lea rdx,8[rcx+rax*8]
mov rcx,qword ptr [rdx]
mov qword ptr [rdx],rbx
mov qword ptr [rbx],rsi
lea rsi,1[rdx]
jmp __mark_node
__mark_a_record_array:
imul rax,qword ptr 8[rcx]
......@@ -2144,7 +2138,7 @@ __mark_r_array:
cmp rbx,rbp
jae __skip_mark_lazy_array_bits
inc rbx
inc rbx
__mark_lazy_array_bits:
or dword ptr [rdi+rbx*4],1
......@@ -2159,44 +2153,25 @@ __skip_mark_lazy_array_bits:
cmp rax,1
jbe __mark_array_length_0_1
mov rbp,qword ptr [rdx]
mov rbx,qword ptr [rcx]
mov qword ptr [rdx],rbx
mov qword ptr [rcx],rbp
lea rbx,(-16)[rcx]
mov rbp,qword ptr (-8)[rdx]
sub rdx,8
mov rbx,qword ptr lazy_array_list+0
add rbp,2
mov qword ptr [rdx],rbx
mov qword ptr (-8)[rcx],rbp
mov qword ptr (-16)[rcx],rax
sub rcx,16
mov qword ptr lazy_array_list+0,rcx
mov rcx,qword ptr (-8)[rdx]
mov qword ptr (-8)[rdx],rsi
lea rsi,(-8)[rdx]
mov rcx,qword ptr [rdx]
mov qword ptr [rdx],rbx
mov qword ptr [rbx],rsi
or qword ptr 24[rbx],1
mov rsi,rdx
jmp __mark_node
__mark_array_length_0_1:
lea rcx,(-16)[rcx]
jb __mark_next_node
jne __mark_next_node
mov rbx,qword ptr 24[rcx]
mov rbp,qword ptr 16[rcx]
mov rdx,qword ptr lazy_array_list+0
mov qword ptr 24[rcx],rbp
mov qword ptr 16[rcx],rdx
mov qword ptr [rcx],rax
mov qword ptr lazy_array_list+0,rcx
mov qword ptr 8[rcx],rbx
add rcx,8
mov rbx,rcx
mov rbp,qword ptr [rcx]
mov qword ptr [rcx],rsi
lea rsi,2[rcx]
mov rcx,rbp
mov rcx,qword ptr [rdx]
mov qword ptr [rdx],rbx
mov qword ptr [rbx],rsi
lea rsi,1[rdx]
jmp __mark_node
__mark_b_record_array:
......
......@@ -67,7 +67,6 @@ no_copy:
shl $5,d0
movl d0,heap_size_32_33
movl d1,lazy_array_list
lea -2000(sp),a3
......@@ -100,84 +99,6 @@ _end_mark_cafs:
movl a3,end_vector
call _mark_stack_nodes
movl lazy_array_list,a0
test a0,a0
je end_restore_arrays
restore_arrays:
movl (a0),d1
movl $__ARRAY__+2,(a0)
cmpl $1,d1
je restore_array_size_1
lea (a0,d1,4),a1
movl 8(a1),d0
test d0,d0
je restore_lazy_array
movl d0,a2
push a1
xorl a1,a1
movl d1,d0
movzwl -2+2(a2),d1
div d1
movl d0,d1
pop a1
movl a2,d0
restore_lazy_array:
movl 8(a0),a4
movl 4(a0),a2
movl d1,4(a0)
movl 4(a1),a3
movl d0,8(a0)
movl a2,4(a1)
movl a4,8(a1)
test d0,d0
je no_reorder_array
movzwl -2(d0),a1
subl $256,a1
movzwl -2+2(d0),a2
cmpl a1,a2
je no_reorder_array
addl $12,a0
imull a1,d1
movl a1,d0
lea (a0,d1,4),a1
movl a2,d1
subl a2,d0
call reorder
no_reorder_array:
movl a3,a0
testl a0,a0
jne restore_arrays
jmp end_restore_arrays
restore_array_size_1:
movl 4(a0),a2
movl 8(a0),a1
movl d1,4(a0)
movl 12(a0),d0
movl a2,12(a0)
movl d0,8(a0)
movl a1,a0
testl a0,a0
jne restore_arrays
end_restore_arrays:
#ifdef FINALIZERS
movl heap_vector,a4
movl $finalizer_list,a0
......@@ -1301,7 +1222,7 @@ __no_shared_argument_part:
addl $4,a0
shl $2,a2
orl $1,(a1)
orl $3,(a1)
addl a2,d0
addl a2,a1
......@@ -1624,23 +1545,17 @@ __mark_next_node:
jmp __mark_node
__mark_parent:
test $2,a3
je __end_or_in_array
movl a3,d1
andl $-4,a3
je __end_mark_using_reversal
andl $3,d1
movl (a3),a2
movl a0,(a3)
subl $1,d1
je __argument_part_parent
#ifdef DEBUG_MARK_COLLECT
cmpl $1,d1
je no_error_in_gc2
call error_in_gc
no_error_in_gc2:
#endif
test $1,d1
jne __argument_part_parent
lea -4(a3),a0
movl a2,a3
......@@ -1656,6 +1571,51 @@ __argument_part_parent:
lea 2-4(a2),a3
jmp __mark_node
__end_or_in_array:
sub $1,a3
je __end_mark_using_reversal
movl (a3),a2
movl a0,(a3)
lea -12(a3),d1
cmpl a2,d1
je __end_array
movl 8(a2),d1
movzbl -2(d1),d0
movzwl -2+2(d1),d1
cmp $1,d1
je __in_array_a1
sub d0,d1
neg d0
orl $1,(a3,d0,4)
lea -4(a3,d1,4),a3
movl (a3),a0
movl a2,(a3)
jmp __mark_node
__in_array_a1:
shl $2,d0
sub d0,a3
movl (a3),a0
movl a2,(a3)
orl $1,a3
jmp __mark_node
__end_array:
movl (a2),a3
movl $__ARRAY__+2,(a2)
movl a2,a0
jmp __mark_next_node
__mark_lazy_node:
movl -4(d0),a2
testl a2,a2
......@@ -1842,7 +1802,7 @@ fits__in__word__14:
lea (a1,d1,4),a3
movl (a1),d0
orl $1,d0
orl $3,d0
movl (a3),a2
movl d0,(a1)
movl a0,(a3)
......@@ -1856,7 +1816,7 @@ __mark_record_3_bb:
__mark_record_3_aab:
movl (a1),a2
movl a0,(a1)
lea 1(a1),a3
lea 3(a1),a3
movl a2,a0
jmp __mark_node
......@@ -1903,54 +1863,80 @@ __mark_array: