Serializable Coroutines for the HotSpot(TM) Java Virtual Machine

Lukas Stadler

Research output: ThesisMaster's / Diploma thesis

Abstract

Coroutines are non-preemptive light-weight 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 trade-off 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 coroutine-like language features, the need for a coroutine implementation has emerged. This thesis presents 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. The implementation of two advanced concepts, namely thread-to-thread migration and serialization of coroutines, is also explained along with the API that is used to control them. For evaluation purposes, coroutines were used to implement JRuby fibers, which lead to a significant speedup of certain JRuby programs. This thesis concludes with general benchmarks that show the performance of the approach and outline its run-time and memory characteristics.
Original languageEnglish
Publication statusPublished - Feb 2011

Fields of science

  • 102 Computer Sciences
  • 102009 Computer simulation
  • 102011 Formal languages
  • 102013 Human-computer interaction
  • 102029 Practical computer science
  • 102022 Software development
  • 102024 Usability research

Cite this