[squeak-dev] The Trunk: Kernel-ul.625.mcz

commits at source.squeak.org commits at source.squeak.org
Sun Sep 18 13:26:32 UTC 2011


Levente Uzonyi uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-ul.625.mcz

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

Name: Kernel-ul.625
Author: ul
Time: 18 September 2011, 11:54:02.722 am
UUID: 14b3a206-0a64-6049-83f2-fa4a151207cf
Ancestors: Kernel-ul.624

Use #copyFrom: and #becomeForward: instead of #become: during changes of MethodDictionaries. These changes assume that #copyFrom: is atomic (just like #become: and #becomeForward:), so the MethodDictionaries never get into an inconsistent state.
These changes speed up #rehash, #removeAll, #removeKey:ifAbsent and also #compact if the dictionary already has the smallest possible capacity. This means that #rehashAllInstances and #rehashWithoutBecome is not necessary anymore, so those were removed.

=============== Diff against Kernel-ul.624 ===============

Item was removed:
- ----- Method: MethodDictionary class>>rehashAllInstances (in category 'initialization') -----
- rehashAllInstances
- 
- 	| instances newInstances |
- 	instances := self allInstances asArray.
- 	newInstances := self allInstances collect: [ :each |
- 		each rehashWithoutBecome ].
- 	instances elementsExchangeIdentityWith: newInstances!

Item was changed:
  ----- Method: MethodDictionary>>compact (in category 'private') -----
  compact
  	"Make sure that I have the highest possible load factor (at least 50%)."
  	
+ 	| newInstance |
+ 	newInstance := self compactWithoutBecome.
+ 	newInstance capacity = self capacity ifFalse: [
+ 		self becomeForward: newInstance ]!
- 	self become: self compactWithoutBecome!

Item was changed:
  ----- Method: MethodDictionary>>rehash (in category 'private') -----
  rehash 
  	
+ 	| newInstance |
+ 	newInstance := self species new: self basicSize - 1. "Make sure it has the same capacity"
+ 	1 to: self basicSize do: [ :index | 
+ 		(self basicAt: index) ifNotNil: [ :key |
+ 			newInstance at: key put: (array at: index) ] ].
+ 	self copyFrom: newInstance!
- 	self become: self rehashWithoutBecome!

Item was removed:
- ----- Method: MethodDictionary>>rehashWithoutBecome (in category 'private') -----
- rehashWithoutBecome
- 
- 	| newInstance |
- 	newInstance := self species new: self basicSize - 1. "Make sure it has the same capacity"
- 	1 to: self basicSize do: [ :index | 
- 		(self basicAt: index) ifNotNil: [ :key |
- 			newInstance at: key put: (array at: index) ] ].
- 	^newInstance!

Item was changed:
  ----- Method: MethodDictionary>>removeAll (in category 'removing') -----
  removeAll
  	"This provides a faster way than repeated become.
  	a single become is still in use to prevent system crash."
  	
  	| newSelf |
  	tally = 0 ifTrue: [^self].
  	newSelf := self species new: self basicSize - 1.  "This will preserve the capacity"
+ 	self copyFrom: newSelf!
- 	self become: newSelf!

Item was changed:
  ----- Method: MethodDictionary>>removeKey:ifAbsent: (in category 'removing') -----
  removeKey: key ifAbsent: errorBlock 
  	"The interpreter might be using this MethodDict while
  	this method is running!!  Therefore we perform the removal
+ 	in a copy, and then atomically copy that copy"
- 	in a copy, and then atomically become that copy"
  
  	| copy |
  	copy := self copy.
  	copy removeDangerouslyKey: key ifAbsent: [^ errorBlock value].
+ 	self copyFrom: copy!
- 	self become: copy!




More information about the Squeak-dev mailing list