240 likes | 514 Views
Bypassing Portability Pitfalls of High-level Low-level Programming. Yi Lin, Steve Blackburn The Australian National University. Introduction Portability issues of high-level low-level programming. Introduction. Program Portability. Portability across platforms Portability across runtimes.
E N D
BypassingPortabilityPitfallsof High-levelLow-level Programming Yi Lin, Steve Blackburn The Australian National University
IntroductionPortability issues of high-level low-level programming Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Introduction Program Portability • Portability across platforms • Portability across runtimes low-level code high-level languages Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Introduction 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 Robustness Productivity Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Introduction 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 Code reusability Development Cost Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Introduction 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 Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Introduction 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 facilitatetranslation to LLL Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Introduction 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 Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
HLL Restrictionin Systems ProgrammingObservations, Design Concerns and Concrete RJava, Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
HLL Restriction Observations Studied use of language features in four non-trivial contexts unrestricted most restricted Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
HLL Restriction 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 Lin & 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 • 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 Lin & 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 Lin & 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 • @RJavaCoreRuleset • Predefined ruleset • Defines RJava • Minimum restriction @RestrictionRule public @interface NoDynamicLoading { } @RestrictionRuleset @NoDynamicLoading @NoReflection @NoException @NoCastOnMagicType public @interface RJavaCore { } @RJavaCore public class SomeRJavaClass { } compiler intrinsics checking rule Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
HLL Restriction Example: MMTk with RJava @RestrictedRuleset @RJavaCore @NoRunTimeAllocation @NoClassLibrary @Uninterruptible public @interface MMTk { } MMTk codebase disallow infinite regress disallow thread switching Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
HLL Restriction Example: MMTk with RJava (cont.) @RestrictedRuleset @MMTk @NoVirtualMethod public @interface MMTkFastpath { } fast path MMTk codebase avoid dynamic dispatch Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
HLL Restriction Example: MMTk with RJava (cont.) @RestrictedRuleset @MMTkFastpath @NoPutfield @NoPutstatic public @interface MMTkWriteBarrier { } write barrier MMTk codebase fast path disallow infinite regress Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Translation into LLLCurrent Work, RJava Toolchain, RJava frontend Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Translating R-HLL to LL Bypass Approach RJava Toolchain: Static constraint checking tool Frontend: RJava into LLL 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 Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Summary and Future WorkRJava Toolchain, frontend Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
Summary & Future 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 Lin & 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/RPythonapproach • Better VM portability Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12