Harry Xu May 2012 Complex, concurrent software Precision (no false - - PowerPoint PPT Presentation

harry xu may 2012 complex concurrent software precision
SMART_READER_LITE
LIVE PREVIEW

Harry Xu May 2012 Complex, concurrent software Precision (no false - - PowerPoint PPT Presentation

Harry Xu May 2012 Complex, concurrent software Precision (no false positives) Find real bugs in real executions Need to modify JVM (e.g., object layout, GC, or ISA-level code) Need to demonstrate realism (usually performance) Otherwise use


slide-1
SLIDE 1

Harry Xu May 2012

slide-2
SLIDE 2

Complex, concurrent software Precision (no false positives)

Find real bugs in real executions

slide-3
SLIDE 3

Need to modify JVM

(e.g., object layout, GC, or ISA-level code)

Need to demonstrate realism

(usually performance)

slide-4
SLIDE 4

Otherwise use RoadRunner, BCEL, Pin, LLVM, …

slide-5
SLIDE 5

Keeping track of stuff as the program executes?

 Change application behavior (add instrumentation)  Store per-object/per-field metadata  Piggyback on GC

slide-6
SLIDE 6

Keeping track of stuff as the program executes?

 JVM written in Java?!  Change application behavior (add instrumentation)  Store per-object/per-field metadata  Piggyback on GC  Uninterruptible code

slide-7
SLIDE 7

 Guide  Research Archive  Research mailing list

Jikes RVM {

slide-8
SLIDE 8

 Guide  Research Archive  Research mailing list

Jikes RVM {

slide-9
SLIDE 9

Jikes RVM source code Dynamic compilers Boot image writer

slide-10
SLIDE 10

Jikes RVM source code Run with another JVM Dynamic compilers Boot image writer

slide-11
SLIDE 11

Jikes RVM source code Boot image (native code + initial heap space) Run with another JVM Dynamic compilers Boot image writer

slide-12
SLIDE 12

Jikes RVM source code Boot image (native code + initial heap space) Run with another JVM Dynamic compilers Boot image writer Build configurations: BaseBase BaseAdaptive FullAdaptive FastAdaptive

slide-13
SLIDE 13

Jikes RVM source code Boot image (native code + initial heap space) Run with another JVM Dynamic compilers Boot image writer Build configurations: BaseBase (prototype) BaseAdaptive (prototype-opt) FullAdaptive (development) FastAdaptive (production)

slide-14
SLIDE 14

Jikes RVM source code Boot image (native code + initial heap space) Run with another JVM Dynamic compilers Boot image writer Build configurations: BaseBase BaseAdaptive FullAdaptive FastAdaptive Testing

slide-15
SLIDE 15

Jikes RVM source code Boot image (native code + initial heap space) Run with another JVM Dynamic compilers Boot image writer Build configurations: BaseBase BaseAdaptive FullAdaptive FastAdaptive Faster builds

slide-16
SLIDE 16

Jikes RVM source code Boot image (native code + initial heap space) Run with another JVM Dynamic compilers Boot image writer Build configurations: BaseBase BaseAdaptive FullAdaptive FastAdaptive Faster runs

slide-17
SLIDE 17

Jikes RVM source code Boot image (native code + initial heap space) Run with another JVM Dynamic compilers Boot image writer Build configurations: BaseBase BaseAdaptive FullAdaptive FastAdaptive Performance

slide-18
SLIDE 18

Jikes RVM source code Boot image (native code + initial heap space) Run with another JVM Dynamic compilers Boot image writer

slide-19
SLIDE 19

Edit with Eclipse (see Guide)

Jikes RVM source code Boot image (native code + initial heap space) Run with another JVM Dynamic compilers Boot image writer

slide-20
SLIDE 20

Keeping track of stuff as the program executes?

 Change application behavior (add instrumentation)  Store per-object/per-field metadata  Piggyback on GC

slide-21
SLIDE 21

Bytecode Native code Baseline compiler

slide-22
SLIDE 22

Bytecode Native code Baseline compiler Each bytecode  several x86 instructions (BaselineCompilerImpl.java)

slide-23
SLIDE 23

Bytecode Native code Baseline compiler Each bytecode  several x86 instructions (BaselineCompilerImpl.java)

slide-24
SLIDE 24
slide-25
SLIDE 25

Bytecode Native code Baseline compiler Profiling Adaptive optimization system

slide-26
SLIDE 26

Bytecode Native code Baseline compiler Profiling Adaptive optimization system Optimizing compiler (Faster) native code

slide-27
SLIDE 27

Bytecode Native code Baseline compiler Profiling Adaptive optimization system Optimizing compiler (Faster) native code

slide-28
SLIDE 28

Bytecode Optimizing compiler (Faster) native code

slide-29
SLIDE 29

Bytecode (Faster) native code HIR LIR MIR Resembles bytecode Resembles assembly code Resembles typical compiler IR (3-address code)

slide-30
SLIDE 30

Bytecode (Faster) native code HIR LIR MIR (Even faster) native code Opt levels: 0, 1, 2

slide-31
SLIDE 31

Bytecode (Faster) native code HIR LIR MIR ExpandRuntimeServices.java Add instrumentation at reads, writes, allocation, synchronization

slide-32
SLIDE 32
slide-33
SLIDE 33
slide-34
SLIDE 34
slide-35
SLIDE 35

Keeping track of stuff as the program executes?

 Change application behavior (add instrumentation)  Store per-object/per-field metadata  Piggyback on GC

slide-36
SLIDE 36

field0 field1 field2 header Low address High address

slide-37
SLIDE 37

field0 field1 field2 type info block locking & GC Object reference

slide-38
SLIDE 38

field0 field1 field2 type info block locking & GC Object reference Array length elem0 elem1 type info block locking & GC Object reference

slide-39
SLIDE 39

field0 field1 field2 type info block locking & GC Object reference Steal bits

slide-40
SLIDE 40

field0 field1 field2 type info block locking & GC Object reference misc MiscHeader.java

slide-41
SLIDE 41

field0 field1 field2 type info block locking & GC Object reference counter

slide-42
SLIDE 42

field0 field1 field2 type info block locking & GC Object reference counter Magic! Compiles down to three x86 instructions

slide-43
SLIDE 43

field0 field1 field2 type info block locking & GC Object reference counter Gotcha: can’t actually use LSB of leftmost word 2

slide-44
SLIDE 44

field0 field1 field2 type info block locking & GC Object reference counter What’s the problem with this code? 2

slide-45
SLIDE 45

field0 field1 field2 type info block locking & GC Object reference counter 2

slide-46
SLIDE 46

field0 field1 field2 type info block locking & GC Object reference not used

slide-47
SLIDE 47

field0 field1 field2 type info block locking & GC Object reference not used Compiles down to three x86 instructions

slide-48
SLIDE 48

field0 field1 field2 type info block locking & GC Object reference misc

slide-49
SLIDE 49

field0 field1 field2 type info block locking & GC Object reference misc What if GC moves object? What if GC collects object?

slide-50
SLIDE 50

Keeping track of stuff as the program executes?

 Change application behavior (add instrumentation)  Store per-object/per-field metadata  Piggyback on GC

slide-51
SLIDE 51

field0 field1 field2 type info block locking & GC Object reference // Initially worklist populated with roots while worklist has elements Object obj = worklist.pop() foreach reference field obj.f

  • bj.f = markAndPossiblyCopy(obj.f)

worklist.push(obj.f)

slide-52
SLIDE 52

field0 field1 field2 type info block locking & GC Object reference // Initially worklist populated with roots while worklist has elements Object obj = worklist.pop() foreach reference field obj.f

  • bj.f = markAndPossiblyCopy(obj.f)

worklist.push(obj.f)

slide-53
SLIDE 53

field0 field1 field2 type info block locking & GC Object reference // Initially worklist populated with roots while worklist has elements Object obj = worklist.pop() foreach reference field obj.f

  • bj.f = markAndPossiblyCopy(obj.f)

worklist.push(obj.f)

slide-54
SLIDE 54

field0 field1 field2 type info block locking & GC Object reference misc // Initially worklist populated with roots while worklist has elements Object obj = worklist.pop() foreach reference field obj.f

  • bj.f = markAndPossiblyCopy(obj.f)

worklist.push(obj.f)

  • bj.misc = markAndPossiblyCopy(obj.f)

worklist.push(obj.misc)

slide-55
SLIDE 55

field0 field1 field2 type info block locking & GC Object reference misc // Initially worklist populated with roots while worklist has elements Object obj = worklist.pop() foreach reference field obj.f

  • bj.f = markAndPossiblyCopy(obj.f)

worklist.push(obj.f)

  • bj.misc = markAndPossiblyCopy(obj.f)

worklist.push(obj.misc)

slide-56
SLIDE 56

field0 field1 field2 type info block locking & GC Object reference misc // Initially worklist populated with roots while worklist has elements Object obj = worklist.pop() foreach reference field obj.f

  • bj.f = markAndPossiblyCopy(obj.f)

worklist.push(obj.f)

  • bj.misc = markAndPossiblyCopy(obj.f)

worklist.push(obj.misc) TraceLocal.scanObject()

slide-57
SLIDE 57

field0 field1 field2 type info block locking & GC Object reference // Initially worklist populated with roots while worklist has elements Object obj = worklist.pop() foreach reference field obj.f

  • bj.f = markAndPossiblyCopy(obj.f)

worklist.push(obj.f)

slide-58
SLIDE 58

field0 field1 field2 type info block locking & GC Object reference // Initially worklist populated with roots while worklist has elements Object obj = worklist.pop() foreach reference field obj.f

  • bj.f = markAndPossiblyCopy(obj.f)

worklist.push(obj.f) TraceLocal.processNode()

slide-59
SLIDE 59

Keeping track of stuff as the program executes?

 Change application behavior (add instrumentation)  Store per-object/per-field metadata  Piggyback on GC  Uninterruptible code

slide-60
SLIDE 60

 Normal application code can be interrupted

  • Allocation  GC
  • Synchronization & yield points  join a GC

 Some VM code shouldn’t be interrupted

  • Heap etc. in inconsistent state

 Most instrumentation can’t be interrupted

  • Reads & writes aren’t GC-safe points
slide-61
SLIDE 61

@Uninterruptible static void myMethod(Object o) { // No allocation or synchronization // No calls to interruptible methods }

slide-62
SLIDE 62

@Uninterruptible static void myMethod(Object o) { currentThread.deferGC = true; Metadata m = new Metadata(); currentThread.deferGC = false; setMiscHeader(o, offset, m); }

slide-63
SLIDE 63

Need to modify JVM internals Need to demonstrate realism

 Guide  Research Archive  Research mailing list

Jikes RVM

Overview of other tasks & components Dynamic analysis examples Help (especially for novices)

slide-64
SLIDE 64

Object layout

  • Extra bits or words in header
  • Stealing bits from references
  • Discuss magic here

Adding instrumentation

  • Baseline & optimizing compilers
  • Allocation sites; reads & writes
  • Inlining instrumentation

Garbage collection

  • Piggybacking on GC
  • New spaces

Low-level stuff

  • Uninterruptible code
  • Walking the stack

Concurrency

  • Atomic stores
  • Thread-local data