Commit 2447c8ff authored by John van Groningen's avatar John van Groningen
Browse files

optimisation, don't allocate profile records if code with stack traces is generated

parent b36fa58b
......@@ -8,13 +8,13 @@ _DATA ends
public init_profiler
public profile_r
public profile_l
public profile_l2
public profile_n
public profile_n2
public profile_s
public profile_s2
public profile_t
public profile_l
public profile_l2
public profile_n
public profile_n2
public profile_s
public profile_s2
public profile_t
public write_profile_stack
public stack_trace_depth
......@@ -29,258 +29,34 @@ _DATA ends
; extrn print_error:near
; extrn profile_stack_pointer:near
next = 0
name_ = 8
FunctionProfile = 16
profile_t:
sub qword ptr profile_stack_pointer,8
ret
profile_r:
sub qword ptr profile_stack_pointer,8
ret
profile_l:
push rbx
mov rbx,qword ptr [rbp]
test rbx,rbx
je allocate_function_profile_record_l
allocate_function_profile_record_lr:
mov rbp,qword ptr profile_stack_pointer
mov qword ptr [rbp],rbx
add rbp,8
mov qword ptr profile_stack_pointer,rbp
pop rbx
ret
allocate_function_profile_record_l:
call allocate_function_profile_record
jmp allocate_function_profile_record_lr
profile_l2:
push rbx
mov rbx,qword ptr [rbp]
test rbx,rbx
je allocate_function_profile_record_l2
allocate_function_profile_record_l2r:
mov rbp,qword ptr profile_stack_pointer
mov qword ptr [rbp],rbx
mov qword ptr 8[rbp],rbx
add rbp,16
mov qword ptr profile_stack_pointer,rbp
pop rbx
ret
allocate_function_profile_record_l2:
call allocate_function_profile_record
jmp allocate_function_profile_record_l2r
profile_n:
profile_s:
push rbx
mov rbx,qword ptr [rbp]
test rbx,rbx
je allocate_function_profile_record_n
allocate_function_profile_record_nr:
mov rbp,qword ptr profile_stack_pointer
mov qword ptr [rbp],rbx
add rbp,8
mov qword ptr profile_stack_pointer,rbp
mov rbx,qword ptr profile_stack_pointer
mov qword ptr [rbx],rbp
add rbx,8
mov qword ptr profile_stack_pointer,rbx
pop rbx
ret
allocate_function_profile_record_n:
call allocate_function_profile_record
jmp allocate_function_profile_record_nr
profile_l2:
profile_n2:
push rbx
mov rbx,qword ptr [rbp]
test rbx,rbx
je allocate_function_profile_record_n2
allocate_function_profile_record_n2r:
mov rbp,qword ptr profile_stack_pointer
mov qword ptr [rbp],rbx
mov qword ptr 8[rbp],rbx
add rbp,16
mov qword ptr profile_stack_pointer,rbp
pop rbx
ret
allocate_function_profile_record_n2:
call allocate_function_profile_record
jmp allocate_function_profile_record_n2r
profile_s2:
push rbx
mov rbx,qword ptr [rbp]
test rbx,rbx
je allocate_function_profile_record_s2
allocate_function_profile_record_s2r:
mov rbp,qword ptr profile_stack_pointer
mov qword ptr [rbp],rbx
mov qword ptr 8[rbp],rbx
add rbp,16
mov qword ptr profile_stack_pointer,rbp
pop rbx
ret
allocate_function_profile_record_s2:
call allocate_function_profile_record
jmp allocate_function_profile_record_s2r
profile_s:
push rbx
mov rbx,qword ptr [rbp]
test rbx,rbx
je allocate_function_profile_record_s
allocate_function_profile_record_sr:
mov rbp,qword ptr profile_stack_pointer
mov qword ptr [rbp],rbx
add rbp,8
mov qword ptr profile_stack_pointer,rbp
mov rbx,qword ptr profile_stack_pointer
mov qword ptr [rbx],rbp
mov qword ptr 8[rbx],rbp
add rbx,16
mov qword ptr profile_stack_pointer,rbx
pop rbx
ret
allocate_function_profile_record_s:
call allocate_function_profile_record
jmp allocate_function_profile_record_sr
; argument: rbp: function name adress-4
; result: rbx: function profile record adress
allocate_function_profile_record:
push rax
mov rax,qword ptr global_n_free_records_in_block
mov rbx,qword ptr global_last_allocated_block
test rax,rax
jne no_alloc
push rcx
push rdx
push rbp
ifdef LINUX
sub rsp,104
mov qword ptr [rsp],rsi
mov qword ptr 8[rsp],rdi
mov qword ptr 16[rsp],r8
mov qword ptr 24[rsp],r10
mov qword ptr 32[rsp],r11
movsd qword ptr 40[rsp],xmm0
movsd qword ptr 48[rsp],xmm1
movsd qword ptr 56[rsp],xmm2
movsd qword ptr 64[rsp],xmm3
movsd qword ptr 72[rsp],xmm4
movsd qword ptr 80[rsp],xmm5
movsd qword ptr 88[rsp],xmm6
movsd qword ptr 96[rsp],xmm7
else
sub rsp,72
mov qword ptr [rsp],r8
mov qword ptr 8[rsp],r10
mov qword ptr 16[rsp],r11
movsd qword ptr 24[rsp],xmm0
movsd qword ptr 32[rsp],xmm1
movsd qword ptr 40[rsp],xmm2
movsd qword ptr 48[rsp],xmm3
movsd qword ptr 56[rsp],xmm4
movsd qword ptr 64[rsp],xmm5
endif
mov rbp,rsp
sub rsp,40
and rsp,-16
ifdef LINUX
mov rdi,8192
; 512*FunctionProfile
call malloc
else
mov rcx,512*FunctionProfile
call allocate_memory
endif
mov rsp,rbp
ifdef LINUX
mov rsi,qword ptr [rsp]
mov rdi,qword ptr 8[rsp]
mov r8,qword ptr 16[rsp]
mov r10,qword ptr 24[rsp]
mov r11,qword ptr 32[rsp]
movlpd xmm0,qword ptr 40[rsp]
movlpd xmm1,qword ptr 48[rsp]
movlpd xmm2,qword ptr 56[rsp]
movlpd xmm3,qword ptr 64[rsp]
movlpd xmm4,qword ptr 72[rsp]
movlpd xmm5,qword ptr 80[rsp]
movlpd xmm6,qword ptr 88[rsp]
movlpd xmm7,qword ptr 96[rsp]
add rsp,104
else
mov r8,qword ptr [rsp]
mov r10,qword ptr 8[rsp]
mov r11,qword ptr 16[rsp]
movlpd xmm0,qword ptr 24[rsp]
movlpd xmm1,qword ptr 32[rsp]
movlpd xmm2,qword ptr 40[rsp]
movlpd xmm3,qword ptr 48[rsp]
movlpd xmm4,qword ptr 56[rsp]
movlpd xmm5,qword ptr 64[rsp]
add rsp,72
endif
test rax,rax
pop rbp
pop rdx
pop rcx
je no_memory
mov rbx,rax
mov rax,512
mov qword ptr global_last_allocated_block,rbx
no_alloc:
dec rax
mov qword ptr global_n_free_records_in_block,rax
lea rax,FunctionProfile[rbx]
mov qword ptr global_last_allocated_block,rax
mov rax,qword ptr global_profile_records
mov qword ptr name_[rbx],rbp
mov qword ptr next[rbx],rax
mov qword ptr global_profile_records,rbx
mov qword ptr [rbp],rbx
pop rax
ret
no_memory:
lea rbp,not_enough_memory_for_profiler
pop rax
jmp print_error
write_profile_stack:
ifdef LINUX
mov r13,rsi
......@@ -309,15 +85,13 @@ write_profile_stack:
; mov rbp,12
mov rbp,qword ptr stack_trace_depth
write_functions_on_stack:
mov rbx,qword ptr (-8)[rax]
mov rcx,qword ptr (-8)[rax]
sub rax,8
test rbx,rbx
test rcx,rcx
je end_profile_stack
push rax
mov rcx,qword ptr name_[rbx]
push rbp
mov edx,dword ptr (-4)[rcx]
......@@ -407,8 +181,7 @@ init_profiler:
push rax
lea rbp,start_string
call allocate_function_profile_record
lea rbx,start_string
pop rdx
......@@ -429,21 +202,11 @@ _TEXT ends
align (1 shl 3)
global_n_free_records_in_block:
dq 0
; 0 n free records in block
global_last_allocated_block:
dq 0
; 8 latest allocated block
global_profile_records:
dq 0
; 16 profile record list
stack_trace_depth:
dq 12
align (1 shl 3)
; m_system also defined in istartup.s
; m_system also defined in astartup.asm
; m_system:
; dq 6
; db "System"
......@@ -460,10 +223,6 @@ not_enough_memory_for_profile_stack:
db "not enough memory for profile stack"
db 10
db 0
not_enough_memory_for_profiler:
db "not enough memory for profiler"
db 10
db 0
stack_trace_string:
db "Stack trace:"
db 10
......
#undef DEBUG_PROFILER
#define MODULE_NAMES
#define d0 %eax
......@@ -50,216 +48,33 @@
.text
profile_t:
subl $4,profile_stack_pointer
ret
profile_r:
subl $4,profile_stack_pointer
ret
profile_l:
push d1
mov (a2),d1
test d1,d1
je allocate_function_profile_record_l
allocate_function_profile_record_lr:
mov profile_stack_pointer,a2
#ifdef DEBUG_PROFILER
testl (d1),d1
#endif
mov d1,(a2)
add $4,a2
mov a2,profile_stack_pointer
pop d1
ret
allocate_function_profile_record_l:
call allocate_function_profile_record
jmp allocate_function_profile_record_lr
profile_l2:
push d1
mov (a2),d1
test d1,d1
je allocate_function_profile_record_l2
allocate_function_profile_record_l2r:
mov profile_stack_pointer,a2
#ifdef DEBUG_PROFILER
testl (d1),d1
#endif
mov d1,(a2)
mov d1,4(a2)
add $8,a2
mov a2,profile_stack_pointer
pop d1
ret
allocate_function_profile_record_l2:
call allocate_function_profile_record
jmp allocate_function_profile_record_l2r
profile_n:
profile_s:
push d1
mov (a2),d1
test d1,d1
je allocate_function_profile_record_n
allocate_function_profile_record_nr:
mov profile_stack_pointer,a2
#ifdef DEBUG_PROFILER
testl (d1),d1
#endif
mov d1,(a2)
add $4,a2
mov a2,profile_stack_pointer
mov profile_stack_pointer,d1
mov a2,(d1)
add $4,d1
mov d1,profile_stack_pointer
pop d1
ret
allocate_function_profile_record_n:
call allocate_function_profile_record
jmp allocate_function_profile_record_nr
profile_l2:
profile_n2:
push d1
mov (a2),d1
test d1,d1
je allocate_function_profile_record_n2
allocate_function_profile_record_n2r:
mov profile_stack_pointer,a2
#ifdef DEBUG_PROFILER
testl (d1),d1
#endif
mov d1,(a2)
mov d1,4(a2)
add $8,a2
mov a2,profile_stack_pointer
pop d1
ret
allocate_function_profile_record_n2:
call allocate_function_profile_record
jmp allocate_function_profile_record_n2r
profile_s2:
push d1
mov (a2),d1
test d1,d1
je allocate_function_profile_record_s2
allocate_function_profile_record_s2r:
mov profile_stack_pointer,a2
#ifdef DEBUG_PROFILER
testl (d1),d1
#endif
movl d1,(a2)
movl d1,4(a2)
add $8,a2
mov a2,profile_stack_pointer
pop d1
ret
allocate_function_profile_record_s2:
call allocate_function_profile_record
jmp allocate_function_profile_record_s2r
profile_s:
push d1
movl (a2),d1
test d1,d1
je allocate_function_profile_record_s
allocate_function_profile_record_sr:
mov profile_stack_pointer,a2
#ifdef DEBUG_PROFILER
testl (d1),d1
#endif
movl d1,(a2)
add $4,a2
mov a2,profile_stack_pointer
pop d1
ret
allocate_function_profile_record_s:
call allocate_function_profile_record
jmp allocate_function_profile_record_sr
/ argument: a2: function name adress-4
/ result: d1: function profile record adress
allocate_function_profile_record:
push d0
mov global_n_free_records_in_block,d0
mov global_last_allocated_block,d1
test d0,d0
jne no_alloc
push d1
push a0
push a1
pushl $512*FunctionProfile
#ifdef LINUX
call @malloc
#else
call @allocate_memory
#endif
add $4,sp
test d0,d0
pop a1
pop a0
mov profile_stack_pointer,d1
mov a2,(d1)
mov a2,4(d1)
add $8,d1
mov d1,profile_stack_pointer
pop d1
je no_memory
mov d0,d1
mov $512,d0
mov d1,global_last_allocated_block
no_alloc:
dec d0
mov d0,global_n_free_records_in_block
lea FunctionProfile(d1),d0
mov d0,global_last_allocated_block
mov global_profile_records,d0
mov a2,name(d1)
mov d0,next(d1)
mov d1,global_profile_records
mov d1,(a2)
pop d0
ret
no_memory:
movl $not_enough_memory_for_profiler,a2
pop d0
jmp print_error
write_profile_information:
ret
......@@ -280,15 +95,13 @@ write_profile_stack:
/ mov $12,a2
movl @stack_trace_depth,a2
write_functions_on_stack:
mov -4(d0),d1
mov -4(d0),a0
sub $4,d0
test d1,d1
test a0,a0
je end_profile_stack
push d0
mov name(d1),a0
push a2
#ifdef MODULE_NAMES
......@@ -350,8 +163,7 @@ init_profiler:
push d0
mov $start_string,a2
call allocate_function_profile_record
mov $start_string,d1
pop a1
......@@ -359,11 +171,6 @@ init_profiler:
movl $0,(a1)
add $8,a1
mov a1,profile_stack_pointer
mov end_heap,a1
sub a4,a1
add $32,a1
mov a1,global_n_bytes_free
ret
init_profiler_error:
......@@ -372,23 +179,13 @@ init_profiler_error:
jmp print_error
.data
align (2)
global_n_free_records_in_block: .long 0
/ 0 n free records in block
global_last_allocated_block: .long 0
/ 4 latest allocated block
global_profile_records: .long 0
/ 8 profile record list
profile_stack_pointer: .long 0
global_n_bytes_free: .long 0
align (2)
@stack_trace_depth:
.long 12
#ifdef MODULE_NAMES
# if 0
/ m_system also defined in cgistartup.s
/ m_system also defined in istartup.s
m_system:
.long 6
.ascii "System"
......@@ -405,10 +202,6 @@ not_enough_memory_for_profile_stack:
.ascii "not enough memory for profile stack"
</