The Trunk: Collections-ul.374.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Collections-ul.374.mcz

commits-2
Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.374.mcz

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

Name: Collections-ul.374
Author: ul
Time: 27 August 2010, 11:46:39.683 pm
UUID: ab565eba-f6e8-8240-8003-d4d62564e08b
Ancestors: Collections-nice.372

- all VMs have finalization support, so there's no need to check for it anymore
- refactored WeakArray class >> #addWeakDependent:

=============== Diff against Collections-nice.372 ===============

Item was changed:
  ----- Method: WeakArray class>>restartFinalizationProcess (in category 'private') -----
  restartFinalizationProcess
  "kill any old process, just in case"
  FinalizationProcess
  ifNotNil: [FinalizationProcess terminate.
  FinalizationProcess := nil].
 
- "Check if Finalization is supported by this VM"
- IsFinalizationSupported := nil.
- self isFinalizationSupported
- ifFalse: [^ self].
-
  FinalizationSemaphore := Smalltalk specialObjectsArray at: 42.
  FinalizationDependents ifNil: [FinalizationDependents := WeakArray new: 10].
  FinalizationLock := Semaphore forMutualExclusion.
  FinalizationProcess := [self finalizationProcess]
  forkAt: Processor userInterruptPriority!

Item was changed:
  ----- Method: WeakArray class>>isFinalizationSupported (in category 'accessing') -----
  isFinalizationSupported
+ "This method is only here for backwards compatibility, all closure VMs support finalization"
+
+ ^true!
- "Check if this VM supports the finalization mechanism"
- | tempObject |
- IsFinalizationSupported ifNotNil:[^IsFinalizationSupported].
- tempObject := WeakArray new: 1.
- "Check if the class format 4 is correctly understood by the VM.
- If the weak class support is not installed then the VM will report
- any weak class as containing 32bit words - not pointers"
- (tempObject at: 1) = nil
- ifFalse:[^IsFinalizationSupported :=false].
- "Check if objects are correctly freed"
- self pvtCreateTemporaryObjectIn: tempObject.
- Smalltalk garbageCollect.
- ^IsFinalizationSupported := (tempObject at: 1) == nil!

Item was changed:
  ----- Method: WeakArray class>>addWeakDependent: (in category 'accessing') -----
  addWeakDependent: anObject
+
+ FinalizationLock
+ critical: [
+ | emptySlotIndex |
+ emptySlotIndex := FinalizationDependents
+ identityIndexOf: nil
+ ifAbsent: [
+ | newIndex |
+ newIndex := FinalizationDependents size + 1.
+ "Grow linearly"
+ FinalizationDependents := FinalizationDependents grownBy: 10.
+ newIndex ].
+ FinalizationDependents at: emptySlotIndex put: anObject ]
+ ifError: [ :msg :rcvr | rcvr error: msg ]!
- self isFinalizationSupported ifFalse:[^self].
- FinalizationLock critical:[
- | finished index weakDependent |
- finished := false.
- index := 0.
- [index := index + 1.
- finished not and:[index <= FinalizationDependents size]] whileTrue:[
- weakDependent := FinalizationDependents at: index.
- weakDependent isNil ifTrue:[
- FinalizationDependents at: index put: anObject.
- finished := true.
- ].
- ].
- finished ifFalse:[
- "Grow linearly"
- FinalizationDependents := FinalizationDependents, (WeakArray new: 10).
- FinalizationDependents at: index put: anObject.
- ].
- ] ifError:[:msg :rcvr| rcvr error: msg].!

Item was changed:
  Array weakSubclass: #WeakArray
  instanceVariableNames: ''
+ classVariableNames: 'FinalizationDependents FinalizationLock FinalizationProcess FinalizationSemaphore'
- classVariableNames: 'FinalizationDependents FinalizationLock FinalizationProcess FinalizationSemaphore IsFinalizationSupported'
  poolDictionaries: ''
  category: 'Collections-Weak'!
 
  !WeakArray commentStamp: '<historical>' prior: 0!
  WeakArray is an array which holds only weakly on its elements. This means whenever an object is only referenced by instances of WeakArray it will be garbage collected.!

Item was changed:
  ----- Method: WeakArray class>>removeWeakDependent: (in category 'accessing') -----
  removeWeakDependent: anObject
+
- self isFinalizationSupported ifFalse:[^self].
  FinalizationLock critical:[
  1 to: FinalizationDependents size do:[:i|
  ((FinalizationDependents at: i) == anObject) ifTrue:[
  FinalizationDependents at: i put: nil.
  ].
  ].
  ] ifError:[:msg :rcvr| rcvr error: msg].!