[squeak-dev] The Inbox: Kernel-jar.1405.mcz

commits at source.squeak.org commits at source.squeak.org
Wed May 12 11:31:58 UTC 2021


A new version of Kernel was added to project The Inbox:
http://source.squeak.org/inbox/Kernel-jar.1405.mcz

==================== Summary ====================

Name: Kernel-jar.1405
Author: jar
Time: 12 May 2021, 1:31:53.708002 pm
UUID: d57e5134-bbd9-af44-9677-b0d70adef3a7
Ancestors: Kernel-nice.1402

Supersede Kernel-jar.1403.mcz

Improve previous chages in Kernel-jar.1403.mcz by preventing cannot return errors crash the VM when accidentally pressing Proceed or stepping over it. Uses the fix from Kernel-jar.1404.mcz

Example previously crashing the VM:

[^2] fork

=============== Diff against Kernel-nice.1402 ===============

Item was changed:
  ----- Method: Context>>cannotReturn: (in category 'private-exceptions') -----
  cannotReturn: result
+ 	"Note: BlockCannotReturn is looped back because returning to thisContext's sender (i.e. to self) wouldn't make sense and would crash the VM - the sender's pc was set to endPC+1 because the sender attempted an illegal non-local return (to a dead context or a to context on another stack). This message is sent by the VM or during simulation."
  
+ 	closureOrNil ifNotNil: [self cannotReturn: result to: self home sender. thisContext privRefresh].
- 	closureOrNil ifNotNil: [^ self cannotReturn: result to: self home sender].
  	Processor debugWithTitle: 'Computation has been terminated!!' translated full: false.!

Item was changed:
  ----- Method: Context>>runUntilErrorOrReturnFrom: (in category 'controlling') -----
  runUntilErrorOrReturnFrom: aSender 
  	"ASSUMES aSender is a sender of self.  Execute self's stack until aSender returns or an unhandled exception is raised.  Return a pair containing the new top context and a possibly nil exception.  The exception is not nil if it was raised before aSender returned and it was not handled.  The exception is returned rather than openning the debugger, giving the caller the choice of how to handle it."
  	"Self is run by jumping directly to it (the active process abandons thisContext and executes self).  However, before jumping to self we insert an ensure block under aSender that jumps back to thisContext when evaluated.  We also insert an exception handler under aSender that jumps back to thisContext when an unhandled exception is raised.  In either case, the inserted ensure and exception handler are removed once control jumps back to thisContext."
  
  	| error ctxt here topContext |
  	here := thisContext.
  
  	"Insert ensure and exception handler contexts under aSender"
  	error := nil.
  	ctxt := aSender insertSender: (Context
  		contextOn: UnhandledError do: [:ex |
  			error ifNil: [
  				error := ex exception.
  				topContext := thisContext.
+ 				here jump.
+ 				"re-signal the error if jumped back;
+ 				required by Process>>#terminate"
+ 				ex signalerContext restart]
- 				ex resumeUnchecked: here jump]
  			ifNotNil: [ex pass]
  		]).
  	ctxt := ctxt insertSender: (Context
  		contextEnsure: [error ifNil: [
  				topContext := thisContext.
  				here jump]
  		]).
  	self jump.  "Control jumps to self"
  
  	"Control resumes here once above ensure block or exception handler is executed"
  	^ error ifNil: [
  		"No error was raised, remove ensure context by stepping until popped"
  		[ctxt isDead] whileFalse: [topContext := topContext stepToCallee].
  		{topContext. nil}
  
  	] ifNotNil: [
  		"Error was raised, remove inserted above contexts then return signaler context"
  		aSender terminateTo: ctxt sender.  "remove above ensure and handler contexts"
  		{topContext. error}
  	]!

Item was changed:
  ----- Method: Process>>terminate (in category 'changing process state') -----
  terminate 
  	"Stop the process that the receiver represents forever.
  	 Unwind to execute pending ensure:/ifCurtailed: blocks before terminating.
  	 If the process is in the middle of a critical: critical section, release it properly."
  
+ 	| ctxt unwindBlock oldList outerMost top pair doNotDebug |
- 	| ctxt unwindBlock oldList outerMost |
  	self isActiveProcess ifTrue: [
  		"If terminating the active process, suspend it first and terminate it as a suspended process."
  		[self terminate] fork.
  		^self suspend].
  
  	"Always suspend the process first so it doesn't accidentally get woken up.
  	 N.B. If oldList is a LinkedList then the process is runnable. If it is a Semaphore/Mutex et al
  	 then the process is blocked, and if it is nil then the process is already suspended."
  	oldList := self suspend.
+ 	suspendedContext ifNotNil: [
+ 		"Release any method marked with the <criticalSection> pragma.
- 	suspendedContext ifNotNil:
- 		["Release any method marked with the <criticalSection> pragma.
  		  The argument is whether the process is runnable."
  		 self releaseCriticalSection: (oldList isNil or: [oldList class == LinkedList]).
  
+ 		ctxt := top := suspendedContext.
+ 		"Disable this process while running its stack in active process below"
+ 		suspendedContext := nil. 
+ 		"Define an exclusion list of exceptions requiring special care to prevent e.g. an infinite 
+ 		recursion of MNU errors or a VM crash in case of a non-local return to a dead home context; 
+ 		blocks containing these exceptions are silently skipped and the unwind procedure continues;
+ 		UndefinedObject represents #runUntilErrorOrReturnFrom: found no error and answered nil."
+ 		doNotDebug := {UndefinedObject. BlockCannotReturn. MessageNotUnderstood}.
  		"If terminating a process halfways through an unwind, try to complete that unwind block first;
  		if there are multiple such nested unwind blocks, try to complete the outer-most one; the inner
+ 		blocks will be completed in the process. Halfway through blocks have already set the complete 
+ 		variable (tempAt: 2) in their defining #ensure:/#ifCurtailed contexts from nil to true."
+ 		[(ctxt := ctxt findNextUnwindContextUpTo: nil) isNil] whileFalse: [
+ 			(ctxt tempAt:2) ifNotNil: [outerMost := ctxt]].
+ 		outerMost ifNotNil: ["This is the outer-most unwind context currently under evaluation"
+ 			"Let's finish the unfinished unwind context only and return here. Note: top may be equal 
+ 			to outerMost e.g. in case #ensure was interrupted right after assigning complete := true."
+ 			pair := top runUntilErrorOrReturnFrom: outerMost.
+ 			"If an error was detected jump back to open a debugger; do not jump back if the error is
+ 			in the doNotDebug list. Note: for more information on the return value pair see comments 
+ 			in #runUntilErrorOrReturnFrom."
+ 			(doNotDebug includes: pair second class) ifFalse: [pair first jump]].
- 		blocks will be completed in the process."
- 		ctxt := suspendedContext.
- 		[(ctxt := ctxt findNextUnwindContextUpTo: nil) isNil] whileFalse: 
- 			"Contexts under evaluation have already set their complete (tempAt: 2) to true."
- 			[(ctxt tempAt:2) ifNotNil: [outerMost := ctxt]].
- 		outerMost ifNotNil: [
- 			"This is the outer-most unwind context currently under evaluation;
- 			let's find an inner context executing outerMost's argument block (tempAt: 1)"
- 			(suspendedContext findContextSuchThat: [:ctx | 
- 				ctx closure == (outerMost tempAt: 1)]) ifNotNil: [:inner | 
- 					"Let's finish the unfinished unwind context only (i.e. up to inner) and return here"
- 					suspendedContext runUntilErrorOrReturnFrom: inner. 
- 					"Update the receiver's suspendedContext (the previous step reset its sender to nil);
- 					return, if the execution stack reached its bottom (e.g. in case of non-local returns)."
- 					(suspendedContext := outerMost sender) ifNil: [^self]]]. 
  
  		"Now all unwind blocks caught halfway through have been completed; 
+ 		let's execute the ones still pending. Note: #findNextUnwindContextUpTo: starts 
+ 		searching from the receiver's sender but the receiver itself may be an unwind context;
+ 		set ctxt as a new starting point in a search for the remaining unwind blocks.
+ 		Note: pair first sender points to outerMost sender i.e. the next unexplored context."
+ 		ctxt := pair ifNil: [top] ifNotNil: [pair first sender].
- 		let's execute the ones still pending. Note: #findNextUnwindContextUpTo: starts
- 		searching from the receiver's sender but the receiver itself may be an unwind context."
- 		ctxt := suspendedContext.
  		ctxt isUnwindContext ifFalse: [ctxt := ctxt findNextUnwindContextUpTo: nil].
  		[ctxt isNil] whileFalse: [
  			(ctxt tempAt: 2) ifNil: [
  				ctxt tempAt: 2 put: true.
  				unwindBlock := ctxt tempAt: 1.
  				"Create a context for the unwind block and execute it on the unwind block's stack. 
  				Note: using #value instead of #runUntilErrorOrReturnFrom: would lead to executing 
  				the unwind on the wrong stack preventing the correct execution of non-local returns."
+ 				top := unwindBlock asContextWithSender: ctxt.
+ 				pair := top runUntilErrorOrReturnFrom: top.
+ 				"If an error was detected jump back to open a debugger; do not jump back if the error is
+ 				in the doNotDebug list. Note: for more information on the return value pair see comments 
+ 				in #runUntilErrorOrReturnFrom."
+ 				(doNotDebug includes: pair second class) ifFalse: [pair first jump]].
+ 			ctxt := ctxt findNextUnwindContextUpTo: nil]]
+ !
- 				suspendedContext := unwindBlock asContextWithSender: ctxt.
- 				suspendedContext runUntilErrorOrReturnFrom: suspendedContext].
- 			ctxt := ctxt findNextUnwindContextUpTo: nil].
- 
- 		"Reset the context's pc and sender to nil for the benefit of isTerminated."
- 		suspendedContext terminate]!



More information about the Squeak-dev mailing list