Efficient Runtime Code Generation in Rotor Antonio Cisternino 23/4/2003 Università di Pisa Supported by Microsoft Research grant.

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

.NET Technology. Introduction Overview of.NET What.NET means for Developers, Users and Businesses Two.NET Research Projects:.NET Generics AsmL.
Introduction to .NET Framework
Tahir Nawaz Introduction to.NET Framework. .NET – What Is It? Software platform Language neutral In other words:.NET is not a language (Runtime and a.
Microsoft Research March 20, 2000 A Programming Language for Developing Interactive Web Services Claus Brabrand BRICS, University of Aarhus, Denmark.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Introduction to JAVA Vijayan Sugumaran School of Business Administration Oakland University Rochester, MI
1 Pass Compiler 1. 1.Introduction 1.1 Types of compilers 2.Stages of 1 Pass Compiler 2.1 Lexical analysis 2.2. syntactical analyzer 2.3. Code generation.
Ross Tate, Juan Chen, Chris Hawblitzel. Typed Assembly Languages Compilers are great but they make mistakes and can introduce vulnerabilities Typed assembly.
.NET Framework Overview Pingping Ma Nov 16 th, 2006.
Kashif Jalal CA-240 (072) Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 2 of…
Antonio Cisternino & Diego Colombo VisualStorms Tools Another Brick in the Robot... Università degli Studi di Pisa.
Introducing the Common Language Runtime for.NET. The Common Language Runtime The Common Language Runtime (CLR) The Common Language Runtime (CLR) –Execution.
Introducing the Common Language Runtime. The Common Language Runtime The Common Language Runtime (CLR) The Common Language Runtime (CLR) –Execution engine.
Building An Interpreter After having done all of the analysis, it’s possible to run the program directly rather than compile it … and it may be worth it.
3/24/2004COSC4301 assignment 31 Compiler, Interpreter, and Bootstrapping Motivation: When we are asked to write a  Compiler for a complex source language.
Session-02. Objective In this session you will learn : What is Class Loader ? What is Byte Code Verifier? JIT & JAVA API Features of Java Java Environment.
Source Code Basics. Code For a computer to execute instructions, it needs to be in binary Each instruction is given a number Known as “operation code”
Platforms and tools for Web Services and Mobile Applications Introduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004.
A Free sample background from © 2001 By Default!Slide 1.NET Overview BY: Pinkesh Desai.
Introduction to .Net Framework
JVM And CLR Dan Agar April 16, Outline Java and.NET Design Philosophies Overview of Virtual Machines Technical Look at JVM and CLR Comparison of.
Meir Botner David Ben-David. Project Goal Build a messenger that allows a customer to communicate with a service provider for a fee.
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
Types for Programs and Proofs Lecture 1. What are types? int, float, char, …, arrays types of procedures, functions, references, records, objects,...
Lecture 1 Programming in C# Introducing C# Writing a C# Program.
Java2C# Antonio Cisternino Part II. Outline Array types Enum types Value types  differences from classes  boxing and unboxing Delegate types  Base.
MSIL & CLI Kun-Yuan Shieh.
Language processors (Chapter 2) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
 OOPLs  Help companies reduce complexity  Increase competition in open markets  Speeds up development  Improves maintenance, resusability, modifiability.
1.  10% Assignments/ class participation  10% Pop Quizzes  05% Attendance  25% Mid Term  50% Final Term 2.
ProgrammingLanguages Programming Languages Language Definition, Translation and Design.
1 Chapter 1 Introduction. 2 Outlines 1.1 Overview and History 1.2 What Do Compilers Do? 1.3 The Structure of a Compiler 1.4 The Syntax and Semantics of.
COMP3190: Principle of Programming Languages
11/23/2015CS2104, Lecture 41 Programming Language Concepts, COSC Lecture 4 Procedures, last call optimization.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.
1 Alex Proctor and Brian Lee for CSCI 431 at UNCA, Fall 2002 ML (Meta Language) a brief introduction Alex Proctor and Brian Lee For CSCI 431 at the University.
Aspect Oriented Programming in.NET with CodeBricks Antonio Cisternino Academic Days Milan, 2004 Università di Pisa Supported by Microsoft Research grant.
Semantic Analysis II Type Checking EECS 483 – Lecture 12 University of Michigan Wednesday, October 18, 2006.
Advanced Functional Programming Tim Sheard 1 Lecture 17 Advanced Functional Programming Tim Sheard Oregon Graduate Institute of Science & Technology Lecture:
Common Language Runtime Introduction  The common language runtime is one of the most essential component of the.Net Framework.  It acts.
Wel come To Seminar On C#.
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm Hutchinson.
The Execution System1. 2 Introduction Managed code and managed data qualify code or data that executes in cooperation with the execution engine The execution.
Constructs for Data Organization and Program Control, Scope, Binding, and Parameter Passing. Expression Evaluation.
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
Presented by : A best website designer company. Chapter 1 Introduction Prof Chung. 1.
METADATA IN.NET Presented By Sukumar Manduva. INTRODUCTION  What is Metadata ? Metadata is a binary information which contains the complete description.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Introduction To Software Development Environment.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
.NET Framework.
Compiler, Interpreter, and Bootstrapping
Chapter 1 Introduction.
Types for Programs and Proofs
Compiler Construction (CS-636)
.Net A brief introduction to
C# and the .NET Framework
Chapter 1 Introduction.
Programming Language Concepts (CIS 635)
2.1. Compilers and Interpreters
.NET and .NET Core 2. .NET Runtimes Pan Wuming 2017.
Web Development Using ASP .NET
More Object-Oriented Programming
.Net Framework Details Imran Rashid CTO at ManiWeber Technologies.
IS 135 Business Programming
Presentation transcript:

Efficient Runtime Code Generation in Rotor Antonio Cisternino 23/4/2003 Università di Pisa Supported by Microsoft Research grant

Introduction Dynamic code generation is a programming technique that is being widely used in complex systemsDynamic code generation is a programming technique that is being widely used in complex systems Strongly Typed Execution Environments (STEE), such as JVM and Microsoft CLR, provide rich services to running code (dynamic loading, security, …)Strongly Typed Execution Environments (STEE), such as JVM and Microsoft CLR, provide rich services to running code (dynamic loading, security, …) To enforce type safety at load time STEE should retain enough information in binaries about types (metadata)To enforce type safety at load time STEE should retain enough information in binaries about types (metadata) It is convenient for PL targeting STEE to share a significant amount of programming abstractionsIt is convenient for PL targeting STEE to share a significant amount of programming abstractions

Encoding Code Generation into Binaries Programming language Intermediate (or machine) language Real transformation Perceived transformation Language Level RTCG EE level RTCG Type T

What we did? We introduced a Code type to represents code valuesWe introduced a Code type to represents code values Code instances are built around methodsCode instances are built around methods A single operation called Bind allow code manipulationA single operation called Bind allow code manipulation public static int add(int i, int j) { return i + j; } return i + j; } Code c = new Code(typeof(T).GetMethod("add")); Code inc = c.Bind(1, new Free()); Delegate int F(int i); F f = (F)inc.MakeDelegate(typeof(F));

Binding Values (Bind v ) Values can be bound to argumentsValues can be bound to arguments All values can be bound to an input argument:All values can be bound to an input argument: Code c = SelectCodeGen(); DBConnection conn = new Connection(…); c.Bind(conn);// Fix the connection

Binding Code Values to Args (Bind  ) An input argument of a code value can be bound with another code value returning a value (compatible with it)An input argument of a code value can be bound with another code value returning a value (compatible with it) Arguments of the code value bound to an argument are lifted into the signature of the resulting code valueArguments of the code value bound to an argument are lifted into the signature of the resulting code value Code c = CodeOfAdd(); // c is x,y.x+y Code d = c.Bind(c, new Free()); // d is x,y,z.x + y + z

Splicing Code Values (Bind  ) If the argument is of higher order type (a delegate type in CLI) we can splice a code value in place of invocations of the argumentIf the argument is of higher order type (a delegate type in CLI) we can splice a code value in place of invocations of the argument With this mechanism it is possible to write methods with holes for other methodsWith this mechanism it is possible to write methods with holes for other methods delegate void Cmd(int i); static void For(Cmd c) { for (int j; j < 10; j++) c(j); } for (int j; j < 10; j++) c(j); } static void Print(int i) { Console.WriteLine("Iteration {0}", i); } Console.WriteLine("Iteration {0}", i); } Code f = CodeOfFor(), p = CodeOfPrint(); Code c = f.Bind(new Splice(p));

Formal Model LetLet –c = addCode.Bind(addCode.Bind(2, new Free()), new Free()), we expect: –add(add(2, x), y) == c(x, y) We have defined a transformation on IL code that perform substitution of code fragmentsWe have defined a transformation on IL code that perform substitution of code fragments Theorem: the code generated by the transformation preserves the expected semanticsTheorem: the code generated by the transformation preserves the expected semantics Theorem: only well-formed and type-safe code can be generatedTheorem: only well-formed and type-safe code can be generated

Applications Bind  is useful to turn interpreter in dummy compilersBind  is useful to turn interpreter in dummy compilers Our current implementation is pretty fast: it is suitable for runtime code generationOur current implementation is pretty fast: it is suitable for runtime code generation General combinators can be defined to generate arbitrary programsGeneral combinators can be defined to generate arbitrary programs It is possible to express staged computations because transformation is IL -> ILIt is possible to express staged computations because transformation is IL -> IL

RE: Benchmark It is a worst case test: we use debug code!!!It is a worst case test: we use debug code!!! Compilation time of Code Bricks version is about one third of the SSCLI versionCompilation time of Code Bricks version is about one third of the SSCLI version

Code Bricks and Multi-Staging Multi stage programs are programs that, when executed, produce other programsMulti stage programs are programs that, when executed, produce other programs The program is annotated so that the whole execution can be controlled in a single sourceThe program is annotated so that the whole execution can be controlled in a single source Real applications make use of multi-stage programming though based on interpreters and preprocessors: examples are PHP and ASP technologiesReal applications make use of multi-stage programming though based on interpreters and preprocessors: examples are PHP and ASP technologies One essential aspect of Code Bricks is that code transformation is performed at IL level so it is easy to write a code which outputs a function which makes use of Code values insideOne essential aspect of Code Bricks is that code transformation is performed at IL level so it is easy to write a code which outputs a function which makes use of Code values inside Usually this would be possible only by shipping an interpreter together with the programUsually this would be possible only by shipping an interpreter together with the program

MetaML and Code Bricks The four operators of MetaML:The four operators of MetaML: 1.Brackets <> construct a code fragment 2.Escape ~ combines code fragments 3.Run run executes a code fragment 4.Lift lift constructs a code fragment from a ground value MetaML compiler can rely on Code Bricks to implement staging operatorsMetaML compiler can rely on Code Bricks to implement staging operators

Code Bricks and Rotor Current implementation supports with.NET and SSCLI for Windows (CLIFileReader depends on file mapping)Current implementation supports with.NET and SSCLI for Windows (CLIFileReader depends on file mapping) RE benchmark has been possible because sources are availableRE benchmark has been possible because sources are available MakeDelegate is implemented with Reflection.Emit: we are changing Rotor to support Code objectsMakeDelegate is implemented with Reflection.Emit: we are changing Rotor to support Code objects Code generated by CodeBricks is associated with a delegate: garbage collection of code can be done when the delegate is collectedCode generated by CodeBricks is associated with a delegate: garbage collection of code can be done when the delegate is collected

Conclusions Code generation is expressed by means of combination of code values (basically methods)Code generation is expressed by means of combination of code values (basically methods) Method application notion offers control over the generated codeMethod application notion offers control over the generated code It is possible to express staged computations that can even be ‘cross process’It is possible to express staged computations that can even be ‘cross process’ It is possible to derive properties of generated code relying on the structure of the bindingIt is possible to derive properties of generated code relying on the structure of the binding CodeBricks will be soon available! ( will be soon available! (