Efficient coroutines for the Java platform

  • Authors:
  • Lukas Stadler;Thomas Würthinger;Christian Wimmer

  • Affiliations:
  • Johannes Kepler University Linz, Austria;Johannes Kepler University Linz, Austria;University of California, Irvine

  • Venue:
  • Proceedings of the 8th International Conference on the Principles and Practice of Programming in Java
  • Year:
  • 2010
  • One VM to rule them all

    Proceedings of the 2013 ACM international symposium on New ideas, new paradigms, and reflections on programming & software

Quantified Score

Hi-index 0.00

Visualization

Abstract

Coroutines are non-preemptive lightweight processes. Their advantage over threads is that they do not have to be synchronized because they pass control to each other explicitly and deterministically. Coroutines are therefore an elegant and efficient implementation construct for numerous algorithmic problems. Many mainstream languages and runtime environments, however, do not provide a coroutine implementation. Even if they do, these implementations often have less than optimal performance characteristics because of the tradeoff between run time and memory efficiency. As more and more languages are implemented on top of the Java virtual machine (JVM), many of which provide coroutinelike language features, the need for a coroutine implementation has emerged. We present an implementation of coroutines in the JVM that efficiently handles a large range of workloads. It imposes no overhead for applications that do not use coroutines and performs well for applications that do. For evaluation purposes, we use our coroutines to implement JRuby fibers, which leads to a significant speedup of certain JRuby programs. We also present general benchmarks that show the performance of our approach and outline its run-time and memory characteristics.