This patch provides simple stackful, first-class symmetric and asymmetric coroutines for the HotSpot JVM.
It's currently meant to be used on its own, without the other patches that are part of the mlvm project. This means that the guards to exclude the other patches need to be given to the qselect command (/indy, /meth, etc.).
Apart from the changes to the HotSpot VM there are also a number of new classes in the java/dyn package, and some changes to the java.lang.Thread class, so it's neccessary to build the JDK or compile and prepend (bootclasspath/p) the classes to the HotSpot boot class path.
Symmetric coroutines are implemented via the Coroutine class. This is used by either subclassing Coroutine and overriding the run method or passing a target Runnable to the Coroutine constructor.
Asymmetric coroutines have a more complicated API (through the class AsymCoroutine), for a number of reasons:
- they are prepared to take an input value and return an output value
- these input and output values are of generic type
- the caller/callee relationship of asymmetric coroutines leads to a differentiation between "calling" a coroutine and "returning" from it
- it implements Iterable so it can be used in for-each loops
CoroutineLocals work like ThreadLocals with the exception that they are scoped to Coroutines.