Ephemeron bug

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
22 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Ephemeron bug

Javier Burroni
Frank,
EphemeronWRescueMemory class is a very silly Ephemeron's subclass.
EphemeronWRescueMemory>>#rescue
   rescued := true
EphemeronWRescueMemory>>#hasBeenRescued
        ^rescued

I've used the methodDictionaryArray message because I wanted to send
something to the key of the toBeRescued's value. I had badly chosen
the message. If I send #isString, the result will the same.

I'm quite sure that the bug is as I've described before. If you have
any other idea for this thesis to be test, will be more than welcome .
Regards
jb

On Wed, May 4, 2011 at 6:59 AM, Frank Lesser
<[hidden email]> wrote:

> Javier,
> Re-reading your posting I guess you get a crash not because the Ephemerons
> are broken in the way you test - maybe because you set the
> methodDictionaryArray of the EphemeronWRescueMemory key to nil to detect
> whether it is rescued. Setting the mda of any Object to nil should crash the
> VSE-VM:
>
> | a | a := Object new. a methodDictionaryArray: nil. a class
>
> Frank
>
> -----Ursprüngliche Nachricht-----
> Von: Using Visual Smalltalk for Windows/Enterprise
> [mailto:[hidden email]] Im Auftrag von Javier Burroni
> Gesendet: Dienstag, 26. April 2011 18:39
> An: [hidden email]
> Betreff: Ephemeron bug
>
> Consider the following code:
>
> testNestedEphemeronsWEphemeronKey
>   | toBeRescued |
>   toBeRescued := EphemeronWRescueMemory
>       key: Object new
>       value: (EphemeronWRescueMemory key: Object new).
>   Smalltalk unusedMemory.
>   Ephemeron processRescuedEphemerons.
>   Smalltalk unusedMemory.
>   self
>       assert: toBeRescued hasBeenRescued;
>       deny: toBeRescued value key methodDictionaryArray isNil;
>       assert: toBeRescued value hasBeenRescued
>
> Where EphemeronWRescueMemory is an Ephemeron's subclass which can
> answer if it has been already rescued.
> This code will break smalltalk.
> The reason for this test to fail, is the existence of an ephemeron (B)
> as other ephemeron's value (A).
> Following Hayes, whenever ephemeron A rescued, it should be traced as
> any other object -loosing the idea of ephemerons, neither in a direct
> or indirect way-.
> However, the apparent behavior when following object A and finding
> ephemerons, is to mark and queue the just found ephemeron -B in this
> case-; but never trace the ephemeron -B-. This makes B's reference to
> be out of date, and (potentially) point to non valid objects.
> In Hayes code:
>
> Heap::markPhase3
>   EphemeronQueue enumerate:[:ephemeron|
>           ephemeron deref signal: almostCollectable.
>           ephemeron deref keyField tracePointerQueueingEphemerons.
>           ephemeron deref valueField tracePointerQueueingEphemerons].
>
> When the correct code should be:
> Heap::markPhase3
>   EphemeronQueue enumerate:[:ephemeron|
>           ephemeron deref signal: almostCollectable.
>           ephemeron deref keyField tracePointer.
>           ephemeron deref valueField tracePointer].
>
> There are an interesting point regarding Hayes work: the first time a
> GC is run, the ephemeron B will be handle as a non-ephemeron ("Mark
> all of the objects reachable from this pointer, paying no attention to
> ephemerons" p. 183 [1]).
> With a small modification, the algorithm may be able to handle object
> B as an ephemeron in the first run. To do so, we have to focus on the
> fundamental idea of ephemerons: the topological relation between
> objects and the ephemeron's key/value. The relation between objects
> and the ephemeron itself shall be of no importance.
>
> So, suppose we have this:
> VMGarbageCollector>>#rescueEphemerons
>   | unknowns rescan rescued |
>   rescued := rescan := false.
>   unknowns := ephemeronsStack.
>   [ephemerons isEmpty] whileFalse: [
>       rescan := self followEphemeronsCollectingIn: unknowns.
>       rescan ifTrue: [ephemerons addAll: unknowns] ifFalse: [
>           unknowns do: [:ephemeron |
>               self rescueEphemeron: ephemeron.
>               rescued := true]].
>       unknowns reset].
>   rescued ifTrue: [self someEphemeronsRescued]
>
>
> VMGarbageCollector>>#followEphemeronsCollectingIn: unknowns
>   | rescan |
>   rescan := false.
>   [ephemerons isEmpty] whileFalse: [| ephemeron |
>       ephemeron := ephemerons pop.
>       ephemeron == nil ifFalse: [
>           (self checkReachablePropertyOf: ephemeron)
>               ifTrue: [
>                   self follow: ephemeron count: ephemeron
> _extendedSize startingAt: 1.
>                   rescan := true]
>               ifFalse: [unknowns add: ephemeron]]].
>   ^rescan
>
> VMGarbageCollector>>#rescueEphemeron: ephemeron
>   ephemeron _haveNoWeaks
>   self follow: ephemeron count: ephemeron _extendedSize startingAt: 1.
>   rescuedEphemerons add: ephemeron
>
> This implementation may fail to detect object as 'almost collectable',
> whenever a rescued ephemeron refers to an object, when this object is
> the key of a non yet seen ephemeron. But the set of correctly rescued
> ephemerons is big than the Hayes set (which is a subset)
>
> /jb
>
> [1]: Hayes, B. 1997. Ephemerons: a new finalization mechanism.
> Proceedings of the 12th ACM SIGPLAN conference on Object-oriented
> programming, systems, languages, and applications.
> http://portal.acm.org/citation.cfm?id=263733
>
> --
> " To be is to do " ( Socrates )
> " To be or not to be " ( Shakespeare )
> " To do is to be " ( Sartre )
> " Do be do be do " ( Sinatra )
>
> ***           this signature added by listserv             ***
> *** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
> *** for archive browsing and VSWE-L membership management  ***
>
> ***           this signature added by listserv             ***
> *** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
> *** for archive browsing and VSWE-L membership management  ***
>



--
" To be is to do " ( Socrates )
" To be or not to be " ( Shakespeare )
" To do is to be " ( Sartre )
" Do be do be do " ( Sinatra )

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***
Reply | Threaded
Open this post in threaded view
|

Re: Ephemeron bug

frank.lesser
Javier,
You are right - I have simplified your test a little & it still produces a
crash in an old Digitalk VM:

testNestedEphemerons
   | toBeRescued |
   toBeRescued := Ephemeron
       key: Object new
       value: (Ephemeron key: Object new).
   Smalltalk unusedMemory.
   Smalltalk unusedMemory.
   toBeRescued value key isNil

But there are much more bugs around finalization - better to use explicit
release of External memory to stabilize your application. I run into those
issues trying to transport a customer's application to 64 Bit...

Frank



-----Ursprüngliche Nachricht-----
Von: Using Visual Smalltalk for Windows/Enterprise
[mailto:[hidden email]] Im Auftrag von Javier Burroni
Gesendet: Mittwoch, 4. Mai 2011 14:40
An: [hidden email]
Betreff: ** SPAM ** Re: Ephemeron bug

Frank,
EphemeronWRescueMemory class is a very silly Ephemeron's subclass.
EphemeronWRescueMemory>>#rescue
   rescued := true
EphemeronWRescueMemory>>#hasBeenRescued
        ^rescued

I've used the methodDictionaryArray message because I wanted to send
something to the key of the toBeRescued's value. I had badly chosen
the message. If I send #isString, the result will the same.

I'm quite sure that the bug is as I've described before. If you have
any other idea for this thesis to be test, will be more than welcome .
Regards
jb

On Wed, May 4, 2011 at 6:59 AM, Frank Lesser
<[hidden email]> wrote:
> Javier,
> Re-reading your posting I guess you get a crash not because the Ephemerons
> are broken in the way you test - maybe because you set the
> methodDictionaryArray of the EphemeronWRescueMemory key to nil to detect
> whether it is rescued. Setting the mda of any Object to nil should crash
the

> VSE-VM:
>
> | a | a := Object new. a methodDictionaryArray: nil. a class
>
> Frank
>
> -----Ursprüngliche Nachricht-----
> Von: Using Visual Smalltalk for Windows/Enterprise
> [mailto:[hidden email]] Im Auftrag von Javier Burroni
> Gesendet: Dienstag, 26. April 2011 18:39
> An: [hidden email]
> Betreff: Ephemeron bug
>
> Consider the following code:
>
> testNestedEphemeronsWEphemeronKey
>   | toBeRescued |
>   toBeRescued := EphemeronWRescueMemory
>       key: Object new
>       value: (EphemeronWRescueMemory key: Object new).
>   Smalltalk unusedMemory.
>   Ephemeron processRescuedEphemerons.
>   Smalltalk unusedMemory.
>   self
>       assert: toBeRescued hasBeenRescued;
>       deny: toBeRescued value key methodDictionaryArray isNil;
>       assert: toBeRescued value hasBeenRescued
>
> Where EphemeronWRescueMemory is an Ephemeron's subclass which can
> answer if it has been already rescued.
> This code will break smalltalk.
> The reason for this test to fail, is the existence of an ephemeron (B)
> as other ephemeron's value (A).
> Following Hayes, whenever ephemeron A rescued, it should be traced as
> any other object -loosing the idea of ephemerons, neither in a direct
> or indirect way-.
> However, the apparent behavior when following object A and finding
> ephemerons, is to mark and queue the just found ephemeron -B in this
> case-; but never trace the ephemeron -B-. This makes B's reference to
> be out of date, and (potentially) point to non valid objects.
> In Hayes code:
>
> Heap::markPhase3
>   EphemeronQueue enumerate:[:ephemeron|
>           ephemeron deref signal: almostCollectable.
>           ephemeron deref keyField tracePointerQueueingEphemerons.
>           ephemeron deref valueField tracePointerQueueingEphemerons].
>
> When the correct code should be:
> Heap::markPhase3
>   EphemeronQueue enumerate:[:ephemeron|
>           ephemeron deref signal: almostCollectable.
>           ephemeron deref keyField tracePointer.
>           ephemeron deref valueField tracePointer].
>
> There are an interesting point regarding Hayes work: the first time a
> GC is run, the ephemeron B will be handle as a non-ephemeron ("Mark
> all of the objects reachable from this pointer, paying no attention to
> ephemerons" p. 183 [1]).
> With a small modification, the algorithm may be able to handle object
> B as an ephemeron in the first run. To do so, we have to focus on the
> fundamental idea of ephemerons: the topological relation between
> objects and the ephemeron's key/value. The relation between objects
> and the ephemeron itself shall be of no importance.
>
> So, suppose we have this:
> VMGarbageCollector>>#rescueEphemerons
>   | unknowns rescan rescued |
>   rescued := rescan := false.
>   unknowns := ephemeronsStack.
>   [ephemerons isEmpty] whileFalse: [
>       rescan := self followEphemeronsCollectingIn: unknowns.
>       rescan ifTrue: [ephemerons addAll: unknowns] ifFalse: [
>           unknowns do: [:ephemeron |
>               self rescueEphemeron: ephemeron.
>               rescued := true]].
>       unknowns reset].
>   rescued ifTrue: [self someEphemeronsRescued]
>
>
> VMGarbageCollector>>#followEphemeronsCollectingIn: unknowns
>   | rescan |
>   rescan := false.
>   [ephemerons isEmpty] whileFalse: [| ephemeron |
>       ephemeron := ephemerons pop.
>       ephemeron == nil ifFalse: [
>           (self checkReachablePropertyOf: ephemeron)
>               ifTrue: [
>                   self follow: ephemeron count: ephemeron
> _extendedSize startingAt: 1.
>                   rescan := true]
>               ifFalse: [unknowns add: ephemeron]]].
>   ^rescan
>
> VMGarbageCollector>>#rescueEphemeron: ephemeron
>   ephemeron _haveNoWeaks
>   self follow: ephemeron count: ephemeron _extendedSize startingAt: 1.
>   rescuedEphemerons add: ephemeron
>
> This implementation may fail to detect object as 'almost collectable',
> whenever a rescued ephemeron refers to an object, when this object is
> the key of a non yet seen ephemeron. But the set of correctly rescued
> ephemerons is big than the Hayes set (which is a subset)
>
> /jb
>
> [1]: Hayes, B. 1997. Ephemerons: a new finalization mechanism.
> Proceedings of the 12th ACM SIGPLAN conference on Object-oriented
> programming, systems, languages, and applications.
> http://portal.acm.org/citation.cfm?id=263733
>
> --
> " To be is to do " ( Socrates )
> " To be or not to be " ( Shakespeare )
> " To do is to be " ( Sartre )
> " Do be do be do " ( Sinatra )
>
> ***           this signature added by listserv             ***
> *** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
> *** for archive browsing and VSWE-L membership management  ***
>
> ***           this signature added by listserv             ***
> *** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
> *** for archive browsing and VSWE-L membership management  ***
>



--
" To be is to do " ( Socrates )
" To be or not to be " ( Shakespeare )
" To do is to be " ( Sartre )
" Do be do be do " ( Sinatra )

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***
12