VM: possible fix for #1319.
Fix for reset_context() so that the top two stack items are never removed from the stack so if the parent->init_context(ctx) call triggers a GC, those items are never collected.db4
							parent
							
								
									8d697fcc34
								
							
						
					
					
						commit
						183ec83a6d
					
				| 
						 | 
				
			
			@ -353,14 +353,22 @@ IN: bootstrap.x86
 | 
			
		|||
 | 
			
		||||
: jit-start-context-and-delete ( -- )
 | 
			
		||||
    jit-load-vm
 | 
			
		||||
    jit-load-context
 | 
			
		||||
 | 
			
		||||
    ! Updates the context to match the values in the data and retain
 | 
			
		||||
    ! stack registers. reset_context can GC.
 | 
			
		||||
    jit-save-context
 | 
			
		||||
 | 
			
		||||
    ! Resets the context. The top two ds item are preserved.
 | 
			
		||||
    vm-reg "reset_context" jit-call-1arg
 | 
			
		||||
 | 
			
		||||
    jit-save-quot-and-param
 | 
			
		||||
    ! Switches to the same context I think, uses ctx-reg
 | 
			
		||||
    ctx-reg jit-switch-context
 | 
			
		||||
    jit-push-param
 | 
			
		||||
 | 
			
		||||
    EAX EDX [] MOV
 | 
			
		||||
    ! Pops the quotation from the stack and puts it in EAX.
 | 
			
		||||
    EAX ds-reg [] MOV
 | 
			
		||||
    ds-reg 4 SUB
 | 
			
		||||
 | 
			
		||||
    ! Jump to the quotation in EAX.
 | 
			
		||||
    jit-jump-quot ;
 | 
			
		||||
 | 
			
		||||
[
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -78,7 +78,8 @@ IN: bootstrap.x86
 | 
			
		|||
    jit-restore-context
 | 
			
		||||
] jit-primitive jit-define
 | 
			
		||||
 | 
			
		||||
: jit-jump-quot ( -- ) arg1 quot-entry-point-offset [+] JMP ;
 | 
			
		||||
: jit-jump-quot ( -- )
 | 
			
		||||
    arg1 quot-entry-point-offset [+] JMP ;
 | 
			
		||||
 | 
			
		||||
: jit-call-quot ( -- ) arg1 quot-entry-point-offset [+] CALL ;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -306,13 +307,24 @@ IN: bootstrap.x86
 | 
			
		|||
    jit-set-context
 | 
			
		||||
] \ (set-context-and-delete) define-sub-primitive
 | 
			
		||||
 | 
			
		||||
! Resets the active context and instead the passed in quotation
 | 
			
		||||
! becomes the new code that it executes.
 | 
			
		||||
: jit-start-context-and-delete ( -- )
 | 
			
		||||
    ! Updates the context to match the values in the data and retain
 | 
			
		||||
    ! stack registers. reset_context can GC.
 | 
			
		||||
    jit-save-context
 | 
			
		||||
 | 
			
		||||
    jit-load-context
 | 
			
		||||
    ! Resets the context. The top two ds items are preserved.
 | 
			
		||||
    vm-reg "reset_context" jit-call-1arg
 | 
			
		||||
    jit-pop-quot-and-param
 | 
			
		||||
 | 
			
		||||
    ! Switches to the same context I think.
 | 
			
		||||
    ctx-reg jit-switch-context
 | 
			
		||||
    jit-push-param
 | 
			
		||||
 | 
			
		||||
    ! Pops the quotation from the stack and puts it in arg1.
 | 
			
		||||
    arg1 ds-reg [] MOV
 | 
			
		||||
    ds-reg 8 SUB
 | 
			
		||||
 | 
			
		||||
    ! Jump to quotation arg1
 | 
			
		||||
    jit-jump-quot ;
 | 
			
		||||
 | 
			
		||||
[
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -123,8 +123,18 @@ VM_C_API void delete_context(factor_vm* parent) {
 | 
			
		|||
 | 
			
		||||
/* Allocates memory (init_context()) */
 | 
			
		||||
VM_C_API void reset_context(factor_vm* parent) {
 | 
			
		||||
  parent->ctx->reset();
 | 
			
		||||
  parent->init_context(parent->ctx);
 | 
			
		||||
 | 
			
		||||
  // The function is used by (start-context-and-delete) which expects
 | 
			
		||||
  // the top two datastack items to be preserved after the context has
 | 
			
		||||
  // been resetted.
 | 
			
		||||
 | 
			
		||||
  context* ctx = parent->ctx;
 | 
			
		||||
  cell arg1 = ctx->pop();
 | 
			
		||||
  cell arg2 = ctx->pop();
 | 
			
		||||
  ctx->reset();
 | 
			
		||||
  ctx->push(arg2);
 | 
			
		||||
  ctx->push(arg1);
 | 
			
		||||
  parent->init_context(ctx);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue