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

commits at source.squeak.org commits at source.squeak.org
Sun Sep 8 00:05:23 UTC 2013


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

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

Name: Cog-eem.78
Author: eem
Time: 7 September 2013, 5:05:10.843 pm
UUID: c76f476f-a48b-479a-aed5-10ba74bf8cf0
Ancestors: Cog-eem.77

Finish installation of replacement methods.
Modifying Character methods that access value is next (and last!).

=============== Diff against Cog-eem.77 ===============

Item was changed:
  Object subclass: #SpurBootstrap
+ 	instanceVariableNames: 'oldHeap newHeap map reverseMap classToIndex oldInterpreter lastClassTablePage symbolMap methodClasses installedPrototypes'
- 	instanceVariableNames: 'oldHeap newHeap map reverseMap classToIndex oldInterpreter lastClassTablePage symbolMap methodClasses'
  	classVariableNames: ''
  	poolDictionaries: 'VMObjectIndices'
  	category: 'Cog-Bootstrapping'!
  
  !SpurBootstrap commentStamp: 'eem 9/7/2013 13:23' prior: 0!
  SpurBootstrap bootstraps an image in SpurMemoryManager format from a Squeak V3 + closures format.
  
  e.g.
  	(SpurBootstrap32 new on: '/Users/eliot/Cog/startreader.image')
  		transform;
  		launch
  
  Instance Variables
  	classToIndex:			<Dictionary>
  	lastClassTablePage:	<Integer>
  	map:					<Dictionary>
  	methodClasses:		<Set>
  	newHeap:				<SpurMemoryManager>
  	oldHeap:				<NewObjectMemory>
  	oldInterpreter:			<StackInterpreterSimulator>
  	reverseMap:			<Dictionary>
  	symbolMap:				<Dictionary>
  
  classToIndex
  	- oldClass to new classIndex map
  
  lastClassTablePage
  	- oop in newHeap of last classTable page.  U<sed in validation to filter-out class table.
  
  methodClasses
  	- cache of methodClassAssociations for classes in which modified methods are installed
  
  map
  	- oldObject to newObject map
  
  newHeap
  	- the output, bootstrapped image
  
  oldHeap
  	- the input, image
  
  oldInterpreter
  	- the interpreter associated with oldHeap, needed for a hack to grab WeakArray
  
  reverseMap
  	- newObject to oldObject map
  
  symbolMap
  	- symbol toi symbol oop in oldHeap, used to map prototype methdos to methods in oldHeap!

Item was changed:
  ----- Method: SpurBootstrap>>addNewMethods (in category 'bootstrap methods') -----
  addNewMethods
  	"Get the simulator to add any and all missing methods immediately."
  	| cmaiaSym basSym |
  	cmaiaSym := self findSymbol: #compiledMethodAt:ifAbsent:.
  	basSym := self findSymbol: #basicAddSelector:withMethod:.
  	basSym ifNil:
  		[basSym := self findSymbol: #addSelectorSilently:withMethod:].
  	self allPrototypeClassNamesDo:
  		[:sym :symIsMeta| | class |
  		class := self findClassNamed: (symbolMap at: sym).
  		symIsMeta ifTrue: [class := oldHeap fetchClassOfNonImm: class].
  		self prototypeClassNameMetaSelectorMethodDo:
  			[:className :isMeta :selector :method| | methodOrNil |
  			(className = sym
  			 and: [symIsMeta = isMeta]) ifTrue:
  				["probe method dictionary of the class for each method, installing a dummy if not found."
  				Transcript cr; nextPutAll: 'checking for '; nextPutAll: selector; flush.
  				 methodOrNil := self interpreterObject: class
  									perform: cmaiaSym
  									withArguments: {symbolMap at: selector. oldHeap nilObject}.
  				 methodOrNil = oldHeap nilObject
  					ifTrue: "no method.  install the real thing now"
  						[Transcript
  							cr;
  							nextPutAll: 'installing ';
  							nextPutAll: className;
  							nextPutAll: (isMeta ifTrue: [' class>>'] ifFalse: ['>>']);
  							store: selector; flush.
  						 self interpreterObject: class
  							perform: basSym
  							withArguments: { symbolMap at: selector.
  											   self installableMethodFor: method
  												selector: selector
  												className: className
+ 												isMeta: isMeta}.
+ 						installedPrototypes add: method selector]
- 												isMeta: isMeta}]
  					ifFalse: "existing method; collect the methodClassAssociation; its needed later"
  						[methodClasses add: (oldInterpreter methodClassAssociationOf: methodOrNil)]]]]!

Item was added:
+ ----- Method: SpurBootstrap>>indexOfSelector:in: (in category 'bootstrap methods') -----
+ indexOfSelector: selectorOop in: methodDict
+ 	SelectorStart to: (oldHeap fetchWordLengthOf: methodDict) - 1 do:
+ 		[:i|
+ 		(oldHeap fetchPointer: i ofObject: methodDict) = selectorOop ifTrue:
+ 			[^i]].
+ 	self error: 'could not find selector in method dict'!

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."
  	symbolMap := Dictionary new.
  	methodClasses := Set new.
+ 	installedPrototypes := Set new.
  	self withExecutableInterpreterDo:
  		[self internAllSymbols.
  		 self addNewMethods.
  		 self replaceMethods].
  	self modifyCharacterMethods!

Item was added:
+ ----- Method: SpurBootstrap>>modifyCharacterMethods (in category 'bootstrap methods') -----
+ modifyCharacterMethods
+ 	self shouldBeImplemented!

Item was added:
+ ----- Method: SpurBootstrap>>replaceMethods (in category 'bootstrap methods') -----
+ replaceMethods
+ 	"Replace all the modified method prototypes."
+ 	self allPrototypeClassNamesDo:
+ 		[:sym :symIsMeta| | class |
+ 		class := self findClassNamed: (symbolMap at: sym).
+ 		symIsMeta ifTrue: [class := oldHeap fetchClassOfNonImm: class].
+ 		self prototypeClassNameMetaSelectorMethodDo:
+ 			[:className :isMeta :selector :method| | replacement methodDict index |
+ 			(className = sym
+ 			 and: [symIsMeta = isMeta]) ifTrue:
+ 				[(installedPrototypes includes: method selector) ifFalse:
+ 					["probe method dictionary of the class for each method, installing a dummy if not found."
+ 					Transcript cr; nextPutAll: 'replacing '; nextPutAll: selector; flush.
+ 					replacement := self installableMethodFor: method
+ 										selector: selector
+ 										className: className
+ 										isMeta: isMeta.
+ 					methodDict := oldHeap fetchPointer: MethodDictionaryIndex ofObject: class.
+ 					index := self indexOfSelector: (symbolMap at: selector) in: methodDict.
+ 					oldHeap
+ 						storePointer: index - SelectorStart
+ 						ofObject: (oldHeap fetchPointer: MethodArrayIndex ofObject: methodDict)
+ 						withValue: replacement.
+ 					installedPrototypes add: method selector]]]]!



More information about the Vm-dev mailing list