Continuations in Java

前端 未结 11 1984
再見小時候
再見小時候 2020-12-05 00:20

Is there a good implementation of continuations in Java?

If so, what is the overhead like? The JVM wasn\'t designed with these sort of things in mind, right? So is t

11条回答
  •  情话喂你
    2020-12-05 01:05

    If I understand this correctly, I suppose the obvious problem involves unwinding the stack with closure instances active. I suppose a language with lexical scope could in theory figure out that a child frame may create a closure instance, identify those intermediate frames that are referenced, and then it could malloc those frames instead of just pushing them on the stack.

    For that matter, a compiler could malloc all frames or all parent frames of a closure referencing a non-globally-bound object.

    Summary

    I don't think the JVM restricts closures any more than a real machine, it's just that they fight the general stack paradigm and so they usually get punted.

提交回复
热议问题