Smalltalk object trampling

Hans-Martin Mosner hmm at heeg.de
Fri Mar 6 16:44:28 UTC 1998


Carl E Gundel wrote:
> 
> Hi everyone!
> 
> I realize this question is not Squeak specific, but I figure this is
> probably the best Smalltalk brain tank around, so I hope you don't mind if
> I ask for a little help.
> 
> I am trying to construct an reproducible example where an object is
> corrupted (via some context switching or recursion perhaps), usually
> causing a protection violation (often revealed at garbage collection).  I
> have seen this in Smalltalk applications in the past, and suspect I am
> seeing the same kind of problem now in our Smalltalk work.
> 
> I need some example code to construct a note to our developers
> illustrating how the problem happens, what to look for, and how to avoid
> the problem.  I'm busting my brain trying to write such an example, but so
> far I've had no luck, so I'm hoping that somebody else has taken the time
> to document their experience in this area.  Does anyone have any
> (hopefully very simple) examples showing how this happens?
> 
> Thanks,
> 
> Carl
> 
One very easy way is to (ab)use the #become: operation.
When you do a "self become: anotherObject" and access an inst var later
which does not have a corresponding slot in the other object, you're
likely
getting into trouble. I've got bitten by this once in a database
framework
where objects were replaced by proxies after being committed to the
database.
Here's some code that has worked for me :-)
Try to inspect the result of (3 at 4) gack for some fun.
It does not always work on the first try, but should work sooner or
later.
The example is done with VisualWorks, but Squeak should show
similar symptoms (probably when you access x instead of y).

Hans-Martin

!Point methodsFor: 'private'!

gack
	"Try to produce an object memory corruption via #become:"
	"(3 at 4) gack"
	self gargle.
	^y!

gargle
	| t1 t2 |
	t1 := Object new.
	t2 := String new: 4.
	self become: t1.
	^t2! !

-- 
+--- Hans-Martin Mosner ---- Senior Smalltalk Guru :-) ---+
| These opinions are entirely ficticious.  Any similarity |
| to real opinions is purely coincidental and unintended. |
+--- <hmm at heeg.de> ------ URL:http://www.heeg.de/~hmm/ ---+





More information about the Squeak-dev mailing list