[ 
https://issues.apache.org/jira/browse/GROOVY-11775?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18032185#comment-18032185
 ] 

Björn Kautler commented on GROOVY-11775:
----------------------------------------

{quote}Is the state you want to maintain supposed to be shared between 
instances of B or C (subclass of B)? Or is it just state you want for the 
lifetime of an instance of B or C?
{quote}
No, not shared between instances unless it is static state.
I would have expected state for different instance of B or also C to be 
separate.
This also is the case as each instance of B gets its own mixin instance and 
thus own state.

The problem is, that at some point the state was lost and new state was 
created, probably because a new mixin instance was created, don't see how it 
could have been otherwise.
{quote}as long as your object instance is reachable, the mixin instance will be 
available
{quote}
Ah, sorry, somehow missed that and probably was too tired to remember at 2 AM.
But my last half-sentence of the original description actually discarded that 
assumption as red herring already anyway. :D
{quote}I'm not sure from your description how you are keeping instances of B or 
C.
{quote}
Also here it was about Spock {{Specification}} instances.
Another try to overcome that private method calling restriction in Groovy 5.
In the meantime I also discarded this approach and instead insert static method 
calls instead of using a trait or mixin and that works much better.

{{A}} is / was {{SpecInternals}} with the {{...Impl}} methods.
B is / was {{{}Specification{}}}.
C is / was the actual specifications that are written and executed.

So I'm pretty sure the instances were not softly-reachable but strongly 
referenced.

> Stateful runtime mixins sometimes do not work properly
> ------------------------------------------------------
>
>                 Key: GROOVY-11775
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11775
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 4.0.26
>            Reporter: Björn Kautler
>            Priority: Major
>
> I have class {{A}} and class {{B}}.
> I {{mixin}} {{A}} to {{B}} using {{B.mixin(A)}}.
> {{A}} has a property {{X}}.
> Now I have a method {{M}} in a subclass of {{B}} which first calls a method 
> {{N}} of {{A}}, then another method {{O}} of {{A}}.
> Both calls happen linearly, both happen on the same thread, yet occasionally 
> the call to {{O}} hits a different instance of {{A}} than the call to {{N}} 
> and thus {{N}} and {{O}} work on a different instance of the field in {{A}}.
> From a quick look at the code an debug, the problem might maybe be, that the 
> {{MixinInMetaClass#managedIdentityConcurrentMap}} holds the {{B}} instances 
> that serve as key in soft references. So maybe if the heap gets exhausted 
> between calling {{N}} and {{O}}, the map entry is nuked by the garbage 
> collector and thus the {{O}} call creates a new {{A}} instance.
> If this is the case (or actually whatever else causes what I see), stateful 
> runtime mixins are quite flaky and should not be used unless this is fixed, 
> as you cannot rely on the state. Actually, I was not able to knit an MCVE by 
> intentionally triggering two OOME between the calls to {{N}} and {{O}}, so my 
> suspicion about the cause might not be correct.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to