yi lin, steve blackburn the australian national university bypassing portability pitfalls of...
TRANSCRIPT
![Page 1: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/1.jpg)
Yi Lin, Steve BlackburnThe Australian National University
Bypassing Portability Pitfallsof High-level Low-level Programming
![Page 2: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/2.jpg)
IntroductionPortability issues of high-level low-level programming
2Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
![Page 3: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/3.jpg)
Program Portability
• Portability across platforms• Portability across runtimes
3
low-level code high-level languages
Introduction
Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
![Page 4: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/4.jpg)
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
![Page 5: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/5.jpg)
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
![Page 6: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/6.jpg)
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
![Page 7: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/7.jpg)
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
![Page 8: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/8.jpg)
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
![Page 9: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/9.jpg)
HLL Restrictionin Systems Programming
Observations, Design Concerns and Concrete RJava,
9Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
![Page 10: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/10.jpg)
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
![Page 11: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/11.jpg)
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
![Page 12: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/12.jpg)
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
![Page 13: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/13.jpg)
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
![Page 14: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/14.jpg)
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
![Page 15: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/15.jpg)
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
![Page 16: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/16.jpg)
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
![Page 17: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/17.jpg)
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
![Page 18: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/18.jpg)
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
![Page 19: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/19.jpg)
Translation into LLLCurrent Work, RJava Toolchain, RJava frontend
19Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
![Page 20: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/20.jpg)
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
![Page 21: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/21.jpg)
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
![Page 22: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/22.jpg)
Summary and Future WorkRJava Toolchain, frontend
22Lin & Blackburn | Bypassing Portability Pitfalls | VMIL’12
![Page 23: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/23.jpg)
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
![Page 24: Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming](https://reader038.vdocument.in/reader038/viewer/2022110205/56649cab5503460f9496d29f/html5/thumbnails/24.jpg)
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