a non readable h eap (and why you might want one )
DESCRIPTION
A Non Readable H eap (and why you might want one ) Laurence Hellyer Computing Laboratory, University of Kent, UK. A Non Readable Heap. ?. ?. ?. ?. ?. Primitive Write Barriers. HEAP’. HEAP’. HEAP. HEAP. Object Foo ’ { Int Bar; }. Object Foo ’ { Int Bar = 1; }. - PowerPoint PPT PresentationTRANSCRIPT
• A Non Readable Heap• (and why you might want one)
• Laurence HellyerComputing Laboratory,University of Kent, UK
A Non Readable Heap
Page 2
?? ?? ?
HEAP’
Object Foo’ {Int Bar;}
HEAP’
Object Foo’ {Int Bar = 1;}
[email protected] MM-NET 2009 Presentation
Primitive Write Barriers
HEAP
Object Foo {Int Bar;}
Foo.Bar = 1;
Primitive Write Barrier
HEAP
Object Foo {Int Bar = 1;}
Page 3
[email protected] ISSM WACI 2009 Presentation
Write Protected Heap
• Catch all non-conforming writes
• Fatal exception as soon as the write is made
• Timely stack trace allows quick pinpointing of non-confirming code
• Almost a pure Java approach
• Doesn’t rely on external tool
Page 4
[email protected] ISSM WACI 2009 Presentation
Non Readable Heap
• Why?
• Last remaining class of barriers to implement in JikesRVM is primitive read barriers
• A non readable heap ensures that all heap accesses must go via an appropriate barrier
Page 5
• Other benefits?
• Catch errors in JNI code that cause direct access to the heap
HEAP
Object Foo {Field Bar;}
HEAP
Object Foo {Field Bar = X;}
[email protected] ISSM WACI 2009 Presentation
Debugging Framework: A Write Protected Heap
Foo.Bar = X;
Write Barrier
Page 7
HEAP
Object Foo {Field Bar;}
HEAP
Object Foo {Field Bar = X;}
[email protected] ISSM WACI 2009 Presentation
Debugging Framework: A Write Protected Heap
Write Barrier
Page 8
[email protected] ISSM WACI 2009 Presentation
Implementation Challenges
• Multiple threads
• Primitive WB’s
• Performance
Page 9
T1
T2
WBFoo
WBFoo
WBFoo
[email protected] ISSM WACI 2009 Presentation
Implementation Challenges
• Multiple threads
• Primitive WB’s
• Performance
Page 10
T1
T2 WBFoo
[email protected] ISSM WACI 2009 Presentation
Implementation Challenges
• Multiple threads
• Primitive WB’s
• Performance
Page 11
T1
T2
WBFoo
WFoo
MMAP’d
Alias
HEAP
Object Foo {Field Bar;}
HEAP
Object Foo {Field Bar;}
[email protected] ISSM WACI 2009 Presentation
Implementation
ALIASED HEAP
Object Foo {Field Bar;}
1. Pages reserved for heap as normal – but marked read only.2. All reads occur on write-protected heap.3. A virtual alias of the heap is created in address space.
•Alias address mapping is writable•Virtual alias only occupies address space
•Backed by same physical pages•Aliased heap is only known to WB
Page 12
HEAP
Object Foo {Field Bar = X;}
MMAP’d
Alias ALIASED HEAPALIASED HEAP
Object Foo {Field Bar;}
HEAP
Object Foo {Field Bar;}
[email protected] ISSM WACI 2009 Presentation
Implementation
Foo.Bar = X;
Write Barrier
Page 13
Object Foo {Field Bar = X;}
MMAP’d
Alias
HEAP
Object Foo {Field Bar;}
HEAP
Object Foo {Field Bar = X;}
[email protected] ISSM WACI 2009 Presentation
Implementation
Write Barrier
ALIASED HEAP
Object Foo {Field Bar = X;}
Page 14
MMAP’d
Alias
HEAP
Object Foo {Field Bar;}
HEAP
Object Foo {Field Bar = X;}
[email protected] ISSM WACI 2009 Presentation
32 bit Address Limitation
ALIASED HEAP
Object Foo {Field Bar = X;}
Page 15
•To avoid exhausting virtual address space, only mmap the page of the field we are writing
•And the next page in case it’s an unaligned double
•Each thread has its own aliased window
•Many threads can have own mapping to same underlying physical page
Thread local
[email protected] ISSM WACI 2009 Presentation
Performance and Testing
Page 16
• Useful benchmarks to ensure correct barrier usage:
• DaCapo Chart:• No debugging framework: 10 seconds• Debugging framework: 552 seconds
• DaCapo Hsqldb• No debugging framework: 6 seconds• Debugging framework: 625 seconds
• JVM98 _200_check:
• No debugging framework: 0.1 second• Debugging framework: 2 seconds• (Total invocation time goes from 1 10 seconds)
[email protected] ISSM WACI 2009 Presentation
Current and Future Uses
Page 17
• Successfully used to implement primitive write barriers in JikesRVM Baseline and Opt compilers
• Will be made available shortly for other researchers
• A potential future use – debugging primitive read barriers
• Heap could be read and write protected
• Aliased address range of heap would allow conforming code to read heap
• Non-conforming code would SIGSEGV and produce stack trace