Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.586.mcz ==================== Summary ==================== Name: Collections-ul.586 Author: ul Time: 27 October 2014, 12:52:51.886 am UUID: 4c460675-3065-4b48-aa30-52ad67e15076 Ancestors: Collections-cmm.585 Symbol table changes: - ensure that enumerations stay consistent - avoid read-write and write-write race conditions - added a safe #condenseNewSymbols method, which is a replacement for former unsafe methods (#shutDown: and #compactSymbolTable). It's also automatically triggered whenever there are more than 1000 NewSymbols. - deprecated #compactSymbolTable - updated some comments Note that interning many symbols is a bit slower, but thread safety is more important. =============== Diff against Collections-cmm.585 =============== Item was changed: ----- Method: Symbol class>>allSymbolTablesDo: (in category 'class initialization') ----- allSymbolTablesDo: aBlock + + | originalNewSymbols originalSymbolTable | + originalNewSymbols := NewSymbols. + originalSymbolTable := SymbolTable. + originalNewSymbols do: aBlock. + originalSymbolTable do: aBlock.! - - NewSymbols do: aBlock. - SymbolTable do: aBlock.! Item was changed: ----- Method: Symbol class>>allSymbolTablesDo:after: (in category 'class initialization') ----- allSymbolTablesDo: aBlock after: aSymbol + | originalNewSymbols originalSymbolTable | + originalNewSymbols := NewSymbols. + originalSymbolTable := SymbolTable. + (originalNewSymbols includes: aSymbol) - (NewSymbols includes: aSymbol) ifTrue: [ + originalNewSymbols do: aBlock after: aSymbol. + originalSymbolTable do: aBlock after: aSymbol ] - NewSymbols do: aBlock after: aSymbol. - SymbolTable do: aBlock after: aSymbol ] ifFalse: [ + originalSymbolTable do: aBlock after: aSymbol. + originalNewSymbols do: aBlock after: aSymbol ] - SymbolTable do: aBlock after: aSymbol. - NewSymbols do: aBlock after: aSymbol ] ! Item was changed: ----- Method: Symbol class>>allSymbols (in category 'access') ----- allSymbols "Answer all interned symbols" + | originalNewSymbols originalSymbolTable | + originalNewSymbols := NewSymbols. + originalSymbolTable := SymbolTable. ^Array + new: originalNewSymbols slowSize + originalSymbolTable slowSize - new: NewSymbols slowSize + SymbolTable slowSize streamContents:[ :stream | stream + nextPutAll: originalNewSymbols; + nextPutAll: originalSymbolTable ] - nextPutAll: NewSymbols; - nextPutAll: SymbolTable ] ! Item was changed: ----- Method: Symbol class>>cleanUp (in category 'class initialization') ----- cleanUp "Flush caches" + self condenseNewSymbols! - self compactSymbolTable.! Item was changed: ----- Method: Symbol class>>compactSymbolTable (in category 'class initialization') ----- compactSymbolTable "Reduce the size of the symbol table so that it holds all existing symbols with 25% free space." + self deprecated: 'Use #condenseNewSymbols instead'. + self condenseNewSymbols! - | oldSize | - Smalltalk garbageCollect. - oldSize := SymbolTable capacity. - SymbolTable compact. - ^(oldSize - SymbolTable capacity) printString, ' slot(s) reclaimed'! Item was added: + ----- Method: Symbol class>>condenseNewSymbols (in category 'private') ----- + condenseNewSymbols + "Move all symbols from NewSymbols to SymbolTable, and compact SymbolTable." + + | originalNewSymbols originalSymbolTable newNewSymbols newSymbolTable | + originalNewSymbols := NewSymbols. + originalSymbolTable := SymbolTable. + newNewSymbols := WeakSet new. + newSymbolTable := originalSymbolTable copy + addAll: originalNewSymbols; + compact; + yourself. + originalNewSymbols == NewSymbols ifFalse: [ + "Some other process has modified the symbols. Try again." + ^self condenseNewSymbols ]. + NewSymbols := newNewSymbols. + SymbolTable := newSymbolTable! Item was changed: ----- Method: Symbol class>>intern: (in category 'instance creation') ----- intern: aStringOrSymbol + | originalNewSymbols | + originalNewSymbols := NewSymbols. ^(self lookup: aStringOrSymbol) ifNil:[ + | aClass aSymbol newNewSymbols | - | aClass aSymbol | aStringOrSymbol isSymbol ifTrue:[ aSymbol := aStringOrSymbol. ] ifFalse:[ aClass := aStringOrSymbol isOctetString ifTrue:[ByteSymbol] ifFalse:[WideSymbol]. aSymbol := aClass new: aStringOrSymbol size. aSymbol string: aStringOrSymbol. ]. + newNewSymbols := originalNewSymbols copyWith: aSymbol. + originalNewSymbols == NewSymbols + ifTrue: [ + NewSymbols := newNewSymbols. + newNewSymbols size > 1000 ifTrue: [ self condenseNewSymbols ]. + aSymbol ] + ifFalse: [ + "Some other process has modified the symbols. Try again." + self intern: aStringOrSymbol ] ]! - NewSymbols add: aSymbol. - aSymbol].! Item was changed: ----- Method: Symbol class>>lookup: (in category 'instance creation') ----- lookup: aStringOrSymbol + | originalNewSymbols originalSymbolTable | + originalNewSymbols := NewSymbols. + originalSymbolTable := SymbolTable. + ^(originalNewSymbols like: aStringOrSymbol) ifNil: [ + originalSymbolTable like: aStringOrSymbol ]! - ^(SymbolTable like: aStringOrSymbol) ifNil: [ - NewSymbols like: aStringOrSymbol - ]! Item was changed: ----- Method: Symbol class>>rehash (in category 'private') ----- + rehash + "Rebuild the hash table, reclaiming unreferenced Symbols. This method will intern all symbols. You're probably looking for #condenseNewSymbols instead." - rehash "Symbol rehash" - "Rebuild the hash table, reclaiming unreferenced Symbols." + | originalNewSymbols originalSymbolTable newNewSymbols newSymbolTable | + originalNewSymbols := NewSymbols. + originalSymbolTable := SymbolTable. + newNewSymbols := WeakSet new. + newSymbolTable := WeakSet withAll: self allSubInstances. + originalNewSymbols == NewSymbols ifFalse: [ + "Some other process has modified the symbols. Try again." + ^self rehash ]. + NewSymbols := newNewSymbols. + SymbolTable := newSymbolTable! - SymbolTable := WeakSet withAll: self allSubInstances. - NewSymbols := WeakSet new.! Item was changed: ----- Method: Symbol class>>shutDown: (in category 'private') ----- shutDown: aboutToQuit + self condenseNewSymbols! - SymbolTable addAll: NewSymbols. - NewSymbols := WeakSet new.! |
Free forum by Nabble | Edit this page |