{"title":"现代编程语言的默认并发安全","authors":"Lun Liu, T. Millstein, M. Musuvathi","doi":"10.1145/3462206","DOIUrl":null,"url":null,"abstract":"Modern “safe” programming languages follow a design principle that we call\n safety by default\n and\n performance by choice\n . 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.\n \n \n In this article, we propose a safe-by-default and performance-by-choice multithreading semantics for safe languages, which we call\n \n volatile\n \n -by-default\n . Under this semantics, programs have\n sequential consistency\n (SC) by default, which is the natural “interleaving” semantics of threads. However, the\n volatile\n -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\n volatile\n -by-default semantics for two different safe languages: Java and Julia. First, we present\n V\n BD-HotSpot and\n V\n BDA-HotSpot, modifications of Oracle’s HotSpot JVM that enforce the\n volatile\n -by-default semantics on Intel x86-64 hardware and ARM-v8 hardware. Second, we present\n S\n C-Julia, a modification to the just-in-time compiler within the standard Julia implementation that provides best-effort enforcement of the\n volatile\n -by-default semantics on x86-64 hardware for the purpose of performance evaluation. We also detail two different implementation techniques: a\n baseline\n approach that simply reuses existing mechanisms in the compilers for handling atomic accesses, and a\n speculative\n approach that avoids the overhead of enforcing the\n volatile\n -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.","PeriodicalId":50939,"journal":{"name":"ACM Transactions on Programming Languages and Systems","volume":"3 1","pages":"10:1-10:50"},"PeriodicalIF":1.5000,"publicationDate":"2021-09-30","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"3","resultStr":"{\"title\":\"Safe-by-default Concurrency for Modern Programming Languages\",\"authors\":\"Lun Liu, T. Millstein, M. Musuvathi\",\"doi\":\"10.1145/3462206\",\"DOIUrl\":null,\"url\":null,\"abstract\":\"Modern “safe” programming languages follow a design principle that we call\\n safety by default\\n and\\n performance by choice\\n . 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.\\n \\n \\n In this article, we propose a safe-by-default and performance-by-choice multithreading semantics for safe languages, which we call\\n \\n volatile\\n \\n -by-default\\n . Under this semantics, programs have\\n sequential consistency\\n (SC) by default, which is the natural “interleaving” semantics of threads. However, the\\n volatile\\n -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\\n volatile\\n -by-default semantics for two different safe languages: Java and Julia. First, we present\\n V\\n BD-HotSpot and\\n V\\n BDA-HotSpot, modifications of Oracle’s HotSpot JVM that enforce the\\n volatile\\n -by-default semantics on Intel x86-64 hardware and ARM-v8 hardware. Second, we present\\n S\\n C-Julia, a modification to the just-in-time compiler within the standard Julia implementation that provides best-effort enforcement of the\\n volatile\\n -by-default semantics on x86-64 hardware for the purpose of performance evaluation. We also detail two different implementation techniques: a\\n baseline\\n approach that simply reuses existing mechanisms in the compilers for handling atomic accesses, and a\\n speculative\\n approach that avoids the overhead of enforcing the\\n volatile\\n -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.\",\"PeriodicalId\":50939,\"journal\":{\"name\":\"ACM Transactions on Programming Languages and Systems\",\"volume\":\"3 1\",\"pages\":\"10:1-10:50\"},\"PeriodicalIF\":1.5000,\"publicationDate\":\"2021-09-30\",\"publicationTypes\":\"Journal Article\",\"fieldsOfStudy\":null,\"isOpenAccess\":false,\"openAccessPdf\":\"\",\"citationCount\":\"3\",\"resultStr\":null,\"platform\":\"Semanticscholar\",\"paperid\":null,\"PeriodicalName\":\"ACM Transactions on Programming Languages and Systems\",\"FirstCategoryId\":\"94\",\"ListUrlMain\":\"https://doi.org/10.1145/3462206\",\"RegionNum\":2,\"RegionCategory\":\"计算机科学\",\"ArticlePicture\":[],\"TitleCN\":null,\"AbstractTextCN\":null,\"PMCID\":null,\"EPubDate\":\"\",\"PubModel\":\"\",\"JCR\":\"Q3\",\"JCRName\":\"COMPUTER SCIENCE, SOFTWARE ENGINEERING\",\"Score\":null,\"Total\":0}","platform":"Semanticscholar","paperid":null,"PeriodicalName":"ACM Transactions on Programming Languages and Systems","FirstCategoryId":"94","ListUrlMain":"https://doi.org/10.1145/3462206","RegionNum":2,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"Q3","JCRName":"COMPUTER SCIENCE, SOFTWARE ENGINEERING","Score":null,"Total":0}
Safe-by-default Concurrency for Modern Programming Languages
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.
期刊介绍:
ACM Transactions on Programming Languages and Systems (TOPLAS) is the premier journal for reporting recent research advances in the areas of programming languages, and systems to assist the task of programming. Papers can be either theoretical or experimental in style, but in either case, they must contain innovative and novel content that advances the state of the art of programming languages and systems. We also invite strictly experimental papers that compare existing approaches, as well as tutorial and survey papers. The scope of TOPLAS includes, but is not limited to, the following subjects:
language design for sequential and parallel programming
programming language implementation
programming language semantics
compilers and interpreters
runtime systems for program execution
storage allocation and garbage collection
languages and methods for writing program specifications
languages and methods for secure and reliable programs
testing and verification of programs