StackContinuations

Skip to end of metadata
Go to start of metadata

Patch name: continuation.patch

Background

This experimental implementation of continuation is an extension to the old version of callcc.patch (http://hg.openjdk.java.net/mlvm/mlvm/hotspot/rev/99e6c3830f6d). It is not based on the latest version of callcc.patch.

It

  • implements a delimited continuation
  • supports save/restore of compiled frames
  • supports inter-thread save/restore
  • is currently Linux/x86 and Linux/amd64 only
  • is reasonably stable

This implementation was used in the work described by the JVM Language Summit 2010 talk titled "Continuation In Servers" (http://wiki.jvmlangsummit.com/Continuations_in_Servers) where the continuation feature is applied to increase the scalability of a synchronous I/O-based servers.

API

The current API looks like the following Javadoc style documentation.

sun/misc/Continuation.java

Basic operations

There are the three following methods in the Continuation API.

enter()

It executes a given Runnable. This marks the entry of a scope. In other words, a enter call indicates the bottom of a scope. A scope (of stack frames) is the unit of stack frames that the save method saves and that the resume method resumes. The two methods must be called inside a scope.

save()

Calling this method causes the stack frames in the current scope to be copied off of the current thread into a continuation object. At the same time, the current thread returns out of the scope (the enter call) without returning from the rest of the call chains in the scope.

resume()

Calling this method with a continuation object causes the current thread to abandon the call chains in the current scope and overwrite them with the ones from the saved scope. The current thread then resumes the execution of the saved call chains (scope) as if it is right after the save call at the time the scope was saved. A continuation is resumable only once.

Basic examples

A simple save example

An example of saving a continuation looks like the following:

The above program does not do much. It does not print the string in line 6. It only saves the continuation.

A simple resume example

An example of resuming a continuation looks like the following:

A simple save-and-resume example

A basic example of saving and resuming a continuation looks like the following:

Advanced examples

See the continuation test files bundled with the patch. Or, go to http://cr.openjdk.java.net/~hiroshi/webrevs/continuation-jdk/.

Limitations

It does not support monitors held or native stack frames inside a continuation scope at the time of a save call (if there is one, an exception will be thrown). It does not currently work with compressed oops in the 64 bit build.

Work in progress
Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Sign up or Log in to add a comment or watch this page.


The individuals who post here are part of the extended Oracle community and they might not be employed or in any way formally affiliated with Oracle. The opinions expressed here are their own, are not necessarily reviewed in advance by anyone but the individual authors, and neither Oracle nor any other party necessarily agrees with them.