Continuations, here I come

Hiroshi Yamauchi yamauchi at google.com
Wed Aug 12 12:43:04 PDT 2009


Hi Attila,

On Sat, Aug 8, 2009 at 12:56 AM, Attila Szegedi<szegedia at gmail.com> wrote:
> The thing is, the semantics of the finally block become application-
> specific when you throw in continuations in the mix. Some finally
> blocks are meant to clean up high-level application state (and thus
> need to only be executed on the very last time). Some finally blocks
> are meant to clean up transient state (i.e. a database connection) and
> should execute every time, plus need some mechanism for
> reestablishment of their state on resume; you yourself mention one
> typical example, which is locking of monitors.
>
> A good continuations mechanism should support both, and add language
> construct for distinguishing between the two. Now, this is not as
> daunting as it might sound. Since - as I said - the nature of the
> finally block becomes application-specific, you can just have an
> application-specific mechanism for checking whether it is a capture or
> the real exit, so you can do:
>
> try {
> ...
> }
> finally {
>    if(isCapturingContinuation()) {
>        ... capturing cleanup (usually unused) ...
>    }
>    else {
>        ... final cleanup ...
>    }
>    ... transient cleanup ...
> }
>
> Those finally blocks that don't have this will be considered to have
> purely transient cleanup, of course. However, a support for
> reinitialization of transient state is naturally required.

You are probably right about that.

It appears that there is currently no obvious support for
reinitialization on resume (aside from monitors, which I argued,
should be handled like transient state above.) So, my thinking was
that finalizers are meant for final cleanup only.

Also, it's not impossible to do the cleanup/reinitialization of
transient state without language support if the app code is written
continuation aware, though it'd be awkward. But if not all the app
code isn't written continuation aware (eg existing legacy code),
finalizers would be written for final cleanup, in which case, running
them more than once would not be a good idea.

Anyhow, it sounds like an interesting question :)

BTW, will the continuation feature be in the planned JDK7?

Thanks,
Hiroshi



More information about the mlvm-dev mailing list