Slide 1

Slide 1 text

High-Level Concurrency Libraries: Challenges for Tools Philipp Haller! KTH Royal Institute of Technology! Sweden! ! Eclipse Technology eXchange (ETX)! SPLASH, Pittsburgh, PA, USA, October 2015 1

Slide 2

Slide 2 text

Haller High-Level Concurrency Libraries: Challenges for Tools Context • 2005–2015: author or co-author of a variety of concurrency libraries for Scala! • Some in wide industrial use, some experimental! • Common theme: how expressive are pure library approaches?! • High-level concurrency libraries ~= embedded domain-specific languages 2

Slide 3

Slide 3 text

Haller High-Level Concurrency Libraries: Challenges for Tools Disclaimers • Disclaimer 1: I am not an IDE expert! • A lot of work I am not aware of! • Disclaimer 2: my observations are biased toward certain languages and runtimes! • Statically-typed languages like Scala or Java! • Managed runtime environments à la JVM 3

Slide 4

Slide 4 text

Haller High-Level Concurrency Libraries: Challenges for Tools Experience • Developed libraries:! • Scala Actors (2006)! • Scala Joins (2008)! • Scala Futures (2012)! • FlowPools (2012)! • Scala Async (2013)! • Exploration of Scala as a growable language 4

Slide 5

Slide 5 text

Haller High-Level Concurrency Libraries: Challenges for Tools Experience • Developed libraries:! • Scala Actors (2006)! • Scala Joins (2008)! • Scala Futures (2012)! • FlowPools (2012)! • Scala Async (2013)! • Exploration of Scala as a growable language 4 Macro library

Slide 6

Slide 6 text

Haller High-Level Concurrency Libraries: Challenges for Tools Experience • Developed libraries:! • Scala Actors (2006)! • Scala Joins (2008)! • Scala Futures (2012)! • FlowPools (2012)! • Scala Async (2013)! • Exploration of Scala as a growable language 4 Macro library Production use at Twitter, The Guardian and others

Slide 7

Slide 7 text

Haller High-Level Concurrency Libraries: Challenges for Tools Experience • Developed libraries:! • Scala Actors (2006)! • Scala Joins (2008)! • Scala Futures (2012)! • FlowPools (2012)! • Scala Async (2013)! • Exploration of Scala as a growable language 4 Macro library Production use at Twitter, The Guardian and others Production use at LinkedIn, Gilt Groupe and others

Slide 8

Slide 8 text

Haller High-Level Concurrency Libraries: Challenges for Tools Experience • Developed libraries:! • Scala Actors (2006)! • Scala Joins (2008)! • Scala Futures (2012)! • FlowPools (2012)! • Scala Async (2013)! • Exploration of Scala as a growable language 4 Production use at Twitter, The Guardian and others Production use at LinkedIn, Gilt Groupe and others Production use at Morgan Stanley, Gawker and others

Slide 9

Slide 9 text

Haller High-Level Concurrency Libraries: Challenges for Tools Experience • Developed libraries:! • Scala Actors (2006)! • Scala Joins (2008)! • Scala Futures (2012)! • FlowPools (2012)! • Scala Async (2013)! • Exploration of Scala as a growable language 4 Guy Steele. “Growing a Language.” OOPSLA ’98 Production use at Twitter, The Guardian and others Production use at LinkedIn, Gilt Groupe and others Production use at Morgan Stanley, Gawker and others

Slide 10

Slide 10 text

Haller High-Level Concurrency Libraries: Challenges for Tools Why Growable Languages for Concurrency? • Actors, agents, communicating event-loops! • CML! • Futures, promises! • Async/await, async-finish! • Reactive Extensions (Rx)! • Join-calculus! • STM! • … 5

Slide 11

Slide 11 text

Haller High-Level Concurrency Libraries: Challenges for Tools Why Growable Languages for Concurrency? • Actors, agents, communicating event-loops! • CML! • Futures, promises! • Async/await, async-finish! • Reactive Extensions (Rx)! • Join-calculus! • STM! • … 5 Which one is going to “win”?

Slide 12

Slide 12 text

Haller High-Level Concurrency Libraries: Challenges for Tools Why Growable Languages for Concurrency? (cont’d) Enables multiple high-level libraries embedded in the same host language! • Richer programming system! • Enables reusing the compilers, debuggers, and IDEs of the host language 6

Slide 13

Slide 13 text

Haller High-Level Concurrency Libraries: Challenges for Tools Why Growable Languages for Concurrency? (cont’d) 7

Slide 14

Slide 14 text

Haller High-Level Concurrency Libraries: Challenges for Tools Why Growable Languages for Concurrency? (cont’d) Simplifies research 7

Slide 15

Slide 15 text

Haller High-Level Concurrency Libraries: Challenges for Tools Why Growable Languages for Concurrency? (cont’d) Simplifies research • Library extensions vs. language extensions 7

Slide 16

Slide 16 text

Haller High-Level Concurrency Libraries: Challenges for Tools Why Growable Languages for Concurrency? (cont’d) Simplifies research • Library extensions vs. language extensions • Performance comparisons between different libraries more meaningful 7

Slide 17

Slide 17 text

Haller High-Level Concurrency Libraries: Challenges for Tools Why Growable Languages for Concurrency? (cont’d) Simplifies research • Library extensions vs. language extensions • Performance comparisons between different libraries more meaningful • Experimental evaluation on real code 7

Slide 18

Slide 18 text

Challenges for Tools 8

Slide 19

Slide 19 text

Haller High-Level Concurrency Libraries: Challenges for Tools New API Designs 9

Slide 20

Slide 20 text

Haller High-Level Concurrency Libraries: Challenges for Tools New API Designs • Unique integration of features: Scala enables new API designs 9

Slide 21

Slide 21 text

Haller High-Level Concurrency Libraries: Challenges for Tools New API Designs • Unique integration of features: Scala enables new API designs • Objects + functions, traits, path-dependent types 9

Slide 22

Slide 22 text

Haller High-Level Concurrency Libraries: Challenges for Tools New API Designs • Unique integration of features: Scala enables new API designs • Objects + functions, traits, path-dependent types • Pattern matching, extractors 9

Slide 23

Slide 23 text

Haller High-Level Concurrency Libraries: Challenges for Tools New API Designs • Unique integration of features: Scala enables new API designs • Objects + functions, traits, path-dependent types • Pattern matching, extractors • Implicits 9

Slide 24

Slide 24 text

Haller High-Level Concurrency Libraries: Challenges for Tools New API Designs • Unique integration of features: Scala enables new API designs • Objects + functions, traits, path-dependent types • Pattern matching, extractors • Implicits • ... 9

Slide 25

Slide 25 text

Haller High-Level Concurrency Libraries: Challenges for Tools New API Designs • Unique integration of features: Scala enables new API designs • Objects + functions, traits, path-dependent types • Pattern matching, extractors • Implicits • ... • Not all API designs well-supported by tools 9

Slide 26

Slide 26 text

Haller High-Level Concurrency Libraries: Challenges for Tools New API Designs: Example 10

Slide 27

Slide 27 text

Haller High-Level Concurrency Libraries: Challenges for Tools New API Designs: Example • Actors widely-used abstraction for concurrent programming in Scala 10

Slide 28

Slide 28 text

Haller High-Level Concurrency Libraries: Challenges for Tools New API Designs: Example • Actors widely-used abstraction for concurrent programming in Scala • Actor = concurrent “process” that communicates via asynchronous messages 10

Slide 29

Slide 29 text

Haller High-Level Concurrency Libraries: Challenges for Tools New API Designs: Example • Actors widely-used abstraction for concurrent programming in Scala • Actor = concurrent “process” that communicates via asynchronous messages • Asynchronous send, event-based receive 10

Slide 30

Slide 30 text

Haller High-Level Concurrency Libraries: Challenges for Tools New API Designs: Example • Actors widely-used abstraction for concurrent programming in Scala • Actor = concurrent “process” that communicates via asynchronous messages • Asynchronous send, event-based receive • Low-level data races easy to avoid (by convention) 10

Slide 31

Slide 31 text

Haller High-Level Concurrency Libraries: Challenges for Tools New API Designs: Example • Actors widely-used abstraction for concurrent programming in Scala • Actor = concurrent “process” that communicates via asynchronous messages • Asynchronous send, event-based receive • Low-level data races easy to avoid (by convention) • Debugging high-level messaging protocols can be difficult 10

Slide 32

Slide 32 text

Haller High-Level Concurrency Libraries: Challenges for Tools Debugging Actor Programs 11 class TaskCoordinator extends Actor { ! var worker: Option[ActorRef] = None ! def receive = { case Start(workerRef) => this.worker = Some(workerRef) ! case Do(tasks) => assert(worker.nonEmpty) ! .. } ! }

Slide 33

Slide 33 text

Haller High-Level Concurrency Libraries: Challenges for Tools Debugging Actor Programs 11 class TaskCoordinator extends Actor { ! var worker: Option[ActorRef] = None ! def receive = { case Start(workerRef) => this.worker = Some(workerRef) ! case Do(tasks) => assert(worker.nonEmpty) ! .. } ! } Fails if ‘Do’ sent without prior ‘Start’

Slide 34

Slide 34 text

Haller High-Level Concurrency Libraries: Challenges for Tools Debugging Actor Programs 11 class TaskCoordinator extends Actor { ! var worker: Option[ActorRef] = None ! def receive = { case Start(workerRef) => this.worker = Some(workerRef) ! case Do(tasks) => assert(worker.nonEmpty) ! .. } ! } Fails if ‘Do’ sent without prior ‘Start’ “At what point was ‘Do’ message sent that caused assertion failure?”

Slide 35

Slide 35 text

Haller High-Level Concurrency Libraries: Challenges for Tools Problem • In general, sender and receiver are executed by two different worker threads, on two different stacks! • Messages transferred using a concurrent queue of the receiver (its “mailbox”)! • Flow of control cannot be traced using traditional stack-based debuggers 12

Slide 36

Slide 36 text

Haller High-Level Concurrency Libraries: Challenges for Tools Solution: Stack Retention 13

Slide 37

Slide 37 text

Haller High-Level Concurrency Libraries: Challenges for Tools Solution: Stack Retention Idea: 13

Slide 38

Slide 38 text

Haller High-Level Concurrency Libraries: Challenges for Tools Solution: Stack Retention Idea: • At the point when a message is sent: 13

Slide 39

Slide 39 text

Haller High-Level Concurrency Libraries: Challenges for Tools Solution: Stack Retention Idea: • At the point when a message is sent: • Save the call stack as well as stack frame information (e.g., local variable values) 13

Slide 40

Slide 40 text

Haller High-Level Concurrency Libraries: Challenges for Tools Solution: Stack Retention Idea: • At the point when a message is sent: • Save the call stack as well as stack frame information (e.g., local variable values) • Attach the call stack to the sent message object 13

Slide 41

Slide 41 text

Haller High-Level Concurrency Libraries: Challenges for Tools Solution: Stack Retention Idea: • At the point when a message is sent: • Save the call stack as well as stack frame information (e.g., local variable values) • Attach the call stack to the sent message object • When a user-defined breakpoint is reached present the collected stack frames to the user (if they are relevant) 13

Slide 42

Slide 42 text

Haller High-Level Concurrency Libraries: Challenges for Tools Solution: Stack Retention Idea: • At the point when a message is sent: • Save the call stack as well as stack frame information (e.g., local variable values) • Attach the call stack to the sent message object • When a user-defined breakpoint is reached present the collected stack frames to the user (if they are relevant) 13 Iulian Dragos. “Stack Retention in Debuggers for Concurrent Programs.” Scala Workshop ’13

Slide 43

Slide 43 text

Haller High-Level Concurrency Libraries: Challenges for Tools Futures • Stack retention also works for futures! • Call stack is saved whenever a future is created 14 val fut = Future { // concurrent computation } ! val transformed = fut.map { x => transform(x) } ! transformed.onComplete { case Success(v) => .. case Failure(t) => .. }

Slide 44

Slide 44 text

Haller High-Level Concurrency Libraries: Challenges for Tools Are We Done? 15

Slide 45

Slide 45 text

Haller High-Level Concurrency Libraries: Challenges for Tools Are We Done? • Actors and futures not the only concurrency abstractions that should be supported 15

Slide 46

Slide 46 text

Haller High-Level Concurrency Libraries: Challenges for Tools Are We Done? • Actors and futures not the only concurrency abstractions that should be supported • Streams, data-flow, join patterns, etc. 15

Slide 47

Slide 47 text

Haller High-Level Concurrency Libraries: Challenges for Tools Are We Done? • Actors and futures not the only concurrency abstractions that should be supported • Streams, data-flow, join patterns, etc. • Effort to implement support for a given concurrency abstraction is high: 15

Slide 48

Slide 48 text

Haller High-Level Concurrency Libraries: Challenges for Tools Are We Done? • Actors and futures not the only concurrency abstractions that should be supported • Streams, data-flow, join patterns, etc. • Effort to implement support for a given concurrency abstraction is high: • First release of Scala Actors: 2006 15

Slide 49

Slide 49 text

Haller High-Level Concurrency Libraries: Challenges for Tools Are We Done? • Actors and futures not the only concurrency abstractions that should be supported • Streams, data-flow, join patterns, etc. • Effort to implement support for a given concurrency abstraction is high: • First release of Scala Actors: 2006 • First use of Scala Actors at Twitter: 2008 15

Slide 50

Slide 50 text

Haller High-Level Concurrency Libraries: Challenges for Tools Are We Done? • Actors and futures not the only concurrency abstractions that should be supported • Streams, data-flow, join patterns, etc. • Effort to implement support for a given concurrency abstraction is high: • First release of Scala Actors: 2006 • First use of Scala Actors at Twitter: 2008 • First release of Akka: 2009 15

Slide 51

Slide 51 text

Haller High-Level Concurrency Libraries: Challenges for Tools Are We Done? • Actors and futures not the only concurrency abstractions that should be supported • Streams, data-flow, join patterns, etc. • Effort to implement support for a given concurrency abstraction is high: • First release of Scala Actors: 2006 • First use of Scala Actors at Twitter: 2008 • First release of Akka: 2009 • Iulian Dragos first presents Async debugger ideas: 2013 15 Iulian Dragos. “Stack Retention in Debuggers for Concurrent Programs.” Scala Workshop ’13

Slide 52

Slide 52 text

Haller High-Level Concurrency Libraries: Challenges for Tools Are We Done? • Actors and futures not the only concurrency abstractions that should be supported • Streams, data-flow, join patterns, etc. • Effort to implement support for a given concurrency abstraction is high: • First release of Scala Actors: 2006 • First use of Scala Actors at Twitter: 2008 • First release of Akka: 2009 • Iulian Dragos first presents Async debugger ideas: 2013 • First release of Async debugger: 2015 15 Iulian Dragos. “Stack Retention in Debuggers for Concurrent Programs.” Scala Workshop ’13

Slide 53

Slide 53 text

Haller High-Level Concurrency Libraries: Challenges for Tools Are We Done? • Actors and futures not the only concurrency abstractions that should be supported • Streams, data-flow, join patterns, etc. • Effort to implement support for a given concurrency abstraction is high: • First release of Scala Actors: 2006 • First use of Scala Actors at Twitter: 2008 • First release of Akka: 2009 • Iulian Dragos first presents Async debugger ideas: 2013 • First release of Async debugger: 2015 15 Iulian Dragos. “Stack Retention in Debuggers for Concurrent Programs.” Scala Workshop ’13 9 years!

Slide 54

Slide 54 text

Haller High-Level Concurrency Libraries: Challenges for Tools Issues 16

Slide 55

Slide 55 text

Haller High-Level Concurrency Libraries: Challenges for Tools Issues • Issue 1: Concurrency libraries often provide new control-flow abstractions 16

Slide 56

Slide 56 text

Haller High-Level Concurrency Libraries: Challenges for Tools Issues • Issue 1: Concurrency libraries often provide new control-flow abstractions • Issue 2: Development of tool support decoupled from library implementation 16

Slide 57

Slide 57 text

Haller High-Level Concurrency Libraries: Challenges for Tools Issues • Issue 1: Concurrency libraries often provide new control-flow abstractions • Issue 2: Development of tool support decoupled from library implementation • Issue 3: High development effort means dedicated tool support only implemented for few libraries 16

Slide 58

Slide 58 text

Haller High-Level Concurrency Libraries: Challenges for Tools Issue 1 17

Slide 59

Slide 59 text

Haller High-Level Concurrency Libraries: Challenges for Tools Issue 1 • Concurrency libraries often provide new abstractions for managing concurrent control flow 17

Slide 60

Slide 60 text

Haller High-Level Concurrency Libraries: Challenges for Tools Issue 1 • Concurrency libraries often provide new abstractions for managing concurrent control flow • Typically, control flow spans several threads 17

Slide 61

Slide 61 text

Haller High-Level Concurrency Libraries: Challenges for Tools Issue 1 • Concurrency libraries often provide new abstractions for managing concurrent control flow • Typically, control flow spans several threads • Examples: actor multiplexing, future scheduling 17

Slide 62

Slide 62 text

Haller High-Level Concurrency Libraries: Challenges for Tools Issue 1 • Concurrency libraries often provide new abstractions for managing concurrent control flow • Typically, control flow spans several threads • Examples: actor multiplexing, future scheduling • Control-flow abstractions not necessarily implemented in terms of abstractions known to tools 17

Slide 63

Slide 63 text

Haller High-Level Concurrency Libraries: Challenges for Tools Issue 1 • Concurrency libraries often provide new abstractions for managing concurrent control flow • Typically, control flow spans several threads • Examples: actor multiplexing, future scheduling • Control-flow abstractions not necessarily implemented in terms of abstractions known to tools • Efficiency and scalability requirements usually preclude layering of abstractions 17

Slide 64

Slide 64 text

Haller High-Level Concurrency Libraries: Challenges for Tools Issue 1: Example • Library defines new control-flow abstractions! • Example: synchronous channel using a Joins library 18

Slide 65

Slide 65 text

Haller High-Level Concurrency Libraries: Challenges for Tools Issue 1: Example • Library defines new control-flow abstractions! • Example: synchronous channel using a Joins library 18 class SyncChannel extends Joins { object Read extends NullarySyncEvent[Int] object Write extends SyncEvent[Unit, Int] ! join { case Read() & Write(x) => Read reply x Write reply {} } } Philipp Haller and Tom Van Cutsem. “Implementing Joins using Extensible Pattern Matching.” Coordination ’08

Slide 66

Slide 66 text

Haller High-Level Concurrency Libraries: Challenges for Tools Issue 1: Example • Library defines new control-flow abstractions! • Example: synchronous channel using a Joins library 18 class SyncChannel extends Joins { object Read extends NullarySyncEvent[Int] object Write extends SyncEvent[Unit, Int] ! join { case Read() & Write(x) => Read reply x Write reply {} } } Events not transferred using actors or futures Philipp Haller and Tom Van Cutsem. “Implementing Joins using Extensible Pattern Matching.” Coordination ’08

Slide 67

Slide 67 text

Haller High-Level Concurrency Libraries: Challenges for Tools Issue 2 Development of tool support decoupled from library implementation! • Library implementer most familiar with mechanics, but cannot support tools through implementation! • Tool developers have to reverse engineer library implementations 19

Slide 68

Slide 68 text

Haller High-Level Concurrency Libraries: Challenges for Tools Libraries with “Support for Tools” • Futures in Scala include usability features! • Little implementation effort makes big difference 20

Slide 69

Slide 69 text

Haller High-Level Concurrency Libraries: Challenges for Tools Libraries with “Support for Tools” • Futures in Scala include usability features! • Little implementation effort makes big difference 20 Welcome to Scala version 2.11.6 (Java HotSpot(TM) ..). Type in expressions to have them evaluated. Type :help for more information. ! scala> import scala.concurrent._ import scala.concurrent._ ! scala> val fut = Future { 40 + 2 } ! ! ! ! !

Slide 70

Slide 70 text

Haller High-Level Concurrency Libraries: Challenges for Tools :10: error: Cannot find an implicit ExecutionContext. You might pass Libraries with “Support for Tools” • Futures in Scala include usability features! • Little implementation effort makes big difference 20 Welcome to Scala version 2.11.6 (Java HotSpot(TM) ..). Type in expressions to have them evaluated. Type :help for more information. ! scala> import scala.concurrent._ import scala.concurrent._ ! scala> val fut = Future { 40 + 2 } ! ! ! ! !

Slide 71

Slide 71 text

Haller High-Level Concurrency Libraries: Challenges for Tools :10: error: Cannot find an implicit ExecutionContext. You might pass Libraries with “Support for Tools” • Futures in Scala include usability features! • Little implementation effort makes big difference 20 Welcome to Scala version 2.11.6 (Java HotSpot(TM) ..). Type in expressions to have them evaluated. Type :help for more information. ! scala> import scala.concurrent._ import scala.concurrent._ ! scala> val fut = Future { 40 + 2 } ! ! ! ! ! ???

Slide 72

Slide 72 text

Haller High-Level Concurrency Libraries: Challenges for Tools :10: error: Cannot find an implicit ExecutionContext. You might pass Libraries with “Support for Tools” • Futures in Scala include usability features! • Little implementation effort makes big difference 20 Welcome to Scala version 2.11.6 (Java HotSpot(TM) ..). Type in expressions to have them evaluated. Type :help for more information. ! scala> import scala.concurrent._ import scala.concurrent._ ! scala> val fut = Future { 40 + 2 } ! ! ! ! ! But…

Slide 73

Slide 73 text

Haller High-Level Concurrency Libraries: Challenges for Tools :10: error: Cannot find an implicit ExecutionContext. You might pass Libraries with “Support for Tools” • Futures in Scala include usability features! • Little implementation effort makes big difference 20 Welcome to Scala version 2.11.6 (Java HotSpot(TM) ..). Type in expressions to have them evaluated. Type :help for more information. ! scala> import scala.concurrent._ import scala.concurrent._ ! scala> val fut = Future { 40 + 2 } ! ! ! ! ! an (implicit ec: ExecutionContext) parameter to your method or import scala.concurrent.ExecutionContext.Implicits.global. val fut = Future { 40 + 2 } ^ But…

Slide 74

Slide 74 text

Haller High-Level Concurrency Libraries: Challenges for Tools Creating Futures 21 val fut = Future { .. } // equivalent to: val fut = Future.apply({ .. })

Slide 75

Slide 75 text

Haller High-Level Concurrency Libraries: Challenges for Tools Creating Futures 21 object Future { ! /** Starts an asynchronous computation and returns a `Future` object.. * * @tparam T the type of the result * @param body the asynchronous computation * @param executor the execution context on which the future is run * @return the `Future` holding the result of the computation */ def apply[T](body: =>T)(implicit executor: ExecutionContext): Future[T] = .. val fut = Future { .. } // equivalent to: val fut = Future.apply({ .. })

Slide 76

Slide 76 text

Haller High-Level Concurrency Libraries: Challenges for Tools Execution Contexts 22 /** * An `ExecutionContext` can execute program logic asynchronously, * typically but not necessarily on a thread pool. * * .. */ @implicitNotFound("""Cannot find an implicit ExecutionContext. You might pass an (implicit ec: ExecutionContext) parameter to your method or import scala.concurrent.ExecutionContext.Implicits.global.""") ! trait ExecutionContext { ! def execute(runnable: Runnable): Unit ! .. }

Slide 77

Slide 77 text

Haller High-Level Concurrency Libraries: Challenges for Tools Execution Contexts 22 /** * An `ExecutionContext` can execute program logic asynchronously, * typically but not necessarily on a thread pool. * * .. */ @implicitNotFound("""Cannot find an implicit ExecutionContext. You might pass an (implicit ec: ExecutionContext) parameter to your method or import scala.concurrent.ExecutionContext.Implicits.global.""") ! trait ExecutionContext { ! def execute(runnable: Runnable): Unit ! .. }

Slide 78

Slide 78 text

Haller High-Level Concurrency Libraries: Challenges for Tools Execution Contexts 22 /** * An `ExecutionContext` can execute program logic asynchronously, * typically but not necessarily on a thread pool. * * .. */ @implicitNotFound("""Cannot find an implicit ExecutionContext. You might pass an (implicit ec: ExecutionContext) parameter to your method or import scala.concurrent.ExecutionContext.Implicits.global.""") ! trait ExecutionContext { ! def execute(runnable: Runnable): Unit ! .. } With suitable mark- up, tools could extract quick fixes automatically!

Slide 79

Slide 79 text

Haller High-Level Concurrency Libraries: Challenges for Tools Going Further: A Proposal 23

Slide 80

Slide 80 text

Haller High-Level Concurrency Libraries: Challenges for Tools Going Further: A Proposal • Library “explains” control flow in form understandable by tools 23

Slide 81

Slide 81 text

Haller High-Level Concurrency Libraries: Challenges for Tools Going Further: A Proposal • Library “explains” control flow in form understandable by tools • Library implementers add annotations for: 23

Slide 82

Slide 82 text

Haller High-Level Concurrency Libraries: Challenges for Tools Going Further: A Proposal • Library “explains” control flow in form understandable by tools • Library implementers add annotations for: • Saving context information 23

Slide 83

Slide 83 text

Haller High-Level Concurrency Libraries: Challenges for Tools Going Further: A Proposal • Library “explains” control flow in form understandable by tools • Library implementers add annotations for: • Saving context information • Indicating which object to attach context information with 23

Slide 84

Slide 84 text

Haller High-Level Concurrency Libraries: Challenges for Tools Going Further: A Proposal • Library “explains” control flow in form understandable by tools • Library implementers add annotations for: • Saving context information • Indicating which object to attach context information with • Async tools extract annotations and enable library- specific control-flow tracing 23

Slide 85

Slide 85 text

Haller High-Level Concurrency Libraries: Challenges for Tools Example 1 24

Slide 86

Slide 86 text

Haller High-Level Concurrency Libraries: Challenges for Tools Example 1 24 object Future { ! /** Starts an asynchronous computation and returns a `Future` object.. * */ @asyncSaveContext def apply[T](body: =>T)(implicit executor: ExecutionContext): Future[T] = ..

Slide 87

Slide 87 text

Haller High-Level Concurrency Libraries: Challenges for Tools Example 1 24 object Future { ! /** Starts an asynchronous computation and returns a `Future` object.. * */ @asyncSaveContext def apply[T](body: =>T)(implicit executor: ExecutionContext): Future[T] = .. • Save context at invocation site of this method • Attach context information with object returned by this method

Slide 88

Slide 88 text

Haller High-Level Concurrency Libraries: Challenges for Tools Example 2 25

Slide 89

Slide 89 text

Haller High-Level Concurrency Libraries: Challenges for Tools Example 2 25 abstract class ActorRef extends java.lang.Comparable[ActorRef] with Serializable { .. ! /** * Sends the specified message to this ActorRef, i.e. fire-­‐and-­‐forget * semantics, including the sender reference if possible. * * Pass [[akka.actor.ActorRef]] `noSender` or `null` as sender if there is * nobody to reply to */ @asyncSaveContext(msg) final def tell(msg: Any, sender: ActorRef): Unit = this.!(msg)(sender) ! ..

Slide 90

Slide 90 text

Haller High-Level Concurrency Libraries: Challenges for Tools Example 2 25 abstract class ActorRef extends java.lang.Comparable[ActorRef] with Serializable { .. ! /** * Sends the specified message to this ActorRef, i.e. fire-­‐and-­‐forget * semantics, including the sender reference if possible. * * Pass [[akka.actor.ActorRef]] `noSender` or `null` as sender if there is * nobody to reply to */ @asyncSaveContext(msg) final def tell(msg: Any, sender: ActorRef): Unit = this.!(msg)(sender) ! .. Akka actor framework

Slide 91

Slide 91 text

Haller High-Level Concurrency Libraries: Challenges for Tools Example 2 25 abstract class ActorRef extends java.lang.Comparable[ActorRef] with Serializable { .. ! /** * Sends the specified message to this ActorRef, i.e. fire-­‐and-­‐forget * semantics, including the sender reference if possible. * * Pass [[akka.actor.ActorRef]] `noSender` or `null` as sender if there is * nobody to reply to */ @asyncSaveContext(msg) final def tell(msg: Any, sender: ActorRef): Unit = this.!(msg)(sender) ! .. • Save context at invocation site of this method • Attach context information with argument `msg` Akka actor framework

Slide 92

Slide 92 text

Haller High-Level Concurrency Libraries: Challenges for Tools Summary • Low implementation effort! • Leverages knowledge of library designers! • High payoff! • Still limited 26

Slide 93

Slide 93 text

Haller High-Level Concurrency Libraries: Challenges for Tools More Challenges 27

Slide 94

Slide 94 text

Haller High-Level Concurrency Libraries: Challenges for Tools More Challenges • “Step over”, “step into”, etc. 27

Slide 95

Slide 95 text

Haller High-Level Concurrency Libraries: Challenges for Tools More Challenges • “Step over”, “step into”, etc. • Lost meaning when “steps” cross thread boundaries 27

Slide 96

Slide 96 text

Haller High-Level Concurrency Libraries: Challenges for Tools More Challenges • “Step over”, “step into”, etc. • Lost meaning when “steps” cross thread boundaries • What’s the most useful interpretations of “step over/into/return” for a given library? 27

Slide 97

Slide 97 text

Haller High-Level Concurrency Libraries: Challenges for Tools More Challenges • “Step over”, “step into”, etc. • Lost meaning when “steps” cross thread boundaries • What’s the most useful interpretations of “step over/into/return” for a given library? • Atomicity of library abstractions 27

Slide 98

Slide 98 text

Haller High-Level Concurrency Libraries: Challenges for Tools More Challenges • “Step over”, “step into”, etc. • Lost meaning when “steps” cross thread boundaries • What’s the most useful interpretations of “step over/into/return” for a given library? • Atomicity of library abstractions • Atomic methods OK: can step over. Otherwise? 27

Slide 99

Slide 99 text

Haller High-Level Concurrency Libraries: Challenges for Tools More Challenges • “Step over”, “step into”, etc. • Lost meaning when “steps” cross thread boundaries • What’s the most useful interpretations of “step over/into/return” for a given library? • Atomicity of library abstractions • Atomic methods OK: can step over. Otherwise? • Combining concurrency abstractions 27

Slide 100

Slide 100 text

Haller High-Level Concurrency Libraries: Challenges for Tools Combining Libraries • Integration of multiple concurrency libraries natural (to some extent)! • Developers will do it anyway (see ECOOP ’13)! • Have to play nicely together! • We discovered many challenges! • Most of them have implications for tools 28

Slide 101

Slide 101 text

Haller High-Level Concurrency Libraries: Challenges for Tools Example: Actors/Futures 29 class ActorWithWorkers(workers: ...) extends Actor { ... ! def receive = { case Do(tasks) => val requests = (tasks zip workers).map { case (task, worker) => worker ? task } val allDone = Future.sequence(requests) allDone andThen { seq => sender ! seq.mkString(",") } } }

Slide 102

Slide 102 text

Haller High-Level Concurrency Libraries: Challenges for Tools Example: Actors/Futures 29 class ActorWithWorkers(workers: ...) extends Actor { ... ! def receive = { case Do(tasks) => val requests = (tasks zip workers).map { case (task, worker) => worker ? task } val allDone = Future.sequence(requests) allDone andThen { seq => sender ! seq.mkString(",") } } }

Slide 103

Slide 103 text

Haller High-Level Concurrency Libraries: Challenges for Tools Fixed Version 30 class ActorWithWorkers(workers: ...) extends Actor { ... ! def receive = { case Do(tasks) => val from = sender ! val requests = (tasks zip workers).map { case (task, worker) => worker ? task } val allDone = Future.sequence(requests) allDone andThen { seq => from ! seq.mkString(",") } } }

Slide 104

Slide 104 text

Haller High-Level Concurrency Libraries: Challenges for Tools Fixed Version 30 class ActorWithWorkers(workers: ...) extends Actor { ... ! def receive = { case Do(tasks) => val from = sender ! val requests = (tasks zip workers).map { case (task, worker) => worker ? task } val allDone = Future.sequence(requests) allDone andThen { seq => from ! seq.mkString(",") } } } Tool support?

Slide 105

Slide 105 text

Haller High-Level Concurrency Libraries: Challenges for Tools Spores • Refinement of closures that demands an explicit environment! • Supports type-based constraints on captured variables 31

Slide 106

Slide 106 text

Haller High-Level Concurrency Libraries: Challenges for Tools Spores • Refinement of closures that demands an explicit environment! • Supports type-based constraints on captured variables 31 case Do(tasks) => .. ! val allDone = Future.sequence(requests) allDone andThen spore { val from = sender seq => from ! seq.mkString(",") } Miller et al. Spores: A Type-Based Foundation for Closures in the Age of Concurrency and Distribution. ECOOP ‘14

Slide 107

Slide 107 text

Haller High-Level Concurrency Libraries: Challenges for Tools Spores • Refinement of closures that demands an explicit environment! • Supports type-based constraints on captured variables 31 case Do(tasks) => .. ! val allDone = Future.sequence(requests) allDone andThen spore { val from = sender seq => from ! seq.mkString(",") } Miller et al. Spores: A Type-Based Foundation for Closures in the Age of Concurrency and Distribution. ECOOP ‘14 Using spores instead of closures disallows erroneous version!

Slide 108

Slide 108 text

Haller High-Level Concurrency Libraries: Challenges for Tools Conclusion • Concurrency libraries present numerous challenges for development tools! • Both low-hanging fruit and major challenges! • Can we improve the interface between library and tool designers? 32