一句话:提出 volatile-by-default 并发语义,使安全语言默认顺序一致,并允许通过注解按需放弃以保证性能。
现代安全语言遵循默认安全、按需性能的原则,但在多线程上却相反:默认弱内存模型允许编译器和硬件优化,却破坏程序顺序与单内存位置的原子访问,且强默认语义的实际性能代价未知。本文提出 volatile-by-default 语义,默认提供顺序一致性,并用注解让专家在性能关键代码中避免开销。作者为 Java 的 HotSpot JVM 和 Julia 的 JIT 实现该语义,采用复用原子访问机制的基线方案和延迟到可能违反 SC 时才付出代价的推测方案。评估显示,强制 SC 开销显著,但部分用例仍可接受;编译器优化和程序员注解能大幅降低开销。
Modern “safe” programming languages follow a design principle that we call safety by default and performance by choice . By default, these languages enforce important programming abstractions, such as memory and type safety, but they also provide mechanisms that allow expert programmers to explicitly trade some safety guarantees for increased performance. However, these same languages have adopted the inverse design principle in their support for multithreading. By default, multithreaded programs violate important abstractions, such as program order and atomic access to individual memory locations to admit compiler and hardware optimizations that would otherwise need to be restricted. Not only does this approach conflict with the design philosophy of safe languages, but very little is known about the practical performance cost of providing a stronger default semantics. In this article, we propose a safe-by-default and performance-by-choice multithreading semantics for safe languages, which we call volatile -by-default . Under this semantics, programs have sequential consistency (SC) by default, which is the natural “interleaving” semantics of threads. However, the volatile -by-default design also includes annotations that allow expert programmers to avoid the associated overheads in performance-critical code. We describe the design, implementation, optimization, and evaluation of the volatile -by-default semantics for two different safe languages: Java and Julia. First, we present V BD-HotSpot and V BDA-HotSpot, modifications of Oracle’s HotSpot JVM that enforce the volatile -by-default semantics on Intel x86-64 hardware and ARM-v8 hardware. Second, we present S C-Julia, a modification to the just-in-time compiler within the standard Julia implementation that provides best-effort enforcement of the volatile -by-default semantics on x86-64 hardware for the purpose of performance evaluation. We also detail two different implementation techniques: a baseline approach that simply reuses existing mechanisms in the compilers for handling atomic accesses, and a speculative approach that avoids the overhead of enforcing the volatile -by-default semantics until there is the possibility of an SC violation. Our results show that the cost of enforcing SC is significant but arguably still acceptable for some use cases today. Further, we demonstrate that compiler optimizations as well as programmer annotations can reduce the overhead considerably.
@article{paperbot1212,
title = {Safe-by-default Concurrency for Modern Programming Languages},
author = {Lun Liu and Todd Millstein and Madanlal Musuvathi},
journal = {ACM Transactions on Programming Languages and Systems},
volume = {43},
number = {3},
year = {2021},
doi = {10.1145/3462206}
}