yi lin, steve blackburn the australian national university bypassing portability pitfalls of...
TRANSCRIPT
Yi Lin, Steve BlackburnThe Australian National University
Bypassing Portability Pitfallsof High-level Low-level Programming
IntroductionPortability issues of high-level low-level programming
2Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Program Portability
• Portability across platforms• Portability across runtimes
3
low-level code high-level languages
Introduction
Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
High-level Low-level Programming
• High-level languages (HLL)✔ Correctness (memory-safety, type-safety)✔ Software engineering tools: a(abstraction, encapsulation)
• Applied to low-level systems programming
4
Robustness Productivity
Introduction
Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
The Portability Pitfalls of HLLL
✘Hardware portability– Low-level code is hardware-sensitive
✘Portability between runtimes– High-level languages need to be extended, and cannot run on a stock
runtime
5
Code reusability Development Cost
Introduction
Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Example: Portable MMTk
Started in JikesRVM, ported to VMKit, Rotor
Shortcomings of previous porting– Inconvenient/slow integration with legacy code: FFI– Repeated work for each porting.
Language extensions need to be implemented for different targets
6
Introduction
Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Possibility of Translation Into LLL
✔ Portable low-level languages (LLL)✗Difficult to map full HLL into LLL
– Dynamic dispatch, exceptions, dynamic dispatch, GC, etc.
✔ High-level low-level lang. is restricted– Restrictions may facilitate translation to LLL
7
Introduction
Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Presentation Outline
Two topics, key to our approach:• HLL restrictions in systems programming• Translation into LLL
Outcome: RJava (restricted subset of Java)– Application to VM implementation– Explicit restriction definition– High-level benefits– Improved portability
8Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Introduction
HLL Restrictionin Systems Programming
Observations, Design Concerns and Concrete RJava,
9Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Observations
MMTk B/L Compiler JikesRVM Eclipse
Lines of Code 29933 17762 113359 n/a
new / LOC 0.59% 0.86% 2.40% 4.47%
throws / LOC - - 0.21% 1.33%
import java.* / LOC - 0.03% 0.40% 0.82%
10
most restricted unrestricted
HLL Restriction
Studied use of language features in four non-trivial contexts
Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Observations (cont.)
Restrictions exist for:• Correctness
– No GC/allocation in Memory manager g use raw memory– No threading/scheduling in Scheduler g use primitive locks
• Performance– Avoid dynamic dispatch in performance-critical areas– Avoid array bound checks in uninterruptible area
11Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
HLL Restriction
Observations (cont.)
Benefits of restricted HLL• Benefits reduced, principally static
– Type/memory-safety at source code level– Software engineering tools
• Restrictions are applied to limited scope– Maximizing benefits
12
Restricted HLL has advantages over LLL
Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
HLL Restriction
Design Concerns of RJava
• Expressiveness vs. Restriction– Mappability to LL– We do not introduce more restrictions than necessary
• Fixed vs. Flexible Restrictions for scope– Restrictions are different among different VM components– Restrictions may be still different within one VM component
13Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
HLL Restriction
Concrete RJava: Extensions
vmmagic extensions [1]• Type-system extensions
– Raw storage– Unboxed types
• Semantic extensions– Intrinsic functions– Semantic regimes
[1] Frampton et al., VEE09
14Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
HLL Restriction
Concrete RJava: Restrictions
• Restriction Rules– Forbid language features– Allow static checking
• Restriction Rulesets– 1-to-1 mapping with scopes
• @RJavaCore Ruleset– Predefined ruleset– Defines RJava – Minimum restriction
15
@RestrictionRule
public@interface NoDynamicLoading {}
compiler intrinsics checking rule
@RestrictionRuleset
@NoDynamicLoading@NoReflection@NoException@NoCastOnMagicTypepublic@interface RJavaCore {}
@RJavaCorepublic class SomeRJavaClass {}
Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
HLL Restriction
Example: MMTk with RJava
16
MMTk codebase
@RestrictedRuleset
@RJavaCore@NoRunTimeAllocation@NoClassLibrary@Uninterruptiblepublic @interface MMTk {}
disallow infinite regress
disallow thread switching
Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
HLL Restriction
Example: MMTk with RJava (cont.)
17
@RestrictedRuleset
@MMTk@NoVirtualMethodpublic @interface MMTkFastpath {}
avoid dynamic dispatch
fast path
MMTk codebase
Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
HLL Restriction
Example: MMTk with RJava (cont.)
18
@RestrictedRuleset
@MMTkFastpath@NoPutfield@NoPutstaticpublic @interface MMTkWriteBarrier {}
disallow infinite regress
MMTk codebase
fast path
write barrier
Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
HLL Restriction
Translation into LLLCurrent Work, RJava Toolchain, RJava frontend
19Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Bypass Approach
20
RJava Toolchain:1. Static constraint checking tool2. Frontend: RJava into LLL3. Backend: LLL into executable
Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Translating R-HLL to LL
RJava Frontend
• Generating plain LL code, with no dependency on Java runtime.
• Besides syntax mapping, the frontend needs to: – Implement compiler intrinsics– Unbox magic types– Remove dependencies on class library
21Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Translating R-HLL to LL
Summary and Future WorkRJava Toolchain, frontend
22Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Summary
• Portability pitfalls of HL-LL programming– Affecting code reusability and development cost– Possibility of low-level language bypass
• HLL restriction and RJava– Observations, design concerns, concrete RJava
• LLL bypass and RJava toolchain
23Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Summary & Future
Future Work - Bootstrapping Java VM
• VMKit– RJava frontend to LLVM, use to compile MMTk
• Bootstrapping Java VM– Interpreter/baseline compiler in RJava– Similar to PyPy/RPython approach– Better VM portability
24Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Summary & Future