[Vm-dev] VM Maker: Cog-eem.74.mcz

commits at source.squeak.org commits at source.squeak.org
Fri Sep 6 22:40:34 UTC 2013


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

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

Name: Cog-eem.74
Author: eem
Time: 6 September 2013, 3:40:17.104 pm
UUID: 0cc1769d-327b-40b3-80d3-32335718ae96
Ancestors: Cog-eem.73

Refactor the simulated execution of oldInterpreter/oldHeap.

Add addNewMethods to install the missing prototype methods.

=============== Diff against Cog-eem.73 ===============

Item was added:
+ ----- Method: SpurBootstrap class>>CharacterPROTOTYPEasInteger (in category 'method prototypes') -----
+ CharacterPROTOTYPEasInteger
+ 	<primitive: 171>
+ 	^self primitiveFailed!

Item was changed:
  ----- Method: SpurBootstrap class>>ProtoObjectPROTOTYPEscaledIdentityHash (in category 'method prototypes') -----
  ProtoObjectPROTOTYPEscaledIdentityHash
  	"For identityHash values returned by primitive 75, answer
+ 	 such values times 2^8.  Otherwise, match the existing
- 	 such values times 2^18.  Otherwise, match the existing
  	 identityHash implementation"
  
  	^self identityHash * 256 "bitShift: 8"!

Item was added:
+ ----- Method: SpurBootstrap>>addNewMethods (in category 'bootstrap methods') -----
+ addNewMethods
+ 	"Get the simulator to add fake methods for all missing methods so that when we install
+ 	 the prototypes we can assign directly to the method dictionaries since by this time the
+ 	 system could well be inconsistent and broken by the changes."
+ 	| cmaiaSym basSym |
+ 	cmaiaSym := self findSymbol: #compiledMethodAt:ifAbsent:.
+ 	basSym := self findSymbol: #basicAddSelector:withMethod:.
+ 	self allPrototypeClassNames do:
+ 		[:sym| | class |
+ 		class := self findClassNamed: (symbolMap at: sym).
+ 		self prototypeClassNameSelectorMethodDo:
+ 			[:className :selector :method|
+ 			className = sym ifTrue:
+ 				["probe method dictionary of the class for each method, installing a dummy if not found."
+ 				[Transcript cr; nextPutAll: 'checking for '; nextPutAll: selector; flush.
+ 				 (self interpreterObject: class
+ 						perform: cmaiaSym
+ 						withArguments: {symbolMap at: selector. oldHeap nilObject}) = oldHeap nilObject ifTrue:
+ 					["no method.  install the real thing now"
+ 					 self interpreterObject: class
+ 						perform: basSym
+ 						withArguments: {symbolMap at: selector. self installableMethodFor: method}]]]]]!

Item was added:
+ ----- Method: SpurBootstrap>>allPrototypeClassNames (in category 'method prototypes') -----
+ allPrototypeClassNames
+ 	"self basicNew allPrototypeClassNames"
+ 	| symbols |
+ 	symbols := Set new.
+ 	(SpurBootstrap class organization listAtCategoryNamed: #'method prototypes') do:
+ 		[:protoSelector| | method |
+ 		method := SpurBootstrap class >> protoSelector.
+ 		symbols add: (self classNameForPrototypeMethod: method)].
+ 	^symbols!

Item was changed:
  ----- Method: SpurBootstrap>>installModifiedMethods (in category 'bootstrap methods') -----
  installModifiedMethods
  	"Install all the methods in the class-side method prototypes protocol in the relevant classes
  	 in the new image.  First use the simulator to get the image to intern all symbols and add
  	 dummy methods under new selectors.  With that done we can manually replace the relevant
  	 methods with the prototypes, mapping selectors and global variables as required."
+ 	self withExecutableInterpreterDo:
+ 		[self internAllSymbols.
+ 		 self addNewMethods.
+ 		 self replaceMethods].
- 	self internAllSymbols.
- 	self addDummyMethods.
- 	self addInstallMethods.
  	self modifyCharacterMethods!

Item was changed:
  ----- Method: SpurBootstrap>>internAllSymbols (in category 'bootstrap methods') -----
  internAllSymbols
  	"Ensure that all symbols in the method prototypes are interned so that later we can install them.
+ 	 Enter them into the map, this system's symbol -> oldHeap's version.
+ 	 Do this by interpreting Symbol intern: 'aSymbol' for each symbol."
+ 	| internSym |
- 	 Do this by interpreting Symbol intern: 'aSymbol' for each symbol.  Make sure the execution state
- 	 has not advanced when doing so, and restore the image to the state it has on snapshot."
- 	| internSym savedpc initialContext finalContext |
  	symbolMap := Dictionary new.
  	internSym := self findSymbol: #intern:.
- 	oldInterpreter
- 		initStackPages;
- 		loadInitialContext;
- 		internalizeIPandSP.
- 	initialContext := oldInterpreter frameContext: oldInterpreter localFP.
- 	savedpc := oldInterpreter localIP.
- 	"oldInterpreter printHeadFrame."
  	self allPrototypeMethodSymbols do:
+ 		[:sym| | string |
- 		[:sym| | string fp |
  		(self findSymbol: sym)
  			ifNotNil: [:imageSym| symbolMap at: sym put: imageSym]
  			ifNil:
  				[Transcript cr; nextPutAll: 'interning '; nextPutAll: sym; flush.
  				string := oldHeap instantiateClass: (oldHeap splObj: ClassByteString) indexableSize: sym size.
  				1 to: sym size do:
  					[:i| oldHeap storeByte: i - 1 ofObject: string withValue: (sym at: i) asInteger].
  				"Interpret Symbol intern: sym to ... intern it :-)"
+ 				symbolMap
+ 					at: sym
+ 					put: (self interpreterObject: self symbolClass
+ 							perform: internSym
+ 							withArguments: {string})]].
- 				oldInterpreter
- 					internalPush: self symbolClass;
- 					internalPush: string;
- 					argumentCount: 1;
- 					messageSelector: internSym.
- 				fp := oldInterpreter localFP.
- 				oldInterpreter normalSend.
- 				[fp = oldInterpreter localFP] whileFalse:
- 					[oldInterpreter singleStep].
- 				symbolMap at: sym put: oldInterpreter internalPopStack.
- 				self assert: oldInterpreter localIP - 1 = savedpc.
- 				oldInterpreter localIP: savedpc]].
  	symbolMap keysAndValuesDo:
  		[:sym :imageSym|
+ 		self assert: sym = (oldHeap stringOf: imageSym)]!
- 		self assert: sym = (oldHeap stringOf: imageSym)].
- 	"oldInterpreter printHeadFrame."
- 	oldInterpreter
- 		internalPush: oldInterpreter localIP;
- 		externalizeIPandSP.
- 	"now undo the execution state"
- 	finalContext := oldInterpreter voidVMStateForSnapshot.
- 	self assert: initialContext = finalContext.
- 	self assert: oldInterpreter localIP = savedpc!

Item was added:
+ ----- Method: SpurBootstrap>>interpreterObject:perform:withArguments: (in category 'bootstrap methods') -----
+ interpreterObject: receiver perform: selector withArguments: arguments
+ 	"Interpret an expression in oldHeap using oldInterpreter.
+ 	 Answer the result."
+ 	| fp savedpc result |
+ 	savedpc := oldInterpreter localIP.
+ 	oldInterpreter internalPush: receiver.
+ 	arguments do: [:arg| oldInterpreter internalPush: arg].
+ 	oldInterpreter
+ 		argumentCount: arguments size;
+ 		messageSelector: selector.
+ 	fp := oldInterpreter localFP.
+ 	oldInterpreter normalSend.
+ 	[fp = oldInterpreter localFP] whileFalse:
+ 		[oldInterpreter singleStep].
+ 	result := oldInterpreter internalPopStack.
+ 	self assert: oldInterpreter localIP - 1 = savedpc.
+ 	oldInterpreter localIP: savedpc.
+ 	^result!

Item was added:
+ ----- Method: SpurBootstrap>>prototypeClassNameSelectorMethodDo: (in category 'method prototypes') -----
+ prototypeClassNameSelectorMethodDo: trinaryBlock
+ 	"Evaluate aBlock with class name, method and selector."
+ 	(SpurBootstrap class organization listAtCategoryNamed: #'method prototypes') do:
+ 		[:protoSelector| | method |
+ 		method := SpurBootstrap class >> protoSelector.
+ 		trinaryBlock
+ 			value: (self classNameForPrototypeMethod: method)
+ 			value: (self selectorForPrototypeMethod: method)
+ 			value: method]!

Item was added:
+ ----- Method: SpurBootstrap>>withExecutableInterpreterDo: (in category 'bootstrap methods') -----
+ withExecutableInterpreterDo: aBlock
+ 	"With the oldInterpreter ready to execute code, evaluate aBlock,
+ 	 then return the interpreter (and the heap) to the ``just snapshotted'' state."
+ 	| savedpc initialContext finalContext |
+ 	oldInterpreter
+ 		initStackPages;
+ 		loadInitialContext;
+ 		internalizeIPandSP.
+ 	initialContext := oldInterpreter frameContext: oldInterpreter localFP.
+ 	savedpc := oldInterpreter localIP.
+ 	"oldInterpreter printHeadFrame."
+ 	aBlock value.
+ 	"oldInterpreter printHeadFrame."
+ 	oldInterpreter
+ 		internalPush: oldInterpreter localIP;
+ 		externalizeIPandSP.
+ 	"now undo the execution state"
+ 	finalContext := oldInterpreter voidVMStateForSnapshot.
+ 	self assert: initialContext = finalContext.
+ 	self assert: oldInterpreter localIP = savedpc!



More information about the Vm-dev mailing list