Run-time Program Management. Hwansoo Han

Similar documents
Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1

JVML Instruction Set. How to get more than 256 local variables! Method Calls. Example. Method Calls

High-Level Language VMs

JVM. What This Topic is About. Course Overview. Recap: Interpretive Compilers. Abstract Machines. Abstract Machines. Class Files and Class File Format

Chapter 5. A Closer Look at Instruction Set Architectures. Chapter 5 Objectives. 5.1 Introduction. 5.2 Instruction Formats

Chapter 5. A Closer Look at Instruction Set Architectures

Java and C II. CSE 351 Spring Instructor: Ruth Anderson

Chapter 5. A Closer Look at Instruction Set Architectures

Chapter 5. A Closer Look at Instruction Set Architectures. Chapter 5 Objectives. 5.1 Introduction. 5.2 Instruction Formats

Java: framework overview and in-the-small features

SOFTWARE ARCHITECTURE 7. JAVA VIRTUAL MACHINE

Java Class Loading and Bytecode Verification

Under the Hood: The Java Virtual Machine. Lecture 23 CS2110 Fall 2008

Course Overview. PART I: overview material. PART II: inside a compiler. PART III: conclusion

JAM 16: The Instruction Set & Sample Programs

Java Security. Compiler. Compiler. Hardware. Interpreter. The virtual machine principle: Abstract Machine Code. Source Code

Delft-Java Link Translation Buffer

Compiling Techniques

Roadmap. Java: Assembly language: OS: Machine code: Computer system:

CSCE 314 Programming Languages

Plan for Today. Safe Programming Languages. What is a secure programming language?

CS2110 Fall 2011 Lecture 25. Under the Hood: The Java Virtual Machine, Part II

SABLEJIT: A Retargetable Just-In-Time Compiler for a Portable Virtual Machine p. 1

Compiler construction 2009

Over-view. CSc Java programs. Java programs. Logging on, and logging o. Slides by Michael Weeks Copyright Unix basics. javac.

02 B The Java Virtual Machine

invokedynamic IN 45 MINUTES!!! Wednesday, February 6, 13

CS263: Runtime Systems Lecture: High-level language virtual machines. Part 1 of 2. Chandra Krintz UCSB Computer Science Department

The Java Virtual Machine. CSc 553. Principles of Compilation. 3 : The Java VM. Department of Computer Science University of Arizona

Program Dynamic Analysis. Overview

3/15/18. Overview. Program Dynamic Analysis. What is dynamic analysis? [3] Why dynamic analysis? Why dynamic analysis? [3]

CHAPTER 5 A Closer Look at Instruction Set Architectures

Under the Hood: The Java Virtual Machine. Problem: Too Many Platforms! Compiling for Different Platforms. Compiling for Different Platforms

The Java Virtual Machine

Code Generation Introduction

The Java Virtual Machine

Hardware-Supported Pointer Detection for common Garbage Collections

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator

Virtual Machines and Dynamic Translation: Implementing ISAs in Software

CSc 453 Interpreters & Interpretation

CHAPTER 5 A Closer Look at Instruction Set Architectures

Today. Instance Method Dispatch. Instance Method Dispatch. Instance Method Dispatch 11/29/11. today. last time

Chapter 1 GETTING STARTED. SYS-ED/ Computer Education Techniques, Inc.

Java byte code verification

An Introduction to Multicodes. Ben Stephenson Department of Computer Science University of Western Ontario

For our next chapter, we will discuss the emulation process which is an integral part of virtual machines.

Delft-Java Dynamic Translation

Topics Power tends to corrupt; absolute power corrupts absolutely. Computer Organization CS Data Representation

YETI. GraduallY Extensible Trace Interpreter VEE Mathew Zaleski, Angela Demke Brown (University of Toronto) Kevin Stoodley (IBM Toronto)

CMPSC 497: Java Security

Problem: Too Many Platforms!

Static Program Analysis

Virtual Machines. Virtual Machines

Question. 1 Features of Java.

Practical Malware Analysis

The Java Language Implementation

A Trace-based Java JIT Compiler Retrofitted from a Method-based Compiler

Building a Compiler with. JoeQ. Outline of this lecture. Building a compiler: what pieces we need? AKA, how to solve Homework 2

Java TM. Multi-Dispatch in the. Virtual Machine: Design and Implementation. Computing Science University of Saskatchewan

Certified Core Java Developer VS-1036

Translating JVM Code to MIPS Code 1 / 43

The Hardware/Software Interface CSE351 Spring 2015

Code Profiling. CSE260, Computer Science B: Honors Stony Brook University

COMP 520 Fall 2009 Virtual machines (1) Virtual machines

Announcements. My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM.

Taming the Java Virtual Machine. Li Haoyi, Chicago Scala Meetup, 19 Apr 2017

CSC 4181 Handout : JVM

Chapter 5. A Closer Look at Instruction Set Architectures

Lecture 4: Instruction Set Architecture

Where We Are. Lexical Analysis. Syntax Analysis. IR Generation. IR Optimization. Code Generation. Machine Code. Optimization.

Project. there are a couple of 3 person teams. a new drop with new type checking is coming. regroup or see me or forever hold your peace

CSc 520 Principles of Programming Languages

Lecture 2: The Art of Emulation

1. Introduction to the Common Language Infrastructure

EITF20: Computer Architecture Part2.1.1: Instruction Set Architecture

Understand the factors involved in instruction set

CSc 453. Compilers and Systems Software. 18 : Interpreters. Department of Computer Science University of Arizona. Kinds of Interpreters

Copyright 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 16

Introduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C

Compiler construction 2009

CSc 553. Principles of Compilation. 2 : Interpreters. Department of Computer Science University of Arizona

Page 1. Structure of von Nuemann machine. Instruction Set - the type of Instructions

Jaos - Java on Aos. Oberon Event 03 Patrik Reali

Trace Compilation. Christian Wimmer September 2009

Computer Systems A Programmer s Perspective 1 (Beta Draft)

Instruction Set Principles and Examples. Appendix B

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations

Improving Java Performance

Notes of the course - Advanced Programming. Barbara Russo

Static Analysis of Dynamic Languages. Jennifer Strater

Chapter 5:: Target Machine Architecture (cont.)

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

CS252 Spring 2017 Graduate Computer Architecture. Lecture 18: Virtual Machines

Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

CMSC 430 Introduction to Compilers. Spring Intermediate Representations and Bytecode Formats

Chapter 5. Names, Bindings, and Scopes

javac 29: pop 30: iconst_0 31: istore_3 32: jsr [label_51]

Typical Processor Execution Cycle

Chapter 2: Instructions How we talk to the computer

Transcription:

Run-time Program Management Hwansoo Han

Run-time System Run-time system refers to Set of libraries needed for correct operation of language implementation Some parts obtain all the information from subroutine arguments (e.g., heap management) Others require more extensive knowledge of the compiler or the generated program (e.g., garbage collector) 2

Compiler/Runtime Integration Examples Garbage collection Variable numbers of arguments Exception handling Event handling Coroutine & thread implementation Remote procedure call Transactional memory Dynamic linking 3

Virtual Machines A complete set of programming environment Application programming interfaces (APIs) Instruction set architecture (ISA) I/O Scheduling Other services provided by libraries and OS 4

System VM vs. Process VM System VMs (virtual machine monitors) Emulates all the hardware needed to run a standard OS Privileged and unprivileged instructions Memory mapped I/O, Virtual memory Interrupt IBM CP/CMS (1967) run multiple single-user CMS s on CP VMware, Parallels run multiple OSes Process VMs Provide an environment for a single user-level process Subset of unprivileged instructions Library-level I/O interface Java Virtual Machine (JVM) runs Java bytecode Common Language Infrastructure (CLI) runs Common Intermediate Language (CIL) 5

Java Virtual Machine (JVM) Sun Microsystems developed the Java Language (1990-1) Code in the JVM was entirely interpreted Just-in-time (JIT) compiler added in 1998 (with Java2) JVM architecture Interfaces are designed as target for a Java compiler Direct support for all the built-in and reference types Enforce definite assignment (i.e., no uninitialized variables) and type safety Built-in support for exceptions, threads, garbage collection, reflection, dynamic loading, and security Compilers targeting JVM exist for many languages other than Java Ruby, JavaScript, Python, Scheme, C, Ada, Cobol,... 6

JVM Storage Management Storage allocations in the JVM mirror those of Java language Global constant pool Set of registers Stack for each thread Method area to hold executable bytecode Heap for dynamically allocated objects 7

Constant Pool Global data Constant pool contains both program constants and a variety of symbol table information Example class Hello { public static void main(string args[]) { System.out.println( Hello, world! ); } } 8

Content of Constant Pool Asciz: zero-terminated ASCII string Textual names Files (14) Classes (21, 22, 23, 26) Methods (7, 11, 27) Fields (24) Others (9, 10, 13) Type signatures Field & method V: void Lname: class name (8, 12, 25, 28) [ output of Sun s javap ] 9

Class Files Class file is stored as a stream of byte javac Hello.java produces a class file, Hello.class Begins with a magic number (0x_cafe_babe) Multiple class files can be combined into a Java archive jar cf jar-file input-files creates a Java archive, jar-file from multiple input-files jar tf jar-file views the content of a Java archive, jar-file jar xf jar-file extracts the content of a Java archive, jar-file 10

Java Bytecode Instructions are operated on a stack based machine An entry of Class file s method table holds Bytecode for a method Other information Number of local variables, including parameters Maximum depth required in the operand stack Table of exception handler information Bytecode range covered by this handler Address (index in the code) of the handler itself Type of exception caught (an index into the constant pool) 11

Bytecode Instruction Set Format Opcode of a single byte Arguments, if any, occupying subsequent bytes (big-endian) Most instructions do not need arguments Version 2 (current as of early 2008) Load/store move values between operand stack and local variable array Arithmetic integer and floating-point operation on operand stack values Type conversion widen or narrow values among built-in types Object management create/query/access the objects & arrays Operand stack management push, pop, duplicate, swap Control transfer conditional, unconditional, multiway branches (switch) Method calls call/return of methods (including constructor/initializers) Exceptions throw Monitors enter and exit (wait, notify, notifyall are invoked) 12

Java Program - example List insert 13

Java Bytecode - example Special load/store 14 First 4 local var array aload_[0123] : reference load iload_[0123] : integer load astore_[0123] : reference store istore_[0123] : integer store Access fields Object reference in the stack Field argument (index of constant pool) getfield, putfield Local var array Operand stack 0: 1: 2: 3: this v n top public void insert(int v) { node n = head; while (n.next!= null && n.next.val < v) {... }... Code: Stack=3, Locals=4, Args_size=2 0: aload_0 // this 1: getfield #4 // head 4: astore_2 5: aload_2 // n 6: getfield #5 // n.next 9: ifnull 31 12: aload_2 // n 13: getfield #5 // n.next 16: getfield #6 // n.next.val 19: iload_1 // v 20: if_icmpge 31

Java Bytecode example (cont d) Control transfer ifnull, if_icmpge, goto,... Object management new, newarray Operand stack management dup Method call/return invokespecial, invokeinterface, invokestatic, invokevirtual, return, areturn, ireturn [ output of Sun s javap ] 15

Common Language Infrastructure (CLI) History of CLI Began at Microsoft in the late 1990s Need for interoperability among programming languages running on Windows platforms For.NET, a specification for CLI VM was standardized by ECMA in 2001 Contributions of CLI Common Type System (CTS) for all supported languages Virtual Execution System (VES) virtual machine architecture Common Intermediate Language (CIL) instruction set for VES Strong resemblance to Java bytecode Portable Executable (PE) a portable file format for code and metadata Based on Common Object File Format (COFF) from AT&T System V Unix Languages supported 16 C#, Visual Basic, C++, Jscript, F# (an ML descendant)

Architecture of CLI Similarities between CLI and JVM Multi-threaded, stack-based virtual machine Garbage collection, exceptions, Virtual method dispatch, mix-in inheritance Platform-independent, self-descriptive, bytecode notation Safety features as in JVMs Definite assignment, strong typing, Protection against overflow/underflow of the operand stack 17

Architecture of CLI (cont d) Contrasts between CLI and JVM 18 Richer type system for CLI Both value and reference variable of structured types Contiguous multidimensional arrays, function pointers,... Richer calling mechanisms in CLI Explicit tail-recursion Value and reference parameters, variable number of parameters Multiple return values, non-virtual methods Unsafe code made explicit in CLI (for unverifiable code) Non-converting type cast Dynamic allocation of non-garbage-collected memory Pointer-to non-heap data, pointer arithmetic Miscellaneous CLI support Global data and functions, Local variables with elaboration-time binding, Optional detection of arithmetic overflow

Late Binding of Machine Code Just-in-time (JIT) compilation JIT system compiles programs immediately prior to execution source/intermediate code to machine code Can add significant delay to program start-up time Cannot apply expensive optimizations Not global, interprocedural, but local optimizations Source-to-bytecode compiler (javac) handles heavy machineindependent optimizations instead, but still heavy machine-code level optimizations cannot be done Use a combination of interpreter and JIT compilation to reduce the overhead of start-up time and latency Incremental JIT compilation Executing with interpreter, compiling in parallel for future calls Caching the compiled code for later use 19

Dynamic Compilation Useful cases for delayed compilation Source or bytecode was not created or discovered until run time Wish to perform optimizations that depend on information gathered during execution Hot paths discovery from profiling 20 Most programs spend most of time in a small fraction of code Aggressive optimizations on hot paths can yield large improvement Making hot paths contiguous in memory Unrolling loops Assigning frequently used expressions to registers Scheduling instructions to minimize the pipeline stalls Allow statically unsafe optimizations, which is OK dynamically In-lining functions which is proved not to be extended SUN s HotSpot JVM and JIT (first released in 1999) Microsoft s CIL-to-machine-code compiler Common Lisp compiler

Binary Translation Recompilation of object code Already compiled code run on a machine with different ISA Apple s Rosetta system (run PowerPC Mac code on x86 Mac) Mac 68K emulator (interpret 68K code for PowerPC) DEC FX!32 for MS Windows (interpret and hot-path translation) HP Aries (PA-RISC to Itanium), Intel IA-32 EL (x86 to Itanium) Dynamic optimizations for long-running programs Fast compilation first, aggressive profile-based dynamic optimizations Partial execution trace (hot path) optimization removes branch overhead HP Dynamo for PA-RISC, DynamoRIO for x86 Challenges from the loss of information in the original code 21 Object code typically lacks type information and control-flow constructs