[Vm-dev] Finding pointers via heap walking and contexts

Igor Stasenko siguctua at gmail.com
Thu Aug 29 17:40:27 UTC 2013


On 29 August 2013 18:34, Eliot Miranda <eliot.miranda at gmail.com> wrote:

>
>
>
>
> On Thu, Aug 29, 2013 at 8:54 AM, Igor Stasenko <siguctua at gmail.com> wrote:
>
>>
>> Hello,
>>
>> i tried to implement a simple algorithm to find nearest common roots for
>> some object(s)..
>> see the attached code.
>>
>> The problem i discovered that the last assertion of my test fails:
>> =====
>> testArrayShouldBeRootOfItsElements
>>
>>     | obj1 obj2 array arrayToTest roots |
>>
>>     obj1 := 'ObjectA' copy.
>>     obj2 := 'ObjectB' copy.
>>
>>     array := {  obj1. obj2 }.
>>     arrayToTest := { obj1. obj2 }.
>>
>>     roots := CommonRootsFinder new findCommonRootsOf:  arrayToTest.
>>
>>     self assert: (roots identityIncludes: array).
>>     self assert: (roots identityIncludes: arrayToTest) not.
>>     self assert: (roots identityIncludes: thisContext).  "- sometimes
>> works , sometimes not "
>> ========
>>
>> but, when i restart the method in debugger and step down through it,
>> assertion DOES NOT fails.
>> This means that memory scan does not reveals this context as it should be.
>>
>> (maybe because it stops at the object which located before location of
>> thisContext)?
>>
>
> That would make sense.  For debugging, why don't you record the objects
> visited in an OrderedCollection, and then you can look at what order the
> pointer finder found them.
>
>

well, if you look at algorithm:

    pointers := IdentitySet new.
    object := self someObject.
    [ object == pointers ] whileFalse: [
        1 to: objects size do: [ :i | ((object pointsTo: (objects at: i))
and: [ (object pointsOnlyWeaklyTo: (objects at: i)) not]) ifTrue: [
pointers add: object ]  ].
        object := object nextObject ].

since the 'pointers' is the last object created on heap, and the subject
context
must exist before entering this method, it should eventually find it..
but as it appears it doesn't..

what i thinking, that maybe i should change the stop condition to
[ object == 0 ]
(which primitive returns when there is no more object on heap),
like that i can be sure that i will visit every heap-allocated object..
But that is tricky because then loop may never stop if there is new
object(s) created (like in #add: ) in loop body..   :(




>> any suggestions/comments/ideas , how to make sure that assert will never
>> fail?
>>
>
> Doesn't that depend on how you've implemented CommonRootsFinder?
>
>
>> --
>> Best regards,
>> Igor Stasenko.
>>
>>
>
>
> --
> best,
> Eliot
>
>


-- 
Best regards,
Igor Stasenko.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20130829/c0404708/attachment-0001.htm


More information about the Vm-dev mailing list