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

commits at source.squeak.org commits at source.squeak.org
Mon Sep 9 17:43:24 UTC 2013


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

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

Name: Cog-eem.79
Author: eem
Time: 9 September 2013, 10:43:13.075 am
UUID: 82a87cb1-f968-4b79-a578-e7a88a010ec3
Ancestors: Cog-eem.78

Complete the bootstrap, replacing Character methods that access
the value inst var with ones that send self asInteger.

Assumes VMMaker.oscog-eem.355 or later.

=============== Diff against Cog-eem.78 ===============

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."
- 				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.
- 							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]
  					ifFalse: "existing method; collect the methodClassAssociation; its needed later"
  						[methodClasses add: (oldInterpreter methodClassAssociationOf: methodOrNil)]]]]!

Item was changed:
  ----- Method: SpurBootstrap>>bootstrapImage (in category 'bootstrap image') -----
  bootstrapImage
+ 	Transcript cr; nextPutAll: 'transforming image'; flush.
  	self cloneNilTrueAndFalse.
  	self buildClassMap.
  	self allocateClassTable.
  	self cloneObjects.
  	self fillInObjects.
  	self fillInClassTable!

Item was added:
+ ----- Method: SpurBootstrap>>cloneMethodProxy: (in category 'bootstrap methods') -----
+ cloneMethodProxy: proxy "<VMCompiledMethodProxy>"
+ 	| bytes newMethod |
+ 	bytes := proxy size - proxy initialPC + 1.
+ 	newMethod := CompiledMethod
+ 						newMethod: bytes
+ 						header: proxy header.
+ 	false
+ 		ifTrue:
+ 			[1 to: proxy numLiterals - 2 do:
+ 				[:i| | literal |
+ 				literal := (proxy literalAt: i) oop.
+ 				literal := (oldHeap isIntegerObject: literal)
+ 							ifTrue: [oldHeap integerValueOf: literal]
+ 							ifFalse: ['literal', i printString].
+ 				newMethod literalAt: i put: literal].
+ 			newMethod
+ 				literalAt: proxy numLiterals - 1
+ 					put: (oldHeap stringOf: (proxy literalAt: proxy numLiterals - 1) oop) asSymbol;
+ 				literalAt: proxy numLiterals
+ 					put: (Smalltalk bindingOf: #Character)]
+ 		ifFalse:
+ 			[1 to: proxy numLiterals - 1 do:
+ 				[:i| newMethod literalAt: i put: (proxy literalAt: i)].
+ 			newMethod
+ 				literalAt: proxy numLiterals
+ 				put: (Smalltalk bindingOf: #Character)].
+ 	proxy initialPC to: proxy size do:
+ 		[:i| newMethod at: i put: (proxy at: i)].
+ 	^newMethod!

Item was changed:
  ----- Method: SpurBootstrap>>installableMethodFor:selector:className:isMeta: (in category 'bootstrap methods') -----
  installableMethodFor: aCompiledMethod selector: selector className: className isMeta: isMeta
  	| compiledMethodClass sourcelessMethod bytes newMethod methodClass |
  	compiledMethodClass := self findClassNamed: (self findSymbol: #CompiledMethod).
+ 	"the prototypes hve source pointers.  the Character methods to be replaced don't."
+ 	sourcelessMethod := aCompiledMethod trailer hasSourcePointer
+ 							ifTrue: [aCompiledMethod copyWithTempsFromMethodNode: aCompiledMethod methodNode]
+ 							ifFalse: [aCompiledMethod].
- 	sourcelessMethod := aCompiledMethod copyWithTempsFromMethodNode: aCompiledMethod methodNode.
- 	sourcelessMethod selector: selector.
  	bytes := sourcelessMethod size - sourcelessMethod initialPC + 1.
  	newMethod := self
  					interpreterObject: compiledMethodClass
  					perform: (self findSymbol: #newMethod:header:)
  					withArguments: { oldHeap integerObjectOf: bytes.
  									   oldHeap integerObjectOf: sourcelessMethod header }.
  	1 to: sourcelessMethod numLiterals - 1 do:
+ 		[:i| | literal oop |
- 		[:i| | literal |
  		literal := sourcelessMethod literalAt: i.
  		literal isMethodProperties ifTrue:
  			[literal := selector].
+ 		oop := (literal isLiteral or: [literal isVariableBinding])
+ 					ifTrue:
+ 						[literal isInteger
+ 							ifTrue: [oldHeap integerObjectOf: literal]
+ 							ifFalse: [symbolMap at: literal ifAbsent: [self findLiteral: literal]]]
+ 					ifFalse: "should be a VMObjectProxy"
+ 						[literal oop].
+ 		oldHeap storePointer: i ofObject: newMethod withValue: oop].
- 		literal := literal isInteger
- 					ifTrue: [oldHeap integerObjectOf: literal]
- 					ifFalse: [symbolMap at: literal ifAbsent: [self findLiteral: literal]].
- 		oldHeap storePointer: i ofObject: newMethod withValue: literal].
  	methodClass := self methodClassForClassName: className isMeta: isMeta.
  	oldHeap storePointer: sourcelessMethod numLiterals ofObject: newMethod withValue: methodClass.
  	sourcelessMethod initialPC to: sourcelessMethod size do:
  		[:i|
  		oldHeap storeByte: i - 1 ofObject: newMethod withValue: (sourcelessMethod byteAt: i)].
  	^newMethod!

Item was changed:
  ----- Method: SpurBootstrap>>modifyCharacterMethods (in category 'bootstrap methods') -----
  modifyCharacterMethods
+ 	| cc md mda |
+ 	cc := oldHeap classCharacter.
+ 	md := oldHeap fetchPointer: MethodDictionaryIndex ofObject: cc.
+ 	mda := oldHeap fetchPointer: MethodArrayIndex ofObject: md..
+ 	0 to: (oldHeap fetchWordLengthOf: mda) - 1 do:
+ 		[:i| | method |
+ 		method := oldHeap fetchPointer: i ofObject: mda.
+ 		method ~= oldHeap nilObject ifTrue:
+ 			[(self replacementForCharacterMethod: method) ifNotNil:
+ 				[:replacement|
+ 				Transcript
+ 					cr;
+ 					nextPutAll: 'replacing Character>>#';
+ 					nextPutAll: (oldHeap stringOf: (oldHeap fetchPointer: i + SelectorStart ofObject: md));
+ 					flush. 
+ 				oldHeap
+ 					storePointer: i
+ 					ofObject: mda
+ 					withValue: replacement]]]!
- 	self shouldBeImplemented!

Item was changed:
  ----- 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: className;
+ 						nextPutAll: (isMeta ifTrue: [' class>>'] ifFalse: ['>>']);
+ 						store: selector;
+ 						flush.
- 					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]]]]!

Item was added:
+ ----- Method: SpurBootstrap>>replacementForCharacterMethod: (in category 'bootstrap methods') -----
+ replacementForCharacterMethod: characterMethodOop
+ 	"Answer a replacement method for the argument if it refers
+ 	 to Character's old inst var value.  Otherwise answer nil."
+ 	| proxy clone assembly newInsts |
+ 	proxy := VMCompiledMethodProxy new
+ 				for: characterMethodOop
+ 				coInterpreter: oldInterpreter
+ 				objectMemory: oldHeap.
+ 	clone := self cloneMethodProxy: proxy.
+ 	clone dropSourcePointer.
+ 	clone hasInstVarRef ifFalse:
+ 		[^nil].
+ 	assembly := BytecodeDisassembler new disassemble: clone.
+ 	assembly literals: (assembly literals allButLast: 2), {symbolMap at: #asInteger}, (assembly literals last: 2).
+ 		"Do this by looking for index of pushReceiverVariable: and replacing it by pushSelf, send asInteger"
+ 	newInsts := (assembly instructions piecesCutWhere:
+ 					[:msgOrLabelAssoc :nextInst|
+ 					 msgOrLabelAssoc isVariableBinding not
+ 					 and: [msgOrLabelAssoc selector == #pushReceiverVariable:]]) fold:
+ 				[:a :b|
+ 				 a allButLast,
+ 				 {	Message selector: #pushReceiver.
+ 					Message
+ 						selector: #send:super:numArgs:
+ 						arguments: {symbolMap at: #asInteger. false. 0}},
+ 				 b].
+ 	assembly instructions: newInsts.
+ 	^self
+ 		installableMethodFor: assembly assemble
+ 		selector: clone selector
+ 		className: #Character
+ 		isMeta: false!



More information about the Vm-dev mailing list