[Vm-dev] VM Maker: VMMaker.oscog-eem.2738.mcz

commits at source.squeak.org commits at source.squeak.org
Fri Apr 3 23:00:08 UTC 2020


Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-eem.2738.mcz

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

Name: VMMaker.oscog-eem.2738
Author: eem
Time: 3 April 2020, 3:59:56.137049 pm
UUID: f6958436-d66a-477c-bbcb-4b6586462abe
Ancestors: VMMaker.oscog-eem.2737

CoInterpreter: small tweak for VMMaker.oscog-eem.2737.  On every entry to interpret avoid checking CReturnAddress and simply assign it.  Once set its value never changes, so an unchecked write will be faster and takes less code.

Simulation: make the simulator's close method a little more robust.

=============== Diff against VMMaker.oscog-eem.2737 ===============

Item was changed:
  ----- Method: CoInterpreter>>interpret (in category 'interpreter shell') -----
  interpret
  	"This is the main interpreter loop.
  	 In a pure interpreter it loops forever, fetching and executing bytecodes.
  	 With the Cogit JIT executing code as well, the interpreter is reentered from machine code
  	 whenever the machine code wants to interpret a method instead of executing its machine
  	 code.  Entry into the interpreter is done via a ''jump call'' in machine code that uses
  	 CFramePointer and CStackPointer to find the base of the C stack (set in CoInterpreter>>
  	 enterSmalltalkExecutiveImplementation) and substitutes CReturnAddress as the return
  	 address in the code so it always appears that interpret has been called from
  	 CoInterpreter>>enterSmalltalkExecutiveImplementation, which may be important to,
  	 for example, C exception handling inside the VM.
  
  	 When running in the context of a browser plugin VM the interpreter must return control
  	 to the browser periodically. This should done only when the state of the currently running
  	 Squeak thread is safely stored in the object heap. Since this is the case at the moment
  	 that a check for interrupts is performed, that is when we return to the browser if it is time
  	 to do so. Interrupt checks happen quite frequently."
  
  	<inline: false>
  	"If stacklimit is zero then the stack pages have not been initialized."
  	stackLimit = 0 ifTrue:
  		[^self initStackPagesAndInterpret].
+ 	"An unchecked write is probably faster, so instead of
+ 	 CReturnAddress ifNil:
+ 		[CReturnAddress := self cCoerceSimple: self getReturnAddress to: #usqIntptr_t]
+ 	 we have simply"
+ 	self assert: (CReturnAddress isNil or: [CReturnAddress = self getReturnAddress]).
+ 	CReturnAddress := self cCoerceSimple: self getReturnAddress to: #usqIntptr_t.
- 	CReturnAddress ifNil:
- 		[CReturnAddress := self cCoerceSimple: self getReturnAddress to: #usqIntptr_t].
  	"record entry time when running as a browser plug-in"
  	self browserPluginInitialiseIfNeeded.
  	self internalizeIPandSP.
  	self initExtensions.
  	self fetchNextBytecode.
  	[true] whileTrue: [self dispatchOn: currentBytecode in: BytecodeTable].
  	localIP := localIP - 1.  "undo the pre-increment of IP before returning"
  	self externalizeIPandSP.
  	^nil!

Item was changed:
  ----- Method: CogVMSimulator>>close (in category 'initialization') -----
  close  "close any files that ST may have opened, etc"
  	pluginList do: [:assoc| | plugin | plugin := assoc value. plugin ~~ self ifTrue: [plugin close]].
  	"Ugh; at least some of this code belongs in the UI..."
  	World submorphs do:
  		[:submorph|
  		(submorph model isVMObjectInspector
  		 and: [submorph model coInterpreter == self]) ifTrue:
  			[submorph delete].
  		(submorph model isDebugger
+ 		 and: [(submorph model interruptedProcess suspendedContext ifNotNil:
+ 				[:sctxt|
+ 				 sctxt findContextSuchThat:
- 		 and: [(submorph model interruptedProcess suspendedContext findContextSuchThat:
  					[:ctxt|
  					(ctxt receiver == cogit
  					 and: [ctxt selector == #simulateCogCodeAt:])
  					or: [ctxt receiver == self
+ 					 and: [ctxt selector == #interpret]]]]) notNil]) ifTrue:
- 					 and: [ctxt selector == #interpret]]]) notNil]) ifTrue:
  			[submorph model windowIsClosing.
  			 submorph delete]]!

Item was changed:
  ----- Method: CogVMSimulator>>interpret (in category 'interpreter shell') -----
  interpret
  	"This is the main interpreter loop. It normally loops forever, fetching and executing bytecodes.
  	 When running in the context of a web browser plugin VM, however, it must return control to the
  	 web browser periodically. This should done only when the state of the currently running Squeak
  	 thread is safely stored in the object heap. Since this is the case at the moment that a check for
  	 interrupts is performed, that is when we return to the browser if it is time to do so.  Interrupt
  	 checks happen quite frequently.
  
  	Override for simulation to insert bytecode breakpoint support."
  
  	"If stacklimit is zero then the stack pages have not been initialized."
  	stackLimit = 0 ifTrue:
  		[^self initStackPagesAndInterpret].
+ 
+ 	"An unchecked write is probably faster, so instead of
+ 	 CReturnAddress ifNil:
+ 		[CReturnAddress := self cCoerceSimple: self getReturnAddress to: #usqIntptr_t]
+ 	 we have simply"
+ 	self assert: (CReturnAddress isNil or: [CReturnAddress = self getReturnAddress]).
+ 	CReturnAddress := self cCoerceSimple: self getReturnAddress to: #usqIntptr_t.
+ 
- 	CReturnAddress ifNil:
- 		[CReturnAddress := self cCoerceSimple: self getReturnAddress to: #usqIntptr_t].
  	self useCogitBreakBlockIfNone.
  	"record entry time when running as a browser plug-in"
  	self browserPluginInitialiseIfNeeded.
  	self internalizeIPandSP.
  	self initExtensions.
  	self fetchNextBytecode.
  	[true] whileTrue:
  		[self assertValidExecutionPointers.
  		 atEachStepBlock value. "N.B. may be nil"
  		 self dispatchOn: currentBytecode in: BytecodeTable.
  		 self incrementByteCount].
  	localIP := localIP - 1.  "undo the pre-increment of IP before returning"
  	self externalizeIPandSP.
  	^nil
  !

Item was changed:
  ----- Method: StackInterpreterSimulator>>close (in category 'initialization') -----
  close  "close any files that ST may have opened, etc"
  	pluginList do: [:assoc| | plugin | plugin := assoc value. plugin ~~ self ifTrue: [plugin close]].
  	"Ugh; at least some of this code belongs in the UI..."
  	World submorphs do:
  		[:submorph|
  		(submorph model isVMObjectInspector
  		 and: [submorph model coInterpreter == self]) ifTrue:
  			[submorph delete].
  		(submorph model isDebugger
+ 		 and: [(submorph model interruptedProcess suspendedContext ifNotNil:
+ 				[:sctxt|
+ 				 sctxt findContextSuchThat:
- 		 and: [(submorph model interruptedProcess suspendedContext findContextSuchThat:
  					[:ctxt|
  					 ctxt receiver == self
+ 					 and: [ctxt selector == #run]]]) notNil]) ifTrue:
- 					 and: [ctxt selector == #run]]) notNil]) ifTrue:
  			[submorph model windowIsClosing.
  			 submorph delete]]!



More information about the Vm-dev mailing list