ForeignLangCallPrimitive sometimes gives an UndefinedStrategyException.
In case of the SDF2 outline, which calls into SDF3, it seems to happen about half of the times.

I thought it had to do with not locking the observer, but adding observer.getLock().lock() etc. to the primitive does not help.

org.spoofax.interpreter.core.UndefinedStrategyException: Definition 'outline-strategy' not found
    at org.spoofax.interpreter.core.Interpreter.invoke(Interpreter.java:79)
    at org.strategoxt.HybridInterpreter.invoke(HybridInterpreter.java:424)
    at org.strategoxt.imp.debug.core.str.launching.DebuggableHybridInterpreter.invoke(DebuggableHybridInterpreter.java:150)
    at org.strategoxt.imp.runtime.stratego.ForeignLangCallPrimitive.call(ForeignLangCallPrimitive.java:67)
    at org.strategoxt.lang.Context.invokePrimitive(Context.java:227)
    at org.strategoxt.lang.Context.invokePrimitive(Context.java:216)
    at trans.foreign_call_0_2.invoke(foreign_call_0_2.java:28)
    at trans.outline_strategy_0_0.invoke(outline_strategy_0_0.java:35)
    at org.strategoxt.lang.Strategy.invokeDynamic(Strategy.java:30)
    at org.strategoxt.lang.InteropSDefT.evaluate(InteropSDefT.java:192)
    at org.strategoxt.lang.InteropSDefT.evaluate(InteropSDefT.java:183)
    at org.strategoxt.lang.InteropSDefT$StrategyBody.evaluate(InteropSDefT.java:245)
    at org.spoofax.interpreter.core.Interpreter.evaluate(Interpreter.java:109)
    at org.spoofax.interpreter.core.Interpreter.invoke(Interpreter.java:82)
    at org.strategoxt.HybridInterpreter.invoke(HybridInterpreter.java:424)
    at org.strategoxt.imp.debug.core.str.launching.DebuggableHybridInterpreter.invoke(DebuggableHybridInterpreter.java:150)
    at org.strategoxt.imp.runtime.Environment$2.invoke(Environment.java:195)
    at org.strategoxt.imp.runtime.services.StrategoObserver.invoke(StrategoObserver.java:704)
    at org.strategoxt.imp.runtime.services.StrategoObserver.invokeSilent(StrategoObserver.java:753)
    at org.strategoxt.imp.runtime.services.StrategoObserver.invokeSilent(StrategoObserver.java:744)
    at org.strategoxt.imp.runtime.services.outline.SpoofaxOutlinePage.update(SpoofaxOutlinePage.java:87)
    at org.strategoxt.imp.runtime.services.outline.SpoofaxOutlinePage.update(SpoofaxOutlinePage.java:72)
    at org.eclipse.imp.editor.ParserScheduler.notifyModelListeners(ParserScheduler.java:136)
    at org.eclipse.imp.editor.ParserScheduler.run(ParserScheduler.java:88)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Submitted by Oskar van Rest on 1 August 2013 at 18:48

On 1 August 2013 at 21:30 Oskar van Rest commented:

Fixed. Thnx Vlad.


On 1 August 2013 at 21:30 Oskar van Rest closed this issue.

On 1 August 2013 at 21:41 Vlad Vergu commented:

I’ll explain what the issue was, for posterity. For every ForeignCall invocation a new StrategoObserver was created. This StrategoObserver was de-initialized explicitly at the end of the every invocation which in turn de-initialized the Hybrid Interpreter it corresponded to, which all seemed pretty normal. The StrategoObserver however maintains a cache of prototypes of HybridInterpreters such that new clones of it can be quickly created without requiring the language classes to be reloaded. The appears to be an issue in the HybridInterpreter such that a de-initialization of a clone of the Hybrid Interpreter causes the original cloned one to also be unloaded. The reason why the issue as reported by Oskar only occurred sometimes (in fact it didn’t occur only sometimes) is because the prototypical interpreters are cached in a WeakWeakMap. When the GC would visit the prototype would disappear causing a new (fully functioning until de-init) interpreter to be created. The rest of the time (in absence of the GC round) the prototype used was broken.

I think this hints to a bug in the HybridInterpreter, opened issue https://yellowgrass.org/issue/StrategoXT/894.

Log in to post comments