CSC 310 – Imperative Programming Languages, Spring, 2009 Virtual Machines and Threaded Intermediate Code (instead of PR Chapter 5 on Target Machine Architecture)

Slides:



Advertisements
Similar presentations
Chapt.2 Machine Architecture Impact of languages –Support – faster, more secure Primitive Operations –e.g. nested subroutine calls »Subroutines implemented.
Advertisements

Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
Instruction Set Design
1 Lecture 10 Intermediate Representations. 2 front end »produces an intermediate representation (IR) for the program. optimizer »transforms the code in.
CPU Review and Programming Models CT101 – Computing Systems.
The Assembly Language Level
Chapter FourModern Programming Languages1 Language Systems.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Intermediate code generation. Code Generation Create linear representation of program Result can be machine code, assembly code, code for an abstract.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
COP4020 Programming Languages
3-1 3 Compilers and interpreters  Compilers and other translators  Interpreters  Tombstone diagrams  Real vs virtual machines  Interpretive compilers.
CSc 453 Interpreters & Interpretation Saumya Debray The University of Arizona Tucson.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Intro to Java The Java Virtual Machine. What is the JVM  a software emulation of a hypothetical computing machine that runs Java bytecodes (Java compiler.
Language Systems Chapter FourModern Programming Languages 1.
CS 355 – Programming Languages
A Portable Virtual Machine for Program Debugging and Directing Camil Demetrescu University of Rome “La Sapienza” Irene Finocchi University of Rome “Tor.
Arpit Jain Mtech1. Outline Introduction Dalvik VM Java VM Examples Comparisons Experimental Evaluation.
Fundamentals of Python: From First Programs Through Data Structures Chapter 14 Linear Collections: Stacks.
Dr. José M. Reyes Álamo 1.  The 80x86 memory addressing modes provide flexible access to memory, allowing you to easily access ◦ Variables ◦ Arrays ◦
4-1 Chapter 4 - The Instruction Set Architecture Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring.
4-1 Chapter 4 - The Instruction Set Architecture Department of Information Technology, Radford University ITEC 352 Computer Organization Principles of.
LANGUAGE TRANSLATORS: WEEK 24 TRANSLATION TO ‘INTERMEDIATE’ CODE (overview) Labs this week: Tutorial Exercises on Code Generation.
CS412/413 Introduction to Compilers and Translators May 3, 1999 Lecture 34: Compiler-like Systems JIT bytecode interpreter src-to-src translator bytecode.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Elements of Computing Systems, Nisan & Schocken, MIT Press, 2005, Chapter 11: Compiler II: Code Generation slide 1www.idc.ac.il/tecs.
4-1 Chapter 4 - The Instruction Set Architecture Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
Copyright © 2007 Addison-Wesley. All rights reserved.1-1 Reasons for Studying Concepts of Programming Languages Increased ability to express ideas Improved.
COP4020 Programming Languages Subroutines and Parameter Passing Prof. Xin Yuan.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 9.
4-1 Chapter 4 - The Instruction Set Architecture Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
LANGUAGE SYSTEMS Chapter Four Modern Programming Languages 1.
Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers Kostis Sagonas
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
Operand Addressing And Instruction Representation Cs355-Chapter 6.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Instruction Sets: Addressing modes and Formats Group #4  Eloy Reyes  Rafael Arevalo  Julio Hernandez  Humood Aljassar Computer Design EEL 4709c Prof:
Introduction to OOP CPS235: Introduction.
Code Generation CPSC 388 Ellen Walker Hiram College.
CS 598 Scripting Languages Design and Implementation 12. Interpreter implementation.
Procedures and Functions Procedures and Functions – subprograms – are named fragments of program they can be called from numerous places  within a main.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 10 Ahmed Ezzat.
LECTURE 19 Subroutines and Parameter Passing. ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments.
Compiler Chapter 9. Intermediate Languages Sung-Dong Kim Dept. of Computer Engineering, Hansung University.
Component 1.6.
Run-Time Environments Chapter 7
William Stallings Computer Organization and Architecture 6th Edition
PROGRAMMING LANGUAGES
Programming Language Hierarchy, Phases of a Java Program
The Stack.
Alvaro Mauricio Peña Dariusz Niworowski Frank Rodriguez
Computer Architecture and Organization Miles Murdocca and Vincent Heuring Chapter 4 – The Instruction Set Architecture.
William Stallings Computer Organization and Architecture 8th Edition
Processor Organization and Architecture
Chapter 9 :: Subroutines and Control Abstraction
CSc 453 Interpreters & Interpretation
CSC 533: Programming Languages Spring 2015
ECEG-3202 Computer Architecture and Organization
Chapter 11 Introduction to Programming in C
(Computer fundamental Lab)
Introduction to Intermediate Code, virtual machine implementation
CSC 533: Programming Languages Spring 2018
CSc 453 Interpreters & Interpretation
CSC 533: Programming Languages Spring 2019
Presentation transcript:

CSC 310 – Imperative Programming Languages, Spring, 2009 Virtual Machines and Threaded Intermediate Code (instead of PR Chapter 5 on Target Machine Architecture)

Virtual Machines and Language Design A VM is an idealization of the run-time processor for a family of source languages. A VM’s instructions, register set, memory access architecture and threading architecture have close mappings to source language requirements. A VM is interpreted via processor simulation. Java compiles to portable Java virtual machine code. Pcode helped popularize Pascal in the 1980’s.

Virtual Machine Approaches from Programming Language Pragmatics Pure compilation – optimize target execution at the cost of compile/optimize/link time Pure interpretation – optimize development time and portability

Intermediate Code VMs Combine Both Approaches VM provides a portable back end for interpreting programs on different processors. VM provides a portable back end for compiled code generation. VM provides a means for designing a language or processor using simulation.

Varieties of Interpreted VMs (A thread is a pointer in this discussion!) Direct interpretation of source code strings. String threading: string -> code mapping and execution via a hash table in early versions of Forth. This approach is slow. Interpretation of a compiler’s abstract syntax tree. This approach is slow and is a poor emulation mechanism. Subroutine threaded virtual machine code. Direct threaded virtual machine code. A sequence of subroutine calls emulate a sequence of machine instructions. Direct threading dispenses with the call instructions. Indirect threaded virtual machine code. Each instruction is a pointer to a pointer to the code. Token threaded code uses non-pointer byte codes.

Forth-like Virtual Machine Forth language pioneered threaded intermediate code, extensible compilers, and stack-based postfix virtual machines. Dense code for small footprint systems. Influenced Postscript, JVM, Sparc bootloader code.html code.html g_models See also our course web page for links. g_models

Stack-based Threaded Emulated Processor (STEP) A Forth like VM architecture from Bell Labs, 1997, used to control remote execution and debugging of digital signal processors (DSPs). It predates availability of a JVM-ME with tool support (end of 1998 and later). “STEP: A Stack-based Controller for HDM Tap Managers” gives the VM architecture and implementation in C language. We will build a similar, scaled down implementation of the VM using indirect threaded code in Python.

STEP VM Architecture ip is instruction pointer, points to VM machine instructions. data stack holds params and return values, ds is stack pointer. thread stack holds return addresses for ip, ts is stack pointer. dictionary holds compiled code and data.

Threaded code has Primitives and Secondaries. A primitive is a sequence of machine code instructions invoked via a call to subroutine, and indirect jump or a doubly indirect jump. A primitive reached via a jump finishes by jumping back to a threaded code interpreter for the VM. A secondary is a sequence of threaded code “opcodes,” possibly intermixed with in-line data. It is typically a subroutine defined in the emulated language. Its opcodes are pointers to primitives, including call instructions for secondaries.

Subroutine Threaded Code A threaded code secondary consists of a sequence of subroutine calls in machine code. 1. call push_inline() to push an inline int to data stack – 2. an in-line value of 5 (calls intermixed w. in-line data) – machine code primitive must adjust return address 3. call push_inline() to push an in-line data addr to stack – 4. an in-line data address 5. call fetch() to pop the address and push its data 6. call add_function() to add top 2 stack elements, leaving the sum on the stack 7. call printi to pop and print the int on the data stack

Direct Threaded Code Subroutine threaded code without the call opcodes. 1. push_inline to push an inline int to data stack – 2. an in-line value of 5 (calls intermixed w. in-line data) – machine code primitive must adjust instruction pointer 3. push_inline to push an in-line data addr to stack – 4. an in-line data address 5. fetch to pop the address and push its data 6. add_function() to add top 2 stack elements, leaving the sum on the stack 7. printi to pop and print the int on the data stack An inner interpreter fetches and jumps to the subroutines. They jump back to the inner interpreter.

Indirect Threaded Code Indirect threaded code adds another level of indirection. A threaded opcode is no longer a pointer to a subroutine. It is a pointer to a pointer to a subroutine. This second pointer resides with data field that were previous in-line. No in-line data with indirect threaded code.

Indirect Threaded Code (continued) Code dictionaries are smaller because in-line data are removed. Interning constant data allows a single copy of a subroutine- data pair to be allocated. Multiple in-line fetches of a constant value 3, for example, can occur from multiple threaded instructions using a single copy of a fetch_function,3 binding. Indirect threaded code runs faster on architectures that separate code and data such as a Harvard Architecture typical of Digital Signal Processors (DSPs) and Network Processors. Indirect threaded code better supports “in-lining” of nested code expressions, e.g. an in-line lambda expression.

Token Threaded Code These are the byte codes of the Java Virtual Machine, for example. These run slower than pointer-based threaded code, but bytes code are portable with recompilation or relocation. Pointer-based threaded code is relative to its run-time process’ address space layout. Mapping byte codes to subroutines (e.g., via hashing) or using them to control switch/case statements are two means of interpretation.

Just-in-time Compilation and HotSpot JIT Compilation JIT compilation replaces a secondary with a machine code routine the first time it is interpreted. There is some performance penalty during compilation, and growth in memory usage. Not all secondaries are in the critical path. HotSpot compilation examines statistical analyses on secondaries before compiling them to machine code.