Demystifying Magic High-Level Low-Level Programming

Slides:



Advertisements
Similar presentations
Yi Lin, Steve Blackburn The Australian National University Bypassing Portability Pitfalls of High-level Low-level Programming.
Advertisements

Extensibility, Safety and Performance in the SPIN Operating System Presented by Allen Kerr.
The Java Language. Topics of this Course  Introduction to Java  The Java Language  Object Oriented Programming in Java  Exceptions Handling  Threads.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Java for High Performance Computing Jordi Garcia Almiñana 14 de Octubre de 1998 de la era post-internet.
Chapter 13 Embedded Systems
Peter Juszczyk CS 492/493 - ISGS. // Is this C# or Java? class TestApp { static void Main() { int counter = 0; counter++; } } The answer is C# - In C#
COMP25212: Virtualization Learning Objectives: a)To describe aims of virtualization - in the context of similar aims in other software components b)To.
Programming Languages and Design Lecture 7 Subroutines and Control Abstraction Instructor: Li Ma Department of Computer Science Texas Southern University,
Ranga Rodrigo. The purpose of software engineering is to find ways of building quality software.
Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling.
Chapter 3.5 Memory and I/O Systems. 2 Memory Management Memory problems are one of the leading causes of bugs in programs (60-80%) MUCH worse in languages.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Abstraction Without Guilt Steve Blackburn Australian National University.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan.
Writing Systems Software in a Functional Language An Experience Report Iavor Diatchki, Thomas Hallgren, Mark Jones, Rebekah Leslie, Andrew Tolmach.
Processes Introduction to Operating Systems: Module 3.
The Fail-Safe C to Java translator Yuhki Kamijima (Tohoku Univ.)
Copyright © Genetic Computer School 2008 Computer Systems Architecture SA 7- 0 Lesson 7 Memory Management.
1 Process Description and Control Chapter 3. 2 Process A program in execution An instance of a program running on a computer The entity that can be assigned.
Layers Architecture Pattern Source: Pattern-Oriented Software Architecture, Vol. 1, Buschmann, et al.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Android Mobile Application Development
Object Oriented Programming in
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Module 3: Operating-System Structures
Kernel Design & Implementation
Chapter 14: System Protection
Memory Protection: Kernel and User Address Spaces
Operating Systems : Overview
Chapter 12: File System Implementation
Naming and Binding A computer system is merely a bunch of resources that are glued together with names Thus, much of system design is merely making choices.
Presentation by Omar Abu-Azzah
Software Design and Architecture
Operating System Structure
Lecture 1 Runtime environments.
Introduction Enosis Learning.
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
CSCI/CMPE 3334 Systems Programming
Chapter 2: Operating-System Structures
Memory Protection: Kernel and User Address Spaces
Introduction Enosis Learning.
Memory Protection: Kernel and User Address Spaces
Memory Protection: Kernel and User Address Spaces
Chapter 3: Operating-System Structures
The Procedure Abstraction Part I: Basics
More Object-Oriented Programming
Basic Concepts Protection: Security:
Lecture Topics: 11/1 General Operating System Concepts Processes
Operating Systems : Overview
Chapter 2: Operating-System Structures
Operating Systems : Overview
Java Programming Introduction
The Challenge of Cross - Language Interoperability
Operating Systems : Overview
Java History, Editions, Version Features
Introduction to Virtual Machines
Lecture 1 Runtime environments.
System calls….. C-program->POSIX call
Introduction to Virtual Machines
CS703 - Advanced Operating Systems
Chapter 2: Operating-System Structures
CSc 453 Interpreters & Interpretation
Memory Protection: Kernel and User Address Spaces
Advanced Operating Systems (CS 202) Operating System Structure
JIT Compiler Design Maxine Virtual Machine Dhwani Pandya
Charles Weems and Tim Richards University of Massachusetts Amherst
Presentation transcript:

Demystifying Magic High-Level Low-Level Programming Jennifer Sartor Daniel Frampton, Steve Blackburn, Perry Cheng, Robin Garner, David Grove, Eliot Moss, Sergey Salishev From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk The Problem Systems programmers: strive for reliability, security, maintainability depend on performance and transparent access to low-level primitives Abstraction: Enables the former Typically obstructs the latter From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk The Goal Abstraction without guilt. [Ken Kennedy] From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Revolution From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Why “In order to manage the complexity of software systems, I find it necessary to partition my concerns, and deal with them separately. A major set of concerns is the efficient allocation of a whole variety of resources, but I don’t worry about all resources all the time. Efficient allocation of registers is important, but quite separable from memory management, … file management, etc. While I am programming any one of these I would like to take the others for granted.” From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Why Not “A person designing and implementing an operating system, … is trying to make a given collection of processors, storage media, and i/o devices work together reliably, efficiently, and conveniently. The operation of these devices is his problem. It is unclear to us why he would ever want to obscure the exact nature of this hardware behind the constructs of a higher-level language.” From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Why (1975) …but is the problem still relevant today? … James J. Horning, Yes! High level languages should be used to write systems software. ACM Annual Conference/Annual Meeting Proceedings of the 1975 Annual Conference. From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Why (1975) …but is the problem still relevant today? … James J. Horning, Yes! High level languages should be used to write systems software. ACM Annual Conference/Annual Meeting Proceedings of the 1975 Annual Conference. From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Why Not (1972) …but is the problem still relevant today? … J.G. Fletcher, On the appropriate language for system programming. ACM SIGPLAN Notices, Volume 7, Number 7, 1972 From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Why The 70s Shift to C? Better language design Better language implementation More complex software More complex hardware More hardware (portability) Charles Landau, On high-level languages for system programming ACM SIGPLAN Notices, Volume 11, Issue 1,1976 From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Revolution II ? From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk A New Revolution? Change continues heterogeneous multi-core? more complex software Higher-level languages type safe memory safe strong abstractions over hardware From Frampton et al.'s VEE'09 Talk

Discussion Should we do low-level programming in high-level languages? Pros? Cons? Layers of abstraction Performance? High-level – easier for synchronization?, memory manage

From Frampton et al.'s VEE'09 Talk Solutions? Fortify low-level languages (C/C++) Memory safety (e.g., cons. GC, talloc) Idioms (e.g., restrictive use of types) Tools (e.g., Valgrind’s memcheck) Use a Systems PL BLISS, Modula-3, Cyclone Use two languages FFI’s such as JNI & PInvoke Extend a high-level language Jikes RVM extends Java From Frampton et al.'s VEE'09 Talk

Our (Small) Battle for the Revolution From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Our Approach Key Principle: Containment Minimize exposure to low-level coding Extensibility Requirements change quickly Languages change slowly Encapsulation Contained low-level semantics Fine-grained lowering of semantics Minimize impedance Separation of concerns FFIs = coarse-grained, performance suffers because impedance mismatch between 2 languages Now can optimize with high level compiler, only lowering for precise low-level concern. From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Our Framework Extend semantics Intrinsic methods Controlling semantics Scoped semantic changes Extend types box/unbox, ref/value, arch. sizes, etc Prefer to retain syntax (pragmatism) Existing front-end tools useable Ex: cache prefetch, invalidate Ex: new(), suspend GC yield Intrinsic functions to directly reflect the required semantics – add operations not expressible in high-level lang Semantic regimes to suspend language-imposed abstractions From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Java Version void prefetchObjects( ?!? buffer) { for(int i=0;i<buffer.length;i++) { ?!? current = buffer[i]; ?!? } void prefetchObjects( OOP *buffer, int size) { for(int i=0;i < size;i++){ OOP o = buffer[i]; asm volatile( "prefetchnta (%0)" :: "r" (o)); } From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk “Magic” in JikesRVM Raw access to memory? Use int and “magic” (peek & poke) Use ADDRESS macro (as int or long) Use magical Address type (~= void*) Use ObjectReference magic type More strongly typed Abstracts over mechanism (handle/pointer) From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Both Versions @NoBoundsCheck void prefetchObjects( ObjectReference[] buffer) { for(int i=0;i<buffer.length;i++) { ObjectReference current = buffer[i]; current.prefetch(); } void prefetchObjects( OOP *buffer, int size) { for(int i=0;i < size;i++){ OOP o = buffer[i]; asm volatile( "prefetchnta (%0)" :: "r" (o)); } From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Summary Higher-languages for low-level coding We propose a framework Extensible semantics (don’t bake in) Containment of semantic change Extend types From Frampton et al.'s VEE'09 Talk

Do You Buy It? Anecdotal No experimental results Advocate it because that’s how they’ve done it? Requires deep-knowledge of JVM and low-level needs, compiler cooperation

From Frampton et al.'s VEE'09 Talk Questions? Abstraction without guilt. [Ken Kennedy] From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Our “Battleground” Jikes RVM Java-in-Java Virtual Machine Combined proven and unproven methods Higher-level abstractions Type safety Memory safety But what about the cost... Abstraction without guilt? From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk A Concrete Example void prefetchObjects(OOP *buffer, int size) { for(int i=0; i < size; i++) { OOP current = buffer[i]; asm volatile("prefetchnta (%0)" :: "r" (current)); } From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk A Concrete Example void prefetchObjects(OOP *buffer, int size) { for(int i=0; i < size; i++) { OOP current = buffer[i]; asm volatile("prefetchnta (%0)" :: "r" (current)); } From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk A Concrete Example void prefetchObjects(OOP *buffer, int size) { for(int i=0; i < size; i++) { OOP current = buffer[i]; asm volatile("prefetchnta (%0)" :: "r" (current)); } From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk “Magic” in JikesRVM Raw access to memory? Use int and “magic” (peek & poke) int ref; int value = VM_Magic.loadIntAtOffset(ref, offset); From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk “Magic” in JikesRVM Raw access to memory? Use int and “magic” (peek & poke) Use ADDRESS macro (as int or long) ADDRESS ref; int value = VM_Magic.loadIntAtOffset(ref, offset); From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk “Magic” in JikesRVM Raw access to memory? Use int and “magic” (peek & poke) Use ADDRESS macro (as int or long) Use magical Address type (~= void*) Typed; magic on “instance” Address ref; int value = ref.loadInt(offset); From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Java Version void prefetchObjects( ObjectReference[] buffer) { for(int i=0;i<buffer.length;i++) { ObjectReference current = buffer[i]; ?!? } void prefetchObjects( OOP *buffer, int size) { for(int i=0;i < size;i++){ OOP o = buffer[i]; asm volatile( "prefetchnta (%0)" :: "r" (o)); } From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Intrinsics Contract between user and compiler Implement semantics beyond language Requires co-operation of compiler writer Canonical intrinsics class ObjectReference { ... @Intrinsic{Prefetch} void prefetch() {} // empty } Express intrinsic abstractly e.g., Intermediate language Intrinsics Prefetch LoadInt ... From Frampton et al.'s VEE'09 Talk

Java Version Other performance overheads? void prefetchObjects( ObjectReference[] buffer) { for(int i=0;i<buffer.length;i++) { ObjectReference current = buffer[i]; current.prefetch(); } void prefetchObjects( OOP *buffer, int size) { for(int i=0;i < size;i++){ OOP o = buffer[i]; asm volatile( "prefetchnta (%0)" :: "r" (o)); } Other performance overheads? From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Java Version @NoBoundsCheck void prefetchObjects( ObjectReference[] buffer) { for(int i=0;i<buffer.length;i++) { ObjectReference current = buffer[i]; current.prefetch(); } void prefetchObjects( OOP *buffer, int size) { for(int i=0;i < size;i++){ OOP o = buffer[i]; asm volatile( "prefetchnta (%0)" :: "r" (o)); } From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Semantic Regimes Scoped semantic change Additive UncheckedCast (allow certain intrinsics) Subtractive NoNew (allocation via new() not permitted) Other SpillAllRegisters NoGCYield NoBoundsChecks From Frampton et al.'s VEE'09 Talk

ObjectReference Overhead? Classes are heap allocated and passed-by-reference @Unboxed class ObjectReference { ... @Intrinsic{Prefetch} void prefetch() { ... } } No dynamic information (vtable, etc) essentially a C struct From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Type System Extension @Unboxed types Remove per-instance typing (struct) Explicit value/reference types Typed pointers (drivers, external data) Control field layout Externally defined interfaces? Alternative to marshalling, etc.? What about new primitives? @RawStorage Native width backing data Only accessed with intrinsics From Frampton et al.'s VEE'09 Talk

ObjectReference Abstraction Insulates from implementation Handles? class ObjectReference { int handle; void prefetch() { getPayload().prefetch(); } Address getPayload() { ... } From Frampton et al.'s VEE'09 Talk

ObjectReference Abstraction Insulates from implementation Handles? class ObjectReference { int handle; void prefetch() { getPayload().prefetch(); } Address getPayload() { ... } From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Abstraction Get abstraction level for the talk right  From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Yes! High level languages should be used to write systems software James Horning, ACM Annual Conference/Annual Meeting Proceedings of the 1975 Annual Conference On the appropriate language for system programming ACM SIGPLAN Notices, Volume 7, Number 7, 1972 From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Issues Still Relevant? From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Spot The Bug… logmessage("DEBUG: fd: %d select(): fd %d is ready for read\n", sockfd, sockfd); /* read as much data as we can */ rres = w_read(sockfd,buf[sockfd]); switch (rres) { case -1: logmessage("DEBUG: fd: %d select(): fd %d is ready for read\n", sockfd, sockfd); /* read as much data as we can */ rres = w_read(sockfd,buf[sockfd],MAXLINE); switch (rres) { case -1: From Frampton et al.'s VEE'09 Talk

Extending: Long History Modula-3 SPIN Java JikesRVM, OVM, Moxie, DRLVM (C/C++ VM) C# Bartok, Singularity usually in the context of runtime research access to the language/runtime complex systems programming task From Frampton et al.'s VEE'09 Talk

Production Virtual Machine ObjectReference Abstraction Power of Abstraction Allows alternate implementations Instrumentation Virtualization Production Virtual Machine Garbage Collector ObjectReference Abstraction (zero overhead) Physical Memory From Frampton et al.'s VEE'09 Talk

Virtualized ObjectReference Abstraction Annotated Simulated Memory Power of Abstraction Allows alternate implementations Instrumentation Virtualization GC Debugging Harness Garbage Collector Virtualized ObjectReference Abstraction Annotated Simulated Memory From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Type System Extension Raw storage User-defined backing data Support unboxing/Boxing Remove per-instance typing (eg no virtual function table ptr; yield a struct) Explicit value/reference types Typed pointers Field layout @RawStorage(lengthInWords=true, length=1) class Address { … byte loadByte(); void storeByte(bytevalue); } foo foo* (foo) foo From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Considerations Low-level coding is the exception not the rule Huge range of low-level details not an all-or-nothing requirement Lift the level of abstraction Maintain flexibility Languages change slowly Requirements change quickly Pragmatic From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Defining Terms High-level language type safe memory safe strong abstractions over hardware Low-level programming requires transparent, efficient access to underlying hardware and/or OS, unimpeded by abstractions. From Frampton et al.'s VEE'09 Talk

From Frampton et al.'s VEE'09 Talk Roadmap 10 years of experience mostly in runtime development broader applications? Simple unboxed types Address, ObjectReference, Word, etc. Semantic regimes NoBoundsChecks, etc Excellent performance Still working on: value/ref types, general unboxing richer semantic regimes more powerful intrinsic mechanism From Frampton et al.'s VEE'09 Talk