60
Overview of Concurrency and Program Analysis Dr. Jeff Huang Fall 2014

Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Overview  of  Concurrency  and  Program  Analysis  

Dr.  Jeff  Huang  Fall  2014  

Page 2: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Outline  

•  What  is  Concurrency?  •  Why  Concurrency?  •  How  to  Program?  •  Hard.  Why?  •  Basic  Concepts  •  StaHc  Analysis  &  Dynamic  Analysis  •  Important  DirecHons  

Page 3: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

What  is  Concurrency?  

•  TradiHonally,  the  expression  of  a  task  in  the  form  of  mulHple,  possibly  interacHng  subtasks,  that  may  potenHally  be  executed  at  the  same  Hme.  

Page 4: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

What  is  Concurrency?  

•  Concurrency  is  a  programming  concept.  •   It  says  nothing  about  how  the  subtasks  are  actually  executed.  

•  Concurrent  tasks  may  be  executed  serially  or  in  parallel  depending  upon  the  underlying  physical  resources  available.  

Page 5: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

The  modern  world  is  parallel  

•  MulHcore  •  Networks  •  Clouds  of  CPUs  •  Loads  of  Users  

•  Capture  the  logical  structure  of  certain  applicaHons  

•  Performance  through  use  of  mulHple  processors  

Page 6: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Why  Concurrency  

•  In  a  serial  environment,  consider  the  following  simple  example  of  a  server,  serving  requests  from  clients  (e.g.,  a  web  server  and  web  clients)  

Page 7: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Why  Concurrency  

•  Let’s  process  requests  serially  

Page 8: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Why  Concurrency  

•  Why  a  concurrent  server  now!  

Page 9: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Why  Concurrency  

•  We  reduced  mean  service  Hme!  

Page 10: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Why  Concurrency  

•  The  lesson  from  the  example  is  quite  simple:  – Not  knowing  anything  about  execuHon  Hmes,  we  can  reduce  average  service  Hme  for  requests  by  processing  them  concurrently!  

•  But  what  if  I  knew  the  service  Hme  for  each  request?  – Would  “shortest  job  first”  not  minimize  average  service  Hme  anyway?  

– Aha!  But  what  about  the  poor  guy  standing  at  the  back  never  ge_ng  any  service  (starvaHon/  fairness)?  

Page 11: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Why  Concurrency  

•  NoHons  of  service  Hme,  starvaHon,  and  fairness  moHvate  the  use  of  concurrency  in  virtually  all  aspects  of  compuHng:  – OperaHng  systems  are  mulHtasking  – Web/database  services  handle  mulHple  concurrent  requests  

– Browsers  are  concurrent  – Virtually  all  user  interfaces  are  concurrent  

Page 12: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Why  Concurrency  

•  In  a  parallel  context,  the  moHvaHons  for  concurrency  are  more  obvious:  – Concurrency  +  parallel  execuHon  =  performance  

Page 13: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

How  to  Program  •  AbstracHons  

–   Shared  memory,  message-­‐passing,  data  parallel  •   Erlang,  MPI,  Concurrent  ML,  Cuda  •   Posix,  Cilk,  OpenMP  

–  Synchronous  vs.  asynchronous  communicaHon  •  Data  Structures  and  Algorithms  

– Queues,  Heaps,  Trees,  Lists  –  SorHng,  Graph  Algorithms  

•  Processor  Architectures  –  Relaxed  memory  models  – GPGPU  

Page 14: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

How  to  Program  

•   Standard  models  of  parallelism  – Shared  memory  (Pthreads)  – Message  passing  (MPI)  – Data  parallel  (HPF,  Chapel,  X10)  – Shared  memory  +  data  parallel  (OpenMP)  

Page 15: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Shared  Memory  

•  Threads  communicate  by  reading  and  wriHng  to  shared  memory  –  Easier  transiHon  from  sequenHal  programs  –   Don’t  have  to  construct  new  communicaHon  abstracHons  

•  But,  implicit  communicaHon  via  shared-­‐memory  raises  complex  issues  of  its  own  –  Data  races:  concurrent  (unintended)  access  to  the  same  memory  locaHon  

•  How  do  we  express  concurrency  and  synchronizaHon?  –  As  language  primiHves  (Java,  C#,  Cilk,  X10...)  –  As  library  calls  (Posix  (Pthreads),  Intel  TBB)  

Page 16: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Message  Passing  

•  Processes  communicate  with  each  other  without  resorHng  to  shared  variables  

•  If  P  and  Q  wish  to  communicate,  they  need  to  – establish  a  communicaHon  link  between  them  – exchange  messages  via  send/receive  

Page 17: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

MPI  (Message  Passing  Interface)  

•  Is  the  de  facto  message  passing  standard  •  A  library  of  rouHnes  (i.e.  API,  called  in  C/C++/Fortune/Java/C#/Python):  – Provide  message  passing  faciliHes  (send  and  receive,  in  various  flavors)  to  distribute  and  communicate  data  

– Provide  addiHonal  synchronizaHon  faciliHes  •  Available  on  virtually  all  plalorms,  including  public  domain  versions  (MPICH,  OpenMPI)  

Page 18: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Data  Parallel  

•  ParHHoned  Global  Address  Space  (PGAS)  model  – Address  space  is  treated  globally  – Most  of  the  parallel  work  focuses  on  performing  operaHons  on  a  data  set.  The  data  set  is  typically  organized  into  a  common  structure,  such  as  an  array  or  cube.  

– A  set  of  tasks  work  collecHvely  on  the  same  data  structure,  however,  each  task  works  on  a  different  parHHon  of  the  same  data  structure.  

–  Tasks  perform  the  same  operaHon  on  their  parHHon  of  work,  for  example,  "add  4  to  every  array  element".  

Page 19: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Why  Hard  

•  The  human  mind  tends  to  be  sequenHal  •  The  noHon  of  Hme  is  onen  misleading  •  Thinking  about  all  possible  sequences  of  events  in  a  computer  system  is  at  least  error  prone  and  frequently  impossible  

Page 20: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Why  Hard  

•  Races:  outcome  depends  on  arbitrary  scheduling  decisions  elsewhere  in  the  system  –  Example:  who  gets  the  last  seat  on  the  airplane?  

•  Deadlock:  improper  resource  allocaHon  prevents  forward  progress  –   Example:  traffic  gridlock  

•  Livelock  /  StarvaHon  /  Fairness:  external  events  and/or  system  scheduling  decisions  can  prevent  sub-­‐task  progress  –  Example:  people  always  jump  in  front  of  you  in  line  

Page 21: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Thread  Safety  

•  Suppose  a  program  creates  N  threads,  each  of  which  calls  the  same  procedure  found  in  some  library  

•  Suppose  the  library  modifies  some  global  (shared)  data  structure  

•  Concurrent  modificaHons  to  this  structure  may  lead  to  data  corrupHon  

Page 22: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Basic  Concepts  •  Concurrency  bug  paperns  

– Data  race  vs  race  condiHons  – Order  violaHon,  atomic  ViolaHons  – Serializability,  linearizability  – Deadlocks  

•  Memory  Models  •  Program  Analysis  techniques  

Page 23: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Data  Race  

•  Every  thread  can  observe  acHons  of  other  threads  on  non-­‐thread  local  data  (e.g.  heap)  

•  Data  visible  to  mulHple  threads  must  be  protected  (synchronized)  to  ensure  the  absence  of  data  races  – A  data  race  consists  of  two  concurrent  accesses  to  the  same  shared  data  by  two  separate  threads,  at  least  one  of  which  is  a  write  

Page 24: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Data  Race  

Page 25: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Race  CondiHon  

•  A  flaw  that  occurs  when  the  Hming  or  ordering  of  events  affects  a  program’s  correctness.  

•  A  semanHc  error!  •  E.g.,  some  kind  of  external  Hming  or  ordering  non-­‐determinism:  context  switches,  OS  signals,  memory  operaHons  on  a  mulHprocessor,  and  hardware  interrupts.  

Page 26: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Race  CondiHon  

Thread  1        Thread  2      lock(l)                      lock(l)    x=1                                  x=2    unlock(l)            unlock(l)  

class  Race  {      staHc  volaHle  int  i;      staHc  int  uniqueInt()  {  return  i++;  }  }  

Page 27: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Order  ViolaHon  

An order violation bug from Mozilla. The program fails to enforce the programmer's order intention: thread 2 should not read mThread until thread 1 initializes mThread. Note that, this bug could not be fixed by making PR CreateThread atomic with the write to mThread.

Page 28: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Atomicity  ViolaHon  

A  real  bug  in  Mozilla.  When  Thread  2  violates  the  atomicity  of  Thread  1’s  accesses  to  gCurrentScript,  the  program  crashes.  

•  A  series  of  related  operaHons  are  interfered  by  certain  other  operaHons,  which  causes  inconsistency  

Page 29: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Serializability  •  ProperHes  of  parallel  data  structures  •  A  data  structure  with  operaHons  is  serializable  if  

–  the  state  of  any  possible  parallel  execuHon,  including  •  arguments  to  operaHons  •  return  values  from  operaHons  •  internal  state  of  data  structure  

–  is  equivalent  to  some  serializaHon  of  the  operaHons  applied  

•  In  other  words  –  there  must  exist  an  ordering  of  operaHons    –  such  that  the  operaHons  executed  in  parallel  appear  to  have  executed  serially  in  that  order  

Page 30: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Serializability  

•  Conflict-­‐serializability  –  Two  execuHons  are  conflict-­‐equivalent  if  and  only  if  they  contain  the  same  events,  and  for  each  pair  of  conflicHng  events,  the  two  events  appear  in  the  same  order.  

•  View-­‐serializability  –  Two  execuHons  are  view-­‐equivalent  if  they  contains  the  same  events,    If  each  read  operaHon  reads  the  same  result  of  the  same  write  operaHon  in  both  execuHons,  and  both  execuHon  must  have  the  same  final  write  for  any  locaHon.  

Page 31: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Serializability  Analysis  Consider  three  accesses  to  a  shared  variable,  the  first  and  the  third  are  by  the  same  thread,  the  second  by  another  thread  Case   Interleaving   Serializable?   Why  

0   Read-­‐Read-­‐Read   Y   Equivalent  to  Read-­‐Read-­‐Read  

1   Write-­‐Read-­‐Read   Y   Equivalent  to  Write-­‐Read-­‐Read  

2   Read-­‐Write  -­‐Read   N   The  Write  may  make  two  Reads  return  different  values  

3   Write-­‐Write  -­‐Read   N   The  Read  does  not  get  the  local  result  it  expects  

4   Read-­‐Read-­‐Write   Y   Equivalent  to  Read-­‐Read-­‐Write  

5   Write-­‐Read-­‐Write   N   The  Read  returns  intermediate  result  

6   Read-­‐Write  -­‐Write   N   The  Write  value  is  lost  

7   Write-­‐Write  -­‐Write   Y   Equivalent  to  Write-­‐Write-­‐Write    

Page 32: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Atomic-­‐set  serializability  

Class  Account{          int  checking,  saving;          transfer(int  n)  {                  checking-­‐=n;                  saving+=n;            }  }    

Consider  accesses  to  mulHple  related  variables?  

Page 33: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Linearizability  

•  Each  method  call  should  appear  to  “take  effect”  instantaneously  at  some  moment  between  its  invocaHon  and  response.  

•  Two  important  properHes:  •   local  property:  a  system  is  linearizable  iff  each  individual  object  is  linearizable.  It  gives  us  composability.  

•   non-­‐blocking  property:  one  method  is  never  forced  to  wait  to  synchronize  with  another.  

Page 34: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Deadlocks  

Traffic  jam     Dinning  philosophers  

Page 35: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Deadlock  

•  Program  hangs  due  to  missing  noHficaHon  

Page 36: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Memory  Model  

•  What  values  a  read  can  return?  

Page 37: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Memory  Model  

•  Programmers  reason  with  interleaved  semanHcs    

•  But  hardware  and  compilers  do  not  – They  use  sophisHcated  techniques  for  opHmizaHon  

– These  techniques  can  “reorder”  statements    

Page 38: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Memory  Model  

•  SequenHal  Consistency  (SC)    – OperaHons  of  a  single  thread  in  program  order  – All  operaHons  in  a  total  order    

•  SC  prohibits  hardware  performance   •  Compiler  transformaHon  violates  SC    

Page 39: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Memory  Model  

•  Data-­‐race-­‐freedom  (DRF)  model  – SC  for  data-­‐race-­‐free  programs  – No  guarantee  for  racy  programs    

Page 40: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Memory  Model  

•  Java  Memory  Model  (JMM)  – DRF  +  weak  semanHc  for  racy  programs    – Forbid  out-­‐of-­‐thin-­‐air    

•  C++0x  •  x86_TSO    •  C++  11/14  

Page 41: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Program  Analysis  

•  Goal:  automaHcally  detect/debug/fix  concurrency  errors,  and  test  concurrent  programs  

Program  Analysis  

Program   Useful  info  

Page 42: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Program  Analysis  

•  StaHc  analysis  vs  dynamic  analysis:  

Sta7c  analysis   Dynamic  analysis  

Analyze  staHc  code   Analyze  running  program  

Find  problems  in  any  execuHon   Find  problems  in  some  real  execuHon  

Sound:  no  false  negaHves*   Unsound:  false  negaHves  

Imprecise:  false  posiHves   Precise:  onen  no  false  posiHves  

Doesn’t  slow  running  program   Slows  execuHng  program  

Page 43: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Control  Flow  Graph  

Page 44: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Dataflow  Analysis  

•  Live  analysis:  Is  “x”  alive  at  point  p?  

•  Reaching  definiHons  •  Available  expressions  •  Busy  expressions  •  …  

Page 45: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Dataflow  Analysis  

Page 46: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Pointer  Analysis  •  What  memory  locaHons  can  a  pointer  expression  refer  to?  

•  E.g.,    int  x;    p  =  &x;  q  =  p;  

•  A  hard  problem,  but  is  essenHal  for  many  compiler  opHmizaHons  

•  Alias  analysis:  When  do  two  pointer  expressions  refer  to  the  same  storage  locaHon?    –  *p  and  *q  alias,  as  do  x  and  *p,  and  x  and  *q  

Page 47: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Call  Graph  

Page 48: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Dynamic  Profiling    

•  A  run-­‐Hme  technique  that  gathers  execuHon  informaHon    –  E.g.,  total  #  objects  created  during  the  execuHon  

•  How-­‐-­‐-­‐  via  program  instrumentaHon  

 void  main(String[]  s){          A  a  =  new  A(…);            for(…){                  B  b  =  new  B(…);            }    }  

long  totalObjs  =  0;      

totalObjs  ++;      

totalObjs  ++;      

print(totalObjs);  

Page 49: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Dynamic  Slicing  

•  Record  all  memory  accesses  and  their  dependence  relaHonships  

 •  ApplicaHons  

– Automated  debugging    – Performance  analysis  

 void  main(String[]  s){              a.f    =    …;                                …              c    =  b.f;    }  

0x23456789  

Page 50: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Context  Profiling  

•  Record  calling  contexts  for  method  invocaHons    

 

void  m(…){          bar(new  A());  //call  1  }  void  n(…){            bar  (new  B());  //call  2  }    void  bar(A  a){            a.f    =    …;              }  

m   n  

bar  

call  1   call  2  

Page 51: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Context  Profiling  

•  Record  calling  contexts  for  method  invocaHons    

 •  ApplicaHons  

– Context-­‐sensiHve  dynamic  analysis  

–  Interprocedural  compiler  opHmizaHon  m   n  

bar   bar  

void  m(…){          bar(new  A());  //call  1  }  void  n(…){            bar  (new  B());  //call  2  }    void  bar(A  a){            a.f    =    …;              }  

call  1   call  2  

Page 52: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Symbolic  ExecuHon  •  Use  symbolic  values,  instead  of  concrete  data  values  as  input  

•  Represent  the  values  of  program  variables  as  symbolic  expressions  over  the  symbolic  input  values.  

•  Each  symbolic  execuHon  path  stands  for  many  actually  program  runs  

•  Thus  can  cover  a  lot  more  of  the  program’s  execuHon  space  than  tesHng  can  

Page 53: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Symbolic  ExecuHon  

Page 54: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Model  Checking  

Page 55: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Important  DirecHons  

•  DeterminisHc  MulHthreading  •  DeterminisHc-­‐by-­‐default  programming  •  TransacHonal  Memory  

Page 56: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

DeterminisHc  MulHthreading  

•  How  to  make  concurrent  program  execuHons  determinisHc?  –  In  the  presence  of  data  races  –  Run  as  fast  as  possible  – Applicable  to  all  mulHthreaded  programs  

•  The  DMP  paper  [ASPLOS  2009]:  200  citaHons  •  Compiler/Library/RunHme:  

– DMP,  Kendo,  Dthread,  Parrot,  Grace,  CoreDet,  dOS,  Determinator,  RFDet  …  

Page 57: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

DeterminisHc-­‐by-­‐default  Programming  

•  Design  a  language  and  type  system  to  ensure  the  resulHng  program  is  always  determinisHc  

•  How  expressive  it  can  be?  •  How  fast?  

•  The  DPJ  paper  [OOPSLA  2009]:  270  citaHons  

Page 58: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

TransacHonal  Memory  •  No  lock-­‐based  synchronizaHon!  •  Simplify  concurrent  programming  by  grouping  operaHons  and  running  them  like  a  single  database  transacHon  

•  Upon  exit  of  a  transacHon  –  If  no  other  thread  concurrently  modified  the  same  data,  all  of  our  changes  will  simultaneously  be  visible    

– Otherwise,  discards  all  changes  and  roll  back  

Page 59: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

TransacHonal  Memory  

•  Sonware:  TinySTM,  DSTM2,  …  •  Hardware:  Intel  Haswell,  IBM  Blue  Gene/Q  

Hardware   So?ware  

Fast  (due  to  hardware  operaHons)   Slow  (due  to  sonware  validaHon/commit)  

Light  code  instrumentaHon   Heavy  code  instrumentaHon  

HW  buffers  keep  amount  of  metadata  low   Lots  of  metadata  

No  need  of  a  middleware   RunHme  library  needed  

Only  short  transacHons  allowed  (why?)   Large  transacHons  possible  

Page 60: Overviewof Concurrency’and’Program’Analysis’jeff/course/689_fall2014/overview.pdf · Shared’Memory’ • Threads’communicate’by’reading’and’wriHng’to’shared’

Specific  Domains  

•  Event-­‐driven  systems  (e.g.,  Android,  browsers)  •  Real-­‐Hme  embedded  systems  (e.g.,  cars,  aircrans,  medical  systems)  

•  GPGPU  compuHng  (CUDA,  OpenCL)