...
Many dynamic languages that have JVM-based runtime environments already support coroutine-like features.
Thus, coroutine support would also help these runtime environments provide an efficient implementation of these features.
...
Coroutines can be implemented very efficiently.
They can be applied to all platforms that at the moment support threading, and could be used as a lightweight alternative to threading on platforms that don't.
...
- JVM-based language implementation need coroutines to efficiently implement coroutine-like language features.
- Server applications can use coroutines to keep more sessions alive, which leads to less latency and better resource utilization.
- Coroutines provide an easy way to inverse algorithms, e.g. turn a callback-based algorithm into one that can be polled for the next result.
- Coroutines are a natural control abstraction for numerous problems like scanner/parser combinations.
- It is often convenient to write algorithms in multiple units that perform synchronous communication.
These non-parallel algorithms can avoid exposing parallelism by using coroutines instead of threads. - Coroutines can be used to hide the inherent complexity of asynchronous I/O and to avoid having to split the program into small pieces.
2.6 Why isn't this need met by existing specifications?
The current java.lang.Thread system is designed for preemptive, operating-system level context switching.
This inherently is orders of magnitude slower that user-level context switching.
2.7 Please give a short description of the underlying technology or technologies:
Coroutines as a programming concept have been around since the early days of computer science, the term "coroutine" itself was coined in 1963 by Melvin Conway (http://dx.doi.org/10.1145%2F366663.366704).
They are available in numerous programming languages and runtime environments.
From a language design perspective, coroutines are a generalization of subroutines.
When they are invoked, they start execution at their first statement and they can subsequently transfer control to some other coroutine (via an operation often called yield).
The state of the local variables and the expression stack at the transfer point is preserved.
When control is transferred back, the coroutine resumes the preserved state and continues to run from the point where it relinquished control.
Coroutines can also be seen as a limited form of continuations, called one-shot continuations.
From a VM perspective, coroutines can be seen as a limited version of threads that happen to transfer control only at some user-specified points in the program.
For the sake of this document, this is the most useful definition, because it can be used to infer sensible memory model and runtime semantics for coroutines.
Coroutines have been seen as an inferior alternative to full-blown threads, because of the manual context switching.
However, there are situations in which manual context switching makes sense or is even desired.
2.8 Is there a proposed package name for the API Specification? (i.e., javapi.something, org.something, etc.)
...
3.1 Please list any existing documents, specifications, or implementations that describe the technology. Please include links to the documents if they are publicly available.
- Master's thesis on HotSpot coroutines: http://ssw.jku.at/Research/Papers/Stadler11Master/
- Prototype implementation: part of the Da Vinci Machine Project (MLVM) http://wikis.sun.com/display/mlvm/Home
3.2 Explanation of how these items might be used as a starting point for the work.
The thesis should provide a starting point for discussions about the features that a coroutine implementation should provide, and the prototype implementation can be seen as a proof-of-concept that can be used to explore the API design and performance characteristics.
Section 4: Additional Information (Optional)
...