[squeak-dev] The Trunk: System-mt.1175.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Dec 17 16:10:09 UTC 2020


Marcel Taeumel uploaded a new version of System to project The Trunk:
http://source.squeak.org/trunk/System-mt.1175.mcz

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

Name: System-mt.1175
Author: mt
Time: 29 September 2020, 1:16:45.233157 pm
UUID: f0acc060-a48b-2c4f-8b56-aaf2f55601b4
Ancestors: System-topa.1174

Adds a way to compute a space tally for objects up to a certain depth.

Questions:
- Is the interface (i.e. "depth" and "seen") OK?
- Is the use of IdentitySet OK?
- Can we speed this up somehow?
- Do we need depth-messages for the "class analysis" protocol, too?

=============== Diff against System-topa.1174 ===============

Item was added:
+ ----- Method: SpaceTally>>spaceForInstance:depth: (in category 'instance size') -----
+ spaceForInstance: anObject depth: anInteger
+ 
+ 	^ self spaceForInstance: anObject depth: anInteger seen: IdentitySet new!

Item was added:
+ ----- Method: SpaceTally>>spaceForInstance:depth:seen: (in category 'instance size') -----
+ spaceForInstance: anObject depth: anInteger seen: someObjects
+ 
+ 	| class depth total |
+ 	(someObjects includes: anObject) ifTrue: [^ 0].
+ 	someObjects add: anObject.
+ 	class := anObject class.
+ 	depth := anInteger - 1.
+ 	total := class isVariable
+ 		ifTrue: [class byteSizeOfInstanceOfSize: anObject basicSize]
+ 		ifFalse: [class isImmediateClass ifTrue: [0] ifFalse: [class byteSizeOfInstance]].
+ 	depth >= 0 ifTrue: [
+ 		anObject isCompiledCode
+ 			ifTrue: [
+ 				anObject literalsDo: [:literal |
+ 					total := total + (self spaceForInstance: literal depth: depth seen: someObjects)]]
+ 			ifFalse: [
+ 				1 to: anObject basicSize do: [:index |
+ 					total := total + (self spaceForInstance: (anObject basicAt: index) depth: depth seen: someObjects)].
+ 				1 to: class instSize do: [:index |
+ 					total := total + (self spaceForInstance: (anObject instVarAt: index) depth: depth seen: someObjects)]]].
+ 	^ total!

Item was added:
+ ----- Method: SpaceTally>>spaceForInstancesOf:depth: (in category 'instance size') -----
+ spaceForInstancesOf: aClass depth: aNumber
+ 	"Answer a pair of the number of bytes consumed by all instances of the given class, including their object headers, and the number of instances. Follow each instance's fields up to the given depth. Beware of cycles to shared objects, which will tamper the resulting numbers.
+ 
+ 	SpaceTally new spaceForInstancesOf: Form depth: 0. --- Same as #spaceForInstanecsOf:
+ 	SpaceTally new spaceForInstancesOf: Form depth: 1. --- Includes memory footprint for bits etc.
+ 	SpaceTally new spaceForInstancesOf: Form depth: 2. --- Also includes LargePositiveIntegers in bitmaps ;-)
+ 	"
+ 
+ 	| instances total sub depth |
+ 	instances := aClass allInstances.
+ 	instances isEmpty ifTrue: [^#(0 0)].
+ 	total := 0.
+ 	instances do: [:each | total := total + (self spaceForInstance: each depth: aNumber)].	
+ 	^{ total. instances size }!



More information about the Squeak-dev mailing list