SLIDE 1
Harry Xu May 2012 Complex, concurrent software Precision (no false - - PowerPoint PPT Presentation
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 2
SLIDE 3
Need to modify JVM
(e.g., object layout, GC, or ISA-level code)
Need to demonstrate realism
(usually performance)
SLIDE 4
Otherwise use RoadRunner, BCEL, Pin, LLVM, …
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
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
Guide Research Archive Research mailing list
Jikes RVM {
SLIDE 8
Guide Research Archive Research mailing list
Jikes RVM {
SLIDE 9
Jikes RVM source code Dynamic compilers Boot image writer
SLIDE 10
Jikes RVM source code Run with another JVM Dynamic compilers Boot image writer
SLIDE 11
Jikes RVM source code Boot image (native code + initial heap space) Run with another JVM Dynamic compilers Boot image writer
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
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
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
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
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
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
Jikes RVM source code Boot image (native code + initial heap space) Run with another JVM Dynamic compilers Boot image writer
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
Keeping track of stuff as the program executes?
Change application behavior (add instrumentation) Store per-object/per-field metadata Piggyback on GC
SLIDE 21
Bytecode Native code Baseline compiler
SLIDE 22
Bytecode Native code Baseline compiler Each bytecode several x86 instructions (BaselineCompilerImpl.java)
SLIDE 23
Bytecode Native code Baseline compiler Each bytecode several x86 instructions (BaselineCompilerImpl.java)
SLIDE 24
SLIDE 25
Bytecode Native code Baseline compiler Profiling Adaptive optimization system
SLIDE 26
Bytecode Native code Baseline compiler Profiling Adaptive optimization system Optimizing compiler (Faster) native code
SLIDE 27
Bytecode Native code Baseline compiler Profiling Adaptive optimization system Optimizing compiler (Faster) native code
SLIDE 28
Bytecode Optimizing compiler (Faster) native code
SLIDE 29
Bytecode (Faster) native code HIR LIR MIR Resembles bytecode Resembles assembly code Resembles typical compiler IR (3-address code)
SLIDE 30
Bytecode (Faster) native code HIR LIR MIR (Even faster) native code Opt levels: 0, 1, 2
SLIDE 31
Bytecode (Faster) native code HIR LIR MIR ExpandRuntimeServices.java Add instrumentation at reads, writes, allocation, synchronization
SLIDE 32
SLIDE 33
SLIDE 34
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
field0 field1 field2 header Low address High address
SLIDE 37
field0 field1 field2 type info block locking & GC Object reference
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
field0 field1 field2 type info block locking & GC Object reference Steal bits
SLIDE 40
field0 field1 field2 type info block locking & GC Object reference misc MiscHeader.java
SLIDE 41
field0 field1 field2 type info block locking & GC Object reference counter
SLIDE 42
field0 field1 field2 type info block locking & GC Object reference counter Magic! Compiles down to three x86 instructions
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
field0 field1 field2 type info block locking & GC Object reference counter What’s the problem with this code? 2
SLIDE 45
field0 field1 field2 type info block locking & GC Object reference counter 2
SLIDE 46
field0 field1 field2 type info block locking & GC Object reference not used
SLIDE 47
field0 field1 field2 type info block locking & GC Object reference not used Compiles down to three x86 instructions
SLIDE 48
field0 field1 field2 type info block locking & GC Object reference misc
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
Keeping track of stuff as the program executes?
Change application behavior (add instrumentation) Store per-object/per-field metadata Piggyback on GC
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
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
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
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
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
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
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
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
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
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
@Uninterruptible static void myMethod(Object o) { // No allocation or synchronization // No calls to interruptible methods }
SLIDE 62
@Uninterruptible static void myMethod(Object o) { currentThread.deferGC = true; Metadata m = new Metadata(); currentThread.deferGC = false; setMiscHeader(o, offset, m); }
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
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