'From Squeak4.5 of 12 January 2014 [latest update: #13621] on 12 January 2014 at 7:51:15 pm'! "Change Set: InterpreterPrimitives-primitiveAllObjects-dtl Date: 12 January 2014 Author: David T. Lewis InterpreterPrimitives>>primitiveAllObjects is a primitive that answers an array of all accessible objects"! !InterpreterPrimitives methodsFor: 'object access primitives' stamp: 'dtl 1/12/2014 19:49'! primitiveAllObjects "Answer an array of all objects that exist when the primitive is called, excluding those that may be garbage collected as a side effect of allocating the result array. Multiple references to nil in the last slots of the array are an indication that garbage collection occured, such that some of the unreferenced objects that existed at the time of calling the primitive no longer exist. Sender is responsible for handling multiple references to nil in the result array." | count obj resultArray idx | self pop: argumentCount+1. "Count the currently accessible objects" count := 0. obj := objectMemory firstAccessibleObject. [obj = nil] whileFalse: [count := count + 1. obj := objectMemory accessibleObjectAfter: obj]. resultArray := objectMemory instantiateClass: objectMemory classArray indexableSize: count. "can cause GC" resultArray = nil ifTrue: [^self primitiveFailFor: PrimErrNoMemory]. "Store all objects in result array, filling any remaining slots with nil if garbage collection occurred during allocation of the result array." obj := objectMemory firstAccessibleObject. idx := 1. [count = 0] whileFalse: [count := count - 1. obj = nil ifTrue: [ "garbage collection happened, fill remaining slots with nil" self stObject: resultArray at: idx put: objectMemory nilObject] ifFalse: [self stObject: resultArray at: idx put: obj. obj := objectMemory accessibleObjectAfter: obj]. idx := idx + 1]. self push: resultArray! !